Changes in uspace/srv/net/nil/nildummy/nildummy.c [9cd8165:6d8455d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r9cd8165 r6d8455d 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * Copyright (c) 2011 Radim Vansa 4 * Copyright (c) 2011 Jiri Svoboda5 4 * All rights reserved. 6 5 * … … 54 53 #include <packet_remote.h> 55 54 #include <packet_client.h> 55 #include <devman.h> 56 56 #include <device/nic.h> 57 #include <loc.h>58 57 #include <nil_skel.h> 59 58 #include "nildummy.h" … … 70 69 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 71 70 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) 71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 76 72 { 77 73 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 78 74 if (nildummy_globals.proto.sess) 79 il_device_state_msg(nildummy_globals.proto.sess, 80 device->device_id,state, nildummy_globals.proto.service);75 il_device_state_msg(nildummy_globals.proto.sess, device_id, 76 state, nildummy_globals.proto.service); 81 77 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 82 78 83 79 return EOK; 84 }85 86 static int nildummy_addr_changed(nildummy_device_t *device)87 {88 return ENOTSUP;89 80 } 90 81 … … 124 115 */ 125 116 static int nildummy_device_message(nic_device_id_t device_id, 126 service_id_t sid, size_t mtu)117 devman_handle_t handle, size_t mtu) 127 118 { 128 119 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 132 123 nildummy_devices_find(&nildummy_globals.devices, device_id); 133 124 if (device) { 134 if (device-> sid != sid) {125 if (device->handle != handle) { 135 126 printf("Device %d exists, handles do not match\n", 136 127 device->device_id); … … 167 158 168 159 device->device_id = device_id; 169 device-> sid = sid;160 device->handle = handle; 170 161 if (mtu > 0) 171 162 device->mtu = mtu; … … 174 165 175 166 /* Bind the device driver */ 176 device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid,167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 177 168 IPC_FLAG_BLOCKING); 178 169 if (device->sess == NULL) { … … 182 173 } 183 174 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 } 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 191 176 192 177 /* Get hardware address */ 193 rc = nic_get_address(device->sess, &device->addr);178 int rc = nic_get_address(device->sess, &device->addr); 194 179 if (rc != EOK) { 195 180 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 360 345 services_t sender) 361 346 { 347 packet_t *p; 348 362 349 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 363 350 … … 369 356 } 370 357 371 p acket_t *p= packet;358 p = packet; 372 359 do { 373 360 nic_send_frame(device->sess, packet_get_data(p), … … 381 368 382 369 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);404 370 } 405 371 … … 458 424 *answer_count = 1; 459 425 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; 460 440 } 461 441 462 442 return ENOTSUP; 463 443 } 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 498 444 499 445 int main(int argc, char *argv[])
Note:
See TracChangeset
for help on using the changeset viewer.