blob: 52cca05044a898b977927f2c9e540b00d6811634 [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 Berg6ff57cf2013-05-16 00:55:00 +020021void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss,
Johannes Berg95de8172012-01-20 13:55:25 +010022 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020023{
Johannes Berg6829c872009-07-02 09:13:27 +020024 struct wireless_dev *wdev = dev->ieee80211_ptr;
25 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020026 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020027 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
28 u8 *ie = mgmt->u.assoc_resp.variable;
Johannes Berg95de8172012-01-20 13:55:25 +010029 int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
Johannes Bergceca7b72013-05-16 00:55:45 +020030 u16 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
Johannes Berg6829c872009-07-02 09:13:27 +020031
Beni Lev4ee3e062012-08-27 12:49:39 +030032 trace_cfg80211_send_rx_assoc(dev, bss);
Johannes Bergcb0b4be2009-07-07 03:56:07 +020033
Johannes Bergf401a6f2009-08-07 14:51:05 +020034 /*
35 * This is a bit of a hack, we don't notify userspace of
36 * a (re-)association reply if we tried to send a reassoc
37 * and got a reject -- we only try again with an assoc
38 * frame instead of reassoc.
39 */
Johannes Bergceca7b72013-05-16 00:55:45 +020040 if (cfg80211_sme_rx_assoc_resp(wdev, status_code)) {
Johannes Bergf1940c52013-06-19 13:21:15 +020041 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg5b112d32013-02-01 01:49:58 +010042 cfg80211_put_bss(wiphy, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +020043 return;
Johannes Berg95de8172012-01-20 13:55:25 +010044 }
Johannes Bergf401a6f2009-08-07 14:51:05 +020045
Johannes Bergcb0b4be2009-07-07 03:56:07 +020046 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +020047 /* update current_bss etc., consumes the bss reference */
Johannes Bergdf7fc0f2009-07-29 11:23:49 +020048 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
49 status_code,
Johannes Berg95de8172012-01-20 13:55:25 +010050 status_code == WLAN_STATUS_SUCCESS, bss);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020051}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020052EXPORT_SYMBOL(cfg80211_rx_assoc_resp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020053
Johannes Bergceca7b72013-05-16 00:55:45 +020054static void cfg80211_process_auth(struct wireless_dev *wdev,
55 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020056{
Johannes Bergceca7b72013-05-16 00:55:45 +020057 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020058
Johannes Bergceca7b72013-05-16 00:55:45 +020059 nl80211_send_rx_auth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
60 cfg80211_sme_rx_auth(wdev, buf, len);
Johannes Berg667503dd2009-07-07 03:56:11 +020061}
Jouni Malinen6039f6d2009-03-19 13:39:21 +020062
Johannes Bergceca7b72013-05-16 00:55:45 +020063static void cfg80211_process_deauth(struct wireless_dev *wdev,
64 const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020065{
Johannes Bergceca7b72013-05-16 00:55:45 +020066 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020067 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
Johannes Berg19957bb2009-07-02 17:20:43 +020068 const u8 *bssid = mgmt->bssid;
Johannes Bergceca7b72013-05-16 00:55:45 +020069 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
70 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg6829c872009-07-02 09:13:27 +020071
Johannes Bergceca7b72013-05-16 00:55:45 +020072 nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
Johannes Berg6829c872009-07-02 09:13:27 +020073
Johannes Bergceca7b72013-05-16 00:55:45 +020074 if (!wdev->current_bss ||
75 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg596a07c2009-07-11 00:17:32 +020076 return;
Johannes Berg6829c872009-07-02 09:13:27 +020077
Johannes Bergceca7b72013-05-16 00:55:45 +020078 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
79 cfg80211_sme_deauth(wdev);
80}
Johannes Berg6829c872009-07-02 09:13:27 +020081
Johannes Bergceca7b72013-05-16 00:55:45 +020082static void cfg80211_process_disassoc(struct wireless_dev *wdev,
83 const u8 *buf, size_t len)
84{
85 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
86 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
87 const u8 *bssid = mgmt->bssid;
88 u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
89 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
Johannes Berg19957bb2009-07-02 17:20:43 +020090
Johannes Bergceca7b72013-05-16 00:55:45 +020091 nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL);
92
93 if (WARN_ON(!wdev->current_bss ||
94 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
95 return;
96
97 __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
98 cfg80211_sme_disassoc(wdev);
Johannes Berg667503dd2009-07-07 03:56:11 +020099}
Jouni Malinena3b8b052009-03-27 21:59:49 +0200100
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200101void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
102{
103 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200104 struct ieee80211_mgmt *mgmt = (void *)buf;
105
106 ASSERT_WDEV_LOCK(wdev);
107
108 trace_cfg80211_rx_mlme_mgmt(dev, buf, len);
109
110 if (WARN_ON(len < 2))
111 return;
112
Johannes Bergceca7b72013-05-16 00:55:45 +0200113 if (ieee80211_is_auth(mgmt->frame_control))
114 cfg80211_process_auth(wdev, buf, len);
115 else if (ieee80211_is_deauth(mgmt->frame_control))
116 cfg80211_process_deauth(wdev, buf, len);
117 else if (ieee80211_is_disassoc(mgmt->frame_control))
118 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200119}
120EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
121
122void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr)
Johannes Berga58ce432009-11-19 12:45:42 +0100123{
124 struct wireless_dev *wdev = dev->ieee80211_ptr;
125 struct wiphy *wiphy = wdev->wiphy;
126 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
127
Beni Lev4ee3e062012-08-27 12:49:39 +0300128 trace_cfg80211_send_auth_timeout(dev, addr);
Johannes Berga58ce432009-11-19 12:45:42 +0100129
130 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200131 cfg80211_sme_auth_timeout(wdev);
Jouni Malinen1965c852009-04-22 21:38:25 +0300132}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200133EXPORT_SYMBOL(cfg80211_auth_timeout);
Jouni Malinen1965c852009-04-22 21:38:25 +0300134
Johannes Berg959867f2013-06-19 13:05:42 +0200135void cfg80211_assoc_timeout(struct net_device *dev, struct cfg80211_bss *bss)
Jouni Malinen1965c852009-04-22 21:38:25 +0300136{
Johannes Berg6829c872009-07-02 09:13:27 +0200137 struct wireless_dev *wdev = dev->ieee80211_ptr;
138 struct wiphy *wiphy = wdev->wiphy;
Jouni Malinen1965c852009-04-22 21:38:25 +0300139 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200140
Johannes Berg959867f2013-06-19 13:05:42 +0200141 trace_cfg80211_send_assoc_timeout(dev, bss->bssid);
Johannes Bergcb0b4be2009-07-07 03:56:07 +0200142
Johannes Berg959867f2013-06-19 13:05:42 +0200143 nl80211_send_assoc_timeout(rdev, dev, bss->bssid, GFP_KERNEL);
Johannes Bergceca7b72013-05-16 00:55:45 +0200144 cfg80211_sme_assoc_timeout(wdev);
Johannes Berg959867f2013-06-19 13:05:42 +0200145
Johannes Bergf1940c52013-06-19 13:21:15 +0200146 cfg80211_unhold_bss(bss_from_pub(bss));
Johannes Berg959867f2013-06-19 13:05:42 +0200147 cfg80211_put_bss(wiphy, bss);
Jouni Malinen1965c852009-04-22 21:38:25 +0300148}
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200149EXPORT_SYMBOL(cfg80211_assoc_timeout);
150
151void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
152{
153 struct wireless_dev *wdev = dev->ieee80211_ptr;
154 struct ieee80211_mgmt *mgmt = (void *)buf;
155
156 ASSERT_WDEV_LOCK(wdev);
157
158 trace_cfg80211_tx_mlme_mgmt(dev, buf, len);
159
160 if (WARN_ON(len < 2))
161 return;
162
163 if (ieee80211_is_deauth(mgmt->frame_control))
Johannes Bergceca7b72013-05-16 00:55:45 +0200164 cfg80211_process_deauth(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200165 else
Johannes Bergceca7b72013-05-16 00:55:45 +0200166 cfg80211_process_disassoc(wdev, buf, len);
Johannes Berg6ff57cf2013-05-16 00:55:00 +0200167}
168EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt);
Jouni Malinen1965c852009-04-22 21:38:25 +0300169
Jouni Malinena3b8b052009-03-27 21:59:49 +0200170void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
171 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +0200172 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +0200173{
174 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
175 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg3d23e342009-09-29 23:27:28 +0200176#ifdef CONFIG_CFG80211_WEXT
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200177 union iwreq_data wrqu;
Johannes Berge6d6e342009-07-01 21:26:47 +0200178 char *buf = kmalloc(128, gfp);
Johannes Bergf58d4ed2009-06-19 02:45:21 +0200179
180 if (buf) {
181 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
182 "keyid=%d %scast addr=%pM)", key_id,
183 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
184 addr);
185 memset(&wrqu, 0, sizeof(wrqu));
186 wrqu.data.length = strlen(buf);
187 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
188 kfree(buf);
189 }
190#endif
191
Beni Lev4ee3e062012-08-27 12:49:39 +0300192 trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc);
Johannes Berge6d6e342009-07-01 21:26:47 +0200193 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +0200194}
195EXPORT_SYMBOL(cfg80211_michael_mic_failure);
Johannes Berg19957bb2009-07-02 17:20:43 +0200196
197/* some MLME handling for userspace SME */
Johannes Berg91bf9b22013-05-15 17:44:01 +0200198int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
199 struct net_device *dev,
200 struct ieee80211_channel *chan,
201 enum nl80211_auth_type auth_type,
202 const u8 *bssid,
203 const u8 *ssid, int ssid_len,
204 const u8 *ie, int ie_len,
205 const u8 *key, int key_len, int key_idx,
206 const u8 *sae_data, int sae_data_len)
Johannes Berg19957bb2009-07-02 17:20:43 +0200207{
208 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200209 struct cfg80211_auth_request req = {
210 .ie = ie,
211 .ie_len = ie_len,
212 .sae_data = sae_data,
213 .sae_data_len = sae_data_len,
214 .auth_type = auth_type,
215 .key = key,
216 .key_len = key_len,
217 .key_idx = key_idx,
218 };
Johannes Berg95de8172012-01-20 13:55:25 +0100219 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200220
Johannes Berg667503dd2009-07-07 03:56:11 +0200221 ASSERT_WDEV_LOCK(wdev);
222
Johannes Bergfffd0932009-07-08 14:22:54 +0200223 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
224 if (!key || !key_len || key_idx < 0 || key_idx > 4)
225 return -EINVAL;
226
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200227 if (wdev->current_bss &&
Joe Perchesac422d32012-05-08 18:56:55 +0000228 ether_addr_equal(bssid, wdev->current_bss->pub.bssid))
Johannes Berg0a9b5e12009-07-02 18:26:18 +0200229 return -EALREADY;
230
Johannes Berg19957bb2009-07-02 17:20:43 +0200231 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
232 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
233 if (!req.bss)
234 return -ENOENT;
235
Michal Kaziore4e32452012-06-29 12:47:08 +0200236 err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
237 CHAN_MODE_SHARED);
238 if (err)
239 goto out;
240
Hila Gonene35e4d22012-06-27 17:19:42 +0300241 err = rdev_auth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200242
Michal Kaziore4e32452012-06-29 12:47:08 +0200243out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100244 cfg80211_put_bss(&rdev->wiphy, req.bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200245 return err;
246}
247
Ben Greear7e7c8922011-11-18 11:31:59 -0800248/* Do a logical ht_capa &= ht_capa_mask. */
249void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
250 const struct ieee80211_ht_cap *ht_capa_mask)
251{
252 int i;
253 u8 *p1, *p2;
254 if (!ht_capa_mask) {
255 memset(ht_capa, 0, sizeof(*ht_capa));
256 return;
257 }
258
259 p1 = (u8*)(ht_capa);
260 p2 = (u8*)(ht_capa_mask);
261 for (i = 0; i<sizeof(*ht_capa); i++)
262 p1[i] &= p2[i];
263}
264
Johannes Bergee2aca32013-02-21 17:36:01 +0100265/* Do a logical ht_capa &= ht_capa_mask. */
266void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
267 const struct ieee80211_vht_cap *vht_capa_mask)
268{
269 int i;
270 u8 *p1, *p2;
271 if (!vht_capa_mask) {
272 memset(vht_capa, 0, sizeof(*vht_capa));
273 return;
274 }
275
276 p1 = (u8*)(vht_capa);
277 p2 = (u8*)(vht_capa_mask);
278 for (i = 0; i < sizeof(*vht_capa); i++)
279 p1[i] &= p2[i];
280}
281
Johannes Berg91bf9b22013-05-15 17:44:01 +0200282int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
283 struct net_device *dev,
284 struct ieee80211_channel *chan,
285 const u8 *bssid,
286 const u8 *ssid, int ssid_len,
287 struct cfg80211_assoc_request *req)
Johannes Berg19957bb2009-07-02 17:20:43 +0200288{
289 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100290 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200291
Johannes Berg667503dd2009-07-07 03:56:11 +0200292 ASSERT_WDEV_LOCK(wdev);
293
Johannes Bergceca7b72013-05-16 00:55:45 +0200294 if (wdev->current_bss &&
295 (!req->prev_bssid || !ether_addr_equal(wdev->current_bss->pub.bssid,
296 req->prev_bssid)))
Johannes Berg19957bb2009-07-02 17:20:43 +0200297 return -EALREADY;
298
Johannes Bergf62fab72013-02-21 20:09:09 +0100299 cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
Ben Greear7e7c8922011-11-18 11:31:59 -0800300 rdev->wiphy.ht_capa_mod_mask);
Johannes Bergf62fab72013-02-21 20:09:09 +0100301 cfg80211_oper_and_vht_capa(&req->vht_capa_mask,
Johannes Bergee2aca32013-02-21 17:36:01 +0100302 rdev->wiphy.vht_capa_mod_mask);
Ben Greear7e7c8922011-11-18 11:31:59 -0800303
Johannes Bergf62fab72013-02-21 20:09:09 +0100304 req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
305 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
Johannes Bergceca7b72013-05-16 00:55:45 +0200306 if (!req->bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200307 return -ENOENT;
308
Johannes Bergf62fab72013-02-21 20:09:09 +0100309 err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
Michal Kaziore4e32452012-06-29 12:47:08 +0200310 if (err)
311 goto out;
312
Johannes Bergf62fab72013-02-21 20:09:09 +0100313 err = rdev_assoc(rdev, dev, req);
Johannes Bergf1940c52013-06-19 13:21:15 +0200314 if (!err)
315 cfg80211_hold_bss(bss_from_pub(req->bss));
Johannes Berg95de8172012-01-20 13:55:25 +0100316
Michal Kaziore4e32452012-06-29 12:47:08 +0200317out:
Johannes Bergceca7b72013-05-16 00:55:45 +0200318 if (err)
Johannes Bergf62fab72013-02-21 20:09:09 +0100319 cfg80211_put_bss(&rdev->wiphy, req->bss);
Johannes Berg95de8172012-01-20 13:55:25 +0100320
Johannes Berg19957bb2009-07-02 17:20:43 +0200321 return err;
322}
323
Johannes Berg91bf9b22013-05-15 17:44:01 +0200324int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
325 struct net_device *dev, const u8 *bssid,
326 const u8 *ie, int ie_len, u16 reason,
327 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200328{
329 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100330 struct cfg80211_deauth_request req = {
331 .bssid = bssid,
332 .reason_code = reason,
333 .ie = ie,
334 .ie_len = ie_len,
Stanislaw Gruszka68632552012-10-15 14:52:41 +0200335 .local_state_change = local_state_change,
Johannes Berg95de8172012-01-20 13:55:25 +0100336 };
Johannes Berg19957bb2009-07-02 17:20:43 +0200337
Johannes Berg667503dd2009-07-07 03:56:11 +0200338 ASSERT_WDEV_LOCK(wdev);
339
Johannes Bergceca7b72013-05-16 00:55:45 +0200340 if (local_state_change &&
341 (!wdev->current_bss ||
342 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
Johannes Berg95de8172012-01-20 13:55:25 +0100343 return 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200344
Hila Gonene35e4d22012-06-27 17:19:42 +0300345 return rdev_deauth(rdev, dev, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200346}
347
Johannes Berg91bf9b22013-05-15 17:44:01 +0200348int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
349 struct net_device *dev, const u8 *bssid,
350 const u8 *ie, int ie_len, u16 reason,
351 bool local_state_change)
Johannes Berg19957bb2009-07-02 17:20:43 +0200352{
353 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg7ade7032013-05-13 11:37:30 +0200354 struct cfg80211_disassoc_request req = {
355 .reason_code = reason,
356 .local_state_change = local_state_change,
357 .ie = ie,
358 .ie_len = ie_len,
359 };
Johannes Bergceca7b72013-05-16 00:55:45 +0200360 int err;
Johannes Berg19957bb2009-07-02 17:20:43 +0200361
Johannes Berg667503dd2009-07-07 03:56:11 +0200362 ASSERT_WDEV_LOCK(wdev);
363
Johannes Bergceca7b72013-05-16 00:55:45 +0200364 if (!wdev->current_bss)
Johannes Bergf9d6b402009-07-27 10:22:28 +0200365 return -ENOTCONN;
366
Joe Perchesac422d32012-05-08 18:56:55 +0000367 if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
Johannes Berg19957bb2009-07-02 17:20:43 +0200368 req.bss = &wdev->current_bss->pub;
369 else
370 return -ENOTCONN;
371
Johannes Bergceca7b72013-05-16 00:55:45 +0200372 err = rdev_disassoc(rdev, dev, &req);
373 if (err)
374 return err;
375
376 /* driver should have reported the disassoc */
377 WARN_ON(wdev->current_bss);
378 return 0;
Johannes Berg667503dd2009-07-07 03:56:11 +0200379}
380
Johannes Berg19957bb2009-07-02 17:20:43 +0200381void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
382 struct net_device *dev)
383{
384 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg95de8172012-01-20 13:55:25 +0100385 u8 bssid[ETH_ALEN];
Johannes Berg19957bb2009-07-02 17:20:43 +0200386
Johannes Berg667503dd2009-07-07 03:56:11 +0200387 ASSERT_WDEV_LOCK(wdev);
388
Johannes Berg19957bb2009-07-02 17:20:43 +0200389 if (!rdev->ops->deauth)
390 return;
391
Johannes Berg95de8172012-01-20 13:55:25 +0100392 if (!wdev->current_bss)
393 return;
Johannes Berg19957bb2009-07-02 17:20:43 +0200394
Johannes Berg95de8172012-01-20 13:55:25 +0100395 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
Johannes Bergceca7b72013-05-16 00:55:45 +0200396 cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
397 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200398}
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100399
Johannes Berg2e161f72010-08-12 15:38:38 +0200400struct cfg80211_mgmt_registration {
Jouni Malinen026331c2010-02-15 12:53:10 +0200401 struct list_head list;
402
Eric W. Biederman15e47302012-09-07 20:12:54 +0000403 u32 nlportid;
Jouni Malinen026331c2010-02-15 12:53:10 +0200404
405 int match_len;
406
Johannes Berg2e161f72010-08-12 15:38:38 +0200407 __le16 frame_type;
408
Jouni Malinen026331c2010-02-15 12:53:10 +0200409 u8 match[];
410};
411
Eric W. Biederman15e47302012-09-07 20:12:54 +0000412int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Johannes Berg2e161f72010-08-12 15:38:38 +0200413 u16 frame_type, const u8 *match_data,
414 int match_len)
Jouni Malinen026331c2010-02-15 12:53:10 +0200415{
Johannes Berg271733c2010-10-13 12:06:23 +0200416 struct wiphy *wiphy = wdev->wiphy;
417 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200418 struct cfg80211_mgmt_registration *reg, *nreg;
Jouni Malinen026331c2010-02-15 12:53:10 +0200419 int err = 0;
Johannes Berg2e161f72010-08-12 15:38:38 +0200420 u16 mgmt_type;
421
422 if (!wdev->wiphy->mgmt_stypes)
423 return -EOPNOTSUPP;
424
425 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
426 return -EINVAL;
427
428 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
429 return -EINVAL;
430
431 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
432 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
433 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +0200434
435 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
436 if (!nreg)
437 return -ENOMEM;
438
Johannes Berg2e161f72010-08-12 15:38:38 +0200439 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200440
Johannes Berg2e161f72010-08-12 15:38:38 +0200441 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200442 int mlen = min(match_len, reg->match_len);
443
Johannes Berg2e161f72010-08-12 15:38:38 +0200444 if (frame_type != le16_to_cpu(reg->frame_type))
445 continue;
446
Jouni Malinen026331c2010-02-15 12:53:10 +0200447 if (memcmp(reg->match, match_data, mlen) == 0) {
448 err = -EALREADY;
449 break;
450 }
451 }
452
453 if (err) {
454 kfree(nreg);
455 goto out;
456 }
457
458 memcpy(nreg->match, match_data, match_len);
459 nreg->match_len = match_len;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000460 nreg->nlportid = snd_portid;
Johannes Berg2e161f72010-08-12 15:38:38 +0200461 nreg->frame_type = cpu_to_le16(frame_type);
462 list_add(&nreg->list, &wdev->mgmt_registrations);
Jouni Malinen026331c2010-02-15 12:53:10 +0200463
Johannes Berg271733c2010-10-13 12:06:23 +0200464 if (rdev->ops->mgmt_frame_register)
Hila Gonene35e4d22012-06-27 17:19:42 +0300465 rdev_mgmt_frame_register(rdev, wdev, frame_type, true);
Johannes Berg271733c2010-10-13 12:06:23 +0200466
Jouni Malinen026331c2010-02-15 12:53:10 +0200467 out:
Johannes Berg2e161f72010-08-12 15:38:38 +0200468 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg271733c2010-10-13 12:06:23 +0200469
Jouni Malinen026331c2010-02-15 12:53:10 +0200470 return err;
471}
472
Eric W. Biederman15e47302012-09-07 20:12:54 +0000473void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid)
Jouni Malinen026331c2010-02-15 12:53:10 +0200474{
Johannes Berg271733c2010-10-13 12:06:23 +0200475 struct wiphy *wiphy = wdev->wiphy;
476 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200477 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200478
Johannes Berg2e161f72010-08-12 15:38:38 +0200479 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200480
Johannes Berg2e161f72010-08-12 15:38:38 +0200481 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000482 if (reg->nlportid != nlportid)
Johannes Berg271733c2010-10-13 12:06:23 +0200483 continue;
484
485 if (rdev->ops->mgmt_frame_register) {
486 u16 frame_type = le16_to_cpu(reg->frame_type);
487
Hila Gonene35e4d22012-06-27 17:19:42 +0300488 rdev_mgmt_frame_register(rdev, wdev,
489 frame_type, false);
Jouni Malinen026331c2010-02-15 12:53:10 +0200490 }
Johannes Berg271733c2010-10-13 12:06:23 +0200491
492 list_del(&reg->list);
493 kfree(reg);
Jouni Malinen026331c2010-02-15 12:53:10 +0200494 }
495
Johannes Berg2e161f72010-08-12 15:38:38 +0200496 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Johannes Berg28946da2011-11-04 11:18:12 +0100497
Arend van Spriel5de17982013-04-18 15:49:00 +0200498 if (nlportid && rdev->crit_proto_nlportid == nlportid) {
499 rdev->crit_proto_nlportid = 0;
500 rdev_crit_proto_stop(rdev, wdev);
501 }
502
Eric W. Biederman15e47302012-09-07 20:12:54 +0000503 if (nlportid == wdev->ap_unexpected_nlportid)
504 wdev->ap_unexpected_nlportid = 0;
Jouni Malinen026331c2010-02-15 12:53:10 +0200505}
506
Johannes Berg2e161f72010-08-12 15:38:38 +0200507void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
Jouni Malinen026331c2010-02-15 12:53:10 +0200508{
Johannes Berg2e161f72010-08-12 15:38:38 +0200509 struct cfg80211_mgmt_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +0200510
Johannes Berg2e161f72010-08-12 15:38:38 +0200511 spin_lock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200512
Johannes Berg2e161f72010-08-12 15:38:38 +0200513 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +0200514 list_del(&reg->list);
515 kfree(reg);
516 }
517
Johannes Berg2e161f72010-08-12 15:38:38 +0200518 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200519}
520
Johannes Berg2e161f72010-08-12 15:38:38 +0200521int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200522 struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200523 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +0200524{
Jouni Malinen026331c2010-02-15 12:53:10 +0200525 const struct ieee80211_mgmt *mgmt;
Johannes Berg2e161f72010-08-12 15:38:38 +0200526 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200527
Johannes Berg2e161f72010-08-12 15:38:38 +0200528 if (!wdev->wiphy->mgmt_stypes)
Jouni Malinen026331c2010-02-15 12:53:10 +0200529 return -EOPNOTSUPP;
Johannes Berg2e161f72010-08-12 15:38:38 +0200530
531 if (!rdev->ops->mgmt_tx)
532 return -EOPNOTSUPP;
533
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200534 if (params->len < 24 + 1)
Jouni Malinen026331c2010-02-15 12:53:10 +0200535 return -EINVAL;
536
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200537 mgmt = (const struct ieee80211_mgmt *)params->buf;
Johannes Berg2e161f72010-08-12 15:38:38 +0200538
539 if (!ieee80211_is_mgmt(mgmt->frame_control))
Jouni Malinen026331c2010-02-15 12:53:10 +0200540 return -EINVAL;
Johannes Berg2e161f72010-08-12 15:38:38 +0200541
542 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
543 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
544 return -EINVAL;
545
546 if (ieee80211_is_action(mgmt->frame_control) &&
547 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200548 int err = 0;
549
Johannes Bergfe100ac2010-08-09 15:52:03 +0200550 wdev_lock(wdev);
551
Johannes Berg663fcaf2010-09-30 21:06:09 +0200552 switch (wdev->iftype) {
553 case NL80211_IFTYPE_ADHOC:
554 case NL80211_IFTYPE_STATION:
555 case NL80211_IFTYPE_P2P_CLIENT:
556 if (!wdev->current_bss) {
557 err = -ENOTCONN;
558 break;
559 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200560
Joe Perchesac422d32012-05-08 18:56:55 +0000561 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
562 mgmt->bssid)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200563 err = -ENOTCONN;
564 break;
565 }
566
567 /*
568 * check for IBSS DA must be done by driver as
569 * cfg80211 doesn't track the stations
570 */
571 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
572 break;
573
574 /* for station, check that DA is the AP */
Joe Perchesac422d32012-05-08 18:56:55 +0000575 if (!ether_addr_equal(wdev->current_bss->pub.bssid,
576 mgmt->da)) {
Johannes Berg663fcaf2010-09-30 21:06:09 +0200577 err = -ENOTCONN;
578 break;
579 }
580 break;
581 case NL80211_IFTYPE_AP:
582 case NL80211_IFTYPE_P2P_GO:
583 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg98104fde2012-06-16 00:19:54 +0200584 if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev)))
Johannes Berg663fcaf2010-09-30 21:06:09 +0200585 err = -EINVAL;
586 break;
Javier Cardona0778a6a2011-05-03 16:57:08 -0700587 case NL80211_IFTYPE_MESH_POINT:
Joe Perchesac422d32012-05-08 18:56:55 +0000588 if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) {
Javier Cardona0778a6a2011-05-03 16:57:08 -0700589 err = -EINVAL;
590 break;
591 }
592 /*
593 * check for mesh DA must be done by driver as
594 * cfg80211 doesn't track the stations
595 */
596 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200597 case NL80211_IFTYPE_P2P_DEVICE:
598 /*
599 * fall through, P2P device only supports
600 * public action frames
601 */
Johannes Berg663fcaf2010-09-30 21:06:09 +0200602 default:
603 err = -EOPNOTSUPP;
604 break;
605 }
Johannes Bergfe100ac2010-08-09 15:52:03 +0200606 wdev_unlock(wdev);
Johannes Berg663fcaf2010-09-30 21:06:09 +0200607
608 if (err)
609 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +0200610 }
611
Johannes Berg98104fde2012-06-16 00:19:54 +0200612 if (!ether_addr_equal(mgmt->sa, wdev_address(wdev)))
Jouni Malinen026331c2010-02-15 12:53:10 +0200613 return -EINVAL;
614
615 /* Transmit the Action frame as requested by user space */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200616 return rdev_mgmt_tx(rdev, wdev, params, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +0200617}
618
Johannes Berg71bbc992012-06-15 15:30:18 +0200619bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +0300620 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +0200621{
Jouni Malinen026331c2010-02-15 12:53:10 +0200622 struct wiphy *wiphy = wdev->wiphy;
623 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg2e161f72010-08-12 15:38:38 +0200624 struct cfg80211_mgmt_registration *reg;
625 const struct ieee80211_txrx_stypes *stypes =
626 &wiphy->mgmt_stypes[wdev->iftype];
627 struct ieee80211_mgmt *mgmt = (void *)buf;
628 const u8 *data;
629 int data_len;
Jouni Malinen026331c2010-02-15 12:53:10 +0200630 bool result = false;
Johannes Berg2e161f72010-08-12 15:38:38 +0200631 __le16 ftype = mgmt->frame_control &
632 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
633 u16 stype;
Jouni Malinen026331c2010-02-15 12:53:10 +0200634
Beni Lev4ee3e062012-08-27 12:49:39 +0300635 trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm);
Johannes Berg2e161f72010-08-12 15:38:38 +0200636 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
Jouni Malinen026331c2010-02-15 12:53:10 +0200637
Beni Lev4ee3e062012-08-27 12:49:39 +0300638 if (!(stypes->rx & BIT(stype))) {
639 trace_cfg80211_return_bool(false);
Johannes Berg2e161f72010-08-12 15:38:38 +0200640 return false;
Beni Lev4ee3e062012-08-27 12:49:39 +0300641 }
Jouni Malinen026331c2010-02-15 12:53:10 +0200642
Johannes Berg2e161f72010-08-12 15:38:38 +0200643 data = buf + ieee80211_hdrlen(mgmt->frame_control);
644 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
Jouni Malinen026331c2010-02-15 12:53:10 +0200645
Johannes Berg2e161f72010-08-12 15:38:38 +0200646 spin_lock_bh(&wdev->mgmt_registrations_lock);
647
648 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
649 if (reg->frame_type != ftype)
Jouni Malinen026331c2010-02-15 12:53:10 +0200650 continue;
651
Johannes Berg2e161f72010-08-12 15:38:38 +0200652 if (reg->match_len > data_len)
653 continue;
654
655 if (memcmp(reg->match, data, reg->match_len))
Jouni Malinen026331c2010-02-15 12:53:10 +0200656 continue;
657
658 /* found match! */
659
660 /* Indicate the received Action frame to user space */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000661 if (nl80211_send_mgmt(rdev, wdev, reg->nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +0100662 freq, sig_mbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +0300663 buf, len, flags, gfp))
Jouni Malinen026331c2010-02-15 12:53:10 +0200664 continue;
665
666 result = true;
667 break;
668 }
669
Johannes Berg2e161f72010-08-12 15:38:38 +0200670 spin_unlock_bh(&wdev->mgmt_registrations_lock);
Jouni Malinen026331c2010-02-15 12:53:10 +0200671
Beni Lev4ee3e062012-08-27 12:49:39 +0300672 trace_cfg80211_return_bool(result);
Jouni Malinen026331c2010-02-15 12:53:10 +0200673 return result;
674}
Johannes Berg2e161f72010-08-12 15:38:38 +0200675EXPORT_SYMBOL(cfg80211_rx_mgmt);
Jouni Malinen026331c2010-02-15 12:53:10 +0200676
Simon Wunderlich04f39042013-02-08 18:16:19 +0100677void cfg80211_dfs_channels_update_work(struct work_struct *work)
678{
679 struct delayed_work *delayed_work;
680 struct cfg80211_registered_device *rdev;
681 struct cfg80211_chan_def chandef;
682 struct ieee80211_supported_band *sband;
683 struct ieee80211_channel *c;
684 struct wiphy *wiphy;
685 bool check_again = false;
686 unsigned long timeout, next_time = 0;
687 int bandid, i;
688
689 delayed_work = container_of(work, struct delayed_work, work);
690 rdev = container_of(delayed_work, struct cfg80211_registered_device,
691 dfs_update_channels_wk);
692 wiphy = &rdev->wiphy;
693
Johannes Berg5fe231e2013-05-08 21:45:15 +0200694 rtnl_lock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100695 for (bandid = 0; bandid < IEEE80211_NUM_BANDS; bandid++) {
696 sband = wiphy->bands[bandid];
697 if (!sband)
698 continue;
699
700 for (i = 0; i < sband->n_channels; i++) {
701 c = &sband->channels[i];
702
703 if (c->dfs_state != NL80211_DFS_UNAVAILABLE)
704 continue;
705
Michal Kaziorc532a582013-10-17 11:21:11 -0700706 timeout = c->dfs_state_entered + msecs_to_jiffies(
707 IEEE80211_DFS_MIN_NOP_TIME_MS);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100708
709 if (time_after_eq(jiffies, timeout)) {
710 c->dfs_state = NL80211_DFS_USABLE;
Michal Kaziorbbe09bb2013-10-17 11:21:12 -0700711 c->dfs_state_entered = jiffies;
712
Simon Wunderlich04f39042013-02-08 18:16:19 +0100713 cfg80211_chandef_create(&chandef, c,
714 NL80211_CHAN_NO_HT);
715
716 nl80211_radar_notify(rdev, &chandef,
717 NL80211_RADAR_NOP_FINISHED,
718 NULL, GFP_ATOMIC);
719 continue;
720 }
721
722 if (!check_again)
723 next_time = timeout - jiffies;
724 else
725 next_time = min(next_time, timeout - jiffies);
726 check_again = true;
727 }
728 }
Johannes Berg5fe231e2013-05-08 21:45:15 +0200729 rtnl_unlock();
Simon Wunderlich04f39042013-02-08 18:16:19 +0100730
731 /* reschedule if there are other channels waiting to be cleared again */
732 if (check_again)
733 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
734 next_time);
735}
736
737
738void cfg80211_radar_event(struct wiphy *wiphy,
739 struct cfg80211_chan_def *chandef,
740 gfp_t gfp)
741{
742 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
743 unsigned long timeout;
744
745 trace_cfg80211_radar_event(wiphy, chandef);
746
747 /* only set the chandef supplied channel to unavailable, in
748 * case the radar is detected on only one of multiple channels
749 * spanned by the chandef.
750 */
751 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE);
752
753 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS);
754 queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk,
755 timeout);
756
757 nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp);
758}
759EXPORT_SYMBOL(cfg80211_radar_event);
760
761void cfg80211_cac_event(struct net_device *netdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100762 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +0100763 enum nl80211_radar_event event, gfp_t gfp)
764{
765 struct wireless_dev *wdev = netdev->ieee80211_ptr;
766 struct wiphy *wiphy = wdev->wiphy;
767 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100768 unsigned long timeout;
769
770 trace_cfg80211_cac_event(netdev, event);
771
772 if (WARN_ON(!wdev->cac_started))
773 return;
774
775 if (WARN_ON(!wdev->channel))
776 return;
777
Simon Wunderlich04f39042013-02-08 18:16:19 +0100778 switch (event) {
779 case NL80211_RADAR_CAC_FINISHED:
780 timeout = wdev->cac_start_time +
781 msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
782 WARN_ON(!time_after_eq(jiffies, timeout));
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100783 cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100784 break;
785 case NL80211_RADAR_CAC_ABORTED:
786 break;
787 default:
788 WARN_ON(1);
789 return;
790 }
791 wdev->cac_started = false;
792
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100793 nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100794}
795EXPORT_SYMBOL(cfg80211_cac_event);