Commit | Line | Data |
---|---|---|
6039f6d2 JM |
1 | /* |
2 | * cfg80211 MLME SAP interface | |
3 | * | |
4 | * Copyright (c) 2009, Jouni Malinen <j@w1.fi> | |
5 | */ | |
6 | ||
7 | #include <linux/kernel.h> | |
8 | #include <linux/module.h> | |
c6fb08aa | 9 | #include <linux/etherdevice.h> |
6039f6d2 JM |
10 | #include <linux/netdevice.h> |
11 | #include <linux/nl80211.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
a9a11622 | 13 | #include <linux/wireless.h> |
6039f6d2 | 14 | #include <net/cfg80211.h> |
a9a11622 | 15 | #include <net/iw_handler.h> |
6039f6d2 JM |
16 | #include "core.h" |
17 | #include "nl80211.h" | |
e35e4d28 HG |
18 | #include "rdev-ops.h" |
19 | ||
6039f6d2 | 20 | |
cb0b4beb | 21 | void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len) |
6039f6d2 | 22 | { |
19957bb3 JB |
23 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
24 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 25 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
19957bb3 | 26 | |
4ee3e063 | 27 | trace_cfg80211_send_rx_auth(dev); |
667503dd | 28 | wdev_lock(wdev); |
cb0b4beb | 29 | |
95de817b JB |
30 | nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL); |
31 | cfg80211_sme_rx_auth(dev, buf, len); | |
667503dd JB |
32 | |
33 | wdev_unlock(wdev); | |
6039f6d2 JM |
34 | } |
35 | EXPORT_SYMBOL(cfg80211_send_rx_auth); | |
36 | ||
95de817b JB |
37 | void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss, |
38 | const u8 *buf, size_t len) | |
6039f6d2 | 39 | { |
6829c878 JB |
40 | u16 status_code; |
41 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
42 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 43 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 JB |
44 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
45 | u8 *ie = mgmt->u.assoc_resp.variable; | |
95de817b | 46 | int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); |
6829c878 | 47 | |
4ee3e063 | 48 | trace_cfg80211_send_rx_assoc(dev, bss); |
667503dd | 49 | wdev_lock(wdev); |
cb0b4beb | 50 | |
6829c878 JB |
51 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
52 | ||
f401a6f7 JB |
53 | /* |
54 | * This is a bit of a hack, we don't notify userspace of | |
55 | * a (re-)association reply if we tried to send a reassoc | |
56 | * and got a reject -- we only try again with an assoc | |
57 | * frame instead of reassoc. | |
58 | */ | |
59 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn && | |
95de817b | 60 | cfg80211_sme_failed_reassoc(wdev)) { |
5b112d3d | 61 | cfg80211_put_bss(wiphy, bss); |
f401a6f7 | 62 | goto out; |
95de817b | 63 | } |
f401a6f7 | 64 | |
cb0b4beb | 65 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); |
6829c878 | 66 | |
95de817b | 67 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) { |
7d930bc3 | 68 | cfg80211_sme_failed_assoc(wdev); |
7d930bc3 JB |
69 | /* |
70 | * do not call connect_result() now because the | |
71 | * sme will schedule work that does it later. | |
72 | */ | |
5b112d3d | 73 | cfg80211_put_bss(wiphy, bss); |
7d930bc3 | 74 | goto out; |
df7fc0f9 JB |
75 | } |
76 | ||
ea416a79 JB |
77 | if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) { |
78 | /* | |
79 | * This is for the userspace SME, the CONNECTING | |
80 | * state will be changed to CONNECTED by | |
81 | * __cfg80211_connect_result() below. | |
82 | */ | |
83 | wdev->sme_state = CFG80211_SME_CONNECTING; | |
84 | } | |
85 | ||
95de817b | 86 | /* this consumes the bss reference */ |
df7fc0f9 JB |
87 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, |
88 | status_code, | |
95de817b | 89 | status_code == WLAN_STATUS_SUCCESS, bss); |
f401a6f7 | 90 | out: |
667503dd | 91 | wdev_unlock(wdev); |
6039f6d2 JM |
92 | } |
93 | EXPORT_SYMBOL(cfg80211_send_rx_assoc); | |
94 | ||
ce470613 | 95 | void __cfg80211_send_deauth(struct net_device *dev, |
667503dd | 96 | const u8 *buf, size_t len) |
6039f6d2 | 97 | { |
6829c878 JB |
98 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
99 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 100 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 | 101 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
19957bb3 | 102 | const u8 *bssid = mgmt->bssid; |
95de817b | 103 | bool was_current = false; |
6829c878 | 104 | |
4ee3e063 | 105 | trace___cfg80211_send_deauth(dev); |
667503dd | 106 | ASSERT_WDEV_LOCK(wdev); |
cb0b4beb | 107 | |
19957bb3 | 108 | if (wdev->current_bss && |
ac422d3c | 109 | ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { |
19957bb3 | 110 | cfg80211_unhold_bss(wdev->current_bss); |
5b112d3d | 111 | cfg80211_put_bss(wiphy, &wdev->current_bss->pub); |
19957bb3 | 112 | wdev->current_bss = NULL; |
3f3b6a8d | 113 | was_current = true; |
19957bb3 | 114 | } |
19957bb3 | 115 | |
5fba4af3 JB |
116 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); |
117 | ||
3f3b6a8d | 118 | if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) { |
6829c878 JB |
119 | u16 reason_code; |
120 | bool from_ap; | |
121 | ||
122 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
123 | ||
ac422d3c | 124 | from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr); |
667503dd | 125 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
6829c878 | 126 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING) { |
667503dd JB |
127 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
128 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
df7fc0f9 | 129 | false, NULL); |
667503dd JB |
130 | } |
131 | } | |
ce470613 | 132 | EXPORT_SYMBOL(__cfg80211_send_deauth); |
667503dd | 133 | |
ce470613 | 134 | void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len) |
667503dd JB |
135 | { |
136 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
137 | ||
ce470613 HS |
138 | wdev_lock(wdev); |
139 | __cfg80211_send_deauth(dev, buf, len); | |
140 | wdev_unlock(wdev); | |
6039f6d2 | 141 | } |
53b46b84 | 142 | EXPORT_SYMBOL(cfg80211_send_deauth); |
6039f6d2 | 143 | |
ce470613 | 144 | void __cfg80211_send_disassoc(struct net_device *dev, |
667503dd | 145 | const u8 *buf, size_t len) |
6039f6d2 | 146 | { |
6829c878 JB |
147 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
148 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 149 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 | 150 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
19957bb3 | 151 | const u8 *bssid = mgmt->bssid; |
19957bb3 JB |
152 | u16 reason_code; |
153 | bool from_ap; | |
6829c878 | 154 | |
4ee3e063 | 155 | trace___cfg80211_send_disassoc(dev); |
596a07c1 | 156 | ASSERT_WDEV_LOCK(wdev); |
cb0b4beb JB |
157 | |
158 | nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); | |
a3b8b056 | 159 | |
596a07c1 JB |
160 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
161 | return; | |
6829c878 | 162 | |
19957bb3 | 163 | if (wdev->current_bss && |
ac422d3c | 164 | ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { |
95de817b JB |
165 | cfg80211_sme_disassoc(dev, wdev->current_bss); |
166 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 167 | cfg80211_put_bss(wiphy, &wdev->current_bss->pub); |
95de817b | 168 | wdev->current_bss = NULL; |
19957bb3 JB |
169 | } else |
170 | WARN_ON(1); | |
6829c878 | 171 | |
6829c878 | 172 | |
19957bb3 JB |
173 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
174 | ||
ac422d3c | 175 | from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr); |
667503dd | 176 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
667503dd | 177 | } |
ce470613 | 178 | EXPORT_SYMBOL(__cfg80211_send_disassoc); |
667503dd | 179 | |
ce470613 | 180 | void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len) |
667503dd JB |
181 | { |
182 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
183 | ||
ce470613 HS |
184 | wdev_lock(wdev); |
185 | __cfg80211_send_disassoc(dev, buf, len); | |
186 | wdev_unlock(wdev); | |
1965c853 | 187 | } |
6829c878 | 188 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
1965c853 | 189 | |
a58ce43f JB |
190 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) |
191 | { | |
192 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
193 | struct wiphy *wiphy = wdev->wiphy; | |
194 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
195 | ||
4ee3e063 | 196 | trace_cfg80211_send_auth_timeout(dev, addr); |
a58ce43f JB |
197 | wdev_lock(wdev); |
198 | ||
199 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); | |
200 | if (wdev->sme_state == CFG80211_SME_CONNECTING) | |
201 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, | |
202 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
203 | false, NULL); | |
204 | ||
667503dd | 205 | wdev_unlock(wdev); |
1965c853 JM |
206 | } |
207 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); | |
208 | ||
cb0b4beb | 209 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
1965c853 | 210 | { |
6829c878 JB |
211 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
212 | struct wiphy *wiphy = wdev->wiphy; | |
1965c853 | 213 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
19957bb3 | 214 | |
4ee3e063 | 215 | trace_cfg80211_send_assoc_timeout(dev, addr); |
667503dd | 216 | wdev_lock(wdev); |
cb0b4beb JB |
217 | |
218 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); | |
6829c878 | 219 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
667503dd JB |
220 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
221 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
df7fc0f9 | 222 | false, NULL); |
19957bb3 | 223 | |
667503dd | 224 | wdev_unlock(wdev); |
1965c853 JM |
225 | } |
226 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); | |
227 | ||
a3b8b056 JM |
228 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
229 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 230 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
231 | { |
232 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | |
233 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
3d23e349 | 234 | #ifdef CONFIG_CFG80211_WEXT |
f58d4ed9 | 235 | union iwreq_data wrqu; |
e6d6e342 | 236 | char *buf = kmalloc(128, gfp); |
f58d4ed9 JB |
237 | |
238 | if (buf) { | |
239 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" | |
240 | "keyid=%d %scast addr=%pM)", key_id, | |
241 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", | |
242 | addr); | |
243 | memset(&wrqu, 0, sizeof(wrqu)); | |
244 | wrqu.data.length = strlen(buf); | |
245 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); | |
246 | kfree(buf); | |
247 | } | |
248 | #endif | |
249 | ||
4ee3e063 | 250 | trace_cfg80211_michael_mic_failure(dev, addr, key_type, key_id, tsc); |
e6d6e342 | 251 | nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp); |
a3b8b056 JM |
252 | } |
253 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); | |
19957bb3 JB |
254 | |
255 | /* some MLME handling for userspace SME */ | |
667503dd JB |
256 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
257 | struct net_device *dev, | |
258 | struct ieee80211_channel *chan, | |
259 | enum nl80211_auth_type auth_type, | |
260 | const u8 *bssid, | |
261 | const u8 *ssid, int ssid_len, | |
fffd0934 | 262 | const u8 *ie, int ie_len, |
e39e5b5e JM |
263 | const u8 *key, int key_len, int key_idx, |
264 | const u8 *sae_data, int sae_data_len) | |
19957bb3 JB |
265 | { |
266 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
267 | struct cfg80211_auth_request req; | |
95de817b | 268 | int err; |
19957bb3 | 269 | |
667503dd JB |
270 | ASSERT_WDEV_LOCK(wdev); |
271 | ||
fffd0934 JB |
272 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
273 | if (!key || !key_len || key_idx < 0 || key_idx > 4) | |
274 | return -EINVAL; | |
275 | ||
0a9b5e17 | 276 | if (wdev->current_bss && |
ac422d3c | 277 | ether_addr_equal(bssid, wdev->current_bss->pub.bssid)) |
0a9b5e17 JB |
278 | return -EALREADY; |
279 | ||
19957bb3 JB |
280 | memset(&req, 0, sizeof(req)); |
281 | ||
282 | req.ie = ie; | |
283 | req.ie_len = ie_len; | |
e39e5b5e JM |
284 | req.sae_data = sae_data; |
285 | req.sae_data_len = sae_data_len; | |
19957bb3 JB |
286 | req.auth_type = auth_type; |
287 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, | |
288 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); | |
fffd0934 JB |
289 | req.key = key; |
290 | req.key_len = key_len; | |
291 | req.key_idx = key_idx; | |
19957bb3 JB |
292 | if (!req.bss) |
293 | return -ENOENT; | |
294 | ||
e4e32459 MK |
295 | err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel, |
296 | CHAN_MODE_SHARED); | |
297 | if (err) | |
298 | goto out; | |
299 | ||
e35e4d28 | 300 | err = rdev_auth(rdev, dev, &req); |
19957bb3 | 301 | |
e4e32459 | 302 | out: |
5b112d3d | 303 | cfg80211_put_bss(&rdev->wiphy, req.bss); |
19957bb3 JB |
304 | return err; |
305 | } | |
306 | ||
667503dd JB |
307 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
308 | struct net_device *dev, struct ieee80211_channel *chan, | |
309 | enum nl80211_auth_type auth_type, const u8 *bssid, | |
310 | const u8 *ssid, int ssid_len, | |
fffd0934 | 311 | const u8 *ie, int ie_len, |
e39e5b5e JM |
312 | const u8 *key, int key_len, int key_idx, |
313 | const u8 *sae_data, int sae_data_len) | |
667503dd JB |
314 | { |
315 | int err; | |
316 | ||
e4e32459 | 317 | mutex_lock(&rdev->devlist_mtx); |
667503dd JB |
318 | wdev_lock(dev->ieee80211_ptr); |
319 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
fffd0934 | 320 | ssid, ssid_len, ie, ie_len, |
e39e5b5e JM |
321 | key, key_len, key_idx, |
322 | sae_data, sae_data_len); | |
667503dd | 323 | wdev_unlock(dev->ieee80211_ptr); |
e4e32459 | 324 | mutex_unlock(&rdev->devlist_mtx); |
667503dd JB |
325 | |
326 | return err; | |
327 | } | |
328 | ||
7e7c8926 BG |
329 | /* Do a logical ht_capa &= ht_capa_mask. */ |
330 | void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa, | |
331 | const struct ieee80211_ht_cap *ht_capa_mask) | |
332 | { | |
333 | int i; | |
334 | u8 *p1, *p2; | |
335 | if (!ht_capa_mask) { | |
336 | memset(ht_capa, 0, sizeof(*ht_capa)); | |
337 | return; | |
338 | } | |
339 | ||
340 | p1 = (u8*)(ht_capa); | |
341 | p2 = (u8*)(ht_capa_mask); | |
342 | for (i = 0; i<sizeof(*ht_capa); i++) | |
343 | p1[i] &= p2[i]; | |
344 | } | |
345 | ||
ee2aca34 JB |
346 | /* Do a logical ht_capa &= ht_capa_mask. */ |
347 | void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa, | |
348 | const struct ieee80211_vht_cap *vht_capa_mask) | |
349 | { | |
350 | int i; | |
351 | u8 *p1, *p2; | |
352 | if (!vht_capa_mask) { | |
353 | memset(vht_capa, 0, sizeof(*vht_capa)); | |
354 | return; | |
355 | } | |
356 | ||
357 | p1 = (u8*)(vht_capa); | |
358 | p2 = (u8*)(vht_capa_mask); | |
359 | for (i = 0; i < sizeof(*vht_capa); i++) | |
360 | p1[i] &= p2[i]; | |
361 | } | |
362 | ||
667503dd JB |
363 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
364 | struct net_device *dev, | |
365 | struct ieee80211_channel *chan, | |
f62fab73 | 366 | const u8 *bssid, |
667503dd | 367 | const u8 *ssid, int ssid_len, |
f62fab73 | 368 | struct cfg80211_assoc_request *req) |
19957bb3 JB |
369 | { |
370 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
95de817b | 371 | int err; |
24b6b15f | 372 | bool was_connected = false; |
19957bb3 | 373 | |
667503dd JB |
374 | ASSERT_WDEV_LOCK(wdev); |
375 | ||
f62fab73 JB |
376 | if (wdev->current_bss && req->prev_bssid && |
377 | ether_addr_equal(wdev->current_bss->pub.bssid, req->prev_bssid)) { | |
24b6b15f JM |
378 | /* |
379 | * Trying to reassociate: Allow this to proceed and let the old | |
380 | * association to be dropped when the new one is completed. | |
381 | */ | |
382 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { | |
383 | was_connected = true; | |
384 | wdev->sme_state = CFG80211_SME_CONNECTING; | |
385 | } | |
386 | } else if (wdev->current_bss) | |
19957bb3 JB |
387 | return -EALREADY; |
388 | ||
f62fab73 | 389 | cfg80211_oper_and_ht_capa(&req->ht_capa_mask, |
7e7c8926 | 390 | rdev->wiphy.ht_capa_mod_mask); |
f62fab73 | 391 | cfg80211_oper_and_vht_capa(&req->vht_capa_mask, |
ee2aca34 | 392 | rdev->wiphy.vht_capa_mod_mask); |
7e7c8926 | 393 | |
f62fab73 JB |
394 | req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
395 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); | |
396 | if (!req->bss) { | |
24b6b15f JM |
397 | if (was_connected) |
398 | wdev->sme_state = CFG80211_SME_CONNECTED; | |
19957bb3 | 399 | return -ENOENT; |
24b6b15f | 400 | } |
19957bb3 | 401 | |
f62fab73 | 402 | err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED); |
e4e32459 MK |
403 | if (err) |
404 | goto out; | |
405 | ||
f62fab73 | 406 | err = rdev_assoc(rdev, dev, req); |
19957bb3 | 407 | |
e4e32459 | 408 | out: |
95de817b JB |
409 | if (err) { |
410 | if (was_connected) | |
411 | wdev->sme_state = CFG80211_SME_CONNECTED; | |
f62fab73 | 412 | cfg80211_put_bss(&rdev->wiphy, req->bss); |
19957bb3 JB |
413 | } |
414 | ||
19957bb3 JB |
415 | return err; |
416 | } | |
417 | ||
667503dd JB |
418 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
419 | struct net_device *dev, | |
420 | struct ieee80211_channel *chan, | |
f62fab73 | 421 | const u8 *bssid, |
667503dd | 422 | const u8 *ssid, int ssid_len, |
f62fab73 | 423 | struct cfg80211_assoc_request *req) |
667503dd JB |
424 | { |
425 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
426 | int err; | |
427 | ||
e4e32459 | 428 | mutex_lock(&rdev->devlist_mtx); |
667503dd | 429 | wdev_lock(wdev); |
f62fab73 JB |
430 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
431 | ssid, ssid_len, req); | |
667503dd | 432 | wdev_unlock(wdev); |
e4e32459 | 433 | mutex_unlock(&rdev->devlist_mtx); |
667503dd JB |
434 | |
435 | return err; | |
436 | } | |
437 | ||
438 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, | |
439 | struct net_device *dev, const u8 *bssid, | |
d5cdfacb JM |
440 | const u8 *ie, int ie_len, u16 reason, |
441 | bool local_state_change) | |
19957bb3 JB |
442 | { |
443 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
95de817b JB |
444 | struct cfg80211_deauth_request req = { |
445 | .bssid = bssid, | |
446 | .reason_code = reason, | |
447 | .ie = ie, | |
448 | .ie_len = ie_len, | |
6863255b | 449 | .local_state_change = local_state_change, |
95de817b | 450 | }; |
19957bb3 | 451 | |
667503dd JB |
452 | ASSERT_WDEV_LOCK(wdev); |
453 | ||
6863255b SG |
454 | if (local_state_change && (!wdev->current_bss || |
455 | !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) | |
95de817b | 456 | return 0; |
19957bb3 | 457 | |
e35e4d28 | 458 | return rdev_deauth(rdev, dev, &req); |
19957bb3 JB |
459 | } |
460 | ||
667503dd JB |
461 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
462 | struct net_device *dev, const u8 *bssid, | |
d5cdfacb JM |
463 | const u8 *ie, int ie_len, u16 reason, |
464 | bool local_state_change) | |
667503dd JB |
465 | { |
466 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
467 | int err; | |
468 | ||
469 | wdev_lock(wdev); | |
d5cdfacb JM |
470 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason, |
471 | local_state_change); | |
667503dd JB |
472 | wdev_unlock(wdev); |
473 | ||
474 | return err; | |
475 | } | |
476 | ||
477 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, | |
478 | struct net_device *dev, const u8 *bssid, | |
d5cdfacb JM |
479 | const u8 *ie, int ie_len, u16 reason, |
480 | bool local_state_change) | |
19957bb3 JB |
481 | { |
482 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
483 | struct cfg80211_disassoc_request req; | |
484 | ||
667503dd JB |
485 | ASSERT_WDEV_LOCK(wdev); |
486 | ||
f9d6b402 JB |
487 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
488 | return -ENOTCONN; | |
489 | ||
8dcf011a | 490 | if (WARN(!wdev->current_bss, "sme_state=%d\n", wdev->sme_state)) |
f9d6b402 JB |
491 | return -ENOTCONN; |
492 | ||
19957bb3 JB |
493 | memset(&req, 0, sizeof(req)); |
494 | req.reason_code = reason; | |
d5cdfacb | 495 | req.local_state_change = local_state_change; |
19957bb3 JB |
496 | req.ie = ie; |
497 | req.ie_len = ie_len; | |
ac422d3c | 498 | if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) |
19957bb3 JB |
499 | req.bss = &wdev->current_bss->pub; |
500 | else | |
501 | return -ENOTCONN; | |
502 | ||
e35e4d28 | 503 | return rdev_disassoc(rdev, dev, &req); |
667503dd JB |
504 | } |
505 | ||
506 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, | |
507 | struct net_device *dev, const u8 *bssid, | |
d5cdfacb JM |
508 | const u8 *ie, int ie_len, u16 reason, |
509 | bool local_state_change) | |
667503dd JB |
510 | { |
511 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
512 | int err; | |
513 | ||
514 | wdev_lock(wdev); | |
d5cdfacb JM |
515 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason, |
516 | local_state_change); | |
667503dd JB |
517 | wdev_unlock(wdev); |
518 | ||
519 | return err; | |
19957bb3 JB |
520 | } |
521 | ||
522 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, | |
523 | struct net_device *dev) | |
524 | { | |
525 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
526 | struct cfg80211_deauth_request req; | |
95de817b | 527 | u8 bssid[ETH_ALEN]; |
19957bb3 | 528 | |
667503dd JB |
529 | ASSERT_WDEV_LOCK(wdev); |
530 | ||
19957bb3 JB |
531 | if (!rdev->ops->deauth) |
532 | return; | |
533 | ||
534 | memset(&req, 0, sizeof(req)); | |
535 | req.reason_code = WLAN_REASON_DEAUTH_LEAVING; | |
536 | req.ie = NULL; | |
537 | req.ie_len = 0; | |
538 | ||
95de817b JB |
539 | if (!wdev->current_bss) |
540 | return; | |
19957bb3 | 541 | |
95de817b JB |
542 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); |
543 | req.bssid = bssid; | |
e35e4d28 | 544 | rdev_deauth(rdev, dev, &req); |
95de817b JB |
545 | |
546 | if (wdev->current_bss) { | |
547 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 548 | cfg80211_put_bss(&rdev->wiphy, &wdev->current_bss->pub); |
95de817b | 549 | wdev->current_bss = NULL; |
19957bb3 JB |
550 | } |
551 | } | |
9588bbd5 | 552 | |
2e161f78 | 553 | struct cfg80211_mgmt_registration { |
026331c4 JM |
554 | struct list_head list; |
555 | ||
15e47304 | 556 | u32 nlportid; |
026331c4 JM |
557 | |
558 | int match_len; | |
559 | ||
2e161f78 JB |
560 | __le16 frame_type; |
561 | ||
026331c4 JM |
562 | u8 match[]; |
563 | }; | |
564 | ||
15e47304 | 565 | int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid, |
2e161f78 JB |
566 | u16 frame_type, const u8 *match_data, |
567 | int match_len) | |
026331c4 | 568 | { |
271733cf JB |
569 | struct wiphy *wiphy = wdev->wiphy; |
570 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
2e161f78 | 571 | struct cfg80211_mgmt_registration *reg, *nreg; |
026331c4 | 572 | int err = 0; |
2e161f78 JB |
573 | u16 mgmt_type; |
574 | ||
575 | if (!wdev->wiphy->mgmt_stypes) | |
576 | return -EOPNOTSUPP; | |
577 | ||
578 | if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) | |
579 | return -EINVAL; | |
580 | ||
581 | if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) | |
582 | return -EINVAL; | |
583 | ||
584 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; | |
585 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type))) | |
586 | return -EINVAL; | |
026331c4 JM |
587 | |
588 | nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); | |
589 | if (!nreg) | |
590 | return -ENOMEM; | |
591 | ||
2e161f78 | 592 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
026331c4 | 593 | |
2e161f78 | 594 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
026331c4 JM |
595 | int mlen = min(match_len, reg->match_len); |
596 | ||
2e161f78 JB |
597 | if (frame_type != le16_to_cpu(reg->frame_type)) |
598 | continue; | |
599 | ||
026331c4 JM |
600 | if (memcmp(reg->match, match_data, mlen) == 0) { |
601 | err = -EALREADY; | |
602 | break; | |
603 | } | |
604 | } | |
605 | ||
606 | if (err) { | |
607 | kfree(nreg); | |
608 | goto out; | |
609 | } | |
610 | ||
611 | memcpy(nreg->match, match_data, match_len); | |
612 | nreg->match_len = match_len; | |
15e47304 | 613 | nreg->nlportid = snd_portid; |
2e161f78 JB |
614 | nreg->frame_type = cpu_to_le16(frame_type); |
615 | list_add(&nreg->list, &wdev->mgmt_registrations); | |
026331c4 | 616 | |
271733cf | 617 | if (rdev->ops->mgmt_frame_register) |
e35e4d28 | 618 | rdev_mgmt_frame_register(rdev, wdev, frame_type, true); |
271733cf | 619 | |
026331c4 | 620 | out: |
2e161f78 | 621 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
271733cf | 622 | |
026331c4 JM |
623 | return err; |
624 | } | |
625 | ||
15e47304 | 626 | void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlportid) |
026331c4 | 627 | { |
271733cf JB |
628 | struct wiphy *wiphy = wdev->wiphy; |
629 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
2e161f78 | 630 | struct cfg80211_mgmt_registration *reg, *tmp; |
026331c4 | 631 | |
2e161f78 | 632 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
026331c4 | 633 | |
2e161f78 | 634 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
15e47304 | 635 | if (reg->nlportid != nlportid) |
271733cf JB |
636 | continue; |
637 | ||
638 | if (rdev->ops->mgmt_frame_register) { | |
639 | u16 frame_type = le16_to_cpu(reg->frame_type); | |
640 | ||
e35e4d28 HG |
641 | rdev_mgmt_frame_register(rdev, wdev, |
642 | frame_type, false); | |
026331c4 | 643 | } |
271733cf JB |
644 | |
645 | list_del(®->list); | |
646 | kfree(reg); | |
026331c4 JM |
647 | } |
648 | ||
2e161f78 | 649 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
28946da7 | 650 | |
5de17984 AS |
651 | if (nlportid && rdev->crit_proto_nlportid == nlportid) { |
652 | rdev->crit_proto_nlportid = 0; | |
653 | rdev_crit_proto_stop(rdev, wdev); | |
654 | } | |
655 | ||
15e47304 EB |
656 | if (nlportid == wdev->ap_unexpected_nlportid) |
657 | wdev->ap_unexpected_nlportid = 0; | |
026331c4 JM |
658 | } |
659 | ||
2e161f78 | 660 | void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev) |
026331c4 | 661 | { |
2e161f78 | 662 | struct cfg80211_mgmt_registration *reg, *tmp; |
026331c4 | 663 | |
2e161f78 | 664 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
026331c4 | 665 | |
2e161f78 | 666 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
026331c4 JM |
667 | list_del(®->list); |
668 | kfree(reg); | |
669 | } | |
670 | ||
2e161f78 | 671 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
026331c4 JM |
672 | } |
673 | ||
2e161f78 | 674 | int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, |
71bbc994 | 675 | struct wireless_dev *wdev, |
f7ca38df | 676 | struct ieee80211_channel *chan, bool offchan, |
42d97a59 JB |
677 | unsigned int wait, const u8 *buf, size_t len, |
678 | bool no_cck, bool dont_wait_for_ack, u64 *cookie) | |
026331c4 | 679 | { |
026331c4 | 680 | const struct ieee80211_mgmt *mgmt; |
2e161f78 JB |
681 | u16 stype; |
682 | ||
683 | if (!wdev->wiphy->mgmt_stypes) | |
684 | return -EOPNOTSUPP; | |
026331c4 | 685 | |
2e161f78 | 686 | if (!rdev->ops->mgmt_tx) |
026331c4 | 687 | return -EOPNOTSUPP; |
2e161f78 | 688 | |
026331c4 JM |
689 | if (len < 24 + 1) |
690 | return -EINVAL; | |
691 | ||
692 | mgmt = (const struct ieee80211_mgmt *) buf; | |
2e161f78 JB |
693 | |
694 | if (!ieee80211_is_mgmt(mgmt->frame_control)) | |
026331c4 | 695 | return -EINVAL; |
2e161f78 JB |
696 | |
697 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; | |
698 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4))) | |
699 | return -EINVAL; | |
700 | ||
701 | if (ieee80211_is_action(mgmt->frame_control) && | |
702 | mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { | |
663fcafd JB |
703 | int err = 0; |
704 | ||
fe100acd JB |
705 | wdev_lock(wdev); |
706 | ||
663fcafd JB |
707 | switch (wdev->iftype) { |
708 | case NL80211_IFTYPE_ADHOC: | |
709 | case NL80211_IFTYPE_STATION: | |
710 | case NL80211_IFTYPE_P2P_CLIENT: | |
711 | if (!wdev->current_bss) { | |
712 | err = -ENOTCONN; | |
713 | break; | |
714 | } | |
715 | ||
ac422d3c JP |
716 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
717 | mgmt->bssid)) { | |
663fcafd JB |
718 | err = -ENOTCONN; |
719 | break; | |
720 | } | |
721 | ||
722 | /* | |
723 | * check for IBSS DA must be done by driver as | |
724 | * cfg80211 doesn't track the stations | |
725 | */ | |
726 | if (wdev->iftype == NL80211_IFTYPE_ADHOC) | |
727 | break; | |
fe100acd | 728 | |
663fcafd | 729 | /* for station, check that DA is the AP */ |
ac422d3c JP |
730 | if (!ether_addr_equal(wdev->current_bss->pub.bssid, |
731 | mgmt->da)) { | |
663fcafd JB |
732 | err = -ENOTCONN; |
733 | break; | |
734 | } | |
735 | break; | |
736 | case NL80211_IFTYPE_AP: | |
737 | case NL80211_IFTYPE_P2P_GO: | |
738 | case NL80211_IFTYPE_AP_VLAN: | |
98104fde | 739 | if (!ether_addr_equal(mgmt->bssid, wdev_address(wdev))) |
663fcafd JB |
740 | err = -EINVAL; |
741 | break; | |
0778a6a3 | 742 | case NL80211_IFTYPE_MESH_POINT: |
ac422d3c | 743 | if (!ether_addr_equal(mgmt->sa, mgmt->bssid)) { |
0778a6a3 JC |
744 | err = -EINVAL; |
745 | break; | |
746 | } | |
747 | /* | |
748 | * check for mesh DA must be done by driver as | |
749 | * cfg80211 doesn't track the stations | |
750 | */ | |
751 | break; | |
98104fde JB |
752 | case NL80211_IFTYPE_P2P_DEVICE: |
753 | /* | |
754 | * fall through, P2P device only supports | |
755 | * public action frames | |
756 | */ | |
663fcafd JB |
757 | default: |
758 | err = -EOPNOTSUPP; | |
759 | break; | |
760 | } | |
fe100acd | 761 | wdev_unlock(wdev); |
663fcafd JB |
762 | |
763 | if (err) | |
764 | return err; | |
026331c4 JM |
765 | } |
766 | ||
98104fde | 767 | if (!ether_addr_equal(mgmt->sa, wdev_address(wdev))) |
026331c4 JM |
768 | return -EINVAL; |
769 | ||
770 | /* Transmit the Action frame as requested by user space */ | |
e35e4d28 | 771 | return rdev_mgmt_tx(rdev, wdev, chan, offchan, |
e35e4d28 HG |
772 | wait, buf, len, no_cck, dont_wait_for_ack, |
773 | cookie); | |
026331c4 JM |
774 | } |
775 | ||
71bbc994 | 776 | bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_mbm, |
804483e9 | 777 | const u8 *buf, size_t len, gfp_t gfp) |
026331c4 | 778 | { |
026331c4 JM |
779 | struct wiphy *wiphy = wdev->wiphy; |
780 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
2e161f78 JB |
781 | struct cfg80211_mgmt_registration *reg; |
782 | const struct ieee80211_txrx_stypes *stypes = | |
783 | &wiphy->mgmt_stypes[wdev->iftype]; | |
784 | struct ieee80211_mgmt *mgmt = (void *)buf; | |
785 | const u8 *data; | |
786 | int data_len; | |
026331c4 | 787 | bool result = false; |
2e161f78 JB |
788 | __le16 ftype = mgmt->frame_control & |
789 | cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE); | |
790 | u16 stype; | |
026331c4 | 791 | |
4ee3e063 | 792 | trace_cfg80211_rx_mgmt(wdev, freq, sig_mbm); |
2e161f78 | 793 | stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4; |
026331c4 | 794 | |
4ee3e063 BL |
795 | if (!(stypes->rx & BIT(stype))) { |
796 | trace_cfg80211_return_bool(false); | |
2e161f78 | 797 | return false; |
4ee3e063 | 798 | } |
026331c4 | 799 | |
2e161f78 JB |
800 | data = buf + ieee80211_hdrlen(mgmt->frame_control); |
801 | data_len = len - ieee80211_hdrlen(mgmt->frame_control); | |
802 | ||
803 | spin_lock_bh(&wdev->mgmt_registrations_lock); | |
804 | ||
805 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { | |
806 | if (reg->frame_type != ftype) | |
807 | continue; | |
026331c4 | 808 | |
2e161f78 | 809 | if (reg->match_len > data_len) |
026331c4 JM |
810 | continue; |
811 | ||
2e161f78 | 812 | if (memcmp(reg->match, data, reg->match_len)) |
026331c4 JM |
813 | continue; |
814 | ||
815 | /* found match! */ | |
816 | ||
817 | /* Indicate the received Action frame to user space */ | |
15e47304 | 818 | if (nl80211_send_mgmt(rdev, wdev, reg->nlportid, |
804483e9 | 819 | freq, sig_mbm, |
2e161f78 | 820 | buf, len, gfp)) |
026331c4 JM |
821 | continue; |
822 | ||
823 | result = true; | |
824 | break; | |
825 | } | |
826 | ||
2e161f78 | 827 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
026331c4 | 828 | |
4ee3e063 | 829 | trace_cfg80211_return_bool(result); |
026331c4 JM |
830 | return result; |
831 | } | |
2e161f78 | 832 | EXPORT_SYMBOL(cfg80211_rx_mgmt); |
026331c4 | 833 | |
04f39047 SW |
834 | void cfg80211_dfs_channels_update_work(struct work_struct *work) |
835 | { | |
836 | struct delayed_work *delayed_work; | |
837 | struct cfg80211_registered_device *rdev; | |
838 | struct cfg80211_chan_def chandef; | |
839 | struct ieee80211_supported_band *sband; | |
840 | struct ieee80211_channel *c; | |
841 | struct wiphy *wiphy; | |
842 | bool check_again = false; | |
843 | unsigned long timeout, next_time = 0; | |
844 | int bandid, i; | |
845 | ||
846 | delayed_work = container_of(work, struct delayed_work, work); | |
847 | rdev = container_of(delayed_work, struct cfg80211_registered_device, | |
848 | dfs_update_channels_wk); | |
849 | wiphy = &rdev->wiphy; | |
850 | ||
851 | mutex_lock(&cfg80211_mutex); | |
852 | for (bandid = 0; bandid < IEEE80211_NUM_BANDS; bandid++) { | |
853 | sband = wiphy->bands[bandid]; | |
854 | if (!sband) | |
855 | continue; | |
856 | ||
857 | for (i = 0; i < sband->n_channels; i++) { | |
858 | c = &sband->channels[i]; | |
859 | ||
860 | if (c->dfs_state != NL80211_DFS_UNAVAILABLE) | |
861 | continue; | |
862 | ||
863 | timeout = c->dfs_state_entered + | |
864 | IEEE80211_DFS_MIN_NOP_TIME_MS; | |
865 | ||
866 | if (time_after_eq(jiffies, timeout)) { | |
867 | c->dfs_state = NL80211_DFS_USABLE; | |
868 | cfg80211_chandef_create(&chandef, c, | |
869 | NL80211_CHAN_NO_HT); | |
870 | ||
871 | nl80211_radar_notify(rdev, &chandef, | |
872 | NL80211_RADAR_NOP_FINISHED, | |
873 | NULL, GFP_ATOMIC); | |
874 | continue; | |
875 | } | |
876 | ||
877 | if (!check_again) | |
878 | next_time = timeout - jiffies; | |
879 | else | |
880 | next_time = min(next_time, timeout - jiffies); | |
881 | check_again = true; | |
882 | } | |
883 | } | |
884 | mutex_unlock(&cfg80211_mutex); | |
885 | ||
886 | /* reschedule if there are other channels waiting to be cleared again */ | |
887 | if (check_again) | |
888 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, | |
889 | next_time); | |
890 | } | |
891 | ||
892 | ||
893 | void cfg80211_radar_event(struct wiphy *wiphy, | |
894 | struct cfg80211_chan_def *chandef, | |
895 | gfp_t gfp) | |
896 | { | |
897 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
898 | unsigned long timeout; | |
899 | ||
900 | trace_cfg80211_radar_event(wiphy, chandef); | |
901 | ||
902 | /* only set the chandef supplied channel to unavailable, in | |
903 | * case the radar is detected on only one of multiple channels | |
904 | * spanned by the chandef. | |
905 | */ | |
906 | cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_UNAVAILABLE); | |
907 | ||
908 | timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS); | |
909 | queue_delayed_work(cfg80211_wq, &rdev->dfs_update_channels_wk, | |
910 | timeout); | |
911 | ||
912 | nl80211_radar_notify(rdev, chandef, NL80211_RADAR_DETECTED, NULL, gfp); | |
913 | } | |
914 | EXPORT_SYMBOL(cfg80211_radar_event); | |
915 | ||
916 | void cfg80211_cac_event(struct net_device *netdev, | |
917 | enum nl80211_radar_event event, gfp_t gfp) | |
918 | { | |
919 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
920 | struct wiphy *wiphy = wdev->wiphy; | |
921 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
922 | struct cfg80211_chan_def chandef; | |
923 | unsigned long timeout; | |
924 | ||
925 | trace_cfg80211_cac_event(netdev, event); | |
926 | ||
927 | if (WARN_ON(!wdev->cac_started)) | |
928 | return; | |
929 | ||
930 | if (WARN_ON(!wdev->channel)) | |
931 | return; | |
932 | ||
933 | cfg80211_chandef_create(&chandef, wdev->channel, NL80211_CHAN_NO_HT); | |
934 | ||
935 | switch (event) { | |
936 | case NL80211_RADAR_CAC_FINISHED: | |
937 | timeout = wdev->cac_start_time + | |
938 | msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS); | |
939 | WARN_ON(!time_after_eq(jiffies, timeout)); | |
940 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_AVAILABLE); | |
941 | break; | |
942 | case NL80211_RADAR_CAC_ABORTED: | |
943 | break; | |
944 | default: | |
945 | WARN_ON(1); | |
946 | return; | |
947 | } | |
948 | wdev->cac_started = false; | |
949 | ||
950 | nl80211_radar_notify(rdev, &chandef, event, netdev, gfp); | |
951 | } | |
952 | EXPORT_SYMBOL(cfg80211_cac_event); |