2 * cfg80211 MLME SAP interface
4 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * Copyright (c) 2015 Intel Deutschland GmbH
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/etherdevice.h>
11 #include <linux/netdevice.h>
12 #include <linux/nl80211.h>
13 #include <linux/slab.h>
14 #include <linux/wireless.h>
15 #include <net/cfg80211.h>
16 #include <net/iw_handler.h>
22 void cfg80211_rx_assoc_resp(struct net_device
*dev
, struct cfg80211_bss
*bss
,
23 const u8
*buf
, size_t len
, int uapsd_queues
)
25 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
26 struct wiphy
*wiphy
= wdev
->wiphy
;
27 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
28 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
29 u8
*ie
= mgmt
->u
.assoc_resp
.variable
;
30 int ieoffs
= offsetof(struct ieee80211_mgmt
, u
.assoc_resp
.variable
);
31 u16 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
33 trace_cfg80211_send_rx_assoc(dev
, bss
);
36 * This is a bit of a hack, we don't notify userspace of
37 * a (re-)association reply if we tried to send a reassoc
38 * and got a reject -- we only try again with an assoc
39 * frame instead of reassoc.
41 if (cfg80211_sme_rx_assoc_resp(wdev
, status_code
)) {
42 cfg80211_unhold_bss(bss_from_pub(bss
));
43 cfg80211_put_bss(wiphy
, bss
);
47 nl80211_send_rx_assoc(rdev
, dev
, buf
, len
, GFP_KERNEL
, uapsd_queues
);
48 /* update current_bss etc., consumes the bss reference */
49 __cfg80211_connect_result(dev
, mgmt
->bssid
, NULL
, 0, ie
, len
- ieoffs
,
51 status_code
== WLAN_STATUS_SUCCESS
, bss
);
53 EXPORT_SYMBOL(cfg80211_rx_assoc_resp
);
55 static void cfg80211_process_auth(struct wireless_dev
*wdev
,
56 const u8
*buf
, size_t len
)
58 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
60 nl80211_send_rx_auth(rdev
, wdev
->netdev
, buf
, len
, GFP_KERNEL
);
61 cfg80211_sme_rx_auth(wdev
, buf
, len
);
64 static void cfg80211_process_deauth(struct wireless_dev
*wdev
,
65 const u8
*buf
, size_t len
)
67 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
68 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
69 const u8
*bssid
= mgmt
->bssid
;
70 u16 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
71 bool from_ap
= !ether_addr_equal(mgmt
->sa
, wdev
->netdev
->dev_addr
);
73 nl80211_send_deauth(rdev
, wdev
->netdev
, buf
, len
, GFP_KERNEL
);
75 if (!wdev
->current_bss
||
76 !ether_addr_equal(wdev
->current_bss
->pub
.bssid
, bssid
))
79 __cfg80211_disconnected(wdev
->netdev
, NULL
, 0, reason_code
, from_ap
);
80 cfg80211_sme_deauth(wdev
);
83 static void cfg80211_process_disassoc(struct wireless_dev
*wdev
,
84 const u8
*buf
, size_t len
)
86 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
87 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
88 const u8
*bssid
= mgmt
->bssid
;
89 u16 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
90 bool from_ap
= !ether_addr_equal(mgmt
->sa
, wdev
->netdev
->dev_addr
);
92 nl80211_send_disassoc(rdev
, wdev
->netdev
, buf
, len
, GFP_KERNEL
);
94 if (WARN_ON(!wdev
->current_bss
||
95 !ether_addr_equal(wdev
->current_bss
->pub
.bssid
, bssid
)))
98 __cfg80211_disconnected(wdev
->netdev
, NULL
, 0, reason_code
, from_ap
);
99 cfg80211_sme_disassoc(wdev
);
102 void cfg80211_rx_mlme_mgmt(struct net_device
*dev
, const u8
*buf
, size_t len
)
104 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
105 struct ieee80211_mgmt
*mgmt
= (void *)buf
;
107 ASSERT_WDEV_LOCK(wdev
);
109 trace_cfg80211_rx_mlme_mgmt(dev
, buf
, len
);
111 if (WARN_ON(len
< 2))
114 if (ieee80211_is_auth(mgmt
->frame_control
))
115 cfg80211_process_auth(wdev
, buf
, len
);
116 else if (ieee80211_is_deauth(mgmt
->frame_control
))
117 cfg80211_process_deauth(wdev
, buf
, len
);
118 else if (ieee80211_is_disassoc(mgmt
->frame_control
))
119 cfg80211_process_disassoc(wdev
, buf
, len
);
121 EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt
);
123 void cfg80211_auth_timeout(struct net_device
*dev
, const u8
*addr
)
125 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
126 struct wiphy
*wiphy
= wdev
->wiphy
;
127 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
129 trace_cfg80211_send_auth_timeout(dev
, addr
);
131 nl80211_send_auth_timeout(rdev
, dev
, addr
, GFP_KERNEL
);
132 cfg80211_sme_auth_timeout(wdev
);
134 EXPORT_SYMBOL(cfg80211_auth_timeout
);
136 void cfg80211_assoc_timeout(struct net_device
*dev
, struct cfg80211_bss
*bss
)
138 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
139 struct wiphy
*wiphy
= wdev
->wiphy
;
140 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
142 trace_cfg80211_send_assoc_timeout(dev
, bss
->bssid
);
144 nl80211_send_assoc_timeout(rdev
, dev
, bss
->bssid
, GFP_KERNEL
);
145 cfg80211_sme_assoc_timeout(wdev
);
147 cfg80211_unhold_bss(bss_from_pub(bss
));
148 cfg80211_put_bss(wiphy
, bss
);
150 EXPORT_SYMBOL(cfg80211_assoc_timeout
);
152 void cfg80211_tx_mlme_mgmt(struct net_device
*dev
, const u8
*buf
, size_t len
)
154 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
155 struct ieee80211_mgmt
*mgmt
= (void *)buf
;
157 ASSERT_WDEV_LOCK(wdev
);
159 trace_cfg80211_tx_mlme_mgmt(dev
, buf
, len
);
161 if (WARN_ON(len
< 2))
164 if (ieee80211_is_deauth(mgmt
->frame_control
))
165 cfg80211_process_deauth(wdev
, buf
, len
);
167 cfg80211_process_disassoc(wdev
, buf
, len
);
169 EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt
);
171 void cfg80211_michael_mic_failure(struct net_device
*dev
, const u8
*addr
,
172 enum nl80211_key_type key_type
, int key_id
,
173 const u8
*tsc
, gfp_t gfp
)
175 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
176 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
177 #ifdef CONFIG_CFG80211_WEXT
178 union iwreq_data wrqu
;
179 char *buf
= kmalloc(128, gfp
);
182 sprintf(buf
, "MLME-MICHAELMICFAILURE.indication("
183 "keyid=%d %scast addr=%pM)", key_id
,
184 key_type
== NL80211_KEYTYPE_GROUP
? "broad" : "uni",
186 memset(&wrqu
, 0, sizeof(wrqu
));
187 wrqu
.data
.length
= strlen(buf
);
188 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
193 trace_cfg80211_michael_mic_failure(dev
, addr
, key_type
, key_id
, tsc
);
194 nl80211_michael_mic_failure(rdev
, dev
, addr
, key_type
, key_id
, tsc
, gfp
);
196 EXPORT_SYMBOL(cfg80211_michael_mic_failure
);
198 /* some MLME handling for userspace SME */
199 int cfg80211_mlme_auth(struct cfg80211_registered_device
*rdev
,
200 struct net_device
*dev
,
201 struct ieee80211_channel
*chan
,
202 enum nl80211_auth_type auth_type
,
204 const u8
*ssid
, int ssid_len
,
205 const u8
*ie
, int ie_len
,
206 const u8
*key
, int key_len
, int key_idx
,
207 const u8
*sae_data
, int sae_data_len
)
209 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
210 struct cfg80211_auth_request req
= {
213 .sae_data
= sae_data
,
214 .sae_data_len
= sae_data_len
,
215 .auth_type
= auth_type
,
222 ASSERT_WDEV_LOCK(wdev
);
224 if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
225 if (!key
|| !key_len
|| key_idx
< 0 || key_idx
> 4)
228 if (wdev
->current_bss
&&
229 ether_addr_equal(bssid
, wdev
->current_bss
->pub
.bssid
))
232 req
.bss
= cfg80211_get_bss(&rdev
->wiphy
, chan
, bssid
, ssid
, ssid_len
,
233 IEEE80211_BSS_TYPE_ESS
,
234 IEEE80211_PRIVACY_ANY
);
238 err
= rdev_auth(rdev
, dev
, &req
);
240 cfg80211_put_bss(&rdev
->wiphy
, req
.bss
);
244 /* Do a logical ht_capa &= ht_capa_mask. */
245 void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap
*ht_capa
,
246 const struct ieee80211_ht_cap
*ht_capa_mask
)
251 memset(ht_capa
, 0, sizeof(*ht_capa
));
256 p2
= (u8
*)(ht_capa_mask
);
257 for (i
= 0; i
<sizeof(*ht_capa
); i
++)
261 /* Do a logical ht_capa &= ht_capa_mask. */
262 void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap
*vht_capa
,
263 const struct ieee80211_vht_cap
*vht_capa_mask
)
267 if (!vht_capa_mask
) {
268 memset(vht_capa
, 0, sizeof(*vht_capa
));
272 p1
= (u8
*)(vht_capa
);
273 p2
= (u8
*)(vht_capa_mask
);
274 for (i
= 0; i
< sizeof(*vht_capa
); i
++)
278 int cfg80211_mlme_assoc(struct cfg80211_registered_device
*rdev
,
279 struct net_device
*dev
,
280 struct ieee80211_channel
*chan
,
282 const u8
*ssid
, int ssid_len
,
283 struct cfg80211_assoc_request
*req
)
285 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
288 ASSERT_WDEV_LOCK(wdev
);
290 if (wdev
->current_bss
&&
291 (!req
->prev_bssid
|| !ether_addr_equal(wdev
->current_bss
->pub
.bssid
,
295 cfg80211_oper_and_ht_capa(&req
->ht_capa_mask
,
296 rdev
->wiphy
.ht_capa_mod_mask
);
297 cfg80211_oper_and_vht_capa(&req
->vht_capa_mask
,
298 rdev
->wiphy
.vht_capa_mod_mask
);
300 req
->bss
= cfg80211_get_bss(&rdev
->wiphy
, chan
, bssid
, ssid
, ssid_len
,
301 IEEE80211_BSS_TYPE_ESS
,
302 IEEE80211_PRIVACY_ANY
);
306 err
= rdev_assoc(rdev
, dev
, req
);
308 cfg80211_hold_bss(bss_from_pub(req
->bss
));
310 cfg80211_put_bss(&rdev
->wiphy
, req
->bss
);
315 int cfg80211_mlme_deauth(struct cfg80211_registered_device
*rdev
,
316 struct net_device
*dev
, const u8
*bssid
,
317 const u8
*ie
, int ie_len
, u16 reason
,
318 bool local_state_change
)
320 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
321 struct cfg80211_deauth_request req
= {
323 .reason_code
= reason
,
326 .local_state_change
= local_state_change
,
329 ASSERT_WDEV_LOCK(wdev
);
331 if (local_state_change
&&
332 (!wdev
->current_bss
||
333 !ether_addr_equal(wdev
->current_bss
->pub
.bssid
, bssid
)))
336 return rdev_deauth(rdev
, dev
, &req
);
339 int cfg80211_mlme_disassoc(struct cfg80211_registered_device
*rdev
,
340 struct net_device
*dev
, const u8
*bssid
,
341 const u8
*ie
, int ie_len
, u16 reason
,
342 bool local_state_change
)
344 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
345 struct cfg80211_disassoc_request req
= {
346 .reason_code
= reason
,
347 .local_state_change
= local_state_change
,
353 ASSERT_WDEV_LOCK(wdev
);
355 if (!wdev
->current_bss
)
358 if (ether_addr_equal(wdev
->current_bss
->pub
.bssid
, bssid
))
359 req
.bss
= &wdev
->current_bss
->pub
;
363 err
= rdev_disassoc(rdev
, dev
, &req
);
367 /* driver should have reported the disassoc */
368 WARN_ON(wdev
->current_bss
);
372 void cfg80211_mlme_down(struct cfg80211_registered_device
*rdev
,
373 struct net_device
*dev
)
375 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
378 ASSERT_WDEV_LOCK(wdev
);
380 if (!rdev
->ops
->deauth
)
383 if (!wdev
->current_bss
)
386 memcpy(bssid
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
);
387 cfg80211_mlme_deauth(rdev
, dev
, bssid
, NULL
, 0,
388 WLAN_REASON_DEAUTH_LEAVING
, false);
391 struct cfg80211_mgmt_registration
{
392 struct list_head list
;
393 struct wireless_dev
*wdev
;
405 cfg80211_process_mlme_unregistrations(struct cfg80211_registered_device
*rdev
)
407 struct cfg80211_mgmt_registration
*reg
;
411 spin_lock_bh(&rdev
->mlme_unreg_lock
);
412 while ((reg
= list_first_entry_or_null(&rdev
->mlme_unreg
,
413 struct cfg80211_mgmt_registration
,
415 list_del(®
->list
);
416 spin_unlock_bh(&rdev
->mlme_unreg_lock
);
418 if (rdev
->ops
->mgmt_frame_register
) {
419 u16 frame_type
= le16_to_cpu(reg
->frame_type
);
421 rdev_mgmt_frame_register(rdev
, reg
->wdev
,
427 spin_lock_bh(&rdev
->mlme_unreg_lock
);
429 spin_unlock_bh(&rdev
->mlme_unreg_lock
);
432 void cfg80211_mlme_unreg_wk(struct work_struct
*wk
)
434 struct cfg80211_registered_device
*rdev
;
436 rdev
= container_of(wk
, struct cfg80211_registered_device
,
440 cfg80211_process_mlme_unregistrations(rdev
);
444 int cfg80211_mlme_register_mgmt(struct wireless_dev
*wdev
, u32 snd_portid
,
445 u16 frame_type
, const u8
*match_data
,
448 struct wiphy
*wiphy
= wdev
->wiphy
;
449 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
450 struct cfg80211_mgmt_registration
*reg
, *nreg
;
454 if (!wdev
->wiphy
->mgmt_stypes
)
457 if ((frame_type
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
)
460 if (frame_type
& ~(IEEE80211_FCTL_FTYPE
| IEEE80211_FCTL_STYPE
))
463 mgmt_type
= (frame_type
& IEEE80211_FCTL_STYPE
) >> 4;
464 if (!(wdev
->wiphy
->mgmt_stypes
[wdev
->iftype
].rx
& BIT(mgmt_type
)))
467 nreg
= kzalloc(sizeof(*reg
) + match_len
, GFP_KERNEL
);
471 spin_lock_bh(&wdev
->mgmt_registrations_lock
);
473 list_for_each_entry(reg
, &wdev
->mgmt_registrations
, list
) {
474 int mlen
= min(match_len
, reg
->match_len
);
476 if (frame_type
!= le16_to_cpu(reg
->frame_type
))
479 if (memcmp(reg
->match
, match_data
, mlen
) == 0) {
490 memcpy(nreg
->match
, match_data
, match_len
);
491 nreg
->match_len
= match_len
;
492 nreg
->nlportid
= snd_portid
;
493 nreg
->frame_type
= cpu_to_le16(frame_type
);
495 list_add(&nreg
->list
, &wdev
->mgmt_registrations
);
496 spin_unlock_bh(&wdev
->mgmt_registrations_lock
);
498 /* process all unregistrations to avoid driver confusion */
499 cfg80211_process_mlme_unregistrations(rdev
);
501 if (rdev
->ops
->mgmt_frame_register
)
502 rdev_mgmt_frame_register(rdev
, wdev
, frame_type
, true);
507 spin_unlock_bh(&wdev
->mgmt_registrations_lock
);
512 void cfg80211_mlme_unregister_socket(struct wireless_dev
*wdev
, u32 nlportid
)
514 struct wiphy
*wiphy
= wdev
->wiphy
;
515 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
516 struct cfg80211_mgmt_registration
*reg
, *tmp
;
518 spin_lock_bh(&wdev
->mgmt_registrations_lock
);
520 list_for_each_entry_safe(reg
, tmp
, &wdev
->mgmt_registrations
, list
) {
521 if (reg
->nlportid
!= nlportid
)
524 list_del(®
->list
);
525 spin_lock(&rdev
->mlme_unreg_lock
);
526 list_add_tail(®
->list
, &rdev
->mlme_unreg
);
527 spin_unlock(&rdev
->mlme_unreg_lock
);
529 schedule_work(&rdev
->mlme_unreg_wk
);
532 spin_unlock_bh(&wdev
->mgmt_registrations_lock
);
534 if (nlportid
&& rdev
->crit_proto_nlportid
== nlportid
) {
535 rdev
->crit_proto_nlportid
= 0;
536 rdev_crit_proto_stop(rdev
, wdev
);
539 if (nlportid
== wdev
->ap_unexpected_nlportid
)
540 wdev
->ap_unexpected_nlportid
= 0;
543 void cfg80211_mlme_purge_registrations(struct wireless_dev
*wdev
)
545 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
547 spin_lock_bh(&wdev
->mgmt_registrations_lock
);
548 spin_lock(&rdev
->mlme_unreg_lock
);
549 list_splice_tail_init(&wdev
->mgmt_registrations
, &rdev
->mlme_unreg
);
550 spin_unlock(&rdev
->mlme_unreg_lock
);
551 spin_unlock_bh(&wdev
->mgmt_registrations_lock
);
553 cfg80211_process_mlme_unregistrations(rdev
);
556 int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device
*rdev
,
557 struct wireless_dev
*wdev
,
558 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
560 const struct ieee80211_mgmt
*mgmt
;
563 if (!wdev
->wiphy
->mgmt_stypes
)
566 if (!rdev
->ops
->mgmt_tx
)
569 if (params
->len
< 24 + 1)
572 mgmt
= (const struct ieee80211_mgmt
*)params
->buf
;
574 if (!ieee80211_is_mgmt(mgmt
->frame_control
))
577 stype
= le16_to_cpu(mgmt
->frame_control
) & IEEE80211_FCTL_STYPE
;
578 if (!(wdev
->wiphy
->mgmt_stypes
[wdev
->iftype
].tx
& BIT(stype
>> 4)))
581 if (ieee80211_is_action(mgmt
->frame_control
) &&
582 mgmt
->u
.action
.category
!= WLAN_CATEGORY_PUBLIC
) {
587 switch (wdev
->iftype
) {
588 case NL80211_IFTYPE_ADHOC
:
589 case NL80211_IFTYPE_STATION
:
590 case NL80211_IFTYPE_P2P_CLIENT
:
591 if (!wdev
->current_bss
) {
596 if (!ether_addr_equal(wdev
->current_bss
->pub
.bssid
,
603 * check for IBSS DA must be done by driver as
604 * cfg80211 doesn't track the stations
606 if (wdev
->iftype
== NL80211_IFTYPE_ADHOC
)
609 /* for station, check that DA is the AP */
610 if (!ether_addr_equal(wdev
->current_bss
->pub
.bssid
,
616 case NL80211_IFTYPE_AP
:
617 case NL80211_IFTYPE_P2P_GO
:
618 case NL80211_IFTYPE_AP_VLAN
:
619 if (!ether_addr_equal(mgmt
->bssid
, wdev_address(wdev
)))
622 case NL80211_IFTYPE_MESH_POINT
:
623 if (!ether_addr_equal(mgmt
->sa
, mgmt
->bssid
)) {
628 * check for mesh DA must be done by driver as
629 * cfg80211 doesn't track the stations
632 case NL80211_IFTYPE_P2P_DEVICE
:
634 * fall through, P2P device only supports
635 * public action frames
647 if (!ether_addr_equal(mgmt
->sa
, wdev_address(wdev
)))
650 /* Transmit the Action frame as requested by user space */
651 return rdev_mgmt_tx(rdev
, wdev
, params
, cookie
);
654 bool cfg80211_rx_mgmt(struct wireless_dev
*wdev
, int freq
, int sig_mbm
,
655 const u8
*buf
, size_t len
, u32 flags
)
657 struct wiphy
*wiphy
= wdev
->wiphy
;
658 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
659 struct cfg80211_mgmt_registration
*reg
;
660 const struct ieee80211_txrx_stypes
*stypes
=
661 &wiphy
->mgmt_stypes
[wdev
->iftype
];
662 struct ieee80211_mgmt
*mgmt
= (void *)buf
;
666 __le16 ftype
= mgmt
->frame_control
&
667 cpu_to_le16(IEEE80211_FCTL_FTYPE
| IEEE80211_FCTL_STYPE
);
670 trace_cfg80211_rx_mgmt(wdev
, freq
, sig_mbm
);
671 stype
= (le16_to_cpu(mgmt
->frame_control
) & IEEE80211_FCTL_STYPE
) >> 4;
673 if (!(stypes
->rx
& BIT(stype
))) {
674 trace_cfg80211_return_bool(false);
678 data
= buf
+ ieee80211_hdrlen(mgmt
->frame_control
);
679 data_len
= len
- ieee80211_hdrlen(mgmt
->frame_control
);
681 spin_lock_bh(&wdev
->mgmt_registrations_lock
);
683 list_for_each_entry(reg
, &wdev
->mgmt_registrations
, list
) {
684 if (reg
->frame_type
!= ftype
)
687 if (reg
->match_len
> data_len
)
690 if (memcmp(reg
->match
, data
, reg
->match_len
))
695 /* Indicate the received Action frame to user space */
696 if (nl80211_send_mgmt(rdev
, wdev
, reg
->nlportid
,
698 buf
, len
, flags
, GFP_ATOMIC
))
705 spin_unlock_bh(&wdev
->mgmt_registrations_lock
);
707 trace_cfg80211_return_bool(result
);
710 EXPORT_SYMBOL(cfg80211_rx_mgmt
);
712 void cfg80211_dfs_channels_update_work(struct work_struct
*work
)
714 struct delayed_work
*delayed_work
= to_delayed_work(work
);
715 struct cfg80211_registered_device
*rdev
;
716 struct cfg80211_chan_def chandef
;
717 struct ieee80211_supported_band
*sband
;
718 struct ieee80211_channel
*c
;
720 bool check_again
= false;
721 unsigned long timeout
, next_time
= 0;
724 rdev
= container_of(delayed_work
, struct cfg80211_registered_device
,
725 dfs_update_channels_wk
);
726 wiphy
= &rdev
->wiphy
;
729 for (bandid
= 0; bandid
< NUM_NL80211_BANDS
; bandid
++) {
730 sband
= wiphy
->bands
[bandid
];
734 for (i
= 0; i
< sband
->n_channels
; i
++) {
735 c
= &sband
->channels
[i
];
737 if (c
->dfs_state
!= NL80211_DFS_UNAVAILABLE
)
740 timeout
= c
->dfs_state_entered
+ msecs_to_jiffies(
741 IEEE80211_DFS_MIN_NOP_TIME_MS
);
743 if (time_after_eq(jiffies
, timeout
)) {
744 c
->dfs_state
= NL80211_DFS_USABLE
;
745 c
->dfs_state_entered
= jiffies
;
747 cfg80211_chandef_create(&chandef
, c
,
750 nl80211_radar_notify(rdev
, &chandef
,
751 NL80211_RADAR_NOP_FINISHED
,
757 next_time
= timeout
- jiffies
;
759 next_time
= min(next_time
, timeout
- jiffies
);
765 /* reschedule if there are other channels waiting to be cleared again */
767 queue_delayed_work(cfg80211_wq
, &rdev
->dfs_update_channels_wk
,
772 void cfg80211_radar_event(struct wiphy
*wiphy
,
773 struct cfg80211_chan_def
*chandef
,
776 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
777 unsigned long timeout
;
779 trace_cfg80211_radar_event(wiphy
, chandef
);
781 /* only set the chandef supplied channel to unavailable, in
782 * case the radar is detected on only one of multiple channels
783 * spanned by the chandef.
785 cfg80211_set_dfs_state(wiphy
, chandef
, NL80211_DFS_UNAVAILABLE
);
787 timeout
= msecs_to_jiffies(IEEE80211_DFS_MIN_NOP_TIME_MS
);
788 queue_delayed_work(cfg80211_wq
, &rdev
->dfs_update_channels_wk
,
791 nl80211_radar_notify(rdev
, chandef
, NL80211_RADAR_DETECTED
, NULL
, gfp
);
793 EXPORT_SYMBOL(cfg80211_radar_event
);
795 void cfg80211_cac_event(struct net_device
*netdev
,
796 const struct cfg80211_chan_def
*chandef
,
797 enum nl80211_radar_event event
, gfp_t gfp
)
799 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
800 struct wiphy
*wiphy
= wdev
->wiphy
;
801 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
802 unsigned long timeout
;
804 trace_cfg80211_cac_event(netdev
, event
);
806 if (WARN_ON(!wdev
->cac_started
))
809 if (WARN_ON(!wdev
->chandef
.chan
))
813 case NL80211_RADAR_CAC_FINISHED
:
814 timeout
= wdev
->cac_start_time
+
815 msecs_to_jiffies(wdev
->cac_time_ms
);
816 WARN_ON(!time_after_eq(jiffies
, timeout
));
817 cfg80211_set_dfs_state(wiphy
, chandef
, NL80211_DFS_AVAILABLE
);
819 case NL80211_RADAR_CAC_ABORTED
:
825 wdev
->cac_started
= false;
827 nl80211_radar_notify(rdev
, chandef
, event
, netdev
, gfp
);
829 EXPORT_SYMBOL(cfg80211_cac_event
);