xref: /linux/include/net/6lowpan.h (revision 478208e3)
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 
644d6a6aedSAlexander Aring #define EUI64_ADDR_LEN		8
654d6a6aedSAlexander Aring 
6687a93e4eSAlexander Aring #define LOWPAN_NHC_MAX_ID_LEN	1
67bf513fd6SAlexander Aring /* Maximum next header compression length which we currently support inclusive
68bf513fd6SAlexander Aring  * possible inline data.
69bf513fd6SAlexander Aring  */
70bf513fd6SAlexander Aring #define LOWPAN_NHC_MAX_HDR_LEN	(sizeof(struct udphdr))
7187a93e4eSAlexander Aring /* Max IPHC Header len without IPv6 hdr specific inline data.
7287a93e4eSAlexander Aring  * Useful for getting the "extra" bytes we need at worst case compression.
7387a93e4eSAlexander Aring  *
7487a93e4eSAlexander Aring  * LOWPAN_IPHC + CID + LOWPAN_NHC_MAX_ID_LEN
7587a93e4eSAlexander Aring  */
7687a93e4eSAlexander Aring #define LOWPAN_IPHC_MAX_HEADER_LEN	(2 + 1 + LOWPAN_NHC_MAX_ID_LEN)
77bf513fd6SAlexander Aring /* Maximum worst case IPHC header buffer size */
78bf513fd6SAlexander Aring #define LOWPAN_IPHC_MAX_HC_BUF_LEN	(sizeof(struct ipv6hdr) +	\
79bf513fd6SAlexander Aring 					 LOWPAN_IPHC_MAX_HEADER_LEN +	\
80bf513fd6SAlexander Aring 					 LOWPAN_NHC_MAX_HDR_LEN)
8187a93e4eSAlexander Aring 
82cefc8c8aSAlexander Aring /*
83cefc8c8aSAlexander Aring  * ipv6 address based on mac
84cefc8c8aSAlexander Aring  * second bit-flip (Universe/Local) is done according RFC2464
85cefc8c8aSAlexander Aring  */
86cefc8c8aSAlexander Aring #define is_addr_mac_addr_based(a, m) \
87cefc8c8aSAlexander Aring 	((((a)->s6_addr[8])  == (((m)[0]) ^ 0x02)) &&	\
88cefc8c8aSAlexander Aring 	 (((a)->s6_addr[9])  == (m)[1]) &&		\
89cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == (m)[2]) &&		\
90cefc8c8aSAlexander Aring 	 (((a)->s6_addr[11]) == (m)[3]) &&		\
91cefc8c8aSAlexander Aring 	 (((a)->s6_addr[12]) == (m)[4]) &&		\
92cefc8c8aSAlexander Aring 	 (((a)->s6_addr[13]) == (m)[5]) &&		\
93cefc8c8aSAlexander Aring 	 (((a)->s6_addr[14]) == (m)[6]) &&		\
94cefc8c8aSAlexander Aring 	 (((a)->s6_addr[15]) == (m)[7]))
95cefc8c8aSAlexander Aring 
96cefc8c8aSAlexander Aring /*
97cefc8c8aSAlexander Aring  * check whether we can compress the IID to 16 bits,
98cefc8c8aSAlexander Aring  * it's possible for unicast adresses with first 49 bits are zero only.
99cefc8c8aSAlexander Aring  */
100cefc8c8aSAlexander Aring #define lowpan_is_iid_16_bit_compressable(a)	\
101cefc8c8aSAlexander Aring 	((((a)->s6_addr16[4]) == 0) &&		\
102cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == 0) &&		\
103cefc8c8aSAlexander Aring 	 (((a)->s6_addr[11]) == 0xff) &&	\
104cefc8c8aSAlexander Aring 	 (((a)->s6_addr[12]) == 0xfe) &&	\
105cefc8c8aSAlexander Aring 	 (((a)->s6_addr[13]) == 0))
106cefc8c8aSAlexander Aring 
107cefc8c8aSAlexander Aring /* check whether the 112-bit gid of the multicast address is mappable to: */
108cefc8c8aSAlexander Aring 
109cefc8c8aSAlexander Aring /* 48 bits, FFXX::00XX:XXXX:XXXX */
110cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable48(a)	\
111cefc8c8aSAlexander Aring 	((((a)->s6_addr16[1]) == 0) &&		\
112cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[2]) == 0) &&		\
113cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[3]) == 0) &&		\
114cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[4]) == 0) &&		\
115cefc8c8aSAlexander Aring 	 (((a)->s6_addr[10]) == 0))
116cefc8c8aSAlexander Aring 
117cefc8c8aSAlexander Aring /* 32 bits, FFXX::00XX:XXXX */
118cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable32(a)	\
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_addr[12]) == 0))
125cefc8c8aSAlexander Aring 
126cefc8c8aSAlexander Aring /* 8 bits, FF02::00XX */
127cefc8c8aSAlexander Aring #define lowpan_is_mcast_addr_compressable8(a)	\
128cefc8c8aSAlexander Aring 	((((a)->s6_addr[1])  == 2) &&		\
129cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[1]) == 0) &&		\
130cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[2]) == 0) &&		\
131cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[3]) == 0) &&		\
132cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[4]) == 0) &&		\
133cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[5]) == 0) &&		\
134cefc8c8aSAlexander Aring 	 (((a)->s6_addr16[6]) == 0) &&		\
135cefc8c8aSAlexander Aring 	 (((a)->s6_addr[14]) == 0))
136cefc8c8aSAlexander Aring 
137cefc8c8aSAlexander Aring #define lowpan_is_addr_broadcast(a)	\
138cefc8c8aSAlexander Aring 	((((a)[0]) == 0xFF) &&	\
139cefc8c8aSAlexander Aring 	 (((a)[1]) == 0xFF) &&	\
140cefc8c8aSAlexander Aring 	 (((a)[2]) == 0xFF) &&	\
141cefc8c8aSAlexander Aring 	 (((a)[3]) == 0xFF) &&	\
142cefc8c8aSAlexander Aring 	 (((a)[4]) == 0xFF) &&	\
143cefc8c8aSAlexander Aring 	 (((a)[5]) == 0xFF) &&	\
144cefc8c8aSAlexander Aring 	 (((a)[6]) == 0xFF) &&	\
145cefc8c8aSAlexander Aring 	 (((a)[7]) == 0xFF))
146cefc8c8aSAlexander Aring 
147cefc8c8aSAlexander Aring #define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
148cefc8c8aSAlexander Aring #define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
14972a5e6bbSAlexander Aring #define LOWPAN_DISPATCH_IPHC_MASK	0xe0
150cefc8c8aSAlexander Aring 
15172a5e6bbSAlexander Aring static inline bool lowpan_is_ipv6(u8 dispatch)
15272a5e6bbSAlexander Aring {
15372a5e6bbSAlexander Aring 	return dispatch == LOWPAN_DISPATCH_IPV6;
15472a5e6bbSAlexander Aring }
15572a5e6bbSAlexander Aring 
15672a5e6bbSAlexander Aring static inline bool lowpan_is_iphc(u8 dispatch)
15772a5e6bbSAlexander Aring {
15872a5e6bbSAlexander Aring 	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
15972a5e6bbSAlexander Aring }
160cefc8c8aSAlexander Aring 
161cefc8c8aSAlexander Aring #define LOWPAN_FRAG_TIMEOUT	(HZ * 60)	/* time-out 60 sec */
162cefc8c8aSAlexander Aring 
163cefc8c8aSAlexander Aring #define LOWPAN_FRAG1_HEAD_SIZE	0x4
164cefc8c8aSAlexander Aring #define LOWPAN_FRAGN_HEAD_SIZE	0x5
165cefc8c8aSAlexander Aring 
166cefc8c8aSAlexander Aring /*
167cefc8c8aSAlexander Aring  * Values of fields within the IPHC encoding first byte
168cefc8c8aSAlexander Aring  * (C stands for compressed and I for inline)
169cefc8c8aSAlexander Aring  */
170cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TF		0x18
171cefc8c8aSAlexander Aring 
172cefc8c8aSAlexander Aring #define LOWPAN_IPHC_FL_C	0x10
173cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TC_C	0x08
174cefc8c8aSAlexander Aring #define LOWPAN_IPHC_NH_C	0x04
175cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_1	0x01
176cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_64	0x02
177cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_255	0x03
178cefc8c8aSAlexander Aring #define LOWPAN_IPHC_TTL_I	0x00
179cefc8c8aSAlexander Aring 
180cefc8c8aSAlexander Aring 
181cefc8c8aSAlexander Aring /* Values of fields within the IPHC encoding second byte */
182cefc8c8aSAlexander Aring #define LOWPAN_IPHC_CID		0x80
183cefc8c8aSAlexander Aring 
184cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_00	0x00
185cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_01	0x01
186cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_02	0x02
187cefc8c8aSAlexander Aring #define LOWPAN_IPHC_ADDR_03	0x03
188cefc8c8aSAlexander Aring 
189cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAC		0x40
190cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAM		0x30
191cefc8c8aSAlexander Aring 
192cefc8c8aSAlexander Aring #define LOWPAN_IPHC_SAM_BIT	4
193cefc8c8aSAlexander Aring 
194cefc8c8aSAlexander Aring #define LOWPAN_IPHC_M		0x08
195cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAC		0x04
196cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_00	0x00
197cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_01	0x01
198cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_10	0x02
199cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_11	0x03
200cefc8c8aSAlexander Aring 
201cefc8c8aSAlexander Aring #define LOWPAN_IPHC_DAM_BIT	0
202cefc8c8aSAlexander Aring /*
203cefc8c8aSAlexander Aring  * LOWPAN_UDP encoding (works together with IPHC)
204cefc8c8aSAlexander Aring  */
205cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_MASK		0xF8
206cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_ID		0xF0
207cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CHECKSUMC	0x04
208cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CHECKSUMI	0x00
209cefc8c8aSAlexander Aring 
210cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_4BIT_PORT	0xF0B0
211cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_4BIT_MASK	0xFFF0
212cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_8BIT_PORT	0xF000
213cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_8BIT_MASK	0xFF00
214cefc8c8aSAlexander Aring 
215cefc8c8aSAlexander Aring /* values for port compression, _with checksum_ ie bit 5 set to 0 */
216cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_00	0xF0 /* all inline */
217cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_01	0xF1 /* source 16bit inline,
218cefc8c8aSAlexander Aring 					dest = 0xF0 + 8 bit inline */
219cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_10	0xF2 /* source = 0xF0 + 8bit inline,
220cefc8c8aSAlexander Aring 					dest = 16 bit inline */
221cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_P_11	0xF3 /* source & dest = 0xF0B + 4bit inline */
222cefc8c8aSAlexander Aring #define LOWPAN_NHC_UDP_CS_C	0x04 /* checksum elided */
223cefc8c8aSAlexander Aring 
224b72f6f51SAlexander Aring #define LOWPAN_PRIV_SIZE(llpriv_size)	\
225b72f6f51SAlexander Aring 	(sizeof(struct lowpan_priv) + llpriv_size)
226b72f6f51SAlexander Aring 
227b72f6f51SAlexander Aring enum lowpan_lltypes {
228b72f6f51SAlexander Aring 	LOWPAN_LLTYPE_BTLE,
229b72f6f51SAlexander Aring 	LOWPAN_LLTYPE_IEEE802154,
230b72f6f51SAlexander Aring };
231b72f6f51SAlexander Aring 
232b72f6f51SAlexander Aring struct lowpan_priv {
233b72f6f51SAlexander Aring 	enum lowpan_lltypes lltype;
234b72f6f51SAlexander Aring 
235b72f6f51SAlexander Aring 	/* must be last */
236b72f6f51SAlexander Aring 	u8 priv[0] __aligned(sizeof(void *));
237b72f6f51SAlexander Aring };
238b72f6f51SAlexander Aring 
239b72f6f51SAlexander Aring static inline
240b72f6f51SAlexander Aring struct lowpan_priv *lowpan_priv(const struct net_device *dev)
241b72f6f51SAlexander Aring {
242b72f6f51SAlexander Aring 	return netdev_priv(dev);
243b72f6f51SAlexander Aring }
244b72f6f51SAlexander Aring 
24572a5e6bbSAlexander Aring struct lowpan_802154_cb {
24672a5e6bbSAlexander Aring 	u16 d_tag;
24772a5e6bbSAlexander Aring 	unsigned int d_size;
24872a5e6bbSAlexander Aring 	u8 d_offset;
24972a5e6bbSAlexander Aring };
25072a5e6bbSAlexander Aring 
25172a5e6bbSAlexander Aring static inline
25272a5e6bbSAlexander Aring struct lowpan_802154_cb *lowpan_802154_cb(const struct sk_buff *skb)
25372a5e6bbSAlexander Aring {
25472a5e6bbSAlexander Aring 	BUILD_BUG_ON(sizeof(struct lowpan_802154_cb) > sizeof(skb->cb));
25572a5e6bbSAlexander Aring 	return (struct lowpan_802154_cb *)skb->cb;
25672a5e6bbSAlexander Aring }
25772a5e6bbSAlexander Aring 
258cefc8c8aSAlexander Aring #ifdef DEBUG
259cefc8c8aSAlexander Aring /* print data in line */
260cefc8c8aSAlexander Aring static inline void raw_dump_inline(const char *caller, char *msg,
261a6f77389SAlexander Aring 				   const unsigned char *buf, int len)
262cefc8c8aSAlexander Aring {
263cefc8c8aSAlexander Aring 	if (msg)
264cefc8c8aSAlexander Aring 		pr_debug("%s():%s: ", caller, msg);
265cefc8c8aSAlexander Aring 
266cefc8c8aSAlexander Aring 	print_hex_dump_debug("", DUMP_PREFIX_NONE, 16, 1, buf, len, false);
267cefc8c8aSAlexander Aring }
268cefc8c8aSAlexander Aring 
269cefc8c8aSAlexander Aring /* print data in a table format:
270cefc8c8aSAlexander Aring  *
271cefc8c8aSAlexander Aring  * addr: xx xx xx xx xx xx
272cefc8c8aSAlexander Aring  * addr: xx xx xx xx xx xx
273cefc8c8aSAlexander Aring  * ...
274cefc8c8aSAlexander Aring  */
275cefc8c8aSAlexander Aring static inline void raw_dump_table(const char *caller, char *msg,
276a6f77389SAlexander Aring 				  const unsigned char *buf, int len)
277cefc8c8aSAlexander Aring {
278cefc8c8aSAlexander Aring 	if (msg)
279cefc8c8aSAlexander Aring 		pr_debug("%s():%s:\n", caller, msg);
280cefc8c8aSAlexander Aring 
281cefc8c8aSAlexander Aring 	print_hex_dump_debug("\t", DUMP_PREFIX_OFFSET, 16, 1, buf, len, false);
282cefc8c8aSAlexander Aring }
283cefc8c8aSAlexander Aring #else
284cefc8c8aSAlexander Aring static inline void raw_dump_table(const char *caller, char *msg,
285a6f77389SAlexander Aring 				  const unsigned char *buf, int len) { }
286cefc8c8aSAlexander Aring static inline void raw_dump_inline(const char *caller, char *msg,
287a6f77389SAlexander Aring 				   const unsigned char *buf, int len) { }
288cefc8c8aSAlexander Aring #endif
289cefc8c8aSAlexander Aring 
290*478208e3SAlexander Aring /**
291*478208e3SAlexander Aring  * lowpan_fetch_skb - getting inline data from 6LoWPAN header
292*478208e3SAlexander Aring  *
293*478208e3SAlexander Aring  * This function will pull data from sk buffer and put it into data to
294*478208e3SAlexander Aring  * remove the 6LoWPAN inline data. This function returns true if the
295*478208e3SAlexander Aring  * sk buffer is too small to pull the amount of data which is specified
296*478208e3SAlexander Aring  * by len.
297*478208e3SAlexander Aring  *
298*478208e3SAlexander Aring  * @skb: the buffer where the inline data should be pulled from.
299*478208e3SAlexander Aring  * @data: destination buffer for the inline data.
300*478208e3SAlexander Aring  * @len: amount of data which should be pulled in bytes.
301*478208e3SAlexander Aring  */
302*478208e3SAlexander Aring static inline bool lowpan_fetch_skb(struct sk_buff *skb, void *data,
303*478208e3SAlexander Aring 				    unsigned int len)
304cefc8c8aSAlexander Aring {
305cefc8c8aSAlexander Aring 	if (unlikely(!pskb_may_pull(skb, len)))
306cefc8c8aSAlexander Aring 		return true;
307cefc8c8aSAlexander Aring 
308cefc8c8aSAlexander Aring 	skb_copy_from_linear_data(skb, data, len);
309cefc8c8aSAlexander Aring 	skb_pull(skb, len);
310cefc8c8aSAlexander Aring 
311cefc8c8aSAlexander Aring 	return false;
312cefc8c8aSAlexander Aring }
313cefc8c8aSAlexander Aring 
314cefc8c8aSAlexander Aring static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
315cefc8c8aSAlexander Aring 				       const size_t len)
316cefc8c8aSAlexander Aring {
317cefc8c8aSAlexander Aring 	memcpy(*hc_ptr, data, len);
318cefc8c8aSAlexander Aring 	*hc_ptr += len;
319cefc8c8aSAlexander Aring }
320cefc8c8aSAlexander Aring 
321b72f6f51SAlexander Aring void lowpan_netdev_setup(struct net_device *dev, enum lowpan_lltypes lltype);
322b72f6f51SAlexander Aring 
3238911d774SAlexander Aring /**
3248911d774SAlexander Aring  * lowpan_header_decompress - replace 6LoWPAN header with IPv6 header
3258911d774SAlexander Aring  *
3268911d774SAlexander Aring  * This function replaces the IPHC 6LoWPAN header which should be pointed at
3278911d774SAlexander Aring  * skb->data and skb_network_header, with the IPv6 header.
3288911d774SAlexander Aring  * It would be nice that the caller have the necessary headroom of IPv6 header
3298911d774SAlexander Aring  * and greatest Transport layer header, this would reduce the overhead for
3308911d774SAlexander Aring  * reallocate headroom.
3318911d774SAlexander Aring  *
3328911d774SAlexander Aring  * @skb: the buffer which should be manipulate.
3338911d774SAlexander Aring  * @dev: the lowpan net device pointer.
3348911d774SAlexander Aring  * @daddr: destination lladdr of mac header which is used for compression
3358911d774SAlexander Aring  *	methods.
3368911d774SAlexander Aring  * @saddr: source lladdr of mac header which is used for compression
3378911d774SAlexander Aring  *	methods.
3388911d774SAlexander Aring  */
3398911d774SAlexander Aring int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
3408911d774SAlexander Aring 			     const void *daddr, const void *saddr);
341a6f77389SAlexander Aring 
342a6f77389SAlexander Aring /**
343a6f77389SAlexander Aring  * lowpan_header_compress - replace IPv6 header with 6LoWPAN header
344a6f77389SAlexander Aring  *
345a6f77389SAlexander Aring  * This function replaces the IPv6 header which should be pointed at
346a6f77389SAlexander Aring  * skb->data and skb_network_header, with the IPHC 6LoWPAN header.
347a6f77389SAlexander Aring  * The caller need to be sure that the sk buffer is not shared and at have
348a6f77389SAlexander Aring  * at least a headroom which is smaller or equal LOWPAN_IPHC_MAX_HEADER_LEN,
349a6f77389SAlexander Aring  * which is the IPHC "more bytes than IPv6 header" at worst case.
350a6f77389SAlexander Aring  *
351a6f77389SAlexander Aring  * @skb: the buffer which should be manipulate.
352a6f77389SAlexander Aring  * @dev: the lowpan net device pointer.
353a6f77389SAlexander Aring  * @daddr: destination lladdr of mac header which is used for compression
354a6f77389SAlexander Aring  *	methods.
355a6f77389SAlexander Aring  * @saddr: source lladdr of mac header which is used for compression
356a6f77389SAlexander Aring  *	methods.
357a6f77389SAlexander Aring  */
358a6f77389SAlexander Aring int lowpan_header_compress(struct sk_buff *skb, const struct net_device *dev,
359a6f77389SAlexander Aring 			   const void *daddr, const void *saddr);
360cefc8c8aSAlexander Aring 
361cefc8c8aSAlexander Aring #endif /* __6LOWPAN_H__ */
362