Changes in uspace/lib/net/netif/netif_local.c [995689d1:46d4d9f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/netif/netif_local.c
r995689d1 r46d4d9f 27 27 */ 28 28 29 /** @addtogroup netif29 /** @addtogroup libnet 30 30 * @{ 31 31 */ … … 43 43 #include <ipc/services.h> 44 44 #include <ipc/netif.h> 45 #include <err .h>45 #include <errno.h> 46 46 47 47 #include <generic.h> … … 58 58 DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t); 59 59 60 /** Network interface global data. 61 */ 60 /** Network interface global data. */ 62 61 netif_globals_t netif_globals; 63 62 … … 65 64 * 66 65 * @param[in] netif_phone The network interface phone. 67 * @param[in] device_id 68 * @param[in] irq 69 * @param[in] io 70 * 71 * @return EOK on success.72 * @return Other errro codes as defined for thenetif_probe_message().73 * 74 */ 75 intnetif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)66 * @param[in] device_id The device identifier. 67 * @param[in] irq The device interrupt number. 68 * @param[in] io The device input/output address. 69 * @return EOK on success. 70 * @return Other error codes as defined for the 71 * netif_probe_message(). 72 */ 73 int 74 netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io) 76 75 { 77 76 fibril_rwlock_write_lock(&netif_globals.lock); … … 85 84 * 86 85 * @param[in] netif_phone The network interface phone. 87 * @param[in] device_id The device identifier. 88 * @param[in] packet The packet queue. 89 * @param[in] sender The sending module service. 90 * 91 * @return EOK on success. 92 * @return Other error codes as defined for the generic_send_msg() function. 93 * 86 * @param[in] device_id The device identifier. 87 * @param[in] packet The packet queue. 88 * @param[in] sender The sending module service. 89 * @return EOK on success. 90 * @return Other error codes as defined for the generic_send_msg() 91 * function. 94 92 */ 95 93 int netif_send_msg_local(int netif_phone, device_id_t device_id, 96 packet_t packet, services_t sender)94 packet_t *packet, services_t sender) 97 95 { 98 96 fibril_rwlock_write_lock(&netif_globals.lock); … … 106 104 * 107 105 * @param[in] netif_phone The network interface phone. 108 * @param[in] device_id 109 * 110 * @return EOK on success.111 * @return Other error codes as defined for the find_device()function.112 * @return Other error codes as defined for the netif_start_message() function.113 * 106 * @param[in] device_id The device identifier. 107 * @return EOK on success. 108 * @return Other error codes as defined for the find_device() 109 * function. 110 * @return Other error codes as defined for the 111 * netif_start_message() function. 114 112 */ 115 113 int netif_start_req_local(int netif_phone, device_id_t device_id) 116 114 { 117 ERROR_DECLARE;115 int rc; 118 116 119 117 fibril_rwlock_write_lock(&netif_globals.lock); 120 118 121 119 netif_device_t *device; 122 if (ERROR_OCCURRED(find_device(device_id, &device))) { 120 rc = find_device(device_id, &device); 121 if (rc != EOK) { 123 122 fibril_rwlock_write_unlock(&netif_globals.lock); 124 return ERROR_CODE;123 return rc; 125 124 } 126 125 … … 141 140 * 142 141 * @param[in] netif_phone The network interface phone. 143 * @param[in] device_id 144 * 145 * @return EOK on success.146 * @return Other error codes as defined for the find_device()function.147 * @return Other error codes as defined for the netif_stop_message() function.148 * 142 * @param[in] device_id The device identifier. 143 * @return EOK on success. 144 * @return Other error codes as defined for the find_device() 145 * function. 146 * @return Other error codes as defined for the 147 * netif_stop_message() function. 149 148 */ 150 149 int netif_stop_req_local(int netif_phone, device_id_t device_id) 151 150 { 152 ERROR_DECLARE;151 int rc; 153 152 154 153 fibril_rwlock_write_lock(&netif_globals.lock); 155 154 156 155 netif_device_t *device; 157 if (ERROR_OCCURRED(find_device(device_id, &device))) { 156 rc = find_device(device_id, &device); 157 if (rc != EOK) { 158 158 fibril_rwlock_write_unlock(&netif_globals.lock); 159 return ERROR_CODE;159 return rc; 160 160 } 161 161 … … 175 175 /** Return the device usage statistics. 176 176 * 177 * @param[in] netif_phone The network interface phone. 178 * @param[in] device_id The device identifier. 179 * @param[out] stats The device usage statistics. 180 * 177 * @param[in] netif_phone The network interface phone. 178 * @param[in] device_id The device identifier. 179 * @param[out] stats The device usage statistics. 181 180 * @return EOK on success. 182 *183 181 */ 184 182 int netif_stats_req_local(int netif_phone, device_id_t device_id, 185 device_stats_ refstats)183 device_stats_t *stats) 186 184 { 187 185 fibril_rwlock_read_lock(&netif_globals.lock); … … 194 192 /** Return the device local hardware address. 195 193 * 196 * @param[in] netif_phone The network interface phone. 197 * @param[in] device_id The device identifier. 198 * @param[out] address The device local hardware address. 199 * @param[out] data The address data. 200 * 201 * @return EOK on success. 202 * @return EBADMEM if the address parameter is NULL. 203 * @return ENOENT if there no such device. 204 * @return Other error codes as defined for the netif_get_addr_message() 205 * function. 206 * 194 * @param[in] netif_phone The network interface phone. 195 * @param[in] device_id The device identifier. 196 * @param[out] address The device local hardware address. 197 * @param[out] data The address data. 198 * @return EOK on success. 199 * @return EBADMEM if the address parameter is NULL. 200 * @return ENOENT if there no such device. 201 * @return Other error codes as defined for the 202 * netif_get_addr_message() function. 207 203 */ 208 204 int netif_get_addr_req_local(int netif_phone, device_id_t device_id, 209 measured_string_ ref*address, char **data)210 { 211 ERROR_DECLARE;212 213 if ( (!address) || (!data))205 measured_string_t **address, char **data) 206 { 207 int rc; 208 209 if (!address || !data) 214 210 return EBADMEM; 215 211 … … 217 213 218 214 measured_string_t translation; 219 if (!ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))) { 215 rc = netif_get_addr_message(device_id, &translation); 216 if (rc == EOK) { 220 217 *address = measured_string_copy(&translation); 221 ERROR_CODE= (*address) ? EOK : ENOMEM;218 rc = (*address) ? EOK : ENOMEM; 222 219 } 223 220 … … 226 223 *data = (**address).value; 227 224 228 return ERROR_CODE;225 return rc; 229 226 } 230 227 231 228 /** Find the device specific data. 232 229 * 233 * @param[in] device_id The device identifier. 234 * @param[out] device The device specific data. 235 * 236 * @return EOK on success. 237 * @return ENOENT if device is not found. 238 * @return EPERM if the device is not initialized. 239 * 230 * @param[in] device_id The device identifier. 231 * @param[out] device The device specific data. 232 * @return EOK on success. 233 * @return ENOENT if device is not found. 234 * @return EPERM if the device is not initialized. 240 235 */ 241 236 int find_device(device_id_t device_id, netif_device_t **device) … … 256 251 /** Clear the usage statistics. 257 252 * 258 * @param[in] stats The usage statistics. 259 * 260 */ 261 void null_device_stats(device_stats_ref stats) 253 * @param[in] stats The usage statistics. 254 */ 255 void null_device_stats(device_stats_t *stats) 262 256 { 263 257 bzero(stats, sizeof(device_stats_t)); … … 266 260 /** Initialize the netif module. 267 261 * 268 * @param[in] client_connection The client connection functio to be 269 * registered. 270 * 271 * @return EOK on success. 272 * @return Other error codes as defined for each specific module 273 * message function. 274 * 262 * @param[in] client_connection The client connection functio to be registered. 263 * @return EOK on success. 264 * @return Other error codes as defined for each specific module 265 * message function. 275 266 */ 276 267 int netif_init_module(async_client_conn_t client_connection) 277 268 { 278 ERROR_DECLARE;269 int rc; 279 270 280 271 async_set_client_connection(client_connection); … … 283 274 netif_device_map_initialize(&netif_globals.device_map); 284 275 285 ERROR_PROPAGATE(pm_init()); 276 rc = pm_init(); 277 if (rc != EOK) 278 return rc; 286 279 287 280 fibril_rwlock_initialize(&netif_globals.lock); 288 if (ERROR_OCCURRED(netif_initialize())) { 281 282 rc = netif_initialize(); 283 if (rc != EOK) { 289 284 pm_destroy(); 290 return ERROR_CODE;285 return rc; 291 286 } 292 287 … … 298 293 * Prepared for future optimization. 299 294 * 300 * @param[in] packet_id The packet identifier. 301 * 295 * @param[in] packet_id The packet identifier. 302 296 */ 303 297 void netif_pq_release(packet_id_t packet_id) … … 308 302 /** Allocate new packet to handle the given content size. 309 303 * 310 * @param[in] content The minimum content size. 311 * 312 * @return The allocated packet. 313 * @return NULL if there is an error. 314 * 315 */ 316 packet_t netif_packet_get_1(size_t content) 304 * @param[in] content The minimum content size. 305 * @return The allocated packet. 306 * @return NULL if there is an error. 307 * 308 */ 309 packet_t *netif_packet_get_1(size_t content) 317 310 { 318 311 return packet_get_1_remote(netif_globals.net_phone, content); 319 312 } 320 313 321 /** Register the device notification receiver, the network interface layer module. 322 * 323 * @param[in] name Module name. 324 * @param[in] device_id The device identifier. 325 * @param[in] phone The network interface layer module phone. 326 * 327 * @return EOK on success. 328 * @return ENOENT if there is no such device. 329 * @return ELIMIT if there is another module registered. 330 * 314 /** Register the device notification receiver, the network interface layer 315 * module. 316 * 317 * @param[in] name Module name. 318 * @param[in] device_id The device identifier. 319 * @param[in] phone The network interface layer module phone. 320 * @return EOK on success. 321 * @return ENOENT if there is no such device. 322 * @return ELIMIT if there is another module registered. 331 323 */ 332 324 static int register_message(const char *name, device_id_t device_id, int phone) 333 325 { 334 ERROR_DECLARE;335 336 326 netif_device_t *device; 337 ERROR_PROPAGATE(find_device(device_id, &device)); 338 if(device->nil_phone > 0) 327 int rc; 328 329 rc = find_device(device_id, &device); 330 if (rc != EOK) 331 return rc; 332 333 if (device->nil_phone > 0) 339 334 return ELIMIT; 340 335 … … 347 342 /** Process the netif module messages. 348 343 * 349 * @param[in] nameModule name.350 * @param[in] callidThe message identifier.351 * @param[in] callThe message parameters.352 * @param[out] answer 353 * @param[out] answer_count The last parameter for the actual answer 354 * in theanswer parameter.355 * 356 * @return EOK on success.357 * @return ENOTSUP if the message is not known.358 * @return Other error codes as defined for each specific modulemessage function.344 * @param[in] name Module name. 345 * @param[in] callid The message identifier. 346 * @param[in] call The message parameters. 347 * @param[out] answer The message answer parameters. 348 * @param[out] answer_count The last parameter for the actual answer in the 349 * answer parameter. 350 * @return EOK on success. 351 * @return ENOTSUP if the message is not known. 352 * @return Other error codes as defined for each specific module 353 * message function. 359 354 * 360 355 * @see IS_NET_NETIF_MESSAGE() … … 364 359 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 365 360 { 366 ERROR_DECLARE;367 368 361 size_t length; 369 362 device_stats_t stats; 370 packet_t packet;363 packet_t *packet; 371 364 measured_string_t address; 365 int rc; 372 366 373 367 *answer_count = 0; 374 368 switch (IPC_GET_METHOD(*call)) { 375 376 377 case NET_NETIF_PROBE:378 return netif_probe_req_local(0, IPC_GET_DEVICE(call),379 NETIF_GET_IRQ(call), NETIF_GET_IO(call));380 case IPC_M_CONNECT_TO_ME:381 fibril_rwlock_write_lock(&netif_globals.lock);382 ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),383 IPC_GET_PHONE(call));384 fibril_rwlock_write_unlock(&netif_globals.lock);385 return ERROR_CODE;386 case NET_NETIF_SEND:387 ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,388 &packet, IPC_GET_PACKET(call)));389 return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,390 IPC_GET_SENDER(call));391 case NET_NETIF_START:392 return netif_start_req_local(0, IPC_GET_DEVICE(call));393 case NET_NETIF_STATS:394 fibril_rwlock_read_lock(&netif_globals.lock);395 if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {396 if (length < sizeof(device_stats_t))397 ERROR_CODE = EOVERFLOW;398 else {399 if (!ERROR_OCCURRED(netif_get_device_stats(400 IPC_GET_DEVICE(call), &stats)))401 ERROR_CODE = async_data_read_finalize(callid, &stats,402 sizeof(device_stats_t)); 403 }404 }369 case IPC_M_PHONE_HUNGUP: 370 return EOK; 371 372 case NET_NETIF_PROBE: 373 return netif_probe_req_local(0, IPC_GET_DEVICE(call), 374 NETIF_GET_IRQ(call), NETIF_GET_IO(call)); 375 376 case IPC_M_CONNECT_TO_ME: 377 fibril_rwlock_write_lock(&netif_globals.lock); 378 rc = register_message(name, IPC_GET_DEVICE(call), 379 IPC_GET_PHONE(call)); 380 fibril_rwlock_write_unlock(&netif_globals.lock); 381 return rc; 382 383 case NET_NETIF_SEND: 384 rc = packet_translate_remote(netif_globals.net_phone, &packet, 385 IPC_GET_PACKET(call)); 386 if (rc != EOK) 387 return rc; 388 return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet, 389 IPC_GET_SENDER(call)); 390 391 case NET_NETIF_START: 392 return netif_start_req_local(0, IPC_GET_DEVICE(call)); 393 394 case NET_NETIF_STATS: 395 fibril_rwlock_read_lock(&netif_globals.lock); 396 397 rc = async_data_read_receive(&callid, &length); 398 if (rc != EOK) { 405 399 fibril_rwlock_read_unlock(&netif_globals.lock); 406 return ERROR_CODE; 407 case NET_NETIF_STOP: 408 return netif_stop_req_local(0, IPC_GET_DEVICE(call)); 409 case NET_NETIF_GET_ADDR: 410 fibril_rwlock_read_lock(&netif_globals.lock); 411 if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), 412 &address))) 413 ERROR_CODE = measured_strings_reply(&address, 1); 400 return rc; 401 } 402 if (length < sizeof(device_stats_t)) { 414 403 fibril_rwlock_read_unlock(&netif_globals.lock); 415 return ERROR_CODE; 404 return EOVERFLOW; 405 } 406 407 rc = netif_get_device_stats(IPC_GET_DEVICE(call), &stats); 408 if (rc == EOK) { 409 rc = async_data_read_finalize(callid, &stats, 410 sizeof(device_stats_t)); 411 } 412 413 fibril_rwlock_read_unlock(&netif_globals.lock); 414 return rc; 415 416 case NET_NETIF_STOP: 417 return netif_stop_req_local(0, IPC_GET_DEVICE(call)); 418 419 case NET_NETIF_GET_ADDR: 420 fibril_rwlock_read_lock(&netif_globals.lock); 421 rc = netif_get_addr_message(IPC_GET_DEVICE(call), &address); 422 if (rc == EOK) 423 rc = measured_strings_reply(&address, 1); 424 fibril_rwlock_read_unlock(&netif_globals.lock); 425 return rc; 416 426 } 417 427 … … 421 431 /** Start the network interface module. 422 432 * 423 * Initialize the client connection serving function, initialize 424 * the module, registers the module service and start the async 425 * manager, processing IPC messages in an infinite loop. 426 * 427 * @param[in] client_connection The client connection processing 428 * function. The module skeleton propagates 429 * its own one. 430 * 431 * @return EOK on success. 432 * @return Other error codes as defined for each specific module message 433 * function. 434 * 433 * Initialize the client connection serving function, initialize the module, 434 * registers the module service and start the async manager, processing IPC 435 * messages in an infinite loop. 436 * 437 * @param[in] client_connection The client connection processing function. 438 * The module skeleton propagates its own one. 439 * @return EOK on success. 440 * @return Other error codes as defined for each specific module 441 * message function. 435 442 */ 436 443 int netif_module_start_standalone(async_client_conn_t client_connection) 437 444 { 438 ERROR_DECLARE; 439 440 ERROR_PROPAGATE(netif_init_module(client_connection)); 445 int rc; 446 447 rc = netif_init_module(client_connection); 448 if (rc != EOK) 449 return rc; 441 450 442 451 async_manager();
Note:
See TracChangeset
for help on using the changeset viewer.