aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/wext-compat.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2009-05-11 07:54:58 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-05-13 15:44:32 -0400
commit08645126dd24872c2e27014f93968f7312e29176 (patch)
tree2011cb3cb2f70d35278ef3b39ea696a058fb7b29 /net/wireless/wext-compat.c
parent7be69c0b9aa93ef655db4d46e5654996489d62f5 (diff)
cfg80211: implement wext key handling
Move key handling wireless extension ioctls from mac80211 to cfg80211 so that all drivers that implement the cfg80211 operations get wext compatibility. Note that this drops the SIOCGIWENCODE ioctl support for getting IW_ENCODE_RESTRICTED/IW_ENCODE_OPEN. This means that iwconfig will no longer report "Security mode:open" or "Security mode:restricted" for mac80211. However, what we displayed there (the authentication algo used) was actually wrong -- linux/wireless.h states that this setting is meant to differentiate between "Refuse non-encoded packets" and "Accept non-encoded packets". (Combined with "cfg80211: fix a couple of bugs with key ioctls". -- JWL) Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/wireless/wext-compat.c')
-rw-r--r--net/wireless/wext-compat.c257
1 files changed, 256 insertions, 1 deletions
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index abf6b0a047d8..ffc98a8d6e5c 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -5,12 +5,13 @@
5 * into cfg80211, when that happens all the exports here go away and 5 * into cfg80211, when that happens all the exports here go away and
6 * we directly assign the wireless handlers of wireless interfaces. 6 * we directly assign the wireless handlers of wireless interfaces.
7 * 7 *
8 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> 8 * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
9 */ 9 */
10 10
11#include <linux/wireless.h> 11#include <linux/wireless.h>
12#include <linux/nl80211.h> 12#include <linux/nl80211.h>
13#include <linux/if_arp.h> 13#include <linux/if_arp.h>
14#include <linux/etherdevice.h>
14#include <net/iw_handler.h> 15#include <net/iw_handler.h>
15#include <net/cfg80211.h> 16#include <net/cfg80211.h>
16#include "core.h" 17#include "core.h"
@@ -477,3 +478,257 @@ int cfg80211_wext_giwretry(struct net_device *dev,
477 return 0; 478 return 0;
478} 479}
479EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); 480EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
481
482static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
483 struct net_device *dev, const u8 *addr,
484 bool remove, bool tx_key, int idx,
485 struct key_params *params)
486{
487 struct wireless_dev *wdev = dev->ieee80211_ptr;
488 int err;
489
490 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
491 if (!rdev->ops->set_default_mgmt_key)
492 return -EOPNOTSUPP;
493
494 if (idx < 4 || idx > 5)
495 return -EINVAL;
496 } else if (idx < 0 || idx > 3)
497 return -EINVAL;
498
499 if (remove) {
500 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
501 if (!err) {
502 if (idx == wdev->wext.default_key)
503 wdev->wext.default_key = -1;
504 else if (idx == wdev->wext.default_mgmt_key)
505 wdev->wext.default_mgmt_key = -1;
506 }
507 return err;
508 } else {
509 if (addr)
510 tx_key = false;
511
512 if (cfg80211_validate_key_settings(params, idx, addr))
513 return -EINVAL;
514
515 err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params);
516 if (err)
517 return err;
518
519 if (tx_key || (!addr && wdev->wext.default_key == -1)) {
520 err = rdev->ops->set_default_key(&rdev->wiphy,
521 dev, idx);
522 if (!err)
523 wdev->wext.default_key = idx;
524 return err;
525 }
526
527 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
528 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
529 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
530 dev, idx);
531 if (!err)
532 wdev->wext.default_mgmt_key = idx;
533 return err;
534 }
535
536 return 0;
537 }
538}
539
540int cfg80211_wext_siwencode(struct net_device *dev,
541 struct iw_request_info *info,
542 struct iw_point *erq, char *keybuf)
543{
544 struct wireless_dev *wdev = dev->ieee80211_ptr;
545 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
546 int idx, err;
547 bool remove = false;
548 struct key_params params;
549
550 /* no use -- only MFP (set_default_mgmt_key) is optional */
551 if (!rdev->ops->del_key ||
552 !rdev->ops->add_key ||
553 !rdev->ops->set_default_key)
554 return -EOPNOTSUPP;
555
556 idx = erq->flags & IW_ENCODE_INDEX;
557 if (idx == 0) {
558 idx = wdev->wext.default_key;
559 if (idx < 0)
560 idx = 0;
561 } else if (idx < 1 || idx > 4)
562 return -EINVAL;
563 else
564 idx--;
565
566 if (erq->flags & IW_ENCODE_DISABLED)
567 remove = true;
568 else if (erq->length == 0) {
569 /* No key data - just set the default TX key index */
570 err = rdev->ops->set_default_key(&rdev->wiphy, dev, idx);
571 if (!err)
572 wdev->wext.default_key = idx;
573 return err;
574 }
575
576 memset(&params, 0, sizeof(params));
577 params.key = keybuf;
578 params.key_len = erq->length;
579 if (erq->length == 5)
580 params.cipher = WLAN_CIPHER_SUITE_WEP40;
581 else if (erq->length == 13)
582 params.cipher = WLAN_CIPHER_SUITE_WEP104;
583 else if (!remove)
584 return -EINVAL;
585
586 return cfg80211_set_encryption(rdev, dev, NULL, remove,
587 wdev->wext.default_key == -1,
588 idx, &params);
589}
590EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
591
592int cfg80211_wext_siwencodeext(struct net_device *dev,
593 struct iw_request_info *info,
594 struct iw_point *erq, char *extra)
595{
596 struct wireless_dev *wdev = dev->ieee80211_ptr;
597 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
598 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
599 const u8 *addr;
600 int idx;
601 bool remove = false;
602 struct key_params params;
603 u32 cipher;
604
605 /* no use -- only MFP (set_default_mgmt_key) is optional */
606 if (!rdev->ops->del_key ||
607 !rdev->ops->add_key ||
608 !rdev->ops->set_default_key)
609 return -EOPNOTSUPP;
610
611 switch (ext->alg) {
612 case IW_ENCODE_ALG_NONE:
613 remove = true;
614 cipher = 0;
615 break;
616 case IW_ENCODE_ALG_WEP:
617 if (ext->key_len == 5)
618 cipher = WLAN_CIPHER_SUITE_WEP40;
619 else if (ext->key_len == 13)
620 cipher = WLAN_CIPHER_SUITE_WEP104;
621 else
622 return -EINVAL;
623 break;
624 case IW_ENCODE_ALG_TKIP:
625 cipher = WLAN_CIPHER_SUITE_TKIP;
626 break;
627 case IW_ENCODE_ALG_CCMP:
628 cipher = WLAN_CIPHER_SUITE_CCMP;
629 break;
630 case IW_ENCODE_ALG_AES_CMAC:
631 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
632 break;
633 default:
634 return -EOPNOTSUPP;
635 }
636
637 if (erq->flags & IW_ENCODE_DISABLED)
638 remove = true;
639
640 idx = erq->flags & IW_ENCODE_INDEX;
641 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
642 if (idx < 4 || idx > 5) {
643 idx = wdev->wext.default_mgmt_key;
644 if (idx < 0)
645 return -EINVAL;
646 } else
647 idx--;
648 } else {
649 if (idx < 1 || idx > 4) {
650 idx = wdev->wext.default_key;
651 if (idx < 0)
652 return -EINVAL;
653 } else
654 idx--;
655 }
656
657 addr = ext->addr.sa_data;
658 if (is_broadcast_ether_addr(addr))
659 addr = NULL;
660
661 memset(&params, 0, sizeof(params));
662 params.key = ext->key;
663 params.key_len = ext->key_len;
664 params.cipher = cipher;
665
666 return cfg80211_set_encryption(
667 rdev, dev, addr, remove,
668 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
669 idx, &params);
670}
671EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
672
673struct giwencode_cookie {
674 size_t buflen;
675 char *keybuf;
676};
677
678static void giwencode_get_key_cb(void *cookie, struct key_params *params)
679{
680 struct giwencode_cookie *data = cookie;
681
682 if (!params->key) {
683 data->buflen = 0;
684 return;
685 }
686
687 data->buflen = min_t(size_t, data->buflen, params->key_len);
688 memcpy(data->keybuf, params->key, data->buflen);
689}
690
691int cfg80211_wext_giwencode(struct net_device *dev,
692 struct iw_request_info *info,
693 struct iw_point *erq, char *keybuf)
694{
695 struct wireless_dev *wdev = dev->ieee80211_ptr;
696 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
697 int idx, err;
698 struct giwencode_cookie data = {
699 .keybuf = keybuf,
700 .buflen = erq->length,
701 };
702
703 if (!rdev->ops->get_key)
704 return -EOPNOTSUPP;
705
706 idx = erq->flags & IW_ENCODE_INDEX;
707 if (idx == 0) {
708 idx = wdev->wext.default_key;
709 if (idx < 0)
710 idx = 0;
711 } else if (idx < 1 || idx > 4)
712 return -EINVAL;
713 else
714 idx--;
715
716 erq->flags = idx + 1;
717
718 err = rdev->ops->get_key(&rdev->wiphy, dev, idx, NULL, &data,
719 giwencode_get_key_cb);
720 if (!err) {
721 erq->length = data.buflen;
722 erq->flags |= IW_ENCODE_ENABLED;
723 return 0;
724 }
725
726 if (err == -ENOENT) {
727 erq->flags |= IW_ENCODE_DISABLED;
728 erq->length = 0;
729 return 0;
730 }
731
732 return err;
733}
734EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);