aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee802154
diff options
context:
space:
mode:
Diffstat (limited to 'net/ieee802154')
-rw-r--r--net/ieee802154/6lowpan_iphc.c801
-rw-r--r--net/ieee802154/6lowpan_rtnl.c20
-rw-r--r--net/ieee802154/Kconfig9
-rw-r--r--net/ieee802154/Makefile5
-rw-r--r--net/ieee802154/af_ieee802154.c26
-rw-r--r--net/ieee802154/dgram.c28
-rw-r--r--net/ieee802154/ieee802154.h2
-rw-r--r--net/ieee802154/netlink.c4
-rw-r--r--net/ieee802154/nl-mac.c48
-rw-r--r--net/ieee802154/nl-phy.c23
-rw-r--r--net/ieee802154/raw.c14
-rw-r--r--net/ieee802154/reassembly.c84
-rw-r--r--net/ieee802154/wpan-class.c10
13 files changed, 137 insertions, 937 deletions
diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
deleted file mode 100644
index 211b5686d719..000000000000
--- a/net/ieee802154/6lowpan_iphc.c
+++ /dev/null
@@ -1,801 +0,0 @@
1/*
2 * Copyright 2011, Siemens AG
3 * written by Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
4 */
5
6/*
7 * Based on patches from Jon Smirl <jonsmirl@gmail.com>
8 * Copyright (c) 2011 Jon Smirl <jonsmirl@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24/* Jon's code is based on 6lowpan implementation for Contiki which is:
25 * Copyright (c) 2008, Swedish Institute of Computer Science.
26 * All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. Neither the name of the Institute nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52
53#include <linux/bitops.h>
54#include <linux/if_arp.h>
55#include <linux/module.h>
56#include <linux/netdevice.h>
57#include <net/6lowpan.h>
58#include <net/ipv6.h>
59#include <net/af_ieee802154.h>
60
61/*
62 * Uncompress address function for source and
63 * destination address(non-multicast).
64 *
65 * address_mode is sam value or dam value.
66 */
67static int uncompress_addr(struct sk_buff *skb,
68 struct in6_addr *ipaddr, const u8 address_mode,
69 const u8 *lladdr, const u8 addr_type,
70 const u8 addr_len)
71{
72 bool fail;
73
74 switch (address_mode) {
75 case LOWPAN_IPHC_ADDR_00:
76 /* for global link addresses */
77 fail = lowpan_fetch_skb(skb, ipaddr->s6_addr, 16);
78 break;
79 case LOWPAN_IPHC_ADDR_01:
80 /* fe:80::XXXX:XXXX:XXXX:XXXX */
81 ipaddr->s6_addr[0] = 0xFE;
82 ipaddr->s6_addr[1] = 0x80;
83 fail = lowpan_fetch_skb(skb, &ipaddr->s6_addr[8], 8);
84 break;
85 case LOWPAN_IPHC_ADDR_02:
86 /* fe:80::ff:fe00:XXXX */
87 ipaddr->s6_addr[0] = 0xFE;
88 ipaddr->s6_addr[1] = 0x80;
89 ipaddr->s6_addr[11] = 0xFF;
90 ipaddr->s6_addr[12] = 0xFE;
91 fail = lowpan_fetch_skb(skb, &ipaddr->s6_addr[14], 2);
92 break;
93 case LOWPAN_IPHC_ADDR_03:
94 fail = false;
95 switch (addr_type) {
96 case IEEE802154_ADDR_LONG:
97 /* fe:80::XXXX:XXXX:XXXX:XXXX
98 * \_________________/
99 * hwaddr
100 */
101 ipaddr->s6_addr[0] = 0xFE;
102 ipaddr->s6_addr[1] = 0x80;
103 memcpy(&ipaddr->s6_addr[8], lladdr, addr_len);
104 /* second bit-flip (Universe/Local)
105 * is done according RFC2464
106 */
107 ipaddr->s6_addr[8] ^= 0x02;
108 break;
109 case IEEE802154_ADDR_SHORT:
110 /* fe:80::ff:fe00:XXXX
111 * \__/
112 * short_addr
113 *
114 * Universe/Local bit is zero.
115 */
116 ipaddr->s6_addr[0] = 0xFE;
117 ipaddr->s6_addr[1] = 0x80;
118 ipaddr->s6_addr[11] = 0xFF;
119 ipaddr->s6_addr[12] = 0xFE;
120 ipaddr->s6_addr16[7] = htons(*((u16 *)lladdr));
121 break;
122 default:
123 pr_debug("Invalid addr_type set\n");
124 return -EINVAL;
125 }
126 break;
127 default:
128 pr_debug("Invalid address mode value: 0x%x\n", address_mode);
129 return -EINVAL;
130 }
131
132 if (fail) {
133 pr_debug("Failed to fetch skb data\n");
134 return -EIO;
135 }
136
137 raw_dump_inline(NULL, "Reconstructed ipv6 addr is",
138 ipaddr->s6_addr, 16);
139
140 return 0;
141}
142
143/*
144 * Uncompress address function for source context
145 * based address(non-multicast).
146 */
147static int uncompress_context_based_src_addr(struct sk_buff *skb,
148 struct in6_addr *ipaddr,
149 const u8 sam)
150{
151 switch (sam) {
152 case LOWPAN_IPHC_ADDR_00:
153 /* unspec address ::
154 * Do nothing, address is already ::
155 */
156 break;
157 case LOWPAN_IPHC_ADDR_01:
158 /* TODO */
159 case LOWPAN_IPHC_ADDR_02:
160 /* TODO */
161 case LOWPAN_IPHC_ADDR_03:
162 /* TODO */
163 netdev_warn(skb->dev, "SAM value 0x%x not supported\n", sam);
164 return -EINVAL;
165 default:
166 pr_debug("Invalid sam value: 0x%x\n", sam);
167 return -EINVAL;
168 }
169
170 raw_dump_inline(NULL,
171 "Reconstructed context based ipv6 src addr is",
172 ipaddr->s6_addr, 16);
173
174 return 0;
175}
176
177static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
178 struct net_device *dev, skb_delivery_cb deliver_skb)
179{
180 struct sk_buff *new;
181 int stat;
182
183 new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
184 GFP_ATOMIC);
185 kfree_skb(skb);
186
187 if (!new)
188 return -ENOMEM;
189
190 skb_push(new, sizeof(struct ipv6hdr));
191 skb_reset_network_header(new);
192 skb_copy_to_linear_data(new, hdr, sizeof(struct ipv6hdr));
193
194 new->protocol = htons(ETH_P_IPV6);
195 new->pkt_type = PACKET_HOST;
196 new->dev = dev;
197
198 raw_dump_table(__func__, "raw skb data dump before receiving",
199 new->data, new->len);
200
201 stat = deliver_skb(new, dev);
202
203 kfree_skb(new);
204
205 return stat;
206}
207
208/* Uncompress function for multicast destination address,
209 * when M bit is set.
210 */
211static int
212lowpan_uncompress_multicast_daddr(struct sk_buff *skb,
213 struct in6_addr *ipaddr,
214 const u8 dam)
215{
216 bool fail;
217
218 switch (dam) {
219 case LOWPAN_IPHC_DAM_00:
220 /* 00: 128 bits. The full address
221 * is carried in-line.
222 */
223 fail = lowpan_fetch_skb(skb, ipaddr->s6_addr, 16);
224 break;
225 case LOWPAN_IPHC_DAM_01:
226 /* 01: 48 bits. The address takes
227 * the form ffXX::00XX:XXXX:XXXX.
228 */
229 ipaddr->s6_addr[0] = 0xFF;
230 fail = lowpan_fetch_skb(skb, &ipaddr->s6_addr[1], 1);
231 fail |= lowpan_fetch_skb(skb, &ipaddr->s6_addr[11], 5);
232 break;
233 case LOWPAN_IPHC_DAM_10:
234 /* 10: 32 bits. The address takes
235 * the form ffXX::00XX:XXXX.
236 */
237 ipaddr->s6_addr[0] = 0xFF;
238 fail = lowpan_fetch_skb(skb, &ipaddr->s6_addr[1], 1);
239 fail |= lowpan_fetch_skb(skb, &ipaddr->s6_addr[13], 3);
240 break;
241 case LOWPAN_IPHC_DAM_11:
242 /* 11: 8 bits. The address takes
243 * the form ff02::00XX.
244 */
245 ipaddr->s6_addr[0] = 0xFF;
246 ipaddr->s6_addr[1] = 0x02;
247 fail = lowpan_fetch_skb(skb, &ipaddr->s6_addr[15], 1);
248 break;
249 default:
250 pr_debug("DAM value has a wrong value: 0x%x\n", dam);
251 return -EINVAL;
252 }
253
254 if (fail) {
255 pr_debug("Failed to fetch skb data\n");
256 return -EIO;
257 }
258
259 raw_dump_inline(NULL, "Reconstructed ipv6 multicast addr is",
260 ipaddr->s6_addr, 16);
261
262 return 0;
263}
264
265static int
266uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
267{
268 bool fail;
269 u8 tmp = 0, val = 0;
270
271 if (!uh)
272 goto err;
273
274 fail = lowpan_fetch_skb(skb, &tmp, 1);
275
276 if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) {
277 pr_debug("UDP header uncompression\n");
278 switch (tmp & LOWPAN_NHC_UDP_CS_P_11) {
279 case LOWPAN_NHC_UDP_CS_P_00:
280 fail |= lowpan_fetch_skb(skb, &uh->source, 2);
281 fail |= lowpan_fetch_skb(skb, &uh->dest, 2);
282 break;
283 case LOWPAN_NHC_UDP_CS_P_01:
284 fail |= lowpan_fetch_skb(skb, &uh->source, 2);
285 fail |= lowpan_fetch_skb(skb, &val, 1);
286 uh->dest = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
287 break;
288 case LOWPAN_NHC_UDP_CS_P_10:
289 fail |= lowpan_fetch_skb(skb, &val, 1);
290 uh->source = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
291 fail |= lowpan_fetch_skb(skb, &uh->dest, 2);
292 break;
293 case LOWPAN_NHC_UDP_CS_P_11:
294 fail |= lowpan_fetch_skb(skb, &val, 1);
295 uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT +
296 (val >> 4));
297 uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT +
298 (val & 0x0f));
299 break;
300 default:
301 pr_debug("ERROR: unknown UDP format\n");
302 goto err;
303 break;
304 }
305
306 pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
307 ntohs(uh->source), ntohs(uh->dest));
308
309 /* checksum */
310 if (tmp & LOWPAN_NHC_UDP_CS_C) {
311 pr_debug_ratelimited("checksum elided currently not supported\n");
312 goto err;
313 } else {
314 fail |= lowpan_fetch_skb(skb, &uh->check, 2);
315 }
316
317 /*
318 * UDP lenght needs to be infered from the lower layers
319 * here, we obtain the hint from the remaining size of the
320 * frame
321 */
322 uh->len = htons(skb->len + sizeof(struct udphdr));
323 pr_debug("uncompressed UDP length: src = %d", ntohs(uh->len));
324 } else {
325 pr_debug("ERROR: unsupported NH format\n");
326 goto err;
327 }
328
329 if (fail)
330 goto err;
331
332 return 0;
333err:
334 return -EINVAL;
335}
336
337/* TTL uncompression values */
338static const u8 lowpan_ttl_values[] = { 0, 1, 64, 255 };
339
340int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
341 const u8 *saddr, const u8 saddr_type, const u8 saddr_len,
342 const u8 *daddr, const u8 daddr_type, const u8 daddr_len,
343 u8 iphc0, u8 iphc1, skb_delivery_cb deliver_skb)
344{
345 struct ipv6hdr hdr = {};
346 u8 tmp, num_context = 0;
347 int err;
348
349 raw_dump_table(__func__, "raw skb data dump uncompressed",
350 skb->data, skb->len);
351
352 /* another if the CID flag is set */
353 if (iphc1 & LOWPAN_IPHC_CID) {
354 pr_debug("CID flag is set, increase header with one\n");
355 if (lowpan_fetch_skb_u8(skb, &num_context))
356 goto drop;
357 }
358
359 hdr.version = 6;
360
361 /* Traffic Class and Flow Label */
362 switch ((iphc0 & LOWPAN_IPHC_TF) >> 3) {
363 /*
364 * Traffic Class and FLow Label carried in-line
365 * ECN + DSCP + 4-bit Pad + Flow Label (4 bytes)
366 */
367 case 0: /* 00b */
368 if (lowpan_fetch_skb_u8(skb, &tmp))
369 goto drop;
370
371 memcpy(&hdr.flow_lbl, &skb->data[0], 3);
372 skb_pull(skb, 3);
373 hdr.priority = ((tmp >> 2) & 0x0f);
374 hdr.flow_lbl[0] = ((tmp >> 2) & 0x30) | (tmp << 6) |
375 (hdr.flow_lbl[0] & 0x0f);
376 break;
377 /*
378 * Traffic class carried in-line
379 * ECN + DSCP (1 byte), Flow Label is elided
380 */
381 case 2: /* 10b */
382 if (lowpan_fetch_skb_u8(skb, &tmp))
383 goto drop;
384
385 hdr.priority = ((tmp >> 2) & 0x0f);
386 hdr.flow_lbl[0] = ((tmp << 6) & 0xC0) | ((tmp >> 2) & 0x30);
387 break;
388 /*
389 * Flow Label carried in-line
390 * ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided
391 */
392 case 1: /* 01b */
393 if (lowpan_fetch_skb_u8(skb, &tmp))
394 goto drop;
395
396 hdr.flow_lbl[0] = (skb->data[0] & 0x0F) | ((tmp >> 2) & 0x30);
397 memcpy(&hdr.flow_lbl[1], &skb->data[0], 2);
398 skb_pull(skb, 2);
399 break;
400 /* Traffic Class and Flow Label are elided */
401 case 3: /* 11b */
402 break;
403 default:
404 break;
405 }
406
407 /* Next Header */
408 if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
409 /* Next header is carried inline */
410 if (lowpan_fetch_skb_u8(skb, &(hdr.nexthdr)))
411 goto drop;
412
413 pr_debug("NH flag is set, next header carried inline: %02x\n",
414 hdr.nexthdr);
415 }
416
417 /* Hop Limit */
418 if ((iphc0 & 0x03) != LOWPAN_IPHC_TTL_I)
419 hdr.hop_limit = lowpan_ttl_values[iphc0 & 0x03];
420 else {
421 if (lowpan_fetch_skb_u8(skb, &(hdr.hop_limit)))
422 goto drop;
423 }
424
425 /* Extract SAM to the tmp variable */
426 tmp = ((iphc1 & LOWPAN_IPHC_SAM) >> LOWPAN_IPHC_SAM_BIT) & 0x03;
427
428 if (iphc1 & LOWPAN_IPHC_SAC) {
429 /* Source address context based uncompression */
430 pr_debug("SAC bit is set. Handle context based source address.\n");
431 err = uncompress_context_based_src_addr(
432 skb, &hdr.saddr, tmp);
433 } else {
434 /* Source address uncompression */
435 pr_debug("source address stateless compression\n");
436 err = uncompress_addr(skb, &hdr.saddr, tmp, saddr,
437 saddr_type, saddr_len);
438 }
439
440 /* Check on error of previous branch */
441 if (err)
442 goto drop;
443
444 /* Extract DAM to the tmp variable */
445 tmp = ((iphc1 & LOWPAN_IPHC_DAM_11) >> LOWPAN_IPHC_DAM_BIT) & 0x03;
446
447 /* check for Multicast Compression */
448 if (iphc1 & LOWPAN_IPHC_M) {
449 if (iphc1 & LOWPAN_IPHC_DAC) {
450 pr_debug("dest: context-based mcast compression\n");
451 /* TODO: implement this */
452 } else {
453 err = lowpan_uncompress_multicast_daddr(
454 skb, &hdr.daddr, tmp);
455 if (err)
456 goto drop;
457 }
458 } else {
459 err = uncompress_addr(skb, &hdr.daddr, tmp, daddr,
460 daddr_type, daddr_len);
461 pr_debug("dest: stateless compression mode %d dest %pI6c\n",
462 tmp, &hdr.daddr);
463 if (err)
464 goto drop;
465 }
466
467 /* UDP data uncompression */
468 if (iphc0 & LOWPAN_IPHC_NH_C) {
469 struct udphdr uh;
470 struct sk_buff *new;
471 if (uncompress_udp_header(skb, &uh))
472 goto drop;
473
474 /*
475 * replace the compressed UDP head by the uncompressed UDP
476 * header
477 */
478 new = skb_copy_expand(skb, sizeof(struct udphdr),
479 skb_tailroom(skb), GFP_ATOMIC);
480 kfree_skb(skb);
481
482 if (!new)
483 return -ENOMEM;
484
485 skb = new;
486
487 skb_push(skb, sizeof(struct udphdr));
488 skb_reset_transport_header(skb);
489 skb_copy_to_linear_data(skb, &uh, sizeof(struct udphdr));
490
491 raw_dump_table(__func__, "raw UDP header dump",
492 (u8 *)&uh, sizeof(uh));
493
494 hdr.nexthdr = UIP_PROTO_UDP;
495 }
496
497 hdr.payload_len = htons(skb->len);
498
499 pr_debug("skb headroom size = %d, data length = %d\n",
500 skb_headroom(skb), skb->len);
501
502 pr_debug("IPv6 header dump:\n\tversion = %d\n\tlength = %d\n\t"
503 "nexthdr = 0x%02x\n\thop_lim = %d\n\tdest = %pI6c\n",
504 hdr.version, ntohs(hdr.payload_len), hdr.nexthdr,
505 hdr.hop_limit, &hdr.daddr);
506
507 raw_dump_table(__func__, "raw header dump", (u8 *)&hdr,
508 sizeof(hdr));
509
510 return skb_deliver(skb, &hdr, dev, deliver_skb);
511
512drop:
513 kfree_skb(skb);
514 return -EINVAL;
515}
516EXPORT_SYMBOL_GPL(lowpan_process_data);
517
518static u8 lowpan_compress_addr_64(u8 **hc06_ptr, u8 shift,
519 const struct in6_addr *ipaddr,
520 const unsigned char *lladdr)
521{
522 u8 val = 0;
523
524 if (is_addr_mac_addr_based(ipaddr, lladdr)) {
525 val = 3; /* 0-bits */
526 pr_debug("address compression 0 bits\n");
527 } else if (lowpan_is_iid_16_bit_compressable(ipaddr)) {
528 /* compress IID to 16 bits xxxx::XXXX */
529 memcpy(*hc06_ptr, &ipaddr->s6_addr16[7], 2);
530 *hc06_ptr += 2;
531 val = 2; /* 16-bits */
532 raw_dump_inline(NULL, "Compressed ipv6 addr is (16 bits)",
533 *hc06_ptr - 2, 2);
534 } else {
535 /* do not compress IID => xxxx::IID */
536 memcpy(*hc06_ptr, &ipaddr->s6_addr16[4], 8);
537 *hc06_ptr += 8;
538 val = 1; /* 64-bits */
539 raw_dump_inline(NULL, "Compressed ipv6 addr is (64 bits)",
540 *hc06_ptr - 8, 8);
541 }
542
543 return rol8(val, shift);
544}
545
546static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
547{
548 struct udphdr *uh = udp_hdr(skb);
549 u8 tmp;
550
551 if (((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_MASK) ==
552 LOWPAN_NHC_UDP_4BIT_PORT) &&
553 ((ntohs(uh->dest) & LOWPAN_NHC_UDP_4BIT_MASK) ==
554 LOWPAN_NHC_UDP_4BIT_PORT)) {
555 pr_debug("UDP header: both ports compression to 4 bits\n");
556 /* compression value */
557 tmp = LOWPAN_NHC_UDP_CS_P_11;
558 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
559 /* source and destination port */
560 tmp = ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT +
561 ((ntohs(uh->source) - LOWPAN_NHC_UDP_4BIT_PORT) << 4);
562 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
563 } else if ((ntohs(uh->dest) & LOWPAN_NHC_UDP_8BIT_MASK) ==
564 LOWPAN_NHC_UDP_8BIT_PORT) {
565 pr_debug("UDP header: remove 8 bits of dest\n");
566 /* compression value */
567 tmp = LOWPAN_NHC_UDP_CS_P_01;
568 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
569 /* source port */
570 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source));
571 /* destination port */
572 tmp = ntohs(uh->dest) - LOWPAN_NHC_UDP_8BIT_PORT;
573 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
574 } else if ((ntohs(uh->source) & LOWPAN_NHC_UDP_8BIT_MASK) ==
575 LOWPAN_NHC_UDP_8BIT_PORT) {
576 pr_debug("UDP header: remove 8 bits of source\n");
577 /* compression value */
578 tmp = LOWPAN_NHC_UDP_CS_P_10;
579 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
580 /* source port */
581 tmp = ntohs(uh->source) - LOWPAN_NHC_UDP_8BIT_PORT;
582 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
583 /* destination port */
584 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest));
585 } else {
586 pr_debug("UDP header: can't compress\n");
587 /* compression value */
588 tmp = LOWPAN_NHC_UDP_CS_P_00;
589 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
590 /* source port */
591 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source));
592 /* destination port */
593 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest));
594 }
595
596 /* checksum is always inline */
597 lowpan_push_hc_data(hc06_ptr, &uh->check, sizeof(uh->check));
598
599 /* skip the UDP header */
600 skb_pull(skb, sizeof(struct udphdr));
601}
602
603int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
604 unsigned short type, const void *_daddr,
605 const void *_saddr, unsigned int len)
606{
607 u8 tmp, iphc0, iphc1, *hc06_ptr;
608 struct ipv6hdr *hdr;
609 u8 head[100] = {};
610
611 if (type != ETH_P_IPV6)
612 return -EINVAL;
613
614 hdr = ipv6_hdr(skb);
615 hc06_ptr = head + 2;
616
617 pr_debug("IPv6 header dump:\n\tversion = %d\n\tlength = %d\n"
618 "\tnexthdr = 0x%02x\n\thop_lim = %d\n\tdest = %pI6c\n",
619 hdr->version, ntohs(hdr->payload_len), hdr->nexthdr,
620 hdr->hop_limit, &hdr->daddr);
621
622 raw_dump_table(__func__, "raw skb network header dump",
623 skb_network_header(skb), sizeof(struct ipv6hdr));
624
625 /*
626 * As we copy some bit-length fields, in the IPHC encoding bytes,
627 * we sometimes use |=
628 * If the field is 0, and the current bit value in memory is 1,
629 * this does not work. We therefore reset the IPHC encoding here
630 */
631 iphc0 = LOWPAN_DISPATCH_IPHC;
632 iphc1 = 0;
633
634 /* TODO: context lookup */
635
636 raw_dump_inline(__func__, "saddr",
637 (unsigned char *)_saddr, IEEE802154_ADDR_LEN);
638 raw_dump_inline(__func__, "daddr",
639 (unsigned char *)_daddr, IEEE802154_ADDR_LEN);
640
641 raw_dump_table(__func__,
642 "sending raw skb network uncompressed packet",
643 skb->data, skb->len);
644
645 /*
646 * Traffic class, flow label
647 * If flow label is 0, compress it. If traffic class is 0, compress it
648 * We have to process both in the same time as the offset of traffic
649 * class depends on the presence of version and flow label
650 */
651
652 /* hc06 format of TC is ECN | DSCP , original one is DSCP | ECN */
653 tmp = (hdr->priority << 4) | (hdr->flow_lbl[0] >> 4);
654 tmp = ((tmp & 0x03) << 6) | (tmp >> 2);
655
656 if (((hdr->flow_lbl[0] & 0x0F) == 0) &&
657 (hdr->flow_lbl[1] == 0) && (hdr->flow_lbl[2] == 0)) {
658 /* flow label can be compressed */
659 iphc0 |= LOWPAN_IPHC_FL_C;
660 if ((hdr->priority == 0) &&
661 ((hdr->flow_lbl[0] & 0xF0) == 0)) {
662 /* compress (elide) all */
663 iphc0 |= LOWPAN_IPHC_TC_C;
664 } else {
665 /* compress only the flow label */
666 *hc06_ptr = tmp;
667 hc06_ptr += 1;
668 }
669 } else {
670 /* Flow label cannot be compressed */
671 if ((hdr->priority == 0) &&
672 ((hdr->flow_lbl[0] & 0xF0) == 0)) {
673 /* compress only traffic class */
674 iphc0 |= LOWPAN_IPHC_TC_C;
675 *hc06_ptr = (tmp & 0xc0) | (hdr->flow_lbl[0] & 0x0F);
676 memcpy(hc06_ptr + 1, &hdr->flow_lbl[1], 2);
677 hc06_ptr += 3;
678 } else {
679 /* compress nothing */
680 memcpy(hc06_ptr, hdr, 4);
681 /* replace the top byte with new ECN | DSCP format */
682 *hc06_ptr = tmp;
683 hc06_ptr += 4;
684 }
685 }
686
687 /* NOTE: payload length is always compressed */
688
689 /* Next Header is compress if UDP */
690 if (hdr->nexthdr == UIP_PROTO_UDP)
691 iphc0 |= LOWPAN_IPHC_NH_C;
692
693 if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
694 *hc06_ptr = hdr->nexthdr;
695 hc06_ptr += 1;
696 }
697
698 /*
699 * Hop limit
700 * if 1: compress, encoding is 01
701 * if 64: compress, encoding is 10
702 * if 255: compress, encoding is 11
703 * else do not compress
704 */
705 switch (hdr->hop_limit) {
706 case 1:
707 iphc0 |= LOWPAN_IPHC_TTL_1;
708 break;
709 case 64:
710 iphc0 |= LOWPAN_IPHC_TTL_64;
711 break;
712 case 255:
713 iphc0 |= LOWPAN_IPHC_TTL_255;
714 break;
715 default:
716 *hc06_ptr = hdr->hop_limit;
717 hc06_ptr += 1;
718 break;
719 }
720
721 /* source address compression */
722 if (is_addr_unspecified(&hdr->saddr)) {
723 pr_debug("source address is unspecified, setting SAC\n");
724 iphc1 |= LOWPAN_IPHC_SAC;
725 /* TODO: context lookup */
726 } else if (is_addr_link_local(&hdr->saddr)) {
727 iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
728 LOWPAN_IPHC_SAM_BIT, &hdr->saddr, _saddr);
729 pr_debug("source address unicast link-local %pI6c "
730 "iphc1 0x%02x\n", &hdr->saddr, iphc1);
731 } else {
732 pr_debug("send the full source address\n");
733 memcpy(hc06_ptr, &hdr->saddr.s6_addr16[0], 16);
734 hc06_ptr += 16;
735 }
736
737 /* destination address compression */
738 if (is_addr_mcast(&hdr->daddr)) {
739 pr_debug("destination address is multicast: ");
740 iphc1 |= LOWPAN_IPHC_M;
741 if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) {
742 pr_debug("compressed to 1 octet\n");
743 iphc1 |= LOWPAN_IPHC_DAM_11;
744 /* use last byte */
745 *hc06_ptr = hdr->daddr.s6_addr[15];
746 hc06_ptr += 1;
747 } else if (lowpan_is_mcast_addr_compressable32(&hdr->daddr)) {
748 pr_debug("compressed to 4 octets\n");
749 iphc1 |= LOWPAN_IPHC_DAM_10;
750 /* second byte + the last three */
751 *hc06_ptr = hdr->daddr.s6_addr[1];
752 memcpy(hc06_ptr + 1, &hdr->daddr.s6_addr[13], 3);
753 hc06_ptr += 4;
754 } else if (lowpan_is_mcast_addr_compressable48(&hdr->daddr)) {
755 pr_debug("compressed to 6 octets\n");
756 iphc1 |= LOWPAN_IPHC_DAM_01;
757 /* second byte + the last five */
758 *hc06_ptr = hdr->daddr.s6_addr[1];
759 memcpy(hc06_ptr + 1, &hdr->daddr.s6_addr[11], 5);
760 hc06_ptr += 6;
761 } else {
762 pr_debug("using full address\n");
763 iphc1 |= LOWPAN_IPHC_DAM_00;
764 memcpy(hc06_ptr, &hdr->daddr.s6_addr[0], 16);
765 hc06_ptr += 16;
766 }
767 } else {
768 /* TODO: context lookup */
769 if (is_addr_link_local(&hdr->daddr)) {
770 iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
771 LOWPAN_IPHC_DAM_BIT, &hdr->daddr, _daddr);
772 pr_debug("dest address unicast link-local %pI6c "
773 "iphc1 0x%02x\n", &hdr->daddr, iphc1);
774 } else {
775 pr_debug("dest address unicast %pI6c\n", &hdr->daddr);
776 memcpy(hc06_ptr, &hdr->daddr.s6_addr16[0], 16);
777 hc06_ptr += 16;
778 }
779 }
780
781 /* UDP header compression */
782 if (hdr->nexthdr == UIP_PROTO_UDP)
783 compress_udp_header(&hc06_ptr, skb);
784
785 head[0] = iphc0;
786 head[1] = iphc1;
787
788 skb_pull(skb, sizeof(struct ipv6hdr));
789 skb_reset_transport_header(skb);
790 memcpy(skb_push(skb, hc06_ptr - head), head, hc06_ptr - head);
791 skb_reset_network_header(skb);
792
793 pr_debug("header len %d skb %u\n", (int)(hc06_ptr - head), skb->len);
794
795 raw_dump_table(__func__, "raw skb data dump compressed",
796 skb->data, skb->len);
797 return 0;
798}
799EXPORT_SYMBOL_GPL(lowpan_header_compress);
800
801MODULE_LICENSE("GPL");
diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
index fe6bd7a71081..6591d27e53a4 100644
--- a/net/ieee802154/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan_rtnl.c
@@ -80,14 +80,14 @@ lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
80static inline void lowpan_address_flip(u8 *src, u8 *dest) 80static inline void lowpan_address_flip(u8 *src, u8 *dest)
81{ 81{
82 int i; 82 int i;
83
83 for (i = 0; i < IEEE802154_ADDR_LEN; i++) 84 for (i = 0; i < IEEE802154_ADDR_LEN; i++)
84 (dest)[IEEE802154_ADDR_LEN - i - 1] = (src)[i]; 85 (dest)[IEEE802154_ADDR_LEN - i - 1] = (src)[i];
85} 86}
86 87
87static int lowpan_header_create(struct sk_buff *skb, 88static int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
88 struct net_device *dev, 89 unsigned short type, const void *_daddr,
89 unsigned short type, const void *_daddr, 90 const void *_saddr, unsigned int len)
90 const void *_saddr, unsigned int len)
91{ 91{
92 const u8 *saddr = _saddr; 92 const u8 *saddr = _saddr;
93 const u8 *daddr = _daddr; 93 const u8 *daddr = _daddr;
@@ -144,7 +144,7 @@ static int lowpan_header_create(struct sk_buff *skb,
144} 144}
145 145
146static int lowpan_give_skb_to_devices(struct sk_buff *skb, 146static int lowpan_give_skb_to_devices(struct sk_buff *skb,
147 struct net_device *dev) 147 struct net_device *dev)
148{ 148{
149 struct lowpan_dev_record *entry; 149 struct lowpan_dev_record *entry;
150 struct sk_buff *skb_cp; 150 struct sk_buff *skb_cp;
@@ -246,7 +246,7 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
246 return ERR_PTR(-rc); 246 return ERR_PTR(-rc);
247 } 247 }
248 } else { 248 } else {
249 frag = ERR_PTR(ENOMEM); 249 frag = ERR_PTR(-ENOMEM);
250 } 250 }
251 251
252 return frag; 252 return frag;
@@ -368,24 +368,28 @@ static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
368static struct wpan_phy *lowpan_get_phy(const struct net_device *dev) 368static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
369{ 369{
370 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; 370 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
371
371 return ieee802154_mlme_ops(real_dev)->get_phy(real_dev); 372 return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
372} 373}
373 374
374static __le16 lowpan_get_pan_id(const struct net_device *dev) 375static __le16 lowpan_get_pan_id(const struct net_device *dev)
375{ 376{
376 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; 377 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
378
377 return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev); 379 return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
378} 380}
379 381
380static __le16 lowpan_get_short_addr(const struct net_device *dev) 382static __le16 lowpan_get_short_addr(const struct net_device *dev)
381{ 383{
382 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; 384 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
385
383 return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev); 386 return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);
384} 387}
385 388
386static u8 lowpan_get_dsn(const struct net_device *dev) 389static u8 lowpan_get_dsn(const struct net_device *dev)
387{ 390{
388 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; 391 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
392
389 return ieee802154_mlme_ops(real_dev)->get_dsn(real_dev); 393 return ieee802154_mlme_ops(real_dev)->get_dsn(real_dev);
390} 394}
391 395
@@ -433,7 +437,7 @@ static void lowpan_setup(struct net_device *dev)
433 /* Frame Control + Sequence Number + Address fields + Security Header */ 437 /* Frame Control + Sequence Number + Address fields + Security Header */
434 dev->hard_header_len = 2 + 1 + 20 + 14; 438 dev->hard_header_len = 2 + 1 + 20 + 14;
435 dev->needed_tailroom = 2; /* FCS */ 439 dev->needed_tailroom = 2; /* FCS */
436 dev->mtu = 1281; 440 dev->mtu = IPV6_MIN_MTU;
437 dev->tx_queue_len = 0; 441 dev->tx_queue_len = 0;
438 dev->flags = IFF_BROADCAST | IFF_MULTICAST; 442 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
439 dev->watchdog_timeo = 0; 443 dev->watchdog_timeo = 0;
@@ -454,7 +458,7 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
454} 458}
455 459
456static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev, 460static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
457 struct packet_type *pt, struct net_device *orig_dev) 461 struct packet_type *pt, struct net_device *orig_dev)
458{ 462{
459 struct ieee802154_hdr hdr; 463 struct ieee802154_hdr hdr;
460 int ret; 464 int ret;
diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig
index 8af1330b3137..c0d4154d144f 100644
--- a/net/ieee802154/Kconfig
+++ b/net/ieee802154/Kconfig
@@ -12,13 +12,6 @@ config IEEE802154
12 12
13config IEEE802154_6LOWPAN 13config IEEE802154_6LOWPAN
14 tristate "6lowpan support over IEEE 802.15.4" 14 tristate "6lowpan support over IEEE 802.15.4"
15 depends on IEEE802154 && IPV6 15 depends on IEEE802154 && 6LOWPAN
16 select 6LOWPAN_IPHC
17 ---help--- 16 ---help---
18 IPv6 compression over IEEE 802.15.4. 17 IPv6 compression over IEEE 802.15.4.
19
20config 6LOWPAN_IPHC
21 tristate
22 ---help---
23 6lowpan compression code which is shared between IEEE 802.15.4 and Bluetooth
24 stacks.
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index bf1b51497a41..3914b1ed4274 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -1,8 +1,7 @@
1obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o 1obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o
2obj-$(CONFIG_IEEE802154_6LOWPAN) += 6lowpan.o 2obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o
3obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o
4 3
56lowpan-y := 6lowpan_rtnl.o reassembly.o 4ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o
6ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o \ 5ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o \
7 header_ops.o 6 header_ops.o
8af_802154-y := af_ieee802154.o raw.o dgram.o 7af_802154-y := af_ieee802154.o raw.o dgram.o
diff --git a/net/ieee802154/af_ieee802154.c b/net/ieee802154/af_ieee802154.c
index 351d9a94ec2f..29e0de63001b 100644
--- a/net/ieee802154/af_ieee802154.c
+++ b/net/ieee802154/af_ieee802154.c
@@ -40,9 +40,7 @@
40 40
41#include "af802154.h" 41#include "af802154.h"
42 42
43/* 43/* Utility function for families */
44 * Utility function for families
45 */
46struct net_device* 44struct net_device*
47ieee802154_get_dev(struct net *net, const struct ieee802154_addr *addr) 45ieee802154_get_dev(struct net *net, const struct ieee802154_addr *addr)
48{ 46{
@@ -87,8 +85,8 @@ ieee802154_get_dev(struct net *net, const struct ieee802154_addr *addr)
87 rtnl_unlock(); 85 rtnl_unlock();
88 break; 86 break;
89 default: 87 default:
90 pr_warning("Unsupported ieee802154 address type: %d\n", 88 pr_warn("Unsupported ieee802154 address type: %d\n",
91 addr->mode); 89 addr->mode);
92 break; 90 break;
93 } 91 }
94 92
@@ -106,7 +104,7 @@ static int ieee802154_sock_release(struct socket *sock)
106 return 0; 104 return 0;
107} 105}
108static int ieee802154_sock_sendmsg(struct kiocb *iocb, struct socket *sock, 106static int ieee802154_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
109 struct msghdr *msg, size_t len) 107 struct msghdr *msg, size_t len)
110{ 108{
111 struct sock *sk = sock->sk; 109 struct sock *sk = sock->sk;
112 110
@@ -114,7 +112,7 @@ static int ieee802154_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
114} 112}
115 113
116static int ieee802154_sock_bind(struct socket *sock, struct sockaddr *uaddr, 114static int ieee802154_sock_bind(struct socket *sock, struct sockaddr *uaddr,
117 int addr_len) 115 int addr_len)
118{ 116{
119 struct sock *sk = sock->sk; 117 struct sock *sk = sock->sk;
120 118
@@ -125,7 +123,7 @@ static int ieee802154_sock_bind(struct socket *sock, struct sockaddr *uaddr,
125} 123}
126 124
127static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr, 125static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr,
128 int addr_len, int flags) 126 int addr_len, int flags)
129{ 127{
130 struct sock *sk = sock->sk; 128 struct sock *sk = sock->sk;
131 129
@@ -139,7 +137,7 @@ static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr,
139} 137}
140 138
141static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg, 139static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg,
142 unsigned int cmd) 140 unsigned int cmd)
143{ 141{
144 struct ifreq ifr; 142 struct ifreq ifr;
145 int ret = -ENOIOCTLCMD; 143 int ret = -ENOIOCTLCMD;
@@ -167,7 +165,7 @@ static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg,
167} 165}
168 166
169static int ieee802154_sock_ioctl(struct socket *sock, unsigned int cmd, 167static int ieee802154_sock_ioctl(struct socket *sock, unsigned int cmd,
170 unsigned long arg) 168 unsigned long arg)
171{ 169{
172 struct sock *sk = sock->sk; 170 struct sock *sk = sock->sk;
173 171
@@ -238,8 +236,7 @@ static const struct proto_ops ieee802154_dgram_ops = {
238}; 236};
239 237
240 238
241/* 239/* Create a socket. Initialise the socket, blank the addresses
242 * Create a socket. Initialise the socket, blank the addresses
243 * set the state. 240 * set the state.
244 */ 241 */
245static int ieee802154_create(struct net *net, struct socket *sock, 242static int ieee802154_create(struct net *net, struct socket *sock,
@@ -301,13 +298,14 @@ static const struct net_proto_family ieee802154_family_ops = {
301}; 298};
302 299
303static int ieee802154_rcv(struct sk_buff *skb, struct net_device *dev, 300static int ieee802154_rcv(struct sk_buff *skb, struct net_device *dev,
304 struct packet_type *pt, struct net_device *orig_dev) 301 struct packet_type *pt, struct net_device *orig_dev)
305{ 302{
306 if (!netif_running(dev)) 303 if (!netif_running(dev))
307 goto drop; 304 goto drop;
308 pr_debug("got frame, type %d, dev %p\n", dev->type, dev); 305 pr_debug("got frame, type %d, dev %p\n", dev->type, dev);
309#ifdef DEBUG 306#ifdef DEBUG
310 print_hex_dump_bytes("ieee802154_rcv ", DUMP_PREFIX_NONE, skb->data, skb->len); 307 print_hex_dump_bytes("ieee802154_rcv ",
308 DUMP_PREFIX_NONE, skb->data, skb->len);
311#endif 309#endif
312 310
313 if (!net_eq(dev_net(dev), &init_net)) 311 if (!net_eq(dev_net(dev), &init_net))
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
index 4f0ed8780194..ef2ad8aaef13 100644
--- a/net/ieee802154/dgram.c
+++ b/net/ieee802154/dgram.c
@@ -149,8 +149,7 @@ static int dgram_ioctl(struct sock *sk, int cmd, unsigned long arg)
149 spin_lock_bh(&sk->sk_receive_queue.lock); 149 spin_lock_bh(&sk->sk_receive_queue.lock);
150 skb = skb_peek(&sk->sk_receive_queue); 150 skb = skb_peek(&sk->sk_receive_queue);
151 if (skb != NULL) { 151 if (skb != NULL) {
152 /* 152 /* We will only return the amount
153 * We will only return the amount
154 * of this packet since that is all 153 * of this packet since that is all
155 * that will be read. 154 * that will be read.
156 */ 155 */
@@ -161,12 +160,13 @@ static int dgram_ioctl(struct sock *sk, int cmd, unsigned long arg)
161 } 160 }
162 161
163 } 162 }
163
164 return -ENOIOCTLCMD; 164 return -ENOIOCTLCMD;
165} 165}
166 166
167/* FIXME: autobind */ 167/* FIXME: autobind */
168static int dgram_connect(struct sock *sk, struct sockaddr *uaddr, 168static int dgram_connect(struct sock *sk, struct sockaddr *uaddr,
169 int len) 169 int len)
170{ 170{
171 struct sockaddr_ieee802154 *addr = (struct sockaddr_ieee802154 *)uaddr; 171 struct sockaddr_ieee802154 *addr = (struct sockaddr_ieee802154 *)uaddr;
172 struct dgram_sock *ro = dgram_sk(sk); 172 struct dgram_sock *ro = dgram_sk(sk);
@@ -205,7 +205,7 @@ static int dgram_disconnect(struct sock *sk, int flags)
205} 205}
206 206
207static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk, 207static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
208 struct msghdr *msg, size_t size) 208 struct msghdr *msg, size_t size)
209{ 209{
210 struct net_device *dev; 210 struct net_device *dev;
211 unsigned int mtu; 211 unsigned int mtu;
@@ -248,8 +248,8 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
248 hlen = LL_RESERVED_SPACE(dev); 248 hlen = LL_RESERVED_SPACE(dev);
249 tlen = dev->needed_tailroom; 249 tlen = dev->needed_tailroom;
250 skb = sock_alloc_send_skb(sk, hlen + tlen + size, 250 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
251 msg->msg_flags & MSG_DONTWAIT, 251 msg->msg_flags & MSG_DONTWAIT,
252 &err); 252 &err);
253 if (!skb) 253 if (!skb)
254 goto out_dev; 254 goto out_dev;
255 255
@@ -262,7 +262,8 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
262 cb->ackreq = ro->want_ack; 262 cb->ackreq = ro->want_ack;
263 263
264 if (msg->msg_name) { 264 if (msg->msg_name) {
265 DECLARE_SOCKADDR(struct sockaddr_ieee802154*, daddr, msg->msg_name); 265 DECLARE_SOCKADDR(struct sockaddr_ieee802154*,
266 daddr, msg->msg_name);
266 267
267 ieee802154_addr_from_sa(&dst_addr, &daddr->addr); 268 ieee802154_addr_from_sa(&dst_addr, &daddr->addr);
268 } else { 269 } else {
@@ -304,8 +305,8 @@ out:
304} 305}
305 306
306static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk, 307static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
307 struct msghdr *msg, size_t len, int noblock, int flags, 308 struct msghdr *msg, size_t len, int noblock,
308 int *addr_len) 309 int flags, int *addr_len)
309{ 310{
310 size_t copied = 0; 311 size_t copied = 0;
311 int err = -EOPNOTSUPP; 312 int err = -EOPNOTSUPP;
@@ -398,6 +399,7 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
398 dgram_sk(sk))) { 399 dgram_sk(sk))) {
399 if (prev) { 400 if (prev) {
400 struct sk_buff *clone; 401 struct sk_buff *clone;
402
401 clone = skb_clone(skb, GFP_ATOMIC); 403 clone = skb_clone(skb, GFP_ATOMIC);
402 if (clone) 404 if (clone)
403 dgram_rcv_skb(prev, clone); 405 dgram_rcv_skb(prev, clone);
@@ -407,9 +409,9 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
407 } 409 }
408 } 410 }
409 411
410 if (prev) 412 if (prev) {
411 dgram_rcv_skb(prev, skb); 413 dgram_rcv_skb(prev, skb);
412 else { 414 } else {
413 kfree_skb(skb); 415 kfree_skb(skb);
414 ret = NET_RX_DROP; 416 ret = NET_RX_DROP;
415 } 417 }
@@ -419,7 +421,7 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
419} 421}
420 422
421static int dgram_getsockopt(struct sock *sk, int level, int optname, 423static int dgram_getsockopt(struct sock *sk, int level, int optname,
422 char __user *optval, int __user *optlen) 424 char __user *optval, int __user *optlen)
423{ 425{
424 struct dgram_sock *ro = dgram_sk(sk); 426 struct dgram_sock *ro = dgram_sk(sk);
425 427
@@ -463,7 +465,7 @@ static int dgram_getsockopt(struct sock *sk, int level, int optname,
463} 465}
464 466
465static int dgram_setsockopt(struct sock *sk, int level, int optname, 467static int dgram_setsockopt(struct sock *sk, int level, int optname,
466 char __user *optval, unsigned int optlen) 468 char __user *optval, unsigned int optlen)
467{ 469{
468 struct dgram_sock *ro = dgram_sk(sk); 470 struct dgram_sock *ro = dgram_sk(sk);
469 struct net *net = sock_net(sk); 471 struct net *net = sock_net(sk);
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
index 8b83a231299e..5d352f86979e 100644
--- a/net/ieee802154/ieee802154.h
+++ b/net/ieee802154/ieee802154.h
@@ -43,7 +43,7 @@ struct genl_info;
43struct sk_buff *ieee802154_nl_create(int flags, u8 req); 43struct sk_buff *ieee802154_nl_create(int flags, u8 req);
44int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group); 44int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group);
45struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info, 45struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
46 int flags, u8 req); 46 int flags, u8 req);
47int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info); 47int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
48 48
49extern struct genl_family nl802154_family; 49extern struct genl_family nl802154_family;
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 26efcf4fd2ff..9222966f5e6d 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -52,7 +52,7 @@ struct sk_buff *ieee802154_nl_create(int flags, u8 req)
52 52
53 spin_lock_irqsave(&ieee802154_seq_lock, f); 53 spin_lock_irqsave(&ieee802154_seq_lock, f);
54 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, 54 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
55 &nl802154_family, flags, req); 55 &nl802154_family, flags, req);
56 spin_unlock_irqrestore(&ieee802154_seq_lock, f); 56 spin_unlock_irqrestore(&ieee802154_seq_lock, f);
57 if (!hdr) { 57 if (!hdr) {
58 nlmsg_free(msg); 58 nlmsg_free(msg);
@@ -86,7 +86,7 @@ struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
86 return NULL; 86 return NULL;
87 87
88 hdr = genlmsg_put_reply(msg, info, 88 hdr = genlmsg_put_reply(msg, info,
89 &nl802154_family, flags, req); 89 &nl802154_family, flags, req);
90 if (!hdr) { 90 if (!hdr) {
91 nlmsg_free(msg); 91 nlmsg_free(msg);
92 return NULL; 92 return NULL;
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index a3281b8bfd5b..c6bfe22bfa5e 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -60,7 +60,8 @@ static __le16 nla_get_shortaddr(const struct nlattr *nla)
60} 60}
61 61
62int ieee802154_nl_assoc_indic(struct net_device *dev, 62int ieee802154_nl_assoc_indic(struct net_device *dev,
63 struct ieee802154_addr *addr, u8 cap) 63 struct ieee802154_addr *addr,
64 u8 cap)
64{ 65{
65 struct sk_buff *msg; 66 struct sk_buff *msg;
66 67
@@ -93,7 +94,7 @@ nla_put_failure:
93EXPORT_SYMBOL(ieee802154_nl_assoc_indic); 94EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
94 95
95int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr, 96int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
96 u8 status) 97 u8 status)
97{ 98{
98 struct sk_buff *msg; 99 struct sk_buff *msg;
99 100
@@ -119,7 +120,8 @@ nla_put_failure:
119EXPORT_SYMBOL(ieee802154_nl_assoc_confirm); 120EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
120 121
121int ieee802154_nl_disassoc_indic(struct net_device *dev, 122int ieee802154_nl_disassoc_indic(struct net_device *dev,
122 struct ieee802154_addr *addr, u8 reason) 123 struct ieee802154_addr *addr,
124 u8 reason)
123{ 125{
124 struct sk_buff *msg; 126 struct sk_buff *msg;
125 127
@@ -205,8 +207,9 @@ nla_put_failure:
205EXPORT_SYMBOL(ieee802154_nl_beacon_indic); 207EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
206 208
207int ieee802154_nl_scan_confirm(struct net_device *dev, 209int ieee802154_nl_scan_confirm(struct net_device *dev,
208 u8 status, u8 scan_type, u32 unscanned, u8 page, 210 u8 status, u8 scan_type,
209 u8 *edl/* , struct list_head *pan_desc_list */) 211 u32 unscanned, u8 page,
212 u8 *edl/* , struct list_head *pan_desc_list */)
210{ 213{
211 struct sk_buff *msg; 214 struct sk_buff *msg;
212 215
@@ -260,7 +263,7 @@ nla_put_failure:
260EXPORT_SYMBOL(ieee802154_nl_start_confirm); 263EXPORT_SYMBOL(ieee802154_nl_start_confirm);
261 264
262static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid, 265static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
263 u32 seq, int flags, struct net_device *dev) 266 u32 seq, int flags, struct net_device *dev)
264{ 267{
265 void *hdr; 268 void *hdr;
266 struct wpan_phy *phy; 269 struct wpan_phy *phy;
@@ -270,7 +273,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
270 pr_debug("%s\n", __func__); 273 pr_debug("%s\n", __func__);
271 274
272 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags, 275 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
273 IEEE802154_LIST_IFACE); 276 IEEE802154_LIST_IFACE);
274 if (!hdr) 277 if (!hdr)
275 goto out; 278 goto out;
276 279
@@ -330,14 +333,16 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
330 333
331 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) { 334 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
332 char name[IFNAMSIZ + 1]; 335 char name[IFNAMSIZ + 1];
336
333 nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME], 337 nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
334 sizeof(name)); 338 sizeof(name));
335 dev = dev_get_by_name(&init_net, name); 339 dev = dev_get_by_name(&init_net, name);
336 } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX]) 340 } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX]) {
337 dev = dev_get_by_index(&init_net, 341 dev = dev_get_by_index(&init_net,
338 nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX])); 342 nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
339 else 343 } else {
340 return NULL; 344 return NULL;
345 }
341 346
342 if (!dev) 347 if (!dev)
343 return NULL; 348 return NULL;
@@ -435,7 +440,7 @@ int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
435 int ret = -EOPNOTSUPP; 440 int ret = -EOPNOTSUPP;
436 441
437 if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] && 442 if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
438 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) || 443 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
439 !info->attrs[IEEE802154_ATTR_REASON]) 444 !info->attrs[IEEE802154_ATTR_REASON])
440 return -EINVAL; 445 return -EINVAL;
441 446
@@ -464,8 +469,7 @@ out:
464 return ret; 469 return ret;
465} 470}
466 471
467/* 472/* PANid, channel, beacon_order = 15, superframe_order = 15,
468 * PANid, channel, beacon_order = 15, superframe_order = 15,
469 * PAN_coordinator, battery_life_extension = 0, 473 * PAN_coordinator, battery_life_extension = 0,
470 * coord_realignment = 0, security_enable = 0 474 * coord_realignment = 0, security_enable = 0
471*/ 475*/
@@ -559,8 +563,8 @@ int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
559 page = 0; 563 page = 0;
560 564
561 565
562 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, page, 566 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels,
563 duration); 567 page, duration);
564 568
565out: 569out:
566 dev_put(dev); 570 dev_put(dev);
@@ -570,7 +574,8 @@ out:
570int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info) 574int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
571{ 575{
572 /* Request for interface name, index, type, IEEE address, 576 /* Request for interface name, index, type, IEEE address,
573 PAN Id, short address */ 577 * PAN Id, short address
578 */
574 struct sk_buff *msg; 579 struct sk_buff *msg;
575 struct net_device *dev = NULL; 580 struct net_device *dev = NULL;
576 int rc = -ENOBUFS; 581 int rc = -ENOBUFS;
@@ -586,7 +591,7 @@ int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
586 goto out_dev; 591 goto out_dev;
587 592
588 rc = ieee802154_nl_fill_iface(msg, info->snd_portid, info->snd_seq, 593 rc = ieee802154_nl_fill_iface(msg, info->snd_portid, info->snd_seq,
589 0, dev); 594 0, dev);
590 if (rc < 0) 595 if (rc < 0)
591 goto out_free; 596 goto out_free;
592 597
@@ -598,7 +603,6 @@ out_free:
598out_dev: 603out_dev:
599 dev_put(dev); 604 dev_put(dev);
600 return rc; 605 return rc;
601
602} 606}
603 607
604int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb) 608int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
@@ -616,7 +620,8 @@ int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
616 goto cont; 620 goto cont;
617 621
618 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid, 622 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
619 cb->nlh->nlmsg_seq, NLM_F_MULTI, dev) < 0) 623 cb->nlh->nlmsg_seq,
624 NLM_F_MULTI, dev) < 0)
620 break; 625 break;
621cont: 626cont:
622 idx++; 627 idx++;
@@ -765,6 +770,7 @@ ieee802154_llsec_parse_key_id(struct genl_info *info,
765 case IEEE802154_SCF_KEY_SHORT_INDEX: 770 case IEEE802154_SCF_KEY_SHORT_INDEX:
766 { 771 {
767 u32 source = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT]); 772 u32 source = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT]);
773
768 desc->short_source = cpu_to_le32(source); 774 desc->short_source = cpu_to_le32(source);
769 break; 775 break;
770 } 776 }
@@ -842,7 +848,7 @@ int ieee802154_llsec_getparams(struct sk_buff *skb, struct genl_info *info)
842 goto out_dev; 848 goto out_dev;
843 849
844 hdr = genlmsg_put(msg, 0, info->snd_seq, &nl802154_family, 0, 850 hdr = genlmsg_put(msg, 0, info->snd_seq, &nl802154_family, 0,
845 IEEE802154_LLSEC_GETPARAMS); 851 IEEE802154_LLSEC_GETPARAMS);
846 if (!hdr) 852 if (!hdr)
847 goto out_free; 853 goto out_free;
848 854
@@ -946,7 +952,7 @@ struct llsec_dump_data {
946 952
947static int 953static int
948ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb, 954ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb,
949 int (*step)(struct llsec_dump_data*)) 955 int (*step)(struct llsec_dump_data *))
950{ 956{
951 struct net *net = sock_net(skb->sk); 957 struct net *net = sock_net(skb->sk);
952 struct net_device *dev; 958 struct net_device *dev;
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 89b265aea151..972baf83411a 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -36,7 +36,7 @@
36#include "ieee802154.h" 36#include "ieee802154.h"
37 37
38static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid, 38static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid,
39 u32 seq, int flags, struct wpan_phy *phy) 39 u32 seq, int flags, struct wpan_phy *phy)
40{ 40{
41 void *hdr; 41 void *hdr;
42 int i, pages = 0; 42 int i, pages = 0;
@@ -48,7 +48,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid,
48 return -EMSGSIZE; 48 return -EMSGSIZE;
49 49
50 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags, 50 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
51 IEEE802154_LIST_PHY); 51 IEEE802154_LIST_PHY);
52 if (!hdr) 52 if (!hdr)
53 goto out; 53 goto out;
54 54
@@ -80,7 +80,8 @@ out:
80int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info) 80int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info)
81{ 81{
82 /* Request for interface name, index, type, IEEE address, 82 /* Request for interface name, index, type, IEEE address,
83 PAN Id, short address */ 83 * PAN Id, short address
84 */
84 struct sk_buff *msg; 85 struct sk_buff *msg;
85 struct wpan_phy *phy; 86 struct wpan_phy *phy;
86 const char *name; 87 const char *name;
@@ -105,7 +106,7 @@ int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info)
105 goto out_dev; 106 goto out_dev;
106 107
107 rc = ieee802154_nl_fill_phy(msg, info->snd_portid, info->snd_seq, 108 rc = ieee802154_nl_fill_phy(msg, info->snd_portid, info->snd_seq,
108 0, phy); 109 0, phy);
109 if (rc < 0) 110 if (rc < 0)
110 goto out_free; 111 goto out_free;
111 112
@@ -117,7 +118,6 @@ out_free:
117out_dev: 118out_dev:
118 wpan_phy_put(phy); 119 wpan_phy_put(phy);
119 return rc; 120 return rc;
120
121} 121}
122 122
123struct dump_phy_data { 123struct dump_phy_data {
@@ -137,10 +137,10 @@ static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
137 return 0; 137 return 0;
138 138
139 rc = ieee802154_nl_fill_phy(data->skb, 139 rc = ieee802154_nl_fill_phy(data->skb,
140 NETLINK_CB(data->cb->skb).portid, 140 NETLINK_CB(data->cb->skb).portid,
141 data->cb->nlh->nlmsg_seq, 141 data->cb->nlh->nlmsg_seq,
142 NLM_F_MULTI, 142 NLM_F_MULTI,
143 phy); 143 phy);
144 144
145 if (rc < 0) { 145 if (rc < 0) {
146 data->idx--; 146 data->idx--;
@@ -238,10 +238,9 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
238 238
239 addr.sa_family = ARPHRD_IEEE802154; 239 addr.sa_family = ARPHRD_IEEE802154;
240 nla_memcpy(&addr.sa_data, info->attrs[IEEE802154_ATTR_HW_ADDR], 240 nla_memcpy(&addr.sa_data, info->attrs[IEEE802154_ATTR_HW_ADDR],
241 IEEE802154_ADDR_LEN); 241 IEEE802154_ADDR_LEN);
242 242
243 /* 243 /* strangely enough, some callbacks (inetdev_event) from
244 * strangely enough, some callbacks (inetdev_event) from
245 * dev_set_mac_address require RTNL_LOCK 244 * dev_set_mac_address require RTNL_LOCK
246 */ 245 */
247 rtnl_lock(); 246 rtnl_lock();
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
index 74d54fae33d7..9d1f64806f02 100644
--- a/net/ieee802154/raw.c
+++ b/net/ieee802154/raw.c
@@ -96,7 +96,7 @@ out:
96} 96}
97 97
98static int raw_connect(struct sock *sk, struct sockaddr *uaddr, 98static int raw_connect(struct sock *sk, struct sockaddr *uaddr,
99 int addr_len) 99 int addr_len)
100{ 100{
101 return -ENOTSUPP; 101 return -ENOTSUPP;
102} 102}
@@ -106,8 +106,8 @@ static int raw_disconnect(struct sock *sk, int flags)
106 return 0; 106 return 0;
107} 107}
108 108
109static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 109static int raw_sendmsg(struct kiocb *iocb, struct sock *sk,
110 size_t size) 110 struct msghdr *msg, size_t size)
111{ 111{
112 struct net_device *dev; 112 struct net_device *dev;
113 unsigned int mtu; 113 unsigned int mtu;
@@ -145,7 +145,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
145 hlen = LL_RESERVED_SPACE(dev); 145 hlen = LL_RESERVED_SPACE(dev);
146 tlen = dev->needed_tailroom; 146 tlen = dev->needed_tailroom;
147 skb = sock_alloc_send_skb(sk, hlen + tlen + size, 147 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
148 msg->msg_flags & MSG_DONTWAIT, &err); 148 msg->msg_flags & MSG_DONTWAIT, &err);
149 if (!skb) 149 if (!skb)
150 goto out_dev; 150 goto out_dev;
151 151
@@ -235,7 +235,6 @@ void ieee802154_raw_deliver(struct net_device *dev, struct sk_buff *skb)
235 bh_lock_sock(sk); 235 bh_lock_sock(sk);
236 if (!sk->sk_bound_dev_if || 236 if (!sk->sk_bound_dev_if ||
237 sk->sk_bound_dev_if == dev->ifindex) { 237 sk->sk_bound_dev_if == dev->ifindex) {
238
239 struct sk_buff *clone; 238 struct sk_buff *clone;
240 239
241 clone = skb_clone(skb, GFP_ATOMIC); 240 clone = skb_clone(skb, GFP_ATOMIC);
@@ -248,13 +247,13 @@ void ieee802154_raw_deliver(struct net_device *dev, struct sk_buff *skb)
248} 247}
249 248
250static int raw_getsockopt(struct sock *sk, int level, int optname, 249static int raw_getsockopt(struct sock *sk, int level, int optname,
251 char __user *optval, int __user *optlen) 250 char __user *optval, int __user *optlen)
252{ 251{
253 return -EOPNOTSUPP; 252 return -EOPNOTSUPP;
254} 253}
255 254
256static int raw_setsockopt(struct sock *sk, int level, int optname, 255static int raw_setsockopt(struct sock *sk, int level, int optname,
257 char __user *optval, unsigned int optlen) 256 char __user *optval, unsigned int optlen)
258{ 257{
259 return -EOPNOTSUPP; 258 return -EOPNOTSUPP;
260} 259}
@@ -274,4 +273,3 @@ struct proto ieee802154_raw_prot = {
274 .getsockopt = raw_getsockopt, 273 .getsockopt = raw_getsockopt,
275 .setsockopt = raw_setsockopt, 274 .setsockopt = raw_setsockopt,
276}; 275};
277
diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
index 6f1428c4870b..32755cb7e64e 100644
--- a/net/ieee802154/reassembly.c
+++ b/net/ieee802154/reassembly.c
@@ -30,6 +30,8 @@
30 30
31#include "reassembly.h" 31#include "reassembly.h"
32 32
33static const char lowpan_frags_cache_name[] = "lowpan-frags";
34
33struct lowpan_frag_info { 35struct lowpan_frag_info {
34 __be16 d_tag; 36 __be16 d_tag;
35 u16 d_size; 37 u16 d_size;
@@ -50,29 +52,25 @@ static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size,
50 const struct ieee802154_addr *saddr, 52 const struct ieee802154_addr *saddr,
51 const struct ieee802154_addr *daddr) 53 const struct ieee802154_addr *daddr)
52{ 54{
53 u32 c;
54
55 net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd)); 55 net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd));
56 c = jhash_3words(ieee802154_addr_hash(saddr), 56 return jhash_3words(ieee802154_addr_hash(saddr),
57 ieee802154_addr_hash(daddr), 57 ieee802154_addr_hash(daddr),
58 (__force u32)(tag + (d_size << 16)), 58 (__force u32)(tag + (d_size << 16)),
59 lowpan_frags.rnd); 59 lowpan_frags.rnd);
60
61 return c & (INETFRAGS_HASHSZ - 1);
62} 60}
63 61
64static unsigned int lowpan_hashfn(struct inet_frag_queue *q) 62static unsigned int lowpan_hashfn(const struct inet_frag_queue *q)
65{ 63{
66 struct lowpan_frag_queue *fq; 64 const struct lowpan_frag_queue *fq;
67 65
68 fq = container_of(q, struct lowpan_frag_queue, q); 66 fq = container_of(q, struct lowpan_frag_queue, q);
69 return lowpan_hash_frag(fq->tag, fq->d_size, &fq->saddr, &fq->daddr); 67 return lowpan_hash_frag(fq->tag, fq->d_size, &fq->saddr, &fq->daddr);
70} 68}
71 69
72static bool lowpan_frag_match(struct inet_frag_queue *q, void *a) 70static bool lowpan_frag_match(const struct inet_frag_queue *q, const void *a)
73{ 71{
74 struct lowpan_frag_queue *fq; 72 const struct lowpan_frag_queue *fq;
75 struct lowpan_create_arg *arg = a; 73 const struct lowpan_create_arg *arg = a;
76 74
77 fq = container_of(q, struct lowpan_frag_queue, q); 75 fq = container_of(q, struct lowpan_frag_queue, q);
78 return fq->tag == arg->tag && fq->d_size == arg->d_size && 76 return fq->tag == arg->tag && fq->d_size == arg->d_size &&
@@ -80,10 +78,10 @@ static bool lowpan_frag_match(struct inet_frag_queue *q, void *a)
80 ieee802154_addr_equal(&fq->daddr, arg->dst); 78 ieee802154_addr_equal(&fq->daddr, arg->dst);
81} 79}
82 80
83static void lowpan_frag_init(struct inet_frag_queue *q, void *a) 81static void lowpan_frag_init(struct inet_frag_queue *q, const void *a)
84{ 82{
83 const struct lowpan_create_arg *arg = a;
85 struct lowpan_frag_queue *fq; 84 struct lowpan_frag_queue *fq;
86 struct lowpan_create_arg *arg = a;
87 85
88 fq = container_of(q, struct lowpan_frag_queue, q); 86 fq = container_of(q, struct lowpan_frag_queue, q);
89 87
@@ -103,7 +101,7 @@ static void lowpan_frag_expire(unsigned long data)
103 101
104 spin_lock(&fq->q.lock); 102 spin_lock(&fq->q.lock);
105 103
106 if (fq->q.last_in & INET_FRAG_COMPLETE) 104 if (fq->q.flags & INET_FRAG_COMPLETE)
107 goto out; 105 goto out;
108 106
109 inet_frag_kill(&fq->q, &lowpan_frags); 107 inet_frag_kill(&fq->q, &lowpan_frags);
@@ -128,7 +126,6 @@ fq_find(struct net *net, const struct lowpan_frag_info *frag_info,
128 arg.src = src; 126 arg.src = src;
129 arg.dst = dst; 127 arg.dst = dst;
130 128
131 read_lock(&lowpan_frags.lock);
132 hash = lowpan_hash_frag(frag_info->d_tag, frag_info->d_size, src, dst); 129 hash = lowpan_hash_frag(frag_info->d_tag, frag_info->d_size, src, dst);
133 130
134 q = inet_frag_find(&ieee802154_lowpan->frags, 131 q = inet_frag_find(&ieee802154_lowpan->frags,
@@ -147,7 +144,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
147 struct net_device *dev; 144 struct net_device *dev;
148 int end, offset; 145 int end, offset;
149 146
150 if (fq->q.last_in & INET_FRAG_COMPLETE) 147 if (fq->q.flags & INET_FRAG_COMPLETE)
151 goto err; 148 goto err;
152 149
153 offset = lowpan_cb(skb)->d_offset << 3; 150 offset = lowpan_cb(skb)->d_offset << 3;
@@ -159,14 +156,14 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
159 * or have different end, the segment is corrupted. 156 * or have different end, the segment is corrupted.
160 */ 157 */
161 if (end < fq->q.len || 158 if (end < fq->q.len ||
162 ((fq->q.last_in & INET_FRAG_LAST_IN) && end != fq->q.len)) 159 ((fq->q.flags & INET_FRAG_LAST_IN) && end != fq->q.len))
163 goto err; 160 goto err;
164 fq->q.last_in |= INET_FRAG_LAST_IN; 161 fq->q.flags |= INET_FRAG_LAST_IN;
165 fq->q.len = end; 162 fq->q.len = end;
166 } else { 163 } else {
167 if (end > fq->q.len) { 164 if (end > fq->q.len) {
168 /* Some bits beyond end -> corruption. */ 165 /* Some bits beyond end -> corruption. */
169 if (fq->q.last_in & INET_FRAG_LAST_IN) 166 if (fq->q.flags & INET_FRAG_LAST_IN)
170 goto err; 167 goto err;
171 fq->q.len = end; 168 fq->q.len = end;
172 } 169 }
@@ -206,13 +203,13 @@ found:
206 if (frag_type == LOWPAN_DISPATCH_FRAG1) { 203 if (frag_type == LOWPAN_DISPATCH_FRAG1) {
207 /* Calculate uncomp. 6lowpan header to estimate full size */ 204 /* Calculate uncomp. 6lowpan header to estimate full size */
208 fq->q.meat += lowpan_uncompress_size(skb, NULL); 205 fq->q.meat += lowpan_uncompress_size(skb, NULL);
209 fq->q.last_in |= INET_FRAG_FIRST_IN; 206 fq->q.flags |= INET_FRAG_FIRST_IN;
210 } else { 207 } else {
211 fq->q.meat += skb->len; 208 fq->q.meat += skb->len;
212 } 209 }
213 add_frag_mem_limit(&fq->q, skb->truesize); 210 add_frag_mem_limit(&fq->q, skb->truesize);
214 211
215 if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) && 212 if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
216 fq->q.meat == fq->q.len) { 213 fq->q.meat == fq->q.len) {
217 int res; 214 int res;
218 unsigned long orefdst = skb->_skb_refdst; 215 unsigned long orefdst = skb->_skb_refdst;
@@ -223,7 +220,6 @@ found:
223 return res; 220 return res;
224 } 221 }
225 222
226 inet_frag_lru_move(&fq->q);
227 return -1; 223 return -1;
228err: 224err:
229 kfree_skb(skb); 225 kfree_skb(skb);
@@ -359,8 +355,6 @@ int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type)
359 struct net *net = dev_net(skb->dev); 355 struct net *net = dev_net(skb->dev);
360 struct lowpan_frag_info *frag_info = lowpan_cb(skb); 356 struct lowpan_frag_info *frag_info = lowpan_cb(skb);
361 struct ieee802154_addr source, dest; 357 struct ieee802154_addr source, dest;
362 struct netns_ieee802154_lowpan *ieee802154_lowpan =
363 net_ieee802154_lowpan(net);
364 int err; 358 int err;
365 359
366 source = mac_cb(skb)->source; 360 source = mac_cb(skb)->source;
@@ -370,14 +364,15 @@ int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type)
370 if (err < 0) 364 if (err < 0)
371 goto err; 365 goto err;
372 366
373 if (frag_info->d_size > ieee802154_lowpan->max_dsize) 367 if (frag_info->d_size > IPV6_MIN_MTU) {
368 net_warn_ratelimited("lowpan_frag_rcv: datagram size exceeds MTU\n");
374 goto err; 369 goto err;
375 370 }
376 inet_frag_evictor(&ieee802154_lowpan->frags, &lowpan_frags, false);
377 371
378 fq = fq_find(net, frag_info, &source, &dest); 372 fq = fq_find(net, frag_info, &source, &dest);
379 if (fq != NULL) { 373 if (fq != NULL) {
380 int ret; 374 int ret;
375
381 spin_lock(&fq->q.lock); 376 spin_lock(&fq->q.lock);
382 ret = lowpan_frag_queue(fq, skb, frag_type); 377 ret = lowpan_frag_queue(fq, skb, frag_type);
383 spin_unlock(&fq->q.lock); 378 spin_unlock(&fq->q.lock);
@@ -393,20 +388,25 @@ err:
393EXPORT_SYMBOL(lowpan_frag_rcv); 388EXPORT_SYMBOL(lowpan_frag_rcv);
394 389
395#ifdef CONFIG_SYSCTL 390#ifdef CONFIG_SYSCTL
391static int zero;
392
396static struct ctl_table lowpan_frags_ns_ctl_table[] = { 393static struct ctl_table lowpan_frags_ns_ctl_table[] = {
397 { 394 {
398 .procname = "6lowpanfrag_high_thresh", 395 .procname = "6lowpanfrag_high_thresh",
399 .data = &init_net.ieee802154_lowpan.frags.high_thresh, 396 .data = &init_net.ieee802154_lowpan.frags.high_thresh,
400 .maxlen = sizeof(int), 397 .maxlen = sizeof(int),
401 .mode = 0644, 398 .mode = 0644,
402 .proc_handler = proc_dointvec 399 .proc_handler = proc_dointvec_minmax,
400 .extra1 = &init_net.ieee802154_lowpan.frags.low_thresh
403 }, 401 },
404 { 402 {
405 .procname = "6lowpanfrag_low_thresh", 403 .procname = "6lowpanfrag_low_thresh",
406 .data = &init_net.ieee802154_lowpan.frags.low_thresh, 404 .data = &init_net.ieee802154_lowpan.frags.low_thresh,
407 .maxlen = sizeof(int), 405 .maxlen = sizeof(int),
408 .mode = 0644, 406 .mode = 0644,
409 .proc_handler = proc_dointvec 407 .proc_handler = proc_dointvec_minmax,
408 .extra1 = &zero,
409 .extra2 = &init_net.ieee802154_lowpan.frags.high_thresh
410 }, 410 },
411 { 411 {
412 .procname = "6lowpanfrag_time", 412 .procname = "6lowpanfrag_time",
@@ -415,20 +415,15 @@ static struct ctl_table lowpan_frags_ns_ctl_table[] = {
415 .mode = 0644, 415 .mode = 0644,
416 .proc_handler = proc_dointvec_jiffies, 416 .proc_handler = proc_dointvec_jiffies,
417 }, 417 },
418 {
419 .procname = "6lowpanfrag_max_datagram_size",
420 .data = &init_net.ieee802154_lowpan.max_dsize,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = proc_dointvec
424 },
425 { } 418 { }
426}; 419};
427 420
421/* secret interval has been deprecated */
422static int lowpan_frags_secret_interval_unused;
428static struct ctl_table lowpan_frags_ctl_table[] = { 423static struct ctl_table lowpan_frags_ctl_table[] = {
429 { 424 {
430 .procname = "6lowpanfrag_secret_interval", 425 .procname = "6lowpanfrag_secret_interval",
431 .data = &lowpan_frags.secret_interval, 426 .data = &lowpan_frags_secret_interval_unused,
432 .maxlen = sizeof(int), 427 .maxlen = sizeof(int),
433 .mode = 0644, 428 .mode = 0644,
434 .proc_handler = proc_dointvec_jiffies, 429 .proc_handler = proc_dointvec_jiffies,
@@ -451,9 +446,11 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
451 goto err_alloc; 446 goto err_alloc;
452 447
453 table[0].data = &ieee802154_lowpan->frags.high_thresh; 448 table[0].data = &ieee802154_lowpan->frags.high_thresh;
449 table[0].extra1 = &ieee802154_lowpan->frags.low_thresh;
450 table[0].extra2 = &init_net.ieee802154_lowpan.frags.high_thresh;
454 table[1].data = &ieee802154_lowpan->frags.low_thresh; 451 table[1].data = &ieee802154_lowpan->frags.low_thresh;
452 table[1].extra2 = &ieee802154_lowpan->frags.high_thresh;
455 table[2].data = &ieee802154_lowpan->frags.timeout; 453 table[2].data = &ieee802154_lowpan->frags.timeout;
456 table[3].data = &ieee802154_lowpan->max_dsize;
457 454
458 /* Don't export sysctls to unprivileged users */ 455 /* Don't export sysctls to unprivileged users */
459 if (net->user_ns != &init_user_ns) 456 if (net->user_ns != &init_user_ns)
@@ -528,7 +525,6 @@ static int __net_init lowpan_frags_init_net(struct net *net)
528 ieee802154_lowpan->frags.high_thresh = IPV6_FRAG_HIGH_THRESH; 525 ieee802154_lowpan->frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
529 ieee802154_lowpan->frags.low_thresh = IPV6_FRAG_LOW_THRESH; 526 ieee802154_lowpan->frags.low_thresh = IPV6_FRAG_LOW_THRESH;
530 ieee802154_lowpan->frags.timeout = IPV6_FRAG_TIMEOUT; 527 ieee802154_lowpan->frags.timeout = IPV6_FRAG_TIMEOUT;
531 ieee802154_lowpan->max_dsize = 0xFFFF;
532 528
533 inet_frags_init_net(&ieee802154_lowpan->frags); 529 inet_frags_init_net(&ieee802154_lowpan->frags);
534 530
@@ -568,8 +564,10 @@ int __init lowpan_net_frag_init(void)
568 lowpan_frags.qsize = sizeof(struct frag_queue); 564 lowpan_frags.qsize = sizeof(struct frag_queue);
569 lowpan_frags.match = lowpan_frag_match; 565 lowpan_frags.match = lowpan_frag_match;
570 lowpan_frags.frag_expire = lowpan_frag_expire; 566 lowpan_frags.frag_expire = lowpan_frag_expire;
571 lowpan_frags.secret_interval = 10 * 60 * HZ; 567 lowpan_frags.frags_cache_name = lowpan_frags_cache_name;
572 inet_frags_init(&lowpan_frags); 568 ret = inet_frags_init(&lowpan_frags);
569 if (ret)
570 goto err_pernet;
573 571
574 return ret; 572 return ret;
575err_pernet: 573err_pernet:
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c
index 8d6f6704da84..4955e0fe5883 100644
--- a/net/ieee802154/wpan-class.c
+++ b/net/ieee802154/wpan-class.c
@@ -48,7 +48,8 @@ MASTER_SHOW(transmit_power, "%d +- 1 dB");
48MASTER_SHOW(cca_mode, "%d"); 48MASTER_SHOW(cca_mode, "%d");
49 49
50static ssize_t channels_supported_show(struct device *dev, 50static ssize_t channels_supported_show(struct device *dev,
51 struct device_attribute *attr, char *buf) 51 struct device_attribute *attr,
52 char *buf)
52{ 53{
53 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); 54 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
54 int ret; 55 int ret;
@@ -57,7 +58,7 @@ static ssize_t channels_supported_show(struct device *dev,
57 mutex_lock(&phy->pib_lock); 58 mutex_lock(&phy->pib_lock);
58 for (i = 0; i < 32; i++) { 59 for (i = 0; i < 32; i++) {
59 ret = snprintf(buf + len, PAGE_SIZE - len, 60 ret = snprintf(buf + len, PAGE_SIZE - len,
60 "%#09x\n", phy->channels_supported[i]); 61 "%#09x\n", phy->channels_supported[i]);
61 if (ret < 0) 62 if (ret < 0)
62 break; 63 break;
63 len += ret; 64 len += ret;
@@ -80,6 +81,7 @@ ATTRIBUTE_GROUPS(pmib);
80static void wpan_phy_release(struct device *d) 81static void wpan_phy_release(struct device *d)
81{ 82{
82 struct wpan_phy *phy = container_of(d, struct wpan_phy, dev); 83 struct wpan_phy *phy = container_of(d, struct wpan_phy, dev);
84
83 kfree(phy); 85 kfree(phy);
84} 86}
85 87
@@ -121,11 +123,12 @@ static int wpan_phy_iter(struct device *dev, void *_data)
121{ 123{
122 struct wpan_phy_iter_data *wpid = _data; 124 struct wpan_phy_iter_data *wpid = _data;
123 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); 125 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
126
124 return wpid->fn(phy, wpid->data); 127 return wpid->fn(phy, wpid->data);
125} 128}
126 129
127int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), 130int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
128 void *data) 131 void *data)
129{ 132{
130 struct wpan_phy_iter_data wpid = { 133 struct wpan_phy_iter_data wpid = {
131 .fn = fn, 134 .fn = fn,
@@ -197,6 +200,7 @@ EXPORT_SYMBOL(wpan_phy_free);
197static int __init wpan_phy_class_init(void) 200static int __init wpan_phy_class_init(void)
198{ 201{
199 int rc; 202 int rc;
203
200 rc = class_register(&wpan_phy_class); 204 rc = class_register(&wpan_phy_class);
201 if (rc) 205 if (rc)
202 goto err; 206 goto err;