Commit | Line | Data |
---|---|---|
2c21d115 | 1 | /* |
69bb631e | 2 | * Netlink interface for IEEE 802.15.4 stack |
2c21d115 SL |
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 | * | |
2c21d115 SL |
15 | * Written by: |
16 | * Sergey Lapin <slapin@ossfans.org> | |
17 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | |
8e753dd0 | 18 | * Maxim Osipov <maxim.osipov@siemens.com> |
2c21d115 SL |
19 | */ |
20 | ||
21 | #include <linux/kernel.h> | |
5a0e3ad6 | 22 | #include <linux/gfp.h> |
2c21d115 SL |
23 | #include <net/genetlink.h> |
24 | #include <linux/nl802154.h> | |
78fe738d DES |
25 | |
26 | #include "ieee802154.h" | |
2c21d115 SL |
27 | |
28 | static unsigned int ieee802154_seq_num; | |
c4835d81 | 29 | static DEFINE_SPINLOCK(ieee802154_seq_lock); |
2c21d115 | 30 | |
78fe738d | 31 | struct genl_family nl802154_family = { |
2c21d115 SL |
32 | .id = GENL_ID_GENERATE, |
33 | .hdrsize = 0, | |
34 | .name = IEEE802154_NL_NAME, | |
35 | .version = 1, | |
36 | .maxattr = IEEE802154_ATTR_MAX, | |
37 | }; | |
38 | ||
2c21d115 | 39 | /* Requests to userspace */ |
78fe738d | 40 | struct sk_buff *ieee802154_nl_create(int flags, u8 req) |
2c21d115 SL |
41 | { |
42 | void *hdr; | |
58050fce | 43 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
c4835d81 | 44 | unsigned long f; |
2c21d115 SL |
45 | |
46 | if (!msg) | |
47 | return NULL; | |
48 | ||
c4835d81 | 49 | spin_lock_irqsave(&ieee802154_seq_lock, f); |
2c21d115 | 50 | hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, |
4710d806 | 51 | &nl802154_family, flags, req); |
c4835d81 | 52 | spin_unlock_irqrestore(&ieee802154_seq_lock, f); |
2c21d115 SL |
53 | if (!hdr) { |
54 | nlmsg_free(msg); | |
55 | return NULL; | |
56 | } | |
57 | ||
58 | return msg; | |
59 | } | |
60 | ||
78fe738d | 61 | int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group) |
2c21d115 | 62 | { |
10c9cbb1 H |
63 | struct nlmsghdr *nlh = nlmsg_hdr(msg); |
64 | void *hdr = genlmsg_data(nlmsg_data(nlh)); | |
2c21d115 | 65 | |
8e753dd0 | 66 | if (genlmsg_end(msg, hdr) < 0) |
2c21d115 SL |
67 | goto out; |
68 | ||
68eb5503 | 69 | return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC); |
2c21d115 SL |
70 | out: |
71 | nlmsg_free(msg); | |
72 | return -ENOBUFS; | |
73 | } | |
74 | ||
339b4ca5 DES |
75 | struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info, |
76 | int flags, u8 req) | |
77 | { | |
78 | void *hdr; | |
58050fce | 79 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
339b4ca5 DES |
80 | |
81 | if (!msg) | |
82 | return NULL; | |
83 | ||
84 | hdr = genlmsg_put_reply(msg, info, | |
4710d806 | 85 | &nl802154_family, flags, req); |
339b4ca5 DES |
86 | if (!hdr) { |
87 | nlmsg_free(msg); | |
88 | return NULL; | |
89 | } | |
90 | ||
91 | return msg; | |
92 | } | |
93 | ||
94 | int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info) | |
95 | { | |
10c9cbb1 H |
96 | struct nlmsghdr *nlh = nlmsg_hdr(msg); |
97 | void *hdr = genlmsg_data(nlmsg_data(nlh)); | |
339b4ca5 DES |
98 | |
99 | if (genlmsg_end(msg, hdr) < 0) | |
100 | goto out; | |
101 | ||
102 | return genlmsg_reply(msg, info); | |
103 | out: | |
104 | nlmsg_free(msg); | |
105 | return -ENOBUFS; | |
106 | } | |
107 | ||
4534de83 | 108 | static const struct genl_ops ieee8021154_ops[] = { |
1c582d91 JB |
109 | /* see nl-phy.c */ |
110 | IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy, | |
111 | ieee802154_dump_phy), | |
112 | IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface), | |
113 | IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface), | |
114 | /* see nl-mac.c */ | |
115 | IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req), | |
116 | IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp), | |
117 | IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req), | |
118 | IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req), | |
119 | IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req), | |
120 | IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface, | |
121 | ieee802154_dump_iface), | |
e462ded6 | 122 | IEEE802154_OP(IEEE802154_SET_MACPARAMS, ieee802154_set_macparams), |
3e9c156e PB |
123 | IEEE802154_OP(IEEE802154_LLSEC_GETPARAMS, ieee802154_llsec_getparams), |
124 | IEEE802154_OP(IEEE802154_LLSEC_SETPARAMS, ieee802154_llsec_setparams), | |
125 | IEEE802154_DUMP(IEEE802154_LLSEC_LIST_KEY, NULL, | |
126 | ieee802154_llsec_dump_keys), | |
127 | IEEE802154_OP(IEEE802154_LLSEC_ADD_KEY, ieee802154_llsec_add_key), | |
128 | IEEE802154_OP(IEEE802154_LLSEC_DEL_KEY, ieee802154_llsec_del_key), | |
129 | IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEV, NULL, | |
130 | ieee802154_llsec_dump_devs), | |
131 | IEEE802154_OP(IEEE802154_LLSEC_ADD_DEV, ieee802154_llsec_add_dev), | |
132 | IEEE802154_OP(IEEE802154_LLSEC_DEL_DEV, ieee802154_llsec_del_dev), | |
133 | IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEVKEY, NULL, | |
134 | ieee802154_llsec_dump_devkeys), | |
135 | IEEE802154_OP(IEEE802154_LLSEC_ADD_DEVKEY, ieee802154_llsec_add_devkey), | |
136 | IEEE802154_OP(IEEE802154_LLSEC_DEL_DEVKEY, ieee802154_llsec_del_devkey), | |
137 | IEEE802154_DUMP(IEEE802154_LLSEC_LIST_SECLEVEL, NULL, | |
138 | ieee802154_llsec_dump_seclevels), | |
139 | IEEE802154_OP(IEEE802154_LLSEC_ADD_SECLEVEL, | |
140 | ieee802154_llsec_add_seclevel), | |
141 | IEEE802154_OP(IEEE802154_LLSEC_DEL_SECLEVEL, | |
142 | ieee802154_llsec_del_seclevel), | |
1c582d91 JB |
143 | }; |
144 | ||
2a94fe48 JB |
145 | static const struct genl_multicast_group ieee802154_mcgrps[] = { |
146 | [IEEE802154_COORD_MCGRP] = { .name = IEEE802154_MCAST_COORD_NAME, }, | |
147 | [IEEE802154_BEACON_MCGRP] = { .name = IEEE802154_MCAST_BEACON_NAME, }, | |
148 | }; | |
2c21d115 | 149 | |
2c21d115 | 150 | |
2a94fe48 JB |
151 | int __init ieee802154_nl_init(void) |
152 | { | |
153 | return genl_register_family_with_ops_groups(&nl802154_family, | |
154 | ieee8021154_ops, | |
155 | ieee802154_mcgrps); | |
2c21d115 | 156 | } |
2c21d115 | 157 | |
79fe1a2a | 158 | void ieee802154_nl_exit(void) |
2c21d115 | 159 | { |
78fe738d | 160 | genl_unregister_family(&nl802154_family); |
2c21d115 | 161 | } |