diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index aa4dd55dee8bc5cce3c5737739356368d7dcaa96..3cef54a4ad992a9cf49d7a9549c325fd8f64c591 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -775,6 +775,21 @@ int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif, const ipv6_addr_t *addr) return idx; } +#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_CC110X) || \ + defined(MODULE_NRFMIN) +static void _create_iid_from_short(const gnrc_netif_t *netif, eui64_t *eui64) +{ + const unsigned offset = sizeof(eui64_t) - netif->l2addr_len; + + assert(netif->l2addr_len <= 3); + memset(eui64->uint8, 0, sizeof(eui64->uint8)); + eui64->uint8[3] = 0xff; + eui64->uint8[4] = 0xfe; + memcpy(&eui64->uint8[offset], netif->l2addr, netif->l2addr_len); +} +#endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_CC110X) || + * defined(MODULE_NRFMIN) */ + int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) { #if GNRC_NETIF_L2ADDR_MAXLEN > 0 @@ -797,14 +812,7 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) case NETDEV_TYPE_IEEE802154: switch (netif->l2addr_len) { case IEEE802154_SHORT_ADDRESS_LEN: - eui64->uint8[0] = 0x0; - eui64->uint8[1] = 0x0; - eui64->uint8[2] = 0x0; - eui64->uint8[3] = 0xff; - eui64->uint8[4] = 0xfe; - eui64->uint8[5] = 0x0; - eui64->uint8[6] = netif->l2addr[0]; - eui64->uint8[7] = netif->l2addr[1]; + _create_iid_from_short(netif, eui64); return 0; case IEEE802154_LONG_ADDRESS_LEN: memcpy(eui64, netif->l2addr, sizeof(eui64_t)); @@ -817,17 +825,10 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) } break; #endif -#ifdef MODULE_CC110X +#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN) case NETDEV_TYPE_CC110X: - assert(netif->l2addr_len == 1U); - eui64->uint8[0] = 0x0; - eui64->uint8[1] = 0x0; - eui64->uint8[2] = 0x0; - eui64->uint8[3] = 0xff; - eui64->uint8[4] = 0xfe; - eui64->uint8[5] = 0x0; - eui64->uint8[6] = 0x0; - eui64->uint8[7] = netif->l2addr[0]; + case NETDEV_TYPE_NRFMIN: + _create_iid_from_short(netif, eui64); return 0; #endif default: