Changeset 00d7e1b in mainline for uspace/lib


Ignore:
Timestamp:
2011-10-07T20:20:33Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
49bd793b
Parents:
e2c50e1
Message:

networking improvements

  • start the networking stack from init
  • add loopback network interface driver (cherrypicked and sanitized from lp:~helenos-nicf/helenos/nicf)
  • add libnic and various small pieces from lp:~helenos-nicf/helenos/nicf
  • fix client side of NIC_GET_ADDRESS
  • net binary overhaul

Note: "ping 127.0.0.1" works, but the first three pings timeout for some reason

Location:
uspace/lib
Files:
14 added
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    re2c50e1 r00d7e1b  
    6767        generic/devman.c \
    6868        generic/device/hw_res.c \
     69        generic/device/hw_res_parsed.c \
    6970        generic/device/char_dev.c \
    7071        generic/device/nic.c \
     
    104105        generic/adt/list.c \
    105106        generic/adt/hash_table.c \
     107        generic/adt/hash_set.c \
    106108        generic/adt/dynamic_fifo.c \
    107109        generic/adt/measured_strings.c \
  • uspace/lib/c/generic/device/nic.c

    re2c50e1 r00d7e1b  
    137137       
    138138        async_exch_t *exch = async_exchange_begin(dev_sess);
    139        
    140         int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_GET_ADDRESS);
    141         if (rc != EOK) {
    142                 async_exchange_end(exch);
    143                 return rc;
    144         }
    145        
    146         rc = async_data_read_start(exch, address, sizeof(nic_address_t));
    147        
    148         async_exchange_end(exch);
    149        
    150         return rc;
     139        aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     140            NIC_GET_ADDRESS, NULL);
     141        int rc = async_data_read_start(exch, address, sizeof(nic_address_t));
     142        async_exchange_end(exch);
     143       
     144        sysarg_t res;
     145        async_wait_for(aid, &res);
     146       
     147        if (rc != EOK)
     148                return rc;
     149       
     150        return (int) res;
    151151}
    152152
     
    164164       
    165165        async_exch_t *exch = async_exchange_begin(dev_sess);
    166         aid_t message_id = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     166        aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    167167            NIC_SET_ADDRESS, NULL);
    168168        int rc = async_data_write_start(exch, address, sizeof(nic_address_t));
     
    170170       
    171171        sysarg_t res;
    172         async_wait_for(message_id, &res);
     172        async_wait_for(aid, &res);
    173173       
    174174        if (rc != EOK)
  • uspace/lib/c/include/net/device.h

    re2c50e1 r00d7e1b  
    4141#include <adt/int_map.h>
    4242#include <net/eth_phys.h>
     43#include <bool.h>
    4344
    4445/** Ethernet address length. */
     
    5152#define ARGSMAC(__a) \
    5253        (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5]
     54
     55/* Compare MAC address with specific value */
     56#define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \
     57        ((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \
     58        && (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5))
     59
     60#define MAC_IS_ZERO(__x) \
     61        MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0)
    5362
    5463/** Device identifier to generic type map declaration. */
     
    221230} nic_device_stats_t;
    222231
     232/** Errors corresponding to those in the nic_device_stats_t */
     233typedef enum {
     234        NIC_SEC_BUFFER_FULL,
     235        NIC_SEC_ABORTED,
     236        NIC_SEC_CARRIER_LOST,
     237        NIC_SEC_FIFO_OVERRUN,
     238        NIC_SEC_HEARTBEAT,
     239        NIC_SEC_WINDOW_ERROR,
     240        /* Error encountered during TX but with other type of error */
     241        NIC_SEC_OTHER
     242} nic_send_error_cause_t;
     243
     244/** Errors corresponding to those in the nic_device_stats_t */
     245typedef enum {
     246        NIC_REC_BUFFER_FULL,
     247        NIC_REC_LENGTH,
     248        NIC_REC_BUFFER_OVERFLOW,
     249        NIC_REC_CRC,
     250        NIC_REC_FRAME_ALIGNMENT,
     251        NIC_REC_FIFO_OVERRUN,
     252        NIC_REC_MISSED,
     253        /* Error encountered during RX but with other type of error */
     254        NIC_REC_OTHER
     255} nic_receive_error_cause_t;
     256
    223257/**
    224258 * Information about the NIC that never changes - name, vendor, model,
     
    246280
    247281/**
     282 * Type of the ethernet frame
     283 */
     284typedef enum nic_frame_type {
     285        NIC_FRAME_UNICAST,
     286        NIC_FRAME_MULTICAST,
     287        NIC_FRAME_BROADCAST
     288} nic_frame_type_t;
     289
     290/**
    248291 * Specifies which unicast frames is the NIC receiving.
    249292 */
     
    292335
    293336/**
     337 * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET.
     338 */
     339typedef struct nic_wv_magic_packet_data {
     340        uint8_t password[6];
     341} nic_wv_magic_packet_data_t;
     342
     343/**
     344 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4
     345 */
     346typedef struct nic_wv_ipv4_data {
     347        uint8_t address[4];
     348} nic_wv_ipv4_data_t;
     349
     350/**
     351 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6
     352 */
     353typedef struct nic_wv_ipv6_data {
     354        uint8_t address[16];
     355} nic_wv_ipv6_data_t;
     356
     357/**
    294358 * WOL virtue types defining the interpretation of data passed to the virtue.
    295359 * Those tagged with S can have only single virtue active at one moment, those
     
    376440        NIC_POLL_SOFTWARE_PERIODIC
    377441} nic_poll_mode_t;
     442
     443/**
     444 * Says if this virtue type is a multi-virtue (there can be multiple virtues of
     445 * this type at once).
     446 *
     447 * @param type
     448 *
     449 * @return true or false
     450 */
     451static inline int nic_wv_is_multi(nic_wv_type_t type) {
     452        switch (type) {
     453        case NIC_WV_FULL_MATCH:
     454        case NIC_WV_DESTINATION:
     455        case NIC_WV_DIRECTED_IPV4:
     456        case NIC_WV_DIRECTED_IPV6:
     457                return true;
     458        default:
     459                return false;
     460        }
     461}
    378462
    379463static inline const char *nic_device_state_to_string(nic_device_state_t state)
  • uspace/lib/net/generic/generic.c

    re2c50e1 r00d7e1b  
    7979{
    8080        async_exch_t *exch = async_exchange_begin(sess);
    81         int rc = async_req_2_0(exch, message, (sysarg_t) device_id,
     81        int rc = async_req_3_0(exch, message, (sysarg_t) device_id, 0,
    8282            (sysarg_t) service);
    8383        async_exchange_end(exch);
  • uspace/lib/net/generic/net_checksum.c

    re2c50e1 r00d7e1b  
    4545#define CRC_DIVIDER_LE  0xedb88320
    4646
     47/** Polynomial used in multicast address hashing */
     48#define CRC_MCAST_POLYNOMIAL  0x04c11db6
     49
    4750/** Compacts the computed checksum to the 16 bit number adding the carries.
    4851 *
     
    221224}
    222225
     226/** Compute the standard hash from MAC
     227 *
     228 * Hashing MAC into 64 possible values and using the value as index to
     229 * 64bit number.
     230 *
     231 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139
     232 * drivers, but according to documentation there it originates in FreeBSD.
     233 *
     234 * @param[in] addr The 6-byte MAC address to be hashed
     235 *
     236 * @return 64-bit number with only single bit set to 1
     237 *
     238 */
     239uint64_t multicast_hash(const uint8_t addr[6])
     240{
     241        uint32_t crc;
     242    int carry, i, j;
     243    uint8_t b;
     244
     245    crc = 0xffffffff;
     246    for (i = 0; i < 6; i++) {
     247        b = addr[i];
     248        for (j = 0; j < 8; j++) {
     249            carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
     250            crc <<= 1;
     251            b >>= 1;
     252            if (carry)
     253                crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);
     254        }
     255    }
     256       
     257    uint64_t one64 = 1;
     258    return one64 << (crc >> 26);
     259}
     260
    223261/** @}
    224262 */
  • uspace/lib/net/il/ip_remote.c

    re2c50e1 r00d7e1b  
    123123 *
    124124 */
    125 int ip_device_req_remote(async_sess_t *sess, nic_device_id_t device_id,
     125int ip_device_req(async_sess_t *sess, nic_device_id_t device_id,
    126126    services_t service)
    127127{
  • uspace/lib/net/include/ip_interface.h

    re2c50e1 r00d7e1b  
    4646#define ip_set_gateway_req     ip_set_gateway_req_remote
    4747#define ip_packet_size_req     ip_packet_size_req_remote
    48 #define ip_device_req          ip_device_req_remote
    4948#define ip_add_route_req       ip_add_route_req_remote
    5049#define ip_send_msg            ip_send_msg_remote
  • uspace/lib/net/include/ip_remote.h

    re2c50e1 r00d7e1b  
    4848extern int ip_received_error_msg_remote(async_sess_t *, nic_device_id_t, packet_t *,
    4949    services_t, services_t);
    50 extern int ip_device_req_remote(async_sess_t *, nic_device_id_t, services_t);
     50extern int ip_device_req(async_sess_t *, nic_device_id_t, services_t);
    5151extern int ip_add_route_req_remote(async_sess_t *, nic_device_id_t, in_addr_t,
    5252    in_addr_t, in_addr_t);
  • uspace/lib/net/include/net_checksum.h

    re2c50e1 r00d7e1b  
    6767extern uint16_t flip_checksum(uint16_t);
    6868extern uint16_t ip_checksum(uint8_t *, size_t);
     69extern uint64_t multicast_hash(const uint8_t addr[6]);
    6970
    7071#endif
  • uspace/lib/net/tl/tl_skel.c

    re2c50e1 r00d7e1b  
    123123                goto out;
    124124       
     125        task_retval(0);
    125126        async_manager();
    126127       
Note: See TracChangeset for help on using the changeset viewer.