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 function will return 0. If we
90 * don't support the nhc by nexthdr this function will return -ENOENT.
92 * @skb: skb of 6LoWPAN header to read nhc and replace header.
93 * @hdr: ipv6hdr to check the nexthdr value
94 * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of
97 int lowpan_nhc_check_compression(struct sk_buff *skb,
98 const struct ipv6hdr *hdr, u8 **hc_ptr);
101 * lowpan_nhc_do_compression - calling compress callback for nhc
103 * @skb: skb of 6LoWPAN header to read nhc and replace header.
104 * @hdr: ipv6hdr to set the nexthdr value
105 * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of
108 int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr,
112 * lowpan_nhc_do_uncompression - calling uncompress callback for nhc
114 * @nhc: 6LoWPAN nhc context, get by lowpan_nhc_by_ functions.
115 * @skb: skb of 6LoWPAN header, skb->data should be pointed to nhc id value.
116 * @dev: netdevice for print logging information.
117 * @hdr: ipv6hdr for setting nexthdr value.
119 int lowpan_nhc_do_uncompression(struct sk_buff *skb,
120 const struct net_device *dev,
121 struct ipv6hdr *hdr);
124 * lowpan_nhc_add - register a next header compression to framework
126 * @nhc: nhc which should be add.
128 int lowpan_nhc_add(struct lowpan_nhc *nhc);
131 * lowpan_nhc_del - delete a next header compression from framework
133 * @nhc: nhc which should be delete.
135 void lowpan_nhc_del(struct lowpan_nhc *nhc);
138 * lowpan_nhc_init - adding all default nhcs
140 void lowpan_nhc_init(void);
142 #endif /* __6LOWPAN_NHC_H */