blob: 7bde5d9c0003166d46e06b3d947e7e2455333eaa [file] [log] [blame]
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001/*
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 Fietkauc6fb08a2012-03-18 22:58:04 +01009#include <linux/etherdevice.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010#include <linux/netdevice.h>
11#include <linux/nl80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berga9a11622009-07-27 12:01:53 +020013#include <linux/wireless.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020014#include <net/cfg80211.h>
Johannes Berga9a11622009-07-27 12:01:53 +020015#include <net/iw_handler.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020016#include "core.h"
17#include "nl80211.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030018#include "rdev-ops.h"
19
Jouni Malinen6039f6d2009-03-19 13:39:21 +020020
Johannes Bergcb0b4be2009-07-07 03:56:07 +020021void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020022{
Johannes Berg19957bb2009-07-02 17:20:43 +020023 struct wireless_dev *wdev = dev->ieee80211_ptr;
24 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020025 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +020026
Beni Lev4ee3e062012-08-27 12:49:39 +030027 trace_cfg80211_send_rx_auth(dev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020028
Johannes Berg95de8172012-01-20 13:55:25 +010029 nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
30 cfg80211_sme_rx_auth(dev, buf, len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020031}
32EXPORT_SYMBOL(cfg80211_send_rx_auth);
33
Johannes Berg95de8172012-01-20 13:55:25 +010034void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss,
35 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020036{
Johannes Berg6829c872009-07-02 09:13:27 +020037 u16 status_code;
38 struct wireless_dev *wdev = dev->ieee80211_ptr;
39 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020040 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020041 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
42 u8 *ie = mgmt->u.assoc_resp.variable;
Johannes Berg95de8172012-01-20 13:55:25 +010043 int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
Johannes Berg6829c872009-07-02 09:13:27 +020044
Beni Lev4ee3e062012-08-27 12:49:39 +030045 trace_cfg80211_send_rx_assoc(dev, bss);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020046
Johannes Berg6829c872009-07-02 09:13:27 +020047 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
48
Johannes Bergf401a6f2009-08-07 14:51:05 +020049 /*
50 * This is a bit of a hack, we don't notify userspace of
51 * a (re-)association reply if we tried to send a reassoc
52 * and got a reject -- we only try again with an assoc
53 * frame instead of reassoc.
54 */
55 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn &&
Johannes Berg95de8172012-01-20 13:55:25 +010056 cfg80211_sme_failed_reassoc(wdev)) {
Johannes Berg5b112d32013-02-01 01:49:58 +010057 cfg80211_put_bss(wiphy, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +020058 return;
Johannes Berg95de8172012-01-20 13:55:25 +010059 }
Johannes Bergf401a6f2009-08-07 14:51:05 +020060
Johannes Bergcb0b4be2009-07-07 03:56:07 +020061 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +020062
Johannes Berg95de8172012-01-20 13:55:25 +010063 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) {
Johannes Berg7d930bc2009-10-20 15:08:53 +090064 cfg80211_sme_failed_assoc(wdev);
Johannes Berg7d930bc2009-10-20 15:08:53 +090065 /*
66 * do not call connect_result() now because the
67 * sme will schedule work that does it later.
68 */
Johannes Berg5b112d32013-02-01 01:49:58 +010069 cfg80211_put_bss(wiphy, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +020070 return;
Johannes Bergdf7fc0f2009-07-29 11:23:49 +020071 }
72
Johannes Bergea416a72009-08-17 12:22:14 +020073 if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) {
74 /*
75 * This is for the userspace SME, the CONNECTING
76 * state will be changed to CONNECTED by
77 * __cfg80211_connect_result() below.
78 */
79 wdev->sme_state = CFG80211_SME_CONNECTING;
80 }
81
Johannes Berg95de8172012-01-20 13:55:25 +010082 /* this consumes the bss reference */
Johannes Bergdf7fc0f2009-07-29 11:23:49 +020083 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
84 status_code,
Johannes Berg95de8172012-01-20 13:55:25 +010085 status_code == WLAN_STATUS_SUCCESS, bss);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020086}
87EXPORT_SYMBOL(cfg80211_send_rx_assoc);
88
Johannes Berg8d61ffa2013-05-10 12:32:47 +020089void cfg80211_send_deauth(struct net_device *dev,
90 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020091{
Johannes Berg6829c872009-07-02 09:13:27 +020092 struct wireless_dev *wdev = dev->ieee80211_ptr;
93 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020094 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020095 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +020096 const u8 *bssid = mgmt->bssid;
Johannes Berg95de8172012-01-20 13:55:25 +010097 bool was_current = false;
Johannes Berg6829c872009-07-02 09:13:27 +020098
Johannes Berg8d61ffa2013-05-10 12:32:47 +020099 trace_cfg80211_send_deauth(dev);
Johannes Berg667503d2009-07-07 03:56:11 +0200100 ASSERT_WDEV_LOCK(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200101
Johannes Berg19957bb2009-07-02 17:20:43 +0200102 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000103 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200104 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100105 cfg80211_put_bss(wiphy, &wdev->current_bss->pub);
Johannes Berg19957bb2009-07-02 17:20:43 +0200106 wdev->current_bss = NULL;
Johannes Berg3f3b6a82010-08-05 10:20:27 +0200107 was_current = true;
Johannes Berg19957bb2009-07-02 17:20:43 +0200108 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200109
Johannes Berg5fba4af32009-12-02 12:43:42 +0100110 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
111
Johannes Berg3f3b6a82010-08-05 10:20:27 +0200112 if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
Johannes Berg6829c872009-07-02 09:13:27 +0200113 u16 reason_code;
114 bool from_ap;
115
116 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
117
Joe Perchesac422d32012-05-08 18:56:55 +0000118 from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr);
Johannes Berg667503d2009-07-07 03:56:11 +0200119 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
Johannes Berg6829c872009-07-02 09:13:27 +0200120 } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
Johannes Berg667503d2009-07-07 03:56:11 +0200121 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
122 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200123 false, NULL);
Johannes Berg667503d2009-07-07 03:56:11 +0200124 }
125}
Jouni Malinen53b46b82009-03-27 20:53:56 +0200126EXPORT_SYMBOL(cfg80211_send_deauth);
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200127
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200128void cfg80211_send_disassoc(struct net_device *dev,
129 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200130{
Johannes Berg6829c872009-07-02 09:13:27 +0200131 struct wireless_dev *wdev = dev->ieee80211_ptr;
132 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +0200133 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200134 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +0200135 const u8 *bssid = mgmt->bssid;
Johannes Berg19957bb2009-07-02 17:20:43 +0200136 u16 reason_code;
137 bool from_ap;
Johannes Berg6829c872009-07-02 09:13:27 +0200138
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200139 trace_cfg80211_send_disassoc(dev);
Johannes Berg596a07c2009-07-11 00:17:32 +0200140 ASSERT_WDEV_LOCK(wdev);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200141
142 nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +0200143
Johannes Berg596a07c2009-07-11 00:17:32 +0200144 if (wdev->sme_state != CFG80211_SME_CONNECTED)
145 return;
Johannes Berg6829c872009-07-02 09:13:27 +0200146
Johannes Berg19957bb2009-07-02 17:20:43 +0200147 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000148 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) {
Johannes Berg95de8172012-01-20 13:55:25 +0100149 cfg80211_sme_disassoc(dev, wdev->current_bss);
150 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100151 cfg80211_put_bss(wiphy, &wdev->current_bss->pub);
Johannes Berg95de8172012-01-20 13:55:25 +0100152 wdev->current_bss = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200153 } else
154 WARN_ON(1);
Johannes Berg6829c872009-07-02 09:13:27 +0200155
Johannes Berg6829c872009-07-02 09:13:27 +0200156
Johannes Berg19957bb2009-07-02 17:20:43 +0200157 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
158
Joe Perchesac422d32012-05-08 18:56:55 +0000159 from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr);
Johannes Berg667503d2009-07-07 03:56:11 +0200160 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
Johannes Berg667503d2009-07-07 03:56:11 +0200161}
Jouni Malinen53b46b82009-03-27 20:53:56 +0200162EXPORT_SYMBOL(cfg80211_send_disassoc);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200163
Johannes Berga58ce432009-11-19 12:45:42 +0100164void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
165{
166 struct wireless_dev *wdev = dev->ieee80211_ptr;
167 struct wiphy *wiphy = wdev->wiphy;
168 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
169
Beni Lev4ee3e062012-08-27 12:49:39 +0300170 trace_cfg80211_send_auth_timeout(dev, addr);
Johannes Berga58ce432009-11-19 12:45:42 +0100171
172 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
173 if (wdev->sme_state == CFG80211_SME_CONNECTING)
174 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
175 WLAN_STATUS_UNSPECIFIED_FAILURE,
176 false, NULL);
Jouni Malinen1965c852009-04-22 21:38:25 +0300177}
178EXPORT_SYMBOL(cfg80211_send_auth_timeout);
179
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200180void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
Jouni Malinen1965c852009-04-22 21:38:25 +0300181{
Johannes Berg6829c872009-07-02 09:13:27 +0200182 struct wireless_dev *wdev = dev->ieee80211_ptr;
183 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen1965c852009-04-22 21:38:25 +0300184 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200185
Beni Lev4ee3e062012-08-27 12:49:39 +0300186 trace_cfg80211_send_assoc_timeout(dev, addr);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200187
188 nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +0200189 if (wdev->sme_state == CFG80211_SME_CONNECTING)
Johannes Berg667503d2009-07-07 03:56:11 +0200190 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
191 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200192 false, NULL);
Jouni Malinen1965c852009-04-22 21:38:25 +0300193}
194EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
195
Jouni Malinena3b8b052009-03-27 21:59:49 +0200196void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
197 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +0200198 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +0200199{
200 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
201 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg3d23e342009-09-29 23:27:28 +0200202#ifdef CONFIG_CFG80211_WEXT
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200203 union iwreq_data wrqu;
Johannes Berge6d6e342009-07-01 21:26:47 +0200204 char *buf = kmalloc(128, gfp);
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200205
206 if (buf) {
207 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
208 "keyid=%d %scast addr=%pM)", key_id,
209 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
210 addr);
211 memset(&wrqu, 0, sizeof(wrqu));
212 wrqu.data.length = strlen(buf);
213 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
214 kfree(buf);
215 }
216#endif
217
Beni Lev4ee3e062012-08-27 12:49:39 +0300218 trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc);
Johannes Berge6d6e342009-07-01 21:26:47 +0200219 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200220}
221EXPORT_SYMBOL(cfg80211_michael_mic_failure);
Johannes Berg19957bb2009-07-02 17:20:43 +0200222
223/* some MLME handling for userspace SME */
Johannes Berg91bf9b22013-05-15 17:44:01 +0200224int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
225 struct net_device *dev,
226 struct ieee80211_channel *chan,
227 enum nl80211_auth_type auth_type,
228 const u8 *bssid,
229 const u8 *ssid, int ssid_len,
230 const u8 *ie, int ie_len,
231 const u8 *key, int key_len, int key_idx,
232 const u8 *sae_data, int sae_data_len)
Johannes Berg19957bb2009-07-02 17:20:43 +0200233{
234 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200235 struct cfg80211_auth_request req = {
236 .ie = ie,
237 .ie_len = ie_len,
238 .sae_data = sae_data,
239 .sae_data_len = sae_data_len,
240 .auth_type = auth_type,
241 .key = key,
242 .key_len = key_len,
243 .key_idx = key_idx,
244 };
Johannes Berg95de8172012-01-20 13:55:25 +0100245 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200246
Johannes Berg667503d2009-07-07 03:56:11 +0200247 ASSERT_WDEV_LOCK(wdev);
248
Johannes Bergfffd0932009-07-08 14:22:54 +0200249 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
250 if (!key || !key_len || key_idx < 0 || key_idx > 4)
251 return -EINVAL;
252
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200253 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000254 ether_addr_equal(bssid, wdev->current_bss->pub.bssid))
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200255 return -EALREADY;
256
Johannes Berg19957bb2009-07-02 17:20:43 +0200257 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
258 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
259 if (!req.bss)
260 return -ENOENT;
261
Michal Kaziore4e32452012-06-29 12:47:08 +0200262 err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
263 CHAN_MODE_SHARED);
264 if (err)
265 goto out;
266
Hila Gonene35e4d22012-06-27 17:19:42 +0300267 err = rdev_auth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200268
Michal Kaziore4e32452012-06-29 12:47:08 +0200269out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100270 cfg80211_put_bss(&rdev->wiphy, req.bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200271 return err;
272}
273
Ben Greear7e7c8922011-11-18 11:31:59 -0800274/* Do a logical ht_capa &= ht_capa_mask. */
275void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
276 const struct ieee80211_ht_cap *ht_capa_mask)
277{
278 int i;
279 u8 *p1, *p2;
280 if (!ht_capa_mask) {
281 memset(ht_capa, 0, sizeof(*ht_capa));
282 return;
283 }
284
285 p1 = (u8*)(ht_capa);
286 p2 = (u8*)(ht_capa_mask);
287 for (i = 0; i<sizeof(*ht_capa); i++)
288 p1[i] &= p2[i];
289}
290
Johannes Bergee2aca32013-02-21 17:36:01 +0100291/* Do a logical ht_capa &= ht_capa_mask. */
292void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
293 const struct ieee80211_vht_cap *vht_capa_mask)
294{
295 int i;
296 u8 *p1, *p2;
297 if (!vht_capa_mask) {
298 memset(vht_capa, 0, sizeof(*vht_capa));
299 return;
300 }
301
302 p1 = (u8*)(vht_capa);
303 p2 = (u8*)(vht_capa_mask);
304 for (i = 0; i < sizeof(*vht_capa); i++)
305 p1[i] &= p2[i];
306}
307
Johannes Berg91bf9b22013-05-15 17:44:01 +0200308int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
309 struct net_device *dev,
310 struct ieee80211_channel *chan,
311 const u8 *bssid,
312 const u8 *ssid, int ssid_len,
313 struct cfg80211_assoc_request *req)
Johannes Berg19957bb2009-07-02 17:20:43 +0200314{
315 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100316 int err;
Jouni Malinen24b6b152009-11-17 21:35:38 +0200317 bool was_connected = false;
Johannes Berg19957bb2009-07-02 17:20:43 +0200318
Johannes Berg667503d2009-07-07 03:56:11 +0200319 ASSERT_WDEV_LOCK(wdev);
320
Johannes Bergf62fab72013-02-21 20:09:09 +0100321 if (wdev->current_bss && req->prev_bssid &&
322 ether_addr_equal(wdev->current_bss->pub.bssid, req->prev_bssid)) {
Jouni Malinen24b6b152009-11-17 21:35:38 +0200323 /*
324 * Trying to reassociate: Allow this to proceed and let the old
325 * association to be dropped when the new one is completed.
326 */
327 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
328 was_connected = true;
329 wdev->sme_state = CFG80211_SME_CONNECTING;
330 }
331 } else if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200332 return -EALREADY;
333
Johannes Bergf62fab72013-02-21 20:09:09 +0100334 cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
Ben Greear7e7c8922011-11-18 11:31:59 -0800335 rdev->wiphy.ht_capa_mod_mask);
Johannes Bergf62fab72013-02-21 20:09:09 +0100336 cfg80211_oper_and_vht_capa(&req->vht_capa_mask,
Johannes Bergee2aca32013-02-21 17:36:01 +0100337 rdev->wiphy.vht_capa_mod_mask);
Ben Greear7e7c8922011-11-18 11:31:59 -0800338
Johannes Bergf62fab72013-02-21 20:09:09 +0100339 req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
340 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
341 if (!req->bss) {
Jouni Malinen24b6b152009-11-17 21:35:38 +0200342 if (was_connected)
343 wdev->sme_state = CFG80211_SME_CONNECTED;
Johannes Berg19957bb2009-07-02 17:20:43 +0200344 return -ENOENT;
Jouni Malinen24b6b152009-11-17 21:35:38 +0200345 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200346
Johannes Bergf62fab72013-02-21 20:09:09 +0100347 err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
Michal Kaziore4e32452012-06-29 12:47:08 +0200348 if (err)
349 goto out;
350
Johannes Bergf62fab72013-02-21 20:09:09 +0100351 err = rdev_assoc(rdev, dev, req);
Johannes Berg95de8172012-01-20 13:55:25 +0100352
Michal Kaziore4e32452012-06-29 12:47:08 +0200353out:
Johannes Berg95de8172012-01-20 13:55:25 +0100354 if (err) {
355 if (was_connected)
356 wdev->sme_state = CFG80211_SME_CONNECTED;
Johannes Bergf62fab72013-02-21 20:09:09 +0100357 cfg80211_put_bss(&rdev->wiphy, req->bss);
Johannes Berg95de8172012-01-20 13:55:25 +0100358 }
359
Johannes Berg19957bb2009-07-02 17:20:43 +0200360 return err;
361}
362
Johannes Berg91bf9b22013-05-15 17:44:01 +0200363int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
364 struct net_device *dev, const u8 *bssid,
365 const u8 *ie, int ie_len, u16 reason,
366 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200367{
368 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100369 struct cfg80211_deauth_request req = {
370 .bssid = bssid,
371 .reason_code = reason,
372 .ie = ie,
373 .ie_len = ie_len,
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200374 .local_state_change = local_state_change,
Johannes Berg95de8172012-01-20 13:55:25 +0100375 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200376
Johannes Berg667503d2009-07-07 03:56:11 +0200377 ASSERT_WDEV_LOCK(wdev);
378
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200379 if (local_state_change && (!wdev->current_bss ||
380 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
Johannes Berg95de8172012-01-20 13:55:25 +0100381 return 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200382
Hila Gonene35e4d22012-06-27 17:19:42 +0300383 return rdev_deauth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200384}
385
Johannes Berg91bf9b22013-05-15 17:44:01 +0200386int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
387 struct net_device *dev, const u8 *bssid,
388 const u8 *ie, int ie_len, u16 reason,
389 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200390{
391 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200392 struct cfg80211_disassoc_request req = {
393 .reason_code = reason,
394 .local_state_change = local_state_change,
395 .ie = ie,
396 .ie_len = ie_len,
397 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200398
Johannes Berg667503d2009-07-07 03:56:11 +0200399 ASSERT_WDEV_LOCK(wdev);
400
Johannes Bergf9d6b402009-07-27 10:22:28 +0200401 if (wdev->sme_state != CFG80211_SME_CONNECTED)
402 return -ENOTCONN;
403
Johannes Berg8dcf0112013-01-26 22:16:08 +0100404 if (WARN(!wdev->current_bss, "sme_state=%d\n", wdev->sme_state))
Johannes Bergf9d6b402009-07-27 10:22:28 +0200405 return -ENOTCONN;
406
Joe Perchesac422d32012-05-08 18:56:55 +0000407 if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg19957bb2009-07-02 17:20:43 +0200408 req.bss = &wdev->current_bss->pub;
409 else
410 return -ENOTCONN;
411
Hila Gonene35e4d22012-06-27 17:19:42 +0300412 return rdev_disassoc(rdev, dev, &req);
Johannes Berg667503d2009-07-07 03:56:11 +0200413}
414
Johannes Berg19957bb2009-07-02 17:20:43 +0200415void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
416 struct net_device *dev)
417{
418 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100419 u8 bssid[ETH_ALEN];
Johannes Berg7ade7032013-05-13 11:37:30 +0200420 struct cfg80211_deauth_request req = {
421 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
422 .bssid = bssid,
423 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200424
Johannes Berg667503d2009-07-07 03:56:11 +0200425 ASSERT_WDEV_LOCK(wdev);
426
Johannes Berg19957bb2009-07-02 17:20:43 +0200427 if (!rdev->ops->deauth)
428 return;
429
Johannes Berg95de8172012-01-20 13:55:25 +0100430 if (!wdev->current_bss)
431 return;
Johannes Berg19957bb2009-07-02 17:20:43 +0200432
Johannes Berg95de8172012-01-20 13:55:25 +0100433 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
Hila Gonene35e4d22012-06-27 17:19:42 +0300434 rdev_deauth(rdev, dev, &req);
Johannes Berg95de8172012-01-20 13:55:25 +0100435
436 if (wdev->current_bss) {
437 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100438 cfg80211_put_bss(&rdev->wiphy, &wdev->current_bss->pub);
Johannes Berg95de8172012-01-20 13:55:25 +0100439 wdev->current_bss = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200440 }
441}
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100442
Johannes Berg2e161f782010-08-12 15:38:38 +0200443struct cfg80211_mgmt_registration {
Jouni Malinen026331c2010-02-15 12:53:10 +0200444 struct list_head list;
445
Eric W. Biederman15e47302012-09-07 20:12:54 +0000446 u32 nlportid;
Jouni Malinen026331c2010-02-15 12:53:10 +0200447
448 int match_len;
449
Johannes Berg2e161f782010-08-12 15:38:38 +0200450 __le16 frame_type;
451
Jouni Malinen026331c2010-02-15 12:53:10 +0200452 u8 match[];
453};
454
Eric W. Biederman15e47302012-09-07 20:12:54 +0000455int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Johannes Berg2e161f782010-08-12 15:38:38 +0200456 u16 frame_type, const u8 *match_data,
457 int match_len)
Jouni Malinen026331c2010-02-15 12:53:10 +0200458{
Johannes Berg271733c2010-10-13 12:06:23 +0200459 struct wiphy *wiphy = wdev->wiphy;
460 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200461 struct cfg80211_mgmt_registration *reg, *nreg;
Jouni Malinen026331c2010-02-15 12:53:10 +0200462 int err = 0;
Johannes Berg2e161f782010-08-12 15:38:38 +0200463 u16 mgmt_type;
464
465 if (!wdev->wiphy->mgmt_stypes)
466 return -EOPNOTSUPP;
467
468 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
469 return -EINVAL;
470
471 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
472 return -EINVAL;
473
474 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
475 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
476 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +0200477
478 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
479 if (!nreg)
480 return -ENOMEM;
481
Johannes Berg2e161f782010-08-12 15:38:38 +0200482 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200483
Johannes Berg2e161f782010-08-12 15:38:38 +0200484 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200485 int mlen = min(match_len, reg->match_len);
486
Johannes Berg2e161f782010-08-12 15:38:38 +0200487 if (frame_type != le16_to_cpu(reg->frame_type))
488 continue;
489
Jouni Malinen026331c2010-02-15 12:53:10 +0200490 if (memcmp(reg->match, match_data, mlen) == 0) {
491 err = -EALREADY;
492 break;
493 }
494 }
495
496 if (err) {
497 kfree(nreg);
498 goto out;
499 }
500
501 memcpy(nreg->match, match_data, match_len);
502 nreg->match_len = match_len;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000503 nreg->nlportid = snd_portid;
Johannes Berg2e161f782010-08-12 15:38:38 +0200504 nreg->frame_type = cpu_to_le16(frame_type);
505 list_add(&nreg->list, &wdev->mgmt_registrations);
Jouni Malinen026331c2010-02-15 12:53:10 +0200506
Johannes Berg271733c2010-10-13 12:06:23 +0200507 if (rdev->ops->mgmt_frame_register)
Hila Gonene35e4d22012-06-27 17:19:42 +0300508 rdev_mgmt_frame_register(rdev, wdev, frame_type, true);
Johannes Berg271733c2010-10-13 12:06:23 +0200509
Jouni Malinen026331c2010-02-15 12:53:10 +0200510 out:
Johannes Berg2e161f782010-08-12 15:38:38 +0200511 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg271733c2010-10-13 12:06:23 +0200512
Jouni Malinen026331c2010-02-15 12:53:10 +0200513 return err;
514}
515
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid)
Jouni Malinen026331c2010-02-15 12:53:10 +0200517{
Johannes Berg271733c2010-10-13 12:06:23 +0200518 struct wiphy *wiphy = wdev->wiphy;
519 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200520 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200521
Johannes Berg2e161f782010-08-12 15:38:38 +0200522 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200523
Johannes Berg2e161f782010-08-12 15:38:38 +0200524 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000525 if (reg->nlportid != nlportid)
Johannes Berg271733c2010-10-13 12:06:23 +0200526 continue;
527
528 if (rdev->ops->mgmt_frame_register) {
529 u16 frame_type = le16_to_cpu(reg->frame_type);
530
Hila Gonene35e4d22012-06-27 17:19:42 +0300531 rdev_mgmt_frame_register(rdev, wdev,
532 frame_type, false);
Jouni Malinen026331c2010-02-15 12:53:10 +0200533 }
Johannes Berg271733c2010-10-13 12:06:23 +0200534
535 list_del(&reg->list);
536 kfree(reg);
Jouni Malinen026331c2010-02-15 12:53:10 +0200537 }
538
Johannes Berg2e161f782010-08-12 15:38:38 +0200539 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg28946da2011-11-04 11:18:12 +0100540
Arend van Spriel5de17982013-04-18 15:49:00 +0200541 if (nlportid && rdev->crit_proto_nlportid == nlportid) {
542 rdev->crit_proto_nlportid = 0;
543 rdev_crit_proto_stop(rdev, wdev);
544 }
545
Eric W. Biederman15e47302012-09-07 20:12:54 +0000546 if (nlportid == wdev->ap_unexpected_nlportid)
547 wdev->ap_unexpected_nlportid = 0;
Jouni Malinen026331c2010-02-15 12:53:10 +0200548}
549
Johannes Berg2e161f782010-08-12 15:38:38 +0200550void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
Jouni Malinen026331c2010-02-15 12:53:10 +0200551{
Johannes Berg2e161f782010-08-12 15:38:38 +0200552 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200553
Johannes Berg2e161f782010-08-12 15:38:38 +0200554 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200555
Johannes Berg2e161f782010-08-12 15:38:38 +0200556 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200557 list_del(&reg->list);
558 kfree(reg);
559 }
560
Johannes Berg2e161f782010-08-12 15:38:38 +0200561 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200562}
563
Johannes Berg2e161f782010-08-12 15:38:38 +0200564int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200565 struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100566 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +0100567 unsigned int wait, const u8 *buf, size_t len,
568 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +0200569{
Jouni Malinen026331c2010-02-15 12:53:10 +0200570 const struct ieee80211_mgmt *mgmt;
Johannes Berg2e161f782010-08-12 15:38:38 +0200571 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200572
Johannes Berg2e161f782010-08-12 15:38:38 +0200573 if (!wdev->wiphy->mgmt_stypes)
Jouni Malinen026331c2010-02-15 12:53:10 +0200574 return -EOPNOTSUPP;
Johannes Berg2e161f782010-08-12 15:38:38 +0200575
576 if (!rdev->ops->mgmt_tx)
577 return -EOPNOTSUPP;
578
Jouni Malinen026331c2010-02-15 12:53:10 +0200579 if (len < 24 + 1)
580 return -EINVAL;
581
582 mgmt = (const struct ieee80211_mgmt *) buf;
Johannes Berg2e161f782010-08-12 15:38:38 +0200583
584 if (!ieee80211_is_mgmt(mgmt->frame_control))
Jouni Malinen026331c2010-02-15 12:53:10 +0200585 return -EINVAL;
Johannes Berg2e161f782010-08-12 15:38:38 +0200586
587 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
588 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
589 return -EINVAL;
590
591 if (ieee80211_is_action(mgmt->frame_control) &&
592 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200593 int err = 0;
594
Johannes Bergfe100ac2010-08-09 15:52:03 +0200595 wdev_lock(wdev);
596
Johannes Berg663fcaf2010-09-30 21:06:09 +0200597 switch (wdev->iftype) {
598 case NL80211_IFTYPE_ADHOC:
599 case NL80211_IFTYPE_STATION:
600 case NL80211_IFTYPE_P2P_CLIENT:
601 if (!wdev->current_bss) {
602 err = -ENOTCONN;
603 break;
604 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200605
Joe Perchesac422d32012-05-08 18:56:55 +0000606 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
607 mgmt->bssid)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200608 err = -ENOTCONN;
609 break;
610 }
611
612 /*
613 * check for IBSS DA must be done by driver as
614 * cfg80211 doesn't track the stations
615 */
616 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
617 break;
618
619 /* for station, check that DA is the AP */
Joe Perchesac422d32012-05-08 18:56:55 +0000620 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
621 mgmt->da)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200622 err = -ENOTCONN;
623 break;
624 }
625 break;
626 case NL80211_IFTYPE_AP:
627 case NL80211_IFTYPE_P2P_GO:
628 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg98104fde2012-06-16 00:19:54 +0200629 if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev)))
Johannes Berg663fcaf2010-09-30 21:06:09 +0200630 err = -EINVAL;
631 break;
Javier Cardona0778a6a2011-05-03 16:57:08 -0700632 case NL80211_IFTYPE_MESH_POINT:
Joe Perchesac422d32012-05-08 18:56:55 +0000633 if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) {
Javier Cardona0778a6a2011-05-03 16:57:08 -0700634 err = -EINVAL;
635 break;
636 }
637 /*
638 * check for mesh DA must be done by driver as
639 * cfg80211 doesn't track the stations
640 */
641 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200642 case NL80211_IFTYPE_P2P_DEVICE:
643 /*
644 * fall through, P2P device only supports
645 * public action frames
646 */
Johannes Berg663fcaf2010-09-30 21:06:09 +0200647 default:
648 err = -EOPNOTSUPP;
649 break;
650 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200651 wdev_unlock(wdev);
Johannes Berg663fcaf2010-09-30 21:06:09 +0200652
653 if (err)
654 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +0200655 }
656
Johannes Berg98104fde2012-06-16 00:19:54 +0200657 if (!ether_addr_equal(mgmt->sa, wdev_address(wdev)))
Jouni Malinen026331c2010-02-15 12:53:10 +0200658 return -EINVAL;
659
660 /* Transmit the Action frame as requested by user space */
Hila Gonene35e4d22012-06-27 17:19:42 +0300661 return rdev_mgmt_tx(rdev, wdev, chan, offchan,
Hila Gonene35e4d22012-06-27 17:19:42 +0300662 wait, buf, len, no_cck, dont_wait_for_ack,
663 cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +0200664}
665
Johannes Berg71bbc992012-06-15 15:30:18 +0200666bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm,
Johannes Berg804483e2012-03-05 22:18:41 +0100667 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +0200668{
Jouni Malinen026331c2010-02-15 12:53:10 +0200669 struct wiphy *wiphy = wdev->wiphy;
670 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200671 struct cfg80211_mgmt_registration *reg;
672 const struct ieee80211_txrx_stypes *stypes =
673 &wiphy->mgmt_stypes[wdev->iftype];
674 struct ieee80211_mgmt *mgmt = (void *)buf;
675 const u8 *data;
676 int data_len;
Jouni Malinen026331c2010-02-15 12:53:10 +0200677 bool result = false;
Johannes Berg2e161f782010-08-12 15:38:38 +0200678 __le16 ftype = mgmt->frame_control &
679 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
680 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200681
Beni Lev4ee3e062012-08-27 12:49:39 +0300682 trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm);
Johannes Berg2e161f782010-08-12 15:38:38 +0200683 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
Jouni Malinen026331c2010-02-15 12:53:10 +0200684
Beni Lev4ee3e062012-08-27 12:49:39 +0300685 if (!(stypes->rx & BIT(stype))) {
686 trace_cfg80211_return_bool(false);
Johannes Berg2e161f782010-08-12 15:38:38 +0200687 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +0300688 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200689
Johannes Berg2e161f782010-08-12 15:38:38 +0200690 data = buf + ieee80211_hdrlen(mgmt->frame_control);
691 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
Jouni Malinen026331c2010-02-15 12:53:10 +0200692
Johannes Berg2e161f782010-08-12 15:38:38 +0200693 spin_lock_bh(&wdev->mgmt_registrations_lock);
694
695 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
696 if (reg->frame_type != ftype)
Jouni Malinen026331c2010-02-15 12:53:10 +0200697 continue;
698
Johannes Berg2e161f782010-08-12 15:38:38 +0200699 if (reg->match_len > data_len)
700 continue;
701
702 if (memcmp(reg->match, data, reg->match_len))
Jouni Malinen026331c2010-02-15 12:53:10 +0200703 continue;
704
705 /* found match! */
706
707 /* Indicate the received Action frame to user space */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000708 if (nl80211_send_mgmt(rdev, wdev, reg->nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +0100709 freq, sig_mbm,
Johannes Berg2e161f782010-08-12 15:38:38 +0200710 buf, len, gfp))
Jouni Malinen026331c2010-02-15 12:53:10 +0200711 continue;
712
713 result = true;
714 break;
715 }
716
Johannes Berg2e161f782010-08-12 15:38:38 +0200717 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200718
Beni Lev4ee3e062012-08-27 12:49:39 +0300719 trace_cfg80211_return_bool(result);
Jouni Malinen026331c2010-02-15 12:53:10 +0200720 return result;
721}
Johannes Berg2e161f782010-08-12 15:38:38 +0200722EXPORT_SYMBOL(cfg80211_rx_mgmt);
Jouni Malinen026331c2010-02-15 12:53:10 +0200723
Simon Wunderlich04f39042013-02-08 18:16:19 +0100724void cfg80211_dfs_channels_update_work(struct work_struct *work)
725{
726 struct delayed_work *delayed_work;
727 struct cfg80211_registered_device *rdev;
728 struct cfg80211_chan_def chandef;
729 struct ieee80211_supported_band *sband;
730 struct ieee80211_channel *c;
731 struct wiphy *wiphy;
732 bool check_again = false;
733 unsigned long timeout, next_time = 0;
734 int bandid, i;
735
736 delayed_work = container_of(work, struct delayed_work, work);
737 rdev = container_of(delayed_work, struct cfg80211_registered_device,
738 dfs_update_channels_wk);
739 wiphy = &rdev->wiphy;
740
Johannes Berg5fe231e2013-05-08 21:45:15 +0200741 rtnl_lock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100742 for (bandid = 0; bandid < IEEE80211_NUM_BANDS; bandid++) {
743 sband = wiphy->bands[bandid];
744 if (!sband)
745 continue;
746
747 for (i = 0; i < sband->n_channels; i++) {
748 c = &sband->channels[i];
749
750 if (c->dfs_state != NL80211_DFS_UNAVAILABLE)
751 continue;
752
753 timeout = c->dfs_state_entered +
754 IEEE80211_DFS_MIN_NOP_TIME_MS;
755
756 if (time_after_eq(jiffies, timeout)) {
757 c->dfs_state = NL80211_DFS_USABLE;
758 cfg80211_chandef_create(&chandef, c,
759 NL80211_CHAN_NO_HT);
760
761 nl80211_radar_notify(rdev, &chandef,
762 NL80211_RADAR_NOP_FINISHED,
763 NULL, GFP_ATOMIC);
764 continue;
765 }
766
767 if (!check_again)
768 next_time = timeout - jiffies;
769 else
770 next_time = min(next_time, timeout - jiffies);
771 check_again = true;
772 }
773 }
Johannes Berg5fe231e2013-05-08 21:45:15 +0200774 rtnl_unlock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100775
776 /* reschedule if there are other channels waiting to be cleared again */
777 if (check_again)
778 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
779 next_time);
780}
781
782
783void cfg80211_radar_event(struct wiphy *wiphy,
784 struct cfg80211_chan_def *chandef,
785 gfp_t gfp)
786{
787 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
788 unsigned long timeout;
789
790 trace_cfg80211_radar_event(wiphy, chandef);
791
792 /* only set the chandef supplied channel to unavailable, in
793 * case the radar is detected on only one of multiple channels
794 * spanned by the chandef.
795 */
796 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE);
797
798 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS);
799 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
800 timeout);
801
802 nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp);
803}
804EXPORT_SYMBOL(cfg80211_radar_event);
805
806void cfg80211_cac_event(struct net_device *netdev,
807 enum nl80211_radar_event event, gfp_t gfp)
808{
809 struct wireless_dev *wdev = netdev->ieee80211_ptr;
810 struct wiphy *wiphy = wdev->wiphy;
811 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
812 struct cfg80211_chan_def chandef;
813 unsigned long timeout;
814
815 trace_cfg80211_cac_event(netdev, event);
816
817 if (WARN_ON(!wdev->cac_started))
818 return;
819
820 if (WARN_ON(!wdev->channel))
821 return;
822
823 cfg80211_chandef_create(&chandef, wdev->channel, NL80211_CHAN_NO_HT);
824
825 switch (event) {
826 case NL80211_RADAR_CAC_FINISHED:
827 timeout = wdev->cac_start_time +
828 msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
829 WARN_ON(!time_after_eq(jiffies, timeout));
830 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_AVAILABLE);
831 break;
832 case NL80211_RADAR_CAC_ABORTED:
833 break;
834 default:
835 WARN_ON(1);
836 return;
837 }
838 wdev->cac_started = false;
839
840 nl80211_radar_notify(rdev, &chandef, event, netdev, gfp);
841}
842EXPORT_SYMBOL(cfg80211_cac_event);