Alexander Aring | b72f6f5 | 2015-08-11 21:44:08 +0200 | [diff] [blame] | 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. |
| 4 | * |
| 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. |
| 9 | * |
| 10 | * Authors: |
| 11 | * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de> |
| 12 | */ |
| 13 | |
Alexander Aring | 4ae935c | 2015-08-11 21:44:09 +0200 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | |
Alexander Aring | b72f6f5 | 2015-08-11 21:44:08 +0200 | [diff] [blame] | 16 | #include <net/6lowpan.h> |
| 17 | |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 18 | #include "6lowpan_i.h" |
| 19 | |
Alexander Aring | 00f5931 | 2015-12-09 22:46:29 +0100 | [diff] [blame] | 20 | int lowpan_register_netdevice(struct net_device *dev, |
| 21 | enum lowpan_lltypes lltype) |
Alexander Aring | b72f6f5 | 2015-08-11 21:44:08 +0200 | [diff] [blame] | 22 | { |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 23 | int ret; |
| 24 | |
Alexander Aring | 4d6a6ae | 2015-10-02 20:28:04 +0200 | [diff] [blame] | 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; |
| 29 | |
Alexander Aring | b72f6f5 | 2015-08-11 21:44:08 +0200 | [diff] [blame] | 30 | lowpan_priv(dev)->lltype = lltype; |
Alexander Aring | 00f5931 | 2015-12-09 22:46:29 +0100 | [diff] [blame] | 31 | |
Alexander Aring | 92e17ee | 2015-12-15 12:25:35 +0100 | [diff] [blame] | 32 | ret = register_netdevice(dev); |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 33 | if (ret < 0) |
| 34 | return ret; |
| 35 | |
Alexander Aring | 92e17ee | 2015-12-15 12:25:35 +0100 | [diff] [blame] | 36 | ret = lowpan_dev_debugfs_init(dev); |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 37 | if (ret < 0) |
Alexander Aring | 92e17ee | 2015-12-15 12:25:35 +0100 | [diff] [blame] | 38 | unregister_netdevice(dev); |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 39 | |
| 40 | return ret; |
Alexander Aring | b72f6f5 | 2015-08-11 21:44:08 +0200 | [diff] [blame] | 41 | } |
Alexander Aring | 00f5931 | 2015-12-09 22:46:29 +0100 | [diff] [blame] | 42 | EXPORT_SYMBOL(lowpan_register_netdevice); |
| 43 | |
| 44 | int lowpan_register_netdev(struct net_device *dev, |
| 45 | enum lowpan_lltypes lltype) |
| 46 | { |
| 47 | int ret; |
| 48 | |
| 49 | rtnl_lock(); |
| 50 | ret = lowpan_register_netdevice(dev, lltype); |
| 51 | rtnl_unlock(); |
| 52 | return ret; |
| 53 | } |
| 54 | EXPORT_SYMBOL(lowpan_register_netdev); |
| 55 | |
| 56 | void lowpan_unregister_netdevice(struct net_device *dev) |
| 57 | { |
| 58 | unregister_netdevice(dev); |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 59 | lowpan_dev_debugfs_exit(dev); |
Alexander Aring | 00f5931 | 2015-12-09 22:46:29 +0100 | [diff] [blame] | 60 | } |
| 61 | EXPORT_SYMBOL(lowpan_unregister_netdevice); |
| 62 | |
| 63 | void lowpan_unregister_netdev(struct net_device *dev) |
| 64 | { |
| 65 | rtnl_lock(); |
| 66 | lowpan_unregister_netdevice(dev); |
| 67 | rtnl_unlock(); |
| 68 | } |
| 69 | EXPORT_SYMBOL(lowpan_unregister_netdev); |
Alexander Aring | 4ae935c | 2015-08-11 21:44:09 +0200 | [diff] [blame] | 70 | |
| 71 | static int __init lowpan_module_init(void) |
| 72 | { |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 73 | int ret; |
| 74 | |
| 75 | ret = lowpan_debugfs_init(); |
| 76 | if (ret < 0) |
| 77 | return ret; |
| 78 | |
Alexander Aring | 4ae935c | 2015-08-11 21:44:09 +0200 | [diff] [blame] | 79 | request_module_nowait("ipv6"); |
| 80 | |
| 81 | request_module_nowait("nhc_dest"); |
| 82 | request_module_nowait("nhc_fragment"); |
| 83 | request_module_nowait("nhc_hop"); |
| 84 | request_module_nowait("nhc_ipv6"); |
| 85 | request_module_nowait("nhc_mobility"); |
| 86 | request_module_nowait("nhc_routing"); |
| 87 | request_module_nowait("nhc_udp"); |
| 88 | |
| 89 | return 0; |
| 90 | } |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 91 | |
| 92 | static void __exit lowpan_module_exit(void) |
| 93 | { |
| 94 | lowpan_debugfs_exit(); |
| 95 | } |
| 96 | |
Alexander Aring | 4ae935c | 2015-08-11 21:44:09 +0200 | [diff] [blame] | 97 | module_init(lowpan_module_init); |
Alexander Aring | b1815fd | 2015-12-09 22:46:30 +0100 | [diff] [blame] | 98 | module_exit(lowpan_module_exit); |
Alexander Aring | 4ae935c | 2015-08-11 21:44:09 +0200 | [diff] [blame] | 99 | |
| 100 | MODULE_LICENSE("GPL"); |