1 #ifndef __6LOWPAN_NHC_H
2 #define __6LOWPAN_NHC_H
4 #include <linux/skbuff.h>
5 #include <linux/rbtree.h>
6 #include <linux/module.h>
8 #include <net/6lowpan.h>
12 * LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct
14 * @__nhc: variable name of the lowpan_nhc struct.
15 * @_name: const char * of common header compression name.
16 * @_nexthdr: ipv6 nexthdr field for the header compression.
17 * @_nexthdrlen: ipv6 nexthdr len for the reserved space.
18 * @_idsetup: callback to setup id and mask values.
19 * @_idlen: len for the next header id and mask, should be always the same.
20 * @_uncompress: callback for uncompression call.
21 * @_compress: callback for compression call.
23 #define LOWPAN_NHC(__nhc, _name, _nexthdr, \
24 _hdrlen, _idsetup, _idlen, \
25 _uncompress, _compress) \
26 static u8 __nhc##_val[_idlen]; \
27 static u8 __nhc##_mask[_idlen]; \
28 static struct lowpan_nhc __nhc = { \
30 .nexthdr = _nexthdr, \
31 .nexthdrlen = _hdrlen, \
33 .idmask = __nhc##_mask, \
35 .idsetup = _idsetup, \
36 .uncompress = _uncompress, \
37 .compress = _compress, \
40 #define module_lowpan_nhc(__nhc) \
41 static int __init __nhc##_init(void) \
43 return lowpan_nhc_add(&(__nhc)); \
45 module_init(__nhc##_init); \
46 static void __exit __nhc##_exit(void) \
48 lowpan_nhc_del(&(__nhc)); \
50 module_exit(__nhc##_exit);
53 * struct lowpan_nhc - hold 6lowpan next hdr compression ifnformation
55 * @node: holder for the rbtree.
56 * @name: name of the specific next header compression
57 * @nexthdr: next header value of the protocol which should be compressed.
58 * @nexthdrlen: ipv6 nexthdr len for the reserved space.
59 * @id: array for nhc id. Note this need to be in network byteorder.
60 * @mask: array for nhc id mask. Note this need to be in network byteorder.
61 * @len: the length of the next header id and mask.
62 * @setup: callback to setup fill the next header id value and mask.
63 * @compress: callback to do the header compression.
64 * @uncompress: callback to do the header uncompression.
70 const size_t nexthdrlen;
75 void (*idsetup)(struct lowpan_nhc *nhc);
76 int (*uncompress)(struct sk_buff *skb, size_t needed);
77 int (*compress)(struct sk_buff *skb, u8 **hc_ptr);
81 * lowpan_nhc_by_nexthdr - return the 6lowpan nhc by ipv6 nexthdr.
83 * @nexthdr: ipv6 nexthdr value.
85 struct lowpan_nhc *lowpan_nhc_by_nexthdr(u8 nexthdr);
88 * lowpan_nhc_check_compression - checks if we support compression format. If
89 * we support the nhc by nexthdr field, the 6LoWPAN iphc NHC bit will be
90 * set. If we don't support nexthdr will be added as inline data to the
93 * @skb: skb of 6LoWPAN header to read nhc and replace header.
94 * @hdr: ipv6hdr to check the nexthdr value
95 * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of
97 * @iphc0: iphc0 pointer to set the 6LoWPAN NHC bit
99 int lowpan_nhc_check_compression(struct sk_buff *skb,
100 const struct ipv6hdr *hdr, u8 **hc_ptr,
104 * lowpan_nhc_do_compression - calling compress callback for nhc
106 * @skb: skb of 6LoWPAN header to read nhc and replace header.
107 * @hdr: ipv6hdr to set the nexthdr value
108 * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of
111 int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr,
115 * lowpan_nhc_do_uncompression - calling uncompress callback for nhc
117 * @nhc: 6LoWPAN nhc context, get by lowpan_nhc_by_ functions.
118 * @skb: skb of 6LoWPAN header, skb->data should be pointed to nhc id value.
119 * @dev: netdevice for print logging information.
120 * @hdr: ipv6hdr for setting nexthdr value.
122 int lowpan_nhc_do_uncompression(struct sk_buff *skb, struct net_device *dev,
123 struct ipv6hdr *hdr);
126 * lowpan_nhc_add - register a next header compression to framework
128 * @nhc: nhc which should be add.
130 int lowpan_nhc_add(struct lowpan_nhc *nhc);
133 * lowpan_nhc_del - delete a next header compression from framework
135 * @nhc: nhc which should be delete.
137 void lowpan_nhc_del(struct lowpan_nhc *nhc);
140 * lowpan_nhc_init - adding all default nhcs
142 void lowpan_nhc_init(void);
144 #endif /* __6LOWPAN_NHC_H */