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