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; | |
157 | int c = 0; | |
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 | ||
176 | range->encoding_size[0] = 5; | |
177 | range->encoding_size[1] = 13; | |
178 | range->num_encoding_sizes = 2; | |
179 | range->max_encoding_tokens = 4; | |
180 | ||
181 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; | |
182 | ||
183 | switch (wdev->wiphy->signal_type) { | |
184 | case CFG80211_SIGNAL_TYPE_NONE: | |
185 | break; | |
186 | case CFG80211_SIGNAL_TYPE_MBM: | |
187 | range->max_qual.level = -110; | |
188 | range->max_qual.qual = 70; | |
189 | range->avg_qual.qual = 35; | |
190 | range->max_qual.updated |= IW_QUAL_DBM; | |
191 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; | |
192 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
193 | break; | |
194 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
195 | range->max_qual.level = 100; | |
196 | range->max_qual.qual = 100; | |
197 | range->avg_qual.qual = 50; | |
198 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; | |
199 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; | |
200 | break; | |
201 | } | |
202 | ||
203 | range->avg_qual.level = range->max_qual.level / 2; | |
204 | range->avg_qual.noise = range->max_qual.noise / 2; | |
205 | range->avg_qual.updated = range->max_qual.updated; | |
206 | ||
3daf0975 DK |
207 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2; |
208 | ||
209 | for (c = 0; c < wdev->wiphy->n_cipher_suites; c++) { | |
210 | switch (wdev->wiphy->cipher_suites[c]) { | |
211 | case WLAN_CIPHER_SUITE_TKIP: | |
212 | range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP; | |
213 | break; | |
214 | ||
215 | case WLAN_CIPHER_SUITE_CCMP: | |
216 | range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP; | |
217 | break; | |
218 | } | |
219 | } | |
4aa188e1 | 220 | |
4aa188e1 JB |
221 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
222 | int i; | |
223 | struct ieee80211_supported_band *sband; | |
224 | ||
225 | sband = wdev->wiphy->bands[band]; | |
226 | ||
227 | if (!sband) | |
228 | continue; | |
229 | ||
230 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { | |
231 | struct ieee80211_channel *chan = &sband->channels[i]; | |
232 | ||
233 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { | |
234 | range->freq[c].i = | |
235 | ieee80211_frequency_to_channel( | |
236 | chan->center_freq); | |
237 | range->freq[c].m = chan->center_freq; | |
238 | range->freq[c].e = 6; | |
239 | c++; | |
240 | } | |
241 | } | |
242 | } | |
243 | range->num_channels = c; | |
244 | range->num_frequency = c; | |
245 | ||
246 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); | |
247 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); | |
248 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
249 | ||
250 | range->scan_capa |= IW_SCAN_CAPA_ESSID; | |
251 | ||
252 | return 0; | |
253 | } | |
ba44cb72 | 254 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); |
691597cb JB |
255 | |
256 | int cfg80211_wext_siwmlme(struct net_device *dev, | |
257 | struct iw_request_info *info, | |
258 | struct iw_point *data, char *extra) | |
259 | { | |
260 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
261 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
262 | struct cfg80211_registered_device *rdev; | |
263 | union { | |
264 | struct cfg80211_disassoc_request disassoc; | |
265 | struct cfg80211_deauth_request deauth; | |
266 | } cmd; | |
267 | ||
268 | if (!wdev) | |
269 | return -EOPNOTSUPP; | |
270 | ||
271 | rdev = wiphy_to_dev(wdev->wiphy); | |
272 | ||
273 | if (wdev->iftype != NL80211_IFTYPE_STATION) | |
274 | return -EINVAL; | |
275 | ||
276 | if (mlme->addr.sa_family != ARPHRD_ETHER) | |
277 | return -EINVAL; | |
278 | ||
279 | memset(&cmd, 0, sizeof(cmd)); | |
280 | ||
281 | switch (mlme->cmd) { | |
282 | case IW_MLME_DEAUTH: | |
283 | if (!rdev->ops->deauth) | |
284 | return -EOPNOTSUPP; | |
285 | cmd.deauth.peer_addr = mlme->addr.sa_data; | |
286 | cmd.deauth.reason_code = mlme->reason_code; | |
287 | return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth); | |
288 | case IW_MLME_DISASSOC: | |
289 | if (!rdev->ops->disassoc) | |
290 | return -EOPNOTSUPP; | |
291 | cmd.disassoc.peer_addr = mlme->addr.sa_data; | |
292 | cmd.disassoc.reason_code = mlme->reason_code; | |
293 | return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc); | |
294 | default: | |
295 | return -EOPNOTSUPP; | |
296 | } | |
297 | } | |
ba44cb72 | 298 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme); |
04a773ad JB |
299 | |
300 | ||
301 | /** | |
302 | * cfg80211_wext_freq - get wext frequency for non-"auto" | |
303 | * @wiphy: the wiphy | |
304 | * @freq: the wext freq encoding | |
305 | * | |
306 | * Returns a channel, %NULL for auto, or an ERR_PTR for errors! | |
307 | */ | |
308 | struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy, | |
309 | struct iw_freq *freq) | |
310 | { | |
0b258582 JB |
311 | struct ieee80211_channel *chan; |
312 | int f; | |
313 | ||
314 | /* | |
315 | * Parse frequency - return NULL for auto and | |
316 | * -EINVAL for impossible things. | |
317 | */ | |
04a773ad JB |
318 | if (freq->e == 0) { |
319 | if (freq->m < 0) | |
320 | return NULL; | |
0b258582 | 321 | f = ieee80211_channel_to_frequency(freq->m); |
04a773ad JB |
322 | } else { |
323 | int i, div = 1000000; | |
324 | for (i = 0; i < freq->e; i++) | |
325 | div /= 10; | |
0b258582 | 326 | if (div <= 0) |
04a773ad | 327 | return ERR_PTR(-EINVAL); |
0b258582 | 328 | f = freq->m / div; |
04a773ad JB |
329 | } |
330 | ||
0b258582 JB |
331 | /* |
332 | * Look up channel struct and return -EINVAL when | |
333 | * it cannot be found. | |
334 | */ | |
335 | chan = ieee80211_get_channel(wiphy, f); | |
336 | if (!chan) | |
337 | return ERR_PTR(-EINVAL); | |
338 | return chan; | |
04a773ad | 339 | } |
ba44cb72 | 340 | EXPORT_SYMBOL_GPL(cfg80211_wext_freq); |
b9a5f8ca JM |
341 | |
342 | int cfg80211_wext_siwrts(struct net_device *dev, | |
343 | struct iw_request_info *info, | |
344 | struct iw_param *rts, char *extra) | |
345 | { | |
346 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
347 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
348 | u32 orts = wdev->wiphy->rts_threshold; | |
349 | int err; | |
350 | ||
351 | if (rts->disabled || !rts->fixed) | |
352 | wdev->wiphy->rts_threshold = (u32) -1; | |
353 | else if (rts->value < 0) | |
354 | return -EINVAL; | |
355 | else | |
356 | wdev->wiphy->rts_threshold = rts->value; | |
357 | ||
358 | err = rdev->ops->set_wiphy_params(wdev->wiphy, | |
359 | WIPHY_PARAM_RTS_THRESHOLD); | |
360 | if (err) | |
361 | wdev->wiphy->rts_threshold = orts; | |
362 | ||
363 | return err; | |
364 | } | |
ba44cb72 | 365 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts); |
b9a5f8ca JM |
366 | |
367 | int cfg80211_wext_giwrts(struct net_device *dev, | |
368 | struct iw_request_info *info, | |
369 | struct iw_param *rts, char *extra) | |
370 | { | |
371 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
372 | ||
373 | rts->value = wdev->wiphy->rts_threshold; | |
374 | rts->disabled = rts->value == (u32) -1; | |
375 | rts->fixed = 1; | |
376 | ||
377 | return 0; | |
378 | } | |
ba44cb72 | 379 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts); |
b9a5f8ca JM |
380 | |
381 | int cfg80211_wext_siwfrag(struct net_device *dev, | |
382 | struct iw_request_info *info, | |
383 | struct iw_param *frag, char *extra) | |
384 | { | |
385 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
386 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
387 | u32 ofrag = wdev->wiphy->frag_threshold; | |
388 | int err; | |
389 | ||
390 | if (frag->disabled || !frag->fixed) | |
391 | wdev->wiphy->frag_threshold = (u32) -1; | |
392 | else if (frag->value < 256) | |
393 | return -EINVAL; | |
394 | else { | |
395 | /* Fragment length must be even, so strip LSB. */ | |
396 | wdev->wiphy->frag_threshold = frag->value & ~0x1; | |
397 | } | |
398 | ||
399 | err = rdev->ops->set_wiphy_params(wdev->wiphy, | |
400 | WIPHY_PARAM_FRAG_THRESHOLD); | |
401 | if (err) | |
402 | wdev->wiphy->frag_threshold = ofrag; | |
403 | ||
404 | return err; | |
405 | } | |
ba44cb72 | 406 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag); |
b9a5f8ca JM |
407 | |
408 | int cfg80211_wext_giwfrag(struct net_device *dev, | |
409 | struct iw_request_info *info, | |
410 | struct iw_param *frag, char *extra) | |
411 | { | |
412 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
413 | ||
414 | frag->value = wdev->wiphy->frag_threshold; | |
415 | frag->disabled = frag->value == (u32) -1; | |
416 | frag->fixed = 1; | |
417 | ||
418 | return 0; | |
419 | } | |
ba44cb72 | 420 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag); |
b9a5f8ca JM |
421 | |
422 | int cfg80211_wext_siwretry(struct net_device *dev, | |
423 | struct iw_request_info *info, | |
424 | struct iw_param *retry, char *extra) | |
425 | { | |
426 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
427 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
428 | u32 changed = 0; | |
429 | u8 olong = wdev->wiphy->retry_long; | |
430 | u8 oshort = wdev->wiphy->retry_short; | |
431 | int err; | |
432 | ||
433 | if (retry->disabled || | |
434 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) | |
435 | return -EINVAL; | |
436 | ||
437 | if (retry->flags & IW_RETRY_LONG) { | |
438 | wdev->wiphy->retry_long = retry->value; | |
439 | changed |= WIPHY_PARAM_RETRY_LONG; | |
440 | } else if (retry->flags & IW_RETRY_SHORT) { | |
441 | wdev->wiphy->retry_short = retry->value; | |
442 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
443 | } else { | |
444 | wdev->wiphy->retry_short = retry->value; | |
445 | wdev->wiphy->retry_long = retry->value; | |
446 | changed |= WIPHY_PARAM_RETRY_LONG; | |
447 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
448 | } | |
449 | ||
450 | if (!changed) | |
451 | return 0; | |
452 | ||
453 | err = rdev->ops->set_wiphy_params(wdev->wiphy, changed); | |
454 | if (err) { | |
455 | wdev->wiphy->retry_short = oshort; | |
456 | wdev->wiphy->retry_long = olong; | |
457 | } | |
458 | ||
459 | return err; | |
460 | } | |
ba44cb72 | 461 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry); |
b9a5f8ca JM |
462 | |
463 | int cfg80211_wext_giwretry(struct net_device *dev, | |
464 | struct iw_request_info *info, | |
465 | struct iw_param *retry, char *extra) | |
466 | { | |
467 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
468 | ||
469 | retry->disabled = 0; | |
470 | ||
471 | if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) { | |
472 | /* | |
473 | * First return short value, iwconfig will ask long value | |
474 | * later if needed | |
475 | */ | |
476 | retry->flags |= IW_RETRY_LIMIT; | |
477 | retry->value = wdev->wiphy->retry_short; | |
478 | if (wdev->wiphy->retry_long != wdev->wiphy->retry_short) | |
479 | retry->flags |= IW_RETRY_LONG; | |
480 | ||
481 | return 0; | |
482 | } | |
483 | ||
484 | if (retry->flags & IW_RETRY_LONG) { | |
485 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
486 | retry->value = wdev->wiphy->retry_long; | |
487 | } | |
488 | ||
489 | return 0; | |
490 | } | |
ba44cb72 | 491 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); |
08645126 JB |
492 | |
493 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | |
494 | struct net_device *dev, const u8 *addr, | |
495 | bool remove, bool tx_key, int idx, | |
496 | struct key_params *params) | |
497 | { | |
498 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
499 | int err; | |
500 | ||
501 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | |
502 | if (!rdev->ops->set_default_mgmt_key) | |
503 | return -EOPNOTSUPP; | |
504 | ||
505 | if (idx < 4 || idx > 5) | |
506 | return -EINVAL; | |
507 | } else if (idx < 0 || idx > 3) | |
508 | return -EINVAL; | |
509 | ||
510 | if (remove) { | |
511 | err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); | |
512 | if (!err) { | |
513 | if (idx == wdev->wext.default_key) | |
514 | wdev->wext.default_key = -1; | |
515 | else if (idx == wdev->wext.default_mgmt_key) | |
516 | wdev->wext.default_mgmt_key = -1; | |
517 | } | |
e3da574a JB |
518 | /* |
519 | * Applications using wireless extensions expect to be | |
520 | * able to delete keys that don't exist, so allow that. | |
521 | */ | |
522 | if (err == -ENOENT) | |
523 | return 0; | |
524 | ||
08645126 JB |
525 | return err; |
526 | } else { | |
527 | if (addr) | |
528 | tx_key = false; | |
529 | ||
530 | if (cfg80211_validate_key_settings(params, idx, addr)) | |
531 | return -EINVAL; | |
532 | ||
533 | err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); | |
534 | if (err) | |
535 | return err; | |
536 | ||
537 | if (tx_key || (!addr && wdev->wext.default_key == -1)) { | |
538 | err = rdev->ops->set_default_key(&rdev->wiphy, | |
539 | dev, idx); | |
540 | if (!err) | |
541 | wdev->wext.default_key = idx; | |
542 | return err; | |
543 | } | |
544 | ||
545 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && | |
546 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { | |
547 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | |
548 | dev, idx); | |
549 | if (!err) | |
550 | wdev->wext.default_mgmt_key = idx; | |
551 | return err; | |
552 | } | |
553 | ||
554 | return 0; | |
555 | } | |
556 | } | |
557 | ||
558 | int cfg80211_wext_siwencode(struct net_device *dev, | |
559 | struct iw_request_info *info, | |
560 | struct iw_point *erq, char *keybuf) | |
561 | { | |
562 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
563 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
564 | int idx, err; | |
565 | bool remove = false; | |
566 | struct key_params params; | |
567 | ||
568 | /* no use -- only MFP (set_default_mgmt_key) is optional */ | |
569 | if (!rdev->ops->del_key || | |
570 | !rdev->ops->add_key || | |
571 | !rdev->ops->set_default_key) | |
572 | return -EOPNOTSUPP; | |
573 | ||
574 | idx = erq->flags & IW_ENCODE_INDEX; | |
575 | if (idx == 0) { | |
576 | idx = wdev->wext.default_key; | |
577 | if (idx < 0) | |
578 | idx = 0; | |
579 | } else if (idx < 1 || idx > 4) | |
580 | return -EINVAL; | |
581 | else | |
582 | idx--; | |
583 | ||
584 | if (erq->flags & IW_ENCODE_DISABLED) | |
585 | remove = true; | |
586 | else if (erq->length == 0) { | |
587 | /* No key data - just set the default TX key index */ | |
588 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, idx); | |
589 | if (!err) | |
590 | wdev->wext.default_key = idx; | |
591 | return err; | |
592 | } | |
593 | ||
594 | memset(¶ms, 0, sizeof(params)); | |
595 | params.key = keybuf; | |
596 | params.key_len = erq->length; | |
597 | if (erq->length == 5) | |
598 | params.cipher = WLAN_CIPHER_SUITE_WEP40; | |
599 | else if (erq->length == 13) | |
600 | params.cipher = WLAN_CIPHER_SUITE_WEP104; | |
601 | else if (!remove) | |
602 | return -EINVAL; | |
603 | ||
604 | return cfg80211_set_encryption(rdev, dev, NULL, remove, | |
605 | wdev->wext.default_key == -1, | |
606 | idx, ¶ms); | |
607 | } | |
608 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode); | |
609 | ||
610 | int cfg80211_wext_siwencodeext(struct net_device *dev, | |
611 | struct iw_request_info *info, | |
612 | struct iw_point *erq, char *extra) | |
613 | { | |
614 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
615 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
616 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; | |
617 | const u8 *addr; | |
618 | int idx; | |
619 | bool remove = false; | |
620 | struct key_params params; | |
621 | u32 cipher; | |
622 | ||
623 | /* no use -- only MFP (set_default_mgmt_key) is optional */ | |
624 | if (!rdev->ops->del_key || | |
625 | !rdev->ops->add_key || | |
626 | !rdev->ops->set_default_key) | |
627 | return -EOPNOTSUPP; | |
628 | ||
629 | switch (ext->alg) { | |
630 | case IW_ENCODE_ALG_NONE: | |
631 | remove = true; | |
632 | cipher = 0; | |
633 | break; | |
634 | case IW_ENCODE_ALG_WEP: | |
635 | if (ext->key_len == 5) | |
636 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
637 | else if (ext->key_len == 13) | |
638 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
639 | else | |
640 | return -EINVAL; | |
641 | break; | |
642 | case IW_ENCODE_ALG_TKIP: | |
643 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
644 | break; | |
645 | case IW_ENCODE_ALG_CCMP: | |
646 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
647 | break; | |
648 | case IW_ENCODE_ALG_AES_CMAC: | |
649 | cipher = WLAN_CIPHER_SUITE_AES_CMAC; | |
650 | break; | |
651 | default: | |
652 | return -EOPNOTSUPP; | |
653 | } | |
654 | ||
655 | if (erq->flags & IW_ENCODE_DISABLED) | |
656 | remove = true; | |
657 | ||
658 | idx = erq->flags & IW_ENCODE_INDEX; | |
659 | if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | |
660 | if (idx < 4 || idx > 5) { | |
661 | idx = wdev->wext.default_mgmt_key; | |
662 | if (idx < 0) | |
663 | return -EINVAL; | |
664 | } else | |
665 | idx--; | |
666 | } else { | |
667 | if (idx < 1 || idx > 4) { | |
668 | idx = wdev->wext.default_key; | |
669 | if (idx < 0) | |
670 | return -EINVAL; | |
671 | } else | |
672 | idx--; | |
673 | } | |
674 | ||
675 | addr = ext->addr.sa_data; | |
676 | if (is_broadcast_ether_addr(addr)) | |
677 | addr = NULL; | |
678 | ||
679 | memset(¶ms, 0, sizeof(params)); | |
680 | params.key = ext->key; | |
681 | params.key_len = ext->key_len; | |
682 | params.cipher = cipher; | |
683 | ||
faa8fdc8 JM |
684 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
685 | params.seq = ext->rx_seq; | |
686 | params.seq_len = 6; | |
687 | } | |
688 | ||
08645126 JB |
689 | return cfg80211_set_encryption( |
690 | rdev, dev, addr, remove, | |
691 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, | |
692 | idx, ¶ms); | |
693 | } | |
694 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext); | |
695 | ||
696 | struct giwencode_cookie { | |
697 | size_t buflen; | |
698 | char *keybuf; | |
699 | }; | |
700 | ||
701 | static void giwencode_get_key_cb(void *cookie, struct key_params *params) | |
702 | { | |
703 | struct giwencode_cookie *data = cookie; | |
704 | ||
705 | if (!params->key) { | |
706 | data->buflen = 0; | |
707 | return; | |
708 | } | |
709 | ||
710 | data->buflen = min_t(size_t, data->buflen, params->key_len); | |
711 | memcpy(data->keybuf, params->key, data->buflen); | |
712 | } | |
713 | ||
714 | int cfg80211_wext_giwencode(struct net_device *dev, | |
715 | struct iw_request_info *info, | |
716 | struct iw_point *erq, char *keybuf) | |
717 | { | |
718 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
719 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
720 | int idx, err; | |
721 | struct giwencode_cookie data = { | |
722 | .keybuf = keybuf, | |
723 | .buflen = erq->length, | |
724 | }; | |
725 | ||
726 | if (!rdev->ops->get_key) | |
727 | return -EOPNOTSUPP; | |
728 | ||
729 | idx = erq->flags & IW_ENCODE_INDEX; | |
730 | if (idx == 0) { | |
731 | idx = wdev->wext.default_key; | |
732 | if (idx < 0) | |
733 | idx = 0; | |
734 | } else if (idx < 1 || idx > 4) | |
735 | return -EINVAL; | |
736 | else | |
737 | idx--; | |
738 | ||
739 | erq->flags = idx + 1; | |
740 | ||
741 | err = rdev->ops->get_key(&rdev->wiphy, dev, idx, NULL, &data, | |
742 | giwencode_get_key_cb); | |
743 | if (!err) { | |
744 | erq->length = data.buflen; | |
745 | erq->flags |= IW_ENCODE_ENABLED; | |
746 | return 0; | |
747 | } | |
748 | ||
749 | if (err == -ENOENT) { | |
750 | erq->flags |= IW_ENCODE_DISABLED; | |
751 | erq->length = 0; | |
752 | return 0; | |
753 | } | |
754 | ||
755 | return err; | |
756 | } | |
757 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); | |
7643a2c3 JB |
758 | |
759 | int cfg80211_wext_siwtxpower(struct net_device *dev, | |
760 | struct iw_request_info *info, | |
761 | union iwreq_data *data, char *extra) | |
762 | { | |
763 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
764 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
765 | enum tx_power_setting type; | |
766 | int dbm = 0; | |
767 | ||
768 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
769 | return -EINVAL; | |
770 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
771 | return -EINVAL; | |
772 | ||
773 | if (!rdev->ops->set_tx_power) | |
774 | return -EOPNOTSUPP; | |
775 | ||
776 | /* only change when not disabling */ | |
777 | if (!data->txpower.disabled) { | |
1f87f7d3 JB |
778 | rfkill_set_sw_state(rdev->rfkill, false); |
779 | ||
7643a2c3 JB |
780 | if (data->txpower.fixed) { |
781 | /* | |
782 | * wext doesn't support negative values, see | |
783 | * below where it's for automatic | |
784 | */ | |
785 | if (data->txpower.value < 0) | |
786 | return -EINVAL; | |
787 | dbm = data->txpower.value; | |
788 | type = TX_POWER_FIXED; | |
789 | /* TODO: do regulatory check! */ | |
790 | } else { | |
791 | /* | |
792 | * Automatic power level setting, max being the value | |
793 | * passed in from userland. | |
794 | */ | |
795 | if (data->txpower.value < 0) { | |
796 | type = TX_POWER_AUTOMATIC; | |
797 | } else { | |
798 | dbm = data->txpower.value; | |
799 | type = TX_POWER_LIMITED; | |
800 | } | |
801 | } | |
802 | } else { | |
1f87f7d3 JB |
803 | rfkill_set_sw_state(rdev->rfkill, true); |
804 | schedule_work(&rdev->rfkill_sync); | |
805 | return 0; | |
7643a2c3 JB |
806 | } |
807 | ||
808 | return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; | |
809 | } | |
810 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); | |
811 | ||
812 | int cfg80211_wext_giwtxpower(struct net_device *dev, | |
813 | struct iw_request_info *info, | |
814 | union iwreq_data *data, char *extra) | |
815 | { | |
816 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
817 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
818 | int err, val; | |
819 | ||
820 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
821 | return -EINVAL; | |
822 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
823 | return -EINVAL; | |
824 | ||
825 | if (!rdev->ops->get_tx_power) | |
826 | return -EOPNOTSUPP; | |
827 | ||
828 | err = rdev->ops->get_tx_power(wdev->wiphy, &val); | |
1f87f7d3 | 829 | if (err) |
7643a2c3 JB |
830 | return err; |
831 | ||
832 | /* well... oh well */ | |
833 | data->txpower.fixed = 1; | |
1f87f7d3 | 834 | data->txpower.disabled = rfkill_blocked(rdev->rfkill); |
7643a2c3 JB |
835 | data->txpower.value = val; |
836 | data->txpower.flags = IW_TXPOW_DBM; | |
837 | ||
838 | return 0; | |
839 | } | |
840 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); |