1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
11 * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
14 #include <linux/module.h>
16 #include <net/6lowpan.h>
18 #include "6lowpan_i.h"
20 int lowpan_register_netdevice(struct net_device
*dev
,
21 enum lowpan_lltypes lltype
)
25 dev
->addr_len
= EUI64_ADDR_LEN
;
26 dev
->type
= ARPHRD_6LOWPAN
;
27 dev
->mtu
= IPV6_MIN_MTU
;
28 dev
->priv_flags
|= IFF_NO_QUEUE
;
30 lowpan_priv(dev
)->lltype
= lltype
;
32 spin_lock_init(&lowpan_priv(dev
)->ctx
.lock
);
33 for (i
= 0; i
< LOWPAN_IPHC_CTX_TABLE_SIZE
; i
++)
34 lowpan_priv(dev
)->ctx
.table
[i
].id
= i
;
36 ret
= register_netdevice(dev
);
40 ret
= lowpan_dev_debugfs_init(dev
);
42 unregister_netdevice(dev
);
46 EXPORT_SYMBOL(lowpan_register_netdevice
);
48 int lowpan_register_netdev(struct net_device
*dev
,
49 enum lowpan_lltypes lltype
)
54 ret
= lowpan_register_netdevice(dev
, lltype
);
58 EXPORT_SYMBOL(lowpan_register_netdev
);
60 void lowpan_unregister_netdevice(struct net_device
*dev
)
62 unregister_netdevice(dev
);
63 lowpan_dev_debugfs_exit(dev
);
65 EXPORT_SYMBOL(lowpan_unregister_netdevice
);
67 void lowpan_unregister_netdev(struct net_device
*dev
)
70 lowpan_unregister_netdevice(dev
);
73 EXPORT_SYMBOL(lowpan_unregister_netdev
);
75 static int lowpan_event(struct notifier_block
*unused
,
76 unsigned long event
, void *ptr
)
78 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
81 if (dev
->type
!= ARPHRD_6LOWPAN
)
86 for (i
= 0; i
< LOWPAN_IPHC_CTX_TABLE_SIZE
; i
++)
87 clear_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE
,
88 &lowpan_priv(dev
)->ctx
.table
[i
].flags
);
97 static struct notifier_block lowpan_notifier
= {
98 .notifier_call
= lowpan_event
,
101 static int __init
lowpan_module_init(void)
105 ret
= lowpan_debugfs_init();
109 ret
= register_netdevice_notifier(&lowpan_notifier
);
111 lowpan_debugfs_exit();
115 request_module_nowait("ipv6");
117 request_module_nowait("nhc_dest");
118 request_module_nowait("nhc_fragment");
119 request_module_nowait("nhc_hop");
120 request_module_nowait("nhc_ipv6");
121 request_module_nowait("nhc_mobility");
122 request_module_nowait("nhc_routing");
123 request_module_nowait("nhc_udp");
128 static void __exit
lowpan_module_exit(void)
130 lowpan_debugfs_exit();
131 unregister_netdevice_notifier(&lowpan_notifier
);
134 module_init(lowpan_module_init
);
135 module_exit(lowpan_module_exit
);
137 MODULE_LICENSE("GPL");