blob: f9462010575f516184e5b7d2221fca1729696ad9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jouni Malinen6039f6d2009-03-19 13:39:21 +02002/*
3 * cfg80211 MLME SAP interface
4 *
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
Johannes Berg33d87832015-06-23 17:47:05 +02006 * Copyright (c) 2015 Intel Deutschland GmbH
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
Felix Fietkauc6fb08a2012-03-18 22:58:04 +010011#include <linux/etherdevice.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012#include <linux/netdevice.h>
13#include <linux/nl80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Johannes Berga9a11622009-07-27 12:01:53 +020015#include <linux/wireless.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020016#include <net/cfg80211.h>
Johannes Berga9a11622009-07-27 12:01:53 +020017#include <net/iw_handler.h>
Jouni Malinen6039f6d2009-03-19 13:39:21 +020018#include "core.h"
19#include "nl80211.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030020#include "rdev-ops.h"
21
Jouni Malinen6039f6d2009-03-19 13:39:21 +020022
Johannes Berg6ff57cf2013-05-16 00:55:00 +020023void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020024 const u8 *buf, size_t len, int uapsd_queues,
25 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020026{
Johannes Berg6829c872009-07-02 09:13:27 +020027 struct wireless_dev *wdev = dev->ieee80211_ptr;
28 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080029 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020030 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030031 struct cfg80211_connect_resp_params cr;
32
33 memset(&cr, 0, sizeof(cr));
34 cr.status = (int)le16_to_cpu(mgmt->u.assoc_resp.status_code);
35 cr.bssid = mgmt->bssid;
36 cr.bss = bss;
Jouni Malinen4d9ec732019-02-15 02:14:33 +020037 cr.req_ie = req_ies;
38 cr.req_ie_len = req_ies_len;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030039 cr.resp_ie = mgmt->u.assoc_resp.variable;
40 cr.resp_ie_len =
41 len - offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
42 cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED;
Johannes Berg6829c872009-07-02 09:13:27 +020043
Beni Lev4ee3e062012-08-27 12:49:39 +030044 trace_cfg80211_send_rx_assoc(dev, bss);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020045
Johannes Bergf401a6f2009-08-07 14:51:05 +020046 /*
47 * This is a bit of a hack, we don't notify userspace of
48 * a (re-)association reply if we tried to send a reassoc
49 * and got a reject -- we only try again with an assoc
50 * frame instead of reassoc.
51 */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030052 if (cfg80211_sme_rx_assoc_resp(wdev, cr.status)) {
Johannes Bergf1940c52013-06-19 13:21:15 +020053 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg5b112d32013-02-01 01:49:58 +010054 cfg80211_put_bss(wiphy, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +020055 return;
Johannes Berg95de8172012-01-20 13:55:25 +010056 }
Johannes Bergf401a6f2009-08-07 14:51:05 +020057
Jouni Malinen4d9ec732019-02-15 02:14:33 +020058 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL, uapsd_queues,
59 req_ies, req_ies_len);
Johannes Bergceca7b72013-05-16 00:55:45 +020060 /* update current_bss etc., consumes the bss reference */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030061 __cfg80211_connect_result(dev, &cr, cr.status == WLAN_STATUS_SUCCESS);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020062}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020063EXPORT_SYMBOL(cfg80211_rx_assoc_resp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020064
Johannes Bergceca7b72013-05-16 00:55:45 +020065static void cfg80211_process_auth(struct wireless_dev *wdev,
66 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020067{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080068 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020069
Johannes Bergceca7b72013-05-16 00:55:45 +020070 nl80211_send_rx_auth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
71 cfg80211_sme_rx_auth(wdev, buf, len);
Johannes Berg667503d2009-07-07 03:56:11 +020072}
Jouni Malinen6039f6d2009-03-19 13:39:21 +020073
Johannes Bergceca7b72013-05-16 00:55:45 +020074static void cfg80211_process_deauth(struct wireless_dev *wdev,
75 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020076{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080077 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020078 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +020079 const u8 *bssid = mgmt->bssid;
Johannes Bergceca7b72013-05-16 00:55:45 +020080 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
81 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg6829c872009-07-02 09:13:27 +020082
Johannes Bergceca7b72013-05-16 00:55:45 +020083 nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +020084
Johannes Bergceca7b72013-05-16 00:55:45 +020085 if (!wdev->current_bss ||
86 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg596a07c2009-07-11 00:17:32 +020087 return;
Johannes Berg6829c872009-07-02 09:13:27 +020088
Johannes Bergceca7b72013-05-16 00:55:45 +020089 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
90 cfg80211_sme_deauth(wdev);
91}
Johannes Berg6829c872009-07-02 09:13:27 +020092
Johannes Bergceca7b72013-05-16 00:55:45 +020093static void cfg80211_process_disassoc(struct wireless_dev *wdev,
94 const u8 *buf, size_t len)
95{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080096 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +020097 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
98 const u8 *bssid = mgmt->bssid;
99 u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
100 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg19957bb2009-07-02 17:20:43 +0200101
Johannes Bergceca7b72013-05-16 00:55:45 +0200102 nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL);
103
104 if (WARN_ON(!wdev->current_bss ||
105 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
106 return;
107
108 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
109 cfg80211_sme_disassoc(wdev);
Johannes Berg667503d2009-07-07 03:56:11 +0200110}
Jouni Malinena3b8b052009-03-27 21:59:49 +0200111
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200112void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
113{
114 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200115 struct ieee80211_mgmt *mgmt = (void *)buf;
116
117 ASSERT_WDEV_LOCK(wdev);
118
119 trace_cfg80211_rx_mlme_mgmt(dev, buf, len);
120
121 if (WARN_ON(len < 2))
122 return;
123
Johannes Bergceca7b72013-05-16 00:55:45 +0200124 if (ieee80211_is_auth(mgmt->frame_control))
125 cfg80211_process_auth(wdev, buf, len);
126 else if (ieee80211_is_deauth(mgmt->frame_control))
127 cfg80211_process_deauth(wdev, buf, len);
128 else if (ieee80211_is_disassoc(mgmt->frame_control))
129 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200130}
131EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
132
133void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr)
Johannes Berga58ce432009-11-19 12:45:42 +0100134{
135 struct wireless_dev *wdev = dev->ieee80211_ptr;
136 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800137 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berga58ce432009-11-19 12:45:42 +0100138
Beni Lev4ee3e062012-08-27 12:49:39 +0300139 trace_cfg80211_send_auth_timeout(dev, addr);
Johannes Berga58ce432009-11-19 12:45:42 +0100140
141 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200142 cfg80211_sme_auth_timeout(wdev);
Jouni Malinen1965c852009-04-22 21:38:25 +0300143}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200144EXPORT_SYMBOL(cfg80211_auth_timeout);
Jouni Malinen1965c852009-04-22 21:38:25 +0300145
Johannes Berg959867f2013-06-19 13:05:42 +0200146void cfg80211_assoc_timeout(struct net_device *dev, struct cfg80211_bss *bss)
Jouni Malinen1965c852009-04-22 21:38:25 +0300147{
Johannes Berg6829c872009-07-02 09:13:27 +0200148 struct wireless_dev *wdev = dev->ieee80211_ptr;
149 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800150 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200151
Johannes Berg959867f2013-06-19 13:05:42 +0200152 trace_cfg80211_send_assoc_timeout(dev, bss->bssid);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200153
Johannes Berg959867f2013-06-19 13:05:42 +0200154 nl80211_send_assoc_timeout(rdev, dev, bss->bssid, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200155 cfg80211_sme_assoc_timeout(wdev);
Johannes Berg959867f2013-06-19 13:05:42 +0200156
Johannes Bergf1940c52013-06-19 13:21:15 +0200157 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg959867f2013-06-19 13:05:42 +0200158 cfg80211_put_bss(wiphy, bss);
Jouni Malinen1965c852009-04-22 21:38:25 +0300159}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200160EXPORT_SYMBOL(cfg80211_assoc_timeout);
161
Johannes Berge6f462d2016-12-08 17:22:09 +0100162void cfg80211_abandon_assoc(struct net_device *dev, struct cfg80211_bss *bss)
163{
164 struct wireless_dev *wdev = dev->ieee80211_ptr;
165 struct wiphy *wiphy = wdev->wiphy;
166
167 cfg80211_sme_abandon_assoc(wdev);
168
169 cfg80211_unhold_bss(bss_from_pub(bss));
170 cfg80211_put_bss(wiphy, bss);
171}
172EXPORT_SYMBOL(cfg80211_abandon_assoc);
173
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200174void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
175{
176 struct wireless_dev *wdev = dev->ieee80211_ptr;
177 struct ieee80211_mgmt *mgmt = (void *)buf;
178
179 ASSERT_WDEV_LOCK(wdev);
180
181 trace_cfg80211_tx_mlme_mgmt(dev, buf, len);
182
183 if (WARN_ON(len < 2))
184 return;
185
186 if (ieee80211_is_deauth(mgmt->frame_control))
Johannes Bergceca7b72013-05-16 00:55:45 +0200187 cfg80211_process_deauth(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200188 else
Johannes Bergceca7b72013-05-16 00:55:45 +0200189 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200190}
191EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt);
Jouni Malinen1965c852009-04-22 21:38:25 +0300192
Jouni Malinena3b8b052009-03-27 21:59:49 +0200193void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
194 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +0200195 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +0200196{
197 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800198 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg3d23e342009-09-29 23:27:28 +0200199#ifdef CONFIG_CFG80211_WEXT
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200200 union iwreq_data wrqu;
Johannes Berge6d6e342009-07-01 21:26:47 +0200201 char *buf = kmalloc(128, gfp);
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200202
203 if (buf) {
204 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
205 "keyid=%d %scast addr=%pM)", key_id,
206 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
207 addr);
208 memset(&wrqu, 0, sizeof(wrqu));
209 wrqu.data.length = strlen(buf);
210 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
211 kfree(buf);
212 }
213#endif
214
Beni Lev4ee3e062012-08-27 12:49:39 +0300215 trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc);
Johannes Berge6d6e342009-07-01 21:26:47 +0200216 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200217}
218EXPORT_SYMBOL(cfg80211_michael_mic_failure);
Johannes Berg19957bb2009-07-02 17:20:43 +0200219
220/* some MLME handling for userspace SME */
Johannes Berg91bf9b22013-05-15 17:44:01 +0200221int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
222 struct net_device *dev,
223 struct ieee80211_channel *chan,
224 enum nl80211_auth_type auth_type,
225 const u8 *bssid,
226 const u8 *ssid, int ssid_len,
227 const u8 *ie, int ie_len,
228 const u8 *key, int key_len, int key_idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300229 const u8 *auth_data, int auth_data_len)
Johannes Berg19957bb2009-07-02 17:20:43 +0200230{
231 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200232 struct cfg80211_auth_request req = {
233 .ie = ie,
234 .ie_len = ie_len,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300235 .auth_data = auth_data,
236 .auth_data_len = auth_data_len,
Johannes Berg7ade7032013-05-13 11:37:30 +0200237 .auth_type = auth_type,
238 .key = key,
239 .key_len = key_len,
240 .key_idx = key_idx,
241 };
Johannes Berg95de8172012-01-20 13:55:25 +0100242 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200243
Johannes Berg667503d2009-07-07 03:56:11 +0200244 ASSERT_WDEV_LOCK(wdev);
245
Johannes Bergfffd0932009-07-08 14:22:54 +0200246 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
Johannes Bergb6b55552016-09-13 16:25:58 +0200247 if (!key || !key_len || key_idx < 0 || key_idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200248 return -EINVAL;
249
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200250 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000251 ether_addr_equal(bssid, wdev->current_bss->pub.bssid))
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200252 return -EALREADY;
253
Johannes Berg19957bb2009-07-02 17:20:43 +0200254 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200255 IEEE80211_BSS_TYPE_ESS,
256 IEEE80211_PRIVACY_ANY);
Johannes Berg19957bb2009-07-02 17:20:43 +0200257 if (!req.bss)
258 return -ENOENT;
259
Hila Gonene35e4d22012-06-27 17:19:42 +0300260 err = rdev_auth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200261
Johannes Berg5b112d32013-02-01 01:49:58 +0100262 cfg80211_put_bss(&rdev->wiphy, req.bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200263 return err;
264}
265
Ben Greear7e7c8922011-11-18 11:31:59 -0800266/* Do a logical ht_capa &= ht_capa_mask. */
267void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
268 const struct ieee80211_ht_cap *ht_capa_mask)
269{
270 int i;
271 u8 *p1, *p2;
272 if (!ht_capa_mask) {
273 memset(ht_capa, 0, sizeof(*ht_capa));
274 return;
275 }
276
277 p1 = (u8*)(ht_capa);
278 p2 = (u8*)(ht_capa_mask);
Sergey Matyukevich81c5dce2018-10-19 15:40:13 +0000279 for (i = 0; i < sizeof(*ht_capa); i++)
Ben Greear7e7c8922011-11-18 11:31:59 -0800280 p1[i] &= p2[i];
281}
282
Sergey Matyukevich81c5dce2018-10-19 15:40:13 +0000283/* Do a logical vht_capa &= vht_capa_mask. */
Johannes Bergee2aca32013-02-21 17:36:01 +0100284void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
285 const struct ieee80211_vht_cap *vht_capa_mask)
286{
287 int i;
288 u8 *p1, *p2;
289 if (!vht_capa_mask) {
290 memset(vht_capa, 0, sizeof(*vht_capa));
291 return;
292 }
293
294 p1 = (u8*)(vht_capa);
295 p2 = (u8*)(vht_capa_mask);
296 for (i = 0; i < sizeof(*vht_capa); i++)
297 p1[i] &= p2[i];
298}
299
Johannes Berg91bf9b22013-05-15 17:44:01 +0200300int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
301 struct net_device *dev,
302 struct ieee80211_channel *chan,
303 const u8 *bssid,
304 const u8 *ssid, int ssid_len,
305 struct cfg80211_assoc_request *req)
Johannes Berg19957bb2009-07-02 17:20:43 +0200306{
307 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100308 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200309
Johannes Berg667503d2009-07-07 03:56:11 +0200310 ASSERT_WDEV_LOCK(wdev);
311
Johannes Bergceca7b72013-05-16 00:55:45 +0200312 if (wdev->current_bss &&
313 (!req->prev_bssid || !ether_addr_equal(wdev->current_bss->pub.bssid,
314 req->prev_bssid)))
Johannes Berg19957bb2009-07-02 17:20:43 +0200315 return -EALREADY;
316
Johannes Bergf62fab72013-02-21 20:09:09 +0100317 cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
Ben Greear7e7c8922011-11-18 11:31:59 -0800318 rdev->wiphy.ht_capa_mod_mask);
Johannes Bergf62fab72013-02-21 20:09:09 +0100319 cfg80211_oper_and_vht_capa(&req->vht_capa_mask,
Johannes Bergee2aca32013-02-21 17:36:01 +0100320 rdev->wiphy.vht_capa_mod_mask);
Ben Greear7e7c8922011-11-18 11:31:59 -0800321
Johannes Bergf62fab72013-02-21 20:09:09 +0100322 req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200323 IEEE80211_BSS_TYPE_ESS,
324 IEEE80211_PRIVACY_ANY);
Johannes Bergceca7b72013-05-16 00:55:45 +0200325 if (!req->bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200326 return -ENOENT;
327
Johannes Bergf62fab72013-02-21 20:09:09 +0100328 err = rdev_assoc(rdev, dev, req);
Johannes Bergf1940c52013-06-19 13:21:15 +0200329 if (!err)
330 cfg80211_hold_bss(bss_from_pub(req->bss));
Luciano Coelho73de86a2014-02-13 11:31:59 +0200331 else
Johannes Bergf62fab72013-02-21 20:09:09 +0100332 cfg80211_put_bss(&rdev->wiphy, req->bss);
Johannes Berg95de8172012-01-20 13:55:25 +0100333
Johannes Berg19957bb2009-07-02 17:20:43 +0200334 return err;
335}
336
Johannes Berg91bf9b22013-05-15 17:44:01 +0200337int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
338 struct net_device *dev, const u8 *bssid,
339 const u8 *ie, int ie_len, u16 reason,
340 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200341{
342 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100343 struct cfg80211_deauth_request req = {
344 .bssid = bssid,
345 .reason_code = reason,
346 .ie = ie,
347 .ie_len = ie_len,
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200348 .local_state_change = local_state_change,
Johannes Berg95de8172012-01-20 13:55:25 +0100349 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200350
Johannes Berg667503d2009-07-07 03:56:11 +0200351 ASSERT_WDEV_LOCK(wdev);
352
Johannes Bergceca7b72013-05-16 00:55:45 +0200353 if (local_state_change &&
354 (!wdev->current_bss ||
355 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
Johannes Berg95de8172012-01-20 13:55:25 +0100356 return 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200357
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500358 if (ether_addr_equal(wdev->disconnect_bssid, bssid) ||
359 (wdev->current_bss &&
360 ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
361 wdev->conn_owner_nlportid = 0;
362
Hila Gonene35e4d22012-06-27 17:19:42 +0300363 return rdev_deauth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200364}
365
Johannes Berg91bf9b22013-05-15 17:44:01 +0200366int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
367 struct net_device *dev, const u8 *bssid,
368 const u8 *ie, int ie_len, u16 reason,
369 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200370{
371 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200372 struct cfg80211_disassoc_request req = {
373 .reason_code = reason,
374 .local_state_change = local_state_change,
375 .ie = ie,
376 .ie_len = ie_len,
377 };
Johannes Bergceca7b72013-05-16 00:55:45 +0200378 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200379
Johannes Berg667503d2009-07-07 03:56:11 +0200380 ASSERT_WDEV_LOCK(wdev);
381
Johannes Bergceca7b72013-05-16 00:55:45 +0200382 if (!wdev->current_bss)
Johannes Bergf9d6b402009-07-27 10:22:28 +0200383 return -ENOTCONN;
384
Joe Perchesac422d32012-05-08 18:56:55 +0000385 if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg19957bb2009-07-02 17:20:43 +0200386 req.bss = &wdev->current_bss->pub;
387 else
388 return -ENOTCONN;
389
Johannes Bergceca7b72013-05-16 00:55:45 +0200390 err = rdev_disassoc(rdev, dev, &req);
391 if (err)
392 return err;
393
394 /* driver should have reported the disassoc */
395 WARN_ON(wdev->current_bss);
396 return 0;
Johannes Berg667503d2009-07-07 03:56:11 +0200397}
398
Johannes Berg19957bb2009-07-02 17:20:43 +0200399void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
400 struct net_device *dev)
401{
402 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100403 u8 bssid[ETH_ALEN];
Johannes Berg19957bb2009-07-02 17:20:43 +0200404
Johannes Berg667503d2009-07-07 03:56:11 +0200405 ASSERT_WDEV_LOCK(wdev);
406
Johannes Berg19957bb2009-07-02 17:20:43 +0200407 if (!rdev->ops->deauth)
408 return;
409
Johannes Berg95de8172012-01-20 13:55:25 +0100410 if (!wdev->current_bss)
411 return;
Johannes Berg19957bb2009-07-02 17:20:43 +0200412
Johannes Berg95de8172012-01-20 13:55:25 +0100413 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
Johannes Bergceca7b72013-05-16 00:55:45 +0200414 cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
415 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200416}
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100417
Johannes Berg2e161f782010-08-12 15:38:38 +0200418struct cfg80211_mgmt_registration {
Jouni Malinen026331c2010-02-15 12:53:10 +0200419 struct list_head list;
Johannes Berg33d87832015-06-23 17:47:05 +0200420 struct wireless_dev *wdev;
Jouni Malinen026331c2010-02-15 12:53:10 +0200421
Eric W. Biederman15e47302012-09-07 20:12:54 +0000422 u32 nlportid;
Jouni Malinen026331c2010-02-15 12:53:10 +0200423
424 int match_len;
425
Johannes Berg2e161f782010-08-12 15:38:38 +0200426 __le16 frame_type;
427
Jouni Malinen026331c2010-02-15 12:53:10 +0200428 u8 match[];
429};
430
Johannes Berg33d87832015-06-23 17:47:05 +0200431static void
432cfg80211_process_mlme_unregistrations(struct cfg80211_registered_device *rdev)
433{
434 struct cfg80211_mgmt_registration *reg;
435
436 ASSERT_RTNL();
437
438 spin_lock_bh(&rdev->mlme_unreg_lock);
439 while ((reg = list_first_entry_or_null(&rdev->mlme_unreg,
440 struct cfg80211_mgmt_registration,
441 list))) {
442 list_del(&reg->list);
443 spin_unlock_bh(&rdev->mlme_unreg_lock);
444
445 if (rdev->ops->mgmt_frame_register) {
446 u16 frame_type = le16_to_cpu(reg->frame_type);
447
448 rdev_mgmt_frame_register(rdev, reg->wdev,
449 frame_type, false);
450 }
451
452 kfree(reg);
453
454 spin_lock_bh(&rdev->mlme_unreg_lock);
455 }
456 spin_unlock_bh(&rdev->mlme_unreg_lock);
457}
458
459void cfg80211_mlme_unreg_wk(struct work_struct *wk)
460{
461 struct cfg80211_registered_device *rdev;
462
463 rdev = container_of(wk, struct cfg80211_registered_device,
464 mlme_unreg_wk);
465
466 rtnl_lock();
467 cfg80211_process_mlme_unregistrations(rdev);
468 rtnl_unlock();
469}
470
Eric W. Biederman15e47302012-09-07 20:12:54 +0000471int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Johannes Berg2e161f782010-08-12 15:38:38 +0200472 u16 frame_type, const u8 *match_data,
473 int match_len)
Jouni Malinen026331c2010-02-15 12:53:10 +0200474{
Johannes Berg271733c2010-10-13 12:06:23 +0200475 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800476 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200477 struct cfg80211_mgmt_registration *reg, *nreg;
Jouni Malinen026331c2010-02-15 12:53:10 +0200478 int err = 0;
Johannes Berg2e161f782010-08-12 15:38:38 +0200479 u16 mgmt_type;
480
481 if (!wdev->wiphy->mgmt_stypes)
482 return -EOPNOTSUPP;
483
484 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
485 return -EINVAL;
486
487 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
488 return -EINVAL;
489
490 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
491 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
492 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +0200493
494 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
495 if (!nreg)
496 return -ENOMEM;
497
Johannes Berg2e161f782010-08-12 15:38:38 +0200498 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200499
Johannes Berg2e161f782010-08-12 15:38:38 +0200500 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200501 int mlen = min(match_len, reg->match_len);
502
Johannes Berg2e161f782010-08-12 15:38:38 +0200503 if (frame_type != le16_to_cpu(reg->frame_type))
504 continue;
505
Jouni Malinen026331c2010-02-15 12:53:10 +0200506 if (memcmp(reg->match, match_data, mlen) == 0) {
507 err = -EALREADY;
508 break;
509 }
510 }
511
512 if (err) {
513 kfree(nreg);
514 goto out;
515 }
516
517 memcpy(nreg->match, match_data, match_len);
518 nreg->match_len = match_len;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000519 nreg->nlportid = snd_portid;
Johannes Berg2e161f782010-08-12 15:38:38 +0200520 nreg->frame_type = cpu_to_le16(frame_type);
Johannes Berg33d87832015-06-23 17:47:05 +0200521 nreg->wdev = wdev;
Johannes Berg2e161f782010-08-12 15:38:38 +0200522 list_add(&nreg->list, &wdev->mgmt_registrations);
Johannes Berg33d87832015-06-23 17:47:05 +0200523 spin_unlock_bh(&wdev->mgmt_registrations_lock);
524
525 /* process all unregistrations to avoid driver confusion */
526 cfg80211_process_mlme_unregistrations(rdev);
Jouni Malinen026331c2010-02-15 12:53:10 +0200527
Johannes Berg271733c2010-10-13 12:06:23 +0200528 if (rdev->ops->mgmt_frame_register)
Hila Gonene35e4d22012-06-27 17:19:42 +0300529 rdev_mgmt_frame_register(rdev, wdev, frame_type, true);
Johannes Berg271733c2010-10-13 12:06:23 +0200530
Johannes Berg33d87832015-06-23 17:47:05 +0200531 return 0;
532
Jouni Malinen026331c2010-02-15 12:53:10 +0200533 out:
Johannes Berg2e161f782010-08-12 15:38:38 +0200534 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg271733c2010-10-13 12:06:23 +0200535
Jouni Malinen026331c2010-02-15 12:53:10 +0200536 return err;
537}
538
Eric W. Biederman15e47302012-09-07 20:12:54 +0000539void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid)
Jouni Malinen026331c2010-02-15 12:53:10 +0200540{
Johannes Berg271733c2010-10-13 12:06:23 +0200541 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800542 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200543 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200544
Johannes Berg2e161f782010-08-12 15:38:38 +0200545 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200546
Johannes Berg2e161f782010-08-12 15:38:38 +0200547 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000548 if (reg->nlportid != nlportid)
Johannes Berg271733c2010-10-13 12:06:23 +0200549 continue;
550
Johannes Berg271733c2010-10-13 12:06:23 +0200551 list_del(&reg->list);
Johannes Berg33d87832015-06-23 17:47:05 +0200552 spin_lock(&rdev->mlme_unreg_lock);
553 list_add_tail(&reg->list, &rdev->mlme_unreg);
554 spin_unlock(&rdev->mlme_unreg_lock);
555
556 schedule_work(&rdev->mlme_unreg_wk);
Jouni Malinen026331c2010-02-15 12:53:10 +0200557 }
558
Johannes Berg2e161f782010-08-12 15:38:38 +0200559 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg28946da2011-11-04 11:18:12 +0100560
Arend van Spriel5de17982013-04-18 15:49:00 +0200561 if (nlportid && rdev->crit_proto_nlportid == nlportid) {
562 rdev->crit_proto_nlportid = 0;
563 rdev_crit_proto_stop(rdev, wdev);
564 }
565
Eric W. Biederman15e47302012-09-07 20:12:54 +0000566 if (nlportid == wdev->ap_unexpected_nlportid)
567 wdev->ap_unexpected_nlportid = 0;
Jouni Malinen026331c2010-02-15 12:53:10 +0200568}
569
Johannes Berg2e161f782010-08-12 15:38:38 +0200570void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
Jouni Malinen026331c2010-02-15 12:53:10 +0200571{
Johannes Berg33d87832015-06-23 17:47:05 +0200572 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen026331c2010-02-15 12:53:10 +0200573
Johannes Berg2e161f782010-08-12 15:38:38 +0200574 spin_lock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg33d87832015-06-23 17:47:05 +0200575 spin_lock(&rdev->mlme_unreg_lock);
576 list_splice_tail_init(&wdev->mgmt_registrations, &rdev->mlme_unreg);
577 spin_unlock(&rdev->mlme_unreg_lock);
Johannes Berg2e161f782010-08-12 15:38:38 +0200578 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg33d87832015-06-23 17:47:05 +0200579
580 cfg80211_process_mlme_unregistrations(rdev);
Jouni Malinen026331c2010-02-15 12:53:10 +0200581}
582
Johannes Berg2e161f782010-08-12 15:38:38 +0200583int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200584 struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200585 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +0200586{
Jouni Malinen026331c2010-02-15 12:53:10 +0200587 const struct ieee80211_mgmt *mgmt;
Johannes Berg2e161f782010-08-12 15:38:38 +0200588 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200589
Johannes Berg2e161f782010-08-12 15:38:38 +0200590 if (!wdev->wiphy->mgmt_stypes)
Jouni Malinen026331c2010-02-15 12:53:10 +0200591 return -EOPNOTSUPP;
Johannes Berg2e161f782010-08-12 15:38:38 +0200592
593 if (!rdev->ops->mgmt_tx)
594 return -EOPNOTSUPP;
595
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200596 if (params->len < 24 + 1)
Jouni Malinen026331c2010-02-15 12:53:10 +0200597 return -EINVAL;
598
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200599 mgmt = (const struct ieee80211_mgmt *)params->buf;
Johannes Berg2e161f782010-08-12 15:38:38 +0200600
601 if (!ieee80211_is_mgmt(mgmt->frame_control))
Jouni Malinen026331c2010-02-15 12:53:10 +0200602 return -EINVAL;
Johannes Berg2e161f782010-08-12 15:38:38 +0200603
604 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
605 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
606 return -EINVAL;
607
608 if (ieee80211_is_action(mgmt->frame_control) &&
609 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200610 int err = 0;
611
Johannes Bergfe100ac2010-08-09 15:52:03 +0200612 wdev_lock(wdev);
613
Johannes Berg663fcaf2010-09-30 21:06:09 +0200614 switch (wdev->iftype) {
615 case NL80211_IFTYPE_ADHOC:
616 case NL80211_IFTYPE_STATION:
617 case NL80211_IFTYPE_P2P_CLIENT:
618 if (!wdev->current_bss) {
619 err = -ENOTCONN;
620 break;
621 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200622
Joe Perchesac422d32012-05-08 18:56:55 +0000623 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
624 mgmt->bssid)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200625 err = -ENOTCONN;
626 break;
627 }
628
629 /*
630 * check for IBSS DA must be done by driver as
631 * cfg80211 doesn't track the stations
632 */
633 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
634 break;
635
636 /* for station, check that DA is the AP */
Joe Perchesac422d32012-05-08 18:56:55 +0000637 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
638 mgmt->da)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200639 err = -ENOTCONN;
640 break;
641 }
642 break;
643 case NL80211_IFTYPE_AP:
644 case NL80211_IFTYPE_P2P_GO:
645 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg98104fde2012-06-16 00:19:54 +0200646 if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev)))
Johannes Berg663fcaf2010-09-30 21:06:09 +0200647 err = -EINVAL;
648 break;
Javier Cardona0778a6a2011-05-03 16:57:08 -0700649 case NL80211_IFTYPE_MESH_POINT:
Joe Perchesac422d32012-05-08 18:56:55 +0000650 if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) {
Javier Cardona0778a6a2011-05-03 16:57:08 -0700651 err = -EINVAL;
652 break;
653 }
654 /*
655 * check for mesh DA must be done by driver as
656 * cfg80211 doesn't track the stations
657 */
658 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200659 case NL80211_IFTYPE_P2P_DEVICE:
660 /*
661 * fall through, P2P device only supports
662 * public action frames
663 */
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300664 case NL80211_IFTYPE_NAN:
Johannes Berg663fcaf2010-09-30 21:06:09 +0200665 default:
666 err = -EOPNOTSUPP;
667 break;
668 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200669 wdev_unlock(wdev);
Johannes Berg663fcaf2010-09-30 21:06:09 +0200670
671 if (err)
672 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +0200673 }
674
vamsi krishnaab5bb2d2017-01-13 01:12:19 +0200675 if (!ether_addr_equal(mgmt->sa, wdev_address(wdev))) {
676 /* Allow random TA to be used with Public Action frames if the
677 * driver has indicated support for this. Otherwise, only allow
678 * the local address to be used.
679 */
680 if (!ieee80211_is_action(mgmt->frame_control) ||
681 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
682 return -EINVAL;
683 if (!wdev->current_bss &&
684 !wiphy_ext_feature_isset(
685 &rdev->wiphy,
686 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA))
687 return -EINVAL;
688 if (wdev->current_bss &&
689 !wiphy_ext_feature_isset(
690 &rdev->wiphy,
691 NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED))
692 return -EINVAL;
693 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200694
695 /* Transmit the Action frame as requested by user space */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200696 return rdev_mgmt_tx(rdev, wdev, params, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +0200697}
698
Sergey Matyukevich6c2fb1e2017-11-09 14:46:30 +0300699bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700700 const u8 *buf, size_t len, u32 flags)
Jouni Malinen026331c2010-02-15 12:53:10 +0200701{
Jouni Malinen026331c2010-02-15 12:53:10 +0200702 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800703 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg2e161f782010-08-12 15:38:38 +0200704 struct cfg80211_mgmt_registration *reg;
705 const struct ieee80211_txrx_stypes *stypes =
706 &wiphy->mgmt_stypes[wdev->iftype];
707 struct ieee80211_mgmt *mgmt = (void *)buf;
708 const u8 *data;
709 int data_len;
Jouni Malinen026331c2010-02-15 12:53:10 +0200710 bool result = false;
Johannes Berg2e161f782010-08-12 15:38:38 +0200711 __le16 ftype = mgmt->frame_control &
712 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
713 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200714
Sergey Matyukevich6c2fb1e2017-11-09 14:46:30 +0300715 trace_cfg80211_rx_mgmt(wdev, freq, sig_dbm);
Johannes Berg2e161f782010-08-12 15:38:38 +0200716 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
Jouni Malinen026331c2010-02-15 12:53:10 +0200717
Beni Lev4ee3e062012-08-27 12:49:39 +0300718 if (!(stypes->rx & BIT(stype))) {
719 trace_cfg80211_return_bool(false);
Johannes Berg2e161f782010-08-12 15:38:38 +0200720 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +0300721 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200722
Johannes Berg2e161f782010-08-12 15:38:38 +0200723 data = buf + ieee80211_hdrlen(mgmt->frame_control);
724 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
Jouni Malinen026331c2010-02-15 12:53:10 +0200725
Johannes Berg2e161f782010-08-12 15:38:38 +0200726 spin_lock_bh(&wdev->mgmt_registrations_lock);
727
728 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
729 if (reg->frame_type != ftype)
Jouni Malinen026331c2010-02-15 12:53:10 +0200730 continue;
731
Johannes Berg2e161f782010-08-12 15:38:38 +0200732 if (reg->match_len > data_len)
733 continue;
734
735 if (memcmp(reg->match, data, reg->match_len))
Jouni Malinen026331c2010-02-15 12:53:10 +0200736 continue;
737
738 /* found match! */
739
740 /* Indicate the received Action frame to user space */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000741 if (nl80211_send_mgmt(rdev, wdev, reg->nlportid,
Sergey Matyukevich6c2fb1e2017-11-09 14:46:30 +0300742 freq, sig_dbm,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700743 buf, len, flags, GFP_ATOMIC))
Jouni Malinen026331c2010-02-15 12:53:10 +0200744 continue;
745
746 result = true;
747 break;
748 }
749
Johannes Berg2e161f782010-08-12 15:38:38 +0200750 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200751
Beni Lev4ee3e062012-08-27 12:49:39 +0300752 trace_cfg80211_return_bool(result);
Jouni Malinen026331c2010-02-15 12:53:10 +0200753 return result;
754}
Johannes Berg2e161f782010-08-12 15:38:38 +0200755EXPORT_SYMBOL(cfg80211_rx_mgmt);
Jouni Malinen026331c2010-02-15 12:53:10 +0200756
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530757void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev)
758{
759 cancel_delayed_work(&rdev->dfs_update_channels_wk);
760 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, 0);
761}
762
Simon Wunderlich04f39042013-02-08 18:16:19 +0100763void cfg80211_dfs_channels_update_work(struct work_struct *work)
764{
Geliang Tanga85a7e22016-01-01 23:48:52 +0800765 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100766 struct cfg80211_registered_device *rdev;
767 struct cfg80211_chan_def chandef;
768 struct ieee80211_supported_band *sband;
769 struct ieee80211_channel *c;
770 struct wiphy *wiphy;
771 bool check_again = false;
772 unsigned long timeout, next_time = 0;
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530773 unsigned long time_dfs_update;
774 enum nl80211_radar_event radar_event;
Simon Wunderlich04f39042013-02-08 18:16:19 +0100775 int bandid, i;
776
Simon Wunderlich04f39042013-02-08 18:16:19 +0100777 rdev = container_of(delayed_work, struct cfg80211_registered_device,
778 dfs_update_channels_wk);
779 wiphy = &rdev->wiphy;
780
Johannes Berg5fe231e2013-05-08 21:45:15 +0200781 rtnl_lock();
Johannes Berg57fbcce2016-04-12 15:56:15 +0200782 for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) {
Simon Wunderlich04f39042013-02-08 18:16:19 +0100783 sband = wiphy->bands[bandid];
784 if (!sband)
785 continue;
786
787 for (i = 0; i < sband->n_channels; i++) {
788 c = &sband->channels[i];
789
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530790 if (!(c->flags & IEEE80211_CHAN_RADAR))
Simon Wunderlich04f39042013-02-08 18:16:19 +0100791 continue;
792
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530793 if (c->dfs_state != NL80211_DFS_UNAVAILABLE &&
794 c->dfs_state != NL80211_DFS_AVAILABLE)
795 continue;
796
797 if (c->dfs_state == NL80211_DFS_UNAVAILABLE) {
798 time_dfs_update = IEEE80211_DFS_MIN_NOP_TIME_MS;
799 radar_event = NL80211_RADAR_NOP_FINISHED;
800 } else {
801 if (regulatory_pre_cac_allowed(wiphy) ||
802 cfg80211_any_wiphy_oper_chan(wiphy, c))
803 continue;
804
805 time_dfs_update = REG_PRE_CAC_EXPIRY_GRACE_MS;
806 radar_event = NL80211_RADAR_PRE_CAC_EXPIRED;
807 }
808
809 timeout = c->dfs_state_entered +
810 msecs_to_jiffies(time_dfs_update);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100811
812 if (time_after_eq(jiffies, timeout)) {
813 c->dfs_state = NL80211_DFS_USABLE;
Michal Kaziorbbe09bb2013-10-17 11:21:12 -0700814 c->dfs_state_entered = jiffies;
815
Simon Wunderlich04f39042013-02-08 18:16:19 +0100816 cfg80211_chandef_create(&chandef, c,
817 NL80211_CHAN_NO_HT);
818
819 nl80211_radar_notify(rdev, &chandef,
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530820 radar_event, NULL,
821 GFP_ATOMIC);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530822
823 regulatory_propagate_dfs_state(wiphy, &chandef,
824 c->dfs_state,
825 radar_event);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100826 continue;
827 }
828
829 if (!check_again)
830 next_time = timeout - jiffies;
831 else
832 next_time = min(next_time, timeout - jiffies);
833 check_again = true;
834 }
835 }
Johannes Berg5fe231e2013-05-08 21:45:15 +0200836 rtnl_unlock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100837
838 /* reschedule if there are other channels waiting to be cleared again */
839 if (check_again)
840 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
841 next_time);
842}
843
844
845void cfg80211_radar_event(struct wiphy *wiphy,
846 struct cfg80211_chan_def *chandef,
847 gfp_t gfp)
848{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800849 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100850
851 trace_cfg80211_radar_event(wiphy, chandef);
852
853 /* only set the chandef supplied channel to unavailable, in
854 * case the radar is detected on only one of multiple channels
855 * spanned by the chandef.
856 */
857 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE);
858
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530859 cfg80211_sched_dfs_chan_update(rdev);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100860
861 nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530862
863 memcpy(&rdev->radar_chandef, chandef, sizeof(struct cfg80211_chan_def));
864 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100865}
866EXPORT_SYMBOL(cfg80211_radar_event);
867
868void cfg80211_cac_event(struct net_device *netdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100869 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +0100870 enum nl80211_radar_event event, gfp_t gfp)
871{
872 struct wireless_dev *wdev = netdev->ieee80211_ptr;
873 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800874 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100875 unsigned long timeout;
876
877 trace_cfg80211_cac_event(netdev, event);
878
Dmitry Lebed85096452018-03-26 16:36:31 +0300879 if (WARN_ON(!wdev->cac_started && event != NL80211_RADAR_CAC_STARTED))
Simon Wunderlich04f39042013-02-08 18:16:19 +0100880 return;
881
Michal Kazior9e0e2962014-01-29 14:22:27 +0100882 if (WARN_ON(!wdev->chandef.chan))
Simon Wunderlich04f39042013-02-08 18:16:19 +0100883 return;
884
Simon Wunderlich04f39042013-02-08 18:16:19 +0100885 switch (event) {
886 case NL80211_RADAR_CAC_FINISHED:
887 timeout = wdev->cac_start_time +
Janusz Dziedzic31559f32014-02-21 19:46:13 +0100888 msecs_to_jiffies(wdev->cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100889 WARN_ON(!time_after_eq(jiffies, timeout));
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100890 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
Vasanthakumar Thiagarajan89766722017-02-27 17:04:35 +0530891 memcpy(&rdev->cac_done_chandef, chandef,
892 sizeof(struct cfg80211_chan_def));
893 queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530894 cfg80211_sched_dfs_chan_update(rdev);
Dmitry Lebed2cb021f2018-03-01 12:39:16 +0300895 /* fall through */
Simon Wunderlich04f39042013-02-08 18:16:19 +0100896 case NL80211_RADAR_CAC_ABORTED:
Dmitry Lebed2cb021f2018-03-01 12:39:16 +0300897 wdev->cac_started = false;
898 break;
899 case NL80211_RADAR_CAC_STARTED:
900 wdev->cac_started = true;
Simon Wunderlich04f39042013-02-08 18:16:19 +0100901 break;
902 default:
903 WARN_ON(1);
904 return;
905 }
Simon Wunderlich04f39042013-02-08 18:16:19 +0100906
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100907 nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100908}
909EXPORT_SYMBOL(cfg80211_cac_event);