diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index abd40fcff5a..764e2a6ba31 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -630,4 +630,3 @@ typedef uint16_t net_stats_t; #endif /* __INCLUDE_NUTTX_NET_NETCONFG_H */ - diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 6bc0147c96b..e0c2e2e1e61 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -124,6 +124,8 @@ static void devif_packet_conversion(FAR struct net_driver_s *dev, { if (dev->d_len > 0) { + /* Check if this is a device served by 6LoWPAN */ + if (dev->d_lltype == NET_LL_IEEE802154 || dev->d_lltype == NET_LL_PKTRADIO) { diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index 1c5c92fc548..a2f229627d6 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -74,8 +74,6 @@ #define ICMPv6RADVERTISE \ ((struct icmpv6_router_advertise_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN]) -#define DEV_LLTYPE(d) ((d)->d_lltype) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -165,7 +163,7 @@ void icmpv6_input(FAR struct net_driver_s *dev) { /* Save the sender's address mapping in our Neighbor Table. */ - neighbor_add(icmp->srcipaddr, DEV_LLTYPE(dev), adv->tgtlladdr); + neighbor_add(dev, icmp->srcipaddr, adv->tgtlladdr); #ifdef CONFIG_NET_ICMPv6_NEIGHBOR /* Then notify any logic waiting for the Neighbor Advertisement */ @@ -240,7 +238,7 @@ void icmpv6_input(FAR struct net_driver_s *dev) if (sllopt->opttype == 1 && sllopt->optlen == 1) { - neighbor_add(icmp->srcipaddr, DEV_LLTYPE(dev), sllopt->srclladdr); + neighbor_add(dev, icmp->srcipaddr, sllopt->srclladdr); } FAR struct icmpv6_prefixinfo_s *opt = diff --git a/net/ipforward/ipfwd_poll.c b/net/ipforward/ipfwd_poll.c index a3563b32d48..00a367a478e 100644 --- a/net/ipforward/ipfwd_poll.c +++ b/net/ipforward/ipfwd_poll.c @@ -108,6 +108,8 @@ static void ipfwd_packet_conversion(FAR struct net_driver_s *dev, int proto) { if (dev->d_len > 0) { + /* Check if this is a device served by 6LoWPAN */ + if (dev->d_lltype == NET_LL_IEEE802154 || dev->d_lltype == NET_LL_PKTRADIO) { @@ -141,7 +143,8 @@ static void ipfwd_packet_conversion(FAR struct net_driver_s *dev, int proto) else #endif { - nwarn("WARNING: Unsupported protocol (%u). Packet dropped\n", proto); + nwarn("WARNING: Unsupported protocol (%u). Packet dropped\n", + proto); } dev->d_len = 0; diff --git a/net/ipforward/ipv6_forward.c b/net/ipforward/ipv6_forward.c index f955f754b10..81cca68956d 100644 --- a/net/ipforward/ipv6_forward.c +++ b/net/ipforward/ipv6_forward.c @@ -205,6 +205,8 @@ static int ipv6_packet_conversion(FAR struct net_driver_s *dev, if (dev->d_len > 0) { + /* Check if this is a device served by 6LoWPAN */ + if (fwddev->d_lltype != NET_LL_IEEE802154 && fwddev->d_lltype != NET_LL_PKTRADIO) { diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 59760a7ae5b..74f84ae5e29 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -113,6 +113,8 @@ extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; * Public Function Prototypes ****************************************************************************/ +struct net_driver_s; /* Forward reference */ + /**************************************************************************** * Name: neighbor_initialize * @@ -158,8 +160,8 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr); * already there). * * Input Parameters: + * dev - Driver instance associated with the MAC * ipaddr - The IPv6 address of the mapping. - * lltype - The link layer address type * addr - The link layer address of the mapping * * Returned Value: @@ -167,7 +169,7 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr); * ****************************************************************************/ -void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype, +void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, FAR uint8_t *addr); /**************************************************************************** diff --git a/net/neighbor/neighbor_add.c b/net/neighbor/neighbor_add.c index 269c8c1f8fb..8574588c5c1 100644 --- a/net/neighbor/neighbor_add.c +++ b/net/neighbor/neighbor_add.c @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -67,8 +68,8 @@ * already there). * * Input Parameters: + * dev - Driver instance associated with the MAC * ipaddr - The IPv6 address of the mapping. - * lltype - The link layer address type * addr - The link layer address of the mapping * * Returned Value: @@ -76,17 +77,21 @@ * ****************************************************************************/ -void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype, +void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, FAR uint8_t *addr) { + uint8_t lltype; uint8_t oldest_time; int oldest_ndx; int i; + DEBUGASSERT(dev != NULL && addr != NULL); + /* Find the first unused entry or the oldest used entry. */ oldest_time = 0; oldest_ndx = 0; + lltype = dev->d_lltype; for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) { @@ -118,7 +123,7 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype, net_ipv6addr_copy(g_neighbors[oldest_ndx].ne_ipaddr, ipaddr); g_neighbors[oldest_ndx].ne_addr.na_lltype = lltype; - g_neighbors[oldest_ndx].ne_addr.na_llsize = netdev_type_lladdrsize(lltype); + g_neighbors[oldest_ndx].ne_addr.na_llsize = netdev_dev_lladdrsize(dev); memcpy(&g_neighbors[oldest_ndx].ne_addr.u, addr, g_neighbors[oldest_ndx].ne_addr.na_llsize); diff --git a/net/netdev/netdev.h b/net/netdev/netdev.h index 8c45536de23..8e8311e3b46 100644 --- a/net/netdev/netdev.h +++ b/net/netdev/netdev.h @@ -403,22 +403,6 @@ void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t lipaddr, int netdev_count(void); #endif -/**************************************************************************** - * Name: netdev_type_lladdrsize - * - * Description: - * Returns the size of the MAC address associated with a link layer type. - * - * Parameters: - * lltype - link layer type code - * - * Returned Value: - * The size of the MAC address associated with this device - * - ****************************************************************************/ - -int netdev_type_lladdrsize(uint8_t lltype); - /**************************************************************************** * Name: netdev_dev_lladdrsize * @@ -426,14 +410,14 @@ int netdev_type_lladdrsize(uint8_t lltype); * Returns the size of the MAC address associated with a network device. * * Parameters: - * dev - A reference to the device of interest + * dev - A reference to the device of interest * * Returned Value: * The size of the MAC address associated with this device * ****************************************************************************/ -#define netdev_dev_lladdrsize(dev) netdev_type_lladdrsize((dev)->d_lltype) +int netdev_dev_lladdrsize(FAR struct net_driver_s *dev); #undef EXTERN #ifdef __cplusplus diff --git a/net/netdev/netdev_lladdrsize.c b/net/netdev/netdev_lladdrsize.c index 2f59bdae3f3..27b7a055b19 100644 --- a/net/netdev/netdev_lladdrsize.c +++ b/net/netdev/netdev_lladdrsize.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -50,73 +51,112 @@ #include "netdev/netdev.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netdev_pktradio_addrlen + * + * Description: + * Returns the size of the node address associated with a packet radio. + * This is probably CONFIG_PKTRADIO_ADDRLEN but we cannot be sure in the + * case that there ar mutiple packet radios. In that case, we have to + * query the radio for its address length. + * + * Parameters: + * dev - A reference to the device of interest + * + * Returned Value: + * The size of the MAC address associated with this radio + * + ****************************************************************************/ + +#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_WIRELESS_PKTRADIO) +static inline int netdev_pktradio_addrlen(FAR struct net_driver_s *dev) +{ + FAR struct sixlowpan_driver_s *radio = (FAR struct sixlowpan_driver_s *)dev; + struct sixlowpan_properties_s properties; + int ret; + + DEBUGASSERT(radio != NULL && radio->r_properties != NULL); + ret = radio->r_properties(radio, &properties); + if (ret < 0) + { + return ret; + } + + return properties.sp_addrlen; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: netdev_type_lladdrsize + * Name: netdev_dev_lladdrsize * * Description: - * Returns the size of the MAC address associated with a link layer type. + * Returns the size of the MAC address associated with a network device. * * Parameters: - * lltype - link layer type code + * dev - A reference to the device of interest * * Returned Value: * The size of the MAC address associated with this device * ****************************************************************************/ -int netdev_type_lladdrsize(uint8_t lltype) +int netdev_type_lladdrsize(FAR struct net_driver_s *dev) { + DEBUGASSERT(dev != NULL); + /* Get the length of the address for this link layer type */ -#ifdef CONFIG_NET_ETHERNET - if (lltype == NET_LL_ETHERNET) + switch (dev->d_lltype) { - /* size of the Ethernet MAC address */ +#ifdef CONFIG_NET_ETHERNET + case NET_LL_ETHERNET: + { + /* Size of the Ethernet MAC address */ - return IFHWADDRLEN; - } - else + return IFHWADDRLEN; + } #endif #ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_WIRELESS_IEEE802154 - if (lltype == NET_LL_IEEE802154) - { - /* 6LoWPAN can be configured to use either extended or short - * addressing. - */ + case NET_LL_IEEE802154: + { + /* 6LoWPAN can be configured to use either extended or short + * addressing. + */ #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - return NET_6LOWPAN_EADDRSIZE; + return NET_6LOWPAN_EADDRSIZE; #else - return NET_6LOWPAN_SADDRSIZE; + return NET_6LOWPAN_SADDRSIZE; #endif - } - else + } + #endif /* CONFIG_WIRELESS_IEEE802154 */ #ifdef CONFIG_WIRELESS_PKTRADIO - if (lltype == NET_LL_PKTRADIO) - { - /* REVISIT: This may no be the correct size if there are multiple - * packet radios. In that case, it will be the maxim address size - * amongst all of the radios. - */ + case NET_LL_PKTRADIO: + { + /* Return the size of the packet radio address */ - return CONFIG_PKTRADIO_ADDRLEN; - } - else + return netdev_pktradio_addrlen(dev); + } #endif /* CONFIG_WIRELESS_PKTRADIO */ #endif /* CONFIG_NET_6LOWPAN */ - { - /* Either the link layer type associated with lltype has no address, - * or support for that link layer type is not enabled. - */ - return 0; + default: + { + /* The link layer type associated has no address */ + + return 0; + } } }