Currently we match fragmentation frames only on his tagid. This patch
adds support to match also on source and destination address.

Signed-off-by: Alexander Aring <alex.ar...@gmail.com>
---
 net/ieee802154/6lowpan.c | 13 ++++++++++++-
 net/ieee802154/6lowpan.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 6df928f..0da513b 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -84,6 +84,8 @@ struct lowpan_fragment {
        u16                     length;         /* length to be assemled */
        u32                     bytes_rcv;      /* bytes received */
        u16                     tag;            /* current fragment tag */
+       struct ieee802154_addr  sa;             /* source address */
+       struct ieee802154_addr  da;             /* destination address */
        struct timer_list       timer;          /* assembling timer */
        struct list_head        list;           /* fragments list */
 };
@@ -760,6 +762,11 @@ lowpan_alloc_new_frame(struct sk_buff *skb, u16 len, u16 
tag)
 
        frame->length = len;
        frame->tag = tag;
+       memcpy(&frame->sa, &mac_cb(skb)->sa,
+                       sizeof(struct ieee802154_addr));
+       memcpy(&frame->da, &mac_cb(skb)->da,
+                       sizeof(struct ieee802154_addr));
+
 
        /* allocate buffer for frame assembling */
        frame->skb = netdev_alloc_skb(skb->dev, frame->length);
@@ -1228,7 +1235,11 @@ static struct lowpan_fragment *lowpan_get_frame(
        struct lowpan_fragment *frame;
 
        list_for_each_entry(frame, &lowpan_fragments, list) {
-               if (frame->tag == d_tag)
+               if (frame->tag == d_tag &&
+                               lowpan_equal_ieee802154_addr(&frame->sa,
+                                       &mac_cb(skb)->sa) &&
+                               lowpan_equal_ieee802154_addr(&frame->da,
+                                       &mac_cb(skb)->da))
                        return frame;
        }
 
diff --git a/net/ieee802154/6lowpan.h b/net/ieee802154/6lowpan.h
index 1b1b5db..05a2a37 100644
--- a/net/ieee802154/6lowpan.h
+++ b/net/ieee802154/6lowpan.h
@@ -246,4 +246,32 @@ static inline bool lowpan_fetch_skb(struct sk_buff *skb,
        return false;
 }
 
+/* Checks if ieee802154_addr are equals,
+ * if yes return 1 otherwise 0
+ */
+static inline int lowpan_equal_ieee802154_addr(struct ieee802154_addr *a,
+               struct ieee802154_addr *b)
+{
+       if (a->pan_id != b->pan_id)
+               return 0;
+
+       if (a->addr_type != b->addr_type)
+               return 0;
+
+       switch (a->addr_type) {
+       case IEEE802154_ADDR_LONG:
+               if (memcmp(a->hwaddr, b->hwaddr, IEEE802154_ADDR_LEN))
+                       return 0;
+               break;
+       case IEEE802154_ADDR_SHORT:
+               if (a->short_addr != b->short_addr)
+                       return 0;
+               break;
+       default:
+               return 0;
+       }
+
+       return 1;
+}
+
 #endif /* __6LOWPAN_H__ */
-- 
1.8.4


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to