]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/bluetooth/6lowpan.c
UBUNTU: Ubuntu-5.15.0-39.42
[mirror_ubuntu-jammy-kernel.git] / net / bluetooth / 6lowpan.c
CommitLineData
97fb5e8d 1// SPDX-License-Identifier: GPL-2.0-only
18722c24 2/*
6b8d4a6a 3 Copyright (c) 2013-2014 Intel Corp.
18722c24 4
18722c24
JR
5*/
6
18722c24
JR
7#include <linux/if_arp.h>
8#include <linux/netdevice.h>
9#include <linux/etherdevice.h>
5547e48c 10#include <linux/module.h>
6b8d4a6a 11#include <linux/debugfs.h>
18722c24
JR
12
13#include <net/ipv6.h>
14#include <net/ip6_route.h>
15#include <net/addrconf.h>
814f1b24 16#include <net/pkt_sched.h>
18722c24 17
18722c24
JR
18#include <net/bluetooth/bluetooth.h>
19#include <net/bluetooth/hci_core.h>
20#include <net/bluetooth/l2cap.h>
21
cefc8c8a 22#include <net/6lowpan.h> /* for the compression support */
18722c24 23
6b8d4a6a
JR
24#define VERSION "0.1"
25
7b2ed60e 26static struct dentry *lowpan_enable_debugfs;
6b8d4a6a
JR
27static struct dentry *lowpan_control_debugfs;
28
18722c24 29#define IFACE_NAME_TEMPLATE "bt%d"
18722c24
JR
30
31struct skb_cb {
32 struct in6_addr addr;
39e90c77 33 struct in6_addr gw;
6b8d4a6a 34 struct l2cap_chan *chan;
18722c24
JR
35};
36#define lowpan_cb(skb) ((struct skb_cb *)((skb)->cb))
37
38/* The devices list contains those devices that we are acting
39 * as a proxy. The BT 6LoWPAN device is a virtual device that
40 * connects to the Bluetooth LE device. The real connection to
41 * BT device is done via l2cap layer. There exists one
42 * virtual device / one BT 6LoWPAN network (=hciX device).
43 * The list contains struct lowpan_dev elements.
44 */
45static LIST_HEAD(bt_6lowpan_devices);
90305829 46static DEFINE_SPINLOCK(devices_lock);
18722c24 47
7b2ed60e 48static bool enable_6lowpan;
6b8d4a6a
JR
49
50/* We are listening incoming connections via this channel
51 */
52static struct l2cap_chan *listen_chan;
f9c70bdc 53static DEFINE_MUTEX(set_lock);
6b8d4a6a 54
18722c24
JR
55struct lowpan_peer {
56 struct list_head list;
90305829 57 struct rcu_head rcu;
6b8d4a6a 58 struct l2cap_chan *chan;
18722c24
JR
59
60 /* peer addresses in various formats */
fa09ae66 61 unsigned char lladdr[ETH_ALEN];
18722c24
JR
62 struct in6_addr peer_addr;
63};
64
2e4d60cb 65struct lowpan_btle_dev {
18722c24
JR
66 struct list_head list;
67
68 struct hci_dev *hdev;
69 struct net_device *netdev;
70 struct list_head peers;
71 atomic_t peer_count; /* number of items in peers list */
72
73 struct work_struct delete_netdev;
74 struct delayed_work notify_peers;
75};
76
2e4d60cb
AA
77static inline struct lowpan_btle_dev *
78lowpan_btle_dev(const struct net_device *netdev)
18722c24 79{
2e4d60cb 80 return (struct lowpan_btle_dev *)lowpan_dev(netdev)->priv;
18722c24
JR
81}
82
2e4d60cb
AA
83static inline void peer_add(struct lowpan_btle_dev *dev,
84 struct lowpan_peer *peer)
18722c24 85{
90305829 86 list_add_rcu(&peer->list, &dev->peers);
18722c24
JR
87 atomic_inc(&dev->peer_count);
88}
89
2e4d60cb
AA
90static inline bool peer_del(struct lowpan_btle_dev *dev,
91 struct lowpan_peer *peer)
18722c24 92{
90305829 93 list_del_rcu(&peer->list);
4e790226 94 kfree_rcu(peer, rcu);
18722c24 95
18d93c17
JR
96 module_put(THIS_MODULE);
97
18722c24
JR
98 if (atomic_dec_and_test(&dev->peer_count)) {
99 BT_DBG("last peer");
100 return true;
101 }
102
103 return false;
104}
105
2e4d60cb
AA
106static inline struct lowpan_peer *
107__peer_lookup_chan(struct lowpan_btle_dev *dev, struct l2cap_chan *chan)
6b8d4a6a 108{
90305829 109 struct lowpan_peer *peer;
6b8d4a6a 110
90305829 111 list_for_each_entry_rcu(peer, &dev->peers, list) {
6b8d4a6a 112 if (peer->chan == chan)
18722c24
JR
113 return peer;
114 }
115
116 return NULL;
117}
118
2e4d60cb
AA
119static inline struct lowpan_peer *
120__peer_lookup_conn(struct lowpan_btle_dev *dev, struct l2cap_conn *conn)
18722c24 121{
90305829 122 struct lowpan_peer *peer;
18722c24 123
90305829 124 list_for_each_entry_rcu(peer, &dev->peers, list) {
6b8d4a6a 125 if (peer->chan->conn == conn)
18722c24
JR
126 return peer;
127 }
128
129 return NULL;
130}
131
2e4d60cb 132static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_btle_dev *dev,
39e90c77
JR
133 struct in6_addr *daddr,
134 struct sk_buff *skb)
135{
39e90c77
JR
136 struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
137 int count = atomic_read(&dev->peer_count);
9b1c1ef1
ND
138 const struct in6_addr *nexthop;
139 struct lowpan_peer *peer;
5636376c 140 struct neighbour *neigh;
39e90c77
JR
141
142 BT_DBG("peers %d addr %pI6c rt %p", count, daddr, rt);
143
39e90c77 144 if (!rt) {
b188b032
JM
145 if (ipv6_addr_any(&lowpan_cb(skb)->gw)) {
146 /* There is neither route nor gateway,
147 * probably the destination is a direct peer.
148 */
149 nexthop = daddr;
150 } else {
151 /* There is a known gateway
152 */
153 nexthop = &lowpan_cb(skb)->gw;
154 }
39e90c77 155 } else {
2647a9b0 156 nexthop = rt6_nexthop(rt, daddr);
39e90c77
JR
157
158 /* We need to remember the address because it is needed
159 * by bt_xmit() when sending the packet. In bt_xmit(), the
160 * destination routing info is not set.
161 */
162 memcpy(&lowpan_cb(skb)->gw, nexthop, sizeof(struct in6_addr));
163 }
164
165 BT_DBG("gw %pI6c", nexthop);
166
90305829
JR
167 rcu_read_lock();
168
169 list_for_each_entry_rcu(peer, &dev->peers, list) {
658d5d80 170 BT_DBG("dst addr %pMR dst type %u ip %pI6c",
39e90c77
JR
171 &peer->chan->dst, peer->chan->dst_type,
172 &peer->peer_addr);
173
90305829
JR
174 if (!ipv6_addr_cmp(&peer->peer_addr, nexthop)) {
175 rcu_read_unlock();
39e90c77 176 return peer;
90305829 177 }
39e90c77
JR
178 }
179
149b3f13 180 /* use the neighbour cache for matching addresses assigned by SLAAC */
5636376c
JM
181 neigh = __ipv6_neigh_lookup(dev->netdev, nexthop);
182 if (neigh) {
183 list_for_each_entry_rcu(peer, &dev->peers, list) {
184 if (!memcmp(neigh->ha, peer->lladdr, ETH_ALEN)) {
185 neigh_release(neigh);
186 rcu_read_unlock();
187 return peer;
188 }
189 }
190 neigh_release(neigh);
191 }
192
90305829
JR
193 rcu_read_unlock();
194
39e90c77
JR
195 return NULL;
196}
197
18722c24
JR
198static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn)
199{
2e4d60cb 200 struct lowpan_btle_dev *entry;
18722c24 201 struct lowpan_peer *peer = NULL;
18722c24 202
90305829 203 rcu_read_lock();
18722c24 204
90305829
JR
205 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
206 peer = __peer_lookup_conn(entry, conn);
18722c24
JR
207 if (peer)
208 break;
209 }
210
90305829 211 rcu_read_unlock();
18722c24
JR
212
213 return peer;
214}
215
2e4d60cb 216static struct lowpan_btle_dev *lookup_dev(struct l2cap_conn *conn)
18722c24 217{
2e4d60cb
AA
218 struct lowpan_btle_dev *entry;
219 struct lowpan_btle_dev *dev = NULL;
18722c24 220
90305829 221 rcu_read_lock();
18722c24 222
90305829 223 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
18722c24
JR
224 if (conn->hcon->hdev == entry->hdev) {
225 dev = entry;
226 break;
227 }
228 }
229
90305829 230 rcu_read_unlock();
18722c24
JR
231
232 return dev;
233}
234
18722c24
JR
235static int give_skb_to_upper(struct sk_buff *skb, struct net_device *dev)
236{
237 struct sk_buff *skb_cp;
18722c24
JR
238
239 skb_cp = skb_copy(skb, GFP_ATOMIC);
240 if (!skb_cp)
f8b36176 241 return NET_RX_DROP;
18722c24 242
324e786e 243 return netif_rx_ni(skb_cp);
18722c24
JR
244}
245
01141234 246static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
27ce68a3 247 struct lowpan_peer *peer)
18722c24 248{
c259d141 249 const u8 *saddr;
18722c24 250
fa09ae66 251 saddr = peer->lladdr;
18722c24 252
fa09ae66 253 return lowpan_header_decompress(skb, netdev, netdev->dev_addr, saddr);
18722c24
JR
254}
255
256static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
27ce68a3 257 struct lowpan_peer *peer)
18722c24
JR
258{
259 struct sk_buff *local_skb;
260 int ret;
261
262 if (!netif_running(dev))
263 goto drop;
264
cefdb801 265 if (dev->type != ARPHRD_6LOWPAN || !skb->len)
18722c24
JR
266 goto drop;
267
cefdb801
AA
268 skb_reset_network_header(skb);
269
11e3ff70
MT
270 skb = skb_share_check(skb, GFP_ATOMIC);
271 if (!skb)
272 goto drop;
273
18722c24 274 /* check that it's our buffer */
cefdb801 275 if (lowpan_is_ipv6(*skb_network_header(skb))) {
87f5fedb
LD
276 /* Pull off the 1-byte of 6lowpan header. */
277 skb_pull(skb, 1);
278
18722c24
JR
279 /* Copy the packet so that the IPv6 header is
280 * properly aligned.
281 */
282 local_skb = skb_copy_expand(skb, NET_SKB_PAD - 1,
283 skb_tailroom(skb), GFP_ATOMIC);
284 if (!local_skb)
285 goto drop;
286
287 local_skb->protocol = htons(ETH_P_IPV6);
288 local_skb->pkt_type = PACKET_HOST;
4c58f328 289 local_skb->dev = dev;
18722c24 290
18722c24
JR
291 skb_set_transport_header(local_skb, sizeof(struct ipv6hdr));
292
293 if (give_skb_to_upper(local_skb, dev) != NET_RX_SUCCESS) {
294 kfree_skb(local_skb);
295 goto drop;
296 }
297
298 dev->stats.rx_bytes += skb->len;
299 dev->stats.rx_packets++;
300
3c400b84
MT
301 consume_skb(local_skb);
302 consume_skb(skb);
cefdb801
AA
303 } else if (lowpan_is_iphc(*skb_network_header(skb))) {
304 local_skb = skb_clone(skb, GFP_ATOMIC);
305 if (!local_skb)
306 goto drop;
307
4c58f328
GRB
308 local_skb->dev = dev;
309
27ce68a3 310 ret = iphc_decompress(local_skb, dev, peer);
cefdb801 311 if (ret < 0) {
da75fdc6 312 BT_DBG("iphc_decompress failed: %d", ret);
cefdb801
AA
313 kfree_skb(local_skb);
314 goto drop;
315 }
316
317 local_skb->protocol = htons(ETH_P_IPV6);
318 local_skb->pkt_type = PACKET_HOST;
cefdb801
AA
319
320 if (give_skb_to_upper(local_skb, dev)
321 != NET_RX_SUCCESS) {
322 kfree_skb(local_skb);
323 goto drop;
18722c24 324 }
cefdb801
AA
325
326 dev->stats.rx_bytes += skb->len;
327 dev->stats.rx_packets++;
328
329 consume_skb(local_skb);
330 consume_skb(skb);
331 } else {
da75fdc6 332 BT_DBG("unknown packet type");
cefdb801 333 goto drop;
18722c24
JR
334 }
335
336 return NET_RX_SUCCESS;
337
338drop:
6b8d4a6a 339 dev->stats.rx_dropped++;
18722c24
JR
340 return NET_RX_DROP;
341}
342
343/* Packet from BT LE device */
6b8d4a6a 344static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
18722c24 345{
2e4d60cb 346 struct lowpan_btle_dev *dev;
18722c24
JR
347 struct lowpan_peer *peer;
348 int err;
349
6b8d4a6a 350 peer = lookup_peer(chan->conn);
18722c24
JR
351 if (!peer)
352 return -ENOENT;
353
6b8d4a6a 354 dev = lookup_dev(chan->conn);
30d3db44 355 if (!dev || !dev->netdev)
18722c24
JR
356 return -ENOENT;
357
27ce68a3 358 err = recv_pkt(skb, dev->netdev, peer);
6b8d4a6a
JR
359 if (err) {
360 BT_DBG("recv pkt %d", err);
361 err = -EAGAIN;
18722c24
JR
362 }
363
6b8d4a6a 364 return err;
18722c24
JR
365}
366
36b3dd25
JR
367static int setup_header(struct sk_buff *skb, struct net_device *netdev,
368 bdaddr_t *peer_addr, u8 *peer_addr_type)
18722c24 369{
36b3dd25 370 struct in6_addr ipv6_daddr;
55441070 371 struct ipv6hdr *hdr;
2e4d60cb 372 struct lowpan_btle_dev *dev;
18722c24 373 struct lowpan_peer *peer;
9dae2e03 374 u8 *daddr;
36b3dd25 375 int err, status = 0;
18722c24 376
55441070
GRB
377 hdr = ipv6_hdr(skb);
378
2e4d60cb 379 dev = lowpan_btle_dev(netdev);
18722c24 380
55441070 381 memcpy(&ipv6_daddr, &hdr->daddr, sizeof(ipv6_daddr));
36b3dd25
JR
382
383 if (ipv6_addr_is_multicast(&ipv6_daddr)) {
6b8d4a6a 384 lowpan_cb(skb)->chan = NULL;
9dae2e03 385 daddr = NULL;
18722c24 386 } else {
9dae2e03 387 BT_DBG("dest IP %pI6c", &ipv6_daddr);
18722c24 388
9dae2e03
LAD
389 /* The packet might be sent to 6lowpan interface
390 * because of routing (either via default route
391 * or user set route) so get peer according to
392 * the destination address.
18722c24 393 */
9dae2e03 394 peer = peer_lookup_dst(dev, &ipv6_daddr, skb);
18722c24 395 if (!peer) {
9dae2e03
LAD
396 BT_DBG("no such peer");
397 return -ENOENT;
18722c24
JR
398 }
399
fa09ae66 400 daddr = peer->lladdr;
fa0eaf84 401 *peer_addr = peer->chan->dst;
9dae2e03 402 *peer_addr_type = peer->chan->dst_type;
6b8d4a6a 403 lowpan_cb(skb)->chan = peer->chan;
36b3dd25
JR
404
405 status = 1;
18722c24
JR
406 }
407
a6f77389 408 lowpan_header_compress(skb, netdev, daddr, dev->netdev->dev_addr);
36b3dd25
JR
409
410 err = dev_hard_header(skb, netdev, ETH_P_IPV6, NULL, NULL, 0);
411 if (err < 0)
412 return err;
413
414 return status;
415}
416
417static int header_create(struct sk_buff *skb, struct net_device *netdev,
418 unsigned short type, const void *_daddr,
419 const void *_saddr, unsigned int len)
420{
36b3dd25
JR
421 if (type != ETH_P_IPV6)
422 return -EINVAL;
423
36b3dd25 424 return 0;
18722c24
JR
425}
426
427/* Packet to BT LE device */
6b8d4a6a 428static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb,
d7b6b0a5 429 struct net_device *netdev)
18722c24 430{
6b8d4a6a
JR
431 struct msghdr msg;
432 struct kvec iv;
433 int err;
434
435 /* Remember the skb so that we can send EAGAIN to the caller if
d7b6b0a5 436 * we run out of credits.
6b8d4a6a 437 */
d7b6b0a5 438 chan->data = skb;
6b8d4a6a 439
6b8d4a6a
JR
440 iv.iov_base = skb->data;
441 iv.iov_len = skb->len;
442
c0371da6 443 memset(&msg, 0, sizeof(msg));
aa563d7b 444 iov_iter_kvec(&msg.msg_iter, WRITE, &iv, 1, skb->len);
c0371da6 445
6b8d4a6a
JR
446 err = l2cap_chan_send(chan, &msg, skb->len);
447 if (err > 0) {
448 netdev->stats.tx_bytes += err;
449 netdev->stats.tx_packets++;
450 return 0;
451 }
452
e1008f95
LAD
453 if (err < 0)
454 netdev->stats.tx_errors++;
18722c24 455
6b8d4a6a 456 return err;
18722c24
JR
457}
458
9c238ca8 459static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
18722c24
JR
460{
461 struct sk_buff *local_skb;
2e4d60cb 462 struct lowpan_btle_dev *entry;
9c238ca8 463 int err = 0;
18722c24 464
90305829 465 rcu_read_lock();
18722c24 466
90305829
JR
467 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
468 struct lowpan_peer *pentry;
2e4d60cb 469 struct lowpan_btle_dev *dev;
18722c24
JR
470
471 if (entry->netdev != netdev)
472 continue;
473
2e4d60cb 474 dev = lowpan_btle_dev(entry->netdev);
18722c24 475
90305829 476 list_for_each_entry_rcu(pentry, &dev->peers, list) {
9c238ca8
JR
477 int ret;
478
18722c24
JR
479 local_skb = skb_clone(skb, GFP_ATOMIC);
480
658d5d80 481 BT_DBG("xmit %s to %pMR type %u IP %pI6c chan %p",
36b3dd25
JR
482 netdev->name,
483 &pentry->chan->dst, pentry->chan->dst_type,
484 &pentry->peer_addr, pentry->chan);
9c238ca8
JR
485 ret = send_pkt(pentry->chan, local_skb, netdev);
486 if (ret < 0)
487 err = ret;
18722c24
JR
488
489 kfree_skb(local_skb);
490 }
491 }
492
90305829 493 rcu_read_unlock();
9c238ca8
JR
494
495 return err;
18722c24
JR
496}
497
498static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
499{
500 int err = 0;
18722c24
JR
501 bdaddr_t addr;
502 u8 addr_type;
503
36b3dd25
JR
504 /* We must take a copy of the skb before we modify/replace the ipv6
505 * header as the header could be used elsewhere
506 */
b0c42cd7
AA
507 skb = skb_unshare(skb, GFP_ATOMIC);
508 if (!skb)
36b3dd25
JR
509 return NET_XMIT_DROP;
510
511 /* Return values from setup_header()
512 * <0 - error, packet is dropped
513 * 0 - this is a multicast packet
514 * 1 - this is unicast packet
515 */
516 err = setup_header(skb, netdev, &addr, &addr_type);
517 if (err < 0) {
518 kfree_skb(skb);
519 return NET_XMIT_DROP;
520 }
18722c24 521
36b3dd25
JR
522 if (err) {
523 if (lowpan_cb(skb)->chan) {
658d5d80 524 BT_DBG("xmit %s to %pMR type %u IP %pI6c chan %p",
36b3dd25
JR
525 netdev->name, &addr, addr_type,
526 &lowpan_cb(skb)->addr, lowpan_cb(skb)->chan);
d7b6b0a5 527 err = send_pkt(lowpan_cb(skb)->chan, skb, netdev);
36b3dd25 528 } else {
6b8d4a6a 529 err = -ENOENT;
36b3dd25
JR
530 }
531 } else {
532 /* We need to send the packet to every device behind this
533 * interface.
534 */
9c238ca8 535 err = send_mcast_pkt(skb, netdev);
18722c24 536 }
18722c24 537
fc12518a
JR
538 dev_kfree_skb(skb);
539
18722c24
JR
540 if (err)
541 BT_DBG("ERROR: xmit failed (%d)", err);
542
36b3dd25 543 return err < 0 ? NET_XMIT_DROP : err;
18722c24
JR
544}
545
1a33e10e
CW
546static int bt_dev_init(struct net_device *dev)
547{
548 netdev_lockdep_set_classes(dev);
549
550 return 0;
551}
552
18722c24 553static const struct net_device_ops netdev_ops = {
1a33e10e 554 .ndo_init = bt_dev_init,
18722c24
JR
555 .ndo_start_xmit = bt_xmit,
556};
557
569428da 558static const struct header_ops header_ops = {
18722c24
JR
559 .create = header_create,
560};
561
562static void netdev_setup(struct net_device *dev)
563{
18722c24
JR
564 dev->hard_header_len = 0;
565 dev->needed_tailroom = 0;
25869522 566 dev->flags = IFF_RUNNING | IFF_MULTICAST;
18722c24 567 dev->watchdog_timeo = 0;
814f1b24 568 dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
18722c24
JR
569
570 dev->netdev_ops = &netdev_ops;
571 dev->header_ops = &header_ops;
cf124db5 572 dev->needs_free_netdev = true;
18722c24
JR
573}
574
575static struct device_type bt_type = {
576 .name = "bluetooth",
577};
578
18722c24
JR
579static void ifup(struct net_device *netdev)
580{
581 int err;
582
583 rtnl_lock();
00f54e68 584 err = dev_open(netdev, NULL);
18722c24
JR
585 if (err < 0)
586 BT_INFO("iface %s cannot be opened (%d)", netdev->name, err);
587 rtnl_unlock();
588}
589
7f118253
JR
590static void ifdown(struct net_device *netdev)
591{
7f118253 592 rtnl_lock();
ddee3103 593 dev_close(netdev);
7f118253
JR
594 rtnl_unlock();
595}
596
18722c24
JR
597static void do_notify_peers(struct work_struct *work)
598{
2e4d60cb
AA
599 struct lowpan_btle_dev *dev = container_of(work, struct lowpan_btle_dev,
600 notify_peers.work);
18722c24
JR
601
602 netdev_notify_peers(dev->netdev); /* send neighbour adv at startup */
603}
604
605static bool is_bt_6lowpan(struct hci_conn *hcon)
606{
607 if (hcon->type != LE_LINK)
608 return false;
609
7b2ed60e 610 if (!enable_6lowpan)
6b8d4a6a
JR
611 return false;
612
613 return true;
18722c24
JR
614}
615
6b8d4a6a
JR
616static struct l2cap_chan *chan_create(void)
617{
618 struct l2cap_chan *chan;
619
620 chan = l2cap_chan_create();
621 if (!chan)
622 return NULL;
623
624 l2cap_chan_set_defaults(chan);
625
626 chan->chan_type = L2CAP_CHAN_CONN_ORIENTED;
627 chan->mode = L2CAP_MODE_LE_FLOWCTL;
301de2cb 628 chan->imtu = 1280;
6b8d4a6a
JR
629
630 return chan;
631}
632
6b8d4a6a 633static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
d2891c4d
MS
634 struct lowpan_btle_dev *dev,
635 bool new_netdev)
18722c24
JR
636{
637 struct lowpan_peer *peer;
18722c24
JR
638
639 peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
640 if (!peer)
6b8d4a6a 641 return NULL;
18722c24 642
6b8d4a6a 643 peer->chan = chan;
18722c24
JR
644 memset(&peer->peer_addr, 0, sizeof(struct in6_addr));
645
fa09ae66 646 baswap((void *)peer->lladdr, &chan->dst);
18722c24 647
fa09ae66 648 lowpan_iphc_uncompress_eui48_lladdr(&peer->peer_addr, peer->lladdr);
18722c24 649
90305829 650 spin_lock(&devices_lock);
18722c24
JR
651 INIT_LIST_HEAD(&peer->list);
652 peer_add(dev, peer);
90305829 653 spin_unlock(&devices_lock);
18722c24
JR
654
655 /* Notifying peers about us needs to be done without locks held */
d2891c4d
MS
656 if (new_netdev)
657 INIT_DELAYED_WORK(&dev->notify_peers, do_notify_peers);
18722c24
JR
658 schedule_delayed_work(&dev->notify_peers, msecs_to_jiffies(100));
659
6b8d4a6a 660 return peer->chan;
18722c24
JR
661}
662
2e4d60cb 663static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)
18722c24 664{
18722c24 665 struct net_device *netdev;
c469c9c9 666 int err;
18722c24 667
2e4d60cb 668 netdev = alloc_netdev(LOWPAN_PRIV_SIZE(sizeof(struct lowpan_btle_dev)),
b72f6f51
AA
669 IFACE_NAME_TEMPLATE, NET_NAME_UNKNOWN,
670 netdev_setup);
18722c24
JR
671 if (!netdev)
672 return -ENOMEM;
673
c259d141
PF
674 netdev->addr_assign_type = NET_ADDR_PERM;
675 baswap((void *)netdev->dev_addr, &chan->src);
18722c24
JR
676
677 netdev->netdev_ops = &netdev_ops;
fc84242f 678 SET_NETDEV_DEV(netdev, &chan->conn->hcon->hdev->dev);
18722c24
JR
679 SET_NETDEV_DEVTYPE(netdev, &bt_type);
680
2e4d60cb 681 *dev = lowpan_btle_dev(netdev);
5857d1db
AA
682 (*dev)->netdev = netdev;
683 (*dev)->hdev = chan->conn->hcon->hdev;
684 INIT_LIST_HEAD(&(*dev)->peers);
685
686 spin_lock(&devices_lock);
687 INIT_LIST_HEAD(&(*dev)->list);
688 list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
689 spin_unlock(&devices_lock);
690
00f59314 691 err = lowpan_register_netdev(netdev, LOWPAN_LLTYPE_BTLE);
18722c24
JR
692 if (err < 0) {
693 BT_INFO("register_netdev failed %d", err);
5857d1db
AA
694 spin_lock(&devices_lock);
695 list_del_rcu(&(*dev)->list);
696 spin_unlock(&devices_lock);
18722c24
JR
697 free_netdev(netdev);
698 goto out;
699 }
700
6b8d4a6a
JR
701 BT_DBG("ifindex %d peer bdaddr %pMR type %d my addr %pMR type %d",
702 netdev->ifindex, &chan->dst, chan->dst_type,
703 &chan->src, chan->src_type);
18722c24
JR
704 set_bit(__LINK_STATE_PRESENT, &netdev->state);
705
6b8d4a6a 706 return 0;
18722c24
JR
707
708out:
709 return err;
710}
711
6b8d4a6a
JR
712static inline void chan_ready_cb(struct l2cap_chan *chan)
713{
2e4d60cb 714 struct lowpan_btle_dev *dev;
d2891c4d 715 bool new_netdev = false;
6b8d4a6a
JR
716
717 dev = lookup_dev(chan->conn);
718
719 BT_DBG("chan %p conn %p dev %p", chan, chan->conn, dev);
720
721 if (!dev) {
722 if (setup_netdev(chan, &dev) < 0) {
723 l2cap_chan_del(chan, -ENOENT);
724 return;
725 }
d2891c4d 726 new_netdev = true;
6b8d4a6a
JR
727 }
728
18d93c17
JR
729 if (!try_module_get(THIS_MODULE))
730 return;
731
d2891c4d 732 add_peer_chan(chan, dev, new_netdev);
6b8d4a6a
JR
733 ifup(dev->netdev);
734}
735
2b293490 736static inline struct l2cap_chan *chan_new_conn_cb(struct l2cap_chan *pchan)
6b8d4a6a 737{
2b293490 738 struct l2cap_chan *chan;
6b8d4a6a 739
630ef791
JH
740 chan = chan_create();
741 if (!chan)
742 return NULL;
743
2b293490 744 chan->ops = pchan->ops;
6b8d4a6a
JR
745
746 BT_DBG("chan %p pchan %p", chan, pchan);
747
2b293490 748 return chan;
6b8d4a6a
JR
749}
750
18722c24
JR
751static void delete_netdev(struct work_struct *work)
752{
2e4d60cb
AA
753 struct lowpan_btle_dev *entry = container_of(work,
754 struct lowpan_btle_dev,
755 delete_netdev);
18722c24 756
00f59314 757 lowpan_unregister_netdev(entry->netdev);
18722c24 758
2ad88fb2 759 /* The entry pointer is deleted by the netdev destructor. */
18722c24
JR
760}
761
6b8d4a6a 762static void chan_close_cb(struct l2cap_chan *chan)
18722c24 763{
2e4d60cb
AA
764 struct lowpan_btle_dev *entry;
765 struct lowpan_btle_dev *dev = NULL;
18722c24
JR
766 struct lowpan_peer *peer;
767 int err = -ENOENT;
f63666d2 768 bool last = false, remove = true;
18722c24 769
6b8d4a6a
JR
770 BT_DBG("chan %p conn %p", chan, chan->conn);
771
772 if (chan->conn && chan->conn->hcon) {
773 if (!is_bt_6lowpan(chan->conn->hcon))
774 return;
775
776 /* If conn is set, then the netdev is also there and we should
777 * not remove it.
778 */
f63666d2 779 remove = false;
6b8d4a6a 780 }
18722c24 781
90305829 782 spin_lock(&devices_lock);
18722c24 783
90305829 784 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
2e4d60cb 785 dev = lowpan_btle_dev(entry->netdev);
90305829 786 peer = __peer_lookup_chan(dev, chan);
18722c24
JR
787 if (peer) {
788 last = peer_del(dev, peer);
789 err = 0;
6b8d4a6a
JR
790
791 BT_DBG("dev %p removing %speer %p", dev,
792 last ? "last " : "1 ", peer);
658d5d80 793 BT_DBG("chan %p orig refcnt %u", chan,
2c935bc5 794 kref_read(&chan->kref));
6b8d4a6a
JR
795
796 l2cap_chan_put(chan);
18722c24
JR
797 break;
798 }
799 }
800
801 if (!err && last && dev && !atomic_read(&dev->peer_count)) {
90305829 802 spin_unlock(&devices_lock);
18722c24
JR
803
804 cancel_delayed_work_sync(&dev->notify_peers);
805
7f118253
JR
806 ifdown(dev->netdev);
807
f63666d2 808 if (remove) {
6b8d4a6a
JR
809 INIT_WORK(&entry->delete_netdev, delete_netdev);
810 schedule_work(&entry->delete_netdev);
811 }
18722c24 812 } else {
90305829 813 spin_unlock(&devices_lock);
18722c24 814 }
6b8d4a6a
JR
815}
816
817static void chan_state_change_cb(struct l2cap_chan *chan, int state, int err)
818{
819 BT_DBG("chan %p conn %p state %s err %d", chan, chan->conn,
820 state_to_string(state), err);
821}
822
823static struct sk_buff *chan_alloc_skb_cb(struct l2cap_chan *chan,
824 unsigned long hdr_len,
825 unsigned long len, int nb)
826{
827 /* Note that we must allocate using GFP_ATOMIC here as
828 * this function is called originally from netdev hard xmit
829 * function in atomic context.
830 */
831 return bt_skb_alloc(hdr_len + len, GFP_ATOMIC);
832}
833
834static void chan_suspend_cb(struct l2cap_chan *chan)
835{
f183e52b
LAD
836 struct lowpan_btle_dev *dev;
837
6dea44f5 838 BT_DBG("chan %p suspend", chan);
f183e52b
LAD
839
840 dev = lookup_dev(chan->conn);
841 if (!dev || !dev->netdev)
842 return;
843
844 netif_stop_queue(dev->netdev);
6b8d4a6a
JR
845}
846
847static void chan_resume_cb(struct l2cap_chan *chan)
848{
f183e52b
LAD
849 struct lowpan_btle_dev *dev;
850
6dea44f5 851 BT_DBG("chan %p resume", chan);
f183e52b
LAD
852
853 dev = lookup_dev(chan->conn);
854 if (!dev || !dev->netdev)
855 return;
856
857 netif_wake_queue(dev->netdev);
6b8d4a6a
JR
858}
859
860static long chan_get_sndtimeo_cb(struct l2cap_chan *chan)
861{
2ae50d8d 862 return L2CAP_CONN_TIMEOUT;
6b8d4a6a
JR
863}
864
865static const struct l2cap_ops bt_6lowpan_chan_ops = {
866 .name = "L2CAP 6LoWPAN channel",
867 .new_connection = chan_new_conn_cb,
868 .recv = chan_recv_cb,
869 .close = chan_close_cb,
870 .state_change = chan_state_change_cb,
871 .ready = chan_ready_cb,
872 .resume = chan_resume_cb,
873 .suspend = chan_suspend_cb,
874 .get_sndtimeo = chan_get_sndtimeo_cb,
875 .alloc_skb = chan_alloc_skb_cb,
6b8d4a6a
JR
876
877 .teardown = l2cap_chan_no_teardown,
878 .defer = l2cap_chan_no_defer,
879 .set_shutdown = l2cap_chan_no_set_shutdown,
880};
881
6b8d4a6a
JR
882static int bt_6lowpan_connect(bdaddr_t *addr, u8 dst_type)
883{
0cd088fc 884 struct l2cap_chan *chan;
6b8d4a6a
JR
885 int err;
886
26d46dff 887 chan = chan_create();
0cd088fc 888 if (!chan)
6b8d4a6a
JR
889 return -EINVAL;
890
26d46dff
JH
891 chan->ops = &bt_6lowpan_chan_ops;
892
0cd088fc 893 err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
6b8d4a6a
JR
894 addr, dst_type);
895
0cd088fc 896 BT_DBG("chan %p err %d", chan, err);
6b8d4a6a 897 if (err < 0)
0cd088fc 898 l2cap_chan_put(chan);
6b8d4a6a 899
18722c24
JR
900 return err;
901}
902
6b8d4a6a
JR
903static int bt_6lowpan_disconnect(struct l2cap_conn *conn, u8 dst_type)
904{
905 struct lowpan_peer *peer;
906
658d5d80 907 BT_DBG("conn %p dst type %u", conn, dst_type);
6b8d4a6a
JR
908
909 peer = lookup_peer(conn);
910 if (!peer)
911 return -ENOENT;
912
913 BT_DBG("peer %p chan %p", peer, peer->chan);
914
915 l2cap_chan_close(peer->chan, ENOENT);
916
917 return 0;
918}
919
920static struct l2cap_chan *bt_6lowpan_listen(void)
921{
922 bdaddr_t *addr = BDADDR_ANY;
0cd088fc 923 struct l2cap_chan *chan;
6b8d4a6a
JR
924 int err;
925
7b2ed60e 926 if (!enable_6lowpan)
6b8d4a6a
JR
927 return NULL;
928
26d46dff 929 chan = chan_create();
0cd088fc 930 if (!chan)
6b8d4a6a
JR
931 return NULL;
932
26d46dff 933 chan->ops = &bt_6lowpan_chan_ops;
0cd088fc
JH
934 chan->state = BT_LISTEN;
935 chan->src_type = BDADDR_LE_PUBLIC;
6b8d4a6a 936
0cd088fc 937 atomic_set(&chan->nesting, L2CAP_NESTING_PARENT);
2773b024 938
658d5d80 939 BT_DBG("chan %p src type %u", chan, chan->src_type);
6b8d4a6a 940
0cd088fc 941 err = l2cap_add_psm(chan, addr, cpu_to_le16(L2CAP_PSM_IPSP));
6b8d4a6a 942 if (err) {
0cd088fc 943 l2cap_chan_put(chan);
6b8d4a6a
JR
944 BT_ERR("psm cannot be added err %d", err);
945 return NULL;
946 }
947
0cd088fc 948 return chan;
6b8d4a6a
JR
949}
950
951static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
952 struct l2cap_conn **conn)
953{
954 struct hci_conn *hcon;
955 struct hci_dev *hdev;
6b8d4a6a
JR
956 int n;
957
958 n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu",
959 &addr->b[5], &addr->b[4], &addr->b[3],
960 &addr->b[2], &addr->b[1], &addr->b[0],
961 addr_type);
962
963 if (n < 7)
964 return -EINVAL;
965
39385cb5
JH
966 /* The LE_PUBLIC address type is ignored because of BDADDR_ANY */
967 hdev = hci_get_route(addr, BDADDR_ANY, BDADDR_LE_PUBLIC);
6b8d4a6a
JR
968 if (!hdev)
969 return -ENOENT;
970
971 hci_dev_lock(hdev);
f5ad4ffc 972 hcon = hci_conn_hash_lookup_le(hdev, addr, *addr_type);
6b8d4a6a
JR
973 hci_dev_unlock(hdev);
974
975 if (!hcon)
976 return -ENOENT;
977
978 *conn = (struct l2cap_conn *)hcon->l2cap_data;
979
658d5d80 980 BT_DBG("conn %p dst %pMR type %u", *conn, &hcon->dst, hcon->dst_type);
6b8d4a6a
JR
981
982 return 0;
983}
984
985static void disconnect_all_peers(void)
986{
2e4d60cb 987 struct lowpan_btle_dev *entry;
6b8d4a6a
JR
988 struct lowpan_peer *peer, *tmp_peer, *new_peer;
989 struct list_head peers;
6b8d4a6a
JR
990
991 INIT_LIST_HEAD(&peers);
992
993 /* We make a separate list of peers as the close_cb() will
994 * modify the device peers list so it is better not to mess
995 * with the same list at the same time.
996 */
997
90305829 998 rcu_read_lock();
6b8d4a6a 999
90305829
JR
1000 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
1001 list_for_each_entry_rcu(peer, &entry->peers, list) {
6b8d4a6a
JR
1002 new_peer = kmalloc(sizeof(*new_peer), GFP_ATOMIC);
1003 if (!new_peer)
1004 break;
1005
1006 new_peer->chan = peer->chan;
1007 INIT_LIST_HEAD(&new_peer->list);
1008
1009 list_add(&new_peer->list, &peers);
1010 }
1011 }
1012
90305829 1013 rcu_read_unlock();
6b8d4a6a 1014
90305829 1015 spin_lock(&devices_lock);
6b8d4a6a
JR
1016 list_for_each_entry_safe(peer, tmp_peer, &peers, list) {
1017 l2cap_chan_close(peer->chan, ENOENT);
90305829
JR
1018
1019 list_del_rcu(&peer->list);
4e790226 1020 kfree_rcu(peer, rcu);
6b8d4a6a 1021 }
90305829 1022 spin_unlock(&devices_lock);
6b8d4a6a
JR
1023}
1024
7b2ed60e 1025struct set_enable {
90305829 1026 struct work_struct work;
7b2ed60e 1027 bool flag;
90305829 1028};
6b8d4a6a 1029
7b2ed60e 1030static void do_enable_set(struct work_struct *work)
90305829 1031{
7b2ed60e
JR
1032 struct set_enable *set_enable = container_of(work,
1033 struct set_enable, work);
90305829 1034
7b2ed60e 1035 if (!set_enable->flag || enable_6lowpan != set_enable->flag)
6b8d4a6a 1036 /* Disconnect existing connections if 6lowpan is
7b2ed60e 1037 * disabled
6b8d4a6a
JR
1038 */
1039 disconnect_all_peers();
1040
7b2ed60e 1041 enable_6lowpan = set_enable->flag;
6b8d4a6a 1042
f9c70bdc 1043 mutex_lock(&set_lock);
6b8d4a6a
JR
1044 if (listen_chan) {
1045 l2cap_chan_close(listen_chan, 0);
1046 l2cap_chan_put(listen_chan);
1047 }
1048
1049 listen_chan = bt_6lowpan_listen();
f9c70bdc 1050 mutex_unlock(&set_lock);
6b8d4a6a 1051
7b2ed60e 1052 kfree(set_enable);
90305829
JR
1053}
1054
7b2ed60e 1055static int lowpan_enable_set(void *data, u64 val)
90305829 1056{
7b2ed60e 1057 struct set_enable *set_enable;
90305829 1058
7b2ed60e
JR
1059 set_enable = kzalloc(sizeof(*set_enable), GFP_KERNEL);
1060 if (!set_enable)
90305829
JR
1061 return -ENOMEM;
1062
7b2ed60e
JR
1063 set_enable->flag = !!val;
1064 INIT_WORK(&set_enable->work, do_enable_set);
90305829 1065
7b2ed60e 1066 schedule_work(&set_enable->work);
90305829 1067
6b8d4a6a
JR
1068 return 0;
1069}
1070
7b2ed60e 1071static int lowpan_enable_get(void *data, u64 *val)
6b8d4a6a 1072{
7b2ed60e 1073 *val = enable_6lowpan;
6b8d4a6a
JR
1074 return 0;
1075}
1076
e250fab6
Y
1077DEFINE_DEBUGFS_ATTRIBUTE(lowpan_enable_fops, lowpan_enable_get,
1078 lowpan_enable_set, "%llu\n");
6b8d4a6a
JR
1079
1080static ssize_t lowpan_control_write(struct file *fp,
1081 const char __user *user_buffer,
1082 size_t count,
1083 loff_t *position)
1084{
1085 char buf[32];
1086 size_t buf_size = min(count, sizeof(buf) - 1);
1087 int ret;
1088 bdaddr_t addr;
1089 u8 addr_type;
1090 struct l2cap_conn *conn = NULL;
1091
1092 if (copy_from_user(buf, user_buffer, buf_size))
1093 return -EFAULT;
1094
1095 buf[buf_size] = '\0';
1096
1097 if (memcmp(buf, "connect ", 8) == 0) {
1098 ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn);
1099 if (ret == -EINVAL)
1100 return ret;
1101
f9c70bdc 1102 mutex_lock(&set_lock);
6b8d4a6a
JR
1103 if (listen_chan) {
1104 l2cap_chan_close(listen_chan, 0);
1105 l2cap_chan_put(listen_chan);
1106 listen_chan = NULL;
1107 }
f9c70bdc 1108 mutex_unlock(&set_lock);
6b8d4a6a
JR
1109
1110 if (conn) {
1111 struct lowpan_peer *peer;
1112
1113 if (!is_bt_6lowpan(conn->hcon))
1114 return -EINVAL;
1115
1116 peer = lookup_peer(conn);
1117 if (peer) {
1118 BT_DBG("6LoWPAN connection already exists");
1119 return -EALREADY;
1120 }
1121
658d5d80 1122 BT_DBG("conn %p dst %pMR type %d user %u", conn,
6b8d4a6a
JR
1123 &conn->hcon->dst, conn->hcon->dst_type,
1124 addr_type);
1125 }
1126
1127 ret = bt_6lowpan_connect(&addr, addr_type);
1128 if (ret < 0)
1129 return ret;
1130
1131 return count;
1132 }
1133
1134 if (memcmp(buf, "disconnect ", 11) == 0) {
1135 ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn);
1136 if (ret < 0)
1137 return ret;
1138
1139 ret = bt_6lowpan_disconnect(conn, addr_type);
1140 if (ret < 0)
1141 return ret;
1142
1143 return count;
1144 }
1145
1146 return count;
1147}
1148
1149static int lowpan_control_show(struct seq_file *f, void *ptr)
1150{
2e4d60cb 1151 struct lowpan_btle_dev *entry;
90305829 1152 struct lowpan_peer *peer;
6b8d4a6a 1153
90305829 1154 spin_lock(&devices_lock);
6b8d4a6a 1155
90305829
JR
1156 list_for_each_entry(entry, &bt_6lowpan_devices, list) {
1157 list_for_each_entry(peer, &entry->peers, list)
6b8d4a6a
JR
1158 seq_printf(f, "%pMR (type %u)\n",
1159 &peer->chan->dst, peer->chan->dst_type);
1160 }
1161
90305829 1162 spin_unlock(&devices_lock);
6b8d4a6a
JR
1163
1164 return 0;
1165}
1166
1167static int lowpan_control_open(struct inode *inode, struct file *file)
1168{
1169 return single_open(file, lowpan_control_show, inode->i_private);
1170}
1171
1172static const struct file_operations lowpan_control_fops = {
1173 .open = lowpan_control_open,
1174 .read = seq_read,
1175 .write = lowpan_control_write,
1176 .llseek = seq_lseek,
1177 .release = single_release,
1178};
1179
7f118253
JR
1180static void disconnect_devices(void)
1181{
2e4d60cb 1182 struct lowpan_btle_dev *entry, *tmp, *new_dev;
7f118253 1183 struct list_head devices;
7f118253
JR
1184
1185 INIT_LIST_HEAD(&devices);
1186
1187 /* We make a separate list of devices because the unregister_netdev()
1188 * will call device_event() which will also want to modify the same
1189 * devices list.
1190 */
1191
90305829 1192 rcu_read_lock();
7f118253 1193
90305829 1194 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
7f118253
JR
1195 new_dev = kmalloc(sizeof(*new_dev), GFP_ATOMIC);
1196 if (!new_dev)
1197 break;
1198
1199 new_dev->netdev = entry->netdev;
1200 INIT_LIST_HEAD(&new_dev->list);
1201
90305829 1202 list_add_rcu(&new_dev->list, &devices);
7f118253
JR
1203 }
1204
90305829 1205 rcu_read_unlock();
7f118253 1206
daac197c 1207 list_for_each_entry_safe(entry, tmp, &devices, list) {
7f118253
JR
1208 ifdown(entry->netdev);
1209 BT_DBG("Unregistering netdev %s %p",
1210 entry->netdev->name, entry->netdev);
00f59314 1211 lowpan_unregister_netdev(entry->netdev);
7f118253
JR
1212 kfree(entry);
1213 }
1214}
1215
18722c24
JR
1216static int device_event(struct notifier_block *unused,
1217 unsigned long event, void *ptr)
1218{
1219 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
2e4d60cb 1220 struct lowpan_btle_dev *entry;
18722c24
JR
1221
1222 if (netdev->type != ARPHRD_6LOWPAN)
1223 return NOTIFY_DONE;
1224
1225 switch (event) {
1226 case NETDEV_UNREGISTER:
90305829
JR
1227 spin_lock(&devices_lock);
1228 list_for_each_entry(entry, &bt_6lowpan_devices, list) {
18722c24 1229 if (entry->netdev == netdev) {
7f118253
JR
1230 BT_DBG("Unregistered netdev %s %p",
1231 netdev->name, netdev);
18722c24 1232 list_del(&entry->list);
18722c24
JR
1233 break;
1234 }
1235 }
90305829 1236 spin_unlock(&devices_lock);
18722c24
JR
1237 break;
1238 }
1239
1240 return NOTIFY_DONE;
1241}
1242
1243static struct notifier_block bt_6lowpan_dev_notifier = {
1244 .notifier_call = device_event,
1245};
1246
5547e48c 1247static int __init bt_6lowpan_init(void)
18722c24 1248{
e250fab6
Y
1249 lowpan_enable_debugfs = debugfs_create_file_unsafe("6lowpan_enable",
1250 0644, bt_debugfs,
1251 NULL,
1252 &lowpan_enable_fops);
6b8d4a6a
JR
1253 lowpan_control_debugfs = debugfs_create_file("6lowpan_control", 0644,
1254 bt_debugfs, NULL,
1255 &lowpan_control_fops);
1256
18722c24
JR
1257 return register_netdevice_notifier(&bt_6lowpan_dev_notifier);
1258}
1259
5547e48c 1260static void __exit bt_6lowpan_exit(void)
18722c24 1261{
7b2ed60e 1262 debugfs_remove(lowpan_enable_debugfs);
6b8d4a6a
JR
1263 debugfs_remove(lowpan_control_debugfs);
1264
1265 if (listen_chan) {
1266 l2cap_chan_close(listen_chan, 0);
1267 l2cap_chan_put(listen_chan);
1268 }
1269
7f118253
JR
1270 disconnect_devices();
1271
18722c24
JR
1272 unregister_netdevice_notifier(&bt_6lowpan_dev_notifier);
1273}
5547e48c
JR
1274
1275module_init(bt_6lowpan_init);
1276module_exit(bt_6lowpan_exit);
1277
1278MODULE_AUTHOR("Jukka Rissanen <jukka.rissanen@linux.intel.com>");
1279MODULE_DESCRIPTION("Bluetooth 6LoWPAN");
1280MODULE_VERSION(VERSION);
1281MODULE_LICENSE("GPL");