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