Changes in uspace/srv/net/nil/nildummy/nildummy.c [797b704:774e6d1a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r797b704 r774e6d1a 42 42 #include <str.h> 43 43 #include <ipc/ipc.h> 44 #include <ipc/nil.h>45 44 #include <ipc/net.h> 46 45 #include <ipc/services.h> … … 48 47 #include <net/modules.h> 49 48 #include <net/device.h> 50 #include <il_remote.h> 49 #include <nil_interface.h> 50 #include <il_interface.h> 51 51 #include <adt/measured_strings.h> 52 52 #include <net/packet.h> 53 53 #include <packet_remote.h> 54 54 #include <netif_remote.h> 55 #include <nil_ skel.h>55 #include <nil_local.h> 56 56 57 57 #include "nildummy.h" … … 81 81 int nil_initialize(int net_phone) 82 82 { 83 int rc; 84 83 85 fibril_rwlock_initialize(&nildummy_globals.devices_lock); 84 86 fibril_rwlock_initialize(&nildummy_globals.protos_lock); … … 88 90 nildummy_globals.net_phone = net_phone; 89 91 nildummy_globals.proto.phone = 0; 90 intrc = nildummy_devices_initialize(&nildummy_globals.devices);92 rc = nildummy_devices_initialize(&nildummy_globals.devices); 91 93 92 94 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 96 98 } 97 99 98 /** Process IPC messages from the registered device driver modules 99 * 100 * @param[in] iid Message identifier.101 * @param[in ,out] icall Message parameters.102 * 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. 103 105 */ 104 106 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) … … 106 108 packet_t *packet; 107 109 int rc; 108 110 109 111 while (true) { 110 112 switch (IPC_GET_IMETHOD(*icall)) { … … 118 120 rc = packet_translate_remote(nildummy_globals.net_phone, 119 121 &packet, IPC_GET_PACKET(*icall)); 120 if (rc == EOK) 122 if (rc == EOK) { 121 123 rc = nil_received_msg_local(0, 122 124 IPC_GET_DEVICE(*icall), packet, 0); 123 125 } 124 126 ipc_answer_0(iid, (sysarg_t) rc); 125 127 break; … … 137 139 * Determine the device local hardware address. 138 140 * 139 * @param[in] device_id New device identifier. 140 * @param[in] service Device driver service. 141 * @param[in] mtu Device maximum transmission unit. 142 * 143 * @return EOK on success. 144 * @return EEXIST if the device with the different service exists. 145 * @return ENOMEM if there is not enough memory left. 146 * @return Other error codes as defined for the 147 * netif_bind_service() function. 148 * @return Other error codes as defined for the 149 * netif_get_addr_req() function. 150 * 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. 151 151 */ 152 152 static int nildummy_device_message(device_id_t device_id, services_t service, 153 153 size_t mtu) 154 154 { 155 nildummy_device_t *device; 156 int index; 157 int rc; 158 155 159 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 156 160 157 161 /* An existing device? */ 158 nildummy_device_t *device = 159 nildummy_devices_find(&nildummy_globals.devices, device_id); 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 160 163 if (device) { 161 164 if (device->service != service) { … … 210 213 211 214 /* Get hardware address */ 212 int rc = netif_get_addr_req(device->phone, device->device_id,213 &device->addr , &device->addr_data);215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 216 &device->addr_data); 214 217 if (rc != EOK) { 215 218 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 219 222 220 223 /* Add to the cache */ 221 in t index = nildummy_devices_add(&nildummy_globals.devices,224 index = nildummy_devices_add(&nildummy_globals.devices, 222 225 device->device_id, device); 223 226 if (index < 0) { … … 237 240 /** Return the device hardware address. 238 241 * 239 * @param[in] device_id Device identifier. 240 * @param[out] address Device hardware address. 241 * 242 * @return EOK on success. 243 * @return EBADMEM if the address parameter is NULL. 244 * @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. 245 247 * 246 248 */ … … 248 250 measured_string_t **address) 249 251 { 252 nildummy_device_t *device; 253 250 254 if (!address) 251 255 return EBADMEM; 252 256 253 257 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 254 255 nildummy_device_t *device = 256 nildummy_devices_find(&nildummy_globals.devices, device_id); 258 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 257 259 if (!device) { 258 260 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 259 261 return ENOENT; 260 262 } 261 262 263 *address = device->addr; 263 264 264 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 265 265 … … 269 269 /** Return the device packet dimensions for sending. 270 270 * 271 * @param[in] device_id Device identifier. 272 * @param[out] addr_len Minimum reserved address length. 273 * @param[out] prefix Minimum reserved prefix size. 274 * @param[out] content Maximum content size. 275 * @param[out] suffix Minimum reserved suffix size. 276 * 277 * @return EOK on success. 278 * @return EBADMEM if either one of the parameters is NULL. 279 * @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. 280 279 * 281 280 */ … … 283 282 size_t *prefix, size_t *content, size_t *suffix) 284 283 { 285 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) 284 nildummy_device_t *device; 285 286 if (!addr_len || !prefix || !content || !suffix) 286 287 return EBADMEM; 287 288 288 289 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 289 290 nildummy_device_t *device = 291 nildummy_devices_find(&nildummy_globals.devices, device_id); 290 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 292 291 if (!device) { 293 292 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 294 293 return ENOENT; 295 294 } 296 295 297 296 *content = device->mtu; 298 299 297 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 300 298 … … 308 306 packet_t *packet, services_t target) 309 307 { 308 packet_t *next; 309 310 310 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 311 312 311 if (nildummy_globals.proto.phone) { 313 312 do { 314 packet_t *next = pq_detach(packet);313 next = pq_detach(packet); 315 314 il_received_msg(nildummy_globals.proto.phone, device_id, 316 315 packet, nildummy_globals.proto.service); 317 316 packet = next; 318 } while (packet); 319 } 320 317 } while(packet); 318 } 321 319 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 322 320 … … 328 326 * Pass received packets for this service. 329 327 * 330 * @param[in] service Module service. 331 * @param[in] phone Service phone. 332 * 333 * @return EOK on success. 334 * @return ENOENT if the service is not known. 335 * @return ENOMEM if there is not enough memory left. 336 * 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. 337 333 */ 338 334 static int nildummy_register_message(services_t service, int phone) … … 351 347 /** Send the packet queue. 352 348 * 353 * @param[in] device_id Device identifier. 354 * @param[in] packet Packet queue. 355 * @param[in] sender Sending module service. 356 * 357 * @return EOK on success. 358 * @return ENOENT if there no such device. 359 * @return EINVAL if the service parameter is not known. 360 * 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. 361 355 */ 362 356 static int nildummy_send_message(device_id_t device_id, packet_t *packet, 363 357 services_t sender) 364 358 { 359 nildummy_device_t *device; 360 365 361 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 366 367 nildummy_device_t *device = 368 nildummy_devices_find(&nildummy_globals.devices, device_id); 362 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 369 363 if (!device) { 370 364 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 371 365 return ENOENT; 372 366 } 373 367 374 368 /* Send packet queue */ 375 369 if (packet) 376 370 netif_send_msg(device->phone, device_id, packet, 377 371 SERVICE_NILDUMMY); 378 379 372 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 380 381 return EOK; 382 } 383 384 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 385 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, size_t *answer_count) 386 378 { 387 379 measured_string_t *address; … … 442 434 } 443 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 size_t count; 452 453 /* Clear the answer structure */ 454 refresh_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, &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, count); 474 } 475 } 476 444 477 int main(int argc, char *argv[]) 445 478 { 479 int rc; 480 446 481 /* Start the module */ 447 return nil_module_start(SERVICE_NILDUMMY); 482 rc = nil_module_start_standalone(nil_client_connection); 483 return rc; 448 484 } 449 485
Note:
See TracChangeset
for help on using the changeset viewer.