Changes in uspace/srv/net/netif/lo/lo.c [46d4d9f:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
r46d4d9f r14f1db0 28 28 29 29 /** @addtogroup lo 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Loopback network interface implementation.34 * Loopback network interface implementation. 35 35 */ 36 36 … … 42 42 #include <ipc/ipc.h> 43 43 #include <ipc/services.h> 44 #include <ipc/nil.h> 45 46 #include <net/modules.h> 44 45 #include <net_err.h> 46 #include <net_messages.h> 47 #include <net_modules.h> 47 48 #include <adt/measured_strings.h> 48 #include <packet _client.h>49 #include <net /device.h>49 #include <packet/packet_client.h> 50 #include <net_device.h> 50 51 #include <nil_interface.h> 52 #include <nil_messages.h> 51 53 #include <netif_interface.h> 52 54 #include <netif_local.h> 53 55 54 /** Default hardware address. */ 56 /** Default hardware address. 57 */ 55 58 #define DEFAULT_ADDR "\0\0\0\0\0\0" 56 59 57 /** Default address length. */ 60 /** Default address length. 61 */ 58 62 #define DEFAULT_ADDR_LEN (sizeof(DEFAULT_ADDR) / sizeof(char)) 59 63 60 /** Loopback module name. */ 64 /** Loopback module name. 65 */ 61 66 #define NAME "lo" 62 67 63 /** Network interface global data. */ 68 /** Network interface global data. 69 */ 64 70 netif_globals_t netif_globals; 65 71 66 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 67 ipc_call_t *answer, int *answer_count) 68 { 72 /** Changes the loopback state. 73 * @param[in] device The device structure. 74 * @param[in] state The new device state. 75 * @returns The new state if changed. 76 * @returns EOK otherwise. 77 */ 78 int change_state_message(netif_device_t * device, device_state_t state); 79 80 /** Creates and returns the loopback network interface structure. 81 * @param[in] device_id The new devce identifier. 82 * @param[out] device The device structure. 83 * @returns EOK on success. 84 * @returns EXDEV if one loopback network interface already exists. 85 * @returns ENOMEM if there is not enough memory left. 86 */ 87 int create(device_id_t device_id, netif_device_t * * device); 88 89 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 69 90 return ENOTSUP; 70 91 } 71 92 72 int netif_get_addr_message(device_id_t device_id, measured_string_t *address) 73 { 74 if (!address) 93 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){ 94 if(! address){ 75 95 return EBADMEM; 76 96 } 77 97 address->value = str_dup(DEFAULT_ADDR); 78 98 address->length = DEFAULT_ADDR_LEN; 79 80 return EOK; 81 } 82 83 int netif_get_device_stats(device_id_t device_id, device_stats_t *stats) 84 { 85 netif_device_t *device; 86 int rc; 87 88 if (!stats) 99 return EOK; 100 } 101 102 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){ 103 ERROR_DECLARE; 104 105 netif_device_t * device; 106 107 if(! stats){ 89 108 return EBADMEM; 90 91 rc = find_device(device_id, &device); 92 if (rc != EOK) 93 return rc; 94 95 memcpy(stats, (device_stats_t *) device->specific, 96 sizeof(device_stats_t)); 97 98 return EOK; 99 } 100 101 /** Changes the loopback state. 102 * 103 * @param[in] device The device structure. 104 * @param[in] state The new device state. 105 * @return The new state if changed. 106 * @return EOK otherwise. 107 */ 108 static int change_state_message(netif_device_t *device, device_state_t state) 109 } 110 ERROR_PROPAGATE(find_device(device_id, &device)); 111 memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t)); 112 return EOK; 113 } 114 115 int change_state_message(netif_device_t * device, device_state_t state) 109 116 { 110 117 if (device->state != state) { … … 120 127 } 121 128 122 /** Creates and returns the loopback network interface structure. 123 * 124 * @param[in] device_id The new devce identifier. 125 * @param[out] device The device structure. 126 * @return EOK on success. 127 * @return EXDEV if one loopback network interface already exists. 128 * @return ENOMEM if there is not enough memory left. 129 */ 130 static int create(device_id_t device_id, netif_device_t **device) 131 { 129 int create(device_id_t device_id, netif_device_t * * device){ 132 130 int index; 133 131 134 if (netif_device_map_count(&netif_globals.device_map) > 0)132 if(netif_device_map_count(&netif_globals.device_map) > 0){ 135 133 return EXDEV; 136 137 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 138 if (!*device) 139 return ENOMEM; 140 141 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 142 if (!(*device)->specific) { 143 free(*device); 144 return ENOMEM; 145 } 146 147 null_device_stats((device_stats_t *) (*device)->specific); 148 (*device)->device_id = device_id; 149 (*device)->nil_phone = -1; 150 (*device)->state = NETIF_STOPPED; 151 index = netif_device_map_add(&netif_globals.device_map, 152 (*device)->device_id, *device); 153 154 if (index < 0) { 155 free(*device); 156 free((*device)->specific); 157 *device = NULL; 158 return index; 159 } 160 161 return EOK; 162 } 163 164 int netif_initialize(void) 165 { 134 }else{ 135 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 136 if(!(*device)){ 137 return ENOMEM; 138 } 139 (** device).specific = malloc(sizeof(device_stats_t)); 140 if(! (** device).specific){ 141 free(*device); 142 return ENOMEM; 143 } 144 null_device_stats((device_stats_ref)(** device).specific); 145 (** device).device_id = device_id; 146 (** device).nil_phone = -1; 147 (** device).state = NETIF_STOPPED; 148 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device); 149 if(index < 0){ 150 free(*device); 151 free((** device).specific); 152 *device = NULL; 153 return index; 154 } 155 } 156 return EOK; 157 } 158 159 int netif_initialize(void){ 166 160 ipcarg_t phonehash; 167 161 … … 169 163 } 170 164 171 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 172 { 173 netif_device_t *device; 174 int rc; 175 176 /* Create a new device */ 177 rc = create(device_id, &device); 178 if (rc != EOK) 179 return rc; 180 181 /* Print the settings */ 165 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 166 ERROR_DECLARE; 167 168 netif_device_t * device; 169 170 // create a new device 171 ERROR_PROPAGATE(create(device_id, &device)); 172 // print the settings 182 173 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 183 184 return EOK; 185 } 186 187 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender) 188 { 189 netif_device_t * device;174 return EOK; 175 } 176 177 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){ 178 ERROR_DECLARE; 179 180 netif_device_t * device; 190 181 size_t length; 191 packet_t *next;182 packet_t next; 192 183 int phone; 193 int rc; 194 195 rc = find_device(device_id, &device); 196 if (rc != EOK) 197 return EOK; 198 199 if (device->state != NETIF_ACTIVE) { 184 185 ERROR_PROPAGATE(find_device(device_id, &device)); 186 if(device->state != NETIF_ACTIVE){ 200 187 netif_pq_release(packet_get_id(packet)); 201 188 return EFORWARD; 202 189 } 203 204 190 next = packet; 205 do 206 ((device_stats_t *) device->specific)->send_packets++;207 ((device_stats_t *) device->specific)->receive_packets++;191 do{ 192 ++ ((device_stats_ref) device->specific)->send_packets; 193 ++ ((device_stats_ref) device->specific)->receive_packets; 208 194 length = packet_get_data_length(next); 209 ((device_stats_ t *) device->specific)->send_bytes += length;210 ((device_stats_ t *) device->specific)->receive_bytes += length;195 ((device_stats_ref) device->specific)->send_bytes += length; 196 ((device_stats_ref) device->specific)->receive_bytes += length; 211 197 next = pq_next(next); 212 } while(next); 213 198 }while(next); 214 199 phone = device->nil_phone; 215 200 fibril_rwlock_write_unlock(&netif_globals.lock); 216 201 nil_received_msg(phone, device_id, packet, sender); 217 202 fibril_rwlock_write_lock(&netif_globals.lock); 218 219 return EOK; 220 } 221 222 int netif_start_message(netif_device_t *device) 223 { 203 return EOK; 204 } 205 206 int netif_start_message(netif_device_t * device){ 224 207 return change_state_message(device, NETIF_ACTIVE); 225 208 } 226 209 227 int netif_stop_message(netif_device_t *device) 228 { 210 int netif_stop_message(netif_device_t * device){ 229 211 return change_state_message(device, NETIF_STOPPED); 230 212 } … … 232 214 /** Default thread for new connections. 233 215 * 234 * @param[in] iid The initial message identifier. 235 * @param[in] icall The initial message call structure. 216 * @param[in] iid The initial message identifier. 217 * @param[in] icall The initial message call structure. 218 * 236 219 */ 237 220 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) … … 243 226 ipc_answer_0(iid, EOK); 244 227 245 while 228 while(true) { 246 229 ipc_call_t answer; 247 230 int answer_count; … … 258 241 &answer_count); 259 242 260 /* 261 * End if told to either by the message or the processing 262 * result. 263 */ 264 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || 265 (res == EHANGUP)) 243 /* End if said to either by the message or the processing result */ 244 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 266 245 return; 267 246 … … 273 252 int main(int argc, char *argv[]) 274 253 { 275 int rc;254 ERROR_DECLARE; 276 255 277 256 /* Start the module */ 278 rc = netif_module_start(netif_client_connection); 279 return rc; 257 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 258 return ERROR_CODE; 259 260 return EOK; 280 261 } 281 262
Note:
See TracChangeset
for help on using the changeset viewer.