xref: /linux/include/net/6lowpan.h (revision 87a93e4e)
1cefc8c8aSAlexander Aring /*
2cefc8c8aSAlexander Aring  * Copyright 2011, Siemens AG
3cefc8c8aSAlexander Aring  * written by Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
4cefc8c8aSAlexander Aring  */
5cefc8c8aSAlexander Aring 
6cefc8c8aSAlexander Aring /*
7cefc8c8aSAlexander Aring  * Based on patches from Jon Smirl <jonsmirl@gmail.com>
8cefc8c8aSAlexander Aring  * Copyright (c) 2011 Jon Smirl <jonsmirl@gmail.com>
9cefc8c8aSAlexander Aring  *
10cefc8c8aSAlexander Aring  * This program is free software; you can redistribute it and/or modify
11cefc8c8aSAlexander Aring  * it under the terms of the GNU General Public License version 2
12cefc8c8aSAlexander Aring  * as published by the Free Software Foundation.
13cefc8c8aSAlexander Aring  *
14cefc8c8aSAlexander Aring  * This program is distributed in the hope that it will be useful,
15cefc8c8aSAlexander Aring  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16cefc8c8aSAlexander Aring  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17cefc8c8aSAlexander Aring  * GNU General Public License for more details.
18cefc8c8aSAlexander Aring  *
19cefc8c8aSAlexander Aring  * You should have received a copy of the GNU General Public License along
20cefc8c8aSAlexander Aring  * with this program; if not, write to the Free Software Foundation, Inc.,
21cefc8c8aSAlexander Aring  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22cefc8c8aSAlexander Aring  */
23cefc8c8aSAlexander Aring 
24cefc8c8aSAlexander Aring /* Jon's code is based on 6lowpan implementation for Contiki which is:
25cefc8c8aSAlexander Aring  * Copyright (c) 2008, Swedish Institute of Computer Science.
26cefc8c8aSAlexander Aring  * All rights reserved.
27cefc8c8aSAlexander Aring  *
28cefc8c8aSAlexander Aring  * Redistribution and use in source and binary forms, with or without
29cefc8c8aSAlexander Aring  * modification, are permitted provided that the following conditions
30cefc8c8aSAlexander Aring  * are met:
31cefc8c8aSAlexander Aring  * 1. Redistributions of source code must retain the above copyright
32cefc8c8aSAlexander Aring  *    notice, this list of conditions and the following disclaimer.
33cefc8c8aSAlexander Aring  * 2. Redistributions in binary form must reproduce the above copyright
34cefc8c8aSAlexander Aring  *    notice, this list of conditions and the following disclaimer in the
35cefc8c8aSAlexander Aring  *    documentation and/or other materials provided with the distribution.
36cefc8c8aSAlexander Aring  * 3. Neither the name of the Institute nor the names of its contributors
37cefc8c8aSAlexander Aring  *    may be used to endorse or promote products derived from this software
38cefc8c8aSAlexander Aring  *    without specific prior written permission.
39cefc8c8aSAlexander Aring  *
40cefc8c8aSAlexander Aring  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
41cefc8c8aSAlexander Aring  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42cefc8c8aSAlexander Aring  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43cefc8c8aSAlexander Aring  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
44cefc8c8aSAlexander Aring  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45cefc8c8aSAlexander Aring  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46cefc8c8aSAlexander Aring  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47cefc8c8aSAlexander Aring  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48cefc8c8aSAlexander Aring  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49cefc8c8aSAlexander Aring  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50cefc8c8aSAlexander Aring  * SUCH DAMAGE.
51cefc8c8aSAlexander Aring  */
52cefc8c8aSAlexander Aring 
53cefc8c8aSAlexander Aring #ifndef __6LOWPAN_H__
54cefc8c8aSAlexander Aring #define __6LOWPAN_H__
55cefc8c8aSAlexander Aring 
56cefc8c8aSAlexander Aring #include <net/ipv6.h>
5717d8ecb8SLuis R. Rodriguez #include <net/net_namespace.h>
58cefc8c8aSAlexander Aring 
59cefc8c8aSAlexander Aring #define UIP_802154_SHORTADDR_LEN	2  /* compressed ipv6 address length */
60cefc8c8aSAlexander Aring #define UIP_IPH_LEN			40 /* ipv6 fixed header size */
61cefc8c8aSAlexander Aring #define UIP_PROTO_UDP			17 /* ipv6 next header value for UDP */
62cefc8c8aSAlexander Aring #define UIP_FRAGH_LEN			8  /* ipv6 fragment header size */
63cefc8c8aSAlexander Aring 
64*87a93e4eSAlexander Aring #define LOWPAN_NHC_MAX_ID_LEN	1
65*87a93e4eSAlexander Aring /* Max IPHC Header len without IPv6 hdr specific inline data.
66*87a93e4eSAlexander Aring  * Useful for getting the "extra" bytes we need at worst case compression.
67*87a93e4eSAlexander Aring  *
68*87a93e4eSAlexander Aring  * LOWPAN_IPHC + CID + LOWPAN_NHC_MAX_ID_LEN
69*87a93e4eSAlexander Aring  */
70*87a93e4eSAlexander Aring #define LOWPAN_IPHC_MAX_HEADER_LEN	(2 + 1 + LOWPAN_NHC_MAX_ID_LEN)
71*87a93e4eSAlexander Aring 
72cefc8c8aSAlexander Aring /*
73cefc8c8aSAlexander Aring  * ipv6 address based on mac
74cefc8c8aSAlexander Aring  * second bit-flip (Universe/Local) is done according RFC2464
75cefc8c8aSAlexander Aring  */
76cefc8c8aSAlexander Aring #define is_addr_mac_addr_based(a, m) \
77cefc8c8aSAlexander Aring 	((((a)->s6_addr[8])  == (((m)[0]) ^ 0x02)) &&	\
78cefc8c8aSAlexander Aring 	 (((a)->s6_addr[9])  == (m)[1]) &&		\
79cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == (m)[2]) &&		\
80cefc8c8aSAlexander Aring 	 (((a)->s6_addr[11]) == (m)[3]) &&		\
81cefc8c8aSAlexander Aring 	 (((a)->s6_addr[12]) == (m)[4]) &&		\
82cefc8c8aSAlexander Aring 	 (((a)->s6_addr[13]) == (m)[5]) &&		\
83cefc8c8aSAlexander Aring 	 (((a)->s6_addr[14]) == (m)[6]) &&		\
84cefc8c8aSAlexander Aring 	 (((a)->s6_addr[15]) == (m)[7]))
85cefc8c8aSAlexander Aring 
86cefc8c8aSAlexander Aring /*
87cefc8c8aSAlexander Aring  * check whether we can compress the IID to 16 bits,
88cefc8c8aSAlexander Aring  * it's possible for unicast adresses with first 49 bits are zero only.
89cefc8c8aSAlexander Aring  */
90cefc8c8aSAlexander Aring #define lowpan_is_iid_16_bit_compressable(a)	\
91cefc8c8aSAlexander Aring 	((((a)->s6_addr16[4]) == 0) &&		\
92cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == 0) &&		\
93cefc8c8aSAlexander Aring 	 (((a)->s6_addr[11]) == 0xff) &&	\
94cefc8c8aSAlexander Aring 	 (((a)->s6_addr[12]) == 0xfe) &&	\
95cefc8c8aSAlexander Aring 	 (((a)->s6_addr[13]) == 0))
96cefc8c8aSAlexander Aring 
97cefc8c8aSAlexander Aring /* check whether the 112-bit gid of the multicast address is mappable to: */
98cefc8c8aSAlexander Aring 
99cefc8c8aSAlexander Aring /* 48 bits, FFXX::00XX:XXXX:XXXX */
100cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable48(a)	\
101cefc8c8aSAlexander Aring 	((((a)->s6_addr16[1]) == 0) &&		\
102cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[2]) == 0) &&		\
103cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[3]) == 0) &&		\
104cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[4]) == 0) &&		\
105cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == 0))
106cefc8c8aSAlexander Aring 
107cefc8c8aSAlexander Aring /* 32 bits, FFXX::00XX:XXXX */
108cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable32(a)	\
109cefc8c8aSAlexander Aring 	((((a)->s6_addr16[1]) == 0) &&		\
110cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[2]) == 0) &&		\
111cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[3]) == 0) &&		\
112cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[4]) == 0) &&		\
113cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[5]) == 0) &&		\
114cefc8c8aSAlexander Aring 	 (((a)->s6_addr[12]) == 0))
115cefc8c8aSAlexander Aring 
116cefc8c8aSAlexander Aring /* 8 bits, FF02::00XX */
117cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable8(a)	\
118cefc8c8aSAlexander Aring 	((((a)->s6_addr[1])  == 2) &&		\
119cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[1]) == 0) &&		\
120cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[2]) == 0) &&		\
121cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[3]) == 0) &&		\
122cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[4]) == 0) &&		\
123cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[5]) == 0) &&		\
124cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[6]) == 0) &&		\
125cefc8c8aSAlexander Aring 	 (((a)->s6_addr[14]) == 0))
126cefc8c8aSAlexander Aring 
127cefc8c8aSAlexander Aring #define lowpan_is_addr_broadcast(a)	\
128cefc8c8aSAlexander Aring 	((((a)[0]) == 0xFF) &&	\
129cefc8c8aSAlexander Aring 	 (((a)[1]) == 0xFF) &&	\
130cefc8c8aSAlexander Aring 	 (((a)[2]) == 0xFF) &&	\
131cefc8c8aSAlexander Aring 	 (((a)[3]) == 0xFF) &&	\
132cefc8c8aSAlexander Aring 	 (((a)[4]) == 0xFF) &&	\
133cefc8c8aSAlexander Aring 	 (((a)[5]) == 0xFF) &&	\
134cefc8c8aSAlexander Aring 	 (((a)[6]) == 0xFF) &&	\
135cefc8c8aSAlexander Aring 	 (((a)[7]) == 0xFF))
136cefc8c8aSAlexander Aring 
137cefc8c8aSAlexander Aring #define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
138cefc8c8aSAlexander Aring #define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
13972a5e6bbSAlexander Aring #define LOWPAN_DISPATCH_IPHC_MASK	0xe0
140cefc8c8aSAlexander Aring 
14172a5e6bbSAlexander Aring static inline bool lowpan_is_ipv6(u8 dispatch)
14272a5e6bbSAlexander Aring {
14372a5e6bbSAlexander Aring 	return dispatch == LOWPAN_DISPATCH_IPV6;
14472a5e6bbSAlexander Aring }
14572a5e6bbSAlexander Aring 
14672a5e6bbSAlexander Aring static inline bool lowpan_is_iphc(u8 dispatch)
14772a5e6bbSAlexander Aring {
14872a5e6bbSAlexander Aring 	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
14972a5e6bbSAlexander Aring }
150cefc8c8aSAlexander Aring 
151cefc8c8aSAlexander Aring #define LOWPAN_FRAG_TIMEOUT	(HZ * 60)	/* time-out 60 sec */
152cefc8c8aSAlexander Aring 
153cefc8c8aSAlexander Aring #define LOWPAN_FRAG1_HEAD_SIZE	0x4
154cefc8c8aSAlexander Aring #define LOWPAN_FRAGN_HEAD_SIZE	0x5
155cefc8c8aSAlexander Aring 
156cefc8c8aSAlexander Aring /*
157cefc8c8aSAlexander Aring  * Values of fields within the IPHC encoding first byte
158cefc8c8aSAlexander Aring  * (C stands for compressed and I for inline)
159cefc8c8aSAlexander Aring  */
160cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TF		0x18
161cefc8c8aSAlexander Aring 
162cefc8c8aSAlexander Aring #define LOWPAN_IPHC_FL_C	0x10
163cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TC_C	0x08
164cefc8c8aSAlexander Aring #define LOWPAN_IPHC_NH_C	0x04
165cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_1	0x01
166cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_64	0x02
167cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_255	0x03
168cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_I	0x00
169cefc8c8aSAlexander Aring 
170cefc8c8aSAlexander Aring 
171cefc8c8aSAlexander Aring /* Values of fields within the IPHC encoding second byte */
172cefc8c8aSAlexander Aring #define LOWPAN_IPHC_CID		0x80
173cefc8c8aSAlexander Aring 
174cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_00	0x00
175cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_01	0x01
176cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_02	0x02
177cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_03	0x03
178cefc8c8aSAlexander Aring 
179cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAC		0x40
180cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAM		0x30
181cefc8c8aSAlexander Aring 
182cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAM_BIT	4
183cefc8c8aSAlexander Aring 
184cefc8c8aSAlexander Aring #define LOWPAN_IPHC_M		0x08
185cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAC		0x04
186cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_00	0x00
187cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_01	0x01
188cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_10	0x02
189cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_11	0x03
190cefc8c8aSAlexander Aring 
191cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_BIT	0
192cefc8c8aSAlexander Aring /*
193cefc8c8aSAlexander Aring  * LOWPAN_UDP encoding (works together with IPHC)
194cefc8c8aSAlexander Aring  */
195cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_MASK		0xF8
196cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_ID		0xF0
197cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CHECKSUMC	0x04
198cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CHECKSUMI	0x00
199cefc8c8aSAlexander Aring 
200cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_4BIT_PORT	0xF0B0
201cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_4BIT_MASK	0xFFF0
202cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_8BIT_PORT	0xF000
203cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_8BIT_MASK	0xFF00
204cefc8c8aSAlexander Aring 
205cefc8c8aSAlexander Aring /* values for port compression, _with checksum_ ie bit 5 set to 0 */
206cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_00	0xF0 /* all inline */
207cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_01	0xF1 /* source 16bit inline,
208cefc8c8aSAlexander Aring 					dest = 0xF0 + 8 bit inline */
209cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_10	0xF2 /* source = 0xF0 + 8bit inline,
210cefc8c8aSAlexander Aring 					dest = 16 bit inline */
211cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_11	0xF3 /* source & dest = 0xF0B + 4bit inline */
212cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_C	0x04 /* checksum elided */
213cefc8c8aSAlexander Aring 
214b72f6f51SAlexander Aring #define LOWPAN_PRIV_SIZE(llpriv_size)	\
215b72f6f51SAlexander Aring 	(sizeof(struct lowpan_priv) + llpriv_size)
216b72f6f51SAlexander Aring 
217b72f6f51SAlexander Aring enum lowpan_lltypes {
218b72f6f51SAlexander Aring 	LOWPAN_LLTYPE_BTLE,
219b72f6f51SAlexander Aring 	LOWPAN_LLTYPE_IEEE802154,
220b72f6f51SAlexander Aring };
221b72f6f51SAlexander Aring 
222b72f6f51SAlexander Aring struct lowpan_priv {
223b72f6f51SAlexander Aring 	enum lowpan_lltypes lltype;
224b72f6f51SAlexander Aring 
225b72f6f51SAlexander Aring 	/* must be last */
226b72f6f51SAlexander Aring 	u8 priv[0] __aligned(sizeof(void *));
227b72f6f51SAlexander Aring };
228b72f6f51SAlexander Aring 
229b72f6f51SAlexander Aring static inline
230b72f6f51SAlexander Aring struct lowpan_priv *lowpan_priv(const struct net_device *dev)
231b72f6f51SAlexander Aring {
232b72f6f51SAlexander Aring 	return netdev_priv(dev);
233b72f6f51SAlexander Aring }
234b72f6f51SAlexander Aring 
23572a5e6bbSAlexander Aring struct lowpan_802154_cb {
23672a5e6bbSAlexander Aring 	u16 d_tag;
23772a5e6bbSAlexander Aring 	unsigned int d_size;
23872a5e6bbSAlexander Aring 	u8 d_offset;
23972a5e6bbSAlexander Aring };
24072a5e6bbSAlexander Aring 
24172a5e6bbSAlexander Aring static inline
24272a5e6bbSAlexander Aring struct lowpan_802154_cb *lowpan_802154_cb(const struct sk_buff *skb)
24372a5e6bbSAlexander Aring {
24472a5e6bbSAlexander Aring 	BUILD_BUG_ON(sizeof(struct lowpan_802154_cb) > sizeof(skb->cb));
24572a5e6bbSAlexander Aring 	return (struct lowpan_802154_cb *)skb->cb;
24672a5e6bbSAlexander Aring }
24772a5e6bbSAlexander Aring 
248cefc8c8aSAlexander Aring #ifdef DEBUG
249cefc8c8aSAlexander Aring /* print data in line */
250cefc8c8aSAlexander Aring static inline void raw_dump_inline(const char *caller, char *msg,
251cefc8c8aSAlexander Aring 				   unsigned char *buf, int len)
252cefc8c8aSAlexander Aring {
253cefc8c8aSAlexander Aring 	if (msg)
254cefc8c8aSAlexander Aring 		pr_debug("%s():%s: ", caller, msg);
255cefc8c8aSAlexander Aring 
256cefc8c8aSAlexander Aring 	print_hex_dump_debug("", DUMP_PREFIX_NONE, 16, 1, buf, len, false);
257cefc8c8aSAlexander Aring }
258cefc8c8aSAlexander Aring 
259cefc8c8aSAlexander Aring /* print data in a table format:
260cefc8c8aSAlexander Aring  *
261cefc8c8aSAlexander Aring  * addr: xx xx xx xx xx xx
262cefc8c8aSAlexander Aring  * addr: xx xx xx xx xx xx
263cefc8c8aSAlexander Aring  * ...
264cefc8c8aSAlexander Aring  */
265cefc8c8aSAlexander Aring static inline void raw_dump_table(const char *caller, char *msg,
266cefc8c8aSAlexander Aring 				  unsigned char *buf, int len)
267cefc8c8aSAlexander Aring {
268cefc8c8aSAlexander Aring 	if (msg)
269cefc8c8aSAlexander Aring 		pr_debug("%s():%s:\n", caller, msg);
270cefc8c8aSAlexander Aring 
271cefc8c8aSAlexander Aring 	print_hex_dump_debug("\t", DUMP_PREFIX_OFFSET, 16, 1, buf, len, false);
272cefc8c8aSAlexander Aring }
273cefc8c8aSAlexander Aring #else
274cefc8c8aSAlexander Aring static inline void raw_dump_table(const char *caller, char *msg,
275cefc8c8aSAlexander Aring 				  unsigned char *buf, int len) { }
276cefc8c8aSAlexander Aring static inline void raw_dump_inline(const char *caller, char *msg,
277cefc8c8aSAlexander Aring 				   unsigned char *buf, int len) { }
278cefc8c8aSAlexander Aring #endif
279cefc8c8aSAlexander Aring 
280cefc8c8aSAlexander Aring static inline int lowpan_fetch_skb_u8(struct sk_buff *skb, u8 *val)
281cefc8c8aSAlexander Aring {
282cefc8c8aSAlexander Aring 	if (unlikely(!pskb_may_pull(skb, 1)))
283cefc8c8aSAlexander Aring 		return -EINVAL;
284cefc8c8aSAlexander Aring 
285cefc8c8aSAlexander Aring 	*val = skb->data[0];
286cefc8c8aSAlexander Aring 	skb_pull(skb, 1);
287cefc8c8aSAlexander Aring 
288cefc8c8aSAlexander Aring 	return 0;
289cefc8c8aSAlexander Aring }
290cefc8c8aSAlexander Aring 
291cefc8c8aSAlexander Aring static inline bool lowpan_fetch_skb(struct sk_buff *skb,
292cefc8c8aSAlexander Aring 		void *data, const unsigned int len)
293cefc8c8aSAlexander Aring {
294cefc8c8aSAlexander Aring 	if (unlikely(!pskb_may_pull(skb, len)))
295cefc8c8aSAlexander Aring 		return true;
296cefc8c8aSAlexander Aring 
297cefc8c8aSAlexander Aring 	skb_copy_from_linear_data(skb, data, len);
298cefc8c8aSAlexander Aring 	skb_pull(skb, len);
299cefc8c8aSAlexander Aring 
300cefc8c8aSAlexander Aring 	return false;
301cefc8c8aSAlexander Aring }
302cefc8c8aSAlexander Aring 
303cefc8c8aSAlexander Aring static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
304cefc8c8aSAlexander Aring 				       const size_t len)
305cefc8c8aSAlexander Aring {
306cefc8c8aSAlexander Aring 	memcpy(*hc_ptr, data, len);
307cefc8c8aSAlexander Aring 	*hc_ptr += len;
308cefc8c8aSAlexander Aring }
309cefc8c8aSAlexander Aring 
310b72f6f51SAlexander Aring void lowpan_netdev_setup(struct net_device *dev, enum lowpan_lltypes lltype);
311b72f6f51SAlexander Aring 
31201141234SMartin Townsend int
31301141234SMartin Townsend lowpan_header_decompress(struct sk_buff *skb, struct net_device *dev,
31401141234SMartin Townsend 			 const u8 *saddr, const u8 saddr_type,
31501141234SMartin Townsend 			 const u8 saddr_len, const u8 *daddr,
31601141234SMartin Townsend 			 const u8 daddr_type, const u8 daddr_len,
317f8b36176SMartin Townsend 			 u8 iphc0, u8 iphc1);
318cefc8c8aSAlexander Aring int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
319cefc8c8aSAlexander Aring 			unsigned short type, const void *_daddr,
320cefc8c8aSAlexander Aring 			const void *_saddr, unsigned int len);
321cefc8c8aSAlexander Aring 
322cefc8c8aSAlexander Aring #endif /* __6LOWPAN_H__ */
323