6lowpan: remove lowpan_fetch_skb_u8
[deliverable/linux.git] / net / 6lowpan / nhc.h
CommitLineData
92aa7c65
AA
1#ifndef __6LOWPAN_NHC_H
2#define __6LOWPAN_NHC_H
3
4#include <linux/skbuff.h>
5#include <linux/rbtree.h>
6#include <linux/module.h>
7
8#include <net/6lowpan.h>
9#include <net/ipv6.h>
10
92aa7c65
AA
11/**
12 * LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct
13 *
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.
22 */
23#define LOWPAN_NHC(__nhc, _name, _nexthdr, \
24 _hdrlen, _idsetup, _idlen, \
25 _uncompress, _compress) \
26static u8 __nhc##_val[_idlen]; \
27static u8 __nhc##_mask[_idlen]; \
28static struct lowpan_nhc __nhc = { \
29 .name = _name, \
30 .nexthdr = _nexthdr, \
31 .nexthdrlen = _hdrlen, \
32 .id = __nhc##_val, \
33 .idmask = __nhc##_mask, \
34 .idlen = _idlen, \
35 .idsetup = _idsetup, \
36 .uncompress = _uncompress, \
37 .compress = _compress, \
38}
39
40#define module_lowpan_nhc(__nhc) \
41static int __init __nhc##_init(void) \
42{ \
43 return lowpan_nhc_add(&(__nhc)); \
44} \
45module_init(__nhc##_init); \
46static void __exit __nhc##_exit(void) \
47{ \
48 lowpan_nhc_del(&(__nhc)); \
49} \
50module_exit(__nhc##_exit);
51
52/**
53 * struct lowpan_nhc - hold 6lowpan next hdr compression ifnformation
54 *
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.
65 */
66struct lowpan_nhc {
67 struct rb_node node;
68 const char *name;
69 const u8 nexthdr;
70 const size_t nexthdrlen;
71 u8 *id;
72 u8 *idmask;
73 const size_t idlen;
74
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);
78};
79
80/**
81 * lowpan_nhc_by_nexthdr - return the 6lowpan nhc by ipv6 nexthdr.
82 *
83 * @nexthdr: ipv6 nexthdr value.
84 */
85struct lowpan_nhc *lowpan_nhc_by_nexthdr(u8 nexthdr);
86
87/**
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
91 * 6LoWPAN header.
92 *
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
96 * replaced header.
97 * @iphc0: iphc0 pointer to set the 6LoWPAN NHC bit
98 */
99int lowpan_nhc_check_compression(struct sk_buff *skb,
100 const struct ipv6hdr *hdr, u8 **hc_ptr,
101 u8 *iphc0);
102
103/**
104 * lowpan_nhc_do_compression - calling compress callback for nhc
105 *
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
109 * replaced header.
110 */
111int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr,
112 u8 **hc_ptr);
113
114/**
115 * lowpan_nhc_do_uncompression - calling uncompress callback for nhc
116 *
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.
121 */
8911d774
AA
122int lowpan_nhc_do_uncompression(struct sk_buff *skb,
123 const struct net_device *dev,
92aa7c65
AA
124 struct ipv6hdr *hdr);
125
126/**
127 * lowpan_nhc_add - register a next header compression to framework
128 *
129 * @nhc: nhc which should be add.
130 */
131int lowpan_nhc_add(struct lowpan_nhc *nhc);
132
133/**
134 * lowpan_nhc_del - delete a next header compression from framework
135 *
136 * @nhc: nhc which should be delete.
137 */
138void lowpan_nhc_del(struct lowpan_nhc *nhc);
139
140/**
141 * lowpan_nhc_init - adding all default nhcs
142 */
143void lowpan_nhc_init(void);
144
145#endif /* __6LOWPAN_NHC_H */
This page took 0.056019 seconds and 5 git commands to generate.