From 6547b2185bd6f0d663c8a7ce6c0538d316fd67e7 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 29 Nov 2018 15:31:55 +0100 Subject: [PATCH 1/2] gnrc_netif: remove ESP-Now related code-duplication --- sys/net/gnrc/netif/gnrc_netif.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 2c31ef15f48d..58d505b04d9e 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -835,8 +835,9 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) } switch (netif->device_type) { -#ifdef MODULE_NETDEV_ETH +#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) case NETDEV_TYPE_ETHERNET: + case NETDEV_TYPE_ESP_NOW: assert(netif->l2addr_len == ETHERNET_ADDR_LEN); eui64->uint8[0] = netif->l2addr[0] ^ 0x02; eui64->uint8[1] = netif->l2addr[1]; @@ -877,18 +878,6 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) case NETDEV_TYPE_NRFMIN: _create_iid_from_short(netif, eui64); return 0; -#endif -#if defined(MODULE_ESP_NOW) - case NETDEV_TYPE_ESP_NOW: - eui64->uint8[0] = netif->l2addr[0] ^ 0x02; - eui64->uint8[1] = netif->l2addr[1]; - eui64->uint8[2] = netif->l2addr[2]; - eui64->uint8[3] = 0xff; - eui64->uint8[4] = 0xfe; - eui64->uint8[5] = netif->l2addr[3]; - eui64->uint8[6] = netif->l2addr[4]; - eui64->uint8[7] = netif->l2addr[5]; - return 0; #endif default: (void)eui64; From 6dcf8aad696688d66060609241932a3671676816 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 29 Nov 2018 15:32:29 +0100 Subject: [PATCH 2/2] gnrc_ipv6_nib: remove ESP-Now related code-duplication --- sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c | 15 +++------------ sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c | 10 +++------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c index 6cc1d45982e3..d0c4bfb39e4c 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c @@ -40,8 +40,9 @@ static inline uint8_t _reverse_iid(const ipv6_addr_t *dst, const gnrc_netif_t *netif, uint8_t *l2addr) { switch (netif->device_type) { -#ifdef MODULE_NETDEV_ETH +#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) case NETDEV_TYPE_ETHERNET: + case NETDEV_TYPE_ESP_NOW: l2addr[0] = dst->u8[8] ^ 0x02; l2addr[1] = dst->u8[9]; l2addr[2] = dst->u8[10]; @@ -49,7 +50,7 @@ static inline uint8_t _reverse_iid(const ipv6_addr_t *dst, l2addr[4] = dst->u8[14]; l2addr[5] = dst->u8[15]; return ETHERNET_ADDR_LEN; -#endif /* MODULE_NETDEV_ETH */ +#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 @@ -69,16 +70,6 @@ static inline uint8_t _reverse_iid(const ipv6_addr_t *dst, l2addr[0] = dst->u8[15]; return sizeof(uint8_t); #endif /* MODULE_CC110X */ -#ifdef MODULE_ESP_NOW - case NETDEV_TYPE_ESP_NOW: - l2addr[0] = dst->u8[8] ^ 0x02; - l2addr[1] = dst->u8[9]; - l2addr[2] = dst->u8[10]; - l2addr[3] = dst->u8[13]; - l2addr[4] = dst->u8[14]; - l2addr[5] = dst->u8[15]; - return ETHERNET_ADDR_LEN; -#endif /* MODULE_ESP_NOW */ default: (void)dst; (void)l2addr; diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c index 4d7b36701c1c..c2d37650a44f 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c @@ -183,11 +183,12 @@ static inline unsigned _get_l2addr_len(gnrc_netif_t *netif, (void)opt; return sizeof(uint8_t); #endif /* MODULE_CC110X */ -#ifdef MODULE_NETDEV_ETH +#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) case NETDEV_TYPE_ETHERNET: + case NETDEV_TYPE_ESP_NOW: (void)opt; return ETHERNET_ADDR_LEN; -#endif /* MODULE_NETDEV_ETH */ +#endif /* defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) */ #ifdef MODULE_NRFMIN case NETDEV_TYPE_NRFMIN: (void)opt; @@ -204,11 +205,6 @@ static inline unsigned _get_l2addr_len(gnrc_netif_t *netif, return 0U; } #endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) */ -#ifdef MODULE_ESP_NOW - case NETDEV_TYPE_ESP_NOW: - (void)opt; - return ETHERNET_ADDR_LEN; -#endif /* MODULE_ESP_NOW */ default: (void)opt; return 0U;