From dc36bdb89db44b406363b18efa92aace641f5575 Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Mon, 11 Jul 2016 11:21:57 +0300 Subject: [PATCH] net: Integrate 6lo and 802.15.4 fragmentation Change-Id: I348656e0049d79f4dfdaba7909ad0b770f3ee922 Signed-off-by: Ravi kumar Veeramally --- net/yaip/6lo.c | 21 ++++++++++++++++----- net/yaip/6lo.h | 6 +++++- tests/net/6lo/src/main.c | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/net/yaip/6lo.c b/net/yaip/6lo.c index 04698efdfa9..d036812718b 100644 --- a/net/yaip/6lo.c +++ b/net/yaip/6lo.c @@ -93,7 +93,8 @@ static inline bool net_6lo_maddr_48_bit_compressible(struct in6_addr *addr) * context based (dst) address compression * Mesh header compression */ -static inline bool compress_IPHC_header(struct net_buf *buf) +static inline bool compress_IPHC_header(struct net_buf *buf, + fragment_handler_t fragment) { struct net_buf *frag; struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf); @@ -431,6 +432,10 @@ end: /* compact the fragments, so that gaps will be filled */ net_nbuf_compact(buf->frags); + if (fragment) { + return fragment(buf, compressed - offset); + } + return true; } @@ -752,7 +757,8 @@ fail: } /* Adds IPv6 dispatch as first byte and adjust fragments */ -static inline bool compress_ipv6_header(struct net_buf *buf) +static inline bool compress_ipv6_header(struct net_buf *buf, + fragment_handler_t fragment) { struct net_buf *frag; @@ -769,6 +775,10 @@ static inline bool compress_ipv6_header(struct net_buf *buf) /* compact the fragments, so that gaps will be filled */ buf->frags = net_nbuf_compact(buf->frags); + if (fragment) { + return fragment(buf, -1); + } + return true; } @@ -783,12 +793,13 @@ static inline bool uncompress_ipv6_header(struct net_buf *buf) return true; } -bool net_6lo_compress(struct net_buf *buf, bool iphc) +bool net_6lo_compress(struct net_buf *buf, bool iphc, + fragment_handler_t fragment) { if (iphc) { - return compress_IPHC_header(buf); + return compress_IPHC_header(buf, fragment); } else { - return compress_ipv6_header(buf); + return compress_ipv6_header(buf, fragment); } } diff --git a/net/yaip/6lo.h b/net/yaip/6lo.h index ce12f43ff65..65f6b14c563 100644 --- a/net/yaip/6lo.h +++ b/net/yaip/6lo.h @@ -28,6 +28,8 @@ #include +typedef bool (*fragment_handler_t)(struct net_buf *, int); + /** * @brief Compress IPv6 packet as per RFC 6282 * @@ -37,10 +39,12 @@ * * @param Pointer to network buffer * @param iphc true for IPHC compression, false for IPv6 dispatch header + * @param Pointer to fragment function * * @return True on success, false otherwise */ -bool net_6lo_compress(struct net_buf *buf, bool iphc); +bool net_6lo_compress(struct net_buf *buf, bool iphc, + fragment_handler_t fragment); /** * @brief Unompress IPv6 packet as per RFC 6282 diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index 7b393c03b60..f887a96b318 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -415,7 +415,7 @@ static int test_6lo(struct net_6lo_data *data) net_hexdump_frags("before-compression", buf); #endif - if (!net_6lo_compress(buf, data->iphc)) { + if (!net_6lo_compress(buf, data->iphc, NULL)) { TC_PRINT("compression failed\n"); goto end; }