net: Integrate 6lo and 802.15.4 fragmentation

Change-Id: I348656e0049d79f4dfdaba7909ad0b770f3ee922
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2016-07-11 11:21:57 +03:00 committed by Jukka Rissanen
commit dc36bdb89d
3 changed files with 22 additions and 7 deletions

View file

@ -93,7 +93,8 @@ static inline bool net_6lo_maddr_48_bit_compressible(struct in6_addr *addr)
* context based (dst) address compression * context based (dst) address compression
* Mesh header 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_buf *frag;
struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf); struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf);
@ -431,6 +432,10 @@ end:
/* compact the fragments, so that gaps will be filled */ /* compact the fragments, so that gaps will be filled */
net_nbuf_compact(buf->frags); net_nbuf_compact(buf->frags);
if (fragment) {
return fragment(buf, compressed - offset);
}
return true; return true;
} }
@ -752,7 +757,8 @@ fail:
} }
/* Adds IPv6 dispatch as first byte and adjust fragments */ /* 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; 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 */ /* compact the fragments, so that gaps will be filled */
buf->frags = net_nbuf_compact(buf->frags); buf->frags = net_nbuf_compact(buf->frags);
if (fragment) {
return fragment(buf, -1);
}
return true; return true;
} }
@ -783,12 +793,13 @@ static inline bool uncompress_ipv6_header(struct net_buf *buf)
return true; 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) { if (iphc) {
return compress_IPHC_header(buf); return compress_IPHC_header(buf, fragment);
} else { } else {
return compress_ipv6_header(buf); return compress_ipv6_header(buf, fragment);
} }
} }

View file

@ -28,6 +28,8 @@
#include <net/nbuf.h> #include <net/nbuf.h>
typedef bool (*fragment_handler_t)(struct net_buf *, int);
/** /**
* @brief Compress IPv6 packet as per RFC 6282 * @brief Compress IPv6 packet as per RFC 6282
* *
@ -37,10 +39,12 @@
* *
* @param Pointer to network buffer * @param Pointer to network buffer
* @param iphc true for IPHC compression, false for IPv6 dispatch header * @param iphc true for IPHC compression, false for IPv6 dispatch header
* @param Pointer to fragment function
* *
* @return True on success, false otherwise * @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 * @brief Unompress IPv6 packet as per RFC 6282

View file

@ -415,7 +415,7 @@ static int test_6lo(struct net_6lo_data *data)
net_hexdump_frags("before-compression", buf); net_hexdump_frags("before-compression", buf);
#endif #endif
if (!net_6lo_compress(buf, data->iphc)) { if (!net_6lo_compress(buf, data->iphc, NULL)) {
TC_PRINT("compression failed\n"); TC_PRINT("compression failed\n");
goto end; goto end;
} }