]>
Commit | Line | Data |
---|---|---|
2c21d115 SL |
1 | /* |
2 | * Netlink inteface for IEEE 802.15.4 stack | |
3 | * | |
4 | * Copyright 2007, 2008 Siemens AG | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | * | |
19 | * Written by: | |
20 | * Sergey Lapin <slapin@ossfans.org> | |
21 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | |
8e753dd0 | 22 | * Maxim Osipov <maxim.osipov@siemens.com> |
2c21d115 SL |
23 | */ |
24 | ||
25 | #include <linux/kernel.h> | |
2c21d115 SL |
26 | #include <net/genetlink.h> |
27 | #include <linux/nl802154.h> | |
78fe738d DB |
28 | |
29 | #include "ieee802154.h" | |
2c21d115 SL |
30 | |
31 | static unsigned int ieee802154_seq_num; | |
c4835d81 | 32 | static DEFINE_SPINLOCK(ieee802154_seq_lock); |
2c21d115 | 33 | |
78fe738d | 34 | struct genl_family nl802154_family = { |
2c21d115 SL |
35 | .id = GENL_ID_GENERATE, |
36 | .hdrsize = 0, | |
37 | .name = IEEE802154_NL_NAME, | |
38 | .version = 1, | |
39 | .maxattr = IEEE802154_ATTR_MAX, | |
40 | }; | |
41 | ||
2c21d115 | 42 | /* Requests to userspace */ |
78fe738d | 43 | struct sk_buff *ieee802154_nl_create(int flags, u8 req) |
2c21d115 SL |
44 | { |
45 | void *hdr; | |
46 | struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); | |
c4835d81 | 47 | unsigned long f; |
2c21d115 SL |
48 | |
49 | if (!msg) | |
50 | return NULL; | |
51 | ||
c4835d81 | 52 | spin_lock_irqsave(&ieee802154_seq_lock, f); |
2c21d115 | 53 | hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, |
78fe738d | 54 | &nl802154_family, flags, req); |
c4835d81 | 55 | spin_unlock_irqrestore(&ieee802154_seq_lock, f); |
2c21d115 SL |
56 | if (!hdr) { |
57 | nlmsg_free(msg); | |
58 | return NULL; | |
59 | } | |
60 | ||
61 | return msg; | |
62 | } | |
63 | ||
78fe738d | 64 | int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group) |
2c21d115 SL |
65 | { |
66 | /* XXX: nlh is right at the start of msg */ | |
67 | void *hdr = genlmsg_data(NLMSG_DATA(msg->data)); | |
68 | ||
8e753dd0 | 69 | if (genlmsg_end(msg, hdr) < 0) |
2c21d115 SL |
70 | goto out; |
71 | ||
78fe738d | 72 | return genlmsg_multicast(msg, 0, group, GFP_ATOMIC); |
2c21d115 SL |
73 | out: |
74 | nlmsg_free(msg); | |
75 | return -ENOBUFS; | |
76 | } | |
77 | ||
cb6b3763 | 78 | int __init ieee802154_nl_init(void) |
2c21d115 SL |
79 | { |
80 | int rc; | |
2c21d115 | 81 | |
78fe738d | 82 | rc = genl_register_family(&nl802154_family); |
2c21d115 SL |
83 | if (rc) |
84 | goto fail; | |
85 | ||
78fe738d | 86 | rc = nl802154_mac_register(); |
2c21d115 SL |
87 | if (rc) |
88 | goto fail; | |
89 | ||
1eaa9d03 DB |
90 | rc = nl802154_phy_register(); |
91 | if (rc) | |
92 | goto fail; | |
93 | ||
2c21d115 SL |
94 | return 0; |
95 | ||
96 | fail: | |
78fe738d | 97 | genl_unregister_family(&nl802154_family); |
2c21d115 SL |
98 | return rc; |
99 | } | |
2c21d115 | 100 | |
cb6b3763 | 101 | void __exit ieee802154_nl_exit(void) |
2c21d115 | 102 | { |
78fe738d | 103 | genl_unregister_family(&nl802154_family); |
2c21d115 | 104 | } |
dfd06fe8 | 105 |