From 0eb7ec046ed31b2831cd9958c8557f0845836db4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 11:36:16 -0600 Subject: [PATCH] 6loWPAN: Use information in struct ieee802154_data_ind_s when reassembling a packet --- include/nuttx/net/netdev.h | 8 +-- include/nuttx/net/sixlowpan.h | 6 +- net/sixlowpan/sixlowpan_input.c | 76 +++++++++++++++++++++--- wireless/ieee802154/mac802154_loopback.c | 5 +- 4 files changed, 78 insertions(+), 17 deletions(-) diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 0b65d2afd3..782c2e3399 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -436,12 +436,12 @@ int ipv6_input(FAR struct net_driver_s *dev); #endif #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 */ +struct ieee802154_driver_s; /* See sixlowpan.h */ +struct ieee802154_data_ind_s; /* See ieee8021454_mac.h */ +struct iob_s; /* See iob.h */ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *framelist, - FAR const struct eee802154_data_ind_s *ind); + FAR const struct ieee802154_data_ind_s *ind); #endif /**************************************************************************** diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 591687bb1d..a99f0e5e67 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -342,7 +342,7 @@ */ struct ieee802154_frame_meta_s; /* Forward reference */ -struct eee802154_data_ind_s; /* Forward reference */ +struct ieee802154_data_ind_s; /* Forward reference */ struct iob_s; /* Forward reference */ struct ieee802154_driver_s @@ -421,7 +421,7 @@ struct ieee802154_driver_s /* The source MAC address of the fragments being merged */ - union sixlowpan_anyaddr_u i_fragsrc; + struct sixlowpan_tagaddr_s i_fragsrc; /* That time at which reassembly was started. If the elapsed time * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will @@ -540,7 +540,7 @@ struct ieee802154_driver_s int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *framelist, - FAR const struct eee802154_data_ind_s *ind); + FAR const struct ieee802154_data_ind_s *ind); #endif /* CONFIG_NET_6LOWPAN */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWPAN_H */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 3c203d07a1..9739ab7f61 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -61,6 +61,7 @@ #include "nuttx/net/netdev.h" #include "nuttx/net/ip.h" #include "nuttx/net/sixlowpan.h" +#include "nuttx/wireless/ieee802154/ieee802154_mac.h" #ifdef CONFIG_NET_PKT # include "pkt/pkt.h" @@ -129,6 +130,55 @@ static uint8_t g_bitbucket[UNCOMP_MAXHDR]; * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: sixlowpan_compare_fragsrc + * + * Description: + * Check if the fragment that we just received is from the same source as + * the previosly received fragements. + * + * Input Parameters: + * ieee - IEEE 802.15.4 MAC driver state reference + * ind - Characteristics of the newly received frame + * + * Returned Value: + * true if the sources are the same. + * + ****************************************************************************/ + +static bool sixlowpan_compare_fragsrc(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_data_ind_s *ind) +{ + /* Check for an extended source address */ + + if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) + { + /* Was the first source address also extended? */ + + if (ieee->i_fragsrc.extended) + { + /* Yes.. perform the extended address comparison */ + + return sixlowpan_eaddrcmp(ieee->i_fragsrc.u.eaddr.u8, ind->src.eaddr); + } + } + else + { + /* Short source address. Was the first source address also short? */ + + if (!ieee->i_fragsrc.extended) + { + /* Yes.. perform the extended short comparison */ + + return sixlowpan_saddrcmp(ieee->i_fragsrc.u.saddr.u8, &ind->src.saddr); + } + } + + /* Address are different size and, hence, cannot match */ + + return false; +} + /**************************************************************************** * Name: sixlowpan_compress_ipv6hdr * @@ -235,6 +285,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. + * ind - Meta data characterizing the received frame. * iob - The IOB containing the frame. * * Returned Value: @@ -246,6 +297,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) ****************************************************************************/ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_data_ind_s *ind, FAR struct iob_s *iob) { FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */ @@ -401,8 +453,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, &ind->???) */) + else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag || + !sixlowpan_compare_fragsrc(ieee, ind)) { /* The packet is a fragment that does not belong to the packet * being reassembled or the packet is not a fragment. @@ -459,10 +511,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * address. */ -#warning Missing logic -#if 0 - sixlowpan_addrcopy(&ieee->i_fragsrc, ind->???]); -#endif + if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) + { + ieee->i_fragsrc.extended = true; + sixlowpan_eaddrcopy(ieee->i_fragsrc.u.eaddr.u8, ind->src.eaddr); + } + else + { + memset(&ieee->i_fragsrc, 0, sizeof(struct sixlowpan_tagaddr_s)); + sixlowpan_saddrcopy(ieee->i_fragsrc.u.saddr.u8, &ind->src.saddr); + } } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -698,7 +756,7 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * 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 + * ind - Meta data characterizing the received frame. If there are * multilple frames in the list, this meta data must apply to * all of the frames! * @@ -709,7 +767,7 @@ 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 const struct eee802154_data_ind_s *ind) + FAR const struct ieee802154_data_ind_s *ind) { int ret = -EINVAL; @@ -730,7 +788,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, /* Process the frame, decompressing it into the packet buffer */ - ret = sixlowpan_frame_process(ieee, iob); + ret = sixlowpan_frame_process(ieee, ind, iob); /* Free the IOB the held the consumed frame */ diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index f30953a386..47940329c7 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -176,9 +176,12 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, static int lo_loopback(FAR struct net_driver_s *dev) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + struct ieee802154_data_ind_s ind; FAR struct iob_s *iob; int ret; + memset(&ind, 0, sizeof(struct ieee802154_data_ind_s)); + /* Loop while there framelist to be sent, i.e., while the freme list is not * emtpy. Sending, of course, just means relaying back through the network * for this driver. @@ -210,7 +213,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, NULL); + ret = sixlowpan_input(&priv->lo_ieee, iob, &ind); /* Increment statistics */