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