6lowpan.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /*
  2. * Copyright 2011, Siemens AG
  3. * written by Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
  4. */
  5. /*
  6. * Based on patches from Jon Smirl <jonsmirl@gmail.com>
  7. * Copyright (c) 2011 Jon Smirl <jonsmirl@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. /* Jon's code is based on 6lowpan implementation for Contiki which is:
  23. * Copyright (c) 2008, Swedish Institute of Computer Science.
  24. * All rights reserved.
  25. *
  26. * Redistribution and use in source and binary forms, with or without
  27. * modification, are permitted provided that the following conditions
  28. * are met:
  29. * 1. Redistributions of source code must retain the above copyright
  30. * notice, this list of conditions and the following disclaimer.
  31. * 2. Redistributions in binary form must reproduce the above copyright
  32. * notice, this list of conditions and the following disclaimer in the
  33. * documentation and/or other materials provided with the distribution.
  34. * 3. Neither the name of the Institute nor the names of its contributors
  35. * may be used to endorse or promote products derived from this software
  36. * without specific prior written permission.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
  39. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  40. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
  42. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  43. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  46. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  47. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48. * SUCH DAMAGE.
  49. */
  50. #include <linux/bitops.h>
  51. #include <linux/if_arp.h>
  52. #include <linux/module.h>
  53. #include <linux/moduleparam.h>
  54. #include <linux/netdevice.h>
  55. #include <net/af_ieee802154.h>
  56. #include <net/ieee802154.h>
  57. #include <net/ieee802154_netdev.h>
  58. #include <net/ipv6.h>
  59. #include "6lowpan.h"
  60. /* TTL uncompression values */
  61. static const u8 lowpan_ttl_values[] = {0, 1, 64, 255};
  62. static LIST_HEAD(lowpan_devices);
  63. /*
  64. * Uncompression of linklocal:
  65. * 0 -> 16 bytes from packet
  66. * 1 -> 2 bytes from prefix - bunch of zeroes and 8 from packet
  67. * 2 -> 2 bytes from prefix - zeroes + 2 from packet
  68. * 3 -> 2 bytes from prefix - infer 8 bytes from lladdr
  69. *
  70. * NOTE: => the uncompress function does change 0xf to 0x10
  71. * NOTE: 0x00 => no-autoconfig => unspecified
  72. */
  73. static const u8 lowpan_unc_llconf[] = {0x0f, 0x28, 0x22, 0x20};
  74. /*
  75. * Uncompression of ctx-based:
  76. * 0 -> 0 bits from packet [unspecified / reserved]
  77. * 1 -> 8 bytes from prefix - bunch of zeroes and 8 from packet
  78. * 2 -> 8 bytes from prefix - zeroes + 2 from packet
  79. * 3 -> 8 bytes from prefix - infer 8 bytes from lladdr
  80. */
  81. static const u8 lowpan_unc_ctxconf[] = {0x00, 0x88, 0x82, 0x80};
  82. /*
  83. * Uncompression of ctx-base
  84. * 0 -> 0 bits from packet
  85. * 1 -> 2 bytes from prefix - bunch of zeroes 5 from packet
  86. * 2 -> 2 bytes from prefix - zeroes + 3 from packet
  87. * 3 -> 2 bytes from prefix - infer 1 bytes from lladdr
  88. */
  89. static const u8 lowpan_unc_mxconf[] = {0x0f, 0x25, 0x23, 0x21};
  90. /* Link local prefix */
  91. static const u8 lowpan_llprefix[] = {0xfe, 0x80};
  92. /* private device info */
  93. struct lowpan_dev_info {
  94. struct net_device *real_dev; /* real WPAN device ptr */
  95. struct mutex dev_list_mtx; /* mutex for list ops */
  96. };
  97. struct lowpan_dev_record {
  98. struct net_device *ldev;
  99. struct list_head list;
  100. };
  101. struct lowpan_fragment {
  102. struct sk_buff *skb; /* skb to be assembled */
  103. spinlock_t lock; /* concurency lock */
  104. u16 length; /* length to be assemled */
  105. u32 bytes_rcv; /* bytes received */
  106. u16 tag; /* current fragment tag */
  107. struct timer_list timer; /* assembling timer */
  108. struct list_head list; /* fragments list */
  109. };
  110. static unsigned short fragment_tag;
  111. static LIST_HEAD(lowpan_fragments);
  112. spinlock_t flist_lock;
  113. static inline struct
  114. lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
  115. {
  116. return netdev_priv(dev);
  117. }
  118. static inline void lowpan_address_flip(u8 *src, u8 *dest)
  119. {
  120. int i;
  121. for (i = 0; i < IEEE802154_ADDR_LEN; i++)
  122. (dest)[IEEE802154_ADDR_LEN - i - 1] = (src)[i];
  123. }
  124. /* list of all 6lowpan devices, uses for package delivering */
  125. /* print data in line */
  126. static inline void lowpan_raw_dump_inline(const char *caller, char *msg,
  127. unsigned char *buf, int len)
  128. {
  129. #ifdef DEBUG
  130. if (msg)
  131. pr_debug("(%s) %s: ", caller, msg);
  132. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE,
  133. 16, 1, buf, len, false);
  134. #endif /* DEBUG */
  135. }
  136. /*
  137. * print data in a table format:
  138. *
  139. * addr: xx xx xx xx xx xx
  140. * addr: xx xx xx xx xx xx
  141. * ...
  142. */
  143. static inline void lowpan_raw_dump_table(const char *caller, char *msg,
  144. unsigned char *buf, int len)
  145. {
  146. #ifdef DEBUG
  147. if (msg)
  148. pr_debug("(%s) %s:\n", caller, msg);
  149. print_hex_dump(KERN_DEBUG, "\t", DUMP_PREFIX_OFFSET,
  150. 16, 1, buf, len, false);
  151. #endif /* DEBUG */
  152. }
  153. static u8
  154. lowpan_compress_addr_64(u8 **hc06_ptr, u8 shift, const struct in6_addr *ipaddr,
  155. const unsigned char *lladdr)
  156. {
  157. u8 val = 0;
  158. if (is_addr_mac_addr_based(ipaddr, lladdr))
  159. val = 3; /* 0-bits */
  160. else if (lowpan_is_iid_16_bit_compressable(ipaddr)) {
  161. /* compress IID to 16 bits xxxx::XXXX */
  162. memcpy(*hc06_ptr, &ipaddr->s6_addr16[7], 2);
  163. *hc06_ptr += 2;
  164. val = 2; /* 16-bits */
  165. } else {
  166. /* do not compress IID => xxxx::IID */
  167. memcpy(*hc06_ptr, &ipaddr->s6_addr16[4], 8);
  168. *hc06_ptr += 8;
  169. val = 1; /* 64-bits */
  170. }
  171. return rol8(val, shift);
  172. }
  173. static void
  174. lowpan_uip_ds6_set_addr_iid(struct in6_addr *ipaddr, unsigned char *lladdr)
  175. {
  176. memcpy(&ipaddr->s6_addr[8], lladdr, IEEE802154_ALEN);
  177. /* second bit-flip (Universe/Local) is done according RFC2464 */
  178. ipaddr->s6_addr[8] ^= 0x02;
  179. }
  180. /*
  181. * Uncompress addresses based on a prefix and a postfix with zeroes in
  182. * between. If the postfix is zero in length it will use the link address
  183. * to configure the IP address (autoconf style).
  184. * pref_post_count takes a byte where the first nibble specify prefix count
  185. * and the second postfix count (NOTE: 15/0xf => 16 bytes copy).
  186. */
  187. static int
  188. lowpan_uncompress_addr(struct sk_buff *skb, struct in6_addr *ipaddr,
  189. u8 const *prefix, u8 pref_post_count, unsigned char *lladdr)
  190. {
  191. u8 prefcount = pref_post_count >> 4;
  192. u8 postcount = pref_post_count & 0x0f;
  193. /* full nibble 15 => 16 */
  194. prefcount = (prefcount == 15 ? 16 : prefcount);
  195. postcount = (postcount == 15 ? 16 : postcount);
  196. if (lladdr)
  197. lowpan_raw_dump_inline(__func__, "linklocal address",
  198. lladdr, IEEE802154_ALEN);
  199. if (prefcount > 0)
  200. memcpy(ipaddr, prefix, prefcount);
  201. if (prefcount + postcount < 16)
  202. memset(&ipaddr->s6_addr[prefcount], 0,
  203. 16 - (prefcount + postcount));
  204. if (postcount > 0) {
  205. memcpy(&ipaddr->s6_addr[16 - postcount], skb->data, postcount);
  206. skb_pull(skb, postcount);
  207. } else if (prefcount > 0) {
  208. if (lladdr == NULL)
  209. return -EINVAL;
  210. /* no IID based configuration if no prefix and no data */
  211. lowpan_uip_ds6_set_addr_iid(ipaddr, lladdr);
  212. }
  213. pr_debug("(%s): uncompressing %d + %d => ", __func__, prefcount,
  214. postcount);
  215. lowpan_raw_dump_inline(NULL, NULL, ipaddr->s6_addr, 16);
  216. return 0;
  217. }
  218. static void
  219. lowpan_compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
  220. {
  221. struct udphdr *uh = udp_hdr(skb);
  222. pr_debug("(%s): UDP header compression\n", __func__);
  223. if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) ==
  224. LOWPAN_NHC_UDP_4BIT_PORT) &&
  225. ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) ==
  226. LOWPAN_NHC_UDP_4BIT_PORT)) {
  227. pr_debug("(%s): both ports compression to 4 bits\n", __func__);
  228. **hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
  229. **(hc06_ptr + 1) = /* subtraction is faster */
  230. (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
  231. ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
  232. *hc06_ptr += 2;
  233. } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) ==
  234. LOWPAN_NHC_UDP_8BIT_PORT) {
  235. pr_debug("(%s): remove 8 bits of dest\n", __func__);
  236. **hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
  237. memcpy(*hc06_ptr + 1, &uh->source, 2);
  238. **(hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
  239. *hc06_ptr += 4;
  240. } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
  241. LOWPAN_NHC_UDP_8BIT_PORT) {
  242. pr_debug("(%s): remove 8 bits of source\n", __func__);
  243. **hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
  244. memcpy(*hc06_ptr + 1, &uh->dest, 2);
  245. **(hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
  246. *hc06_ptr += 4;
  247. } else {
  248. pr_debug("(%s): can't compress header\n", __func__);
  249. **hc06_ptr = LOWPAN_NHC_UDP_CS_P_00;
  250. memcpy(*hc06_ptr + 1, &uh->source, 2);
  251. memcpy(*hc06_ptr + 3, &uh->dest, 2);
  252. *hc06_ptr += 5;
  253. }
  254. /* checksum is always inline */
  255. memcpy(*hc06_ptr, &uh->check, 2);
  256. *hc06_ptr += 2;
  257. }
  258. static u8 lowpan_fetch_skb_u8(struct sk_buff *skb)
  259. {
  260. u8 ret;
  261. ret = skb->data[0];
  262. skb_pull(skb, 1);
  263. return ret;
  264. }
  265. static u16 lowpan_fetch_skb_u16(struct sk_buff *skb)
  266. {
  267. u16 ret;
  268. BUG_ON(!pskb_may_pull(skb, 2));
  269. ret = skb->data[0] | (skb->data[1] << 8);
  270. skb_pull(skb, 2);
  271. return ret;
  272. }
  273. static int lowpan_header_create(struct sk_buff *skb,
  274. struct net_device *dev,
  275. unsigned short type, const void *_daddr,
  276. const void *_saddr, unsigned len)
  277. {
  278. u8 tmp, iphc0, iphc1, *hc06_ptr;
  279. struct ipv6hdr *hdr;
  280. const u8 *saddr = _saddr;
  281. const u8 *daddr = _daddr;
  282. u8 *head;
  283. struct ieee802154_addr sa, da;
  284. if (type != ETH_P_IPV6)
  285. return 0;
  286. /* TODO:
  287. * if this package isn't ipv6 one, where should it be routed?
  288. */
  289. head = kzalloc(100, GFP_KERNEL);
  290. if (head == NULL)
  291. return -ENOMEM;
  292. hdr = ipv6_hdr(skb);
  293. hc06_ptr = head + 2;
  294. pr_debug("(%s): IPv6 header dump:\n\tversion = %d\n\tlength = %d\n"
  295. "\tnexthdr = 0x%02x\n\thop_lim = %d\n", __func__,
  296. hdr->version, ntohs(hdr->payload_len), hdr->nexthdr,
  297. hdr->hop_limit);
  298. lowpan_raw_dump_table(__func__, "raw skb network header dump",
  299. skb_network_header(skb), sizeof(struct ipv6hdr));
  300. if (!saddr)
  301. saddr = dev->dev_addr;
  302. lowpan_raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
  303. /*
  304. * As we copy some bit-length fields, in the IPHC encoding bytes,
  305. * we sometimes use |=
  306. * If the field is 0, and the current bit value in memory is 1,
  307. * this does not work. We therefore reset the IPHC encoding here
  308. */
  309. iphc0 = LOWPAN_DISPATCH_IPHC;
  310. iphc1 = 0;
  311. /* TODO: context lookup */
  312. lowpan_raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
  313. /*
  314. * Traffic class, flow label
  315. * If flow label is 0, compress it. If traffic class is 0, compress it
  316. * We have to process both in the same time as the offset of traffic
  317. * class depends on the presence of version and flow label
  318. */
  319. /* hc06 format of TC is ECN | DSCP , original one is DSCP | ECN */
  320. tmp = (hdr->priority << 4) | (hdr->flow_lbl[0] >> 4);
  321. tmp = ((tmp & 0x03) << 6) | (tmp >> 2);
  322. if (((hdr->flow_lbl[0] & 0x0F) == 0) &&
  323. (hdr->flow_lbl[1] == 0) && (hdr->flow_lbl[2] == 0)) {
  324. /* flow label can be compressed */
  325. iphc0 |= LOWPAN_IPHC_FL_C;
  326. if ((hdr->priority == 0) &&
  327. ((hdr->flow_lbl[0] & 0xF0) == 0)) {
  328. /* compress (elide) all */
  329. iphc0 |= LOWPAN_IPHC_TC_C;
  330. } else {
  331. /* compress only the flow label */
  332. *hc06_ptr = tmp;
  333. hc06_ptr += 1;
  334. }
  335. } else {
  336. /* Flow label cannot be compressed */
  337. if ((hdr->priority == 0) &&
  338. ((hdr->flow_lbl[0] & 0xF0) == 0)) {
  339. /* compress only traffic class */
  340. iphc0 |= LOWPAN_IPHC_TC_C;
  341. *hc06_ptr = (tmp & 0xc0) | (hdr->flow_lbl[0] & 0x0F);
  342. memcpy(hc06_ptr + 1, &hdr->flow_lbl[1], 2);
  343. hc06_ptr += 3;
  344. } else {
  345. /* compress nothing */
  346. memcpy(hc06_ptr, &hdr, 4);
  347. /* replace the top byte with new ECN | DSCP format */
  348. *hc06_ptr = tmp;
  349. hc06_ptr += 4;
  350. }
  351. }
  352. /* NOTE: payload length is always compressed */
  353. /* Next Header is compress if UDP */
  354. if (hdr->nexthdr == UIP_PROTO_UDP)
  355. iphc0 |= LOWPAN_IPHC_NH_C;
  356. if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
  357. *hc06_ptr = hdr->nexthdr;
  358. hc06_ptr += 1;
  359. }
  360. /*
  361. * Hop limit
  362. * if 1: compress, encoding is 01
  363. * if 64: compress, encoding is 10
  364. * if 255: compress, encoding is 11
  365. * else do not compress
  366. */
  367. switch (hdr->hop_limit) {
  368. case 1:
  369. iphc0 |= LOWPAN_IPHC_TTL_1;
  370. break;
  371. case 64:
  372. iphc0 |= LOWPAN_IPHC_TTL_64;
  373. break;
  374. case 255:
  375. iphc0 |= LOWPAN_IPHC_TTL_255;
  376. break;
  377. default:
  378. *hc06_ptr = hdr->hop_limit;
  379. break;
  380. }
  381. /* source address compression */
  382. if (is_addr_unspecified(&hdr->saddr)) {
  383. pr_debug("(%s): source address is unspecified, setting SAC\n",
  384. __func__);
  385. iphc1 |= LOWPAN_IPHC_SAC;
  386. /* TODO: context lookup */
  387. } else if (is_addr_link_local(&hdr->saddr)) {
  388. pr_debug("(%s): source address is link-local\n", __func__);
  389. iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
  390. LOWPAN_IPHC_SAM_BIT, &hdr->saddr, saddr);
  391. } else {
  392. pr_debug("(%s): send the full source address\n", __func__);
  393. memcpy(hc06_ptr, &hdr->saddr.s6_addr16[0], 16);
  394. hc06_ptr += 16;
  395. }
  396. /* destination address compression */
  397. if (is_addr_mcast(&hdr->daddr)) {
  398. pr_debug("(%s): destination address is multicast", __func__);
  399. iphc1 |= LOWPAN_IPHC_M;
  400. if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) {
  401. pr_debug("compressed to 1 octet\n");
  402. iphc1 |= LOWPAN_IPHC_DAM_11;
  403. /* use last byte */
  404. *hc06_ptr = hdr->daddr.s6_addr[15];
  405. hc06_ptr += 1;
  406. } else if (lowpan_is_mcast_addr_compressable32(&hdr->daddr)) {
  407. pr_debug("compressed to 4 octets\n");
  408. iphc1 |= LOWPAN_IPHC_DAM_10;
  409. /* second byte + the last three */
  410. *hc06_ptr = hdr->daddr.s6_addr[1];
  411. memcpy(hc06_ptr + 1, &hdr->daddr.s6_addr[13], 3);
  412. hc06_ptr += 4;
  413. } else if (lowpan_is_mcast_addr_compressable48(&hdr->daddr)) {
  414. pr_debug("compressed to 6 octets\n");
  415. iphc1 |= LOWPAN_IPHC_DAM_01;
  416. /* second byte + the last five */
  417. *hc06_ptr = hdr->daddr.s6_addr[1];
  418. memcpy(hc06_ptr + 1, &hdr->daddr.s6_addr[11], 5);
  419. hc06_ptr += 6;
  420. } else {
  421. pr_debug("using full address\n");
  422. iphc1 |= LOWPAN_IPHC_DAM_00;
  423. memcpy(hc06_ptr, &hdr->daddr.s6_addr[0], 16);
  424. hc06_ptr += 16;
  425. }
  426. } else {
  427. pr_debug("(%s): destination address is unicast: ", __func__);
  428. /* TODO: context lookup */
  429. if (is_addr_link_local(&hdr->daddr)) {
  430. pr_debug("destination address is link-local\n");
  431. iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
  432. LOWPAN_IPHC_DAM_BIT, &hdr->daddr, daddr);
  433. } else {
  434. pr_debug("using full address\n");
  435. memcpy(hc06_ptr, &hdr->daddr.s6_addr16[0], 16);
  436. hc06_ptr += 16;
  437. }
  438. }
  439. /* UDP header compression */
  440. if (hdr->nexthdr == UIP_PROTO_UDP)
  441. lowpan_compress_udp_header(&hc06_ptr, skb);
  442. head[0] = iphc0;
  443. head[1] = iphc1;
  444. skb_pull(skb, sizeof(struct ipv6hdr));
  445. memcpy(skb_push(skb, hc06_ptr - head), head, hc06_ptr - head);
  446. kfree(head);
  447. lowpan_raw_dump_table(__func__, "raw skb data dump", skb->data,
  448. skb->len);
  449. /*
  450. * NOTE1: I'm still unsure about the fact that compression and WPAN
  451. * header are created here and not later in the xmit. So wait for
  452. * an opinion of net maintainers.
  453. */
  454. /*
  455. * NOTE2: to be absolutely correct, we must derive PANid information
  456. * from MAC subif of the 'dev' and 'real_dev' network devices, but
  457. * this isn't implemented in mainline yet, so currently we assign 0xff
  458. */
  459. {
  460. /* prepare wpan address data */
  461. sa.addr_type = IEEE802154_ADDR_LONG;
  462. sa.pan_id = 0xff;
  463. da.addr_type = IEEE802154_ADDR_LONG;
  464. da.pan_id = 0xff;
  465. memcpy(&(da.hwaddr), daddr, 8);
  466. memcpy(&(sa.hwaddr), saddr, 8);
  467. mac_cb(skb)->flags = IEEE802154_FC_TYPE_DATA;
  468. return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
  469. type, (void *)&da, (void *)&sa, skb->len);
  470. }
  471. }
  472. static int lowpan_skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr)
  473. {
  474. struct sk_buff *new;
  475. struct lowpan_dev_record *entry;
  476. int stat = NET_RX_SUCCESS;
  477. new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
  478. GFP_ATOMIC);
  479. kfree_skb(skb);
  480. if (!new)
  481. return -ENOMEM;
  482. skb_push(new, sizeof(struct ipv6hdr));
  483. skb_reset_network_header(new);
  484. skb_copy_to_linear_data(new, hdr, sizeof(struct ipv6hdr));
  485. new->protocol = htons(ETH_P_IPV6);
  486. new->pkt_type = PACKET_HOST;
  487. rcu_read_lock();
  488. list_for_each_entry_rcu(entry, &lowpan_devices, list)
  489. if (lowpan_dev_info(entry->ldev)->real_dev == new->dev) {
  490. skb = skb_copy(new, GFP_ATOMIC);
  491. if (!skb) {
  492. stat = -ENOMEM;
  493. break;
  494. }
  495. skb->dev = entry->ldev;
  496. stat = netif_rx(skb);
  497. }
  498. rcu_read_unlock();
  499. kfree_skb(new);
  500. return stat;
  501. }
  502. static void lowpan_fragment_timer_expired(unsigned long entry_addr)
  503. {
  504. struct lowpan_fragment *entry = (struct lowpan_fragment *)entry_addr;
  505. pr_debug("%s: timer expired for frame with tag %d\n", __func__,
  506. entry->tag);
  507. spin_lock(&flist_lock);
  508. list_del(&entry->list);
  509. spin_unlock(&flist_lock);
  510. dev_kfree_skb(entry->skb);
  511. kfree(entry);
  512. }
  513. static int
  514. lowpan_process_data(struct sk_buff *skb)
  515. {
  516. struct ipv6hdr hdr;
  517. u8 tmp, iphc0, iphc1, num_context = 0;
  518. u8 *_saddr, *_daddr;
  519. int err;
  520. lowpan_raw_dump_table(__func__, "raw skb data dump", skb->data,
  521. skb->len);
  522. /* at least two bytes will be used for the encoding */
  523. if (skb->len < 2)
  524. goto drop;
  525. iphc0 = lowpan_fetch_skb_u8(skb);
  526. /* fragments assembling */
  527. switch (iphc0 & LOWPAN_DISPATCH_MASK) {
  528. case LOWPAN_DISPATCH_FRAG1:
  529. case LOWPAN_DISPATCH_FRAGN:
  530. {
  531. struct lowpan_fragment *frame;
  532. u8 len, offset;
  533. u16 tag;
  534. bool found = false;
  535. len = lowpan_fetch_skb_u8(skb); /* frame length */
  536. tag = lowpan_fetch_skb_u16(skb);
  537. /*
  538. * check if frame assembling with the same tag is
  539. * already in progress
  540. */
  541. spin_lock(&flist_lock);
  542. list_for_each_entry(frame, &lowpan_fragments, list)
  543. if (frame->tag == tag) {
  544. found = true;
  545. break;
  546. }
  547. /* alloc new frame structure */
  548. if (!found) {
  549. frame = kzalloc(sizeof(struct lowpan_fragment),
  550. GFP_ATOMIC);
  551. if (!frame)
  552. goto unlock_and_drop;
  553. INIT_LIST_HEAD(&frame->list);
  554. frame->length = (iphc0 & 7) | (len << 3);
  555. frame->tag = tag;
  556. /* allocate buffer for frame assembling */
  557. frame->skb = alloc_skb(frame->length +
  558. sizeof(struct ipv6hdr), GFP_ATOMIC);
  559. if (!frame->skb) {
  560. kfree(frame);
  561. goto unlock_and_drop;
  562. }
  563. frame->skb->priority = skb->priority;
  564. frame->skb->dev = skb->dev;
  565. /* reserve headroom for uncompressed ipv6 header */
  566. skb_reserve(frame->skb, sizeof(struct ipv6hdr));
  567. skb_put(frame->skb, frame->length);
  568. init_timer(&frame->timer);
  569. /* time out is the same as for ipv6 - 60 sec */
  570. frame->timer.expires = jiffies + LOWPAN_FRAG_TIMEOUT;
  571. frame->timer.data = (unsigned long)frame;
  572. frame->timer.function = lowpan_fragment_timer_expired;
  573. add_timer(&frame->timer);
  574. list_add_tail(&frame->list, &lowpan_fragments);
  575. }
  576. if ((iphc0 & LOWPAN_DISPATCH_MASK) == LOWPAN_DISPATCH_FRAG1)
  577. goto unlock_and_drop;
  578. offset = lowpan_fetch_skb_u8(skb); /* fetch offset */
  579. /* if payload fits buffer, copy it */
  580. if (likely((offset * 8 + skb->len) <= frame->length))
  581. skb_copy_to_linear_data_offset(frame->skb, offset * 8,
  582. skb->data, skb->len);
  583. else
  584. goto unlock_and_drop;
  585. frame->bytes_rcv += skb->len;
  586. /* frame assembling complete */
  587. if ((frame->bytes_rcv == frame->length) &&
  588. frame->timer.expires > jiffies) {
  589. /* if timer haven't expired - first of all delete it */
  590. del_timer(&frame->timer);
  591. list_del(&frame->list);
  592. spin_unlock(&flist_lock);
  593. dev_kfree_skb(skb);
  594. skb = frame->skb;
  595. kfree(frame);
  596. iphc0 = lowpan_fetch_skb_u8(skb);
  597. break;
  598. }
  599. spin_unlock(&flist_lock);
  600. return kfree_skb(skb), 0;
  601. }
  602. default:
  603. break;
  604. }
  605. iphc1 = lowpan_fetch_skb_u8(skb);
  606. _saddr = mac_cb(skb)->sa.hwaddr;
  607. _daddr = mac_cb(skb)->da.hwaddr;
  608. pr_debug("(%s): iphc0 = %02x, iphc1 = %02x\n", __func__, iphc0, iphc1);
  609. /* another if the CID flag is set */
  610. if (iphc1 & LOWPAN_IPHC_CID) {
  611. pr_debug("(%s): CID flag is set, increase header with one\n",
  612. __func__);
  613. if (!skb->len)
  614. goto drop;
  615. num_context = lowpan_fetch_skb_u8(skb);
  616. }
  617. hdr.version = 6;
  618. /* Traffic Class and Flow Label */
  619. switch ((iphc0 & LOWPAN_IPHC_TF) >> 3) {
  620. /*
  621. * Traffic Class and FLow Label carried in-line
  622. * ECN + DSCP + 4-bit Pad + Flow Label (4 bytes)
  623. */
  624. case 0: /* 00b */
  625. if (!skb->len)
  626. goto drop;
  627. tmp = lowpan_fetch_skb_u8(skb);
  628. memcpy(&hdr.flow_lbl, &skb->data[0], 3);
  629. skb_pull(skb, 3);
  630. hdr.priority = ((tmp >> 2) & 0x0f);
  631. hdr.flow_lbl[0] = ((tmp >> 2) & 0x30) | (tmp << 6) |
  632. (hdr.flow_lbl[0] & 0x0f);
  633. break;
  634. /*
  635. * Traffic class carried in-line
  636. * ECN + DSCP (1 byte), Flow Label is elided
  637. */
  638. case 1: /* 10b */
  639. if (!skb->len)
  640. goto drop;
  641. tmp = lowpan_fetch_skb_u8(skb);
  642. hdr.priority = ((tmp >> 2) & 0x0f);
  643. hdr.flow_lbl[0] = ((tmp << 6) & 0xC0) | ((tmp >> 2) & 0x30);
  644. hdr.flow_lbl[1] = 0;
  645. hdr.flow_lbl[2] = 0;
  646. break;
  647. /*
  648. * Flow Label carried in-line
  649. * ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided
  650. */
  651. case 2: /* 01b */
  652. if (!skb->len)
  653. goto drop;
  654. tmp = lowpan_fetch_skb_u8(skb);
  655. hdr.flow_lbl[0] = (skb->data[0] & 0x0F) | ((tmp >> 2) & 0x30);
  656. memcpy(&hdr.flow_lbl[1], &skb->data[0], 2);
  657. skb_pull(skb, 2);
  658. break;
  659. /* Traffic Class and Flow Label are elided */
  660. case 3: /* 11b */
  661. hdr.priority = 0;
  662. hdr.flow_lbl[0] = 0;
  663. hdr.flow_lbl[1] = 0;
  664. hdr.flow_lbl[2] = 0;
  665. break;
  666. default:
  667. break;
  668. }
  669. /* Next Header */
  670. if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
  671. /* Next header is carried inline */
  672. if (!skb->len)
  673. goto drop;
  674. hdr.nexthdr = lowpan_fetch_skb_u8(skb);
  675. pr_debug("(%s): NH flag is set, next header is carried "
  676. "inline: %02x\n", __func__, hdr.nexthdr);
  677. }
  678. /* Hop Limit */
  679. if ((iphc0 & 0x03) != LOWPAN_IPHC_TTL_I)
  680. hdr.hop_limit = lowpan_ttl_values[iphc0 & 0x03];
  681. else {
  682. if (!skb->len)
  683. goto drop;
  684. hdr.hop_limit = lowpan_fetch_skb_u8(skb);
  685. }
  686. /* Extract SAM to the tmp variable */
  687. tmp = ((iphc1 & LOWPAN_IPHC_SAM) >> LOWPAN_IPHC_SAM_BIT) & 0x03;
  688. /* Source address uncompression */
  689. pr_debug("(%s): source address stateless compression\n", __func__);
  690. err = lowpan_uncompress_addr(skb, &hdr.saddr, lowpan_llprefix,
  691. lowpan_unc_llconf[tmp], skb->data);
  692. if (err)
  693. goto drop;
  694. /* Extract DAM to the tmp variable */
  695. tmp = ((iphc1 & LOWPAN_IPHC_DAM_11) >> LOWPAN_IPHC_DAM_BIT) & 0x03;
  696. /* check for Multicast Compression */
  697. if (iphc1 & LOWPAN_IPHC_M) {
  698. if (iphc1 & LOWPAN_IPHC_DAC) {
  699. pr_debug("(%s): destination address context-based "
  700. "multicast compression\n", __func__);
  701. /* TODO: implement this */
  702. } else {
  703. u8 prefix[] = {0xff, 0x02};
  704. pr_debug("(%s): destination address non-context-based"
  705. " multicast compression\n", __func__);
  706. if (0 < tmp && tmp < 3) {
  707. if (!skb->len)
  708. goto drop;
  709. else
  710. prefix[1] = lowpan_fetch_skb_u8(skb);
  711. }
  712. err = lowpan_uncompress_addr(skb, &hdr.daddr, prefix,
  713. lowpan_unc_mxconf[tmp], NULL);
  714. if (err)
  715. goto drop;
  716. }
  717. } else {
  718. pr_debug("(%s): destination address stateless compression\n",
  719. __func__);
  720. err = lowpan_uncompress_addr(skb, &hdr.daddr, lowpan_llprefix,
  721. lowpan_unc_llconf[tmp], skb->data);
  722. if (err)
  723. goto drop;
  724. }
  725. /* TODO: UDP header parse */
  726. /* Not fragmented package */
  727. hdr.payload_len = htons(skb->len);
  728. pr_debug("(%s): skb headroom size = %d, data length = %d\n", __func__,
  729. skb_headroom(skb), skb->len);
  730. pr_debug("(%s): IPv6 header dump:\n\tversion = %d\n\tlength = %d\n\t"
  731. "nexthdr = 0x%02x\n\thop_lim = %d\n", __func__, hdr.version,
  732. ntohs(hdr.payload_len), hdr.nexthdr, hdr.hop_limit);
  733. lowpan_raw_dump_table(__func__, "raw header dump", (u8 *)&hdr,
  734. sizeof(hdr));
  735. return lowpan_skb_deliver(skb, &hdr);
  736. unlock_and_drop:
  737. spin_unlock(&flist_lock);
  738. drop:
  739. kfree_skb(skb);
  740. return -EINVAL;
  741. }
  742. static int lowpan_set_address(struct net_device *dev, void *p)
  743. {
  744. struct sockaddr *sa = p;
  745. if (netif_running(dev))
  746. return -EBUSY;
  747. /* TODO: validate addr */
  748. memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
  749. return 0;
  750. }
  751. static int lowpan_get_mac_header_length(struct sk_buff *skb)
  752. {
  753. /*
  754. * Currently long addressing mode is supported only, so the overall
  755. * header size is 21:
  756. * FC SeqNum DPAN DA SA Sec
  757. * 2 + 1 + 2 + 8 + 8 + 0 = 21
  758. */
  759. return 21;
  760. }
  761. static int
  762. lowpan_fragment_xmit(struct sk_buff *skb, u8 *head,
  763. int mlen, int plen, int offset)
  764. {
  765. struct sk_buff *frag;
  766. int hlen, ret;
  767. /* if payload length is zero, therefore it's a first fragment */
  768. hlen = (plen == 0 ? LOWPAN_FRAG1_HEAD_SIZE : LOWPAN_FRAGN_HEAD_SIZE);
  769. lowpan_raw_dump_inline(__func__, "6lowpan fragment header", head, hlen);
  770. frag = dev_alloc_skb(hlen + mlen + plen + IEEE802154_MFR_SIZE);
  771. if (!frag)
  772. return -ENOMEM;
  773. frag->priority = skb->priority;
  774. frag->dev = skb->dev;
  775. /* copy header, MFR and payload */
  776. memcpy(skb_put(frag, mlen), skb->data, mlen);
  777. memcpy(skb_put(frag, hlen), head, hlen);
  778. if (plen)
  779. skb_copy_from_linear_data_offset(skb, offset + mlen,
  780. skb_put(frag, plen), plen);
  781. lowpan_raw_dump_table(__func__, " raw fragment dump", frag->data,
  782. frag->len);
  783. ret = dev_queue_xmit(frag);
  784. if (ret < 0)
  785. dev_kfree_skb(frag);
  786. return ret;
  787. }
  788. static int
  789. lowpan_skb_fragmentation(struct sk_buff *skb)
  790. {
  791. int err, header_length, payload_length, tag, offset = 0;
  792. u8 head[5];
  793. header_length = lowpan_get_mac_header_length(skb);
  794. payload_length = skb->len - header_length;
  795. tag = fragment_tag++;
  796. /* first fragment header */
  797. head[0] = LOWPAN_DISPATCH_FRAG1 | (payload_length & 0x7);
  798. head[1] = (payload_length >> 3) & 0xff;
  799. head[2] = tag & 0xff;
  800. head[3] = tag >> 8;
  801. err = lowpan_fragment_xmit(skb, head, header_length, 0, 0);
  802. /* next fragment header */
  803. head[0] &= ~LOWPAN_DISPATCH_FRAG1;
  804. head[0] |= LOWPAN_DISPATCH_FRAGN;
  805. while ((payload_length - offset > 0) && (err >= 0)) {
  806. int len = LOWPAN_FRAG_SIZE;
  807. head[4] = offset / 8;
  808. if (payload_length - offset < len)
  809. len = payload_length - offset;
  810. err = lowpan_fragment_xmit(skb, head, header_length,
  811. len, offset);
  812. offset += len;
  813. }
  814. return err;
  815. }
  816. static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
  817. {
  818. int err = -1;
  819. pr_debug("(%s): package xmit\n", __func__);
  820. skb->dev = lowpan_dev_info(dev)->real_dev;
  821. if (skb->dev == NULL) {
  822. pr_debug("(%s) ERROR: no real wpan device found\n", __func__);
  823. goto error;
  824. }
  825. if (skb->len <= IEEE802154_MTU) {
  826. err = dev_queue_xmit(skb);
  827. goto out;
  828. }
  829. pr_debug("(%s): frame is too big, fragmentation is needed\n",
  830. __func__);
  831. err = lowpan_skb_fragmentation(skb);
  832. error:
  833. dev_kfree_skb(skb);
  834. out:
  835. if (err < 0)
  836. pr_debug("(%s): ERROR: xmit failed\n", __func__);
  837. return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK);
  838. }
  839. static void lowpan_dev_free(struct net_device *dev)
  840. {
  841. dev_put(lowpan_dev_info(dev)->real_dev);
  842. free_netdev(dev);
  843. }
  844. static struct header_ops lowpan_header_ops = {
  845. .create = lowpan_header_create,
  846. };
  847. static const struct net_device_ops lowpan_netdev_ops = {
  848. .ndo_start_xmit = lowpan_xmit,
  849. .ndo_set_mac_address = lowpan_set_address,
  850. };
  851. static void lowpan_setup(struct net_device *dev)
  852. {
  853. pr_debug("(%s)\n", __func__);
  854. dev->addr_len = IEEE802154_ADDR_LEN;
  855. memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
  856. dev->type = ARPHRD_IEEE802154;
  857. /* Frame Control + Sequence Number + Address fields + Security Header */
  858. dev->hard_header_len = 2 + 1 + 20 + 14;
  859. dev->needed_tailroom = 2; /* FCS */
  860. dev->mtu = 1281;
  861. dev->tx_queue_len = 0;
  862. dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  863. dev->watchdog_timeo = 0;
  864. dev->netdev_ops = &lowpan_netdev_ops;
  865. dev->header_ops = &lowpan_header_ops;
  866. dev->destructor = lowpan_dev_free;
  867. }
  868. static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
  869. {
  870. pr_debug("(%s)\n", __func__);
  871. if (tb[IFLA_ADDRESS]) {
  872. if (nla_len(tb[IFLA_ADDRESS]) != IEEE802154_ADDR_LEN)
  873. return -EINVAL;
  874. }
  875. return 0;
  876. }
  877. static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  878. struct packet_type *pt, struct net_device *orig_dev)
  879. {
  880. if (!netif_running(dev))
  881. goto drop;
  882. if (dev->type != ARPHRD_IEEE802154)
  883. goto drop;
  884. /* check that it's our buffer */
  885. switch (skb->data[0] & 0xe0) {
  886. case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */
  887. case LOWPAN_DISPATCH_FRAG1: /* first fragment header */
  888. case LOWPAN_DISPATCH_FRAGN: /* next fragments headers */
  889. lowpan_process_data(skb);
  890. break;
  891. default:
  892. break;
  893. }
  894. return NET_RX_SUCCESS;
  895. drop:
  896. kfree_skb(skb);
  897. return NET_RX_DROP;
  898. }
  899. static int lowpan_newlink(struct net *src_net, struct net_device *dev,
  900. struct nlattr *tb[], struct nlattr *data[])
  901. {
  902. struct net_device *real_dev;
  903. struct lowpan_dev_record *entry;
  904. pr_debug("(%s)\n", __func__);
  905. if (!tb[IFLA_LINK])
  906. return -EINVAL;
  907. /* find and hold real wpan device */
  908. real_dev = dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
  909. if (!real_dev)
  910. return -ENODEV;
  911. lowpan_dev_info(dev)->real_dev = real_dev;
  912. mutex_init(&lowpan_dev_info(dev)->dev_list_mtx);
  913. entry = kzalloc(sizeof(struct lowpan_dev_record), GFP_KERNEL);
  914. if (!entry) {
  915. dev_put(real_dev);
  916. lowpan_dev_info(dev)->real_dev = NULL;
  917. return -ENOMEM;
  918. }
  919. entry->ldev = dev;
  920. mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
  921. INIT_LIST_HEAD(&entry->list);
  922. list_add_tail(&entry->list, &lowpan_devices);
  923. mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
  924. register_netdevice(dev);
  925. return 0;
  926. }
  927. static void lowpan_dellink(struct net_device *dev, struct list_head *head)
  928. {
  929. struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
  930. struct net_device *real_dev = lowpan_dev->real_dev;
  931. struct lowpan_dev_record *entry;
  932. struct lowpan_dev_record *tmp;
  933. ASSERT_RTNL();
  934. mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
  935. list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
  936. if (entry->ldev == dev) {
  937. list_del(&entry->list);
  938. kfree(entry);
  939. }
  940. }
  941. mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
  942. mutex_destroy(&lowpan_dev_info(dev)->dev_list_mtx);
  943. unregister_netdevice_queue(dev, head);
  944. dev_put(real_dev);
  945. }
  946. static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
  947. .kind = "lowpan",
  948. .priv_size = sizeof(struct lowpan_dev_info),
  949. .setup = lowpan_setup,
  950. .newlink = lowpan_newlink,
  951. .dellink = lowpan_dellink,
  952. .validate = lowpan_validate,
  953. };
  954. static inline int __init lowpan_netlink_init(void)
  955. {
  956. return rtnl_link_register(&lowpan_link_ops);
  957. }
  958. static inline void __init lowpan_netlink_fini(void)
  959. {
  960. rtnl_link_unregister(&lowpan_link_ops);
  961. }
  962. static struct packet_type lowpan_packet_type = {
  963. .type = __constant_htons(ETH_P_IEEE802154),
  964. .func = lowpan_rcv,
  965. };
  966. static int __init lowpan_init_module(void)
  967. {
  968. int err = 0;
  969. pr_debug("(%s)\n", __func__);
  970. err = lowpan_netlink_init();
  971. if (err < 0)
  972. goto out;
  973. dev_add_pack(&lowpan_packet_type);
  974. out:
  975. return err;
  976. }
  977. static void __exit lowpan_cleanup_module(void)
  978. {
  979. pr_debug("(%s)\n", __func__);
  980. lowpan_netlink_fini();
  981. dev_remove_pack(&lowpan_packet_type);
  982. }
  983. module_init(lowpan_init_module);
  984. module_exit(lowpan_cleanup_module);
  985. MODULE_LICENSE("GPL");
  986. MODULE_ALIAS_RTNL_LINK("lowpan");