Changeset d7ff048 in mainline for uspace/srv
- Timestamp:
- 2011-10-08T13:08:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bf08ff0
- Parents:
- 8367d1d (diff), 80099c19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv
- Files:
-
- 4 deleted
- 21 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r8367d1d rd7ff048 794 794 case EOK: 795 795 dev->state = DEVICE_USABLE; 796 exch = async_exchange_begin(drv->sess); 797 async_msg_1(exch, DRIVER_DEV_ADDED, dev->handle); 798 async_exchange_end(exch); 796 799 break; 797 800 case ENOENT: … … 1066 1069 1067 1070 link = hash_table_find(&tree->devman_devices, &key); 1071 if (link == NULL) 1072 return NULL; 1073 1068 1074 return hash_table_get_instance(link, dev_node_t, devman_dev); 1069 1075 } -
uspace/srv/devman/main.c
r8367d1d rd7ff048 634 634 fibril_rwlock_read_unlock(&device_tree.rwlock); 635 635 dev_del_ref(dev); 636 if (gone_rc == EOK) 637 gone_rc = ENOTSUP; 638 async_answer_0(callid, gone_rc); 636 639 return; 637 640 } -
uspace/srv/fs/fat/fat.h
r8367d1d rd7ff048 141 141 } __attribute__ ((packed)) fat_bs_t; 142 142 143 #define FAT32_FSINFO_SIG1 "RRaA" 144 #define FAT32_FSINFO_SIG2 "rrAa" 145 #define FAT32_FSINFO_SIG3 "\x00\x00\x55\xaa" 146 147 typedef struct { 148 uint8_t sig1[4]; 149 uint8_t res1[480]; 150 uint8_t sig2[4]; 151 uint32_t free_clusters; 152 uint32_t last_allocated_cluster; 153 uint8_t res2[12]; 154 uint8_t sig3[4]; 155 } __attribute__ ((packed)) fat32_fsinfo_t; 156 143 157 typedef enum { 144 158 FAT_INVALID, -
uspace/srv/fs/fat/fat_ops.c
r8367d1d rd7ff048 1025 1025 } 1026 1026 1027 static int fat_update_fat32_fsinfo(service_id_t service_id) 1028 { 1029 fat_bs_t *bs; 1030 fat32_fsinfo_t *info; 1031 block_t *b; 1032 int rc; 1033 1034 bs = block_bb_get(service_id); 1035 assert(FAT_IS_FAT32(bs)); 1036 1037 rc = block_get(&b, service_id, uint16_t_le2host(bs->fat32.fsinfo_sec), 1038 BLOCK_FLAGS_NONE); 1039 if (rc != EOK) 1040 return rc; 1041 1042 info = (fat32_fsinfo_t *) b->data; 1043 1044 if (bcmp(info->sig1, FAT32_FSINFO_SIG1, sizeof(info->sig1)) || 1045 bcmp(info->sig2, FAT32_FSINFO_SIG2, sizeof(info->sig2)) || 1046 bcmp(info->sig3, FAT32_FSINFO_SIG3, sizeof(info->sig3))) { 1047 (void) block_put(b); 1048 return EINVAL; 1049 } 1050 1051 /* For now, invalidate the counter. */ 1052 info->free_clusters = host2uint16_t_le(-1); 1053 1054 b->dirty = true; 1055 return block_put(b); 1056 } 1057 1027 1058 static int fat_unmounted(service_id_t service_id) 1028 1059 { 1029 1060 fs_node_t *fn; 1030 1061 fat_node_t *nodep; 1031 int rc; 1062 fat_bs_t *bs; 1063 int rc; 1064 1065 bs = block_bb_get(service_id); 1032 1066 1033 1067 rc = fat_root_get(&fn, service_id); … … 1043 1077 (void) fat_node_put(fn); 1044 1078 return EBUSY; 1079 } 1080 1081 if (FAT_IS_FAT32(bs)) { 1082 /* 1083 * Attempt to update the FAT32 FS info. 1084 */ 1085 (void) fat_update_fat32_fsinfo(service_id); 1045 1086 } 1046 1087 -
uspace/srv/hw/irc/apic/apic.c
r8367d1d rd7ff048 206 206 } 207 207 208 if (pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE, 209 (void **) &io_apic) != EOK) 208 int rc = pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE, 209 (void **) &io_apic); 210 if (rc != EOK) { 211 printf("%s: Failed to enable PIO for APIC: %d\n", NAME, rc); 210 212 return false; 213 } 211 214 212 215 async_set_client_connection(apic_connection); -
uspace/srv/loc/loc.c
r8367d1d rd7ff048 1288 1288 cat = category_new("virtual"); 1289 1289 categ_dir_add_cat(&cdir, cat); 1290 1291 1290 1291 cat = category_new("nic"); 1292 categ_dir_add_cat(&cdir, cat); 1293 1292 1294 return true; 1293 1295 } -
uspace/srv/net/cfg/lo.nic
r8367d1d rd7ff048 3 3 NAME=lo 4 4 5 NETIF=lo 5 HWPATH=/virt/lo/port0 6 6 NIL=nildummy 7 7 IL=ip -
uspace/srv/net/cfg/ne2k.nic
r8367d1d rd7ff048 1 # DP8390 (NE2k)configuration1 # NE2000 configuration 2 2 3 3 NAME=ne2k 4 4 5 NETIF=ne20005 HWPATH=/hw/pci0/00:01.0/ne2k/port0 6 6 NIL=eth 7 7 IL=ip 8 9 IRQ=510 IO=30011 8 12 9 # 8023_2_LSAP, 8023_2_SNAP … … 17 14 IP_ADDR=10.0.2.15 18 15 IP_ROUTING=yes 19 IP_NETMASK=255.255.255. 016 IP_NETMASK=255.255.255.240 20 17 IP_BROADCAST=10.0.2.255 21 18 IP_GATEWAY=10.0.2.2 -
uspace/srv/net/il/arp/arp.c
r8367d1d rd7ff048 174 174 count); 175 175 176 if (device) {176 if (device) 177 177 arp_clear_device(device); 178 if (device->addr_data)179 free(device->addr_data);180 181 if (device->broadcast_data)182 free(device->broadcast_data);183 }184 178 } 185 179 … … 190 184 } 191 185 192 static int arp_clear_address_req( device_id_t device_id, services_t protocol,193 measured_string_t *address)186 static int arp_clear_address_req(nic_device_id_t device_id, 187 services_t protocol, measured_string_t *address) 194 188 { 195 189 fibril_mutex_lock(&arp_globals.lock); … … 218 212 } 219 213 220 static int arp_clear_device_req( device_id_t device_id)214 static int arp_clear_device_req(nic_device_id_t device_id) 221 215 { 222 216 fibril_mutex_lock(&arp_globals.lock); … … 289 283 * 290 284 */ 291 static int arp_receive_message( device_id_t device_id, packet_t *packet)285 static int arp_receive_message(nic_device_id_t device_id, packet_t *packet) 292 286 { 293 287 int rc; … … 365 359 memcpy(src_proto, proto->addr->value, 366 360 header->protocol_length); 367 memcpy(src_hw, device->addr ->value,361 memcpy(src_hw, device->addr, 368 362 device->packet_dimension.addr_len); 369 363 memcpy(des_hw, trans->hw_addr->value, … … 393 387 * 394 388 */ 395 static int arp_mtu_changed_message( device_id_t device_id, size_t mtu)389 static int arp_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 396 390 { 397 391 fibril_mutex_lock(&arp_globals.lock); … … 409 403 printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu); 410 404 405 return EOK; 406 } 407 408 static int arp_addr_changed_message(nic_device_id_t device_id) 409 { 410 uint8_t addr_buffer[NIC_MAX_ADDRESS_LENGTH]; 411 size_t length; 412 ipc_callid_t data_callid; 413 if (!async_data_write_receive(&data_callid, &length)) { 414 async_answer_0(data_callid, EINVAL); 415 return EINVAL; 416 } 417 if (length > NIC_MAX_ADDRESS_LENGTH) { 418 async_answer_0(data_callid, ELIMIT); 419 return ELIMIT; 420 } 421 if (async_data_write_finalize(data_callid, addr_buffer, length) != EOK) { 422 return EINVAL; 423 } 424 425 fibril_mutex_lock(&arp_globals.lock); 426 427 arp_device_t *device = arp_cache_find(&arp_globals.cache, device_id); 428 if (!device) { 429 fibril_mutex_unlock(&arp_globals.lock); 430 return ENOENT; 431 } 432 433 memcpy(device->addr, addr_buffer, length); 434 device->addr_len = length; 435 436 fibril_mutex_unlock(&arp_globals.lock); 411 437 return EOK; 412 438 } … … 456 482 async_answer_0(iid, (sysarg_t) rc); 457 483 break; 484 case NET_IL_ADDR_CHANGED: 485 rc = arp_addr_changed_message(IPC_GET_DEVICE(*icall)); 486 async_answer_0(iid, (sysarg_t) rc); 458 487 459 488 default: … … 483 512 * 484 513 */ 485 static int arp_device_message( device_id_t device_id, services_t service,514 static int arp_device_message(nic_device_id_t device_id, services_t service, 486 515 services_t protocol, measured_string_t *address) 487 516 { … … 586 615 587 616 /* Get hardware address */ 588 rc = nil_get_addr_req(device->sess, device_id, &device->addr,589 &device->addr_data);590 if ( rc != EOK) {617 int len = nil_get_addr_req(device->sess, device_id, device->addr, 618 NIC_MAX_ADDRESS_LENGTH); 619 if (len < 0) { 591 620 fibril_mutex_unlock(&arp_globals.lock); 592 621 arp_protos_destroy(&device->protos, free); 593 622 free(device); 594 return rc; 595 } 623 return len; 624 } 625 626 device->addr_len = len; 596 627 597 628 /* Get broadcast address */ 598 rc = nil_get_broadcast_addr_req(device->sess, device_id, 599 &device->broadcast_addr, &device->broadcast_data); 600 if (rc != EOK) { 601 fibril_mutex_unlock(&arp_globals.lock); 602 free(device->addr); 603 free(device->addr_data); 629 len = nil_get_broadcast_addr_req(device->sess, device_id, 630 device->broadcast_addr, NIC_MAX_ADDRESS_LENGTH); 631 if (len < 0) { 632 fibril_mutex_unlock(&arp_globals.lock); 604 633 arp_protos_destroy(&device->protos, free); 605 634 free(device); 606 return rc; 607 } 635 return len; 636 } 637 638 device->broadcast_addr_len = len; 608 639 609 640 rc = arp_cache_add(&arp_globals.cache, device->device_id, … … 611 642 if (rc != EOK) { 612 643 fibril_mutex_unlock(&arp_globals.lock); 613 free(device->addr);614 free(device->addr_data);615 free(device->broadcast_addr);616 free(device->broadcast_data);617 644 arp_protos_destroy(&device->protos, free); 618 645 free(device); … … 640 667 } 641 668 642 static int arp_send_request( device_id_t device_id, services_t protocol,669 static int arp_send_request(nic_device_id_t device_id, services_t protocol, 643 670 measured_string_t *target, arp_device_t *device, arp_proto_t *proto) 644 671 { 645 672 /* ARP packet content size = header + (address + translation) * 2 */ 646 size_t length = 8 + 2 * (proto->addr->length + device->addr ->length);673 size_t length = 8 + 2 * (proto->addr->length + device->addr_len); 647 674 if (length > device->packet_dimension.content) 648 675 return ELIMIT; … … 661 688 662 689 header->hardware = htons(device->hardware); 663 header->hardware_length = (uint8_t) device->addr ->length;690 header->hardware_length = (uint8_t) device->addr_len; 664 691 header->protocol = htons(protocol_map(device->service, protocol)); 665 692 header->protocol_length = (uint8_t) proto->addr->length; … … 667 694 668 695 length = sizeof(arp_header_t); 669 670 memcpy(((uint8_t *) header) + length, device->addr->value, 671 device->addr->length); 672 length += device->addr->length; 696 memcpy(((uint8_t *) header) + length, device->addr, 697 device->addr_len); 698 length += device->addr_len; 673 699 memcpy(((uint8_t *) header) + length, proto->addr->value, 674 700 proto->addr->length); 675 701 length += proto->addr->length; 676 bzero(((uint8_t *) header) + length, device->addr ->length);677 length += device->addr ->length;702 bzero(((uint8_t *) header) + length, device->addr_len); 703 length += device->addr_len; 678 704 memcpy(((uint8_t *) header) + length, target->value, target->length); 679 680 int rc = packet_set_addr(packet, (uint8_t *) device->addr->value,681 (uint8_t *) device->broadcast_addr->value, device->addr->length);705 706 int rc = packet_set_addr(packet, device->addr, device->broadcast_addr, 707 device->addr_len); 682 708 if (rc != EOK) { 683 709 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); … … 704 730 * 705 731 */ 706 static int arp_translate_message( device_id_t device_id, services_t protocol,732 static int arp_translate_message(nic_device_id_t device_id, services_t protocol, 707 733 measured_string_t *target, measured_string_t **translation) 708 734 { -
uspace/srv/net/il/arp/arp.h
r8367d1d rd7ff048 92 92 struct arp_device { 93 93 /** Actual device hardware address. */ 94 measured_string_t *addr;95 /** Actual device hardware address data. */96 uint8_t *addr_data;94 uint8_t addr[NIC_MAX_ADDRESS_LENGTH]; 95 /** Actual device hardware address length. */ 96 size_t addr_len; 97 97 /** Broadcast device hardware address. */ 98 measured_string_t *broadcast_addr;99 /** Broadcast device hardware address data. */100 uint8_t *broadcast_data;98 uint8_t broadcast_addr[NIC_MAX_ADDRESS_LENGTH]; 99 /** Broadcast device hardware address length. */ 100 size_t broadcast_addr_len; 101 101 /** Device identifier. */ 102 device_id_t device_id;102 nic_device_id_t device_id; 103 103 /** Hardware type. */ 104 104 hw_type_t hardware; -
uspace/srv/net/il/ip/ip.c
r8367d1d rd7ff048 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 } 483 484 484 static int ip_device_req_local( device_id_t device_id, services_t netif)485 static int ip_device_req_local(nic_device_id_t device_id, services_t netif) 485 486 { 486 487 ip_netif_t *ip_netif; … … 498 499 return rc; 499 500 } 500 501 501 502 ip_netif->device_id = device_id; 502 503 ip_netif->service = netif; 503 ip_netif->state = N ETIF_STOPPED;504 504 ip_netif->state = NIC_STATE_STOPPED; 505 505 506 fibril_rwlock_write_lock(&ip_globals.netifs_lock); 506 507 … … 594 595 while (index >= 0) { 595 596 netif = ip_netifs_get_index(&ip_globals.netifs, index); 596 if (netif && (netif->state == N ETIF_ACTIVE)) {597 if (netif && (netif->state == NIC_STATE_ACTIVE)) { 597 598 route = ip_netif_find_route(netif, destination); 598 599 if (route) … … 1142 1143 } 1143 1144 1144 static int ip_send_msg_local( device_id_t device_id, packet_t *packet,1145 static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet, 1145 1146 services_t sender, services_t error) 1146 1147 { … … 1258 1259 * @return ENOENT if device is not found. 1259 1260 */ 1260 static int ip_device_state_message(device_id_t device_id, device_state_t state) 1261 static int ip_device_state_message(nic_device_id_t device_id, 1262 nic_device_state_t state) 1261 1263 { 1262 1264 ip_netif_t *netif; … … 1272 1274 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1273 1275 1274 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 1276 printf("%s: Device %d changed state to '%s'\n", NAME, device_id, 1277 nic_device_state_to_string(state)); 1275 1278 1276 1279 return EOK; … … 1312 1315 * tl_received_msg() function. 1313 1316 */ 1314 static int ip_deliver_local( device_id_t device_id, packet_t *packet,1317 static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet, 1315 1318 ip_header_t *header, services_t error) 1316 1319 { … … 1413 1416 * is disabled. 1414 1417 */ 1415 static int ip_process_packet( device_id_t device_id, packet_t *packet)1418 static int ip_process_packet(nic_device_id_t device_id, packet_t *packet) 1416 1419 { 1417 1420 ip_header_t *header; … … 1514 1517 * 1515 1518 */ 1516 static int ip_packet_size_message( device_id_t device_id, size_t *addr_len,1519 static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len, 1517 1520 size_t *prefix, size_t *content, size_t *suffix) 1518 1521 { … … 1572 1575 * @return ENOENT if device is not found. 1573 1576 */ 1574 static int ip_mtu_changed_message( device_id_t device_id, size_t mtu)1577 static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 1575 1578 { 1576 1579 ip_netif_t *netif; … … 1629 1632 async_answer_0(iid, (sysarg_t) rc); 1630 1633 break; 1631 1634 case NET_IL_ADDR_CHANGED: 1635 async_answer_0(iid, (sysarg_t) EOK); 1636 break; 1637 1632 1638 default: 1633 1639 async_answer_0(iid, (sysarg_t) ENOTSUP); … … 1689 1695 } 1690 1696 1691 static int ip_add_route_req_local( device_id_t device_id, in_addr_t address,1697 static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address, 1692 1698 in_addr_t netmask, in_addr_t gateway) 1693 1699 { … … 1723 1729 } 1724 1730 1725 static int ip_set_gateway_req_local(device_id_t device_id, in_addr_t gateway) 1731 static int ip_set_gateway_req_local(nic_device_id_t device_id, 1732 in_addr_t gateway) 1726 1733 { 1727 1734 ip_netif_t *netif; … … 1757 1764 * 1758 1765 */ 1759 static int ip_received_error_msg_local( device_id_t device_id,1766 static int ip_received_error_msg_local(nic_device_id_t device_id, 1760 1767 packet_t *packet, services_t target, services_t error) 1761 1768 { … … 1818 1825 static int ip_get_route_req_local(ip_protocol_t protocol, 1819 1826 const struct sockaddr *destination, socklen_t addrlen, 1820 device_id_t *device_id, void **header, size_t *headerlen)1827 nic_device_id_t *device_id, void **header, size_t *headerlen) 1821 1828 { 1822 1829 struct sockaddr_in *address_in; … … 1909 1916 size_t suffix; 1910 1917 size_t content; 1911 device_id_t device_id;1918 nic_device_id_t device_id; 1912 1919 int rc; 1913 1920 -
uspace/srv/net/il/ip/ip.h
r8367d1d rd7ff048 92 92 in_addr_t broadcast; 93 93 /** Device identifier. */ 94 device_id_t device_id;94 nic_device_id_t device_id; 95 95 /** Indicates whether using DHCP. */ 96 96 int dhcp; … … 108 108 services_t service; 109 109 /** Device state. */ 110 device_state_t state;110 nic_device_state_t state; 111 111 }; 112 112 -
uspace/srv/net/net/Makefile
r8367d1d rd7ff048 30 30 USPACE_PREFIX = ../../.. 31 31 ROOT_PATH = $(USPACE_PREFIX)/.. 32 LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBPACKET_PREFIX)/libpacket.a33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBPACKET_PREFIX)/include32 LIBS = $(LIBNET_PREFIX)/libnet.a 33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include 34 34 35 35 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common … … 43 43 SOURCES = \ 44 44 net.c \ 45 net_standalone.c45 packet_server.c 46 46 47 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/net/net.c
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 31 32 */ 32 33 33 /** @file 34 * Networking subsystem central module implementation. 35 * 36 */ 37 34 #include <assert.h> 38 35 #include <async.h> 39 36 #include <ctype.h> 40 37 #include <ddi.h> 41 38 #include <errno.h> 39 #include <str_error.h> 42 40 #include <malloc.h> 43 41 #include <stdio.h> 44 42 #include <str.h> 43 #include <devman.h> 45 44 #include <str_error.h> 46 45 #include <ns.h> … … 49 48 #include <ipc/net_net.h> 50 49 #include <ipc/il.h> 50 #include <ipc/ip.h> 51 51 #include <ipc/nil.h> 52 #include <net/modules.h>53 52 #include <net/packet.h> 54 53 #include <net/device.h> … … 57 56 #include <adt/measured_strings.h> 58 57 #include <adt/module_map.h> 59 #include <netif_remote.h>60 58 #include <nil_remote.h> 61 59 #include <net_interface.h> 62 60 #include <ip_interface.h> 61 #include <device/nic.h> 62 #include <dirent.h> 63 #include <fcntl.h> 64 #include <cfg.h> 63 65 #include "net.h" 64 65 /** Networking module name. */ 66 #define NAME "net" 67 68 /** File read buffer size. */ 69 #define BUFFER_SIZE 256 66 #include "packet_server.h" 67 68 #define MAX_PATH_LENGTH 1024 70 69 71 70 /** Networking module global data. */ … … 74 73 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t); 75 74 DEVICE_MAP_IMPLEMENT(netifs, netif_t); 76 77 static int startup(void);78 75 79 76 /** Add the configured setting to the configuration map. … … 87 84 * 88 85 */ 89 int add_configuration(measured_strings_t *configuration, const uint8_t *name,90 const uint8_t * value)86 static int add_configuration(measured_strings_t *configuration, 87 const uint8_t *name, const uint8_t *value) 91 88 { 92 89 int rc; … … 109 106 /** Generate new system-unique device identifier. 110 107 * 111 * @return The system-unique devic identifier. 112 */ 113 static device_id_t generate_new_device_id(void) 108 * @return The system-unique devic identifier. 109 * 110 */ 111 static nic_device_id_t generate_new_device_id(void) 114 112 { 115 113 return device_assign_devno(); 116 }117 118 static int parse_line(measured_strings_t *configuration, uint8_t *line)119 {120 int rc;121 122 /* From the beginning */123 uint8_t *name = line;124 125 /* Skip comments and blank lines */126 if ((*name == '#') || (*name == '\0'))127 return EOK;128 129 /* Skip spaces */130 while (isspace(*name))131 name++;132 133 /* Remember the name start */134 uint8_t *value = name;135 136 /* Skip the name */137 while (isalnum(*value) || (*value == '_'))138 value++;139 140 if (*value == '=') {141 /* Terminate the name */142 *value = '\0';143 } else {144 /* Terminate the name */145 *value = '\0';146 147 /* Skip until '=' */148 value++;149 while ((*value) && (*value != '='))150 value++;151 152 /* Not found? */153 if (*value != '=')154 return EINVAL;155 }156 157 value++;158 159 /* Skip spaces */160 while (isspace(*value))161 value++;162 163 /* Create a bulk measured string till the end */164 measured_string_t *setting =165 measured_string_create_bulk(value, 0);166 if (!setting)167 return ENOMEM;168 169 /* Add the configuration setting */170 rc = measured_strings_add(configuration, name, 0, setting);171 if (rc != EOK) {172 free(setting);173 return rc;174 }175 176 return EOK;177 114 } 178 115 … … 182 119 printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename); 183 120 184 /* Construct the full filename */ 185 char fname[BUFFER_SIZE]; 186 if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE) 187 return EOVERFLOW; 188 189 /* Open the file */ 190 FILE *cfg = fopen(fname, "r"); 191 if (!cfg) 121 cfg_file_t cfg; 122 int rc = cfg_load_path(directory, filename, &cfg); 123 if (rc != EOK) 124 return rc; 125 126 if (cfg_anonymous(&cfg) == NULL) { 127 cfg_unload(&cfg); 192 128 return ENOENT; 193 194 /* 195 * Read the configuration line by line 196 * until an error or the end of file 197 */ 198 unsigned int line_number = 0; 199 size_t index = 0; 200 uint8_t line[BUFFER_SIZE]; 201 202 while (!ferror(cfg) && !feof(cfg)) { 203 int read = fgetc(cfg); 204 if ((read > 0) && (read != '\n') && (read != '\r')) { 205 if (index >= BUFFER_SIZE) { 206 line[BUFFER_SIZE - 1] = '\0'; 207 fprintf(stderr, "%s: Configuration line %u too " 208 "long: %s\n", NAME, line_number, (char *) line); 209 210 /* No space left in the line buffer */ 211 return EOVERFLOW; 212 } 213 /* Append the character */ 214 line[index] = (uint8_t) read; 215 index++; 216 } else { 217 /* On error or new line */ 218 line[index] = '\0'; 219 line_number++; 220 if (parse_line(configuration, line) != EOK) { 221 fprintf(stderr, "%s: Configuration error on " 222 "line %u: %s\n", NAME, line_number, (char *) line); 223 } 224 225 index = 0; 129 } 130 131 cfg_section_foreach(cfg_anonymous(&cfg), link) { 132 const cfg_entry_t *entry = cfg_entry_instance(link); 133 134 rc = add_configuration(configuration, 135 (uint8_t *) entry->key, (uint8_t *) entry->value); 136 if (rc != EOK) { 137 cfg_unload(&cfg); 138 return rc; 226 139 } 227 140 } 228 141 229 fclose(cfg);142 cfg_unload(&cfg); 230 143 return EOK; 231 144 } … … 255 168 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, 256 169 &net_globals.configuration); 257 }258 259 /** Initialize the networking module.260 *261 * @param[in] client_connection The client connection processing262 * function. The module skeleton propagates263 * its own one.264 *265 * @return EOK on success.266 * @return ENOMEM if there is not enough memory left.267 *268 */269 static int net_initialize(async_client_conn_t client_connection)270 {271 int rc;272 273 netifs_initialize(&net_globals.netifs);274 char_map_initialize(&net_globals.netif_names);275 modules_initialize(&net_globals.modules);276 measured_strings_initialize(&net_globals.configuration);277 278 /* TODO: dynamic configuration */279 rc = read_configuration();280 if (rc != EOK)281 return rc;282 283 rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,284 (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);285 if (rc != EOK)286 return rc;287 288 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME,289 (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service);290 if (rc != EOK)291 return rc;292 293 rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,294 (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);295 if (rc != EOK)296 return rc;297 298 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,299 (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);300 if (rc != EOK)301 return rc;302 303 /* Build specific initialization */304 return net_initialize_build(client_connection);305 }306 307 /** Start the networking module.308 *309 * Initializes the client connection serving function,310 * initializes the module, registers the module service311 * and starts the async manager, processing IPC messages312 * in an infinite loop.313 *314 * @param[in] client_connection The client connection315 * processing function. The316 * module skeleton propagates317 * its own one.318 *319 * @return EOK on successful module termination.320 * @return Other error codes as defined for the net_initialize() function.321 * @return Other error codes as defined for the REGISTER_ME() macro function.322 *323 */324 static int net_module_start(async_client_conn_t client_connection)325 {326 int rc;327 328 async_set_client_connection(client_connection);329 rc = pm_init();330 if (rc != EOK)331 return rc;332 333 rc = net_initialize(client_connection);334 if (rc != EOK)335 goto out;336 337 rc = service_register(SERVICE_NETWORKING);338 if (rc != EOK)339 goto out;340 341 rc = startup();342 if (rc != EOK)343 goto out;344 345 task_retval(0);346 async_manager();347 348 out:349 pm_destroy();350 return rc;351 170 } 352 171 … … 364 183 */ 365 184 static int net_get_conf(measured_strings_t *netif_conf, 366 measured_string_t *configuration, size_t count , uint8_t **data)367 { 368 if ( data)369 *data = NULL;185 measured_string_t *configuration, size_t count) 186 { 187 if ((!configuration) || (count <= 0)) 188 return EINVAL; 370 189 371 190 size_t index; … … 389 208 } 390 209 391 static int net_get_conf_req_local(measured_string_t **configuration, 392 size_t count, uint8_t **data) 393 { 394 if (!configuration || (count <= 0)) 395 return EINVAL; 396 397 return net_get_conf(NULL, *configuration, count, data); 398 } 399 400 static int net_get_device_conf_req_local(device_id_t device_id, 401 measured_string_t **configuration, size_t count, uint8_t **data) 402 { 403 if ((!configuration) || (count == 0)) 404 return EINVAL; 405 210 static int net_get_device_conf(nic_device_id_t device_id, 211 measured_string_t *configuration, size_t count) 212 { 406 213 netif_t *netif = netifs_find(&net_globals.netifs, device_id); 407 214 if (netif) 408 return net_get_conf(&netif->configuration, *configuration, count, data);215 return net_get_conf(&netif->configuration, configuration, count); 409 216 else 410 return net_get_conf(NULL, *configuration, count, data); 411 } 412 413 void net_free_settings(measured_string_t *settings, uint8_t *data) 414 { 217 return net_get_conf(NULL, configuration, count); 218 } 219 220 static int net_get_devices(measured_string_t **devices, size_t *dev_count) 221 { 222 if (!devices) 223 return EBADMEM; 224 225 size_t max_count = netifs_count(&net_globals.netifs); 226 *devices = malloc(max_count * sizeof(measured_string_t)); 227 if (*devices == NULL) 228 return ENOMEM; 229 230 size_t count = 0; 231 for (size_t i = 0; i < max_count; i++) { 232 netif_t *item = netifs_get_index(&net_globals.netifs, i); 233 if (item->sess != NULL) { 234 /* 235 * Use format "device_id:device_name" 236 * FIXME: This typecasting looks really ugly 237 */ 238 (*devices)[count].length = asprintf( 239 (char **) &((*devices)[count].value), 240 NIC_DEVICE_PRINT_FMT ":%s", item->id, 241 (const char *) item->name); 242 count++; 243 } 244 } 245 246 *dev_count = (size_t) count; 247 return EOK; 248 } 249 250 static int net_get_devices_count() 251 { 252 size_t max_count = netifs_count(&net_globals.netifs); 253 254 size_t count = 0; 255 for (size_t i = 0; i < max_count; i++) { 256 netif_t *item = netifs_get_index(&net_globals.netifs, i); 257 if (item->sess != NULL) 258 count++; 259 } 260 261 return count; 262 } 263 264 static void net_free_devices(measured_string_t *devices, size_t count) 265 { 266 size_t i; 267 for (i = 0; i < count; ++i) 268 free(devices[i].value); 269 270 free(devices); 415 271 } 416 272 … … 431 287 * 432 288 */ 433 static int start_device(netif_t *netif) 434 { 435 int rc; 436 437 /* Mandatory netif */ 438 measured_string_t *setting = 439 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0); 440 441 netif->driver = get_running_module(&net_globals.modules, setting->value); 442 if (!netif->driver) { 443 fprintf(stderr, "%s: Failed to start network interface driver '%s'\n", 444 NAME, setting->value); 445 return EINVAL; 289 static int init_device(netif_t *netif, devman_handle_t handle) 290 { 291 printf("%s: Initializing device '%s'\n", NAME, netif->name); 292 293 netif->handle = handle; 294 netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle, 295 IPC_FLAG_BLOCKING); 296 if (netif->sess == NULL) { 297 printf("%s: Unable to connect to device\n", NAME); 298 return EREFUSED; 446 299 } 447 300 448 301 /* Optional network interface layer */ 449 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0); 302 measured_string_t *setting = measured_strings_find(&netif->configuration, 303 (uint8_t *) CONF_NIL, 0); 450 304 if (setting) { 451 netif->nil = get_running_module(&net_globals.modules, setting->value); 305 netif->nil = get_running_module(&net_globals.modules, 306 setting->value); 452 307 if (!netif->nil) { 453 fprintf(stderr, "%s: Failed to startnetwork interface layer '%s'\n",308 printf("%s: Unable to connect to network interface layer '%s'\n", 454 309 NAME, setting->value); 455 310 return EINVAL; … … 459 314 460 315 /* Mandatory internet layer */ 461 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0); 462 netif->il = get_running_module(&net_globals.modules, setting->value); 316 setting = measured_strings_find(&netif->configuration, 317 (uint8_t *) CONF_IL, 0); 318 netif->il = get_running_module(&net_globals.modules, 319 setting->value); 463 320 if (!netif->il) { 464 fprintf(stderr, "%s: Failed to startinternet layer '%s'\n",321 printf("%s: Unable to connect to internet layer '%s'\n", 465 322 NAME, setting->value); 466 323 return EINVAL; 467 324 } 468 325 469 /* Hardware configuration */470 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);471 int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;472 473 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);474 uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0;475 476 rc = netif_probe_req(netif->driver->sess, netif->id, irq, (void *) io);477 if (rc != EOK)478 return rc;479 480 326 /* Network interface layer startup */ 481 services_t internet_service; 327 int rc; 328 services_t nil_service; 482 329 if (netif->nil) { 483 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0); 330 setting = measured_strings_find(&netif->configuration, 331 (uint8_t *) CONF_MTU, 0); 484 332 if (!setting) 485 333 setting = measured_strings_find(&net_globals.configuration, 486 334 (uint8_t *) CONF_MTU, 0); 487 335 488 int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0; 489 rc = nil_device_req(netif->nil->sess, netif->id, mtu, 490 netif->driver->service); 336 int mtu = setting ? 337 strtol((const char *) setting->value, NULL, 10) : 0; 338 rc = nil_device_req(netif->nil->sess, netif->id, 339 netif->handle, mtu); 340 if (rc != EOK) { 341 printf("%s: Unable to start network interface layer\n", 342 NAME); 343 return rc; 344 } 345 346 nil_service = netif->nil->service; 347 } else 348 nil_service = -1; 349 350 /* Inter-network layer startup */ 351 switch (netif->il->service) { 352 case SERVICE_IP: 353 rc = ip_device_req(netif->il->sess, netif->id, nil_service); 354 if (rc != EOK) { 355 printf("%s: Unable to start internet layer\n", NAME); 356 return rc; 357 } 358 359 break; 360 default: 361 return ENOENT; 362 } 363 364 printf("%s: Activating device '%s'\n", NAME, netif->name); 365 return nic_set_state(netif->sess, NIC_STATE_ACTIVE); 366 } 367 368 static int net_port_ready(devman_handle_t handle) 369 { 370 char hwpath[MAX_PATH_LENGTH]; 371 int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH); 372 if (rc != EOK) 373 return EINVAL; 374 375 int index = char_map_find(&net_globals.netif_hwpaths, 376 (uint8_t *) hwpath, 0); 377 if (index == CHAR_MAP_NULL) 378 return ENOENT; 379 380 netif_t *netif = netifs_get_index(&net_globals.netifs, index); 381 if (netif == NULL) 382 return ENOENT; 383 384 rc = init_device(netif, handle); 385 if (rc != EOK) 386 return rc; 387 388 /* Increment module usage */ 389 if (netif->nil) 390 netif->nil->usage++; 391 392 netif->il->usage++; 393 394 return EOK; 395 } 396 397 static int net_driver_ready_local(devman_handle_t handle) 398 { 399 devman_handle_t *funs; 400 size_t count; 401 int rc = devman_dev_get_functions(handle, &funs, &count); 402 if (rc != EOK) 403 return rc; 404 405 for (size_t i = 0; i < count; i++) { 406 rc = net_port_ready(funs[i]); 491 407 if (rc != EOK) 492 408 return rc; 493 494 internet_service = netif->nil->service;495 } else496 internet_service = netif->driver->service;497 498 /* Inter-network layer startup */499 rc = ip_device_req(netif->il->sess, netif->id, internet_service);500 if (rc != EOK)501 return rc;502 503 return netif_start_req(netif->driver->sess, netif->id);504 }505 506 /** Read the configuration and start all network interfaces.507 *508 * @return EOK on success.509 * @return EXDEV if there is no available system-unique device identifier.510 * @return EINVAL if any of the network interface names are not configured.511 * @return ENOMEM if there is not enough memory left.512 * @return Other error codes as defined for the read_configuration()513 * function.514 * @return Other error codes as defined for the read_netif_configuration()515 * function.516 * @return Other error codes as defined for the start_device() function.517 *518 */519 static int startup(void)520 {521 const char *conf_files[] = {522 "lo",523 "ne2k"524 };525 size_t count = sizeof(conf_files) / sizeof(char *);526 int rc;527 528 size_t i;529 for (i = 0; i < count; i++) {530 netif_t *netif = (netif_t *) malloc(sizeof(netif_t));531 if (!netif)532 return ENOMEM;533 534 netif->id = generate_new_device_id();535 if (!netif->id)536 return EXDEV;537 538 rc = measured_strings_initialize(&netif->configuration);539 if (rc != EOK)540 return rc;541 542 /* Read configuration files */543 rc = read_netif_configuration(conf_files[i], netif);544 if (rc != EOK) {545 measured_strings_destroy(&netif->configuration, free);546 free(netif);547 return rc;548 }549 550 /* Mandatory name */551 measured_string_t *setting =552 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);553 if (!setting) {554 fprintf(stderr, "%s: Network interface name is missing\n", NAME);555 measured_strings_destroy(&netif->configuration, free);556 free(netif);557 return EINVAL;558 }559 netif->name = setting->value;560 561 /* Add to the netifs map */562 int index = netifs_add(&net_globals.netifs, netif->id, netif);563 if (index < 0) {564 measured_strings_destroy(&netif->configuration, free);565 free(netif);566 return index;567 }568 569 /*570 * Add to the netif names map and start network interfaces571 * and needed modules.572 */573 rc = char_map_add(&net_globals.netif_names, netif->name, 0,574 index);575 if (rc != EOK) {576 measured_strings_destroy(&netif->configuration, free);577 netifs_exclude_index(&net_globals.netifs, index, free);578 return rc;579 }580 581 rc = start_device(netif);582 if (rc != EOK) {583 printf("%s: Ignoring failed interface %s (%s)\n", NAME,584 netif->name, str_error(rc));585 measured_strings_destroy(&netif->configuration, free);586 netifs_exclude_index(&net_globals.netifs, index, free);587 continue;588 }589 590 /* Increment modules' usage */591 netif->driver->usage++;592 if (netif->nil)593 netif->nil->usage++;594 netif->il->usage++;595 596 printf("%s: Network interface started (name: %s, id: %d, driver: %s, "597 "nil: %s, il: %s)\n", NAME, netif->name, netif->id,598 netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]",599 netif->il->name);600 409 } 601 410 … … 618 427 * 619 428 */ 620 int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,621 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) 622 431 { 623 432 measured_string_t *strings; 624 433 uint8_t *data; 625 434 int rc; 435 size_t count; 626 436 627 437 *answer_count = 0; … … 636 446 if (rc != EOK) 637 447 return rc; 638 net_get_device_conf_req_local(IPC_GET_DEVICE(*call), &strings, 639 IPC_GET_COUNT(*call), NULL); 640 641 /* Strings should not contain received data anymore */ 642 free(data); 448 449 net_get_device_conf(IPC_GET_DEVICE(*call), strings, 450 IPC_GET_COUNT(*call)); 643 451 644 452 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 645 453 free(strings); 454 free(data); 646 455 return rc; 647 456 case NET_NET_GET_CONF: … … 650 459 if (rc != EOK) 651 460 return rc; 652 net_get_conf_req_local(&strings, IPC_GET_COUNT(*call), NULL); 653 654 /* Strings should not contain received data anymore */ 655 free(data); 461 462 net_get_conf(NULL, strings, IPC_GET_COUNT(*call)); 656 463 657 464 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 658 465 free(strings); 659 return rc; 660 case NET_NET_STARTUP: 661 return startup(); 662 } 663 664 return ENOTSUP; 466 free(data); 467 return rc; 468 case NET_NET_GET_DEVICES_COUNT: 469 count = (size_t) net_get_devices_count(); 470 IPC_SET_ARG1(*answer, count); 471 *answer_count = 1; 472 return EOK; 473 case NET_NET_GET_DEVICES: 474 rc = net_get_devices(&strings, &count); 475 if (rc != EOK) 476 return rc; 477 478 rc = measured_strings_reply(strings, count); 479 net_free_devices(strings, count); 480 return rc; 481 case NET_NET_DRIVER_READY: 482 rc = net_driver_ready_local(IPC_GET_ARG1(*call)); 483 *answer_count = 0; 484 return rc; 485 default: 486 return ENOTSUP; 487 } 665 488 } 666 489 … … 684 507 /* Clear the answer structure */ 685 508 ipc_call_t answer; 686 size_t answer_count;687 refresh_answer(&answer, & answer_count);509 size_t count; 510 refresh_answer(&answer, &count); 688 511 689 512 /* Fetch the next message */ … … 692 515 693 516 /* Process the message */ 694 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); 695 522 696 523 /* End if told to either by the message or the processing result */ … … 699 526 700 527 /* Answer the message */ 701 answer_call(callid, res, &answer, answer_count);528 answer_call(callid, res, &answer, count); 702 529 } 703 530 } … … 705 532 int main(int argc, char *argv[]) 706 533 { 707 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; 708 702 } 709 703 -
uspace/srv/net/net/net.h
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 31 32 */ 32 33 33 /** @file34 * Networking subsystem central module.35 *36 */37 38 34 #ifndef NET_NET_H_ 39 35 #define NET_NET_H_ … … 45 41 #include <adt/module_map.h> 46 42 #include <net/packet.h> 43 #include <devman.h> 47 44 48 /** @name Modules definitions 49 * @{ 50 */ 51 52 #define NE2000_FILENAME "/srv/ne2000" 53 #define NE2000_NAME "ne2000" 45 #define NAME "net" 54 46 55 47 #define ETHERNET_FILENAME "/srv/eth" … … 58 50 #define IP_FILENAME "/srv/ip" 59 51 #define IP_NAME "ip" 60 61 #define LO_FILENAME "/srv/lo"62 #define LO_NAME "lo"63 52 64 53 #define NILDUMMY_FILENAME "/srv/nildummy" … … 77 66 #define CONF_MTU "MTU" /**< Maximum transmission unit configuration label. */ 78 67 #define CONF_NAME "NAME" /**< Network interface name configuration label. */ 79 #define CONF_ NETIF "NETIF" /**< Network interface module name configurationlabel. */68 #define CONF_HWPATH "HWPATH" /**< Network interface hardware pathname label. */ 80 69 #define CONF_NIL "NIL" /**< Network interface layer module name configuration label. */ 81 70 … … 85 74 #define CONF_DIR "/cfg/net" /**< Configuration directory. */ 86 75 #define CONF_GENERAL_FILE "general" /**< General configuration file. */ 76 #define CONF_EXT ".nic" /**< Extension for NIC's configuration files. */ 87 77 88 78 /** Configuration settings. … … 98 88 */ 99 89 typedef struct { 100 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; 101 96 102 97 /** Serving network interface driver module index. */ 103 module_t *driver; 98 devman_handle_t handle; /**< Handle for devman */ 99 async_sess_t *sess; /**< Driver session. */ 104 100 105 device_id_t id; /**< System-unique network interface identifier. */ 106 module_t *il; /**< Serving internet layer module index. */ 107 uint8_t *name; /**< System-unique network interface name. */ 108 module_t *nil; /**< Serving link layer module index. */ 101 module_t *nil; /**< Serving link layer module index. */ 102 module_t *il; /**< Serving internet layer module index. */ 109 103 } netif_t; 110 104 … … 124 118 modules_t modules; /**< Available modules. */ 125 119 126 /** Network interface structure indices by names. */127 char_map_t netif_ names;120 /** Network interface structure indices by hardware path. */ 121 char_map_t netif_hwpaths; 128 122 129 123 /** Present network interfaces. */ … … 131 125 } net_globals_t; 132 126 133 extern int add_configuration(measured_strings_t *, const uint8_t *,134 const uint8_t *);135 extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);136 extern int net_initialize_build(async_client_conn_t);137 extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);138 139 127 #endif 140 128 -
uspace/srv/net/net/packet_server.c
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 35 36 */ 36 37 37 #include <packet_server.h>38 38 #include <align.h> 39 39 #include <assert.h> 40 40 #include <async.h> 41 41 #include <errno.h> 42 #include <str_error.h> 43 #include <stdio.h> 42 44 #include <fibril_synch.h> 43 45 #include <unistd.h> … … 48 50 #include <net/packet_header.h> 49 51 52 #include "packet_server.h" 53 54 #define PACKET_SERVER_PROFILE 1 55 56 /** Number of queues cacheing the unused packets */ 50 57 #define FREE_QUEUES_COUNT 7 58 /** Maximum number of packets in each queue */ 59 #define FREE_QUEUE_MAX_LENGTH 16 51 60 52 61 /** The default address length reserved for new packets. */ … … 58 67 /** The default suffix reserved for new packets. */ 59 68 #define DEFAULT_SUFFIX 64 69 70 /** The queue with unused packets */ 71 typedef struct packet_queue { 72 packet_t *first; /**< First packet in the queue */ 73 size_t packet_size; /**< Maximal size of the packets in this queue */ 74 int count; /**< Length of the queue */ 75 } packet_queue_t; 60 76 61 77 /** Packet server global data. */ … … 64 80 fibril_mutex_t lock; 65 81 /** Free packet queues. */ 66 packet_t *free[FREE_QUEUES_COUNT]; 67 68 /** 69 * Packet length upper bounds of the free packet queues. The maximal 70 * lengths of packets in each queue in the ascending order. The last 71 * queue is not limited. 72 */ 73 size_t sizes[FREE_QUEUES_COUNT]; 82 packet_queue_t free_queues[FREE_QUEUES_COUNT]; 74 83 75 84 /** Total packets allocated. */ 76 unsigned int count;85 packet_id_t next_id; 77 86 } ps_globals = { 78 87 .lock = FIBRIL_MUTEX_INITIALIZER(ps_globals.lock), 79 .free = {80 NULL,81 NULL,82 NULL,83 NULL,84 NULL,85 NULL,86 NULL88 .free_queues = { 89 { NULL, PAGE_SIZE, 0}, 90 { NULL, PAGE_SIZE * 2, 0}, 91 { NULL, PAGE_SIZE * 4, 0}, 92 { NULL, PAGE_SIZE * 8, 0}, 93 { NULL, PAGE_SIZE * 16, 0}, 94 { NULL, PAGE_SIZE * 32, 0}, 95 { NULL, PAGE_SIZE * 64, 0}, 87 96 }, 88 .sizes = { 89 PAGE_SIZE, 90 PAGE_SIZE * 2, 91 PAGE_SIZE * 4, 92 PAGE_SIZE * 8, 93 PAGE_SIZE * 16, 94 PAGE_SIZE * 32, 95 PAGE_SIZE * 64 96 }, 97 .count = 0 97 .next_id = 1 98 98 }; 99 99 … … 107 107 * @param[in] max_suffix The maximal suffix length in bytes. 108 108 */ 109 static void 110 packet_init(packet_t *packet, size_t addr_len, size_t max_prefix, 111 size_t max_content, size_t max_suffix) 109 static void packet_init(packet_t *packet, 110 size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix) 112 111 { 113 112 /* Clear the packet content */ … … 120 119 packet->previous = 0; 121 120 packet->next = 0; 121 packet->offload_info = 0; 122 packet->offload_mask = 0; 122 123 packet->addr_len = 0; 123 124 packet->src_addr = sizeof(packet_t); … … 127 128 packet->data_start = packet->dest_addr + addr_len + packet->max_prefix; 128 129 packet->data_end = packet->data_start; 130 } 131 132 /** 133 * Releases the memory allocated for the packet 134 * 135 * @param[in] packet Pointer to the memory where the packet was allocated 136 */ 137 static void packet_dealloc(packet_t *packet) 138 { 139 pm_remove(packet); 140 munmap(packet, packet->length); 129 141 } 130 142 … … 141 153 * @return NULL if there is not enough memory left. 142 154 */ 143 static packet_t * 144 packet_create(size_t length, size_t addr_len, size_t max_prefix, 145 size_t max_content, size_t max_suffix) 155 static packet_t *packet_alloc(size_t length, size_t addr_len, 156 size_t max_prefix, size_t max_content, size_t max_suffix) 146 157 { 147 158 packet_t *packet; 148 159 int rc; 149 160 161 /* Global lock is locked */ 150 162 assert(fibril_mutex_is_locked(&ps_globals.lock)); 151 152 /* Already locked */ 163 /* The length is some multiple of PAGE_SIZE */ 164 assert(!(length & (PAGE_SIZE - 1))); 165 153 166 packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE, 154 167 MAP_SHARED | MAP_ANONYMOUS, 0, 0); 155 168 if (packet == MAP_FAILED) 156 169 return NULL; 157 158 ps_globals.count++; 159 packet->packet_id = ps_globals.count; 170 171 /* Using 32bit packet_id the id could overflow */ 172 packet_id_t pid; 173 do { 174 pid = ps_globals.next_id; 175 ps_globals.next_id++; 176 } while (!pid || pm_find(pid)); 177 packet->packet_id = pid; 178 160 179 packet->length = length; 161 180 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); … … 163 182 rc = pm_add(packet); 164 183 if (rc != EOK) { 165 munmap(packet, packet->length);184 packet_dealloc(packet); 166 185 return NULL; 167 186 } … … 184 203 * @return NULL if there is not enough memory left. 185 204 */ 186 static packet_t * 187 packet_get_local(size_t addr_len, size_t max_prefix, size_t max_content, 188 size_t max_suffix) 189 { 190 size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len + 191 max_prefix + max_content + max_suffix, PAGE_SIZE); 192 205 static packet_t *packet_get_local(size_t addr_len, 206 size_t max_prefix, size_t max_content, size_t max_suffix) 207 { 208 size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len 209 + max_prefix + max_content + max_suffix, PAGE_SIZE); 210 211 if (length > PACKET_MAX_LENGTH) 212 return NULL; 213 193 214 fibril_mutex_lock(&ps_globals.lock); 194 215 … … 197 218 198 219 for (index = 0; index < FREE_QUEUES_COUNT; index++) { 199 if ((length > ps_globals. sizes[index]) &&200 220 if ((length > ps_globals.free_queues[index].packet_size) && 221 (index < FREE_QUEUES_COUNT - 1)) 201 222 continue; 202 223 203 packet = ps_globals.free [index];224 packet = ps_globals.free_queues[index].first; 204 225 while (packet_is_valid(packet) && (packet->length < length)) 205 226 packet = pm_find(packet->next); 206 227 207 228 if (packet_is_valid(packet)) { 208 if (packet == ps_globals.free[index]) 209 ps_globals.free[index] = pq_detach(packet); 210 else 229 ps_globals.free_queues[index].count--; 230 if (packet == ps_globals.free_queues[index].first) { 231 ps_globals.free_queues[index].first = pq_detach(packet); 232 } else { 211 233 pq_detach(packet); 234 } 212 235 213 packet_init(packet, addr_len, max_prefix, max_content, 214 max_suffix); 236 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); 215 237 fibril_mutex_unlock(&ps_globals.lock); 216 238 … … 219 241 } 220 242 221 packet = packet_ create(length, addr_len, max_prefix, max_content,222 243 packet = packet_alloc(length, addr_len, 244 max_prefix, max_content, max_suffix); 223 245 224 246 fibril_mutex_unlock(&ps_globals.lock); … … 240 262 241 263 for (index = 0; (index < FREE_QUEUES_COUNT - 1) && 242 (packet->length > ps_globals. sizes[index]); index++) {264 (packet->length > ps_globals.free_queues[index].packet_size); index++) { 243 265 ; 244 266 } 245 267 246 result = pq_add(&ps_globals.free[index], packet, packet->length, 247 packet->length); 268 ps_globals.free_queues[index].count++; 269 result = pq_add(&ps_globals.free_queues[index].first, packet, 270 packet->length, packet->length); 248 271 assert(result == EOK); 249 272 } … … 328 351 case NET_PACKET_CREATE_1: 329 352 packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, 330 353 IPC_GET_CONTENT(*call), DEFAULT_SUFFIX); 331 354 if (!packet) 332 355 return ENOMEM; … … 338 361 case NET_PACKET_CREATE_4: 339 362 packet = packet_get_local( 340 363 ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ? 341 364 IPC_GET_ADDR_LEN(*call) : DEFAULT_ADDR_LEN), 342 365 DEFAULT_PREFIX + IPC_GET_PREFIX(*call), … … 352 375 case NET_PACKET_GET: 353 376 packet = pm_find(IPC_GET_ID(*call)); 354 if (!packet_is_valid(packet)) 377 if (!packet_is_valid(packet)) { 355 378 return ENOENT; 379 } 356 380 return packet_reply(packet); 357 381 … … 371 395 } 372 396 397 int packet_server_init() 398 { 399 return EOK; 400 } 401 373 402 /** @} 374 403 */ -
uspace/srv/net/net/packet_server.h
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 42 43 */ 43 44 44 #ifndef LIBPACKET_PACKET_SERVER_H_45 #define LIBPACKET_PACKET_SERVER_H_45 #ifndef NET_PACKET_SERVER_H_ 46 #define NET_PACKET_SERVER_H_ 46 47 47 48 #include <ipc/common.h> 48 49 50 extern int packet_server_init(void); 49 51 extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, 50 52 size_t *); -
uspace/srv/net/nil/eth/eth.c
r8367d1d rd7ff048 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> … … 52 54 #include <protocol_map.h> 53 55 #include <net/device.h> 54 #include <netif_remote.h>55 56 #include <net_interface.h> 56 57 #include <il_remote.h> … … 58 59 #include <packet_client.h> 59 60 #include <packet_remote.h> 61 #include <device/nic.h> 60 62 #include <nil_skel.h> 61 63 #include "eth.h" … … 167 169 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 168 170 169 int nil_device_state_msg_local( device_id_t device_id, sysarg_t state)171 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 170 172 { 171 173 int index; … … 196 198 fibril_rwlock_write_lock(ð_globals.protos_lock); 197 199 eth_globals.net_sess = sess; 198 199 eth_globals.broadcast_addr = 200 measured_string_create_bulk((uint8_t *) "\xFF\xFF\xFF\xFF\xFF\xFF", ETH_ADDR); 201 if (!eth_globals.broadcast_addr) { 202 rc = ENOMEM; 203 goto out; 204 } 200 memcpy(eth_globals.broadcast_addr, "\xFF\xFF\xFF\xFF\xFF\xFF", 201 ETH_ADDR); 205 202 206 203 rc = eth_devices_initialize(ð_globals.devices); … … 215 212 eth_devices_destroy(ð_globals.devices, free); 216 213 } 214 217 215 out: 218 216 fibril_rwlock_write_unlock(ð_globals.protos_lock); … … 222 220 } 223 221 224 /** Process IPC messages from the registered device driver modules in an 225 * infinite loop. 226 * 227 * @param[in] iid Message identifier. 228 * @param[in,out] icall Message parameters. 229 * @param[in] arg Local argument. 230 * 231 */ 232 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 233 { 234 packet_t *packet; 235 int rc; 236 237 while (true) { 238 switch (IPC_GET_IMETHOD(*icall)) { 239 case NET_NIL_DEVICE_STATE: 240 nil_device_state_msg_local(IPC_GET_DEVICE(*icall), 241 IPC_GET_STATE(*icall)); 242 async_answer_0(iid, EOK); 243 break; 244 case NET_NIL_RECEIVED: 245 rc = packet_translate_remote(eth_globals.net_sess, 246 &packet, IPC_GET_PACKET(*icall)); 247 if (rc == EOK) 248 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall), 249 packet, 0); 250 251 async_answer_0(iid, (sysarg_t) rc); 252 break; 253 default: 254 async_answer_0(iid, (sysarg_t) ENOTSUP); 255 } 256 257 iid = async_get_call(icall); 258 } 259 } 260 261 /** Registers new device or updates the MTU of an existing one. 262 * 263 * Determines the device local hardware address. 264 * 265 * @param[in] device_id The new device identifier. 266 * @param[in] service The device driver service. 267 * @param[in] mtu The device maximum transmission unit. 268 * @return EOK on success. 269 * @return EEXIST if the device with the different service exists. 270 * @return ENOMEM if there is not enough memory left. 271 * @return Other error codes as defined for the 272 * net_get_device_conf_req() function. 273 * @return Other error codes as defined for the 274 * netif_bind_service() function. 275 * @return Other error codes as defined for the 276 * netif_get_addr_req() function. 277 */ 278 static int eth_device_message(device_id_t device_id, services_t service, 222 /** Register new device or updates the MTU of an existing one. 223 * 224 * Determine the device local hardware address. 225 * 226 * @param[in] device_id New device identifier. 227 * @param[in] handle Device driver handle. 228 * @param[in] mtu Device maximum transmission unit. 229 * 230 * @return EOK on success. 231 * @return EEXIST if the device with the different service exists. 232 * @return ENOMEM if there is not enough memory left. 233 * 234 */ 235 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle, 279 236 size_t mtu) 280 237 { … … 301 258 device = eth_devices_find(ð_globals.devices, device_id); 302 259 if (device) { 303 if (device-> service != service) {260 if (device->handle != handle) { 304 261 printf("Device %d already exists\n", device->device_id); 305 262 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 340 297 341 298 device->device_id = device_id; 342 device-> service = service;299 device->handle = handle; 343 300 device->flags = 0; 344 301 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) … … 377 334 378 335 /* Bind the device driver */ 379 device->sess = netif_bind_service(device->service, device->device_id,380 SERVICE_ETHERNET, eth_receiver);336 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 337 IPC_FLAG_BLOCKING); 381 338 if (device->sess == NULL) { 382 339 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 385 342 } 386 343 344 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 345 387 346 /* Get hardware address */ 388 rc = netif_get_addr_req(device->sess, device->device_id, &device->addr, 389 &device->addr_data); 347 rc = nic_get_address(device->sess, &device->addr); 390 348 if (rc != EOK) { 391 349 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 399 357 if (index < 0) { 400 358 fibril_rwlock_write_unlock(ð_globals.devices_lock); 401 free(device->addr);402 free(device->addr_data);403 359 free(device); 404 360 return index; 405 361 } 406 362 407 printf("%s: Device registered (id: %d, service: %d: mtu: %zu, " 408 "mac: %02x:%02x:%02x:%02x:%02x:%02x, flags: 0x%x)\n", 409 NAME, device->device_id, device->service, device->mtu, 410 device->addr_data[0], device->addr_data[1], 411 device->addr_data[2], device->addr_data[3], 412 device->addr_data[4], device->addr_data[5], device->flags); 363 printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, " 364 "mac: " PRIMAC ", flags: 0x%x)\n", NAME, 365 device->device_id, device->handle, device->mtu, 366 ARGSMAC(device->addr.address), device->flags); 413 367 414 368 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 456 410 fcs = (eth_fcs_t *) data + length - sizeof(eth_fcs_t); 457 411 length -= sizeof(eth_fcs_t); 458 } else if (type <= ETH_MAX_CONTENT) {412 } else if (type <= ETH_MAX_CONTENT) { 459 413 /* Translate "LSAP" values */ 460 414 if ((header->lsap.dsap == ETH_LSAP_GLSAP) && … … 462 416 /* Raw packet -- discard */ 463 417 return NULL; 464 } else if ((header->lsap.dsap == ETH_LSAP_SNAP) &&418 } else if ((header->lsap.dsap == ETH_LSAP_SNAP) && 465 419 (header->lsap.ssap == ETH_LSAP_SNAP)) { 466 420 /* … … 469 423 */ 470 424 type = ntohs(header->snap.ethertype); 471 prefix = sizeof(eth_header_t) + 472 sizeof(eth_header_lsap_t) + 425 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + 473 426 sizeof(eth_header_snap_t); 474 427 } else { 475 428 /* IEEE 802.3 + 802.2 LSAP */ 476 429 type = lsap_map(header->lsap.dsap); 477 prefix = sizeof(eth_header_t) + 478 sizeof(eth_header_lsap_t); 430 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t); 479 431 } 480 432 … … 506 458 } 507 459 508 int nil_received_msg_local(device_id_t device_id, packet_t *packet, 509 services_t target) 460 int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet) 510 461 { 511 462 eth_proto_t *proto; … … 523 474 flags = device->flags; 524 475 fibril_rwlock_read_unlock(ð_globals.devices_lock); 525 526 476 fibril_rwlock_read_lock(ð_globals.protos_lock); 477 527 478 do { 528 479 next = pq_detach(packet); … … 537 488 } 538 489 packet = next; 539 } while (packet);490 } while (packet); 540 491 541 492 fibril_rwlock_read_unlock(ð_globals.protos_lock); … … 554 505 * @return ENOENT if there is no such device. 555 506 */ 556 static int eth_packet_space_message( device_id_t device_id, size_t *addr_len,507 static int eth_packet_space_message(nic_device_id_t device_id, size_t *addr_len, 557 508 size_t *prefix, size_t *content, size_t *suffix) 558 509 { … … 579 530 } 580 531 581 /** Returnsthe device hardware address.532 /** Send the device hardware address. 582 533 * 583 534 * @param[in] device_id The device identifier. 584 535 * @param[in] type Type of the desired address. 585 * @param[out] address The device hardware address.586 536 * @return EOK on success. 587 537 * @return EBADMEM if the address parameter is NULL. 588 538 * @return ENOENT if there no such device. 589 539 */ 590 static int eth_addr_message(device_id_t device_id, eth_addr_type_t type, 591 measured_string_t **address) 592 { 593 eth_device_t *device; 594 595 if (!address) 596 return EBADMEM; 597 598 if (type == ETH_BROADCAST_ADDR) { 599 *address = eth_globals.broadcast_addr; 600 } else { 540 static int eth_addr_message(nic_device_id_t device_id, eth_addr_type_t type) 541 { 542 eth_device_t *device = NULL; 543 uint8_t *address; 544 size_t max_len; 545 ipc_callid_t callid; 546 547 if (type == ETH_BROADCAST_ADDR) 548 address = eth_globals.broadcast_addr; 549 else { 601 550 fibril_rwlock_read_lock(ð_globals.devices_lock); 602 551 device = eth_devices_find(ð_globals.devices, device_id); … … 605 554 return ENOENT; 606 555 } 607 *address = device->addr; 556 557 address = (uint8_t *) &device->addr.address; 558 } 559 560 int rc = EOK; 561 if (!async_data_read_receive(&callid, &max_len)) { 562 rc = EREFUSED; 563 goto end; 564 } 565 566 if (max_len < ETH_ADDR) { 567 async_data_read_finalize(callid, NULL, 0); 568 rc = ELIMIT; 569 goto end; 570 } 571 572 rc = async_data_read_finalize(callid, address, ETH_ADDR); 573 if (rc != EOK) 574 goto end; 575 576 end: 577 578 if (type == ETH_LOCAL_ADDR) 608 579 fibril_rwlock_read_unlock(ð_globals.devices_lock); 609 } 610 611 return (*address) ? EOK : ENOENT; 580 581 return rc; 612 582 } 613 583 … … 659 629 } 660 630 661 printf("%s: Protocol registered (protocol: %d, service: % d)\n",631 printf("%s: Protocol registered (protocol: %d, service: %#x)\n", 662 632 NAME, proto->protocol, proto->service); 663 633 … … 697 667 if (i < 0) 698 668 return i; 669 699 670 if (i != ETH_ADDR) 700 671 return EINVAL; 672 673 for (i = 0; i < ETH_ADDR; i++) { 674 if (src[i]) { 675 src_addr = src; 676 break; 677 } 678 } 701 679 702 680 length = packet_get_data_length(packet); … … 722 700 memcpy(header_dix->destination_address, dest, ETH_ADDR); 723 701 src = &header_dix->destination_address[0]; 724 } else if (IS_8023_2_LSAP(flags)) {702 } else if (IS_8023_2_LSAP(flags)) { 725 703 header_lsap = PACKET_PREFIX(packet, eth_header_lsap_t); 726 704 if (!header_lsap) … … 735 713 memcpy(header_lsap->header.destination_address, dest, ETH_ADDR); 736 714 src = &header_lsap->header.destination_address[0]; 737 } else if (IS_8023_2_SNAP(flags)) {715 } else if (IS_8023_2_SNAP(flags)) { 738 716 header = PACKET_PREFIX(packet, eth_header_snap_t); 739 717 if (!header) … … 746 724 header->lsap.ctrl = IEEE_8023_2_UI; 747 725 748 for (i = 0; i < 3; ++ i)726 for (i = 0; i < 3; i++) 749 727 header->snap.protocol[i] = 0; 750 728 … … 760 738 return ENOMEM; 761 739 762 for (i = 0; i < 7; ++ i)740 for (i = 0; i < 7; i++) 763 741 preamble->preamble[i] = ETH_PREAMBLE; 764 742 … … 787 765 * @return EINVAL if the service parameter is not known. 788 766 */ 789 static int eth_send_message( device_id_t device_id, packet_t *packet,767 static int eth_send_message(nic_device_id_t device_id, packet_t *packet, 790 768 services_t sender) 791 769 { … … 813 791 do { 814 792 rc = eth_prepare_packet(device->flags, next, 815 (uint8_t *) device->addr->value, ethertype, device->mtu);793 (uint8_t *) &device->addr.address, ethertype, device->mtu); 816 794 if (rc != EOK) { 817 795 /* Release invalid packet */ … … 825 803 next = pq_next(next); 826 804 } 827 } while (next);805 } while (next); 828 806 829 807 /* Send packet queue */ 830 if (packet) { 831 netif_send_msg(device->sess, device_id, packet, 832 SERVICE_ETHERNET); 833 } 834 808 if (packet) 809 nic_send_message(device->sess, packet_get_id(packet)); 810 835 811 fibril_rwlock_read_unlock(ð_globals.devices_lock); 836 812 return EOK; 837 813 } 838 814 815 static int eth_addr_changed(nic_device_id_t device_id) 816 { 817 nic_address_t address; 818 size_t length; 819 ipc_callid_t data_callid; 820 if (!async_data_write_receive(&data_callid, &length)) { 821 async_answer_0(data_callid, EINVAL); 822 return EINVAL; 823 } 824 if (length > sizeof (nic_address_t)) { 825 async_answer_0(data_callid, ELIMIT); 826 return ELIMIT; 827 } 828 if (async_data_write_finalize(data_callid, &address, length) != EOK) { 829 return EINVAL; 830 } 831 832 fibril_rwlock_write_lock(ð_globals.devices_lock); 833 /* An existing device? */ 834 eth_device_t *device = eth_devices_find(ð_globals.devices, device_id); 835 if (device) { 836 printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n", 837 device_id, ARGSMAC(device->addr.address), ARGSMAC(address.address)); 838 memcpy(&device->addr, &address, sizeof (nic_address_t)); 839 fibril_rwlock_write_unlock(ð_globals.devices_lock); 840 841 /* Notify all upper layer modules */ 842 fibril_rwlock_read_lock(ð_globals.protos_lock); 843 int index; 844 for (index = 0; index < eth_protos_count(ð_globals.protos); index++) { 845 eth_proto_t *proto = eth_protos_get_index(ð_globals.protos, index); 846 if (proto->sess != NULL) { 847 il_addr_changed_msg(proto->sess, device->device_id, 848 ETH_ADDR, address.address); 849 } 850 } 851 852 fibril_rwlock_read_unlock(ð_globals.protos_lock); 853 return EOK; 854 } else { 855 return ENOENT; 856 } 857 } 858 839 859 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 840 860 ipc_call_t *answer, size_t *answer_count) 841 861 { 842 measured_string_t *address;843 862 packet_t *packet; 844 863 size_t addrlen; … … 861 880 case NET_NIL_DEVICE: 862 881 return eth_device_message(IPC_GET_DEVICE(*call), 863 IPC_GET_ SERVICE(*call), IPC_GET_MTU(*call));882 IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call)); 864 883 case NET_NIL_SEND: 865 884 rc = packet_translate_remote(eth_globals.net_sess, &packet, … … 867 886 if (rc != EOK) 868 887 return rc; 888 869 889 return eth_send_message(IPC_GET_DEVICE(*call), packet, 870 890 IPC_GET_SERVICE(*call)); … … 874 894 if (rc != EOK) 875 895 return rc; 896 876 897 IPC_SET_ADDR(*answer, addrlen); 877 898 IPC_SET_PREFIX(*answer, prefix); … … 879 900 IPC_SET_SUFFIX(*answer, suffix); 880 901 *answer_count = 4; 902 881 903 return EOK; 882 904 case NET_NIL_ADDR: 883 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR, 884 &address); 905 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR); 885 906 if (rc != EOK) 886 907 return rc; 887 return measured_strings_reply(address, 1); 908 909 IPC_SET_ADDR(*answer, ETH_ADDR); 910 *answer_count = 1; 911 912 return EOK; 888 913 case NET_NIL_BROADCAST_ADDR: 889 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR, 890 &address); 914 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR); 891 915 if (rc != EOK) 892 return EOK; 893 return measured_strings_reply(address, 1); 916 return rc; 917 918 IPC_SET_ADDR(*answer, ETH_ADDR); 919 *answer_count = 1; 920 921 return EOK; 922 case NET_NIL_DEVICE_STATE: 923 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call)); 924 async_answer_0(callid, EOK); 925 return EOK; 926 case NET_NIL_RECEIVED: 927 rc = packet_translate_remote(eth_globals.net_sess, &packet, 928 IPC_GET_ARG2(*call)); 929 if (rc == EOK) 930 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet); 931 932 async_answer_0(callid, (sysarg_t) rc); 933 return rc; 934 case NET_NIL_ADDR_CHANGED: 935 rc = eth_addr_changed(IPC_GET_DEVICE(*call)); 936 async_answer_0(callid, (sysarg_t) rc); 937 return rc; 894 938 } 895 939 -
uspace/srv/net/nil/eth/eth.h
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 43 44 #include <net/device.h> 44 45 #include <adt/measured_strings.h> 46 #include <devman.h> 45 47 46 48 /** Ethernet address length. */ … … 220 222 struct eth_device { 221 223 /** Device identifier. */ 222 device_id_t device_id;223 /** Device driver service.*/224 services_t service;224 nic_device_id_t device_id; 225 /** Device handle */ 226 devman_handle_t handle; 225 227 /** Driver session. */ 226 228 async_sess_t *sess; … … 236 238 237 239 /** Actual device hardware address. */ 238 measured_string_t *addr; 239 240 /** Actual device hardware address data. */ 241 uint8_t *addr_data; 240 nic_address_t addr; 242 241 }; 243 242 … … 270 269 271 270 /** Broadcast device hardware address. */ 272 measured_string_t *broadcast_addr;271 uint8_t broadcast_addr[ETH_ADDR]; 273 272 }; 274 273 -
uspace/srv/net/nil/nildummy/nildummy.c
r8367d1d rd7ff048 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 -
uspace/srv/net/nil/nildummy/nildummy.h
r8367d1d rd7ff048 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 41 42 #include <fibril_synch.h> 42 43 #include <ipc/services.h> 44 #include <ipc/devman.h> 43 45 #include <net/device.h> 44 46 #include <adt/measured_strings.h> … … 76 78 struct nildummy_device { 77 79 /** Device identifier. */ 78 device_id_t device_id; 79 80 /** Device driver service. */ 81 services_t service; 82 80 nic_device_id_t device_id; 81 /** Device driver handle. */ 82 devman_handle_t handle; 83 83 /** Driver session. */ 84 84 async_sess_t *sess; … … 88 88 89 89 /** Actual device hardware address. */ 90 measured_string_t *addr; 91 92 /** Actual device hardware address data. */ 93 uint8_t *addr_data; 90 nic_address_t addr; 91 /** Actual device hardware address length. */ 92 size_t addr_len; 94 93 }; 95 94 -
uspace/srv/net/tl/icmp/icmp.c
r8367d1d rd7ff048 753 753 return rc; 754 754 755 rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call), 755 rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call), 756 756 ICMP_GET_TIMEOUT(*call), ICMP_GET_TTL(*call), 757 757 ICMP_GET_TOS(*call), ICMP_GET_DONT_FRAGMENT(*call), -
uspace/srv/net/tl/tcp/tcp.c
r8367d1d rd7ff048 169 169 static int tcp_release_after_timeout(void *); 170 170 171 static int tcp_process_packet( device_id_t, packet_t *, services_t);171 static int tcp_process_packet(nic_device_id_t, packet_t *, services_t); 172 172 static int tcp_connect_core(socket_core_t *, socket_cores_t *, 173 173 struct sockaddr *, socklen_t); … … 177 177 size_t); 178 178 static packet_t *tcp_get_packets_to_send(socket_core_t *, tcp_socket_data_t *); 179 static void tcp_send_packets( device_id_t, packet_t *);179 static void tcp_send_packets(nic_device_id_t, packet_t *); 180 180 181 181 static void tcp_process_acknowledgement(socket_core_t *, tcp_socket_data_t *, … … 205 205 static void tcp_queue_received_end_of_data(socket_core_t *socket); 206 206 207 static int tcp_received_msg( device_id_t, packet_t *, services_t, services_t);207 static int tcp_received_msg(nic_device_id_t, packet_t *, services_t, services_t); 208 208 static int tcp_process_client_messages(async_sess_t *, ipc_callid_t, 209 209 ipc_call_t); … … 220 220 tcp_globals_t tcp_globals; 221 221 222 int tcp_received_msg( device_id_t device_id, packet_t *packet,222 int tcp_received_msg(nic_device_id_t device_id, packet_t *packet, 223 223 services_t receiver, services_t error) 224 224 { … … 238 238 } 239 239 240 int tcp_process_packet( device_id_t device_id, packet_t *packet, services_t error)240 int tcp_process_packet(nic_device_id_t device_id, packet_t *packet, services_t error) 241 241 { 242 242 size_t length; … … 1251 1251 bzero(socket_data, sizeof(*socket_data)); 1252 1252 socket_data->state = TCP_SOCKET_INITIAL; 1253 socket_data->device_id = DEVICE_INVALID_ID;1253 socket_data->device_id = NIC_DEVICE_INVALID_ID; 1254 1254 socket_data->window = NET_DEFAULT_TCP_WINDOW; 1255 1255 socket_data->treshold = socket_data->window; … … 1335 1335 } 1336 1336 if (tl_get_ip_packet_dimension(tcp_globals.ip_sess, 1337 &tcp_globals.dimensions, DEVICE_INVALID_ID,1337 &tcp_globals.dimensions, NIC_DEVICE_INVALID_ID, 1338 1338 &packet_dimension) == EOK) { 1339 1339 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, … … 1651 1651 /* Sent packet? */ 1652 1652 packet = pq_find(socket_data->outgoing, sequence_number); 1653 printf("retransmit %d\n", packet_get_id(packet));1654 1653 if (packet) { 1655 1654 pq_get_order(packet, NULL, &data_length); … … 1790 1789 1791 1790 /* Send the packet */ 1792 printf("connecting %d\n", packet_get_id(packet));1793 1791 tcp_send_packets(socket_data->device_id, packet); 1794 1792 … … 2004 2002 } 2005 2003 2006 void tcp_send_packets( device_id_t device_id, packet_t *packet)2004 void tcp_send_packets(nic_device_id_t device_id, packet_t *packet) 2007 2005 { 2008 2006 packet_t *next; -
uspace/srv/net/tl/tcp/tcp.h
r8367d1d rd7ff048 182 182 183 183 /** Device identifier. */ 184 device_id_t device_id;184 nic_device_id_t device_id; 185 185 186 186 /** -
uspace/srv/net/tl/udp/udp.c
r8367d1d rd7ff048 124 124 * ip_client_process_packet() function. 125 125 */ 126 static int udp_process_packet( device_id_t device_id, packet_t *packet,126 static int udp_process_packet(nic_device_id_t device_id, packet_t *packet, 127 127 services_t error) 128 128 { … … 322 322 * udp_process_packet() function. 323 323 */ 324 static int udp_received_msg( device_id_t device_id, packet_t *packet,324 static int udp_received_msg(nic_device_id_t device_id, packet_t *packet, 325 325 services_t receiver, services_t error) 326 326 { … … 499 499 void *ip_header; 500 500 size_t headerlen; 501 device_id_t device_id;501 nic_device_id_t device_id; 502 502 packet_dimension_t *packet_dimension; 503 503 size_t size; … … 617 617 htons(flip_checksum(compact_checksum(checksum))); 618 618 free(ip_header); 619 } else { 620 device_id = DEVICE_INVALID_ID; 621 } 619 } else 620 device_id = NIC_DEVICE_INVALID_ID; 622 621 623 622 /* Prepare the first packet fragment */ … … 806 805 size = MAX_UDP_FRAGMENT_SIZE; 807 806 if (tl_get_ip_packet_dimension(udp_globals.ip_sess, 808 &udp_globals.dimensions, DEVICE_INVALID_ID,807 &udp_globals.dimensions, NIC_DEVICE_INVALID_ID, 809 808 &packet_dimension) == EOK) { 810 809 if (packet_dimension->content < size)
Note:
See TracChangeset
for help on using the changeset viewer.