Changeset eb522e8 in mainline for uspace/srv/net/nil/nildummy/nildummy.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r9e2e715 reb522e8 41 41 #include <stdio.h> 42 42 #include <str.h> 43 #include <ipc/ ipc.h>43 #include <ipc/nil.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 <netif_interface.h> 50 #include <nil_interface.h> 51 #include <il_interface.h> 49 #include <il_remote.h> 52 50 #include <adt/measured_strings.h> 53 51 #include <net/packet.h> 54 52 #include <packet_remote.h> 55 #include <nil_local.h> 53 #include <netif_remote.h> 54 #include <nil_skel.h> 56 55 57 56 #include "nildummy.h" … … 81 80 int nil_initialize(int net_phone) 82 81 { 83 int rc;84 85 82 fibril_rwlock_initialize(&nildummy_globals.devices_lock); 86 83 fibril_rwlock_initialize(&nildummy_globals.protos_lock); … … 90 87 nildummy_globals.net_phone = net_phone; 91 88 nildummy_globals.proto.phone = 0; 92 rc = nildummy_devices_initialize(&nildummy_globals.devices);89 int rc = nildummy_devices_initialize(&nildummy_globals.devices); 93 90 94 91 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 98 95 } 99 96 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.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 * 105 102 */ 106 103 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) 107 104 { 108 packet_t packet;105 packet_t *packet; 109 106 int rc; 110 107 111 108 while (true) { 112 switch (IPC_GET_ METHOD(*icall)) {109 switch (IPC_GET_IMETHOD(*icall)) { 113 110 case NET_NIL_DEVICE_STATE: 114 111 rc = nil_device_state_msg_local(0, 115 IPC_GET_DEVICE( icall), IPC_GET_STATE(icall));116 ipc_answer_0(iid, (ipcarg_t) rc);112 IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall)); 113 async_answer_0(iid, (sysarg_t) rc); 117 114 break; 118 115 119 116 case NET_NIL_RECEIVED: 120 117 rc = packet_translate_remote(nildummy_globals.net_phone, 121 &packet, IPC_GET_PACKET( icall));122 if (rc == EOK) {118 &packet, IPC_GET_PACKET(*icall)); 119 if (rc == EOK) 123 120 rc = nil_received_msg_local(0, 124 IPC_GET_DEVICE( icall), packet, 0);125 }126 ipc_answer_0(iid, (ipcarg_t) rc);121 IPC_GET_DEVICE(*icall), packet, 0); 122 123 async_answer_0(iid, (sysarg_t) rc); 127 124 break; 128 125 129 126 default: 130 ipc_answer_0(iid, (ipcarg_t) ENOTSUP);127 async_answer_0(iid, (sysarg_t) ENOTSUP); 131 128 } 132 129 … … 139 136 * Determine the device local hardware address. 140 137 * 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 * @returns EOK on success. 145 * @returns EEXIST if the device with the different service exists. 146 * @returns ENOMEM if there is not enough memory left. 147 * @returns Other error codes as defined for the 148 * netif_bind_service() function. 149 * @returns Other error codes as defined for the 150 * netif_get_addr_req() function. 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 * 151 150 */ 152 151 static int nildummy_device_message(device_id_t device_id, services_t service, 153 152 size_t mtu) 154 153 { 155 nildummy_device_ref device;156 int index;157 int rc;158 159 154 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 160 155 161 156 /* An existing device? */ 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 157 nildummy_device_t *device = 158 nildummy_devices_find(&nildummy_globals.devices, device_id); 163 159 if (device) { 164 160 if (device->service != service) { … … 175 171 device->mtu = NET_DEFAULT_MTU; 176 172 177 printf("Device %d already exists:\tMTU\t= % d\n",173 printf("Device %d already exists:\tMTU\t= %zu\n", 178 174 device->device_id, device->mtu); 179 175 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 192 188 193 189 /* Create a new device */ 194 device = (nildummy_device_ ref) malloc(sizeof(nildummy_device_t));190 device = (nildummy_device_t *) malloc(sizeof(nildummy_device_t)); 195 191 if (!device) 196 192 return ENOMEM; … … 213 209 214 210 /* Get hardware address */ 215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,216 &device->addr _data);211 int rc = netif_get_addr_req(device->phone, device->device_id, 212 &device->addr, &device->addr_data); 217 213 if (rc != EOK) { 218 214 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 222 218 223 219 /* Add to the cache */ 224 in dex = nildummy_devices_add(&nildummy_globals.devices,220 int index = nildummy_devices_add(&nildummy_globals.devices, 225 221 device->device_id, device); 226 222 if (index < 0) { … … 232 228 } 233 229 234 printf("%s: Device registered (id: %d, service: %d, mtu: % d)\n",230 printf("%s: Device registered (id: %d, service: %d, mtu: %zu)\n", 235 231 NAME, device->device_id, device->service, device->mtu); 236 232 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 240 236 /** Return the device hardware address. 241 237 * 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. 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. 247 244 * 248 245 */ 249 246 static int nildummy_addr_message(device_id_t device_id, 250 measured_string_ref *address) 251 { 252 nildummy_device_ref device; 253 247 measured_string_t **address) 248 { 254 249 if (!address) 255 250 return EBADMEM; 256 251 257 252 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 258 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 253 254 nildummy_device_t *device = 255 nildummy_devices_find(&nildummy_globals.devices, device_id); 259 256 if (!device) { 260 257 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 261 258 return ENOENT; 262 259 } 260 263 261 *address = device->addr; 262 264 263 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 265 264 … … 269 268 /** Return the device packet dimensions for sending. 270 269 * 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. 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. 279 279 * 280 280 */ … … 282 282 size_t *prefix, size_t *content, size_t *suffix) 283 283 { 284 nildummy_device_ref device; 285 286 if (!addr_len || !prefix || !content || !suffix) 284 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) 287 285 return EBADMEM; 288 286 289 287 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 290 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 288 289 nildummy_device_t *device = 290 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 297 298 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 298 299 … … 304 305 305 306 int nil_received_msg_local(int nil_phone, device_id_t device_id, 306 packet_t packet, services_t target) 307 { 308 packet_t next; 309 307 packet_t *packet, services_t target) 308 { 310 309 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 310 311 311 if (nildummy_globals.proto.phone) { 312 312 do { 313 next = pq_detach(packet);313 packet_t *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 } 317 } while (packet); 318 } 319 319 320 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 320 321 … … 326 327 * Pass received packets for this service. 327 328 * 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. 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 * 333 336 */ 334 337 static int nildummy_register_message(services_t service, int phone) … … 347 350 /** Send the packet queue. 348 351 * 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. 355 */ 356 static int nildummy_send_message(device_id_t device_id, packet_t packet, 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 * 360 */ 361 static int nildummy_send_message(device_id_t device_id, packet_t *packet, 357 362 services_t sender) 358 363 { 359 nildummy_device_ref device;360 361 364 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 362 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 365 366 nildummy_device_t *device = 367 nildummy_devices_find(&nildummy_globals.devices, device_id); 363 368 if (!device) { 364 369 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 365 370 return ENOENT; 366 371 } 367 372 368 373 /* Send packet queue */ 369 374 if (packet) 370 375 netif_send_msg(device->phone, device_id, packet, 371 376 SERVICE_NILDUMMY); 377 372 378 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, int *answer_count) 378 { 379 measured_string_ref address; 380 packet_t packet; 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) 385 { 386 measured_string_t *address; 387 packet_t *packet; 381 388 size_t addrlen; 382 389 size_t prefix; … … 386 393 387 394 *answer_count = 0; 388 switch (IPC_GET_ METHOD(*call)) {395 switch (IPC_GET_IMETHOD(*call)) { 389 396 case IPC_M_PHONE_HUNGUP: 390 397 return EOK; 391 398 392 399 case NET_NIL_DEVICE: 393 return nildummy_device_message(IPC_GET_DEVICE( call),394 IPC_GET_SERVICE( call), IPC_GET_MTU(call));400 return nildummy_device_message(IPC_GET_DEVICE(*call), 401 IPC_GET_SERVICE(*call), IPC_GET_MTU(*call)); 395 402 396 403 case NET_NIL_SEND: 397 404 rc = packet_translate_remote(nildummy_globals.net_phone, 398 &packet, IPC_GET_PACKET( call));405 &packet, IPC_GET_PACKET(*call)); 399 406 if (rc != EOK) 400 407 return rc; 401 return nildummy_send_message(IPC_GET_DEVICE( call), packet,402 IPC_GET_SERVICE( call));408 return nildummy_send_message(IPC_GET_DEVICE(*call), packet, 409 IPC_GET_SERVICE(*call)); 403 410 404 411 case NET_NIL_PACKET_SPACE: 405 rc = nildummy_packet_space_message(IPC_GET_DEVICE( call),412 rc = nildummy_packet_space_message(IPC_GET_DEVICE(*call), 406 413 &addrlen, &prefix, &content, &suffix); 407 414 if (rc != EOK) 408 415 return rc; 409 IPC_SET_ADDR( answer, addrlen);410 IPC_SET_PREFIX( answer, prefix);411 IPC_SET_CONTENT( answer, content);412 IPC_SET_SUFFIX( answer, suffix);416 IPC_SET_ADDR(*answer, addrlen); 417 IPC_SET_PREFIX(*answer, prefix); 418 IPC_SET_CONTENT(*answer, content); 419 IPC_SET_SUFFIX(*answer, suffix); 413 420 *answer_count = 4; 414 421 return EOK; 415 422 416 423 case NET_NIL_ADDR: 417 rc = nildummy_addr_message(IPC_GET_DEVICE( call), &address);424 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 418 425 if (rc != EOK) 419 426 return rc; … … 421 428 422 429 case NET_NIL_BROADCAST_ADDR: 423 rc = nildummy_addr_message(IPC_GET_DEVICE( call), &address);430 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 424 431 if (rc != EOK) 425 432 return rc; … … 427 434 428 435 case IPC_M_CONNECT_TO_ME: 429 return nildummy_register_message(NIL_GET_PROTO( call),430 IPC_GET_PHONE( call));436 return nildummy_register_message(NIL_GET_PROTO(*call), 437 IPC_GET_PHONE(*call)); 431 438 } 432 439 … … 434 441 } 435 442 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 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 processing466 * result.467 */468 if ((IPC_GET_METHOD(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 477 443 int main(int argc, char *argv[]) 478 444 { 479 int rc;480 481 445 /* Start the module */ 482 rc = nil_module_start_standalone(nil_client_connection); 483 return rc; 446 return nil_module_start(SERVICE_NILDUMMY); 484 447 } 485 448
Note:
See TracChangeset
for help on using the changeset viewer.