ieee802154: change _cb handling slightly
[pandora-kernel.git] / net / ieee802154 / 6lowpan_rtnl.c
1 /* Copyright 2011, Siemens AG
2  * written by Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
3  */
4
5 /* Based on patches from Jon Smirl <jonsmirl@gmail.com>
6  * Copyright (c) 2011 Jon Smirl <jonsmirl@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17
18 /* Jon's code is based on 6lowpan implementation for Contiki which is:
19  * Copyright (c) 2008, Swedish Institute of Computer Science.
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. Neither the name of the Institute nor the names of its contributors
31  *    may be used to endorse or promote products derived from this software
32  *    without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
35  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
38  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  */
46
47 #include <linux/bitops.h>
48 #include <linux/if_arp.h>
49 #include <linux/module.h>
50 #include <linux/moduleparam.h>
51 #include <linux/netdevice.h>
52 #include <net/af_ieee802154.h>
53 #include <net/ieee802154.h>
54 #include <net/ieee802154_netdev.h>
55 #include <net/6lowpan.h>
56 #include <net/ipv6.h>
57
58 #include "reassembly.h"
59
60 static LIST_HEAD(lowpan_devices);
61
62 /* private device info */
63 struct lowpan_dev_info {
64         struct net_device       *real_dev; /* real WPAN device ptr */
65         struct mutex            dev_list_mtx; /* mutex for list ops */
66         __be16                  fragment_tag;
67 };
68
69 struct lowpan_dev_record {
70         struct net_device *ldev;
71         struct list_head list;
72 };
73
74 static inline struct
75 lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
76 {
77         return netdev_priv(dev);
78 }
79
80 static inline void lowpan_address_flip(u8 *src, u8 *dest)
81 {
82         int i;
83         for (i = 0; i < IEEE802154_ADDR_LEN; i++)
84                 (dest)[IEEE802154_ADDR_LEN - i - 1] = (src)[i];
85 }
86
87 static int lowpan_header_create(struct sk_buff *skb,
88                            struct net_device *dev,
89                            unsigned short type, const void *_daddr,
90                            const void *_saddr, unsigned int len)
91 {
92         const u8 *saddr = _saddr;
93         const u8 *daddr = _daddr;
94         struct ieee802154_addr sa, da;
95         struct ieee802154_mac_cb *cb = mac_cb_init(skb);
96
97         /* TODO:
98          * if this package isn't ipv6 one, where should it be routed?
99          */
100         if (type != ETH_P_IPV6)
101                 return 0;
102
103         if (!saddr)
104                 saddr = dev->dev_addr;
105
106         raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
107         raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
108
109         lowpan_header_compress(skb, dev, type, daddr, saddr, len);
110
111         /* NOTE1: I'm still unsure about the fact that compression and WPAN
112          * header are created here and not later in the xmit. So wait for
113          * an opinion of net maintainers.
114          */
115         /* NOTE2: to be absolutely correct, we must derive PANid information
116          * from MAC subif of the 'dev' and 'real_dev' network devices, but
117          * this isn't implemented in mainline yet, so currently we assign 0xff
118          */
119         cb->type = IEEE802154_FC_TYPE_DATA;
120
121         /* prepare wpan address data */
122         sa.mode = IEEE802154_ADDR_LONG;
123         sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
124         sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
125
126         /* intra-PAN communications */
127         da.pan_id = sa.pan_id;
128
129         /* if the destination address is the broadcast address, use the
130          * corresponding short address
131          */
132         if (lowpan_is_addr_broadcast(daddr)) {
133                 da.mode = IEEE802154_ADDR_SHORT;
134                 da.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
135         } else {
136                 da.mode = IEEE802154_ADDR_LONG;
137                 da.extended_addr = ieee802154_devaddr_from_raw(daddr);
138         }
139
140         cb->ackreq = !lowpan_is_addr_broadcast(daddr);
141
142         return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
143                         type, (void *)&da, (void *)&sa, 0);
144 }
145
146 static int lowpan_give_skb_to_devices(struct sk_buff *skb,
147                                         struct net_device *dev)
148 {
149         struct lowpan_dev_record *entry;
150         struct sk_buff *skb_cp;
151         int stat = NET_RX_SUCCESS;
152
153         rcu_read_lock();
154         list_for_each_entry_rcu(entry, &lowpan_devices, list)
155                 if (lowpan_dev_info(entry->ldev)->real_dev == skb->dev) {
156                         skb_cp = skb_copy(skb, GFP_ATOMIC);
157                         if (!skb_cp) {
158                                 stat = -ENOMEM;
159                                 break;
160                         }
161
162                         skb_cp->dev = entry->ldev;
163                         stat = netif_rx(skb_cp);
164                 }
165         rcu_read_unlock();
166
167         return stat;
168 }
169
170 static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
171 {
172         u8 iphc0, iphc1;
173         struct ieee802154_addr_sa sa, da;
174         void *sap, *dap;
175
176         raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
177         /* at least two bytes will be used for the encoding */
178         if (skb->len < 2)
179                 goto drop;
180
181         if (lowpan_fetch_skb_u8(skb, &iphc0))
182                 goto drop;
183
184         if (lowpan_fetch_skb_u8(skb, &iphc1))
185                 goto drop;
186
187         ieee802154_addr_to_sa(&sa, &hdr->source);
188         ieee802154_addr_to_sa(&da, &hdr->dest);
189
190         if (sa.addr_type == IEEE802154_ADDR_SHORT)
191                 sap = &sa.short_addr;
192         else
193                 sap = &sa.hwaddr;
194
195         if (da.addr_type == IEEE802154_ADDR_SHORT)
196                 dap = &da.short_addr;
197         else
198                 dap = &da.hwaddr;
199
200         return lowpan_process_data(skb, skb->dev, sap, sa.addr_type,
201                                    IEEE802154_ADDR_LEN, dap, da.addr_type,
202                                    IEEE802154_ADDR_LEN, iphc0, iphc1,
203                                    lowpan_give_skb_to_devices);
204
205 drop:
206         kfree_skb(skb);
207         return -EINVAL;
208 }
209
210 static int lowpan_set_address(struct net_device *dev, void *p)
211 {
212         struct sockaddr *sa = p;
213
214         if (netif_running(dev))
215                 return -EBUSY;
216
217         /* TODO: validate addr */
218         memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
219
220         return 0;
221 }
222
223 static int
224 lowpan_fragment_xmit(struct sk_buff *skb, u8 *head,
225                      int mlen, int plen, int offset, int type)
226 {
227         struct sk_buff *frag;
228         int hlen;
229
230         hlen = (type == LOWPAN_DISPATCH_FRAG1) ?
231                         LOWPAN_FRAG1_HEAD_SIZE : LOWPAN_FRAGN_HEAD_SIZE;
232
233         raw_dump_inline(__func__, "6lowpan fragment header", head, hlen);
234
235         frag = netdev_alloc_skb(skb->dev,
236                                 hlen + mlen + plen + IEEE802154_MFR_SIZE);
237         if (!frag)
238                 return -ENOMEM;
239
240         frag->priority = skb->priority;
241
242         /* copy header, MFR and payload */
243         skb_put(frag, mlen);
244         skb_copy_to_linear_data(frag, skb_mac_header(skb), mlen);
245
246         skb_put(frag, hlen);
247         skb_copy_to_linear_data_offset(frag, mlen, head, hlen);
248
249         skb_put(frag, plen);
250         skb_copy_to_linear_data_offset(frag, mlen + hlen,
251                                        skb_network_header(skb) + offset, plen);
252
253         raw_dump_table(__func__, " raw fragment dump", frag->data, frag->len);
254
255         return dev_queue_xmit(frag);
256 }
257
258 static int
259 lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
260 {
261         int err;
262         u16 dgram_offset, dgram_size, payload_length, header_length,
263             lowpan_size, frag_plen, offset;
264         __be16 tag;
265         u8 head[5];
266
267         header_length = skb->mac_len;
268         payload_length = skb->len - header_length;
269         tag = lowpan_dev_info(dev)->fragment_tag++;
270         lowpan_size = skb_network_header_len(skb);
271         dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
272                      header_length;
273
274         /* first fragment header */
275         head[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x7);
276         head[1] = dgram_size & 0xff;
277         memcpy(head + 2, &tag, sizeof(tag));
278
279         /* calc the nearest payload length(divided to 8) for first fragment
280          * which fits into a IEEE802154_MTU
281          */
282         frag_plen = round_down(IEEE802154_MTU - header_length -
283                                LOWPAN_FRAG1_HEAD_SIZE - lowpan_size -
284                                IEEE802154_MFR_SIZE, 8);
285
286         err = lowpan_fragment_xmit(skb, head, header_length,
287                                    frag_plen + lowpan_size, 0,
288                                    LOWPAN_DISPATCH_FRAG1);
289         if (err) {
290                 pr_debug("%s unable to send FRAG1 packet (tag: %d)",
291                          __func__, tag);
292                 goto exit;
293         }
294
295         offset = lowpan_size + frag_plen;
296         dgram_offset += frag_plen;
297
298         /* next fragment header */
299         head[0] &= ~LOWPAN_DISPATCH_FRAG1;
300         head[0] |= LOWPAN_DISPATCH_FRAGN;
301
302         frag_plen = round_down(IEEE802154_MTU - header_length -
303                                LOWPAN_FRAGN_HEAD_SIZE - IEEE802154_MFR_SIZE, 8);
304
305         while (payload_length - offset > 0) {
306                 int len = frag_plen;
307
308                 head[4] = dgram_offset >> 3;
309
310                 if (payload_length - offset < len)
311                         len = payload_length - offset;
312
313                 err = lowpan_fragment_xmit(skb, head, header_length, len,
314                                            offset, LOWPAN_DISPATCH_FRAGN);
315                 if (err) {
316                         pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
317                                  __func__, tag, offset);
318                         goto exit;
319                 }
320
321                 offset += len;
322                 dgram_offset += len;
323         }
324
325 exit:
326         return err;
327 }
328
329 static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
330 {
331         int err = -1;
332
333         pr_debug("package xmit\n");
334
335         skb->dev = lowpan_dev_info(dev)->real_dev;
336         if (skb->dev == NULL) {
337                 pr_debug("ERROR: no real wpan device found\n");
338                 goto error;
339         }
340
341         /* Send directly if less than the MTU minus the 2 checksum bytes. */
342         if (skb->len <= IEEE802154_MTU - IEEE802154_MFR_SIZE) {
343                 err = dev_queue_xmit(skb);
344                 goto out;
345         }
346
347         pr_debug("frame is too big, fragmentation is needed\n");
348         err = lowpan_skb_fragmentation(skb, dev);
349 error:
350         dev_kfree_skb(skb);
351 out:
352         if (err)
353                 pr_debug("ERROR: xmit failed\n");
354
355         return (err < 0) ? NET_XMIT_DROP : err;
356 }
357
358 static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
359 {
360         struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
361         return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
362 }
363
364 static __le16 lowpan_get_pan_id(const struct net_device *dev)
365 {
366         struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
367         return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
368 }
369
370 static __le16 lowpan_get_short_addr(const struct net_device *dev)
371 {
372         struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
373         return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);
374 }
375
376 static u8 lowpan_get_dsn(const struct net_device *dev)
377 {
378         struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
379         return ieee802154_mlme_ops(real_dev)->get_dsn(real_dev);
380 }
381
382 static struct header_ops lowpan_header_ops = {
383         .create = lowpan_header_create,
384 };
385
386 static struct lock_class_key lowpan_tx_busylock;
387 static struct lock_class_key lowpan_netdev_xmit_lock_key;
388
389 static void lowpan_set_lockdep_class_one(struct net_device *dev,
390                                          struct netdev_queue *txq,
391                                          void *_unused)
392 {
393         lockdep_set_class(&txq->_xmit_lock,
394                           &lowpan_netdev_xmit_lock_key);
395 }
396
397
398 static int lowpan_dev_init(struct net_device *dev)
399 {
400         netdev_for_each_tx_queue(dev, lowpan_set_lockdep_class_one, NULL);
401         dev->qdisc_tx_busylock = &lowpan_tx_busylock;
402         return 0;
403 }
404
405 static const struct net_device_ops lowpan_netdev_ops = {
406         .ndo_init               = lowpan_dev_init,
407         .ndo_start_xmit         = lowpan_xmit,
408         .ndo_set_mac_address    = lowpan_set_address,
409 };
410
411 static struct ieee802154_mlme_ops lowpan_mlme = {
412         .get_pan_id = lowpan_get_pan_id,
413         .get_phy = lowpan_get_phy,
414         .get_short_addr = lowpan_get_short_addr,
415         .get_dsn = lowpan_get_dsn,
416 };
417
418 static void lowpan_setup(struct net_device *dev)
419 {
420         dev->addr_len           = IEEE802154_ADDR_LEN;
421         memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
422         dev->type               = ARPHRD_IEEE802154;
423         /* Frame Control + Sequence Number + Address fields + Security Header */
424         dev->hard_header_len    = 2 + 1 + 20 + 14;
425         dev->needed_tailroom    = 2; /* FCS */
426         dev->mtu                = 1281;
427         dev->tx_queue_len       = 0;
428         dev->flags              = IFF_BROADCAST | IFF_MULTICAST;
429         dev->watchdog_timeo     = 0;
430
431         dev->netdev_ops         = &lowpan_netdev_ops;
432         dev->header_ops         = &lowpan_header_ops;
433         dev->ml_priv            = &lowpan_mlme;
434         dev->destructor         = free_netdev;
435 }
436
437 static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
438 {
439         if (tb[IFLA_ADDRESS]) {
440                 if (nla_len(tb[IFLA_ADDRESS]) != IEEE802154_ADDR_LEN)
441                         return -EINVAL;
442         }
443         return 0;
444 }
445
446 static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
447         struct packet_type *pt, struct net_device *orig_dev)
448 {
449         struct ieee802154_hdr hdr;
450         int ret;
451
452         skb = skb_share_check(skb, GFP_ATOMIC);
453         if (!skb)
454                 goto drop;
455
456         if (!netif_running(dev))
457                 goto drop_skb;
458
459         if (dev->type != ARPHRD_IEEE802154)
460                 goto drop_skb;
461
462         if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
463                 goto drop_skb;
464
465         /* check that it's our buffer */
466         if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
467                 skb->protocol = htons(ETH_P_IPV6);
468                 skb->pkt_type = PACKET_HOST;
469
470                 /* Pull off the 1-byte of 6lowpan header. */
471                 skb_pull(skb, 1);
472
473                 ret = lowpan_give_skb_to_devices(skb, NULL);
474                 if (ret == NET_RX_DROP)
475                         goto drop;
476         } else {
477                 switch (skb->data[0] & 0xe0) {
478                 case LOWPAN_DISPATCH_IPHC:      /* ipv6 datagram */
479                         ret = process_data(skb, &hdr);
480                         if (ret == NET_RX_DROP)
481                                 goto drop;
482                         break;
483                 case LOWPAN_DISPATCH_FRAG1:     /* first fragment header */
484                         ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
485                         if (ret == 1) {
486                                 ret = process_data(skb, &hdr);
487                                 if (ret == NET_RX_DROP)
488                                         goto drop;
489                         }
490                         break;
491                 case LOWPAN_DISPATCH_FRAGN:     /* next fragments headers */
492                         ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
493                         if (ret == 1) {
494                                 ret = process_data(skb, &hdr);
495                                 if (ret == NET_RX_DROP)
496                                         goto drop;
497                         }
498                         break;
499                 default:
500                         break;
501                 }
502         }
503
504         return NET_RX_SUCCESS;
505 drop_skb:
506         kfree_skb(skb);
507 drop:
508         return NET_RX_DROP;
509 }
510
511 static int lowpan_newlink(struct net *src_net, struct net_device *dev,
512                           struct nlattr *tb[], struct nlattr *data[])
513 {
514         struct net_device *real_dev;
515         struct lowpan_dev_record *entry;
516
517         pr_debug("adding new link\n");
518
519         if (!tb[IFLA_LINK])
520                 return -EINVAL;
521         /* find and hold real wpan device */
522         real_dev = dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
523         if (!real_dev)
524                 return -ENODEV;
525         if (real_dev->type != ARPHRD_IEEE802154) {
526                 dev_put(real_dev);
527                 return -EINVAL;
528         }
529
530         lowpan_dev_info(dev)->real_dev = real_dev;
531         mutex_init(&lowpan_dev_info(dev)->dev_list_mtx);
532
533         entry = kzalloc(sizeof(*entry), GFP_KERNEL);
534         if (!entry) {
535                 dev_put(real_dev);
536                 lowpan_dev_info(dev)->real_dev = NULL;
537                 return -ENOMEM;
538         }
539
540         entry->ldev = dev;
541
542         /* Set the lowpan harware address to the wpan hardware address. */
543         memcpy(dev->dev_addr, real_dev->dev_addr, IEEE802154_ADDR_LEN);
544
545         mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
546         INIT_LIST_HEAD(&entry->list);
547         list_add_tail(&entry->list, &lowpan_devices);
548         mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
549
550         register_netdevice(dev);
551
552         return 0;
553 }
554
555 static void lowpan_dellink(struct net_device *dev, struct list_head *head)
556 {
557         struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
558         struct net_device *real_dev = lowpan_dev->real_dev;
559         struct lowpan_dev_record *entry, *tmp;
560
561         ASSERT_RTNL();
562
563         mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
564         list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
565                 if (entry->ldev == dev) {
566                         list_del(&entry->list);
567                         kfree(entry);
568                 }
569         }
570         mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
571
572         mutex_destroy(&lowpan_dev_info(dev)->dev_list_mtx);
573
574         unregister_netdevice_queue(dev, head);
575
576         dev_put(real_dev);
577 }
578
579 static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
580         .kind           = "lowpan",
581         .priv_size      = sizeof(struct lowpan_dev_info),
582         .setup          = lowpan_setup,
583         .newlink        = lowpan_newlink,
584         .dellink        = lowpan_dellink,
585         .validate       = lowpan_validate,
586 };
587
588 static inline int __init lowpan_netlink_init(void)
589 {
590         return rtnl_link_register(&lowpan_link_ops);
591 }
592
593 static inline void lowpan_netlink_fini(void)
594 {
595         rtnl_link_unregister(&lowpan_link_ops);
596 }
597
598 static int lowpan_device_event(struct notifier_block *unused,
599                                unsigned long event, void *ptr)
600 {
601         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
602         LIST_HEAD(del_list);
603         struct lowpan_dev_record *entry, *tmp;
604
605         if (dev->type != ARPHRD_IEEE802154)
606                 goto out;
607
608         if (event == NETDEV_UNREGISTER) {
609                 list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
610                         if (lowpan_dev_info(entry->ldev)->real_dev == dev)
611                                 lowpan_dellink(entry->ldev, &del_list);
612                 }
613
614                 unregister_netdevice_many(&del_list);
615         }
616
617 out:
618         return NOTIFY_DONE;
619 }
620
621 static struct notifier_block lowpan_dev_notifier = {
622         .notifier_call = lowpan_device_event,
623 };
624
625 static struct packet_type lowpan_packet_type = {
626         .type = htons(ETH_P_IEEE802154),
627         .func = lowpan_rcv,
628 };
629
630 static int __init lowpan_init_module(void)
631 {
632         int err = 0;
633
634         err = lowpan_net_frag_init();
635         if (err < 0)
636                 goto out;
637
638         err = lowpan_netlink_init();
639         if (err < 0)
640                 goto out_frag;
641
642         dev_add_pack(&lowpan_packet_type);
643
644         err = register_netdevice_notifier(&lowpan_dev_notifier);
645         if (err < 0)
646                 goto out_pack;
647
648         return 0;
649
650 out_pack:
651         dev_remove_pack(&lowpan_packet_type);
652         lowpan_netlink_fini();
653 out_frag:
654         lowpan_net_frag_exit();
655 out:
656         return err;
657 }
658
659 static void __exit lowpan_cleanup_module(void)
660 {
661         lowpan_netlink_fini();
662
663         dev_remove_pack(&lowpan_packet_type);
664
665         lowpan_net_frag_exit();
666
667         unregister_netdevice_notifier(&lowpan_dev_notifier);
668 }
669
670 module_init(lowpan_init_module);
671 module_exit(lowpan_cleanup_module);
672 MODULE_LICENSE("GPL");
673 MODULE_ALIAS_RTNL_LINK("lowpan");