Changes in uspace/srv/net/nil/nildummy/nildummy.c [6b82009:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r6b82009 rffa2c8ef 44 44 #include <ipc/net.h> 45 45 #include <ipc/services.h> 46 46 47 #include <net/modules.h> 47 48 #include <net/device.h> … … 52 53 #include <netif_remote.h> 53 54 #include <nil_skel.h> 55 54 56 #include "nildummy.h" 55 57 … … 65 67 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 66 68 67 int nil_device_state_msg_local( device_id_t device_id, sysarg_t state)69 int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state) 68 70 { 69 71 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 70 if (nildummy_globals.proto. sess)71 il_device_state_msg(nildummy_globals.proto. sess, device_id,72 if (nildummy_globals.proto.phone) 73 il_device_state_msg(nildummy_globals.proto.phone, device_id, 72 74 state, nildummy_globals.proto.service); 73 75 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); … … 76 78 } 77 79 78 int nil_initialize( async_sess_t *sess)80 int nil_initialize(int net_phone) 79 81 { 80 82 fibril_rwlock_initialize(&nildummy_globals.devices_lock); … … 83 85 fibril_rwlock_write_lock(&nildummy_globals.protos_lock); 84 86 85 nildummy_globals.net_ sess = sess;86 nildummy_globals.proto. sess = NULL;87 nildummy_globals.net_phone = net_phone; 88 nildummy_globals.proto.phone = 0; 87 89 int rc = nildummy_devices_initialize(&nildummy_globals.devices); 88 90 … … 97 99 * @param[in] iid Message identifier. 98 100 * @param[in,out] icall Message parameters. 99 * @param[in] arg Local argument. 100 * 101 */ 102 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 101 * 102 */ 103 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) 103 104 { 104 105 packet_t *packet; … … 108 109 switch (IPC_GET_IMETHOD(*icall)) { 109 110 case NET_NIL_DEVICE_STATE: 110 rc = nil_device_state_msg_local( IPC_GET_DEVICE(*icall),111 IPC_GET_ STATE(*icall));111 rc = nil_device_state_msg_local(0, 112 IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall)); 112 113 async_answer_0(iid, (sysarg_t) rc); 113 114 break; 114 115 115 116 case NET_NIL_RECEIVED: 116 rc = packet_translate_remote(nildummy_globals.net_ sess,117 rc = packet_translate_remote(nildummy_globals.net_phone, 117 118 &packet, IPC_GET_PACKET(*icall)); 118 119 if (rc == EOK) 119 rc = nil_received_msg_local( IPC_GET_DEVICE(*icall),120 packet, 0);120 rc = nil_received_msg_local(0, 121 IPC_GET_DEVICE(*icall), packet, 0); 121 122 122 123 async_answer_0(iid, (sysarg_t) rc); … … 176 177 /* Notify the upper layer module */ 177 178 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 178 if (nildummy_globals.proto. sess) {179 il_mtu_changed_msg(nildummy_globals.proto. sess,179 if (nildummy_globals.proto.phone) { 180 il_mtu_changed_msg(nildummy_globals.proto.phone, 180 181 device->device_id, device->mtu, 181 182 nildummy_globals.proto.service); … … 199 200 200 201 /* Bind the device driver */ 201 device-> sess= netif_bind_service(device->service, device->device_id,202 device->phone = netif_bind_service(device->service, device->device_id, 202 203 SERVICE_ETHERNET, nildummy_receiver); 203 if (device-> sess == NULL) {204 if (device->phone < 0) { 204 205 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 205 206 free(device); 206 return ENOENT;207 return device->phone; 207 208 } 208 209 209 210 /* Get hardware address */ 210 int rc = netif_get_addr_req(device-> sess, device->device_id,211 int rc = netif_get_addr_req(device->phone, device->device_id, 211 212 &device->addr, &device->addr_data); 212 213 if (rc != EOK) { … … 303 304 } 304 305 305 int nil_received_msg_local( device_id_t device_id, packet_t *packet,306 services_t target)306 int nil_received_msg_local(int nil_phone, device_id_t device_id, 307 packet_t *packet, services_t target) 307 308 { 308 309 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 309 310 310 if (nildummy_globals.proto. sess) {311 if (nildummy_globals.proto.phone) { 311 312 do { 312 313 packet_t *next = pq_detach(packet); 313 il_received_msg(nildummy_globals.proto. sess, device_id,314 il_received_msg(nildummy_globals.proto.phone, device_id, 314 315 packet, nildummy_globals.proto.service); 315 316 packet = next; … … 327 328 * 328 329 * @param[in] service Module service. 329 * @param[in] sess Service session.330 * @param[in] phone Service phone. 330 331 * 331 332 * @return EOK on success. … … 334 335 * 335 336 */ 336 static int nildummy_register_message(services_t service, async_sess_t *sess)337 static int nildummy_register_message(services_t service, int phone) 337 338 { 338 339 fibril_rwlock_write_lock(&nildummy_globals.protos_lock); 339 340 nildummy_globals.proto.service = service; 340 nildummy_globals.proto. sess = sess;341 342 printf("%s: Protocol registered (service: %d )\n",343 NAME, nildummy_globals.proto.service );341 nildummy_globals.proto.phone = phone; 342 343 printf("%s: Protocol registered (service: %d, phone: %d)\n", 344 NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone); 344 345 345 346 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 372 373 /* Send packet queue */ 373 374 if (packet) 374 netif_send_msg(device-> sess, device_id, packet,375 netif_send_msg(device->phone, device_id, packet, 375 376 SERVICE_NILDUMMY); 376 377 … … 392 393 393 394 *answer_count = 0; 394 395 if (!IPC_GET_IMETHOD(*call))395 switch (IPC_GET_IMETHOD(*call)) { 396 case IPC_M_PHONE_HUNGUP: 396 397 return EOK; 397 398 398 async_sess_t *callback =399 async_callback_receive_start(EXCHANGE_SERIALIZE, call);400 if (callback)401 return nildummy_register_message(NIL_GET_PROTO(*call), callback);402 403 switch (IPC_GET_IMETHOD(*call)) {404 399 case NET_NIL_DEVICE: 405 400 return nildummy_device_message(IPC_GET_DEVICE(*call), … … 407 402 408 403 case NET_NIL_SEND: 409 rc = packet_translate_remote(nildummy_globals.net_ sess,404 rc = packet_translate_remote(nildummy_globals.net_phone, 410 405 &packet, IPC_GET_PACKET(*call)); 411 406 if (rc != EOK) … … 437 432 return rc; 438 433 return measured_strings_reply(address, 1); 434 435 case IPC_M_CONNECT_TO_ME: 436 return nildummy_register_message(NIL_GET_PROTO(*call), 437 IPC_GET_PHONE(*call)); 439 438 } 440 439
Note:
See TracChangeset
for help on using the changeset viewer.