gnrc_netif: centralize function to get l2addr NETOPT
This commit is contained in:
parent
8f763535ac
commit
ea9bbd72b8
@ -46,6 +46,7 @@
|
||||
#endif
|
||||
#include "net/ndp.h"
|
||||
#include "net/netdev.h"
|
||||
#include "net/netopt.h"
|
||||
#include "rmutex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#define NET_GNRC_NETIF_INTERNAL_H
|
||||
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/netopt.h"
|
||||
|
||||
#ifdef MODULE_GNRC_IPV6_NIB
|
||||
#include "net/gnrc/ipv6/nib/conf.h"
|
||||
@ -414,6 +415,17 @@ static inline bool gnrc_netif_is_6lbr(const gnrc_netif_t *netif)
|
||||
* need adaptions for your port
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Get the default link-layer address option for the given
|
||||
* gnrc_netif_t::device_type of a network interface
|
||||
*
|
||||
* @param[in] netif The network interface to get the default link-layer
|
||||
* address option for.
|
||||
*
|
||||
* @return Either @ref NETOPT_ADDRESS or @ref NETOPT_ADDRESS_LONG.
|
||||
*/
|
||||
netopt_t gnrc_netif_get_l2addr_opt(const gnrc_netif_t *netif);
|
||||
|
||||
#if defined(MODULE_GNRC_IPV6) || defined(DOXYGEN)
|
||||
/**
|
||||
* @brief Converts a given hardware address to an IPv6 IID.
|
||||
|
||||
@ -1109,27 +1109,8 @@ static void _update_l2addr_from_dev(gnrc_netif_t *netif)
|
||||
{
|
||||
netdev_t *dev = netif->dev;
|
||||
int res;
|
||||
netopt_t opt = NETOPT_ADDRESS;
|
||||
netopt_t opt = gnrc_netif_get_l2addr_opt(netif);
|
||||
|
||||
switch (netif->device_type) {
|
||||
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) \
|
||||
|| defined(MODULE_NORDIC_SOFTDEVICE_BLE)
|
||||
case NETDEV_TYPE_BLE:
|
||||
case NETDEV_TYPE_IEEE802154: {
|
||||
uint16_t tmp;
|
||||
|
||||
res = dev->driver->get(dev, NETOPT_SRC_LEN, &tmp, sizeof(tmp));
|
||||
assert(res == sizeof(tmp));
|
||||
netif->l2addr_len = (uint8_t)tmp;
|
||||
if (tmp == IEEE802154_LONG_ADDRESS_LEN) {
|
||||
opt = NETOPT_ADDRESS_LONG;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
res = dev->driver->get(dev, opt, netif->l2addr,
|
||||
sizeof(netif->l2addr));
|
||||
if (res != -ENOTSUP) {
|
||||
|
||||
@ -21,6 +21,35 @@
|
||||
#include "net/eui48.h"
|
||||
#include "net/ieee802154.h"
|
||||
|
||||
netopt_t gnrc_netif_get_l2addr_opt(const gnrc_netif_t *netif)
|
||||
{
|
||||
netopt_t res = NETOPT_ADDRESS;
|
||||
|
||||
switch (netif->device_type) {
|
||||
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) || \
|
||||
defined(MODULE_NORDIC_SOFTDEVICE_BLE)
|
||||
case NETDEV_TYPE_IEEE802154:
|
||||
case NETDEV_TYPE_BLE: {
|
||||
netdev_t *dev = netif->dev;
|
||||
int r;
|
||||
uint16_t tmp;
|
||||
|
||||
r = dev->driver->get(dev, NETOPT_SRC_LEN, &tmp, sizeof(tmp));
|
||||
assert(r == sizeof(tmp));
|
||||
assert(r <= ((int)UINT8_MAX));
|
||||
(void)r;
|
||||
if (tmp == IEEE802154_LONG_ADDRESS_LEN) {
|
||||
res = NETOPT_ADDRESS_LONG;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef MODULE_GNRC_IPV6
|
||||
#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN)
|
||||
static void _create_iid_from_short(const uint8_t *addr, size_t addr_len,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user