1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#ifndef __6LOWPAN_H__
54#define __6LOWPAN_H__
55
56#include <linux/debugfs.h>
57
58#include <net/ipv6.h>
59#include <net/net_namespace.h>
60
61
62#include <net/mac802154.h>
63
64#define EUI64_ADDR_LEN 8
65
66#define LOWPAN_NHC_MAX_ID_LEN 1
67
68
69
70#define LOWPAN_NHC_MAX_HDR_LEN (sizeof(struct udphdr))
71
72
73
74
75
76#define LOWPAN_IPHC_MAX_HEADER_LEN (2 + 1 + LOWPAN_NHC_MAX_ID_LEN)
77
78#define LOWPAN_IPHC_MAX_HC_BUF_LEN (sizeof(struct ipv6hdr) + \
79 LOWPAN_IPHC_MAX_HEADER_LEN + \
80 LOWPAN_NHC_MAX_HDR_LEN)
81
82#define LOWPAN_IPHC_CTX_TABLE_SIZE (1 << 4)
83
84#define LOWPAN_DISPATCH_IPV6 0x41
85#define LOWPAN_DISPATCH_IPHC 0x60
86#define LOWPAN_DISPATCH_IPHC_MASK 0xe0
87
88static inline bool lowpan_is_ipv6(u8 dispatch)
89{
90 return dispatch == LOWPAN_DISPATCH_IPV6;
91}
92
93static inline bool lowpan_is_iphc(u8 dispatch)
94{
95 return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
96}
97
98#define LOWPAN_PRIV_SIZE(llpriv_size) \
99 (sizeof(struct lowpan_dev) + llpriv_size)
100
101enum lowpan_lltypes {
102 LOWPAN_LLTYPE_BTLE,
103 LOWPAN_LLTYPE_IEEE802154,
104};
105
106enum lowpan_iphc_ctx_flags {
107 LOWPAN_IPHC_CTX_FLAG_ACTIVE,
108 LOWPAN_IPHC_CTX_FLAG_COMPRESSION,
109};
110
111struct lowpan_iphc_ctx {
112 u8 id;
113 struct in6_addr pfx;
114 u8 plen;
115 unsigned long flags;
116};
117
118struct lowpan_iphc_ctx_table {
119 spinlock_t lock;
120 const struct lowpan_iphc_ctx_ops *ops;
121 struct lowpan_iphc_ctx table[LOWPAN_IPHC_CTX_TABLE_SIZE];
122};
123
124static inline bool lowpan_iphc_ctx_is_active(const struct lowpan_iphc_ctx *ctx)
125{
126 return test_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags);
127}
128
129static inline bool
130lowpan_iphc_ctx_is_compression(const struct lowpan_iphc_ctx *ctx)
131{
132 return test_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags);
133}
134
135struct lowpan_dev {
136 enum lowpan_lltypes lltype;
137 struct dentry *iface_debugfs;
138 struct lowpan_iphc_ctx_table ctx;
139
140
141 u8 priv[0] __aligned(sizeof(void *));
142};
143
144struct lowpan_802154_neigh {
145 __le16 short_addr;
146};
147
148static inline
149struct lowpan_802154_neigh *lowpan_802154_neigh(void *neigh_priv)
150{
151 return neigh_priv;
152}
153
154static inline
155struct lowpan_dev *lowpan_dev(const struct net_device *dev)
156{
157 return netdev_priv(dev);
158}
159
160
161struct lowpan_802154_dev {
162 struct net_device *wdev;
163 u16 fragment_tag;
164};
165
166static inline struct
167lowpan_802154_dev *lowpan_802154_dev(const struct net_device *dev)
168{
169 return (struct lowpan_802154_dev *)lowpan_dev(dev)->priv;
170}
171
172struct lowpan_802154_cb {
173 u16 d_tag;
174 unsigned int d_size;
175 u8 d_offset;
176};
177
178static inline
179struct lowpan_802154_cb *lowpan_802154_cb(const struct sk_buff *skb)
180{
181 BUILD_BUG_ON(sizeof(struct lowpan_802154_cb) > sizeof(skb->cb));
182 return (struct lowpan_802154_cb *)skb->cb;
183}
184
185static inline void lowpan_iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr,
186 const void *lladdr)
187{
188
189
190
191
192 ipaddr->s6_addr[0] = 0xFE;
193 ipaddr->s6_addr[1] = 0x80;
194 memcpy(&ipaddr->s6_addr[8], lladdr, EUI64_ADDR_LEN);
195
196
197
198 ipaddr->s6_addr[8] ^= 0x02;
199}
200
201#ifdef DEBUG
202
203static inline void raw_dump_inline(const char *caller, char *msg,
204 const unsigned char *buf, int len)
205{
206 if (msg)
207 pr_debug("%s():%s: ", caller, msg);
208
209 print_hex_dump_debug("", DUMP_PREFIX_NONE, 16, 1, buf, len, false);
210}
211
212
213
214
215
216
217
218static inline void raw_dump_table(const char *caller, char *msg,
219 const unsigned char *buf, int len)
220{
221 if (msg)
222 pr_debug("%s():%s:\n", caller, msg);
223
224 print_hex_dump_debug("\t", DUMP_PREFIX_OFFSET, 16, 1, buf, len, false);
225}
226#else
227static inline void raw_dump_table(const char *caller, char *msg,
228 const unsigned char *buf, int len) { }
229static inline void raw_dump_inline(const char *caller, char *msg,
230 const unsigned char *buf, int len) { }
231#endif
232
233
234
235
236
237
238
239
240
241
242
243
244
245static inline bool lowpan_fetch_skb(struct sk_buff *skb, void *data,
246 unsigned int len)
247{
248 if (unlikely(!pskb_may_pull(skb, len)))
249 return true;
250
251 skb_copy_from_linear_data(skb, data, len);
252 skb_pull(skb, len);
253
254 return false;
255}
256
257static inline bool lowpan_802154_is_valid_src_short_addr(__le16 addr)
258{
259
260 return !(addr & cpu_to_le16(0x8000));
261}
262
263static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
264 const size_t len)
265{
266 memcpy(*hc_ptr, data, len);
267 *hc_ptr += len;
268}
269
270int lowpan_register_netdevice(struct net_device *dev,
271 enum lowpan_lltypes lltype);
272int lowpan_register_netdev(struct net_device *dev,
273 enum lowpan_lltypes lltype);
274void lowpan_unregister_netdevice(struct net_device *dev);
275void lowpan_unregister_netdev(struct net_device *dev);
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
294 const void *daddr, const void *saddr);
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312int lowpan_header_compress(struct sk_buff *skb, const struct net_device *dev,
313 const void *daddr, const void *saddr);
314
315#endif
316