-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gnrc_netif: add general IID to/from l2addr conversion functions #10513
Changes from all commits
5ca30b9
a44f7f7
bc1b490
f757376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright (C) 2018 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @{ | ||
* | ||
* @file | ||
* @brief Functions that are based around a network interface's device type. | ||
* @author Martine Lenders <[email protected]> | ||
*/ | ||
|
||
#include <errno.h> | ||
|
||
#include "log.h" | ||
#include "net/gnrc/netif.h" | ||
#include "net/ethernet.h" | ||
#include "net/ieee802154.h" | ||
|
||
#ifdef MODULE_GNRC_IPV6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is pretty hacky. Better only build this file in case GNRC_IPV6 is selected: put
into the gnrc/netif/Makefile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #10546 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, see #10524 where introduce stuff to this file that is not IPv6 specific, as reflected by the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could make a separate submodule |
||
#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN) | ||
static void _create_iid_from_short(const uint8_t *addr, size_t addr_len, | ||
eui64_t *iid) | ||
{ | ||
const unsigned offset = sizeof(eui64_t) - addr_len; | ||
|
||
memset(iid->uint8, 0, sizeof(iid->uint8)); | ||
iid->uint8[3] = 0xff; | ||
iid->uint8[4] = 0xfe; | ||
memcpy(&iid->uint8[offset], addr, addr_len); | ||
} | ||
#endif /* defined(MODULE_CC110X) || defined(MODULE_NRFMIN) */ | ||
|
||
int gnrc_netif_ipv6_iid_from_addr(const gnrc_netif_t *netif, | ||
const uint8_t *addr, size_t addr_len, | ||
eui64_t *iid) | ||
{ | ||
miri64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#if GNRC_NETIF_L2ADDR_MAXLEN > 0 | ||
if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) { | ||
switch (netif->device_type) { | ||
#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) | ||
case NETDEV_TYPE_ETHERNET: | ||
case NETDEV_TYPE_ESP_NOW: | ||
if (addr_len == ETHERNET_ADDR_LEN) { | ||
ethernet_get_iid(iid, (uint8_t *)addr); | ||
return sizeof(eui64_t); | ||
} | ||
else { | ||
return -EINVAL; | ||
} | ||
#endif /* defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) */ | ||
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) | ||
case NETDEV_TYPE_IEEE802154: | ||
if (ieee802154_get_iid(iid, addr, addr_len) != NULL) { | ||
return sizeof(eui64_t); | ||
} | ||
else { | ||
return -EINVAL; | ||
} | ||
#endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) */ | ||
#ifdef MODULE_NORDIC_SOFTDEVICE_BLE | ||
case NETDEV_TYPE_BLE: | ||
if (addr_len == sizeof(eui64_t)) { | ||
memcpy(iid, addr, sizeof(eui64_t)); | ||
iid->uint8[0] ^= 0x02; | ||
return sizeof(eui64_t); | ||
} | ||
else { | ||
return -EINVAL; | ||
} | ||
#endif /* MODULE_NORDIC_SOFTDEVICE_BLE */ | ||
#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN) | ||
case NETDEV_TYPE_CC110X: | ||
case NETDEV_TYPE_NRFMIN: | ||
if (addr_len <= 3) { | ||
_create_iid_from_short(addr, addr_len, iid); | ||
return sizeof(eui64_t); | ||
} | ||
else { | ||
return -EINVAL; | ||
} | ||
#endif /* defined(MODULE_CC110X) || defined(MODULE_NRFMIN) */ | ||
default: | ||
(void)addr; | ||
(void)addr_len; | ||
(void)iid; | ||
#ifdef DEVELHELP | ||
LOG_ERROR("gnrc_netif: can't convert hardware address to IID " | ||
"on interface %u\n", netif->pid); | ||
#endif /* DEVELHELP */ | ||
assert(false); | ||
break; | ||
} | ||
} | ||
#endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */ | ||
return -ENOTSUP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is never reached (every switch statement terminates, see the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is reached if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What @maribu is saying. Also it is in accordance with what you proposed ;-). |
||
} | ||
|
||
int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif, const eui64_t *iid, | ||
uint8_t *addr) | ||
{ | ||
assert(netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR); | ||
switch (netif->device_type) { | ||
#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) | ||
case NETDEV_TYPE_ETHERNET: | ||
case NETDEV_TYPE_ESP_NOW: | ||
addr[0] = iid->uint8[0] ^ 0x02; | ||
addr[1] = iid->uint8[1]; | ||
addr[2] = iid->uint8[2]; | ||
addr[3] = iid->uint8[5]; | ||
addr[4] = iid->uint8[6]; | ||
addr[5] = iid->uint8[7]; | ||
return ETHERNET_ADDR_LEN; | ||
#endif /* defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) */ | ||
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) | ||
case NETDEV_TYPE_IEEE802154: | ||
/* assume address was based on EUI-64 | ||
* (see https://tools.ietf.org/html/rfc6775#section-5.2) */ | ||
memcpy(addr, iid, sizeof(eui64_t)); | ||
addr[0] ^= 0x02; | ||
return sizeof(eui64_t); | ||
#endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) */ | ||
#ifdef MODULE_NRFMIN | ||
case NETDEV_TYPE_NRFMIN: | ||
addr[0] = iid->uint8[6]; | ||
addr[1] = iid->uint8[7]; | ||
return sizeof(uint16_t); | ||
#endif /* MODULE_NETDEV_IEEE802154 */ | ||
#ifdef MODULE_NORDIC_SOFTDEVICE_BLE | ||
case NETDEV_TYPE_BLE: | ||
memcpy(addr, iid, sizeof(eui64_t)); | ||
addr[0] ^= 0x02; | ||
return sizeof(eui64_t); | ||
#endif /* MODULE_NORDIC_SOFTDEVICE_BLE */ | ||
#ifdef MODULE_CC110X | ||
case NETDEV_TYPE_CC110X: | ||
addr[0] = iid->uint8[7]; | ||
return sizeof(uint8_t); | ||
#endif /* MODULE_CC110X */ | ||
default: | ||
(void)iid; | ||
(void)addr; | ||
#ifdef DEVELHELP | ||
LOG_ERROR("gnrc_netif: can't convert IID to hardware address " | ||
"on interface %u\n", netif->pid); | ||
#endif /* DEVELHELP */ | ||
assert(false); | ||
break; | ||
} | ||
return -ENOTSUP; | ||
miri64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#endif /* MODULE_GNRC_IPV6 */ | ||
|
||
/** @} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the
defined(DOXYGEN)
, right?!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ifdef in above opens with
defined(MODULE_GNRC_IPV6) || defined(DOXYGEN)
, so I don't see why I would remove that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I mistakenly took the
else
for anif
here...