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