2 * SME code for cfg80211
3 * both driver SME event handling and the SME implementation
4 * (for nl80211's connect() and wext)
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (C) 2009 Intel Corporation. All rights reserved.
10 #include <linux/etherdevice.h>
11 #include <linux/if_arp.h>
12 #include <linux/slab.h>
13 #include <linux/workqueue.h>
14 #include <linux/wireless.h>
15 #include <linux/export.h>
16 #include <net/iw_handler.h>
17 #include <net/cfg80211.h>
18 #include <net/rtnetlink.h>
24 * Software SME in cfg80211, using auth/assoc/deauth calls to the
25 * driver. This is is for implementing nl80211's connect/disconnect
26 * and wireless extensions (if configured.)
29 struct cfg80211_conn
{
30 struct cfg80211_connect_params params
;
31 /* these are sub-states of the _CONNECTING sme_state */
33 CFG80211_CONN_SCANNING
,
34 CFG80211_CONN_SCAN_AGAIN
,
35 CFG80211_CONN_AUTHENTICATE_NEXT
,
36 CFG80211_CONN_AUTHENTICATING
,
37 CFG80211_CONN_AUTH_FAILED
,
38 CFG80211_CONN_ASSOCIATE_NEXT
,
39 CFG80211_CONN_ASSOCIATING
,
40 CFG80211_CONN_ASSOC_FAILED
,
42 CFG80211_CONN_CONNECTED
,
44 u8 bssid
[ETH_ALEN
], prev_bssid
[ETH_ALEN
];
47 bool auto_auth
, prev_bssid_valid
;
50 static void cfg80211_sme_free(struct wireless_dev
*wdev
)
55 kfree(wdev
->conn
->ie
);
60 static int cfg80211_conn_scan(struct wireless_dev
*wdev
)
62 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
63 struct cfg80211_scan_request
*request
;
67 ASSERT_WDEV_LOCK(wdev
);
69 if (rdev
->scan_req
|| rdev
->scan_msg
)
72 if (wdev
->conn
->params
.channel
)
75 n_channels
= ieee80211_get_num_supported_channels(wdev
->wiphy
);
77 request
= kzalloc(sizeof(*request
) + sizeof(request
->ssids
[0]) +
78 sizeof(request
->channels
[0]) * n_channels
,
83 if (wdev
->conn
->params
.channel
) {
84 enum ieee80211_band band
= wdev
->conn
->params
.channel
->band
;
85 struct ieee80211_supported_band
*sband
=
86 wdev
->wiphy
->bands
[band
];
92 request
->channels
[0] = wdev
->conn
->params
.channel
;
93 request
->rates
[band
] = (1 << sband
->n_bitrates
) - 1;
96 enum ieee80211_band band
;
97 struct ieee80211_supported_band
*bands
;
98 struct ieee80211_channel
*channel
;
100 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
101 bands
= wdev
->wiphy
->bands
[band
];
104 for (j
= 0; j
< bands
->n_channels
; j
++) {
105 channel
= &bands
->channels
[j
];
106 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
108 request
->channels
[i
++] = channel
;
110 request
->rates
[band
] = (1 << bands
->n_bitrates
) - 1;
114 request
->n_channels
= n_channels
;
115 request
->ssids
= (void *)&request
->channels
[n_channels
];
116 request
->n_ssids
= 1;
118 memcpy(request
->ssids
[0].ssid
, wdev
->conn
->params
.ssid
,
119 wdev
->conn
->params
.ssid_len
);
120 request
->ssids
[0].ssid_len
= wdev
->conn
->params
.ssid_len
;
122 request
->wdev
= wdev
;
123 request
->wiphy
= &rdev
->wiphy
;
124 request
->scan_start
= jiffies
;
126 rdev
->scan_req
= request
;
128 err
= rdev_scan(rdev
, request
);
130 wdev
->conn
->state
= CFG80211_CONN_SCANNING
;
131 nl80211_send_scan_start(rdev
, wdev
);
132 dev_hold(wdev
->netdev
);
134 rdev
->scan_req
= NULL
;
140 static int cfg80211_conn_do_work(struct wireless_dev
*wdev
)
142 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
143 struct cfg80211_connect_params
*params
;
144 struct cfg80211_assoc_request req
= {};
147 ASSERT_WDEV_LOCK(wdev
);
152 params
= &wdev
->conn
->params
;
154 switch (wdev
->conn
->state
) {
155 case CFG80211_CONN_SCANNING
:
156 /* didn't find it during scan ... */
158 case CFG80211_CONN_SCAN_AGAIN
:
159 return cfg80211_conn_scan(wdev
);
160 case CFG80211_CONN_AUTHENTICATE_NEXT
:
161 if (WARN_ON(!rdev
->ops
->auth
))
163 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATING
;
164 return cfg80211_mlme_auth(rdev
, wdev
->netdev
,
165 params
->channel
, params
->auth_type
,
167 params
->ssid
, params
->ssid_len
,
169 params
->key
, params
->key_len
,
170 params
->key_idx
, NULL
, 0);
171 case CFG80211_CONN_AUTH_FAILED
:
173 case CFG80211_CONN_ASSOCIATE_NEXT
:
174 if (WARN_ON(!rdev
->ops
->assoc
))
176 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATING
;
177 if (wdev
->conn
->prev_bssid_valid
)
178 req
.prev_bssid
= wdev
->conn
->prev_bssid
;
180 req
.ie_len
= params
->ie_len
;
181 req
.use_mfp
= params
->mfp
!= NL80211_MFP_NO
;
182 req
.crypto
= params
->crypto
;
183 req
.flags
= params
->flags
;
184 req
.ht_capa
= params
->ht_capa
;
185 req
.ht_capa_mask
= params
->ht_capa_mask
;
186 req
.vht_capa
= params
->vht_capa
;
187 req
.vht_capa_mask
= params
->vht_capa_mask
;
189 err
= cfg80211_mlme_assoc(rdev
, wdev
->netdev
, params
->channel
,
190 params
->bssid
, params
->ssid
,
191 params
->ssid_len
, &req
);
193 cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
195 WLAN_REASON_DEAUTH_LEAVING
,
198 case CFG80211_CONN_ASSOC_FAILED
:
199 cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
201 WLAN_REASON_DEAUTH_LEAVING
, false);
203 case CFG80211_CONN_DEAUTH
:
204 cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
206 WLAN_REASON_DEAUTH_LEAVING
, false);
207 /* free directly, disconnected event already sent */
208 cfg80211_sme_free(wdev
);
215 void cfg80211_conn_work(struct work_struct
*work
)
217 struct cfg80211_registered_device
*rdev
=
218 container_of(work
, struct cfg80211_registered_device
, conn_work
);
219 struct wireless_dev
*wdev
;
220 u8 bssid_buf
[ETH_ALEN
], *bssid
= NULL
;
224 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
229 if (!netif_running(wdev
->netdev
)) {
234 wdev
->conn
->state
== CFG80211_CONN_CONNECTED
) {
238 if (wdev
->conn
->params
.bssid
) {
239 memcpy(bssid_buf
, wdev
->conn
->params
.bssid
, ETH_ALEN
);
242 if (cfg80211_conn_do_work(wdev
)) {
243 __cfg80211_connect_result(
246 WLAN_STATUS_UNSPECIFIED_FAILURE
,
255 /* Returned bss is reference counted and must be cleaned up appropriately. */
256 static struct cfg80211_bss
*cfg80211_get_conn_bss(struct wireless_dev
*wdev
)
258 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
259 struct cfg80211_bss
*bss
;
260 u16 capa
= WLAN_CAPABILITY_ESS
;
262 ASSERT_WDEV_LOCK(wdev
);
264 if (wdev
->conn
->params
.privacy
)
265 capa
|= WLAN_CAPABILITY_PRIVACY
;
267 bss
= cfg80211_get_bss(wdev
->wiphy
, wdev
->conn
->params
.channel
,
268 wdev
->conn
->params
.bssid
,
269 wdev
->conn
->params
.ssid
,
270 wdev
->conn
->params
.ssid_len
,
271 WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_PRIVACY
,
276 memcpy(wdev
->conn
->bssid
, bss
->bssid
, ETH_ALEN
);
277 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
278 wdev
->conn
->params
.channel
= bss
->channel
;
279 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
280 schedule_work(&rdev
->conn_work
);
285 static void __cfg80211_sme_scan_done(struct net_device
*dev
)
287 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
288 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
289 struct cfg80211_bss
*bss
;
291 ASSERT_WDEV_LOCK(wdev
);
296 if (wdev
->conn
->state
!= CFG80211_CONN_SCANNING
&&
297 wdev
->conn
->state
!= CFG80211_CONN_SCAN_AGAIN
)
300 bss
= cfg80211_get_conn_bss(wdev
);
302 cfg80211_put_bss(&rdev
->wiphy
, bss
);
304 schedule_work(&rdev
->conn_work
);
307 void cfg80211_sme_scan_done(struct net_device
*dev
)
309 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
312 __cfg80211_sme_scan_done(dev
);
316 void cfg80211_sme_rx_auth(struct wireless_dev
*wdev
, const u8
*buf
, size_t len
)
318 struct wiphy
*wiphy
= wdev
->wiphy
;
319 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
320 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
321 u16 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
323 ASSERT_WDEV_LOCK(wdev
);
325 if (!wdev
->conn
|| wdev
->conn
->state
== CFG80211_CONN_CONNECTED
)
328 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
329 wdev
->conn
->auto_auth
&&
330 wdev
->conn
->params
.auth_type
!= NL80211_AUTHTYPE_NETWORK_EAP
) {
331 /* select automatically between only open, shared, leap */
332 switch (wdev
->conn
->params
.auth_type
) {
333 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
334 if (wdev
->connect_keys
)
335 wdev
->conn
->params
.auth_type
=
336 NL80211_AUTHTYPE_SHARED_KEY
;
338 wdev
->conn
->params
.auth_type
=
339 NL80211_AUTHTYPE_NETWORK_EAP
;
341 case NL80211_AUTHTYPE_SHARED_KEY
:
342 wdev
->conn
->params
.auth_type
=
343 NL80211_AUTHTYPE_NETWORK_EAP
;
347 wdev
->conn
->params
.auth_type
=
348 NL80211_AUTHTYPE_OPEN_SYSTEM
;
351 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
352 schedule_work(&rdev
->conn_work
);
353 } else if (status_code
!= WLAN_STATUS_SUCCESS
) {
354 __cfg80211_connect_result(wdev
->netdev
, mgmt
->bssid
,
356 status_code
, false, NULL
);
357 } else if (wdev
->conn
->state
== CFG80211_CONN_AUTHENTICATING
) {
358 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
359 schedule_work(&rdev
->conn_work
);
363 bool cfg80211_sme_rx_assoc_resp(struct wireless_dev
*wdev
, u16 status
)
365 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
370 if (status
== WLAN_STATUS_SUCCESS
) {
371 wdev
->conn
->state
= CFG80211_CONN_CONNECTED
;
375 if (wdev
->conn
->prev_bssid_valid
) {
377 * Some stupid APs don't accept reassoc, so we
378 * need to fall back to trying regular assoc;
379 * return true so no event is sent to userspace.
381 wdev
->conn
->prev_bssid_valid
= false;
382 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
383 schedule_work(&rdev
->conn_work
);
387 wdev
->conn
->state
= CFG80211_CONN_ASSOC_FAILED
;
388 schedule_work(&rdev
->conn_work
);
392 void cfg80211_sme_deauth(struct wireless_dev
*wdev
)
394 cfg80211_sme_free(wdev
);
397 void cfg80211_sme_auth_timeout(struct wireless_dev
*wdev
)
399 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
404 wdev
->conn
->state
= CFG80211_CONN_AUTH_FAILED
;
405 schedule_work(&rdev
->conn_work
);
408 void cfg80211_sme_disassoc(struct wireless_dev
*wdev
)
410 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
415 wdev
->conn
->state
= CFG80211_CONN_DEAUTH
;
416 schedule_work(&rdev
->conn_work
);
419 void cfg80211_sme_assoc_timeout(struct wireless_dev
*wdev
)
421 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
426 wdev
->conn
->state
= CFG80211_CONN_ASSOC_FAILED
;
427 schedule_work(&rdev
->conn_work
);
430 static int cfg80211_sme_connect(struct wireless_dev
*wdev
,
431 struct cfg80211_connect_params
*connect
,
432 const u8
*prev_bssid
)
434 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
435 struct cfg80211_bss
*bss
;
438 if (!rdev
->ops
->auth
|| !rdev
->ops
->assoc
)
441 if (wdev
->current_bss
)
444 if (WARN_ON(wdev
->conn
))
447 wdev
->conn
= kzalloc(sizeof(*wdev
->conn
), GFP_KERNEL
);
452 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
454 memcpy(&wdev
->conn
->params
, connect
, sizeof(*connect
));
455 if (connect
->bssid
) {
456 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
457 memcpy(wdev
->conn
->bssid
, connect
->bssid
, ETH_ALEN
);
461 wdev
->conn
->ie
= kmemdup(connect
->ie
, connect
->ie_len
,
463 wdev
->conn
->params
.ie
= wdev
->conn
->ie
;
464 if (!wdev
->conn
->ie
) {
471 if (connect
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) {
472 wdev
->conn
->auto_auth
= true;
473 /* start with open system ... should mostly work */
474 wdev
->conn
->params
.auth_type
=
475 NL80211_AUTHTYPE_OPEN_SYSTEM
;
477 wdev
->conn
->auto_auth
= false;
480 wdev
->conn
->params
.ssid
= wdev
->ssid
;
481 wdev
->conn
->params
.ssid_len
= wdev
->ssid_len
;
483 /* see if we have the bss already */
484 bss
= cfg80211_get_conn_bss(wdev
);
487 memcpy(wdev
->conn
->prev_bssid
, prev_bssid
, ETH_ALEN
);
488 wdev
->conn
->prev_bssid_valid
= true;
491 /* we're good if we have a matching bss struct */
493 err
= cfg80211_conn_do_work(wdev
);
494 cfg80211_put_bss(wdev
->wiphy
, bss
);
496 /* otherwise we'll need to scan for the AP first */
497 err
= cfg80211_conn_scan(wdev
);
500 * If we can't scan right now, then we need to scan again
501 * after the current scan finished, since the parameters
502 * changed (unless we find a good AP anyway).
506 wdev
->conn
->state
= CFG80211_CONN_SCAN_AGAIN
;
511 cfg80211_sme_free(wdev
);
516 static int cfg80211_sme_disconnect(struct wireless_dev
*wdev
, u16 reason
)
518 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
524 if (!rdev
->ops
->deauth
)
527 if (wdev
->conn
->state
== CFG80211_CONN_SCANNING
||
528 wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
) {
533 /* wdev->conn->params.bssid must be set if > SCANNING */
534 err
= cfg80211_mlme_deauth(rdev
, wdev
->netdev
,
535 wdev
->conn
->params
.bssid
,
536 NULL
, 0, reason
, false);
538 cfg80211_sme_free(wdev
);
543 * code shared for in-device and software SME
546 static bool cfg80211_is_all_idle(void)
548 struct cfg80211_registered_device
*rdev
;
549 struct wireless_dev
*wdev
;
550 bool is_all_idle
= true;
553 * All devices must be idle as otherwise if you are actively
554 * scanning some new beacon hints could be learned and would
555 * count as new regulatory hints.
557 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
558 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
560 if (wdev
->conn
|| wdev
->current_bss
)
569 static void disconnect_work(struct work_struct
*work
)
572 if (cfg80211_is_all_idle())
573 regulatory_hint_disconnect();
577 static DECLARE_WORK(cfg80211_disconnect_work
, disconnect_work
);
581 * API calls for drivers implementing connect/disconnect and
585 /* This method must consume bss one way or another */
586 void __cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
587 const u8
*req_ie
, size_t req_ie_len
,
588 const u8
*resp_ie
, size_t resp_ie_len
,
589 u16 status
, bool wextev
,
590 struct cfg80211_bss
*bss
)
592 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
593 const u8
*country_ie
;
594 #ifdef CONFIG_CFG80211_WEXT
595 union iwreq_data wrqu
;
598 ASSERT_WDEV_LOCK(wdev
);
600 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
601 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)) {
602 cfg80211_put_bss(wdev
->wiphy
, bss
);
606 nl80211_send_connect_result(wiphy_to_rdev(wdev
->wiphy
), dev
,
607 bssid
, req_ie
, req_ie_len
,
608 resp_ie
, resp_ie_len
,
611 #ifdef CONFIG_CFG80211_WEXT
613 if (req_ie
&& status
== WLAN_STATUS_SUCCESS
) {
614 memset(&wrqu
, 0, sizeof(wrqu
));
615 wrqu
.data
.length
= req_ie_len
;
616 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, req_ie
);
619 if (resp_ie
&& status
== WLAN_STATUS_SUCCESS
) {
620 memset(&wrqu
, 0, sizeof(wrqu
));
621 wrqu
.data
.length
= resp_ie_len
;
622 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, resp_ie
);
625 memset(&wrqu
, 0, sizeof(wrqu
));
626 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
627 if (bssid
&& status
== WLAN_STATUS_SUCCESS
) {
628 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
629 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
630 wdev
->wext
.prev_bssid_valid
= true;
632 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
636 if (!bss
&& (status
== WLAN_STATUS_SUCCESS
)) {
637 WARN_ON_ONCE(!wiphy_to_rdev(wdev
->wiphy
)->ops
->connect
);
638 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, bssid
,
639 wdev
->ssid
, wdev
->ssid_len
,
641 WLAN_CAPABILITY_ESS
);
643 cfg80211_hold_bss(bss_from_pub(bss
));
646 if (wdev
->current_bss
) {
647 cfg80211_unhold_bss(wdev
->current_bss
);
648 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
649 wdev
->current_bss
= NULL
;
652 if (status
!= WLAN_STATUS_SUCCESS
) {
653 kzfree(wdev
->connect_keys
);
654 wdev
->connect_keys
= NULL
;
657 cfg80211_unhold_bss(bss_from_pub(bss
));
658 cfg80211_put_bss(wdev
->wiphy
, bss
);
660 cfg80211_sme_free(wdev
);
667 wdev
->current_bss
= bss_from_pub(bss
);
669 cfg80211_upload_connect_keys(wdev
);
672 country_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
678 country_ie
= kmemdup(country_ie
, 2 + country_ie
[1], GFP_ATOMIC
);
685 * ieee80211_bss_get_ie() ensures we can access:
686 * - country_ie + 2, the start of the country ie data, and
687 * - and country_ie[1] which is the IE length
689 regulatory_hint_country_ie(wdev
->wiphy
, bss
->channel
->band
,
690 country_ie
+ 2, country_ie
[1]);
694 void cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
695 const u8
*req_ie
, size_t req_ie_len
,
696 const u8
*resp_ie
, size_t resp_ie_len
,
697 u16 status
, gfp_t gfp
)
699 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
700 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
701 struct cfg80211_event
*ev
;
704 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
708 ev
->type
= EVENT_CONNECT_RESULT
;
710 memcpy(ev
->cr
.bssid
, bssid
, ETH_ALEN
);
712 ev
->cr
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
713 ev
->cr
.req_ie_len
= req_ie_len
;
714 memcpy((void *)ev
->cr
.req_ie
, req_ie
, req_ie_len
);
717 ev
->cr
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
718 ev
->cr
.resp_ie_len
= resp_ie_len
;
719 memcpy((void *)ev
->cr
.resp_ie
, resp_ie
, resp_ie_len
);
721 ev
->cr
.status
= status
;
723 spin_lock_irqsave(&wdev
->event_lock
, flags
);
724 list_add_tail(&ev
->list
, &wdev
->event_list
);
725 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
726 queue_work(cfg80211_wq
, &rdev
->event_work
);
728 EXPORT_SYMBOL(cfg80211_connect_result
);
730 /* Consumes bss object one way or another */
731 void __cfg80211_roamed(struct wireless_dev
*wdev
,
732 struct cfg80211_bss
*bss
,
733 const u8
*req_ie
, size_t req_ie_len
,
734 const u8
*resp_ie
, size_t resp_ie_len
)
736 #ifdef CONFIG_CFG80211_WEXT
737 union iwreq_data wrqu
;
739 ASSERT_WDEV_LOCK(wdev
);
741 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
742 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
))
745 if (WARN_ON(!wdev
->current_bss
))
748 cfg80211_unhold_bss(wdev
->current_bss
);
749 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
750 wdev
->current_bss
= NULL
;
752 cfg80211_hold_bss(bss_from_pub(bss
));
753 wdev
->current_bss
= bss_from_pub(bss
);
755 nl80211_send_roamed(wiphy_to_rdev(wdev
->wiphy
),
756 wdev
->netdev
, bss
->bssid
,
757 req_ie
, req_ie_len
, resp_ie
, resp_ie_len
,
760 #ifdef CONFIG_CFG80211_WEXT
762 memset(&wrqu
, 0, sizeof(wrqu
));
763 wrqu
.data
.length
= req_ie_len
;
764 wireless_send_event(wdev
->netdev
, IWEVASSOCREQIE
,
769 memset(&wrqu
, 0, sizeof(wrqu
));
770 wrqu
.data
.length
= resp_ie_len
;
771 wireless_send_event(wdev
->netdev
, IWEVASSOCRESPIE
,
775 memset(&wrqu
, 0, sizeof(wrqu
));
776 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
777 memcpy(wrqu
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
778 memcpy(wdev
->wext
.prev_bssid
, bss
->bssid
, ETH_ALEN
);
779 wdev
->wext
.prev_bssid_valid
= true;
780 wireless_send_event(wdev
->netdev
, SIOCGIWAP
, &wrqu
, NULL
);
785 cfg80211_put_bss(wdev
->wiphy
, bss
);
788 void cfg80211_roamed(struct net_device
*dev
,
789 struct ieee80211_channel
*channel
,
791 const u8
*req_ie
, size_t req_ie_len
,
792 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
794 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
795 struct cfg80211_bss
*bss
;
797 bss
= cfg80211_get_bss(wdev
->wiphy
, channel
, bssid
, wdev
->ssid
,
798 wdev
->ssid_len
, WLAN_CAPABILITY_ESS
,
799 WLAN_CAPABILITY_ESS
);
803 cfg80211_roamed_bss(dev
, bss
, req_ie
, req_ie_len
, resp_ie
,
806 EXPORT_SYMBOL(cfg80211_roamed
);
808 /* Consumes bss object one way or another */
809 void cfg80211_roamed_bss(struct net_device
*dev
,
810 struct cfg80211_bss
*bss
, const u8
*req_ie
,
811 size_t req_ie_len
, const u8
*resp_ie
,
812 size_t resp_ie_len
, gfp_t gfp
)
814 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
815 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
816 struct cfg80211_event
*ev
;
822 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
824 cfg80211_put_bss(wdev
->wiphy
, bss
);
828 ev
->type
= EVENT_ROAMED
;
829 ev
->rm
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
830 ev
->rm
.req_ie_len
= req_ie_len
;
831 memcpy((void *)ev
->rm
.req_ie
, req_ie
, req_ie_len
);
832 ev
->rm
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
833 ev
->rm
.resp_ie_len
= resp_ie_len
;
834 memcpy((void *)ev
->rm
.resp_ie
, resp_ie
, resp_ie_len
);
837 spin_lock_irqsave(&wdev
->event_lock
, flags
);
838 list_add_tail(&ev
->list
, &wdev
->event_list
);
839 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
840 queue_work(cfg80211_wq
, &rdev
->event_work
);
842 EXPORT_SYMBOL(cfg80211_roamed_bss
);
844 void __cfg80211_disconnected(struct net_device
*dev
, const u8
*ie
,
845 size_t ie_len
, u16 reason
, bool from_ap
)
847 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
848 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
850 #ifdef CONFIG_CFG80211_WEXT
851 union iwreq_data wrqu
;
854 ASSERT_WDEV_LOCK(wdev
);
856 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
857 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
))
860 if (wdev
->current_bss
) {
861 cfg80211_unhold_bss(wdev
->current_bss
);
862 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
865 wdev
->current_bss
= NULL
;
868 nl80211_send_disconnected(rdev
, dev
, reason
, ie
, ie_len
, from_ap
);
871 * Delete all the keys ... pairwise keys can't really
872 * exist any more anyway, but default keys might.
874 if (rdev
->ops
->del_key
)
875 for (i
= 0; i
< 6; i
++)
876 rdev_del_key(rdev
, dev
, i
, false, NULL
);
878 rdev_set_qos_map(rdev
, dev
, NULL
);
880 #ifdef CONFIG_CFG80211_WEXT
881 memset(&wrqu
, 0, sizeof(wrqu
));
882 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
883 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
884 wdev
->wext
.connect
.ssid_len
= 0;
887 schedule_work(&cfg80211_disconnect_work
);
890 void cfg80211_disconnected(struct net_device
*dev
, u16 reason
,
891 const u8
*ie
, size_t ie_len
, gfp_t gfp
)
893 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
894 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
895 struct cfg80211_event
*ev
;
898 ev
= kzalloc(sizeof(*ev
) + ie_len
, gfp
);
902 ev
->type
= EVENT_DISCONNECTED
;
903 ev
->dc
.ie
= ((u8
*)ev
) + sizeof(*ev
);
904 ev
->dc
.ie_len
= ie_len
;
905 memcpy((void *)ev
->dc
.ie
, ie
, ie_len
);
906 ev
->dc
.reason
= reason
;
908 spin_lock_irqsave(&wdev
->event_lock
, flags
);
909 list_add_tail(&ev
->list
, &wdev
->event_list
);
910 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
911 queue_work(cfg80211_wq
, &rdev
->event_work
);
913 EXPORT_SYMBOL(cfg80211_disconnected
);
916 * API calls for nl80211/wext compatibility code
918 int cfg80211_connect(struct cfg80211_registered_device
*rdev
,
919 struct net_device
*dev
,
920 struct cfg80211_connect_params
*connect
,
921 struct cfg80211_cached_keys
*connkeys
,
922 const u8
*prev_bssid
)
924 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
927 ASSERT_WDEV_LOCK(wdev
);
929 if (WARN_ON(wdev
->connect_keys
)) {
930 kzfree(wdev
->connect_keys
);
931 wdev
->connect_keys
= NULL
;
934 cfg80211_oper_and_ht_capa(&connect
->ht_capa_mask
,
935 rdev
->wiphy
.ht_capa_mod_mask
);
937 if (connkeys
&& connkeys
->def
>= 0) {
942 cipher
= connkeys
->params
[idx
].cipher
;
943 /* If given a WEP key we may need it for shared key auth */
944 if (cipher
== WLAN_CIPHER_SUITE_WEP40
||
945 cipher
== WLAN_CIPHER_SUITE_WEP104
) {
946 connect
->key_idx
= idx
;
947 connect
->key
= connkeys
->params
[idx
].key
;
948 connect
->key_len
= connkeys
->params
[idx
].key_len
;
951 * If ciphers are not set (e.g. when going through
952 * iwconfig), we have to set them appropriately here.
954 if (connect
->crypto
.cipher_group
== 0)
955 connect
->crypto
.cipher_group
= cipher
;
957 if (connect
->crypto
.n_ciphers_pairwise
== 0) {
958 connect
->crypto
.n_ciphers_pairwise
= 1;
959 connect
->crypto
.ciphers_pairwise
[0] = cipher
;
964 wdev
->connect_keys
= connkeys
;
965 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
966 wdev
->ssid_len
= connect
->ssid_len
;
968 if (!rdev
->ops
->connect
)
969 err
= cfg80211_sme_connect(wdev
, connect
, prev_bssid
);
971 err
= rdev_connect(rdev
, dev
, connect
);
974 wdev
->connect_keys
= NULL
;
982 int cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
983 struct net_device
*dev
, u16 reason
, bool wextev
)
985 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
988 ASSERT_WDEV_LOCK(wdev
);
990 kzfree(wdev
->connect_keys
);
991 wdev
->connect_keys
= NULL
;
994 err
= cfg80211_sme_disconnect(wdev
, reason
);
995 else if (!rdev
->ops
->disconnect
)
996 cfg80211_mlme_down(rdev
, dev
);
997 else if (wdev
->current_bss
)
998 err
= rdev_disconnect(rdev
, dev
, reason
);