From 1cf891bbe1c30496fe2c930ce0df257947f136e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 11:33:22 -0600 Subject: [PATCH] Another baby step in removing MAC knowledge from 6loWPAN. --- include/nuttx/net/ieee802154.h | 44 ---------- include/nuttx/net/netdev.h | 4 +- include/nuttx/net/sixlowpan.h | 13 ++- net/sixlowpan/sixlowpan_framelist.c | 29 +++++-- net/sixlowpan/sixlowpan_framer.c | 103 +++++++++++++++++------ net/sixlowpan/sixlowpan_globals.c | 15 +++- net/sixlowpan/sixlowpan_hc06.c | 26 +++--- net/sixlowpan/sixlowpan_hc1.c | 8 -- net/sixlowpan/sixlowpan_input.c | 27 ++++-- net/sixlowpan/sixlowpan_internal.h | 53 +++++++++--- wireless/ieee802154/mac802154_loopback.c | 2 +- wireless/ieee802154/mac802154_netdev.c | 2 +- 12 files changed, 206 insertions(+), 120 deletions(-) diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h index 9d9260f61b..b677195715 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/ieee802154.h @@ -72,50 +72,6 @@ # define NET_6LOWPAN_ADDRSIZE NET_6LOWPAN_SADDRSIZE #endif -/* Frame format definitions *************************************************/ -/* These are some definitions of element values used in the FCF. See the - * IEEE802.15.4 spec for details. - */ - -#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ -#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) -#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ -#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ -#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ -#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ - /* Bits 7-9: Reserved */ -#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ -#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) -#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ -#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) -#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ -#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) - -/* Unshifted values for use in struct frame802154_fcf_s */ - -#define FRAME802154_BEACONFRAME (0) -#define FRAME802154_DATAFRAME (1) -#define FRAME802154_ACKFRAME (2) -#define FRAME802154_CMDFRAME (3) - -#define FRAME802154_BEACONREQ (7) - -#define FRAME802154_IEEERESERVED (0) -#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ -#define FRAME802154_SHORTADDRMODE (2) -#define FRAME802154_LONGADDRMODE (3) - -#define FRAME802154_NOBEACONS 0x0f - -#define FRAME802154_BROADCASTADDR 0xffff -#define FRAME802154_BROADCASTPANDID 0xffff - -#define FRAME802154_IEEE802154_2003 (0) -#define FRAME802154_IEEE802154_2006 (1) - -#define FRAME802154_SECURITY_LEVEL_NONE (0) -#define FRAME802154_SECURITY_LEVEL_128 (3) - /* This maximum size of an IEEE802.15.4 frame. Certain, non-standard * devices may exceed this value, however. */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index fe2743f5e9..0b65d2afd3 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -437,9 +437,11 @@ int ipv6_input(FAR struct net_driver_s *dev); #ifdef CONFIG_NET_6LOWPAN struct ieee802154_driver_s; /* See sixlowpan.h */ +struct eee802154_data_ind_s; /* See sixlowpan.h */ struct iob_s; /* See iob.h */ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist); + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind); #endif /**************************************************************************** diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 91869dd41f..48370a79e5 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -342,6 +342,7 @@ */ struct ieee802154_frame_meta_s; /* Forward reference */ +struct eee802154_data_ind_s; /* Forward reference */ struct iob_s; /* Forward reference */ struct ieee802154_driver_s @@ -420,7 +421,7 @@ struct ieee802154_driver_s /* The source MAC address of the fragments being merged */ - struct sixlowpan_addr_s i_fragsrc; + union sixlowpan_anyaddr_u i_fragsrc; /* That time at which reassembly was started. If the elapsed time * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will @@ -525,7 +526,12 @@ struct ieee802154_driver_s * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. - * framelist - The head of an incoming list of frames. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * ind - Meta data characterizing the received packet. If there are + * multilple frames in the list, this meta data must apply to + * all of the frames! * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -533,7 +539,8 @@ struct ieee802154_driver_s ****************************************************************************/ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist); + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind); #endif /* CONFIG_NET_6LOWPAN */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWPAN_H */ diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 005473c4e0..46e2bd750d 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -234,7 +234,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Reset address buffer and packet buffer metatadata */ memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); - memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct sixlowpan_addr_s)); + memset(&g_packet_meta, 0, sizeof(struct packet_metadata_s)); g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; @@ -284,11 +284,30 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, ninfo("Sending packet length %d\n", buflen); - /* Set the source and destination address */ + /* Set the source and destination address. The source MAC address + * is a fixed size, determined by a configuration setting. The + * destination MAC address many be either short or extended. + */ - sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], - &ieee->i_dev.d_mac.ieee802154); - sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + g_packet_meta.sextended = TRUE; + sixlowpan_eaddrcopy(g_packet_meta.source.eaddr.u8, + &ieee->i_dev.d_mac.ieee802154); +#else + sixlowpan_saddrcopy(g_packet_meta.source.saddr.u8, + &ieee->i_dev.d_mac.ieee802154); +#endif + + /* REVISIT: Destination MAC address could be of different size than + * the source MAC address. + */ + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + g_packet_meta.dextended = TRUE; + sixlowpan_addrcopy(g_packet_meta.dest.eaddr.u8, destmac); +#else + sixlowpan_addrcopy(g_packet_meta.dest.saddr.u8, destmac); +#endif /* Get the destination PAN ID. * diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 49b1548498..db2ac6dfce 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -67,27 +67,26 @@ ****************************************************************************/ /**************************************************************************** - * Name: sixlowpan_addrnull + * Name: sixlowpan_anyaddrnull * * Description: - * If the output address is NULL in the MAC header buf, then it is + * If the destination address is all zero in the MAC header buf, then it is * broadcast on the 802.15.4 network. * * Input parameters: - * addrmode - The address mode + * addr - The address to check + * addrlen - The length of the address in bytes * * Returned Value: - * The address length associated with the address mode. + * True if the address is all zero. * ****************************************************************************/ -static bool sixlowpan_addrnull(FAR uint8_t *addr) +static bool sixlowpan_anyaddrnull(FAR uint8_t *addr, uint8_t addrlen) { - int i = NET_6LOWPAN_ADDRSIZE; - - while (i-- > 0) + while (addrlen-- > 0) { - if (addr[i] != 0x00) + if (addr[addrlen] != 0x00) { return false; } @@ -96,6 +95,46 @@ static bool sixlowpan_addrnull(FAR uint8_t *addr) return true; } +/**************************************************************************** + * Name: sixlowpan_saddrnull + * + * Description: + * If the destination address is all zero in the MAC header buf, then it is + * broadcast on the 802.15.4 network. + * + * Input parameters: + * eaddr - The short address to check + * + * Returned Value: + * The address length associated with the address mode. + * + ****************************************************************************/ + +static inline bool sixlowpan_saddrnull(FAR uint8_t *saddr) +{ + return sixlowpan_anyaddrnull(saddr, NET_6LOWPAN_SADDRSIZE); +} + +/**************************************************************************** + * Name: sixlowpan_eaddrnull + * + * Description: + * If the destination address is all zero in the MAC header buf, then it is + * broadcast on the 802.15.4 network. + * + * Input parameters: + * eaddr - The extended address to check + * + * Returned Value: + * The address length associated with the address mode. + * + ****************************************************************************/ + +static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) +{ + return sixlowpan_anyaddrnull(eaddr, NET_6LOWPAN_EADDRSIZE); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -142,7 +181,15 @@ int sixlowpan_meta_data(uint16_t dest_panid, * broadcast on the 802.15.4 network. */ - rcvrnull = sixlowpan_addrnull(g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); + if (g_packet_meta.dextended != 0) + { + rcvrnull = sixlowpan_eaddrnull(g_packet_meta.dest.eaddr.u8); + } + else + { + rcvrnull = sixlowpan_saddrnull(g_packet_meta.dest.saddr.u8); + } + if (rcvrnull) { meta->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK]; @@ -175,26 +222,30 @@ int sixlowpan_meta_data(uint16_t dest_panid, meta->dest_addr[0] = 0xff; meta->dest_addr[1] = 0xff; } + else if (g_packet_meta.dextended != 0) + { + meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; + sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, + g_packet_meta.dest.eaddr.u8); + } else { - /* Copy the destination address */ - - sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, - g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); - - /* Use short destination address mode if so configured */ - -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; -#else meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; -#endif + sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, + g_packet_meta.dest.saddr.u8); } - /* Set the source address to the node address assigned to the device */ - - sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->src_addr, - &ieee->i_dev.d_mac.ieee802154); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + DEBUGASSERT(g_packet_meta.sextended != 0); + meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; + sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, + g_packet_meta.source.eaddr.u8); +#else + DEBUGASSERT(g_packet_meta.sextended == 0); + meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; + sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, + g_packet_meta.source.saddr.u8); +#endif /* Use short soruce address mode if so configured */ @@ -203,7 +254,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, #else meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; #endif -#endif +#endif /* 0 */ #warning Missing logic return -ENOSYS; diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index 646e2fec21..c1f4f9ef50 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -67,9 +67,22 @@ uint8_t g_uncomp_hdrlen; uint8_t g_frame_hdrlen; +/* In order to provide a customizable IEEE 802.15.4 MAC header, a structure + * of meta data is passed to the MAC network driver, struct + * ieee802154_frame_meta_s. Many of the settings in this meta data are + * fixed, deterimined by the 6loWPAN configuration. Other settings depend + * on the protocol used in the current packet or on chacteristics of the + * destination node. + * + * The following structure is used to summarize those per-packet + * customizations and, along, with the fixed configuratin settings, + * determines the full form of that meta data. + */ + /* Packet buffer metadata: Attributes and addresses */ uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; + +struct packet_metadata_s g_packet_meta; #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 2a262f5b53..0413e834c9 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -275,7 +275,7 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, ****************************************************************************/ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], - uint8_t prefpost, FAR struct sixlowpan_addr_s *macaddr) + uint8_t prefpost) { uint8_t prefcount = prefpost >> 4; uint8_t postcount = prefpost & 0x0f; @@ -316,7 +316,7 @@ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], { /* No IID based configuration if no prefix and no data => unspec */ - sixlowpan_ipfromaddr(macaddr, ipaddr); + nwarn("WARNING: No IID based configuration\n") } ninfo("Uncompressing %d + %d => %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", @@ -983,18 +983,22 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, } } - /* If tmp == 0 we do not have a Address context and therefore no prefix */ + /* If tmp == 0 we do not have a address context and therefore no prefix */ + /* REVISIT: Source address may not be the same size as the destination + * address. + */ uncompress_addr(ipv6->srcipaddr, - tmp != 0 ? addrcontext->prefix : NULL, g_unc_ctxconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + tmp != 0 ? addrcontext->prefix : NULL, g_unc_ctxconf[tmp]); } else { /* No compression and link local */ + /* REVISIT: Source address may not be the same size as the destination + * address. + */ - uncompress_addr(ipv6->srcipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + uncompress_addr(ipv6->srcipaddr, g_llprefix, g_unc_llconf[tmp]); } /* Destination address */ @@ -1029,7 +1033,7 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, g_hc06ptr++; } - uncompress_addr(ipv6->destipaddr, prefix, g_unc_mxconf[tmp], NULL); + uncompress_addr(ipv6->destipaddr, prefix, g_unc_mxconf[tmp]); } } else @@ -1052,15 +1056,13 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, return; } - uncompress_addr(ipv6->destipaddr, addrcontext->prefix, g_unc_ctxconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + uncompress_addr(ipv6->destipaddr, addrcontext->prefix, g_unc_ctxconf[tmp]); } else { /* Not address context based => link local M = 0, DAC = 0 - same as SAC */ - uncompress_addr(ipv6->destipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + uncompress_addr(ipv6->destipaddr, g_llprefix, g_unc_llconf[tmp]); } } diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index d0e5b13d99..88d7f72412 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -271,14 +271,6 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, ipv6->tcf = 0; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ ipv6->flow = 0; /* 16-bit flow label (LS) */ - /* Use stateless auto-configuration to set source and destination IP - * addresses. - */ - - sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_SENDER], - ipv6->srcipaddr); - sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], - ipv6->destipaddr); g_uncomp_hdrlen += IPv6_HDRLEN; /* len[], proto, and ttl depend on the encoding */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 7a2621cfba..58ee8af571 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -401,8 +401,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Verify that this fragment is part of that reassembly sequence */ - else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag || - !sixlowpan_addrcmp(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER])) + else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag /* || + !sixlowpan_addrcmp(&ieee->i_fragsrc, &ind->???) */) { /* The packet is a fragment that does not belong to the packet * being reassembled or the packet is not a fragment. @@ -454,7 +454,15 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, ninfo("Starting reassembly: i_pktlen %u, i_reasstag %d\n", ieee->i_pktlen, ieee->i_reasstag); - sixlowpan_addrcopy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); + /* Extract the source address from the 'ind' meta data. NOTE that the + * size of the source address may be different that our local, destination + * address. + */ + +#warning Missing logic +#if 0 + sixlowpan_addrcopy(&ieee->i_fragsrc, ind->???]); +#endif } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -496,7 +504,6 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_FRAG /* Is this the first fragment is a sequence? */ - if (isfirstfrag) { /* Yes.. Remember the offset from the beginning of d_buf where we @@ -517,6 +524,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = ieee->i_boffset; } + + #endif /* CONFIG_NET_6LOWPAN_FRAG */ /* Copy "payload" from the frame buffer to the IEEE802.15.4 MAC driver's @@ -686,7 +695,12 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. - * framelist - The head of an incoming list of frames. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * ind - Meta data characterizing the received packet. If there are + * multilple frames in the list, this meta data must apply to + * all of the frames! * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -694,7 +708,8 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) ****************************************************************************/ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist) + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind) { int ret = -EINVAL; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index aefe48b11b..1720ddcdf4 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -74,13 +74,31 @@ /* IEEE 802.15.4 addres macros */ /* Copy a an IEEE 802.15.4 address */ +#define sixlowpan_anyaddrcopy(dest,src,len) \ + memcpy(dest, src, len) + +#define sixlowpan_saddrcopy(dest,src) \ + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_SADDRSIZE) + +#define sixlowpan_aeddrcopy(dest,src) \ + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_EADDRSIZE) + #define sixlowpan_addrcopy(dest,src) \ - memcpy(dest, src, NET_6LOWPAN_ADDRSIZE) + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_ADDRSIZE) /* Compare two IEEE 802.15.4 addresses */ +#define sixlowpan_anyaddrcmp(addr1,addr2,len) \ + (memcmp(addr1, addr2, len) == 0) + +#define sixlowpan_saddrcmp(addr1,addr2) \ + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_SADDRSIZE) + +#define sixlowpan_eaddrcmp(addr1,addr2) \ + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_EADDRSIZE) + #define sixlowpan_addrcmp(addr1,addr2) \ - (memcmp(addr1, addr2, NET_6LOWPAN_ADDRSIZE) == 0) + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_ADDRSIZE) /* Packet buffer Definitions */ @@ -127,15 +145,6 @@ #define PACKETBUF_NUM_ATTRS 23 -/* Addresses (indices into g_pktaddrs) */ - -#define PACKETBUF_ADDR_SENDER 0 -#define PACKETBUF_ADDR_RECEIVER 1 -#define PACKETBUF_ADDR_ESENDER 2 -#define PACKETBUF_ADDR_ERECEIVER 3 - -#define PACKETBUF_NUM_ADDRS 4 - /* General helper macros ****************************************************/ #define GETINT16(ptr,index) \ @@ -185,6 +194,26 @@ struct ipv6icmp_hdr_s struct icmpv6_iphdr_s icmp; }; +/* In order to provide a customizable IEEE 802.15.4 MAC header, a structure + * of meta data is passed to the MAC network driver, struct + * ieee802154_frame_meta_s. Many of the settings in this meta data are + * fixed, deterimined by the 6loWPAN configuration. Other settings depend + * on the protocol used in the current packet or on chacteristics of the + * destination node. + * + * The following structure is used to summarize those per-packet + * customizations and, along, with the fixed configuratin settings, + * determines the full form of that meta data. + */ + +struct packet_metadata_s +{ + uint8_t sextended : 1; /* Extended source address */ + uint8_t dextended : 1; /* Extended destination address */ + union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */ + union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -212,7 +241,7 @@ extern uint8_t g_frame_hdrlen; /* Packet buffer metadata: Attributes and addresses */ extern uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -extern struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; +extern struct packet_metadata_s g_packet_meta; /**************************************************************************** * Public Types diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 51780af2c4..8b0abaf5b5 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -211,7 +211,7 @@ static int lo_loopback(FAR struct net_driver_s *dev) ninfo("Send frame %p to the network: Offset=%u Length=%u\n", iob, iob->io_offset, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee, iob); + ret = sixlowpan_input(&priv->lo_ieee, iob, NULL); /* Increment statistics */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index b81ad465bc..bf4c9013cb 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -718,7 +718,7 @@ static void macnet_receive(FAR struct macnet_driver_s *priv) /* Transfer the frame to the network logic */ - sixlowpan_input(&priv->md_dev, iob); + sixlowpan_input(&priv->md_dev, iob, NULL); } /****************************************************************************