Ignore:
Timestamp:
2021-08-08T17:30:29Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a7f7b9c3
Parents:
b4edc96
Message:

Represent Ethernet address as a number instead of an array

Carefully document the design since this breaks the principle of least
surprise. Also add unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_ieee80211.c

    rb4edc96 r3e6bca8  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2015 Jan Kolarik
    34 * All rights reserved.
     
    8485}
    8586
    86 static bool mac_matches(uint8_t *mac1, uint8_t *mac2)
    87 {
    88         for (size_t i = 0; i < ETH_ADDR; i++) {
    89                 if (mac1[i] != mac2[i])
    90                         return false;
    91         }
    92 
    93         return true;
    94 }
    95 
     87// XXX This is wrong. Wifi should not have anything to do with IP links
    9688static sysarg_t get_link_id(uint8_t *mac)
    9789{
    9890        sysarg_t *link_list;
    9991        inet_link_info_t link_info;
     92        eth_addr_t eth_addr;
    10093        size_t count;
     94
     95        eth_addr_decode(mac, &eth_addr);
    10196
    10297        errno_t rc = inetcfg_get_link_list(&link_list, &count);
     
    109104                        return -1;
    110105
    111                 if (mac_matches(mac, link_info.mac_addr.b))
     106                if (eth_addr_compare(&eth_addr, &link_info.mac_addr) == 0)
    112107                        return link_list[i];
    113108        }
     
    170165                return rc;
    171166
     167        // XXX This is wrong. Wifi should not initiate DHCP
     168
    172169        /* Send DHCP discover. */
    173170        nic_address_t wifi_mac;
     
    207204        if (rc != EOK)
    208205                return rc;
     206
     207        eth_addr_t eth_addr;
     208        eth_addr_decode(wifi_mac.address, &eth_addr);
    209209
    210210        inet_link_info_t link_info;
     
    215215        size_t count;
    216216
     217        /// XXX This is wrong. Wifi should do nothing with DHCP
     218
    217219        /* Remove previous DHCP address. */
    218220        rc = inetcfg_get_addr_list(&addr_list, &count);
     
    229231                        return rc;
    230232
    231                 if (mac_matches(wifi_mac.address, link_info.mac_addr.b)) {
     233                if (eth_addr_compare(&eth_addr, &link_info.mac_addr) == 0) {
    232234                        if (str_test_prefix(addr_info.name, "dhcp")) {
    233235                                rc = inetcfg_addr_delete(addr_list[i]);
Note: See TracChangeset for help on using the changeset viewer.