]>
Commit | Line | Data |
---|---|---|
fee52678 JB |
1 | /* |
2 | * cfg80211 - wext compat code | |
3 | * | |
4 | * This is temporary code until all wireless functionality is migrated | |
5 | * into cfg80211, when that happens all the exports here go away and | |
6 | * we directly assign the wireless handlers of wireless interfaces. | |
7 | * | |
08645126 | 8 | * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net> |
fee52678 JB |
9 | */ |
10 | ||
11 | #include <linux/wireless.h> | |
12 | #include <linux/nl80211.h> | |
691597cb | 13 | #include <linux/if_arp.h> |
08645126 | 14 | #include <linux/etherdevice.h> |
fee52678 | 15 | #include <net/iw_handler.h> |
fee52678 | 16 | #include <net/cfg80211.h> |
0e82ffe3 | 17 | #include "wext-compat.h" |
fee52678 JB |
18 | #include "core.h" |
19 | ||
20 | int cfg80211_wext_giwname(struct net_device *dev, | |
21 | struct iw_request_info *info, | |
22 | char *name, char *extra) | |
23 | { | |
24 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
25 | struct ieee80211_supported_band *sband; | |
26 | bool is_ht = false, is_a = false, is_b = false, is_g = false; | |
27 | ||
28 | if (!wdev) | |
29 | return -EOPNOTSUPP; | |
30 | ||
31 | sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ]; | |
32 | if (sband) { | |
33 | is_a = true; | |
34 | is_ht |= sband->ht_cap.ht_supported; | |
35 | } | |
36 | ||
37 | sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ]; | |
38 | if (sband) { | |
39 | int i; | |
40 | /* Check for mandatory rates */ | |
41 | for (i = 0; i < sband->n_bitrates; i++) { | |
42 | if (sband->bitrates[i].bitrate == 10) | |
43 | is_b = true; | |
44 | if (sband->bitrates[i].bitrate == 60) | |
45 | is_g = true; | |
46 | } | |
47 | is_ht |= sband->ht_cap.ht_supported; | |
48 | } | |
49 | ||
50 | strcpy(name, "IEEE 802.11"); | |
51 | if (is_a) | |
52 | strcat(name, "a"); | |
53 | if (is_b) | |
54 | strcat(name, "b"); | |
55 | if (is_g) | |
56 | strcat(name, "g"); | |
57 | if (is_ht) | |
58 | strcat(name, "n"); | |
59 | ||
60 | return 0; | |
61 | } | |
ba44cb72 | 62 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwname); |
e60c7744 JB |
63 | |
64 | int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, | |
65 | u32 *mode, char *extra) | |
66 | { | |
67 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
68 | struct cfg80211_registered_device *rdev; | |
69 | struct vif_params vifparams; | |
70 | enum nl80211_iftype type; | |
ac7f9cfa | 71 | int ret; |
e60c7744 JB |
72 | |
73 | if (!wdev) | |
74 | return -EOPNOTSUPP; | |
75 | ||
76 | rdev = wiphy_to_dev(wdev->wiphy); | |
77 | ||
78 | if (!rdev->ops->change_virtual_intf) | |
79 | return -EOPNOTSUPP; | |
80 | ||
81 | /* don't support changing VLANs, you just re-create them */ | |
82 | if (wdev->iftype == NL80211_IFTYPE_AP_VLAN) | |
83 | return -EOPNOTSUPP; | |
84 | ||
85 | switch (*mode) { | |
86 | case IW_MODE_INFRA: | |
87 | type = NL80211_IFTYPE_STATION; | |
88 | break; | |
89 | case IW_MODE_ADHOC: | |
90 | type = NL80211_IFTYPE_ADHOC; | |
91 | break; | |
92 | case IW_MODE_REPEAT: | |
93 | type = NL80211_IFTYPE_WDS; | |
94 | break; | |
95 | case IW_MODE_MONITOR: | |
96 | type = NL80211_IFTYPE_MONITOR; | |
97 | break; | |
98 | default: | |
99 | return -EINVAL; | |
100 | } | |
101 | ||
ac7f9cfa JB |
102 | if (type == wdev->iftype) |
103 | return 0; | |
104 | ||
e60c7744 JB |
105 | memset(&vifparams, 0, sizeof(vifparams)); |
106 | ||
e36d56b6 | 107 | ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type, |
ac7f9cfa JB |
108 | NULL, &vifparams); |
109 | WARN_ON(!ret && wdev->iftype != type); | |
110 | ||
111 | return ret; | |
e60c7744 | 112 | } |
ba44cb72 | 113 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode); |
e60c7744 JB |
114 | |
115 | int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info, | |
116 | u32 *mode, char *extra) | |
117 | { | |
118 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
119 | ||
120 | if (!wdev) | |
121 | return -EOPNOTSUPP; | |
122 | ||
123 | switch (wdev->iftype) { | |
124 | case NL80211_IFTYPE_AP: | |
125 | *mode = IW_MODE_MASTER; | |
126 | break; | |
127 | case NL80211_IFTYPE_STATION: | |
128 | *mode = IW_MODE_INFRA; | |
129 | break; | |
130 | case NL80211_IFTYPE_ADHOC: | |
131 | *mode = IW_MODE_ADHOC; | |
132 | break; | |
133 | case NL80211_IFTYPE_MONITOR: | |
134 | *mode = IW_MODE_MONITOR; | |
135 | break; | |
136 | case NL80211_IFTYPE_WDS: | |
137 | *mode = IW_MODE_REPEAT; | |
138 | break; | |
139 | case NL80211_IFTYPE_AP_VLAN: | |
140 | *mode = IW_MODE_SECOND; /* FIXME */ | |
141 | break; | |
142 | default: | |
143 | *mode = IW_MODE_AUTO; | |
144 | break; | |
145 | } | |
146 | return 0; | |
147 | } | |
ba44cb72 | 148 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode); |
4aa188e1 JB |
149 | |
150 | ||
151 | int cfg80211_wext_giwrange(struct net_device *dev, | |
152 | struct iw_request_info *info, | |
153 | struct iw_point *data, char *extra) | |
154 | { | |
155 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
156 | struct iw_range *range = (struct iw_range *) extra; | |
157 | enum ieee80211_band band; | |
9834c079 | 158 | int i, c = 0; |
4aa188e1 JB |
159 | |
160 | if (!wdev) | |
161 | return -EOPNOTSUPP; | |
162 | ||
163 | data->length = sizeof(struct iw_range); | |
164 | memset(range, 0, sizeof(struct iw_range)); | |
165 | ||
166 | range->we_version_compiled = WIRELESS_EXT; | |
167 | range->we_version_source = 21; | |
168 | range->retry_capa = IW_RETRY_LIMIT; | |
169 | range->retry_flags = IW_RETRY_LIMIT; | |
170 | range->min_retry = 0; | |
171 | range->max_retry = 255; | |
172 | range->min_rts = 0; | |
173 | range->max_rts = 2347; | |
174 | range->min_frag = 256; | |
175 | range->max_frag = 2346; | |
176 | ||
4aa188e1 JB |
177 | range->max_encoding_tokens = 4; |
178 | ||
179 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; | |
180 | ||
181 | switch (wdev->wiphy->signal_type) { | |
182 | case CFG80211_SIGNAL_TYPE_NONE: | |
183 | break; | |
184 | case CFG80211_SIGNAL_TYPE_MBM: | |
185 | range->max_qual.level = -110; | |
186 | range->max_qual.qual = 70; | |
187 | range->avg_qual.qual = 35; | |
188 | range->max_qual.updated |= IW_QUAL_DBM; | |
189 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; | |
190 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
191 | break; | |
192 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
193 | range->max_qual.level = 100; | |
194 | range->max_qual.qual = 100; | |
195 | range->avg_qual.qual = 50; | |
196 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; | |
197 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
198 | break; | |
199 | } | |
200 | ||
201 | range->avg_qual.level = range->max_qual.level / 2; | |
202 | range->avg_qual.noise = range->max_qual.noise / 2; | |
203 | range->avg_qual.updated = range->max_qual.updated; | |
204 | ||
9834c079 JB |
205 | for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) { |
206 | switch (wdev->wiphy->cipher_suites[i]) { | |
3daf0975 | 207 | case WLAN_CIPHER_SUITE_TKIP: |
27bea66c DK |
208 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP | |
209 | IW_ENC_CAPA_WPA); | |
3daf0975 DK |
210 | break; |
211 | ||
212 | case WLAN_CIPHER_SUITE_CCMP: | |
27bea66c DK |
213 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP | |
214 | IW_ENC_CAPA_WPA2); | |
3daf0975 | 215 | break; |
2ab658f9 DK |
216 | |
217 | case WLAN_CIPHER_SUITE_WEP40: | |
218 | range->encoding_size[range->num_encoding_sizes++] = | |
219 | WLAN_KEY_LEN_WEP40; | |
220 | break; | |
221 | ||
222 | case WLAN_CIPHER_SUITE_WEP104: | |
223 | range->encoding_size[range->num_encoding_sizes++] = | |
224 | WLAN_KEY_LEN_WEP104; | |
225 | break; | |
3daf0975 DK |
226 | } |
227 | } | |
4aa188e1 | 228 | |
4aa188e1 | 229 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
4aa188e1 JB |
230 | struct ieee80211_supported_band *sband; |
231 | ||
232 | sband = wdev->wiphy->bands[band]; | |
233 | ||
234 | if (!sband) | |
235 | continue; | |
236 | ||
237 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { | |
238 | struct ieee80211_channel *chan = &sband->channels[i]; | |
239 | ||
240 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { | |
241 | range->freq[c].i = | |
242 | ieee80211_frequency_to_channel( | |
243 | chan->center_freq); | |
244 | range->freq[c].m = chan->center_freq; | |
245 | range->freq[c].e = 6; | |
246 | c++; | |
247 | } | |
248 | } | |
249 | } | |
250 | range->num_channels = c; | |
251 | range->num_frequency = c; | |
252 | ||
253 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); | |
254 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); | |
255 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
256 | ||
51cd4aab DK |
257 | if (wdev->wiphy->max_scan_ssids > 0) |
258 | range->scan_capa |= IW_SCAN_CAPA_ESSID; | |
4aa188e1 JB |
259 | |
260 | return 0; | |
261 | } | |
ba44cb72 | 262 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); |
691597cb | 263 | |
04a773ad JB |
264 | |
265 | /** | |
266 | * cfg80211_wext_freq - get wext frequency for non-"auto" | |
267 | * @wiphy: the wiphy | |
268 | * @freq: the wext freq encoding | |
269 | * | |
59bbb6f7 | 270 | * Returns a frequency, or a negative error code, or 0 for auto. |
04a773ad | 271 | */ |
59bbb6f7 | 272 | int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq) |
04a773ad | 273 | { |
0b258582 | 274 | /* |
59bbb6f7 | 275 | * Parse frequency - return 0 for auto and |
0b258582 JB |
276 | * -EINVAL for impossible things. |
277 | */ | |
04a773ad JB |
278 | if (freq->e == 0) { |
279 | if (freq->m < 0) | |
59bbb6f7 JB |
280 | return 0; |
281 | return ieee80211_channel_to_frequency(freq->m); | |
04a773ad JB |
282 | } else { |
283 | int i, div = 1000000; | |
284 | for (i = 0; i < freq->e; i++) | |
285 | div /= 10; | |
0b258582 | 286 | if (div <= 0) |
59bbb6f7 JB |
287 | return -EINVAL; |
288 | return freq->m / div; | |
04a773ad | 289 | } |
04a773ad | 290 | } |
b9a5f8ca JM |
291 | |
292 | int cfg80211_wext_siwrts(struct net_device *dev, | |
293 | struct iw_request_info *info, | |
294 | struct iw_param *rts, char *extra) | |
295 | { | |
296 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
297 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
298 | u32 orts = wdev->wiphy->rts_threshold; | |
299 | int err; | |
300 | ||
301 | if (rts->disabled || !rts->fixed) | |
302 | wdev->wiphy->rts_threshold = (u32) -1; | |
303 | else if (rts->value < 0) | |
304 | return -EINVAL; | |
305 | else | |
306 | wdev->wiphy->rts_threshold = rts->value; | |
307 | ||
308 | err = rdev->ops->set_wiphy_params(wdev->wiphy, | |
309 | WIPHY_PARAM_RTS_THRESHOLD); | |
310 | if (err) | |
311 | wdev->wiphy->rts_threshold = orts; | |
312 | ||
313 | return err; | |
314 | } | |
ba44cb72 | 315 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts); |
b9a5f8ca JM |
316 | |
317 | int cfg80211_wext_giwrts(struct net_device *dev, | |
318 | struct iw_request_info *info, | |
319 | struct iw_param *rts, char *extra) | |
320 | { | |
321 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
322 | ||
323 | rts->value = wdev->wiphy->rts_threshold; | |
324 | rts->disabled = rts->value == (u32) -1; | |
325 | rts->fixed = 1; | |
326 | ||
327 | return 0; | |
328 | } | |
ba44cb72 | 329 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts); |
b9a5f8ca JM |
330 | |
331 | int cfg80211_wext_siwfrag(struct net_device *dev, | |
332 | struct iw_request_info *info, | |
333 | struct iw_param *frag, char *extra) | |
334 | { | |
335 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
336 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
337 | u32 ofrag = wdev->wiphy->frag_threshold; | |
338 | int err; | |
339 | ||
340 | if (frag->disabled || !frag->fixed) | |
341 | wdev->wiphy->frag_threshold = (u32) -1; | |
342 | else if (frag->value < 256) | |
343 | return -EINVAL; | |
344 | else { | |
345 | /* Fragment length must be even, so strip LSB. */ | |
346 | wdev->wiphy->frag_threshold = frag->value & ~0x1; | |
347 | } | |
348 | ||
349 | err = rdev->ops->set_wiphy_params(wdev->wiphy, | |
350 | WIPHY_PARAM_FRAG_THRESHOLD); | |
351 | if (err) | |
352 | wdev->wiphy->frag_threshold = ofrag; | |
353 | ||
354 | return err; | |
355 | } | |
ba44cb72 | 356 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag); |
b9a5f8ca JM |
357 | |
358 | int cfg80211_wext_giwfrag(struct net_device *dev, | |
359 | struct iw_request_info *info, | |
360 | struct iw_param *frag, char *extra) | |
361 | { | |
362 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
363 | ||
364 | frag->value = wdev->wiphy->frag_threshold; | |
365 | frag->disabled = frag->value == (u32) -1; | |
366 | frag->fixed = 1; | |
367 | ||
368 | return 0; | |
369 | } | |
ba44cb72 | 370 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag); |
b9a5f8ca JM |
371 | |
372 | int cfg80211_wext_siwretry(struct net_device *dev, | |
373 | struct iw_request_info *info, | |
374 | struct iw_param *retry, char *extra) | |
375 | { | |
376 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
377 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
378 | u32 changed = 0; | |
379 | u8 olong = wdev->wiphy->retry_long; | |
380 | u8 oshort = wdev->wiphy->retry_short; | |
381 | int err; | |
382 | ||
383 | if (retry->disabled || | |
384 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) | |
385 | return -EINVAL; | |
386 | ||
387 | if (retry->flags & IW_RETRY_LONG) { | |
388 | wdev->wiphy->retry_long = retry->value; | |
389 | changed |= WIPHY_PARAM_RETRY_LONG; | |
390 | } else if (retry->flags & IW_RETRY_SHORT) { | |
391 | wdev->wiphy->retry_short = retry->value; | |
392 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
393 | } else { | |
394 | wdev->wiphy->retry_short = retry->value; | |
395 | wdev->wiphy->retry_long = retry->value; | |
396 | changed |= WIPHY_PARAM_RETRY_LONG; | |
397 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
398 | } | |
399 | ||
400 | if (!changed) | |
401 | return 0; | |
402 | ||
403 | err = rdev->ops->set_wiphy_params(wdev->wiphy, changed); | |
404 | if (err) { | |
405 | wdev->wiphy->retry_short = oshort; | |
406 | wdev->wiphy->retry_long = olong; | |
407 | } | |
408 | ||
409 | return err; | |
410 | } | |
ba44cb72 | 411 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry); |
b9a5f8ca JM |
412 | |
413 | int cfg80211_wext_giwretry(struct net_device *dev, | |
414 | struct iw_request_info *info, | |
415 | struct iw_param *retry, char *extra) | |
416 | { | |
417 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
418 | ||
419 | retry->disabled = 0; | |
420 | ||
421 | if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) { | |
422 | /* | |
423 | * First return short value, iwconfig will ask long value | |
424 | * later if needed | |
425 | */ | |
426 | retry->flags |= IW_RETRY_LIMIT; | |
427 | retry->value = wdev->wiphy->retry_short; | |
428 | if (wdev->wiphy->retry_long != wdev->wiphy->retry_short) | |
429 | retry->flags |= IW_RETRY_LONG; | |
430 | ||
431 | return 0; | |
432 | } | |
433 | ||
434 | if (retry->flags & IW_RETRY_LONG) { | |
435 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
436 | retry->value = wdev->wiphy->retry_long; | |
437 | } | |
438 | ||
439 | return 0; | |
440 | } | |
ba44cb72 | 441 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); |
08645126 | 442 | |
fffd0934 JB |
443 | static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev, |
444 | struct net_device *dev, const u8 *addr, | |
445 | bool remove, bool tx_key, int idx, | |
446 | struct key_params *params) | |
08645126 JB |
447 | { |
448 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
fffd0934 JB |
449 | int err, i; |
450 | ||
451 | if (!wdev->wext.keys) { | |
452 | wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys), | |
453 | GFP_KERNEL); | |
454 | if (!wdev->wext.keys) | |
455 | return -ENOMEM; | |
456 | for (i = 0; i < 6; i++) | |
457 | wdev->wext.keys->params[i].key = | |
458 | wdev->wext.keys->data[i]; | |
459 | } | |
460 | ||
461 | if (wdev->iftype != NL80211_IFTYPE_ADHOC && | |
462 | wdev->iftype != NL80211_IFTYPE_STATION) | |
463 | return -EOPNOTSUPP; | |
08645126 JB |
464 | |
465 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | |
fffd0934 JB |
466 | if (!wdev->current_bss) |
467 | return -ENOLINK; | |
468 | ||
08645126 JB |
469 | if (!rdev->ops->set_default_mgmt_key) |
470 | return -EOPNOTSUPP; | |
471 | ||
472 | if (idx < 4 || idx > 5) | |
473 | return -EINVAL; | |
474 | } else if (idx < 0 || idx > 3) | |
475 | return -EINVAL; | |
476 | ||
477 | if (remove) { | |
fffd0934 JB |
478 | err = 0; |
479 | if (wdev->current_bss) | |
480 | err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); | |
08645126 | 481 | if (!err) { |
fffd0934 JB |
482 | if (!addr) { |
483 | wdev->wext.keys->params[idx].key_len = 0; | |
484 | wdev->wext.keys->params[idx].cipher = 0; | |
485 | } | |
08645126 JB |
486 | if (idx == wdev->wext.default_key) |
487 | wdev->wext.default_key = -1; | |
488 | else if (idx == wdev->wext.default_mgmt_key) | |
489 | wdev->wext.default_mgmt_key = -1; | |
490 | } | |
e3da574a JB |
491 | /* |
492 | * Applications using wireless extensions expect to be | |
493 | * able to delete keys that don't exist, so allow that. | |
494 | */ | |
495 | if (err == -ENOENT) | |
496 | return 0; | |
497 | ||
08645126 | 498 | return err; |
fffd0934 | 499 | } |
08645126 | 500 | |
fffd0934 JB |
501 | if (addr) |
502 | tx_key = false; | |
503 | ||
504 | if (cfg80211_validate_key_settings(rdev, params, idx, addr)) | |
505 | return -EINVAL; | |
08645126 | 506 | |
fffd0934 JB |
507 | err = 0; |
508 | if (wdev->current_bss) | |
08645126 | 509 | err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); |
fffd0934 JB |
510 | if (err) |
511 | return err; | |
512 | ||
513 | if (!addr) { | |
514 | wdev->wext.keys->params[idx] = *params; | |
515 | memcpy(wdev->wext.keys->data[idx], | |
516 | params->key, params->key_len); | |
517 | wdev->wext.keys->params[idx].key = | |
518 | wdev->wext.keys->data[idx]; | |
519 | } | |
08645126 | 520 | |
1f00fca5 ZY |
521 | if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 || |
522 | params->cipher == WLAN_CIPHER_SUITE_WEP104) && | |
fffd0934 JB |
523 | (tx_key || (!addr && wdev->wext.default_key == -1))) { |
524 | if (wdev->current_bss) | |
08645126 JB |
525 | err = rdev->ops->set_default_key(&rdev->wiphy, |
526 | dev, idx); | |
fffd0934 JB |
527 | if (!err) |
528 | wdev->wext.default_key = idx; | |
529 | return err; | |
530 | } | |
08645126 | 531 | |
fffd0934 JB |
532 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && |
533 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { | |
534 | if (wdev->current_bss) | |
08645126 JB |
535 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
536 | dev, idx); | |
fffd0934 JB |
537 | if (!err) |
538 | wdev->wext.default_mgmt_key = idx; | |
539 | return err; | |
08645126 | 540 | } |
fffd0934 JB |
541 | |
542 | return 0; | |
543 | } | |
544 | ||
545 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | |
546 | struct net_device *dev, const u8 *addr, | |
547 | bool remove, bool tx_key, int idx, | |
548 | struct key_params *params) | |
549 | { | |
550 | int err; | |
551 | ||
552 | wdev_lock(dev->ieee80211_ptr); | |
553 | err = __cfg80211_set_encryption(rdev, dev, addr, remove, | |
554 | tx_key, idx, params); | |
555 | wdev_unlock(dev->ieee80211_ptr); | |
556 | ||
557 | return err; | |
08645126 JB |
558 | } |
559 | ||
560 | int cfg80211_wext_siwencode(struct net_device *dev, | |
561 | struct iw_request_info *info, | |
562 | struct iw_point *erq, char *keybuf) | |
563 | { | |
564 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
565 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
566 | int idx, err; | |
567 | bool remove = false; | |
568 | struct key_params params; | |
569 | ||
fffd0934 JB |
570 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
571 | wdev->iftype != NL80211_IFTYPE_ADHOC) | |
572 | return -EOPNOTSUPP; | |
573 | ||
08645126 JB |
574 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
575 | if (!rdev->ops->del_key || | |
576 | !rdev->ops->add_key || | |
577 | !rdev->ops->set_default_key) | |
578 | return -EOPNOTSUPP; | |
579 | ||
580 | idx = erq->flags & IW_ENCODE_INDEX; | |
581 | if (idx == 0) { | |
582 | idx = wdev->wext.default_key; | |
583 | if (idx < 0) | |
584 | idx = 0; | |
585 | } else if (idx < 1 || idx > 4) | |
586 | return -EINVAL; | |
587 | else | |
588 | idx--; | |
589 | ||
590 | if (erq->flags & IW_ENCODE_DISABLED) | |
591 | remove = true; | |
592 | else if (erq->length == 0) { | |
593 | /* No key data - just set the default TX key index */ | |
fffd0934 JB |
594 | err = 0; |
595 | wdev_lock(wdev); | |
596 | if (wdev->current_bss) | |
597 | err = rdev->ops->set_default_key(&rdev->wiphy, | |
598 | dev, idx); | |
08645126 JB |
599 | if (!err) |
600 | wdev->wext.default_key = idx; | |
fffd0934 | 601 | wdev_unlock(wdev); |
08645126 JB |
602 | return err; |
603 | } | |
604 | ||
605 | memset(¶ms, 0, sizeof(params)); | |
606 | params.key = keybuf; | |
607 | params.key_len = erq->length; | |
608 | if (erq->length == 5) | |
609 | params.cipher = WLAN_CIPHER_SUITE_WEP40; | |
610 | else if (erq->length == 13) | |
611 | params.cipher = WLAN_CIPHER_SUITE_WEP104; | |
612 | else if (!remove) | |
613 | return -EINVAL; | |
614 | ||
615 | return cfg80211_set_encryption(rdev, dev, NULL, remove, | |
616 | wdev->wext.default_key == -1, | |
617 | idx, ¶ms); | |
618 | } | |
619 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode); | |
620 | ||
621 | int cfg80211_wext_siwencodeext(struct net_device *dev, | |
622 | struct iw_request_info *info, | |
623 | struct iw_point *erq, char *extra) | |
624 | { | |
625 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
626 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
627 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; | |
628 | const u8 *addr; | |
629 | int idx; | |
630 | bool remove = false; | |
631 | struct key_params params; | |
632 | u32 cipher; | |
633 | ||
fffd0934 JB |
634 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
635 | wdev->iftype != NL80211_IFTYPE_ADHOC) | |
636 | return -EOPNOTSUPP; | |
637 | ||
08645126 JB |
638 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
639 | if (!rdev->ops->del_key || | |
640 | !rdev->ops->add_key || | |
641 | !rdev->ops->set_default_key) | |
642 | return -EOPNOTSUPP; | |
643 | ||
644 | switch (ext->alg) { | |
645 | case IW_ENCODE_ALG_NONE: | |
646 | remove = true; | |
647 | cipher = 0; | |
648 | break; | |
649 | case IW_ENCODE_ALG_WEP: | |
650 | if (ext->key_len == 5) | |
651 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
652 | else if (ext->key_len == 13) | |
653 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
654 | else | |
655 | return -EINVAL; | |
656 | break; | |
657 | case IW_ENCODE_ALG_TKIP: | |
658 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
659 | break; | |
660 | case IW_ENCODE_ALG_CCMP: | |
661 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
662 | break; | |
663 | case IW_ENCODE_ALG_AES_CMAC: | |
664 | cipher = WLAN_CIPHER_SUITE_AES_CMAC; | |
665 | break; | |
666 | default: | |
667 | return -EOPNOTSUPP; | |
668 | } | |
669 | ||
670 | if (erq->flags & IW_ENCODE_DISABLED) | |
671 | remove = true; | |
672 | ||
673 | idx = erq->flags & IW_ENCODE_INDEX; | |
674 | if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | |
675 | if (idx < 4 || idx > 5) { | |
676 | idx = wdev->wext.default_mgmt_key; | |
677 | if (idx < 0) | |
678 | return -EINVAL; | |
679 | } else | |
680 | idx--; | |
681 | } else { | |
682 | if (idx < 1 || idx > 4) { | |
683 | idx = wdev->wext.default_key; | |
684 | if (idx < 0) | |
685 | return -EINVAL; | |
686 | } else | |
687 | idx--; | |
688 | } | |
689 | ||
690 | addr = ext->addr.sa_data; | |
691 | if (is_broadcast_ether_addr(addr)) | |
692 | addr = NULL; | |
693 | ||
694 | memset(¶ms, 0, sizeof(params)); | |
695 | params.key = ext->key; | |
696 | params.key_len = ext->key_len; | |
697 | params.cipher = cipher; | |
698 | ||
faa8fdc8 JM |
699 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
700 | params.seq = ext->rx_seq; | |
701 | params.seq_len = 6; | |
702 | } | |
703 | ||
08645126 JB |
704 | return cfg80211_set_encryption( |
705 | rdev, dev, addr, remove, | |
706 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, | |
707 | idx, ¶ms); | |
708 | } | |
709 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext); | |
710 | ||
08645126 JB |
711 | int cfg80211_wext_giwencode(struct net_device *dev, |
712 | struct iw_request_info *info, | |
713 | struct iw_point *erq, char *keybuf) | |
714 | { | |
715 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
fffd0934 | 716 | int idx; |
08645126 | 717 | |
fffd0934 JB |
718 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
719 | wdev->iftype != NL80211_IFTYPE_ADHOC) | |
08645126 JB |
720 | return -EOPNOTSUPP; |
721 | ||
722 | idx = erq->flags & IW_ENCODE_INDEX; | |
723 | if (idx == 0) { | |
724 | idx = wdev->wext.default_key; | |
725 | if (idx < 0) | |
726 | idx = 0; | |
727 | } else if (idx < 1 || idx > 4) | |
728 | return -EINVAL; | |
729 | else | |
730 | idx--; | |
731 | ||
732 | erq->flags = idx + 1; | |
733 | ||
fffd0934 | 734 | if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) { |
08645126 JB |
735 | erq->flags |= IW_ENCODE_DISABLED; |
736 | erq->length = 0; | |
737 | return 0; | |
738 | } | |
739 | ||
fffd0934 JB |
740 | erq->length = min_t(size_t, erq->length, |
741 | wdev->wext.keys->params[idx].key_len); | |
742 | memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length); | |
743 | erq->flags |= IW_ENCODE_ENABLED; | |
744 | ||
745 | return 0; | |
08645126 JB |
746 | } |
747 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); | |
7643a2c3 | 748 | |
0e82ffe3 JB |
749 | int cfg80211_wext_siwfreq(struct net_device *dev, |
750 | struct iw_request_info *info, | |
59bbb6f7 | 751 | struct iw_freq *wextfreq, char *extra) |
0e82ffe3 JB |
752 | { |
753 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
754 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
59bbb6f7 | 755 | int freq, err; |
0e82ffe3 JB |
756 | |
757 | switch (wdev->iftype) { | |
758 | case NL80211_IFTYPE_STATION: | |
59bbb6f7 | 759 | return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra); |
0e82ffe3 | 760 | case NL80211_IFTYPE_ADHOC: |
59bbb6f7 | 761 | return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); |
0e82ffe3 | 762 | default: |
59bbb6f7 JB |
763 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
764 | if (freq < 0) | |
765 | return freq; | |
766 | if (freq == 0) | |
0e82ffe3 | 767 | return -EINVAL; |
59bbb6f7 | 768 | mutex_lock(&rdev->devlist_mtx); |
4b181144 | 769 | err = rdev_set_freq(rdev, NULL, freq, NL80211_CHAN_NO_HT); |
59bbb6f7 JB |
770 | mutex_unlock(&rdev->devlist_mtx); |
771 | return err; | |
0e82ffe3 JB |
772 | } |
773 | } | |
a8b875e7 | 774 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq); |
0e82ffe3 JB |
775 | |
776 | int cfg80211_wext_giwfreq(struct net_device *dev, | |
777 | struct iw_request_info *info, | |
778 | struct iw_freq *freq, char *extra) | |
779 | { | |
780 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
781 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
782 | ||
783 | switch (wdev->iftype) { | |
784 | case NL80211_IFTYPE_STATION: | |
785 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); | |
786 | case NL80211_IFTYPE_ADHOC: | |
787 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); | |
788 | default: | |
789 | if (!rdev->channel) | |
790 | return -EINVAL; | |
791 | freq->m = rdev->channel->center_freq; | |
792 | freq->e = 6; | |
793 | return 0; | |
794 | } | |
795 | } | |
796 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq); | |
797 | ||
7643a2c3 JB |
798 | int cfg80211_wext_siwtxpower(struct net_device *dev, |
799 | struct iw_request_info *info, | |
800 | union iwreq_data *data, char *extra) | |
801 | { | |
802 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
803 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
804 | enum tx_power_setting type; | |
805 | int dbm = 0; | |
806 | ||
807 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
808 | return -EINVAL; | |
809 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
810 | return -EINVAL; | |
811 | ||
812 | if (!rdev->ops->set_tx_power) | |
813 | return -EOPNOTSUPP; | |
814 | ||
815 | /* only change when not disabling */ | |
816 | if (!data->txpower.disabled) { | |
1f87f7d3 JB |
817 | rfkill_set_sw_state(rdev->rfkill, false); |
818 | ||
7643a2c3 JB |
819 | if (data->txpower.fixed) { |
820 | /* | |
821 | * wext doesn't support negative values, see | |
822 | * below where it's for automatic | |
823 | */ | |
824 | if (data->txpower.value < 0) | |
825 | return -EINVAL; | |
826 | dbm = data->txpower.value; | |
827 | type = TX_POWER_FIXED; | |
828 | /* TODO: do regulatory check! */ | |
829 | } else { | |
830 | /* | |
831 | * Automatic power level setting, max being the value | |
832 | * passed in from userland. | |
833 | */ | |
834 | if (data->txpower.value < 0) { | |
835 | type = TX_POWER_AUTOMATIC; | |
836 | } else { | |
837 | dbm = data->txpower.value; | |
838 | type = TX_POWER_LIMITED; | |
839 | } | |
840 | } | |
841 | } else { | |
1f87f7d3 JB |
842 | rfkill_set_sw_state(rdev->rfkill, true); |
843 | schedule_work(&rdev->rfkill_sync); | |
844 | return 0; | |
7643a2c3 JB |
845 | } |
846 | ||
847 | return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; | |
848 | } | |
849 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); | |
850 | ||
851 | int cfg80211_wext_giwtxpower(struct net_device *dev, | |
852 | struct iw_request_info *info, | |
853 | union iwreq_data *data, char *extra) | |
854 | { | |
855 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
856 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
857 | int err, val; | |
858 | ||
859 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
860 | return -EINVAL; | |
861 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
862 | return -EINVAL; | |
863 | ||
864 | if (!rdev->ops->get_tx_power) | |
865 | return -EOPNOTSUPP; | |
866 | ||
867 | err = rdev->ops->get_tx_power(wdev->wiphy, &val); | |
1f87f7d3 | 868 | if (err) |
7643a2c3 JB |
869 | return err; |
870 | ||
871 | /* well... oh well */ | |
872 | data->txpower.fixed = 1; | |
1f87f7d3 | 873 | data->txpower.disabled = rfkill_blocked(rdev->rfkill); |
7643a2c3 JB |
874 | data->txpower.value = val; |
875 | data->txpower.flags = IW_TXPOW_DBM; | |
876 | ||
877 | return 0; | |
878 | } | |
879 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); | |
f2129354 JB |
880 | |
881 | static int cfg80211_set_auth_alg(struct wireless_dev *wdev, | |
882 | s32 auth_alg) | |
883 | { | |
884 | int nr_alg = 0; | |
885 | ||
886 | if (!auth_alg) | |
887 | return -EINVAL; | |
888 | ||
889 | if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM | | |
890 | IW_AUTH_ALG_SHARED_KEY | | |
891 | IW_AUTH_ALG_LEAP)) | |
892 | return -EINVAL; | |
893 | ||
894 | if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) { | |
895 | nr_alg++; | |
896 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
897 | } | |
898 | ||
899 | if (auth_alg & IW_AUTH_ALG_SHARED_KEY) { | |
900 | nr_alg++; | |
901 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY; | |
902 | } | |
903 | ||
904 | if (auth_alg & IW_AUTH_ALG_LEAP) { | |
905 | nr_alg++; | |
906 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP; | |
907 | } | |
908 | ||
909 | if (nr_alg > 1) | |
910 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
911 | ||
912 | return 0; | |
913 | } | |
914 | ||
915 | static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions) | |
916 | { | |
917 | wdev->wext.connect.crypto.wpa_versions = 0; | |
918 | ||
919 | if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA | | |
323d566e GS |
920 | IW_AUTH_WPA_VERSION_WPA2| |
921 | IW_AUTH_WPA_VERSION_DISABLED)) | |
f2129354 JB |
922 | return -EINVAL; |
923 | ||
323d566e GS |
924 | if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) && |
925 | (wpa_versions & (IW_AUTH_WPA_VERSION_WPA| | |
926 | IW_AUTH_WPA_VERSION_WPA2))) | |
927 | return -EINVAL; | |
928 | ||
929 | if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) | |
930 | wdev->wext.connect.crypto.wpa_versions &= | |
931 | ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2); | |
932 | ||
f2129354 JB |
933 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA) |
934 | wdev->wext.connect.crypto.wpa_versions |= | |
935 | NL80211_WPA_VERSION_1; | |
936 | ||
937 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2) | |
938 | wdev->wext.connect.crypto.wpa_versions |= | |
939 | NL80211_WPA_VERSION_2; | |
940 | ||
941 | return 0; | |
942 | } | |
943 | ||
4f5dadce | 944 | static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher) |
f2129354 JB |
945 | { |
946 | wdev->wext.connect.crypto.cipher_group = 0; | |
947 | ||
948 | if (cipher & IW_AUTH_CIPHER_WEP40) | |
949 | wdev->wext.connect.crypto.cipher_group = | |
950 | WLAN_CIPHER_SUITE_WEP40; | |
951 | else if (cipher & IW_AUTH_CIPHER_WEP104) | |
952 | wdev->wext.connect.crypto.cipher_group = | |
953 | WLAN_CIPHER_SUITE_WEP104; | |
954 | else if (cipher & IW_AUTH_CIPHER_TKIP) | |
955 | wdev->wext.connect.crypto.cipher_group = | |
956 | WLAN_CIPHER_SUITE_TKIP; | |
957 | else if (cipher & IW_AUTH_CIPHER_CCMP) | |
958 | wdev->wext.connect.crypto.cipher_group = | |
959 | WLAN_CIPHER_SUITE_CCMP; | |
960 | else if (cipher & IW_AUTH_CIPHER_AES_CMAC) | |
961 | wdev->wext.connect.crypto.cipher_group = | |
962 | WLAN_CIPHER_SUITE_AES_CMAC; | |
963 | else | |
964 | return -EINVAL; | |
965 | ||
966 | return 0; | |
967 | } | |
968 | ||
4f5dadce | 969 | static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher) |
f2129354 JB |
970 | { |
971 | int nr_ciphers = 0; | |
972 | u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise; | |
973 | ||
974 | if (cipher & IW_AUTH_CIPHER_WEP40) { | |
975 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40; | |
976 | nr_ciphers++; | |
977 | } | |
978 | ||
979 | if (cipher & IW_AUTH_CIPHER_WEP104) { | |
980 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104; | |
981 | nr_ciphers++; | |
982 | } | |
983 | ||
984 | if (cipher & IW_AUTH_CIPHER_TKIP) { | |
985 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP; | |
986 | nr_ciphers++; | |
987 | } | |
988 | ||
989 | if (cipher & IW_AUTH_CIPHER_CCMP) { | |
990 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP; | |
991 | nr_ciphers++; | |
992 | } | |
993 | ||
994 | if (cipher & IW_AUTH_CIPHER_AES_CMAC) { | |
995 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC; | |
996 | nr_ciphers++; | |
997 | } | |
998 | ||
999 | BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5); | |
1000 | ||
1001 | wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers; | |
1002 | ||
1003 | return 0; | |
1004 | } | |
1005 | ||
1006 | ||
4f5dadce | 1007 | static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt) |
f2129354 JB |
1008 | { |
1009 | int nr_akm_suites = 0; | |
1010 | ||
1011 | if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X | | |
1012 | IW_AUTH_KEY_MGMT_PSK)) | |
1013 | return -EINVAL; | |
1014 | ||
1015 | if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) { | |
1016 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = | |
1017 | WLAN_AKM_SUITE_8021X; | |
1018 | nr_akm_suites++; | |
1019 | } | |
1020 | ||
1021 | if (key_mgt & IW_AUTH_KEY_MGMT_PSK) { | |
1022 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = | |
1023 | WLAN_AKM_SUITE_PSK; | |
1024 | nr_akm_suites++; | |
1025 | } | |
1026 | ||
1027 | wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites; | |
1028 | ||
1029 | return 0; | |
1030 | } | |
1031 | ||
1032 | int cfg80211_wext_siwauth(struct net_device *dev, | |
1033 | struct iw_request_info *info, | |
1034 | struct iw_param *data, char *extra) | |
1035 | { | |
1036 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1037 | ||
1038 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
1039 | return -EOPNOTSUPP; | |
1040 | ||
1041 | switch (data->flags & IW_AUTH_INDEX) { | |
1042 | case IW_AUTH_PRIVACY_INVOKED: | |
1043 | wdev->wext.connect.privacy = data->value; | |
1044 | return 0; | |
1045 | case IW_AUTH_WPA_VERSION: | |
1046 | return cfg80211_set_wpa_version(wdev, data->value); | |
1047 | case IW_AUTH_CIPHER_GROUP: | |
1048 | return cfg80211_set_cipher_group(wdev, data->value); | |
1049 | case IW_AUTH_KEY_MGMT: | |
1050 | return cfg80211_set_key_mgt(wdev, data->value); | |
1051 | case IW_AUTH_CIPHER_PAIRWISE: | |
1052 | return cfg80211_set_cipher_pairwise(wdev, data->value); | |
1053 | case IW_AUTH_80211_AUTH_ALG: | |
1054 | return cfg80211_set_auth_alg(wdev, data->value); | |
1055 | case IW_AUTH_WPA_ENABLED: | |
1056 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1057 | case IW_AUTH_DROP_UNENCRYPTED: | |
1058 | case IW_AUTH_MFP: | |
1059 | return 0; | |
1060 | default: | |
1061 | return -EOPNOTSUPP; | |
1062 | } | |
1063 | } | |
1064 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth); | |
1065 | ||
1066 | int cfg80211_wext_giwauth(struct net_device *dev, | |
1067 | struct iw_request_info *info, | |
1068 | struct iw_param *data, char *extra) | |
1069 | { | |
1070 | /* XXX: what do we need? */ | |
1071 | ||
1072 | return -EOPNOTSUPP; | |
1073 | } | |
1074 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth); | |
bc92afd9 JB |
1075 | |
1076 | int cfg80211_wext_siwpower(struct net_device *dev, | |
1077 | struct iw_request_info *info, | |
1078 | struct iw_param *wrq, char *extra) | |
1079 | { | |
1080 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1081 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
1082 | bool ps = wdev->wext.ps; | |
1083 | int timeout = wdev->wext.ps_timeout; | |
1084 | int err; | |
1085 | ||
1086 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
1087 | return -EINVAL; | |
1088 | ||
1089 | if (!rdev->ops->set_power_mgmt) | |
1090 | return -EOPNOTSUPP; | |
1091 | ||
1092 | if (wrq->disabled) { | |
1093 | ps = false; | |
1094 | } else { | |
1095 | switch (wrq->flags & IW_POWER_MODE) { | |
1096 | case IW_POWER_ON: /* If not specified */ | |
1097 | case IW_POWER_MODE: /* If set all mask */ | |
1098 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
1099 | ps = true; | |
1100 | break; | |
1101 | default: /* Otherwise we ignore */ | |
1102 | return -EINVAL; | |
1103 | } | |
1104 | ||
1105 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) | |
1106 | return -EINVAL; | |
1107 | ||
1108 | if (wrq->flags & IW_POWER_TIMEOUT) | |
1109 | timeout = wrq->value / 1000; | |
1110 | } | |
1111 | ||
1112 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout); | |
1113 | if (err) | |
1114 | return err; | |
1115 | ||
1116 | wdev->wext.ps = ps; | |
1117 | wdev->wext.ps_timeout = timeout; | |
1118 | ||
1119 | return 0; | |
1120 | ||
1121 | } | |
1122 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower); | |
1123 | ||
1124 | int cfg80211_wext_giwpower(struct net_device *dev, | |
1125 | struct iw_request_info *info, | |
1126 | struct iw_param *wrq, char *extra) | |
1127 | { | |
1128 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1129 | ||
1130 | wrq->disabled = !wdev->wext.ps; | |
1131 | ||
1132 | return 0; | |
1133 | } | |
1134 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower); | |
ab737a4f | 1135 | |
562e4822 JB |
1136 | static int cfg80211_wds_wext_siwap(struct net_device *dev, |
1137 | struct iw_request_info *info, | |
1138 | struct sockaddr *addr, char *extra) | |
ab737a4f JB |
1139 | { |
1140 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1141 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
1142 | int err; | |
1143 | ||
1144 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) | |
1145 | return -EINVAL; | |
1146 | ||
1147 | if (addr->sa_family != ARPHRD_ETHER) | |
1148 | return -EINVAL; | |
1149 | ||
1150 | if (netif_running(dev)) | |
1151 | return -EBUSY; | |
1152 | ||
1153 | if (!rdev->ops->set_wds_peer) | |
1154 | return -EOPNOTSUPP; | |
1155 | ||
1156 | err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data); | |
1157 | if (err) | |
1158 | return err; | |
1159 | ||
1160 | memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN); | |
1161 | ||
1162 | return 0; | |
1163 | } | |
ab737a4f | 1164 | |
562e4822 JB |
1165 | static int cfg80211_wds_wext_giwap(struct net_device *dev, |
1166 | struct iw_request_info *info, | |
1167 | struct sockaddr *addr, char *extra) | |
ab737a4f JB |
1168 | { |
1169 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1170 | ||
1171 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) | |
1172 | return -EINVAL; | |
1173 | ||
1174 | addr->sa_family = ARPHRD_ETHER; | |
1175 | memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN); | |
1176 | ||
1177 | return 0; | |
1178 | } | |
9930380f JB |
1179 | |
1180 | int cfg80211_wext_siwrate(struct net_device *dev, | |
1181 | struct iw_request_info *info, | |
1182 | struct iw_param *rate, char *extra) | |
1183 | { | |
1184 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1185 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
1186 | struct cfg80211_bitrate_mask mask; | |
1187 | ||
1188 | if (!rdev->ops->set_bitrate_mask) | |
1189 | return -EOPNOTSUPP; | |
1190 | ||
1191 | mask.fixed = 0; | |
1192 | mask.maxrate = 0; | |
1193 | ||
1194 | if (rate->value < 0) { | |
1195 | /* nothing */ | |
1196 | } else if (rate->fixed) { | |
1197 | mask.fixed = rate->value / 1000; /* kbps */ | |
1198 | } else { | |
1199 | mask.maxrate = rate->value / 1000; /* kbps */ | |
1200 | } | |
1201 | ||
1202 | return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask); | |
1203 | } | |
1204 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate); | |
1205 | ||
1206 | int cfg80211_wext_giwrate(struct net_device *dev, | |
1207 | struct iw_request_info *info, | |
1208 | struct iw_param *rate, char *extra) | |
1209 | { | |
1210 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1211 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
1212 | /* we are under RTNL - globally locked - so can use a static struct */ | |
1213 | static struct station_info sinfo; | |
a71d62db | 1214 | u8 addr[ETH_ALEN]; |
9930380f JB |
1215 | int err; |
1216 | ||
1217 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
1218 | return -EOPNOTSUPP; | |
1219 | ||
1220 | if (!rdev->ops->get_station) | |
1221 | return -EOPNOTSUPP; | |
1222 | ||
a71d62db JB |
1223 | err = 0; |
1224 | wdev_lock(wdev); | |
6c230c02 | 1225 | if (wdev->current_bss) |
a71d62db | 1226 | memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN); |
6c230c02 | 1227 | else |
a71d62db JB |
1228 | err = -EOPNOTSUPP; |
1229 | wdev_unlock(wdev); | |
1230 | if (err) | |
1231 | return err; | |
9930380f JB |
1232 | |
1233 | err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo); | |
1234 | if (err) | |
1235 | return err; | |
1236 | ||
1237 | if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) | |
1238 | return -EOPNOTSUPP; | |
1239 | ||
1240 | rate->value = 0; | |
1241 | ||
1242 | if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS)) | |
1243 | rate->value = 100000 * sinfo.txrate.legacy; | |
1244 | ||
1245 | return 0; | |
1246 | } | |
1247 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate); | |
8990646d JB |
1248 | |
1249 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ | |
1250 | struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev) | |
1251 | { | |
1252 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1253 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
1254 | /* we are under RTNL - globally locked - so can use static structs */ | |
1255 | static struct iw_statistics wstats; | |
1256 | static struct station_info sinfo; | |
c56c5714 | 1257 | u8 bssid[ETH_ALEN]; |
8990646d JB |
1258 | |
1259 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) | |
1260 | return NULL; | |
1261 | ||
1262 | if (!rdev->ops->get_station) | |
1263 | return NULL; | |
1264 | ||
c56c5714 JB |
1265 | /* Grab BSSID of current BSS, if any */ |
1266 | wdev_lock(wdev); | |
1267 | if (!wdev->current_bss) { | |
1268 | wdev_unlock(wdev); | |
8990646d | 1269 | return NULL; |
c56c5714 JB |
1270 | } |
1271 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); | |
1272 | wdev_unlock(wdev); | |
8990646d | 1273 | |
c56c5714 | 1274 | if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo)) |
8990646d JB |
1275 | return NULL; |
1276 | ||
1277 | memset(&wstats, 0, sizeof(wstats)); | |
1278 | ||
1279 | switch (rdev->wiphy.signal_type) { | |
1280 | case CFG80211_SIGNAL_TYPE_MBM: | |
1281 | if (sinfo.filled & STATION_INFO_SIGNAL) { | |
1282 | int sig = sinfo.signal; | |
1283 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
1284 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; | |
1285 | wstats.qual.updated |= IW_QUAL_DBM; | |
1286 | wstats.qual.level = sig; | |
1287 | if (sig < -110) | |
1288 | sig = -110; | |
1289 | else if (sig > -40) | |
1290 | sig = -40; | |
1291 | wstats.qual.qual = sig + 110; | |
1292 | break; | |
1293 | } | |
1294 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
1295 | if (sinfo.filled & STATION_INFO_SIGNAL) { | |
1296 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
1297 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; | |
1298 | wstats.qual.level = sinfo.signal; | |
1299 | wstats.qual.qual = sinfo.signal; | |
1300 | break; | |
1301 | } | |
1302 | default: | |
1303 | wstats.qual.updated |= IW_QUAL_LEVEL_INVALID; | |
1304 | wstats.qual.updated |= IW_QUAL_QUAL_INVALID; | |
1305 | } | |
1306 | ||
1307 | wstats.qual.updated |= IW_QUAL_NOISE_INVALID; | |
1308 | ||
1309 | return &wstats; | |
1310 | } | |
1311 | EXPORT_SYMBOL_GPL(cfg80211_wireless_stats); | |
562e4822 JB |
1312 | |
1313 | int cfg80211_wext_siwap(struct net_device *dev, | |
1314 | struct iw_request_info *info, | |
1315 | struct sockaddr *ap_addr, char *extra) | |
1316 | { | |
1317 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1318 | ||
1319 | switch (wdev->iftype) { | |
1320 | case NL80211_IFTYPE_ADHOC: | |
1321 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); | |
1322 | case NL80211_IFTYPE_STATION: | |
1323 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); | |
1324 | case NL80211_IFTYPE_WDS: | |
1325 | return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra); | |
1326 | default: | |
1327 | return -EOPNOTSUPP; | |
1328 | } | |
1329 | } | |
1330 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwap); | |
1331 | ||
1332 | int cfg80211_wext_giwap(struct net_device *dev, | |
1333 | struct iw_request_info *info, | |
1334 | struct sockaddr *ap_addr, char *extra) | |
1335 | { | |
1336 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1337 | ||
1338 | switch (wdev->iftype) { | |
1339 | case NL80211_IFTYPE_ADHOC: | |
1340 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); | |
1341 | case NL80211_IFTYPE_STATION: | |
1342 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); | |
1343 | case NL80211_IFTYPE_WDS: | |
1344 | return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra); | |
1345 | default: | |
1346 | return -EOPNOTSUPP; | |
1347 | } | |
1348 | } | |
1349 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwap); | |
1f9298f9 JB |
1350 | |
1351 | int cfg80211_wext_siwessid(struct net_device *dev, | |
1352 | struct iw_request_info *info, | |
1353 | struct iw_point *data, char *ssid) | |
1354 | { | |
1355 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1356 | ||
1357 | switch (wdev->iftype) { | |
1358 | case NL80211_IFTYPE_ADHOC: | |
1359 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); | |
1360 | case NL80211_IFTYPE_STATION: | |
1361 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); | |
1362 | default: | |
1363 | return -EOPNOTSUPP; | |
1364 | } | |
1365 | } | |
1366 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid); | |
1367 | ||
1368 | int cfg80211_wext_giwessid(struct net_device *dev, | |
1369 | struct iw_request_info *info, | |
1370 | struct iw_point *data, char *ssid) | |
1371 | { | |
1372 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1373 | ||
1374 | switch (wdev->iftype) { | |
1375 | case NL80211_IFTYPE_ADHOC: | |
1376 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); | |
1377 | case NL80211_IFTYPE_STATION: | |
1378 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); | |
1379 | default: | |
1380 | return -EOPNOTSUPP; | |
1381 | } | |
1382 | } | |
1383 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid); | |
a9a11622 JB |
1384 | |
1385 | static const iw_handler cfg80211_handlers[] = { | |
1386 | [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname, | |
1387 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq, | |
1388 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq, | |
1389 | [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode, | |
1390 | [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode, | |
1391 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange, | |
1392 | [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap, | |
1393 | [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap, | |
1394 | [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme, | |
1395 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan, | |
1396 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan, | |
1397 | [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid, | |
1398 | [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid, | |
1399 | [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate, | |
1400 | [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate, | |
1401 | [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts, | |
1402 | [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts, | |
1403 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag, | |
1404 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag, | |
1405 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower, | |
1406 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower, | |
1407 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry, | |
1408 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry, | |
1409 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode, | |
1410 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode, | |
1411 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower, | |
1412 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower, | |
1413 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie, | |
1414 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth, | |
1415 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth, | |
1416 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext, | |
1417 | }; | |
1418 | ||
1419 | const struct iw_handler_def cfg80211_wext_handler = { | |
1420 | .num_standard = ARRAY_SIZE(cfg80211_handlers), | |
1421 | .standard = cfg80211_handlers, | |
1422 | .get_wireless_stats = cfg80211_wireless_stats, | |
1423 | }; |