aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-04-26 13:15:56 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-26 13:15:56 -0400
commitc0b04793076167c8d8aade4c31fe06a4cc45b626 (patch)
treef00ecf6720c7b4c5c742c0080e80a809cf5abffb
parent9c9f261d6e3b1084816e9e2df794a55df16e7387 (diff)
parent55441070ca1cbd47ce1ad2959bbf4b47aed9b83b (diff)
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Johan Hedberg says: ==================== pull request: bluetooth-next 2016-04-26 Here's another set of Bluetooth & 802.15.4 patches for the 4.7 kernel: - Cleanups & refactoring of ieee802154 & 6lowpan code - Security related additions to ieee802154 and mrf24j40 driver - Memory corruption fix to Bluetooth 6lowpan code - Race condition fix in vhci driver - Enhancements to the atusb 802.15.4 driver Please let me know if there are any issues pulling. Thanks. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/bluetooth/ath3k.c6
-rw-r--r--drivers/bluetooth/hci_vhci.c23
-rw-r--r--drivers/net/ieee802154/at86rf230.c6
-rw-r--r--drivers/net/ieee802154/atusb.c91
-rw-r--r--drivers/net/ieee802154/mrf24j40.c14
-rw-r--r--include/linux/ieee802154.h45
-rw-r--r--include/net/6lowpan.h37
-rw-r--r--include/net/bluetooth/hci.h2
-rw-r--r--include/net/mac802154.h10
-rw-r--r--net/6lowpan/6lowpan_i.h9
-rw-r--r--net/6lowpan/core.c8
-rw-r--r--net/6lowpan/debugfs.c22
-rw-r--r--net/6lowpan/iphc.c111
-rw-r--r--net/6lowpan/nhc_udp.c2
-rw-r--r--net/bluetooth/6lowpan.c93
-rw-r--r--net/ieee802154/6lowpan/6lowpan_i.h14
-rw-r--r--net/ieee802154/6lowpan/core.c6
-rw-r--r--net/ieee802154/6lowpan/tx.c14
-rw-r--r--net/ieee802154/nl802154.c10
19 files changed, 356 insertions, 167 deletions
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 47ca4b39d306..641c2d19fc57 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -206,7 +206,8 @@ static int ath3k_load_firmware(struct usb_device *udev,
206 const struct firmware *firmware) 206 const struct firmware *firmware)
207{ 207{
208 u8 *send_buf; 208 u8 *send_buf;
209 int err, pipe, len, size, sent = 0; 209 int len = 0;
210 int err, pipe, size, sent = 0;
210 int count = firmware->size; 211 int count = firmware->size;
211 212
212 BT_DBG("udev %p", udev); 213 BT_DBG("udev %p", udev);
@@ -302,7 +303,8 @@ static int ath3k_load_fwfile(struct usb_device *udev,
302 const struct firmware *firmware) 303 const struct firmware *firmware)
303{ 304{
304 u8 *send_buf; 305 u8 *send_buf;
305 int err, pipe, len, size, count, sent = 0; 306 int len = 0;
307 int err, pipe, size, count, sent = 0;
306 int ret; 308 int ret;
307 309
308 count = firmware->size; 310 count = firmware->size;
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index f67ea1c090cb..aba31210c802 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -50,6 +50,7 @@ struct vhci_data {
50 wait_queue_head_t read_wait; 50 wait_queue_head_t read_wait;
51 struct sk_buff_head readq; 51 struct sk_buff_head readq;
52 52
53 struct mutex open_mutex;
53 struct delayed_work open_timeout; 54 struct delayed_work open_timeout;
54}; 55};
55 56
@@ -87,12 +88,15 @@ static int vhci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
87 return 0; 88 return 0;
88} 89}
89 90
90static int vhci_create_device(struct vhci_data *data, __u8 opcode) 91static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
91{ 92{
92 struct hci_dev *hdev; 93 struct hci_dev *hdev;
93 struct sk_buff *skb; 94 struct sk_buff *skb;
94 __u8 dev_type; 95 __u8 dev_type;
95 96
97 if (data->hdev)
98 return -EBADFD;
99
96 /* bits 0-1 are dev_type (BR/EDR or AMP) */ 100 /* bits 0-1 are dev_type (BR/EDR or AMP) */
97 dev_type = opcode & 0x03; 101 dev_type = opcode & 0x03;
98 102
@@ -151,6 +155,17 @@ static int vhci_create_device(struct vhci_data *data, __u8 opcode)
151 return 0; 155 return 0;
152} 156}
153 157
158static int vhci_create_device(struct vhci_data *data, __u8 opcode)
159{
160 int err;
161
162 mutex_lock(&data->open_mutex);
163 err = __vhci_create_device(data, opcode);
164 mutex_unlock(&data->open_mutex);
165
166 return err;
167}
168
154static inline ssize_t vhci_get_user(struct vhci_data *data, 169static inline ssize_t vhci_get_user(struct vhci_data *data,
155 struct iov_iter *from) 170 struct iov_iter *from)
156{ 171{
@@ -191,11 +206,6 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,
191 case HCI_VENDOR_PKT: 206 case HCI_VENDOR_PKT:
192 cancel_delayed_work_sync(&data->open_timeout); 207 cancel_delayed_work_sync(&data->open_timeout);
193 208
194 if (data->hdev) {
195 kfree_skb(skb);
196 return -EBADFD;
197 }
198
199 opcode = *((__u8 *) skb->data); 209 opcode = *((__u8 *) skb->data);
200 skb_pull(skb, 1); 210 skb_pull(skb, 1);
201 211
@@ -320,6 +330,7 @@ static int vhci_open(struct inode *inode, struct file *file)
320 skb_queue_head_init(&data->readq); 330 skb_queue_head_init(&data->readq);
321 init_waitqueue_head(&data->read_wait); 331 init_waitqueue_head(&data->read_wait);
322 332
333 mutex_init(&data->open_mutex);
323 INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout); 334 INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
324 335
325 file->private_data = data; 336 file->private_data = data;
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index cb9e9fe6d77a..9f10da60e02d 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1340,7 +1340,7 @@ static struct at86rf2xx_chip_data at86rf233_data = {
1340 .t_off_to_aack = 80, 1340 .t_off_to_aack = 80,
1341 .t_off_to_tx_on = 80, 1341 .t_off_to_tx_on = 80,
1342 .t_off_to_sleep = 35, 1342 .t_off_to_sleep = 35,
1343 .t_sleep_to_off = 210, 1343 .t_sleep_to_off = 1000,
1344 .t_frame = 4096, 1344 .t_frame = 4096,
1345 .t_p_ack = 545, 1345 .t_p_ack = 545,
1346 .rssi_base_val = -91, 1346 .rssi_base_val = -91,
@@ -1355,7 +1355,7 @@ static struct at86rf2xx_chip_data at86rf231_data = {
1355 .t_off_to_aack = 110, 1355 .t_off_to_aack = 110,
1356 .t_off_to_tx_on = 110, 1356 .t_off_to_tx_on = 110,
1357 .t_off_to_sleep = 35, 1357 .t_off_to_sleep = 35,
1358 .t_sleep_to_off = 380, 1358 .t_sleep_to_off = 1000,
1359 .t_frame = 4096, 1359 .t_frame = 4096,
1360 .t_p_ack = 545, 1360 .t_p_ack = 545,
1361 .rssi_base_val = -91, 1361 .rssi_base_val = -91,
@@ -1370,7 +1370,7 @@ static struct at86rf2xx_chip_data at86rf212_data = {
1370 .t_off_to_aack = 200, 1370 .t_off_to_aack = 200,
1371 .t_off_to_tx_on = 200, 1371 .t_off_to_tx_on = 200,
1372 .t_off_to_sleep = 35, 1372 .t_off_to_sleep = 35,
1373 .t_sleep_to_off = 380, 1373 .t_sleep_to_off = 1000,
1374 .t_frame = 4096, 1374 .t_frame = 4096,
1375 .t_p_ack = 545, 1375 .t_p_ack = 545,
1376 .rssi_base_val = -100, 1376 .rssi_base_val = -100,
diff --git a/drivers/net/ieee802154/atusb.c b/drivers/net/ieee802154/atusb.c
index b1cd865ade2e..52c9051f3b95 100644
--- a/drivers/net/ieee802154/atusb.c
+++ b/drivers/net/ieee802154/atusb.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Written 2013 by Werner Almesberger <werner@almesberger.net> 4 * Written 2013 by Werner Almesberger <werner@almesberger.net>
5 * 5 *
6 * Copyright (c) 2015 - 2016 Stefan Schmidt <stefan@datenfreihafen.org>
7 *
6 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 10 * published by the Free Software Foundation, version 2
@@ -472,6 +474,76 @@ atusb_set_txpower(struct ieee802154_hw *hw, s32 mbm)
472 return -EINVAL; 474 return -EINVAL;
473} 475}
474 476
477#define ATUSB_MAX_ED_LEVELS 0xF
478static const s32 atusb_ed_levels[ATUSB_MAX_ED_LEVELS + 1] = {
479 -9100, -8900, -8700, -8500, -8300, -8100, -7900, -7700, -7500, -7300,
480 -7100, -6900, -6700, -6500, -6300, -6100,
481};
482
483static int
484atusb_set_cca_mode(struct ieee802154_hw *hw, const struct wpan_phy_cca *cca)
485{
486 struct atusb *atusb = hw->priv;
487 u8 val;
488
489 /* mapping 802.15.4 to driver spec */
490 switch (cca->mode) {
491 case NL802154_CCA_ENERGY:
492 val = 1;
493 break;
494 case NL802154_CCA_CARRIER:
495 val = 2;
496 break;
497 case NL802154_CCA_ENERGY_CARRIER:
498 switch (cca->opt) {
499 case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
500 val = 3;
501 break;
502 case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
503 val = 0;
504 break;
505 default:
506 return -EINVAL;
507 }
508 break;
509 default:
510 return -EINVAL;
511 }
512
513 return atusb_write_subreg(atusb, SR_CCA_MODE, val);
514}
515
516static int
517atusb_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
518{
519 struct atusb *atusb = hw->priv;
520 u32 i;
521
522 for (i = 0; i < hw->phy->supported.cca_ed_levels_size; i++) {
523 if (hw->phy->supported.cca_ed_levels[i] == mbm)
524 return atusb_write_subreg(atusb, SR_CCA_ED_THRES, i);
525 }
526
527 return -EINVAL;
528}
529
530static int
531atusb_set_csma_params(struct ieee802154_hw *hw, u8 min_be, u8 max_be, u8 retries)
532{
533 struct atusb *atusb = hw->priv;
534 int ret;
535
536 ret = atusb_write_subreg(atusb, SR_MIN_BE, min_be);
537 if (ret)
538 return ret;
539
540 ret = atusb_write_subreg(atusb, SR_MAX_BE, max_be);
541 if (ret)
542 return ret;
543
544 return atusb_write_subreg(atusb, SR_MAX_CSMA_RETRIES, retries);
545}
546
475static int 547static int
476atusb_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on) 548atusb_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
477{ 549{
@@ -508,6 +580,9 @@ static struct ieee802154_ops atusb_ops = {
508 .stop = atusb_stop, 580 .stop = atusb_stop,
509 .set_hw_addr_filt = atusb_set_hw_addr_filt, 581 .set_hw_addr_filt = atusb_set_hw_addr_filt,
510 .set_txpower = atusb_set_txpower, 582 .set_txpower = atusb_set_txpower,
583 .set_cca_mode = atusb_set_cca_mode,
584 .set_cca_ed_level = atusb_set_cca_ed_level,
585 .set_csma_params = atusb_set_csma_params,
511 .set_promiscuous_mode = atusb_set_promiscuous_mode, 586 .set_promiscuous_mode = atusb_set_promiscuous_mode,
512}; 587};
513 588
@@ -636,9 +711,20 @@ static int atusb_probe(struct usb_interface *interface,
636 711
637 hw->parent = &usb_dev->dev; 712 hw->parent = &usb_dev->dev;
638 hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT | 713 hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT |
639 IEEE802154_HW_PROMISCUOUS; 714 IEEE802154_HW_PROMISCUOUS | IEEE802154_HW_CSMA_PARAMS;
715
716 hw->phy->flags = WPAN_PHY_FLAG_TXPOWER | WPAN_PHY_FLAG_CCA_ED_LEVEL |
717 WPAN_PHY_FLAG_CCA_MODE;
718
719 hw->phy->supported.cca_modes = BIT(NL802154_CCA_ENERGY) |
720 BIT(NL802154_CCA_CARRIER) | BIT(NL802154_CCA_ENERGY_CARRIER);
721 hw->phy->supported.cca_opts = BIT(NL802154_CCA_OPT_ENERGY_CARRIER_AND) |
722 BIT(NL802154_CCA_OPT_ENERGY_CARRIER_OR);
723
724 hw->phy->supported.cca_ed_levels = atusb_ed_levels;
725 hw->phy->supported.cca_ed_levels_size = ARRAY_SIZE(atusb_ed_levels);
640 726
641 hw->phy->flags = WPAN_PHY_FLAG_TXPOWER; 727 hw->phy->cca.mode = NL802154_CCA_ENERGY;
642 728
643 hw->phy->current_page = 0; 729 hw->phy->current_page = 0;
644 hw->phy->current_channel = 11; /* reset default */ 730 hw->phy->current_channel = 11; /* reset default */
@@ -647,6 +733,7 @@ static int atusb_probe(struct usb_interface *interface,
647 hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers); 733 hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers);
648 hw->phy->transmit_power = hw->phy->supported.tx_powers[0]; 734 hw->phy->transmit_power = hw->phy->supported.tx_powers[0];
649 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); 735 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
736 hw->phy->cca_ed_level = hw->phy->supported.cca_ed_levels[7];
650 737
651 atusb_command(atusb, ATUSB_RF_RESET, 0); 738 atusb_command(atusb, ATUSB_RF_RESET, 0);
652 atusb_get_and_show_chip(atusb); 739 atusb_get_and_show_chip(atusb);
diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index 764a2bddfaee..f446db828561 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -61,6 +61,7 @@
61#define REG_TXBCON0 0x1A 61#define REG_TXBCON0 0x1A
62#define REG_TXNCON 0x1B /* Transmit Normal FIFO Control */ 62#define REG_TXNCON 0x1B /* Transmit Normal FIFO Control */
63#define BIT_TXNTRIG BIT(0) 63#define BIT_TXNTRIG BIT(0)
64#define BIT_TXNSECEN BIT(1)
64#define BIT_TXNACKREQ BIT(2) 65#define BIT_TXNACKREQ BIT(2)
65 66
66#define REG_TXG1CON 0x1C 67#define REG_TXG1CON 0x1C
@@ -85,10 +86,13 @@
85#define REG_INTSTAT 0x31 /* Interrupt Status */ 86#define REG_INTSTAT 0x31 /* Interrupt Status */
86#define BIT_TXNIF BIT(0) 87#define BIT_TXNIF BIT(0)
87#define BIT_RXIF BIT(3) 88#define BIT_RXIF BIT(3)
89#define BIT_SECIF BIT(4)
90#define BIT_SECIGNORE BIT(7)
88 91
89#define REG_INTCON 0x32 /* Interrupt Control */ 92#define REG_INTCON 0x32 /* Interrupt Control */
90#define BIT_TXNIE BIT(0) 93#define BIT_TXNIE BIT(0)
91#define BIT_RXIE BIT(3) 94#define BIT_RXIE BIT(3)
95#define BIT_SECIE BIT(4)
92 96
93#define REG_GPIO 0x33 /* GPIO */ 97#define REG_GPIO 0x33 /* GPIO */
94#define REG_TRISGPIO 0x34 /* GPIO direction */ 98#define REG_TRISGPIO 0x34 /* GPIO direction */
@@ -548,6 +552,9 @@ static void write_tx_buf_complete(void *context)
548 u8 val = BIT_TXNTRIG; 552 u8 val = BIT_TXNTRIG;
549 int ret; 553 int ret;
550 554
555 if (ieee802154_is_secen(fc))
556 val |= BIT_TXNSECEN;
557
551 if (ieee802154_is_ackreq(fc)) 558 if (ieee802154_is_ackreq(fc))
552 val |= BIT_TXNACKREQ; 559 val |= BIT_TXNACKREQ;
553 560
@@ -616,7 +623,7 @@ static int mrf24j40_start(struct ieee802154_hw *hw)
616 623
617 /* Clear TXNIE and RXIE. Enable interrupts */ 624 /* Clear TXNIE and RXIE. Enable interrupts */
618 return regmap_update_bits(devrec->regmap_short, REG_INTCON, 625 return regmap_update_bits(devrec->regmap_short, REG_INTCON,
619 BIT_TXNIE | BIT_RXIE, 0); 626 BIT_TXNIE | BIT_RXIE | BIT_SECIE, 0);
620} 627}
621 628
622static void mrf24j40_stop(struct ieee802154_hw *hw) 629static void mrf24j40_stop(struct ieee802154_hw *hw)
@@ -1025,6 +1032,11 @@ static void mrf24j40_intstat_complete(void *context)
1025 1032
1026 enable_irq(devrec->spi->irq); 1033 enable_irq(devrec->spi->irq);
1027 1034
1035 /* Ignore Rx security decryption */
1036 if (intstat & BIT_SECIF)
1037 regmap_write_async(devrec->regmap_short, REG_SECCON0,
1038 BIT_SECIGNORE);
1039
1028 /* Check for TX complete */ 1040 /* Check for TX complete */
1029 if (intstat & BIT_TXNIF) 1041 if (intstat & BIT_TXNIF)
1030 ieee802154_xmit_complete(devrec->hw, devrec->tx_skb, false); 1042 ieee802154_xmit_complete(devrec->hw, devrec->tx_skb, false);
diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
index d3e415674dac..acedbb68a5a3 100644
--- a/include/linux/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -47,6 +47,7 @@
47#define IEEE802154_ADDR_SHORT_UNSPEC 0xfffe 47#define IEEE802154_ADDR_SHORT_UNSPEC 0xfffe
48 48
49#define IEEE802154_EXTENDED_ADDR_LEN 8 49#define IEEE802154_EXTENDED_ADDR_LEN 8
50#define IEEE802154_SHORT_ADDR_LEN 2
50 51
51#define IEEE802154_LIFS_PERIOD 40 52#define IEEE802154_LIFS_PERIOD 40
52#define IEEE802154_SIFS_PERIOD 12 53#define IEEE802154_SIFS_PERIOD 12
@@ -218,6 +219,7 @@ enum {
218/* frame control handling */ 219/* frame control handling */
219#define IEEE802154_FCTL_FTYPE 0x0003 220#define IEEE802154_FCTL_FTYPE 0x0003
220#define IEEE802154_FCTL_ACKREQ 0x0020 221#define IEEE802154_FCTL_ACKREQ 0x0020
222#define IEEE802154_FCTL_SECEN 0x0004
221#define IEEE802154_FCTL_INTRA_PAN 0x0040 223#define IEEE802154_FCTL_INTRA_PAN 0x0040
222 224
223#define IEEE802154_FTYPE_DATA 0x0001 225#define IEEE802154_FTYPE_DATA 0x0001
@@ -233,6 +235,15 @@ static inline int ieee802154_is_data(__le16 fc)
233} 235}
234 236
235/** 237/**
238 * ieee802154_is_secen - check if Security bit is set
239 * @fc: frame control bytes in little-endian byteorder
240 */
241static inline bool ieee802154_is_secen(__le16 fc)
242{
243 return fc & cpu_to_le16(IEEE802154_FCTL_SECEN);
244}
245
246/**
236 * ieee802154_is_ackreq - check if acknowledgment request bit is set 247 * ieee802154_is_ackreq - check if acknowledgment request bit is set
237 * @fc: frame control bytes in little-endian byteorder 248 * @fc: frame control bytes in little-endian byteorder
238 */ 249 */
@@ -260,17 +271,17 @@ static inline bool ieee802154_is_intra_pan(__le16 fc)
260 * 271 *
261 * @len: psdu len with (MHR + payload + MFR) 272 * @len: psdu len with (MHR + payload + MFR)
262 */ 273 */
263static inline bool ieee802154_is_valid_psdu_len(const u8 len) 274static inline bool ieee802154_is_valid_psdu_len(u8 len)
264{ 275{
265 return (len == IEEE802154_ACK_PSDU_LEN || 276 return (len == IEEE802154_ACK_PSDU_LEN ||
266 (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU)); 277 (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU));
267} 278}
268 279
269/** 280/**
270 * ieee802154_is_valid_psdu_len - check if extended addr is valid 281 * ieee802154_is_valid_extended_unicast_addr - check if extended addr is valid
271 * @addr: extended addr to check 282 * @addr: extended addr to check
272 */ 283 */
273static inline bool ieee802154_is_valid_extended_unicast_addr(const __le64 addr) 284static inline bool ieee802154_is_valid_extended_unicast_addr(__le64 addr)
274{ 285{
275 /* Bail out if the address is all zero, or if the group 286 /* Bail out if the address is all zero, or if the group
276 * address bit is set. 287 * address bit is set.
@@ -280,6 +291,34 @@ static inline bool ieee802154_is_valid_extended_unicast_addr(const __le64 addr)
280} 291}
281 292
282/** 293/**
294 * ieee802154_is_broadcast_short_addr - check if short addr is broadcast
295 * @addr: short addr to check
296 */
297static inline bool ieee802154_is_broadcast_short_addr(__le16 addr)
298{
299 return (addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST));
300}
301
302/**
303 * ieee802154_is_unspec_short_addr - check if short addr is unspecified
304 * @addr: short addr to check
305 */
306static inline bool ieee802154_is_unspec_short_addr(__le16 addr)
307{
308 return (addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC));
309}
310
311/**
312 * ieee802154_is_valid_src_short_addr - check if source short address is valid
313 * @addr: short addr to check
314 */
315static inline bool ieee802154_is_valid_src_short_addr(__le16 addr)
316{
317 return !(ieee802154_is_broadcast_short_addr(addr) ||
318 ieee802154_is_unspec_short_addr(addr));
319}
320
321/**
283 * ieee802154_random_extended_addr - generates a random extended address 322 * ieee802154_random_extended_addr - generates a random extended address
284 * @addr: extended addr pointer to place the random address 323 * @addr: extended addr pointer to place the random address
285 */ 324 */
diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h
index da3a77d25fcb..da84cf920b78 100644
--- a/include/net/6lowpan.h
+++ b/include/net/6lowpan.h
@@ -58,6 +58,9 @@
58#include <net/ipv6.h> 58#include <net/ipv6.h>
59#include <net/net_namespace.h> 59#include <net/net_namespace.h>
60 60
61/* special link-layer handling */
62#include <net/mac802154.h>
63
61#define EUI64_ADDR_LEN 8 64#define EUI64_ADDR_LEN 8
62 65
63#define LOWPAN_NHC_MAX_ID_LEN 1 66#define LOWPAN_NHC_MAX_ID_LEN 1
@@ -93,7 +96,7 @@ static inline bool lowpan_is_iphc(u8 dispatch)
93} 96}
94 97
95#define LOWPAN_PRIV_SIZE(llpriv_size) \ 98#define LOWPAN_PRIV_SIZE(llpriv_size) \
96 (sizeof(struct lowpan_priv) + llpriv_size) 99 (sizeof(struct lowpan_dev) + llpriv_size)
97 100
98enum lowpan_lltypes { 101enum lowpan_lltypes {
99 LOWPAN_LLTYPE_BTLE, 102 LOWPAN_LLTYPE_BTLE,
@@ -129,7 +132,7 @@ lowpan_iphc_ctx_is_compression(const struct lowpan_iphc_ctx *ctx)
129 return test_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags); 132 return test_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags);
130} 133}
131 134
132struct lowpan_priv { 135struct lowpan_dev {
133 enum lowpan_lltypes lltype; 136 enum lowpan_lltypes lltype;
134 struct dentry *iface_debugfs; 137 struct dentry *iface_debugfs;
135 struct lowpan_iphc_ctx_table ctx; 138 struct lowpan_iphc_ctx_table ctx;
@@ -139,11 +142,23 @@ struct lowpan_priv {
139}; 142};
140 143
141static inline 144static inline
142struct lowpan_priv *lowpan_priv(const struct net_device *dev) 145struct lowpan_dev *lowpan_dev(const struct net_device *dev)
143{ 146{
144 return netdev_priv(dev); 147 return netdev_priv(dev);
145} 148}
146 149
150/* private device info */
151struct lowpan_802154_dev {
152 struct net_device *wdev; /* wpan device ptr */
153 u16 fragment_tag;
154};
155
156static inline struct
157lowpan_802154_dev *lowpan_802154_dev(const struct net_device *dev)
158{
159 return (struct lowpan_802154_dev *)lowpan_dev(dev)->priv;
160}
161
147struct lowpan_802154_cb { 162struct lowpan_802154_cb {
148 u16 d_tag; 163 u16 d_tag;
149 unsigned int d_size; 164 unsigned int d_size;
@@ -157,6 +172,22 @@ struct lowpan_802154_cb *lowpan_802154_cb(const struct sk_buff *skb)
157 return (struct lowpan_802154_cb *)skb->cb; 172 return (struct lowpan_802154_cb *)skb->cb;
158} 173}
159 174
175static inline void lowpan_iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr,
176 const void *lladdr)
177{
178 /* fe:80::XXXX:XXXX:XXXX:XXXX
179 * \_________________/
180 * hwaddr
181 */
182 ipaddr->s6_addr[0] = 0xFE;
183 ipaddr->s6_addr[1] = 0x80;
184 memcpy(&ipaddr->s6_addr[8], lladdr, EUI64_ADDR_LEN);
185 /* second bit-flip (Universe/Local)
186 * is done according RFC2464
187 */
188 ipaddr->s6_addr[8] ^= 0x02;
189}
190
160#ifdef DEBUG 191#ifdef DEBUG
161/* print data in line */ 192/* print data in line */
162static inline void raw_dump_inline(const char *caller, char *msg, 193static inline void raw_dump_inline(const char *caller, char *msg,
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 5d38d980b89d..eefcf3e96421 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -61,6 +61,8 @@
61#define HCI_RS232 4 61#define HCI_RS232 4
62#define HCI_PCI 5 62#define HCI_PCI 5
63#define HCI_SDIO 6 63#define HCI_SDIO 6
64#define HCI_SPI 7
65#define HCI_I2C 8
64 66
65/* HCI controller types */ 67/* HCI controller types */
66#define HCI_BREDR 0x00 68#define HCI_BREDR 0x00
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 6cd7a70706a9..e465c8551ac3 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -288,6 +288,16 @@ static inline void ieee802154_le16_to_be16(void *be16_dst, const void *le16_src)
288} 288}
289 289
290/** 290/**
291 * ieee802154_be16_to_le16 - copies and convert be16 to le16
292 * @le16_dst: le16 destination pointer
293 * @be16_src: be16 source pointer
294 */
295static inline void ieee802154_be16_to_le16(void *le16_dst, const void *be16_src)
296{
297 put_unaligned_le16(get_unaligned_be16(be16_src), le16_dst);
298}
299
300/**
291 * ieee802154_alloc_hw - Allocate a new hardware device 301 * ieee802154_alloc_hw - Allocate a new hardware device
292 * 302 *
293 * This must be called once for each hardware device. The returned pointer 303 * This must be called once for each hardware device. The returned pointer
diff --git a/net/6lowpan/6lowpan_i.h b/net/6lowpan/6lowpan_i.h
index d16bb4b14aa1..97ecc27aeca6 100644
--- a/net/6lowpan/6lowpan_i.h
+++ b/net/6lowpan/6lowpan_i.h
@@ -3,6 +3,15 @@
3 3
4#include <linux/netdevice.h> 4#include <linux/netdevice.h>
5 5
6#include <net/6lowpan.h>
7
8/* caller need to be sure it's dev->type is ARPHRD_6LOWPAN */
9static inline bool lowpan_is_ll(const struct net_device *dev,
10 enum lowpan_lltypes lltype)
11{
12 return lowpan_dev(dev)->lltype == lltype;
13}
14
6#ifdef CONFIG_6LOWPAN_DEBUGFS 15#ifdef CONFIG_6LOWPAN_DEBUGFS
7int lowpan_dev_debugfs_init(struct net_device *dev); 16int lowpan_dev_debugfs_init(struct net_device *dev);
8void lowpan_dev_debugfs_exit(struct net_device *dev); 17void lowpan_dev_debugfs_exit(struct net_device *dev);
diff --git a/net/6lowpan/core.c b/net/6lowpan/core.c
index 34e44c0c0836..7a240b3eaed1 100644
--- a/net/6lowpan/core.c
+++ b/net/6lowpan/core.c
@@ -27,11 +27,11 @@ int lowpan_register_netdevice(struct net_device *dev,
27 dev->mtu = IPV6_MIN_MTU; 27 dev->mtu = IPV6_MIN_MTU;
28 dev->priv_flags |= IFF_NO_QUEUE; 28 dev->priv_flags |= IFF_NO_QUEUE;
29 29
30 lowpan_priv(dev)->lltype = lltype; 30 lowpan_dev(dev)->lltype = lltype;
31 31
32 spin_lock_init(&lowpan_priv(dev)->ctx.lock); 32 spin_lock_init(&lowpan_dev(dev)->ctx.lock);
33 for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) 33 for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++)
34 lowpan_priv(dev)->ctx.table[i].id = i; 34 lowpan_dev(dev)->ctx.table[i].id = i;
35 35
36 ret = register_netdevice(dev); 36 ret = register_netdevice(dev);
37 if (ret < 0) 37 if (ret < 0)
@@ -85,7 +85,7 @@ static int lowpan_event(struct notifier_block *unused,
85 case NETDEV_DOWN: 85 case NETDEV_DOWN:
86 for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) 86 for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++)
87 clear_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, 87 clear_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE,
88 &lowpan_priv(dev)->ctx.table[i].flags); 88 &lowpan_dev(dev)->ctx.table[i].flags);
89 break; 89 break;
90 default: 90 default:
91 return NOTIFY_DONE; 91 return NOTIFY_DONE;
diff --git a/net/6lowpan/debugfs.c b/net/6lowpan/debugfs.c
index 0793a8157472..acbaa3db493b 100644
--- a/net/6lowpan/debugfs.c
+++ b/net/6lowpan/debugfs.c
@@ -172,7 +172,7 @@ static const struct file_operations lowpan_ctx_pfx_fops = {
172static int lowpan_dev_debugfs_ctx_init(struct net_device *dev, 172static int lowpan_dev_debugfs_ctx_init(struct net_device *dev,
173 struct dentry *ctx, u8 id) 173 struct dentry *ctx, u8 id)
174{ 174{
175 struct lowpan_priv *lpriv = lowpan_priv(dev); 175 struct lowpan_dev *ldev = lowpan_dev(dev);
176 struct dentry *dentry, *root; 176 struct dentry *dentry, *root;
177 char buf[32]; 177 char buf[32];
178 178
@@ -185,25 +185,25 @@ static int lowpan_dev_debugfs_ctx_init(struct net_device *dev,
185 return -EINVAL; 185 return -EINVAL;
186 186
187 dentry = debugfs_create_file("active", 0644, root, 187 dentry = debugfs_create_file("active", 0644, root,
188 &lpriv->ctx.table[id], 188 &ldev->ctx.table[id],
189 &lowpan_ctx_flag_active_fops); 189 &lowpan_ctx_flag_active_fops);
190 if (!dentry) 190 if (!dentry)
191 return -EINVAL; 191 return -EINVAL;
192 192
193 dentry = debugfs_create_file("compression", 0644, root, 193 dentry = debugfs_create_file("compression", 0644, root,
194 &lpriv->ctx.table[id], 194 &ldev->ctx.table[id],
195 &lowpan_ctx_flag_c_fops); 195 &lowpan_ctx_flag_c_fops);
196 if (!dentry) 196 if (!dentry)
197 return -EINVAL; 197 return -EINVAL;
198 198
199 dentry = debugfs_create_file("prefix", 0644, root, 199 dentry = debugfs_create_file("prefix", 0644, root,
200 &lpriv->ctx.table[id], 200 &ldev->ctx.table[id],
201 &lowpan_ctx_pfx_fops); 201 &lowpan_ctx_pfx_fops);
202 if (!dentry) 202 if (!dentry)
203 return -EINVAL; 203 return -EINVAL;
204 204
205 dentry = debugfs_create_file("prefix_len", 0644, root, 205 dentry = debugfs_create_file("prefix_len", 0644, root,
206 &lpriv->ctx.table[id], 206 &ldev->ctx.table[id],
207 &lowpan_ctx_plen_fops); 207 &lowpan_ctx_plen_fops);
208 if (!dentry) 208 if (!dentry)
209 return -EINVAL; 209 return -EINVAL;
@@ -247,21 +247,21 @@ static const struct file_operations lowpan_context_fops = {
247 247
248int lowpan_dev_debugfs_init(struct net_device *dev) 248int lowpan_dev_debugfs_init(struct net_device *dev)
249{ 249{
250 struct lowpan_priv *lpriv = lowpan_priv(dev); 250 struct lowpan_dev *ldev = lowpan_dev(dev);
251 struct dentry *contexts, *dentry; 251 struct dentry *contexts, *dentry;
252 int ret, i; 252 int ret, i;
253 253
254 /* creating the root */ 254 /* creating the root */
255 lpriv->iface_debugfs = debugfs_create_dir(dev->name, lowpan_debugfs); 255 ldev->iface_debugfs = debugfs_create_dir(dev->name, lowpan_debugfs);
256 if (!lpriv->iface_debugfs) 256 if (!ldev->iface_debugfs)
257 goto fail; 257 goto fail;
258 258
259 contexts = debugfs_create_dir("contexts", lpriv->iface_debugfs); 259 contexts = debugfs_create_dir("contexts", ldev->iface_debugfs);
260 if (!contexts) 260 if (!contexts)
261 goto remove_root; 261 goto remove_root;
262 262
263 dentry = debugfs_create_file("show", 0644, contexts, 263 dentry = debugfs_create_file("show", 0644, contexts,
264 &lowpan_priv(dev)->ctx, 264 &lowpan_dev(dev)->ctx,
265 &lowpan_context_fops); 265 &lowpan_context_fops);
266 if (!dentry) 266 if (!dentry)
267 goto remove_root; 267 goto remove_root;
@@ -282,7 +282,7 @@ fail:
282 282
283void lowpan_dev_debugfs_exit(struct net_device *dev) 283void lowpan_dev_debugfs_exit(struct net_device *dev)
284{ 284{
285 debugfs_remove_recursive(lowpan_priv(dev)->iface_debugfs); 285 debugfs_remove_recursive(lowpan_dev(dev)->iface_debugfs);
286} 286}
287 287
288int __init lowpan_debugfs_init(void) 288int __init lowpan_debugfs_init(void)
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index 68c80f3c9add..8501dd532fe1 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -53,9 +53,6 @@
53#include <net/6lowpan.h> 53#include <net/6lowpan.h>
54#include <net/ipv6.h> 54#include <net/ipv6.h>
55 55
56/* special link-layer handling */
57#include <net/mac802154.h>
58
59#include "6lowpan_i.h" 56#include "6lowpan_i.h"
60#include "nhc.h" 57#include "nhc.h"
61 58
@@ -156,32 +153,17 @@
156#define LOWPAN_IPHC_CID_DCI(cid) (cid & 0x0f) 153#define LOWPAN_IPHC_CID_DCI(cid) (cid & 0x0f)
157#define LOWPAN_IPHC_CID_SCI(cid) ((cid & 0xf0) >> 4) 154#define LOWPAN_IPHC_CID_SCI(cid) ((cid & 0xf0) >> 4)
158 155
159static inline void iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr, 156static inline void
160 const void *lladdr) 157lowpan_iphc_uncompress_802154_lladdr(struct in6_addr *ipaddr,
161{ 158 const void *lladdr)
162 /* fe:80::XXXX:XXXX:XXXX:XXXX
163 * \_________________/
164 * hwaddr
165 */
166 ipaddr->s6_addr[0] = 0xFE;
167 ipaddr->s6_addr[1] = 0x80;
168 memcpy(&ipaddr->s6_addr[8], lladdr, EUI64_ADDR_LEN);
169 /* second bit-flip (Universe/Local)
170 * is done according RFC2464
171 */
172 ipaddr->s6_addr[8] ^= 0x02;
173}
174
175static inline void iphc_uncompress_802154_lladdr(struct in6_addr *ipaddr,
176 const void *lladdr)
177{ 159{
178 const struct ieee802154_addr *addr = lladdr; 160 const struct ieee802154_addr *addr = lladdr;
179 u8 eui64[EUI64_ADDR_LEN] = { }; 161 u8 eui64[EUI64_ADDR_LEN];
180 162
181 switch (addr->mode) { 163 switch (addr->mode) {
182 case IEEE802154_ADDR_LONG: 164 case IEEE802154_ADDR_LONG:
183 ieee802154_le64_to_be64(eui64, &addr->extended_addr); 165 ieee802154_le64_to_be64(eui64, &addr->extended_addr);
184 iphc_uncompress_eui64_lladdr(ipaddr, eui64); 166 lowpan_iphc_uncompress_eui64_lladdr(ipaddr, eui64);
185 break; 167 break;
186 case IEEE802154_ADDR_SHORT: 168 case IEEE802154_ADDR_SHORT:
187 /* fe:80::ff:fe00:XXXX 169 /* fe:80::ff:fe00:XXXX
@@ -207,7 +189,7 @@ static inline void iphc_uncompress_802154_lladdr(struct in6_addr *ipaddr,
207static struct lowpan_iphc_ctx * 189static struct lowpan_iphc_ctx *
208lowpan_iphc_ctx_get_by_id(const struct net_device *dev, u8 id) 190lowpan_iphc_ctx_get_by_id(const struct net_device *dev, u8 id)
209{ 191{
210 struct lowpan_iphc_ctx *ret = &lowpan_priv(dev)->ctx.table[id]; 192 struct lowpan_iphc_ctx *ret = &lowpan_dev(dev)->ctx.table[id];
211 193
212 if (!lowpan_iphc_ctx_is_active(ret)) 194 if (!lowpan_iphc_ctx_is_active(ret))
213 return NULL; 195 return NULL;
@@ -219,7 +201,7 @@ static struct lowpan_iphc_ctx *
219lowpan_iphc_ctx_get_by_addr(const struct net_device *dev, 201lowpan_iphc_ctx_get_by_addr(const struct net_device *dev,
220 const struct in6_addr *addr) 202 const struct in6_addr *addr)
221{ 203{
222 struct lowpan_iphc_ctx *table = lowpan_priv(dev)->ctx.table; 204 struct lowpan_iphc_ctx *table = lowpan_dev(dev)->ctx.table;
223 struct lowpan_iphc_ctx *ret = NULL; 205 struct lowpan_iphc_ctx *ret = NULL;
224 struct in6_addr addr_pfx; 206 struct in6_addr addr_pfx;
225 u8 addr_plen; 207 u8 addr_plen;
@@ -263,7 +245,7 @@ static struct lowpan_iphc_ctx *
263lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev, 245lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev,
264 const struct in6_addr *addr) 246 const struct in6_addr *addr)
265{ 247{
266 struct lowpan_iphc_ctx *table = lowpan_priv(dev)->ctx.table; 248 struct lowpan_iphc_ctx *table = lowpan_dev(dev)->ctx.table;
267 struct lowpan_iphc_ctx *ret = NULL; 249 struct lowpan_iphc_ctx *ret = NULL;
268 struct in6_addr addr_mcast, network_pfx = {}; 250 struct in6_addr addr_mcast, network_pfx = {};
269 int i; 251 int i;
@@ -301,9 +283,10 @@ lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev,
301 * 283 *
302 * address_mode is the masked value for sam or dam value 284 * address_mode is the masked value for sam or dam value
303 */ 285 */
304static int uncompress_addr(struct sk_buff *skb, const struct net_device *dev, 286static int lowpan_iphc_uncompress_addr(struct sk_buff *skb,
305 struct in6_addr *ipaddr, u8 address_mode, 287 const struct net_device *dev,
306 const void *lladdr) 288 struct in6_addr *ipaddr,
289 u8 address_mode, const void *lladdr)
307{ 290{
308 bool fail; 291 bool fail;
309 292
@@ -332,12 +315,12 @@ static int uncompress_addr(struct sk_buff *skb, const struct net_device *dev,
332 case LOWPAN_IPHC_SAM_11: 315 case LOWPAN_IPHC_SAM_11:
333 case LOWPAN_IPHC_DAM_11: 316 case LOWPAN_IPHC_DAM_11:
334 fail = false; 317 fail = false;
335 switch (lowpan_priv(dev)->lltype) { 318 switch (lowpan_dev(dev)->lltype) {
336 case LOWPAN_LLTYPE_IEEE802154: 319 case LOWPAN_LLTYPE_IEEE802154:
337 iphc_uncompress_802154_lladdr(ipaddr, lladdr); 320 lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
338 break; 321 break;
339 default: 322 default:
340 iphc_uncompress_eui64_lladdr(ipaddr, lladdr); 323 lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
341 break; 324 break;
342 } 325 }
343 break; 326 break;
@@ -360,11 +343,11 @@ static int uncompress_addr(struct sk_buff *skb, const struct net_device *dev,
360/* Uncompress address function for source context 343/* Uncompress address function for source context
361 * based address(non-multicast). 344 * based address(non-multicast).
362 */ 345 */
363static int uncompress_ctx_addr(struct sk_buff *skb, 346static int lowpan_iphc_uncompress_ctx_addr(struct sk_buff *skb,
364 const struct net_device *dev, 347 const struct net_device *dev,
365 const struct lowpan_iphc_ctx *ctx, 348 const struct lowpan_iphc_ctx *ctx,
366 struct in6_addr *ipaddr, u8 address_mode, 349 struct in6_addr *ipaddr,
367 const void *lladdr) 350 u8 address_mode, const void *lladdr)
368{ 351{
369 bool fail; 352 bool fail;
370 353
@@ -393,12 +376,12 @@ static int uncompress_ctx_addr(struct sk_buff *skb,
393 case LOWPAN_IPHC_SAM_11: 376 case LOWPAN_IPHC_SAM_11:
394 case LOWPAN_IPHC_DAM_11: 377 case LOWPAN_IPHC_DAM_11:
395 fail = false; 378 fail = false;
396 switch (lowpan_priv(dev)->lltype) { 379 switch (lowpan_dev(dev)->lltype) {
397 case LOWPAN_LLTYPE_IEEE802154: 380 case LOWPAN_LLTYPE_IEEE802154:
398 iphc_uncompress_802154_lladdr(ipaddr, lladdr); 381 lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
399 break; 382 break;
400 default: 383 default:
401 iphc_uncompress_eui64_lladdr(ipaddr, lladdr); 384 lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
402 break; 385 break;
403 } 386 }
404 ipv6_addr_prefix_copy(ipaddr, &ctx->pfx, ctx->plen); 387 ipv6_addr_prefix_copy(ipaddr, &ctx->pfx, ctx->plen);
@@ -657,22 +640,24 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
657 } 640 }
658 641
659 if (iphc1 & LOWPAN_IPHC_SAC) { 642 if (iphc1 & LOWPAN_IPHC_SAC) {
660 spin_lock_bh(&lowpan_priv(dev)->ctx.lock); 643 spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
661 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_SCI(cid)); 644 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_SCI(cid));
662 if (!ci) { 645 if (!ci) {
663 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 646 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
664 return -EINVAL; 647 return -EINVAL;
665 } 648 }
666 649
667 pr_debug("SAC bit is set. Handle context based source address.\n"); 650 pr_debug("SAC bit is set. Handle context based source address.\n");
668 err = uncompress_ctx_addr(skb, dev, ci, &hdr.saddr, 651 err = lowpan_iphc_uncompress_ctx_addr(skb, dev, ci, &hdr.saddr,
669 iphc1 & LOWPAN_IPHC_SAM_MASK, saddr); 652 iphc1 & LOWPAN_IPHC_SAM_MASK,
670 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 653 saddr);
654 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
671 } else { 655 } else {
672 /* Source address uncompression */ 656 /* Source address uncompression */
673 pr_debug("source address stateless compression\n"); 657 pr_debug("source address stateless compression\n");
674 err = uncompress_addr(skb, dev, &hdr.saddr, 658 err = lowpan_iphc_uncompress_addr(skb, dev, &hdr.saddr,
675 iphc1 & LOWPAN_IPHC_SAM_MASK, saddr); 659 iphc1 & LOWPAN_IPHC_SAM_MASK,
660 saddr);
676 } 661 }
677 662
678 /* Check on error of previous branch */ 663 /* Check on error of previous branch */
@@ -681,10 +666,10 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
681 666
682 switch (iphc1 & (LOWPAN_IPHC_M | LOWPAN_IPHC_DAC)) { 667 switch (iphc1 & (LOWPAN_IPHC_M | LOWPAN_IPHC_DAC)) {
683 case LOWPAN_IPHC_M | LOWPAN_IPHC_DAC: 668 case LOWPAN_IPHC_M | LOWPAN_IPHC_DAC:
684 spin_lock_bh(&lowpan_priv(dev)->ctx.lock); 669 spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
685 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid)); 670 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid));
686 if (!ci) { 671 if (!ci) {
687 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 672 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
688 return -EINVAL; 673 return -EINVAL;
689 } 674 }
690 675
@@ -693,7 +678,7 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
693 err = lowpan_uncompress_multicast_ctx_daddr(skb, ci, 678 err = lowpan_uncompress_multicast_ctx_daddr(skb, ci,
694 &hdr.daddr, 679 &hdr.daddr,
695 iphc1 & LOWPAN_IPHC_DAM_MASK); 680 iphc1 & LOWPAN_IPHC_DAM_MASK);
696 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 681 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
697 break; 682 break;
698 case LOWPAN_IPHC_M: 683 case LOWPAN_IPHC_M:
699 /* multicast */ 684 /* multicast */
@@ -701,22 +686,24 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
701 iphc1 & LOWPAN_IPHC_DAM_MASK); 686 iphc1 & LOWPAN_IPHC_DAM_MASK);
702 break; 687 break;
703 case LOWPAN_IPHC_DAC: 688 case LOWPAN_IPHC_DAC:
704 spin_lock_bh(&lowpan_priv(dev)->ctx.lock); 689 spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
705 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid)); 690 ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid));
706 if (!ci) { 691 if (!ci) {
707 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 692 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
708 return -EINVAL; 693 return -EINVAL;
709 } 694 }
710 695
711 /* Destination address context based uncompression */ 696 /* Destination address context based uncompression */
712 pr_debug("DAC bit is set. Handle context based destination address.\n"); 697 pr_debug("DAC bit is set. Handle context based destination address.\n");
713 err = uncompress_ctx_addr(skb, dev, ci, &hdr.daddr, 698 err = lowpan_iphc_uncompress_ctx_addr(skb, dev, ci, &hdr.daddr,
714 iphc1 & LOWPAN_IPHC_DAM_MASK, daddr); 699 iphc1 & LOWPAN_IPHC_DAM_MASK,
715 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 700 daddr);
701 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
716 break; 702 break;
717 default: 703 default:
718 err = uncompress_addr(skb, dev, &hdr.daddr, 704 err = lowpan_iphc_uncompress_addr(skb, dev, &hdr.daddr,
719 iphc1 & LOWPAN_IPHC_DAM_MASK, daddr); 705 iphc1 & LOWPAN_IPHC_DAM_MASK,
706 daddr);
720 pr_debug("dest: stateless compression mode %d dest %pI6c\n", 707 pr_debug("dest: stateless compression mode %d dest %pI6c\n",
721 iphc1 & LOWPAN_IPHC_DAM_MASK, &hdr.daddr); 708 iphc1 & LOWPAN_IPHC_DAM_MASK, &hdr.daddr);
722 break; 709 break;
@@ -736,7 +723,7 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
736 return err; 723 return err;
737 } 724 }
738 725
739 switch (lowpan_priv(dev)->lltype) { 726 switch (lowpan_dev(dev)->lltype) {
740 case LOWPAN_LLTYPE_IEEE802154: 727 case LOWPAN_LLTYPE_IEEE802154:
741 if (lowpan_802154_cb(skb)->d_size) 728 if (lowpan_802154_cb(skb)->d_size)
742 hdr.payload_len = htons(lowpan_802154_cb(skb)->d_size - 729 hdr.payload_len = htons(lowpan_802154_cb(skb)->d_size -
@@ -1033,7 +1020,7 @@ int lowpan_header_compress(struct sk_buff *skb, const struct net_device *dev,
1033 skb->data, skb->len); 1020 skb->data, skb->len);
1034 1021
1035 ipv6_daddr_type = ipv6_addr_type(&hdr->daddr); 1022 ipv6_daddr_type = ipv6_addr_type(&hdr->daddr);
1036 spin_lock_bh(&lowpan_priv(dev)->ctx.lock); 1023 spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
1037 if (ipv6_daddr_type & IPV6_ADDR_MULTICAST) 1024 if (ipv6_daddr_type & IPV6_ADDR_MULTICAST)
1038 dci = lowpan_iphc_ctx_get_by_mcast_addr(dev, &hdr->daddr); 1025 dci = lowpan_iphc_ctx_get_by_mcast_addr(dev, &hdr->daddr);
1039 else 1026 else
@@ -1042,15 +1029,15 @@ int lowpan_header_compress(struct sk_buff *skb, const struct net_device *dev,
1042 memcpy(&dci_entry, dci, sizeof(*dci)); 1029 memcpy(&dci_entry, dci, sizeof(*dci));
1043 cid |= dci->id; 1030 cid |= dci->id;
1044 } 1031 }
1045 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 1032 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
1046 1033
1047 spin_lock_bh(&lowpan_priv(dev)->ctx.lock); 1034 spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
1048 sci = lowpan_iphc_ctx_get_by_addr(dev, &hdr->saddr); 1035 sci = lowpan_iphc_ctx_get_by_addr(dev, &hdr->saddr);
1049 if (sci) { 1036 if (sci) {
1050 memcpy(&sci_entry, sci, sizeof(*sci)); 1037 memcpy(&sci_entry, sci, sizeof(*sci));
1051 cid |= (sci->id << 4); 1038 cid |= (sci->id << 4);
1052 } 1039 }
1053 spin_unlock_bh(&lowpan_priv(dev)->ctx.lock); 1040 spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
1054 1041
1055 /* if cid is zero it will be compressed */ 1042 /* if cid is zero it will be compressed */
1056 if (cid) { 1043 if (cid) {
diff --git a/net/6lowpan/nhc_udp.c b/net/6lowpan/nhc_udp.c
index 69537a2eaab1..225d91906dfa 100644
--- a/net/6lowpan/nhc_udp.c
+++ b/net/6lowpan/nhc_udp.c
@@ -91,7 +91,7 @@ static int udp_uncompress(struct sk_buff *skb, size_t needed)
91 * here, we obtain the hint from the remaining size of the 91 * here, we obtain the hint from the remaining size of the
92 * frame 92 * frame
93 */ 93 */
94 switch (lowpan_priv(skb->dev)->lltype) { 94 switch (lowpan_dev(skb->dev)->lltype) {
95 case LOWPAN_LLTYPE_IEEE802154: 95 case LOWPAN_LLTYPE_IEEE802154:
96 if (lowpan_802154_cb(skb)->d_size) 96 if (lowpan_802154_cb(skb)->d_size)
97 uh.len = htons(lowpan_802154_cb(skb)->d_size - 97 uh.len = htons(lowpan_802154_cb(skb)->d_size -
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 8a4cc2f7f0db..780089d75915 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -68,7 +68,7 @@ struct lowpan_peer {
68 struct in6_addr peer_addr; 68 struct in6_addr peer_addr;
69}; 69};
70 70
71struct lowpan_dev { 71struct lowpan_btle_dev {
72 struct list_head list; 72 struct list_head list;
73 73
74 struct hci_dev *hdev; 74 struct hci_dev *hdev;
@@ -80,18 +80,21 @@ struct lowpan_dev {
80 struct delayed_work notify_peers; 80 struct delayed_work notify_peers;
81}; 81};
82 82
83static inline struct lowpan_dev *lowpan_dev(const struct net_device *netdev) 83static inline struct lowpan_btle_dev *
84lowpan_btle_dev(const struct net_device *netdev)
84{ 85{
85 return (struct lowpan_dev *)lowpan_priv(netdev)->priv; 86 return (struct lowpan_btle_dev *)lowpan_dev(netdev)->priv;
86} 87}
87 88
88static inline void peer_add(struct lowpan_dev *dev, struct lowpan_peer *peer) 89static inline void peer_add(struct lowpan_btle_dev *dev,
90 struct lowpan_peer *peer)
89{ 91{
90 list_add_rcu(&peer->list, &dev->peers); 92 list_add_rcu(&peer->list, &dev->peers);
91 atomic_inc(&dev->peer_count); 93 atomic_inc(&dev->peer_count);
92} 94}
93 95
94static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer) 96static inline bool peer_del(struct lowpan_btle_dev *dev,
97 struct lowpan_peer *peer)
95{ 98{
96 list_del_rcu(&peer->list); 99 list_del_rcu(&peer->list);
97 kfree_rcu(peer, rcu); 100 kfree_rcu(peer, rcu);
@@ -106,7 +109,7 @@ static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer)
106 return false; 109 return false;
107} 110}
108 111
109static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_dev *dev, 112static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_btle_dev *dev,
110 bdaddr_t *ba, __u8 type) 113 bdaddr_t *ba, __u8 type)
111{ 114{
112 struct lowpan_peer *peer; 115 struct lowpan_peer *peer;
@@ -134,8 +137,8 @@ static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_dev *dev,
134 return NULL; 137 return NULL;
135} 138}
136 139
137static inline struct lowpan_peer *__peer_lookup_chan(struct lowpan_dev *dev, 140static inline struct lowpan_peer *
138 struct l2cap_chan *chan) 141__peer_lookup_chan(struct lowpan_btle_dev *dev, struct l2cap_chan *chan)
139{ 142{
140 struct lowpan_peer *peer; 143 struct lowpan_peer *peer;
141 144
@@ -147,8 +150,8 @@ static inline struct lowpan_peer *__peer_lookup_chan(struct lowpan_dev *dev,
147 return NULL; 150 return NULL;
148} 151}
149 152
150static inline struct lowpan_peer *__peer_lookup_conn(struct lowpan_dev *dev, 153static inline struct lowpan_peer *
151 struct l2cap_conn *conn) 154__peer_lookup_conn(struct lowpan_btle_dev *dev, struct l2cap_conn *conn)
152{ 155{
153 struct lowpan_peer *peer; 156 struct lowpan_peer *peer;
154 157
@@ -160,7 +163,7 @@ static inline struct lowpan_peer *__peer_lookup_conn(struct lowpan_dev *dev,
160 return NULL; 163 return NULL;
161} 164}
162 165
163static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev, 166static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_btle_dev *dev,
164 struct in6_addr *daddr, 167 struct in6_addr *daddr,
165 struct sk_buff *skb) 168 struct sk_buff *skb)
166{ 169{
@@ -220,7 +223,7 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
220 223
221static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn) 224static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn)
222{ 225{
223 struct lowpan_dev *entry; 226 struct lowpan_btle_dev *entry;
224 struct lowpan_peer *peer = NULL; 227 struct lowpan_peer *peer = NULL;
225 228
226 rcu_read_lock(); 229 rcu_read_lock();
@@ -236,10 +239,10 @@ static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn)
236 return peer; 239 return peer;
237} 240}
238 241
239static struct lowpan_dev *lookup_dev(struct l2cap_conn *conn) 242static struct lowpan_btle_dev *lookup_dev(struct l2cap_conn *conn)
240{ 243{
241 struct lowpan_dev *entry; 244 struct lowpan_btle_dev *entry;
242 struct lowpan_dev *dev = NULL; 245 struct lowpan_btle_dev *dev = NULL;
243 246
244 rcu_read_lock(); 247 rcu_read_lock();
245 248
@@ -270,10 +273,10 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
270 struct l2cap_chan *chan) 273 struct l2cap_chan *chan)
271{ 274{
272 const u8 *saddr, *daddr; 275 const u8 *saddr, *daddr;
273 struct lowpan_dev *dev; 276 struct lowpan_btle_dev *dev;
274 struct lowpan_peer *peer; 277 struct lowpan_peer *peer;
275 278
276 dev = lowpan_dev(netdev); 279 dev = lowpan_btle_dev(netdev);
277 280
278 rcu_read_lock(); 281 rcu_read_lock();
279 peer = __peer_lookup_chan(dev, chan); 282 peer = __peer_lookup_chan(dev, chan);
@@ -375,7 +378,7 @@ drop:
375/* Packet from BT LE device */ 378/* Packet from BT LE device */
376static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) 379static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
377{ 380{
378 struct lowpan_dev *dev; 381 struct lowpan_btle_dev *dev;
379 struct lowpan_peer *peer; 382 struct lowpan_peer *peer;
380 int err; 383 int err;
381 384
@@ -431,15 +434,18 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
431 bdaddr_t *peer_addr, u8 *peer_addr_type) 434 bdaddr_t *peer_addr, u8 *peer_addr_type)
432{ 435{
433 struct in6_addr ipv6_daddr; 436 struct in6_addr ipv6_daddr;
434 struct lowpan_dev *dev; 437 struct ipv6hdr *hdr;
438 struct lowpan_btle_dev *dev;
435 struct lowpan_peer *peer; 439 struct lowpan_peer *peer;
436 bdaddr_t addr, *any = BDADDR_ANY; 440 bdaddr_t addr, *any = BDADDR_ANY;
437 u8 *daddr = any->b; 441 u8 *daddr = any->b;
438 int err, status = 0; 442 int err, status = 0;
439 443
440 dev = lowpan_dev(netdev); 444 hdr = ipv6_hdr(skb);
445
446 dev = lowpan_btle_dev(netdev);
441 447
442 memcpy(&ipv6_daddr, &lowpan_cb(skb)->addr, sizeof(ipv6_daddr)); 448 memcpy(&ipv6_daddr, &hdr->daddr, sizeof(ipv6_daddr));
443 449
444 if (ipv6_addr_is_multicast(&ipv6_daddr)) { 450 if (ipv6_addr_is_multicast(&ipv6_daddr)) {
445 lowpan_cb(skb)->chan = NULL; 451 lowpan_cb(skb)->chan = NULL;
@@ -489,15 +495,9 @@ static int header_create(struct sk_buff *skb, struct net_device *netdev,
489 unsigned short type, const void *_daddr, 495 unsigned short type, const void *_daddr,
490 const void *_saddr, unsigned int len) 496 const void *_saddr, unsigned int len)
491{ 497{
492 struct ipv6hdr *hdr;
493
494 if (type != ETH_P_IPV6) 498 if (type != ETH_P_IPV6)
495 return -EINVAL; 499 return -EINVAL;
496 500
497 hdr = ipv6_hdr(skb);
498
499 memcpy(&lowpan_cb(skb)->addr, &hdr->daddr, sizeof(struct in6_addr));
500
501 return 0; 501 return 0;
502} 502}
503 503
@@ -543,19 +543,19 @@ static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb,
543static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev) 543static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
544{ 544{
545 struct sk_buff *local_skb; 545 struct sk_buff *local_skb;
546 struct lowpan_dev *entry; 546 struct lowpan_btle_dev *entry;
547 int err = 0; 547 int err = 0;
548 548
549 rcu_read_lock(); 549 rcu_read_lock();
550 550
551 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) { 551 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
552 struct lowpan_peer *pentry; 552 struct lowpan_peer *pentry;
553 struct lowpan_dev *dev; 553 struct lowpan_btle_dev *dev;
554 554
555 if (entry->netdev != netdev) 555 if (entry->netdev != netdev)
556 continue; 556 continue;
557 557
558 dev = lowpan_dev(entry->netdev); 558 dev = lowpan_btle_dev(entry->netdev);
559 559
560 list_for_each_entry_rcu(pentry, &dev->peers, list) { 560 list_for_each_entry_rcu(pentry, &dev->peers, list) {
561 int ret; 561 int ret;
@@ -723,8 +723,8 @@ static void ifdown(struct net_device *netdev)
723 723
724static void do_notify_peers(struct work_struct *work) 724static void do_notify_peers(struct work_struct *work)
725{ 725{
726 struct lowpan_dev *dev = container_of(work, struct lowpan_dev, 726 struct lowpan_btle_dev *dev = container_of(work, struct lowpan_btle_dev,
727 notify_peers.work); 727 notify_peers.work);
728 728
729 netdev_notify_peers(dev->netdev); /* send neighbour adv at startup */ 729 netdev_notify_peers(dev->netdev); /* send neighbour adv at startup */
730} 730}
@@ -766,7 +766,7 @@ static void set_ip_addr_bits(u8 addr_type, u8 *addr)
766} 766}
767 767
768static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan, 768static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
769 struct lowpan_dev *dev) 769 struct lowpan_btle_dev *dev)
770{ 770{
771 struct lowpan_peer *peer; 771 struct lowpan_peer *peer;
772 772
@@ -803,12 +803,12 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
803 return peer->chan; 803 return peer->chan;
804} 804}
805 805
806static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev) 806static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)
807{ 807{
808 struct net_device *netdev; 808 struct net_device *netdev;
809 int err = 0; 809 int err = 0;
810 810
811 netdev = alloc_netdev(LOWPAN_PRIV_SIZE(sizeof(struct lowpan_dev)), 811 netdev = alloc_netdev(LOWPAN_PRIV_SIZE(sizeof(struct lowpan_btle_dev)),
812 IFACE_NAME_TEMPLATE, NET_NAME_UNKNOWN, 812 IFACE_NAME_TEMPLATE, NET_NAME_UNKNOWN,
813 netdev_setup); 813 netdev_setup);
814 if (!netdev) 814 if (!netdev)
@@ -820,7 +820,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
820 SET_NETDEV_DEV(netdev, &chan->conn->hcon->hdev->dev); 820 SET_NETDEV_DEV(netdev, &chan->conn->hcon->hdev->dev);
821 SET_NETDEV_DEVTYPE(netdev, &bt_type); 821 SET_NETDEV_DEVTYPE(netdev, &bt_type);
822 822
823 *dev = lowpan_dev(netdev); 823 *dev = lowpan_btle_dev(netdev);
824 (*dev)->netdev = netdev; 824 (*dev)->netdev = netdev;
825 (*dev)->hdev = chan->conn->hcon->hdev; 825 (*dev)->hdev = chan->conn->hcon->hdev;
826 INIT_LIST_HEAD(&(*dev)->peers); 826 INIT_LIST_HEAD(&(*dev)->peers);
@@ -853,7 +853,7 @@ out:
853 853
854static inline void chan_ready_cb(struct l2cap_chan *chan) 854static inline void chan_ready_cb(struct l2cap_chan *chan)
855{ 855{
856 struct lowpan_dev *dev; 856 struct lowpan_btle_dev *dev;
857 857
858 dev = lookup_dev(chan->conn); 858 dev = lookup_dev(chan->conn);
859 859
@@ -890,8 +890,9 @@ static inline struct l2cap_chan *chan_new_conn_cb(struct l2cap_chan *pchan)
890 890
891static void delete_netdev(struct work_struct *work) 891static void delete_netdev(struct work_struct *work)
892{ 892{
893 struct lowpan_dev *entry = container_of(work, struct lowpan_dev, 893 struct lowpan_btle_dev *entry = container_of(work,
894 delete_netdev); 894 struct lowpan_btle_dev,
895 delete_netdev);
895 896
896 lowpan_unregister_netdev(entry->netdev); 897 lowpan_unregister_netdev(entry->netdev);
897 898
@@ -900,8 +901,8 @@ static void delete_netdev(struct work_struct *work)
900 901
901static void chan_close_cb(struct l2cap_chan *chan) 902static void chan_close_cb(struct l2cap_chan *chan)
902{ 903{
903 struct lowpan_dev *entry; 904 struct lowpan_btle_dev *entry;
904 struct lowpan_dev *dev = NULL; 905 struct lowpan_btle_dev *dev = NULL;
905 struct lowpan_peer *peer; 906 struct lowpan_peer *peer;
906 int err = -ENOENT; 907 int err = -ENOENT;
907 bool last = false, remove = true; 908 bool last = false, remove = true;
@@ -921,7 +922,7 @@ static void chan_close_cb(struct l2cap_chan *chan)
921 spin_lock(&devices_lock); 922 spin_lock(&devices_lock);
922 923
923 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) { 924 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
924 dev = lowpan_dev(entry->netdev); 925 dev = lowpan_btle_dev(entry->netdev);
925 peer = __peer_lookup_chan(dev, chan); 926 peer = __peer_lookup_chan(dev, chan);
926 if (peer) { 927 if (peer) {
927 last = peer_del(dev, peer); 928 last = peer_del(dev, peer);
@@ -1131,7 +1132,7 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
1131 1132
1132static void disconnect_all_peers(void) 1133static void disconnect_all_peers(void)
1133{ 1134{
1134 struct lowpan_dev *entry; 1135 struct lowpan_btle_dev *entry;
1135 struct lowpan_peer *peer, *tmp_peer, *new_peer; 1136 struct lowpan_peer *peer, *tmp_peer, *new_peer;
1136 struct list_head peers; 1137 struct list_head peers;
1137 1138
@@ -1291,7 +1292,7 @@ static ssize_t lowpan_control_write(struct file *fp,
1291 1292
1292static int lowpan_control_show(struct seq_file *f, void *ptr) 1293static int lowpan_control_show(struct seq_file *f, void *ptr)
1293{ 1294{
1294 struct lowpan_dev *entry; 1295 struct lowpan_btle_dev *entry;
1295 struct lowpan_peer *peer; 1296 struct lowpan_peer *peer;
1296 1297
1297 spin_lock(&devices_lock); 1298 spin_lock(&devices_lock);
@@ -1322,7 +1323,7 @@ static const struct file_operations lowpan_control_fops = {
1322 1323
1323static void disconnect_devices(void) 1324static void disconnect_devices(void)
1324{ 1325{
1325 struct lowpan_dev *entry, *tmp, *new_dev; 1326 struct lowpan_btle_dev *entry, *tmp, *new_dev;
1326 struct list_head devices; 1327 struct list_head devices;
1327 1328
1328 INIT_LIST_HEAD(&devices); 1329 INIT_LIST_HEAD(&devices);
@@ -1360,7 +1361,7 @@ static int device_event(struct notifier_block *unused,
1360 unsigned long event, void *ptr) 1361 unsigned long event, void *ptr)
1361{ 1362{
1362 struct net_device *netdev = netdev_notifier_info_to_dev(ptr); 1363 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
1363 struct lowpan_dev *entry; 1364 struct lowpan_btle_dev *entry;
1364 1365
1365 if (netdev->type != ARPHRD_6LOWPAN) 1366 if (netdev->type != ARPHRD_6LOWPAN)
1366 return NOTIFY_DONE; 1367 return NOTIFY_DONE;
diff --git a/net/ieee802154/6lowpan/6lowpan_i.h b/net/ieee802154/6lowpan/6lowpan_i.h
index b4e17a7c0df0..5ac778962e4e 100644
--- a/net/ieee802154/6lowpan/6lowpan_i.h
+++ b/net/ieee802154/6lowpan/6lowpan_i.h
@@ -41,24 +41,12 @@ static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a)
41 return (((__force u64)a->extended_addr) >> 32) ^ 41 return (((__force u64)a->extended_addr) >> 32) ^
42 (((__force u64)a->extended_addr) & 0xffffffff); 42 (((__force u64)a->extended_addr) & 0xffffffff);
43 case IEEE802154_ADDR_SHORT: 43 case IEEE802154_ADDR_SHORT:
44 return (__force u32)(a->short_addr); 44 return (__force u32)(a->short_addr + (a->pan_id << 16));
45 default: 45 default:
46 return 0; 46 return 0;
47 } 47 }
48} 48}
49 49
50/* private device info */
51struct lowpan_dev_info {
52 struct net_device *wdev; /* wpan device ptr */
53 u16 fragment_tag;
54};
55
56static inline struct
57lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
58{
59 return (struct lowpan_dev_info *)lowpan_priv(dev)->priv;
60}
61
62int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type); 50int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type);
63void lowpan_net_frag_exit(void); 51void lowpan_net_frag_exit(void);
64int lowpan_net_frag_init(void); 52int lowpan_net_frag_init(void);
diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index 0023c9048812..dd085db8580e 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -148,7 +148,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
148 return -EBUSY; 148 return -EBUSY;
149 } 149 }
150 150
151 lowpan_dev_info(ldev)->wdev = wdev; 151 lowpan_802154_dev(ldev)->wdev = wdev;
152 /* Set the lowpan hardware address to the wpan hardware address. */ 152 /* Set the lowpan hardware address to the wpan hardware address. */
153 memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN); 153 memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN);
154 /* We need headroom for possible wpan_dev_hard_header call and tailroom 154 /* We need headroom for possible wpan_dev_hard_header call and tailroom
@@ -173,7 +173,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
173 173
174static void lowpan_dellink(struct net_device *ldev, struct list_head *head) 174static void lowpan_dellink(struct net_device *ldev, struct list_head *head)
175{ 175{
176 struct net_device *wdev = lowpan_dev_info(ldev)->wdev; 176 struct net_device *wdev = lowpan_802154_dev(ldev)->wdev;
177 177
178 ASSERT_RTNL(); 178 ASSERT_RTNL();
179 179
@@ -184,7 +184,7 @@ static void lowpan_dellink(struct net_device *ldev, struct list_head *head)
184 184
185static struct rtnl_link_ops lowpan_link_ops __read_mostly = { 185static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
186 .kind = "lowpan", 186 .kind = "lowpan",
187 .priv_size = LOWPAN_PRIV_SIZE(sizeof(struct lowpan_dev_info)), 187 .priv_size = LOWPAN_PRIV_SIZE(sizeof(struct lowpan_802154_dev)),
188 .setup = lowpan_setup, 188 .setup = lowpan_setup,
189 .newlink = lowpan_newlink, 189 .newlink = lowpan_newlink,
190 .dellink = lowpan_dellink, 190 .dellink = lowpan_dellink,
diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
index d4353faced35..e459afd16bb3 100644
--- a/net/ieee802154/6lowpan/tx.c
+++ b/net/ieee802154/6lowpan/tx.c
@@ -84,7 +84,7 @@ static struct sk_buff*
84lowpan_alloc_frag(struct sk_buff *skb, int size, 84lowpan_alloc_frag(struct sk_buff *skb, int size,
85 const struct ieee802154_hdr *master_hdr, bool frag1) 85 const struct ieee802154_hdr *master_hdr, bool frag1)
86{ 86{
87 struct net_device *wdev = lowpan_dev_info(skb->dev)->wdev; 87 struct net_device *wdev = lowpan_802154_dev(skb->dev)->wdev;
88 struct sk_buff *frag; 88 struct sk_buff *frag;
89 int rc; 89 int rc;
90 90
@@ -148,8 +148,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
148 int frag_cap, frag_len, payload_cap, rc; 148 int frag_cap, frag_len, payload_cap, rc;
149 int skb_unprocessed, skb_offset; 149 int skb_unprocessed, skb_offset;
150 150
151 frag_tag = htons(lowpan_dev_info(ldev)->fragment_tag); 151 frag_tag = htons(lowpan_802154_dev(ldev)->fragment_tag);
152 lowpan_dev_info(ldev)->fragment_tag++; 152 lowpan_802154_dev(ldev)->fragment_tag++;
153 153
154 frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07); 154 frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
155 frag_hdr[1] = dgram_size & 0xff; 155 frag_hdr[1] = dgram_size & 0xff;
@@ -208,7 +208,7 @@ err:
208static int lowpan_header(struct sk_buff *skb, struct net_device *ldev, 208static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
209 u16 *dgram_size, u16 *dgram_offset) 209 u16 *dgram_size, u16 *dgram_offset)
210{ 210{
211 struct wpan_dev *wpan_dev = lowpan_dev_info(ldev)->wdev->ieee802154_ptr; 211 struct wpan_dev *wpan_dev = lowpan_802154_dev(ldev)->wdev->ieee802154_ptr;
212 struct ieee802154_addr sa, da; 212 struct ieee802154_addr sa, da;
213 struct ieee802154_mac_cb *cb = mac_cb_init(skb); 213 struct ieee802154_mac_cb *cb = mac_cb_init(skb);
214 struct lowpan_addr_info info; 214 struct lowpan_addr_info info;
@@ -248,8 +248,8 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
248 cb->ackreq = wpan_dev->ackreq; 248 cb->ackreq = wpan_dev->ackreq;
249 } 249 }
250 250
251 return wpan_dev_hard_header(skb, lowpan_dev_info(ldev)->wdev, &da, &sa, 251 return wpan_dev_hard_header(skb, lowpan_802154_dev(ldev)->wdev, &da,
252 0); 252 &sa, 0);
253} 253}
254 254
255netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev) 255netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
@@ -283,7 +283,7 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
283 max_single = ieee802154_max_payload(&wpan_hdr); 283 max_single = ieee802154_max_payload(&wpan_hdr);
284 284
285 if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) { 285 if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
286 skb->dev = lowpan_dev_info(ldev)->wdev; 286 skb->dev = lowpan_802154_dev(ldev)->wdev;
287 ldev->stats.tx_packets++; 287 ldev->stats.tx_packets++;
288 ldev->stats.tx_bytes += dgram_size; 288 ldev->stats.tx_bytes += dgram_size;
289 return dev_queue_xmit(skb); 289 return dev_queue_xmit(skb);
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 8035c93dd527..ca207dbf673b 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -1078,6 +1078,11 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
1078 if (netif_running(dev)) 1078 if (netif_running(dev))
1079 return -EBUSY; 1079 return -EBUSY;
1080 1080
1081 if (wpan_dev->lowpan_dev) {
1082 if (netif_running(wpan_dev->lowpan_dev))
1083 return -EBUSY;
1084 }
1085
1081 /* don't change address fields on monitor */ 1086 /* don't change address fields on monitor */
1082 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR || 1087 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
1083 !info->attrs[NL802154_ATTR_PAN_ID]) 1088 !info->attrs[NL802154_ATTR_PAN_ID])
@@ -1109,6 +1114,11 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
1109 if (netif_running(dev)) 1114 if (netif_running(dev))
1110 return -EBUSY; 1115 return -EBUSY;
1111 1116
1117 if (wpan_dev->lowpan_dev) {
1118 if (netif_running(wpan_dev->lowpan_dev))
1119 return -EBUSY;
1120 }
1121
1112 /* don't change address fields on monitor */ 1122 /* don't change address fields on monitor */
1113 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR || 1123 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
1114 !info->attrs[NL802154_ATTR_SHORT_ADDR]) 1124 !info->attrs[NL802154_ATTR_SHORT_ADDR])