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