diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-14 13:37:28 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-14 13:37:28 -0400 |
commit | d7e9660ad9d5e0845f52848bce31bcf5cdcdea6b (patch) | |
tree | c6c67d145771187b194d79d603742b31090a59d6 /net/wireless/wext-compat.c | |
parent | b8cb48aae1b8c50b37dcb7710363aa69a7a0d9ca (diff) | |
parent | 13af7a6ea502fcdd4c0e3d7de6e332b102309491 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1623 commits)
netxen: update copyright
netxen: fix tx timeout recovery
netxen: fix file firmware leak
netxen: improve pci memory access
netxen: change firmware write size
tg3: Fix return ring size breakage
netxen: build fix for INET=n
cdc-phonet: autoconfigure Phonet address
Phonet: back-end for autoconfigured addresses
Phonet: fix netlink address dump error handling
ipv6: Add IFA_F_DADFAILED flag
net: Add DEVTYPE support for Ethernet based devices
mv643xx_eth.c: remove unused txq_set_wrr()
ucc_geth: Fix hangs after switching from full to half duplex
ucc_geth: Rearrange some code to avoid forward declarations
phy/marvell: Make non-aneg speed/duplex forcing work for 88E1111 PHYs
drivers/net/phy: introduce missing kfree
drivers/net/wan: introduce missing kfree
net: force bridge module(s) to be GPL
Subject: [PATCH] appletalk: Fix skb leak when ipddp interface is not loaded
...
Fixed up trivial conflicts:
- arch/x86/include/asm/socket.h
converted to <asm-generic/socket.h> in the x86 tree. The generic
header has the same new #define's, so that works out fine.
- drivers/net/tun.c
fix conflict between 89f56d1e9 ("tun: reuse struct sock fields") that
switched over to using 'tun->socket.sk' instead of the redundantly
available (and thus removed) 'tun->sk', and 2b980dbd ("lsm: Add hooks
to the TUN driver") which added a new 'tun->sk' use.
Noted in 'next' by Stephen Rothwell.
Diffstat (limited to 'net/wireless/wext-compat.c')
-rw-r--r-- | net/wireless/wext-compat.c | 880 |
1 files changed, 732 insertions, 148 deletions
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c index d030c5315672..429dd06a4ecc 100644 --- a/net/wireless/wext-compat.c +++ b/net/wireless/wext-compat.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/etherdevice.h> | 14 | #include <linux/etherdevice.h> |
15 | #include <net/iw_handler.h> | 15 | #include <net/iw_handler.h> |
16 | #include <net/cfg80211.h> | 16 | #include <net/cfg80211.h> |
17 | #include "wext-compat.h" | ||
17 | #include "core.h" | 18 | #include "core.h" |
18 | 19 | ||
19 | int cfg80211_wext_giwname(struct net_device *dev, | 20 | int cfg80211_wext_giwname(struct net_device *dev, |
@@ -69,18 +70,8 @@ int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, | |||
69 | enum nl80211_iftype type; | 70 | enum nl80211_iftype type; |
70 | int ret; | 71 | int ret; |
71 | 72 | ||
72 | if (!wdev) | ||
73 | return -EOPNOTSUPP; | ||
74 | |||
75 | rdev = wiphy_to_dev(wdev->wiphy); | 73 | rdev = wiphy_to_dev(wdev->wiphy); |
76 | 74 | ||
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) { | 75 | switch (*mode) { |
85 | case IW_MODE_INFRA: | 76 | case IW_MODE_INFRA: |
86 | type = NL80211_IFTYPE_STATION; | 77 | type = NL80211_IFTYPE_STATION; |
@@ -103,9 +94,9 @@ int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, | |||
103 | 94 | ||
104 | memset(&vifparams, 0, sizeof(vifparams)); | 95 | memset(&vifparams, 0, sizeof(vifparams)); |
105 | 96 | ||
106 | ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev->ifindex, type, | 97 | cfg80211_lock_rdev(rdev); |
107 | NULL, &vifparams); | 98 | ret = cfg80211_change_iface(rdev, dev, type, NULL, &vifparams); |
108 | WARN_ON(!ret && wdev->iftype != type); | 99 | cfg80211_unlock_rdev(rdev); |
109 | 100 | ||
110 | return ret; | 101 | return ret; |
111 | } | 102 | } |
@@ -154,7 +145,7 @@ int cfg80211_wext_giwrange(struct net_device *dev, | |||
154 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 145 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
155 | struct iw_range *range = (struct iw_range *) extra; | 146 | struct iw_range *range = (struct iw_range *) extra; |
156 | enum ieee80211_band band; | 147 | enum ieee80211_band band; |
157 | int c = 0; | 148 | int i, c = 0; |
158 | 149 | ||
159 | if (!wdev) | 150 | if (!wdev) |
160 | return -EOPNOTSUPP; | 151 | return -EOPNOTSUPP; |
@@ -173,9 +164,6 @@ int cfg80211_wext_giwrange(struct net_device *dev, | |||
173 | range->min_frag = 256; | 164 | range->min_frag = 256; |
174 | range->max_frag = 2346; | 165 | range->max_frag = 2346; |
175 | 166 | ||
176 | range->encoding_size[0] = 5; | ||
177 | range->encoding_size[1] = 13; | ||
178 | range->num_encoding_sizes = 2; | ||
179 | range->max_encoding_tokens = 4; | 167 | range->max_encoding_tokens = 4; |
180 | 168 | ||
181 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; | 169 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; |
@@ -204,11 +192,31 @@ int cfg80211_wext_giwrange(struct net_device *dev, | |||
204 | range->avg_qual.noise = range->max_qual.noise / 2; | 192 | range->avg_qual.noise = range->max_qual.noise / 2; |
205 | range->avg_qual.updated = range->max_qual.updated; | 193 | range->avg_qual.updated = range->max_qual.updated; |
206 | 194 | ||
207 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | 195 | for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) { |
208 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | 196 | switch (wdev->wiphy->cipher_suites[i]) { |
197 | case WLAN_CIPHER_SUITE_TKIP: | ||
198 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP | | ||
199 | IW_ENC_CAPA_WPA); | ||
200 | break; | ||
201 | |||
202 | case WLAN_CIPHER_SUITE_CCMP: | ||
203 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP | | ||
204 | IW_ENC_CAPA_WPA2); | ||
205 | break; | ||
206 | |||
207 | case WLAN_CIPHER_SUITE_WEP40: | ||
208 | range->encoding_size[range->num_encoding_sizes++] = | ||
209 | WLAN_KEY_LEN_WEP40; | ||
210 | break; | ||
211 | |||
212 | case WLAN_CIPHER_SUITE_WEP104: | ||
213 | range->encoding_size[range->num_encoding_sizes++] = | ||
214 | WLAN_KEY_LEN_WEP104; | ||
215 | break; | ||
216 | } | ||
217 | } | ||
209 | 218 | ||
210 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { | 219 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
211 | int i; | ||
212 | struct ieee80211_supported_band *sband; | 220 | struct ieee80211_supported_band *sband; |
213 | 221 | ||
214 | sband = wdev->wiphy->bands[band]; | 222 | sband = wdev->wiphy->bands[band]; |
@@ -236,97 +244,40 @@ int cfg80211_wext_giwrange(struct net_device *dev, | |||
236 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); | 244 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
237 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | 245 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
238 | 246 | ||
239 | range->scan_capa |= IW_SCAN_CAPA_ESSID; | 247 | if (wdev->wiphy->max_scan_ssids > 0) |
248 | range->scan_capa |= IW_SCAN_CAPA_ESSID; | ||
240 | 249 | ||
241 | return 0; | 250 | return 0; |
242 | } | 251 | } |
243 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); | 252 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); |
244 | 253 | ||
245 | int cfg80211_wext_siwmlme(struct net_device *dev, | ||
246 | struct iw_request_info *info, | ||
247 | struct iw_point *data, char *extra) | ||
248 | { | ||
249 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
250 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | ||
251 | struct cfg80211_registered_device *rdev; | ||
252 | union { | ||
253 | struct cfg80211_disassoc_request disassoc; | ||
254 | struct cfg80211_deauth_request deauth; | ||
255 | } cmd; | ||
256 | |||
257 | if (!wdev) | ||
258 | return -EOPNOTSUPP; | ||
259 | |||
260 | rdev = wiphy_to_dev(wdev->wiphy); | ||
261 | |||
262 | if (wdev->iftype != NL80211_IFTYPE_STATION) | ||
263 | return -EINVAL; | ||
264 | |||
265 | if (mlme->addr.sa_family != ARPHRD_ETHER) | ||
266 | return -EINVAL; | ||
267 | |||
268 | memset(&cmd, 0, sizeof(cmd)); | ||
269 | |||
270 | switch (mlme->cmd) { | ||
271 | case IW_MLME_DEAUTH: | ||
272 | if (!rdev->ops->deauth) | ||
273 | return -EOPNOTSUPP; | ||
274 | cmd.deauth.peer_addr = mlme->addr.sa_data; | ||
275 | cmd.deauth.reason_code = mlme->reason_code; | ||
276 | return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth); | ||
277 | case IW_MLME_DISASSOC: | ||
278 | if (!rdev->ops->disassoc) | ||
279 | return -EOPNOTSUPP; | ||
280 | cmd.disassoc.peer_addr = mlme->addr.sa_data; | ||
281 | cmd.disassoc.reason_code = mlme->reason_code; | ||
282 | return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc); | ||
283 | default: | ||
284 | return -EOPNOTSUPP; | ||
285 | } | ||
286 | } | ||
287 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme); | ||
288 | |||
289 | 254 | ||
290 | /** | 255 | /** |
291 | * cfg80211_wext_freq - get wext frequency for non-"auto" | 256 | * cfg80211_wext_freq - get wext frequency for non-"auto" |
292 | * @wiphy: the wiphy | 257 | * @wiphy: the wiphy |
293 | * @freq: the wext freq encoding | 258 | * @freq: the wext freq encoding |
294 | * | 259 | * |
295 | * Returns a channel, %NULL for auto, or an ERR_PTR for errors! | 260 | * Returns a frequency, or a negative error code, or 0 for auto. |
296 | */ | 261 | */ |
297 | struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy, | 262 | int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq) |
298 | struct iw_freq *freq) | ||
299 | { | 263 | { |
300 | struct ieee80211_channel *chan; | ||
301 | int f; | ||
302 | |||
303 | /* | 264 | /* |
304 | * Parse frequency - return NULL for auto and | 265 | * Parse frequency - return 0 for auto and |
305 | * -EINVAL for impossible things. | 266 | * -EINVAL for impossible things. |
306 | */ | 267 | */ |
307 | if (freq->e == 0) { | 268 | if (freq->e == 0) { |
308 | if (freq->m < 0) | 269 | if (freq->m < 0) |
309 | return NULL; | 270 | return 0; |
310 | f = ieee80211_channel_to_frequency(freq->m); | 271 | return ieee80211_channel_to_frequency(freq->m); |
311 | } else { | 272 | } else { |
312 | int i, div = 1000000; | 273 | int i, div = 1000000; |
313 | for (i = 0; i < freq->e; i++) | 274 | for (i = 0; i < freq->e; i++) |
314 | div /= 10; | 275 | div /= 10; |
315 | if (div <= 0) | 276 | if (div <= 0) |
316 | return ERR_PTR(-EINVAL); | 277 | return -EINVAL; |
317 | f = freq->m / div; | 278 | return freq->m / div; |
318 | } | 279 | } |
319 | |||
320 | /* | ||
321 | * Look up channel struct and return -EINVAL when | ||
322 | * it cannot be found. | ||
323 | */ | ||
324 | chan = ieee80211_get_channel(wiphy, f); | ||
325 | if (!chan) | ||
326 | return ERR_PTR(-EINVAL); | ||
327 | return chan; | ||
328 | } | 280 | } |
329 | EXPORT_SYMBOL_GPL(cfg80211_wext_freq); | ||
330 | 281 | ||
331 | int cfg80211_wext_siwrts(struct net_device *dev, | 282 | int cfg80211_wext_siwrts(struct net_device *dev, |
332 | struct iw_request_info *info, | 283 | struct iw_request_info *info, |
@@ -479,15 +430,32 @@ int cfg80211_wext_giwretry(struct net_device *dev, | |||
479 | } | 430 | } |
480 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); | 431 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); |
481 | 432 | ||
482 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | 433 | static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev, |
483 | struct net_device *dev, const u8 *addr, | 434 | struct net_device *dev, const u8 *addr, |
484 | bool remove, bool tx_key, int idx, | 435 | bool remove, bool tx_key, int idx, |
485 | struct key_params *params) | 436 | struct key_params *params) |
486 | { | 437 | { |
487 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 438 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
488 | int err; | 439 | int err, i; |
440 | |||
441 | if (!wdev->wext.keys) { | ||
442 | wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys), | ||
443 | GFP_KERNEL); | ||
444 | if (!wdev->wext.keys) | ||
445 | return -ENOMEM; | ||
446 | for (i = 0; i < 6; i++) | ||
447 | wdev->wext.keys->params[i].key = | ||
448 | wdev->wext.keys->data[i]; | ||
449 | } | ||
450 | |||
451 | if (wdev->iftype != NL80211_IFTYPE_ADHOC && | ||
452 | wdev->iftype != NL80211_IFTYPE_STATION) | ||
453 | return -EOPNOTSUPP; | ||
489 | 454 | ||
490 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | 455 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
456 | if (!wdev->current_bss) | ||
457 | return -ENOLINK; | ||
458 | |||
491 | if (!rdev->ops->set_default_mgmt_key) | 459 | if (!rdev->ops->set_default_mgmt_key) |
492 | return -EOPNOTSUPP; | 460 | return -EOPNOTSUPP; |
493 | 461 | ||
@@ -497,8 +465,14 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | |||
497 | return -EINVAL; | 465 | return -EINVAL; |
498 | 466 | ||
499 | if (remove) { | 467 | if (remove) { |
500 | err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); | 468 | err = 0; |
469 | if (wdev->current_bss) | ||
470 | err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); | ||
501 | if (!err) { | 471 | if (!err) { |
472 | if (!addr) { | ||
473 | wdev->wext.keys->params[idx].key_len = 0; | ||
474 | wdev->wext.keys->params[idx].cipher = 0; | ||
475 | } | ||
502 | if (idx == wdev->wext.default_key) | 476 | if (idx == wdev->wext.default_key) |
503 | wdev->wext.default_key = -1; | 477 | wdev->wext.default_key = -1; |
504 | else if (idx == wdev->wext.default_mgmt_key) | 478 | else if (idx == wdev->wext.default_mgmt_key) |
@@ -512,36 +486,65 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | |||
512 | return 0; | 486 | return 0; |
513 | 487 | ||
514 | return err; | 488 | return err; |
515 | } else { | 489 | } |
516 | if (addr) | ||
517 | tx_key = false; | ||
518 | 490 | ||
519 | if (cfg80211_validate_key_settings(params, idx, addr)) | 491 | if (addr) |
520 | return -EINVAL; | 492 | tx_key = false; |
521 | 493 | ||
494 | if (cfg80211_validate_key_settings(rdev, params, idx, addr)) | ||
495 | return -EINVAL; | ||
496 | |||
497 | err = 0; | ||
498 | if (wdev->current_bss) | ||
522 | err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); | 499 | err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); |
523 | if (err) | 500 | if (err) |
524 | return err; | 501 | return err; |
502 | |||
503 | if (!addr) { | ||
504 | wdev->wext.keys->params[idx] = *params; | ||
505 | memcpy(wdev->wext.keys->data[idx], | ||
506 | params->key, params->key_len); | ||
507 | wdev->wext.keys->params[idx].key = | ||
508 | wdev->wext.keys->data[idx]; | ||
509 | } | ||
525 | 510 | ||
526 | if (tx_key || (!addr && wdev->wext.default_key == -1)) { | 511 | if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 || |
512 | params->cipher == WLAN_CIPHER_SUITE_WEP104) && | ||
513 | (tx_key || (!addr && wdev->wext.default_key == -1))) { | ||
514 | if (wdev->current_bss) | ||
527 | err = rdev->ops->set_default_key(&rdev->wiphy, | 515 | err = rdev->ops->set_default_key(&rdev->wiphy, |
528 | dev, idx); | 516 | dev, idx); |
529 | if (!err) | 517 | if (!err) |
530 | wdev->wext.default_key = idx; | 518 | wdev->wext.default_key = idx; |
531 | return err; | 519 | return err; |
532 | } | 520 | } |
533 | 521 | ||
534 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && | 522 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && |
535 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { | 523 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { |
524 | if (wdev->current_bss) | ||
536 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | 525 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
537 | dev, idx); | 526 | dev, idx); |
538 | if (!err) | 527 | if (!err) |
539 | wdev->wext.default_mgmt_key = idx; | 528 | wdev->wext.default_mgmt_key = idx; |
540 | return err; | 529 | return err; |
541 | } | ||
542 | |||
543 | return 0; | ||
544 | } | 530 | } |
531 | |||
532 | return 0; | ||
533 | } | ||
534 | |||
535 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, | ||
536 | struct net_device *dev, const u8 *addr, | ||
537 | bool remove, bool tx_key, int idx, | ||
538 | struct key_params *params) | ||
539 | { | ||
540 | int err; | ||
541 | |||
542 | wdev_lock(dev->ieee80211_ptr); | ||
543 | err = __cfg80211_set_encryption(rdev, dev, addr, remove, | ||
544 | tx_key, idx, params); | ||
545 | wdev_unlock(dev->ieee80211_ptr); | ||
546 | |||
547 | return err; | ||
545 | } | 548 | } |
546 | 549 | ||
547 | int cfg80211_wext_siwencode(struct net_device *dev, | 550 | int cfg80211_wext_siwencode(struct net_device *dev, |
@@ -554,6 +557,10 @@ int cfg80211_wext_siwencode(struct net_device *dev, | |||
554 | bool remove = false; | 557 | bool remove = false; |
555 | struct key_params params; | 558 | struct key_params params; |
556 | 559 | ||
560 | if (wdev->iftype != NL80211_IFTYPE_STATION && | ||
561 | wdev->iftype != NL80211_IFTYPE_ADHOC) | ||
562 | return -EOPNOTSUPP; | ||
563 | |||
557 | /* no use -- only MFP (set_default_mgmt_key) is optional */ | 564 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
558 | if (!rdev->ops->del_key || | 565 | if (!rdev->ops->del_key || |
559 | !rdev->ops->add_key || | 566 | !rdev->ops->add_key || |
@@ -574,9 +581,14 @@ int cfg80211_wext_siwencode(struct net_device *dev, | |||
574 | remove = true; | 581 | remove = true; |
575 | else if (erq->length == 0) { | 582 | else if (erq->length == 0) { |
576 | /* No key data - just set the default TX key index */ | 583 | /* No key data - just set the default TX key index */ |
577 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, idx); | 584 | err = 0; |
585 | wdev_lock(wdev); | ||
586 | if (wdev->current_bss) | ||
587 | err = rdev->ops->set_default_key(&rdev->wiphy, | ||
588 | dev, idx); | ||
578 | if (!err) | 589 | if (!err) |
579 | wdev->wext.default_key = idx; | 590 | wdev->wext.default_key = idx; |
591 | wdev_unlock(wdev); | ||
580 | return err; | 592 | return err; |
581 | } | 593 | } |
582 | 594 | ||
@@ -609,6 +621,10 @@ int cfg80211_wext_siwencodeext(struct net_device *dev, | |||
609 | struct key_params params; | 621 | struct key_params params; |
610 | u32 cipher; | 622 | u32 cipher; |
611 | 623 | ||
624 | if (wdev->iftype != NL80211_IFTYPE_STATION && | ||
625 | wdev->iftype != NL80211_IFTYPE_ADHOC) | ||
626 | return -EOPNOTSUPP; | ||
627 | |||
612 | /* no use -- only MFP (set_default_mgmt_key) is optional */ | 628 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
613 | if (!rdev->ops->del_key || | 629 | if (!rdev->ops->del_key || |
614 | !rdev->ops->add_key || | 630 | !rdev->ops->add_key || |
@@ -682,37 +698,15 @@ int cfg80211_wext_siwencodeext(struct net_device *dev, | |||
682 | } | 698 | } |
683 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext); | 699 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext); |
684 | 700 | ||
685 | struct giwencode_cookie { | ||
686 | size_t buflen; | ||
687 | char *keybuf; | ||
688 | }; | ||
689 | |||
690 | static void giwencode_get_key_cb(void *cookie, struct key_params *params) | ||
691 | { | ||
692 | struct giwencode_cookie *data = cookie; | ||
693 | |||
694 | if (!params->key) { | ||
695 | data->buflen = 0; | ||
696 | return; | ||
697 | } | ||
698 | |||
699 | data->buflen = min_t(size_t, data->buflen, params->key_len); | ||
700 | memcpy(data->keybuf, params->key, data->buflen); | ||
701 | } | ||
702 | |||
703 | int cfg80211_wext_giwencode(struct net_device *dev, | 701 | int cfg80211_wext_giwencode(struct net_device *dev, |
704 | struct iw_request_info *info, | 702 | struct iw_request_info *info, |
705 | struct iw_point *erq, char *keybuf) | 703 | struct iw_point *erq, char *keybuf) |
706 | { | 704 | { |
707 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 705 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
708 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | 706 | int idx; |
709 | int idx, err; | ||
710 | struct giwencode_cookie data = { | ||
711 | .keybuf = keybuf, | ||
712 | .buflen = erq->length, | ||
713 | }; | ||
714 | 707 | ||
715 | if (!rdev->ops->get_key) | 708 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
709 | wdev->iftype != NL80211_IFTYPE_ADHOC) | ||
716 | return -EOPNOTSUPP; | 710 | return -EOPNOTSUPP; |
717 | 711 | ||
718 | idx = erq->flags & IW_ENCODE_INDEX; | 712 | idx = erq->flags & IW_ENCODE_INDEX; |
@@ -727,24 +721,70 @@ int cfg80211_wext_giwencode(struct net_device *dev, | |||
727 | 721 | ||
728 | erq->flags = idx + 1; | 722 | erq->flags = idx + 1; |
729 | 723 | ||
730 | err = rdev->ops->get_key(&rdev->wiphy, dev, idx, NULL, &data, | 724 | if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) { |
731 | giwencode_get_key_cb); | ||
732 | if (!err) { | ||
733 | erq->length = data.buflen; | ||
734 | erq->flags |= IW_ENCODE_ENABLED; | ||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | if (err == -ENOENT) { | ||
739 | erq->flags |= IW_ENCODE_DISABLED; | 725 | erq->flags |= IW_ENCODE_DISABLED; |
740 | erq->length = 0; | 726 | erq->length = 0; |
741 | return 0; | 727 | return 0; |
742 | } | 728 | } |
743 | 729 | ||
744 | return err; | 730 | erq->length = min_t(size_t, erq->length, |
731 | wdev->wext.keys->params[idx].key_len); | ||
732 | memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length); | ||
733 | erq->flags |= IW_ENCODE_ENABLED; | ||
734 | |||
735 | return 0; | ||
745 | } | 736 | } |
746 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); | 737 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); |
747 | 738 | ||
739 | int cfg80211_wext_siwfreq(struct net_device *dev, | ||
740 | struct iw_request_info *info, | ||
741 | struct iw_freq *wextfreq, char *extra) | ||
742 | { | ||
743 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
744 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
745 | int freq, err; | ||
746 | |||
747 | switch (wdev->iftype) { | ||
748 | case NL80211_IFTYPE_STATION: | ||
749 | return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra); | ||
750 | case NL80211_IFTYPE_ADHOC: | ||
751 | return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); | ||
752 | default: | ||
753 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); | ||
754 | if (freq < 0) | ||
755 | return freq; | ||
756 | if (freq == 0) | ||
757 | return -EINVAL; | ||
758 | mutex_lock(&rdev->devlist_mtx); | ||
759 | err = rdev_set_freq(rdev, NULL, freq, NL80211_CHAN_NO_HT); | ||
760 | mutex_unlock(&rdev->devlist_mtx); | ||
761 | return err; | ||
762 | } | ||
763 | } | ||
764 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq); | ||
765 | |||
766 | int cfg80211_wext_giwfreq(struct net_device *dev, | ||
767 | struct iw_request_info *info, | ||
768 | struct iw_freq *freq, char *extra) | ||
769 | { | ||
770 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
771 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
772 | |||
773 | switch (wdev->iftype) { | ||
774 | case NL80211_IFTYPE_STATION: | ||
775 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); | ||
776 | case NL80211_IFTYPE_ADHOC: | ||
777 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); | ||
778 | default: | ||
779 | if (!rdev->channel) | ||
780 | return -EINVAL; | ||
781 | freq->m = rdev->channel->center_freq; | ||
782 | freq->e = 6; | ||
783 | return 0; | ||
784 | } | ||
785 | } | ||
786 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq); | ||
787 | |||
748 | int cfg80211_wext_siwtxpower(struct net_device *dev, | 788 | int cfg80211_wext_siwtxpower(struct net_device *dev, |
749 | struct iw_request_info *info, | 789 | struct iw_request_info *info, |
750 | union iwreq_data *data, char *extra) | 790 | union iwreq_data *data, char *extra) |
@@ -827,3 +867,547 @@ int cfg80211_wext_giwtxpower(struct net_device *dev, | |||
827 | return 0; | 867 | return 0; |
828 | } | 868 | } |
829 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); | 869 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); |
870 | |||
871 | static int cfg80211_set_auth_alg(struct wireless_dev *wdev, | ||
872 | s32 auth_alg) | ||
873 | { | ||
874 | int nr_alg = 0; | ||
875 | |||
876 | if (!auth_alg) | ||
877 | return -EINVAL; | ||
878 | |||
879 | if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM | | ||
880 | IW_AUTH_ALG_SHARED_KEY | | ||
881 | IW_AUTH_ALG_LEAP)) | ||
882 | return -EINVAL; | ||
883 | |||
884 | if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) { | ||
885 | nr_alg++; | ||
886 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; | ||
887 | } | ||
888 | |||
889 | if (auth_alg & IW_AUTH_ALG_SHARED_KEY) { | ||
890 | nr_alg++; | ||
891 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY; | ||
892 | } | ||
893 | |||
894 | if (auth_alg & IW_AUTH_ALG_LEAP) { | ||
895 | nr_alg++; | ||
896 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP; | ||
897 | } | ||
898 | |||
899 | if (nr_alg > 1) | ||
900 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | ||
901 | |||
902 | return 0; | ||
903 | } | ||
904 | |||
905 | static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions) | ||
906 | { | ||
907 | wdev->wext.connect.crypto.wpa_versions = 0; | ||
908 | |||
909 | if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA | | ||
910 | IW_AUTH_WPA_VERSION_WPA2| | ||
911 | IW_AUTH_WPA_VERSION_DISABLED)) | ||
912 | return -EINVAL; | ||
913 | |||
914 | if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) && | ||
915 | (wpa_versions & (IW_AUTH_WPA_VERSION_WPA| | ||
916 | IW_AUTH_WPA_VERSION_WPA2))) | ||
917 | return -EINVAL; | ||
918 | |||
919 | if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) | ||
920 | wdev->wext.connect.crypto.wpa_versions &= | ||
921 | ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2); | ||
922 | |||
923 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA) | ||
924 | wdev->wext.connect.crypto.wpa_versions |= | ||
925 | NL80211_WPA_VERSION_1; | ||
926 | |||
927 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2) | ||
928 | wdev->wext.connect.crypto.wpa_versions |= | ||
929 | NL80211_WPA_VERSION_2; | ||
930 | |||
931 | return 0; | ||
932 | } | ||
933 | |||
934 | static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher) | ||
935 | { | ||
936 | wdev->wext.connect.crypto.cipher_group = 0; | ||
937 | |||
938 | if (cipher & IW_AUTH_CIPHER_WEP40) | ||
939 | wdev->wext.connect.crypto.cipher_group = | ||
940 | WLAN_CIPHER_SUITE_WEP40; | ||
941 | else if (cipher & IW_AUTH_CIPHER_WEP104) | ||
942 | wdev->wext.connect.crypto.cipher_group = | ||
943 | WLAN_CIPHER_SUITE_WEP104; | ||
944 | else if (cipher & IW_AUTH_CIPHER_TKIP) | ||
945 | wdev->wext.connect.crypto.cipher_group = | ||
946 | WLAN_CIPHER_SUITE_TKIP; | ||
947 | else if (cipher & IW_AUTH_CIPHER_CCMP) | ||
948 | wdev->wext.connect.crypto.cipher_group = | ||
949 | WLAN_CIPHER_SUITE_CCMP; | ||
950 | else if (cipher & IW_AUTH_CIPHER_AES_CMAC) | ||
951 | wdev->wext.connect.crypto.cipher_group = | ||
952 | WLAN_CIPHER_SUITE_AES_CMAC; | ||
953 | else | ||
954 | return -EINVAL; | ||
955 | |||
956 | return 0; | ||
957 | } | ||
958 | |||
959 | static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher) | ||
960 | { | ||
961 | int nr_ciphers = 0; | ||
962 | u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise; | ||
963 | |||
964 | if (cipher & IW_AUTH_CIPHER_WEP40) { | ||
965 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40; | ||
966 | nr_ciphers++; | ||
967 | } | ||
968 | |||
969 | if (cipher & IW_AUTH_CIPHER_WEP104) { | ||
970 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104; | ||
971 | nr_ciphers++; | ||
972 | } | ||
973 | |||
974 | if (cipher & IW_AUTH_CIPHER_TKIP) { | ||
975 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP; | ||
976 | nr_ciphers++; | ||
977 | } | ||
978 | |||
979 | if (cipher & IW_AUTH_CIPHER_CCMP) { | ||
980 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP; | ||
981 | nr_ciphers++; | ||
982 | } | ||
983 | |||
984 | if (cipher & IW_AUTH_CIPHER_AES_CMAC) { | ||
985 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC; | ||
986 | nr_ciphers++; | ||
987 | } | ||
988 | |||
989 | BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5); | ||
990 | |||
991 | wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers; | ||
992 | |||
993 | return 0; | ||
994 | } | ||
995 | |||
996 | |||
997 | static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt) | ||
998 | { | ||
999 | int nr_akm_suites = 0; | ||
1000 | |||
1001 | if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X | | ||
1002 | IW_AUTH_KEY_MGMT_PSK)) | ||
1003 | return -EINVAL; | ||
1004 | |||
1005 | if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) { | ||
1006 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = | ||
1007 | WLAN_AKM_SUITE_8021X; | ||
1008 | nr_akm_suites++; | ||
1009 | } | ||
1010 | |||
1011 | if (key_mgt & IW_AUTH_KEY_MGMT_PSK) { | ||
1012 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = | ||
1013 | WLAN_AKM_SUITE_PSK; | ||
1014 | nr_akm_suites++; | ||
1015 | } | ||
1016 | |||
1017 | wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites; | ||
1018 | |||
1019 | return 0; | ||
1020 | } | ||
1021 | |||
1022 | int cfg80211_wext_siwauth(struct net_device *dev, | ||
1023 | struct iw_request_info *info, | ||
1024 | struct iw_param *data, char *extra) | ||
1025 | { | ||
1026 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1027 | |||
1028 | if (wdev->iftype != NL80211_IFTYPE_STATION) | ||
1029 | return -EOPNOTSUPP; | ||
1030 | |||
1031 | switch (data->flags & IW_AUTH_INDEX) { | ||
1032 | case IW_AUTH_PRIVACY_INVOKED: | ||
1033 | wdev->wext.connect.privacy = data->value; | ||
1034 | return 0; | ||
1035 | case IW_AUTH_WPA_VERSION: | ||
1036 | return cfg80211_set_wpa_version(wdev, data->value); | ||
1037 | case IW_AUTH_CIPHER_GROUP: | ||
1038 | return cfg80211_set_cipher_group(wdev, data->value); | ||
1039 | case IW_AUTH_KEY_MGMT: | ||
1040 | return cfg80211_set_key_mgt(wdev, data->value); | ||
1041 | case IW_AUTH_CIPHER_PAIRWISE: | ||
1042 | return cfg80211_set_cipher_pairwise(wdev, data->value); | ||
1043 | case IW_AUTH_80211_AUTH_ALG: | ||
1044 | return cfg80211_set_auth_alg(wdev, data->value); | ||
1045 | case IW_AUTH_WPA_ENABLED: | ||
1046 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | ||
1047 | case IW_AUTH_DROP_UNENCRYPTED: | ||
1048 | case IW_AUTH_MFP: | ||
1049 | return 0; | ||
1050 | default: | ||
1051 | return -EOPNOTSUPP; | ||
1052 | } | ||
1053 | } | ||
1054 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth); | ||
1055 | |||
1056 | int cfg80211_wext_giwauth(struct net_device *dev, | ||
1057 | struct iw_request_info *info, | ||
1058 | struct iw_param *data, char *extra) | ||
1059 | { | ||
1060 | /* XXX: what do we need? */ | ||
1061 | |||
1062 | return -EOPNOTSUPP; | ||
1063 | } | ||
1064 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth); | ||
1065 | |||
1066 | int cfg80211_wext_siwpower(struct net_device *dev, | ||
1067 | struct iw_request_info *info, | ||
1068 | struct iw_param *wrq, char *extra) | ||
1069 | { | ||
1070 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1071 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
1072 | bool ps = wdev->wext.ps; | ||
1073 | int timeout = wdev->wext.ps_timeout; | ||
1074 | int err; | ||
1075 | |||
1076 | if (wdev->iftype != NL80211_IFTYPE_STATION) | ||
1077 | return -EINVAL; | ||
1078 | |||
1079 | if (!rdev->ops->set_power_mgmt) | ||
1080 | return -EOPNOTSUPP; | ||
1081 | |||
1082 | if (wrq->disabled) { | ||
1083 | ps = false; | ||
1084 | } else { | ||
1085 | switch (wrq->flags & IW_POWER_MODE) { | ||
1086 | case IW_POWER_ON: /* If not specified */ | ||
1087 | case IW_POWER_MODE: /* If set all mask */ | ||
1088 | case IW_POWER_ALL_R: /* If explicitely state all */ | ||
1089 | ps = true; | ||
1090 | break; | ||
1091 | default: /* Otherwise we ignore */ | ||
1092 | return -EINVAL; | ||
1093 | } | ||
1094 | |||
1095 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) | ||
1096 | return -EINVAL; | ||
1097 | |||
1098 | if (wrq->flags & IW_POWER_TIMEOUT) | ||
1099 | timeout = wrq->value / 1000; | ||
1100 | } | ||
1101 | |||
1102 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout); | ||
1103 | if (err) | ||
1104 | return err; | ||
1105 | |||
1106 | wdev->wext.ps = ps; | ||
1107 | wdev->wext.ps_timeout = timeout; | ||
1108 | |||
1109 | return 0; | ||
1110 | |||
1111 | } | ||
1112 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower); | ||
1113 | |||
1114 | int cfg80211_wext_giwpower(struct net_device *dev, | ||
1115 | struct iw_request_info *info, | ||
1116 | struct iw_param *wrq, char *extra) | ||
1117 | { | ||
1118 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1119 | |||
1120 | wrq->disabled = !wdev->wext.ps; | ||
1121 | |||
1122 | return 0; | ||
1123 | } | ||
1124 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower); | ||
1125 | |||
1126 | static int cfg80211_wds_wext_siwap(struct net_device *dev, | ||
1127 | struct iw_request_info *info, | ||
1128 | struct sockaddr *addr, char *extra) | ||
1129 | { | ||
1130 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1131 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
1132 | int err; | ||
1133 | |||
1134 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) | ||
1135 | return -EINVAL; | ||
1136 | |||
1137 | if (addr->sa_family != ARPHRD_ETHER) | ||
1138 | return -EINVAL; | ||
1139 | |||
1140 | if (netif_running(dev)) | ||
1141 | return -EBUSY; | ||
1142 | |||
1143 | if (!rdev->ops->set_wds_peer) | ||
1144 | return -EOPNOTSUPP; | ||
1145 | |||
1146 | err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data); | ||
1147 | if (err) | ||
1148 | return err; | ||
1149 | |||
1150 | memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN); | ||
1151 | |||
1152 | return 0; | ||
1153 | } | ||
1154 | |||
1155 | static int cfg80211_wds_wext_giwap(struct net_device *dev, | ||
1156 | struct iw_request_info *info, | ||
1157 | struct sockaddr *addr, char *extra) | ||
1158 | { | ||
1159 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1160 | |||
1161 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) | ||
1162 | return -EINVAL; | ||
1163 | |||
1164 | addr->sa_family = ARPHRD_ETHER; | ||
1165 | memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN); | ||
1166 | |||
1167 | return 0; | ||
1168 | } | ||
1169 | |||
1170 | int cfg80211_wext_siwrate(struct net_device *dev, | ||
1171 | struct iw_request_info *info, | ||
1172 | struct iw_param *rate, char *extra) | ||
1173 | { | ||
1174 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1175 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
1176 | struct cfg80211_bitrate_mask mask; | ||
1177 | |||
1178 | if (!rdev->ops->set_bitrate_mask) | ||
1179 | return -EOPNOTSUPP; | ||
1180 | |||
1181 | mask.fixed = 0; | ||
1182 | mask.maxrate = 0; | ||
1183 | |||
1184 | if (rate->value < 0) { | ||
1185 | /* nothing */ | ||
1186 | } else if (rate->fixed) { | ||
1187 | mask.fixed = rate->value / 1000; /* kbps */ | ||
1188 | } else { | ||
1189 | mask.maxrate = rate->value / 1000; /* kbps */ | ||
1190 | } | ||
1191 | |||
1192 | return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask); | ||
1193 | } | ||
1194 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate); | ||
1195 | |||
1196 | int cfg80211_wext_giwrate(struct net_device *dev, | ||
1197 | struct iw_request_info *info, | ||
1198 | struct iw_param *rate, char *extra) | ||
1199 | { | ||
1200 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1201 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
1202 | /* we are under RTNL - globally locked - so can use a static struct */ | ||
1203 | static struct station_info sinfo; | ||
1204 | u8 addr[ETH_ALEN]; | ||
1205 | int err; | ||
1206 | |||
1207 | if (wdev->iftype != NL80211_IFTYPE_STATION) | ||
1208 | return -EOPNOTSUPP; | ||
1209 | |||
1210 | if (!rdev->ops->get_station) | ||
1211 | return -EOPNOTSUPP; | ||
1212 | |||
1213 | err = 0; | ||
1214 | wdev_lock(wdev); | ||
1215 | if (wdev->current_bss) | ||
1216 | memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN); | ||
1217 | else | ||
1218 | err = -EOPNOTSUPP; | ||
1219 | wdev_unlock(wdev); | ||
1220 | if (err) | ||
1221 | return err; | ||
1222 | |||
1223 | err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo); | ||
1224 | if (err) | ||
1225 | return err; | ||
1226 | |||
1227 | if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) | ||
1228 | return -EOPNOTSUPP; | ||
1229 | |||
1230 | rate->value = 0; | ||
1231 | |||
1232 | if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS)) | ||
1233 | rate->value = 100000 * sinfo.txrate.legacy; | ||
1234 | |||
1235 | return 0; | ||
1236 | } | ||
1237 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate); | ||
1238 | |||
1239 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ | ||
1240 | struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev) | ||
1241 | { | ||
1242 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1243 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | ||
1244 | /* we are under RTNL - globally locked - so can use static structs */ | ||
1245 | static struct iw_statistics wstats; | ||
1246 | static struct station_info sinfo; | ||
1247 | u8 bssid[ETH_ALEN]; | ||
1248 | |||
1249 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) | ||
1250 | return NULL; | ||
1251 | |||
1252 | if (!rdev->ops->get_station) | ||
1253 | return NULL; | ||
1254 | |||
1255 | /* Grab BSSID of current BSS, if any */ | ||
1256 | wdev_lock(wdev); | ||
1257 | if (!wdev->current_bss) { | ||
1258 | wdev_unlock(wdev); | ||
1259 | return NULL; | ||
1260 | } | ||
1261 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); | ||
1262 | wdev_unlock(wdev); | ||
1263 | |||
1264 | if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo)) | ||
1265 | return NULL; | ||
1266 | |||
1267 | memset(&wstats, 0, sizeof(wstats)); | ||
1268 | |||
1269 | switch (rdev->wiphy.signal_type) { | ||
1270 | case CFG80211_SIGNAL_TYPE_MBM: | ||
1271 | if (sinfo.filled & STATION_INFO_SIGNAL) { | ||
1272 | int sig = sinfo.signal; | ||
1273 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; | ||
1274 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; | ||
1275 | wstats.qual.updated |= IW_QUAL_DBM; | ||
1276 | wstats.qual.level = sig; | ||
1277 | if (sig < -110) | ||
1278 | sig = -110; | ||
1279 | else if (sig > -40) | ||
1280 | sig = -40; | ||
1281 | wstats.qual.qual = sig + 110; | ||
1282 | break; | ||
1283 | } | ||
1284 | case CFG80211_SIGNAL_TYPE_UNSPEC: | ||
1285 | if (sinfo.filled & STATION_INFO_SIGNAL) { | ||
1286 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; | ||
1287 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; | ||
1288 | wstats.qual.level = sinfo.signal; | ||
1289 | wstats.qual.qual = sinfo.signal; | ||
1290 | break; | ||
1291 | } | ||
1292 | default: | ||
1293 | wstats.qual.updated |= IW_QUAL_LEVEL_INVALID; | ||
1294 | wstats.qual.updated |= IW_QUAL_QUAL_INVALID; | ||
1295 | } | ||
1296 | |||
1297 | wstats.qual.updated |= IW_QUAL_NOISE_INVALID; | ||
1298 | |||
1299 | return &wstats; | ||
1300 | } | ||
1301 | EXPORT_SYMBOL_GPL(cfg80211_wireless_stats); | ||
1302 | |||
1303 | int cfg80211_wext_siwap(struct net_device *dev, | ||
1304 | struct iw_request_info *info, | ||
1305 | struct sockaddr *ap_addr, char *extra) | ||
1306 | { | ||
1307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1308 | |||
1309 | switch (wdev->iftype) { | ||
1310 | case NL80211_IFTYPE_ADHOC: | ||
1311 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); | ||
1312 | case NL80211_IFTYPE_STATION: | ||
1313 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); | ||
1314 | case NL80211_IFTYPE_WDS: | ||
1315 | return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra); | ||
1316 | default: | ||
1317 | return -EOPNOTSUPP; | ||
1318 | } | ||
1319 | } | ||
1320 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwap); | ||
1321 | |||
1322 | int cfg80211_wext_giwap(struct net_device *dev, | ||
1323 | struct iw_request_info *info, | ||
1324 | struct sockaddr *ap_addr, char *extra) | ||
1325 | { | ||
1326 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1327 | |||
1328 | switch (wdev->iftype) { | ||
1329 | case NL80211_IFTYPE_ADHOC: | ||
1330 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); | ||
1331 | case NL80211_IFTYPE_STATION: | ||
1332 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); | ||
1333 | case NL80211_IFTYPE_WDS: | ||
1334 | return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra); | ||
1335 | default: | ||
1336 | return -EOPNOTSUPP; | ||
1337 | } | ||
1338 | } | ||
1339 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwap); | ||
1340 | |||
1341 | int cfg80211_wext_siwessid(struct net_device *dev, | ||
1342 | struct iw_request_info *info, | ||
1343 | struct iw_point *data, char *ssid) | ||
1344 | { | ||
1345 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1346 | |||
1347 | switch (wdev->iftype) { | ||
1348 | case NL80211_IFTYPE_ADHOC: | ||
1349 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); | ||
1350 | case NL80211_IFTYPE_STATION: | ||
1351 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); | ||
1352 | default: | ||
1353 | return -EOPNOTSUPP; | ||
1354 | } | ||
1355 | } | ||
1356 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid); | ||
1357 | |||
1358 | int cfg80211_wext_giwessid(struct net_device *dev, | ||
1359 | struct iw_request_info *info, | ||
1360 | struct iw_point *data, char *ssid) | ||
1361 | { | ||
1362 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1363 | |||
1364 | switch (wdev->iftype) { | ||
1365 | case NL80211_IFTYPE_ADHOC: | ||
1366 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); | ||
1367 | case NL80211_IFTYPE_STATION: | ||
1368 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); | ||
1369 | default: | ||
1370 | return -EOPNOTSUPP; | ||
1371 | } | ||
1372 | } | ||
1373 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid); | ||
1374 | |||
1375 | static const iw_handler cfg80211_handlers[] = { | ||
1376 | [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname, | ||
1377 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq, | ||
1378 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq, | ||
1379 | [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode, | ||
1380 | [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode, | ||
1381 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange, | ||
1382 | [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap, | ||
1383 | [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap, | ||
1384 | [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme, | ||
1385 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan, | ||
1386 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan, | ||
1387 | [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid, | ||
1388 | [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid, | ||
1389 | [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate, | ||
1390 | [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate, | ||
1391 | [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts, | ||
1392 | [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts, | ||
1393 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag, | ||
1394 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag, | ||
1395 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower, | ||
1396 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower, | ||
1397 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry, | ||
1398 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry, | ||
1399 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode, | ||
1400 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode, | ||
1401 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower, | ||
1402 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower, | ||
1403 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie, | ||
1404 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth, | ||
1405 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth, | ||
1406 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext, | ||
1407 | }; | ||
1408 | |||
1409 | const struct iw_handler_def cfg80211_wext_handler = { | ||
1410 | .num_standard = ARRAY_SIZE(cfg80211_handlers), | ||
1411 | .standard = cfg80211_handlers, | ||
1412 | .get_wireless_stats = cfg80211_wireless_stats, | ||
1413 | }; | ||