blob: eef89d0b558bf969d02f8d7cb3ad7d007dbe011d [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Johannes Berg4c476992010-10-04 21:36:35 +020026static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
27 struct genl_info *info);
28static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
29 struct genl_info *info);
30
Johannes Berg55682962007-09-20 13:09:35 -040031/* the netlink family */
32static struct genl_family nl80211_fam = {
33 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
34 .name = "nl80211", /* have users key off the name instead */
35 .hdrsize = 0, /* no private header */
36 .version = 1, /* no particular meaning now */
37 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020038 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020039 .pre_doit = nl80211_pre_doit,
40 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040041};
42
Johannes Berg79c97e92009-07-07 03:56:12 +020043/* internal helper: get rdev and dev */
Johannes Berg463d0182009-07-14 00:33:35 +020044static int get_rdev_dev_by_info_ifindex(struct genl_info *info,
Johannes Berg79c97e92009-07-07 03:56:12 +020045 struct cfg80211_registered_device **rdev,
Johannes Berg55682962007-09-20 13:09:35 -040046 struct net_device **dev)
47{
Johannes Berg463d0182009-07-14 00:33:35 +020048 struct nlattr **attrs = info->attrs;
Johannes Berg55682962007-09-20 13:09:35 -040049 int ifindex;
50
Johannes Bergbba95fe2008-07-29 13:22:51 +020051 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040052 return -EINVAL;
53
Johannes Bergbba95fe2008-07-29 13:22:51 +020054 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg463d0182009-07-14 00:33:35 +020055 *dev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040056 if (!*dev)
57 return -ENODEV;
58
Johannes Berg463d0182009-07-14 00:33:35 +020059 *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020060 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040061 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020062 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040063 }
64
65 return 0;
66}
67
68/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000069static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040070 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
71 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070072 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020073 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020074 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053075 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020076 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
77 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010080 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040081
82 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
83 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
84 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010085
86 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg3e5d7642009-07-07 14:37:26 +020087 [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010088
Johannes Bergb9454e82009-07-08 13:29:08 +020089 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010090 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
91 .len = WLAN_MAX_KEY_LEN },
92 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
93 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
94 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen9f26a952009-05-15 12:38:32 +030095 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
Johannes Berge31b8212010-10-05 19:39:30 +020096 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010097
98 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
99 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
100 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
101 .len = IEEE80211_MAX_DATA_LEN },
102 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
103 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100104 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
105 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
106 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
107 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
108 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100109 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100110 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200111 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100112 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
113 .len = IEEE80211_MAX_MESH_ID_LEN },
114 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300115
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700116 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
117 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
118
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300119 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
123 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100124 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300125
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800126 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700127
Jouni Malinen36aedc92008-08-25 11:58:58 +0300128 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
129 .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200130
131 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
132 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
133 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100134 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
135 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200136
137 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
138 .len = IEEE80211_MAX_SSID_LEN },
139 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
140 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200141 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300142 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300143 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300144 [NL80211_ATTR_STA_FLAGS2] = {
145 .len = sizeof(struct nl80211_sta_flag_update),
146 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300147 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300148 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
149 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200150 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
151 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
152 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200153 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100154 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100155 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
156 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100157 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
158 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200159 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200160 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
161 .len = IEEE80211_MAX_DATA_LEN },
162 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200163 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200164 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300165 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200166 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300167 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
168 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200169 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900170 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
171 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100172 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100173 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100174 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Berg55682962007-09-20 13:09:35 -0400175};
176
Johannes Berge31b8212010-10-05 19:39:30 +0200177/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000178static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200179 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200180 [NL80211_KEY_IDX] = { .type = NLA_U8 },
181 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
182 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
183 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
184 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200185 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100186 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
187};
188
189/* policy for the key default flags */
190static const struct nla_policy
191nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
192 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
193 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200194};
195
Holger Schuriga0438972009-11-11 11:30:02 +0100196/* ifidx get helper */
197static int nl80211_get_ifidx(struct netlink_callback *cb)
198{
199 int res;
200
201 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
202 nl80211_fam.attrbuf, nl80211_fam.maxattr,
203 nl80211_policy);
204 if (res)
205 return res;
206
207 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
208 return -EINVAL;
209
210 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
211 if (!res)
212 return -EINVAL;
213 return res;
214}
215
Johannes Berg67748892010-10-04 21:14:06 +0200216static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
217 struct netlink_callback *cb,
218 struct cfg80211_registered_device **rdev,
219 struct net_device **dev)
220{
221 int ifidx = cb->args[0];
222 int err;
223
224 if (!ifidx)
225 ifidx = nl80211_get_ifidx(cb);
226 if (ifidx < 0)
227 return ifidx;
228
229 cb->args[0] = ifidx;
230
231 rtnl_lock();
232
233 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
234 if (!*dev) {
235 err = -ENODEV;
236 goto out_rtnl;
237 }
238
239 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100240 if (IS_ERR(*rdev)) {
241 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200242 goto out_rtnl;
243 }
244
245 return 0;
246 out_rtnl:
247 rtnl_unlock();
248 return err;
249}
250
251static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
252{
253 cfg80211_unlock_rdev(rdev);
254 rtnl_unlock();
255}
256
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100257/* IE validation */
258static bool is_valid_ie_attr(const struct nlattr *attr)
259{
260 const u8 *pos;
261 int len;
262
263 if (!attr)
264 return true;
265
266 pos = nla_data(attr);
267 len = nla_len(attr);
268
269 while (len) {
270 u8 elemlen;
271
272 if (len < 2)
273 return false;
274 len -= 2;
275
276 elemlen = pos[1];
277 if (elemlen > len)
278 return false;
279
280 len -= elemlen;
281 pos += 2 + elemlen;
282 }
283
284 return true;
285}
286
Johannes Berg55682962007-09-20 13:09:35 -0400287/* message building helper */
288static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
289 int flags, u8 cmd)
290{
291 /* since there is no private header just add the generic one */
292 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
293}
294
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400295static int nl80211_msg_put_channel(struct sk_buff *msg,
296 struct ieee80211_channel *chan)
297{
298 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
299 chan->center_freq);
300
301 if (chan->flags & IEEE80211_CHAN_DISABLED)
302 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
303 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
304 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
305 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
306 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
307 if (chan->flags & IEEE80211_CHAN_RADAR)
308 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
309
310 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
311 DBM_TO_MBM(chan->max_power));
312
313 return 0;
314
315 nla_put_failure:
316 return -ENOBUFS;
317}
318
Johannes Berg55682962007-09-20 13:09:35 -0400319/* netlink command implementations */
320
Johannes Bergb9454e82009-07-08 13:29:08 +0200321struct key_parse {
322 struct key_params p;
323 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200324 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200325 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100326 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200327};
328
329static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
330{
331 struct nlattr *tb[NL80211_KEY_MAX + 1];
332 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
333 nl80211_key_policy);
334 if (err)
335 return err;
336
337 k->def = !!tb[NL80211_KEY_DEFAULT];
338 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
339
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100340 if (k->def) {
341 k->def_uni = true;
342 k->def_multi = true;
343 }
344 if (k->defmgmt)
345 k->def_multi = true;
346
Johannes Bergb9454e82009-07-08 13:29:08 +0200347 if (tb[NL80211_KEY_IDX])
348 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
349
350 if (tb[NL80211_KEY_DATA]) {
351 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
352 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
353 }
354
355 if (tb[NL80211_KEY_SEQ]) {
356 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
357 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
358 }
359
360 if (tb[NL80211_KEY_CIPHER])
361 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
362
Johannes Berge31b8212010-10-05 19:39:30 +0200363 if (tb[NL80211_KEY_TYPE]) {
364 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
365 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
366 return -EINVAL;
367 }
368
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100369 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
370 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
371 int err = nla_parse_nested(kdt,
372 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
373 tb[NL80211_KEY_DEFAULT_TYPES],
374 nl80211_key_default_policy);
375 if (err)
376 return err;
377
378 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
379 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
380 }
381
Johannes Bergb9454e82009-07-08 13:29:08 +0200382 return 0;
383}
384
385static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
386{
387 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
388 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
389 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
390 }
391
392 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
393 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
394 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
395 }
396
397 if (info->attrs[NL80211_ATTR_KEY_IDX])
398 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
399
400 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
401 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
402
403 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
404 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
405
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100406 if (k->def) {
407 k->def_uni = true;
408 k->def_multi = true;
409 }
410 if (k->defmgmt)
411 k->def_multi = true;
412
Johannes Berge31b8212010-10-05 19:39:30 +0200413 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
414 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
415 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
416 return -EINVAL;
417 }
418
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100419 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
420 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
421 int err = nla_parse_nested(
422 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
423 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
424 nl80211_key_default_policy);
425 if (err)
426 return err;
427
428 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
429 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
430 }
431
Johannes Bergb9454e82009-07-08 13:29:08 +0200432 return 0;
433}
434
435static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
436{
437 int err;
438
439 memset(k, 0, sizeof(*k));
440 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200441 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200442
443 if (info->attrs[NL80211_ATTR_KEY])
444 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
445 else
446 err = nl80211_parse_key_old(info, k);
447
448 if (err)
449 return err;
450
451 if (k->def && k->defmgmt)
452 return -EINVAL;
453
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100454 if (k->defmgmt) {
455 if (k->def_uni || !k->def_multi)
456 return -EINVAL;
457 }
458
Johannes Bergb9454e82009-07-08 13:29:08 +0200459 if (k->idx != -1) {
460 if (k->defmgmt) {
461 if (k->idx < 4 || k->idx > 5)
462 return -EINVAL;
463 } else if (k->def) {
464 if (k->idx < 0 || k->idx > 3)
465 return -EINVAL;
466 } else {
467 if (k->idx < 0 || k->idx > 5)
468 return -EINVAL;
469 }
470 }
471
472 return 0;
473}
474
Johannes Bergfffd0932009-07-08 14:22:54 +0200475static struct cfg80211_cached_keys *
476nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
477 struct nlattr *keys)
478{
479 struct key_parse parse;
480 struct nlattr *key;
481 struct cfg80211_cached_keys *result;
482 int rem, err, def = 0;
483
484 result = kzalloc(sizeof(*result), GFP_KERNEL);
485 if (!result)
486 return ERR_PTR(-ENOMEM);
487
488 result->def = -1;
489 result->defmgmt = -1;
490
491 nla_for_each_nested(key, keys, rem) {
492 memset(&parse, 0, sizeof(parse));
493 parse.idx = -1;
494
495 err = nl80211_parse_key_new(key, &parse);
496 if (err)
497 goto error;
498 err = -EINVAL;
499 if (!parse.p.key)
500 goto error;
501 if (parse.idx < 0 || parse.idx > 4)
502 goto error;
503 if (parse.def) {
504 if (def)
505 goto error;
506 def = 1;
507 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100508 if (!parse.def_uni || !parse.def_multi)
509 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200510 } else if (parse.defmgmt)
511 goto error;
512 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200513 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200514 if (err)
515 goto error;
516 result->params[parse.idx].cipher = parse.p.cipher;
517 result->params[parse.idx].key_len = parse.p.key_len;
518 result->params[parse.idx].key = result->data[parse.idx];
519 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
520 }
521
522 return result;
523 error:
524 kfree(result);
525 return ERR_PTR(err);
526}
527
528static int nl80211_key_allowed(struct wireless_dev *wdev)
529{
530 ASSERT_WDEV_LOCK(wdev);
531
Johannes Bergfffd0932009-07-08 14:22:54 +0200532 switch (wdev->iftype) {
533 case NL80211_IFTYPE_AP:
534 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200535 case NL80211_IFTYPE_P2P_GO:
Johannes Bergfffd0932009-07-08 14:22:54 +0200536 break;
537 case NL80211_IFTYPE_ADHOC:
538 if (!wdev->current_bss)
539 return -ENOLINK;
540 break;
541 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200542 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200543 if (wdev->sme_state != CFG80211_SME_CONNECTED)
544 return -ENOLINK;
545 break;
546 default:
547 return -EINVAL;
548 }
549
550 return 0;
551}
552
Johannes Berg55682962007-09-20 13:09:35 -0400553static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
554 struct cfg80211_registered_device *dev)
555{
556 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100557 struct nlattr *nl_bands, *nl_band;
558 struct nlattr *nl_freqs, *nl_freq;
559 struct nlattr *nl_rates, *nl_rate;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700560 struct nlattr *nl_modes;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100561 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100562 enum ieee80211_band band;
563 struct ieee80211_channel *chan;
564 struct ieee80211_rate *rate;
565 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700566 u16 ifmodes = dev->wiphy.interface_modes;
Johannes Berg2e161f72010-08-12 15:38:38 +0200567 const struct ieee80211_txrx_stypes *mgmt_stypes =
568 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400569
570 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
571 if (!hdr)
572 return -1;
573
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500574 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400575 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200576
Johannes Bergf5ea9122009-08-07 16:17:38 +0200577 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
578 cfg80211_rdev_list_generation);
579
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200580 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
581 dev->wiphy.retry_short);
582 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
583 dev->wiphy.retry_long);
584 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
585 dev->wiphy.frag_threshold);
586 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
587 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100588 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
589 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100590 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
591 dev->wiphy.max_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200592 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
593 dev->wiphy.max_scan_ie_len);
Johannes Bergee688b002008-01-24 19:38:39 +0100594
Johannes Berge31b8212010-10-05 19:39:30 +0200595 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
596 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
597
Johannes Berg25e47c182009-04-02 20:14:06 +0200598 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
599 sizeof(u32) * dev->wiphy.n_cipher_suites,
600 dev->wiphy.cipher_suites);
601
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100602 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
603 dev->wiphy.max_num_pmkids);
604
Johannes Bergc0692b82010-08-27 14:26:53 +0300605 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
606 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
607
Bruno Randolfa7ffac92010-12-08 13:59:24 +0900608 if (dev->wiphy.available_antennas && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900609 u32 tx_ant = 0, rx_ant = 0;
610 int res;
611 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
612 if (!res) {
613 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
614 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
615 }
616 }
617
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700618 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
619 if (!nl_modes)
620 goto nla_put_failure;
621
622 i = 0;
623 while (ifmodes) {
624 if (ifmodes & 1)
625 NLA_PUT_FLAG(msg, i);
626 ifmodes >>= 1;
627 i++;
628 }
629
630 nla_nest_end(msg, nl_modes);
631
Johannes Bergee688b002008-01-24 19:38:39 +0100632 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
633 if (!nl_bands)
634 goto nla_put_failure;
635
636 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
637 if (!dev->wiphy.bands[band])
638 continue;
639
640 nl_band = nla_nest_start(msg, band);
641 if (!nl_band)
642 goto nla_put_failure;
643
Johannes Bergd51626d2008-10-09 12:20:13 +0200644 /* add HT info */
645 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
646 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
647 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
648 &dev->wiphy.bands[band]->ht_cap.mcs);
649 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
650 dev->wiphy.bands[band]->ht_cap.cap);
651 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
652 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
653 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
654 dev->wiphy.bands[band]->ht_cap.ampdu_density);
655 }
656
Johannes Bergee688b002008-01-24 19:38:39 +0100657 /* add frequencies */
658 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
659 if (!nl_freqs)
660 goto nla_put_failure;
661
662 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
663 nl_freq = nla_nest_start(msg, i);
664 if (!nl_freq)
665 goto nla_put_failure;
666
667 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100668
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400669 if (nl80211_msg_put_channel(msg, chan))
670 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200671
Johannes Bergee688b002008-01-24 19:38:39 +0100672 nla_nest_end(msg, nl_freq);
673 }
674
675 nla_nest_end(msg, nl_freqs);
676
677 /* add bitrates */
678 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
679 if (!nl_rates)
680 goto nla_put_failure;
681
682 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
683 nl_rate = nla_nest_start(msg, i);
684 if (!nl_rate)
685 goto nla_put_failure;
686
687 rate = &dev->wiphy.bands[band]->bitrates[i];
688 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
689 rate->bitrate);
690 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
691 NLA_PUT_FLAG(msg,
692 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
693
694 nla_nest_end(msg, nl_rate);
695 }
696
697 nla_nest_end(msg, nl_rates);
698
699 nla_nest_end(msg, nl_band);
700 }
701 nla_nest_end(msg, nl_bands);
702
Johannes Berg8fdc6212009-03-14 09:34:01 +0100703 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
704 if (!nl_cmds)
705 goto nla_put_failure;
706
707 i = 0;
708#define CMD(op, n) \
709 do { \
710 if (dev->ops->op) { \
711 i++; \
712 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
713 } \
714 } while (0)
715
716 CMD(add_virtual_intf, NEW_INTERFACE);
717 CMD(change_virtual_intf, SET_INTERFACE);
718 CMD(add_key, NEW_KEY);
719 CMD(add_beacon, NEW_BEACON);
720 CMD(add_station, NEW_STATION);
721 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800722 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100723 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200724 CMD(auth, AUTHENTICATE);
725 CMD(assoc, ASSOCIATE);
726 CMD(deauth, DEAUTHENTICATE);
727 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200728 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100729 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100730 CMD(set_pmksa, SET_PMKSA);
731 CMD(del_pmksa, DEL_PMKSA);
732 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100733 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200734 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200735 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100736 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100737 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200738 i++;
739 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
740 }
Johannes Bergf444de02010-05-05 15:25:02 +0200741 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400742 CMD(set_wds_peer, SET_WDS_PEER);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100743
744#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200745
Johannes Berg6829c8782009-07-02 09:13:27 +0200746 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200747 i++;
748 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
749 }
750
Johannes Berg6829c8782009-07-02 09:13:27 +0200751 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200752 i++;
753 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
754 }
755
Johannes Berg8fdc6212009-03-14 09:34:01 +0100756 nla_nest_end(msg, nl_cmds);
757
Johannes Berga2939112010-12-14 17:54:28 +0100758 if (dev->ops->remain_on_channel)
759 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
760 dev->wiphy.max_remain_on_channel_duration);
761
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100762 /* for now at least assume all drivers have it */
763 if (dev->ops->mgmt_tx)
764 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
765
Johannes Berg2e161f72010-08-12 15:38:38 +0200766 if (mgmt_stypes) {
767 u16 stypes;
768 struct nlattr *nl_ftypes, *nl_ifs;
769 enum nl80211_iftype ift;
770
771 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
772 if (!nl_ifs)
773 goto nla_put_failure;
774
775 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
776 nl_ftypes = nla_nest_start(msg, ift);
777 if (!nl_ftypes)
778 goto nla_put_failure;
779 i = 0;
780 stypes = mgmt_stypes[ift].tx;
781 while (stypes) {
782 if (stypes & 1)
783 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
784 (i << 4) | IEEE80211_FTYPE_MGMT);
785 stypes >>= 1;
786 i++;
787 }
788 nla_nest_end(msg, nl_ftypes);
789 }
790
Johannes Berg74b70a42010-08-24 12:15:53 +0200791 nla_nest_end(msg, nl_ifs);
792
Johannes Berg2e161f72010-08-12 15:38:38 +0200793 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
794 if (!nl_ifs)
795 goto nla_put_failure;
796
797 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
798 nl_ftypes = nla_nest_start(msg, ift);
799 if (!nl_ftypes)
800 goto nla_put_failure;
801 i = 0;
802 stypes = mgmt_stypes[ift].rx;
803 while (stypes) {
804 if (stypes & 1)
805 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
806 (i << 4) | IEEE80211_FTYPE_MGMT);
807 stypes >>= 1;
808 i++;
809 }
810 nla_nest_end(msg, nl_ftypes);
811 }
812 nla_nest_end(msg, nl_ifs);
813 }
814
Johannes Berg55682962007-09-20 13:09:35 -0400815 return genlmsg_end(msg, hdr);
816
817 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700818 genlmsg_cancel(msg, hdr);
819 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400820}
821
822static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
823{
824 int idx = 0;
825 int start = cb->args[0];
826 struct cfg80211_registered_device *dev;
827
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500828 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200829 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +0200830 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
831 continue;
Julius Volzb4637272008-07-08 14:02:19 +0200832 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -0400833 continue;
834 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
835 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +0200836 dev) < 0) {
837 idx--;
Johannes Berg55682962007-09-20 13:09:35 -0400838 break;
Julius Volzb4637272008-07-08 14:02:19 +0200839 }
Johannes Berg55682962007-09-20 13:09:35 -0400840 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500841 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400842
843 cb->args[0] = idx;
844
845 return skb->len;
846}
847
848static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
849{
850 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +0200851 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -0400852
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -0700853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -0400854 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +0200855 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -0400856
Johannes Berg4c476992010-10-04 21:36:35 +0200857 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
858 nlmsg_free(msg);
859 return -ENOBUFS;
860 }
Johannes Berg55682962007-09-20 13:09:35 -0400861
Johannes Berg134e6372009-07-10 09:51:34 +0000862 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -0400863}
864
Jouni Malinen31888482008-10-30 16:59:24 +0200865static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
866 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
867 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
868 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
869 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
870 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
871};
872
873static int parse_txq_params(struct nlattr *tb[],
874 struct ieee80211_txq_params *txq_params)
875{
876 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
877 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
878 !tb[NL80211_TXQ_ATTR_AIFS])
879 return -EINVAL;
880
881 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
882 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
883 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
884 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
885 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
886
887 return 0;
888}
889
Johannes Bergf444de02010-05-05 15:25:02 +0200890static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
891{
892 /*
893 * You can only set the channel explicitly for AP, mesh
894 * and WDS type interfaces; all others have their channel
895 * managed via their respective "establish a connection"
896 * command (connect, join, ...)
897 *
898 * Monitors are special as they are normally slaved to
899 * whatever else is going on, so they behave as though
900 * you tried setting the wiphy channel itself.
901 */
902 return !wdev ||
903 wdev->iftype == NL80211_IFTYPE_AP ||
904 wdev->iftype == NL80211_IFTYPE_WDS ||
905 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +0200906 wdev->iftype == NL80211_IFTYPE_MONITOR ||
907 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +0200908}
909
910static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
911 struct wireless_dev *wdev,
912 struct genl_info *info)
913{
914 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
915 u32 freq;
916 int result;
917
918 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
919 return -EINVAL;
920
921 if (!nl80211_can_set_dev_channel(wdev))
922 return -EOPNOTSUPP;
923
924 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
925 channel_type = nla_get_u32(info->attrs[
926 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
927 if (channel_type != NL80211_CHAN_NO_HT &&
928 channel_type != NL80211_CHAN_HT20 &&
929 channel_type != NL80211_CHAN_HT40PLUS &&
930 channel_type != NL80211_CHAN_HT40MINUS)
931 return -EINVAL;
932 }
933
934 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
935
936 mutex_lock(&rdev->devlist_mtx);
937 if (wdev) {
938 wdev_lock(wdev);
939 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
940 wdev_unlock(wdev);
941 } else {
942 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
943 }
944 mutex_unlock(&rdev->devlist_mtx);
945
946 return result;
947}
948
949static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
950{
Johannes Berg4c476992010-10-04 21:36:35 +0200951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
952 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +0200953
Johannes Berg4c476992010-10-04 21:36:35 +0200954 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +0200955}
956
Bill Jordane8347eb2010-10-01 13:54:28 -0400957static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
958{
Johannes Berg43b19952010-10-07 13:10:30 +0200959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
960 struct net_device *dev = info->user_ptr[1];
961 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +0200962 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -0400963
964 if (!info->attrs[NL80211_ATTR_MAC])
965 return -EINVAL;
966
Johannes Berg43b19952010-10-07 13:10:30 +0200967 if (netif_running(dev))
968 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -0400969
Johannes Berg43b19952010-10-07 13:10:30 +0200970 if (!rdev->ops->set_wds_peer)
971 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -0400972
Johannes Berg43b19952010-10-07 13:10:30 +0200973 if (wdev->iftype != NL80211_IFTYPE_WDS)
974 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -0400975
976 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +0200977 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -0400978}
979
980
Johannes Berg55682962007-09-20 13:09:35 -0400981static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
982{
983 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +0200984 struct net_device *netdev = NULL;
985 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -0400986 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +0200987 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200988 u32 changed;
989 u8 retry_short = 0, retry_long = 0;
990 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +0100991 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -0400992
Johannes Bergf444de02010-05-05 15:25:02 +0200993 /*
994 * Try to find the wiphy and netdev. Normally this
995 * function shouldn't need the netdev, but this is
996 * done for backward compatibility -- previously
997 * setting the channel was done per wiphy, but now
998 * it is per netdev. Previous userland like hostapd
999 * also passed a netdev to set_wiphy, so that it is
1000 * possible to let that go to the right netdev!
1001 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001002 mutex_lock(&cfg80211_mutex);
1003
Johannes Bergf444de02010-05-05 15:25:02 +02001004 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1005 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1006
1007 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1008 if (netdev && netdev->ieee80211_ptr) {
1009 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1010 mutex_lock(&rdev->mtx);
1011 } else
1012 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001013 }
1014
Johannes Bergf444de02010-05-05 15:25:02 +02001015 if (!netdev) {
1016 rdev = __cfg80211_rdev_from_info(info);
1017 if (IS_ERR(rdev)) {
1018 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001019 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001020 }
1021 wdev = NULL;
1022 netdev = NULL;
1023 result = 0;
1024
1025 mutex_lock(&rdev->mtx);
1026 } else if (netif_running(netdev) &&
1027 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1028 wdev = netdev->ieee80211_ptr;
1029 else
1030 wdev = NULL;
1031
1032 /*
1033 * end workaround code, by now the rdev is available
1034 * and locked, and wdev may or may not be NULL.
1035 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001036
1037 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001038 result = cfg80211_dev_rename(
1039 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001040
1041 mutex_unlock(&cfg80211_mutex);
1042
1043 if (result)
1044 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001045
Jouni Malinen31888482008-10-30 16:59:24 +02001046 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1047 struct ieee80211_txq_params txq_params;
1048 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1049
1050 if (!rdev->ops->set_txq_params) {
1051 result = -EOPNOTSUPP;
1052 goto bad_res;
1053 }
1054
1055 nla_for_each_nested(nl_txq_params,
1056 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1057 rem_txq_params) {
1058 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1059 nla_data(nl_txq_params),
1060 nla_len(nl_txq_params),
1061 txq_params_policy);
1062 result = parse_txq_params(tb, &txq_params);
1063 if (result)
1064 goto bad_res;
1065
1066 result = rdev->ops->set_txq_params(&rdev->wiphy,
1067 &txq_params);
1068 if (result)
1069 goto bad_res;
1070 }
1071 }
1072
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001073 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001074 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001075 if (result)
1076 goto bad_res;
1077 }
1078
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001079 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1080 enum nl80211_tx_power_setting type;
1081 int idx, mbm = 0;
1082
1083 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001084 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001085 goto bad_res;
1086 }
1087
1088 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1089 type = nla_get_u32(info->attrs[idx]);
1090
1091 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1092 (type != NL80211_TX_POWER_AUTOMATIC)) {
1093 result = -EINVAL;
1094 goto bad_res;
1095 }
1096
1097 if (type != NL80211_TX_POWER_AUTOMATIC) {
1098 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1099 mbm = nla_get_u32(info->attrs[idx]);
1100 }
1101
1102 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1103 if (result)
1104 goto bad_res;
1105 }
1106
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001107 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1108 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1109 u32 tx_ant, rx_ant;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001110 if (!rdev->wiphy.available_antennas || !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001111 result = -EOPNOTSUPP;
1112 goto bad_res;
1113 }
1114
1115 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1116 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1117
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001118 /* reject antenna configurations which don't match the
1119 * available antenna mask, except for the "all" mask */
1120 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas)) ||
1121 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas))) {
1122 result = -EINVAL;
1123 goto bad_res;
1124 }
1125
1126 tx_ant = tx_ant & rdev->wiphy.available_antennas;
1127 rx_ant = rx_ant & rdev->wiphy.available_antennas;
1128
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001129 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1130 if (result)
1131 goto bad_res;
1132 }
1133
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001134 changed = 0;
1135
1136 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1137 retry_short = nla_get_u8(
1138 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1139 if (retry_short == 0) {
1140 result = -EINVAL;
1141 goto bad_res;
1142 }
1143 changed |= WIPHY_PARAM_RETRY_SHORT;
1144 }
1145
1146 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1147 retry_long = nla_get_u8(
1148 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1149 if (retry_long == 0) {
1150 result = -EINVAL;
1151 goto bad_res;
1152 }
1153 changed |= WIPHY_PARAM_RETRY_LONG;
1154 }
1155
1156 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1157 frag_threshold = nla_get_u32(
1158 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1159 if (frag_threshold < 256) {
1160 result = -EINVAL;
1161 goto bad_res;
1162 }
1163 if (frag_threshold != (u32) -1) {
1164 /*
1165 * Fragments (apart from the last one) are required to
1166 * have even length. Make the fragmentation code
1167 * simpler by stripping LSB should someone try to use
1168 * odd threshold value.
1169 */
1170 frag_threshold &= ~0x1;
1171 }
1172 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1173 }
1174
1175 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1176 rts_threshold = nla_get_u32(
1177 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1178 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1179 }
1180
Lukáš Turek81077e82009-12-21 22:50:47 +01001181 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1182 coverage_class = nla_get_u8(
1183 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1184 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1185 }
1186
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001187 if (changed) {
1188 u8 old_retry_short, old_retry_long;
1189 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001190 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001191
1192 if (!rdev->ops->set_wiphy_params) {
1193 result = -EOPNOTSUPP;
1194 goto bad_res;
1195 }
1196
1197 old_retry_short = rdev->wiphy.retry_short;
1198 old_retry_long = rdev->wiphy.retry_long;
1199 old_frag_threshold = rdev->wiphy.frag_threshold;
1200 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001201 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001202
1203 if (changed & WIPHY_PARAM_RETRY_SHORT)
1204 rdev->wiphy.retry_short = retry_short;
1205 if (changed & WIPHY_PARAM_RETRY_LONG)
1206 rdev->wiphy.retry_long = retry_long;
1207 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1208 rdev->wiphy.frag_threshold = frag_threshold;
1209 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1210 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001211 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1212 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001213
1214 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1215 if (result) {
1216 rdev->wiphy.retry_short = old_retry_short;
1217 rdev->wiphy.retry_long = old_retry_long;
1218 rdev->wiphy.frag_threshold = old_frag_threshold;
1219 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001220 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001221 }
1222 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001223
Johannes Berg306d6112008-12-08 12:39:04 +01001224 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001225 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001226 if (netdev)
1227 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001228 return result;
1229}
1230
1231
1232static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001233 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001234 struct net_device *dev)
1235{
1236 void *hdr;
1237
1238 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1239 if (!hdr)
1240 return -1;
1241
1242 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001243 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001244 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001245 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001246
1247 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1248 rdev->devlist_generation ^
1249 (cfg80211_rdev_list_generation << 2));
1250
Johannes Berg55682962007-09-20 13:09:35 -04001251 return genlmsg_end(msg, hdr);
1252
1253 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001254 genlmsg_cancel(msg, hdr);
1255 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001256}
1257
1258static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1259{
1260 int wp_idx = 0;
1261 int if_idx = 0;
1262 int wp_start = cb->args[0];
1263 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001264 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001265 struct wireless_dev *wdev;
1266
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001267 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001268 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1269 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001270 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001271 if (wp_idx < wp_start) {
1272 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001273 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001274 }
Johannes Berg55682962007-09-20 13:09:35 -04001275 if_idx = 0;
1276
Johannes Bergf5ea9122009-08-07 16:17:38 +02001277 mutex_lock(&rdev->devlist_mtx);
1278 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001279 if (if_idx < if_start) {
1280 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001281 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001282 }
Johannes Berg55682962007-09-20 13:09:35 -04001283 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1284 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001285 rdev, wdev->netdev) < 0) {
1286 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001287 goto out;
1288 }
1289 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001290 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001291 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001292
1293 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001294 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001295 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001296 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001297
1298 cb->args[0] = wp_idx;
1299 cb->args[1] = if_idx;
1300
1301 return skb->len;
1302}
1303
1304static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1305{
1306 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001307 struct cfg80211_registered_device *dev = info->user_ptr[0];
1308 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001309
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001311 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001312 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001313
Johannes Bergd7264052009-04-19 16:23:20 +02001314 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001315 dev, netdev) < 0) {
1316 nlmsg_free(msg);
1317 return -ENOBUFS;
1318 }
Johannes Berg55682962007-09-20 13:09:35 -04001319
Johannes Berg134e6372009-07-10 09:51:34 +00001320 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001321}
1322
Michael Wu66f7ac52008-01-31 19:48:22 +01001323static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1324 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1325 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1326 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1327 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1328 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1329};
1330
1331static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1332{
1333 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1334 int flag;
1335
1336 *mntrflags = 0;
1337
1338 if (!nla)
1339 return -EINVAL;
1340
1341 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1342 nla, mntr_flags_policy))
1343 return -EINVAL;
1344
1345 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1346 if (flags[flag])
1347 *mntrflags |= (1<<flag);
1348
1349 return 0;
1350}
1351
Johannes Berg9bc383d2009-11-19 11:55:19 +01001352static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001353 struct net_device *netdev, u8 use_4addr,
1354 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001355{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001356 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001357 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001358 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001359 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001360 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001361
1362 switch (iftype) {
1363 case NL80211_IFTYPE_AP_VLAN:
1364 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1365 return 0;
1366 break;
1367 case NL80211_IFTYPE_STATION:
1368 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1369 return 0;
1370 break;
1371 default:
1372 break;
1373 }
1374
1375 return -EOPNOTSUPP;
1376}
1377
Johannes Berg55682962007-09-20 13:09:35 -04001378static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1379{
Johannes Berg4c476992010-10-04 21:36:35 +02001380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001381 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001382 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001383 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001384 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001385 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001386 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001387
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001388 memset(&params, 0, sizeof(params));
1389
Johannes Berg04a773a2009-04-19 21:24:32 +02001390 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001391
Johannes Berg723b0382008-09-16 20:22:09 +02001392 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001393 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001394 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001395 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001396 if (ntype > NL80211_IFTYPE_MAX)
1397 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001398 }
1399
Johannes Berg92ffe052008-09-16 20:39:36 +02001400 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001401 struct wireless_dev *wdev = dev->ieee80211_ptr;
1402
Johannes Berg4c476992010-10-04 21:36:35 +02001403 if (ntype != NL80211_IFTYPE_MESH_POINT)
1404 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001405 if (netif_running(dev))
1406 return -EBUSY;
1407
1408 wdev_lock(wdev);
1409 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1410 IEEE80211_MAX_MESH_ID_LEN);
1411 wdev->mesh_id_up_len =
1412 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1413 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1414 wdev->mesh_id_up_len);
1415 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001416 }
1417
Felix Fietkau8b787642009-11-10 18:53:10 +01001418 if (info->attrs[NL80211_ATTR_4ADDR]) {
1419 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1420 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001421 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001422 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001423 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001424 } else {
1425 params.use_4addr = -1;
1426 }
1427
Johannes Berg92ffe052008-09-16 20:39:36 +02001428 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001429 if (ntype != NL80211_IFTYPE_MONITOR)
1430 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001431 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1432 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001433 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001434 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001435
1436 flags = &_flags;
1437 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001438 }
Johannes Berg3b858752009-03-12 09:55:09 +01001439
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001440 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001441 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001442 else
1443 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001444
Johannes Berg9bc383d2009-11-19 11:55:19 +01001445 if (!err && params.use_4addr != -1)
1446 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1447
Johannes Berg55682962007-09-20 13:09:35 -04001448 return err;
1449}
1450
1451static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1452{
Johannes Berg4c476992010-10-04 21:36:35 +02001453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001454 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001455 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001456 int err;
1457 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001458 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001459
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001460 memset(&params, 0, sizeof(params));
1461
Johannes Berg55682962007-09-20 13:09:35 -04001462 if (!info->attrs[NL80211_ATTR_IFNAME])
1463 return -EINVAL;
1464
1465 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1466 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1467 if (type > NL80211_IFTYPE_MAX)
1468 return -EINVAL;
1469 }
1470
Johannes Berg79c97e92009-07-07 03:56:12 +02001471 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001472 !(rdev->wiphy.interface_modes & (1 << type)))
1473 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001474
Johannes Berg9bc383d2009-11-19 11:55:19 +01001475 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001476 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001477 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001478 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001479 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001480 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001481
Michael Wu66f7ac52008-01-31 19:48:22 +01001482 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1483 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1484 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001485 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001486 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001487 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001488 if (IS_ERR(dev))
1489 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001490
Johannes Berg29cbe682010-12-03 09:20:44 +01001491 if (type == NL80211_IFTYPE_MESH_POINT &&
1492 info->attrs[NL80211_ATTR_MESH_ID]) {
1493 struct wireless_dev *wdev = dev->ieee80211_ptr;
1494
1495 wdev_lock(wdev);
1496 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1497 IEEE80211_MAX_MESH_ID_LEN);
1498 wdev->mesh_id_up_len =
1499 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1500 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1501 wdev->mesh_id_up_len);
1502 wdev_unlock(wdev);
1503 }
1504
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001505 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001506}
1507
1508static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1509{
Johannes Berg4c476992010-10-04 21:36:35 +02001510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1511 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001512
Johannes Berg4c476992010-10-04 21:36:35 +02001513 if (!rdev->ops->del_virtual_intf)
1514 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001515
Johannes Berg4c476992010-10-04 21:36:35 +02001516 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001517}
1518
Johannes Berg41ade002007-12-19 02:03:29 +01001519struct get_key_cookie {
1520 struct sk_buff *msg;
1521 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001522 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001523};
1524
1525static void get_key_callback(void *c, struct key_params *params)
1526{
Johannes Bergb9454e82009-07-08 13:29:08 +02001527 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001528 struct get_key_cookie *cookie = c;
1529
1530 if (params->key)
1531 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1532 params->key_len, params->key);
1533
1534 if (params->seq)
1535 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1536 params->seq_len, params->seq);
1537
1538 if (params->cipher)
1539 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1540 params->cipher);
1541
Johannes Bergb9454e82009-07-08 13:29:08 +02001542 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1543 if (!key)
1544 goto nla_put_failure;
1545
1546 if (params->key)
1547 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1548 params->key_len, params->key);
1549
1550 if (params->seq)
1551 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1552 params->seq_len, params->seq);
1553
1554 if (params->cipher)
1555 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1556 params->cipher);
1557
1558 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1559
1560 nla_nest_end(cookie->msg, key);
1561
Johannes Berg41ade002007-12-19 02:03:29 +01001562 return;
1563 nla_put_failure:
1564 cookie->error = 1;
1565}
1566
1567static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1568{
Johannes Berg4c476992010-10-04 21:36:35 +02001569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001570 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001571 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001572 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001573 const u8 *mac_addr = NULL;
1574 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001575 struct get_key_cookie cookie = {
1576 .error = 0,
1577 };
1578 void *hdr;
1579 struct sk_buff *msg;
1580
1581 if (info->attrs[NL80211_ATTR_KEY_IDX])
1582 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1583
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001584 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001585 return -EINVAL;
1586
1587 if (info->attrs[NL80211_ATTR_MAC])
1588 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1589
Johannes Berge31b8212010-10-05 19:39:30 +02001590 pairwise = !!mac_addr;
1591 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1592 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1593 if (kt >= NUM_NL80211_KEYTYPES)
1594 return -EINVAL;
1595 if (kt != NL80211_KEYTYPE_GROUP &&
1596 kt != NL80211_KEYTYPE_PAIRWISE)
1597 return -EINVAL;
1598 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1599 }
1600
Johannes Berg4c476992010-10-04 21:36:35 +02001601 if (!rdev->ops->get_key)
1602 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001603
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001605 if (!msg)
1606 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001607
1608 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1609 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001610 if (IS_ERR(hdr))
1611 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001612
1613 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001614 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001615
1616 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1617 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1618 if (mac_addr)
1619 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1620
Johannes Berge31b8212010-10-05 19:39:30 +02001621 if (pairwise && mac_addr &&
1622 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1623 return -ENOENT;
1624
1625 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1626 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001627
1628 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001629 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001630
1631 if (cookie.error)
1632 goto nla_put_failure;
1633
1634 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001635 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001636
1637 nla_put_failure:
1638 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001639 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001640 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001641 return err;
1642}
1643
1644static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1645{
Johannes Berg4c476992010-10-04 21:36:35 +02001646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001647 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001648 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001649 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001650
Johannes Bergb9454e82009-07-08 13:29:08 +02001651 err = nl80211_parse_key(info, &key);
1652 if (err)
1653 return err;
1654
1655 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001656 return -EINVAL;
1657
Johannes Bergb9454e82009-07-08 13:29:08 +02001658 /* only support setting default key */
1659 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001660 return -EINVAL;
1661
Johannes Bergfffd0932009-07-08 14:22:54 +02001662 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001663
1664 if (key.def) {
1665 if (!rdev->ops->set_default_key) {
1666 err = -EOPNOTSUPP;
1667 goto out;
1668 }
1669
1670 err = nl80211_key_allowed(dev->ieee80211_ptr);
1671 if (err)
1672 goto out;
1673
1674 if (!(rdev->wiphy.flags &
1675 WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS)) {
1676 if (!key.def_uni || !key.def_multi) {
1677 err = -EOPNOTSUPP;
1678 goto out;
1679 }
1680 }
1681
1682 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1683 key.def_uni, key.def_multi);
1684
1685 if (err)
1686 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001687
Johannes Berg3d23e342009-09-29 23:27:28 +02001688#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001689 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001690#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001691 } else {
1692 if (key.def_uni || !key.def_multi) {
1693 err = -EINVAL;
1694 goto out;
1695 }
1696
1697 if (!rdev->ops->set_default_mgmt_key) {
1698 err = -EOPNOTSUPP;
1699 goto out;
1700 }
1701
1702 err = nl80211_key_allowed(dev->ieee80211_ptr);
1703 if (err)
1704 goto out;
1705
1706 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1707 dev, key.idx);
1708 if (err)
1709 goto out;
1710
1711#ifdef CONFIG_CFG80211_WEXT
1712 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1713#endif
1714 }
1715
1716 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001717 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001718
Johannes Berg41ade002007-12-19 02:03:29 +01001719 return err;
1720}
1721
1722static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1723{
Johannes Berg4c476992010-10-04 21:36:35 +02001724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001725 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001726 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001727 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001728 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001729
Johannes Bergb9454e82009-07-08 13:29:08 +02001730 err = nl80211_parse_key(info, &key);
1731 if (err)
1732 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001733
Johannes Bergb9454e82009-07-08 13:29:08 +02001734 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001735 return -EINVAL;
1736
Johannes Berg41ade002007-12-19 02:03:29 +01001737 if (info->attrs[NL80211_ATTR_MAC])
1738 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1739
Johannes Berge31b8212010-10-05 19:39:30 +02001740 if (key.type == -1) {
1741 if (mac_addr)
1742 key.type = NL80211_KEYTYPE_PAIRWISE;
1743 else
1744 key.type = NL80211_KEYTYPE_GROUP;
1745 }
1746
1747 /* for now */
1748 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1749 key.type != NL80211_KEYTYPE_GROUP)
1750 return -EINVAL;
1751
Johannes Berg4c476992010-10-04 21:36:35 +02001752 if (!rdev->ops->add_key)
1753 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001754
Johannes Berge31b8212010-10-05 19:39:30 +02001755 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1756 key.type == NL80211_KEYTYPE_PAIRWISE,
1757 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001758 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001759
1760 wdev_lock(dev->ieee80211_ptr);
1761 err = nl80211_key_allowed(dev->ieee80211_ptr);
1762 if (!err)
1763 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001764 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001765 mac_addr, &key.p);
1766 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001767
Johannes Berg41ade002007-12-19 02:03:29 +01001768 return err;
1769}
1770
1771static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1772{
Johannes Berg4c476992010-10-04 21:36:35 +02001773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001774 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001775 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001776 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001777 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001778
Johannes Bergb9454e82009-07-08 13:29:08 +02001779 err = nl80211_parse_key(info, &key);
1780 if (err)
1781 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001782
1783 if (info->attrs[NL80211_ATTR_MAC])
1784 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1785
Johannes Berge31b8212010-10-05 19:39:30 +02001786 if (key.type == -1) {
1787 if (mac_addr)
1788 key.type = NL80211_KEYTYPE_PAIRWISE;
1789 else
1790 key.type = NL80211_KEYTYPE_GROUP;
1791 }
1792
1793 /* for now */
1794 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1795 key.type != NL80211_KEYTYPE_GROUP)
1796 return -EINVAL;
1797
Johannes Berg4c476992010-10-04 21:36:35 +02001798 if (!rdev->ops->del_key)
1799 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001800
Johannes Bergfffd0932009-07-08 14:22:54 +02001801 wdev_lock(dev->ieee80211_ptr);
1802 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02001803
1804 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
1805 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1806 err = -ENOENT;
1807
Johannes Bergfffd0932009-07-08 14:22:54 +02001808 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02001809 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
1810 key.type == NL80211_KEYTYPE_PAIRWISE,
1811 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01001812
Johannes Berg3d23e342009-09-29 23:27:28 +02001813#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02001814 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02001815 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02001816 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001817 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02001818 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
1819 }
1820#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02001821 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02001822
Johannes Berg41ade002007-12-19 02:03:29 +01001823 return err;
1824}
1825
Johannes Berged1b6cc2007-12-19 02:03:32 +01001826static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1827{
1828 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1829 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02001830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1831 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01001832 struct beacon_parameters params;
1833 int haveinfo = 0;
1834
Johannes Bergf4a11bb2009-03-27 12:40:28 +01001835 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1836 return -EINVAL;
1837
Johannes Berg074ac8d2010-09-16 14:58:22 +02001838 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001839 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1840 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02001841
Johannes Berged1b6cc2007-12-19 02:03:32 +01001842 switch (info->genlhdr->cmd) {
1843 case NL80211_CMD_NEW_BEACON:
1844 /* these are required for NEW_BEACON */
1845 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1846 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02001847 !info->attrs[NL80211_ATTR_BEACON_HEAD])
1848 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001849
Johannes Berg79c97e92009-07-07 03:56:12 +02001850 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001851 break;
1852 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02001853 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001854 break;
1855 default:
1856 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02001857 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001858 }
1859
Johannes Berg4c476992010-10-04 21:36:35 +02001860 if (!call)
1861 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001862
1863 memset(&params, 0, sizeof(params));
1864
1865 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1866 params.interval =
1867 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1868 haveinfo = 1;
1869 }
1870
1871 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1872 params.dtim_period =
1873 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1874 haveinfo = 1;
1875 }
1876
1877 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1878 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1879 params.head_len =
1880 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1881 haveinfo = 1;
1882 }
1883
1884 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1885 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1886 params.tail_len =
1887 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1888 haveinfo = 1;
1889 }
1890
Johannes Berg4c476992010-10-04 21:36:35 +02001891 if (!haveinfo)
1892 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001893
Johannes Berg4c476992010-10-04 21:36:35 +02001894 return call(&rdev->wiphy, dev, &params);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001895}
1896
1897static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1898{
Johannes Berg4c476992010-10-04 21:36:35 +02001899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1900 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01001901
Johannes Berg4c476992010-10-04 21:36:35 +02001902 if (!rdev->ops->del_beacon)
1903 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001904
Johannes Berg074ac8d2010-09-16 14:58:22 +02001905 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001906 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1907 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001908
Johannes Berg4c476992010-10-04 21:36:35 +02001909 return rdev->ops->del_beacon(&rdev->wiphy, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001910}
1911
Johannes Berg5727ef12007-12-19 02:03:34 +01001912static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1913 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1914 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1915 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03001916 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01001917};
1918
Johannes Bergeccb8e82009-05-11 21:57:56 +03001919static int parse_station_flags(struct genl_info *info,
1920 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01001921{
1922 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03001923 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01001924 int flag;
1925
Johannes Bergeccb8e82009-05-11 21:57:56 +03001926 /*
1927 * Try parsing the new attribute first so userspace
1928 * can specify both for older kernels.
1929 */
1930 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
1931 if (nla) {
1932 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01001933
Johannes Bergeccb8e82009-05-11 21:57:56 +03001934 sta_flags = nla_data(nla);
1935 params->sta_flags_mask = sta_flags->mask;
1936 params->sta_flags_set = sta_flags->set;
1937 if ((params->sta_flags_mask |
1938 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
1939 return -EINVAL;
1940 return 0;
1941 }
1942
1943 /* if present, parse the old attribute */
1944
1945 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01001946 if (!nla)
1947 return 0;
1948
1949 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1950 nla, sta_flags_policy))
1951 return -EINVAL;
1952
Johannes Bergeccb8e82009-05-11 21:57:56 +03001953 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
1954 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01001955
1956 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1957 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03001958 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01001959
1960 return 0;
1961}
1962
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001963static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1964 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01001965 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001966{
1967 void *hdr;
Henning Rogge420e7fa2008-12-11 22:04:19 +01001968 struct nlattr *sinfoattr, *txrate;
1969 u16 bitrate;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001970
1971 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1972 if (!hdr)
1973 return -1;
1974
1975 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1976 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1977
Johannes Bergf5ea9122009-08-07 16:17:38 +02001978 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
1979
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001980 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1981 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001982 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001983 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1984 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1985 sinfo->inactive_time);
1986 if (sinfo->filled & STATION_INFO_RX_BYTES)
1987 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1988 sinfo->rx_bytes);
1989 if (sinfo->filled & STATION_INFO_TX_BYTES)
1990 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1991 sinfo->tx_bytes);
1992 if (sinfo->filled & STATION_INFO_LLID)
1993 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1994 sinfo->llid);
1995 if (sinfo->filled & STATION_INFO_PLID)
1996 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1997 sinfo->plid);
1998 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1999 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2000 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002001 if (sinfo->filled & STATION_INFO_SIGNAL)
2002 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2003 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002004 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2005 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2006 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002007 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
2008 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
2009 if (!txrate)
2010 goto nla_put_failure;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002011
John W. Linville254416a2009-12-09 16:43:52 -05002012 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2013 bitrate = cfg80211_calculate_bitrate(&sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002014 if (bitrate > 0)
2015 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2016
2017 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
2018 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
2019 sinfo->txrate.mcs);
2020 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2021 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2022 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
2023 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2024
2025 nla_nest_end(msg, txrate);
2026 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002027 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2028 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2029 sinfo->rx_packets);
2030 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2031 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2032 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002033 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2034 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2035 sinfo->tx_retries);
2036 if (sinfo->filled & STATION_INFO_TX_FAILED)
2037 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2038 sinfo->tx_failed);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002039 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002040
2041 return genlmsg_end(msg, hdr);
2042
2043 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002044 genlmsg_cancel(msg, hdr);
2045 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002046}
2047
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002048static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002049 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002050{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002051 struct station_info sinfo;
2052 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002053 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002054 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002055 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002056 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002057
Johannes Berg67748892010-10-04 21:14:06 +02002058 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2059 if (err)
2060 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002061
2062 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002063 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002064 goto out_err;
2065 }
2066
Johannes Bergbba95fe2008-07-29 13:22:51 +02002067 while (1) {
2068 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2069 mac_addr, &sinfo);
2070 if (err == -ENOENT)
2071 break;
2072 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002073 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002074
2075 if (nl80211_send_station(skb,
2076 NETLINK_CB(cb->skb).pid,
2077 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2078 netdev, mac_addr,
2079 &sinfo) < 0)
2080 goto out;
2081
2082 sta_idx++;
2083 }
2084
2085
2086 out:
2087 cb->args[1] = sta_idx;
2088 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002089 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002090 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002091
2092 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002093}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002094
Johannes Berg5727ef12007-12-19 02:03:34 +01002095static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2096{
Johannes Berg4c476992010-10-04 21:36:35 +02002097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2098 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002099 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002100 struct sk_buff *msg;
2101 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002102 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002103
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002104 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002105
2106 if (!info->attrs[NL80211_ATTR_MAC])
2107 return -EINVAL;
2108
2109 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2110
Johannes Berg4c476992010-10-04 21:36:35 +02002111 if (!rdev->ops->get_station)
2112 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002113
Johannes Berg79c97e92009-07-07 03:56:12 +02002114 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002115 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002116 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002117
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002119 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002120 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002121
2122 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002123 dev, mac_addr, &sinfo) < 0) {
2124 nlmsg_free(msg);
2125 return -ENOBUFS;
2126 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002127
Johannes Berg4c476992010-10-04 21:36:35 +02002128 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002129}
2130
2131/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002132 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002133 */
Johannes Berg463d0182009-07-14 00:33:35 +02002134static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002135 struct cfg80211_registered_device *rdev,
2136 struct net_device **vlan)
2137{
Johannes Berg463d0182009-07-14 00:33:35 +02002138 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002139 *vlan = NULL;
2140
2141 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002142 *vlan = dev_get_by_index(genl_info_net(info),
2143 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002144 if (!*vlan)
2145 return -ENODEV;
2146 if (!(*vlan)->ieee80211_ptr)
2147 return -EINVAL;
2148 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2149 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002150 if (!netif_running(*vlan))
2151 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002152 }
2153 return 0;
2154}
2155
2156static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2157{
Johannes Berg4c476992010-10-04 21:36:35 +02002158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002159 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002160 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002161 struct station_parameters params;
2162 u8 *mac_addr = NULL;
2163
2164 memset(&params, 0, sizeof(params));
2165
2166 params.listen_interval = -1;
2167
2168 if (info->attrs[NL80211_ATTR_STA_AID])
2169 return -EINVAL;
2170
2171 if (!info->attrs[NL80211_ATTR_MAC])
2172 return -EINVAL;
2173
2174 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2175
2176 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2177 params.supported_rates =
2178 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2179 params.supported_rates_len =
2180 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2181 }
2182
2183 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2184 params.listen_interval =
2185 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2186
Jouni Malinen36aedc92008-08-25 11:58:58 +03002187 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2188 params.ht_capa =
2189 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2190
Johannes Bergeccb8e82009-05-11 21:57:56 +03002191 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002192 return -EINVAL;
2193
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002194 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2195 params.plink_action =
2196 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2197
Johannes Berg463d0182009-07-14 00:33:35 +02002198 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002199 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002200 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002201
2202 /* validate settings */
2203 err = 0;
2204
2205 switch (dev->ieee80211_ptr->iftype) {
2206 case NL80211_IFTYPE_AP:
2207 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002208 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002209 /* disallow mesh-specific things */
2210 if (params.plink_action)
2211 err = -EINVAL;
2212 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002213 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002214 case NL80211_IFTYPE_STATION:
2215 /* disallow everything but AUTHORIZED flag */
2216 if (params.plink_action)
2217 err = -EINVAL;
2218 if (params.vlan)
2219 err = -EINVAL;
2220 if (params.supported_rates)
2221 err = -EINVAL;
2222 if (params.ht_capa)
2223 err = -EINVAL;
2224 if (params.listen_interval >= 0)
2225 err = -EINVAL;
2226 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2227 err = -EINVAL;
2228 break;
2229 case NL80211_IFTYPE_MESH_POINT:
2230 /* disallow things mesh doesn't support */
2231 if (params.vlan)
2232 err = -EINVAL;
2233 if (params.ht_capa)
2234 err = -EINVAL;
2235 if (params.listen_interval >= 0)
2236 err = -EINVAL;
2237 if (params.supported_rates)
2238 err = -EINVAL;
2239 if (params.sta_flags_mask)
2240 err = -EINVAL;
2241 break;
2242 default:
2243 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002244 }
2245
Johannes Berg5727ef12007-12-19 02:03:34 +01002246 if (err)
2247 goto out;
2248
Johannes Berg79c97e92009-07-07 03:56:12 +02002249 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002250 err = -EOPNOTSUPP;
2251 goto out;
2252 }
2253
Johannes Berg79c97e92009-07-07 03:56:12 +02002254 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002255
2256 out:
2257 if (params.vlan)
2258 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002259
Johannes Berg5727ef12007-12-19 02:03:34 +01002260 return err;
2261}
2262
2263static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2264{
Johannes Berg4c476992010-10-04 21:36:35 +02002265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002266 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002267 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002268 struct station_parameters params;
2269 u8 *mac_addr = NULL;
2270
2271 memset(&params, 0, sizeof(params));
2272
2273 if (!info->attrs[NL80211_ATTR_MAC])
2274 return -EINVAL;
2275
Johannes Berg5727ef12007-12-19 02:03:34 +01002276 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2277 return -EINVAL;
2278
2279 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2280 return -EINVAL;
2281
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002282 if (!info->attrs[NL80211_ATTR_STA_AID])
2283 return -EINVAL;
2284
Johannes Berg5727ef12007-12-19 02:03:34 +01002285 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2286 params.supported_rates =
2287 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2288 params.supported_rates_len =
2289 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2290 params.listen_interval =
2291 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002292
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002293 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2294 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2295 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002296
Jouni Malinen36aedc92008-08-25 11:58:58 +03002297 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2298 params.ht_capa =
2299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002300
Johannes Bergeccb8e82009-05-11 21:57:56 +03002301 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002302 return -EINVAL;
2303
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002304 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002305 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02002306 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2307 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002308
Johannes Berg463d0182009-07-14 00:33:35 +02002309 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002310 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002311 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002312
2313 /* validate settings */
2314 err = 0;
2315
Johannes Berg79c97e92009-07-07 03:56:12 +02002316 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002317 err = -EOPNOTSUPP;
2318 goto out;
2319 }
2320
Johannes Berg79c97e92009-07-07 03:56:12 +02002321 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002322
2323 out:
2324 if (params.vlan)
2325 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002326 return err;
2327}
2328
2329static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2330{
Johannes Berg4c476992010-10-04 21:36:35 +02002331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2332 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002333 u8 *mac_addr = NULL;
2334
2335 if (info->attrs[NL80211_ATTR_MAC])
2336 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2337
Johannes Berge80cf852009-05-11 14:43:13 +02002338 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002339 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002340 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002341 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2342 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002343
Johannes Berg4c476992010-10-04 21:36:35 +02002344 if (!rdev->ops->del_station)
2345 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002346
Johannes Berg4c476992010-10-04 21:36:35 +02002347 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002348}
2349
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002350static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2351 int flags, struct net_device *dev,
2352 u8 *dst, u8 *next_hop,
2353 struct mpath_info *pinfo)
2354{
2355 void *hdr;
2356 struct nlattr *pinfoattr;
2357
2358 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2359 if (!hdr)
2360 return -1;
2361
2362 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2363 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2364 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2365
Johannes Bergf5ea9122009-08-07 16:17:38 +02002366 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2367
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002368 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2369 if (!pinfoattr)
2370 goto nla_put_failure;
2371 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2372 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2373 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002374 if (pinfo->filled & MPATH_INFO_SN)
2375 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2376 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002377 if (pinfo->filled & MPATH_INFO_METRIC)
2378 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2379 pinfo->metric);
2380 if (pinfo->filled & MPATH_INFO_EXPTIME)
2381 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2382 pinfo->exptime);
2383 if (pinfo->filled & MPATH_INFO_FLAGS)
2384 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2385 pinfo->flags);
2386 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2387 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2388 pinfo->discovery_timeout);
2389 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2390 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2391 pinfo->discovery_retries);
2392
2393 nla_nest_end(msg, pinfoattr);
2394
2395 return genlmsg_end(msg, hdr);
2396
2397 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002398 genlmsg_cancel(msg, hdr);
2399 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002400}
2401
2402static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002403 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002404{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002405 struct mpath_info pinfo;
2406 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002407 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002408 u8 dst[ETH_ALEN];
2409 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002410 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002411 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002412
Johannes Berg67748892010-10-04 21:14:06 +02002413 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2414 if (err)
2415 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002416
2417 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002418 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002419 goto out_err;
2420 }
2421
Jouni Malineneec60b02009-03-20 21:21:19 +02002422 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2423 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002424 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002425 }
2426
Johannes Bergbba95fe2008-07-29 13:22:51 +02002427 while (1) {
2428 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2429 dst, next_hop, &pinfo);
2430 if (err == -ENOENT)
2431 break;
2432 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002433 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002434
2435 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2436 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2437 netdev, dst, next_hop,
2438 &pinfo) < 0)
2439 goto out;
2440
2441 path_idx++;
2442 }
2443
2444
2445 out:
2446 cb->args[1] = path_idx;
2447 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002448 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002449 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002450 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002451}
2452
2453static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2454{
Johannes Berg4c476992010-10-04 21:36:35 +02002455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002456 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002457 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002458 struct mpath_info pinfo;
2459 struct sk_buff *msg;
2460 u8 *dst = NULL;
2461 u8 next_hop[ETH_ALEN];
2462
2463 memset(&pinfo, 0, sizeof(pinfo));
2464
2465 if (!info->attrs[NL80211_ATTR_MAC])
2466 return -EINVAL;
2467
2468 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2469
Johannes Berg4c476992010-10-04 21:36:35 +02002470 if (!rdev->ops->get_mpath)
2471 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002472
Johannes Berg4c476992010-10-04 21:36:35 +02002473 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2474 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002475
Johannes Berg79c97e92009-07-07 03:56:12 +02002476 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002477 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002478 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002479
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002481 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002482 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002483
2484 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002485 dev, dst, next_hop, &pinfo) < 0) {
2486 nlmsg_free(msg);
2487 return -ENOBUFS;
2488 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002489
Johannes Berg4c476992010-10-04 21:36:35 +02002490 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002491}
2492
2493static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2494{
Johannes Berg4c476992010-10-04 21:36:35 +02002495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2496 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002497 u8 *dst = NULL;
2498 u8 *next_hop = NULL;
2499
2500 if (!info->attrs[NL80211_ATTR_MAC])
2501 return -EINVAL;
2502
2503 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2504 return -EINVAL;
2505
2506 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2507 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2508
Johannes Berg4c476992010-10-04 21:36:35 +02002509 if (!rdev->ops->change_mpath)
2510 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002511
Johannes Berg4c476992010-10-04 21:36:35 +02002512 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2513 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002514
Johannes Berg4c476992010-10-04 21:36:35 +02002515 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002516}
Johannes Berg4c476992010-10-04 21:36:35 +02002517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002518static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2519{
Johannes Berg4c476992010-10-04 21:36:35 +02002520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2521 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002522 u8 *dst = NULL;
2523 u8 *next_hop = NULL;
2524
2525 if (!info->attrs[NL80211_ATTR_MAC])
2526 return -EINVAL;
2527
2528 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2529 return -EINVAL;
2530
2531 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2532 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2533
Johannes Berg4c476992010-10-04 21:36:35 +02002534 if (!rdev->ops->add_mpath)
2535 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002536
Johannes Berg4c476992010-10-04 21:36:35 +02002537 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2538 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002539
Johannes Berg4c476992010-10-04 21:36:35 +02002540 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002541}
2542
2543static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2544{
Johannes Berg4c476992010-10-04 21:36:35 +02002545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2546 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002547 u8 *dst = NULL;
2548
2549 if (info->attrs[NL80211_ATTR_MAC])
2550 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2551
Johannes Berg4c476992010-10-04 21:36:35 +02002552 if (!rdev->ops->del_mpath)
2553 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002554
Johannes Berg4c476992010-10-04 21:36:35 +02002555 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002556}
2557
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002558static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2559{
Johannes Berg4c476992010-10-04 21:36:35 +02002560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2561 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002562 struct bss_parameters params;
2563
2564 memset(&params, 0, sizeof(params));
2565 /* default to not changing parameters */
2566 params.use_cts_prot = -1;
2567 params.use_short_preamble = -1;
2568 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002569 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002570 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002571
2572 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2573 params.use_cts_prot =
2574 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2575 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2576 params.use_short_preamble =
2577 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2578 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2579 params.use_short_slot_time =
2580 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002581 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2582 params.basic_rates =
2583 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2584 params.basic_rates_len =
2585 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2586 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002587 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2588 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002589 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2590 params.ht_opmode =
2591 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002592
Johannes Berg4c476992010-10-04 21:36:35 +02002593 if (!rdev->ops->change_bss)
2594 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002595
Johannes Berg074ac8d2010-09-16 14:58:22 +02002596 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002597 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2598 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002599
Johannes Berg4c476992010-10-04 21:36:35 +02002600 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002601}
2602
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002603static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002604 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2605 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2606 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2607 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2608 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2609 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2610};
2611
2612static int parse_reg_rule(struct nlattr *tb[],
2613 struct ieee80211_reg_rule *reg_rule)
2614{
2615 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2616 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2617
2618 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2619 return -EINVAL;
2620 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2621 return -EINVAL;
2622 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2623 return -EINVAL;
2624 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2625 return -EINVAL;
2626 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2627 return -EINVAL;
2628
2629 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2630
2631 freq_range->start_freq_khz =
2632 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2633 freq_range->end_freq_khz =
2634 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2635 freq_range->max_bandwidth_khz =
2636 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2637
2638 power_rule->max_eirp =
2639 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2640
2641 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2642 power_rule->max_antenna_gain =
2643 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2644
2645 return 0;
2646}
2647
2648static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2649{
2650 int r;
2651 char *data = NULL;
2652
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002653 /*
2654 * You should only get this when cfg80211 hasn't yet initialized
2655 * completely when built-in to the kernel right between the time
2656 * window between nl80211_init() and regulatory_init(), if that is
2657 * even possible.
2658 */
2659 mutex_lock(&cfg80211_mutex);
2660 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002661 mutex_unlock(&cfg80211_mutex);
2662 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002663 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002664 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002665
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002666 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2667 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002668
2669 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2670
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002671 r = regulatory_hint_user(data);
2672
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002673 return r;
2674}
2675
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002676static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01002677 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002678{
Johannes Berg4c476992010-10-04 21:36:35 +02002679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02002680 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01002681 struct wireless_dev *wdev = dev->ieee80211_ptr;
2682 struct mesh_config cur_params;
2683 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002684 void *hdr;
2685 struct nlattr *pinfoattr;
2686 struct sk_buff *msg;
2687
Johannes Berg29cbe682010-12-03 09:20:44 +01002688 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2689 return -EOPNOTSUPP;
2690
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002691 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02002692 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002693
Johannes Berg29cbe682010-12-03 09:20:44 +01002694 wdev_lock(wdev);
2695 /* If not connected, get default parameters */
2696 if (!wdev->mesh_id_len)
2697 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2698 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002699 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01002700 &cur_params);
2701 wdev_unlock(wdev);
2702
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002703 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002704 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002705
2706 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002707 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002708 if (!msg)
2709 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002710 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002711 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002712 if (!hdr)
2713 goto nla_put_failure;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002714 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002715 if (!pinfoattr)
2716 goto nla_put_failure;
2717 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2718 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2719 cur_params.dot11MeshRetryTimeout);
2720 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2721 cur_params.dot11MeshConfirmTimeout);
2722 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2723 cur_params.dot11MeshHoldingTimeout);
2724 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2725 cur_params.dot11MeshMaxPeerLinks);
2726 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2727 cur_params.dot11MeshMaxRetries);
2728 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2729 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01002730 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2731 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002732 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2733 cur_params.auto_open_plinks);
2734 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2735 cur_params.dot11MeshHWMPmaxPREQretries);
2736 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2737 cur_params.path_refresh_time);
2738 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2739 cur_params.min_discovery_timeout);
2740 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2741 cur_params.dot11MeshHWMPactivePathTimeout);
2742 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2743 cur_params.dot11MeshHWMPpreqMinInterval);
2744 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2745 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00002746 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2747 cur_params.dot11MeshHWMPRootMode);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002748 nla_nest_end(msg, pinfoattr);
2749 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002750 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002751
Johannes Berg3b858752009-03-12 09:55:09 +01002752 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002753 genlmsg_cancel(msg, hdr);
Yuri Ershovd080e272010-06-29 15:08:07 +04002754 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02002755 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002756}
2757
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002758static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002759 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2760 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2761 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2762 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2763 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2764 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01002765 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002766 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2767
2768 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2769 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2770 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2771 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2772 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2773 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2774};
2775
Javier Cardonac80d5452010-12-16 17:37:49 -08002776static const struct nla_policy
2777 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
2778 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
2779 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
2780 [NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE] = { .type = NLA_BINARY,
2781 .len = IEEE80211_MAX_DATA_LEN },
2782};
2783
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002784static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002785 struct mesh_config *cfg,
2786 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002787{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002788 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002789 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002790
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002791#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2792do {\
2793 if (table[attr_num]) {\
2794 cfg->param = nla_fn(table[attr_num]); \
2795 mask |= (1 << (attr_num - 1)); \
2796 } \
2797} while (0);\
2798
2799
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002800 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002801 return -EINVAL;
2802 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002803 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002804 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002805 return -EINVAL;
2806
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002807 /* This makes sure that there aren't more than 32 mesh config
2808 * parameters (otherwise our bitfield scheme would not work.) */
2809 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2810
2811 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2813 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2815 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2816 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2817 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2819 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2821 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2822 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2823 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01002824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
2825 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2827 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2828 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2829 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2830 nla_get_u8);
2831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2832 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2834 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2835 nla_get_u16);
2836 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2837 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2838 nla_get_u32);
2839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2840 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2841 nla_get_u16);
2842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2843 dot11MeshHWMPnetDiameterTraversalTime,
2844 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2845 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00002846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2847 dot11MeshHWMPRootMode, mask,
2848 NL80211_MESHCONF_HWMP_ROOTMODE,
2849 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002850 if (mask_out)
2851 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08002852
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002853 return 0;
2854
2855#undef FILL_IN_MESH_PARAM_IF_SET
2856}
2857
Javier Cardonac80d5452010-12-16 17:37:49 -08002858static int nl80211_parse_mesh_setup(struct genl_info *info,
2859 struct mesh_setup *setup)
2860{
2861 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
2862
2863 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
2864 return -EINVAL;
2865 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
2866 info->attrs[NL80211_ATTR_MESH_SETUP],
2867 nl80211_mesh_setup_params_policy))
2868 return -EINVAL;
2869
2870 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
2871 setup->path_sel_proto =
2872 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
2873 IEEE80211_PATH_PROTOCOL_VENDOR :
2874 IEEE80211_PATH_PROTOCOL_HWMP;
2875
2876 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
2877 setup->path_metric =
2878 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
2879 IEEE80211_PATH_METRIC_VENDOR :
2880 IEEE80211_PATH_METRIC_AIRTIME;
2881
2882 if (tb[NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE]) {
2883 struct nlattr *ieattr =
2884 tb[NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE];
2885 if (!is_valid_ie_attr(ieattr))
2886 return -EINVAL;
2887 setup->vendor_ie = nla_data(ieattr);
2888 setup->vendor_ie_len = nla_len(ieattr);
2889 }
2890
2891 return 0;
2892}
2893
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002894static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01002895 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002896{
2897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2898 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01002899 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002900 struct mesh_config cfg;
2901 u32 mask;
2902 int err;
2903
Johannes Berg29cbe682010-12-03 09:20:44 +01002904 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2905 return -EOPNOTSUPP;
2906
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002907 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002908 return -EOPNOTSUPP;
2909
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002910 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002911 if (err)
2912 return err;
2913
Johannes Berg29cbe682010-12-03 09:20:44 +01002914 wdev_lock(wdev);
2915 if (!wdev->mesh_id_len)
2916 err = -ENOLINK;
2917
2918 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002919 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01002920 mask, &cfg);
2921
2922 wdev_unlock(wdev);
2923
2924 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002925}
2926
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002927static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2928{
2929 struct sk_buff *msg;
2930 void *hdr = NULL;
2931 struct nlattr *nl_reg_rules;
2932 unsigned int i;
2933 int err = -EINVAL;
2934
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002935 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002936
2937 if (!cfg80211_regdomain)
2938 goto out;
2939
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002940 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002941 if (!msg) {
2942 err = -ENOBUFS;
2943 goto out;
2944 }
2945
2946 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2947 NL80211_CMD_GET_REG);
2948 if (!hdr)
2949 goto nla_put_failure;
2950
2951 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2952 cfg80211_regdomain->alpha2);
2953
2954 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2955 if (!nl_reg_rules)
2956 goto nla_put_failure;
2957
2958 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2959 struct nlattr *nl_reg_rule;
2960 const struct ieee80211_reg_rule *reg_rule;
2961 const struct ieee80211_freq_range *freq_range;
2962 const struct ieee80211_power_rule *power_rule;
2963
2964 reg_rule = &cfg80211_regdomain->reg_rules[i];
2965 freq_range = &reg_rule->freq_range;
2966 power_rule = &reg_rule->power_rule;
2967
2968 nl_reg_rule = nla_nest_start(msg, i);
2969 if (!nl_reg_rule)
2970 goto nla_put_failure;
2971
2972 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2973 reg_rule->flags);
2974 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2975 freq_range->start_freq_khz);
2976 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2977 freq_range->end_freq_khz);
2978 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2979 freq_range->max_bandwidth_khz);
2980 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2981 power_rule->max_antenna_gain);
2982 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2983 power_rule->max_eirp);
2984
2985 nla_nest_end(msg, nl_reg_rule);
2986 }
2987
2988 nla_nest_end(msg, nl_reg_rules);
2989
2990 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00002991 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002992 goto out;
2993
2994nla_put_failure:
2995 genlmsg_cancel(msg, hdr);
Yuri Ershovd080e272010-06-29 15:08:07 +04002996 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002997 err = -EMSGSIZE;
2998out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002999 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003000 return err;
3001}
3002
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003003static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3004{
3005 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3006 struct nlattr *nl_reg_rule;
3007 char *alpha2 = NULL;
3008 int rem_reg_rules = 0, r = 0;
3009 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3010 struct ieee80211_regdomain *rd = NULL;
3011
3012 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3013 return -EINVAL;
3014
3015 if (!info->attrs[NL80211_ATTR_REG_RULES])
3016 return -EINVAL;
3017
3018 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3019
3020 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3021 rem_reg_rules) {
3022 num_rules++;
3023 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003024 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003025 }
3026
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003027 mutex_lock(&cfg80211_mutex);
3028
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003029 if (!reg_is_valid_request(alpha2)) {
3030 r = -EINVAL;
3031 goto bad_reg;
3032 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003033
3034 size_of_regd = sizeof(struct ieee80211_regdomain) +
3035 (num_rules * sizeof(struct ieee80211_reg_rule));
3036
3037 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003038 if (!rd) {
3039 r = -ENOMEM;
3040 goto bad_reg;
3041 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003042
3043 rd->n_reg_rules = num_rules;
3044 rd->alpha2[0] = alpha2[0];
3045 rd->alpha2[1] = alpha2[1];
3046
3047 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3048 rem_reg_rules) {
3049 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3050 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3051 reg_rule_policy);
3052 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3053 if (r)
3054 goto bad_reg;
3055
3056 rule_idx++;
3057
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003058 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3059 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003060 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003061 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003062 }
3063
3064 BUG_ON(rule_idx != num_rules);
3065
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003066 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003067
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003068 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003069
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003070 return r;
3071
Johannes Bergd2372b32008-10-24 20:32:20 +02003072 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003073 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003074 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003075 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003076}
3077
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003078static int validate_scan_freqs(struct nlattr *freqs)
3079{
3080 struct nlattr *attr1, *attr2;
3081 int n_channels = 0, tmp1, tmp2;
3082
3083 nla_for_each_nested(attr1, freqs, tmp1) {
3084 n_channels++;
3085 /*
3086 * Some hardware has a limited channel list for
3087 * scanning, and it is pretty much nonsensical
3088 * to scan for a channel twice, so disallow that
3089 * and don't require drivers to check that the
3090 * channel list they get isn't longer than what
3091 * they can scan, as long as they can scan all
3092 * the channels they registered at once.
3093 */
3094 nla_for_each_nested(attr2, freqs, tmp2)
3095 if (attr1 != attr2 &&
3096 nla_get_u32(attr1) == nla_get_u32(attr2))
3097 return 0;
3098 }
3099
3100 return n_channels;
3101}
3102
Johannes Berg2a519312009-02-10 21:25:55 +01003103static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3104{
Johannes Berg4c476992010-10-04 21:36:35 +02003105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3106 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003107 struct cfg80211_scan_request *request;
3108 struct cfg80211_ssid *ssid;
3109 struct ieee80211_channel *channel;
3110 struct nlattr *attr;
3111 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003112 int err, tmp, n_ssids = 0, n_channels, i;
Johannes Berg2a519312009-02-10 21:25:55 +01003113 enum ieee80211_band band;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003114 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003115
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003116 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3117 return -EINVAL;
3118
Johannes Berg79c97e92009-07-07 03:56:12 +02003119 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003120
Johannes Berg4c476992010-10-04 21:36:35 +02003121 if (!rdev->ops->scan)
3122 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003123
Johannes Berg4c476992010-10-04 21:36:35 +02003124 if (rdev->scan_req)
3125 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003126
3127 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003128 n_channels = validate_scan_freqs(
3129 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003130 if (!n_channels)
3131 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003132 } else {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003133 n_channels = 0;
3134
Johannes Berg2a519312009-02-10 21:25:55 +01003135 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3136 if (wiphy->bands[band])
3137 n_channels += wiphy->bands[band]->n_channels;
3138 }
3139
3140 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3141 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3142 n_ssids++;
3143
Johannes Berg4c476992010-10-04 21:36:35 +02003144 if (n_ssids > wiphy->max_scan_ssids)
3145 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003146
Jouni Malinen70692ad2009-02-16 19:39:13 +02003147 if (info->attrs[NL80211_ATTR_IE])
3148 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3149 else
3150 ie_len = 0;
3151
Johannes Berg4c476992010-10-04 21:36:35 +02003152 if (ie_len > wiphy->max_scan_ie_len)
3153 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003154
Johannes Berg2a519312009-02-10 21:25:55 +01003155 request = kzalloc(sizeof(*request)
3156 + sizeof(*ssid) * n_ssids
Jouni Malinen70692ad2009-02-16 19:39:13 +02003157 + sizeof(channel) * n_channels
3158 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003159 if (!request)
3160 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003161
Johannes Berg2a519312009-02-10 21:25:55 +01003162 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003163 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003164 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003165 if (ie_len) {
3166 if (request->ssids)
3167 request->ie = (void *)(request->ssids + n_ssids);
3168 else
3169 request->ie = (void *)(request->channels + n_channels);
3170 }
Johannes Berg2a519312009-02-10 21:25:55 +01003171
Johannes Berg584991d2009-11-02 13:32:03 +01003172 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003173 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3174 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003175 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003176 struct ieee80211_channel *chan;
3177
3178 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3179
3180 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003181 err = -EINVAL;
3182 goto out_free;
3183 }
Johannes Berg584991d2009-11-02 13:32:03 +01003184
3185 /* ignore disabled channels */
3186 if (chan->flags & IEEE80211_CHAN_DISABLED)
3187 continue;
3188
3189 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003190 i++;
3191 }
3192 } else {
3193 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003194 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3195 int j;
3196 if (!wiphy->bands[band])
3197 continue;
3198 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003199 struct ieee80211_channel *chan;
3200
3201 chan = &wiphy->bands[band]->channels[j];
3202
3203 if (chan->flags & IEEE80211_CHAN_DISABLED)
3204 continue;
3205
3206 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003207 i++;
3208 }
3209 }
3210 }
3211
Johannes Berg584991d2009-11-02 13:32:03 +01003212 if (!i) {
3213 err = -EINVAL;
3214 goto out_free;
3215 }
3216
3217 request->n_channels = i;
3218
Johannes Berg2a519312009-02-10 21:25:55 +01003219 i = 0;
3220 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3221 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
3222 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
3223 err = -EINVAL;
3224 goto out_free;
3225 }
3226 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
3227 request->ssids[i].ssid_len = nla_len(attr);
3228 i++;
3229 }
3230 }
3231
Jouni Malinen70692ad2009-02-16 19:39:13 +02003232 if (info->attrs[NL80211_ATTR_IE]) {
3233 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003234 memcpy((void *)request->ie,
3235 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003236 request->ie_len);
3237 }
3238
Johannes Berg463d0182009-07-14 00:33:35 +02003239 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003240 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003241
Johannes Berg79c97e92009-07-07 03:56:12 +02003242 rdev->scan_req = request;
3243 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003244
Johannes Berg463d0182009-07-14 00:33:35 +02003245 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003246 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003247 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003248 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003249 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003250 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003251 kfree(request);
3252 }
Johannes Berg3b858752009-03-12 09:55:09 +01003253
Johannes Berg2a519312009-02-10 21:25:55 +01003254 return err;
3255}
3256
3257static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
3258 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003259 struct wireless_dev *wdev,
3260 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003261{
Johannes Berg48ab9052009-07-10 18:42:31 +02003262 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003263 void *hdr;
3264 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003265 int i;
3266
3267 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003268
3269 hdr = nl80211hdr_put(msg, pid, seq, flags,
3270 NL80211_CMD_NEW_SCAN_RESULTS);
3271 if (!hdr)
3272 return -1;
3273
Johannes Bergf5ea9122009-08-07 16:17:38 +02003274 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003275 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003276
3277 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3278 if (!bss)
3279 goto nla_put_failure;
3280 if (!is_zero_ether_addr(res->bssid))
3281 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3282 if (res->information_elements && res->len_information_elements)
3283 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3284 res->len_information_elements,
3285 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003286 if (res->beacon_ies && res->len_beacon_ies &&
3287 res->beacon_ies != res->information_elements)
3288 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3289 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003290 if (res->tsf)
3291 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3292 if (res->beacon_interval)
3293 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3294 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3295 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003296 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3297 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003298
Johannes Berg77965c92009-02-18 18:45:06 +01003299 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003300 case CFG80211_SIGNAL_TYPE_MBM:
3301 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3302 break;
3303 case CFG80211_SIGNAL_TYPE_UNSPEC:
3304 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3305 break;
3306 default:
3307 break;
3308 }
3309
Johannes Berg48ab9052009-07-10 18:42:31 +02003310 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003311 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003312 case NL80211_IFTYPE_STATION:
3313 if (intbss == wdev->current_bss)
3314 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3315 NL80211_BSS_STATUS_ASSOCIATED);
3316 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3317 if (intbss != wdev->auth_bsses[i])
3318 continue;
3319 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3320 NL80211_BSS_STATUS_AUTHENTICATED);
3321 break;
3322 }
3323 break;
3324 case NL80211_IFTYPE_ADHOC:
3325 if (intbss == wdev->current_bss)
3326 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3327 NL80211_BSS_STATUS_IBSS_JOINED);
3328 break;
3329 default:
3330 break;
3331 }
3332
Johannes Berg2a519312009-02-10 21:25:55 +01003333 nla_nest_end(msg, bss);
3334
3335 return genlmsg_end(msg, hdr);
3336
3337 nla_put_failure:
3338 genlmsg_cancel(msg, hdr);
3339 return -EMSGSIZE;
3340}
3341
3342static int nl80211_dump_scan(struct sk_buff *skb,
3343 struct netlink_callback *cb)
3344{
Johannes Berg48ab9052009-07-10 18:42:31 +02003345 struct cfg80211_registered_device *rdev;
3346 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01003347 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02003348 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01003349 int start = cb->args[1], idx = 0;
3350 int err;
3351
Johannes Berg67748892010-10-04 21:14:06 +02003352 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3353 if (err)
3354 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01003355
Johannes Berg48ab9052009-07-10 18:42:31 +02003356 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01003357
Johannes Berg48ab9052009-07-10 18:42:31 +02003358 wdev_lock(wdev);
3359 spin_lock_bh(&rdev->bss_lock);
3360 cfg80211_bss_expire(rdev);
3361
3362 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01003363 if (++idx <= start)
3364 continue;
3365 if (nl80211_send_bss(skb,
3366 NETLINK_CB(cb->skb).pid,
3367 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02003368 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01003369 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02003370 break;
Johannes Berg2a519312009-02-10 21:25:55 +01003371 }
3372 }
3373
Johannes Berg48ab9052009-07-10 18:42:31 +02003374 spin_unlock_bh(&rdev->bss_lock);
3375 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003376
3377 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02003378 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003379
Johannes Berg67748892010-10-04 21:14:06 +02003380 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01003381}
3382
Holger Schurig61fa7132009-11-11 12:25:40 +01003383static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3384 int flags, struct net_device *dev,
3385 struct survey_info *survey)
3386{
3387 void *hdr;
3388 struct nlattr *infoattr;
3389
3390 /* Survey without a channel doesn't make sense */
3391 if (!survey->channel)
3392 return -EINVAL;
3393
3394 hdr = nl80211hdr_put(msg, pid, seq, flags,
3395 NL80211_CMD_NEW_SURVEY_RESULTS);
3396 if (!hdr)
3397 return -ENOMEM;
3398
3399 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3400
3401 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3402 if (!infoattr)
3403 goto nla_put_failure;
3404
3405 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3406 survey->channel->center_freq);
3407 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3408 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3409 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02003410 if (survey->filled & SURVEY_INFO_IN_USE)
3411 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02003412 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3413 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3414 survey->channel_time);
3415 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3416 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3417 survey->channel_time_busy);
3418 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3419 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3420 survey->channel_time_ext_busy);
3421 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3422 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3423 survey->channel_time_rx);
3424 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3425 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3426 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01003427
3428 nla_nest_end(msg, infoattr);
3429
3430 return genlmsg_end(msg, hdr);
3431
3432 nla_put_failure:
3433 genlmsg_cancel(msg, hdr);
3434 return -EMSGSIZE;
3435}
3436
3437static int nl80211_dump_survey(struct sk_buff *skb,
3438 struct netlink_callback *cb)
3439{
3440 struct survey_info survey;
3441 struct cfg80211_registered_device *dev;
3442 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01003443 int survey_idx = cb->args[1];
3444 int res;
3445
Johannes Berg67748892010-10-04 21:14:06 +02003446 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3447 if (res)
3448 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01003449
3450 if (!dev->ops->dump_survey) {
3451 res = -EOPNOTSUPP;
3452 goto out_err;
3453 }
3454
3455 while (1) {
3456 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3457 &survey);
3458 if (res == -ENOENT)
3459 break;
3460 if (res)
3461 goto out_err;
3462
3463 if (nl80211_send_survey(skb,
3464 NETLINK_CB(cb->skb).pid,
3465 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3466 netdev,
3467 &survey) < 0)
3468 goto out;
3469 survey_idx++;
3470 }
3471
3472 out:
3473 cb->args[1] = survey_idx;
3474 res = skb->len;
3475 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003476 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01003477 return res;
3478}
3479
Jouni Malinen255e7372009-03-20 21:21:17 +02003480static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3481{
Samuel Ortizb23aa672009-07-01 21:26:54 +02003482 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02003483}
3484
Samuel Ortizb23aa672009-07-01 21:26:54 +02003485static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3486{
3487 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3488 NL80211_WPA_VERSION_2));
3489}
3490
3491static bool nl80211_valid_akm_suite(u32 akm)
3492{
3493 return akm == WLAN_AKM_SUITE_8021X ||
3494 akm == WLAN_AKM_SUITE_PSK;
3495}
3496
3497static bool nl80211_valid_cipher_suite(u32 cipher)
3498{
3499 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3500 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3501 cipher == WLAN_CIPHER_SUITE_TKIP ||
3502 cipher == WLAN_CIPHER_SUITE_CCMP ||
3503 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3504}
3505
3506
Jouni Malinen636a5d32009-03-19 13:39:22 +02003507static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3508{
Johannes Berg4c476992010-10-04 21:36:35 +02003509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3510 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003511 struct ieee80211_channel *chan;
3512 const u8 *bssid, *ssid, *ie = NULL;
3513 int err, ssid_len, ie_len = 0;
3514 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02003515 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003516 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003517
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003518 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3519 return -EINVAL;
3520
3521 if (!info->attrs[NL80211_ATTR_MAC])
3522 return -EINVAL;
3523
Jouni Malinen17780922009-03-27 20:52:47 +02003524 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
3525 return -EINVAL;
3526
Johannes Berg19957bb2009-07-02 17:20:43 +02003527 if (!info->attrs[NL80211_ATTR_SSID])
3528 return -EINVAL;
3529
3530 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3531 return -EINVAL;
3532
Johannes Bergfffd0932009-07-08 14:22:54 +02003533 err = nl80211_parse_key(info, &key);
3534 if (err)
3535 return err;
3536
3537 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02003538 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3539 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003540 if (!key.p.key || !key.p.key_len)
3541 return -EINVAL;
3542 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
3543 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
3544 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
3545 key.p.key_len != WLAN_KEY_LEN_WEP104))
3546 return -EINVAL;
3547 if (key.idx > 4)
3548 return -EINVAL;
3549 } else {
3550 key.p.key_len = 0;
3551 key.p.key = NULL;
3552 }
3553
Johannes Bergafea0b72010-08-10 09:46:42 +02003554 if (key.idx >= 0) {
3555 int i;
3556 bool ok = false;
3557 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
3558 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
3559 ok = true;
3560 break;
3561 }
3562 }
Johannes Berg4c476992010-10-04 21:36:35 +02003563 if (!ok)
3564 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02003565 }
3566
Johannes Berg4c476992010-10-04 21:36:35 +02003567 if (!rdev->ops->auth)
3568 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003569
Johannes Berg074ac8d2010-09-16 14:58:22 +02003570 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3572 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003573
Johannes Berg19957bb2009-07-02 17:20:43 +02003574 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02003575 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02003576 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02003577 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3578 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003579
Johannes Berg19957bb2009-07-02 17:20:43 +02003580 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3581 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3582
3583 if (info->attrs[NL80211_ATTR_IE]) {
3584 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3585 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3586 }
3587
3588 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02003589 if (!nl80211_valid_auth_type(auth_type))
3590 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02003591
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003592 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3593
Johannes Berg4c476992010-10-04 21:36:35 +02003594 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
3595 ssid, ssid_len, ie, ie_len,
3596 key.p.key, key.p.key_len, key.idx,
3597 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003598}
3599
Johannes Bergc0692b82010-08-27 14:26:53 +03003600static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
3601 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02003602 struct cfg80211_crypto_settings *settings,
3603 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02003604{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02003605 memset(settings, 0, sizeof(*settings));
3606
Samuel Ortizb23aa672009-07-01 21:26:54 +02003607 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
3608
Johannes Bergc0692b82010-08-27 14:26:53 +03003609 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
3610 u16 proto;
3611 proto = nla_get_u16(
3612 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
3613 settings->control_port_ethertype = cpu_to_be16(proto);
3614 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
3615 proto != ETH_P_PAE)
3616 return -EINVAL;
3617 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
3618 settings->control_port_no_encrypt = true;
3619 } else
3620 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
3621
Samuel Ortizb23aa672009-07-01 21:26:54 +02003622 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
3623 void *data;
3624 int len, i;
3625
3626 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3627 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3628 settings->n_ciphers_pairwise = len / sizeof(u32);
3629
3630 if (len % sizeof(u32))
3631 return -EINVAL;
3632
Johannes Berg3dc27d22009-07-02 21:36:37 +02003633 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02003634 return -EINVAL;
3635
3636 memcpy(settings->ciphers_pairwise, data, len);
3637
3638 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3639 if (!nl80211_valid_cipher_suite(
3640 settings->ciphers_pairwise[i]))
3641 return -EINVAL;
3642 }
3643
3644 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
3645 settings->cipher_group =
3646 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
3647 if (!nl80211_valid_cipher_suite(settings->cipher_group))
3648 return -EINVAL;
3649 }
3650
3651 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
3652 settings->wpa_versions =
3653 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
3654 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
3655 return -EINVAL;
3656 }
3657
3658 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
3659 void *data;
3660 int len, i;
3661
3662 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
3663 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
3664 settings->n_akm_suites = len / sizeof(u32);
3665
3666 if (len % sizeof(u32))
3667 return -EINVAL;
3668
3669 memcpy(settings->akm_suites, data, len);
3670
3671 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3672 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
3673 return -EINVAL;
3674 }
3675
3676 return 0;
3677}
3678
Jouni Malinen636a5d32009-03-19 13:39:22 +02003679static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3680{
Johannes Berg4c476992010-10-04 21:36:35 +02003681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3682 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003683 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02003684 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02003685 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02003686 int err, ssid_len, ie_len = 0;
3687 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003688
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003689 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3690 return -EINVAL;
3691
3692 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02003693 !info->attrs[NL80211_ATTR_SSID] ||
3694 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003695 return -EINVAL;
3696
Johannes Berg4c476992010-10-04 21:36:35 +02003697 if (!rdev->ops->assoc)
3698 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003699
Johannes Berg074ac8d2010-09-16 14:58:22 +02003700 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003701 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3702 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003703
Johannes Berg19957bb2009-07-02 17:20:43 +02003704 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003705
Johannes Berg19957bb2009-07-02 17:20:43 +02003706 chan = ieee80211_get_channel(&rdev->wiphy,
3707 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02003708 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3709 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003710
Johannes Berg19957bb2009-07-02 17:20:43 +02003711 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3712 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003713
3714 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003715 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3716 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003717 }
3718
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003719 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02003720 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003721 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02003722 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02003723 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02003724 else if (mfp != NL80211_MFP_NO)
3725 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003726 }
3727
Johannes Berg3e5d7642009-07-07 14:37:26 +02003728 if (info->attrs[NL80211_ATTR_PREV_BSSID])
3729 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
3730
Johannes Bergc0692b82010-08-27 14:26:53 +03003731 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02003732 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02003733 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
3734 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02003735 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003736
Jouni Malinen636a5d32009-03-19 13:39:22 +02003737 return err;
3738}
3739
3740static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3741{
Johannes Berg4c476992010-10-04 21:36:35 +02003742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3743 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003744 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02003745 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02003746 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003747 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003748
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003749 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3750 return -EINVAL;
3751
3752 if (!info->attrs[NL80211_ATTR_MAC])
3753 return -EINVAL;
3754
3755 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3756 return -EINVAL;
3757
Johannes Berg4c476992010-10-04 21:36:35 +02003758 if (!rdev->ops->deauth)
3759 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003760
Johannes Berg074ac8d2010-09-16 14:58:22 +02003761 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003762 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3763 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003764
Johannes Berg19957bb2009-07-02 17:20:43 +02003765 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003766
Johannes Berg19957bb2009-07-02 17:20:43 +02003767 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3768 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003769 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02003770 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02003771 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003772
3773 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003774 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3775 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003776 }
3777
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003778 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3779
Johannes Berg4c476992010-10-04 21:36:35 +02003780 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
3781 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003782}
3783
3784static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3785{
Johannes Berg4c476992010-10-04 21:36:35 +02003786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3787 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003788 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02003789 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02003790 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003791 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003792
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003793 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3794 return -EINVAL;
3795
3796 if (!info->attrs[NL80211_ATTR_MAC])
3797 return -EINVAL;
3798
3799 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3800 return -EINVAL;
3801
Johannes Berg4c476992010-10-04 21:36:35 +02003802 if (!rdev->ops->disassoc)
3803 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003804
Johannes Berg074ac8d2010-09-16 14:58:22 +02003805 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003806 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3807 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003808
Johannes Berg19957bb2009-07-02 17:20:43 +02003809 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003810
Johannes Berg19957bb2009-07-02 17:20:43 +02003811 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3812 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003813 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02003814 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02003815 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003816
3817 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003818 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3819 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003820 }
3821
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003822 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3823
Johannes Berg4c476992010-10-04 21:36:35 +02003824 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
3825 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003826}
3827
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01003828static bool
3829nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
3830 int mcast_rate[IEEE80211_NUM_BANDS],
3831 int rateval)
3832{
3833 struct wiphy *wiphy = &rdev->wiphy;
3834 bool found = false;
3835 int band, i;
3836
3837 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3838 struct ieee80211_supported_band *sband;
3839
3840 sband = wiphy->bands[band];
3841 if (!sband)
3842 continue;
3843
3844 for (i = 0; i < sband->n_bitrates; i++) {
3845 if (sband->bitrates[i].bitrate == rateval) {
3846 mcast_rate[band] = i + 1;
3847 found = true;
3848 break;
3849 }
3850 }
3851 }
3852
3853 return found;
3854}
3855
Johannes Berg04a773a2009-04-19 21:24:32 +02003856static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3857{
Johannes Berg4c476992010-10-04 21:36:35 +02003858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3859 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02003860 struct cfg80211_ibss_params ibss;
3861 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02003862 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02003863 int err;
3864
Johannes Berg8e30bc52009-04-22 17:45:38 +02003865 memset(&ibss, 0, sizeof(ibss));
3866
Johannes Berg04a773a2009-04-19 21:24:32 +02003867 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3868 return -EINVAL;
3869
3870 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
3871 !info->attrs[NL80211_ATTR_SSID] ||
3872 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3873 return -EINVAL;
3874
Johannes Berg8e30bc52009-04-22 17:45:38 +02003875 ibss.beacon_interval = 100;
3876
3877 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
3878 ibss.beacon_interval =
3879 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3880 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
3881 return -EINVAL;
3882 }
3883
Johannes Berg4c476992010-10-04 21:36:35 +02003884 if (!rdev->ops->join_ibss)
3885 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003886
Johannes Berg4c476992010-10-04 21:36:35 +02003887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
3888 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003889
Johannes Berg79c97e92009-07-07 03:56:12 +02003890 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02003891
3892 if (info->attrs[NL80211_ATTR_MAC])
3893 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3894 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3895 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3896
3897 if (info->attrs[NL80211_ATTR_IE]) {
3898 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3899 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3900 }
3901
3902 ibss.channel = ieee80211_get_channel(wiphy,
3903 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3904 if (!ibss.channel ||
3905 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02003906 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
3907 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02003908
3909 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02003910 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02003911
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003912 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3913 u8 *rates =
3914 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3915 int n_rates =
3916 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3917 struct ieee80211_supported_band *sband =
3918 wiphy->bands[ibss.channel->band];
3919 int i, j;
3920
Johannes Berg4c476992010-10-04 21:36:35 +02003921 if (n_rates == 0)
3922 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003923
3924 for (i = 0; i < n_rates; i++) {
3925 int rate = (rates[i] & 0x7f) * 5;
3926 bool found = false;
3927
3928 for (j = 0; j < sband->n_bitrates; j++) {
3929 if (sband->bitrates[j].bitrate == rate) {
3930 found = true;
3931 ibss.basic_rates |= BIT(j);
3932 break;
3933 }
3934 }
Johannes Berg4c476992010-10-04 21:36:35 +02003935 if (!found)
3936 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003937 }
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003938 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01003939
3940 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
3941 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
3942 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
3943 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003944
Johannes Berg4c476992010-10-04 21:36:35 +02003945 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
3946 connkeys = nl80211_parse_connkeys(rdev,
3947 info->attrs[NL80211_ATTR_KEYS]);
3948 if (IS_ERR(connkeys))
3949 return PTR_ERR(connkeys);
3950 }
Johannes Berg04a773a2009-04-19 21:24:32 +02003951
Johannes Berg4c476992010-10-04 21:36:35 +02003952 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02003953 if (err)
3954 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02003955 return err;
3956}
3957
3958static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3959{
Johannes Berg4c476992010-10-04 21:36:35 +02003960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3961 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02003962
Johannes Berg4c476992010-10-04 21:36:35 +02003963 if (!rdev->ops->leave_ibss)
3964 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003965
Johannes Berg4c476992010-10-04 21:36:35 +02003966 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
3967 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003968
Johannes Berg4c476992010-10-04 21:36:35 +02003969 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02003970}
3971
Johannes Bergaff89a92009-07-01 21:26:51 +02003972#ifdef CONFIG_NL80211_TESTMODE
3973static struct genl_multicast_group nl80211_testmode_mcgrp = {
3974 .name = "testmode",
3975};
3976
3977static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
3978{
Johannes Berg4c476992010-10-04 21:36:35 +02003979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02003980 int err;
3981
3982 if (!info->attrs[NL80211_ATTR_TESTDATA])
3983 return -EINVAL;
3984
Johannes Bergaff89a92009-07-01 21:26:51 +02003985 err = -EOPNOTSUPP;
3986 if (rdev->ops->testmode_cmd) {
3987 rdev->testmode_info = info;
3988 err = rdev->ops->testmode_cmd(&rdev->wiphy,
3989 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
3990 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
3991 rdev->testmode_info = NULL;
3992 }
3993
Johannes Bergaff89a92009-07-01 21:26:51 +02003994 return err;
3995}
3996
3997static struct sk_buff *
3998__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
3999 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4000{
4001 struct sk_buff *skb;
4002 void *hdr;
4003 struct nlattr *data;
4004
4005 skb = nlmsg_new(approxlen + 100, gfp);
4006 if (!skb)
4007 return NULL;
4008
4009 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4010 if (!hdr) {
4011 kfree_skb(skb);
4012 return NULL;
4013 }
4014
4015 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4016 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4017
4018 ((void **)skb->cb)[0] = rdev;
4019 ((void **)skb->cb)[1] = hdr;
4020 ((void **)skb->cb)[2] = data;
4021
4022 return skb;
4023
4024 nla_put_failure:
4025 kfree_skb(skb);
4026 return NULL;
4027}
4028
4029struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4030 int approxlen)
4031{
4032 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4033
4034 if (WARN_ON(!rdev->testmode_info))
4035 return NULL;
4036
4037 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4038 rdev->testmode_info->snd_pid,
4039 rdev->testmode_info->snd_seq,
4040 GFP_KERNEL);
4041}
4042EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4043
4044int cfg80211_testmode_reply(struct sk_buff *skb)
4045{
4046 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4047 void *hdr = ((void **)skb->cb)[1];
4048 struct nlattr *data = ((void **)skb->cb)[2];
4049
4050 if (WARN_ON(!rdev->testmode_info)) {
4051 kfree_skb(skb);
4052 return -EINVAL;
4053 }
4054
4055 nla_nest_end(skb, data);
4056 genlmsg_end(skb, hdr);
4057 return genlmsg_reply(skb, rdev->testmode_info);
4058}
4059EXPORT_SYMBOL(cfg80211_testmode_reply);
4060
4061struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4062 int approxlen, gfp_t gfp)
4063{
4064 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4065
4066 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4067}
4068EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4069
4070void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4071{
4072 void *hdr = ((void **)skb->cb)[1];
4073 struct nlattr *data = ((void **)skb->cb)[2];
4074
4075 nla_nest_end(skb, data);
4076 genlmsg_end(skb, hdr);
4077 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4078}
4079EXPORT_SYMBOL(cfg80211_testmode_event);
4080#endif
4081
Samuel Ortizb23aa672009-07-01 21:26:54 +02004082static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4083{
Johannes Berg4c476992010-10-04 21:36:35 +02004084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4085 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004086 struct cfg80211_connect_params connect;
4087 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004088 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004089 int err;
4090
4091 memset(&connect, 0, sizeof(connect));
4092
4093 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4094 return -EINVAL;
4095
4096 if (!info->attrs[NL80211_ATTR_SSID] ||
4097 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4098 return -EINVAL;
4099
4100 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4101 connect.auth_type =
4102 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4103 if (!nl80211_valid_auth_type(connect.auth_type))
4104 return -EINVAL;
4105 } else
4106 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4107
4108 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4109
Johannes Bergc0692b82010-08-27 14:26:53 +03004110 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004111 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004112 if (err)
4113 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004114
Johannes Berg074ac8d2010-09-16 14:58:22 +02004115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004116 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4117 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004118
Johannes Berg79c97e92009-07-07 03:56:12 +02004119 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004120
Samuel Ortizb23aa672009-07-01 21:26:54 +02004121 if (info->attrs[NL80211_ATTR_MAC])
4122 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4123 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4124 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4125
4126 if (info->attrs[NL80211_ATTR_IE]) {
4127 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4128 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4129 }
4130
4131 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4132 connect.channel =
4133 ieee80211_get_channel(wiphy,
4134 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4135 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004136 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4137 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004138 }
4139
Johannes Bergfffd0932009-07-08 14:22:54 +02004140 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4141 connkeys = nl80211_parse_connkeys(rdev,
4142 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004143 if (IS_ERR(connkeys))
4144 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004145 }
4146
4147 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004148 if (err)
4149 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004150 return err;
4151}
4152
4153static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4154{
Johannes Berg4c476992010-10-04 21:36:35 +02004155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4156 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004157 u16 reason;
4158
4159 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4160 reason = WLAN_REASON_DEAUTH_LEAVING;
4161 else
4162 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4163
4164 if (reason == 0)
4165 return -EINVAL;
4166
Johannes Berg074ac8d2010-09-16 14:58:22 +02004167 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004168 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4169 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004170
Johannes Berg4c476992010-10-04 21:36:35 +02004171 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004172}
4173
Johannes Berg463d0182009-07-14 00:33:35 +02004174static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4175{
Johannes Berg4c476992010-10-04 21:36:35 +02004176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004177 struct net *net;
4178 int err;
4179 u32 pid;
4180
4181 if (!info->attrs[NL80211_ATTR_PID])
4182 return -EINVAL;
4183
4184 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4185
Johannes Berg463d0182009-07-14 00:33:35 +02004186 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004187 if (IS_ERR(net))
4188 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004189
4190 err = 0;
4191
4192 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004193 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4194 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004195
Johannes Berg463d0182009-07-14 00:33:35 +02004196 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004197 return err;
4198}
4199
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004200static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4201{
Johannes Berg4c476992010-10-04 21:36:35 +02004202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004203 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4204 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004205 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004206 struct cfg80211_pmksa pmksa;
4207
4208 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4209
4210 if (!info->attrs[NL80211_ATTR_MAC])
4211 return -EINVAL;
4212
4213 if (!info->attrs[NL80211_ATTR_PMKID])
4214 return -EINVAL;
4215
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004216 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4217 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4218
Johannes Berg074ac8d2010-09-16 14:58:22 +02004219 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004220 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4221 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004222
4223 switch (info->genlhdr->cmd) {
4224 case NL80211_CMD_SET_PMKSA:
4225 rdev_ops = rdev->ops->set_pmksa;
4226 break;
4227 case NL80211_CMD_DEL_PMKSA:
4228 rdev_ops = rdev->ops->del_pmksa;
4229 break;
4230 default:
4231 WARN_ON(1);
4232 break;
4233 }
4234
Johannes Berg4c476992010-10-04 21:36:35 +02004235 if (!rdev_ops)
4236 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004237
Johannes Berg4c476992010-10-04 21:36:35 +02004238 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004239}
4240
4241static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4242{
Johannes Berg4c476992010-10-04 21:36:35 +02004243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4244 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004245
Johannes Berg074ac8d2010-09-16 14:58:22 +02004246 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004247 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4248 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004249
Johannes Berg4c476992010-10-04 21:36:35 +02004250 if (!rdev->ops->flush_pmksa)
4251 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004252
Johannes Berg4c476992010-10-04 21:36:35 +02004253 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004254}
4255
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004256static int nl80211_remain_on_channel(struct sk_buff *skb,
4257 struct genl_info *info)
4258{
Johannes Berg4c476992010-10-04 21:36:35 +02004259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4260 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004261 struct ieee80211_channel *chan;
4262 struct sk_buff *msg;
4263 void *hdr;
4264 u64 cookie;
4265 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4266 u32 freq, duration;
4267 int err;
4268
4269 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4270 !info->attrs[NL80211_ATTR_DURATION])
4271 return -EINVAL;
4272
4273 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4274
4275 /*
4276 * We should be on that channel for at least one jiffie,
4277 * and more than 5 seconds seems excessive.
4278 */
Johannes Berga2939112010-12-14 17:54:28 +01004279 if (!duration || !msecs_to_jiffies(duration) ||
4280 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004281 return -EINVAL;
4282
Johannes Berg4c476992010-10-04 21:36:35 +02004283 if (!rdev->ops->remain_on_channel)
4284 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004285
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004286 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4287 channel_type = nla_get_u32(
4288 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4289 if (channel_type != NL80211_CHAN_NO_HT &&
4290 channel_type != NL80211_CHAN_HT20 &&
4291 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004292 channel_type != NL80211_CHAN_HT40MINUS)
4293 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004294 }
4295
4296 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4297 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004298 if (chan == NULL)
4299 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004300
4301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004302 if (!msg)
4303 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004304
4305 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4306 NL80211_CMD_REMAIN_ON_CHANNEL);
4307
4308 if (IS_ERR(hdr)) {
4309 err = PTR_ERR(hdr);
4310 goto free_msg;
4311 }
4312
4313 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4314 channel_type, duration, &cookie);
4315
4316 if (err)
4317 goto free_msg;
4318
4319 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4320
4321 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004322
4323 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004324
4325 nla_put_failure:
4326 err = -ENOBUFS;
4327 free_msg:
4328 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004329 return err;
4330}
4331
4332static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4333 struct genl_info *info)
4334{
Johannes Berg4c476992010-10-04 21:36:35 +02004335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4336 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004337 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004338
4339 if (!info->attrs[NL80211_ATTR_COOKIE])
4340 return -EINVAL;
4341
Johannes Berg4c476992010-10-04 21:36:35 +02004342 if (!rdev->ops->cancel_remain_on_channel)
4343 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004344
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004345 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4346
Johannes Berg4c476992010-10-04 21:36:35 +02004347 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004348}
4349
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004350static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4351 u8 *rates, u8 rates_len)
4352{
4353 u8 i;
4354 u32 mask = 0;
4355
4356 for (i = 0; i < rates_len; i++) {
4357 int rate = (rates[i] & 0x7f) * 5;
4358 int ridx;
4359 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4360 struct ieee80211_rate *srate =
4361 &sband->bitrates[ridx];
4362 if (rate == srate->bitrate) {
4363 mask |= 1 << ridx;
4364 break;
4365 }
4366 }
4367 if (ridx == sband->n_bitrates)
4368 return 0; /* rate not found */
4369 }
4370
4371 return mask;
4372}
4373
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004374static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004375 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4376 .len = NL80211_MAX_SUPP_RATES },
4377};
4378
4379static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4380 struct genl_info *info)
4381{
4382 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02004383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004384 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02004385 int rem, i;
4386 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004387 struct nlattr *tx_rates;
4388 struct ieee80211_supported_band *sband;
4389
4390 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4391 return -EINVAL;
4392
Johannes Berg4c476992010-10-04 21:36:35 +02004393 if (!rdev->ops->set_bitrate_mask)
4394 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004395
4396 memset(&mask, 0, sizeof(mask));
4397 /* Default to all rates enabled */
4398 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4399 sband = rdev->wiphy.bands[i];
4400 mask.control[i].legacy =
4401 sband ? (1 << sband->n_bitrates) - 1 : 0;
4402 }
4403
4404 /*
4405 * The nested attribute uses enum nl80211_band as the index. This maps
4406 * directly to the enum ieee80211_band values used in cfg80211.
4407 */
4408 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4409 {
4410 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02004411 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4412 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004413 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02004414 if (sband == NULL)
4415 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004416 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4417 nla_len(tx_rates), nl80211_txattr_policy);
4418 if (tb[NL80211_TXRATE_LEGACY]) {
4419 mask.control[band].legacy = rateset_to_mask(
4420 sband,
4421 nla_data(tb[NL80211_TXRATE_LEGACY]),
4422 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02004423 if (mask.control[band].legacy == 0)
4424 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004425 }
4426 }
4427
Johannes Berg4c476992010-10-04 21:36:35 +02004428 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004429}
4430
Johannes Berg2e161f72010-08-12 15:38:38 +02004431static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004432{
Johannes Berg4c476992010-10-04 21:36:35 +02004433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4434 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02004435 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02004436
4437 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4438 return -EINVAL;
4439
Johannes Berg2e161f72010-08-12 15:38:38 +02004440 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4441 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02004442
Johannes Berg9d38d852010-06-09 17:20:33 +02004443 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004444 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004445 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4446 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4447 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02004448 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4449 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004450
4451 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02004452 if (!rdev->ops->mgmt_tx)
4453 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004454
Johannes Berg4c476992010-10-04 21:36:35 +02004455 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02004456 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02004457 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4458 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02004459}
4460
Johannes Berg2e161f72010-08-12 15:38:38 +02004461static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004462{
Johannes Berg4c476992010-10-04 21:36:35 +02004463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4464 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02004465 struct ieee80211_channel *chan;
4466 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02004467 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02004468 u32 freq;
4469 int err;
4470 void *hdr;
4471 u64 cookie;
4472 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004473 unsigned int wait = 0;
4474 bool offchan;
Jouni Malinen026331c2010-02-15 12:53:10 +02004475
4476 if (!info->attrs[NL80211_ATTR_FRAME] ||
4477 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4478 return -EINVAL;
4479
Johannes Berg4c476992010-10-04 21:36:35 +02004480 if (!rdev->ops->mgmt_tx)
4481 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004482
Johannes Berg9d38d852010-06-09 17:20:33 +02004483 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004484 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004485 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4486 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4487 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02004488 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4489 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004490
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004491 if (info->attrs[NL80211_ATTR_DURATION]) {
4492 if (!rdev->ops->mgmt_tx_cancel_wait)
4493 return -EINVAL;
4494 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4495 }
4496
Jouni Malinen026331c2010-02-15 12:53:10 +02004497 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4498 channel_type = nla_get_u32(
4499 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4500 if (channel_type != NL80211_CHAN_NO_HT &&
4501 channel_type != NL80211_CHAN_HT20 &&
4502 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004503 channel_type != NL80211_CHAN_HT40MINUS)
4504 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02004505 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02004506 }
4507
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004508 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
4509
Jouni Malinen026331c2010-02-15 12:53:10 +02004510 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4511 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004512 if (chan == NULL)
4513 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02004514
4515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004516 if (!msg)
4517 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02004518
4519 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02004520 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02004521
4522 if (IS_ERR(hdr)) {
4523 err = PTR_ERR(hdr);
4524 goto free_msg;
4525 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004526 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
4527 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02004528 nla_data(info->attrs[NL80211_ATTR_FRAME]),
4529 nla_len(info->attrs[NL80211_ATTR_FRAME]),
4530 &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02004531 if (err)
4532 goto free_msg;
4533
4534 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4535
4536 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004537 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02004538
4539 nla_put_failure:
4540 err = -ENOBUFS;
4541 free_msg:
4542 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02004543 return err;
4544}
4545
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004546static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
4547{
4548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4549 struct net_device *dev = info->user_ptr[1];
4550 u64 cookie;
4551
4552 if (!info->attrs[NL80211_ATTR_COOKIE])
4553 return -EINVAL;
4554
4555 if (!rdev->ops->mgmt_tx_cancel_wait)
4556 return -EOPNOTSUPP;
4557
4558 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4559 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
4560 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4561 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4562 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4563 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4564 return -EOPNOTSUPP;
4565
4566 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4567
4568 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
4569}
4570
Kalle Valoffb9eb32010-02-17 17:58:10 +02004571static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
4572{
Johannes Berg4c476992010-10-04 21:36:35 +02004573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004574 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004575 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004576 u8 ps_state;
4577 bool state;
4578 int err;
4579
Johannes Berg4c476992010-10-04 21:36:35 +02004580 if (!info->attrs[NL80211_ATTR_PS_STATE])
4581 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004582
4583 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
4584
Johannes Berg4c476992010-10-04 21:36:35 +02004585 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
4586 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004587
4588 wdev = dev->ieee80211_ptr;
4589
Johannes Berg4c476992010-10-04 21:36:35 +02004590 if (!rdev->ops->set_power_mgmt)
4591 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004592
4593 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
4594
4595 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02004596 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004597
Johannes Berg4c476992010-10-04 21:36:35 +02004598 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
4599 wdev->ps_timeout);
4600 if (!err)
4601 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004602 return err;
4603}
4604
4605static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
4606{
Johannes Berg4c476992010-10-04 21:36:35 +02004607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004608 enum nl80211_ps_state ps_state;
4609 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004610 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004611 struct sk_buff *msg;
4612 void *hdr;
4613 int err;
4614
Kalle Valoffb9eb32010-02-17 17:58:10 +02004615 wdev = dev->ieee80211_ptr;
4616
Johannes Berg4c476992010-10-04 21:36:35 +02004617 if (!rdev->ops->set_power_mgmt)
4618 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004619
4620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004621 if (!msg)
4622 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004623
4624 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4625 NL80211_CMD_GET_POWER_SAVE);
4626 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02004627 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004628 goto free_msg;
4629 }
4630
4631 if (wdev->ps)
4632 ps_state = NL80211_PS_ENABLED;
4633 else
4634 ps_state = NL80211_PS_DISABLED;
4635
4636 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
4637
4638 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004639 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02004640
Johannes Berg4c476992010-10-04 21:36:35 +02004641 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02004642 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02004643 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02004644 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02004645 return err;
4646}
4647
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004648static struct nla_policy
4649nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
4650 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
4651 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
4652 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
4653};
4654
4655static int nl80211_set_cqm_rssi(struct genl_info *info,
4656 s32 threshold, u32 hysteresis)
4657{
Johannes Berg4c476992010-10-04 21:36:35 +02004658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004659 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004660 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004661
4662 if (threshold > 0)
4663 return -EINVAL;
4664
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004665 wdev = dev->ieee80211_ptr;
4666
Johannes Berg4c476992010-10-04 21:36:35 +02004667 if (!rdev->ops->set_cqm_rssi_config)
4668 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004669
Johannes Berg074ac8d2010-09-16 14:58:22 +02004670 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004671 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
4672 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004673
Johannes Berg4c476992010-10-04 21:36:35 +02004674 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
4675 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004676}
4677
4678static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
4679{
4680 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
4681 struct nlattr *cqm;
4682 int err;
4683
4684 cqm = info->attrs[NL80211_ATTR_CQM];
4685 if (!cqm) {
4686 err = -EINVAL;
4687 goto out;
4688 }
4689
4690 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
4691 nl80211_attr_cqm_policy);
4692 if (err)
4693 goto out;
4694
4695 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
4696 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
4697 s32 threshold;
4698 u32 hysteresis;
4699 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
4700 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
4701 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
4702 } else
4703 err = -EINVAL;
4704
4705out:
4706 return err;
4707}
4708
Johannes Berg29cbe682010-12-03 09:20:44 +01004709static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
4710{
4711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4712 struct net_device *dev = info->user_ptr[1];
4713 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08004714 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01004715 int err;
4716
4717 /* start with default */
4718 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08004719 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01004720
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004721 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01004722 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004723 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01004724 if (err)
4725 return err;
4726 }
4727
4728 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
4729 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
4730 return -EINVAL;
4731
Javier Cardonac80d5452010-12-16 17:37:49 -08004732 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
4733 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4734
4735 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
4736 /* parse additional setup parameters if given */
4737 err = nl80211_parse_mesh_setup(info, &setup);
4738 if (err)
4739 return err;
4740 }
4741
4742 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004743}
4744
4745static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
4746{
4747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4748 struct net_device *dev = info->user_ptr[1];
4749
4750 return cfg80211_leave_mesh(rdev, dev);
4751}
4752
Johannes Berg4c476992010-10-04 21:36:35 +02004753#define NL80211_FLAG_NEED_WIPHY 0x01
4754#define NL80211_FLAG_NEED_NETDEV 0x02
4755#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02004756#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
4757#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
4758 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02004759
4760static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
4761 struct genl_info *info)
4762{
4763 struct cfg80211_registered_device *rdev;
4764 struct net_device *dev;
4765 int err;
4766 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
4767
4768 if (rtnl)
4769 rtnl_lock();
4770
4771 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
4772 rdev = cfg80211_get_dev_from_info(info);
4773 if (IS_ERR(rdev)) {
4774 if (rtnl)
4775 rtnl_unlock();
4776 return PTR_ERR(rdev);
4777 }
4778 info->user_ptr[0] = rdev;
4779 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
4780 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4781 if (err) {
4782 if (rtnl)
4783 rtnl_unlock();
4784 return err;
4785 }
Johannes Berg41265712010-10-04 21:14:05 +02004786 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
4787 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02004788 cfg80211_unlock_rdev(rdev);
4789 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02004790 if (rtnl)
4791 rtnl_unlock();
4792 return -ENETDOWN;
4793 }
Johannes Berg4c476992010-10-04 21:36:35 +02004794 info->user_ptr[0] = rdev;
4795 info->user_ptr[1] = dev;
4796 }
4797
4798 return 0;
4799}
4800
4801static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
4802 struct genl_info *info)
4803{
4804 if (info->user_ptr[0])
4805 cfg80211_unlock_rdev(info->user_ptr[0]);
4806 if (info->user_ptr[1])
4807 dev_put(info->user_ptr[1]);
4808 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
4809 rtnl_unlock();
4810}
4811
Johannes Berg55682962007-09-20 13:09:35 -04004812static struct genl_ops nl80211_ops[] = {
4813 {
4814 .cmd = NL80211_CMD_GET_WIPHY,
4815 .doit = nl80211_get_wiphy,
4816 .dumpit = nl80211_dump_wiphy,
4817 .policy = nl80211_policy,
4818 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004819 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04004820 },
4821 {
4822 .cmd = NL80211_CMD_SET_WIPHY,
4823 .doit = nl80211_set_wiphy,
4824 .policy = nl80211_policy,
4825 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004826 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004827 },
4828 {
4829 .cmd = NL80211_CMD_GET_INTERFACE,
4830 .doit = nl80211_get_interface,
4831 .dumpit = nl80211_dump_interface,
4832 .policy = nl80211_policy,
4833 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004834 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04004835 },
4836 {
4837 .cmd = NL80211_CMD_SET_INTERFACE,
4838 .doit = nl80211_set_interface,
4839 .policy = nl80211_policy,
4840 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004841 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4842 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004843 },
4844 {
4845 .cmd = NL80211_CMD_NEW_INTERFACE,
4846 .doit = nl80211_new_interface,
4847 .policy = nl80211_policy,
4848 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004849 .internal_flags = NL80211_FLAG_NEED_WIPHY |
4850 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004851 },
4852 {
4853 .cmd = NL80211_CMD_DEL_INTERFACE,
4854 .doit = nl80211_del_interface,
4855 .policy = nl80211_policy,
4856 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004857 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4858 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004859 },
Johannes Berg41ade002007-12-19 02:03:29 +01004860 {
4861 .cmd = NL80211_CMD_GET_KEY,
4862 .doit = nl80211_get_key,
4863 .policy = nl80211_policy,
4864 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004865 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4866 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004867 },
4868 {
4869 .cmd = NL80211_CMD_SET_KEY,
4870 .doit = nl80211_set_key,
4871 .policy = nl80211_policy,
4872 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004874 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004875 },
4876 {
4877 .cmd = NL80211_CMD_NEW_KEY,
4878 .doit = nl80211_new_key,
4879 .policy = nl80211_policy,
4880 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004882 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004883 },
4884 {
4885 .cmd = NL80211_CMD_DEL_KEY,
4886 .doit = nl80211_del_key,
4887 .policy = nl80211_policy,
4888 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004890 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004891 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01004892 {
4893 .cmd = NL80211_CMD_SET_BEACON,
4894 .policy = nl80211_policy,
4895 .flags = GENL_ADMIN_PERM,
4896 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4898 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004899 },
4900 {
4901 .cmd = NL80211_CMD_NEW_BEACON,
4902 .policy = nl80211_policy,
4903 .flags = GENL_ADMIN_PERM,
4904 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004905 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4906 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004907 },
4908 {
4909 .cmd = NL80211_CMD_DEL_BEACON,
4910 .policy = nl80211_policy,
4911 .flags = GENL_ADMIN_PERM,
4912 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004913 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4914 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004915 },
Johannes Berg5727ef12007-12-19 02:03:34 +01004916 {
4917 .cmd = NL80211_CMD_GET_STATION,
4918 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004919 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01004920 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02004921 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4922 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004923 },
4924 {
4925 .cmd = NL80211_CMD_SET_STATION,
4926 .doit = nl80211_set_station,
4927 .policy = nl80211_policy,
4928 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004929 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4930 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004931 },
4932 {
4933 .cmd = NL80211_CMD_NEW_STATION,
4934 .doit = nl80211_new_station,
4935 .policy = nl80211_policy,
4936 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004938 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004939 },
4940 {
4941 .cmd = NL80211_CMD_DEL_STATION,
4942 .doit = nl80211_del_station,
4943 .policy = nl80211_policy,
4944 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004945 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4946 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004947 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004948 {
4949 .cmd = NL80211_CMD_GET_MPATH,
4950 .doit = nl80211_get_mpath,
4951 .dumpit = nl80211_dump_mpath,
4952 .policy = nl80211_policy,
4953 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004955 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004956 },
4957 {
4958 .cmd = NL80211_CMD_SET_MPATH,
4959 .doit = nl80211_set_mpath,
4960 .policy = nl80211_policy,
4961 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004963 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004964 },
4965 {
4966 .cmd = NL80211_CMD_NEW_MPATH,
4967 .doit = nl80211_new_mpath,
4968 .policy = nl80211_policy,
4969 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004971 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004972 },
4973 {
4974 .cmd = NL80211_CMD_DEL_MPATH,
4975 .doit = nl80211_del_mpath,
4976 .policy = nl80211_policy,
4977 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004978 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4979 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004980 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004981 {
4982 .cmd = NL80211_CMD_SET_BSS,
4983 .doit = nl80211_set_bss,
4984 .policy = nl80211_policy,
4985 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004986 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4987 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004988 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004989 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004990 .cmd = NL80211_CMD_GET_REG,
4991 .doit = nl80211_get_reg,
4992 .policy = nl80211_policy,
4993 /* can be retrieved by unprivileged users */
4994 },
4995 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004996 .cmd = NL80211_CMD_SET_REG,
4997 .doit = nl80211_set_reg,
4998 .policy = nl80211_policy,
4999 .flags = GENL_ADMIN_PERM,
5000 },
5001 {
5002 .cmd = NL80211_CMD_REQ_SET_REG,
5003 .doit = nl80211_req_set_reg,
5004 .policy = nl80211_policy,
5005 .flags = GENL_ADMIN_PERM,
5006 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005007 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005008 .cmd = NL80211_CMD_GET_MESH_CONFIG,
5009 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005010 .policy = nl80211_policy,
5011 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005012 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5013 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005014 },
5015 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005016 .cmd = NL80211_CMD_SET_MESH_CONFIG,
5017 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005018 .policy = nl80211_policy,
5019 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01005020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005021 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005022 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02005023 {
Johannes Berg2a519312009-02-10 21:25:55 +01005024 .cmd = NL80211_CMD_TRIGGER_SCAN,
5025 .doit = nl80211_trigger_scan,
5026 .policy = nl80211_policy,
5027 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005028 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005029 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01005030 },
5031 {
5032 .cmd = NL80211_CMD_GET_SCAN,
5033 .policy = nl80211_policy,
5034 .dumpit = nl80211_dump_scan,
5035 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02005036 {
5037 .cmd = NL80211_CMD_AUTHENTICATE,
5038 .doit = nl80211_authenticate,
5039 .policy = nl80211_policy,
5040 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005042 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005043 },
5044 {
5045 .cmd = NL80211_CMD_ASSOCIATE,
5046 .doit = nl80211_associate,
5047 .policy = nl80211_policy,
5048 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005050 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005051 },
5052 {
5053 .cmd = NL80211_CMD_DEAUTHENTICATE,
5054 .doit = nl80211_deauthenticate,
5055 .policy = nl80211_policy,
5056 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005058 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005059 },
5060 {
5061 .cmd = NL80211_CMD_DISASSOCIATE,
5062 .doit = nl80211_disassociate,
5063 .policy = nl80211_policy,
5064 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005066 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005067 },
Johannes Berg04a773a2009-04-19 21:24:32 +02005068 {
5069 .cmd = NL80211_CMD_JOIN_IBSS,
5070 .doit = nl80211_join_ibss,
5071 .policy = nl80211_policy,
5072 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005074 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005075 },
5076 {
5077 .cmd = NL80211_CMD_LEAVE_IBSS,
5078 .doit = nl80211_leave_ibss,
5079 .policy = nl80211_policy,
5080 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005081 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005082 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005083 },
Johannes Bergaff89a92009-07-01 21:26:51 +02005084#ifdef CONFIG_NL80211_TESTMODE
5085 {
5086 .cmd = NL80211_CMD_TESTMODE,
5087 .doit = nl80211_testmode_do,
5088 .policy = nl80211_policy,
5089 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005090 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5091 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02005092 },
5093#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02005094 {
5095 .cmd = NL80211_CMD_CONNECT,
5096 .doit = nl80211_connect,
5097 .policy = nl80211_policy,
5098 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005099 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005100 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005101 },
5102 {
5103 .cmd = NL80211_CMD_DISCONNECT,
5104 .doit = nl80211_disconnect,
5105 .policy = nl80211_policy,
5106 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005107 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005108 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005109 },
Johannes Berg463d0182009-07-14 00:33:35 +02005110 {
5111 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
5112 .doit = nl80211_wiphy_netns,
5113 .policy = nl80211_policy,
5114 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005115 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5116 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02005117 },
Holger Schurig61fa7132009-11-11 12:25:40 +01005118 {
5119 .cmd = NL80211_CMD_GET_SURVEY,
5120 .policy = nl80211_policy,
5121 .dumpit = nl80211_dump_survey,
5122 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005123 {
5124 .cmd = NL80211_CMD_SET_PMKSA,
5125 .doit = nl80211_setdel_pmksa,
5126 .policy = nl80211_policy,
5127 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005128 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5129 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005130 },
5131 {
5132 .cmd = NL80211_CMD_DEL_PMKSA,
5133 .doit = nl80211_setdel_pmksa,
5134 .policy = nl80211_policy,
5135 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005136 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5137 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005138 },
5139 {
5140 .cmd = NL80211_CMD_FLUSH_PMKSA,
5141 .doit = nl80211_flush_pmksa,
5142 .policy = nl80211_policy,
5143 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005144 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5145 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005146 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005147 {
5148 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5149 .doit = nl80211_remain_on_channel,
5150 .policy = nl80211_policy,
5151 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005153 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005154 },
5155 {
5156 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5157 .doit = nl80211_cancel_remain_on_channel,
5158 .policy = nl80211_policy,
5159 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005161 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005162 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005163 {
5164 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5165 .doit = nl80211_set_tx_bitrate_mask,
5166 .policy = nl80211_policy,
5167 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005168 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5169 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005170 },
Jouni Malinen026331c2010-02-15 12:53:10 +02005171 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005172 .cmd = NL80211_CMD_REGISTER_FRAME,
5173 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005174 .policy = nl80211_policy,
5175 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005176 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5177 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005178 },
5179 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005180 .cmd = NL80211_CMD_FRAME,
5181 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005182 .policy = nl80211_policy,
5183 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005185 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005186 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02005187 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005188 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
5189 .doit = nl80211_tx_mgmt_cancel_wait,
5190 .policy = nl80211_policy,
5191 .flags = GENL_ADMIN_PERM,
5192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5193 NL80211_FLAG_NEED_RTNL,
5194 },
5195 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02005196 .cmd = NL80211_CMD_SET_POWER_SAVE,
5197 .doit = nl80211_set_power_save,
5198 .policy = nl80211_policy,
5199 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005200 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5201 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02005202 },
5203 {
5204 .cmd = NL80211_CMD_GET_POWER_SAVE,
5205 .doit = nl80211_get_power_save,
5206 .policy = nl80211_policy,
5207 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005208 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5209 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02005210 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005211 {
5212 .cmd = NL80211_CMD_SET_CQM,
5213 .doit = nl80211_set_cqm,
5214 .policy = nl80211_policy,
5215 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005216 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5217 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005218 },
Johannes Bergf444de02010-05-05 15:25:02 +02005219 {
5220 .cmd = NL80211_CMD_SET_CHANNEL,
5221 .doit = nl80211_set_channel,
5222 .policy = nl80211_policy,
5223 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005224 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5225 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02005226 },
Bill Jordane8347eb2010-10-01 13:54:28 -04005227 {
5228 .cmd = NL80211_CMD_SET_WDS_PEER,
5229 .doit = nl80211_set_wds_peer,
5230 .policy = nl80211_policy,
5231 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02005232 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5233 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04005234 },
Johannes Berg29cbe682010-12-03 09:20:44 +01005235 {
5236 .cmd = NL80211_CMD_JOIN_MESH,
5237 .doit = nl80211_join_mesh,
5238 .policy = nl80211_policy,
5239 .flags = GENL_ADMIN_PERM,
5240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5241 NL80211_FLAG_NEED_RTNL,
5242 },
5243 {
5244 .cmd = NL80211_CMD_LEAVE_MESH,
5245 .doit = nl80211_leave_mesh,
5246 .policy = nl80211_policy,
5247 .flags = GENL_ADMIN_PERM,
5248 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5249 NL80211_FLAG_NEED_RTNL,
5250 },
Johannes Berg55682962007-09-20 13:09:35 -04005251};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005252
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005253static struct genl_multicast_group nl80211_mlme_mcgrp = {
5254 .name = "mlme",
5255};
Johannes Berg55682962007-09-20 13:09:35 -04005256
5257/* multicast groups */
5258static struct genl_multicast_group nl80211_config_mcgrp = {
5259 .name = "config",
5260};
Johannes Berg2a519312009-02-10 21:25:55 +01005261static struct genl_multicast_group nl80211_scan_mcgrp = {
5262 .name = "scan",
5263};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005264static struct genl_multicast_group nl80211_regulatory_mcgrp = {
5265 .name = "regulatory",
5266};
Johannes Berg55682962007-09-20 13:09:35 -04005267
5268/* notification functions */
5269
5270void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
5271{
5272 struct sk_buff *msg;
5273
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005274 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04005275 if (!msg)
5276 return;
5277
5278 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
5279 nlmsg_free(msg);
5280 return;
5281 }
5282
Johannes Berg463d0182009-07-14 00:33:35 +02005283 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5284 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04005285}
5286
Johannes Berg362a4152009-05-24 16:43:15 +02005287static int nl80211_add_scan_req(struct sk_buff *msg,
5288 struct cfg80211_registered_device *rdev)
5289{
5290 struct cfg80211_scan_request *req = rdev->scan_req;
5291 struct nlattr *nest;
5292 int i;
5293
Johannes Berg667503d2009-07-07 03:56:11 +02005294 ASSERT_RDEV_LOCK(rdev);
5295
Johannes Berg362a4152009-05-24 16:43:15 +02005296 if (WARN_ON(!req))
5297 return 0;
5298
5299 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
5300 if (!nest)
5301 goto nla_put_failure;
5302 for (i = 0; i < req->n_ssids; i++)
5303 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
5304 nla_nest_end(msg, nest);
5305
5306 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
5307 if (!nest)
5308 goto nla_put_failure;
5309 for (i = 0; i < req->n_channels; i++)
5310 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
5311 nla_nest_end(msg, nest);
5312
5313 if (req->ie)
5314 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
5315
5316 return 0;
5317 nla_put_failure:
5318 return -ENOBUFS;
5319}
5320
Johannes Berga538e2d2009-06-16 19:56:42 +02005321static int nl80211_send_scan_msg(struct sk_buff *msg,
5322 struct cfg80211_registered_device *rdev,
5323 struct net_device *netdev,
5324 u32 pid, u32 seq, int flags,
5325 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01005326{
5327 void *hdr;
5328
5329 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
5330 if (!hdr)
5331 return -1;
5332
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05005333 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01005334 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5335
Johannes Berg362a4152009-05-24 16:43:15 +02005336 /* ignore errors and send incomplete event anyway */
5337 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005338
5339 return genlmsg_end(msg, hdr);
5340
5341 nla_put_failure:
5342 genlmsg_cancel(msg, hdr);
5343 return -EMSGSIZE;
5344}
5345
Johannes Berga538e2d2009-06-16 19:56:42 +02005346void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
5347 struct net_device *netdev)
5348{
5349 struct sk_buff *msg;
5350
5351 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
5352 if (!msg)
5353 return;
5354
5355 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
5356 NL80211_CMD_TRIGGER_SCAN) < 0) {
5357 nlmsg_free(msg);
5358 return;
5359 }
5360
Johannes Berg463d0182009-07-14 00:33:35 +02005361 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5362 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02005363}
5364
Johannes Berg2a519312009-02-10 21:25:55 +01005365void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
5366 struct net_device *netdev)
5367{
5368 struct sk_buff *msg;
5369
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005371 if (!msg)
5372 return;
5373
Johannes Berga538e2d2009-06-16 19:56:42 +02005374 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
5375 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005376 nlmsg_free(msg);
5377 return;
5378 }
5379
Johannes Berg463d0182009-07-14 00:33:35 +02005380 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5381 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005382}
5383
5384void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
5385 struct net_device *netdev)
5386{
5387 struct sk_buff *msg;
5388
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005390 if (!msg)
5391 return;
5392
Johannes Berga538e2d2009-06-16 19:56:42 +02005393 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
5394 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005395 nlmsg_free(msg);
5396 return;
5397 }
5398
Johannes Berg463d0182009-07-14 00:33:35 +02005399 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5400 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005401}
5402
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005403/*
5404 * This can happen on global regulatory changes or device specific settings
5405 * based on custom world regulatory domains.
5406 */
5407void nl80211_send_reg_change_event(struct regulatory_request *request)
5408{
5409 struct sk_buff *msg;
5410 void *hdr;
5411
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005413 if (!msg)
5414 return;
5415
5416 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
5417 if (!hdr) {
5418 nlmsg_free(msg);
5419 return;
5420 }
5421
5422 /* Userspace can always count this one always being set */
5423 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
5424
5425 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
5426 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5427 NL80211_REGDOM_TYPE_WORLD);
5428 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
5429 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5430 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
5431 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
5432 request->intersect)
5433 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5434 NL80211_REGDOM_TYPE_INTERSECTION);
5435 else {
5436 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5437 NL80211_REGDOM_TYPE_COUNTRY);
5438 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
5439 }
5440
5441 if (wiphy_idx_valid(request->wiphy_idx))
5442 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
5443
5444 if (genlmsg_end(msg, hdr) < 0) {
5445 nlmsg_free(msg);
5446 return;
5447 }
5448
Johannes Bergbc43b282009-07-25 10:54:13 +02005449 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02005450 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02005451 GFP_ATOMIC);
5452 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005453
5454 return;
5455
5456nla_put_failure:
5457 genlmsg_cancel(msg, hdr);
5458 nlmsg_free(msg);
5459}
5460
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005461static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
5462 struct net_device *netdev,
5463 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005464 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005465{
5466 struct sk_buff *msg;
5467 void *hdr;
5468
Johannes Berge6d6e342009-07-01 21:26:47 +02005469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005470 if (!msg)
5471 return;
5472
5473 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5474 if (!hdr) {
5475 nlmsg_free(msg);
5476 return;
5477 }
5478
5479 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5480 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5481 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5482
5483 if (genlmsg_end(msg, hdr) < 0) {
5484 nlmsg_free(msg);
5485 return;
5486 }
5487
Johannes Berg463d0182009-07-14 00:33:35 +02005488 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5489 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005490 return;
5491
5492 nla_put_failure:
5493 genlmsg_cancel(msg, hdr);
5494 nlmsg_free(msg);
5495}
5496
5497void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005498 struct net_device *netdev, const u8 *buf,
5499 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005500{
5501 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005502 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005503}
5504
5505void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
5506 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02005507 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005508{
Johannes Berge6d6e342009-07-01 21:26:47 +02005509 nl80211_send_mlme_event(rdev, netdev, buf, len,
5510 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005511}
5512
Jouni Malinen53b46b82009-03-27 20:53:56 +02005513void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005514 struct net_device *netdev, const u8 *buf,
5515 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005516{
5517 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005518 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005519}
5520
Jouni Malinen53b46b82009-03-27 20:53:56 +02005521void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
5522 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02005523 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005524{
5525 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005526 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005527}
5528
Jouni Malinencf4e5942010-12-16 00:52:40 +02005529void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
5530 struct net_device *netdev, const u8 *buf,
5531 size_t len, gfp_t gfp)
5532{
5533 nl80211_send_mlme_event(rdev, netdev, buf, len,
5534 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
5535}
5536
5537void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
5538 struct net_device *netdev, const u8 *buf,
5539 size_t len, gfp_t gfp)
5540{
5541 nl80211_send_mlme_event(rdev, netdev, buf, len,
5542 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
5543}
5544
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04005545static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
5546 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02005547 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005548{
5549 struct sk_buff *msg;
5550 void *hdr;
5551
Johannes Berge6d6e342009-07-01 21:26:47 +02005552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005553 if (!msg)
5554 return;
5555
5556 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5557 if (!hdr) {
5558 nlmsg_free(msg);
5559 return;
5560 }
5561
5562 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5563 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5564 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
5565 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
5566
5567 if (genlmsg_end(msg, hdr) < 0) {
5568 nlmsg_free(msg);
5569 return;
5570 }
5571
Johannes Berg463d0182009-07-14 00:33:35 +02005572 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5573 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005574 return;
5575
5576 nla_put_failure:
5577 genlmsg_cancel(msg, hdr);
5578 nlmsg_free(msg);
5579}
5580
5581void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005582 struct net_device *netdev, const u8 *addr,
5583 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005584{
5585 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02005586 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005587}
5588
5589void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005590 struct net_device *netdev, const u8 *addr,
5591 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005592{
Johannes Berge6d6e342009-07-01 21:26:47 +02005593 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
5594 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005595}
5596
Samuel Ortizb23aa672009-07-01 21:26:54 +02005597void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
5598 struct net_device *netdev, const u8 *bssid,
5599 const u8 *req_ie, size_t req_ie_len,
5600 const u8 *resp_ie, size_t resp_ie_len,
5601 u16 status, gfp_t gfp)
5602{
5603 struct sk_buff *msg;
5604 void *hdr;
5605
5606 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5607 if (!msg)
5608 return;
5609
5610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
5611 if (!hdr) {
5612 nlmsg_free(msg);
5613 return;
5614 }
5615
5616 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5617 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5618 if (bssid)
5619 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5620 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
5621 if (req_ie)
5622 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
5623 if (resp_ie)
5624 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
5625
5626 if (genlmsg_end(msg, hdr) < 0) {
5627 nlmsg_free(msg);
5628 return;
5629 }
5630
Johannes Berg463d0182009-07-14 00:33:35 +02005631 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5632 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005633 return;
5634
5635 nla_put_failure:
5636 genlmsg_cancel(msg, hdr);
5637 nlmsg_free(msg);
5638
5639}
5640
5641void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
5642 struct net_device *netdev, const u8 *bssid,
5643 const u8 *req_ie, size_t req_ie_len,
5644 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
5645{
5646 struct sk_buff *msg;
5647 void *hdr;
5648
5649 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5650 if (!msg)
5651 return;
5652
5653 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
5654 if (!hdr) {
5655 nlmsg_free(msg);
5656 return;
5657 }
5658
5659 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5660 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5661 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5662 if (req_ie)
5663 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
5664 if (resp_ie)
5665 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
5666
5667 if (genlmsg_end(msg, hdr) < 0) {
5668 nlmsg_free(msg);
5669 return;
5670 }
5671
Johannes Berg463d0182009-07-14 00:33:35 +02005672 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5673 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005674 return;
5675
5676 nla_put_failure:
5677 genlmsg_cancel(msg, hdr);
5678 nlmsg_free(msg);
5679
5680}
5681
5682void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
5683 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02005684 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005685{
5686 struct sk_buff *msg;
5687 void *hdr;
5688
Johannes Berg667503d2009-07-07 03:56:11 +02005689 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005690 if (!msg)
5691 return;
5692
5693 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
5694 if (!hdr) {
5695 nlmsg_free(msg);
5696 return;
5697 }
5698
5699 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5700 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5701 if (from_ap && reason)
5702 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
5703 if (from_ap)
5704 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
5705 if (ie)
5706 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
5707
5708 if (genlmsg_end(msg, hdr) < 0) {
5709 nlmsg_free(msg);
5710 return;
5711 }
5712
Johannes Berg463d0182009-07-14 00:33:35 +02005713 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5714 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005715 return;
5716
5717 nla_put_failure:
5718 genlmsg_cancel(msg, hdr);
5719 nlmsg_free(msg);
5720
5721}
5722
Johannes Berg04a773a2009-04-19 21:24:32 +02005723void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
5724 struct net_device *netdev, const u8 *bssid,
5725 gfp_t gfp)
5726{
5727 struct sk_buff *msg;
5728 void *hdr;
5729
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02005731 if (!msg)
5732 return;
5733
5734 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
5735 if (!hdr) {
5736 nlmsg_free(msg);
5737 return;
5738 }
5739
5740 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5741 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5742 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5743
5744 if (genlmsg_end(msg, hdr) < 0) {
5745 nlmsg_free(msg);
5746 return;
5747 }
5748
Johannes Berg463d0182009-07-14 00:33:35 +02005749 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5750 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02005751 return;
5752
5753 nla_put_failure:
5754 genlmsg_cancel(msg, hdr);
5755 nlmsg_free(msg);
5756}
5757
Jouni Malinena3b8b052009-03-27 21:59:49 +02005758void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
5759 struct net_device *netdev, const u8 *addr,
5760 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02005761 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02005762{
5763 struct sk_buff *msg;
5764 void *hdr;
5765
Johannes Berge6d6e342009-07-01 21:26:47 +02005766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02005767 if (!msg)
5768 return;
5769
5770 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
5771 if (!hdr) {
5772 nlmsg_free(msg);
5773 return;
5774 }
5775
5776 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5777 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5778 if (addr)
5779 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
5780 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
5781 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
5782 if (tsc)
5783 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
5784
5785 if (genlmsg_end(msg, hdr) < 0) {
5786 nlmsg_free(msg);
5787 return;
5788 }
5789
Johannes Berg463d0182009-07-14 00:33:35 +02005790 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5791 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02005792 return;
5793
5794 nla_put_failure:
5795 genlmsg_cancel(msg, hdr);
5796 nlmsg_free(msg);
5797}
5798
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005799void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
5800 struct ieee80211_channel *channel_before,
5801 struct ieee80211_channel *channel_after)
5802{
5803 struct sk_buff *msg;
5804 void *hdr;
5805 struct nlattr *nl_freq;
5806
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005807 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005808 if (!msg)
5809 return;
5810
5811 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
5812 if (!hdr) {
5813 nlmsg_free(msg);
5814 return;
5815 }
5816
5817 /*
5818 * Since we are applying the beacon hint to a wiphy we know its
5819 * wiphy_idx is valid
5820 */
5821 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
5822
5823 /* Before */
5824 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
5825 if (!nl_freq)
5826 goto nla_put_failure;
5827 if (nl80211_msg_put_channel(msg, channel_before))
5828 goto nla_put_failure;
5829 nla_nest_end(msg, nl_freq);
5830
5831 /* After */
5832 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
5833 if (!nl_freq)
5834 goto nla_put_failure;
5835 if (nl80211_msg_put_channel(msg, channel_after))
5836 goto nla_put_failure;
5837 nla_nest_end(msg, nl_freq);
5838
5839 if (genlmsg_end(msg, hdr) < 0) {
5840 nlmsg_free(msg);
5841 return;
5842 }
5843
Johannes Berg463d0182009-07-14 00:33:35 +02005844 rcu_read_lock();
5845 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
5846 GFP_ATOMIC);
5847 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005848
5849 return;
5850
5851nla_put_failure:
5852 genlmsg_cancel(msg, hdr);
5853 nlmsg_free(msg);
5854}
5855
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005856static void nl80211_send_remain_on_chan_event(
5857 int cmd, struct cfg80211_registered_device *rdev,
5858 struct net_device *netdev, u64 cookie,
5859 struct ieee80211_channel *chan,
5860 enum nl80211_channel_type channel_type,
5861 unsigned int duration, gfp_t gfp)
5862{
5863 struct sk_buff *msg;
5864 void *hdr;
5865
5866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5867 if (!msg)
5868 return;
5869
5870 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5871 if (!hdr) {
5872 nlmsg_free(msg);
5873 return;
5874 }
5875
5876 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5877 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5878 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
5879 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
5880 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5881
5882 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
5883 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
5884
5885 if (genlmsg_end(msg, hdr) < 0) {
5886 nlmsg_free(msg);
5887 return;
5888 }
5889
5890 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5891 nl80211_mlme_mcgrp.id, gfp);
5892 return;
5893
5894 nla_put_failure:
5895 genlmsg_cancel(msg, hdr);
5896 nlmsg_free(msg);
5897}
5898
5899void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
5900 struct net_device *netdev, u64 cookie,
5901 struct ieee80211_channel *chan,
5902 enum nl80211_channel_type channel_type,
5903 unsigned int duration, gfp_t gfp)
5904{
5905 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
5906 rdev, netdev, cookie, chan,
5907 channel_type, duration, gfp);
5908}
5909
5910void nl80211_send_remain_on_channel_cancel(
5911 struct cfg80211_registered_device *rdev, struct net_device *netdev,
5912 u64 cookie, struct ieee80211_channel *chan,
5913 enum nl80211_channel_type channel_type, gfp_t gfp)
5914{
5915 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5916 rdev, netdev, cookie, chan,
5917 channel_type, 0, gfp);
5918}
5919
Johannes Berg98b62182009-12-23 13:15:44 +01005920void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
5921 struct net_device *dev, const u8 *mac_addr,
5922 struct station_info *sinfo, gfp_t gfp)
5923{
5924 struct sk_buff *msg;
5925
5926 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5927 if (!msg)
5928 return;
5929
5930 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
5931 nlmsg_free(msg);
5932 return;
5933 }
5934
5935 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5936 nl80211_mlme_mcgrp.id, gfp);
5937}
5938
Johannes Berg2e161f72010-08-12 15:38:38 +02005939int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
5940 struct net_device *netdev, u32 nlpid,
5941 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02005942{
5943 struct sk_buff *msg;
5944 void *hdr;
5945 int err;
5946
5947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5948 if (!msg)
5949 return -ENOMEM;
5950
Johannes Berg2e161f72010-08-12 15:38:38 +02005951 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005952 if (!hdr) {
5953 nlmsg_free(msg);
5954 return -ENOMEM;
5955 }
5956
5957 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5958 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5959 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
5960 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5961
5962 err = genlmsg_end(msg, hdr);
5963 if (err < 0) {
5964 nlmsg_free(msg);
5965 return err;
5966 }
5967
5968 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
5969 if (err < 0)
5970 return err;
5971 return 0;
5972
5973 nla_put_failure:
5974 genlmsg_cancel(msg, hdr);
5975 nlmsg_free(msg);
5976 return -ENOBUFS;
5977}
5978
Johannes Berg2e161f72010-08-12 15:38:38 +02005979void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
5980 struct net_device *netdev, u64 cookie,
5981 const u8 *buf, size_t len, bool ack,
5982 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02005983{
5984 struct sk_buff *msg;
5985 void *hdr;
5986
5987 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5988 if (!msg)
5989 return;
5990
Johannes Berg2e161f72010-08-12 15:38:38 +02005991 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02005992 if (!hdr) {
5993 nlmsg_free(msg);
5994 return;
5995 }
5996
5997 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5998 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5999 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6000 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6001 if (ack)
6002 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
6003
6004 if (genlmsg_end(msg, hdr) < 0) {
6005 nlmsg_free(msg);
6006 return;
6007 }
6008
6009 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
6010 return;
6011
6012 nla_put_failure:
6013 genlmsg_cancel(msg, hdr);
6014 nlmsg_free(msg);
6015}
6016
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006017void
6018nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
6019 struct net_device *netdev,
6020 enum nl80211_cqm_rssi_threshold_event rssi_event,
6021 gfp_t gfp)
6022{
6023 struct sk_buff *msg;
6024 struct nlattr *pinfoattr;
6025 void *hdr;
6026
6027 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6028 if (!msg)
6029 return;
6030
6031 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
6032 if (!hdr) {
6033 nlmsg_free(msg);
6034 return;
6035 }
6036
6037 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6038 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6039
6040 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
6041 if (!pinfoattr)
6042 goto nla_put_failure;
6043
6044 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
6045 rssi_event);
6046
6047 nla_nest_end(msg, pinfoattr);
6048
6049 if (genlmsg_end(msg, hdr) < 0) {
6050 nlmsg_free(msg);
6051 return;
6052 }
6053
6054 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6055 nl80211_mlme_mcgrp.id, gfp);
6056 return;
6057
6058 nla_put_failure:
6059 genlmsg_cancel(msg, hdr);
6060 nlmsg_free(msg);
6061}
6062
Johannes Bergc063dbf2010-11-24 08:10:05 +01006063void
6064nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
6065 struct net_device *netdev, const u8 *peer,
6066 u32 num_packets, gfp_t gfp)
6067{
6068 struct sk_buff *msg;
6069 struct nlattr *pinfoattr;
6070 void *hdr;
6071
6072 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6073 if (!msg)
6074 return;
6075
6076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
6077 if (!hdr) {
6078 nlmsg_free(msg);
6079 return;
6080 }
6081
6082 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6083 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6084 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
6085
6086 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
6087 if (!pinfoattr)
6088 goto nla_put_failure;
6089
6090 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
6091
6092 nla_nest_end(msg, pinfoattr);
6093
6094 if (genlmsg_end(msg, hdr) < 0) {
6095 nlmsg_free(msg);
6096 return;
6097 }
6098
6099 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6100 nl80211_mlme_mcgrp.id, gfp);
6101 return;
6102
6103 nla_put_failure:
6104 genlmsg_cancel(msg, hdr);
6105 nlmsg_free(msg);
6106}
6107
Jouni Malinen026331c2010-02-15 12:53:10 +02006108static int nl80211_netlink_notify(struct notifier_block * nb,
6109 unsigned long state,
6110 void *_notify)
6111{
6112 struct netlink_notify *notify = _notify;
6113 struct cfg80211_registered_device *rdev;
6114 struct wireless_dev *wdev;
6115
6116 if (state != NETLINK_URELEASE)
6117 return NOTIFY_DONE;
6118
6119 rcu_read_lock();
6120
6121 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
6122 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02006123 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02006124
6125 rcu_read_unlock();
6126
6127 return NOTIFY_DONE;
6128}
6129
6130static struct notifier_block nl80211_netlink_notifier = {
6131 .notifier_call = nl80211_netlink_notify,
6132};
6133
Johannes Berg55682962007-09-20 13:09:35 -04006134/* initialisation/exit functions */
6135
6136int nl80211_init(void)
6137{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00006138 int err;
Johannes Berg55682962007-09-20 13:09:35 -04006139
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00006140 err = genl_register_family_with_ops(&nl80211_fam,
6141 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04006142 if (err)
6143 return err;
6144
Johannes Berg55682962007-09-20 13:09:35 -04006145 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
6146 if (err)
6147 goto err_out;
6148
Johannes Berg2a519312009-02-10 21:25:55 +01006149 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
6150 if (err)
6151 goto err_out;
6152
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006153 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
6154 if (err)
6155 goto err_out;
6156
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006157 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
6158 if (err)
6159 goto err_out;
6160
Johannes Bergaff89a92009-07-01 21:26:51 +02006161#ifdef CONFIG_NL80211_TESTMODE
6162 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
6163 if (err)
6164 goto err_out;
6165#endif
6166
Jouni Malinen026331c2010-02-15 12:53:10 +02006167 err = netlink_register_notifier(&nl80211_netlink_notifier);
6168 if (err)
6169 goto err_out;
6170
Johannes Berg55682962007-09-20 13:09:35 -04006171 return 0;
6172 err_out:
6173 genl_unregister_family(&nl80211_fam);
6174 return err;
6175}
6176
6177void nl80211_exit(void)
6178{
Jouni Malinen026331c2010-02-15 12:53:10 +02006179 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04006180 genl_unregister_family(&nl80211_fam);
6181}