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