6loWPAN: Add IEEE802.15.4 Rime address to union of link layer addresses in the network driver.

This commit is contained in:
Gregory Nutt
2017-04-22 11:52:45 -06:00
parent 79256573e1
commit 7da031aea1
9 changed files with 43 additions and 51 deletions
+12 -3
View File
@@ -56,12 +56,16 @@
#include <net/ethernet.h> #include <net/ethernet.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/ip.h>
#ifdef CONFIG_NET_IGMP #ifdef CONFIG_NET_IGMP
# include <nuttx/net/igmp.h> # include <nuttx/net/igmp.h>
#endif #endif
#include <nuttx/net/netconfig.h> #ifdef CONFIG_NET_6LOWPAN
#include <nuttx/net/ip.h> # include <nuttx/net/ieee802154.h>
#endif
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@@ -207,7 +211,7 @@ struct net_driver_s
#endif #endif
#endif #endif
#if defined(CONFIG_NET_ETHERNET) #if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN)
/* Link layer address */ /* Link layer address */
union union
@@ -216,6 +220,11 @@ struct net_driver_s
/* Ethernet device identity */ /* Ethernet device identity */
struct ether_addr ether; /* Device Ethernet MAC address */ struct ether_addr ether; /* Device Ethernet MAC address */
#endif
#ifdef CONFIG_NET_6LOWPAN
/* The address assigned to an IEEE 802.15.4 radio. */
struct rimeaddr_s ieee802154; /* IEEE 802.15.4 Radio address */
#endif #endif
} d_mac; } d_mac;
#endif #endif
+2 -8
View File
@@ -366,9 +366,7 @@
* 2. i_dsn must be set to a random value. After that, it will be managed * 2. i_dsn must be set to a random value. After that, it will be managed
* by the network. * by the network.
* *
* 3. i_nodeaddr must be set after the MAC is assigned an address. * 3. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver
*
* 4. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver
* structure with i_framelist set to NULL. At the conclusion of the * structure with i_framelist set to NULL. At the conclusion of the
* poll, if there are frames to be sent, they will have been added to * poll, if there are frames to be sent, they will have been added to
* the i_framelist. The non-empty frame list at the conclusion of the * the i_framelist. The non-empty frame list at the conclusion of the
@@ -383,7 +381,7 @@
* After sending each frame, the driver must return the IOB to the pool * After sending each frame, the driver must return the IOB to the pool
* of free IOBs using the FROM_IOB_FREE() macro. * of free IOBs using the FROM_IOB_FREE() macro.
* *
* 5. When receiving data both buffers must be provided: * 4. When receiving data both buffers must be provided:
* *
* The IEEE802.15.4 MAC driver should receive the frame data directly * The IEEE802.15.4 MAC driver should receive the frame data directly
* into the payload area of an IOB structure. That IOB structure may be * into the payload area of an IOB structure. That IOB structure may be
@@ -444,10 +442,6 @@ struct ieee802154_driver_s
uint16_t i_panid; uint16_t i_panid;
/* i_node_addr. The address assigned to this node. */
struct rimeaddr_s i_nodeaddr;
/* i_dsn. The sequence number in the range 0x00-0xff added to the /* i_dsn. The sequence number in the range 0x00-0xff added to the
* transmitted data or MAC command frame. The default is a random value * transmitted data or MAC command frame. The default is a random value
* within that range. * within that range.
+5 -13
View File
@@ -707,13 +707,9 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
if (true) if (true)
#endif #endif
{ {
FAR struct ieee802154_driver_s *ieee =
(FAR struct ieee802154_driver_s *)dev;
req->ifr_hwaddr.sa_family = AF_INETX; req->ifr_hwaddr.sa_family = AF_INETX;
memcpy(req->ifr_hwaddr.sa_data, ieee->i_nodeaddr.u8, memcpy(req->ifr_hwaddr.sa_data,
NET_6LOWPAN_RIMEADDR_SIZE); dev->d_mac.ieee802154.u8, NET_6LOWPAN_RIMEADDR_SIZE);
ret = OK;
} }
else else
#endif #endif
@@ -750,13 +746,9 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
if (true) if (true)
#endif #endif
{ {
FAR struct ieee802154_driver_s *ieee = memcpy(dev->d_mac.ieee802154.u8,
(FAR struct ieee802154_driver_s *)dev; req->ifr_hwaddr.sa_data, NET_6LOWPAN_RIMEADDR_SIZE);
ret = OK;
req->ifr_hwaddr.sa_family = AF_INETX;
memcpy(ieee->i_nodeaddr.u8, req->ifr_hwaddr.sa_data,
NET_6LOWPAN_RIMEADDR_SIZE);
ret = OK;
} }
else else
#endif #endif
+10 -17
View File
@@ -112,9 +112,6 @@ static const linegen_t g_linegen[] =
static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile)
{ {
FAR struct net_driver_s *dev; FAR struct net_driver_s *dev;
#ifdef CONFIG_NET_6LOWPAN
FAR struct ieee802154_driver_s *ieee;
#endif
FAR const char *status; FAR const char *status;
int len = 0; int len = 0;
@@ -154,22 +151,20 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile)
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
case NET_LL_IEEE802154: case NET_LL_IEEE802154:
{ {
ieee = (FAR struct ieee802154_driver_s *)dev;
#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED #ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED
len += snprintf(&netfile->line[len], NET_LINELEN - len, len += snprintf(&netfile->line[len], NET_LINELEN - len,
"%s\tLink encap:6loWPAN HWaddr " "%s\tLink encap:6loWPAN HWaddr "
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
dev->d_ifname, dev->d_ifname,
ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3],
ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5],
ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7]); dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7]);
#else #else
len += snprintf(&netfile->line[len], NET_LINELEN - len, len += snprintf(&netfile->line[len], NET_LINELEN - len,
"%s\tLink encap:6loWPAN HWaddr %02x:%02x", "%s\tLink encap:6loWPAN HWaddr %02x:%02x",
dev->d_ifname, dev->d_ifname,
ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1]);
#endif #endif
} }
break; break;
@@ -218,23 +213,21 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile)
dev->d_ifname, ether_ntoa(&dev->d_mac.ether), status); dev->d_ifname, ether_ntoa(&dev->d_mac.ether), status);
#elif defined(CONFIG_NET_6LOWPAN) #elif defined(CONFIG_NET_6LOWPAN)
ieee = (FAR struct ieee802154_driver_s *)dev;
#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED #ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED
len += snprintf(&netfile->line[len], NET_LINELEN - len, len += snprintf(&netfile->line[len], NET_LINELEN - len,
"%s\tLink encap:6loWPAN HWaddr " "%s\tLink encap:6loWPAN HWaddr "
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s\n", "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s\n",
dev->d_ifname, dev->d_ifname,
ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3],
ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5],
ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7], dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7],
status); status);
#else #else
len += snprintf(&netfile->line[len], NET_LINELEN - len, len += snprintf(&netfile->line[len], NET_LINELEN - len,
"%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s\n", "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s\n",
dev->d_ifname, dev->d_ifname,
ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
status); status);
#endif #endif
#elif defined(CONFIG_NET_LOOPBACK) #elif defined(CONFIG_NET_LOOPBACK)
+2 -1
View File
@@ -283,7 +283,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Set the source and destinatino address */ /* Set the source and destinatino address */
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], &ieee->i_nodeaddr); rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_SENDER],
&ieee->i_dev.d_mac.ieee802154);
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac);
/* Pre-calculate frame header length. */ /* Pre-calculate frame header length. */
+2 -1
View File
@@ -366,7 +366,8 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
/* Set the source address to the node address assigned to the device */ /* Set the source address to the node address assigned to the device */
rimeaddr_copy((struct rimeaddr_s *)&params->src_addr, &ieee->i_nodeaddr); rimeaddr_copy((struct rimeaddr_s *)&params->src_addr,
&ieee->i_dev.d_mac.ieee802154);
/* Use short soruce address mode if so configured */ /* Use short soruce address mode if so configured */
+4 -2
View File
@@ -614,7 +614,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
/* Compression compare with this nodes address (source) */ /* Compression compare with this nodes address (source) */
iphc1 |= compress_addr_64(ipv6->srcipaddr, &ieee->i_nodeaddr, iphc1 |= compress_addr_64(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT); SIXLOWPAN_IPHC_SAM_BIT);
} }
@@ -624,7 +625,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 && ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 &&
ipv6->destipaddr[3] == 0) ipv6->destipaddr[3] == 0)
{ {
iphc1 |= compress_addr_64(ipv6->srcipaddr, &ieee->i_nodeaddr, iphc1 |= compress_addr_64(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT); SIXLOWPAN_IPHC_SAM_BIT);
} }
else else
+1 -1
View File
@@ -129,7 +129,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
if (ipv6->vtc != 0x60 || ipv6->tcf != 0 || ipv6->flow != 0 || if (ipv6->vtc != 0x60 || ipv6->tcf != 0 || ipv6->flow != 0 ||
!sixlowpan_islinklocal(ipv6->srcipaddr) || !sixlowpan_islinklocal(ipv6->srcipaddr) ||
!sixlowpan_ismacbased(ipv6->srcipaddr, &ieee->i_nodeaddr) || !sixlowpan_ismacbased(ipv6->srcipaddr, &ieee->i_dev.d_mac.ieee802154) ||
!sixlowpan_islinklocal(ipv6->destipaddr) || !sixlowpan_islinklocal(ipv6->destipaddr) ||
!sixlowpan_ismacbased(ipv6->destipaddr, destmac) || !sixlowpan_ismacbased(ipv6->destipaddr, destmac) ||
(ipv6->proto != IP_PROTO_ICMP6 && ipv6->proto != IP_PROTO_UDP && (ipv6->proto != IP_PROTO_ICMP6 && ipv6->proto != IP_PROTO_UDP &&
+5 -5
View File
@@ -365,14 +365,14 @@ static int lo_ifup(FAR struct net_driver_s *dev)
#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED #ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED
ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n", ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n",
priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
priv->lo_ieee.i_nodeaddr.u8[2], priv->lo_ieee.i_nodeaddr.u8[3], dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3],
priv->lo_ieee.i_nodeaddr.u8[4], priv->lo_ieee.i_nodeaddr.u8[5], dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5],
priv->lo_ieee.i_nodeaddr.u8[6], priv->lo_ieee.i_nodeaddr.u8[7], dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7],
priv->lo_ieee.i_panid); priv->lo_ieee.i_panid);
#else #else
ninfo(" Node: %02x:%02x PANID=%04x\n", ninfo(" Node: %02x:%02x PANID=%04x\n",
priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
priv->lo_ieee.i_panid); priv->lo_ieee.i_panid);
#endif #endif