Changes in uspace/srv/net/nil/nildummy/nildummy.c [6b82009:49bd793b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/nildummy/nildummy.c
r6b82009 r49bd793b 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 36 37 */ 37 38 39 #include <assert.h> 38 40 #include <async.h> 39 41 #include <malloc.h> … … 50 52 #include <net/packet.h> 51 53 #include <packet_remote.h> 52 #include <netif_remote.h> 54 #include <packet_client.h> 55 #include <devman.h> 56 #include <device/nic.h> 53 57 #include <nil_skel.h> 54 58 #include "nildummy.h" … … 65 69 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 66 70 67 int nil_device_state_msg_local( device_id_t device_id, sysarg_t state)71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 68 72 { 69 73 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 91 95 92 96 return rc; 93 }94 95 /** Process IPC messages from the registered device driver modules96 *97 * @param[in] iid Message identifier.98 * @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)103 {104 packet_t *packet;105 int rc;106 107 while (true) {108 switch (IPC_GET_IMETHOD(*icall)) {109 case NET_NIL_DEVICE_STATE:110 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),111 IPC_GET_STATE(*icall));112 async_answer_0(iid, (sysarg_t) rc);113 break;114 115 case NET_NIL_RECEIVED:116 rc = packet_translate_remote(nildummy_globals.net_sess,117 &packet, IPC_GET_PACKET(*icall));118 if (rc == EOK)119 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),120 packet, 0);121 122 async_answer_0(iid, (sysarg_t) rc);123 break;124 125 default:126 async_answer_0(iid, (sysarg_t) ENOTSUP);127 }128 129 iid = async_get_call(icall);130 }131 97 } 132 98 … … 148 114 * 149 115 */ 150 static int nildummy_device_message( device_id_t device_id, services_t service,151 size_t mtu)116 static int nildummy_device_message(nic_device_id_t device_id, 117 devman_handle_t handle, size_t mtu) 152 118 { 153 119 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 157 123 nildummy_devices_find(&nildummy_globals.devices, device_id); 158 124 if (device) { 159 if (device-> service != service) {160 printf("Device %d already exists\n", device->device_id);161 fibril_rwlock_write_unlock(162 125 if (device->handle != handle) { 126 printf("Device %d exists, handles do not match\n", 127 device->device_id); 128 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 163 129 return EEXIST; 164 130 } … … 170 136 device->mtu = NET_DEFAULT_MTU; 171 137 172 printf("Device %d already exists :\tMTU\t= %zu\n",173 device-> device_id, device->mtu);138 printf("Device %d already exists (mtu: %zu)\n", device->device_id, 139 device->mtu); 174 140 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 175 141 … … 192 158 193 159 device->device_id = device_id; 194 device-> service = service;160 device->handle = handle; 195 161 if (mtu > 0) 196 162 device->mtu = mtu; 197 163 else 198 164 device->mtu = NET_DEFAULT_MTU; 199 165 200 166 /* Bind the device driver */ 201 device->sess = netif_bind_service(device->service, device->device_id,202 SERVICE_ETHERNET, nildummy_receiver);167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 168 IPC_FLAG_BLOCKING); 203 169 if (device->sess == NULL) { 204 170 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 207 173 } 208 174 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 176 209 177 /* Get hardware address */ 210 int rc = netif_get_addr_req(device->sess, device->device_id, 211 &device->addr, &device->addr_data); 178 int rc = nic_get_address(device->sess, &device->addr); 212 179 if (rc != EOK) { 213 180 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 215 182 return rc; 216 183 } 184 185 device->addr_len = ETH_ADDR; 217 186 218 187 /* Add to the cache */ … … 221 190 if (index < 0) { 222 191 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 223 free(device->addr);224 free(device->addr_data);225 192 free(device); 226 193 return index; 227 194 } 228 195 229 printf("%s: Device registered (id: %d, service: %d, mtu: %zu)\n",230 NAME, device->device_id, device->service, device->mtu);196 printf("%s: Device registered (id: %d, mtu: %zu)\n", NAME, 197 device->device_id, device->mtu); 231 198 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 232 199 return EOK; … … 243 210 * 244 211 */ 245 static int nildummy_addr_message(device_id_t device_id, 246 measured_string_t **address) 247 { 248 if (!address) 212 static int nildummy_addr_message(nic_device_id_t device_id, size_t *addrlen) 213 { 214 if (!addrlen) 249 215 return EBADMEM; 250 216 … … 258 224 } 259 225 260 *address = device->addr; 226 ipc_callid_t callid; 227 size_t max_len; 228 if (!async_data_read_receive(&callid, &max_len)) { 229 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 230 return EREFUSED; 231 } 232 233 if (max_len < device->addr_len) { 234 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 235 async_data_read_finalize(callid, NULL, 0); 236 return ELIMIT; 237 } 238 239 int rc = async_data_read_finalize(callid, 240 (uint8_t *) &device->addr.address, device->addr_len); 241 if (rc != EOK) { 242 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 243 return rc; 244 } 245 246 *addrlen = device->addr_len; 261 247 262 248 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 263 264 return (*address) ? EOK : ENOENT; 249 return EOK; 265 250 } 266 251 … … 278 263 * 279 264 */ 280 static int nildummy_packet_space_message( device_id_t device_id, size_t *addr_len,281 size_t * prefix, size_t *content, size_t *suffix)265 static int nildummy_packet_space_message(nic_device_id_t device_id, 266 size_t *addr_len, size_t *prefix, size_t *content, size_t *suffix) 282 267 { 283 268 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) … … 303 288 } 304 289 305 int nil_received_msg_local(device_id_t device_id, packet_t *packet, 306 services_t target) 290 int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet) 307 291 { 308 292 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 340 324 nildummy_globals.proto.sess = sess; 341 325 342 printf("%s: Protocol registered (service: % d)\n",326 printf("%s: Protocol registered (service: %#x)\n", 343 327 NAME, nildummy_globals.proto.service); 344 328 … … 358 342 * 359 343 */ 360 static int nildummy_send_message( device_id_t device_id, packet_t *packet,344 static int nildummy_send_message(nic_device_id_t device_id, packet_t *packet, 361 345 services_t sender) 362 346 { … … 372 356 /* Send packet queue */ 373 357 if (packet) 374 netif_send_msg(device->sess, device_id, packet, 375 SERVICE_NILDUMMY); 358 nic_send_message(device->sess, packet_get_id(packet)); 376 359 377 360 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); … … 383 366 ipc_call_t *answer, size_t *answer_count) 384 367 { 385 measured_string_t *address;386 368 packet_t *packet; 387 369 size_t addrlen; … … 404 386 case NET_NIL_DEVICE: 405 387 return nildummy_device_message(IPC_GET_DEVICE(*call), 406 IPC_GET_ SERVICE(*call), IPC_GET_MTU(*call));388 IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call)); 407 389 408 390 case NET_NIL_SEND: … … 427 409 428 410 case NET_NIL_ADDR: 429 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 411 case NET_NIL_BROADCAST_ADDR: 412 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &addrlen); 430 413 if (rc != EOK) 431 414 return rc; 432 return measured_strings_reply(address, 1); 433 434 case NET_NIL_BROADCAST_ADDR: 435 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 436 if (rc != EOK) 437 return rc; 438 return measured_strings_reply(address, 1); 415 416 IPC_SET_ADDR(*answer, addrlen); 417 *answer_count = 1; 418 return rc; 419 case NET_NIL_DEVICE_STATE: 420 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call), 421 IPC_GET_STATE(*call)); 422 async_answer_0(callid, (sysarg_t) rc); 423 return rc; 424 425 case NET_NIL_RECEIVED: 426 rc = packet_translate_remote(nildummy_globals.net_sess, &packet, 427 IPC_GET_ARG2(*call)); 428 if (rc == EOK) 429 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet); 430 431 async_answer_0(callid, (sysarg_t) rc); 432 return rc; 439 433 } 440 434
Note:
See TracChangeset
for help on using the changeset viewer.