Changes in uspace/srv/net/nil/nildummy/nildummy.c [774e6d1a:797b704] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r774e6d1a r797b704 42 42 #include <str.h> 43 43 #include <ipc/ipc.h> 44 #include <ipc/nil.h> 44 45 #include <ipc/net.h> 45 46 #include <ipc/services.h> … … 47 48 #include <net/modules.h> 48 49 #include <net/device.h> 49 #include <nil_interface.h> 50 #include <il_interface.h> 50 #include <il_remote.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_ local.h>55 #include <nil_skel.h> 56 56 57 57 #include "nildummy.h" … … 81 81 int nil_initialize(int net_phone) 82 82 { 83 int rc;84 85 83 fibril_rwlock_initialize(&nildummy_globals.devices_lock); 86 84 fibril_rwlock_initialize(&nildummy_globals.protos_lock); … … 90 88 nildummy_globals.net_phone = net_phone; 91 89 nildummy_globals.proto.phone = 0; 92 rc = nildummy_devices_initialize(&nildummy_globals.devices);90 int rc = nildummy_devices_initialize(&nildummy_globals.devices); 93 91 94 92 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 98 96 } 99 97 100 /** Process IPC messages from the registered device driver modules in an101 * infinite loop.102 * 103 * @param[in ] iid The message identifier.104 * @param[in,out] icall The message parameters.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 * 105 103 */ 106 104 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) … … 108 106 packet_t *packet; 109 107 int rc; 110 108 111 109 while (true) { 112 110 switch (IPC_GET_IMETHOD(*icall)) { … … 120 118 rc = packet_translate_remote(nildummy_globals.net_phone, 121 119 &packet, IPC_GET_PACKET(*icall)); 122 if (rc == EOK) {120 if (rc == EOK) 123 121 rc = nil_received_msg_local(0, 124 122 IPC_GET_DEVICE(*icall), packet, 0); 125 }123 126 124 ipc_answer_0(iid, (sysarg_t) rc); 127 125 break; … … 139 137 * Determine the device local hardware address. 140 138 * 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. 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 * 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 159 155 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 160 156 161 157 /* An existing device? */ 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 158 nildummy_device_t *device = 159 nildummy_devices_find(&nildummy_globals.devices, device_id); 163 160 if (device) { 164 161 if (device->service != service) { … … 213 210 214 211 /* Get hardware address */ 215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,216 &device->addr _data);212 int rc = netif_get_addr_req(device->phone, device->device_id, 213 &device->addr, &device->addr_data); 217 214 if (rc != EOK) { 218 215 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 222 219 223 220 /* Add to the cache */ 224 in dex = nildummy_devices_add(&nildummy_globals.devices,221 int index = nildummy_devices_add(&nildummy_globals.devices, 225 222 device->device_id, device); 226 223 if (index < 0) { … … 240 237 /** Return the device hardware address. 241 238 * 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. 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. 247 245 * 248 246 */ … … 250 248 measured_string_t **address) 251 249 { 252 nildummy_device_t *device;253 254 250 if (!address) 255 251 return EBADMEM; 256 252 257 253 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 258 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 254 255 nildummy_device_t *device = 256 nildummy_devices_find(&nildummy_globals.devices, device_id); 259 257 if (!device) { 260 258 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 261 259 return ENOENT; 262 260 } 261 263 262 *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 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. 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. 279 280 * 280 281 */ … … 282 283 size_t *prefix, size_t *content, size_t *suffix) 283 284 { 284 nildummy_device_t *device; 285 286 if (!addr_len || !prefix || !content || !suffix) 285 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) 287 286 return EBADMEM; 288 287 289 288 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 290 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 289 290 nildummy_device_t *device = 291 nildummy_devices_find(&nildummy_globals.devices, device_id); 291 292 if (!device) { 292 293 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 293 294 return ENOENT; 294 295 } 295 296 296 297 *content = device->mtu; 298 297 299 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 298 300 … … 306 308 packet_t *packet, services_t target) 307 309 { 308 packet_t *next;309 310 310 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 311 311 312 if (nildummy_globals.proto.phone) { 312 313 do { 313 next = pq_detach(packet);314 packet_t *next = pq_detach(packet); 314 315 il_received_msg(nildummy_globals.proto.phone, device_id, 315 316 packet, nildummy_globals.proto.service); 316 317 packet = next; 317 } while(packet); 318 } 318 } while (packet); 319 } 320 319 321 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 320 322 … … 326 328 * Pass received packets for this service. 327 329 * 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. 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 * 333 337 */ 334 338 static int nildummy_register_message(services_t service, int phone) … … 347 351 /** Send the packet queue. 348 352 * 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. 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 * 355 361 */ 356 362 static int nildummy_send_message(device_id_t device_id, packet_t *packet, 357 363 services_t sender) 358 364 { 359 nildummy_device_t *device;360 361 365 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 362 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 366 367 nildummy_device_t *device = 368 nildummy_devices_find(&nildummy_globals.devices, device_id); 363 369 if (!device) { 364 370 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 365 371 return ENOENT; 366 372 } 367 373 368 374 /* Send packet queue */ 369 375 if (packet) 370 376 netif_send_msg(device->phone, device_id, packet, 371 377 SERVICE_NILDUMMY); 378 372 379 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 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) 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) 378 386 { 379 387 measured_string_t *address; … … 434 442 } 435 443 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 connection445 * - 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 processing466 * 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 477 444 int main(int argc, char *argv[]) 478 445 { 479 int rc;480 481 446 /* Start the module */ 482 rc = nil_module_start_standalone(nil_client_connection); 483 return rc; 447 return nil_module_start(SERVICE_NILDUMMY); 484 448 } 485 449
Note:
See TracChangeset
for help on using the changeset viewer.