2 * SME code for cfg80211's connect emulation.
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2009 Intel Corporation. All rights reserved.
8 #include <linux/etherdevice.h>
9 #include <linux/if_arp.h>
10 #include <linux/slab.h>
11 #include <linux/workqueue.h>
12 #include <linux/wireless.h>
13 #include <linux/export.h>
14 #include <net/iw_handler.h>
15 #include <net/cfg80211.h>
16 #include <net/rtnetlink.h>
21 struct cfg80211_conn
{
22 struct cfg80211_connect_params params
;
23 /* these are sub-states of the _CONNECTING sme_state */
26 CFG80211_CONN_SCANNING
,
27 CFG80211_CONN_SCAN_AGAIN
,
28 CFG80211_CONN_AUTHENTICATE_NEXT
,
29 CFG80211_CONN_AUTHENTICATING
,
30 CFG80211_CONN_ASSOCIATE_NEXT
,
31 CFG80211_CONN_ASSOCIATING
,
32 CFG80211_CONN_DEAUTH_ASSOC_FAIL
,
34 u8 bssid
[ETH_ALEN
], prev_bssid
[ETH_ALEN
];
37 bool auto_auth
, prev_bssid_valid
;
40 static bool cfg80211_is_all_idle(void)
42 struct cfg80211_registered_device
*rdev
;
43 struct wireless_dev
*wdev
;
44 bool is_all_idle
= true;
46 mutex_lock(&cfg80211_mutex
);
49 * All devices must be idle as otherwise if you are actively
50 * scanning some new beacon hints could be learned and would
51 * count as new regulatory hints.
53 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
54 cfg80211_lock_rdev(rdev
);
55 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
57 if (wdev
->sme_state
!= CFG80211_SME_IDLE
)
61 cfg80211_unlock_rdev(rdev
);
64 mutex_unlock(&cfg80211_mutex
);
69 static void disconnect_work(struct work_struct
*work
)
71 if (!cfg80211_is_all_idle())
74 regulatory_hint_disconnect();
77 static DECLARE_WORK(cfg80211_disconnect_work
, disconnect_work
);
79 static int cfg80211_conn_scan(struct wireless_dev
*wdev
)
81 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
82 struct cfg80211_scan_request
*request
;
86 ASSERT_RDEV_LOCK(rdev
);
87 ASSERT_WDEV_LOCK(wdev
);
88 lockdep_assert_held(&rdev
->sched_scan_mtx
);
93 if (wdev
->conn
->params
.channel
) {
96 enum ieee80211_band band
;
99 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
100 if (!wdev
->wiphy
->bands
[band
])
102 n_channels
+= wdev
->wiphy
->bands
[band
]->n_channels
;
105 request
= kzalloc(sizeof(*request
) + sizeof(request
->ssids
[0]) +
106 sizeof(request
->channels
[0]) * n_channels
,
111 if (wdev
->conn
->params
.channel
)
112 request
->channels
[0] = wdev
->conn
->params
.channel
;
115 enum ieee80211_band band
;
116 struct ieee80211_supported_band
*bands
;
117 struct ieee80211_channel
*channel
;
119 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
120 bands
= wdev
->wiphy
->bands
[band
];
123 for (j
= 0; j
< bands
->n_channels
; j
++) {
124 channel
= &bands
->channels
[j
];
125 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
127 request
->channels
[i
++] = channel
;
129 request
->rates
[band
] = (1 << bands
->n_bitrates
) - 1;
133 request
->n_channels
= n_channels
;
134 request
->ssids
= (void *)&request
->channels
[n_channels
];
135 request
->n_ssids
= 1;
137 memcpy(request
->ssids
[0].ssid
, wdev
->conn
->params
.ssid
,
138 wdev
->conn
->params
.ssid_len
);
139 request
->ssids
[0].ssid_len
= wdev
->conn
->params
.ssid_len
;
141 request
->wdev
= wdev
;
142 request
->wiphy
= &rdev
->wiphy
;
143 request
->scan_start
= jiffies
;
145 rdev
->scan_req
= request
;
147 err
= rdev_scan(rdev
, request
);
149 wdev
->conn
->state
= CFG80211_CONN_SCANNING
;
150 nl80211_send_scan_start(rdev
, wdev
);
151 dev_hold(wdev
->netdev
);
153 rdev
->scan_req
= NULL
;
159 static int cfg80211_conn_do_work(struct wireless_dev
*wdev
)
161 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
162 struct cfg80211_connect_params
*params
;
163 struct cfg80211_assoc_request req
= {};
166 ASSERT_WDEV_LOCK(wdev
);
171 params
= &wdev
->conn
->params
;
173 switch (wdev
->conn
->state
) {
174 case CFG80211_CONN_SCAN_AGAIN
:
175 return cfg80211_conn_scan(wdev
);
176 case CFG80211_CONN_AUTHENTICATE_NEXT
:
177 BUG_ON(!rdev
->ops
->auth
);
178 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATING
;
179 return __cfg80211_mlme_auth(rdev
, wdev
->netdev
,
180 params
->channel
, params
->auth_type
,
182 params
->ssid
, params
->ssid_len
,
184 params
->key
, params
->key_len
,
185 params
->key_idx
, NULL
, 0);
186 case CFG80211_CONN_ASSOCIATE_NEXT
:
187 BUG_ON(!rdev
->ops
->assoc
);
188 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATING
;
189 if (wdev
->conn
->prev_bssid_valid
)
190 req
.prev_bssid
= wdev
->conn
->prev_bssid
;
192 req
.ie_len
= params
->ie_len
;
193 req
.use_mfp
= params
->mfp
!= NL80211_MFP_NO
;
194 req
.crypto
= params
->crypto
;
195 req
.flags
= params
->flags
;
196 req
.ht_capa
= params
->ht_capa
;
197 req
.ht_capa_mask
= params
->ht_capa_mask
;
198 req
.vht_capa
= params
->vht_capa
;
199 req
.vht_capa_mask
= params
->vht_capa_mask
;
201 err
= __cfg80211_mlme_assoc(rdev
, wdev
->netdev
, params
->channel
,
202 params
->bssid
, params
->ssid
,
203 params
->ssid_len
, &req
);
205 __cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
207 WLAN_REASON_DEAUTH_LEAVING
,
210 case CFG80211_CONN_DEAUTH_ASSOC_FAIL
:
211 __cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
213 WLAN_REASON_DEAUTH_LEAVING
, false);
214 /* return an error so that we call __cfg80211_connect_result() */
221 void cfg80211_conn_work(struct work_struct
*work
)
223 struct cfg80211_registered_device
*rdev
=
224 container_of(work
, struct cfg80211_registered_device
, conn_work
);
225 struct wireless_dev
*wdev
;
226 u8 bssid_buf
[ETH_ALEN
], *bssid
= NULL
;
229 cfg80211_lock_rdev(rdev
);
230 mutex_lock(&rdev
->devlist_mtx
);
231 mutex_lock(&rdev
->sched_scan_mtx
);
233 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
235 if (!netif_running(wdev
->netdev
)) {
239 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
|| !wdev
->conn
) {
243 if (wdev
->conn
->params
.bssid
) {
244 memcpy(bssid_buf
, wdev
->conn
->params
.bssid
, ETH_ALEN
);
247 if (cfg80211_conn_do_work(wdev
))
248 __cfg80211_connect_result(
251 WLAN_STATUS_UNSPECIFIED_FAILURE
,
256 mutex_unlock(&rdev
->sched_scan_mtx
);
257 mutex_unlock(&rdev
->devlist_mtx
);
258 cfg80211_unlock_rdev(rdev
);
262 static struct cfg80211_bss
*cfg80211_get_conn_bss(struct wireless_dev
*wdev
)
264 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
265 struct cfg80211_bss
*bss
;
266 u16 capa
= WLAN_CAPABILITY_ESS
;
268 ASSERT_WDEV_LOCK(wdev
);
270 if (wdev
->conn
->params
.privacy
)
271 capa
|= WLAN_CAPABILITY_PRIVACY
;
273 bss
= cfg80211_get_bss(wdev
->wiphy
, wdev
->conn
->params
.channel
,
274 wdev
->conn
->params
.bssid
,
275 wdev
->conn
->params
.ssid
,
276 wdev
->conn
->params
.ssid_len
,
277 WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_PRIVACY
,
282 memcpy(wdev
->conn
->bssid
, bss
->bssid
, ETH_ALEN
);
283 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
284 wdev
->conn
->params
.channel
= bss
->channel
;
285 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
286 schedule_work(&rdev
->conn_work
);
291 static void __cfg80211_sme_scan_done(struct net_device
*dev
)
293 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
294 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
295 struct cfg80211_bss
*bss
;
297 ASSERT_WDEV_LOCK(wdev
);
299 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
305 if (wdev
->conn
->state
!= CFG80211_CONN_SCANNING
&&
306 wdev
->conn
->state
!= CFG80211_CONN_SCAN_AGAIN
)
309 bss
= cfg80211_get_conn_bss(wdev
);
311 cfg80211_put_bss(&rdev
->wiphy
, bss
);
314 if (wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)
315 schedule_work(&rdev
->conn_work
);
317 __cfg80211_connect_result(
319 wdev
->conn
->params
.bssid
,
321 WLAN_STATUS_UNSPECIFIED_FAILURE
,
326 void cfg80211_sme_scan_done(struct net_device
*dev
)
328 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
331 __cfg80211_sme_scan_done(dev
);
335 void cfg80211_sme_rx_auth(struct net_device
*dev
,
336 const u8
*buf
, size_t len
)
338 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
339 struct wiphy
*wiphy
= wdev
->wiphy
;
340 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
341 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
342 u16 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
344 ASSERT_WDEV_LOCK(wdev
);
346 /* should only RX auth frames when connecting */
347 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
350 if (WARN_ON(!wdev
->conn
))
353 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
354 wdev
->conn
->auto_auth
&&
355 wdev
->conn
->params
.auth_type
!= NL80211_AUTHTYPE_NETWORK_EAP
) {
356 /* select automatically between only open, shared, leap */
357 switch (wdev
->conn
->params
.auth_type
) {
358 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
359 if (wdev
->connect_keys
)
360 wdev
->conn
->params
.auth_type
=
361 NL80211_AUTHTYPE_SHARED_KEY
;
363 wdev
->conn
->params
.auth_type
=
364 NL80211_AUTHTYPE_NETWORK_EAP
;
366 case NL80211_AUTHTYPE_SHARED_KEY
:
367 wdev
->conn
->params
.auth_type
=
368 NL80211_AUTHTYPE_NETWORK_EAP
;
372 wdev
->conn
->params
.auth_type
=
373 NL80211_AUTHTYPE_OPEN_SYSTEM
;
376 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
377 schedule_work(&rdev
->conn_work
);
378 } else if (status_code
!= WLAN_STATUS_SUCCESS
) {
379 __cfg80211_connect_result(dev
, mgmt
->bssid
, NULL
, 0, NULL
, 0,
380 status_code
, false, NULL
);
381 } else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
382 wdev
->conn
->state
== CFG80211_CONN_AUTHENTICATING
) {
383 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
384 schedule_work(&rdev
->conn_work
);
388 bool cfg80211_sme_failed_reassoc(struct wireless_dev
*wdev
)
390 struct wiphy
*wiphy
= wdev
->wiphy
;
391 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
393 if (WARN_ON(!wdev
->conn
))
396 if (!wdev
->conn
->prev_bssid_valid
)
400 * Some stupid APs don't accept reassoc, so we
401 * need to fall back to trying regular assoc.
403 wdev
->conn
->prev_bssid_valid
= false;
404 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
405 schedule_work(&rdev
->conn_work
);
410 void cfg80211_sme_failed_assoc(struct wireless_dev
*wdev
)
412 struct wiphy
*wiphy
= wdev
->wiphy
;
413 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
415 wdev
->conn
->state
= CFG80211_CONN_DEAUTH_ASSOC_FAIL
;
416 schedule_work(&rdev
->conn_work
);
419 void __cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
420 const u8
*req_ie
, size_t req_ie_len
,
421 const u8
*resp_ie
, size_t resp_ie_len
,
422 u16 status
, bool wextev
,
423 struct cfg80211_bss
*bss
)
425 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
426 const u8
*country_ie
;
427 #ifdef CONFIG_CFG80211_WEXT
428 union iwreq_data wrqu
;
431 ASSERT_WDEV_LOCK(wdev
);
433 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
434 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
))
437 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
440 nl80211_send_connect_result(wiphy_to_dev(wdev
->wiphy
), dev
,
441 bssid
, req_ie
, req_ie_len
,
442 resp_ie
, resp_ie_len
,
445 #ifdef CONFIG_CFG80211_WEXT
447 if (req_ie
&& status
== WLAN_STATUS_SUCCESS
) {
448 memset(&wrqu
, 0, sizeof(wrqu
));
449 wrqu
.data
.length
= req_ie_len
;
450 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, req_ie
);
453 if (resp_ie
&& status
== WLAN_STATUS_SUCCESS
) {
454 memset(&wrqu
, 0, sizeof(wrqu
));
455 wrqu
.data
.length
= resp_ie_len
;
456 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, resp_ie
);
459 memset(&wrqu
, 0, sizeof(wrqu
));
460 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
461 if (bssid
&& status
== WLAN_STATUS_SUCCESS
) {
462 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
463 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
464 wdev
->wext
.prev_bssid_valid
= true;
466 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
470 if (wdev
->current_bss
) {
471 cfg80211_unhold_bss(wdev
->current_bss
);
472 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
473 wdev
->current_bss
= NULL
;
477 wdev
->conn
->state
= CFG80211_CONN_IDLE
;
479 if (status
!= WLAN_STATUS_SUCCESS
) {
480 wdev
->sme_state
= CFG80211_SME_IDLE
;
482 kfree(wdev
->conn
->ie
);
485 kfree(wdev
->connect_keys
);
486 wdev
->connect_keys
= NULL
;
488 cfg80211_put_bss(wdev
->wiphy
, bss
);
493 bss
= cfg80211_get_bss(wdev
->wiphy
,
494 wdev
->conn
? wdev
->conn
->params
.channel
:
497 wdev
->ssid
, wdev
->ssid_len
,
499 WLAN_CAPABILITY_ESS
);
504 cfg80211_hold_bss(bss_from_pub(bss
));
505 wdev
->current_bss
= bss_from_pub(bss
);
507 wdev
->sme_state
= CFG80211_SME_CONNECTED
;
508 cfg80211_upload_connect_keys(wdev
);
511 country_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
517 country_ie
= kmemdup(country_ie
, 2 + country_ie
[1], GFP_ATOMIC
);
524 * ieee80211_bss_get_ie() ensures we can access:
525 * - country_ie + 2, the start of the country ie data, and
526 * - and country_ie[1] which is the IE length
528 regulatory_hint_11d(wdev
->wiphy
, bss
->channel
->band
,
529 country_ie
+ 2, country_ie
[1]);
533 void cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
534 const u8
*req_ie
, size_t req_ie_len
,
535 const u8
*resp_ie
, size_t resp_ie_len
,
536 u16 status
, gfp_t gfp
)
538 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
539 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
540 struct cfg80211_event
*ev
;
543 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTING
);
545 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
549 ev
->type
= EVENT_CONNECT_RESULT
;
551 memcpy(ev
->cr
.bssid
, bssid
, ETH_ALEN
);
553 ev
->cr
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
554 ev
->cr
.req_ie_len
= req_ie_len
;
555 memcpy((void *)ev
->cr
.req_ie
, req_ie
, req_ie_len
);
558 ev
->cr
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
559 ev
->cr
.resp_ie_len
= resp_ie_len
;
560 memcpy((void *)ev
->cr
.resp_ie
, resp_ie
, resp_ie_len
);
562 ev
->cr
.status
= status
;
564 spin_lock_irqsave(&wdev
->event_lock
, flags
);
565 list_add_tail(&ev
->list
, &wdev
->event_list
);
566 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
567 queue_work(cfg80211_wq
, &rdev
->event_work
);
569 EXPORT_SYMBOL(cfg80211_connect_result
);
571 void __cfg80211_roamed(struct wireless_dev
*wdev
,
572 struct cfg80211_bss
*bss
,
573 const u8
*req_ie
, size_t req_ie_len
,
574 const u8
*resp_ie
, size_t resp_ie_len
)
576 #ifdef CONFIG_CFG80211_WEXT
577 union iwreq_data wrqu
;
579 ASSERT_WDEV_LOCK(wdev
);
581 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
582 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
))
585 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
588 /* internal error -- how did we get to CONNECTED w/o BSS? */
589 if (WARN_ON(!wdev
->current_bss
)) {
593 cfg80211_unhold_bss(wdev
->current_bss
);
594 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
595 wdev
->current_bss
= NULL
;
597 cfg80211_hold_bss(bss_from_pub(bss
));
598 wdev
->current_bss
= bss_from_pub(bss
);
600 nl80211_send_roamed(wiphy_to_dev(wdev
->wiphy
), wdev
->netdev
, bss
->bssid
,
601 req_ie
, req_ie_len
, resp_ie
, resp_ie_len
,
604 #ifdef CONFIG_CFG80211_WEXT
606 memset(&wrqu
, 0, sizeof(wrqu
));
607 wrqu
.data
.length
= req_ie_len
;
608 wireless_send_event(wdev
->netdev
, IWEVASSOCREQIE
,
613 memset(&wrqu
, 0, sizeof(wrqu
));
614 wrqu
.data
.length
= resp_ie_len
;
615 wireless_send_event(wdev
->netdev
, IWEVASSOCRESPIE
,
619 memset(&wrqu
, 0, sizeof(wrqu
));
620 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
621 memcpy(wrqu
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
622 memcpy(wdev
->wext
.prev_bssid
, bss
->bssid
, ETH_ALEN
);
623 wdev
->wext
.prev_bssid_valid
= true;
624 wireless_send_event(wdev
->netdev
, SIOCGIWAP
, &wrqu
, NULL
);
629 cfg80211_put_bss(wdev
->wiphy
, bss
);
632 void cfg80211_roamed(struct net_device
*dev
,
633 struct ieee80211_channel
*channel
,
635 const u8
*req_ie
, size_t req_ie_len
,
636 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
638 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
639 struct cfg80211_bss
*bss
;
641 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
643 bss
= cfg80211_get_bss(wdev
->wiphy
, channel
, bssid
, wdev
->ssid
,
644 wdev
->ssid_len
, WLAN_CAPABILITY_ESS
,
645 WLAN_CAPABILITY_ESS
);
649 cfg80211_roamed_bss(dev
, bss
, req_ie
, req_ie_len
, resp_ie
,
652 EXPORT_SYMBOL(cfg80211_roamed
);
654 void cfg80211_roamed_bss(struct net_device
*dev
,
655 struct cfg80211_bss
*bss
, const u8
*req_ie
,
656 size_t req_ie_len
, const u8
*resp_ie
,
657 size_t resp_ie_len
, gfp_t gfp
)
659 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
660 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
661 struct cfg80211_event
*ev
;
664 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
669 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
671 cfg80211_put_bss(wdev
->wiphy
, bss
);
675 ev
->type
= EVENT_ROAMED
;
676 ev
->rm
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
677 ev
->rm
.req_ie_len
= req_ie_len
;
678 memcpy((void *)ev
->rm
.req_ie
, req_ie
, req_ie_len
);
679 ev
->rm
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
680 ev
->rm
.resp_ie_len
= resp_ie_len
;
681 memcpy((void *)ev
->rm
.resp_ie
, resp_ie
, resp_ie_len
);
684 spin_lock_irqsave(&wdev
->event_lock
, flags
);
685 list_add_tail(&ev
->list
, &wdev
->event_list
);
686 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
687 queue_work(cfg80211_wq
, &rdev
->event_work
);
689 EXPORT_SYMBOL(cfg80211_roamed_bss
);
691 void __cfg80211_disconnected(struct net_device
*dev
, const u8
*ie
,
692 size_t ie_len
, u16 reason
, bool from_ap
)
694 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
695 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
697 #ifdef CONFIG_CFG80211_WEXT
698 union iwreq_data wrqu
;
701 ASSERT_WDEV_LOCK(wdev
);
703 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
704 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
))
707 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
710 if (wdev
->current_bss
) {
711 cfg80211_unhold_bss(wdev
->current_bss
);
712 cfg80211_put_bss(wdev
->wiphy
, &wdev
->current_bss
->pub
);
715 wdev
->current_bss
= NULL
;
716 wdev
->sme_state
= CFG80211_SME_IDLE
;
720 kfree(wdev
->conn
->ie
);
721 wdev
->conn
->ie
= NULL
;
726 nl80211_send_disconnected(rdev
, dev
, reason
, ie
, ie_len
, from_ap
);
729 * Delete all the keys ... pairwise keys can't really
730 * exist any more anyway, but default keys might.
732 if (rdev
->ops
->del_key
)
733 for (i
= 0; i
< 6; i
++)
734 rdev_del_key(rdev
, dev
, i
, false, NULL
);
736 #ifdef CONFIG_CFG80211_WEXT
737 memset(&wrqu
, 0, sizeof(wrqu
));
738 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
739 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
740 wdev
->wext
.connect
.ssid_len
= 0;
743 schedule_work(&cfg80211_disconnect_work
);
746 void cfg80211_disconnected(struct net_device
*dev
, u16 reason
,
747 u8
*ie
, size_t ie_len
, gfp_t gfp
)
749 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
750 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
751 struct cfg80211_event
*ev
;
754 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
756 ev
= kzalloc(sizeof(*ev
) + ie_len
, gfp
);
760 ev
->type
= EVENT_DISCONNECTED
;
761 ev
->dc
.ie
= ((u8
*)ev
) + sizeof(*ev
);
762 ev
->dc
.ie_len
= ie_len
;
763 memcpy((void *)ev
->dc
.ie
, ie
, ie_len
);
764 ev
->dc
.reason
= reason
;
766 spin_lock_irqsave(&wdev
->event_lock
, flags
);
767 list_add_tail(&ev
->list
, &wdev
->event_list
);
768 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
769 queue_work(cfg80211_wq
, &rdev
->event_work
);
771 EXPORT_SYMBOL(cfg80211_disconnected
);
773 int __cfg80211_connect(struct cfg80211_registered_device
*rdev
,
774 struct net_device
*dev
,
775 struct cfg80211_connect_params
*connect
,
776 struct cfg80211_cached_keys
*connkeys
,
777 const u8
*prev_bssid
)
779 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
780 struct cfg80211_bss
*bss
= NULL
;
783 ASSERT_WDEV_LOCK(wdev
);
785 if (wdev
->sme_state
!= CFG80211_SME_IDLE
)
788 if (WARN_ON(wdev
->connect_keys
)) {
789 kfree(wdev
->connect_keys
);
790 wdev
->connect_keys
= NULL
;
793 cfg80211_oper_and_ht_capa(&connect
->ht_capa_mask
,
794 rdev
->wiphy
.ht_capa_mod_mask
);
796 if (connkeys
&& connkeys
->def
>= 0) {
801 cipher
= connkeys
->params
[idx
].cipher
;
802 /* If given a WEP key we may need it for shared key auth */
803 if (cipher
== WLAN_CIPHER_SUITE_WEP40
||
804 cipher
== WLAN_CIPHER_SUITE_WEP104
) {
805 connect
->key_idx
= idx
;
806 connect
->key
= connkeys
->params
[idx
].key
;
807 connect
->key_len
= connkeys
->params
[idx
].key_len
;
810 * If ciphers are not set (e.g. when going through
811 * iwconfig), we have to set them appropriately here.
813 if (connect
->crypto
.cipher_group
== 0)
814 connect
->crypto
.cipher_group
= cipher
;
816 if (connect
->crypto
.n_ciphers_pairwise
== 0) {
817 connect
->crypto
.n_ciphers_pairwise
= 1;
818 connect
->crypto
.ciphers_pairwise
[0] = cipher
;
823 if (!rdev
->ops
->connect
) {
824 if (!rdev
->ops
->auth
|| !rdev
->ops
->assoc
)
827 if (WARN_ON(wdev
->conn
))
830 wdev
->conn
= kzalloc(sizeof(*wdev
->conn
), GFP_KERNEL
);
835 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
837 memcpy(&wdev
->conn
->params
, connect
, sizeof(*connect
));
838 if (connect
->bssid
) {
839 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
840 memcpy(wdev
->conn
->bssid
, connect
->bssid
, ETH_ALEN
);
844 wdev
->conn
->ie
= kmemdup(connect
->ie
, connect
->ie_len
,
846 wdev
->conn
->params
.ie
= wdev
->conn
->ie
;
847 if (!wdev
->conn
->ie
) {
854 if (connect
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) {
855 wdev
->conn
->auto_auth
= true;
856 /* start with open system ... should mostly work */
857 wdev
->conn
->params
.auth_type
=
858 NL80211_AUTHTYPE_OPEN_SYSTEM
;
860 wdev
->conn
->auto_auth
= false;
863 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
864 wdev
->ssid_len
= connect
->ssid_len
;
865 wdev
->conn
->params
.ssid
= wdev
->ssid
;
866 wdev
->conn
->params
.ssid_len
= connect
->ssid_len
;
868 /* see if we have the bss already */
869 bss
= cfg80211_get_conn_bss(wdev
);
871 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
872 wdev
->connect_keys
= connkeys
;
875 memcpy(wdev
->conn
->prev_bssid
, prev_bssid
, ETH_ALEN
);
876 wdev
->conn
->prev_bssid_valid
= true;
879 /* we're good if we have a matching bss struct */
881 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
882 err
= cfg80211_conn_do_work(wdev
);
883 cfg80211_put_bss(wdev
->wiphy
, bss
);
885 /* otherwise we'll need to scan for the AP first */
886 err
= cfg80211_conn_scan(wdev
);
888 * If we can't scan right now, then we need to scan again
889 * after the current scan finished, since the parameters
890 * changed (unless we find a good AP anyway).
894 wdev
->conn
->state
= CFG80211_CONN_SCAN_AGAIN
;
898 kfree(wdev
->conn
->ie
);
901 wdev
->sme_state
= CFG80211_SME_IDLE
;
902 wdev
->connect_keys
= NULL
;
908 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
909 wdev
->connect_keys
= connkeys
;
910 err
= rdev_connect(rdev
, dev
, connect
);
912 wdev
->connect_keys
= NULL
;
913 wdev
->sme_state
= CFG80211_SME_IDLE
;
917 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
918 wdev
->ssid_len
= connect
->ssid_len
;
924 int cfg80211_connect(struct cfg80211_registered_device
*rdev
,
925 struct net_device
*dev
,
926 struct cfg80211_connect_params
*connect
,
927 struct cfg80211_cached_keys
*connkeys
)
931 mutex_lock(&rdev
->devlist_mtx
);
932 /* might request scan - scan_mtx -> wdev_mtx dependency */
933 mutex_lock(&rdev
->sched_scan_mtx
);
934 wdev_lock(dev
->ieee80211_ptr
);
935 err
= __cfg80211_connect(rdev
, dev
, connect
, connkeys
, NULL
);
936 wdev_unlock(dev
->ieee80211_ptr
);
937 mutex_unlock(&rdev
->sched_scan_mtx
);
938 mutex_unlock(&rdev
->devlist_mtx
);
943 int __cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
944 struct net_device
*dev
, u16 reason
, bool wextev
)
946 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
949 ASSERT_WDEV_LOCK(wdev
);
951 if (wdev
->sme_state
== CFG80211_SME_IDLE
)
954 kfree(wdev
->connect_keys
);
955 wdev
->connect_keys
= NULL
;
957 if (!rdev
->ops
->disconnect
) {
958 if (!rdev
->ops
->deauth
)
961 /* was it connected by userspace SME? */
963 cfg80211_mlme_down(rdev
, dev
);
967 if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
968 (wdev
->conn
->state
== CFG80211_CONN_SCANNING
||
969 wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)) {
970 wdev
->sme_state
= CFG80211_SME_IDLE
;
971 kfree(wdev
->conn
->ie
);
978 /* wdev->conn->params.bssid must be set if > SCANNING */
979 err
= __cfg80211_mlme_deauth(rdev
, dev
,
980 wdev
->conn
->params
.bssid
,
981 NULL
, 0, reason
, false);
985 err
= rdev_disconnect(rdev
, dev
, reason
);
991 if (wdev
->sme_state
== CFG80211_SME_CONNECTED
)
992 __cfg80211_disconnected(dev
, NULL
, 0, 0, false);
993 else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
)
994 __cfg80211_connect_result(dev
, NULL
, NULL
, 0, NULL
, 0,
995 WLAN_STATUS_UNSPECIFIED_FAILURE
,
1001 int cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
1002 struct net_device
*dev
,
1003 u16 reason
, bool wextev
)
1007 wdev_lock(dev
->ieee80211_ptr
);
1008 err
= __cfg80211_disconnect(rdev
, dev
, reason
, wextev
);
1009 wdev_unlock(dev
->ieee80211_ptr
);
1014 void cfg80211_sme_disassoc(struct net_device
*dev
,
1015 struct cfg80211_internal_bss
*bss
)
1017 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1018 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
1021 ASSERT_WDEV_LOCK(wdev
);
1026 if (wdev
->conn
->state
== CFG80211_CONN_IDLE
)
1030 * Ok, so the association was made by this SME -- we don't
1031 * want it any more so deauthenticate too.
1034 memcpy(bssid
, bss
->pub
.bssid
, ETH_ALEN
);
1036 __cfg80211_mlme_deauth(rdev
, dev
, bssid
, NULL
, 0,
1037 WLAN_REASON_DEAUTH_LEAVING
, false);