Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
55682965 JB |
10 | #include <linux/list.h> |
11 | #include <linux/if_ether.h> | |
12 | #include <linux/ieee80211.h> | |
13 | #include <linux/nl80211.h> | |
14 | #include <linux/rtnetlink.h> | |
15 | #include <linux/netlink.h> | |
2a519311 | 16 | #include <linux/etherdevice.h> |
463d0183 | 17 | #include <net/net_namespace.h> |
55682965 JB |
18 | #include <net/genetlink.h> |
19 | #include <net/cfg80211.h> | |
463d0183 | 20 | #include <net/sock.h> |
55682965 JB |
21 | #include "core.h" |
22 | #include "nl80211.h" | |
b2e1b302 | 23 | #include "reg.h" |
55682965 JB |
24 | |
25 | /* the netlink family */ | |
26 | static struct genl_family nl80211_fam = { | |
27 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
28 | .name = "nl80211", /* have users key off the name instead */ | |
29 | .hdrsize = 0, /* no private header */ | |
30 | .version = 1, /* no particular meaning now */ | |
31 | .maxattr = NL80211_ATTR_MAX, | |
463d0183 | 32 | .netnsok = true, |
55682965 JB |
33 | }; |
34 | ||
79c97e97 | 35 | /* internal helper: get rdev and dev */ |
463d0183 | 36 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
79c97e97 | 37 | struct cfg80211_registered_device **rdev, |
55682965 JB |
38 | struct net_device **dev) |
39 | { | |
463d0183 | 40 | struct nlattr **attrs = info->attrs; |
55682965 JB |
41 | int ifindex; |
42 | ||
bba95fef | 43 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
44 | return -EINVAL; |
45 | ||
bba95fef | 46 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
463d0183 | 47 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
55682965 JB |
48 | if (!*dev) |
49 | return -ENODEV; | |
50 | ||
463d0183 | 51 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
79c97e97 | 52 | if (IS_ERR(*rdev)) { |
55682965 | 53 | dev_put(*dev); |
79c97e97 | 54 | return PTR_ERR(*rdev); |
55682965 JB |
55 | } |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
60 | /* policy for the attributes */ | |
b54452b0 | 61 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
62 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
63 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 64 | .len = 20-1 }, |
31888487 | 65 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 66 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 67 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
b9a5f8ca JM |
68 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
69 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
70 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
71 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 72 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
73 | |
74 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
75 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
76 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f JB |
77 | |
78 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, | |
3e5d7649 | 79 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
41ade00f | 80 | |
b9454e83 | 81 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
82 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
83 | .len = WLAN_MAX_KEY_LEN }, | |
84 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
85 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
86 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
9f26a952 | 87 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
ed1b6cc7 JB |
88 | |
89 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
90 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
91 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
92 | .len = IEEE80211_MAX_DATA_LEN }, | |
93 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
94 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
95 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
96 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
97 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
98 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
99 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 100 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 101 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 102 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 LCC |
103 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
104 | .len = IEEE80211_MAX_MESH_ID_LEN }, | |
105 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, | |
9f1ba906 | 106 | |
b2e1b302 LR |
107 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
108 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
109 | ||
9f1ba906 JM |
110 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
111 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
112 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
113 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
114 | .len = NL80211_MAX_SUPP_RATES }, | |
36aedc90 | 115 | |
93da9cc1 | 116 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
117 | ||
36aedc90 JM |
118 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
119 | .len = NL80211_HT_CAPABILITY_LEN }, | |
9aed3cc1 JM |
120 | |
121 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
122 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
123 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
124 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
125 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
126 | |
127 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
128 | .len = IEEE80211_MAX_SSID_LEN }, | |
129 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
130 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 131 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 132 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 133 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
134 | [NL80211_ATTR_STA_FLAGS2] = { |
135 | .len = sizeof(struct nl80211_sta_flag_update), | |
136 | }, | |
3f77316c | 137 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
b23aa676 SO |
138 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
139 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
140 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 141 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 142 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
143 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
144 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
145 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
146 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 147 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
148 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
149 | .len = IEEE80211_MAX_DATA_LEN }, | |
150 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 151 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
55682965 JB |
152 | }; |
153 | ||
b9454e83 | 154 | /* policy for the attributes */ |
b54452b0 | 155 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 156 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
157 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
158 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
159 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | |
160 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
161 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
162 | }; | |
163 | ||
a043897a HS |
164 | /* ifidx get helper */ |
165 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
166 | { | |
167 | int res; | |
168 | ||
169 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
170 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
171 | nl80211_policy); | |
172 | if (res) | |
173 | return res; | |
174 | ||
175 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
176 | return -EINVAL; | |
177 | ||
178 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
179 | if (!res) | |
180 | return -EINVAL; | |
181 | return res; | |
182 | } | |
183 | ||
f4a11bb0 JB |
184 | /* IE validation */ |
185 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
186 | { | |
187 | const u8 *pos; | |
188 | int len; | |
189 | ||
190 | if (!attr) | |
191 | return true; | |
192 | ||
193 | pos = nla_data(attr); | |
194 | len = nla_len(attr); | |
195 | ||
196 | while (len) { | |
197 | u8 elemlen; | |
198 | ||
199 | if (len < 2) | |
200 | return false; | |
201 | len -= 2; | |
202 | ||
203 | elemlen = pos[1]; | |
204 | if (elemlen > len) | |
205 | return false; | |
206 | ||
207 | len -= elemlen; | |
208 | pos += 2 + elemlen; | |
209 | } | |
210 | ||
211 | return true; | |
212 | } | |
213 | ||
55682965 JB |
214 | /* message building helper */ |
215 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
216 | int flags, u8 cmd) | |
217 | { | |
218 | /* since there is no private header just add the generic one */ | |
219 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
220 | } | |
221 | ||
5dab3b8a LR |
222 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
223 | struct ieee80211_channel *chan) | |
224 | { | |
225 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, | |
226 | chan->center_freq); | |
227 | ||
228 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
229 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); | |
230 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) | |
231 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); | |
232 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) | |
233 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); | |
234 | if (chan->flags & IEEE80211_CHAN_RADAR) | |
235 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); | |
236 | ||
237 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | |
238 | DBM_TO_MBM(chan->max_power)); | |
239 | ||
240 | return 0; | |
241 | ||
242 | nla_put_failure: | |
243 | return -ENOBUFS; | |
244 | } | |
245 | ||
55682965 JB |
246 | /* netlink command implementations */ |
247 | ||
b9454e83 JB |
248 | struct key_parse { |
249 | struct key_params p; | |
250 | int idx; | |
251 | bool def, defmgmt; | |
252 | }; | |
253 | ||
254 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
255 | { | |
256 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
257 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
258 | nl80211_key_policy); | |
259 | if (err) | |
260 | return err; | |
261 | ||
262 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
263 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
264 | ||
265 | if (tb[NL80211_KEY_IDX]) | |
266 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
267 | ||
268 | if (tb[NL80211_KEY_DATA]) { | |
269 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
270 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
271 | } | |
272 | ||
273 | if (tb[NL80211_KEY_SEQ]) { | |
274 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
275 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
276 | } | |
277 | ||
278 | if (tb[NL80211_KEY_CIPHER]) | |
279 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
280 | ||
281 | return 0; | |
282 | } | |
283 | ||
284 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
285 | { | |
286 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
287 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
288 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
289 | } | |
290 | ||
291 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
292 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
293 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
294 | } | |
295 | ||
296 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
297 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
298 | ||
299 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
300 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
301 | ||
302 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
303 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
304 | ||
305 | return 0; | |
306 | } | |
307 | ||
308 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
309 | { | |
310 | int err; | |
311 | ||
312 | memset(k, 0, sizeof(*k)); | |
313 | k->idx = -1; | |
314 | ||
315 | if (info->attrs[NL80211_ATTR_KEY]) | |
316 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
317 | else | |
318 | err = nl80211_parse_key_old(info, k); | |
319 | ||
320 | if (err) | |
321 | return err; | |
322 | ||
323 | if (k->def && k->defmgmt) | |
324 | return -EINVAL; | |
325 | ||
326 | if (k->idx != -1) { | |
327 | if (k->defmgmt) { | |
328 | if (k->idx < 4 || k->idx > 5) | |
329 | return -EINVAL; | |
330 | } else if (k->def) { | |
331 | if (k->idx < 0 || k->idx > 3) | |
332 | return -EINVAL; | |
333 | } else { | |
334 | if (k->idx < 0 || k->idx > 5) | |
335 | return -EINVAL; | |
336 | } | |
337 | } | |
338 | ||
339 | return 0; | |
340 | } | |
341 | ||
fffd0934 JB |
342 | static struct cfg80211_cached_keys * |
343 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
344 | struct nlattr *keys) | |
345 | { | |
346 | struct key_parse parse; | |
347 | struct nlattr *key; | |
348 | struct cfg80211_cached_keys *result; | |
349 | int rem, err, def = 0; | |
350 | ||
351 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
352 | if (!result) | |
353 | return ERR_PTR(-ENOMEM); | |
354 | ||
355 | result->def = -1; | |
356 | result->defmgmt = -1; | |
357 | ||
358 | nla_for_each_nested(key, keys, rem) { | |
359 | memset(&parse, 0, sizeof(parse)); | |
360 | parse.idx = -1; | |
361 | ||
362 | err = nl80211_parse_key_new(key, &parse); | |
363 | if (err) | |
364 | goto error; | |
365 | err = -EINVAL; | |
366 | if (!parse.p.key) | |
367 | goto error; | |
368 | if (parse.idx < 0 || parse.idx > 4) | |
369 | goto error; | |
370 | if (parse.def) { | |
371 | if (def) | |
372 | goto error; | |
373 | def = 1; | |
374 | result->def = parse.idx; | |
375 | } else if (parse.defmgmt) | |
376 | goto error; | |
377 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
378 | parse.idx, NULL); | |
379 | if (err) | |
380 | goto error; | |
381 | result->params[parse.idx].cipher = parse.p.cipher; | |
382 | result->params[parse.idx].key_len = parse.p.key_len; | |
383 | result->params[parse.idx].key = result->data[parse.idx]; | |
384 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
385 | } | |
386 | ||
387 | return result; | |
388 | error: | |
389 | kfree(result); | |
390 | return ERR_PTR(err); | |
391 | } | |
392 | ||
393 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
394 | { | |
395 | ASSERT_WDEV_LOCK(wdev); | |
396 | ||
397 | if (!netif_running(wdev->netdev)) | |
398 | return -ENETDOWN; | |
399 | ||
400 | switch (wdev->iftype) { | |
401 | case NL80211_IFTYPE_AP: | |
402 | case NL80211_IFTYPE_AP_VLAN: | |
403 | break; | |
404 | case NL80211_IFTYPE_ADHOC: | |
405 | if (!wdev->current_bss) | |
406 | return -ENOLINK; | |
407 | break; | |
408 | case NL80211_IFTYPE_STATION: | |
409 | if (wdev->sme_state != CFG80211_SME_CONNECTED) | |
410 | return -ENOLINK; | |
411 | break; | |
412 | default: | |
413 | return -EINVAL; | |
414 | } | |
415 | ||
416 | return 0; | |
417 | } | |
418 | ||
55682965 JB |
419 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
420 | struct cfg80211_registered_device *dev) | |
421 | { | |
422 | void *hdr; | |
ee688b00 JB |
423 | struct nlattr *nl_bands, *nl_band; |
424 | struct nlattr *nl_freqs, *nl_freq; | |
425 | struct nlattr *nl_rates, *nl_rate; | |
f59ac048 | 426 | struct nlattr *nl_modes; |
8fdc621d | 427 | struct nlattr *nl_cmds; |
ee688b00 JB |
428 | enum ieee80211_band band; |
429 | struct ieee80211_channel *chan; | |
430 | struct ieee80211_rate *rate; | |
431 | int i; | |
f59ac048 | 432 | u16 ifmodes = dev->wiphy.interface_modes; |
55682965 JB |
433 | |
434 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
435 | if (!hdr) | |
436 | return -1; | |
437 | ||
b5850a7a | 438 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
55682965 | 439 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
b9a5f8ca | 440 | |
f5ea9120 JB |
441 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
442 | cfg80211_rdev_list_generation); | |
443 | ||
b9a5f8ca JM |
444 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
445 | dev->wiphy.retry_short); | |
446 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
447 | dev->wiphy.retry_long); | |
448 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
449 | dev->wiphy.frag_threshold); | |
450 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
451 | dev->wiphy.rts_threshold); | |
81077e82 LT |
452 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
453 | dev->wiphy.coverage_class); | |
b9a5f8ca | 454 | |
2a519311 JB |
455 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
456 | dev->wiphy.max_scan_ssids); | |
18a83659 JB |
457 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
458 | dev->wiphy.max_scan_ie_len); | |
ee688b00 | 459 | |
25e47c18 JB |
460 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
461 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
462 | dev->wiphy.cipher_suites); | |
463 | ||
67fbb16b SO |
464 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
465 | dev->wiphy.max_num_pmkids); | |
466 | ||
f59ac048 LR |
467 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
468 | if (!nl_modes) | |
469 | goto nla_put_failure; | |
470 | ||
471 | i = 0; | |
472 | while (ifmodes) { | |
473 | if (ifmodes & 1) | |
474 | NLA_PUT_FLAG(msg, i); | |
475 | ifmodes >>= 1; | |
476 | i++; | |
477 | } | |
478 | ||
479 | nla_nest_end(msg, nl_modes); | |
480 | ||
ee688b00 JB |
481 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
482 | if (!nl_bands) | |
483 | goto nla_put_failure; | |
484 | ||
485 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
486 | if (!dev->wiphy.bands[band]) | |
487 | continue; | |
488 | ||
489 | nl_band = nla_nest_start(msg, band); | |
490 | if (!nl_band) | |
491 | goto nla_put_failure; | |
492 | ||
d51626df JB |
493 | /* add HT info */ |
494 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { | |
495 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
496 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
497 | &dev->wiphy.bands[band]->ht_cap.mcs); | |
498 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
499 | dev->wiphy.bands[band]->ht_cap.cap); | |
500 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
501 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); | |
502 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
503 | dev->wiphy.bands[band]->ht_cap.ampdu_density); | |
504 | } | |
505 | ||
ee688b00 JB |
506 | /* add frequencies */ |
507 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
508 | if (!nl_freqs) | |
509 | goto nla_put_failure; | |
510 | ||
511 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
512 | nl_freq = nla_nest_start(msg, i); | |
513 | if (!nl_freq) | |
514 | goto nla_put_failure; | |
515 | ||
516 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
517 | |
518 | if (nl80211_msg_put_channel(msg, chan)) | |
519 | goto nla_put_failure; | |
e2f367f2 | 520 | |
ee688b00 JB |
521 | nla_nest_end(msg, nl_freq); |
522 | } | |
523 | ||
524 | nla_nest_end(msg, nl_freqs); | |
525 | ||
526 | /* add bitrates */ | |
527 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
528 | if (!nl_rates) | |
529 | goto nla_put_failure; | |
530 | ||
531 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
532 | nl_rate = nla_nest_start(msg, i); | |
533 | if (!nl_rate) | |
534 | goto nla_put_failure; | |
535 | ||
536 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
537 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, | |
538 | rate->bitrate); | |
539 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
540 | NLA_PUT_FLAG(msg, | |
541 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); | |
542 | ||
543 | nla_nest_end(msg, nl_rate); | |
544 | } | |
545 | ||
546 | nla_nest_end(msg, nl_rates); | |
547 | ||
548 | nla_nest_end(msg, nl_band); | |
549 | } | |
550 | nla_nest_end(msg, nl_bands); | |
551 | ||
8fdc621d JB |
552 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
553 | if (!nl_cmds) | |
554 | goto nla_put_failure; | |
555 | ||
556 | i = 0; | |
557 | #define CMD(op, n) \ | |
558 | do { \ | |
559 | if (dev->ops->op) { \ | |
560 | i++; \ | |
561 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ | |
562 | } \ | |
563 | } while (0) | |
564 | ||
565 | CMD(add_virtual_intf, NEW_INTERFACE); | |
566 | CMD(change_virtual_intf, SET_INTERFACE); | |
567 | CMD(add_key, NEW_KEY); | |
568 | CMD(add_beacon, NEW_BEACON); | |
569 | CMD(add_station, NEW_STATION); | |
570 | CMD(add_mpath, NEW_MPATH); | |
571 | CMD(set_mesh_params, SET_MESH_PARAMS); | |
572 | CMD(change_bss, SET_BSS); | |
636a5d36 JM |
573 | CMD(auth, AUTHENTICATE); |
574 | CMD(assoc, ASSOCIATE); | |
575 | CMD(deauth, DEAUTHENTICATE); | |
576 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 577 | CMD(join_ibss, JOIN_IBSS); |
67fbb16b SO |
578 | CMD(set_pmksa, SET_PMKSA); |
579 | CMD(del_pmksa, DEL_PMKSA); | |
580 | CMD(flush_pmksa, FLUSH_PMKSA); | |
9588bbd5 | 581 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
13ae75b1 | 582 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
026331c4 | 583 | CMD(action, ACTION); |
5be83de5 | 584 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 JB |
585 | i++; |
586 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); | |
587 | } | |
8fdc621d JB |
588 | |
589 | #undef CMD | |
b23aa676 | 590 | |
6829c878 | 591 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 SO |
592 | i++; |
593 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); | |
594 | } | |
595 | ||
6829c878 | 596 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 SO |
597 | i++; |
598 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); | |
599 | } | |
600 | ||
8fdc621d JB |
601 | nla_nest_end(msg, nl_cmds); |
602 | ||
55682965 JB |
603 | return genlmsg_end(msg, hdr); |
604 | ||
605 | nla_put_failure: | |
bc3ed28c TG |
606 | genlmsg_cancel(msg, hdr); |
607 | return -EMSGSIZE; | |
55682965 JB |
608 | } |
609 | ||
610 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
611 | { | |
612 | int idx = 0; | |
613 | int start = cb->args[0]; | |
614 | struct cfg80211_registered_device *dev; | |
615 | ||
a1794390 | 616 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 617 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
618 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
619 | continue; | |
b4637271 | 620 | if (++idx <= start) |
55682965 JB |
621 | continue; |
622 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
623 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
624 | dev) < 0) { |
625 | idx--; | |
55682965 | 626 | break; |
b4637271 | 627 | } |
55682965 | 628 | } |
a1794390 | 629 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
630 | |
631 | cb->args[0] = idx; | |
632 | ||
633 | return skb->len; | |
634 | } | |
635 | ||
636 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
637 | { | |
638 | struct sk_buff *msg; | |
639 | struct cfg80211_registered_device *dev; | |
640 | ||
641 | dev = cfg80211_get_dev_from_info(info); | |
642 | if (IS_ERR(dev)) | |
643 | return PTR_ERR(dev); | |
644 | ||
fd2120ca | 645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
646 | if (!msg) |
647 | goto out_err; | |
648 | ||
649 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) | |
650 | goto out_free; | |
651 | ||
4d0c8aea | 652 | cfg80211_unlock_rdev(dev); |
55682965 | 653 | |
134e6375 | 654 | return genlmsg_reply(msg, info); |
55682965 JB |
655 | |
656 | out_free: | |
657 | nlmsg_free(msg); | |
658 | out_err: | |
4d0c8aea | 659 | cfg80211_unlock_rdev(dev); |
55682965 JB |
660 | return -ENOBUFS; |
661 | } | |
662 | ||
31888487 JM |
663 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
664 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
665 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
666 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
667 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
668 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
669 | }; | |
670 | ||
671 | static int parse_txq_params(struct nlattr *tb[], | |
672 | struct ieee80211_txq_params *txq_params) | |
673 | { | |
674 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || | |
675 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | |
676 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
677 | return -EINVAL; | |
678 | ||
679 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); | |
680 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | |
681 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
682 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
683 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
684 | ||
685 | return 0; | |
686 | } | |
687 | ||
55682965 JB |
688 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
689 | { | |
690 | struct cfg80211_registered_device *rdev; | |
31888487 JM |
691 | int result = 0, rem_txq_params = 0; |
692 | struct nlattr *nl_txq_params; | |
b9a5f8ca JM |
693 | u32 changed; |
694 | u8 retry_short = 0, retry_long = 0; | |
695 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 696 | u8 coverage_class = 0; |
55682965 | 697 | |
4bbf4d56 | 698 | rtnl_lock(); |
55682965 | 699 | |
4bbf4d56 JB |
700 | mutex_lock(&cfg80211_mutex); |
701 | ||
79c97e97 | 702 | rdev = __cfg80211_rdev_from_info(info); |
4bbf4d56 | 703 | if (IS_ERR(rdev)) { |
1f5fc70a | 704 | mutex_unlock(&cfg80211_mutex); |
4bbf4d56 JB |
705 | result = PTR_ERR(rdev); |
706 | goto unlock; | |
707 | } | |
708 | ||
709 | mutex_lock(&rdev->mtx); | |
710 | ||
711 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
712 | result = cfg80211_dev_rename( |
713 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
714 | |
715 | mutex_unlock(&cfg80211_mutex); | |
716 | ||
717 | if (result) | |
718 | goto bad_res; | |
31888487 JM |
719 | |
720 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
721 | struct ieee80211_txq_params txq_params; | |
722 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
723 | ||
724 | if (!rdev->ops->set_txq_params) { | |
725 | result = -EOPNOTSUPP; | |
726 | goto bad_res; | |
727 | } | |
728 | ||
729 | nla_for_each_nested(nl_txq_params, | |
730 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
731 | rem_txq_params) { | |
732 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
733 | nla_data(nl_txq_params), | |
734 | nla_len(nl_txq_params), | |
735 | txq_params_policy); | |
736 | result = parse_txq_params(tb, &txq_params); | |
737 | if (result) | |
738 | goto bad_res; | |
739 | ||
740 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
741 | &txq_params); | |
742 | if (result) | |
743 | goto bad_res; | |
744 | } | |
745 | } | |
55682965 | 746 | |
72bdcf34 | 747 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
094d05dc | 748 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
294196ab | 749 | u32 freq; |
72bdcf34 | 750 | |
306d6112 JB |
751 | result = -EINVAL; |
752 | ||
094d05dc S |
753 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
754 | channel_type = nla_get_u32(info->attrs[ | |
755 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
756 | if (channel_type != NL80211_CHAN_NO_HT && | |
757 | channel_type != NL80211_CHAN_HT20 && | |
758 | channel_type != NL80211_CHAN_HT40PLUS && | |
759 | channel_type != NL80211_CHAN_HT40MINUS) | |
72bdcf34 | 760 | goto bad_res; |
72bdcf34 JM |
761 | } |
762 | ||
763 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
306d6112 | 764 | |
59bbb6f7 | 765 | mutex_lock(&rdev->devlist_mtx); |
4b181144 | 766 | result = rdev_set_freq(rdev, NULL, freq, channel_type); |
59bbb6f7 | 767 | mutex_unlock(&rdev->devlist_mtx); |
72bdcf34 JM |
768 | if (result) |
769 | goto bad_res; | |
770 | } | |
771 | ||
b9a5f8ca JM |
772 | changed = 0; |
773 | ||
774 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
775 | retry_short = nla_get_u8( | |
776 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
777 | if (retry_short == 0) { | |
778 | result = -EINVAL; | |
779 | goto bad_res; | |
780 | } | |
781 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
782 | } | |
783 | ||
784 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
785 | retry_long = nla_get_u8( | |
786 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
787 | if (retry_long == 0) { | |
788 | result = -EINVAL; | |
789 | goto bad_res; | |
790 | } | |
791 | changed |= WIPHY_PARAM_RETRY_LONG; | |
792 | } | |
793 | ||
794 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
795 | frag_threshold = nla_get_u32( | |
796 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
797 | if (frag_threshold < 256) { | |
798 | result = -EINVAL; | |
799 | goto bad_res; | |
800 | } | |
801 | if (frag_threshold != (u32) -1) { | |
802 | /* | |
803 | * Fragments (apart from the last one) are required to | |
804 | * have even length. Make the fragmentation code | |
805 | * simpler by stripping LSB should someone try to use | |
806 | * odd threshold value. | |
807 | */ | |
808 | frag_threshold &= ~0x1; | |
809 | } | |
810 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
811 | } | |
812 | ||
813 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
814 | rts_threshold = nla_get_u32( | |
815 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
816 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
817 | } | |
818 | ||
81077e82 LT |
819 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
820 | coverage_class = nla_get_u8( | |
821 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
822 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
823 | } | |
824 | ||
b9a5f8ca JM |
825 | if (changed) { |
826 | u8 old_retry_short, old_retry_long; | |
827 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 828 | u8 old_coverage_class; |
b9a5f8ca JM |
829 | |
830 | if (!rdev->ops->set_wiphy_params) { | |
831 | result = -EOPNOTSUPP; | |
832 | goto bad_res; | |
833 | } | |
834 | ||
835 | old_retry_short = rdev->wiphy.retry_short; | |
836 | old_retry_long = rdev->wiphy.retry_long; | |
837 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
838 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 839 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
840 | |
841 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
842 | rdev->wiphy.retry_short = retry_short; | |
843 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
844 | rdev->wiphy.retry_long = retry_long; | |
845 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
846 | rdev->wiphy.frag_threshold = frag_threshold; | |
847 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
848 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
849 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
850 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca JM |
851 | |
852 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); | |
853 | if (result) { | |
854 | rdev->wiphy.retry_short = old_retry_short; | |
855 | rdev->wiphy.retry_long = old_retry_long; | |
856 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
857 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 858 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
859 | } |
860 | } | |
72bdcf34 | 861 | |
306d6112 | 862 | bad_res: |
4bbf4d56 JB |
863 | mutex_unlock(&rdev->mtx); |
864 | unlock: | |
865 | rtnl_unlock(); | |
55682965 JB |
866 | return result; |
867 | } | |
868 | ||
869 | ||
870 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
d726405a | 871 | struct cfg80211_registered_device *rdev, |
55682965 JB |
872 | struct net_device *dev) |
873 | { | |
874 | void *hdr; | |
875 | ||
876 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
877 | if (!hdr) | |
878 | return -1; | |
879 | ||
880 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
d726405a | 881 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
55682965 | 882 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
60719ffd | 883 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
f5ea9120 JB |
884 | |
885 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, | |
886 | rdev->devlist_generation ^ | |
887 | (cfg80211_rdev_list_generation << 2)); | |
888 | ||
55682965 JB |
889 | return genlmsg_end(msg, hdr); |
890 | ||
891 | nla_put_failure: | |
bc3ed28c TG |
892 | genlmsg_cancel(msg, hdr); |
893 | return -EMSGSIZE; | |
55682965 JB |
894 | } |
895 | ||
896 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
897 | { | |
898 | int wp_idx = 0; | |
899 | int if_idx = 0; | |
900 | int wp_start = cb->args[0]; | |
901 | int if_start = cb->args[1]; | |
f5ea9120 | 902 | struct cfg80211_registered_device *rdev; |
55682965 JB |
903 | struct wireless_dev *wdev; |
904 | ||
a1794390 | 905 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
906 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
907 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 908 | continue; |
bba95fef JB |
909 | if (wp_idx < wp_start) { |
910 | wp_idx++; | |
55682965 | 911 | continue; |
bba95fef | 912 | } |
55682965 JB |
913 | if_idx = 0; |
914 | ||
f5ea9120 JB |
915 | mutex_lock(&rdev->devlist_mtx); |
916 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
bba95fef JB |
917 | if (if_idx < if_start) { |
918 | if_idx++; | |
55682965 | 919 | continue; |
bba95fef | 920 | } |
55682965 JB |
921 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
922 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
f5ea9120 JB |
923 | rdev, wdev->netdev) < 0) { |
924 | mutex_unlock(&rdev->devlist_mtx); | |
bba95fef JB |
925 | goto out; |
926 | } | |
927 | if_idx++; | |
55682965 | 928 | } |
f5ea9120 | 929 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
930 | |
931 | wp_idx++; | |
55682965 | 932 | } |
bba95fef | 933 | out: |
a1794390 | 934 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
935 | |
936 | cb->args[0] = wp_idx; | |
937 | cb->args[1] = if_idx; | |
938 | ||
939 | return skb->len; | |
940 | } | |
941 | ||
942 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
943 | { | |
944 | struct sk_buff *msg; | |
945 | struct cfg80211_registered_device *dev; | |
946 | struct net_device *netdev; | |
947 | int err; | |
948 | ||
463d0183 | 949 | err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev); |
55682965 JB |
950 | if (err) |
951 | return err; | |
952 | ||
fd2120ca | 953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
954 | if (!msg) |
955 | goto out_err; | |
956 | ||
d726405a JB |
957 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
958 | dev, netdev) < 0) | |
55682965 JB |
959 | goto out_free; |
960 | ||
961 | dev_put(netdev); | |
4d0c8aea | 962 | cfg80211_unlock_rdev(dev); |
55682965 | 963 | |
134e6375 | 964 | return genlmsg_reply(msg, info); |
55682965 JB |
965 | |
966 | out_free: | |
967 | nlmsg_free(msg); | |
968 | out_err: | |
969 | dev_put(netdev); | |
4d0c8aea | 970 | cfg80211_unlock_rdev(dev); |
55682965 JB |
971 | return -ENOBUFS; |
972 | } | |
973 | ||
66f7ac50 MW |
974 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
975 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
976 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
977 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
978 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
979 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
980 | }; | |
981 | ||
982 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
983 | { | |
984 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
985 | int flag; | |
986 | ||
987 | *mntrflags = 0; | |
988 | ||
989 | if (!nla) | |
990 | return -EINVAL; | |
991 | ||
992 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
993 | nla, mntr_flags_policy)) | |
994 | return -EINVAL; | |
995 | ||
996 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
997 | if (flags[flag]) | |
998 | *mntrflags |= (1<<flag); | |
999 | ||
1000 | return 0; | |
1001 | } | |
1002 | ||
9bc383de | 1003 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1004 | struct net_device *netdev, u8 use_4addr, |
1005 | enum nl80211_iftype iftype) | |
9bc383de | 1006 | { |
ad4bb6f8 JB |
1007 | if (!use_4addr) { |
1008 | if (netdev && netdev->br_port) | |
1009 | return -EBUSY; | |
9bc383de | 1010 | return 0; |
ad4bb6f8 | 1011 | } |
9bc383de JB |
1012 | |
1013 | switch (iftype) { | |
1014 | case NL80211_IFTYPE_AP_VLAN: | |
1015 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
1016 | return 0; | |
1017 | break; | |
1018 | case NL80211_IFTYPE_STATION: | |
1019 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
1020 | return 0; | |
1021 | break; | |
1022 | default: | |
1023 | break; | |
1024 | } | |
1025 | ||
1026 | return -EOPNOTSUPP; | |
1027 | } | |
1028 | ||
55682965 JB |
1029 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1030 | { | |
79c97e97 | 1031 | struct cfg80211_registered_device *rdev; |
2ec600d6 | 1032 | struct vif_params params; |
e36d56b6 | 1033 | int err; |
04a773ad | 1034 | enum nl80211_iftype otype, ntype; |
55682965 | 1035 | struct net_device *dev; |
92ffe055 | 1036 | u32 _flags, *flags = NULL; |
ac7f9cfa | 1037 | bool change = false; |
55682965 | 1038 | |
2ec600d6 LCC |
1039 | memset(¶ms, 0, sizeof(params)); |
1040 | ||
3b85875a JB |
1041 | rtnl_lock(); |
1042 | ||
463d0183 | 1043 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
55682965 | 1044 | if (err) |
3b85875a JB |
1045 | goto unlock_rtnl; |
1046 | ||
04a773ad | 1047 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 1048 | |
723b038d | 1049 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 1050 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 1051 | if (otype != ntype) |
ac7f9cfa | 1052 | change = true; |
04a773ad | 1053 | if (ntype > NL80211_IFTYPE_MAX) { |
ac7f9cfa | 1054 | err = -EINVAL; |
723b038d | 1055 | goto unlock; |
ac7f9cfa | 1056 | } |
723b038d JB |
1057 | } |
1058 | ||
92ffe055 | 1059 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
04a773ad | 1060 | if (ntype != NL80211_IFTYPE_MESH_POINT) { |
92ffe055 JB |
1061 | err = -EINVAL; |
1062 | goto unlock; | |
1063 | } | |
2ec600d6 LCC |
1064 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
1065 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
ac7f9cfa | 1066 | change = true; |
2ec600d6 LCC |
1067 | } |
1068 | ||
8b787643 FF |
1069 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1070 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
1071 | change = true; | |
ad4bb6f8 | 1072 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de JB |
1073 | if (err) |
1074 | goto unlock; | |
8b787643 FF |
1075 | } else { |
1076 | params.use_4addr = -1; | |
1077 | } | |
1078 | ||
92ffe055 | 1079 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
04a773ad | 1080 | if (ntype != NL80211_IFTYPE_MONITOR) { |
92ffe055 JB |
1081 | err = -EINVAL; |
1082 | goto unlock; | |
1083 | } | |
1084 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
1085 | &_flags); | |
ac7f9cfa JB |
1086 | if (err) |
1087 | goto unlock; | |
1088 | ||
1089 | flags = &_flags; | |
1090 | change = true; | |
92ffe055 | 1091 | } |
3b85875a | 1092 | |
ac7f9cfa | 1093 | if (change) |
3d54d255 | 1094 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
1095 | else |
1096 | err = 0; | |
60719ffd | 1097 | |
9bc383de JB |
1098 | if (!err && params.use_4addr != -1) |
1099 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
1100 | ||
55682965 | 1101 | unlock: |
e36d56b6 | 1102 | dev_put(dev); |
79c97e97 | 1103 | cfg80211_unlock_rdev(rdev); |
3b85875a JB |
1104 | unlock_rtnl: |
1105 | rtnl_unlock(); | |
55682965 JB |
1106 | return err; |
1107 | } | |
1108 | ||
1109 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
1110 | { | |
79c97e97 | 1111 | struct cfg80211_registered_device *rdev; |
2ec600d6 | 1112 | struct vif_params params; |
55682965 JB |
1113 | int err; |
1114 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 1115 | u32 flags; |
55682965 | 1116 | |
2ec600d6 LCC |
1117 | memset(¶ms, 0, sizeof(params)); |
1118 | ||
55682965 JB |
1119 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
1120 | return -EINVAL; | |
1121 | ||
1122 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
1123 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
1124 | if (type > NL80211_IFTYPE_MAX) | |
1125 | return -EINVAL; | |
1126 | } | |
1127 | ||
3b85875a JB |
1128 | rtnl_lock(); |
1129 | ||
79c97e97 JB |
1130 | rdev = cfg80211_get_dev_from_info(info); |
1131 | if (IS_ERR(rdev)) { | |
1132 | err = PTR_ERR(rdev); | |
3b85875a JB |
1133 | goto unlock_rtnl; |
1134 | } | |
55682965 | 1135 | |
79c97e97 JB |
1136 | if (!rdev->ops->add_virtual_intf || |
1137 | !(rdev->wiphy.interface_modes & (1 << type))) { | |
55682965 JB |
1138 | err = -EOPNOTSUPP; |
1139 | goto unlock; | |
1140 | } | |
1141 | ||
2ec600d6 LCC |
1142 | if (type == NL80211_IFTYPE_MESH_POINT && |
1143 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
1144 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | |
1145 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1146 | } | |
1147 | ||
9bc383de | 1148 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 1149 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 1150 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de JB |
1151 | if (err) |
1152 | goto unlock; | |
1153 | } | |
8b787643 | 1154 | |
66f7ac50 MW |
1155 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1156 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
1157 | &flags); | |
79c97e97 | 1158 | err = rdev->ops->add_virtual_intf(&rdev->wiphy, |
66f7ac50 | 1159 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 1160 | type, err ? NULL : &flags, ¶ms); |
2ec600d6 | 1161 | |
55682965 | 1162 | unlock: |
79c97e97 | 1163 | cfg80211_unlock_rdev(rdev); |
3b85875a JB |
1164 | unlock_rtnl: |
1165 | rtnl_unlock(); | |
55682965 JB |
1166 | return err; |
1167 | } | |
1168 | ||
1169 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
1170 | { | |
79c97e97 | 1171 | struct cfg80211_registered_device *rdev; |
463d0183 | 1172 | int err; |
55682965 JB |
1173 | struct net_device *dev; |
1174 | ||
3b85875a JB |
1175 | rtnl_lock(); |
1176 | ||
463d0183 | 1177 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
55682965 | 1178 | if (err) |
3b85875a | 1179 | goto unlock_rtnl; |
55682965 | 1180 | |
79c97e97 | 1181 | if (!rdev->ops->del_virtual_intf) { |
55682965 JB |
1182 | err = -EOPNOTSUPP; |
1183 | goto out; | |
1184 | } | |
1185 | ||
463d0183 | 1186 | err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
55682965 JB |
1187 | |
1188 | out: | |
79c97e97 | 1189 | cfg80211_unlock_rdev(rdev); |
463d0183 | 1190 | dev_put(dev); |
3b85875a JB |
1191 | unlock_rtnl: |
1192 | rtnl_unlock(); | |
55682965 JB |
1193 | return err; |
1194 | } | |
1195 | ||
41ade00f JB |
1196 | struct get_key_cookie { |
1197 | struct sk_buff *msg; | |
1198 | int error; | |
b9454e83 | 1199 | int idx; |
41ade00f JB |
1200 | }; |
1201 | ||
1202 | static void get_key_callback(void *c, struct key_params *params) | |
1203 | { | |
b9454e83 | 1204 | struct nlattr *key; |
41ade00f JB |
1205 | struct get_key_cookie *cookie = c; |
1206 | ||
1207 | if (params->key) | |
1208 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, | |
1209 | params->key_len, params->key); | |
1210 | ||
1211 | if (params->seq) | |
1212 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
1213 | params->seq_len, params->seq); | |
1214 | ||
1215 | if (params->cipher) | |
1216 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
1217 | params->cipher); | |
1218 | ||
b9454e83 JB |
1219 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
1220 | if (!key) | |
1221 | goto nla_put_failure; | |
1222 | ||
1223 | if (params->key) | |
1224 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, | |
1225 | params->key_len, params->key); | |
1226 | ||
1227 | if (params->seq) | |
1228 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, | |
1229 | params->seq_len, params->seq); | |
1230 | ||
1231 | if (params->cipher) | |
1232 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, | |
1233 | params->cipher); | |
1234 | ||
1235 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); | |
1236 | ||
1237 | nla_nest_end(cookie->msg, key); | |
1238 | ||
41ade00f JB |
1239 | return; |
1240 | nla_put_failure: | |
1241 | cookie->error = 1; | |
1242 | } | |
1243 | ||
1244 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
1245 | { | |
79c97e97 | 1246 | struct cfg80211_registered_device *rdev; |
41ade00f JB |
1247 | int err; |
1248 | struct net_device *dev; | |
1249 | u8 key_idx = 0; | |
1250 | u8 *mac_addr = NULL; | |
1251 | struct get_key_cookie cookie = { | |
1252 | .error = 0, | |
1253 | }; | |
1254 | void *hdr; | |
1255 | struct sk_buff *msg; | |
1256 | ||
1257 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1258 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1259 | ||
3cfcf6ac | 1260 | if (key_idx > 5) |
41ade00f JB |
1261 | return -EINVAL; |
1262 | ||
1263 | if (info->attrs[NL80211_ATTR_MAC]) | |
1264 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1265 | ||
3b85875a JB |
1266 | rtnl_lock(); |
1267 | ||
463d0183 | 1268 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1269 | if (err) |
3b85875a | 1270 | goto unlock_rtnl; |
41ade00f | 1271 | |
79c97e97 | 1272 | if (!rdev->ops->get_key) { |
41ade00f JB |
1273 | err = -EOPNOTSUPP; |
1274 | goto out; | |
1275 | } | |
1276 | ||
fd2120ca | 1277 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
41ade00f JB |
1278 | if (!msg) { |
1279 | err = -ENOMEM; | |
1280 | goto out; | |
1281 | } | |
1282 | ||
1283 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
1284 | NL80211_CMD_NEW_KEY); | |
1285 | ||
1286 | if (IS_ERR(hdr)) { | |
1287 | err = PTR_ERR(hdr); | |
6c95e2a2 | 1288 | goto free_msg; |
41ade00f JB |
1289 | } |
1290 | ||
1291 | cookie.msg = msg; | |
b9454e83 | 1292 | cookie.idx = key_idx; |
41ade00f JB |
1293 | |
1294 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1295 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1296 | if (mac_addr) | |
1297 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1298 | ||
79c97e97 | 1299 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, |
41ade00f | 1300 | &cookie, get_key_callback); |
41ade00f JB |
1301 | |
1302 | if (err) | |
6c95e2a2 | 1303 | goto free_msg; |
41ade00f JB |
1304 | |
1305 | if (cookie.error) | |
1306 | goto nla_put_failure; | |
1307 | ||
1308 | genlmsg_end(msg, hdr); | |
134e6375 | 1309 | err = genlmsg_reply(msg, info); |
41ade00f JB |
1310 | goto out; |
1311 | ||
1312 | nla_put_failure: | |
1313 | err = -ENOBUFS; | |
6c95e2a2 | 1314 | free_msg: |
41ade00f JB |
1315 | nlmsg_free(msg); |
1316 | out: | |
79c97e97 | 1317 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1318 | dev_put(dev); |
3b85875a JB |
1319 | unlock_rtnl: |
1320 | rtnl_unlock(); | |
1321 | ||
41ade00f JB |
1322 | return err; |
1323 | } | |
1324 | ||
1325 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
1326 | { | |
79c97e97 | 1327 | struct cfg80211_registered_device *rdev; |
b9454e83 | 1328 | struct key_parse key; |
41ade00f JB |
1329 | int err; |
1330 | struct net_device *dev; | |
3cfcf6ac JM |
1331 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
1332 | u8 key_index); | |
41ade00f | 1333 | |
b9454e83 JB |
1334 | err = nl80211_parse_key(info, &key); |
1335 | if (err) | |
1336 | return err; | |
41ade00f | 1337 | |
b9454e83 | 1338 | if (key.idx < 0) |
41ade00f JB |
1339 | return -EINVAL; |
1340 | ||
b9454e83 JB |
1341 | /* only support setting default key */ |
1342 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
1343 | return -EINVAL; |
1344 | ||
3b85875a JB |
1345 | rtnl_lock(); |
1346 | ||
463d0183 | 1347 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1348 | if (err) |
3b85875a | 1349 | goto unlock_rtnl; |
41ade00f | 1350 | |
b9454e83 | 1351 | if (key.def) |
79c97e97 | 1352 | func = rdev->ops->set_default_key; |
3cfcf6ac | 1353 | else |
79c97e97 | 1354 | func = rdev->ops->set_default_mgmt_key; |
3cfcf6ac JM |
1355 | |
1356 | if (!func) { | |
41ade00f JB |
1357 | err = -EOPNOTSUPP; |
1358 | goto out; | |
1359 | } | |
1360 | ||
fffd0934 JB |
1361 | wdev_lock(dev->ieee80211_ptr); |
1362 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1363 | if (!err) | |
1364 | err = func(&rdev->wiphy, dev, key.idx); | |
1365 | ||
3d23e349 | 1366 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 1367 | if (!err) { |
79c97e97 | 1368 | if (func == rdev->ops->set_default_key) |
b9454e83 | 1369 | dev->ieee80211_ptr->wext.default_key = key.idx; |
08645126 | 1370 | else |
b9454e83 | 1371 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
08645126 JB |
1372 | } |
1373 | #endif | |
fffd0934 | 1374 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f JB |
1375 | |
1376 | out: | |
79c97e97 | 1377 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1378 | dev_put(dev); |
3b85875a JB |
1379 | |
1380 | unlock_rtnl: | |
1381 | rtnl_unlock(); | |
1382 | ||
41ade00f JB |
1383 | return err; |
1384 | } | |
1385 | ||
1386 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
1387 | { | |
79c97e97 | 1388 | struct cfg80211_registered_device *rdev; |
fffd0934 | 1389 | int err; |
41ade00f | 1390 | struct net_device *dev; |
b9454e83 | 1391 | struct key_parse key; |
41ade00f JB |
1392 | u8 *mac_addr = NULL; |
1393 | ||
b9454e83 JB |
1394 | err = nl80211_parse_key(info, &key); |
1395 | if (err) | |
1396 | return err; | |
41ade00f | 1397 | |
b9454e83 | 1398 | if (!key.p.key) |
41ade00f JB |
1399 | return -EINVAL; |
1400 | ||
41ade00f JB |
1401 | if (info->attrs[NL80211_ATTR_MAC]) |
1402 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1403 | ||
3b85875a JB |
1404 | rtnl_lock(); |
1405 | ||
463d0183 | 1406 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1407 | if (err) |
3b85875a | 1408 | goto unlock_rtnl; |
41ade00f | 1409 | |
fffd0934 JB |
1410 | if (!rdev->ops->add_key) { |
1411 | err = -EOPNOTSUPP; | |
25e47c18 JB |
1412 | goto out; |
1413 | } | |
1414 | ||
fffd0934 JB |
1415 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { |
1416 | err = -EINVAL; | |
41ade00f JB |
1417 | goto out; |
1418 | } | |
1419 | ||
fffd0934 JB |
1420 | wdev_lock(dev->ieee80211_ptr); |
1421 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1422 | if (!err) | |
1423 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | |
1424 | mac_addr, &key.p); | |
1425 | wdev_unlock(dev->ieee80211_ptr); | |
41ade00f JB |
1426 | |
1427 | out: | |
79c97e97 | 1428 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1429 | dev_put(dev); |
3b85875a JB |
1430 | unlock_rtnl: |
1431 | rtnl_unlock(); | |
1432 | ||
41ade00f JB |
1433 | return err; |
1434 | } | |
1435 | ||
1436 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
1437 | { | |
79c97e97 | 1438 | struct cfg80211_registered_device *rdev; |
41ade00f JB |
1439 | int err; |
1440 | struct net_device *dev; | |
41ade00f | 1441 | u8 *mac_addr = NULL; |
b9454e83 | 1442 | struct key_parse key; |
41ade00f | 1443 | |
b9454e83 JB |
1444 | err = nl80211_parse_key(info, &key); |
1445 | if (err) | |
1446 | return err; | |
41ade00f JB |
1447 | |
1448 | if (info->attrs[NL80211_ATTR_MAC]) | |
1449 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1450 | ||
3b85875a JB |
1451 | rtnl_lock(); |
1452 | ||
463d0183 | 1453 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1454 | if (err) |
3b85875a | 1455 | goto unlock_rtnl; |
41ade00f | 1456 | |
79c97e97 | 1457 | if (!rdev->ops->del_key) { |
41ade00f JB |
1458 | err = -EOPNOTSUPP; |
1459 | goto out; | |
1460 | } | |
1461 | ||
fffd0934 JB |
1462 | wdev_lock(dev->ieee80211_ptr); |
1463 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1464 | if (!err) | |
1465 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); | |
41ade00f | 1466 | |
3d23e349 | 1467 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 1468 | if (!err) { |
b9454e83 | 1469 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 1470 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 1471 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
1472 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
1473 | } | |
1474 | #endif | |
fffd0934 | 1475 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 1476 | |
41ade00f | 1477 | out: |
79c97e97 | 1478 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1479 | dev_put(dev); |
3b85875a JB |
1480 | |
1481 | unlock_rtnl: | |
1482 | rtnl_unlock(); | |
1483 | ||
41ade00f JB |
1484 | return err; |
1485 | } | |
1486 | ||
ed1b6cc7 JB |
1487 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
1488 | { | |
1489 | int (*call)(struct wiphy *wiphy, struct net_device *dev, | |
1490 | struct beacon_parameters *info); | |
79c97e97 | 1491 | struct cfg80211_registered_device *rdev; |
ed1b6cc7 JB |
1492 | int err; |
1493 | struct net_device *dev; | |
1494 | struct beacon_parameters params; | |
1495 | int haveinfo = 0; | |
1496 | ||
f4a11bb0 JB |
1497 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
1498 | return -EINVAL; | |
1499 | ||
3b85875a JB |
1500 | rtnl_lock(); |
1501 | ||
463d0183 | 1502 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
ed1b6cc7 | 1503 | if (err) |
3b85875a | 1504 | goto unlock_rtnl; |
ed1b6cc7 | 1505 | |
eec60b03 JM |
1506 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
1507 | err = -EOPNOTSUPP; | |
1508 | goto out; | |
1509 | } | |
1510 | ||
ed1b6cc7 JB |
1511 | switch (info->genlhdr->cmd) { |
1512 | case NL80211_CMD_NEW_BEACON: | |
1513 | /* these are required for NEW_BEACON */ | |
1514 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
1515 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
1516 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1517 | err = -EINVAL; | |
1518 | goto out; | |
1519 | } | |
1520 | ||
79c97e97 | 1521 | call = rdev->ops->add_beacon; |
ed1b6cc7 JB |
1522 | break; |
1523 | case NL80211_CMD_SET_BEACON: | |
79c97e97 | 1524 | call = rdev->ops->set_beacon; |
ed1b6cc7 JB |
1525 | break; |
1526 | default: | |
1527 | WARN_ON(1); | |
1528 | err = -EOPNOTSUPP; | |
1529 | goto out; | |
1530 | } | |
1531 | ||
1532 | if (!call) { | |
1533 | err = -EOPNOTSUPP; | |
1534 | goto out; | |
1535 | } | |
1536 | ||
1537 | memset(¶ms, 0, sizeof(params)); | |
1538 | ||
1539 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
1540 | params.interval = | |
1541 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
1542 | haveinfo = 1; | |
1543 | } | |
1544 | ||
1545 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
1546 | params.dtim_period = | |
1547 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
1548 | haveinfo = 1; | |
1549 | } | |
1550 | ||
1551 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1552 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1553 | params.head_len = | |
1554 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1555 | haveinfo = 1; | |
1556 | } | |
1557 | ||
1558 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
1559 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1560 | params.tail_len = | |
1561 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1562 | haveinfo = 1; | |
1563 | } | |
1564 | ||
1565 | if (!haveinfo) { | |
1566 | err = -EINVAL; | |
1567 | goto out; | |
1568 | } | |
1569 | ||
79c97e97 | 1570 | err = call(&rdev->wiphy, dev, ¶ms); |
ed1b6cc7 JB |
1571 | |
1572 | out: | |
79c97e97 | 1573 | cfg80211_unlock_rdev(rdev); |
ed1b6cc7 | 1574 | dev_put(dev); |
3b85875a JB |
1575 | unlock_rtnl: |
1576 | rtnl_unlock(); | |
1577 | ||
ed1b6cc7 JB |
1578 | return err; |
1579 | } | |
1580 | ||
1581 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) | |
1582 | { | |
79c97e97 | 1583 | struct cfg80211_registered_device *rdev; |
ed1b6cc7 JB |
1584 | int err; |
1585 | struct net_device *dev; | |
1586 | ||
3b85875a JB |
1587 | rtnl_lock(); |
1588 | ||
463d0183 | 1589 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
ed1b6cc7 | 1590 | if (err) |
3b85875a | 1591 | goto unlock_rtnl; |
ed1b6cc7 | 1592 | |
79c97e97 | 1593 | if (!rdev->ops->del_beacon) { |
ed1b6cc7 JB |
1594 | err = -EOPNOTSUPP; |
1595 | goto out; | |
1596 | } | |
1597 | ||
eec60b03 JM |
1598 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
1599 | err = -EOPNOTSUPP; | |
1600 | goto out; | |
1601 | } | |
79c97e97 | 1602 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
ed1b6cc7 JB |
1603 | |
1604 | out: | |
79c97e97 | 1605 | cfg80211_unlock_rdev(rdev); |
ed1b6cc7 | 1606 | dev_put(dev); |
3b85875a JB |
1607 | unlock_rtnl: |
1608 | rtnl_unlock(); | |
1609 | ||
ed1b6cc7 JB |
1610 | return err; |
1611 | } | |
1612 | ||
5727ef1b JB |
1613 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
1614 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
1615 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
1616 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 1617 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
5727ef1b JB |
1618 | }; |
1619 | ||
eccb8e8f JB |
1620 | static int parse_station_flags(struct genl_info *info, |
1621 | struct station_parameters *params) | |
5727ef1b JB |
1622 | { |
1623 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 1624 | struct nlattr *nla; |
5727ef1b JB |
1625 | int flag; |
1626 | ||
eccb8e8f JB |
1627 | /* |
1628 | * Try parsing the new attribute first so userspace | |
1629 | * can specify both for older kernels. | |
1630 | */ | |
1631 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
1632 | if (nla) { | |
1633 | struct nl80211_sta_flag_update *sta_flags; | |
1634 | ||
1635 | sta_flags = nla_data(nla); | |
1636 | params->sta_flags_mask = sta_flags->mask; | |
1637 | params->sta_flags_set = sta_flags->set; | |
1638 | if ((params->sta_flags_mask | | |
1639 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
1640 | return -EINVAL; | |
1641 | return 0; | |
1642 | } | |
1643 | ||
1644 | /* if present, parse the old attribute */ | |
5727ef1b | 1645 | |
eccb8e8f | 1646 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
1647 | if (!nla) |
1648 | return 0; | |
1649 | ||
1650 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
1651 | nla, sta_flags_policy)) | |
1652 | return -EINVAL; | |
1653 | ||
eccb8e8f JB |
1654 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
1655 | params->sta_flags_mask &= ~1; | |
5727ef1b JB |
1656 | |
1657 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) | |
1658 | if (flags[flag]) | |
eccb8e8f | 1659 | params->sta_flags_set |= (1<<flag); |
5727ef1b JB |
1660 | |
1661 | return 0; | |
1662 | } | |
1663 | ||
fd5b74dc JB |
1664 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1665 | int flags, struct net_device *dev, | |
98b62183 | 1666 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
1667 | { |
1668 | void *hdr; | |
420e7fab HR |
1669 | struct nlattr *sinfoattr, *txrate; |
1670 | u16 bitrate; | |
fd5b74dc JB |
1671 | |
1672 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
1673 | if (!hdr) | |
1674 | return -1; | |
1675 | ||
1676 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1677 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1678 | ||
f5ea9120 JB |
1679 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
1680 | ||
2ec600d6 LCC |
1681 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
1682 | if (!sinfoattr) | |
fd5b74dc | 1683 | goto nla_put_failure; |
2ec600d6 LCC |
1684 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
1685 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
1686 | sinfo->inactive_time); | |
1687 | if (sinfo->filled & STATION_INFO_RX_BYTES) | |
1688 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, | |
1689 | sinfo->rx_bytes); | |
1690 | if (sinfo->filled & STATION_INFO_TX_BYTES) | |
1691 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, | |
1692 | sinfo->tx_bytes); | |
1693 | if (sinfo->filled & STATION_INFO_LLID) | |
1694 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, | |
1695 | sinfo->llid); | |
1696 | if (sinfo->filled & STATION_INFO_PLID) | |
1697 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, | |
1698 | sinfo->plid); | |
1699 | if (sinfo->filled & STATION_INFO_PLINK_STATE) | |
1700 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, | |
1701 | sinfo->plink_state); | |
420e7fab HR |
1702 | if (sinfo->filled & STATION_INFO_SIGNAL) |
1703 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | |
1704 | sinfo->signal); | |
1705 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { | |
1706 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); | |
1707 | if (!txrate) | |
1708 | goto nla_put_failure; | |
1709 | ||
254416aa JL |
1710 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
1711 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); | |
420e7fab HR |
1712 | if (bitrate > 0) |
1713 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | |
2ec600d6 | 1714 | |
420e7fab HR |
1715 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
1716 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, | |
1717 | sinfo->txrate.mcs); | |
1718 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | |
1719 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | |
1720 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) | |
1721 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | |
1722 | ||
1723 | nla_nest_end(msg, txrate); | |
1724 | } | |
98c8a60a JM |
1725 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
1726 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, | |
1727 | sinfo->rx_packets); | |
1728 | if (sinfo->filled & STATION_INFO_TX_PACKETS) | |
1729 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, | |
1730 | sinfo->tx_packets); | |
2ec600d6 | 1731 | nla_nest_end(msg, sinfoattr); |
fd5b74dc JB |
1732 | |
1733 | return genlmsg_end(msg, hdr); | |
1734 | ||
1735 | nla_put_failure: | |
bc3ed28c TG |
1736 | genlmsg_cancel(msg, hdr); |
1737 | return -EMSGSIZE; | |
fd5b74dc JB |
1738 | } |
1739 | ||
2ec600d6 | 1740 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 1741 | struct netlink_callback *cb) |
2ec600d6 | 1742 | { |
2ec600d6 LCC |
1743 | struct station_info sinfo; |
1744 | struct cfg80211_registered_device *dev; | |
bba95fef | 1745 | struct net_device *netdev; |
2ec600d6 | 1746 | u8 mac_addr[ETH_ALEN]; |
bba95fef JB |
1747 | int ifidx = cb->args[0]; |
1748 | int sta_idx = cb->args[1]; | |
2ec600d6 | 1749 | int err; |
2ec600d6 | 1750 | |
a043897a HS |
1751 | if (!ifidx) |
1752 | ifidx = nl80211_get_ifidx(cb); | |
1753 | if (ifidx < 0) | |
1754 | return ifidx; | |
2ec600d6 | 1755 | |
3b85875a JB |
1756 | rtnl_lock(); |
1757 | ||
463d0183 | 1758 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
3b85875a JB |
1759 | if (!netdev) { |
1760 | err = -ENODEV; | |
1761 | goto out_rtnl; | |
1762 | } | |
2ec600d6 | 1763 | |
463d0183 | 1764 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
bba95fef JB |
1765 | if (IS_ERR(dev)) { |
1766 | err = PTR_ERR(dev); | |
3b85875a | 1767 | goto out_rtnl; |
bba95fef JB |
1768 | } |
1769 | ||
1770 | if (!dev->ops->dump_station) { | |
eec60b03 | 1771 | err = -EOPNOTSUPP; |
bba95fef JB |
1772 | goto out_err; |
1773 | } | |
1774 | ||
bba95fef JB |
1775 | while (1) { |
1776 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, | |
1777 | mac_addr, &sinfo); | |
1778 | if (err == -ENOENT) | |
1779 | break; | |
1780 | if (err) | |
3b85875a | 1781 | goto out_err; |
bba95fef JB |
1782 | |
1783 | if (nl80211_send_station(skb, | |
1784 | NETLINK_CB(cb->skb).pid, | |
1785 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
1786 | netdev, mac_addr, | |
1787 | &sinfo) < 0) | |
1788 | goto out; | |
1789 | ||
1790 | sta_idx++; | |
1791 | } | |
1792 | ||
1793 | ||
1794 | out: | |
1795 | cb->args[1] = sta_idx; | |
1796 | err = skb->len; | |
bba95fef | 1797 | out_err: |
4d0c8aea | 1798 | cfg80211_unlock_rdev(dev); |
3b85875a JB |
1799 | out_rtnl: |
1800 | rtnl_unlock(); | |
bba95fef JB |
1801 | |
1802 | return err; | |
2ec600d6 | 1803 | } |
fd5b74dc | 1804 | |
5727ef1b JB |
1805 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
1806 | { | |
79c97e97 | 1807 | struct cfg80211_registered_device *rdev; |
fd5b74dc JB |
1808 | int err; |
1809 | struct net_device *dev; | |
2ec600d6 | 1810 | struct station_info sinfo; |
fd5b74dc JB |
1811 | struct sk_buff *msg; |
1812 | u8 *mac_addr = NULL; | |
1813 | ||
2ec600d6 | 1814 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
1815 | |
1816 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1817 | return -EINVAL; | |
1818 | ||
1819 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1820 | ||
3b85875a JB |
1821 | rtnl_lock(); |
1822 | ||
463d0183 | 1823 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
fd5b74dc | 1824 | if (err) |
3b85875a | 1825 | goto out_rtnl; |
fd5b74dc | 1826 | |
79c97e97 | 1827 | if (!rdev->ops->get_station) { |
fd5b74dc JB |
1828 | err = -EOPNOTSUPP; |
1829 | goto out; | |
1830 | } | |
1831 | ||
79c97e97 | 1832 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
2ec600d6 LCC |
1833 | if (err) |
1834 | goto out; | |
1835 | ||
fd2120ca | 1836 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc JB |
1837 | if (!msg) |
1838 | goto out; | |
1839 | ||
1840 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
2ec600d6 | 1841 | dev, mac_addr, &sinfo) < 0) |
fd5b74dc JB |
1842 | goto out_free; |
1843 | ||
134e6375 | 1844 | err = genlmsg_reply(msg, info); |
fd5b74dc JB |
1845 | goto out; |
1846 | ||
1847 | out_free: | |
1848 | nlmsg_free(msg); | |
fd5b74dc | 1849 | out: |
79c97e97 | 1850 | cfg80211_unlock_rdev(rdev); |
fd5b74dc | 1851 | dev_put(dev); |
3b85875a JB |
1852 | out_rtnl: |
1853 | rtnl_unlock(); | |
1854 | ||
fd5b74dc | 1855 | return err; |
5727ef1b JB |
1856 | } |
1857 | ||
1858 | /* | |
c258d2de | 1859 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 1860 | */ |
463d0183 | 1861 | static int get_vlan(struct genl_info *info, |
5727ef1b JB |
1862 | struct cfg80211_registered_device *rdev, |
1863 | struct net_device **vlan) | |
1864 | { | |
463d0183 | 1865 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
5727ef1b JB |
1866 | *vlan = NULL; |
1867 | ||
1868 | if (vlanattr) { | |
463d0183 JB |
1869 | *vlan = dev_get_by_index(genl_info_net(info), |
1870 | nla_get_u32(vlanattr)); | |
5727ef1b JB |
1871 | if (!*vlan) |
1872 | return -ENODEV; | |
1873 | if (!(*vlan)->ieee80211_ptr) | |
1874 | return -EINVAL; | |
1875 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) | |
1876 | return -EINVAL; | |
c258d2de FF |
1877 | if (!netif_running(*vlan)) |
1878 | return -ENETDOWN; | |
5727ef1b JB |
1879 | } |
1880 | return 0; | |
1881 | } | |
1882 | ||
1883 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
1884 | { | |
79c97e97 | 1885 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
1886 | int err; |
1887 | struct net_device *dev; | |
1888 | struct station_parameters params; | |
1889 | u8 *mac_addr = NULL; | |
1890 | ||
1891 | memset(¶ms, 0, sizeof(params)); | |
1892 | ||
1893 | params.listen_interval = -1; | |
1894 | ||
1895 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
1896 | return -EINVAL; | |
1897 | ||
1898 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1899 | return -EINVAL; | |
1900 | ||
1901 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1902 | ||
1903 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
1904 | params.supported_rates = | |
1905 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1906 | params.supported_rates_len = | |
1907 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1908 | } | |
1909 | ||
1910 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
1911 | params.listen_interval = | |
1912 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
1913 | ||
36aedc90 JM |
1914 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
1915 | params.ht_capa = | |
1916 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
1917 | ||
eccb8e8f | 1918 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
1919 | return -EINVAL; |
1920 | ||
2ec600d6 LCC |
1921 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
1922 | params.plink_action = | |
1923 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
1924 | ||
3b85875a JB |
1925 | rtnl_lock(); |
1926 | ||
463d0183 | 1927 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 1928 | if (err) |
3b85875a | 1929 | goto out_rtnl; |
5727ef1b | 1930 | |
463d0183 | 1931 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 1932 | if (err) |
034d655e | 1933 | goto out; |
a97f4424 JB |
1934 | |
1935 | /* validate settings */ | |
1936 | err = 0; | |
1937 | ||
1938 | switch (dev->ieee80211_ptr->iftype) { | |
1939 | case NL80211_IFTYPE_AP: | |
1940 | case NL80211_IFTYPE_AP_VLAN: | |
1941 | /* disallow mesh-specific things */ | |
1942 | if (params.plink_action) | |
1943 | err = -EINVAL; | |
1944 | break; | |
1945 | case NL80211_IFTYPE_STATION: | |
1946 | /* disallow everything but AUTHORIZED flag */ | |
1947 | if (params.plink_action) | |
1948 | err = -EINVAL; | |
1949 | if (params.vlan) | |
1950 | err = -EINVAL; | |
1951 | if (params.supported_rates) | |
1952 | err = -EINVAL; | |
1953 | if (params.ht_capa) | |
1954 | err = -EINVAL; | |
1955 | if (params.listen_interval >= 0) | |
1956 | err = -EINVAL; | |
1957 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
1958 | err = -EINVAL; | |
1959 | break; | |
1960 | case NL80211_IFTYPE_MESH_POINT: | |
1961 | /* disallow things mesh doesn't support */ | |
1962 | if (params.vlan) | |
1963 | err = -EINVAL; | |
1964 | if (params.ht_capa) | |
1965 | err = -EINVAL; | |
1966 | if (params.listen_interval >= 0) | |
1967 | err = -EINVAL; | |
1968 | if (params.supported_rates) | |
1969 | err = -EINVAL; | |
1970 | if (params.sta_flags_mask) | |
1971 | err = -EINVAL; | |
1972 | break; | |
1973 | default: | |
1974 | err = -EINVAL; | |
034d655e JB |
1975 | } |
1976 | ||
5727ef1b JB |
1977 | if (err) |
1978 | goto out; | |
1979 | ||
79c97e97 | 1980 | if (!rdev->ops->change_station) { |
5727ef1b JB |
1981 | err = -EOPNOTSUPP; |
1982 | goto out; | |
1983 | } | |
1984 | ||
79c97e97 | 1985 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
1986 | |
1987 | out: | |
1988 | if (params.vlan) | |
1989 | dev_put(params.vlan); | |
79c97e97 | 1990 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 1991 | dev_put(dev); |
3b85875a JB |
1992 | out_rtnl: |
1993 | rtnl_unlock(); | |
1994 | ||
5727ef1b JB |
1995 | return err; |
1996 | } | |
1997 | ||
1998 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
1999 | { | |
79c97e97 | 2000 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
2001 | int err; |
2002 | struct net_device *dev; | |
2003 | struct station_parameters params; | |
2004 | u8 *mac_addr = NULL; | |
2005 | ||
2006 | memset(¶ms, 0, sizeof(params)); | |
2007 | ||
2008 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2009 | return -EINVAL; | |
2010 | ||
5727ef1b JB |
2011 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
2012 | return -EINVAL; | |
2013 | ||
2014 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
2015 | return -EINVAL; | |
2016 | ||
0e956c13 TLSC |
2017 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
2018 | return -EINVAL; | |
2019 | ||
5727ef1b JB |
2020 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2021 | params.supported_rates = | |
2022 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2023 | params.supported_rates_len = | |
2024 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2025 | params.listen_interval = | |
2026 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 2027 | |
0e956c13 TLSC |
2028 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
2029 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
2030 | return -EINVAL; | |
51b50fbe | 2031 | |
36aedc90 JM |
2032 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2033 | params.ht_capa = | |
2034 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 2035 | |
eccb8e8f | 2036 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2037 | return -EINVAL; |
2038 | ||
3b85875a JB |
2039 | rtnl_lock(); |
2040 | ||
463d0183 | 2041 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 2042 | if (err) |
3b85875a | 2043 | goto out_rtnl; |
5727ef1b | 2044 | |
0e956c13 TLSC |
2045 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
2046 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { | |
2047 | err = -EINVAL; | |
2048 | goto out; | |
2049 | } | |
2050 | ||
463d0183 | 2051 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2052 | if (err) |
e80cf853 | 2053 | goto out; |
a97f4424 JB |
2054 | |
2055 | /* validate settings */ | |
2056 | err = 0; | |
2057 | ||
79c97e97 | 2058 | if (!rdev->ops->add_station) { |
5727ef1b JB |
2059 | err = -EOPNOTSUPP; |
2060 | goto out; | |
2061 | } | |
2062 | ||
35a8efe1 JM |
2063 | if (!netif_running(dev)) { |
2064 | err = -ENETDOWN; | |
2065 | goto out; | |
2066 | } | |
2067 | ||
79c97e97 | 2068 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2069 | |
2070 | out: | |
2071 | if (params.vlan) | |
2072 | dev_put(params.vlan); | |
79c97e97 | 2073 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 2074 | dev_put(dev); |
3b85875a JB |
2075 | out_rtnl: |
2076 | rtnl_unlock(); | |
2077 | ||
5727ef1b JB |
2078 | return err; |
2079 | } | |
2080 | ||
2081 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
2082 | { | |
79c97e97 | 2083 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
2084 | int err; |
2085 | struct net_device *dev; | |
2086 | u8 *mac_addr = NULL; | |
2087 | ||
2088 | if (info->attrs[NL80211_ATTR_MAC]) | |
2089 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2090 | ||
3b85875a JB |
2091 | rtnl_lock(); |
2092 | ||
463d0183 | 2093 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 2094 | if (err) |
3b85875a | 2095 | goto out_rtnl; |
5727ef1b | 2096 | |
e80cf853 | 2097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
0e956c13 | 2098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { |
e80cf853 JB |
2099 | err = -EINVAL; |
2100 | goto out; | |
2101 | } | |
2102 | ||
79c97e97 | 2103 | if (!rdev->ops->del_station) { |
5727ef1b JB |
2104 | err = -EOPNOTSUPP; |
2105 | goto out; | |
2106 | } | |
2107 | ||
79c97e97 | 2108 | err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
2109 | |
2110 | out: | |
79c97e97 | 2111 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 2112 | dev_put(dev); |
3b85875a JB |
2113 | out_rtnl: |
2114 | rtnl_unlock(); | |
2115 | ||
5727ef1b JB |
2116 | return err; |
2117 | } | |
2118 | ||
2ec600d6 LCC |
2119 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
2120 | int flags, struct net_device *dev, | |
2121 | u8 *dst, u8 *next_hop, | |
2122 | struct mpath_info *pinfo) | |
2123 | { | |
2124 | void *hdr; | |
2125 | struct nlattr *pinfoattr; | |
2126 | ||
2127 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2128 | if (!hdr) | |
2129 | return -1; | |
2130 | ||
2131 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2132 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
2133 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); | |
2134 | ||
f5ea9120 JB |
2135 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
2136 | ||
2ec600d6 LCC |
2137 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
2138 | if (!pinfoattr) | |
2139 | goto nla_put_failure; | |
2140 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) | |
2141 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
2142 | pinfo->frame_qlen); | |
d19b3bf6 RP |
2143 | if (pinfo->filled & MPATH_INFO_SN) |
2144 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, | |
2145 | pinfo->sn); | |
2ec600d6 LCC |
2146 | if (pinfo->filled & MPATH_INFO_METRIC) |
2147 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, | |
2148 | pinfo->metric); | |
2149 | if (pinfo->filled & MPATH_INFO_EXPTIME) | |
2150 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, | |
2151 | pinfo->exptime); | |
2152 | if (pinfo->filled & MPATH_INFO_FLAGS) | |
2153 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, | |
2154 | pinfo->flags); | |
2155 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) | |
2156 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
2157 | pinfo->discovery_timeout); | |
2158 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) | |
2159 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
2160 | pinfo->discovery_retries); | |
2161 | ||
2162 | nla_nest_end(msg, pinfoattr); | |
2163 | ||
2164 | return genlmsg_end(msg, hdr); | |
2165 | ||
2166 | nla_put_failure: | |
bc3ed28c TG |
2167 | genlmsg_cancel(msg, hdr); |
2168 | return -EMSGSIZE; | |
2ec600d6 LCC |
2169 | } |
2170 | ||
2171 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 2172 | struct netlink_callback *cb) |
2ec600d6 | 2173 | { |
2ec600d6 LCC |
2174 | struct mpath_info pinfo; |
2175 | struct cfg80211_registered_device *dev; | |
bba95fef | 2176 | struct net_device *netdev; |
2ec600d6 LCC |
2177 | u8 dst[ETH_ALEN]; |
2178 | u8 next_hop[ETH_ALEN]; | |
bba95fef JB |
2179 | int ifidx = cb->args[0]; |
2180 | int path_idx = cb->args[1]; | |
2ec600d6 | 2181 | int err; |
2ec600d6 | 2182 | |
a043897a HS |
2183 | if (!ifidx) |
2184 | ifidx = nl80211_get_ifidx(cb); | |
2185 | if (ifidx < 0) | |
2186 | return ifidx; | |
bba95fef | 2187 | |
3b85875a JB |
2188 | rtnl_lock(); |
2189 | ||
463d0183 | 2190 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
3b85875a JB |
2191 | if (!netdev) { |
2192 | err = -ENODEV; | |
2193 | goto out_rtnl; | |
2194 | } | |
bba95fef | 2195 | |
463d0183 | 2196 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
bba95fef JB |
2197 | if (IS_ERR(dev)) { |
2198 | err = PTR_ERR(dev); | |
3b85875a | 2199 | goto out_rtnl; |
bba95fef JB |
2200 | } |
2201 | ||
2202 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 2203 | err = -EOPNOTSUPP; |
bba95fef JB |
2204 | goto out_err; |
2205 | } | |
2206 | ||
eec60b03 JM |
2207 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2208 | err = -EOPNOTSUPP; | |
0448b5fc | 2209 | goto out_err; |
eec60b03 JM |
2210 | } |
2211 | ||
bba95fef JB |
2212 | while (1) { |
2213 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
2214 | dst, next_hop, &pinfo); | |
2215 | if (err == -ENOENT) | |
2ec600d6 | 2216 | break; |
bba95fef | 2217 | if (err) |
3b85875a | 2218 | goto out_err; |
2ec600d6 | 2219 | |
bba95fef JB |
2220 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
2221 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2222 | netdev, dst, next_hop, | |
2223 | &pinfo) < 0) | |
2224 | goto out; | |
2ec600d6 | 2225 | |
bba95fef | 2226 | path_idx++; |
2ec600d6 | 2227 | } |
2ec600d6 | 2228 | |
2ec600d6 | 2229 | |
bba95fef JB |
2230 | out: |
2231 | cb->args[1] = path_idx; | |
2232 | err = skb->len; | |
bba95fef | 2233 | out_err: |
4d0c8aea | 2234 | cfg80211_unlock_rdev(dev); |
3b85875a JB |
2235 | out_rtnl: |
2236 | rtnl_unlock(); | |
bba95fef JB |
2237 | |
2238 | return err; | |
2ec600d6 LCC |
2239 | } |
2240 | ||
2241 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
2242 | { | |
79c97e97 | 2243 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2244 | int err; |
2245 | struct net_device *dev; | |
2246 | struct mpath_info pinfo; | |
2247 | struct sk_buff *msg; | |
2248 | u8 *dst = NULL; | |
2249 | u8 next_hop[ETH_ALEN]; | |
2250 | ||
2251 | memset(&pinfo, 0, sizeof(pinfo)); | |
2252 | ||
2253 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2254 | return -EINVAL; | |
2255 | ||
2256 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2257 | ||
3b85875a JB |
2258 | rtnl_lock(); |
2259 | ||
463d0183 | 2260 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2261 | if (err) |
3b85875a | 2262 | goto out_rtnl; |
2ec600d6 | 2263 | |
79c97e97 | 2264 | if (!rdev->ops->get_mpath) { |
2ec600d6 LCC |
2265 | err = -EOPNOTSUPP; |
2266 | goto out; | |
2267 | } | |
2268 | ||
eec60b03 JM |
2269 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2270 | err = -EOPNOTSUPP; | |
2271 | goto out; | |
2272 | } | |
2273 | ||
79c97e97 | 2274 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 LCC |
2275 | if (err) |
2276 | goto out; | |
2277 | ||
fd2120ca | 2278 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 LCC |
2279 | if (!msg) |
2280 | goto out; | |
2281 | ||
2282 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
2283 | dev, dst, next_hop, &pinfo) < 0) | |
2284 | goto out_free; | |
2285 | ||
134e6375 | 2286 | err = genlmsg_reply(msg, info); |
2ec600d6 LCC |
2287 | goto out; |
2288 | ||
2289 | out_free: | |
2290 | nlmsg_free(msg); | |
2ec600d6 | 2291 | out: |
79c97e97 | 2292 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2293 | dev_put(dev); |
3b85875a JB |
2294 | out_rtnl: |
2295 | rtnl_unlock(); | |
2296 | ||
2ec600d6 LCC |
2297 | return err; |
2298 | } | |
2299 | ||
2300 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
2301 | { | |
79c97e97 | 2302 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2303 | int err; |
2304 | struct net_device *dev; | |
2305 | u8 *dst = NULL; | |
2306 | u8 *next_hop = NULL; | |
2307 | ||
2308 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2309 | return -EINVAL; | |
2310 | ||
2311 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2312 | return -EINVAL; | |
2313 | ||
2314 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2315 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2316 | ||
3b85875a JB |
2317 | rtnl_lock(); |
2318 | ||
463d0183 | 2319 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2320 | if (err) |
3b85875a | 2321 | goto out_rtnl; |
2ec600d6 | 2322 | |
79c97e97 | 2323 | if (!rdev->ops->change_mpath) { |
2ec600d6 LCC |
2324 | err = -EOPNOTSUPP; |
2325 | goto out; | |
2326 | } | |
2327 | ||
eec60b03 JM |
2328 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2329 | err = -EOPNOTSUPP; | |
2330 | goto out; | |
2331 | } | |
2332 | ||
35a8efe1 JM |
2333 | if (!netif_running(dev)) { |
2334 | err = -ENETDOWN; | |
2335 | goto out; | |
2336 | } | |
2337 | ||
79c97e97 | 2338 | err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2339 | |
2340 | out: | |
79c97e97 | 2341 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2342 | dev_put(dev); |
3b85875a JB |
2343 | out_rtnl: |
2344 | rtnl_unlock(); | |
2345 | ||
2ec600d6 LCC |
2346 | return err; |
2347 | } | |
2348 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | |
2349 | { | |
79c97e97 | 2350 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2351 | int err; |
2352 | struct net_device *dev; | |
2353 | u8 *dst = NULL; | |
2354 | u8 *next_hop = NULL; | |
2355 | ||
2356 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2357 | return -EINVAL; | |
2358 | ||
2359 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2360 | return -EINVAL; | |
2361 | ||
2362 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2363 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2364 | ||
3b85875a JB |
2365 | rtnl_lock(); |
2366 | ||
463d0183 | 2367 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2368 | if (err) |
3b85875a | 2369 | goto out_rtnl; |
2ec600d6 | 2370 | |
79c97e97 | 2371 | if (!rdev->ops->add_mpath) { |
2ec600d6 LCC |
2372 | err = -EOPNOTSUPP; |
2373 | goto out; | |
2374 | } | |
2375 | ||
eec60b03 JM |
2376 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2377 | err = -EOPNOTSUPP; | |
2378 | goto out; | |
2379 | } | |
2380 | ||
35a8efe1 JM |
2381 | if (!netif_running(dev)) { |
2382 | err = -ENETDOWN; | |
2383 | goto out; | |
2384 | } | |
2385 | ||
79c97e97 | 2386 | err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2387 | |
2388 | out: | |
79c97e97 | 2389 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2390 | dev_put(dev); |
3b85875a JB |
2391 | out_rtnl: |
2392 | rtnl_unlock(); | |
2393 | ||
2ec600d6 LCC |
2394 | return err; |
2395 | } | |
2396 | ||
2397 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
2398 | { | |
79c97e97 | 2399 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2400 | int err; |
2401 | struct net_device *dev; | |
2402 | u8 *dst = NULL; | |
2403 | ||
2404 | if (info->attrs[NL80211_ATTR_MAC]) | |
2405 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2406 | ||
3b85875a JB |
2407 | rtnl_lock(); |
2408 | ||
463d0183 | 2409 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2410 | if (err) |
3b85875a | 2411 | goto out_rtnl; |
2ec600d6 | 2412 | |
79c97e97 | 2413 | if (!rdev->ops->del_mpath) { |
2ec600d6 LCC |
2414 | err = -EOPNOTSUPP; |
2415 | goto out; | |
2416 | } | |
2417 | ||
79c97e97 | 2418 | err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
2419 | |
2420 | out: | |
79c97e97 | 2421 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2422 | dev_put(dev); |
3b85875a JB |
2423 | out_rtnl: |
2424 | rtnl_unlock(); | |
2425 | ||
2ec600d6 LCC |
2426 | return err; |
2427 | } | |
2428 | ||
9f1ba906 JM |
2429 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2430 | { | |
79c97e97 | 2431 | struct cfg80211_registered_device *rdev; |
9f1ba906 JM |
2432 | int err; |
2433 | struct net_device *dev; | |
2434 | struct bss_parameters params; | |
2435 | ||
2436 | memset(¶ms, 0, sizeof(params)); | |
2437 | /* default to not changing parameters */ | |
2438 | params.use_cts_prot = -1; | |
2439 | params.use_short_preamble = -1; | |
2440 | params.use_short_slot_time = -1; | |
2441 | ||
2442 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
2443 | params.use_cts_prot = | |
2444 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
2445 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
2446 | params.use_short_preamble = | |
2447 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
2448 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
2449 | params.use_short_slot_time = | |
2450 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
2451 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
2452 | params.basic_rates = | |
2453 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2454 | params.basic_rates_len = | |
2455 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2456 | } | |
9f1ba906 | 2457 | |
3b85875a JB |
2458 | rtnl_lock(); |
2459 | ||
463d0183 | 2460 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
9f1ba906 | 2461 | if (err) |
3b85875a | 2462 | goto out_rtnl; |
9f1ba906 | 2463 | |
79c97e97 | 2464 | if (!rdev->ops->change_bss) { |
9f1ba906 JM |
2465 | err = -EOPNOTSUPP; |
2466 | goto out; | |
2467 | } | |
2468 | ||
eec60b03 JM |
2469 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
2470 | err = -EOPNOTSUPP; | |
2471 | goto out; | |
2472 | } | |
2473 | ||
79c97e97 | 2474 | err = rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
2475 | |
2476 | out: | |
79c97e97 | 2477 | cfg80211_unlock_rdev(rdev); |
9f1ba906 | 2478 | dev_put(dev); |
3b85875a JB |
2479 | out_rtnl: |
2480 | rtnl_unlock(); | |
2481 | ||
9f1ba906 JM |
2482 | return err; |
2483 | } | |
2484 | ||
b54452b0 | 2485 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
2486 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
2487 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
2488 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
2489 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
2490 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
2491 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
2492 | }; | |
2493 | ||
2494 | static int parse_reg_rule(struct nlattr *tb[], | |
2495 | struct ieee80211_reg_rule *reg_rule) | |
2496 | { | |
2497 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
2498 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
2499 | ||
2500 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
2501 | return -EINVAL; | |
2502 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
2503 | return -EINVAL; | |
2504 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
2505 | return -EINVAL; | |
2506 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
2507 | return -EINVAL; | |
2508 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
2509 | return -EINVAL; | |
2510 | ||
2511 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
2512 | ||
2513 | freq_range->start_freq_khz = | |
2514 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
2515 | freq_range->end_freq_khz = | |
2516 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
2517 | freq_range->max_bandwidth_khz = | |
2518 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
2519 | ||
2520 | power_rule->max_eirp = | |
2521 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
2522 | ||
2523 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
2524 | power_rule->max_antenna_gain = | |
2525 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
2526 | ||
2527 | return 0; | |
2528 | } | |
2529 | ||
2530 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
2531 | { | |
2532 | int r; | |
2533 | char *data = NULL; | |
2534 | ||
80778f18 LR |
2535 | /* |
2536 | * You should only get this when cfg80211 hasn't yet initialized | |
2537 | * completely when built-in to the kernel right between the time | |
2538 | * window between nl80211_init() and regulatory_init(), if that is | |
2539 | * even possible. | |
2540 | */ | |
2541 | mutex_lock(&cfg80211_mutex); | |
2542 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
2543 | mutex_unlock(&cfg80211_mutex); |
2544 | return -EINPROGRESS; | |
80778f18 | 2545 | } |
fe33eb39 | 2546 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 2547 | |
fe33eb39 LR |
2548 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
2549 | return -EINVAL; | |
b2e1b302 LR |
2550 | |
2551 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2552 | ||
fe33eb39 LR |
2553 | r = regulatory_hint_user(data); |
2554 | ||
b2e1b302 LR |
2555 | return r; |
2556 | } | |
2557 | ||
93da9cc1 | 2558 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
2559 | struct genl_info *info) | |
2560 | { | |
79c97e97 | 2561 | struct cfg80211_registered_device *rdev; |
93da9cc1 | 2562 | struct mesh_config cur_params; |
2563 | int err; | |
2564 | struct net_device *dev; | |
2565 | void *hdr; | |
2566 | struct nlattr *pinfoattr; | |
2567 | struct sk_buff *msg; | |
2568 | ||
3b85875a JB |
2569 | rtnl_lock(); |
2570 | ||
93da9cc1 | 2571 | /* Look up our device */ |
463d0183 | 2572 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
93da9cc1 | 2573 | if (err) |
3b85875a | 2574 | goto out_rtnl; |
93da9cc1 | 2575 | |
79c97e97 | 2576 | if (!rdev->ops->get_mesh_params) { |
f3f92586 JM |
2577 | err = -EOPNOTSUPP; |
2578 | goto out; | |
2579 | } | |
2580 | ||
93da9cc1 | 2581 | /* Get the mesh params */ |
79c97e97 | 2582 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); |
93da9cc1 | 2583 | if (err) |
2584 | goto out; | |
2585 | ||
2586 | /* Draw up a netlink message to send back */ | |
fd2120ca | 2587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
93da9cc1 | 2588 | if (!msg) { |
2589 | err = -ENOBUFS; | |
2590 | goto out; | |
2591 | } | |
2592 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2593 | NL80211_CMD_GET_MESH_PARAMS); | |
2594 | if (!hdr) | |
2595 | goto nla_put_failure; | |
2596 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); | |
2597 | if (!pinfoattr) | |
2598 | goto nla_put_failure; | |
2599 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2600 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
2601 | cur_params.dot11MeshRetryTimeout); | |
2602 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
2603 | cur_params.dot11MeshConfirmTimeout); | |
2604 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
2605 | cur_params.dot11MeshHoldingTimeout); | |
2606 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
2607 | cur_params.dot11MeshMaxPeerLinks); | |
2608 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
2609 | cur_params.dot11MeshMaxRetries); | |
2610 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | |
2611 | cur_params.dot11MeshTTL); | |
2612 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
2613 | cur_params.auto_open_plinks); | |
2614 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2615 | cur_params.dot11MeshHWMPmaxPREQretries); | |
2616 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
2617 | cur_params.path_refresh_time); | |
2618 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2619 | cur_params.min_discovery_timeout); | |
2620 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2621 | cur_params.dot11MeshHWMPactivePathTimeout); | |
2622 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2623 | cur_params.dot11MeshHWMPpreqMinInterval); | |
2624 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2625 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | |
63c5723b RP |
2626 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
2627 | cur_params.dot11MeshHWMPRootMode); | |
93da9cc1 | 2628 | nla_nest_end(msg, pinfoattr); |
2629 | genlmsg_end(msg, hdr); | |
134e6375 | 2630 | err = genlmsg_reply(msg, info); |
93da9cc1 | 2631 | goto out; |
2632 | ||
3b85875a | 2633 | nla_put_failure: |
93da9cc1 | 2634 | genlmsg_cancel(msg, hdr); |
2635 | err = -EMSGSIZE; | |
3b85875a | 2636 | out: |
93da9cc1 | 2637 | /* Cleanup */ |
79c97e97 | 2638 | cfg80211_unlock_rdev(rdev); |
93da9cc1 | 2639 | dev_put(dev); |
3b85875a JB |
2640 | out_rtnl: |
2641 | rtnl_unlock(); | |
2642 | ||
93da9cc1 | 2643 | return err; |
2644 | } | |
2645 | ||
2646 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | |
2647 | do {\ | |
2648 | if (table[attr_num]) {\ | |
2649 | cfg.param = nla_fn(table[attr_num]); \ | |
2650 | mask |= (1 << (attr_num - 1)); \ | |
2651 | } \ | |
2652 | } while (0);\ | |
2653 | ||
b54452b0 | 2654 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 2655 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
2656 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
2657 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
2658 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
2659 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
2660 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
2661 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | |
2662 | ||
2663 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
2664 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
2665 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
2666 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
2667 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
2668 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | |
2669 | }; | |
2670 | ||
2671 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | |
2672 | { | |
2673 | int err; | |
2674 | u32 mask; | |
79c97e97 | 2675 | struct cfg80211_registered_device *rdev; |
93da9cc1 | 2676 | struct net_device *dev; |
2677 | struct mesh_config cfg; | |
2678 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | |
2679 | struct nlattr *parent_attr; | |
2680 | ||
2681 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; | |
2682 | if (!parent_attr) | |
2683 | return -EINVAL; | |
2684 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
2685 | parent_attr, nl80211_meshconf_params_policy)) | |
2686 | return -EINVAL; | |
2687 | ||
3b85875a JB |
2688 | rtnl_lock(); |
2689 | ||
463d0183 | 2690 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
93da9cc1 | 2691 | if (err) |
3b85875a | 2692 | goto out_rtnl; |
93da9cc1 | 2693 | |
79c97e97 | 2694 | if (!rdev->ops->set_mesh_params) { |
f3f92586 JM |
2695 | err = -EOPNOTSUPP; |
2696 | goto out; | |
2697 | } | |
2698 | ||
93da9cc1 | 2699 | /* This makes sure that there aren't more than 32 mesh config |
2700 | * parameters (otherwise our bitfield scheme would not work.) */ | |
2701 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
2702 | ||
2703 | /* Fill in the params struct */ | |
2704 | mask = 0; | |
2705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, | |
2706 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
2707 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
2708 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
2709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
2710 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
2711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
2712 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
2713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
2714 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
2715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
2716 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
2717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, | |
2718 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
2719 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | |
2720 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2721 | nla_get_u8); | |
2722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
2723 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
2724 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
2725 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2726 | nla_get_u16); | |
2727 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
2728 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2729 | nla_get_u32); | |
2730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
2731 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2732 | nla_get_u16); | |
2733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
2734 | dot11MeshHWMPnetDiameterTraversalTime, | |
2735 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2736 | nla_get_u16); | |
63c5723b RP |
2737 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
2738 | dot11MeshHWMPRootMode, mask, | |
2739 | NL80211_MESHCONF_HWMP_ROOTMODE, | |
2740 | nla_get_u8); | |
93da9cc1 | 2741 | |
2742 | /* Apply changes */ | |
79c97e97 | 2743 | err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); |
93da9cc1 | 2744 | |
f3f92586 | 2745 | out: |
93da9cc1 | 2746 | /* cleanup */ |
79c97e97 | 2747 | cfg80211_unlock_rdev(rdev); |
93da9cc1 | 2748 | dev_put(dev); |
3b85875a JB |
2749 | out_rtnl: |
2750 | rtnl_unlock(); | |
2751 | ||
93da9cc1 | 2752 | return err; |
2753 | } | |
2754 | ||
2755 | #undef FILL_IN_MESH_PARAM_IF_SET | |
2756 | ||
f130347c LR |
2757 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
2758 | { | |
2759 | struct sk_buff *msg; | |
2760 | void *hdr = NULL; | |
2761 | struct nlattr *nl_reg_rules; | |
2762 | unsigned int i; | |
2763 | int err = -EINVAL; | |
2764 | ||
a1794390 | 2765 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
2766 | |
2767 | if (!cfg80211_regdomain) | |
2768 | goto out; | |
2769 | ||
fd2120ca | 2770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
2771 | if (!msg) { |
2772 | err = -ENOBUFS; | |
2773 | goto out; | |
2774 | } | |
2775 | ||
2776 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2777 | NL80211_CMD_GET_REG); | |
2778 | if (!hdr) | |
2779 | goto nla_put_failure; | |
2780 | ||
2781 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | |
2782 | cfg80211_regdomain->alpha2); | |
2783 | ||
2784 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
2785 | if (!nl_reg_rules) | |
2786 | goto nla_put_failure; | |
2787 | ||
2788 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
2789 | struct nlattr *nl_reg_rule; | |
2790 | const struct ieee80211_reg_rule *reg_rule; | |
2791 | const struct ieee80211_freq_range *freq_range; | |
2792 | const struct ieee80211_power_rule *power_rule; | |
2793 | ||
2794 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
2795 | freq_range = ®_rule->freq_range; | |
2796 | power_rule = ®_rule->power_rule; | |
2797 | ||
2798 | nl_reg_rule = nla_nest_start(msg, i); | |
2799 | if (!nl_reg_rule) | |
2800 | goto nla_put_failure; | |
2801 | ||
2802 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, | |
2803 | reg_rule->flags); | |
2804 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
2805 | freq_range->start_freq_khz); | |
2806 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
2807 | freq_range->end_freq_khz); | |
2808 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
2809 | freq_range->max_bandwidth_khz); | |
2810 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
2811 | power_rule->max_antenna_gain); | |
2812 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
2813 | power_rule->max_eirp); | |
2814 | ||
2815 | nla_nest_end(msg, nl_reg_rule); | |
2816 | } | |
2817 | ||
2818 | nla_nest_end(msg, nl_reg_rules); | |
2819 | ||
2820 | genlmsg_end(msg, hdr); | |
134e6375 | 2821 | err = genlmsg_reply(msg, info); |
f130347c LR |
2822 | goto out; |
2823 | ||
2824 | nla_put_failure: | |
2825 | genlmsg_cancel(msg, hdr); | |
2826 | err = -EMSGSIZE; | |
2827 | out: | |
a1794390 | 2828 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
2829 | return err; |
2830 | } | |
2831 | ||
b2e1b302 LR |
2832 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
2833 | { | |
2834 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
2835 | struct nlattr *nl_reg_rule; | |
2836 | char *alpha2 = NULL; | |
2837 | int rem_reg_rules = 0, r = 0; | |
2838 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
2839 | struct ieee80211_regdomain *rd = NULL; | |
2840 | ||
2841 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
2842 | return -EINVAL; | |
2843 | ||
2844 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
2845 | return -EINVAL; | |
2846 | ||
2847 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2848 | ||
2849 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
2850 | rem_reg_rules) { | |
2851 | num_rules++; | |
2852 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 2853 | return -EINVAL; |
b2e1b302 LR |
2854 | } |
2855 | ||
61405e97 LR |
2856 | mutex_lock(&cfg80211_mutex); |
2857 | ||
d0e18f83 LR |
2858 | if (!reg_is_valid_request(alpha2)) { |
2859 | r = -EINVAL; | |
2860 | goto bad_reg; | |
2861 | } | |
b2e1b302 LR |
2862 | |
2863 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
2864 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
2865 | ||
2866 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
2867 | if (!rd) { |
2868 | r = -ENOMEM; | |
2869 | goto bad_reg; | |
2870 | } | |
b2e1b302 LR |
2871 | |
2872 | rd->n_reg_rules = num_rules; | |
2873 | rd->alpha2[0] = alpha2[0]; | |
2874 | rd->alpha2[1] = alpha2[1]; | |
2875 | ||
2876 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
2877 | rem_reg_rules) { | |
2878 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
2879 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
2880 | reg_rule_policy); | |
2881 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
2882 | if (r) | |
2883 | goto bad_reg; | |
2884 | ||
2885 | rule_idx++; | |
2886 | ||
d0e18f83 LR |
2887 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
2888 | r = -EINVAL; | |
b2e1b302 | 2889 | goto bad_reg; |
d0e18f83 | 2890 | } |
b2e1b302 LR |
2891 | } |
2892 | ||
2893 | BUG_ON(rule_idx != num_rules); | |
2894 | ||
b2e1b302 | 2895 | r = set_regdom(rd); |
61405e97 | 2896 | |
a1794390 | 2897 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 2898 | |
b2e1b302 LR |
2899 | return r; |
2900 | ||
d2372b31 | 2901 | bad_reg: |
61405e97 | 2902 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 2903 | kfree(rd); |
d0e18f83 | 2904 | return r; |
b2e1b302 LR |
2905 | } |
2906 | ||
83f5e2cf JB |
2907 | static int validate_scan_freqs(struct nlattr *freqs) |
2908 | { | |
2909 | struct nlattr *attr1, *attr2; | |
2910 | int n_channels = 0, tmp1, tmp2; | |
2911 | ||
2912 | nla_for_each_nested(attr1, freqs, tmp1) { | |
2913 | n_channels++; | |
2914 | /* | |
2915 | * Some hardware has a limited channel list for | |
2916 | * scanning, and it is pretty much nonsensical | |
2917 | * to scan for a channel twice, so disallow that | |
2918 | * and don't require drivers to check that the | |
2919 | * channel list they get isn't longer than what | |
2920 | * they can scan, as long as they can scan all | |
2921 | * the channels they registered at once. | |
2922 | */ | |
2923 | nla_for_each_nested(attr2, freqs, tmp2) | |
2924 | if (attr1 != attr2 && | |
2925 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
2926 | return 0; | |
2927 | } | |
2928 | ||
2929 | return n_channels; | |
2930 | } | |
2931 | ||
2a519311 JB |
2932 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
2933 | { | |
79c97e97 | 2934 | struct cfg80211_registered_device *rdev; |
2a519311 JB |
2935 | struct net_device *dev; |
2936 | struct cfg80211_scan_request *request; | |
2937 | struct cfg80211_ssid *ssid; | |
2938 | struct ieee80211_channel *channel; | |
2939 | struct nlattr *attr; | |
2940 | struct wiphy *wiphy; | |
83f5e2cf | 2941 | int err, tmp, n_ssids = 0, n_channels, i; |
2a519311 | 2942 | enum ieee80211_band band; |
70692ad2 | 2943 | size_t ie_len; |
2a519311 | 2944 | |
f4a11bb0 JB |
2945 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2946 | return -EINVAL; | |
2947 | ||
3b85875a JB |
2948 | rtnl_lock(); |
2949 | ||
463d0183 | 2950 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2a519311 | 2951 | if (err) |
3b85875a | 2952 | goto out_rtnl; |
2a519311 | 2953 | |
79c97e97 | 2954 | wiphy = &rdev->wiphy; |
2a519311 | 2955 | |
79c97e97 | 2956 | if (!rdev->ops->scan) { |
2a519311 JB |
2957 | err = -EOPNOTSUPP; |
2958 | goto out; | |
2959 | } | |
2960 | ||
35a8efe1 JM |
2961 | if (!netif_running(dev)) { |
2962 | err = -ENETDOWN; | |
2963 | goto out; | |
2964 | } | |
2965 | ||
79c97e97 | 2966 | if (rdev->scan_req) { |
2a519311 | 2967 | err = -EBUSY; |
3b85875a | 2968 | goto out; |
2a519311 JB |
2969 | } |
2970 | ||
2971 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
2972 | n_channels = validate_scan_freqs( |
2973 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
2a519311 JB |
2974 | if (!n_channels) { |
2975 | err = -EINVAL; | |
3b85875a | 2976 | goto out; |
2a519311 JB |
2977 | } |
2978 | } else { | |
83f5e2cf JB |
2979 | n_channels = 0; |
2980 | ||
2a519311 JB |
2981 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
2982 | if (wiphy->bands[band]) | |
2983 | n_channels += wiphy->bands[band]->n_channels; | |
2984 | } | |
2985 | ||
2986 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
2987 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
2988 | n_ssids++; | |
2989 | ||
2990 | if (n_ssids > wiphy->max_scan_ssids) { | |
2991 | err = -EINVAL; | |
3b85875a | 2992 | goto out; |
2a519311 JB |
2993 | } |
2994 | ||
70692ad2 JM |
2995 | if (info->attrs[NL80211_ATTR_IE]) |
2996 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
2997 | else | |
2998 | ie_len = 0; | |
2999 | ||
18a83659 JB |
3000 | if (ie_len > wiphy->max_scan_ie_len) { |
3001 | err = -EINVAL; | |
3002 | goto out; | |
3003 | } | |
3004 | ||
2a519311 JB |
3005 | request = kzalloc(sizeof(*request) |
3006 | + sizeof(*ssid) * n_ssids | |
70692ad2 JM |
3007 | + sizeof(channel) * n_channels |
3008 | + ie_len, GFP_KERNEL); | |
2a519311 JB |
3009 | if (!request) { |
3010 | err = -ENOMEM; | |
3b85875a | 3011 | goto out; |
2a519311 JB |
3012 | } |
3013 | ||
2a519311 | 3014 | if (n_ssids) |
5ba63533 | 3015 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 3016 | request->n_ssids = n_ssids; |
70692ad2 JM |
3017 | if (ie_len) { |
3018 | if (request->ssids) | |
3019 | request->ie = (void *)(request->ssids + n_ssids); | |
3020 | else | |
3021 | request->ie = (void *)(request->channels + n_channels); | |
3022 | } | |
2a519311 | 3023 | |
584991dc | 3024 | i = 0; |
2a519311 JB |
3025 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3026 | /* user specified, bail out if channel not found */ | |
2a519311 | 3027 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
3028 | struct ieee80211_channel *chan; |
3029 | ||
3030 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3031 | ||
3032 | if (!chan) { | |
2a519311 JB |
3033 | err = -EINVAL; |
3034 | goto out_free; | |
3035 | } | |
584991dc JB |
3036 | |
3037 | /* ignore disabled channels */ | |
3038 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3039 | continue; | |
3040 | ||
3041 | request->channels[i] = chan; | |
2a519311 JB |
3042 | i++; |
3043 | } | |
3044 | } else { | |
3045 | /* all channels */ | |
2a519311 JB |
3046 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
3047 | int j; | |
3048 | if (!wiphy->bands[band]) | |
3049 | continue; | |
3050 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
3051 | struct ieee80211_channel *chan; |
3052 | ||
3053 | chan = &wiphy->bands[band]->channels[j]; | |
3054 | ||
3055 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3056 | continue; | |
3057 | ||
3058 | request->channels[i] = chan; | |
2a519311 JB |
3059 | i++; |
3060 | } | |
3061 | } | |
3062 | } | |
3063 | ||
584991dc JB |
3064 | if (!i) { |
3065 | err = -EINVAL; | |
3066 | goto out_free; | |
3067 | } | |
3068 | ||
3069 | request->n_channels = i; | |
3070 | ||
2a519311 JB |
3071 | i = 0; |
3072 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3073 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
3074 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { | |
3075 | err = -EINVAL; | |
3076 | goto out_free; | |
3077 | } | |
3078 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | |
3079 | request->ssids[i].ssid_len = nla_len(attr); | |
3080 | i++; | |
3081 | } | |
3082 | } | |
3083 | ||
70692ad2 JM |
3084 | if (info->attrs[NL80211_ATTR_IE]) { |
3085 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
3086 | memcpy((void *)request->ie, |
3087 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
3088 | request->ie_len); |
3089 | } | |
3090 | ||
463d0183 | 3091 | request->dev = dev; |
79c97e97 | 3092 | request->wiphy = &rdev->wiphy; |
2a519311 | 3093 | |
79c97e97 JB |
3094 | rdev->scan_req = request; |
3095 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 3096 | |
463d0183 | 3097 | if (!err) { |
79c97e97 | 3098 | nl80211_send_scan_start(rdev, dev); |
463d0183 JB |
3099 | dev_hold(dev); |
3100 | } | |
a538e2d5 | 3101 | |
2a519311 JB |
3102 | out_free: |
3103 | if (err) { | |
79c97e97 | 3104 | rdev->scan_req = NULL; |
2a519311 JB |
3105 | kfree(request); |
3106 | } | |
2a519311 | 3107 | out: |
79c97e97 | 3108 | cfg80211_unlock_rdev(rdev); |
2a519311 | 3109 | dev_put(dev); |
3b85875a JB |
3110 | out_rtnl: |
3111 | rtnl_unlock(); | |
3112 | ||
2a519311 JB |
3113 | return err; |
3114 | } | |
3115 | ||
3116 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
3117 | struct cfg80211_registered_device *rdev, | |
48ab905d JB |
3118 | struct wireless_dev *wdev, |
3119 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 3120 | { |
48ab905d | 3121 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
3122 | void *hdr; |
3123 | struct nlattr *bss; | |
48ab905d JB |
3124 | int i; |
3125 | ||
3126 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 JB |
3127 | |
3128 | hdr = nl80211hdr_put(msg, pid, seq, flags, | |
3129 | NL80211_CMD_NEW_SCAN_RESULTS); | |
3130 | if (!hdr) | |
3131 | return -1; | |
3132 | ||
f5ea9120 | 3133 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
48ab905d | 3134 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
2a519311 JB |
3135 | |
3136 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
3137 | if (!bss) | |
3138 | goto nla_put_failure; | |
3139 | if (!is_zero_ether_addr(res->bssid)) | |
3140 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); | |
3141 | if (res->information_elements && res->len_information_elements) | |
3142 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
3143 | res->len_information_elements, | |
3144 | res->information_elements); | |
34a6eddb JM |
3145 | if (res->beacon_ies && res->len_beacon_ies && |
3146 | res->beacon_ies != res->information_elements) | |
3147 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, | |
3148 | res->len_beacon_ies, res->beacon_ies); | |
2a519311 JB |
3149 | if (res->tsf) |
3150 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); | |
3151 | if (res->beacon_interval) | |
3152 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); | |
3153 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); | |
3154 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); | |
7c89606e HS |
3155 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
3156 | jiffies_to_msecs(jiffies - intbss->ts)); | |
2a519311 | 3157 | |
77965c97 | 3158 | switch (rdev->wiphy.signal_type) { |
2a519311 JB |
3159 | case CFG80211_SIGNAL_TYPE_MBM: |
3160 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); | |
3161 | break; | |
3162 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
3163 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); | |
3164 | break; | |
3165 | default: | |
3166 | break; | |
3167 | } | |
3168 | ||
48ab905d JB |
3169 | switch (wdev->iftype) { |
3170 | case NL80211_IFTYPE_STATION: | |
3171 | if (intbss == wdev->current_bss) | |
3172 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3173 | NL80211_BSS_STATUS_ASSOCIATED); | |
3174 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
3175 | if (intbss != wdev->auth_bsses[i]) | |
3176 | continue; | |
3177 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3178 | NL80211_BSS_STATUS_AUTHENTICATED); | |
3179 | break; | |
3180 | } | |
3181 | break; | |
3182 | case NL80211_IFTYPE_ADHOC: | |
3183 | if (intbss == wdev->current_bss) | |
3184 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3185 | NL80211_BSS_STATUS_IBSS_JOINED); | |
3186 | break; | |
3187 | default: | |
3188 | break; | |
3189 | } | |
3190 | ||
2a519311 JB |
3191 | nla_nest_end(msg, bss); |
3192 | ||
3193 | return genlmsg_end(msg, hdr); | |
3194 | ||
3195 | nla_put_failure: | |
3196 | genlmsg_cancel(msg, hdr); | |
3197 | return -EMSGSIZE; | |
3198 | } | |
3199 | ||
3200 | static int nl80211_dump_scan(struct sk_buff *skb, | |
3201 | struct netlink_callback *cb) | |
3202 | { | |
48ab905d JB |
3203 | struct cfg80211_registered_device *rdev; |
3204 | struct net_device *dev; | |
2a519311 | 3205 | struct cfg80211_internal_bss *scan; |
48ab905d | 3206 | struct wireless_dev *wdev; |
2a519311 JB |
3207 | int ifidx = cb->args[0]; |
3208 | int start = cb->args[1], idx = 0; | |
3209 | int err; | |
3210 | ||
a043897a HS |
3211 | if (!ifidx) |
3212 | ifidx = nl80211_get_ifidx(cb); | |
3213 | if (ifidx < 0) | |
3214 | return ifidx; | |
3215 | cb->args[0] = ifidx; | |
2a519311 | 3216 | |
463d0183 | 3217 | dev = dev_get_by_index(sock_net(skb->sk), ifidx); |
48ab905d | 3218 | if (!dev) |
2a519311 JB |
3219 | return -ENODEV; |
3220 | ||
463d0183 | 3221 | rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
48ab905d JB |
3222 | if (IS_ERR(rdev)) { |
3223 | err = PTR_ERR(rdev); | |
2a519311 JB |
3224 | goto out_put_netdev; |
3225 | } | |
3226 | ||
48ab905d | 3227 | wdev = dev->ieee80211_ptr; |
2a519311 | 3228 | |
48ab905d JB |
3229 | wdev_lock(wdev); |
3230 | spin_lock_bh(&rdev->bss_lock); | |
3231 | cfg80211_bss_expire(rdev); | |
3232 | ||
3233 | list_for_each_entry(scan, &rdev->bss_list, list) { | |
2a519311 JB |
3234 | if (++idx <= start) |
3235 | continue; | |
3236 | if (nl80211_send_bss(skb, | |
3237 | NETLINK_CB(cb->skb).pid, | |
3238 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
48ab905d | 3239 | rdev, wdev, scan) < 0) { |
2a519311 JB |
3240 | idx--; |
3241 | goto out; | |
3242 | } | |
3243 | } | |
3244 | ||
3245 | out: | |
48ab905d JB |
3246 | spin_unlock_bh(&rdev->bss_lock); |
3247 | wdev_unlock(wdev); | |
2a519311 JB |
3248 | |
3249 | cb->args[1] = idx; | |
3250 | err = skb->len; | |
48ab905d | 3251 | cfg80211_unlock_rdev(rdev); |
2a519311 | 3252 | out_put_netdev: |
48ab905d | 3253 | dev_put(dev); |
2a519311 JB |
3254 | |
3255 | return err; | |
3256 | } | |
3257 | ||
61fa713c HS |
3258 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
3259 | int flags, struct net_device *dev, | |
3260 | struct survey_info *survey) | |
3261 | { | |
3262 | void *hdr; | |
3263 | struct nlattr *infoattr; | |
3264 | ||
3265 | /* Survey without a channel doesn't make sense */ | |
3266 | if (!survey->channel) | |
3267 | return -EINVAL; | |
3268 | ||
3269 | hdr = nl80211hdr_put(msg, pid, seq, flags, | |
3270 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
3271 | if (!hdr) | |
3272 | return -ENOMEM; | |
3273 | ||
3274 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
3275 | ||
3276 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
3277 | if (!infoattr) | |
3278 | goto nla_put_failure; | |
3279 | ||
3280 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
3281 | survey->channel->center_freq); | |
3282 | if (survey->filled & SURVEY_INFO_NOISE_DBM) | |
3283 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, | |
3284 | survey->noise); | |
3285 | ||
3286 | nla_nest_end(msg, infoattr); | |
3287 | ||
3288 | return genlmsg_end(msg, hdr); | |
3289 | ||
3290 | nla_put_failure: | |
3291 | genlmsg_cancel(msg, hdr); | |
3292 | return -EMSGSIZE; | |
3293 | } | |
3294 | ||
3295 | static int nl80211_dump_survey(struct sk_buff *skb, | |
3296 | struct netlink_callback *cb) | |
3297 | { | |
3298 | struct survey_info survey; | |
3299 | struct cfg80211_registered_device *dev; | |
3300 | struct net_device *netdev; | |
3301 | int ifidx = cb->args[0]; | |
3302 | int survey_idx = cb->args[1]; | |
3303 | int res; | |
3304 | ||
3305 | if (!ifidx) | |
3306 | ifidx = nl80211_get_ifidx(cb); | |
3307 | if (ifidx < 0) | |
3308 | return ifidx; | |
3309 | cb->args[0] = ifidx; | |
3310 | ||
3311 | rtnl_lock(); | |
3312 | ||
3313 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
3314 | if (!netdev) { | |
3315 | res = -ENODEV; | |
3316 | goto out_rtnl; | |
3317 | } | |
3318 | ||
3319 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3320 | if (IS_ERR(dev)) { | |
3321 | res = PTR_ERR(dev); | |
3322 | goto out_rtnl; | |
3323 | } | |
3324 | ||
3325 | if (!dev->ops->dump_survey) { | |
3326 | res = -EOPNOTSUPP; | |
3327 | goto out_err; | |
3328 | } | |
3329 | ||
3330 | while (1) { | |
3331 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, | |
3332 | &survey); | |
3333 | if (res == -ENOENT) | |
3334 | break; | |
3335 | if (res) | |
3336 | goto out_err; | |
3337 | ||
3338 | if (nl80211_send_survey(skb, | |
3339 | NETLINK_CB(cb->skb).pid, | |
3340 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
3341 | netdev, | |
3342 | &survey) < 0) | |
3343 | goto out; | |
3344 | survey_idx++; | |
3345 | } | |
3346 | ||
3347 | out: | |
3348 | cb->args[1] = survey_idx; | |
3349 | res = skb->len; | |
3350 | out_err: | |
3351 | cfg80211_unlock_rdev(dev); | |
3352 | out_rtnl: | |
3353 | rtnl_unlock(); | |
3354 | ||
3355 | return res; | |
3356 | } | |
3357 | ||
255e737e JM |
3358 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
3359 | { | |
b23aa676 SO |
3360 | return auth_type <= NL80211_AUTHTYPE_MAX; |
3361 | } | |
3362 | ||
3363 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
3364 | { | |
3365 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
3366 | NL80211_WPA_VERSION_2)); | |
3367 | } | |
3368 | ||
3369 | static bool nl80211_valid_akm_suite(u32 akm) | |
3370 | { | |
3371 | return akm == WLAN_AKM_SUITE_8021X || | |
3372 | akm == WLAN_AKM_SUITE_PSK; | |
3373 | } | |
3374 | ||
3375 | static bool nl80211_valid_cipher_suite(u32 cipher) | |
3376 | { | |
3377 | return cipher == WLAN_CIPHER_SUITE_WEP40 || | |
3378 | cipher == WLAN_CIPHER_SUITE_WEP104 || | |
3379 | cipher == WLAN_CIPHER_SUITE_TKIP || | |
3380 | cipher == WLAN_CIPHER_SUITE_CCMP || | |
3381 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; | |
255e737e JM |
3382 | } |
3383 | ||
b23aa676 | 3384 | |
636a5d36 JM |
3385 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
3386 | { | |
79c97e97 | 3387 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3388 | struct net_device *dev; |
19957bb3 JB |
3389 | struct ieee80211_channel *chan; |
3390 | const u8 *bssid, *ssid, *ie = NULL; | |
3391 | int err, ssid_len, ie_len = 0; | |
3392 | enum nl80211_auth_type auth_type; | |
fffd0934 | 3393 | struct key_parse key; |
636a5d36 | 3394 | |
f4a11bb0 JB |
3395 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3396 | return -EINVAL; | |
3397 | ||
3398 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3399 | return -EINVAL; | |
3400 | ||
1778092e JM |
3401 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
3402 | return -EINVAL; | |
3403 | ||
19957bb3 JB |
3404 | if (!info->attrs[NL80211_ATTR_SSID]) |
3405 | return -EINVAL; | |
3406 | ||
3407 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
3408 | return -EINVAL; | |
3409 | ||
fffd0934 JB |
3410 | err = nl80211_parse_key(info, &key); |
3411 | if (err) | |
3412 | return err; | |
3413 | ||
3414 | if (key.idx >= 0) { | |
3415 | if (!key.p.key || !key.p.key_len) | |
3416 | return -EINVAL; | |
3417 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
3418 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
3419 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
3420 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
3421 | return -EINVAL; | |
3422 | if (key.idx > 4) | |
3423 | return -EINVAL; | |
3424 | } else { | |
3425 | key.p.key_len = 0; | |
3426 | key.p.key = NULL; | |
3427 | } | |
3428 | ||
636a5d36 JM |
3429 | rtnl_lock(); |
3430 | ||
463d0183 | 3431 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3432 | if (err) |
3433 | goto unlock_rtnl; | |
3434 | ||
79c97e97 | 3435 | if (!rdev->ops->auth) { |
636a5d36 JM |
3436 | err = -EOPNOTSUPP; |
3437 | goto out; | |
3438 | } | |
3439 | ||
eec60b03 JM |
3440 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
3441 | err = -EOPNOTSUPP; | |
3442 | goto out; | |
3443 | } | |
3444 | ||
35a8efe1 JM |
3445 | if (!netif_running(dev)) { |
3446 | err = -ENETDOWN; | |
3447 | goto out; | |
3448 | } | |
3449 | ||
19957bb3 | 3450 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 3451 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 JB |
3452 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
3453 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | |
3454 | err = -EINVAL; | |
3455 | goto out; | |
636a5d36 JM |
3456 | } |
3457 | ||
19957bb3 JB |
3458 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3459 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
3460 | |
3461 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3462 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3463 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3464 | } |
3465 | ||
19957bb3 JB |
3466 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
3467 | if (!nl80211_valid_auth_type(auth_type)) { | |
1778092e JM |
3468 | err = -EINVAL; |
3469 | goto out; | |
636a5d36 JM |
3470 | } |
3471 | ||
79c97e97 | 3472 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
fffd0934 JB |
3473 | ssid, ssid_len, ie, ie_len, |
3474 | key.p.key, key.p.key_len, key.idx); | |
636a5d36 JM |
3475 | |
3476 | out: | |
79c97e97 | 3477 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3478 | dev_put(dev); |
3479 | unlock_rtnl: | |
3480 | rtnl_unlock(); | |
3481 | return err; | |
3482 | } | |
3483 | ||
b23aa676 | 3484 | static int nl80211_crypto_settings(struct genl_info *info, |
3dc27d25 JB |
3485 | struct cfg80211_crypto_settings *settings, |
3486 | int cipher_limit) | |
b23aa676 | 3487 | { |
c0b2bbd8 JB |
3488 | memset(settings, 0, sizeof(*settings)); |
3489 | ||
b23aa676 SO |
3490 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
3491 | ||
3492 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { | |
3493 | void *data; | |
3494 | int len, i; | |
3495 | ||
3496 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
3497 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
3498 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
3499 | ||
3500 | if (len % sizeof(u32)) | |
3501 | return -EINVAL; | |
3502 | ||
3dc27d25 | 3503 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
3504 | return -EINVAL; |
3505 | ||
3506 | memcpy(settings->ciphers_pairwise, data, len); | |
3507 | ||
3508 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
3509 | if (!nl80211_valid_cipher_suite( | |
3510 | settings->ciphers_pairwise[i])) | |
3511 | return -EINVAL; | |
3512 | } | |
3513 | ||
3514 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
3515 | settings->cipher_group = | |
3516 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
3517 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) | |
3518 | return -EINVAL; | |
3519 | } | |
3520 | ||
3521 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
3522 | settings->wpa_versions = | |
3523 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
3524 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
3525 | return -EINVAL; | |
3526 | } | |
3527 | ||
3528 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
3529 | void *data; | |
3530 | int len, i; | |
3531 | ||
3532 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
3533 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
3534 | settings->n_akm_suites = len / sizeof(u32); | |
3535 | ||
3536 | if (len % sizeof(u32)) | |
3537 | return -EINVAL; | |
3538 | ||
3539 | memcpy(settings->akm_suites, data, len); | |
3540 | ||
3541 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
3542 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) | |
3543 | return -EINVAL; | |
3544 | } | |
3545 | ||
3546 | return 0; | |
3547 | } | |
3548 | ||
636a5d36 JM |
3549 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
3550 | { | |
19957bb3 | 3551 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3552 | struct net_device *dev; |
27e310c9 | 3553 | struct wireless_dev *wdev; |
19957bb3 | 3554 | struct cfg80211_crypto_settings crypto; |
59bbb6f7 | 3555 | struct ieee80211_channel *chan, *fixedchan; |
3e5d7649 | 3556 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
3557 | int err, ssid_len, ie_len = 0; |
3558 | bool use_mfp = false; | |
636a5d36 | 3559 | |
f4a11bb0 JB |
3560 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3561 | return -EINVAL; | |
3562 | ||
3563 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
3564 | !info->attrs[NL80211_ATTR_SSID] || |
3565 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
3566 | return -EINVAL; |
3567 | ||
636a5d36 JM |
3568 | rtnl_lock(); |
3569 | ||
463d0183 | 3570 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3571 | if (err) |
3572 | goto unlock_rtnl; | |
3573 | ||
19957bb3 | 3574 | if (!rdev->ops->assoc) { |
636a5d36 JM |
3575 | err = -EOPNOTSUPP; |
3576 | goto out; | |
3577 | } | |
3578 | ||
eec60b03 JM |
3579 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
3580 | err = -EOPNOTSUPP; | |
3581 | goto out; | |
3582 | } | |
3583 | ||
35a8efe1 JM |
3584 | if (!netif_running(dev)) { |
3585 | err = -ENETDOWN; | |
3586 | goto out; | |
3587 | } | |
3588 | ||
19957bb3 | 3589 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3590 | |
19957bb3 JB |
3591 | chan = ieee80211_get_channel(&rdev->wiphy, |
3592 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
3593 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | |
3594 | err = -EINVAL; | |
3595 | goto out; | |
636a5d36 JM |
3596 | } |
3597 | ||
59bbb6f7 | 3598 | mutex_lock(&rdev->devlist_mtx); |
27e310c9 JM |
3599 | wdev = dev->ieee80211_ptr; |
3600 | fixedchan = rdev_fixed_channel(rdev, wdev); | |
59bbb6f7 JB |
3601 | if (fixedchan && chan != fixedchan) { |
3602 | err = -EBUSY; | |
3603 | mutex_unlock(&rdev->devlist_mtx); | |
3604 | goto out; | |
3605 | } | |
3606 | mutex_unlock(&rdev->devlist_mtx); | |
3607 | ||
19957bb3 JB |
3608 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3609 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
3610 | |
3611 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3612 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3613 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3614 | } |
3615 | ||
dc6382ce | 3616 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 3617 | enum nl80211_mfp mfp = |
dc6382ce | 3618 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 3619 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 3620 | use_mfp = true; |
4f5dadce | 3621 | else if (mfp != NL80211_MFP_NO) { |
dc6382ce JM |
3622 | err = -EINVAL; |
3623 | goto out; | |
3624 | } | |
3625 | } | |
3626 | ||
3e5d7649 JB |
3627 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
3628 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
3629 | ||
3dc27d25 | 3630 | err = nl80211_crypto_settings(info, &crypto, 1); |
b23aa676 | 3631 | if (!err) |
3e5d7649 JB |
3632 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
3633 | ssid, ssid_len, ie, ie_len, use_mfp, | |
19957bb3 | 3634 | &crypto); |
636a5d36 JM |
3635 | |
3636 | out: | |
4d0c8aea | 3637 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3638 | dev_put(dev); |
3639 | unlock_rtnl: | |
3640 | rtnl_unlock(); | |
3641 | return err; | |
3642 | } | |
3643 | ||
3644 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
3645 | { | |
79c97e97 | 3646 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3647 | struct net_device *dev; |
19957bb3 JB |
3648 | const u8 *ie = NULL, *bssid; |
3649 | int err, ie_len = 0; | |
3650 | u16 reason_code; | |
636a5d36 | 3651 | |
f4a11bb0 JB |
3652 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3653 | return -EINVAL; | |
3654 | ||
3655 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3656 | return -EINVAL; | |
3657 | ||
3658 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
3659 | return -EINVAL; | |
3660 | ||
636a5d36 JM |
3661 | rtnl_lock(); |
3662 | ||
463d0183 | 3663 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3664 | if (err) |
3665 | goto unlock_rtnl; | |
3666 | ||
79c97e97 | 3667 | if (!rdev->ops->deauth) { |
636a5d36 JM |
3668 | err = -EOPNOTSUPP; |
3669 | goto out; | |
3670 | } | |
3671 | ||
eec60b03 JM |
3672 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
3673 | err = -EOPNOTSUPP; | |
3674 | goto out; | |
3675 | } | |
3676 | ||
35a8efe1 JM |
3677 | if (!netif_running(dev)) { |
3678 | err = -ENETDOWN; | |
3679 | goto out; | |
3680 | } | |
3681 | ||
19957bb3 | 3682 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3683 | |
19957bb3 JB |
3684 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3685 | if (reason_code == 0) { | |
f4a11bb0 JB |
3686 | /* Reason Code 0 is reserved */ |
3687 | err = -EINVAL; | |
3688 | goto out; | |
255e737e | 3689 | } |
636a5d36 JM |
3690 | |
3691 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3692 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3693 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3694 | } |
3695 | ||
79c97e97 | 3696 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code); |
636a5d36 JM |
3697 | |
3698 | out: | |
79c97e97 | 3699 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3700 | dev_put(dev); |
3701 | unlock_rtnl: | |
3702 | rtnl_unlock(); | |
3703 | return err; | |
3704 | } | |
3705 | ||
3706 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
3707 | { | |
79c97e97 | 3708 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3709 | struct net_device *dev; |
19957bb3 JB |
3710 | const u8 *ie = NULL, *bssid; |
3711 | int err, ie_len = 0; | |
3712 | u16 reason_code; | |
636a5d36 | 3713 | |
f4a11bb0 JB |
3714 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3715 | return -EINVAL; | |
3716 | ||
3717 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3718 | return -EINVAL; | |
3719 | ||
3720 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
3721 | return -EINVAL; | |
3722 | ||
636a5d36 JM |
3723 | rtnl_lock(); |
3724 | ||
463d0183 | 3725 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3726 | if (err) |
3727 | goto unlock_rtnl; | |
3728 | ||
79c97e97 | 3729 | if (!rdev->ops->disassoc) { |
636a5d36 JM |
3730 | err = -EOPNOTSUPP; |
3731 | goto out; | |
3732 | } | |
3733 | ||
eec60b03 JM |
3734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
3735 | err = -EOPNOTSUPP; | |
3736 | goto out; | |
3737 | } | |
3738 | ||
35a8efe1 JM |
3739 | if (!netif_running(dev)) { |
3740 | err = -ENETDOWN; | |
3741 | goto out; | |
3742 | } | |
3743 | ||
19957bb3 | 3744 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3745 | |
19957bb3 JB |
3746 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3747 | if (reason_code == 0) { | |
f4a11bb0 JB |
3748 | /* Reason Code 0 is reserved */ |
3749 | err = -EINVAL; | |
3750 | goto out; | |
255e737e | 3751 | } |
636a5d36 JM |
3752 | |
3753 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3754 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3755 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3756 | } |
3757 | ||
79c97e97 | 3758 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code); |
636a5d36 JM |
3759 | |
3760 | out: | |
79c97e97 | 3761 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3762 | dev_put(dev); |
3763 | unlock_rtnl: | |
3764 | rtnl_unlock(); | |
3765 | return err; | |
3766 | } | |
3767 | ||
04a773ad JB |
3768 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
3769 | { | |
79c97e97 | 3770 | struct cfg80211_registered_device *rdev; |
04a773ad JB |
3771 | struct net_device *dev; |
3772 | struct cfg80211_ibss_params ibss; | |
3773 | struct wiphy *wiphy; | |
fffd0934 | 3774 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
3775 | int err; |
3776 | ||
8e30bc55 JB |
3777 | memset(&ibss, 0, sizeof(ibss)); |
3778 | ||
04a773ad JB |
3779 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3780 | return -EINVAL; | |
3781 | ||
3782 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
3783 | !info->attrs[NL80211_ATTR_SSID] || | |
3784 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
3785 | return -EINVAL; | |
3786 | ||
8e30bc55 JB |
3787 | ibss.beacon_interval = 100; |
3788 | ||
3789 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
3790 | ibss.beacon_interval = | |
3791 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3792 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
3793 | return -EINVAL; | |
3794 | } | |
3795 | ||
04a773ad JB |
3796 | rtnl_lock(); |
3797 | ||
463d0183 | 3798 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
04a773ad JB |
3799 | if (err) |
3800 | goto unlock_rtnl; | |
3801 | ||
79c97e97 | 3802 | if (!rdev->ops->join_ibss) { |
04a773ad JB |
3803 | err = -EOPNOTSUPP; |
3804 | goto out; | |
3805 | } | |
3806 | ||
3807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | |
3808 | err = -EOPNOTSUPP; | |
3809 | goto out; | |
3810 | } | |
3811 | ||
3812 | if (!netif_running(dev)) { | |
3813 | err = -ENETDOWN; | |
3814 | goto out; | |
3815 | } | |
3816 | ||
79c97e97 | 3817 | wiphy = &rdev->wiphy; |
04a773ad JB |
3818 | |
3819 | if (info->attrs[NL80211_ATTR_MAC]) | |
3820 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3821 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3822 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3823 | ||
3824 | if (info->attrs[NL80211_ATTR_IE]) { | |
3825 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
3826 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3827 | } | |
3828 | ||
3829 | ibss.channel = ieee80211_get_channel(wiphy, | |
3830 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
3831 | if (!ibss.channel || | |
3832 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
3833 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { | |
3834 | err = -EINVAL; | |
3835 | goto out; | |
3836 | } | |
3837 | ||
3838 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | |
fffd0934 JB |
3839 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
3840 | ||
3841 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { | |
3842 | connkeys = nl80211_parse_connkeys(rdev, | |
3843 | info->attrs[NL80211_ATTR_KEYS]); | |
3844 | if (IS_ERR(connkeys)) { | |
3845 | err = PTR_ERR(connkeys); | |
3846 | connkeys = NULL; | |
3847 | goto out; | |
3848 | } | |
3849 | } | |
04a773ad | 3850 | |
fffd0934 | 3851 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
04a773ad JB |
3852 | |
3853 | out: | |
79c97e97 | 3854 | cfg80211_unlock_rdev(rdev); |
04a773ad JB |
3855 | dev_put(dev); |
3856 | unlock_rtnl: | |
fffd0934 JB |
3857 | if (err) |
3858 | kfree(connkeys); | |
04a773ad JB |
3859 | rtnl_unlock(); |
3860 | return err; | |
3861 | } | |
3862 | ||
3863 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
3864 | { | |
79c97e97 | 3865 | struct cfg80211_registered_device *rdev; |
04a773ad JB |
3866 | struct net_device *dev; |
3867 | int err; | |
3868 | ||
3869 | rtnl_lock(); | |
3870 | ||
463d0183 | 3871 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
04a773ad JB |
3872 | if (err) |
3873 | goto unlock_rtnl; | |
3874 | ||
79c97e97 | 3875 | if (!rdev->ops->leave_ibss) { |
04a773ad JB |
3876 | err = -EOPNOTSUPP; |
3877 | goto out; | |
3878 | } | |
3879 | ||
3880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | |
3881 | err = -EOPNOTSUPP; | |
3882 | goto out; | |
3883 | } | |
3884 | ||
3885 | if (!netif_running(dev)) { | |
3886 | err = -ENETDOWN; | |
3887 | goto out; | |
3888 | } | |
3889 | ||
79c97e97 | 3890 | err = cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
3891 | |
3892 | out: | |
79c97e97 | 3893 | cfg80211_unlock_rdev(rdev); |
04a773ad JB |
3894 | dev_put(dev); |
3895 | unlock_rtnl: | |
3896 | rtnl_unlock(); | |
3897 | return err; | |
3898 | } | |
3899 | ||
aff89a9b JB |
3900 | #ifdef CONFIG_NL80211_TESTMODE |
3901 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
3902 | .name = "testmode", | |
3903 | }; | |
3904 | ||
3905 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
3906 | { | |
3907 | struct cfg80211_registered_device *rdev; | |
3908 | int err; | |
3909 | ||
3910 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
3911 | return -EINVAL; | |
3912 | ||
3913 | rtnl_lock(); | |
3914 | ||
3915 | rdev = cfg80211_get_dev_from_info(info); | |
3916 | if (IS_ERR(rdev)) { | |
3917 | err = PTR_ERR(rdev); | |
3918 | goto unlock_rtnl; | |
3919 | } | |
3920 | ||
3921 | err = -EOPNOTSUPP; | |
3922 | if (rdev->ops->testmode_cmd) { | |
3923 | rdev->testmode_info = info; | |
3924 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
3925 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
3926 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
3927 | rdev->testmode_info = NULL; | |
3928 | } | |
3929 | ||
4d0c8aea | 3930 | cfg80211_unlock_rdev(rdev); |
aff89a9b JB |
3931 | |
3932 | unlock_rtnl: | |
3933 | rtnl_unlock(); | |
3934 | return err; | |
3935 | } | |
3936 | ||
3937 | static struct sk_buff * | |
3938 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
3939 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
3940 | { | |
3941 | struct sk_buff *skb; | |
3942 | void *hdr; | |
3943 | struct nlattr *data; | |
3944 | ||
3945 | skb = nlmsg_new(approxlen + 100, gfp); | |
3946 | if (!skb) | |
3947 | return NULL; | |
3948 | ||
3949 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
3950 | if (!hdr) { | |
3951 | kfree_skb(skb); | |
3952 | return NULL; | |
3953 | } | |
3954 | ||
3955 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
3956 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
3957 | ||
3958 | ((void **)skb->cb)[0] = rdev; | |
3959 | ((void **)skb->cb)[1] = hdr; | |
3960 | ((void **)skb->cb)[2] = data; | |
3961 | ||
3962 | return skb; | |
3963 | ||
3964 | nla_put_failure: | |
3965 | kfree_skb(skb); | |
3966 | return NULL; | |
3967 | } | |
3968 | ||
3969 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
3970 | int approxlen) | |
3971 | { | |
3972 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
3973 | ||
3974 | if (WARN_ON(!rdev->testmode_info)) | |
3975 | return NULL; | |
3976 | ||
3977 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
3978 | rdev->testmode_info->snd_pid, | |
3979 | rdev->testmode_info->snd_seq, | |
3980 | GFP_KERNEL); | |
3981 | } | |
3982 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
3983 | ||
3984 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
3985 | { | |
3986 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
3987 | void *hdr = ((void **)skb->cb)[1]; | |
3988 | struct nlattr *data = ((void **)skb->cb)[2]; | |
3989 | ||
3990 | if (WARN_ON(!rdev->testmode_info)) { | |
3991 | kfree_skb(skb); | |
3992 | return -EINVAL; | |
3993 | } | |
3994 | ||
3995 | nla_nest_end(skb, data); | |
3996 | genlmsg_end(skb, hdr); | |
3997 | return genlmsg_reply(skb, rdev->testmode_info); | |
3998 | } | |
3999 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
4000 | ||
4001 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
4002 | int approxlen, gfp_t gfp) | |
4003 | { | |
4004 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4005 | ||
4006 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
4007 | } | |
4008 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
4009 | ||
4010 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
4011 | { | |
4012 | void *hdr = ((void **)skb->cb)[1]; | |
4013 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4014 | ||
4015 | nla_nest_end(skb, data); | |
4016 | genlmsg_end(skb, hdr); | |
4017 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
4018 | } | |
4019 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
4020 | #endif | |
4021 | ||
b23aa676 SO |
4022 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
4023 | { | |
79c97e97 | 4024 | struct cfg80211_registered_device *rdev; |
b23aa676 SO |
4025 | struct net_device *dev; |
4026 | struct cfg80211_connect_params connect; | |
4027 | struct wiphy *wiphy; | |
fffd0934 | 4028 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
4029 | int err; |
4030 | ||
4031 | memset(&connect, 0, sizeof(connect)); | |
4032 | ||
4033 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4034 | return -EINVAL; | |
4035 | ||
4036 | if (!info->attrs[NL80211_ATTR_SSID] || | |
4037 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4038 | return -EINVAL; | |
4039 | ||
4040 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
4041 | connect.auth_type = | |
4042 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
4043 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
4044 | return -EINVAL; | |
4045 | } else | |
4046 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4047 | ||
4048 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
4049 | ||
3dc27d25 JB |
4050 | err = nl80211_crypto_settings(info, &connect.crypto, |
4051 | NL80211_MAX_NR_CIPHER_SUITES); | |
b23aa676 SO |
4052 | if (err) |
4053 | return err; | |
4054 | rtnl_lock(); | |
4055 | ||
463d0183 | 4056 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
b23aa676 SO |
4057 | if (err) |
4058 | goto unlock_rtnl; | |
4059 | ||
4060 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4061 | err = -EOPNOTSUPP; | |
4062 | goto out; | |
4063 | } | |
4064 | ||
4065 | if (!netif_running(dev)) { | |
4066 | err = -ENETDOWN; | |
4067 | goto out; | |
4068 | } | |
4069 | ||
79c97e97 | 4070 | wiphy = &rdev->wiphy; |
b23aa676 | 4071 | |
b23aa676 SO |
4072 | if (info->attrs[NL80211_ATTR_MAC]) |
4073 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4074 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4075 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4076 | ||
4077 | if (info->attrs[NL80211_ATTR_IE]) { | |
4078 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4079 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4080 | } | |
4081 | ||
4082 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
4083 | connect.channel = | |
4084 | ieee80211_get_channel(wiphy, | |
4085 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4086 | if (!connect.channel || | |
4087 | connect.channel->flags & IEEE80211_CHAN_DISABLED) { | |
4088 | err = -EINVAL; | |
4089 | goto out; | |
4090 | } | |
4091 | } | |
4092 | ||
fffd0934 JB |
4093 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4094 | connkeys = nl80211_parse_connkeys(rdev, | |
4095 | info->attrs[NL80211_ATTR_KEYS]); | |
4096 | if (IS_ERR(connkeys)) { | |
4097 | err = PTR_ERR(connkeys); | |
4098 | connkeys = NULL; | |
4099 | goto out; | |
4100 | } | |
4101 | } | |
4102 | ||
4103 | err = cfg80211_connect(rdev, dev, &connect, connkeys); | |
b23aa676 SO |
4104 | |
4105 | out: | |
79c97e97 | 4106 | cfg80211_unlock_rdev(rdev); |
b23aa676 SO |
4107 | dev_put(dev); |
4108 | unlock_rtnl: | |
fffd0934 JB |
4109 | if (err) |
4110 | kfree(connkeys); | |
b23aa676 SO |
4111 | rtnl_unlock(); |
4112 | return err; | |
4113 | } | |
4114 | ||
4115 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
4116 | { | |
79c97e97 | 4117 | struct cfg80211_registered_device *rdev; |
b23aa676 SO |
4118 | struct net_device *dev; |
4119 | int err; | |
4120 | u16 reason; | |
4121 | ||
4122 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4123 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
4124 | else | |
4125 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4126 | ||
4127 | if (reason == 0) | |
4128 | return -EINVAL; | |
4129 | ||
4130 | rtnl_lock(); | |
4131 | ||
463d0183 | 4132 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
b23aa676 SO |
4133 | if (err) |
4134 | goto unlock_rtnl; | |
4135 | ||
4136 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4137 | err = -EOPNOTSUPP; | |
4138 | goto out; | |
4139 | } | |
4140 | ||
4141 | if (!netif_running(dev)) { | |
4142 | err = -ENETDOWN; | |
4143 | goto out; | |
4144 | } | |
4145 | ||
79c97e97 | 4146 | err = cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
4147 | |
4148 | out: | |
79c97e97 | 4149 | cfg80211_unlock_rdev(rdev); |
b23aa676 SO |
4150 | dev_put(dev); |
4151 | unlock_rtnl: | |
4152 | rtnl_unlock(); | |
4153 | return err; | |
4154 | } | |
4155 | ||
463d0183 JB |
4156 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
4157 | { | |
4158 | struct cfg80211_registered_device *rdev; | |
4159 | struct net *net; | |
4160 | int err; | |
4161 | u32 pid; | |
4162 | ||
4163 | if (!info->attrs[NL80211_ATTR_PID]) | |
4164 | return -EINVAL; | |
4165 | ||
4166 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
4167 | ||
4168 | rtnl_lock(); | |
4169 | ||
4170 | rdev = cfg80211_get_dev_from_info(info); | |
4171 | if (IS_ERR(rdev)) { | |
4172 | err = PTR_ERR(rdev); | |
8a8e05e5 | 4173 | goto out_rtnl; |
463d0183 JB |
4174 | } |
4175 | ||
4176 | net = get_net_ns_by_pid(pid); | |
4177 | if (IS_ERR(net)) { | |
4178 | err = PTR_ERR(net); | |
4179 | goto out; | |
4180 | } | |
4181 | ||
4182 | err = 0; | |
4183 | ||
4184 | /* check if anything to do */ | |
4185 | if (net_eq(wiphy_net(&rdev->wiphy), net)) | |
4186 | goto out_put_net; | |
4187 | ||
4188 | err = cfg80211_switch_netns(rdev, net); | |
4189 | out_put_net: | |
4190 | put_net(net); | |
4191 | out: | |
4192 | cfg80211_unlock_rdev(rdev); | |
8a8e05e5 | 4193 | out_rtnl: |
463d0183 JB |
4194 | rtnl_unlock(); |
4195 | return err; | |
4196 | } | |
4197 | ||
67fbb16b SO |
4198 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
4199 | { | |
4200 | struct cfg80211_registered_device *rdev; | |
4201 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, | |
4202 | struct cfg80211_pmksa *pmksa) = NULL; | |
4203 | int err; | |
4204 | struct net_device *dev; | |
4205 | struct cfg80211_pmksa pmksa; | |
4206 | ||
4207 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
4208 | ||
4209 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4210 | return -EINVAL; | |
4211 | ||
4212 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
4213 | return -EINVAL; | |
4214 | ||
4215 | rtnl_lock(); | |
4216 | ||
4217 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4218 | if (err) | |
4219 | goto out_rtnl; | |
4220 | ||
4221 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | |
4222 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4223 | ||
4224 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4225 | err = -EOPNOTSUPP; | |
4226 | goto out; | |
4227 | } | |
4228 | ||
4229 | switch (info->genlhdr->cmd) { | |
4230 | case NL80211_CMD_SET_PMKSA: | |
4231 | rdev_ops = rdev->ops->set_pmksa; | |
4232 | break; | |
4233 | case NL80211_CMD_DEL_PMKSA: | |
4234 | rdev_ops = rdev->ops->del_pmksa; | |
4235 | break; | |
4236 | default: | |
4237 | WARN_ON(1); | |
4238 | break; | |
4239 | } | |
4240 | ||
4241 | if (!rdev_ops) { | |
4242 | err = -EOPNOTSUPP; | |
4243 | goto out; | |
4244 | } | |
4245 | ||
4246 | err = rdev_ops(&rdev->wiphy, dev, &pmksa); | |
4247 | ||
4248 | out: | |
4249 | cfg80211_unlock_rdev(rdev); | |
4250 | dev_put(dev); | |
4251 | out_rtnl: | |
4252 | rtnl_unlock(); | |
4253 | ||
4254 | return err; | |
4255 | } | |
4256 | ||
4257 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
4258 | { | |
4259 | struct cfg80211_registered_device *rdev; | |
4260 | int err; | |
4261 | struct net_device *dev; | |
4262 | ||
4263 | rtnl_lock(); | |
4264 | ||
4265 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4266 | if (err) | |
4267 | goto out_rtnl; | |
4268 | ||
4269 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4270 | err = -EOPNOTSUPP; | |
4271 | goto out; | |
4272 | } | |
4273 | ||
4274 | if (!rdev->ops->flush_pmksa) { | |
4275 | err = -EOPNOTSUPP; | |
4276 | goto out; | |
4277 | } | |
4278 | ||
4279 | err = rdev->ops->flush_pmksa(&rdev->wiphy, dev); | |
4280 | ||
4281 | out: | |
4282 | cfg80211_unlock_rdev(rdev); | |
4283 | dev_put(dev); | |
4284 | out_rtnl: | |
4285 | rtnl_unlock(); | |
4286 | ||
4287 | return err; | |
4288 | ||
4289 | } | |
4290 | ||
9588bbd5 JM |
4291 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
4292 | struct genl_info *info) | |
4293 | { | |
4294 | struct cfg80211_registered_device *rdev; | |
4295 | struct net_device *dev; | |
4296 | struct ieee80211_channel *chan; | |
4297 | struct sk_buff *msg; | |
4298 | void *hdr; | |
4299 | u64 cookie; | |
4300 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
4301 | u32 freq, duration; | |
4302 | int err; | |
4303 | ||
4304 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4305 | !info->attrs[NL80211_ATTR_DURATION]) | |
4306 | return -EINVAL; | |
4307 | ||
4308 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
4309 | ||
4310 | /* | |
4311 | * We should be on that channel for at least one jiffie, | |
4312 | * and more than 5 seconds seems excessive. | |
4313 | */ | |
4314 | if (!duration || !msecs_to_jiffies(duration) || duration > 5000) | |
4315 | return -EINVAL; | |
4316 | ||
4317 | rtnl_lock(); | |
4318 | ||
4319 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4320 | if (err) | |
4321 | goto unlock_rtnl; | |
4322 | ||
4323 | if (!rdev->ops->remain_on_channel) { | |
4324 | err = -EOPNOTSUPP; | |
4325 | goto out; | |
4326 | } | |
4327 | ||
4328 | if (!netif_running(dev)) { | |
4329 | err = -ENETDOWN; | |
4330 | goto out; | |
4331 | } | |
4332 | ||
4333 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
4334 | channel_type = nla_get_u32( | |
4335 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
4336 | if (channel_type != NL80211_CHAN_NO_HT && | |
4337 | channel_type != NL80211_CHAN_HT20 && | |
4338 | channel_type != NL80211_CHAN_HT40PLUS && | |
4339 | channel_type != NL80211_CHAN_HT40MINUS) | |
4340 | err = -EINVAL; | |
4341 | goto out; | |
4342 | } | |
4343 | ||
4344 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
4345 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4346 | if (chan == NULL) { | |
4347 | err = -EINVAL; | |
4348 | goto out; | |
4349 | } | |
4350 | ||
4351 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4352 | if (!msg) { | |
4353 | err = -ENOMEM; | |
4354 | goto out; | |
4355 | } | |
4356 | ||
4357 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
4358 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
4359 | ||
4360 | if (IS_ERR(hdr)) { | |
4361 | err = PTR_ERR(hdr); | |
4362 | goto free_msg; | |
4363 | } | |
4364 | ||
4365 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
4366 | channel_type, duration, &cookie); | |
4367 | ||
4368 | if (err) | |
4369 | goto free_msg; | |
4370 | ||
4371 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
4372 | ||
4373 | genlmsg_end(msg, hdr); | |
4374 | err = genlmsg_reply(msg, info); | |
4375 | goto out; | |
4376 | ||
4377 | nla_put_failure: | |
4378 | err = -ENOBUFS; | |
4379 | free_msg: | |
4380 | nlmsg_free(msg); | |
4381 | out: | |
4382 | cfg80211_unlock_rdev(rdev); | |
4383 | dev_put(dev); | |
4384 | unlock_rtnl: | |
4385 | rtnl_unlock(); | |
4386 | return err; | |
4387 | } | |
4388 | ||
4389 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
4390 | struct genl_info *info) | |
4391 | { | |
4392 | struct cfg80211_registered_device *rdev; | |
4393 | struct net_device *dev; | |
4394 | u64 cookie; | |
4395 | int err; | |
4396 | ||
4397 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
4398 | return -EINVAL; | |
4399 | ||
4400 | rtnl_lock(); | |
4401 | ||
4402 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4403 | if (err) | |
4404 | goto unlock_rtnl; | |
4405 | ||
4406 | if (!rdev->ops->cancel_remain_on_channel) { | |
4407 | err = -EOPNOTSUPP; | |
4408 | goto out; | |
4409 | } | |
4410 | ||
4411 | if (!netif_running(dev)) { | |
4412 | err = -ENETDOWN; | |
4413 | goto out; | |
4414 | } | |
4415 | ||
4416 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
4417 | ||
4418 | err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); | |
4419 | ||
4420 | out: | |
4421 | cfg80211_unlock_rdev(rdev); | |
4422 | dev_put(dev); | |
4423 | unlock_rtnl: | |
4424 | rtnl_unlock(); | |
4425 | return err; | |
4426 | } | |
4427 | ||
13ae75b1 JM |
4428 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
4429 | u8 *rates, u8 rates_len) | |
4430 | { | |
4431 | u8 i; | |
4432 | u32 mask = 0; | |
4433 | ||
4434 | for (i = 0; i < rates_len; i++) { | |
4435 | int rate = (rates[i] & 0x7f) * 5; | |
4436 | int ridx; | |
4437 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
4438 | struct ieee80211_rate *srate = | |
4439 | &sband->bitrates[ridx]; | |
4440 | if (rate == srate->bitrate) { | |
4441 | mask |= 1 << ridx; | |
4442 | break; | |
4443 | } | |
4444 | } | |
4445 | if (ridx == sband->n_bitrates) | |
4446 | return 0; /* rate not found */ | |
4447 | } | |
4448 | ||
4449 | return mask; | |
4450 | } | |
4451 | ||
b54452b0 | 4452 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
4453 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
4454 | .len = NL80211_MAX_SUPP_RATES }, | |
4455 | }; | |
4456 | ||
4457 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
4458 | struct genl_info *info) | |
4459 | { | |
4460 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4461 | struct cfg80211_registered_device *rdev; | |
4462 | struct cfg80211_bitrate_mask mask; | |
4463 | int err, rem, i; | |
4464 | struct net_device *dev; | |
4465 | struct nlattr *tx_rates; | |
4466 | struct ieee80211_supported_band *sband; | |
4467 | ||
4468 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
4469 | return -EINVAL; | |
4470 | ||
4471 | rtnl_lock(); | |
4472 | ||
4473 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4474 | if (err) | |
4475 | goto unlock_rtnl; | |
4476 | ||
4477 | if (!rdev->ops->set_bitrate_mask) { | |
4478 | err = -EOPNOTSUPP; | |
4479 | goto unlock; | |
4480 | } | |
4481 | ||
4482 | memset(&mask, 0, sizeof(mask)); | |
4483 | /* Default to all rates enabled */ | |
4484 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
4485 | sband = rdev->wiphy.bands[i]; | |
4486 | mask.control[i].legacy = | |
4487 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
4488 | } | |
4489 | ||
4490 | /* | |
4491 | * The nested attribute uses enum nl80211_band as the index. This maps | |
4492 | * directly to the enum ieee80211_band values used in cfg80211. | |
4493 | */ | |
4494 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) | |
4495 | { | |
4496 | enum ieee80211_band band = nla_type(tx_rates); | |
4497 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { | |
4498 | err = -EINVAL; | |
4499 | goto unlock; | |
4500 | } | |
4501 | sband = rdev->wiphy.bands[band]; | |
4502 | if (sband == NULL) { | |
4503 | err = -EINVAL; | |
4504 | goto unlock; | |
4505 | } | |
4506 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | |
4507 | nla_len(tx_rates), nl80211_txattr_policy); | |
4508 | if (tb[NL80211_TXRATE_LEGACY]) { | |
4509 | mask.control[band].legacy = rateset_to_mask( | |
4510 | sband, | |
4511 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
4512 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
4513 | if (mask.control[band].legacy == 0) { | |
4514 | err = -EINVAL; | |
4515 | goto unlock; | |
4516 | } | |
4517 | } | |
4518 | } | |
4519 | ||
4520 | err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); | |
4521 | ||
4522 | unlock: | |
4523 | dev_put(dev); | |
4524 | cfg80211_unlock_rdev(rdev); | |
4525 | unlock_rtnl: | |
4526 | rtnl_unlock(); | |
4527 | return err; | |
4528 | } | |
4529 | ||
026331c4 JM |
4530 | static int nl80211_register_action(struct sk_buff *skb, struct genl_info *info) |
4531 | { | |
4532 | struct cfg80211_registered_device *rdev; | |
4533 | struct net_device *dev; | |
4534 | int err; | |
4535 | ||
4536 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
4537 | return -EINVAL; | |
4538 | ||
4539 | if (nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]) < 1) | |
4540 | return -EINVAL; | |
4541 | ||
4542 | rtnl_lock(); | |
4543 | ||
4544 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4545 | if (err) | |
4546 | goto unlock_rtnl; | |
4547 | ||
4548 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4549 | err = -EOPNOTSUPP; | |
4550 | goto out; | |
4551 | } | |
4552 | ||
4553 | /* not much point in registering if we can't reply */ | |
4554 | if (!rdev->ops->action) { | |
4555 | err = -EOPNOTSUPP; | |
4556 | goto out; | |
4557 | } | |
4558 | ||
4559 | err = cfg80211_mlme_register_action(dev->ieee80211_ptr, info->snd_pid, | |
4560 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), | |
4561 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
4562 | out: | |
4563 | cfg80211_unlock_rdev(rdev); | |
4564 | dev_put(dev); | |
4565 | unlock_rtnl: | |
4566 | rtnl_unlock(); | |
4567 | return err; | |
4568 | } | |
4569 | ||
4570 | static int nl80211_action(struct sk_buff *skb, struct genl_info *info) | |
4571 | { | |
4572 | struct cfg80211_registered_device *rdev; | |
4573 | struct net_device *dev; | |
4574 | struct ieee80211_channel *chan; | |
4575 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
4576 | u32 freq; | |
4577 | int err; | |
4578 | void *hdr; | |
4579 | u64 cookie; | |
4580 | struct sk_buff *msg; | |
4581 | ||
4582 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
4583 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4584 | return -EINVAL; | |
4585 | ||
4586 | rtnl_lock(); | |
4587 | ||
4588 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4589 | if (err) | |
4590 | goto unlock_rtnl; | |
4591 | ||
4592 | if (!rdev->ops->action) { | |
4593 | err = -EOPNOTSUPP; | |
4594 | goto out; | |
4595 | } | |
4596 | ||
4597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | |
4598 | err = -EOPNOTSUPP; | |
4599 | goto out; | |
4600 | } | |
4601 | ||
4602 | if (!netif_running(dev)) { | |
4603 | err = -ENETDOWN; | |
4604 | goto out; | |
4605 | } | |
4606 | ||
4607 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
4608 | channel_type = nla_get_u32( | |
4609 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
4610 | if (channel_type != NL80211_CHAN_NO_HT && | |
4611 | channel_type != NL80211_CHAN_HT20 && | |
4612 | channel_type != NL80211_CHAN_HT40PLUS && | |
4613 | channel_type != NL80211_CHAN_HT40MINUS) | |
4614 | err = -EINVAL; | |
4615 | goto out; | |
4616 | } | |
4617 | ||
4618 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
4619 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4620 | if (chan == NULL) { | |
4621 | err = -EINVAL; | |
4622 | goto out; | |
4623 | } | |
4624 | ||
4625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4626 | if (!msg) { | |
4627 | err = -ENOMEM; | |
4628 | goto out; | |
4629 | } | |
4630 | ||
4631 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
4632 | NL80211_CMD_ACTION); | |
4633 | ||
4634 | if (IS_ERR(hdr)) { | |
4635 | err = PTR_ERR(hdr); | |
4636 | goto free_msg; | |
4637 | } | |
4638 | err = cfg80211_mlme_action(rdev, dev, chan, channel_type, | |
4639 | nla_data(info->attrs[NL80211_ATTR_FRAME]), | |
4640 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
4641 | &cookie); | |
4642 | if (err) | |
4643 | goto free_msg; | |
4644 | ||
4645 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
4646 | ||
4647 | genlmsg_end(msg, hdr); | |
4648 | err = genlmsg_reply(msg, info); | |
4649 | goto out; | |
4650 | ||
4651 | nla_put_failure: | |
4652 | err = -ENOBUFS; | |
4653 | free_msg: | |
4654 | nlmsg_free(msg); | |
4655 | out: | |
4656 | cfg80211_unlock_rdev(rdev); | |
4657 | dev_put(dev); | |
4658 | unlock_rtnl: | |
4659 | rtnl_unlock(); | |
4660 | return err; | |
4661 | } | |
4662 | ||
ffb9eb3d KV |
4663 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
4664 | { | |
4665 | struct cfg80211_registered_device *rdev; | |
4666 | struct wireless_dev *wdev; | |
4667 | struct net_device *dev; | |
4668 | u8 ps_state; | |
4669 | bool state; | |
4670 | int err; | |
4671 | ||
4672 | if (!info->attrs[NL80211_ATTR_PS_STATE]) { | |
4673 | err = -EINVAL; | |
4674 | goto out; | |
4675 | } | |
4676 | ||
4677 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
4678 | ||
4679 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) { | |
4680 | err = -EINVAL; | |
4681 | goto out; | |
4682 | } | |
4683 | ||
4684 | rtnl_lock(); | |
4685 | ||
4686 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4687 | if (err) | |
4688 | goto unlock_rdev; | |
4689 | ||
4690 | wdev = dev->ieee80211_ptr; | |
4691 | ||
4692 | if (!rdev->ops->set_power_mgmt) { | |
4693 | err = -EOPNOTSUPP; | |
4694 | goto unlock_rdev; | |
4695 | } | |
4696 | ||
4697 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
4698 | ||
4699 | if (state == wdev->ps) | |
4700 | goto unlock_rdev; | |
4701 | ||
4702 | wdev->ps = state; | |
4703 | ||
4704 | if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps, | |
4705 | wdev->ps_timeout)) | |
4706 | /* assume this means it's off */ | |
4707 | wdev->ps = false; | |
4708 | ||
4709 | unlock_rdev: | |
4710 | cfg80211_unlock_rdev(rdev); | |
4711 | dev_put(dev); | |
4712 | rtnl_unlock(); | |
4713 | ||
4714 | out: | |
4715 | return err; | |
4716 | } | |
4717 | ||
4718 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
4719 | { | |
4720 | struct cfg80211_registered_device *rdev; | |
4721 | enum nl80211_ps_state ps_state; | |
4722 | struct wireless_dev *wdev; | |
4723 | struct net_device *dev; | |
4724 | struct sk_buff *msg; | |
4725 | void *hdr; | |
4726 | int err; | |
4727 | ||
4728 | rtnl_lock(); | |
4729 | ||
4730 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4731 | if (err) | |
4732 | goto unlock_rtnl; | |
4733 | ||
4734 | wdev = dev->ieee80211_ptr; | |
4735 | ||
4736 | if (!rdev->ops->set_power_mgmt) { | |
4737 | err = -EOPNOTSUPP; | |
4738 | goto out; | |
4739 | } | |
4740 | ||
4741 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4742 | if (!msg) { | |
4743 | err = -ENOMEM; | |
4744 | goto out; | |
4745 | } | |
4746 | ||
4747 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
4748 | NL80211_CMD_GET_POWER_SAVE); | |
4749 | if (!hdr) { | |
4750 | err = -ENOMEM; | |
4751 | goto free_msg; | |
4752 | } | |
4753 | ||
4754 | if (wdev->ps) | |
4755 | ps_state = NL80211_PS_ENABLED; | |
4756 | else | |
4757 | ps_state = NL80211_PS_DISABLED; | |
4758 | ||
4759 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | |
4760 | ||
4761 | genlmsg_end(msg, hdr); | |
4762 | err = genlmsg_reply(msg, info); | |
4763 | goto out; | |
4764 | ||
4765 | nla_put_failure: | |
4766 | err = -ENOBUFS; | |
4767 | ||
4768 | free_msg: | |
4769 | nlmsg_free(msg); | |
4770 | ||
4771 | out: | |
4772 | cfg80211_unlock_rdev(rdev); | |
4773 | dev_put(dev); | |
4774 | ||
4775 | unlock_rtnl: | |
4776 | rtnl_unlock(); | |
4777 | ||
4778 | return err; | |
4779 | } | |
4780 | ||
55682965 JB |
4781 | static struct genl_ops nl80211_ops[] = { |
4782 | { | |
4783 | .cmd = NL80211_CMD_GET_WIPHY, | |
4784 | .doit = nl80211_get_wiphy, | |
4785 | .dumpit = nl80211_dump_wiphy, | |
4786 | .policy = nl80211_policy, | |
4787 | /* can be retrieved by unprivileged users */ | |
4788 | }, | |
4789 | { | |
4790 | .cmd = NL80211_CMD_SET_WIPHY, | |
4791 | .doit = nl80211_set_wiphy, | |
4792 | .policy = nl80211_policy, | |
4793 | .flags = GENL_ADMIN_PERM, | |
4794 | }, | |
4795 | { | |
4796 | .cmd = NL80211_CMD_GET_INTERFACE, | |
4797 | .doit = nl80211_get_interface, | |
4798 | .dumpit = nl80211_dump_interface, | |
4799 | .policy = nl80211_policy, | |
4800 | /* can be retrieved by unprivileged users */ | |
4801 | }, | |
4802 | { | |
4803 | .cmd = NL80211_CMD_SET_INTERFACE, | |
4804 | .doit = nl80211_set_interface, | |
4805 | .policy = nl80211_policy, | |
4806 | .flags = GENL_ADMIN_PERM, | |
4807 | }, | |
4808 | { | |
4809 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
4810 | .doit = nl80211_new_interface, | |
4811 | .policy = nl80211_policy, | |
4812 | .flags = GENL_ADMIN_PERM, | |
4813 | }, | |
4814 | { | |
4815 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
4816 | .doit = nl80211_del_interface, | |
4817 | .policy = nl80211_policy, | |
41ade00f JB |
4818 | .flags = GENL_ADMIN_PERM, |
4819 | }, | |
4820 | { | |
4821 | .cmd = NL80211_CMD_GET_KEY, | |
4822 | .doit = nl80211_get_key, | |
4823 | .policy = nl80211_policy, | |
4824 | .flags = GENL_ADMIN_PERM, | |
4825 | }, | |
4826 | { | |
4827 | .cmd = NL80211_CMD_SET_KEY, | |
4828 | .doit = nl80211_set_key, | |
4829 | .policy = nl80211_policy, | |
4830 | .flags = GENL_ADMIN_PERM, | |
4831 | }, | |
4832 | { | |
4833 | .cmd = NL80211_CMD_NEW_KEY, | |
4834 | .doit = nl80211_new_key, | |
4835 | .policy = nl80211_policy, | |
4836 | .flags = GENL_ADMIN_PERM, | |
4837 | }, | |
4838 | { | |
4839 | .cmd = NL80211_CMD_DEL_KEY, | |
4840 | .doit = nl80211_del_key, | |
4841 | .policy = nl80211_policy, | |
55682965 JB |
4842 | .flags = GENL_ADMIN_PERM, |
4843 | }, | |
ed1b6cc7 JB |
4844 | { |
4845 | .cmd = NL80211_CMD_SET_BEACON, | |
4846 | .policy = nl80211_policy, | |
4847 | .flags = GENL_ADMIN_PERM, | |
4848 | .doit = nl80211_addset_beacon, | |
4849 | }, | |
4850 | { | |
4851 | .cmd = NL80211_CMD_NEW_BEACON, | |
4852 | .policy = nl80211_policy, | |
4853 | .flags = GENL_ADMIN_PERM, | |
4854 | .doit = nl80211_addset_beacon, | |
4855 | }, | |
4856 | { | |
4857 | .cmd = NL80211_CMD_DEL_BEACON, | |
4858 | .policy = nl80211_policy, | |
4859 | .flags = GENL_ADMIN_PERM, | |
4860 | .doit = nl80211_del_beacon, | |
4861 | }, | |
5727ef1b JB |
4862 | { |
4863 | .cmd = NL80211_CMD_GET_STATION, | |
4864 | .doit = nl80211_get_station, | |
2ec600d6 | 4865 | .dumpit = nl80211_dump_station, |
5727ef1b | 4866 | .policy = nl80211_policy, |
5727ef1b JB |
4867 | }, |
4868 | { | |
4869 | .cmd = NL80211_CMD_SET_STATION, | |
4870 | .doit = nl80211_set_station, | |
4871 | .policy = nl80211_policy, | |
4872 | .flags = GENL_ADMIN_PERM, | |
4873 | }, | |
4874 | { | |
4875 | .cmd = NL80211_CMD_NEW_STATION, | |
4876 | .doit = nl80211_new_station, | |
4877 | .policy = nl80211_policy, | |
4878 | .flags = GENL_ADMIN_PERM, | |
4879 | }, | |
4880 | { | |
4881 | .cmd = NL80211_CMD_DEL_STATION, | |
4882 | .doit = nl80211_del_station, | |
4883 | .policy = nl80211_policy, | |
2ec600d6 LCC |
4884 | .flags = GENL_ADMIN_PERM, |
4885 | }, | |
4886 | { | |
4887 | .cmd = NL80211_CMD_GET_MPATH, | |
4888 | .doit = nl80211_get_mpath, | |
4889 | .dumpit = nl80211_dump_mpath, | |
4890 | .policy = nl80211_policy, | |
4891 | .flags = GENL_ADMIN_PERM, | |
4892 | }, | |
4893 | { | |
4894 | .cmd = NL80211_CMD_SET_MPATH, | |
4895 | .doit = nl80211_set_mpath, | |
4896 | .policy = nl80211_policy, | |
4897 | .flags = GENL_ADMIN_PERM, | |
4898 | }, | |
4899 | { | |
4900 | .cmd = NL80211_CMD_NEW_MPATH, | |
4901 | .doit = nl80211_new_mpath, | |
4902 | .policy = nl80211_policy, | |
4903 | .flags = GENL_ADMIN_PERM, | |
4904 | }, | |
4905 | { | |
4906 | .cmd = NL80211_CMD_DEL_MPATH, | |
4907 | .doit = nl80211_del_mpath, | |
4908 | .policy = nl80211_policy, | |
9f1ba906 JM |
4909 | .flags = GENL_ADMIN_PERM, |
4910 | }, | |
4911 | { | |
4912 | .cmd = NL80211_CMD_SET_BSS, | |
4913 | .doit = nl80211_set_bss, | |
4914 | .policy = nl80211_policy, | |
b2e1b302 LR |
4915 | .flags = GENL_ADMIN_PERM, |
4916 | }, | |
f130347c LR |
4917 | { |
4918 | .cmd = NL80211_CMD_GET_REG, | |
4919 | .doit = nl80211_get_reg, | |
4920 | .policy = nl80211_policy, | |
4921 | /* can be retrieved by unprivileged users */ | |
4922 | }, | |
b2e1b302 LR |
4923 | { |
4924 | .cmd = NL80211_CMD_SET_REG, | |
4925 | .doit = nl80211_set_reg, | |
4926 | .policy = nl80211_policy, | |
4927 | .flags = GENL_ADMIN_PERM, | |
4928 | }, | |
4929 | { | |
4930 | .cmd = NL80211_CMD_REQ_SET_REG, | |
4931 | .doit = nl80211_req_set_reg, | |
4932 | .policy = nl80211_policy, | |
93da9cc1 | 4933 | .flags = GENL_ADMIN_PERM, |
4934 | }, | |
4935 | { | |
4936 | .cmd = NL80211_CMD_GET_MESH_PARAMS, | |
4937 | .doit = nl80211_get_mesh_params, | |
4938 | .policy = nl80211_policy, | |
4939 | /* can be retrieved by unprivileged users */ | |
4940 | }, | |
4941 | { | |
4942 | .cmd = NL80211_CMD_SET_MESH_PARAMS, | |
4943 | .doit = nl80211_set_mesh_params, | |
4944 | .policy = nl80211_policy, | |
9aed3cc1 JM |
4945 | .flags = GENL_ADMIN_PERM, |
4946 | }, | |
2a519311 JB |
4947 | { |
4948 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
4949 | .doit = nl80211_trigger_scan, | |
4950 | .policy = nl80211_policy, | |
4951 | .flags = GENL_ADMIN_PERM, | |
4952 | }, | |
4953 | { | |
4954 | .cmd = NL80211_CMD_GET_SCAN, | |
4955 | .policy = nl80211_policy, | |
4956 | .dumpit = nl80211_dump_scan, | |
4957 | }, | |
636a5d36 JM |
4958 | { |
4959 | .cmd = NL80211_CMD_AUTHENTICATE, | |
4960 | .doit = nl80211_authenticate, | |
4961 | .policy = nl80211_policy, | |
4962 | .flags = GENL_ADMIN_PERM, | |
4963 | }, | |
4964 | { | |
4965 | .cmd = NL80211_CMD_ASSOCIATE, | |
4966 | .doit = nl80211_associate, | |
4967 | .policy = nl80211_policy, | |
4968 | .flags = GENL_ADMIN_PERM, | |
4969 | }, | |
4970 | { | |
4971 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
4972 | .doit = nl80211_deauthenticate, | |
4973 | .policy = nl80211_policy, | |
4974 | .flags = GENL_ADMIN_PERM, | |
4975 | }, | |
4976 | { | |
4977 | .cmd = NL80211_CMD_DISASSOCIATE, | |
4978 | .doit = nl80211_disassociate, | |
4979 | .policy = nl80211_policy, | |
4980 | .flags = GENL_ADMIN_PERM, | |
4981 | }, | |
04a773ad JB |
4982 | { |
4983 | .cmd = NL80211_CMD_JOIN_IBSS, | |
4984 | .doit = nl80211_join_ibss, | |
4985 | .policy = nl80211_policy, | |
4986 | .flags = GENL_ADMIN_PERM, | |
4987 | }, | |
4988 | { | |
4989 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
4990 | .doit = nl80211_leave_ibss, | |
4991 | .policy = nl80211_policy, | |
4992 | .flags = GENL_ADMIN_PERM, | |
4993 | }, | |
aff89a9b JB |
4994 | #ifdef CONFIG_NL80211_TESTMODE |
4995 | { | |
4996 | .cmd = NL80211_CMD_TESTMODE, | |
4997 | .doit = nl80211_testmode_do, | |
4998 | .policy = nl80211_policy, | |
4999 | .flags = GENL_ADMIN_PERM, | |
5000 | }, | |
5001 | #endif | |
b23aa676 SO |
5002 | { |
5003 | .cmd = NL80211_CMD_CONNECT, | |
5004 | .doit = nl80211_connect, | |
5005 | .policy = nl80211_policy, | |
5006 | .flags = GENL_ADMIN_PERM, | |
5007 | }, | |
5008 | { | |
5009 | .cmd = NL80211_CMD_DISCONNECT, | |
5010 | .doit = nl80211_disconnect, | |
5011 | .policy = nl80211_policy, | |
5012 | .flags = GENL_ADMIN_PERM, | |
5013 | }, | |
463d0183 JB |
5014 | { |
5015 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
5016 | .doit = nl80211_wiphy_netns, | |
5017 | .policy = nl80211_policy, | |
5018 | .flags = GENL_ADMIN_PERM, | |
5019 | }, | |
61fa713c HS |
5020 | { |
5021 | .cmd = NL80211_CMD_GET_SURVEY, | |
5022 | .policy = nl80211_policy, | |
5023 | .dumpit = nl80211_dump_survey, | |
5024 | }, | |
67fbb16b SO |
5025 | { |
5026 | .cmd = NL80211_CMD_SET_PMKSA, | |
5027 | .doit = nl80211_setdel_pmksa, | |
5028 | .policy = nl80211_policy, | |
5029 | .flags = GENL_ADMIN_PERM, | |
5030 | }, | |
5031 | { | |
5032 | .cmd = NL80211_CMD_DEL_PMKSA, | |
5033 | .doit = nl80211_setdel_pmksa, | |
5034 | .policy = nl80211_policy, | |
5035 | .flags = GENL_ADMIN_PERM, | |
5036 | }, | |
5037 | { | |
5038 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
5039 | .doit = nl80211_flush_pmksa, | |
5040 | .policy = nl80211_policy, | |
5041 | .flags = GENL_ADMIN_PERM, | |
5042 | }, | |
9588bbd5 JM |
5043 | { |
5044 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
5045 | .doit = nl80211_remain_on_channel, | |
5046 | .policy = nl80211_policy, | |
5047 | .flags = GENL_ADMIN_PERM, | |
5048 | }, | |
5049 | { | |
5050 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
5051 | .doit = nl80211_cancel_remain_on_channel, | |
5052 | .policy = nl80211_policy, | |
5053 | .flags = GENL_ADMIN_PERM, | |
5054 | }, | |
13ae75b1 JM |
5055 | { |
5056 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
5057 | .doit = nl80211_set_tx_bitrate_mask, | |
5058 | .policy = nl80211_policy, | |
5059 | .flags = GENL_ADMIN_PERM, | |
5060 | }, | |
026331c4 JM |
5061 | { |
5062 | .cmd = NL80211_CMD_REGISTER_ACTION, | |
5063 | .doit = nl80211_register_action, | |
5064 | .policy = nl80211_policy, | |
5065 | .flags = GENL_ADMIN_PERM, | |
5066 | }, | |
5067 | { | |
5068 | .cmd = NL80211_CMD_ACTION, | |
5069 | .doit = nl80211_action, | |
5070 | .policy = nl80211_policy, | |
5071 | .flags = GENL_ADMIN_PERM, | |
5072 | }, | |
ffb9eb3d KV |
5073 | { |
5074 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
5075 | .doit = nl80211_set_power_save, | |
5076 | .policy = nl80211_policy, | |
5077 | .flags = GENL_ADMIN_PERM, | |
5078 | }, | |
5079 | { | |
5080 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
5081 | .doit = nl80211_get_power_save, | |
5082 | .policy = nl80211_policy, | |
5083 | /* can be retrieved by unprivileged users */ | |
5084 | }, | |
55682965 | 5085 | }; |
9588bbd5 | 5086 | |
6039f6d2 JM |
5087 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
5088 | .name = "mlme", | |
5089 | }; | |
55682965 JB |
5090 | |
5091 | /* multicast groups */ | |
5092 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
5093 | .name = "config", | |
5094 | }; | |
2a519311 JB |
5095 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
5096 | .name = "scan", | |
5097 | }; | |
73d54c9e LR |
5098 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
5099 | .name = "regulatory", | |
5100 | }; | |
55682965 JB |
5101 | |
5102 | /* notification functions */ | |
5103 | ||
5104 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
5105 | { | |
5106 | struct sk_buff *msg; | |
5107 | ||
fd2120ca | 5108 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
5109 | if (!msg) |
5110 | return; | |
5111 | ||
5112 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
5113 | nlmsg_free(msg); | |
5114 | return; | |
5115 | } | |
5116 | ||
463d0183 JB |
5117 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5118 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
5119 | } |
5120 | ||
362a415d JB |
5121 | static int nl80211_add_scan_req(struct sk_buff *msg, |
5122 | struct cfg80211_registered_device *rdev) | |
5123 | { | |
5124 | struct cfg80211_scan_request *req = rdev->scan_req; | |
5125 | struct nlattr *nest; | |
5126 | int i; | |
5127 | ||
667503dd JB |
5128 | ASSERT_RDEV_LOCK(rdev); |
5129 | ||
362a415d JB |
5130 | if (WARN_ON(!req)) |
5131 | return 0; | |
5132 | ||
5133 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
5134 | if (!nest) | |
5135 | goto nla_put_failure; | |
5136 | for (i = 0; i < req->n_ssids; i++) | |
5137 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); | |
5138 | nla_nest_end(msg, nest); | |
5139 | ||
5140 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
5141 | if (!nest) | |
5142 | goto nla_put_failure; | |
5143 | for (i = 0; i < req->n_channels; i++) | |
5144 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); | |
5145 | nla_nest_end(msg, nest); | |
5146 | ||
5147 | if (req->ie) | |
5148 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); | |
5149 | ||
5150 | return 0; | |
5151 | nla_put_failure: | |
5152 | return -ENOBUFS; | |
5153 | } | |
5154 | ||
a538e2d5 JB |
5155 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
5156 | struct cfg80211_registered_device *rdev, | |
5157 | struct net_device *netdev, | |
5158 | u32 pid, u32 seq, int flags, | |
5159 | u32 cmd) | |
2a519311 JB |
5160 | { |
5161 | void *hdr; | |
5162 | ||
5163 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
5164 | if (!hdr) | |
5165 | return -1; | |
5166 | ||
b5850a7a | 5167 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
2a519311 JB |
5168 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
5169 | ||
362a415d JB |
5170 | /* ignore errors and send incomplete event anyway */ |
5171 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
5172 | |
5173 | return genlmsg_end(msg, hdr); | |
5174 | ||
5175 | nla_put_failure: | |
5176 | genlmsg_cancel(msg, hdr); | |
5177 | return -EMSGSIZE; | |
5178 | } | |
5179 | ||
a538e2d5 JB |
5180 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
5181 | struct net_device *netdev) | |
5182 | { | |
5183 | struct sk_buff *msg; | |
5184 | ||
5185 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
5186 | if (!msg) | |
5187 | return; | |
5188 | ||
5189 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
5190 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
5191 | nlmsg_free(msg); | |
5192 | return; | |
5193 | } | |
5194 | ||
463d0183 JB |
5195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5196 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
5197 | } |
5198 | ||
2a519311 JB |
5199 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
5200 | struct net_device *netdev) | |
5201 | { | |
5202 | struct sk_buff *msg; | |
5203 | ||
fd2120ca | 5204 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
5205 | if (!msg) |
5206 | return; | |
5207 | ||
a538e2d5 JB |
5208 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
5209 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
5210 | nlmsg_free(msg); |
5211 | return; | |
5212 | } | |
5213 | ||
463d0183 JB |
5214 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5215 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
5216 | } |
5217 | ||
5218 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
5219 | struct net_device *netdev) | |
5220 | { | |
5221 | struct sk_buff *msg; | |
5222 | ||
fd2120ca | 5223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
5224 | if (!msg) |
5225 | return; | |
5226 | ||
a538e2d5 JB |
5227 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
5228 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
5229 | nlmsg_free(msg); |
5230 | return; | |
5231 | } | |
5232 | ||
463d0183 JB |
5233 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5234 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
5235 | } |
5236 | ||
73d54c9e LR |
5237 | /* |
5238 | * This can happen on global regulatory changes or device specific settings | |
5239 | * based on custom world regulatory domains. | |
5240 | */ | |
5241 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
5242 | { | |
5243 | struct sk_buff *msg; | |
5244 | void *hdr; | |
5245 | ||
fd2120ca | 5246 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
5247 | if (!msg) |
5248 | return; | |
5249 | ||
5250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
5251 | if (!hdr) { | |
5252 | nlmsg_free(msg); | |
5253 | return; | |
5254 | } | |
5255 | ||
5256 | /* Userspace can always count this one always being set */ | |
5257 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); | |
5258 | ||
5259 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') | |
5260 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5261 | NL80211_REGDOM_TYPE_WORLD); | |
5262 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') | |
5263 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5264 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); | |
5265 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
5266 | request->intersect) | |
5267 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5268 | NL80211_REGDOM_TYPE_INTERSECTION); | |
5269 | else { | |
5270 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5271 | NL80211_REGDOM_TYPE_COUNTRY); | |
5272 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); | |
5273 | } | |
5274 | ||
5275 | if (wiphy_idx_valid(request->wiphy_idx)) | |
5276 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); | |
5277 | ||
5278 | if (genlmsg_end(msg, hdr) < 0) { | |
5279 | nlmsg_free(msg); | |
5280 | return; | |
5281 | } | |
5282 | ||
bc43b28c | 5283 | rcu_read_lock(); |
463d0183 | 5284 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
5285 | GFP_ATOMIC); |
5286 | rcu_read_unlock(); | |
73d54c9e LR |
5287 | |
5288 | return; | |
5289 | ||
5290 | nla_put_failure: | |
5291 | genlmsg_cancel(msg, hdr); | |
5292 | nlmsg_free(msg); | |
5293 | } | |
5294 | ||
6039f6d2 JM |
5295 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
5296 | struct net_device *netdev, | |
5297 | const u8 *buf, size_t len, | |
e6d6e342 | 5298 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
5299 | { |
5300 | struct sk_buff *msg; | |
5301 | void *hdr; | |
5302 | ||
e6d6e342 | 5303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
5304 | if (!msg) |
5305 | return; | |
5306 | ||
5307 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
5308 | if (!hdr) { | |
5309 | nlmsg_free(msg); | |
5310 | return; | |
5311 | } | |
5312 | ||
5313 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5314 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5315 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
5316 | ||
5317 | if (genlmsg_end(msg, hdr) < 0) { | |
5318 | nlmsg_free(msg); | |
5319 | return; | |
5320 | } | |
5321 | ||
463d0183 JB |
5322 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5323 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
5324 | return; |
5325 | ||
5326 | nla_put_failure: | |
5327 | genlmsg_cancel(msg, hdr); | |
5328 | nlmsg_free(msg); | |
5329 | } | |
5330 | ||
5331 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5332 | struct net_device *netdev, const u8 *buf, |
5333 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
5334 | { |
5335 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5336 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
5337 | } |
5338 | ||
5339 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
5340 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 5341 | size_t len, gfp_t gfp) |
6039f6d2 | 5342 | { |
e6d6e342 JB |
5343 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
5344 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
5345 | } |
5346 | ||
53b46b84 | 5347 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
5348 | struct net_device *netdev, const u8 *buf, |
5349 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
5350 | { |
5351 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5352 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
5353 | } |
5354 | ||
53b46b84 JM |
5355 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
5356 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 5357 | size_t len, gfp_t gfp) |
6039f6d2 JM |
5358 | { |
5359 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5360 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
5361 | } |
5362 | ||
1b06bb40 LR |
5363 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
5364 | struct net_device *netdev, int cmd, | |
e6d6e342 | 5365 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
5366 | { |
5367 | struct sk_buff *msg; | |
5368 | void *hdr; | |
5369 | ||
e6d6e342 | 5370 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
5371 | if (!msg) |
5372 | return; | |
5373 | ||
5374 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
5375 | if (!hdr) { | |
5376 | nlmsg_free(msg); | |
5377 | return; | |
5378 | } | |
5379 | ||
5380 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5381 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5382 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); | |
5383 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
5384 | ||
5385 | if (genlmsg_end(msg, hdr) < 0) { | |
5386 | nlmsg_free(msg); | |
5387 | return; | |
5388 | } | |
5389 | ||
463d0183 JB |
5390 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5391 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
5392 | return; |
5393 | ||
5394 | nla_put_failure: | |
5395 | genlmsg_cancel(msg, hdr); | |
5396 | nlmsg_free(msg); | |
5397 | } | |
5398 | ||
5399 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5400 | struct net_device *netdev, const u8 *addr, |
5401 | gfp_t gfp) | |
1965c853 JM |
5402 | { |
5403 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 5404 | addr, gfp); |
1965c853 JM |
5405 | } |
5406 | ||
5407 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5408 | struct net_device *netdev, const u8 *addr, |
5409 | gfp_t gfp) | |
1965c853 | 5410 | { |
e6d6e342 JB |
5411 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
5412 | addr, gfp); | |
1965c853 JM |
5413 | } |
5414 | ||
b23aa676 SO |
5415 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
5416 | struct net_device *netdev, const u8 *bssid, | |
5417 | const u8 *req_ie, size_t req_ie_len, | |
5418 | const u8 *resp_ie, size_t resp_ie_len, | |
5419 | u16 status, gfp_t gfp) | |
5420 | { | |
5421 | struct sk_buff *msg; | |
5422 | void *hdr; | |
5423 | ||
5424 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
5425 | if (!msg) | |
5426 | return; | |
5427 | ||
5428 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
5429 | if (!hdr) { | |
5430 | nlmsg_free(msg); | |
5431 | return; | |
5432 | } | |
5433 | ||
5434 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5435 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5436 | if (bssid) | |
5437 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5438 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); | |
5439 | if (req_ie) | |
5440 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
5441 | if (resp_ie) | |
5442 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
5443 | ||
5444 | if (genlmsg_end(msg, hdr) < 0) { | |
5445 | nlmsg_free(msg); | |
5446 | return; | |
5447 | } | |
5448 | ||
463d0183 JB |
5449 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5450 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
5451 | return; |
5452 | ||
5453 | nla_put_failure: | |
5454 | genlmsg_cancel(msg, hdr); | |
5455 | nlmsg_free(msg); | |
5456 | ||
5457 | } | |
5458 | ||
5459 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
5460 | struct net_device *netdev, const u8 *bssid, | |
5461 | const u8 *req_ie, size_t req_ie_len, | |
5462 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
5463 | { | |
5464 | struct sk_buff *msg; | |
5465 | void *hdr; | |
5466 | ||
5467 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
5468 | if (!msg) | |
5469 | return; | |
5470 | ||
5471 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
5472 | if (!hdr) { | |
5473 | nlmsg_free(msg); | |
5474 | return; | |
5475 | } | |
5476 | ||
5477 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5478 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5479 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5480 | if (req_ie) | |
5481 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
5482 | if (resp_ie) | |
5483 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
5484 | ||
5485 | if (genlmsg_end(msg, hdr) < 0) { | |
5486 | nlmsg_free(msg); | |
5487 | return; | |
5488 | } | |
5489 | ||
463d0183 JB |
5490 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5491 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
5492 | return; |
5493 | ||
5494 | nla_put_failure: | |
5495 | genlmsg_cancel(msg, hdr); | |
5496 | nlmsg_free(msg); | |
5497 | ||
5498 | } | |
5499 | ||
5500 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
5501 | struct net_device *netdev, u16 reason, | |
667503dd | 5502 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
5503 | { |
5504 | struct sk_buff *msg; | |
5505 | void *hdr; | |
5506 | ||
667503dd | 5507 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
5508 | if (!msg) |
5509 | return; | |
5510 | ||
5511 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
5512 | if (!hdr) { | |
5513 | nlmsg_free(msg); | |
5514 | return; | |
5515 | } | |
5516 | ||
5517 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5518 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5519 | if (from_ap && reason) | |
5520 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); | |
5521 | if (from_ap) | |
5522 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); | |
5523 | if (ie) | |
5524 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); | |
5525 | ||
5526 | if (genlmsg_end(msg, hdr) < 0) { | |
5527 | nlmsg_free(msg); | |
5528 | return; | |
5529 | } | |
5530 | ||
463d0183 JB |
5531 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5532 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
5533 | return; |
5534 | ||
5535 | nla_put_failure: | |
5536 | genlmsg_cancel(msg, hdr); | |
5537 | nlmsg_free(msg); | |
5538 | ||
5539 | } | |
5540 | ||
04a773ad JB |
5541 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
5542 | struct net_device *netdev, const u8 *bssid, | |
5543 | gfp_t gfp) | |
5544 | { | |
5545 | struct sk_buff *msg; | |
5546 | void *hdr; | |
5547 | ||
fd2120ca | 5548 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
5549 | if (!msg) |
5550 | return; | |
5551 | ||
5552 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
5553 | if (!hdr) { | |
5554 | nlmsg_free(msg); | |
5555 | return; | |
5556 | } | |
5557 | ||
5558 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5559 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5560 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5561 | ||
5562 | if (genlmsg_end(msg, hdr) < 0) { | |
5563 | nlmsg_free(msg); | |
5564 | return; | |
5565 | } | |
5566 | ||
463d0183 JB |
5567 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5568 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
5569 | return; |
5570 | ||
5571 | nla_put_failure: | |
5572 | genlmsg_cancel(msg, hdr); | |
5573 | nlmsg_free(msg); | |
5574 | } | |
5575 | ||
a3b8b056 JM |
5576 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
5577 | struct net_device *netdev, const u8 *addr, | |
5578 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 5579 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
5580 | { |
5581 | struct sk_buff *msg; | |
5582 | void *hdr; | |
5583 | ||
e6d6e342 | 5584 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
5585 | if (!msg) |
5586 | return; | |
5587 | ||
5588 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
5589 | if (!hdr) { | |
5590 | nlmsg_free(msg); | |
5591 | return; | |
5592 | } | |
5593 | ||
5594 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5595 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5596 | if (addr) | |
5597 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
5598 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | |
5599 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | |
5600 | if (tsc) | |
5601 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | |
5602 | ||
5603 | if (genlmsg_end(msg, hdr) < 0) { | |
5604 | nlmsg_free(msg); | |
5605 | return; | |
5606 | } | |
5607 | ||
463d0183 JB |
5608 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5609 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
5610 | return; |
5611 | ||
5612 | nla_put_failure: | |
5613 | genlmsg_cancel(msg, hdr); | |
5614 | nlmsg_free(msg); | |
5615 | } | |
5616 | ||
6bad8766 LR |
5617 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
5618 | struct ieee80211_channel *channel_before, | |
5619 | struct ieee80211_channel *channel_after) | |
5620 | { | |
5621 | struct sk_buff *msg; | |
5622 | void *hdr; | |
5623 | struct nlattr *nl_freq; | |
5624 | ||
fd2120ca | 5625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
5626 | if (!msg) |
5627 | return; | |
5628 | ||
5629 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
5630 | if (!hdr) { | |
5631 | nlmsg_free(msg); | |
5632 | return; | |
5633 | } | |
5634 | ||
5635 | /* | |
5636 | * Since we are applying the beacon hint to a wiphy we know its | |
5637 | * wiphy_idx is valid | |
5638 | */ | |
5639 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); | |
5640 | ||
5641 | /* Before */ | |
5642 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
5643 | if (!nl_freq) | |
5644 | goto nla_put_failure; | |
5645 | if (nl80211_msg_put_channel(msg, channel_before)) | |
5646 | goto nla_put_failure; | |
5647 | nla_nest_end(msg, nl_freq); | |
5648 | ||
5649 | /* After */ | |
5650 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
5651 | if (!nl_freq) | |
5652 | goto nla_put_failure; | |
5653 | if (nl80211_msg_put_channel(msg, channel_after)) | |
5654 | goto nla_put_failure; | |
5655 | nla_nest_end(msg, nl_freq); | |
5656 | ||
5657 | if (genlmsg_end(msg, hdr) < 0) { | |
5658 | nlmsg_free(msg); | |
5659 | return; | |
5660 | } | |
5661 | ||
463d0183 JB |
5662 | rcu_read_lock(); |
5663 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
5664 | GFP_ATOMIC); | |
5665 | rcu_read_unlock(); | |
6bad8766 LR |
5666 | |
5667 | return; | |
5668 | ||
5669 | nla_put_failure: | |
5670 | genlmsg_cancel(msg, hdr); | |
5671 | nlmsg_free(msg); | |
5672 | } | |
5673 | ||
9588bbd5 JM |
5674 | static void nl80211_send_remain_on_chan_event( |
5675 | int cmd, struct cfg80211_registered_device *rdev, | |
5676 | struct net_device *netdev, u64 cookie, | |
5677 | struct ieee80211_channel *chan, | |
5678 | enum nl80211_channel_type channel_type, | |
5679 | unsigned int duration, gfp_t gfp) | |
5680 | { | |
5681 | struct sk_buff *msg; | |
5682 | void *hdr; | |
5683 | ||
5684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
5685 | if (!msg) | |
5686 | return; | |
5687 | ||
5688 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
5689 | if (!hdr) { | |
5690 | nlmsg_free(msg); | |
5691 | return; | |
5692 | } | |
5693 | ||
5694 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5695 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5696 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); | |
5697 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); | |
5698 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
5699 | ||
5700 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) | |
5701 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
5702 | ||
5703 | if (genlmsg_end(msg, hdr) < 0) { | |
5704 | nlmsg_free(msg); | |
5705 | return; | |
5706 | } | |
5707 | ||
5708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
5709 | nl80211_mlme_mcgrp.id, gfp); | |
5710 | return; | |
5711 | ||
5712 | nla_put_failure: | |
5713 | genlmsg_cancel(msg, hdr); | |
5714 | nlmsg_free(msg); | |
5715 | } | |
5716 | ||
5717 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
5718 | struct net_device *netdev, u64 cookie, | |
5719 | struct ieee80211_channel *chan, | |
5720 | enum nl80211_channel_type channel_type, | |
5721 | unsigned int duration, gfp_t gfp) | |
5722 | { | |
5723 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
5724 | rdev, netdev, cookie, chan, | |
5725 | channel_type, duration, gfp); | |
5726 | } | |
5727 | ||
5728 | void nl80211_send_remain_on_channel_cancel( | |
5729 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
5730 | u64 cookie, struct ieee80211_channel *chan, | |
5731 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
5732 | { | |
5733 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
5734 | rdev, netdev, cookie, chan, | |
5735 | channel_type, 0, gfp); | |
5736 | } | |
5737 | ||
98b62183 JB |
5738 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
5739 | struct net_device *dev, const u8 *mac_addr, | |
5740 | struct station_info *sinfo, gfp_t gfp) | |
5741 | { | |
5742 | struct sk_buff *msg; | |
5743 | ||
5744 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
5745 | if (!msg) | |
5746 | return; | |
5747 | ||
5748 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { | |
5749 | nlmsg_free(msg); | |
5750 | return; | |
5751 | } | |
5752 | ||
5753 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
5754 | nl80211_mlme_mcgrp.id, gfp); | |
5755 | } | |
5756 | ||
026331c4 JM |
5757 | int nl80211_send_action(struct cfg80211_registered_device *rdev, |
5758 | struct net_device *netdev, u32 nlpid, | |
5759 | int freq, const u8 *buf, size_t len, gfp_t gfp) | |
5760 | { | |
5761 | struct sk_buff *msg; | |
5762 | void *hdr; | |
5763 | int err; | |
5764 | ||
5765 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
5766 | if (!msg) | |
5767 | return -ENOMEM; | |
5768 | ||
5769 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION); | |
5770 | if (!hdr) { | |
5771 | nlmsg_free(msg); | |
5772 | return -ENOMEM; | |
5773 | } | |
5774 | ||
5775 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5776 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5777 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
5778 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
5779 | ||
5780 | err = genlmsg_end(msg, hdr); | |
5781 | if (err < 0) { | |
5782 | nlmsg_free(msg); | |
5783 | return err; | |
5784 | } | |
5785 | ||
5786 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
5787 | if (err < 0) | |
5788 | return err; | |
5789 | return 0; | |
5790 | ||
5791 | nla_put_failure: | |
5792 | genlmsg_cancel(msg, hdr); | |
5793 | nlmsg_free(msg); | |
5794 | return -ENOBUFS; | |
5795 | } | |
5796 | ||
5797 | void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev, | |
5798 | struct net_device *netdev, u64 cookie, | |
5799 | const u8 *buf, size_t len, bool ack, | |
5800 | gfp_t gfp) | |
5801 | { | |
5802 | struct sk_buff *msg; | |
5803 | void *hdr; | |
5804 | ||
5805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
5806 | if (!msg) | |
5807 | return; | |
5808 | ||
5809 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS); | |
5810 | if (!hdr) { | |
5811 | nlmsg_free(msg); | |
5812 | return; | |
5813 | } | |
5814 | ||
5815 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5816 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5817 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
5818 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
5819 | if (ack) | |
5820 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); | |
5821 | ||
5822 | if (genlmsg_end(msg, hdr) < 0) { | |
5823 | nlmsg_free(msg); | |
5824 | return; | |
5825 | } | |
5826 | ||
5827 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
5828 | return; | |
5829 | ||
5830 | nla_put_failure: | |
5831 | genlmsg_cancel(msg, hdr); | |
5832 | nlmsg_free(msg); | |
5833 | } | |
5834 | ||
5835 | static int nl80211_netlink_notify(struct notifier_block * nb, | |
5836 | unsigned long state, | |
5837 | void *_notify) | |
5838 | { | |
5839 | struct netlink_notify *notify = _notify; | |
5840 | struct cfg80211_registered_device *rdev; | |
5841 | struct wireless_dev *wdev; | |
5842 | ||
5843 | if (state != NETLINK_URELEASE) | |
5844 | return NOTIFY_DONE; | |
5845 | ||
5846 | rcu_read_lock(); | |
5847 | ||
5848 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) | |
5849 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) | |
5850 | cfg80211_mlme_unregister_actions(wdev, notify->pid); | |
5851 | ||
5852 | rcu_read_unlock(); | |
5853 | ||
5854 | return NOTIFY_DONE; | |
5855 | } | |
5856 | ||
5857 | static struct notifier_block nl80211_netlink_notifier = { | |
5858 | .notifier_call = nl80211_netlink_notify, | |
5859 | }; | |
5860 | ||
55682965 JB |
5861 | /* initialisation/exit functions */ |
5862 | ||
5863 | int nl80211_init(void) | |
5864 | { | |
0d63cbb5 | 5865 | int err; |
55682965 | 5866 | |
0d63cbb5 MM |
5867 | err = genl_register_family_with_ops(&nl80211_fam, |
5868 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
5869 | if (err) |
5870 | return err; | |
5871 | ||
55682965 JB |
5872 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
5873 | if (err) | |
5874 | goto err_out; | |
5875 | ||
2a519311 JB |
5876 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
5877 | if (err) | |
5878 | goto err_out; | |
5879 | ||
73d54c9e LR |
5880 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
5881 | if (err) | |
5882 | goto err_out; | |
5883 | ||
6039f6d2 JM |
5884 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
5885 | if (err) | |
5886 | goto err_out; | |
5887 | ||
aff89a9b JB |
5888 | #ifdef CONFIG_NL80211_TESTMODE |
5889 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
5890 | if (err) | |
5891 | goto err_out; | |
5892 | #endif | |
5893 | ||
026331c4 JM |
5894 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
5895 | if (err) | |
5896 | goto err_out; | |
5897 | ||
55682965 JB |
5898 | return 0; |
5899 | err_out: | |
5900 | genl_unregister_family(&nl80211_fam); | |
5901 | return err; | |
5902 | } | |
5903 | ||
5904 | void nl80211_exit(void) | |
5905 | { | |
026331c4 | 5906 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
5907 | genl_unregister_family(&nl80211_fam); |
5908 | } |