Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cfg80211 MLME SAP interface |
| 3 | * |
| 4 | * Copyright (c) 2009, Jouni Malinen <j@w1.fi> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/module.h> |
Felix Fietkau | c6fb08a | 2012-03-18 22:58:04 +0100 | [diff] [blame] | 9 | #include <linux/etherdevice.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/nl80211.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 13 | #include <linux/wireless.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 15 | #include <net/iw_handler.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16 | #include "core.h" |
| 17 | #include "nl80211.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 18 | #include "rdev-ops.h" |
| 19 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 20 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 21 | void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 22 | const u8 *buf, size_t len, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 23 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 24 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 25 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 26 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 27 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 28 | u8 *ie = mgmt->u.assoc_resp.variable; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 29 | int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 30 | u16 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 31 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 32 | trace_cfg80211_send_rx_assoc(dev, bss); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 33 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 34 | /* |
| 35 | * This is a bit of a hack, we don't notify userspace of |
| 36 | * a (re-)association reply if we tried to send a reassoc |
| 37 | * and got a reject -- we only try again with an assoc |
| 38 | * frame instead of reassoc. |
| 39 | */ |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 40 | if (cfg80211_sme_rx_assoc_resp(wdev, status_code)) { |
Johannes Berg | f1940c5 | 2013-06-19 13:21:15 +0200 | [diff] [blame] | 41 | cfg80211_unhold_bss(bss_from_pub(bss)); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 42 | cfg80211_put_bss(wiphy, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 43 | return; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 44 | } |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 45 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 46 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL, uapsd_queues); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 47 | /* update current_bss etc., consumes the bss reference */ |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 48 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, |
| 49 | status_code, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 50 | status_code == WLAN_STATUS_SUCCESS, bss); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 51 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 52 | EXPORT_SYMBOL(cfg80211_rx_assoc_resp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 53 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 54 | static void cfg80211_process_auth(struct wireless_dev *wdev, |
| 55 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 56 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 57 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 58 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 59 | nl80211_send_rx_auth(rdev, wdev->netdev, buf, len, GFP_KERNEL); |
| 60 | cfg80211_sme_rx_auth(wdev, buf, len); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 61 | } |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 62 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 63 | static void cfg80211_process_deauth(struct wireless_dev *wdev, |
| 64 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 65 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 66 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 67 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 68 | const u8 *bssid = mgmt->bssid; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 69 | u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 70 | bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 71 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 72 | nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 73 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 74 | if (!wdev->current_bss || |
| 75 | !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 76 | return; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 77 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 78 | __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap); |
| 79 | cfg80211_sme_deauth(wdev); |
| 80 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 81 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 82 | static void cfg80211_process_disassoc(struct wireless_dev *wdev, |
| 83 | const u8 *buf, size_t len) |
| 84 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 85 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 86 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 87 | const u8 *bssid = mgmt->bssid; |
| 88 | u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 89 | bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 90 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 91 | nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL); |
| 92 | |
| 93 | if (WARN_ON(!wdev->current_bss || |
| 94 | !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) |
| 95 | return; |
| 96 | |
| 97 | __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap); |
| 98 | cfg80211_sme_disassoc(wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 99 | } |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 100 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 101 | void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len) |
| 102 | { |
| 103 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 104 | struct ieee80211_mgmt *mgmt = (void *)buf; |
| 105 | |
| 106 | ASSERT_WDEV_LOCK(wdev); |
| 107 | |
| 108 | trace_cfg80211_rx_mlme_mgmt(dev, buf, len); |
| 109 | |
| 110 | if (WARN_ON(len < 2)) |
| 111 | return; |
| 112 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 113 | if (ieee80211_is_auth(mgmt->frame_control)) |
| 114 | cfg80211_process_auth(wdev, buf, len); |
| 115 | else if (ieee80211_is_deauth(mgmt->frame_control)) |
| 116 | cfg80211_process_deauth(wdev, buf, len); |
| 117 | else if (ieee80211_is_disassoc(mgmt->frame_control)) |
| 118 | cfg80211_process_disassoc(wdev, buf, len); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 119 | } |
| 120 | EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt); |
| 121 | |
| 122 | void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr) |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 123 | { |
| 124 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 125 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 126 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 127 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 128 | trace_cfg80211_send_auth_timeout(dev, addr); |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 129 | |
| 130 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 131 | cfg80211_sme_auth_timeout(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 132 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 133 | EXPORT_SYMBOL(cfg80211_auth_timeout); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 134 | |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 135 | void cfg80211_assoc_timeout(struct net_device *dev, struct cfg80211_bss *bss) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 136 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 137 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 138 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 139 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 140 | |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 141 | trace_cfg80211_send_assoc_timeout(dev, bss->bssid); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 142 | |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 143 | nl80211_send_assoc_timeout(rdev, dev, bss->bssid, GFP_KERNEL); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 144 | cfg80211_sme_assoc_timeout(wdev); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 145 | |
Johannes Berg | f1940c5 | 2013-06-19 13:21:15 +0200 | [diff] [blame] | 146 | cfg80211_unhold_bss(bss_from_pub(bss)); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 147 | cfg80211_put_bss(wiphy, bss); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 148 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 149 | EXPORT_SYMBOL(cfg80211_assoc_timeout); |
| 150 | |
| 151 | void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len) |
| 152 | { |
| 153 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 154 | struct ieee80211_mgmt *mgmt = (void *)buf; |
| 155 | |
| 156 | ASSERT_WDEV_LOCK(wdev); |
| 157 | |
| 158 | trace_cfg80211_tx_mlme_mgmt(dev, buf, len); |
| 159 | |
| 160 | if (WARN_ON(len < 2)) |
| 161 | return; |
| 162 | |
| 163 | if (ieee80211_is_deauth(mgmt->frame_control)) |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 164 | cfg80211_process_deauth(wdev, buf, len); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 165 | else |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 166 | cfg80211_process_disassoc(wdev, buf, len); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 167 | } |
| 168 | EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 169 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 170 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
| 171 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 172 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 173 | { |
| 174 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 175 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 176 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 177 | union iwreq_data wrqu; |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 178 | char *buf = kmalloc(128, gfp); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 179 | |
| 180 | if (buf) { |
| 181 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" |
| 182 | "keyid=%d %scast addr=%pM)", key_id, |
| 183 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", |
| 184 | addr); |
| 185 | memset(&wrqu, 0, sizeof(wrqu)); |
| 186 | wrqu.data.length = strlen(buf); |
| 187 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 188 | kfree(buf); |
| 189 | } |
| 190 | #endif |
| 191 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 192 | trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc); |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 193 | nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 194 | } |
| 195 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 196 | |
| 197 | /* some MLME handling for userspace SME */ |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 198 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 199 | struct net_device *dev, |
| 200 | struct ieee80211_channel *chan, |
| 201 | enum nl80211_auth_type auth_type, |
| 202 | const u8 *bssid, |
| 203 | const u8 *ssid, int ssid_len, |
| 204 | const u8 *ie, int ie_len, |
| 205 | const u8 *key, int key_len, int key_idx, |
| 206 | const u8 *sae_data, int sae_data_len) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 207 | { |
| 208 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 7ade703 | 2013-05-13 11:37:30 +0200 | [diff] [blame] | 209 | struct cfg80211_auth_request req = { |
| 210 | .ie = ie, |
| 211 | .ie_len = ie_len, |
| 212 | .sae_data = sae_data, |
| 213 | .sae_data_len = sae_data_len, |
| 214 | .auth_type = auth_type, |
| 215 | .key = key, |
| 216 | .key_len = key_len, |
| 217 | .key_idx = key_idx, |
| 218 | }; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 219 | int err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 220 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 221 | ASSERT_WDEV_LOCK(wdev); |
| 222 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 223 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
| 224 | if (!key || !key_len || key_idx < 0 || key_idx > 4) |
| 225 | return -EINVAL; |
| 226 | |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 227 | if (wdev->current_bss && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 228 | ether_addr_equal(bssid, wdev->current_bss->pub.bssid)) |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 229 | return -EALREADY; |
| 230 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 231 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 232 | IEEE80211_BSS_TYPE_ESS, |
| 233 | IEEE80211_PRIVACY_ANY); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 234 | if (!req.bss) |
| 235 | return -ENOENT; |
| 236 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 237 | err = rdev_auth(rdev, dev, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 238 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 239 | cfg80211_put_bss(&rdev->wiphy, req.bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 240 | return err; |
| 241 | } |
| 242 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 243 | /* Do a logical ht_capa &= ht_capa_mask. */ |
| 244 | void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa, |
| 245 | const struct ieee80211_ht_cap *ht_capa_mask) |
| 246 | { |
| 247 | int i; |
| 248 | u8 *p1, *p2; |
| 249 | if (!ht_capa_mask) { |
| 250 | memset(ht_capa, 0, sizeof(*ht_capa)); |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | p1 = (u8*)(ht_capa); |
| 255 | p2 = (u8*)(ht_capa_mask); |
| 256 | for (i = 0; i<sizeof(*ht_capa); i++) |
| 257 | p1[i] &= p2[i]; |
| 258 | } |
| 259 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 260 | /* Do a logical ht_capa &= ht_capa_mask. */ |
| 261 | void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa, |
| 262 | const struct ieee80211_vht_cap *vht_capa_mask) |
| 263 | { |
| 264 | int i; |
| 265 | u8 *p1, *p2; |
| 266 | if (!vht_capa_mask) { |
| 267 | memset(vht_capa, 0, sizeof(*vht_capa)); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | p1 = (u8*)(vht_capa); |
| 272 | p2 = (u8*)(vht_capa_mask); |
| 273 | for (i = 0; i < sizeof(*vht_capa); i++) |
| 274 | p1[i] &= p2[i]; |
| 275 | } |
| 276 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 277 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 278 | struct net_device *dev, |
| 279 | struct ieee80211_channel *chan, |
| 280 | const u8 *bssid, |
| 281 | const u8 *ssid, int ssid_len, |
| 282 | struct cfg80211_assoc_request *req) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 283 | { |
| 284 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 285 | int err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 286 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 287 | ASSERT_WDEV_LOCK(wdev); |
| 288 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 289 | if (wdev->current_bss && |
| 290 | (!req->prev_bssid || !ether_addr_equal(wdev->current_bss->pub.bssid, |
| 291 | req->prev_bssid))) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 292 | return -EALREADY; |
| 293 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 294 | cfg80211_oper_and_ht_capa(&req->ht_capa_mask, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 295 | rdev->wiphy.ht_capa_mod_mask); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 296 | cfg80211_oper_and_vht_capa(&req->vht_capa_mask, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 297 | rdev->wiphy.vht_capa_mod_mask); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 298 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 299 | req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 300 | IEEE80211_BSS_TYPE_ESS, |
| 301 | IEEE80211_PRIVACY_ANY); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 302 | if (!req->bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 303 | return -ENOENT; |
| 304 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 305 | err = rdev_assoc(rdev, dev, req); |
Johannes Berg | f1940c5 | 2013-06-19 13:21:15 +0200 | [diff] [blame] | 306 | if (!err) |
| 307 | cfg80211_hold_bss(bss_from_pub(req->bss)); |
Luciano Coelho | 73de86a | 2014-02-13 11:31:59 +0200 | [diff] [blame] | 308 | else |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 309 | cfg80211_put_bss(&rdev->wiphy, req->bss); |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 310 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 311 | return err; |
| 312 | } |
| 313 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 314 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 315 | struct net_device *dev, const u8 *bssid, |
| 316 | const u8 *ie, int ie_len, u16 reason, |
| 317 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 318 | { |
| 319 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 320 | struct cfg80211_deauth_request req = { |
| 321 | .bssid = bssid, |
| 322 | .reason_code = reason, |
| 323 | .ie = ie, |
| 324 | .ie_len = ie_len, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 325 | .local_state_change = local_state_change, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 326 | }; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 327 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 328 | ASSERT_WDEV_LOCK(wdev); |
| 329 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 330 | if (local_state_change && |
| 331 | (!wdev->current_bss || |
| 332 | !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 333 | return 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 334 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 335 | return rdev_deauth(rdev, dev, &req); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 338 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 339 | struct net_device *dev, const u8 *bssid, |
| 340 | const u8 *ie, int ie_len, u16 reason, |
| 341 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 342 | { |
| 343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 7ade703 | 2013-05-13 11:37:30 +0200 | [diff] [blame] | 344 | struct cfg80211_disassoc_request req = { |
| 345 | .reason_code = reason, |
| 346 | .local_state_change = local_state_change, |
| 347 | .ie = ie, |
| 348 | .ie_len = ie_len, |
| 349 | }; |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 350 | int err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 351 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 352 | ASSERT_WDEV_LOCK(wdev); |
| 353 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 354 | if (!wdev->current_bss) |
Johannes Berg | f9d6b40 | 2009-07-27 10:22:28 +0200 | [diff] [blame] | 355 | return -ENOTCONN; |
| 356 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 357 | if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 358 | req.bss = &wdev->current_bss->pub; |
| 359 | else |
| 360 | return -ENOTCONN; |
| 361 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 362 | err = rdev_disassoc(rdev, dev, &req); |
| 363 | if (err) |
| 364 | return err; |
| 365 | |
| 366 | /* driver should have reported the disassoc */ |
| 367 | WARN_ON(wdev->current_bss); |
| 368 | return 0; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 371 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, |
| 372 | struct net_device *dev) |
| 373 | { |
| 374 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 375 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 376 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 377 | ASSERT_WDEV_LOCK(wdev); |
| 378 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 379 | if (!rdev->ops->deauth) |
| 380 | return; |
| 381 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 382 | if (!wdev->current_bss) |
| 383 | return; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 384 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 385 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 386 | cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0, |
| 387 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 388 | } |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 389 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 390 | struct cfg80211_mgmt_registration { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 391 | struct list_head list; |
| 392 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 393 | u32 nlportid; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 394 | |
| 395 | int match_len; |
| 396 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 397 | __le16 frame_type; |
| 398 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 399 | u8 match[]; |
| 400 | }; |
| 401 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 402 | int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 403 | u16 frame_type, const u8 *match_data, |
| 404 | int match_len) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 405 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 406 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 407 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 408 | struct cfg80211_mgmt_registration *reg, *nreg; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 409 | int err = 0; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 410 | u16 mgmt_type; |
| 411 | |
| 412 | if (!wdev->wiphy->mgmt_stypes) |
| 413 | return -EOPNOTSUPP; |
| 414 | |
| 415 | if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) |
| 419 | return -EINVAL; |
| 420 | |
| 421 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
| 422 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type))) |
| 423 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 424 | |
| 425 | nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); |
| 426 | if (!nreg) |
| 427 | return -ENOMEM; |
| 428 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 429 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 430 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 431 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 432 | int mlen = min(match_len, reg->match_len); |
| 433 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 434 | if (frame_type != le16_to_cpu(reg->frame_type)) |
| 435 | continue; |
| 436 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 437 | if (memcmp(reg->match, match_data, mlen) == 0) { |
| 438 | err = -EALREADY; |
| 439 | break; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | if (err) { |
| 444 | kfree(nreg); |
| 445 | goto out; |
| 446 | } |
| 447 | |
| 448 | memcpy(nreg->match, match_data, match_len); |
| 449 | nreg->match_len = match_len; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 450 | nreg->nlportid = snd_portid; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 451 | nreg->frame_type = cpu_to_le16(frame_type); |
| 452 | list_add(&nreg->list, &wdev->mgmt_registrations); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 453 | |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 454 | if (rdev->ops->mgmt_frame_register) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 455 | rdev_mgmt_frame_register(rdev, wdev, frame_type, true); |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 456 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 457 | out: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 458 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 459 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 460 | return err; |
| 461 | } |
| 462 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 463 | void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 464 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 465 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 467 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 468 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 469 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 470 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 471 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 472 | if (reg->nlportid != nlportid) |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 473 | continue; |
| 474 | |
| 475 | if (rdev->ops->mgmt_frame_register) { |
| 476 | u16 frame_type = le16_to_cpu(reg->frame_type); |
| 477 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 478 | rdev_mgmt_frame_register(rdev, wdev, |
| 479 | frame_type, false); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 480 | } |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 481 | |
| 482 | list_del(®->list); |
| 483 | kfree(reg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 484 | } |
| 485 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 486 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 487 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 488 | if (nlportid && rdev->crit_proto_nlportid == nlportid) { |
| 489 | rdev->crit_proto_nlportid = 0; |
| 490 | rdev_crit_proto_stop(rdev, wdev); |
| 491 | } |
| 492 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 493 | if (nlportid == wdev->ap_unexpected_nlportid) |
| 494 | wdev->ap_unexpected_nlportid = 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 495 | } |
| 496 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 497 | void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 498 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 499 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 500 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 501 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 502 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 503 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 504 | list_del(®->list); |
| 505 | kfree(reg); |
| 506 | } |
| 507 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 508 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 511 | int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 512 | struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 513 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 514 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 515 | const struct ieee80211_mgmt *mgmt; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 516 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 517 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 518 | if (!wdev->wiphy->mgmt_stypes) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 519 | return -EOPNOTSUPP; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 520 | |
| 521 | if (!rdev->ops->mgmt_tx) |
| 522 | return -EOPNOTSUPP; |
| 523 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 524 | if (params->len < 24 + 1) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 525 | return -EINVAL; |
| 526 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 527 | mgmt = (const struct ieee80211_mgmt *)params->buf; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 528 | |
| 529 | if (!ieee80211_is_mgmt(mgmt->frame_control)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 530 | return -EINVAL; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 531 | |
| 532 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; |
| 533 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4))) |
| 534 | return -EINVAL; |
| 535 | |
| 536 | if (ieee80211_is_action(mgmt->frame_control) && |
| 537 | mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 538 | int err = 0; |
| 539 | |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 540 | wdev_lock(wdev); |
| 541 | |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 542 | switch (wdev->iftype) { |
| 543 | case NL80211_IFTYPE_ADHOC: |
| 544 | case NL80211_IFTYPE_STATION: |
| 545 | case NL80211_IFTYPE_P2P_CLIENT: |
| 546 | if (!wdev->current_bss) { |
| 547 | err = -ENOTCONN; |
| 548 | break; |
| 549 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 550 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 551 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
| 552 | mgmt->bssid)) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 553 | err = -ENOTCONN; |
| 554 | break; |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | * check for IBSS DA must be done by driver as |
| 559 | * cfg80211 doesn't track the stations |
| 560 | */ |
| 561 | if (wdev->iftype == NL80211_IFTYPE_ADHOC) |
| 562 | break; |
| 563 | |
| 564 | /* for station, check that DA is the AP */ |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 565 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
| 566 | mgmt->da)) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 567 | err = -ENOTCONN; |
| 568 | break; |
| 569 | } |
| 570 | break; |
| 571 | case NL80211_IFTYPE_AP: |
| 572 | case NL80211_IFTYPE_P2P_GO: |
| 573 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 574 | if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev))) |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 575 | err = -EINVAL; |
| 576 | break; |
Javier Cardona | 0778a6a | 2011-05-03 16:57:08 -0700 | [diff] [blame] | 577 | case NL80211_IFTYPE_MESH_POINT: |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 578 | if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) { |
Javier Cardona | 0778a6a | 2011-05-03 16:57:08 -0700 | [diff] [blame] | 579 | err = -EINVAL; |
| 580 | break; |
| 581 | } |
| 582 | /* |
| 583 | * check for mesh DA must be done by driver as |
| 584 | * cfg80211 doesn't track the stations |
| 585 | */ |
| 586 | break; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 587 | case NL80211_IFTYPE_P2P_DEVICE: |
| 588 | /* |
| 589 | * fall through, P2P device only supports |
| 590 | * public action frames |
| 591 | */ |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 592 | default: |
| 593 | err = -EOPNOTSUPP; |
| 594 | break; |
| 595 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 596 | wdev_unlock(wdev); |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 597 | |
| 598 | if (err) |
| 599 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 602 | if (!ether_addr_equal(mgmt->sa, wdev_address(wdev))) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 603 | return -EINVAL; |
| 604 | |
| 605 | /* Transmit the Action frame as requested by user space */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 606 | return rdev_mgmt_tx(rdev, wdev, params, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 607 | } |
| 608 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 609 | bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm, |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 610 | const u8 *buf, size_t len, u32 flags) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 611 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 612 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 613 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 614 | struct cfg80211_mgmt_registration *reg; |
| 615 | const struct ieee80211_txrx_stypes *stypes = |
| 616 | &wiphy->mgmt_stypes[wdev->iftype]; |
| 617 | struct ieee80211_mgmt *mgmt = (void *)buf; |
| 618 | const u8 *data; |
| 619 | int data_len; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 620 | bool result = false; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 621 | __le16 ftype = mgmt->frame_control & |
| 622 | cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE); |
| 623 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 624 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 625 | trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 626 | stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 627 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 628 | if (!(stypes->rx & BIT(stype))) { |
| 629 | trace_cfg80211_return_bool(false); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 630 | return false; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 631 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 632 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 633 | data = buf + ieee80211_hdrlen(mgmt->frame_control); |
| 634 | data_len = len - ieee80211_hdrlen(mgmt->frame_control); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 635 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 636 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
| 637 | |
| 638 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
| 639 | if (reg->frame_type != ftype) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 640 | continue; |
| 641 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 642 | if (reg->match_len > data_len) |
| 643 | continue; |
| 644 | |
| 645 | if (memcmp(reg->match, data, reg->match_len)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 646 | continue; |
| 647 | |
| 648 | /* found match! */ |
| 649 | |
| 650 | /* Indicate the received Action frame to user space */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 651 | if (nl80211_send_mgmt(rdev, wdev, reg->nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 652 | freq, sig_mbm, |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 653 | buf, len, flags, GFP_ATOMIC)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 654 | continue; |
| 655 | |
| 656 | result = true; |
| 657 | break; |
| 658 | } |
| 659 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 660 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 661 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 662 | trace_cfg80211_return_bool(result); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 663 | return result; |
| 664 | } |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 665 | EXPORT_SYMBOL(cfg80211_rx_mgmt); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 666 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 667 | void cfg80211_dfs_channels_update_work(struct work_struct *work) |
| 668 | { |
| 669 | struct delayed_work *delayed_work; |
| 670 | struct cfg80211_registered_device *rdev; |
| 671 | struct cfg80211_chan_def chandef; |
| 672 | struct ieee80211_supported_band *sband; |
| 673 | struct ieee80211_channel *c; |
| 674 | struct wiphy *wiphy; |
| 675 | bool check_again = false; |
| 676 | unsigned long timeout, next_time = 0; |
| 677 | int bandid, i; |
| 678 | |
| 679 | delayed_work = container_of(work, struct delayed_work, work); |
| 680 | rdev = container_of(delayed_work, struct cfg80211_registered_device, |
| 681 | dfs_update_channels_wk); |
| 682 | wiphy = &rdev->wiphy; |
| 683 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 684 | rtnl_lock(); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 685 | for (bandid = 0; bandid < IEEE80211_NUM_BANDS; bandid++) { |
| 686 | sband = wiphy->bands[bandid]; |
| 687 | if (!sband) |
| 688 | continue; |
| 689 | |
| 690 | for (i = 0; i < sband->n_channels; i++) { |
| 691 | c = &sband->channels[i]; |
| 692 | |
| 693 | if (c->dfs_state != NL80211_DFS_UNAVAILABLE) |
| 694 | continue; |
| 695 | |
Michal Kazior | c532a58 | 2013-10-17 11:21:11 -0700 | [diff] [blame] | 696 | timeout = c->dfs_state_entered + msecs_to_jiffies( |
| 697 | IEEE80211_DFS_MIN_NOP_TIME_MS); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 698 | |
| 699 | if (time_after_eq(jiffies, timeout)) { |
| 700 | c->dfs_state = NL80211_DFS_USABLE; |
Michal Kazior | bbe09bb | 2013-10-17 11:21:12 -0700 | [diff] [blame] | 701 | c->dfs_state_entered = jiffies; |
| 702 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 703 | cfg80211_chandef_create(&chandef, c, |
| 704 | NL80211_CHAN_NO_HT); |
| 705 | |
| 706 | nl80211_radar_notify(rdev, &chandef, |
| 707 | NL80211_RADAR_NOP_FINISHED, |
| 708 | NULL, GFP_ATOMIC); |
| 709 | continue; |
| 710 | } |
| 711 | |
| 712 | if (!check_again) |
| 713 | next_time = timeout - jiffies; |
| 714 | else |
| 715 | next_time = min(next_time, timeout - jiffies); |
| 716 | check_again = true; |
| 717 | } |
| 718 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 719 | rtnl_unlock(); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 720 | |
| 721 | /* reschedule if there are other channels waiting to be cleared again */ |
| 722 | if (check_again) |
| 723 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, |
| 724 | next_time); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | void cfg80211_radar_event(struct wiphy *wiphy, |
| 729 | struct cfg80211_chan_def *chandef, |
| 730 | gfp_t gfp) |
| 731 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 732 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 733 | unsigned long timeout; |
| 734 | |
| 735 | trace_cfg80211_radar_event(wiphy, chandef); |
| 736 | |
| 737 | /* only set the chandef supplied channel to unavailable, in |
| 738 | * case the radar is detected on only one of multiple channels |
| 739 | * spanned by the chandef. |
| 740 | */ |
| 741 | cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE); |
| 742 | |
| 743 | timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS); |
| 744 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, |
| 745 | timeout); |
| 746 | |
| 747 | nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp); |
| 748 | } |
| 749 | EXPORT_SYMBOL(cfg80211_radar_event); |
| 750 | |
| 751 | void cfg80211_cac_event(struct net_device *netdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 752 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 753 | enum nl80211_radar_event event, gfp_t gfp) |
| 754 | { |
| 755 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 756 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 757 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 758 | unsigned long timeout; |
| 759 | |
| 760 | trace_cfg80211_cac_event(netdev, event); |
| 761 | |
| 762 | if (WARN_ON(!wdev->cac_started)) |
| 763 | return; |
| 764 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 765 | if (WARN_ON(!wdev->chandef.chan)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 766 | return; |
| 767 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 768 | switch (event) { |
| 769 | case NL80211_RADAR_CAC_FINISHED: |
| 770 | timeout = wdev->cac_start_time + |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 771 | msecs_to_jiffies(wdev->cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 772 | WARN_ON(!time_after_eq(jiffies, timeout)); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 773 | cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 774 | break; |
| 775 | case NL80211_RADAR_CAC_ABORTED: |
| 776 | break; |
| 777 | default: |
| 778 | WARN_ON(1); |
| 779 | return; |
| 780 | } |
| 781 | wdev->cac_started = false; |
| 782 | |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 783 | nl80211_radar_notify(rdev, chandef, event, netdev, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 784 | } |
| 785 | EXPORT_SYMBOL(cfg80211_cac_event); |