6lowpan.c 30 KB

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