Changeset d7ff048 in mainline for uspace/srv


Ignore:
Timestamp:
2011-10-08T13:08:53Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
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.
Message:

Merge mainline changes

Location:
uspace/srv
Files:
4 deleted
21 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r8367d1d rd7ff048  
    794794        case EOK:
    795795                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);
    796799                break;
    797800        case ENOENT:
     
    10661069       
    10671070        link = hash_table_find(&tree->devman_devices, &key);
     1071        if (link == NULL)
     1072                return NULL;
     1073       
    10681074        return hash_table_get_instance(link, dev_node_t, devman_dev);
    10691075}
  • uspace/srv/devman/main.c

    r8367d1d rd7ff048  
    634634                                fibril_rwlock_read_unlock(&device_tree.rwlock);
    635635                                dev_del_ref(dev);
     636                                if (gone_rc == EOK)
     637                                        gone_rc = ENOTSUP;
     638                                async_answer_0(callid, gone_rc);
    636639                                return;
    637640                        }
  • uspace/srv/fs/fat/fat.h

    r8367d1d rd7ff048  
    141141} __attribute__ ((packed)) fat_bs_t;
    142142
     143#define FAT32_FSINFO_SIG1       "RRaA"
     144#define FAT32_FSINFO_SIG2       "rrAa"
     145#define FAT32_FSINFO_SIG3       "\x00\x00\x55\xaa"
     146
     147typedef 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
    143157typedef enum {
    144158        FAT_INVALID,
  • uspace/srv/fs/fat/fat_ops.c

    r8367d1d rd7ff048  
    10251025}
    10261026
     1027static 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
    10271058static int fat_unmounted(service_id_t service_id)
    10281059{
    10291060        fs_node_t *fn;
    10301061        fat_node_t *nodep;
    1031         int rc;
     1062        fat_bs_t *bs;
     1063        int rc;
     1064
     1065        bs = block_bb_get(service_id);
    10321066
    10331067        rc = fat_root_get(&fn, service_id);
     
    10431077                (void) fat_node_put(fn);
    10441078                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);
    10451086        }
    10461087
  • uspace/srv/hw/irc/apic/apic.c

    r8367d1d rd7ff048  
    206206        }
    207207
    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);
    210212                return false;   
     213        }
    211214       
    212215        async_set_client_connection(apic_connection);
  • uspace/srv/loc/loc.c

    r8367d1d rd7ff048  
    12881288        cat = category_new("virtual");
    12891289        categ_dir_add_cat(&cdir, cat);
    1290 
    1291 
     1290       
     1291        cat = category_new("nic");
     1292        categ_dir_add_cat(&cdir, cat);
     1293       
    12921294        return true;
    12931295}
  • uspace/srv/net/cfg/lo.nic

    r8367d1d rd7ff048  
    33NAME=lo
    44
    5 NETIF=lo
     5HWPATH=/virt/lo/port0
    66NIL=nildummy
    77IL=ip
  • uspace/srv/net/cfg/ne2k.nic

    r8367d1d rd7ff048  
    1 # DP8390 (NE2k) configuration
     1# NE2000 configuration
    22
    33NAME=ne2k
    44
    5 NETIF=ne2000
     5HWPATH=/hw/pci0/00:01.0/ne2k/port0
    66NIL=eth
    77IL=ip
    8 
    9 IRQ=5
    10 IO=300
    118
    129# 8023_2_LSAP, 8023_2_SNAP
     
    1714IP_ADDR=10.0.2.15
    1815IP_ROUTING=yes
    19 IP_NETMASK=255.255.255.0
     16IP_NETMASK=255.255.255.240
    2017IP_BROADCAST=10.0.2.255
    2118IP_GATEWAY=10.0.2.2
  • uspace/srv/net/il/arp/arp.c

    r8367d1d rd7ff048  
    174174                    count);
    175175               
    176                 if (device) {
     176                if (device)
    177177                        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                 }
    184178        }
    185179       
     
    190184}
    191185
    192 static int arp_clear_address_req(device_id_t device_id, services_t protocol,
    193     measured_string_t *address)
     186static int arp_clear_address_req(nic_device_id_t device_id,
     187    services_t protocol, measured_string_t *address)
    194188{
    195189        fibril_mutex_lock(&arp_globals.lock);
     
    218212}
    219213
    220 static int arp_clear_device_req(device_id_t device_id)
     214static int arp_clear_device_req(nic_device_id_t device_id)
    221215{
    222216        fibril_mutex_lock(&arp_globals.lock);
     
    289283 *
    290284 */
    291 static int arp_receive_message(device_id_t device_id, packet_t *packet)
     285static int arp_receive_message(nic_device_id_t device_id, packet_t *packet)
    292286{
    293287        int rc;
     
    365359                        memcpy(src_proto, proto->addr->value,
    366360                            header->protocol_length);
    367                         memcpy(src_hw, device->addr->value,
     361                        memcpy(src_hw, device->addr,
    368362                            device->packet_dimension.addr_len);
    369363                        memcpy(des_hw, trans->hw_addr->value,
     
    393387 *
    394388 */
    395 static int arp_mtu_changed_message(device_id_t device_id, size_t mtu)
     389static int arp_mtu_changed_message(nic_device_id_t device_id, size_t mtu)
    396390{
    397391        fibril_mutex_lock(&arp_globals.lock);
     
    409403        printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu);
    410404       
     405        return EOK;
     406}
     407
     408static 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);
    411437        return EOK;
    412438}
     
    456482                        async_answer_0(iid, (sysarg_t) rc);
    457483                        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);
    458487               
    459488                default:
     
    483512 *
    484513 */
    485 static int arp_device_message(device_id_t device_id, services_t service,
     514static int arp_device_message(nic_device_id_t device_id, services_t service,
    486515    services_t protocol, measured_string_t *address)
    487516{
     
    586615               
    587616                /* 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) {
    591620                        fibril_mutex_unlock(&arp_globals.lock);
    592621                        arp_protos_destroy(&device->protos, free);
    593622                        free(device);
    594                         return rc;
    595                 }
     623                        return len;
     624                }
     625               
     626                device->addr_len = len;
    596627               
    597628                /* 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);
    604633                        arp_protos_destroy(&device->protos, free);
    605634                        free(device);
    606                         return rc;
    607                 }
     635                        return len;
     636                }
     637               
     638                device->broadcast_addr_len = len;
    608639               
    609640                rc = arp_cache_add(&arp_globals.cache, device->device_id,
     
    611642                if (rc != EOK) {
    612643                        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);
    617644                        arp_protos_destroy(&device->protos, free);
    618645                        free(device);
     
    640667}
    641668
    642 static int arp_send_request(device_id_t device_id, services_t protocol,
     669static int arp_send_request(nic_device_id_t device_id, services_t protocol,
    643670    measured_string_t *target, arp_device_t *device, arp_proto_t *proto)
    644671{
    645672        /* 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);
    647674        if (length > device->packet_dimension.content)
    648675                return ELIMIT;
     
    661688       
    662689        header->hardware = htons(device->hardware);
    663         header->hardware_length = (uint8_t) device->addr->length;
     690        header->hardware_length = (uint8_t) device->addr_len;
    664691        header->protocol = htons(protocol_map(device->service, protocol));
    665692        header->protocol_length = (uint8_t) proto->addr->length;
     
    667694       
    668695        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;
    673699        memcpy(((uint8_t *) header) + length, proto->addr->value,
    674700            proto->addr->length);
    675701        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;
    678704        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);
    682708        if (rc != EOK) {
    683709                pq_release_remote(arp_globals.net_sess, packet_get_id(packet));
     
    704730 *
    705731 */
    706 static int arp_translate_message(device_id_t device_id, services_t protocol,
     732static int arp_translate_message(nic_device_id_t device_id, services_t protocol,
    707733    measured_string_t *target, measured_string_t **translation)
    708734{
  • uspace/srv/net/il/arp/arp.h

    r8367d1d rd7ff048  
    9292struct arp_device {
    9393        /** 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;
    9797        /** 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;
    101101        /** Device identifier. */
    102         device_id_t device_id;
     102        nic_device_id_t device_id;
    103103        /** Hardware type. */
    104104        hw_type_t hardware;
  • uspace/srv/net/il/ip/ip.c

    r8367d1d rd7ff048  
    354354        ip_netif->routing = NET_DEFAULT_IP_ROUTING;
    355355        configuration = &names[0];
    356 
     356       
    357357        /* Get configuration */
    358358        rc = net_get_device_conf_req(ip_globals.net_sess, ip_netif->device_id,
     
    406406                        return ENOTSUP;
    407407                }
    408 
     408               
    409409                if (configuration[6].value) {
    410410                        ip_netif->arp = get_running_module(&ip_globals.modules,
     
    417417                        }
    418418                }
     419               
    419420                if (configuration[7].value)
    420421                        ip_netif->routing = (configuration[7].value[0] == 'y');
    421 
     422               
    422423                net_free_settings(configuration, data);
    423424        }
    424 
     425       
    425426        /* Bind netif service which also initializes the device */
    426427        ip_netif->sess = nil_bind_service(ip_netif->service,
     
    432433                return ENOENT;
    433434        }
    434 
     435       
    435436        /* Has to be after the device netif module initialization */
    436437        if (ip_netif->arp) {
     
    448449                }
    449450        }
    450 
     451       
    451452        /* Get packet dimensions */
    452453        rc = nil_packet_size_req(ip_netif->sess, ip_netif->device_id,
     
    461462                ip_netif->packet_dimension.content = IP_MIN_CONTENT;
    462463        }
    463 
     464       
    464465        index = ip_netifs_add(&ip_globals.netifs, ip_netif->device_id, ip_netif);
    465466        if (index < 0)
     
    478479                printf("%s: Default gateway (%s)\n", NAME, defgateway);
    479480        }
    480 
     481       
    481482        return EOK;
    482483}
    483484
    484 static int ip_device_req_local(device_id_t device_id, services_t netif)
     485static int ip_device_req_local(nic_device_id_t device_id, services_t netif)
    485486{
    486487        ip_netif_t *ip_netif;
     
    498499                return rc;
    499500        }
    500 
     501       
    501502        ip_netif->device_id = device_id;
    502503        ip_netif->service = netif;
    503         ip_netif->state = NETIF_STOPPED;
    504 
     504        ip_netif->state = NIC_STATE_STOPPED;
     505       
    505506        fibril_rwlock_write_lock(&ip_globals.netifs_lock);
    506507
     
    594595        while (index >= 0) {
    595596                netif = ip_netifs_get_index(&ip_globals.netifs, index);
    596                 if (netif && (netif->state == NETIF_ACTIVE)) {
     597                if (netif && (netif->state == NIC_STATE_ACTIVE)) {
    597598                        route = ip_netif_find_route(netif, destination);
    598599                        if (route)
     
    11421143}
    11431144
    1144 static int ip_send_msg_local(device_id_t device_id, packet_t *packet,
     1145static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet,
    11451146    services_t sender, services_t error)
    11461147{
     
    12581259 * @return              ENOENT if device is not found.
    12591260 */
    1260 static int ip_device_state_message(device_id_t device_id, device_state_t state)
     1261static int ip_device_state_message(nic_device_id_t device_id,
     1262    nic_device_state_t state)
    12611263{
    12621264        ip_netif_t *netif;
     
    12721274        fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    12731275
    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));
    12751278
    12761279        return EOK;
     
    13121315 *                      tl_received_msg() function.
    13131316 */
    1314 static int ip_deliver_local(device_id_t device_id, packet_t *packet,
     1317static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet,
    13151318    ip_header_t *header, services_t error)
    13161319{
     
    14131416 *                      is disabled.
    14141417 */
    1415 static int ip_process_packet(device_id_t device_id, packet_t *packet)
     1418static int ip_process_packet(nic_device_id_t device_id, packet_t *packet)
    14161419{
    14171420        ip_header_t *header;
     
    15141517 *
    15151518 */
    1516 static int ip_packet_size_message(device_id_t device_id, size_t *addr_len,
     1519static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len,
    15171520    size_t *prefix, size_t *content, size_t *suffix)
    15181521{
     
    15721575 * @return              ENOENT if device is not found.
    15731576 */
    1574 static int ip_mtu_changed_message(device_id_t device_id, size_t mtu)
     1577static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu)
    15751578{
    15761579        ip_netif_t *netif;
     
    16291632                        async_answer_0(iid, (sysarg_t) rc);
    16301633                        break;
    1631                
     1634                case NET_IL_ADDR_CHANGED:
     1635                        async_answer_0(iid, (sysarg_t) EOK);
     1636                        break;
     1637
    16321638                default:
    16331639                        async_answer_0(iid, (sysarg_t) ENOTSUP);
     
    16891695}
    16901696
    1691 static int ip_add_route_req_local(device_id_t device_id, in_addr_t address,
     1697static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address,
    16921698    in_addr_t netmask, in_addr_t gateway)
    16931699{
     
    17231729}
    17241730
    1725 static int ip_set_gateway_req_local(device_id_t device_id, in_addr_t gateway)
     1731static int ip_set_gateway_req_local(nic_device_id_t device_id,
     1732    in_addr_t gateway)
    17261733{
    17271734        ip_netif_t *netif;
     
    17571764 *
    17581765 */
    1759 static int ip_received_error_msg_local(device_id_t device_id,
     1766static int ip_received_error_msg_local(nic_device_id_t device_id,
    17601767    packet_t *packet, services_t target, services_t error)
    17611768{
     
    18181825static int ip_get_route_req_local(ip_protocol_t protocol,
    18191826    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)
    18211828{
    18221829        struct sockaddr_in *address_in;
     
    19091916        size_t suffix;
    19101917        size_t content;
    1911         device_id_t device_id;
     1918        nic_device_id_t device_id;
    19121919        int rc;
    19131920       
  • uspace/srv/net/il/ip/ip.h

    r8367d1d rd7ff048  
    9292        in_addr_t broadcast;
    9393        /** Device identifier. */
    94         device_id_t device_id;
     94        nic_device_id_t device_id;
    9595        /** Indicates whether using DHCP. */
    9696        int dhcp;
     
    108108        services_t service;
    109109        /** Device state. */
    110         device_state_t state;
     110        nic_device_state_t state;
    111111};
    112112
  • uspace/srv/net/net/Makefile

    r8367d1d rd7ff048  
    3030USPACE_PREFIX = ../../..
    3131ROOT_PATH = $(USPACE_PREFIX)/..
    32 LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBPACKET_PREFIX)/libpacket.a
    33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBPACKET_PREFIX)/include
     32LIBS = $(LIBNET_PREFIX)/libnet.a
     33EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
    3434
    3535COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
     
    4343SOURCES = \
    4444        net.c \
    45         net_standalone.c
     45        packet_server.c
    4646
    4747include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/net/net.c

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3132 */
    3233
    33 /** @file
    34  * Networking subsystem central module implementation.
    35  *
    36  */
    37 
     34#include <assert.h>
    3835#include <async.h>
    3936#include <ctype.h>
    4037#include <ddi.h>
    4138#include <errno.h>
     39#include <str_error.h>
    4240#include <malloc.h>
    4341#include <stdio.h>
    4442#include <str.h>
     43#include <devman.h>
    4544#include <str_error.h>
    4645#include <ns.h>
     
    4948#include <ipc/net_net.h>
    5049#include <ipc/il.h>
     50#include <ipc/ip.h>
    5151#include <ipc/nil.h>
    52 #include <net/modules.h>
    5352#include <net/packet.h>
    5453#include <net/device.h>
     
    5756#include <adt/measured_strings.h>
    5857#include <adt/module_map.h>
    59 #include <netif_remote.h>
    6058#include <nil_remote.h>
    6159#include <net_interface.h>
    6260#include <ip_interface.h>
     61#include <device/nic.h>
     62#include <dirent.h>
     63#include <fcntl.h>
     64#include <cfg.h>
    6365#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
    7069
    7170/** Networking module global data. */
     
    7473GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
    7574DEVICE_MAP_IMPLEMENT(netifs, netif_t);
    76 
    77 static int startup(void);
    7875
    7976/** Add the configured setting to the configuration map.
     
    8784 *
    8885 */
    89 int add_configuration(measured_strings_t *configuration, const uint8_t *name,
    90     const uint8_t *value)
     86static int add_configuration(measured_strings_t *configuration,
     87    const uint8_t *name, const uint8_t *value)
    9188{
    9289        int rc;
     
    109106/** Generate new system-unique device identifier.
    110107 *
    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 */
     111static nic_device_id_t generate_new_device_id(void)
    114112{
    115113        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;
    177114}
    178115
     
    182119        printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
    183120       
    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);
    192128                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;
    226139                }
    227140        }
    228141       
    229         fclose(cfg);
     142        cfg_unload(&cfg);
    230143        return EOK;
    231144}
     
    255168        return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE,
    256169            &net_globals.configuration);
    257 }
    258 
    259 /** Initialize the networking module.
    260  *
    261  * @param[in] client_connection The client connection processing
    262  *                              function. The module skeleton propagates
    263  *                              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 service
    311  * and starts the async manager, processing IPC messages
    312  * in an infinite loop.
    313  *
    314  * @param[in] client_connection The client connection
    315  *                              processing function. The
    316  *                              module skeleton propagates
    317  *                              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;
    351170}
    352171
     
    364183 */
    365184static 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;
    370189       
    371190        size_t index;
     
    389208}
    390209
    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 
     210static int net_get_device_conf(nic_device_id_t device_id,
     211    measured_string_t *configuration, size_t count)
     212{
    406213        netif_t *netif = netifs_find(&net_globals.netifs, device_id);
    407214        if (netif)
    408                 return net_get_conf(&netif->configuration, *configuration, count, data);
     215                return net_get_conf(&netif->configuration, configuration, count);
    409216        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
     220static 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
     250static 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
     264static 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);
    415271}
    416272
     
    431287 *
    432288 */
    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;
     289static 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;
    446299        }
    447300       
    448301        /* 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);
    450304        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);
    452307                if (!netif->nil) {
    453                         fprintf(stderr, "%s: Failed to start network interface layer '%s'\n",
     308                        printf("%s: Unable to connect to network interface layer '%s'\n",
    454309                            NAME, setting->value);
    455310                        return EINVAL;
     
    459314       
    460315        /* 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);
    463320        if (!netif->il) {
    464                 fprintf(stderr, "%s: Failed to start internet layer '%s'\n",
     321                printf("%s: Unable to connect to internet layer '%s'\n",
    465322                    NAME, setting->value);
    466323                return EINVAL;
    467324        }
    468325       
    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        
    480326        /* Network interface layer startup */
    481         services_t internet_service;
     327        int rc;
     328        services_t nil_service;
    482329        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);
    484332                if (!setting)
    485333                        setting = measured_strings_find(&net_globals.configuration,
    486334                            (uint8_t *) CONF_MTU, 0);
    487335               
    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
     368static 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
     397static 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]);
    491407                if (rc != EOK)
    492408                        return rc;
    493                
    494                 internet_service = netif->nil->service;
    495         } else
    496                 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 interfaces
    571                  * 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);
    600409        }
    601410       
     
    618427 *
    619428 */
    620 int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
    621     size_t *answer_count)
     429static int net_message(ipc_callid_t callid, ipc_call_t *call,
     430    ipc_call_t *answer, size_t *answer_count)
    622431{
    623432        measured_string_t *strings;
    624433        uint8_t *data;
    625434        int rc;
     435        size_t count;
    626436       
    627437        *answer_count = 0;
     
    636446                if (rc != EOK)
    637447                        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));
    643451               
    644452                rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
    645453                free(strings);
     454                free(data);
    646455                return rc;
    647456        case NET_NET_GET_CONF:
     
    650459                if (rc != EOK)
    651460                        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));
    656463               
    657464                rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
    658465                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        }
    665488}
    666489
     
    684507                /* Clear the answer structure */
    685508                ipc_call_t answer;
    686                 size_t answer_count;
    687                 refresh_answer(&answer, &answer_count);
     509                size_t count;
     510                refresh_answer(&answer, &count);
    688511               
    689512                /* Fetch the next message */
     
    692515               
    693516                /* 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);
    695522               
    696523                /* End if told to either by the message or the processing result */
     
    699526               
    700527                /* Answer the message */
    701                 answer_call(callid, res, &answer, answer_count);
     528                answer_call(callid, res, &answer, count);
    702529        }
    703530}
     
    705532int main(int argc, char *argv[])
    706533{
    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;
    708702}
    709703
  • uspace/srv/net/net/net.h

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3132 */
    3233
    33 /** @file
    34  * Networking subsystem central module.
    35  *
    36  */
    37 
    3834#ifndef NET_NET_H_
    3935#define NET_NET_H_
     
    4541#include <adt/module_map.h>
    4642#include <net/packet.h>
     43#include <devman.h>
    4744
    48 /** @name Modules definitions
    49  * @{
    50  */
    51 
    52 #define NE2000_FILENAME  "/srv/ne2000"
    53 #define NE2000_NAME      "ne2000"
     45#define NAME  "net"
    5446
    5547#define ETHERNET_FILENAME  "/srv/eth"
     
    5850#define IP_FILENAME  "/srv/ip"
    5951#define IP_NAME      "ip"
    60 
    61 #define LO_FILENAME  "/srv/lo"
    62 #define LO_NAME      "lo"
    6352
    6453#define NILDUMMY_FILENAME  "/srv/nildummy"
     
    7766#define CONF_MTU    "MTU"    /**< Maximum transmission unit configuration label. */
    7867#define CONF_NAME   "NAME"   /**< Network interface name configuration label. */
    79 #define CONF_NETIF  "NETIF"  /**< Network interface module name configuration label. */
     68#define CONF_HWPATH "HWPATH" /**< Network interface hardware pathname label. */
    8069#define CONF_NIL    "NIL"    /**< Network interface layer module name configuration label. */
    8170
     
    8574#define CONF_DIR           "/cfg/net"  /**< Configuration directory. */
    8675#define CONF_GENERAL_FILE  "general"   /**< General configuration file. */
     76#define CONF_EXT           ".nic"      /**< Extension for NIC's configuration files. */
    8777
    8878/** Configuration settings.
     
    9888 */
    9989typedef 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;
    10196       
    10297        /** 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. */
    104100       
    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. */
    109103} netif_t;
    110104
     
    124118        modules_t modules;                 /**< Available modules. */
    125119       
    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;
    128122       
    129123        /** Present network interfaces. */
     
    131125} net_globals_t;
    132126
    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 
    139127#endif
    140128
  • uspace/srv/net/net/packet_server.c

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3536 */
    3637
    37 #include <packet_server.h>
    3838#include <align.h>
    3939#include <assert.h>
    4040#include <async.h>
    4141#include <errno.h>
     42#include <str_error.h>
     43#include <stdio.h>
    4244#include <fibril_synch.h>
    4345#include <unistd.h>
     
    4850#include <net/packet_header.h>
    4951
     52#include "packet_server.h"
     53
     54#define PACKET_SERVER_PROFILE 1
     55
     56/** Number of queues cacheing the unused packets */
    5057#define FREE_QUEUES_COUNT       7
     58/** Maximum number of packets in each queue */
     59#define FREE_QUEUE_MAX_LENGTH   16
    5160
    5261/** The default address length reserved for new packets. */
     
    5867/** The default suffix reserved for new packets. */
    5968#define DEFAULT_SUFFIX          64
     69
     70/** The queue with unused packets */
     71typedef 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;
    6076
    6177/** Packet server global data. */
     
    6480        fibril_mutex_t lock;
    6581        /** 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];
    7483       
    7584        /** Total packets allocated. */
    76         unsigned int count;
     85        packet_id_t next_id;
    7786} ps_globals = {
    7887        .lock = FIBRIL_MUTEX_INITIALIZER(ps_globals.lock),
    79         .free = {
    80                 NULL,
    81                 NULL,
    82                 NULL,
    83                 NULL,
    84                 NULL,
    85                 NULL,
    86                 NULL
     88        .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},
    8796        },
    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
    9898};
    9999
     
    107107 * @param[in] max_suffix The maximal suffix length in bytes.
    108108 */
    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)
     109static void packet_init(packet_t *packet,
     110        size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix)
    112111{
    113112        /* Clear the packet content */
     
    120119        packet->previous = 0;
    121120        packet->next = 0;
     121        packet->offload_info = 0;
     122        packet->offload_mask = 0;
    122123        packet->addr_len = 0;
    123124        packet->src_addr = sizeof(packet_t);
     
    127128        packet->data_start = packet->dest_addr + addr_len + packet->max_prefix;
    128129        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 */
     137static void packet_dealloc(packet_t *packet)
     138{
     139        pm_remove(packet);
     140        munmap(packet, packet->length);
    129141}
    130142
     
    141153 * @return              NULL if there is not enough memory left.
    142154 */
    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)
     155static packet_t *packet_alloc(size_t length, size_t addr_len,
     156        size_t max_prefix, size_t max_content, size_t max_suffix)
    146157{
    147158        packet_t *packet;
    148159        int rc;
    149160
     161        /* Global lock is locked */
    150162        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
    153166        packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE,
    154             MAP_SHARED | MAP_ANONYMOUS, 0, 0);
     167                MAP_SHARED | MAP_ANONYMOUS, 0, 0);
    155168        if (packet == MAP_FAILED)
    156169                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
    160179        packet->length = length;
    161180        packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
     
    163182        rc = pm_add(packet);
    164183        if (rc != EOK) {
    165                 munmap(packet, packet->length);
     184                packet_dealloc(packet);
    166185                return NULL;
    167186        }
     
    184203 * @return              NULL if there is not enough memory left.
    185204 */
    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        
     205static 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
    193214        fibril_mutex_lock(&ps_globals.lock);
    194215       
     
    197218       
    198219        for (index = 0; index < FREE_QUEUES_COUNT; index++) {
    199                 if ((length > ps_globals.sizes[index]) &&
    200                     (index < FREE_QUEUES_COUNT - 1))
     220                if ((length > ps_globals.free_queues[index].packet_size) &&
     221                        (index < FREE_QUEUES_COUNT - 1))
    201222                        continue;
    202223               
    203                 packet = ps_globals.free[index];
     224                packet = ps_globals.free_queues[index].first;
    204225                while (packet_is_valid(packet) && (packet->length < length))
    205226                        packet = pm_find(packet->next);
    206227               
    207228                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 {
    211233                                pq_detach(packet);
     234                        }
    212235                       
    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);
    215237                        fibril_mutex_unlock(&ps_globals.lock);
    216238                       
     
    219241        }
    220242       
    221         packet = packet_create(length, addr_len, max_prefix, max_content,
    222             max_suffix);
     243        packet = packet_alloc(length, addr_len,
     244                max_prefix, max_content, max_suffix);
    223245       
    224246        fibril_mutex_unlock(&ps_globals.lock);
     
    240262
    241263        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++) {
    243265                ;
    244266        }
    245267       
    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);
    248271        assert(result == EOK);
    249272}
     
    328351        case NET_PACKET_CREATE_1:
    329352                packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX,
    330                     IPC_GET_CONTENT(*call), DEFAULT_SUFFIX);
     353                        IPC_GET_CONTENT(*call), DEFAULT_SUFFIX);
    331354                if (!packet)
    332355                        return ENOMEM;
     
    338361        case NET_PACKET_CREATE_4:
    339362                packet = packet_get_local(
    340                     ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ?
     363                        ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ?
    341364                    IPC_GET_ADDR_LEN(*call) : DEFAULT_ADDR_LEN),
    342365                    DEFAULT_PREFIX + IPC_GET_PREFIX(*call),
     
    352375        case NET_PACKET_GET:
    353376                packet = pm_find(IPC_GET_ID(*call));
    354                 if (!packet_is_valid(packet))
     377                if (!packet_is_valid(packet)) {
    355378                        return ENOENT;
     379                }
    356380                return packet_reply(packet);
    357381       
     
    371395}
    372396
     397int packet_server_init()
     398{
     399        return EOK;
     400}
     401
    373402/** @}
    374403 */
  • uspace/srv/net/net/packet_server.h

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    4243 */
    4344
    44 #ifndef LIBPACKET_PACKET_SERVER_H_
    45 #define LIBPACKET_PACKET_SERVER_H_
     45#ifndef NET_PACKET_SERVER_H_
     46#define NET_PACKET_SERVER_H_
    4647
    4748#include <ipc/common.h>
    4849
     50extern int packet_server_init(void);
    4951extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *,
    5052    size_t *);
  • uspace/srv/net/nil/eth/eth.c

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3637 */
    3738
     39#include <assert.h>
    3840#include <async.h>
    3941#include <malloc.h>
     
    5254#include <protocol_map.h>
    5355#include <net/device.h>
    54 #include <netif_remote.h>
    5556#include <net_interface.h>
    5657#include <il_remote.h>
     
    5859#include <packet_client.h>
    5960#include <packet_remote.h>
     61#include <device/nic.h>
    6062#include <nil_skel.h>
    6163#include "eth.h"
     
    167169INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    168170
    169 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     171int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
    170172{
    171173        int index;
     
    196198        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    197199        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);
    205202
    206203        rc = eth_devices_initialize(&eth_globals.devices);
     
    215212                eth_devices_destroy(&eth_globals.devices, free);
    216213        }
     214       
    217215out:
    218216        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    222220}
    223221
    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 */
     235static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,
    279236    size_t mtu)
    280237{
     
    301258        device = eth_devices_find(&eth_globals.devices, device_id);
    302259        if (device) {
    303                 if (device->service != service) {
     260                if (device->handle != handle) {
    304261                        printf("Device %d already exists\n", device->device_id);
    305262                        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    340297
    341298        device->device_id = device_id;
    342         device->service = service;
     299        device->handle = handle;
    343300        device->flags = 0;
    344301        if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
     
    377334       
    378335        /* 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);
    381338        if (device->sess == NULL) {
    382339                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    385342        }
    386343       
     344        nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id);
     345       
    387346        /* 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);
    390348        if (rc != EOK) {
    391349                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    399357        if (index < 0) {
    400358                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    401                 free(device->addr);
    402                 free(device->addr_data);
    403359                free(device);
    404360                return index;
    405361        }
    406362       
    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);
    413367
    414368        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    456410                fcs = (eth_fcs_t *) data + length - sizeof(eth_fcs_t);
    457411                length -= sizeof(eth_fcs_t);
    458         } else if(type <= ETH_MAX_CONTENT) {
     412        } else if (type <= ETH_MAX_CONTENT) {
    459413                /* Translate "LSAP" values */
    460414                if ((header->lsap.dsap == ETH_LSAP_GLSAP) &&
     
    462416                        /* Raw packet -- discard */
    463417                        return NULL;
    464                 } else if((header->lsap.dsap == ETH_LSAP_SNAP) &&
     418                } else if ((header->lsap.dsap == ETH_LSAP_SNAP) &&
    465419                    (header->lsap.ssap == ETH_LSAP_SNAP)) {
    466420                        /*
     
    469423                         */
    470424                        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) +
    473426                            sizeof(eth_header_snap_t);
    474427                } else {
    475428                        /* IEEE 802.3 + 802.2 LSAP */
    476429                        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);
    479431                }
    480432
     
    506458}
    507459
    508 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    509     services_t target)
     460int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet)
    510461{
    511462        eth_proto_t *proto;
     
    523474        flags = device->flags;
    524475        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    525        
    526476        fibril_rwlock_read_lock(&eth_globals.protos_lock);
     477       
    527478        do {
    528479                next = pq_detach(packet);
     
    537488                }
    538489                packet = next;
    539         } while(packet);
     490        } while (packet);
    540491
    541492        fibril_rwlock_read_unlock(&eth_globals.protos_lock);
     
    554505 * @return              ENOENT if there is no such device.
    555506 */
    556 static int eth_packet_space_message(device_id_t device_id, size_t *addr_len,
     507static int eth_packet_space_message(nic_device_id_t device_id, size_t *addr_len,
    557508    size_t *prefix, size_t *content, size_t *suffix)
    558509{
     
    579530}
    580531
    581 /** Returns the device hardware address.
     532/** Send the device hardware address.
    582533 *
    583534 * @param[in] device_id The device identifier.
    584535 * @param[in] type      Type of the desired address.
    585  * @param[out] address  The device hardware address.
    586536 * @return              EOK on success.
    587537 * @return              EBADMEM if the address parameter is NULL.
    588538 * @return              ENOENT if there no such device.
    589539 */
    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 {
     540static 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 {
    601550                fibril_rwlock_read_lock(&eth_globals.devices_lock);
    602551                device = eth_devices_find(&eth_globals.devices, device_id);
     
    605554                        return ENOENT;
    606555                }
    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       
     576end:
     577       
     578        if (type == ETH_LOCAL_ADDR)
    608579                fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    609         }
    610        
    611         return (*address) ? EOK : ENOENT;
     580       
     581        return rc;
    612582}
    613583
     
    659629        }
    660630       
    661         printf("%s: Protocol registered (protocol: %d, service: %d)\n",
     631        printf("%s: Protocol registered (protocol: %d, service: %#x)\n",
    662632            NAME, proto->protocol, proto->service);
    663633       
     
    697667        if (i < 0)
    698668                return i;
     669       
    699670        if (i != ETH_ADDR)
    700671                return EINVAL;
     672       
     673        for (i = 0; i < ETH_ADDR; i++) {
     674                if (src[i]) {
     675                        src_addr = src;
     676                        break;
     677                }
     678        }
    701679
    702680        length = packet_get_data_length(packet);
     
    722700                memcpy(header_dix->destination_address, dest, ETH_ADDR);
    723701                src = &header_dix->destination_address[0];
    724         } else if(IS_8023_2_LSAP(flags)) {
     702        } else if (IS_8023_2_LSAP(flags)) {
    725703                header_lsap = PACKET_PREFIX(packet, eth_header_lsap_t);
    726704                if (!header_lsap)
     
    735713                memcpy(header_lsap->header.destination_address, dest, ETH_ADDR);
    736714                src = &header_lsap->header.destination_address[0];
    737         } else if(IS_8023_2_SNAP(flags)) {
     715        } else if (IS_8023_2_SNAP(flags)) {
    738716                header = PACKET_PREFIX(packet, eth_header_snap_t);
    739717                if (!header)
     
    746724                header->lsap.ctrl = IEEE_8023_2_UI;
    747725               
    748                 for (i = 0; i < 3; ++ i)
     726                for (i = 0; i < 3; i++)
    749727                        header->snap.protocol[i] = 0;
    750728               
     
    760738                        return ENOMEM;
    761739               
    762                 for (i = 0; i < 7; ++ i)
     740                for (i = 0; i < 7; i++)
    763741                        preamble->preamble[i] = ETH_PREAMBLE;
    764742               
     
    787765 * @return              EINVAL if the service parameter is not known.
    788766 */
    789 static int eth_send_message(device_id_t device_id, packet_t *packet,
     767static int eth_send_message(nic_device_id_t device_id, packet_t *packet,
    790768    services_t sender)
    791769{
     
    813791        do {
    814792                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);
    816794                if (rc != EOK) {
    817795                        /* Release invalid packet */
     
    825803                        next = pq_next(next);
    826804                }
    827         } while(next);
     805        } while (next);
    828806       
    829807        /* 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       
    835811        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    836812        return EOK;
    837813}
    838814
     815static 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(&eth_globals.devices_lock);
     833        /* An existing device? */
     834        eth_device_t *device = eth_devices_find(&eth_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(&eth_globals.devices_lock);
     840
     841                /* Notify all upper layer modules */
     842                fibril_rwlock_read_lock(&eth_globals.protos_lock);
     843                int index;
     844                for (index = 0; index < eth_protos_count(&eth_globals.protos); index++) {
     845                        eth_proto_t *proto = eth_protos_get_index(&eth_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(&eth_globals.protos_lock);
     853                return EOK;
     854        } else {
     855                return ENOENT;
     856        }
     857}
     858
    839859int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    840860    ipc_call_t *answer, size_t *answer_count)
    841861{
    842         measured_string_t *address;
    843862        packet_t *packet;
    844863        size_t addrlen;
     
    861880        case NET_NIL_DEVICE:
    862881                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));
    864883        case NET_NIL_SEND:
    865884                rc = packet_translate_remote(eth_globals.net_sess, &packet,
     
    867886                if (rc != EOK)
    868887                        return rc;
     888               
    869889                return eth_send_message(IPC_GET_DEVICE(*call), packet,
    870890                    IPC_GET_SERVICE(*call));
     
    874894                if (rc != EOK)
    875895                        return rc;
     896               
    876897                IPC_SET_ADDR(*answer, addrlen);
    877898                IPC_SET_PREFIX(*answer, prefix);
     
    879900                IPC_SET_SUFFIX(*answer, suffix);
    880901                *answer_count = 4;
     902               
    881903                return EOK;
    882904        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);
    885906                if (rc != EOK)
    886907                        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;
    888913        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);
    891915                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;
    894938        }
    895939       
  • uspace/srv/net/nil/eth/eth.h

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    4344#include <net/device.h>
    4445#include <adt/measured_strings.h>
     46#include <devman.h>
    4547
    4648/** Ethernet address length. */
     
    220222struct eth_device {
    221223        /** 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;
    225227        /** Driver session. */
    226228        async_sess_t *sess;
     
    236238       
    237239        /** 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;
    242241};
    243242
     
    270269       
    271270        /** Broadcast device hardware address. */
    272         measured_string_t *broadcast_addr;
     271        uint8_t broadcast_addr[ETH_ADDR];
    273272};
    274273
  • uspace/srv/net/nil/nildummy/nildummy.c

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    3637 */
    3738
     39#include <assert.h>
    3840#include <async.h>
    3941#include <malloc.h>
     
    5052#include <net/packet.h>
    5153#include <packet_remote.h>
    52 #include <netif_remote.h>
     54#include <packet_client.h>
     55#include <devman.h>
     56#include <device/nic.h>
    5357#include <nil_skel.h>
    5458#include "nildummy.h"
     
    6569DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    6670
    67 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     71int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
    6872{
    6973        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     
    9195       
    9296        return rc;
    93 }
    94 
    95 /** Process IPC messages from the registered device driver modules
    96  *
    97  * @param[in]     iid   Message identifier.
    98  * @param[in,out] icall Message parameters.
    99  * @param[in]     arg    Local argument.
    100  *
    101  */
    102 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    103 {
    104         packet_t *packet;
    105         int rc;
    106        
    107         while (true) {
    108                 switch (IPC_GET_IMETHOD(*icall)) {
    109                 case NET_NIL_DEVICE_STATE:
    110                         rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    111                             IPC_GET_STATE(*icall));
    112                         async_answer_0(iid, (sysarg_t) rc);
    113                         break;
    114                
    115                 case NET_NIL_RECEIVED:
    116                         rc = packet_translate_remote(nildummy_globals.net_sess,
    117                             &packet, IPC_GET_PACKET(*icall));
    118                         if (rc == EOK)
    119                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    120                                     packet, 0);
    121                        
    122                         async_answer_0(iid, (sysarg_t) rc);
    123                         break;
    124                
    125                 default:
    126                         async_answer_0(iid, (sysarg_t) ENOTSUP);
    127                 }
    128                
    129                 iid = async_get_call(icall);
    130         }
    13197}
    13298
     
    148114 *
    149115 */
    150 static int nildummy_device_message(device_id_t device_id, services_t service,
    151     size_t mtu)
     116static int nildummy_device_message(nic_device_id_t device_id,
     117    devman_handle_t handle, size_t mtu)
    152118{
    153119        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
     
    157123            nildummy_devices_find(&nildummy_globals.devices, device_id);
    158124        if (device) {
    159                 if (device->service != service) {
    160                         printf("Device %d already exists\n", device->device_id);
    161                         fibril_rwlock_write_unlock(
    162                             &nildummy_globals.devices_lock);
     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);
    163129                        return EEXIST;
    164130                }
     
    170136                        device->mtu = NET_DEFAULT_MTU;
    171137               
    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);
    174140                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    175141               
     
    192158       
    193159        device->device_id = device_id;
    194         device->service = service;
     160        device->handle = handle;
    195161        if (mtu > 0)
    196162                device->mtu = mtu;
    197163        else
    198164                device->mtu = NET_DEFAULT_MTU;
    199 
     165       
    200166        /* 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);
    203169        if (device->sess == NULL) {
    204170                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    207173        }
    208174       
     175        nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id);
     176       
    209177        /* 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);
    212179        if (rc != EOK) {
    213180                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    215182                return rc;
    216183        }
     184       
     185        device->addr_len = ETH_ADDR;
    217186       
    218187        /* Add to the cache */
     
    221190        if (index < 0) {
    222191                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    223                 free(device->addr);
    224                 free(device->addr_data);
    225192                free(device);
    226193                return index;
    227194        }
    228195       
    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);
    231198        fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    232199        return EOK;
     
    243210 *
    244211 */
    245 static int nildummy_addr_message(device_id_t device_id,
    246     measured_string_t **address)
    247 {
    248         if (!address)
     212static int nildummy_addr_message(nic_device_id_t device_id, size_t *addrlen)
     213{
     214        if (!addrlen)
    249215                return EBADMEM;
    250216       
     
    258224        }
    259225       
    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;
    261247       
    262248        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    263        
    264         return (*address) ? EOK : ENOENT;
     249        return EOK;
    265250}
    266251
     
    278263 *
    279264 */
    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)
     265static 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)
    282267{
    283268        if ((!addr_len) || (!prefix) || (!content) || (!suffix))
     
    303288}
    304289
    305 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    306     services_t target)
     290int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet)
    307291{
    308292        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     
    340324        nildummy_globals.proto.sess = sess;
    341325       
    342         printf("%s: Protocol registered (service: %d)\n",
     326        printf("%s: Protocol registered (service: %#x)\n",
    343327            NAME, nildummy_globals.proto.service);
    344328       
     
    358342 *
    359343 */
    360 static int nildummy_send_message(device_id_t device_id, packet_t *packet,
     344static int nildummy_send_message(nic_device_id_t device_id, packet_t *packet,
    361345    services_t sender)
    362346{
     
    372356        /* Send packet queue */
    373357        if (packet)
    374                 netif_send_msg(device->sess, device_id, packet,
    375                     SERVICE_NILDUMMY);
     358                nic_send_message(device->sess, packet_get_id(packet));
    376359       
    377360        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
     
    383366    ipc_call_t *answer, size_t *answer_count)
    384367{
    385         measured_string_t *address;
    386368        packet_t *packet;
    387369        size_t addrlen;
     
    404386        case NET_NIL_DEVICE:
    405387                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));
    407389       
    408390        case NET_NIL_SEND:
     
    427409       
    428410        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);
    430413                if (rc != EOK)
    431414                        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;
    439433        }
    440434       
  • uspace/srv/net/nil/nildummy/nildummy.h

    r8367d1d rd7ff048  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
     3 * Copyright (c) 2011 Radim Vansa
    34 * All rights reserved.
    45 *
     
    4142#include <fibril_synch.h>
    4243#include <ipc/services.h>
     44#include <ipc/devman.h>
    4345#include <net/device.h>
    4446#include <adt/measured_strings.h>
     
    7678struct nildummy_device {
    7779        /** 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;
    8383        /** Driver session. */
    8484        async_sess_t *sess;
     
    8888       
    8989        /** 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;
    9493};
    9594
  • uspace/srv/net/tl/icmp/icmp.c

    r8367d1d rd7ff048  
    753753                        return rc;
    754754               
    755                 rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call), 
     755                rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call),
    756756                    ICMP_GET_TIMEOUT(*call), ICMP_GET_TTL(*call),
    757757                    ICMP_GET_TOS(*call), ICMP_GET_DONT_FRAGMENT(*call),
  • uspace/srv/net/tl/tcp/tcp.c

    r8367d1d rd7ff048  
    169169static int tcp_release_after_timeout(void *);
    170170
    171 static int tcp_process_packet(device_id_t, packet_t *, services_t);
     171static int tcp_process_packet(nic_device_id_t, packet_t *, services_t);
    172172static int tcp_connect_core(socket_core_t *, socket_cores_t *,
    173173    struct sockaddr *, socklen_t);
     
    177177    size_t);
    178178static 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 *);
     179static void tcp_send_packets(nic_device_id_t, packet_t *);
    180180
    181181static void tcp_process_acknowledgement(socket_core_t *, tcp_socket_data_t *,
     
    205205static void tcp_queue_received_end_of_data(socket_core_t *socket);
    206206
    207 static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t);
     207static int tcp_received_msg(nic_device_id_t, packet_t *, services_t, services_t);
    208208static int tcp_process_client_messages(async_sess_t *, ipc_callid_t,
    209209    ipc_call_t);
     
    220220tcp_globals_t tcp_globals;
    221221
    222 int tcp_received_msg(device_id_t device_id, packet_t *packet,
     222int tcp_received_msg(nic_device_id_t device_id, packet_t *packet,
    223223    services_t receiver, services_t error)
    224224{
     
    238238}
    239239
    240 int tcp_process_packet(device_id_t device_id, packet_t *packet, services_t error)
     240int tcp_process_packet(nic_device_id_t device_id, packet_t *packet, services_t error)
    241241{
    242242        size_t length;
     
    12511251        bzero(socket_data, sizeof(*socket_data));
    12521252        socket_data->state = TCP_SOCKET_INITIAL;
    1253         socket_data->device_id = DEVICE_INVALID_ID;
     1253        socket_data->device_id = NIC_DEVICE_INVALID_ID;
    12541254        socket_data->window = NET_DEFAULT_TCP_WINDOW;
    12551255        socket_data->treshold = socket_data->window;
     
    13351335                        }
    13361336                        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,
    13381338                            &packet_dimension) == EOK) {
    13391339                                SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
     
    16511651        /* Sent packet? */
    16521652        packet = pq_find(socket_data->outgoing, sequence_number);
    1653         printf("retransmit %d\n", packet_get_id(packet));
    16541653        if (packet) {
    16551654                pq_get_order(packet, NULL, &data_length);
     
    17901789
    17911790                        /* Send the packet */
    1792                         printf("connecting %d\n", packet_get_id(packet));
    17931791                        tcp_send_packets(socket_data->device_id, packet);
    17941792
     
    20042002}
    20052003
    2006 void tcp_send_packets(device_id_t device_id, packet_t *packet)
     2004void tcp_send_packets(nic_device_id_t device_id, packet_t *packet)
    20072005{
    20082006        packet_t *next;
  • uspace/srv/net/tl/tcp/tcp.h

    r8367d1d rd7ff048  
    182182       
    183183        /** Device identifier. */
    184         device_id_t device_id;
     184        nic_device_id_t device_id;
    185185       
    186186        /**
  • uspace/srv/net/tl/udp/udp.c

    r8367d1d rd7ff048  
    124124 *                      ip_client_process_packet() function.
    125125 */
    126 static int udp_process_packet(device_id_t device_id, packet_t *packet,
     126static int udp_process_packet(nic_device_id_t device_id, packet_t *packet,
    127127    services_t error)
    128128{
     
    322322 *                      udp_process_packet() function.
    323323 */
    324 static int udp_received_msg(device_id_t device_id, packet_t *packet,
     324static int udp_received_msg(nic_device_id_t device_id, packet_t *packet,
    325325    services_t receiver, services_t error)
    326326{
     
    499499        void *ip_header;
    500500        size_t headerlen;
    501         device_id_t device_id;
     501        nic_device_id_t device_id;
    502502        packet_dimension_t *packet_dimension;
    503503        size_t size;
     
    617617                    htons(flip_checksum(compact_checksum(checksum)));
    618618                free(ip_header);
    619         } else {
    620                 device_id = DEVICE_INVALID_ID;
    621         }
     619        } else
     620                device_id = NIC_DEVICE_INVALID_ID;
    622621
    623622        /* Prepare the first packet fragment */
     
    806805                        size = MAX_UDP_FRAGMENT_SIZE;
    807806                        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,
    809808                            &packet_dimension) == EOK) {
    810809                                if (packet_dimension->content < size)
Note: See TracChangeset for help on using the changeset viewer.