6lowpan.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. /*
  2. Copyright (c) 2013-2014 Intel Corp.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License version 2 and
  5. only version 2 as published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. */
  11. #include <linux/if_arp.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/module.h>
  15. #include <linux/debugfs.h>
  16. #include <net/ipv6.h>
  17. #include <net/ip6_route.h>
  18. #include <net/addrconf.h>
  19. #include <net/af_ieee802154.h> /* to get the address type */
  20. #include <net/bluetooth/bluetooth.h>
  21. #include <net/bluetooth/hci_core.h>
  22. #include <net/bluetooth/l2cap.h>
  23. #include <net/6lowpan.h> /* for the compression support */
  24. #define VERSION "0.1"
  25. static struct dentry *lowpan_psm_debugfs;
  26. static struct dentry *lowpan_control_debugfs;
  27. #define IFACE_NAME_TEMPLATE "bt%d"
  28. #define EUI64_ADDR_LEN 8
  29. struct skb_cb {
  30. struct in6_addr addr;
  31. struct in6_addr gw;
  32. struct l2cap_chan *chan;
  33. int status;
  34. };
  35. #define lowpan_cb(skb) ((struct skb_cb *)((skb)->cb))
  36. /* The devices list contains those devices that we are acting
  37. * as a proxy. The BT 6LoWPAN device is a virtual device that
  38. * connects to the Bluetooth LE device. The real connection to
  39. * BT device is done via l2cap layer. There exists one
  40. * virtual device / one BT 6LoWPAN network (=hciX device).
  41. * The list contains struct lowpan_dev elements.
  42. */
  43. static LIST_HEAD(bt_6lowpan_devices);
  44. static DEFINE_RWLOCK(devices_lock);
  45. /* If psm is set to 0 (default value), then 6lowpan is disabled.
  46. * Other values are used to indicate a Protocol Service Multiplexer
  47. * value for 6lowpan.
  48. */
  49. static u16 psm_6lowpan;
  50. /* We are listening incoming connections via this channel
  51. */
  52. static struct l2cap_chan *listen_chan;
  53. struct lowpan_peer {
  54. struct list_head list;
  55. struct l2cap_chan *chan;
  56. /* peer addresses in various formats */
  57. unsigned char eui64_addr[EUI64_ADDR_LEN];
  58. struct in6_addr peer_addr;
  59. };
  60. struct lowpan_dev {
  61. struct list_head list;
  62. struct hci_dev *hdev;
  63. struct net_device *netdev;
  64. struct list_head peers;
  65. atomic_t peer_count; /* number of items in peers list */
  66. struct work_struct delete_netdev;
  67. struct delayed_work notify_peers;
  68. };
  69. static inline struct lowpan_dev *lowpan_dev(const struct net_device *netdev)
  70. {
  71. return netdev_priv(netdev);
  72. }
  73. static inline void peer_add(struct lowpan_dev *dev, struct lowpan_peer *peer)
  74. {
  75. list_add(&peer->list, &dev->peers);
  76. atomic_inc(&dev->peer_count);
  77. }
  78. static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer)
  79. {
  80. list_del(&peer->list);
  81. module_put(THIS_MODULE);
  82. if (atomic_dec_and_test(&dev->peer_count)) {
  83. BT_DBG("last peer");
  84. return true;
  85. }
  86. return false;
  87. }
  88. static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_dev *dev,
  89. bdaddr_t *ba, __u8 type)
  90. {
  91. struct lowpan_peer *peer, *tmp;
  92. BT_DBG("peers %d addr %pMR type %d", atomic_read(&dev->peer_count),
  93. ba, type);
  94. list_for_each_entry_safe(peer, tmp, &dev->peers, list) {
  95. BT_DBG("dst addr %pMR dst type %d",
  96. &peer->chan->dst, peer->chan->dst_type);
  97. if (bacmp(&peer->chan->dst, ba))
  98. continue;
  99. if (type == peer->chan->dst_type)
  100. return peer;
  101. }
  102. return NULL;
  103. }
  104. static inline struct lowpan_peer *peer_lookup_chan(struct lowpan_dev *dev,
  105. struct l2cap_chan *chan)
  106. {
  107. struct lowpan_peer *peer, *tmp;
  108. list_for_each_entry_safe(peer, tmp, &dev->peers, list) {
  109. if (peer->chan == chan)
  110. return peer;
  111. }
  112. return NULL;
  113. }
  114. static inline struct lowpan_peer *peer_lookup_conn(struct lowpan_dev *dev,
  115. struct l2cap_conn *conn)
  116. {
  117. struct lowpan_peer *peer, *tmp;
  118. list_for_each_entry_safe(peer, tmp, &dev->peers, list) {
  119. if (peer->chan->conn == conn)
  120. return peer;
  121. }
  122. return NULL;
  123. }
  124. static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
  125. struct in6_addr *daddr,
  126. struct sk_buff *skb)
  127. {
  128. struct lowpan_peer *peer, *tmp;
  129. struct in6_addr *nexthop;
  130. struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
  131. int count = atomic_read(&dev->peer_count);
  132. BT_DBG("peers %d addr %pI6c rt %p", count, daddr, rt);
  133. /* If we have multiple 6lowpan peers, then check where we should
  134. * send the packet. If only one peer exists, then we can send the
  135. * packet right away.
  136. */
  137. if (count == 1)
  138. return list_first_entry(&dev->peers, struct lowpan_peer,
  139. list);
  140. if (!rt) {
  141. nexthop = &lowpan_cb(skb)->gw;
  142. if (ipv6_addr_any(nexthop))
  143. return NULL;
  144. } else {
  145. nexthop = rt6_nexthop(rt);
  146. /* We need to remember the address because it is needed
  147. * by bt_xmit() when sending the packet. In bt_xmit(), the
  148. * destination routing info is not set.
  149. */
  150. memcpy(&lowpan_cb(skb)->gw, nexthop, sizeof(struct in6_addr));
  151. }
  152. BT_DBG("gw %pI6c", nexthop);
  153. list_for_each_entry_safe(peer, tmp, &dev->peers, list) {
  154. BT_DBG("dst addr %pMR dst type %d ip %pI6c",
  155. &peer->chan->dst, peer->chan->dst_type,
  156. &peer->peer_addr);
  157. if (!ipv6_addr_cmp(&peer->peer_addr, nexthop))
  158. return peer;
  159. }
  160. return NULL;
  161. }
  162. static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn)
  163. {
  164. struct lowpan_dev *entry, *tmp;
  165. struct lowpan_peer *peer = NULL;
  166. unsigned long flags;
  167. read_lock_irqsave(&devices_lock, flags);
  168. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
  169. peer = peer_lookup_conn(entry, conn);
  170. if (peer)
  171. break;
  172. }
  173. read_unlock_irqrestore(&devices_lock, flags);
  174. return peer;
  175. }
  176. static struct lowpan_dev *lookup_dev(struct l2cap_conn *conn)
  177. {
  178. struct lowpan_dev *entry, *tmp;
  179. struct lowpan_dev *dev = NULL;
  180. unsigned long flags;
  181. read_lock_irqsave(&devices_lock, flags);
  182. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
  183. if (conn->hcon->hdev == entry->hdev) {
  184. dev = entry;
  185. break;
  186. }
  187. }
  188. read_unlock_irqrestore(&devices_lock, flags);
  189. return dev;
  190. }
  191. static int give_skb_to_upper(struct sk_buff *skb, struct net_device *dev)
  192. {
  193. struct sk_buff *skb_cp;
  194. int ret;
  195. skb_cp = skb_copy(skb, GFP_ATOMIC);
  196. if (!skb_cp)
  197. return -ENOMEM;
  198. ret = netif_rx(skb_cp);
  199. if (ret < 0) {
  200. BT_DBG("receive skb %d", ret);
  201. return NET_RX_DROP;
  202. }
  203. return ret;
  204. }
  205. static int process_data(struct sk_buff *skb, struct net_device *netdev,
  206. struct l2cap_chan *chan)
  207. {
  208. const u8 *saddr, *daddr;
  209. u8 iphc0, iphc1;
  210. struct lowpan_dev *dev;
  211. struct lowpan_peer *peer;
  212. unsigned long flags;
  213. dev = lowpan_dev(netdev);
  214. read_lock_irqsave(&devices_lock, flags);
  215. peer = peer_lookup_chan(dev, chan);
  216. read_unlock_irqrestore(&devices_lock, flags);
  217. if (!peer)
  218. goto drop;
  219. saddr = peer->eui64_addr;
  220. daddr = dev->netdev->dev_addr;
  221. /* at least two bytes will be used for the encoding */
  222. if (skb->len < 2)
  223. goto drop;
  224. if (lowpan_fetch_skb_u8(skb, &iphc0))
  225. goto drop;
  226. if (lowpan_fetch_skb_u8(skb, &iphc1))
  227. goto drop;
  228. return lowpan_process_data(skb, netdev,
  229. saddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN,
  230. daddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN,
  231. iphc0, iphc1, give_skb_to_upper);
  232. drop:
  233. kfree_skb(skb);
  234. return -EINVAL;
  235. }
  236. static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
  237. struct l2cap_chan *chan)
  238. {
  239. struct sk_buff *local_skb;
  240. int ret;
  241. if (!netif_running(dev))
  242. goto drop;
  243. if (dev->type != ARPHRD_6LOWPAN)
  244. goto drop;
  245. /* check that it's our buffer */
  246. if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
  247. /* Copy the packet so that the IPv6 header is
  248. * properly aligned.
  249. */
  250. local_skb = skb_copy_expand(skb, NET_SKB_PAD - 1,
  251. skb_tailroom(skb), GFP_ATOMIC);
  252. if (!local_skb)
  253. goto drop;
  254. local_skb->protocol = htons(ETH_P_IPV6);
  255. local_skb->pkt_type = PACKET_HOST;
  256. skb_reset_network_header(local_skb);
  257. skb_set_transport_header(local_skb, sizeof(struct ipv6hdr));
  258. if (give_skb_to_upper(local_skb, dev) != NET_RX_SUCCESS) {
  259. kfree_skb(local_skb);
  260. goto drop;
  261. }
  262. dev->stats.rx_bytes += skb->len;
  263. dev->stats.rx_packets++;
  264. kfree_skb(local_skb);
  265. kfree_skb(skb);
  266. } else {
  267. switch (skb->data[0] & 0xe0) {
  268. case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */
  269. local_skb = skb_clone(skb, GFP_ATOMIC);
  270. if (!local_skb)
  271. goto drop;
  272. ret = process_data(local_skb, dev, chan);
  273. if (ret != NET_RX_SUCCESS)
  274. goto drop;
  275. dev->stats.rx_bytes += skb->len;
  276. dev->stats.rx_packets++;
  277. kfree_skb(skb);
  278. break;
  279. default:
  280. break;
  281. }
  282. }
  283. return NET_RX_SUCCESS;
  284. drop:
  285. dev->stats.rx_dropped++;
  286. kfree_skb(skb);
  287. return NET_RX_DROP;
  288. }
  289. /* Packet from BT LE device */
  290. static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
  291. {
  292. struct lowpan_dev *dev;
  293. struct lowpan_peer *peer;
  294. int err;
  295. peer = lookup_peer(chan->conn);
  296. if (!peer)
  297. return -ENOENT;
  298. dev = lookup_dev(chan->conn);
  299. if (!dev || !dev->netdev)
  300. return -ENOENT;
  301. err = recv_pkt(skb, dev->netdev, chan);
  302. if (err) {
  303. BT_DBG("recv pkt %d", err);
  304. err = -EAGAIN;
  305. }
  306. return err;
  307. }
  308. static u8 get_addr_type_from_eui64(u8 byte)
  309. {
  310. /* Is universal(0) or local(1) bit */
  311. return ((byte & 0x02) ? BDADDR_LE_RANDOM : BDADDR_LE_PUBLIC);
  312. }
  313. static void copy_to_bdaddr(struct in6_addr *ip6_daddr, bdaddr_t *addr)
  314. {
  315. u8 *eui64 = ip6_daddr->s6_addr + 8;
  316. addr->b[0] = eui64[7];
  317. addr->b[1] = eui64[6];
  318. addr->b[2] = eui64[5];
  319. addr->b[3] = eui64[2];
  320. addr->b[4] = eui64[1];
  321. addr->b[5] = eui64[0];
  322. }
  323. static void convert_dest_bdaddr(struct in6_addr *ip6_daddr,
  324. bdaddr_t *addr, u8 *addr_type)
  325. {
  326. copy_to_bdaddr(ip6_daddr, addr);
  327. /* We need to toggle the U/L bit that we got from IPv6 address
  328. * so that we get the proper address and type of the BD address.
  329. */
  330. addr->b[5] ^= 0x02;
  331. *addr_type = get_addr_type_from_eui64(addr->b[5]);
  332. }
  333. static int setup_header(struct sk_buff *skb, struct net_device *netdev,
  334. bdaddr_t *peer_addr, u8 *peer_addr_type)
  335. {
  336. struct in6_addr ipv6_daddr;
  337. struct lowpan_dev *dev;
  338. struct lowpan_peer *peer;
  339. bdaddr_t addr, *any = BDADDR_ANY;
  340. u8 *daddr = any->b;
  341. int err, status = 0;
  342. dev = lowpan_dev(netdev);
  343. memcpy(&ipv6_daddr, &lowpan_cb(skb)->addr, sizeof(ipv6_daddr));
  344. if (ipv6_addr_is_multicast(&ipv6_daddr)) {
  345. lowpan_cb(skb)->chan = NULL;
  346. } else {
  347. unsigned long flags;
  348. u8 addr_type;
  349. /* Get destination BT device from skb.
  350. * If there is no such peer then discard the packet.
  351. */
  352. convert_dest_bdaddr(&ipv6_daddr, &addr, &addr_type);
  353. BT_DBG("dest addr %pMR type %d IP %pI6c", &addr,
  354. addr_type, &ipv6_daddr);
  355. read_lock_irqsave(&devices_lock, flags);
  356. peer = peer_lookup_ba(dev, &addr, addr_type);
  357. read_unlock_irqrestore(&devices_lock, flags);
  358. if (!peer) {
  359. /* The packet might be sent to 6lowpan interface
  360. * because of routing (either via default route
  361. * or user set route) so get peer according to
  362. * the destination address.
  363. */
  364. read_lock_irqsave(&devices_lock, flags);
  365. peer = peer_lookup_dst(dev, &ipv6_daddr, skb);
  366. read_unlock_irqrestore(&devices_lock, flags);
  367. if (!peer) {
  368. BT_DBG("no such peer %pMR found", &addr);
  369. return -ENOENT;
  370. }
  371. }
  372. daddr = peer->eui64_addr;
  373. *peer_addr = addr;
  374. *peer_addr_type = addr_type;
  375. lowpan_cb(skb)->chan = peer->chan;
  376. status = 1;
  377. }
  378. lowpan_header_compress(skb, netdev, ETH_P_IPV6, daddr,
  379. dev->netdev->dev_addr, skb->len);
  380. err = dev_hard_header(skb, netdev, ETH_P_IPV6, NULL, NULL, 0);
  381. if (err < 0)
  382. return err;
  383. return status;
  384. }
  385. static int header_create(struct sk_buff *skb, struct net_device *netdev,
  386. unsigned short type, const void *_daddr,
  387. const void *_saddr, unsigned int len)
  388. {
  389. struct ipv6hdr *hdr;
  390. if (type != ETH_P_IPV6)
  391. return -EINVAL;
  392. hdr = ipv6_hdr(skb);
  393. memcpy(&lowpan_cb(skb)->addr, &hdr->daddr, sizeof(struct in6_addr));
  394. return 0;
  395. }
  396. /* Packet to BT LE device */
  397. static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb,
  398. struct net_device *netdev)
  399. {
  400. struct msghdr msg;
  401. struct kvec iv;
  402. int err;
  403. /* Remember the skb so that we can send EAGAIN to the caller if
  404. * we run out of credits.
  405. */
  406. chan->data = skb;
  407. memset(&msg, 0, sizeof(msg));
  408. msg.msg_iov = (struct iovec *) &iv;
  409. msg.msg_iovlen = 1;
  410. iv.iov_base = skb->data;
  411. iv.iov_len = skb->len;
  412. err = l2cap_chan_send(chan, &msg, skb->len);
  413. if (err > 0) {
  414. netdev->stats.tx_bytes += err;
  415. netdev->stats.tx_packets++;
  416. return 0;
  417. }
  418. if (!err)
  419. err = lowpan_cb(skb)->status;
  420. if (err < 0) {
  421. if (err == -EAGAIN)
  422. netdev->stats.tx_dropped++;
  423. else
  424. netdev->stats.tx_errors++;
  425. }
  426. return err;
  427. }
  428. static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
  429. {
  430. struct sk_buff *local_skb;
  431. struct lowpan_dev *entry, *tmp;
  432. unsigned long flags;
  433. int err = 0;
  434. read_lock_irqsave(&devices_lock, flags);
  435. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
  436. struct lowpan_peer *pentry, *ptmp;
  437. struct lowpan_dev *dev;
  438. if (entry->netdev != netdev)
  439. continue;
  440. dev = lowpan_dev(entry->netdev);
  441. list_for_each_entry_safe(pentry, ptmp, &dev->peers, list) {
  442. int ret;
  443. local_skb = skb_clone(skb, GFP_ATOMIC);
  444. BT_DBG("xmit %s to %pMR type %d IP %pI6c chan %p",
  445. netdev->name,
  446. &pentry->chan->dst, pentry->chan->dst_type,
  447. &pentry->peer_addr, pentry->chan);
  448. ret = send_pkt(pentry->chan, local_skb, netdev);
  449. if (ret < 0)
  450. err = ret;
  451. kfree_skb(local_skb);
  452. }
  453. }
  454. read_unlock_irqrestore(&devices_lock, flags);
  455. return err;
  456. }
  457. static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
  458. {
  459. int err = 0;
  460. bdaddr_t addr;
  461. u8 addr_type;
  462. struct sk_buff *tmpskb;
  463. /* We must take a copy of the skb before we modify/replace the ipv6
  464. * header as the header could be used elsewhere
  465. */
  466. tmpskb = skb_unshare(skb, GFP_ATOMIC);
  467. if (!tmpskb) {
  468. kfree_skb(skb);
  469. return NET_XMIT_DROP;
  470. }
  471. skb = tmpskb;
  472. /* Return values from setup_header()
  473. * <0 - error, packet is dropped
  474. * 0 - this is a multicast packet
  475. * 1 - this is unicast packet
  476. */
  477. err = setup_header(skb, netdev, &addr, &addr_type);
  478. if (err < 0) {
  479. kfree_skb(skb);
  480. return NET_XMIT_DROP;
  481. }
  482. if (err) {
  483. if (lowpan_cb(skb)->chan) {
  484. BT_DBG("xmit %s to %pMR type %d IP %pI6c chan %p",
  485. netdev->name, &addr, addr_type,
  486. &lowpan_cb(skb)->addr, lowpan_cb(skb)->chan);
  487. err = send_pkt(lowpan_cb(skb)->chan, skb, netdev);
  488. } else {
  489. err = -ENOENT;
  490. }
  491. } else {
  492. /* We need to send the packet to every device behind this
  493. * interface.
  494. */
  495. err = send_mcast_pkt(skb, netdev);
  496. }
  497. dev_kfree_skb(skb);
  498. if (err)
  499. BT_DBG("ERROR: xmit failed (%d)", err);
  500. return err < 0 ? NET_XMIT_DROP : err;
  501. }
  502. static const struct net_device_ops netdev_ops = {
  503. .ndo_start_xmit = bt_xmit,
  504. };
  505. static struct header_ops header_ops = {
  506. .create = header_create,
  507. };
  508. static void netdev_setup(struct net_device *dev)
  509. {
  510. dev->addr_len = EUI64_ADDR_LEN;
  511. dev->type = ARPHRD_6LOWPAN;
  512. dev->hard_header_len = 0;
  513. dev->needed_tailroom = 0;
  514. dev->mtu = IPV6_MIN_MTU;
  515. dev->tx_queue_len = 0;
  516. dev->flags = IFF_RUNNING | IFF_POINTOPOINT |
  517. IFF_MULTICAST;
  518. dev->watchdog_timeo = 0;
  519. dev->netdev_ops = &netdev_ops;
  520. dev->header_ops = &header_ops;
  521. dev->destructor = free_netdev;
  522. }
  523. static struct device_type bt_type = {
  524. .name = "bluetooth",
  525. };
  526. static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
  527. {
  528. /* addr is the BT address in little-endian format */
  529. eui[0] = addr[5];
  530. eui[1] = addr[4];
  531. eui[2] = addr[3];
  532. eui[3] = 0xFF;
  533. eui[4] = 0xFE;
  534. eui[5] = addr[2];
  535. eui[6] = addr[1];
  536. eui[7] = addr[0];
  537. /* Universal/local bit set, BT 6lowpan draft ch. 3.2.1 */
  538. if (addr_type == BDADDR_LE_PUBLIC)
  539. eui[0] &= ~0x02;
  540. else
  541. eui[0] |= 0x02;
  542. BT_DBG("type %d addr %*phC", addr_type, 8, eui);
  543. }
  544. static void set_dev_addr(struct net_device *netdev, bdaddr_t *addr,
  545. u8 addr_type)
  546. {
  547. netdev->addr_assign_type = NET_ADDR_PERM;
  548. set_addr(netdev->dev_addr, addr->b, addr_type);
  549. }
  550. static void ifup(struct net_device *netdev)
  551. {
  552. int err;
  553. rtnl_lock();
  554. err = dev_open(netdev);
  555. if (err < 0)
  556. BT_INFO("iface %s cannot be opened (%d)", netdev->name, err);
  557. rtnl_unlock();
  558. }
  559. static void ifdown(struct net_device *netdev)
  560. {
  561. int err;
  562. rtnl_lock();
  563. err = dev_close(netdev);
  564. if (err < 0)
  565. BT_INFO("iface %s cannot be closed (%d)", netdev->name, err);
  566. rtnl_unlock();
  567. }
  568. static void do_notify_peers(struct work_struct *work)
  569. {
  570. struct lowpan_dev *dev = container_of(work, struct lowpan_dev,
  571. notify_peers.work);
  572. netdev_notify_peers(dev->netdev); /* send neighbour adv at startup */
  573. }
  574. static bool is_bt_6lowpan(struct hci_conn *hcon)
  575. {
  576. if (hcon->type != LE_LINK)
  577. return false;
  578. if (!psm_6lowpan)
  579. return false;
  580. return true;
  581. }
  582. static struct l2cap_chan *chan_create(void)
  583. {
  584. struct l2cap_chan *chan;
  585. chan = l2cap_chan_create();
  586. if (!chan)
  587. return NULL;
  588. l2cap_chan_set_defaults(chan);
  589. chan->chan_type = L2CAP_CHAN_CONN_ORIENTED;
  590. chan->mode = L2CAP_MODE_LE_FLOWCTL;
  591. chan->omtu = 65535;
  592. chan->imtu = chan->omtu;
  593. return chan;
  594. }
  595. static struct l2cap_chan *chan_open(struct l2cap_chan *pchan)
  596. {
  597. struct l2cap_chan *chan;
  598. chan = chan_create();
  599. if (!chan)
  600. return NULL;
  601. chan->remote_mps = chan->omtu;
  602. chan->mps = chan->omtu;
  603. chan->state = BT_CONNECTED;
  604. return chan;
  605. }
  606. static void set_ip_addr_bits(u8 addr_type, u8 *addr)
  607. {
  608. if (addr_type == BDADDR_LE_PUBLIC)
  609. *addr |= 0x02;
  610. else
  611. *addr &= ~0x02;
  612. }
  613. static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
  614. struct lowpan_dev *dev)
  615. {
  616. struct lowpan_peer *peer;
  617. unsigned long flags;
  618. peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
  619. if (!peer)
  620. return NULL;
  621. peer->chan = chan;
  622. memset(&peer->peer_addr, 0, sizeof(struct in6_addr));
  623. /* RFC 2464 ch. 5 */
  624. peer->peer_addr.s6_addr[0] = 0xFE;
  625. peer->peer_addr.s6_addr[1] = 0x80;
  626. set_addr((u8 *)&peer->peer_addr.s6_addr + 8, chan->dst.b,
  627. chan->dst_type);
  628. memcpy(&peer->eui64_addr, (u8 *)&peer->peer_addr.s6_addr + 8,
  629. EUI64_ADDR_LEN);
  630. /* IPv6 address needs to have the U/L bit set properly so toggle
  631. * it back here.
  632. */
  633. set_ip_addr_bits(chan->dst_type, (u8 *)&peer->peer_addr.s6_addr + 8);
  634. write_lock_irqsave(&devices_lock, flags);
  635. INIT_LIST_HEAD(&peer->list);
  636. peer_add(dev, peer);
  637. write_unlock_irqrestore(&devices_lock, flags);
  638. /* Notifying peers about us needs to be done without locks held */
  639. INIT_DELAYED_WORK(&dev->notify_peers, do_notify_peers);
  640. schedule_delayed_work(&dev->notify_peers, msecs_to_jiffies(100));
  641. return peer->chan;
  642. }
  643. static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
  644. {
  645. struct net_device *netdev;
  646. int err = 0;
  647. unsigned long flags;
  648. netdev = alloc_netdev(sizeof(struct lowpan_dev), IFACE_NAME_TEMPLATE,
  649. NET_NAME_UNKNOWN, netdev_setup);
  650. if (!netdev)
  651. return -ENOMEM;
  652. set_dev_addr(netdev, &chan->src, chan->src_type);
  653. netdev->netdev_ops = &netdev_ops;
  654. SET_NETDEV_DEV(netdev, &chan->conn->hcon->dev);
  655. SET_NETDEV_DEVTYPE(netdev, &bt_type);
  656. err = register_netdev(netdev);
  657. if (err < 0) {
  658. BT_INFO("register_netdev failed %d", err);
  659. free_netdev(netdev);
  660. goto out;
  661. }
  662. BT_DBG("ifindex %d peer bdaddr %pMR type %d my addr %pMR type %d",
  663. netdev->ifindex, &chan->dst, chan->dst_type,
  664. &chan->src, chan->src_type);
  665. set_bit(__LINK_STATE_PRESENT, &netdev->state);
  666. *dev = netdev_priv(netdev);
  667. (*dev)->netdev = netdev;
  668. (*dev)->hdev = chan->conn->hcon->hdev;
  669. INIT_LIST_HEAD(&(*dev)->peers);
  670. write_lock_irqsave(&devices_lock, flags);
  671. INIT_LIST_HEAD(&(*dev)->list);
  672. list_add(&(*dev)->list, &bt_6lowpan_devices);
  673. write_unlock_irqrestore(&devices_lock, flags);
  674. return 0;
  675. out:
  676. return err;
  677. }
  678. static inline void chan_ready_cb(struct l2cap_chan *chan)
  679. {
  680. struct lowpan_dev *dev;
  681. dev = lookup_dev(chan->conn);
  682. BT_DBG("chan %p conn %p dev %p", chan, chan->conn, dev);
  683. if (!dev) {
  684. if (setup_netdev(chan, &dev) < 0) {
  685. l2cap_chan_del(chan, -ENOENT);
  686. return;
  687. }
  688. }
  689. if (!try_module_get(THIS_MODULE))
  690. return;
  691. add_peer_chan(chan, dev);
  692. ifup(dev->netdev);
  693. }
  694. static inline struct l2cap_chan *chan_new_conn_cb(struct l2cap_chan *pchan)
  695. {
  696. struct l2cap_chan *chan;
  697. chan = chan_open(pchan);
  698. chan->ops = pchan->ops;
  699. BT_DBG("chan %p pchan %p", chan, pchan);
  700. return chan;
  701. }
  702. static void delete_netdev(struct work_struct *work)
  703. {
  704. struct lowpan_dev *entry = container_of(work, struct lowpan_dev,
  705. delete_netdev);
  706. unregister_netdev(entry->netdev);
  707. /* The entry pointer is deleted in device_event() */
  708. }
  709. static void chan_close_cb(struct l2cap_chan *chan)
  710. {
  711. struct lowpan_dev *entry, *tmp;
  712. struct lowpan_dev *dev = NULL;
  713. struct lowpan_peer *peer;
  714. int err = -ENOENT;
  715. unsigned long flags;
  716. bool last = false, removed = true;
  717. BT_DBG("chan %p conn %p", chan, chan->conn);
  718. if (chan->conn && chan->conn->hcon) {
  719. if (!is_bt_6lowpan(chan->conn->hcon))
  720. return;
  721. /* If conn is set, then the netdev is also there and we should
  722. * not remove it.
  723. */
  724. removed = false;
  725. }
  726. write_lock_irqsave(&devices_lock, flags);
  727. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
  728. dev = lowpan_dev(entry->netdev);
  729. peer = peer_lookup_chan(dev, chan);
  730. if (peer) {
  731. last = peer_del(dev, peer);
  732. err = 0;
  733. BT_DBG("dev %p removing %speer %p", dev,
  734. last ? "last " : "1 ", peer);
  735. BT_DBG("chan %p orig refcnt %d", chan,
  736. atomic_read(&chan->kref.refcount));
  737. l2cap_chan_put(chan);
  738. kfree(peer);
  739. break;
  740. }
  741. }
  742. if (!err && last && dev && !atomic_read(&dev->peer_count)) {
  743. write_unlock_irqrestore(&devices_lock, flags);
  744. cancel_delayed_work_sync(&dev->notify_peers);
  745. ifdown(dev->netdev);
  746. if (!removed) {
  747. INIT_WORK(&entry->delete_netdev, delete_netdev);
  748. schedule_work(&entry->delete_netdev);
  749. }
  750. } else {
  751. write_unlock_irqrestore(&devices_lock, flags);
  752. }
  753. return;
  754. }
  755. static void chan_state_change_cb(struct l2cap_chan *chan, int state, int err)
  756. {
  757. BT_DBG("chan %p conn %p state %s err %d", chan, chan->conn,
  758. state_to_string(state), err);
  759. }
  760. static struct sk_buff *chan_alloc_skb_cb(struct l2cap_chan *chan,
  761. unsigned long hdr_len,
  762. unsigned long len, int nb)
  763. {
  764. /* Note that we must allocate using GFP_ATOMIC here as
  765. * this function is called originally from netdev hard xmit
  766. * function in atomic context.
  767. */
  768. return bt_skb_alloc(hdr_len + len, GFP_ATOMIC);
  769. }
  770. static void chan_suspend_cb(struct l2cap_chan *chan)
  771. {
  772. struct sk_buff *skb = chan->data;
  773. BT_DBG("chan %p conn %p skb %p", chan, chan->conn, skb);
  774. if (!skb)
  775. return;
  776. lowpan_cb(skb)->status = -EAGAIN;
  777. }
  778. static void chan_resume_cb(struct l2cap_chan *chan)
  779. {
  780. struct sk_buff *skb = chan->data;
  781. BT_DBG("chan %p conn %p skb %p", chan, chan->conn, skb);
  782. if (!skb)
  783. return;
  784. lowpan_cb(skb)->status = 0;
  785. }
  786. static long chan_get_sndtimeo_cb(struct l2cap_chan *chan)
  787. {
  788. return L2CAP_CONN_TIMEOUT;
  789. }
  790. static const struct l2cap_ops bt_6lowpan_chan_ops = {
  791. .name = "L2CAP 6LoWPAN channel",
  792. .new_connection = chan_new_conn_cb,
  793. .recv = chan_recv_cb,
  794. .close = chan_close_cb,
  795. .state_change = chan_state_change_cb,
  796. .ready = chan_ready_cb,
  797. .resume = chan_resume_cb,
  798. .suspend = chan_suspend_cb,
  799. .get_sndtimeo = chan_get_sndtimeo_cb,
  800. .alloc_skb = chan_alloc_skb_cb,
  801. .memcpy_fromiovec = l2cap_chan_no_memcpy_fromiovec,
  802. .teardown = l2cap_chan_no_teardown,
  803. .defer = l2cap_chan_no_defer,
  804. .set_shutdown = l2cap_chan_no_set_shutdown,
  805. };
  806. static inline __u8 bdaddr_type(__u8 type)
  807. {
  808. if (type == ADDR_LE_DEV_PUBLIC)
  809. return BDADDR_LE_PUBLIC;
  810. else
  811. return BDADDR_LE_RANDOM;
  812. }
  813. static struct l2cap_chan *chan_get(void)
  814. {
  815. struct l2cap_chan *pchan;
  816. pchan = chan_create();
  817. if (!pchan)
  818. return NULL;
  819. pchan->ops = &bt_6lowpan_chan_ops;
  820. return pchan;
  821. }
  822. static int bt_6lowpan_connect(bdaddr_t *addr, u8 dst_type)
  823. {
  824. struct l2cap_chan *pchan;
  825. int err;
  826. pchan = chan_get();
  827. if (!pchan)
  828. return -EINVAL;
  829. err = l2cap_chan_connect(pchan, cpu_to_le16(psm_6lowpan), 0,
  830. addr, dst_type);
  831. BT_DBG("chan %p err %d", pchan, err);
  832. if (err < 0)
  833. l2cap_chan_put(pchan);
  834. return err;
  835. }
  836. static int bt_6lowpan_disconnect(struct l2cap_conn *conn, u8 dst_type)
  837. {
  838. struct lowpan_peer *peer;
  839. BT_DBG("conn %p dst type %d", conn, dst_type);
  840. peer = lookup_peer(conn);
  841. if (!peer)
  842. return -ENOENT;
  843. BT_DBG("peer %p chan %p", peer, peer->chan);
  844. l2cap_chan_close(peer->chan, ENOENT);
  845. return 0;
  846. }
  847. static struct l2cap_chan *bt_6lowpan_listen(void)
  848. {
  849. bdaddr_t *addr = BDADDR_ANY;
  850. struct l2cap_chan *pchan;
  851. int err;
  852. if (psm_6lowpan == 0)
  853. return NULL;
  854. pchan = chan_get();
  855. if (!pchan)
  856. return NULL;
  857. pchan->state = BT_LISTEN;
  858. pchan->src_type = BDADDR_LE_PUBLIC;
  859. BT_DBG("psm 0x%04x chan %p src type %d", psm_6lowpan, pchan,
  860. pchan->src_type);
  861. err = l2cap_add_psm(pchan, addr, cpu_to_le16(psm_6lowpan));
  862. if (err) {
  863. l2cap_chan_put(pchan);
  864. BT_ERR("psm cannot be added err %d", err);
  865. return NULL;
  866. }
  867. return pchan;
  868. }
  869. static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
  870. struct l2cap_conn **conn)
  871. {
  872. struct hci_conn *hcon;
  873. struct hci_dev *hdev;
  874. bdaddr_t *src = BDADDR_ANY;
  875. int n;
  876. n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu",
  877. &addr->b[5], &addr->b[4], &addr->b[3],
  878. &addr->b[2], &addr->b[1], &addr->b[0],
  879. addr_type);
  880. if (n < 7)
  881. return -EINVAL;
  882. hdev = hci_get_route(addr, src);
  883. if (!hdev)
  884. return -ENOENT;
  885. hci_dev_lock(hdev);
  886. hcon = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr);
  887. hci_dev_unlock(hdev);
  888. if (!hcon)
  889. return -ENOENT;
  890. *conn = (struct l2cap_conn *)hcon->l2cap_data;
  891. BT_DBG("conn %p dst %pMR type %d", *conn, &hcon->dst, hcon->dst_type);
  892. return 0;
  893. }
  894. static void disconnect_all_peers(void)
  895. {
  896. struct lowpan_dev *entry, *tmp_dev;
  897. struct lowpan_peer *peer, *tmp_peer, *new_peer;
  898. struct list_head peers;
  899. unsigned long flags;
  900. INIT_LIST_HEAD(&peers);
  901. /* We make a separate list of peers as the close_cb() will
  902. * modify the device peers list so it is better not to mess
  903. * with the same list at the same time.
  904. */
  905. read_lock_irqsave(&devices_lock, flags);
  906. list_for_each_entry_safe(entry, tmp_dev, &bt_6lowpan_devices, list) {
  907. list_for_each_entry_safe(peer, tmp_peer, &entry->peers, list) {
  908. new_peer = kmalloc(sizeof(*new_peer), GFP_ATOMIC);
  909. if (!new_peer)
  910. break;
  911. new_peer->chan = peer->chan;
  912. INIT_LIST_HEAD(&new_peer->list);
  913. list_add(&new_peer->list, &peers);
  914. }
  915. }
  916. read_unlock_irqrestore(&devices_lock, flags);
  917. list_for_each_entry_safe(peer, tmp_peer, &peers, list) {
  918. l2cap_chan_close(peer->chan, ENOENT);
  919. kfree(peer);
  920. }
  921. }
  922. static int lowpan_psm_set(void *data, u64 val)
  923. {
  924. u16 psm;
  925. psm = val;
  926. if (psm == 0 || psm_6lowpan != psm)
  927. /* Disconnect existing connections if 6lowpan is
  928. * disabled (psm = 0), or if psm changes.
  929. */
  930. disconnect_all_peers();
  931. psm_6lowpan = psm;
  932. if (listen_chan) {
  933. l2cap_chan_close(listen_chan, 0);
  934. l2cap_chan_put(listen_chan);
  935. }
  936. listen_chan = bt_6lowpan_listen();
  937. return 0;
  938. }
  939. static int lowpan_psm_get(void *data, u64 *val)
  940. {
  941. *val = psm_6lowpan;
  942. return 0;
  943. }
  944. DEFINE_SIMPLE_ATTRIBUTE(lowpan_psm_fops, lowpan_psm_get,
  945. lowpan_psm_set, "%llu\n");
  946. static ssize_t lowpan_control_write(struct file *fp,
  947. const char __user *user_buffer,
  948. size_t count,
  949. loff_t *position)
  950. {
  951. char buf[32];
  952. size_t buf_size = min(count, sizeof(buf) - 1);
  953. int ret;
  954. bdaddr_t addr;
  955. u8 addr_type;
  956. struct l2cap_conn *conn = NULL;
  957. if (copy_from_user(buf, user_buffer, buf_size))
  958. return -EFAULT;
  959. buf[buf_size] = '\0';
  960. if (memcmp(buf, "connect ", 8) == 0) {
  961. ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn);
  962. if (ret == -EINVAL)
  963. return ret;
  964. if (listen_chan) {
  965. l2cap_chan_close(listen_chan, 0);
  966. l2cap_chan_put(listen_chan);
  967. listen_chan = NULL;
  968. }
  969. if (conn) {
  970. struct lowpan_peer *peer;
  971. if (!is_bt_6lowpan(conn->hcon))
  972. return -EINVAL;
  973. peer = lookup_peer(conn);
  974. if (peer) {
  975. BT_DBG("6LoWPAN connection already exists");
  976. return -EALREADY;
  977. }
  978. BT_DBG("conn %p dst %pMR type %d user %d", conn,
  979. &conn->hcon->dst, conn->hcon->dst_type,
  980. addr_type);
  981. }
  982. ret = bt_6lowpan_connect(&addr, addr_type);
  983. if (ret < 0)
  984. return ret;
  985. return count;
  986. }
  987. if (memcmp(buf, "disconnect ", 11) == 0) {
  988. ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn);
  989. if (ret < 0)
  990. return ret;
  991. ret = bt_6lowpan_disconnect(conn, addr_type);
  992. if (ret < 0)
  993. return ret;
  994. return count;
  995. }
  996. return count;
  997. }
  998. static int lowpan_control_show(struct seq_file *f, void *ptr)
  999. {
  1000. struct lowpan_dev *entry, *tmp_dev;
  1001. struct lowpan_peer *peer, *tmp_peer;
  1002. unsigned long flags;
  1003. read_lock_irqsave(&devices_lock, flags);
  1004. list_for_each_entry_safe(entry, tmp_dev, &bt_6lowpan_devices, list) {
  1005. list_for_each_entry_safe(peer, tmp_peer, &entry->peers, list)
  1006. seq_printf(f, "%pMR (type %u)\n",
  1007. &peer->chan->dst, peer->chan->dst_type);
  1008. }
  1009. read_unlock_irqrestore(&devices_lock, flags);
  1010. return 0;
  1011. }
  1012. static int lowpan_control_open(struct inode *inode, struct file *file)
  1013. {
  1014. return single_open(file, lowpan_control_show, inode->i_private);
  1015. }
  1016. static const struct file_operations lowpan_control_fops = {
  1017. .open = lowpan_control_open,
  1018. .read = seq_read,
  1019. .write = lowpan_control_write,
  1020. .llseek = seq_lseek,
  1021. .release = single_release,
  1022. };
  1023. static void disconnect_devices(void)
  1024. {
  1025. struct lowpan_dev *entry, *tmp, *new_dev;
  1026. struct list_head devices;
  1027. unsigned long flags;
  1028. INIT_LIST_HEAD(&devices);
  1029. /* We make a separate list of devices because the unregister_netdev()
  1030. * will call device_event() which will also want to modify the same
  1031. * devices list.
  1032. */
  1033. read_lock_irqsave(&devices_lock, flags);
  1034. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
  1035. new_dev = kmalloc(sizeof(*new_dev), GFP_ATOMIC);
  1036. if (!new_dev)
  1037. break;
  1038. new_dev->netdev = entry->netdev;
  1039. INIT_LIST_HEAD(&new_dev->list);
  1040. list_add(&new_dev->list, &devices);
  1041. }
  1042. read_unlock_irqrestore(&devices_lock, flags);
  1043. list_for_each_entry_safe(entry, tmp, &devices, list) {
  1044. ifdown(entry->netdev);
  1045. BT_DBG("Unregistering netdev %s %p",
  1046. entry->netdev->name, entry->netdev);
  1047. unregister_netdev(entry->netdev);
  1048. kfree(entry);
  1049. }
  1050. }
  1051. static int device_event(struct notifier_block *unused,
  1052. unsigned long event, void *ptr)
  1053. {
  1054. struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
  1055. struct lowpan_dev *entry, *tmp;
  1056. unsigned long flags;
  1057. if (netdev->type != ARPHRD_6LOWPAN)
  1058. return NOTIFY_DONE;
  1059. switch (event) {
  1060. case NETDEV_UNREGISTER:
  1061. write_lock_irqsave(&devices_lock, flags);
  1062. list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices,
  1063. list) {
  1064. if (entry->netdev == netdev) {
  1065. BT_DBG("Unregistered netdev %s %p",
  1066. netdev->name, netdev);
  1067. list_del(&entry->list);
  1068. kfree(entry);
  1069. break;
  1070. }
  1071. }
  1072. write_unlock_irqrestore(&devices_lock, flags);
  1073. break;
  1074. }
  1075. return NOTIFY_DONE;
  1076. }
  1077. static struct notifier_block bt_6lowpan_dev_notifier = {
  1078. .notifier_call = device_event,
  1079. };
  1080. static int __init bt_6lowpan_init(void)
  1081. {
  1082. lowpan_psm_debugfs = debugfs_create_file("6lowpan_psm", 0644,
  1083. bt_debugfs, NULL,
  1084. &lowpan_psm_fops);
  1085. lowpan_control_debugfs = debugfs_create_file("6lowpan_control", 0644,
  1086. bt_debugfs, NULL,
  1087. &lowpan_control_fops);
  1088. return register_netdevice_notifier(&bt_6lowpan_dev_notifier);
  1089. }
  1090. static void __exit bt_6lowpan_exit(void)
  1091. {
  1092. debugfs_remove(lowpan_psm_debugfs);
  1093. debugfs_remove(lowpan_control_debugfs);
  1094. if (listen_chan) {
  1095. l2cap_chan_close(listen_chan, 0);
  1096. l2cap_chan_put(listen_chan);
  1097. }
  1098. disconnect_devices();
  1099. unregister_netdevice_notifier(&bt_6lowpan_dev_notifier);
  1100. }
  1101. module_init(bt_6lowpan_init);
  1102. module_exit(bt_6lowpan_exit);
  1103. MODULE_AUTHOR("Jukka Rissanen <jukka.rissanen@linux.intel.com>");
  1104. MODULE_DESCRIPTION("Bluetooth 6LoWPAN");
  1105. MODULE_VERSION(VERSION);
  1106. MODULE_LICENSE("GPL");