blob: d8df7a5180a0473b56e74e8b4eb93b380965ea49 [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>
Johannes Berg33d87832015-06-23 17:47:05 +02005 * Copyright (c) 2015 Intel Deutschland GmbH
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
Felix Fietkauc6fb08a2012-03-18 22:58:04 +010010#include <linux/etherdevice.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011#include <linux/netdevice.h>
12#include <linux/nl80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Johannes Berga9a11622009-07-27 12:01:53 +020014#include <linux/wireless.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015#include <net/cfg80211.h>
Johannes Berga9a11622009-07-27 12:01:53 +020016#include <net/iw_handler.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020017#include "core.h"
18#include "nl80211.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030019#include "rdev-ops.h"
20
Jouni Malinen6039f6d2009-03-19 13:39:21 +020021
Johannes Berg6ff57cf2013-05-16 00:55:00 +020022void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030023 const u8 *buf, size_t len, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020024{
Johannes Berg6829c872009-07-02 09:13:27 +020025 struct wireless_dev *wdev = dev->ieee80211_ptr;
26 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080027 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020028 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030029 struct cfg80211_connect_resp_params cr;
30
31 memset(&cr, 0, sizeof(cr));
32 cr.status = (int)le16_to_cpu(mgmt->u.assoc_resp.status_code);
33 cr.bssid = mgmt->bssid;
34 cr.bss = bss;
35 cr.resp_ie = mgmt->u.assoc_resp.variable;
36 cr.resp_ie_len =
37 len - offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
38 cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED;
Johannes Berg6829c872009-07-02 09:13:27 +020039
Beni Lev4ee3e062012-08-27 12:49:39 +030040 trace_cfg80211_send_rx_assoc(dev, bss);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020041
Johannes Bergf401a6f2009-08-07 14:51:05 +020042 /*
43 * This is a bit of a hack, we don't notify userspace of
44 * a (re-)association reply if we tried to send a reassoc
45 * and got a reject -- we only try again with an assoc
46 * frame instead of reassoc.
47 */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030048 if (cfg80211_sme_rx_assoc_resp(wdev, cr.status)) {
Johannes Bergf1940c52013-06-19 13:21:15 +020049 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg5b112d32013-02-01 01:49:58 +010050 cfg80211_put_bss(wiphy, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +020051 return;
Johannes Berg95de8172012-01-20 13:55:25 +010052 }
Johannes Bergf401a6f2009-08-07 14:51:05 +020053
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030054 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL, uapsd_queues);
Johannes Bergceca7b72013-05-16 00:55:45 +020055 /* update current_bss etc., consumes the bss reference */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030056 __cfg80211_connect_result(dev, &cr, cr.status == WLAN_STATUS_SUCCESS);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020057}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020058EXPORT_SYMBOL(cfg80211_rx_assoc_resp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020059
Johannes Bergceca7b72013-05-16 00:55:45 +020060static void cfg80211_process_auth(struct wireless_dev *wdev,
61 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020062{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080063 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020064
Johannes Bergceca7b72013-05-16 00:55:45 +020065 nl80211_send_rx_auth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
66 cfg80211_sme_rx_auth(wdev, buf, len);
Johannes Berg667503d2009-07-07 03:56:11 +020067}
Jouni Malinen6039f6d2009-03-19 13:39:21 +020068
Johannes Bergceca7b72013-05-16 00:55:45 +020069static void cfg80211_process_deauth(struct wireless_dev *wdev,
70 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020071{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080072 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020073 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +020074 const u8 *bssid = mgmt->bssid;
Johannes Bergceca7b72013-05-16 00:55:45 +020075 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
76 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg6829c872009-07-02 09:13:27 +020077
Johannes Bergceca7b72013-05-16 00:55:45 +020078 nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +020079
Johannes Bergceca7b72013-05-16 00:55:45 +020080 if (!wdev->current_bss ||
81 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg596a07c2009-07-11 00:17:32 +020082 return;
Johannes Berg6829c872009-07-02 09:13:27 +020083
Johannes Bergceca7b72013-05-16 00:55:45 +020084 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
85 cfg80211_sme_deauth(wdev);
86}
Johannes Berg6829c872009-07-02 09:13:27 +020087
Johannes Bergceca7b72013-05-16 00:55:45 +020088static void cfg80211_process_disassoc(struct wireless_dev *wdev,
89 const u8 *buf, size_t len)
90{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080091 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +020092 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
93 const u8 *bssid = mgmt->bssid;
94 u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
95 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg19957bb2009-07-02 17:20:43 +020096
Johannes Bergceca7b72013-05-16 00:55:45 +020097 nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL);
98
99 if (WARN_ON(!wdev->current_bss ||
100 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
101 return;
102
103 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
104 cfg80211_sme_disassoc(wdev);
Johannes Berg667503d2009-07-07 03:56:11 +0200105}
Jouni Malinena3b8b052009-03-27 21:59:49 +0200106
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200107void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
108{
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200110 struct ieee80211_mgmt *mgmt = (void *)buf;
111
112 ASSERT_WDEV_LOCK(wdev);
113
114 trace_cfg80211_rx_mlme_mgmt(dev, buf, len);
115
116 if (WARN_ON(len < 2))
117 return;
118
Johannes Bergceca7b72013-05-16 00:55:45 +0200119 if (ieee80211_is_auth(mgmt->frame_control))
120 cfg80211_process_auth(wdev, buf, len);
121 else if (ieee80211_is_deauth(mgmt->frame_control))
122 cfg80211_process_deauth(wdev, buf, len);
123 else if (ieee80211_is_disassoc(mgmt->frame_control))
124 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200125}
126EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
127
128void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr)
Johannes Berga58ce432009-11-19 12:45:42 +0100129{
130 struct wireless_dev *wdev = dev->ieee80211_ptr;
131 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800132 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berga58ce432009-11-19 12:45:42 +0100133
Beni Lev4ee3e062012-08-27 12:49:39 +0300134 trace_cfg80211_send_auth_timeout(dev, addr);
Johannes Berga58ce432009-11-19 12:45:42 +0100135
136 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200137 cfg80211_sme_auth_timeout(wdev);
Jouni Malinen1965c852009-04-22 21:38:25 +0300138}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200139EXPORT_SYMBOL(cfg80211_auth_timeout);
Jouni Malinen1965c852009-04-22 21:38:25 +0300140
Johannes Berg959867f2013-06-19 13:05:42 +0200141void cfg80211_assoc_timeout(struct net_device *dev, struct cfg80211_bss *bss)
Jouni Malinen1965c852009-04-22 21:38:25 +0300142{
Johannes Berg6829c872009-07-02 09:13:27 +0200143 struct wireless_dev *wdev = dev->ieee80211_ptr;
144 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800145 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200146
Johannes Berg959867f2013-06-19 13:05:42 +0200147 trace_cfg80211_send_assoc_timeout(dev, bss->bssid);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200148
Johannes Berg959867f2013-06-19 13:05:42 +0200149 nl80211_send_assoc_timeout(rdev, dev, bss->bssid, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200150 cfg80211_sme_assoc_timeout(wdev);
Johannes Berg959867f2013-06-19 13:05:42 +0200151
Johannes Bergf1940c52013-06-19 13:21:15 +0200152 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg959867f2013-06-19 13:05:42 +0200153 cfg80211_put_bss(wiphy, bss);
Jouni Malinen1965c852009-04-22 21:38:25 +0300154}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200155EXPORT_SYMBOL(cfg80211_assoc_timeout);
156
Johannes Berge6f462d2016-12-08 17:22:09 +0100157void cfg80211_abandon_assoc(struct net_device *dev, struct cfg80211_bss *bss)
158{
159 struct wireless_dev *wdev = dev->ieee80211_ptr;
160 struct wiphy *wiphy = wdev->wiphy;
161
162 cfg80211_sme_abandon_assoc(wdev);
163
164 cfg80211_unhold_bss(bss_from_pub(bss));
165 cfg80211_put_bss(wiphy, bss);
166}
167EXPORT_SYMBOL(cfg80211_abandon_assoc);
168
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200169void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
170{
171 struct wireless_dev *wdev = dev->ieee80211_ptr;
172 struct ieee80211_mgmt *mgmt = (void *)buf;
173
174 ASSERT_WDEV_LOCK(wdev);
175
176 trace_cfg80211_tx_mlme_mgmt(dev, buf, len);
177
178 if (WARN_ON(len < 2))
179 return;
180
181 if (ieee80211_is_deauth(mgmt->frame_control))
Johannes Bergceca7b72013-05-16 00:55:45 +0200182 cfg80211_process_deauth(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200183 else
Johannes Bergceca7b72013-05-16 00:55:45 +0200184 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200185}
186EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt);
Jouni Malinen1965c852009-04-22 21:38:25 +0300187
Jouni Malinena3b8b052009-03-27 21:59:49 +0200188void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
189 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +0200190 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +0200191{
192 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800193 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg3d23e342009-09-29 23:27:28 +0200194#ifdef CONFIG_CFG80211_WEXT
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200195 union iwreq_data wrqu;
Johannes Berge6d6e342009-07-01 21:26:47 +0200196 char *buf = kmalloc(128, gfp);
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200197
198 if (buf) {
199 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
200 "keyid=%d %scast addr=%pM)", key_id,
201 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
202 addr);
203 memset(&wrqu, 0, sizeof(wrqu));
204 wrqu.data.length = strlen(buf);
205 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
206 kfree(buf);
207 }
208#endif
209
Beni Lev4ee3e062012-08-27 12:49:39 +0300210 trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc);
Johannes Berge6d6e342009-07-01 21:26:47 +0200211 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200212}
213EXPORT_SYMBOL(cfg80211_michael_mic_failure);
Johannes Berg19957bb2009-07-02 17:20:43 +0200214
215/* some MLME handling for userspace SME */
Johannes Berg91bf9b22013-05-15 17:44:01 +0200216int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
217 struct net_device *dev,
218 struct ieee80211_channel *chan,
219 enum nl80211_auth_type auth_type,
220 const u8 *bssid,
221 const u8 *ssid, int ssid_len,
222 const u8 *ie, int ie_len,
223 const u8 *key, int key_len, int key_idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300224 const u8 *auth_data, int auth_data_len)
Johannes Berg19957bb2009-07-02 17:20:43 +0200225{
226 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200227 struct cfg80211_auth_request req = {
228 .ie = ie,
229 .ie_len = ie_len,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300230 .auth_data = auth_data,
231 .auth_data_len = auth_data_len,
Johannes Berg7ade7032013-05-13 11:37:30 +0200232 .auth_type = auth_type,
233 .key = key,
234 .key_len = key_len,
235 .key_idx = key_idx,
236 };
Johannes Berg95de8172012-01-20 13:55:25 +0100237 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200238
Johannes Berg667503d2009-07-07 03:56:11 +0200239 ASSERT_WDEV_LOCK(wdev);
240
Johannes Bergfffd0932009-07-08 14:22:54 +0200241 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
Johannes Bergb6b55552016-09-13 16:25:58 +0200242 if (!key || !key_len || key_idx < 0 || key_idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200243 return -EINVAL;
244
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200245 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000246 ether_addr_equal(bssid, wdev->current_bss->pub.bssid))
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200247 return -EALREADY;
248
Johannes Berg19957bb2009-07-02 17:20:43 +0200249 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200250 IEEE80211_BSS_TYPE_ESS,
251 IEEE80211_PRIVACY_ANY);
Johannes Berg19957bb2009-07-02 17:20:43 +0200252 if (!req.bss)
253 return -ENOENT;
254
Hila Gonene35e4d22012-06-27 17:19:42 +0300255 err = rdev_auth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200256
Johannes Berg5b112d32013-02-01 01:49:58 +0100257 cfg80211_put_bss(&rdev->wiphy, req.bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200258 return err;
259}
260
Ben Greear7e7c8922011-11-18 11:31:59 -0800261/* Do a logical ht_capa &= ht_capa_mask. */
262void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
263 const struct ieee80211_ht_cap *ht_capa_mask)
264{
265 int i;
266 u8 *p1, *p2;
267 if (!ht_capa_mask) {
268 memset(ht_capa, 0, sizeof(*ht_capa));
269 return;
270 }
271
272 p1 = (u8*)(ht_capa);
273 p2 = (u8*)(ht_capa_mask);
274 for (i = 0; i<sizeof(*ht_capa); i++)
275 p1[i] &= p2[i];
276}
277
Johannes Bergee2aca32013-02-21 17:36:01 +0100278/* Do a logical ht_capa &= ht_capa_mask. */
279void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
280 const struct ieee80211_vht_cap *vht_capa_mask)
281{
282 int i;
283 u8 *p1, *p2;
284 if (!vht_capa_mask) {
285 memset(vht_capa, 0, sizeof(*vht_capa));
286 return;
287 }
288
289 p1 = (u8*)(vht_capa);
290 p2 = (u8*)(vht_capa_mask);
291 for (i = 0; i < sizeof(*vht_capa); i++)
292 p1[i] &= p2[i];
293}
294
Johannes Berg91bf9b22013-05-15 17:44:01 +0200295int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
296 struct net_device *dev,
297 struct ieee80211_channel *chan,
298 const u8 *bssid,
299 const u8 *ssid, int ssid_len,
300 struct cfg80211_assoc_request *req)
Johannes Berg19957bb2009-07-02 17:20:43 +0200301{
302 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100303 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200304
Johannes Berg667503d2009-07-07 03:56:11 +0200305 ASSERT_WDEV_LOCK(wdev);
306
Johannes Bergceca7b72013-05-16 00:55:45 +0200307 if (wdev->current_bss &&
308 (!req->prev_bssid || !ether_addr_equal(wdev->current_bss->pub.bssid,
309 req->prev_bssid)))
Johannes Berg19957bb2009-07-02 17:20:43 +0200310 return -EALREADY;
311
Johannes Bergf62fab72013-02-21 20:09:09 +0100312 cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
Ben Greear7e7c8922011-11-18 11:31:59 -0800313 rdev->wiphy.ht_capa_mod_mask);
Johannes Bergf62fab72013-02-21 20:09:09 +0100314 cfg80211_oper_and_vht_capa(&req->vht_capa_mask,
Johannes Bergee2aca32013-02-21 17:36:01 +0100315 rdev->wiphy.vht_capa_mod_mask);
Ben Greear7e7c8922011-11-18 11:31:59 -0800316
Johannes Bergf62fab72013-02-21 20:09:09 +0100317 req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200318 IEEE80211_BSS_TYPE_ESS,
319 IEEE80211_PRIVACY_ANY);
Johannes Bergceca7b72013-05-16 00:55:45 +0200320 if (!req->bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200321 return -ENOENT;
322
Johannes Bergf62fab72013-02-21 20:09:09 +0100323 err = rdev_assoc(rdev, dev, req);
Johannes Bergf1940c52013-06-19 13:21:15 +0200324 if (!err)
325 cfg80211_hold_bss(bss_from_pub(req->bss));
Luciano Coelho73de86a2014-02-13 11:31:59 +0200326 else
Johannes Bergf62fab72013-02-21 20:09:09 +0100327 cfg80211_put_bss(&rdev->wiphy, req->bss);
Johannes Berg95de8172012-01-20 13:55:25 +0100328
Johannes Berg19957bb2009-07-02 17:20:43 +0200329 return err;
330}
331
Johannes Berg91bf9b22013-05-15 17:44:01 +0200332int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
333 struct net_device *dev, const u8 *bssid,
334 const u8 *ie, int ie_len, u16 reason,
335 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200336{
337 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100338 struct cfg80211_deauth_request req = {
339 .bssid = bssid,
340 .reason_code = reason,
341 .ie = ie,
342 .ie_len = ie_len,
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200343 .local_state_change = local_state_change,
Johannes Berg95de8172012-01-20 13:55:25 +0100344 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200345
Johannes Berg667503d2009-07-07 03:56:11 +0200346 ASSERT_WDEV_LOCK(wdev);
347
Johannes Bergceca7b72013-05-16 00:55:45 +0200348 if (local_state_change &&
349 (!wdev->current_bss ||
350 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
Johannes Berg95de8172012-01-20 13:55:25 +0100351 return 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200352
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500353 if (ether_addr_equal(wdev->disconnect_bssid, bssid) ||
354 (wdev->current_bss &&
355 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
356 wdev->conn_owner_nlportid = 0;
357
Hila Gonene35e4d22012-06-27 17:19:42 +0300358 return rdev_deauth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200359}
360
Johannes Berg91bf9b22013-05-15 17:44:01 +0200361int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
362 struct net_device *dev, const u8 *bssid,
363 const u8 *ie, int ie_len, u16 reason,
364 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200365{
366 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200367 struct cfg80211_disassoc_request req = {
368 .reason_code = reason,
369 .local_state_change = local_state_change,
370 .ie = ie,
371 .ie_len = ie_len,
372 };
Johannes Bergceca7b72013-05-16 00:55:45 +0200373 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200374
Johannes Berg667503d2009-07-07 03:56:11 +0200375 ASSERT_WDEV_LOCK(wdev);
376
Johannes Bergceca7b72013-05-16 00:55:45 +0200377 if (!wdev->current_bss)
Johannes Bergf9d6b402009-07-27 10:22:28 +0200378 return -ENOTCONN;
379
Joe Perchesac422d32012-05-08 18:56:55 +0000380 if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg19957bb2009-07-02 17:20:43 +0200381 req.bss = &wdev->current_bss->pub;
382 else
383 return -ENOTCONN;
384
Johannes Bergceca7b72013-05-16 00:55:45 +0200385 err = rdev_disassoc(rdev, dev, &req);
386 if (err)
387 return err;
388
389 /* driver should have reported the disassoc */
390 WARN_ON(wdev->current_bss);
391 return 0;
Johannes Berg667503d2009-07-07 03:56:11 +0200392}
393
Johannes Berg19957bb2009-07-02 17:20:43 +0200394void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
395 struct net_device *dev)
396{
397 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100398 u8 bssid[ETH_ALEN];
Johannes Berg19957bb2009-07-02 17:20:43 +0200399
Johannes Berg667503d2009-07-07 03:56:11 +0200400 ASSERT_WDEV_LOCK(wdev);
401
Johannes Berg19957bb2009-07-02 17:20:43 +0200402 if (!rdev->ops->deauth)
403 return;
404
Johannes Berg95de8172012-01-20 13:55:25 +0100405 if (!wdev->current_bss)
406 return;
Johannes Berg19957bb2009-07-02 17:20:43 +0200407
Johannes Berg95de8172012-01-20 13:55:25 +0100408 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
Johannes Bergceca7b72013-05-16 00:55:45 +0200409 cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
410 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200411}
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100412
Johannes Berg2e161f782010-08-12 15:38:38 +0200413struct cfg80211_mgmt_registration {
Jouni Malinen026331c2010-02-15 12:53:10 +0200414 struct list_head list;
Johannes Berg33d87832015-06-23 17:47:05 +0200415 struct wireless_dev *wdev;
Jouni Malinen026331c2010-02-15 12:53:10 +0200416
Eric W. Biederman15e47302012-09-07 20:12:54 +0000417 u32 nlportid;
Jouni Malinen026331c2010-02-15 12:53:10 +0200418
419 int match_len;
420
Johannes Berg2e161f782010-08-12 15:38:38 +0200421 __le16 frame_type;
422
Jouni Malinen026331c2010-02-15 12:53:10 +0200423 u8 match[];
424};
425
Johannes Berg33d87832015-06-23 17:47:05 +0200426static void
427cfg80211_process_mlme_unregistrations(struct cfg80211_registered_device *rdev)
428{
429 struct cfg80211_mgmt_registration *reg;
430
431 ASSERT_RTNL();
432
433 spin_lock_bh(&rdev->mlme_unreg_lock);
434 while ((reg = list_first_entry_or_null(&rdev->mlme_unreg,
435 struct cfg80211_mgmt_registration,
436 list))) {
437 list_del(&reg->list);
438 spin_unlock_bh(&rdev->mlme_unreg_lock);
439
440 if (rdev->ops->mgmt_frame_register) {
441 u16 frame_type = le16_to_cpu(reg->frame_type);
442
443 rdev_mgmt_frame_register(rdev, reg->wdev,
444 frame_type, false);
445 }
446
447 kfree(reg);
448
449 spin_lock_bh(&rdev->mlme_unreg_lock);
450 }
451 spin_unlock_bh(&rdev->mlme_unreg_lock);
452}
453
454void cfg80211_mlme_unreg_wk(struct work_struct *wk)
455{
456 struct cfg80211_registered_device *rdev;
457
458 rdev = container_of(wk, struct cfg80211_registered_device,
459 mlme_unreg_wk);
460
461 rtnl_lock();
462 cfg80211_process_mlme_unregistrations(rdev);
463 rtnl_unlock();
464}
465
Eric W. Biederman15e47302012-09-07 20:12:54 +0000466int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Johannes Berg2e161f782010-08-12 15:38:38 +0200467 u16 frame_type, const u8 *match_data,
468 int match_len)
Jouni Malinen026331c2010-02-15 12:53:10 +0200469{
Johannes Berg271733c2010-10-13 12:06:23 +0200470 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800471 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200472 struct cfg80211_mgmt_registration *reg, *nreg;
Jouni Malinen026331c2010-02-15 12:53:10 +0200473 int err = 0;
Johannes Berg2e161f782010-08-12 15:38:38 +0200474 u16 mgmt_type;
475
476 if (!wdev->wiphy->mgmt_stypes)
477 return -EOPNOTSUPP;
478
479 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
480 return -EINVAL;
481
482 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
483 return -EINVAL;
484
485 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
486 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
487 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +0200488
489 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
490 if (!nreg)
491 return -ENOMEM;
492
Johannes Berg2e161f782010-08-12 15:38:38 +0200493 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200494
Johannes Berg2e161f782010-08-12 15:38:38 +0200495 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200496 int mlen = min(match_len, reg->match_len);
497
Johannes Berg2e161f782010-08-12 15:38:38 +0200498 if (frame_type != le16_to_cpu(reg->frame_type))
499 continue;
500
Jouni Malinen026331c2010-02-15 12:53:10 +0200501 if (memcmp(reg->match, match_data, mlen) == 0) {
502 err = -EALREADY;
503 break;
504 }
505 }
506
507 if (err) {
508 kfree(nreg);
509 goto out;
510 }
511
512 memcpy(nreg->match, match_data, match_len);
513 nreg->match_len = match_len;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000514 nreg->nlportid = snd_portid;
Johannes Berg2e161f782010-08-12 15:38:38 +0200515 nreg->frame_type = cpu_to_le16(frame_type);
Johannes Berg33d87832015-06-23 17:47:05 +0200516 nreg->wdev = wdev;
Johannes Berg2e161f782010-08-12 15:38:38 +0200517 list_add(&nreg->list, &wdev->mgmt_registrations);
Johannes Berg33d87832015-06-23 17:47:05 +0200518 spin_unlock_bh(&wdev->mgmt_registrations_lock);
519
520 /* process all unregistrations to avoid driver confusion */
521 cfg80211_process_mlme_unregistrations(rdev);
Jouni Malinen026331c2010-02-15 12:53:10 +0200522
Johannes Berg271733c2010-10-13 12:06:23 +0200523 if (rdev->ops->mgmt_frame_register)
Hila Gonene35e4d22012-06-27 17:19:42 +0300524 rdev_mgmt_frame_register(rdev, wdev, frame_type, true);
Johannes Berg271733c2010-10-13 12:06:23 +0200525
Johannes Berg33d87832015-06-23 17:47:05 +0200526 return 0;
527
Jouni Malinen026331c2010-02-15 12:53:10 +0200528 out:
Johannes Berg2e161f782010-08-12 15:38:38 +0200529 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg271733c2010-10-13 12:06:23 +0200530
Jouni Malinen026331c2010-02-15 12:53:10 +0200531 return err;
532}
533
Eric W. Biederman15e47302012-09-07 20:12:54 +0000534void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid)
Jouni Malinen026331c2010-02-15 12:53:10 +0200535{
Johannes Berg271733c2010-10-13 12:06:23 +0200536 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800537 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200538 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200539
Johannes Berg2e161f782010-08-12 15:38:38 +0200540 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200541
Johannes Berg2e161f782010-08-12 15:38:38 +0200542 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000543 if (reg->nlportid != nlportid)
Johannes Berg271733c2010-10-13 12:06:23 +0200544 continue;
545
Johannes Berg271733c2010-10-13 12:06:23 +0200546 list_del(&reg->list);
Johannes Berg33d87832015-06-23 17:47:05 +0200547 spin_lock(&rdev->mlme_unreg_lock);
548 list_add_tail(&reg->list, &rdev->mlme_unreg);
549 spin_unlock(&rdev->mlme_unreg_lock);
550
551 schedule_work(&rdev->mlme_unreg_wk);
Jouni Malinen026331c2010-02-15 12:53:10 +0200552 }
553
Johannes Berg2e161f782010-08-12 15:38:38 +0200554 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg28946da2011-11-04 11:18:12 +0100555
Arend van Spriel5de17982013-04-18 15:49:00 +0200556 if (nlportid && rdev->crit_proto_nlportid == nlportid) {
557 rdev->crit_proto_nlportid = 0;
558 rdev_crit_proto_stop(rdev, wdev);
559 }
560
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561 if (nlportid == wdev->ap_unexpected_nlportid)
562 wdev->ap_unexpected_nlportid = 0;
Jouni Malinen026331c2010-02-15 12:53:10 +0200563}
564
Johannes Berg2e161f782010-08-12 15:38:38 +0200565void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
Jouni Malinen026331c2010-02-15 12:53:10 +0200566{
Johannes Berg33d87832015-06-23 17:47:05 +0200567 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen026331c2010-02-15 12:53:10 +0200568
Johannes Berg2e161f782010-08-12 15:38:38 +0200569 spin_lock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg33d87832015-06-23 17:47:05 +0200570 spin_lock(&rdev->mlme_unreg_lock);
571 list_splice_tail_init(&wdev->mgmt_registrations, &rdev->mlme_unreg);
572 spin_unlock(&rdev->mlme_unreg_lock);
Johannes Berg2e161f782010-08-12 15:38:38 +0200573 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg33d87832015-06-23 17:47:05 +0200574
575 cfg80211_process_mlme_unregistrations(rdev);
Jouni Malinen026331c2010-02-15 12:53:10 +0200576}
577
Johannes Berg2e161f782010-08-12 15:38:38 +0200578int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200579 struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200580 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +0200581{
Jouni Malinen026331c2010-02-15 12:53:10 +0200582 const struct ieee80211_mgmt *mgmt;
Johannes Berg2e161f782010-08-12 15:38:38 +0200583 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200584
Johannes Berg2e161f782010-08-12 15:38:38 +0200585 if (!wdev->wiphy->mgmt_stypes)
Jouni Malinen026331c2010-02-15 12:53:10 +0200586 return -EOPNOTSUPP;
Johannes Berg2e161f782010-08-12 15:38:38 +0200587
588 if (!rdev->ops->mgmt_tx)
589 return -EOPNOTSUPP;
590
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200591 if (params->len < 24 + 1)
Jouni Malinen026331c2010-02-15 12:53:10 +0200592 return -EINVAL;
593
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200594 mgmt = (const struct ieee80211_mgmt *)params->buf;
Johannes Berg2e161f782010-08-12 15:38:38 +0200595
596 if (!ieee80211_is_mgmt(mgmt->frame_control))
Jouni Malinen026331c2010-02-15 12:53:10 +0200597 return -EINVAL;
Johannes Berg2e161f782010-08-12 15:38:38 +0200598
599 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
600 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
601 return -EINVAL;
602
603 if (ieee80211_is_action(mgmt->frame_control) &&
604 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200605 int err = 0;
606
Johannes Bergfe100ac2010-08-09 15:52:03 +0200607 wdev_lock(wdev);
608
Johannes Berg663fcaf2010-09-30 21:06:09 +0200609 switch (wdev->iftype) {
610 case NL80211_IFTYPE_ADHOC:
611 case NL80211_IFTYPE_STATION:
612 case NL80211_IFTYPE_P2P_CLIENT:
613 if (!wdev->current_bss) {
614 err = -ENOTCONN;
615 break;
616 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200617
Joe Perchesac422d32012-05-08 18:56:55 +0000618 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
619 mgmt->bssid)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200620 err = -ENOTCONN;
621 break;
622 }
623
624 /*
625 * check for IBSS DA must be done by driver as
626 * cfg80211 doesn't track the stations
627 */
628 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
629 break;
630
631 /* for station, check that DA is the AP */
Joe Perchesac422d32012-05-08 18:56:55 +0000632 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
633 mgmt->da)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200634 err = -ENOTCONN;
635 break;
636 }
637 break;
638 case NL80211_IFTYPE_AP:
639 case NL80211_IFTYPE_P2P_GO:
640 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg98104fde2012-06-16 00:19:54 +0200641 if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev)))
Johannes Berg663fcaf2010-09-30 21:06:09 +0200642 err = -EINVAL;
643 break;
Javier Cardona0778a6a2011-05-03 16:57:08 -0700644 case NL80211_IFTYPE_MESH_POINT:
Joe Perchesac422d32012-05-08 18:56:55 +0000645 if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) {
Javier Cardona0778a6a2011-05-03 16:57:08 -0700646 err = -EINVAL;
647 break;
648 }
649 /*
650 * check for mesh DA must be done by driver as
651 * cfg80211 doesn't track the stations
652 */
653 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200654 case NL80211_IFTYPE_P2P_DEVICE:
655 /*
656 * fall through, P2P device only supports
657 * public action frames
658 */
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300659 case NL80211_IFTYPE_NAN:
Johannes Berg663fcaf2010-09-30 21:06:09 +0200660 default:
661 err = -EOPNOTSUPP;
662 break;
663 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200664 wdev_unlock(wdev);
Johannes Berg663fcaf2010-09-30 21:06:09 +0200665
666 if (err)
667 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +0200668 }
669
vamsi krishnaab5bb2d2017-01-13 01:12:19 +0200670 if (!ether_addr_equal(mgmt->sa, wdev_address(wdev))) {
671 /* Allow random TA to be used with Public Action frames if the
672 * driver has indicated support for this. Otherwise, only allow
673 * the local address to be used.
674 */
675 if (!ieee80211_is_action(mgmt->frame_control) ||
676 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
677 return -EINVAL;
678 if (!wdev->current_bss &&
679 !wiphy_ext_feature_isset(
680 &rdev->wiphy,
681 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
682 return -EINVAL;
683 if (wdev->current_bss &&
684 !wiphy_ext_feature_isset(
685 &rdev->wiphy,
686 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
687 return -EINVAL;
688 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200689
690 /* Transmit the Action frame as requested by user space */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200691 return rdev_mgmt_tx(rdev, wdev, params, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +0200692}
693
Johannes Berg71bbc992012-06-15 15:30:18 +0200694bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700695 const u8 *buf, size_t len, u32 flags)
Jouni Malinen026331c2010-02-15 12:53:10 +0200696{
Jouni Malinen026331c2010-02-15 12:53:10 +0200697 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800698 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200699 struct cfg80211_mgmt_registration *reg;
700 const struct ieee80211_txrx_stypes *stypes =
701 &wiphy->mgmt_stypes[wdev->iftype];
702 struct ieee80211_mgmt *mgmt = (void *)buf;
703 const u8 *data;
704 int data_len;
Jouni Malinen026331c2010-02-15 12:53:10 +0200705 bool result = false;
Johannes Berg2e161f782010-08-12 15:38:38 +0200706 __le16 ftype = mgmt->frame_control &
707 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
708 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200709
Beni Lev4ee3e062012-08-27 12:49:39 +0300710 trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm);
Johannes Berg2e161f782010-08-12 15:38:38 +0200711 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
Jouni Malinen026331c2010-02-15 12:53:10 +0200712
Beni Lev4ee3e062012-08-27 12:49:39 +0300713 if (!(stypes->rx & BIT(stype))) {
714 trace_cfg80211_return_bool(false);
Johannes Berg2e161f782010-08-12 15:38:38 +0200715 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +0300716 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200717
Johannes Berg2e161f782010-08-12 15:38:38 +0200718 data = buf + ieee80211_hdrlen(mgmt->frame_control);
719 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
Jouni Malinen026331c2010-02-15 12:53:10 +0200720
Johannes Berg2e161f782010-08-12 15:38:38 +0200721 spin_lock_bh(&wdev->mgmt_registrations_lock);
722
723 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
724 if (reg->frame_type != ftype)
Jouni Malinen026331c2010-02-15 12:53:10 +0200725 continue;
726
Johannes Berg2e161f782010-08-12 15:38:38 +0200727 if (reg->match_len > data_len)
728 continue;
729
730 if (memcmp(reg->match, data, reg->match_len))
Jouni Malinen026331c2010-02-15 12:53:10 +0200731 continue;
732
733 /* found match! */
734
735 /* Indicate the received Action frame to user space */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000736 if (nl80211_send_mgmt(rdev, wdev, reg->nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +0100737 freq, sig_mbm,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700738 buf, len, flags, GFP_ATOMIC))
Jouni Malinen026331c2010-02-15 12:53:10 +0200739 continue;
740
741 result = true;
742 break;
743 }
744
Johannes Berg2e161f782010-08-12 15:38:38 +0200745 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200746
Beni Lev4ee3e062012-08-27 12:49:39 +0300747 trace_cfg80211_return_bool(result);
Jouni Malinen026331c2010-02-15 12:53:10 +0200748 return result;
749}
Johannes Berg2e161f782010-08-12 15:38:38 +0200750EXPORT_SYMBOL(cfg80211_rx_mgmt);
Jouni Malinen026331c2010-02-15 12:53:10 +0200751
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530752void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev)
753{
754 cancel_delayed_work(&rdev->dfs_update_channels_wk);
755 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, 0);
756}
757
Simon Wunderlich04f39042013-02-08 18:16:19 +0100758void cfg80211_dfs_channels_update_work(struct work_struct *work)
759{
Geliang Tanga85a7e22016-01-01 23:48:52 +0800760 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100761 struct cfg80211_registered_device *rdev;
762 struct cfg80211_chan_def chandef;
763 struct ieee80211_supported_band *sband;
764 struct ieee80211_channel *c;
765 struct wiphy *wiphy;
766 bool check_again = false;
767 unsigned long timeout, next_time = 0;
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530768 unsigned long time_dfs_update;
769 enum nl80211_radar_event radar_event;
Simon Wunderlich04f39042013-02-08 18:16:19 +0100770 int bandid, i;
771
Simon Wunderlich04f39042013-02-08 18:16:19 +0100772 rdev = container_of(delayed_work, struct cfg80211_registered_device,
773 dfs_update_channels_wk);
774 wiphy = &rdev->wiphy;
775
Johannes Berg5fe231e2013-05-08 21:45:15 +0200776 rtnl_lock();
Johannes Berg57fbcce2016-04-12 15:56:15 +0200777 for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) {
Simon Wunderlich04f39042013-02-08 18:16:19 +0100778 sband = wiphy->bands[bandid];
779 if (!sband)
780 continue;
781
782 for (i = 0; i < sband->n_channels; i++) {
783 c = &sband->channels[i];
784
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530785 if (!(c->flags & IEEE80211_CHAN_RADAR))
Simon Wunderlich04f39042013-02-08 18:16:19 +0100786 continue;
787
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530788 if (c->dfs_state != NL80211_DFS_UNAVAILABLE &&
789 c->dfs_state != NL80211_DFS_AVAILABLE)
790 continue;
791
792 if (c->dfs_state == NL80211_DFS_UNAVAILABLE) {
793 time_dfs_update = IEEE80211_DFS_MIN_NOP_TIME_MS;
794 radar_event = NL80211_RADAR_NOP_FINISHED;
795 } else {
796 if (regulatory_pre_cac_allowed(wiphy) ||
797 cfg80211_any_wiphy_oper_chan(wiphy, c))
798 continue;
799
800 time_dfs_update = REG_PRE_CAC_EXPIRY_GRACE_MS;
801 radar_event = NL80211_RADAR_PRE_CAC_EXPIRED;
802 }
803
804 timeout = c->dfs_state_entered +
805 msecs_to_jiffies(time_dfs_update);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100806
807 if (time_after_eq(jiffies, timeout)) {
808 c->dfs_state = NL80211_DFS_USABLE;
Michal Kaziorbbe09bb2013-10-17 11:21:12 -0700809 c->dfs_state_entered = jiffies;
810
Simon Wunderlich04f39042013-02-08 18:16:19 +0100811 cfg80211_chandef_create(&chandef, c,
812 NL80211_CHAN_NO_HT);
813
814 nl80211_radar_notify(rdev, &chandef,
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530815 radar_event, NULL,
816 GFP_ATOMIC);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530817
818 regulatory_propagate_dfs_state(wiphy, &chandef,
819 c->dfs_state,
820 radar_event);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100821 continue;
822 }
823
824 if (!check_again)
825 next_time = timeout - jiffies;
826 else
827 next_time = min(next_time, timeout - jiffies);
828 check_again = true;
829 }
830 }
Johannes Berg5fe231e2013-05-08 21:45:15 +0200831 rtnl_unlock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100832
833 /* reschedule if there are other channels waiting to be cleared again */
834 if (check_again)
835 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
836 next_time);
837}
838
839
840void cfg80211_radar_event(struct wiphy *wiphy,
841 struct cfg80211_chan_def *chandef,
842 gfp_t gfp)
843{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800844 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100845
846 trace_cfg80211_radar_event(wiphy, chandef);
847
848 /* only set the chandef supplied channel to unavailable, in
849 * case the radar is detected on only one of multiple channels
850 * spanned by the chandef.
851 */
852 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE);
853
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530854 cfg80211_sched_dfs_chan_update(rdev);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100855
856 nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530857
858 memcpy(&rdev->radar_chandef, chandef, sizeof(struct cfg80211_chan_def));
859 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100860}
861EXPORT_SYMBOL(cfg80211_radar_event);
862
863void cfg80211_cac_event(struct net_device *netdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100864 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +0100865 enum nl80211_radar_event event, gfp_t gfp)
866{
867 struct wireless_dev *wdev = netdev->ieee80211_ptr;
868 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800869 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100870 unsigned long timeout;
871
872 trace_cfg80211_cac_event(netdev, event);
873
874 if (WARN_ON(!wdev->cac_started))
875 return;
876
Michal Kazior9e0e2962014-01-29 14:22:27 +0100877 if (WARN_ON(!wdev->chandef.chan))
Simon Wunderlich04f39042013-02-08 18:16:19 +0100878 return;
879
Simon Wunderlich04f39042013-02-08 18:16:19 +0100880 switch (event) {
881 case NL80211_RADAR_CAC_FINISHED:
882 timeout = wdev->cac_start_time +
Janusz Dziedzic31559f32014-02-21 19:46:13 +0100883 msecs_to_jiffies(wdev->cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100884 WARN_ON(!time_after_eq(jiffies, timeout));
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100885 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530886 memcpy(&rdev->cac_done_chandef, chandef,
887 sizeof(struct cfg80211_chan_def));
888 queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530889 cfg80211_sched_dfs_chan_update(rdev);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100890 break;
891 case NL80211_RADAR_CAC_ABORTED:
892 break;
893 default:
894 WARN_ON(1);
895 return;
896 }
897 wdev->cac_started = false;
898
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100899 nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100900}
901EXPORT_SYMBOL(cfg80211_cac_event);