Changes in uspace/srv/net/nil/nildummy/nildummy.c [ffa2c8ef:228e490] in mainline
- File:
-
- 1 edited
-
uspace/srv/net/nil/nildummy/nildummy.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
rffa2c8ef r228e490 41 41 #include <stdio.h> 42 42 #include <str.h> 43 #include <ipc/ nil.h>43 #include <ipc/ipc.h> 44 44 #include <ipc/net.h> 45 45 #include <ipc/services.h> … … 47 47 #include <net/modules.h> 48 48 #include <net/device.h> 49 #include <il_remote.h> 49 #include <netif_interface.h> 50 #include <nil_interface.h> 51 #include <il_interface.h> 50 52 #include <adt/measured_strings.h> 51 53 #include <net/packet.h> 52 54 #include <packet_remote.h> 53 #include <netif_remote.h> 54 #include <nil_skel.h> 55 #include <nil_local.h> 55 56 56 57 #include "nildummy.h" … … 80 81 int nil_initialize(int net_phone) 81 82 { 83 int rc; 84 82 85 fibril_rwlock_initialize(&nildummy_globals.devices_lock); 83 86 fibril_rwlock_initialize(&nildummy_globals.protos_lock); … … 87 90 nildummy_globals.net_phone = net_phone; 88 91 nildummy_globals.proto.phone = 0; 89 intrc = nildummy_devices_initialize(&nildummy_globals.devices);92 rc = nildummy_devices_initialize(&nildummy_globals.devices); 90 93 91 94 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 95 98 } 96 99 97 /** Process IPC messages from the registered device driver modules 98 * 99 * @param[in] iid Message identifier.100 * @param[in ,out] icall Message parameters.101 * 100 /** Process IPC messages from the registered device driver modules in an 101 * infinite loop. 102 * 103 * @param[in] iid The message identifier. 104 * @param[in,out] icall The message parameters. 102 105 */ 103 106 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) … … 105 108 packet_t *packet; 106 109 int rc; 107 110 108 111 while (true) { 109 112 switch (IPC_GET_IMETHOD(*icall)) { 110 113 case NET_NIL_DEVICE_STATE: 111 114 rc = nil_device_state_msg_local(0, 112 IPC_GET_DEVICE( *icall), IPC_GET_STATE(*icall));113 async_answer_0(iid, (sysarg_t) rc);115 IPC_GET_DEVICE(icall), IPC_GET_STATE(icall)); 116 ipc_answer_0(iid, (sysarg_t) rc); 114 117 break; 115 118 116 119 case NET_NIL_RECEIVED: 117 120 rc = packet_translate_remote(nildummy_globals.net_phone, 118 &packet, IPC_GET_PACKET( *icall));119 if (rc == EOK) 121 &packet, IPC_GET_PACKET(icall)); 122 if (rc == EOK) { 120 123 rc = nil_received_msg_local(0, 121 IPC_GET_DEVICE( *icall), packet, 0);122 123 async_answer_0(iid, (sysarg_t) rc);124 IPC_GET_DEVICE(icall), packet, 0); 125 } 126 ipc_answer_0(iid, (sysarg_t) rc); 124 127 break; 125 128 126 129 default: 127 async_answer_0(iid, (sysarg_t) ENOTSUP);130 ipc_answer_0(iid, (sysarg_t) ENOTSUP); 128 131 } 129 132 … … 136 139 * Determine the device local hardware address. 137 140 * 138 * @param[in] device_id New device identifier. 139 * @param[in] service Device driver service. 140 * @param[in] mtu Device maximum transmission unit. 141 * 142 * @return EOK on success. 143 * @return EEXIST if the device with the different service exists. 144 * @return ENOMEM if there is not enough memory left. 145 * @return Other error codes as defined for the 146 * netif_bind_service() function. 147 * @return Other error codes as defined for the 148 * netif_get_addr_req() function. 149 * 141 * @param[in] device_id The new device identifier. 142 * @param[in] service The device driver service. 143 * @param[in] mtu The device maximum transmission unit. 144 * @return EOK on success. 145 * @return EEXIST if the device with the different service exists. 146 * @return ENOMEM if there is not enough memory left. 147 * @return Other error codes as defined for the 148 * netif_bind_service() function. 149 * @return Other error codes as defined for the 150 * netif_get_addr_req() function. 150 151 */ 151 152 static int nildummy_device_message(device_id_t device_id, services_t service, 152 153 size_t mtu) 153 154 { 155 nildummy_device_t *device; 156 int index; 157 int rc; 158 154 159 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 155 160 156 161 /* An existing device? */ 157 nildummy_device_t *device = 158 nildummy_devices_find(&nildummy_globals.devices, device_id); 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 159 163 if (device) { 160 164 if (device->service != service) { … … 209 213 210 214 /* Get hardware address */ 211 int rc = netif_get_addr_req(device->phone, device->device_id,212 &device->addr , &device->addr_data);215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 216 &device->addr_data); 213 217 if (rc != EOK) { 214 218 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 218 222 219 223 /* Add to the cache */ 220 in t index = nildummy_devices_add(&nildummy_globals.devices,224 index = nildummy_devices_add(&nildummy_globals.devices, 221 225 device->device_id, device); 222 226 if (index < 0) { … … 236 240 /** Return the device hardware address. 237 241 * 238 * @param[in] device_id Device identifier. 239 * @param[out] address Device hardware address. 240 * 241 * @return EOK on success. 242 * @return EBADMEM if the address parameter is NULL. 243 * @return ENOENT if there no such device. 242 * @param[in] device_id The device identifier. 243 * @param[out] address The device hardware address. 244 * @return EOK on success. 245 * @return EBADMEM if the address parameter is NULL. 246 * @return ENOENT if there no such device. 244 247 * 245 248 */ … … 247 250 measured_string_t **address) 248 251 { 252 nildummy_device_t *device; 253 249 254 if (!address) 250 255 return EBADMEM; 251 256 252 257 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 253 254 nildummy_device_t *device = 255 nildummy_devices_find(&nildummy_globals.devices, device_id); 258 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 256 259 if (!device) { 257 260 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 258 261 return ENOENT; 259 262 } 260 261 263 *address = device->addr; 262 263 264 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 264 265 … … 268 269 /** Return the device packet dimensions for sending. 269 270 * 270 * @param[in] device_id Device identifier. 271 * @param[out] addr_len Minimum reserved address length. 272 * @param[out] prefix Minimum reserved prefix size. 273 * @param[out] content Maximum content size. 274 * @param[out] suffix Minimum reserved suffix size. 275 * 276 * @return EOK on success. 277 * @return EBADMEM if either one of the parameters is NULL. 278 * @return ENOENT if there is no such device. 271 * @param[in] device_id The device identifier. 272 * @param[out] addr_len The minimum reserved address length. 273 * @param[out] prefix The minimum reserved prefix size. 274 * @param[out] content The maximum content size. 275 * @param[out] suffix The minimum reserved suffix size. 276 * @return EOK on success. 277 * @return EBADMEM if either one of the parameters is NULL. 278 * @return ENOENT if there is no such device. 279 279 * 280 280 */ … … 282 282 size_t *prefix, size_t *content, size_t *suffix) 283 283 { 284 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) 284 nildummy_device_t *device; 285 286 if (!addr_len || !prefix || !content || !suffix) 285 287 return EBADMEM; 286 288 287 289 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 288 289 nildummy_device_t *device = 290 nildummy_devices_find(&nildummy_globals.devices, device_id); 290 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 291 291 if (!device) { 292 292 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 293 293 return ENOENT; 294 294 } 295 295 296 296 *content = device->mtu; 297 298 297 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 299 298 … … 307 306 packet_t *packet, services_t target) 308 307 { 308 packet_t *next; 309 309 310 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 310 311 311 if (nildummy_globals.proto.phone) { 312 312 do { 313 packet_t *next = pq_detach(packet);313 next = pq_detach(packet); 314 314 il_received_msg(nildummy_globals.proto.phone, device_id, 315 315 packet, nildummy_globals.proto.service); 316 316 packet = next; 317 } while (packet); 318 } 319 317 } while(packet); 318 } 320 319 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 321 320 … … 327 326 * Pass received packets for this service. 328 327 * 329 * @param[in] service Module service. 330 * @param[in] phone Service phone. 331 * 332 * @return EOK on success. 333 * @return ENOENT if the service is not known. 334 * @return ENOMEM if there is not enough memory left. 335 * 328 * @param[in] service The module service. 329 * @param[in] phone The service phone. 330 * @return EOK on success. 331 * @return ENOENT if the service is not known. 332 * @return ENOMEM if there is not enough memory left. 336 333 */ 337 334 static int nildummy_register_message(services_t service, int phone) … … 350 347 /** Send the packet queue. 351 348 * 352 * @param[in] device_id Device identifier. 353 * @param[in] packet Packet queue. 354 * @param[in] sender Sending module service. 355 * 356 * @return EOK on success. 357 * @return ENOENT if there no such device. 358 * @return EINVAL if the service parameter is not known. 359 * 349 * @param[in] device_id The device identifier. 350 * @param[in] packet The packet queue. 351 * @param[in] sender The sending module service. 352 * @return EOK on success. 353 * @return ENOENT if there no such device. 354 * @return EINVAL if the service parameter is not known. 360 355 */ 361 356 static int nildummy_send_message(device_id_t device_id, packet_t *packet, 362 357 services_t sender) 363 358 { 359 nildummy_device_t *device; 360 364 361 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 365 366 nildummy_device_t *device = 367 nildummy_devices_find(&nildummy_globals.devices, device_id); 362 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 368 363 if (!device) { 369 364 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 370 365 return ENOENT; 371 366 } 372 367 373 368 /* Send packet queue */ 374 369 if (packet) 375 370 netif_send_msg(device->phone, device_id, packet, 376 371 SERVICE_NILDUMMY); 377 378 372 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 379 380 return EOK; 381 } 382 383 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 384 ipc_call_t *answer, size_t *answer_count) 373 return EOK; 374 } 375 376 int nil_message_standalone(const char *name, ipc_callid_t callid, 377 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 385 378 { 386 379 measured_string_t *address; … … 398 391 399 392 case NET_NIL_DEVICE: 400 return nildummy_device_message(IPC_GET_DEVICE( *call),401 IPC_GET_SERVICE( *call), IPC_GET_MTU(*call));393 return nildummy_device_message(IPC_GET_DEVICE(call), 394 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 402 395 403 396 case NET_NIL_SEND: 404 397 rc = packet_translate_remote(nildummy_globals.net_phone, 405 &packet, IPC_GET_PACKET( *call));398 &packet, IPC_GET_PACKET(call)); 406 399 if (rc != EOK) 407 400 return rc; 408 return nildummy_send_message(IPC_GET_DEVICE( *call), packet,409 IPC_GET_SERVICE( *call));401 return nildummy_send_message(IPC_GET_DEVICE(call), packet, 402 IPC_GET_SERVICE(call)); 410 403 411 404 case NET_NIL_PACKET_SPACE: 412 rc = nildummy_packet_space_message(IPC_GET_DEVICE( *call),405 rc = nildummy_packet_space_message(IPC_GET_DEVICE(call), 413 406 &addrlen, &prefix, &content, &suffix); 414 407 if (rc != EOK) 415 408 return rc; 416 IPC_SET_ADDR( *answer, addrlen);417 IPC_SET_PREFIX( *answer, prefix);418 IPC_SET_CONTENT( *answer, content);419 IPC_SET_SUFFIX( *answer, suffix);409 IPC_SET_ADDR(answer, addrlen); 410 IPC_SET_PREFIX(answer, prefix); 411 IPC_SET_CONTENT(answer, content); 412 IPC_SET_SUFFIX(answer, suffix); 420 413 *answer_count = 4; 421 414 return EOK; 422 415 423 416 case NET_NIL_ADDR: 424 rc = nildummy_addr_message(IPC_GET_DEVICE( *call), &address);417 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address); 425 418 if (rc != EOK) 426 419 return rc; … … 428 421 429 422 case NET_NIL_BROADCAST_ADDR: 430 rc = nildummy_addr_message(IPC_GET_DEVICE( *call), &address);423 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address); 431 424 if (rc != EOK) 432 425 return rc; … … 434 427 435 428 case IPC_M_CONNECT_TO_ME: 436 return nildummy_register_message(NIL_GET_PROTO( *call),437 IPC_GET_PHONE( *call));429 return nildummy_register_message(NIL_GET_PROTO(call), 430 IPC_GET_PHONE(call)); 438 431 } 439 432 … … 441 434 } 442 435 436 /** Default thread for new connections. 437 * 438 * @param[in] iid The initial message identifier. 439 * @param[in] icall The initial message call structure. 440 */ 441 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall) 442 { 443 /* 444 * Accept the connection 445 * - Answer the first IPC_M_CONNECT_ME_TO call. 446 */ 447 ipc_answer_0(iid, EOK); 448 449 while (true) { 450 ipc_call_t answer; 451 int answer_count; 452 453 /* Clear the answer structure */ 454 refresh_answer(&answer, &answer_count); 455 456 /* Fetch the next message */ 457 ipc_call_t call; 458 ipc_callid_t callid = async_get_call(&call); 459 460 /* Process the message */ 461 int res = nil_module_message_standalone(NAME, callid, &call, 462 &answer, &answer_count); 463 464 /* 465 * End if told to either by the message or the processing 466 * result. 467 */ 468 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 469 (res == EHANGUP)) 470 return; 471 472 /* Answer the message */ 473 answer_call(callid, res, &answer, answer_count); 474 } 475 } 476 443 477 int main(int argc, char *argv[]) 444 478 { 479 int rc; 480 445 481 /* Start the module */ 446 return nil_module_start(SERVICE_NILDUMMY); 482 rc = nil_module_start_standalone(nil_client_connection); 483 return rc; 447 484 } 448 485
Note:
See TracChangeset
for help on using the changeset viewer.
