Changeset 00d7e1b in mainline
- Timestamp:
- 2011-10-07T20:20:33Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 49bd793b
- Parents:
- e2c50e1
- Files:
-
- 17 added
- 1 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
re2c50e1 r00d7e1b 122 122 test/test1 \ 123 123 test/test2 \ 124 test/test3 124 test/test3 \ 125 nic/lo 125 126 126 127 RD_DRV_CFG = -
uspace/Makefile
re2c50e1 r00d7e1b 117 117 drv/bus/usb/usbmid \ 118 118 drv/bus/usb/usbmouse \ 119 drv/bus/usb/vhc 119 drv/bus/usb/vhc \ 120 drv/nic/lo 120 121 121 122 ifeq ($(CONFIG_PCC),y) … … 181 182 lib/fb \ 182 183 lib/net \ 184 lib/nic \ 183 185 lib/ext2 \ 184 186 lib/usb \ -
uspace/Makefile.common
re2c50e1 r00d7e1b 124 124 LIBDRV_PREFIX = $(LIB_PREFIX)/drv 125 125 LIBNET_PREFIX = $(LIB_PREFIX)/net 126 LIBNIC_PREFIX = $(LIB_PREFIX)/nic 126 127 LIBMINIX_PREFIX = $(LIB_PREFIX)/minix 127 128 -
uspace/app/init/init.c
re2c50e1 r00d7e1b 306 306 srv_start("/srv/s3c24ts"); 307 307 308 spawn("/srv/net"); 309 308 310 spawn("/srv/fb"); 309 311 spawn("/srv/input"); -
uspace/doc/doxygroups.h
re2c50e1 r00d7e1b 33 33 34 34 /** 35 * @defgroup n etif Network interface drivers36 * @ingroup net 37 */ 38 39 /** 40 * @defgroup l o Loopback Service41 * @ingroup n etif42 */ 43 44 /** 45 * @defgroup n e2000 NE2000 network interface service46 * @ingroup n etif35 * @defgroup nic Network interface controllers 36 * @ingroup net 37 */ 38 39 /** 40 * @defgroup libnic Base NIC framework library 41 * @ingroup nic 42 */ 43 44 /** 45 * @defgroup nic_drivers Drivers using the NICF 46 * @ingroup nic 47 47 */ 48 48 -
uspace/drv/infrastructure/rootvirt/devices.def
re2c50e1 r00d7e1b 4 4 * Unless the list is empty, the last item shall be followed by a comma. 5 5 */ 6 7 /* Loopback network interface */ 8 { 9 .name = "lo", 10 .match_id = "virtual&loopback" 11 }, 12 6 13 #ifdef CONFIG_TEST_DRIVERS 14 7 15 { 8 16 .name = "test1", … … 25 33 .match_id = "virtual&test3" 26 34 }, 35 27 36 #endif 37 28 38 #ifdef CONFIG_RUN_VIRTUAL_USB_HC 39 29 40 /* Virtual USB host controller. */ 30 41 { … … 32 43 .match_id = "usb&hc=vhc" 33 44 }, 45 34 46 #endif -
uspace/lib/c/Makefile
re2c50e1 r00d7e1b 67 67 generic/devman.c \ 68 68 generic/device/hw_res.c \ 69 generic/device/hw_res_parsed.c \ 69 70 generic/device/char_dev.c \ 70 71 generic/device/nic.c \ … … 104 105 generic/adt/list.c \ 105 106 generic/adt/hash_table.c \ 107 generic/adt/hash_set.c \ 106 108 generic/adt/dynamic_fifo.c \ 107 109 generic/adt/measured_strings.c \ -
uspace/lib/c/generic/device/nic.c
re2c50e1 r00d7e1b 137 137 138 138 async_exch_t *exch = async_exchange_begin(dev_sess); 139 140 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_GET_ADDRESS);141 i f (rc != EOK) {142 143 return rc;144 }145 146 rc = async_data_read_start(exch, address, sizeof(nic_address_t));147 148 async_exchange_end(exch);149 150 return rc;139 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 140 NIC_GET_ADDRESS, NULL); 141 int rc = async_data_read_start(exch, address, sizeof(nic_address_t)); 142 async_exchange_end(exch); 143 144 sysarg_t res; 145 async_wait_for(aid, &res); 146 147 if (rc != EOK) 148 return rc; 149 150 return (int) res; 151 151 } 152 152 … … 164 164 165 165 async_exch_t *exch = async_exchange_begin(dev_sess); 166 aid_t message_id = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),166 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 167 167 NIC_SET_ADDRESS, NULL); 168 168 int rc = async_data_write_start(exch, address, sizeof(nic_address_t)); … … 170 170 171 171 sysarg_t res; 172 async_wait_for( message_id, &res);172 async_wait_for(aid, &res); 173 173 174 174 if (rc != EOK) -
uspace/lib/c/include/net/device.h
re2c50e1 r00d7e1b 41 41 #include <adt/int_map.h> 42 42 #include <net/eth_phys.h> 43 #include <bool.h> 43 44 44 45 /** Ethernet address length. */ … … 51 52 #define ARGSMAC(__a) \ 52 53 (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5] 54 55 /* Compare MAC address with specific value */ 56 #define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \ 57 ((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \ 58 && (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5)) 59 60 #define MAC_IS_ZERO(__x) \ 61 MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0) 53 62 54 63 /** Device identifier to generic type map declaration. */ … … 221 230 } nic_device_stats_t; 222 231 232 /** Errors corresponding to those in the nic_device_stats_t */ 233 typedef enum { 234 NIC_SEC_BUFFER_FULL, 235 NIC_SEC_ABORTED, 236 NIC_SEC_CARRIER_LOST, 237 NIC_SEC_FIFO_OVERRUN, 238 NIC_SEC_HEARTBEAT, 239 NIC_SEC_WINDOW_ERROR, 240 /* Error encountered during TX but with other type of error */ 241 NIC_SEC_OTHER 242 } nic_send_error_cause_t; 243 244 /** Errors corresponding to those in the nic_device_stats_t */ 245 typedef enum { 246 NIC_REC_BUFFER_FULL, 247 NIC_REC_LENGTH, 248 NIC_REC_BUFFER_OVERFLOW, 249 NIC_REC_CRC, 250 NIC_REC_FRAME_ALIGNMENT, 251 NIC_REC_FIFO_OVERRUN, 252 NIC_REC_MISSED, 253 /* Error encountered during RX but with other type of error */ 254 NIC_REC_OTHER 255 } nic_receive_error_cause_t; 256 223 257 /** 224 258 * Information about the NIC that never changes - name, vendor, model, … … 246 280 247 281 /** 282 * Type of the ethernet frame 283 */ 284 typedef enum nic_frame_type { 285 NIC_FRAME_UNICAST, 286 NIC_FRAME_MULTICAST, 287 NIC_FRAME_BROADCAST 288 } nic_frame_type_t; 289 290 /** 248 291 * Specifies which unicast frames is the NIC receiving. 249 292 */ … … 292 335 293 336 /** 337 * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET. 338 */ 339 typedef struct nic_wv_magic_packet_data { 340 uint8_t password[6]; 341 } nic_wv_magic_packet_data_t; 342 343 /** 344 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4 345 */ 346 typedef struct nic_wv_ipv4_data { 347 uint8_t address[4]; 348 } nic_wv_ipv4_data_t; 349 350 /** 351 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6 352 */ 353 typedef struct nic_wv_ipv6_data { 354 uint8_t address[16]; 355 } nic_wv_ipv6_data_t; 356 357 /** 294 358 * WOL virtue types defining the interpretation of data passed to the virtue. 295 359 * Those tagged with S can have only single virtue active at one moment, those … … 376 440 NIC_POLL_SOFTWARE_PERIODIC 377 441 } nic_poll_mode_t; 442 443 /** 444 * Says if this virtue type is a multi-virtue (there can be multiple virtues of 445 * this type at once). 446 * 447 * @param type 448 * 449 * @return true or false 450 */ 451 static inline int nic_wv_is_multi(nic_wv_type_t type) { 452 switch (type) { 453 case NIC_WV_FULL_MATCH: 454 case NIC_WV_DESTINATION: 455 case NIC_WV_DIRECTED_IPV4: 456 case NIC_WV_DIRECTED_IPV6: 457 return true; 458 default: 459 return false; 460 } 461 } 378 462 379 463 static inline const char *nic_device_state_to_string(nic_device_state_t state) -
uspace/lib/net/generic/generic.c
re2c50e1 r00d7e1b 79 79 { 80 80 async_exch_t *exch = async_exchange_begin(sess); 81 int rc = async_req_ 2_0(exch, message, (sysarg_t) device_id,81 int rc = async_req_3_0(exch, message, (sysarg_t) device_id, 0, 82 82 (sysarg_t) service); 83 83 async_exchange_end(exch); -
uspace/lib/net/generic/net_checksum.c
re2c50e1 r00d7e1b 45 45 #define CRC_DIVIDER_LE 0xedb88320 46 46 47 /** Polynomial used in multicast address hashing */ 48 #define CRC_MCAST_POLYNOMIAL 0x04c11db6 49 47 50 /** Compacts the computed checksum to the 16 bit number adding the carries. 48 51 * … … 221 224 } 222 225 226 /** Compute the standard hash from MAC 227 * 228 * Hashing MAC into 64 possible values and using the value as index to 229 * 64bit number. 230 * 231 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139 232 * drivers, but according to documentation there it originates in FreeBSD. 233 * 234 * @param[in] addr The 6-byte MAC address to be hashed 235 * 236 * @return 64-bit number with only single bit set to 1 237 * 238 */ 239 uint64_t multicast_hash(const uint8_t addr[6]) 240 { 241 uint32_t crc; 242 int carry, i, j; 243 uint8_t b; 244 245 crc = 0xffffffff; 246 for (i = 0; i < 6; i++) { 247 b = addr[i]; 248 for (j = 0; j < 8; j++) { 249 carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); 250 crc <<= 1; 251 b >>= 1; 252 if (carry) 253 crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry); 254 } 255 } 256 257 uint64_t one64 = 1; 258 return one64 << (crc >> 26); 259 } 260 223 261 /** @} 224 262 */ -
uspace/lib/net/il/ip_remote.c
re2c50e1 r00d7e1b 123 123 * 124 124 */ 125 int ip_device_req _remote(async_sess_t *sess, nic_device_id_t device_id,125 int ip_device_req(async_sess_t *sess, nic_device_id_t device_id, 126 126 services_t service) 127 127 { -
uspace/lib/net/include/ip_interface.h
re2c50e1 r00d7e1b 46 46 #define ip_set_gateway_req ip_set_gateway_req_remote 47 47 #define ip_packet_size_req ip_packet_size_req_remote 48 #define ip_device_req ip_device_req_remote49 48 #define ip_add_route_req ip_add_route_req_remote 50 49 #define ip_send_msg ip_send_msg_remote -
uspace/lib/net/include/ip_remote.h
re2c50e1 r00d7e1b 48 48 extern int ip_received_error_msg_remote(async_sess_t *, nic_device_id_t, packet_t *, 49 49 services_t, services_t); 50 extern int ip_device_req _remote(async_sess_t *, nic_device_id_t, services_t);50 extern int ip_device_req(async_sess_t *, nic_device_id_t, services_t); 51 51 extern int ip_add_route_req_remote(async_sess_t *, nic_device_id_t, in_addr_t, 52 52 in_addr_t, in_addr_t); -
uspace/lib/net/include/net_checksum.h
re2c50e1 r00d7e1b 67 67 extern uint16_t flip_checksum(uint16_t); 68 68 extern uint16_t ip_checksum(uint8_t *, size_t); 69 extern uint64_t multicast_hash(const uint8_t addr[6]); 69 70 70 71 #endif -
uspace/lib/net/tl/tl_skel.c
re2c50e1 r00d7e1b 123 123 goto out; 124 124 125 task_retval(0); 125 126 async_manager(); 126 127 -
uspace/srv/net/il/ip/ip.c
re2c50e1 r00d7e1b 354 354 ip_netif->routing = NET_DEFAULT_IP_ROUTING; 355 355 configuration = &names[0]; 356 356 357 357 /* Get configuration */ 358 358 rc = net_get_device_conf_req(ip_globals.net_sess, ip_netif->device_id, … … 406 406 return ENOTSUP; 407 407 } 408 408 409 409 if (configuration[6].value) { 410 410 ip_netif->arp = get_running_module(&ip_globals.modules, … … 417 417 } 418 418 } 419 419 420 if (configuration[7].value) 420 421 ip_netif->routing = (configuration[7].value[0] == 'y'); 421 422 422 423 net_free_settings(configuration, data); 423 424 } 424 425 425 426 /* Bind netif service which also initializes the device */ 426 427 ip_netif->sess = nil_bind_service(ip_netif->service, … … 432 433 return ENOENT; 433 434 } 434 435 435 436 /* Has to be after the device netif module initialization */ 436 437 if (ip_netif->arp) { … … 448 449 } 449 450 } 450 451 451 452 /* Get packet dimensions */ 452 453 rc = nil_packet_size_req(ip_netif->sess, ip_netif->device_id, … … 461 462 ip_netif->packet_dimension.content = IP_MIN_CONTENT; 462 463 } 463 464 464 465 index = ip_netifs_add(&ip_globals.netifs, ip_netif->device_id, ip_netif); 465 466 if (index < 0) … … 478 479 printf("%s: Default gateway (%s)\n", NAME, defgateway); 479 480 } 480 481 481 482 return EOK; 482 483 } … … 498 499 return rc; 499 500 } 500 501 501 502 ip_netif->device_id = device_id; 502 503 ip_netif->service = netif; 503 504 ip_netif->state = NIC_STATE_STOPPED; 504 505 505 506 fibril_rwlock_write_lock(&ip_globals.netifs_lock); 506 507 -
uspace/srv/net/net/Makefile
re2c50e1 r00d7e1b 43 43 SOURCES = \ 44 44 net.c \ 45 net_standalone.c \46 45 packet_server.c 47 46 -
uspace/srv/net/net/net.c
re2c50e1 r00d7e1b 30 30 /** @addtogroup net 31 31 * @{ 32 */33 34 /** @file35 * Networking subsystem central module implementation.36 *37 32 */ 38 33 … … 55 50 #include <ipc/ip.h> 56 51 #include <ipc/nil.h> 57 #include <net/modules.h>58 52 #include <net/packet.h> 59 53 #include <net/device.h> … … 72 66 #include "packet_server.h" 73 67 74 /** Networking module name. */75 #define NAME "net"76 77 68 #define MAX_PATH_LENGTH 1024 78 69 … … 82 73 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t); 83 74 DEVICE_MAP_IMPLEMENT(netifs, netif_t); 84 85 static int startup(void);86 75 87 76 /** Add the configured setting to the configuration map. … … 95 84 * 96 85 */ 97 int add_configuration(measured_strings_t *configuration, const uint8_t *name,98 const uint8_t * value)86 static int add_configuration(measured_strings_t *configuration, 87 const uint8_t *name, const uint8_t *value) 99 88 { 100 89 int rc; … … 146 135 (uint8_t *) entry->key, (uint8_t *) entry->value); 147 136 if (rc != EOK) { 148 printf("%s: Error processing configuration\n", NAME);149 137 cfg_unload(&cfg); 150 138 return rc; … … 180 168 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, 181 169 &net_globals.configuration); 182 }183 184 /** Initialize the networking module.185 *186 * @param[in] client_connection The client connection processing187 * function. The module skeleton propagates188 * its own one.189 *190 * @return EOK on success.191 * @return ENOMEM if there is not enough memory left.192 *193 */194 static int net_initialize(async_client_conn_t client_connection)195 {196 int rc;197 198 netifs_initialize(&net_globals.netifs);199 char_map_initialize(&net_globals.netif_hwpaths);200 modules_initialize(&net_globals.modules);201 measured_strings_initialize(&net_globals.configuration);202 203 rc = read_configuration();204 if (rc != EOK)205 return rc;206 207 rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,208 (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);209 if (rc != EOK)210 return rc;211 212 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,213 (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);214 if (rc != EOK)215 return rc;216 217 /* Build specific initialization */218 return net_initialize_build(client_connection);219 }220 221 /** Start the networking module.222 *223 * Initializes the client connection serving function,224 * initializes the module, registers the module service225 * and starts the async manager, processing IPC messages226 * in an infinite loop.227 *228 * @param[in] client_connection The client connection229 * processing function. The230 * module skeleton propagates231 * its own one.232 *233 * @return EOK on successful module termination.234 * @return Other error codes as defined for the net_initialize() function.235 * @return Other error codes as defined for the REGISTER_ME() macro function.236 *237 */238 static int net_module_start(async_client_conn_t client_connection)239 {240 int rc;241 242 async_set_client_connection(client_connection);243 rc = pm_init();244 if (rc != EOK)245 return rc;246 247 rc = packet_server_init();248 if (rc != EOK)249 goto out;250 251 rc = net_initialize(client_connection);252 if (rc != EOK)253 goto out;254 255 rc = startup();256 if (rc != EOK)257 goto out;258 259 rc = service_register(SERVICE_NETWORKING);260 if (rc != EOK)261 goto out;262 263 task_retval(0);264 async_manager();265 266 out:267 pm_destroy();268 return rc;269 170 } 270 171 … … 388 289 static int init_device(netif_t *netif, devman_handle_t handle) 389 290 { 291 printf("%s: Initializing device '%s'\n", NAME, netif->name); 292 390 293 netif->handle = handle; 391 294 netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle, … … 459 362 } 460 363 364 printf("%s: Activating device '%s'\n", NAME, netif->name); 461 365 return nic_set_state(netif->sess, NIC_STATE_ACTIVE); 462 366 } 463 367 464 static int net_ driver_port_ready(devman_handle_t handle)368 static int net_port_ready(devman_handle_t handle) 465 369 { 466 370 char hwpath[MAX_PATH_LENGTH]; … … 500 404 501 405 for (size_t i = 0; i < count; i++) { 502 rc = net_ driver_port_ready(funs[i]);406 rc = net_port_ready(funs[i]); 503 407 if (rc != EOK) 504 408 return rc; 505 409 } 506 410 507 return EOK;508 }509 510 /** Read the configuration and start all network interfaces.511 *512 * @return EOK on success.513 * @return EXDEV if there is no available system-unique device identifier.514 * @return EINVAL if any of the network interface names are not configured.515 * @return ENOMEM if there is not enough memory left.516 * @return Other error codes as defined for the read_configuration()517 * function.518 * @return Other error codes as defined for the read_netif_configuration()519 * function.520 * @return Other error codes as defined for the start_device() function.521 *522 */523 static int startup(void)524 {525 int rc;526 527 DIR *config_dir = opendir(CONF_DIR);528 if (config_dir == NULL)529 return ENOENT;530 531 struct dirent *dir_entry;532 while ((dir_entry = readdir(config_dir))) {533 if (str_cmp(dir_entry->d_name + str_length(dir_entry->d_name)534 - str_length(CONF_EXT), CONF_EXT) != 0)535 continue;536 537 netif_t *netif = (netif_t *) malloc(sizeof(netif_t));538 if (!netif)539 continue;540 541 netif->handle = -1;542 netif->sess = NULL;543 544 netif->id = generate_new_device_id();545 if (!netif->id) {546 free(netif);547 continue;548 }549 550 rc = measured_strings_initialize(&netif->configuration);551 if (rc != EOK) {552 free(netif);553 continue;554 }555 556 rc = read_netif_configuration(dir_entry->d_name, netif);557 if (rc != EOK) {558 free(netif);559 continue;560 }561 562 /* Mandatory name */563 measured_string_t *name = measured_strings_find(&netif->configuration,564 (uint8_t *) CONF_NAME, 0);565 if (!name) {566 printf("%s: Network interface name is missing\n", NAME);567 measured_strings_destroy(&netif->configuration, free);568 free(netif);569 continue;570 }571 572 netif->name = name->value;573 574 /* Mandatory hardware path */575 measured_string_t *hwpath = measured_strings_find(576 &netif->configuration, (const uint8_t *) CONF_HWPATH, 0);577 if (!hwpath) {578 measured_strings_destroy(&netif->configuration, free);579 free(netif);580 }581 582 /* Add to the netifs map */583 int index = netifs_add(&net_globals.netifs, netif->id, netif);584 if (index < 0) {585 measured_strings_destroy(&netif->configuration, free);586 free(netif);587 continue;588 }589 590 /*591 * Add to the hardware paths map and init network interfaces592 * and needed modules.593 */594 rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index);595 if (rc != EOK) {596 measured_strings_destroy(&netif->configuration, free);597 netifs_exclude_index(&net_globals.netifs, index, free);598 continue;599 }600 }601 602 closedir(config_dir);603 411 return EOK; 604 412 } … … 619 427 * 620 428 */ 621 int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,622 size_t *answer_count)429 static int net_message(ipc_callid_t callid, ipc_call_t *call, 430 ipc_call_t *answer, size_t *answer_count) 623 431 { 624 432 measured_string_t *strings; … … 699 507 /* Clear the answer structure */ 700 508 ipc_call_t answer; 701 size_t answer_count;702 refresh_answer(&answer, & answer_count);509 size_t count; 510 refresh_answer(&answer, &count); 703 511 704 512 /* Fetch the next message */ … … 707 515 708 516 /* Process the message */ 709 int res = net_module_message(callid, &call, &answer, &answer_count); 517 int res; 518 if (IS_NET_PACKET_MESSAGE(call)) 519 res = packet_server_message(callid, &call, &answer, &count); 520 else 521 res = net_message(callid, &call, &answer, &count); 710 522 711 523 /* End if told to either by the message or the processing result */ … … 714 526 715 527 /* Answer the message */ 716 answer_call(callid, res, &answer, answer_count);528 answer_call(callid, res, &answer, count); 717 529 } 718 530 } … … 720 532 int main(int argc, char *argv[]) 721 533 { 722 return net_module_start(net_client_connection); 534 netifs_initialize(&net_globals.netifs); 535 char_map_initialize(&net_globals.netif_hwpaths); 536 modules_initialize(&net_globals.modules); 537 measured_strings_initialize(&net_globals.configuration); 538 async_set_client_connection(net_client_connection); 539 540 int rc = pm_init(); 541 if (rc != EOK) { 542 printf("%s: Unable to initialize packet management\n", NAME); 543 return rc; 544 } 545 546 rc = packet_server_init(); 547 if (rc != EOK) { 548 printf("%s: Unable to initialize packet server\n", NAME); 549 pm_destroy(); 550 return rc; 551 } 552 553 rc = read_configuration(); 554 if (rc != EOK) { 555 printf("%s: Error reading configuration\n", NAME); 556 pm_destroy(); 557 return rc; 558 } 559 560 DIR *config_dir = opendir(CONF_DIR); 561 if (config_dir != NULL) { 562 struct dirent *dir_entry; 563 while ((dir_entry = readdir(config_dir))) { 564 /* Ignore files without the CONF_EXT extension */ 565 if ((str_size(dir_entry->d_name) < str_size(CONF_EXT)) || 566 (str_cmp(dir_entry->d_name + str_size(dir_entry->d_name) - 567 str_size(CONF_EXT), CONF_EXT) != 0)) 568 continue; 569 570 571 netif_t *netif = (netif_t *) malloc(sizeof(netif_t)); 572 if (!netif) 573 continue; 574 575 netif->handle = -1; 576 netif->sess = NULL; 577 578 netif->id = generate_new_device_id(); 579 if (!netif->id) { 580 free(netif); 581 continue; 582 } 583 584 rc = measured_strings_initialize(&netif->configuration); 585 if (rc != EOK) { 586 free(netif); 587 continue; 588 } 589 590 rc = read_netif_configuration(dir_entry->d_name, netif); 591 if (rc != EOK) { 592 printf("%s: Error reading configuration %s\n", NAME, 593 dir_entry->d_name); 594 free(netif); 595 continue; 596 } 597 598 measured_string_t *name = measured_strings_find(&netif->configuration, 599 (uint8_t *) CONF_NAME, 0); 600 if (!name) { 601 printf("%s: Network interface name is missing in %s\n", 602 NAME, dir_entry->d_name); 603 measured_strings_destroy(&netif->configuration, free); 604 free(netif); 605 continue; 606 } 607 608 netif->name = name->value; 609 610 /* Mandatory hardware path */ 611 measured_string_t *hwpath = measured_strings_find( 612 &netif->configuration, (const uint8_t *) CONF_HWPATH, 0); 613 if (!hwpath) { 614 printf("%s: Hardware path is missing in %s\n", 615 NAME, dir_entry->d_name); 616 measured_strings_destroy(&netif->configuration, free); 617 free(netif); 618 continue; 619 } 620 621 int index = netifs_add(&net_globals.netifs, netif->id, netif); 622 if (index < 0) { 623 measured_strings_destroy(&netif->configuration, free); 624 free(netif); 625 continue; 626 } 627 628 /* 629 * Add to the hardware paths map and init network interfaces 630 * and needed modules. 631 */ 632 rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index); 633 if (rc != EOK) { 634 measured_strings_destroy(&netif->configuration, free); 635 netifs_exclude_index(&net_globals.netifs, index, free); 636 continue; 637 } 638 } 639 640 closedir(config_dir); 641 } 642 643 rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME, 644 (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service); 645 if (rc != EOK) { 646 printf("%s: Error adding module '%s'\n", NAME, ETHERNET_NAME); 647 pm_destroy(); 648 return rc; 649 } 650 651 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME, 652 (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service); 653 if (rc != EOK) { 654 printf("%s: Error adding module '%s'\n", NAME, NILDUMMY_NAME); 655 pm_destroy(); 656 return rc; 657 } 658 659 task_id_t task_id = net_spawn((uint8_t *) IP_FILENAME); 660 if (!task_id) { 661 printf("%s: Error spawning IP module\n", NAME); 662 pm_destroy(); 663 return EINVAL; 664 } 665 666 rc = add_module(NULL, &net_globals.modules, (uint8_t *) IP_NAME, 667 (uint8_t *) IP_FILENAME, SERVICE_IP, task_id, ip_connect_module); 668 if (rc != EOK) { 669 printf("%s: Error adding module '%s'\n", NAME, IP_NAME); 670 pm_destroy(); 671 return rc; 672 } 673 674 if (!net_spawn((uint8_t *) "/srv/icmp")) { 675 printf("%s: Error spawning ICMP module\n", NAME); 676 pm_destroy(); 677 return EINVAL; 678 } 679 680 if (!net_spawn((uint8_t *) "/srv/udp")) { 681 printf("%s: Error spawning UDP module\n", NAME); 682 pm_destroy(); 683 return EINVAL; 684 } 685 686 if (!net_spawn((uint8_t *) "/srv/tcp")) { 687 printf("%s: Error spawning TCP module\n", NAME); 688 pm_destroy(); 689 return EINVAL; 690 } 691 692 rc = service_register(SERVICE_NETWORKING); 693 if (rc != EOK) { 694 printf("%s: Error registering service\n", NAME); 695 pm_destroy(); 696 return rc; 697 } 698 699 task_retval(0); 700 async_manager(); 701 return 0; 723 702 } 724 703 -
uspace/srv/net/net/net.h
re2c50e1 r00d7e1b 32 32 */ 33 33 34 /** @file35 * Networking subsystem central module.36 *37 */38 39 34 #ifndef NET_NET_H_ 40 35 #define NET_NET_H_ … … 48 43 #include <devman.h> 49 44 50 /** @name Modules definitions 51 * @{ 52 */ 45 #define NAME "net" 53 46 54 47 #define ETHERNET_FILENAME "/srv/eth" … … 95 88 */ 96 89 typedef struct { 97 uint8_t *name; /**< System-unique network interface name. */ 98 nic_device_id_t id; /**< System-unique network interface identifier. */ 99 measured_strings_t configuration; /**< Configuration. */ 90 /** System-unique network interface name. */ 91 uint8_t *name; 92 /** System-unique network interface identifier. */ 93 nic_device_id_t id; 94 /** Configuration. */ 95 measured_strings_t configuration; 100 96 101 97 /** Serving network interface driver module index. */ 102 devman_handle_t handle; 103 async_sess_t *sess; 98 devman_handle_t handle; /**< Handle for devman */ 99 async_sess_t *sess; /**< Driver session. */ 104 100 105 module_t *nil; 106 module_t *il; 101 module_t *nil; /**< Serving link layer module index. */ 102 module_t *il; /**< Serving internet layer module index. */ 107 103 } netif_t; 108 104 … … 129 125 } net_globals_t; 130 126 131 extern int add_configuration(measured_strings_t *, const uint8_t *,132 const uint8_t *);133 extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);134 extern int net_initialize_build(async_client_conn_t);135 extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);136 137 127 #endif 138 128 -
uspace/srv/net/net/packet_server.h
re2c50e1 r00d7e1b 43 43 */ 44 44 45 #ifndef LIBPACKET_PACKET_SERVER_H_46 #define LIBPACKET_PACKET_SERVER_H_45 #ifndef NET_PACKET_SERVER_H_ 46 #define NET_PACKET_SERVER_H_ 47 47 48 48 #include <ipc/common.h> -
uspace/srv/net/nil/eth/eth.c
re2c50e1 r00d7e1b 629 629 } 630 630 631 printf("%s: Protocol registered (protocol: %d, service: % d)\n",631 printf("%s: Protocol registered (protocol: %d, service: %#x)\n", 632 632 NAME, proto->protocol, proto->service); 633 633 -
uspace/srv/net/nil/nildummy/nildummy.c
re2c50e1 r00d7e1b 324 324 nildummy_globals.proto.sess = sess; 325 325 326 printf("%s: Protocol registered (service: % d)\n",326 printf("%s: Protocol registered (service: %#x)\n", 327 327 NAME, nildummy_globals.proto.service); 328 328
Note:
See TracChangeset
for help on using the changeset viewer.