Changes in uspace/srv/net/nil/nildummy/nildummy.c [6d8455d:9cd8165] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r6d8455d r9cd8165 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda 4 5 * All rights reserved. 5 6 * … … 53 54 #include <packet_remote.h> 54 55 #include <packet_client.h> 55 #include <devman.h>56 56 #include <device/nic.h> 57 #include <loc.h> 57 58 #include <nil_skel.h> 58 59 #include "nildummy.h" … … 69 70 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 70 71 71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 72 static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, 73 void *arg); 74 75 static int nildummy_device_state(nildummy_device_t *device, sysarg_t state) 72 76 { 73 77 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 74 78 if (nildummy_globals.proto.sess) 75 il_device_state_msg(nildummy_globals.proto.sess, device_id,76 state, nildummy_globals.proto.service);79 il_device_state_msg(nildummy_globals.proto.sess, 80 device->device_id, state, nildummy_globals.proto.service); 77 81 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 78 82 79 83 return EOK; 84 } 85 86 static int nildummy_addr_changed(nildummy_device_t *device) 87 { 88 return ENOTSUP; 80 89 } 81 90 … … 115 124 */ 116 125 static int nildummy_device_message(nic_device_id_t device_id, 117 devman_handle_t handle, size_t mtu)126 service_id_t sid, size_t mtu) 118 127 { 119 128 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 123 132 nildummy_devices_find(&nildummy_globals.devices, device_id); 124 133 if (device) { 125 if (device-> handle != handle) {134 if (device->sid != sid) { 126 135 printf("Device %d exists, handles do not match\n", 127 136 device->device_id); … … 158 167 159 168 device->device_id = device_id; 160 device-> handle = handle;169 device->sid = sid; 161 170 if (mtu > 0) 162 171 device->mtu = mtu; … … 165 174 166 175 /* Bind the device driver */ 167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,176 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 168 177 IPC_FLAG_BLOCKING); 169 178 if (device->sess == NULL) { … … 173 182 } 174 183 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 184 int rc = nic_callback_create(device->sess, nildummy_nic_cb_conn, 185 device); 186 if (rc != EOK) { 187 async_hangup(device->sess); 188 189 return ENOENT; 190 } 176 191 177 192 /* Get hardware address */ 178 intrc = nic_get_address(device->sess, &device->addr);193 rc = nic_get_address(device->sess, &device->addr); 179 194 if (rc != EOK) { 180 195 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 345 360 services_t sender) 346 361 { 347 packet_t *p;348 349 362 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 350 363 … … 356 369 } 357 370 358 p = packet;371 packet_t *p = packet; 359 372 do { 360 373 nic_send_frame(device->sess, packet_get_data(p), … … 368 381 369 382 return EOK; 383 } 384 385 static int nildummy_received(nildummy_device_t *device) 386 { 387 void *data; 388 size_t size; 389 int rc; 390 391 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); 392 if (rc != EOK) 393 return rc; 394 395 packet_t *packet = packet_get_1_remote(nildummy_globals.net_sess, size); 396 if (packet == NULL) 397 return ENOMEM; 398 399 void *pdata = packet_suffix(packet, size); 400 memcpy(pdata, data, size); 401 free(pdata); 402 403 return nil_received_msg_local(device->device_id, packet); 370 404 } 371 405 … … 424 458 *answer_count = 1; 425 459 return rc; 426 case NET_NIL_DEVICE_STATE:427 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),428 IPC_GET_STATE(*call));429 async_answer_0(callid, (sysarg_t) rc);430 return rc;431 432 case NET_NIL_RECEIVED:433 rc = packet_translate_remote(nildummy_globals.net_sess, &packet,434 IPC_GET_ARG2(*call));435 if (rc == EOK)436 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);437 438 async_answer_0(callid, (sysarg_t) rc);439 return rc;440 460 } 441 461 442 462 return ENOTSUP; 443 463 } 464 465 static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 466 { 467 nildummy_device_t *device = (nildummy_device_t *)arg; 468 int rc; 469 470 async_answer_0(iid, EOK); 471 472 while (true) { 473 ipc_call_t call; 474 ipc_callid_t callid = async_get_call(&call); 475 476 if (!IPC_GET_IMETHOD(call)) 477 break; 478 479 switch (IPC_GET_IMETHOD(call)) { 480 case NIC_EV_DEVICE_STATE: 481 rc = nildummy_device_state(device, IPC_GET_ARG1(call)); 482 async_answer_0(callid, (sysarg_t) rc); 483 break; 484 case NIC_EV_RECEIVED: 485 rc = nildummy_received(device); 486 async_answer_0(callid, (sysarg_t) rc); 487 break; 488 case NIC_EV_ADDR_CHANGED: 489 rc = nildummy_addr_changed(device); 490 async_answer_0(callid, (sysarg_t) rc); 491 break; 492 default: 493 async_answer_0(callid, ENOTSUP); 494 } 495 } 496 } 497 444 498 445 499 int main(int argc, char *argv[])
Note:
See TracChangeset
for help on using the changeset viewer.