aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/mlme.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/wireless/mlme.c')
-rw-r--r--net/wireless/mlme.c225
1 files changed, 160 insertions, 65 deletions
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index d1a3fb99fdf2..26838d903b9a 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -149,7 +149,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
149 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; 149 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
150 const u8 *bssid = mgmt->bssid; 150 const u8 *bssid = mgmt->bssid;
151 int i; 151 int i;
152 bool found = false; 152 bool found = false, was_current = false;
153 153
154 ASSERT_WDEV_LOCK(wdev); 154 ASSERT_WDEV_LOCK(wdev);
155 155
@@ -159,6 +159,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
159 cfg80211_put_bss(&wdev->current_bss->pub); 159 cfg80211_put_bss(&wdev->current_bss->pub);
160 wdev->current_bss = NULL; 160 wdev->current_bss = NULL;
161 found = true; 161 found = true;
162 was_current = true;
162 } else for (i = 0; i < MAX_AUTH_BSSES; i++) { 163 } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
163 if (wdev->auth_bsses[i] && 164 if (wdev->auth_bsses[i] &&
164 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { 165 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
@@ -183,7 +184,7 @@ void __cfg80211_send_deauth(struct net_device *dev,
183 184
184 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); 185 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
185 186
186 if (wdev->sme_state == CFG80211_SME_CONNECTED) { 187 if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
187 u16 reason_code; 188 u16 reason_code;
188 bool from_ap; 189 bool from_ap;
189 190
@@ -747,31 +748,53 @@ void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
747} 748}
748EXPORT_SYMBOL(cfg80211_new_sta); 749EXPORT_SYMBOL(cfg80211_new_sta);
749 750
750struct cfg80211_action_registration { 751struct cfg80211_mgmt_registration {
751 struct list_head list; 752 struct list_head list;
752 753
753 u32 nlpid; 754 u32 nlpid;
754 755
755 int match_len; 756 int match_len;
756 757
758 __le16 frame_type;
759
757 u8 match[]; 760 u8 match[];
758}; 761};
759 762
760int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid, 763int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
761 const u8 *match_data, int match_len) 764 u16 frame_type, const u8 *match_data,
765 int match_len)
762{ 766{
763 struct cfg80211_action_registration *reg, *nreg; 767 struct wiphy *wiphy = wdev->wiphy;
768 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
769 struct cfg80211_mgmt_registration *reg, *nreg;
764 int err = 0; 770 int err = 0;
771 u16 mgmt_type;
772
773 if (!wdev->wiphy->mgmt_stypes)
774 return -EOPNOTSUPP;
775
776 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
777 return -EINVAL;
778
779 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
780 return -EINVAL;
781
782 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
783 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
784 return -EINVAL;
765 785
766 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); 786 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
767 if (!nreg) 787 if (!nreg)
768 return -ENOMEM; 788 return -ENOMEM;
769 789
770 spin_lock_bh(&wdev->action_registrations_lock); 790 spin_lock_bh(&wdev->mgmt_registrations_lock);
771 791
772 list_for_each_entry(reg, &wdev->action_registrations, list) { 792 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
773 int mlen = min(match_len, reg->match_len); 793 int mlen = min(match_len, reg->match_len);
774 794
795 if (frame_type != le16_to_cpu(reg->frame_type))
796 continue;
797
775 if (memcmp(reg->match, match_data, mlen) == 0) { 798 if (memcmp(reg->match, match_data, mlen) == 0) {
776 err = -EALREADY; 799 err = -EALREADY;
777 break; 800 break;
@@ -786,140 +809,212 @@ int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid,
786 memcpy(nreg->match, match_data, match_len); 809 memcpy(nreg->match, match_data, match_len);
787 nreg->match_len = match_len; 810 nreg->match_len = match_len;
788 nreg->nlpid = snd_pid; 811 nreg->nlpid = snd_pid;
789 list_add(&nreg->list, &wdev->action_registrations); 812 nreg->frame_type = cpu_to_le16(frame_type);
813 list_add(&nreg->list, &wdev->mgmt_registrations);
814
815 if (rdev->ops->mgmt_frame_register)
816 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
817 frame_type, true);
790 818
791 out: 819 out:
792 spin_unlock_bh(&wdev->action_registrations_lock); 820 spin_unlock_bh(&wdev->mgmt_registrations_lock);
821
793 return err; 822 return err;
794} 823}
795 824
796void cfg80211_mlme_unregister_actions(struct wireless_dev *wdev, u32 nlpid) 825void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid)
797{ 826{
798 struct cfg80211_action_registration *reg, *tmp; 827 struct wiphy *wiphy = wdev->wiphy;
828 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
829 struct cfg80211_mgmt_registration *reg, *tmp;
799 830
800 spin_lock_bh(&wdev->action_registrations_lock); 831 spin_lock_bh(&wdev->mgmt_registrations_lock);
801 832
802 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) { 833 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
803 if (reg->nlpid == nlpid) { 834 if (reg->nlpid != nlpid)
804 list_del(&reg->list); 835 continue;
805 kfree(reg); 836
837 if (rdev->ops->mgmt_frame_register) {
838 u16 frame_type = le16_to_cpu(reg->frame_type);
839
840 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
841 frame_type, false);
806 } 842 }
843
844 list_del(&reg->list);
845 kfree(reg);
807 } 846 }
808 847
809 spin_unlock_bh(&wdev->action_registrations_lock); 848 spin_unlock_bh(&wdev->mgmt_registrations_lock);
810} 849}
811 850
812void cfg80211_mlme_purge_actions(struct wireless_dev *wdev) 851void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
813{ 852{
814 struct cfg80211_action_registration *reg, *tmp; 853 struct cfg80211_mgmt_registration *reg, *tmp;
815 854
816 spin_lock_bh(&wdev->action_registrations_lock); 855 spin_lock_bh(&wdev->mgmt_registrations_lock);
817 856
818 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) { 857 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
819 list_del(&reg->list); 858 list_del(&reg->list);
820 kfree(reg); 859 kfree(reg);
821 } 860 }
822 861
823 spin_unlock_bh(&wdev->action_registrations_lock); 862 spin_unlock_bh(&wdev->mgmt_registrations_lock);
824} 863}
825 864
826int cfg80211_mlme_action(struct cfg80211_registered_device *rdev, 865int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
827 struct net_device *dev, 866 struct net_device *dev,
828 struct ieee80211_channel *chan, 867 struct ieee80211_channel *chan,
829 enum nl80211_channel_type channel_type, 868 enum nl80211_channel_type channel_type,
830 bool channel_type_valid, 869 bool channel_type_valid,
831 const u8 *buf, size_t len, u64 *cookie) 870 const u8 *buf, size_t len, u64 *cookie)
832{ 871{
833 struct wireless_dev *wdev = dev->ieee80211_ptr; 872 struct wireless_dev *wdev = dev->ieee80211_ptr;
834 const struct ieee80211_mgmt *mgmt; 873 const struct ieee80211_mgmt *mgmt;
874 u16 stype;
835 875
836 if (rdev->ops->action == NULL) 876 if (!wdev->wiphy->mgmt_stypes)
837 return -EOPNOTSUPP; 877 return -EOPNOTSUPP;
878
879 if (!rdev->ops->mgmt_tx)
880 return -EOPNOTSUPP;
881
838 if (len < 24 + 1) 882 if (len < 24 + 1)
839 return -EINVAL; 883 return -EINVAL;
840 884
841 mgmt = (const struct ieee80211_mgmt *) buf; 885 mgmt = (const struct ieee80211_mgmt *) buf;
842 if (!ieee80211_is_action(mgmt->frame_control)) 886
887 if (!ieee80211_is_mgmt(mgmt->frame_control))
843 return -EINVAL; 888 return -EINVAL;
844 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { 889
845 /* Verify that we are associated with the destination AP */ 890 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
891 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
892 return -EINVAL;
893
894 if (ieee80211_is_action(mgmt->frame_control) &&
895 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
896 int err = 0;
897
846 wdev_lock(wdev); 898 wdev_lock(wdev);
847 899
848 if (!wdev->current_bss || 900 switch (wdev->iftype) {
849 memcmp(wdev->current_bss->pub.bssid, mgmt->bssid, 901 case NL80211_IFTYPE_ADHOC:
850 ETH_ALEN) != 0 || 902 case NL80211_IFTYPE_STATION:
851 (wdev->iftype == NL80211_IFTYPE_STATION && 903 case NL80211_IFTYPE_P2P_CLIENT:
852 memcmp(wdev->current_bss->pub.bssid, mgmt->da, 904 if (!wdev->current_bss) {
853 ETH_ALEN) != 0)) { 905 err = -ENOTCONN;
854 wdev_unlock(wdev); 906 break;
855 return -ENOTCONN; 907 }
856 } 908
909 if (memcmp(wdev->current_bss->pub.bssid,
910 mgmt->bssid, ETH_ALEN)) {
911 err = -ENOTCONN;
912 break;
913 }
914
915 /*
916 * check for IBSS DA must be done by driver as
917 * cfg80211 doesn't track the stations
918 */
919 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
920 break;
857 921
922 /* for station, check that DA is the AP */
923 if (memcmp(wdev->current_bss->pub.bssid,
924 mgmt->da, ETH_ALEN)) {
925 err = -ENOTCONN;
926 break;
927 }
928 break;
929 case NL80211_IFTYPE_AP:
930 case NL80211_IFTYPE_P2P_GO:
931 case NL80211_IFTYPE_AP_VLAN:
932 if (memcmp(mgmt->bssid, dev->dev_addr, ETH_ALEN))
933 err = -EINVAL;
934 break;
935 default:
936 err = -EOPNOTSUPP;
937 break;
938 }
858 wdev_unlock(wdev); 939 wdev_unlock(wdev);
940
941 if (err)
942 return err;
859 } 943 }
860 944
861 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0) 945 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0)
862 return -EINVAL; 946 return -EINVAL;
863 947
864 /* Transmit the Action frame as requested by user space */ 948 /* Transmit the Action frame as requested by user space */
865 return rdev->ops->action(&rdev->wiphy, dev, chan, channel_type, 949 return rdev->ops->mgmt_tx(&rdev->wiphy, dev, chan, channel_type,
866 channel_type_valid, buf, len, cookie); 950 channel_type_valid, buf, len, cookie);
867} 951}
868 952
869bool cfg80211_rx_action(struct net_device *dev, int freq, const u8 *buf, 953bool cfg80211_rx_mgmt(struct net_device *dev, int freq, const u8 *buf,
870 size_t len, gfp_t gfp) 954 size_t len, gfp_t gfp)
871{ 955{
872 struct wireless_dev *wdev = dev->ieee80211_ptr; 956 struct wireless_dev *wdev = dev->ieee80211_ptr;
873 struct wiphy *wiphy = wdev->wiphy; 957 struct wiphy *wiphy = wdev->wiphy;
874 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 958 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
875 struct cfg80211_action_registration *reg; 959 struct cfg80211_mgmt_registration *reg;
876 const u8 *action_data; 960 const struct ieee80211_txrx_stypes *stypes =
877 int action_data_len; 961 &wiphy->mgmt_stypes[wdev->iftype];
962 struct ieee80211_mgmt *mgmt = (void *)buf;
963 const u8 *data;
964 int data_len;
878 bool result = false; 965 bool result = false;
966 __le16 ftype = mgmt->frame_control &
967 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
968 u16 stype;
879 969
880 /* frame length - min size excluding category */ 970 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
881 action_data_len = len - (IEEE80211_MIN_ACTION_SIZE - 1);
882 971
883 /* action data starts with category */ 972 if (!(stypes->rx & BIT(stype)))
884 action_data = buf + IEEE80211_MIN_ACTION_SIZE - 1; 973 return false;
885 974
886 spin_lock_bh(&wdev->action_registrations_lock); 975 data = buf + ieee80211_hdrlen(mgmt->frame_control);
976 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
977
978 spin_lock_bh(&wdev->mgmt_registrations_lock);
979
980 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
981 if (reg->frame_type != ftype)
982 continue;
887 983
888 list_for_each_entry(reg, &wdev->action_registrations, list) { 984 if (reg->match_len > data_len)
889 if (reg->match_len > action_data_len)
890 continue; 985 continue;
891 986
892 if (memcmp(reg->match, action_data, reg->match_len)) 987 if (memcmp(reg->match, data, reg->match_len))
893 continue; 988 continue;
894 989
895 /* found match! */ 990 /* found match! */
896 991
897 /* Indicate the received Action frame to user space */ 992 /* Indicate the received Action frame to user space */
898 if (nl80211_send_action(rdev, dev, reg->nlpid, freq, 993 if (nl80211_send_mgmt(rdev, dev, reg->nlpid, freq,
899 buf, len, gfp)) 994 buf, len, gfp))
900 continue; 995 continue;
901 996
902 result = true; 997 result = true;
903 break; 998 break;
904 } 999 }
905 1000
906 spin_unlock_bh(&wdev->action_registrations_lock); 1001 spin_unlock_bh(&wdev->mgmt_registrations_lock);
907 1002
908 return result; 1003 return result;
909} 1004}
910EXPORT_SYMBOL(cfg80211_rx_action); 1005EXPORT_SYMBOL(cfg80211_rx_mgmt);
911 1006
912void cfg80211_action_tx_status(struct net_device *dev, u64 cookie, 1007void cfg80211_mgmt_tx_status(struct net_device *dev, u64 cookie,
913 const u8 *buf, size_t len, bool ack, gfp_t gfp) 1008 const u8 *buf, size_t len, bool ack, gfp_t gfp)
914{ 1009{
915 struct wireless_dev *wdev = dev->ieee80211_ptr; 1010 struct wireless_dev *wdev = dev->ieee80211_ptr;
916 struct wiphy *wiphy = wdev->wiphy; 1011 struct wiphy *wiphy = wdev->wiphy;
917 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 1012 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
918 1013
919 /* Indicate TX status of the Action frame to user space */ 1014 /* Indicate TX status of the Action frame to user space */
920 nl80211_send_action_tx_status(rdev, dev, cookie, buf, len, ack, gfp); 1015 nl80211_send_mgmt_tx_status(rdev, dev, cookie, buf, len, ack, gfp);
921} 1016}
922EXPORT_SYMBOL(cfg80211_action_tx_status); 1017EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
923 1018
924void cfg80211_cqm_rssi_notify(struct net_device *dev, 1019void cfg80211_cqm_rssi_notify(struct net_device *dev,
925 enum nl80211_cqm_rssi_threshold_event rssi_event, 1020 enum nl80211_cqm_rssi_threshold_event rssi_event,