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 <net/iw_handler.h>
14 #include <net/cfg80211.h>
15 #include <net/rtnetlink.h>
19 struct cfg80211_conn
{
20 struct cfg80211_connect_params params
;
21 /* these are sub-states of the _CONNECTING sme_state */
24 CFG80211_CONN_SCANNING
,
25 CFG80211_CONN_SCAN_AGAIN
,
26 CFG80211_CONN_AUTHENTICATE_NEXT
,
27 CFG80211_CONN_AUTHENTICATING
,
28 CFG80211_CONN_ASSOCIATE_NEXT
,
29 CFG80211_CONN_ASSOCIATING
,
30 CFG80211_CONN_DEAUTH_ASSOC_FAIL
,
32 u8 bssid
[ETH_ALEN
], prev_bssid
[ETH_ALEN
];
35 bool auto_auth
, prev_bssid_valid
;
38 bool cfg80211_is_all_idle(void)
40 struct cfg80211_registered_device
*rdev
;
41 struct wireless_dev
*wdev
;
42 bool is_all_idle
= true;
44 mutex_lock(&cfg80211_mutex
);
47 * All devices must be idle as otherwise if you are actively
48 * scanning some new beacon hints could be learned and would
49 * count as new regulatory hints.
51 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
52 cfg80211_lock_rdev(rdev
);
53 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
55 if (wdev
->sme_state
!= CFG80211_SME_IDLE
)
59 cfg80211_unlock_rdev(rdev
);
62 mutex_unlock(&cfg80211_mutex
);
67 static void disconnect_work(struct work_struct
*work
)
69 if (!cfg80211_is_all_idle())
72 regulatory_hint_disconnect();
75 static DECLARE_WORK(cfg80211_disconnect_work
, disconnect_work
);
77 static int cfg80211_conn_scan(struct wireless_dev
*wdev
)
79 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
80 struct cfg80211_scan_request
*request
;
84 ASSERT_RDEV_LOCK(rdev
);
85 ASSERT_WDEV_LOCK(wdev
);
90 if (wdev
->conn
->params
.channel
) {
93 enum ieee80211_band band
;
96 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
97 if (!wdev
->wiphy
->bands
[band
])
99 n_channels
+= wdev
->wiphy
->bands
[band
]->n_channels
;
102 request
= kzalloc(sizeof(*request
) + sizeof(request
->ssids
[0]) +
103 sizeof(request
->channels
[0]) * n_channels
,
108 if (wdev
->conn
->params
.channel
)
109 request
->channels
[0] = wdev
->conn
->params
.channel
;
112 enum ieee80211_band band
;
114 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
115 if (!wdev
->wiphy
->bands
[band
])
117 for (j
= 0; j
< wdev
->wiphy
->bands
[band
]->n_channels
;
119 request
->channels
[i
] =
120 &wdev
->wiphy
->bands
[band
]->channels
[j
];
123 request
->n_channels
= n_channels
;
124 request
->ssids
= (void *)&request
->channels
[n_channels
];
125 request
->n_ssids
= 1;
127 memcpy(request
->ssids
[0].ssid
, wdev
->conn
->params
.ssid
,
128 wdev
->conn
->params
.ssid_len
);
129 request
->ssids
[0].ssid_len
= wdev
->conn
->params
.ssid_len
;
131 request
->dev
= wdev
->netdev
;
132 request
->wiphy
= &rdev
->wiphy
;
134 rdev
->scan_req
= request
;
136 err
= rdev
->ops
->scan(wdev
->wiphy
, wdev
->netdev
, request
);
138 wdev
->conn
->state
= CFG80211_CONN_SCANNING
;
139 nl80211_send_scan_start(rdev
, wdev
->netdev
);
140 dev_hold(wdev
->netdev
);
142 rdev
->scan_req
= NULL
;
148 static int cfg80211_conn_do_work(struct wireless_dev
*wdev
)
150 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
151 struct cfg80211_connect_params
*params
;
152 const u8
*prev_bssid
= NULL
;
155 ASSERT_WDEV_LOCK(wdev
);
160 params
= &wdev
->conn
->params
;
162 switch (wdev
->conn
->state
) {
163 case CFG80211_CONN_SCAN_AGAIN
:
164 return cfg80211_conn_scan(wdev
);
165 case CFG80211_CONN_AUTHENTICATE_NEXT
:
166 BUG_ON(!rdev
->ops
->auth
);
167 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATING
;
168 return __cfg80211_mlme_auth(rdev
, wdev
->netdev
,
169 params
->channel
, params
->auth_type
,
171 params
->ssid
, params
->ssid_len
,
173 params
->key
, params
->key_len
,
174 params
->key_idx
, false);
175 case CFG80211_CONN_ASSOCIATE_NEXT
:
176 BUG_ON(!rdev
->ops
->assoc
);
177 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATING
;
178 if (wdev
->conn
->prev_bssid_valid
)
179 prev_bssid
= wdev
->conn
->prev_bssid
;
180 err
= __cfg80211_mlme_assoc(rdev
, wdev
->netdev
,
181 params
->channel
, params
->bssid
,
183 params
->ssid
, params
->ssid_len
,
184 params
->ie
, params
->ie_len
,
185 false, ¶ms
->crypto
);
187 __cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
189 WLAN_REASON_DEAUTH_LEAVING
,
192 case CFG80211_CONN_DEAUTH_ASSOC_FAIL
:
193 __cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
195 WLAN_REASON_DEAUTH_LEAVING
, false);
196 /* return an error so that we call __cfg80211_connect_result() */
203 void cfg80211_conn_work(struct work_struct
*work
)
205 struct cfg80211_registered_device
*rdev
=
206 container_of(work
, struct cfg80211_registered_device
, conn_work
);
207 struct wireless_dev
*wdev
;
208 u8 bssid_buf
[ETH_ALEN
], *bssid
= NULL
;
211 cfg80211_lock_rdev(rdev
);
212 mutex_lock(&rdev
->devlist_mtx
);
214 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
216 if (!netif_running(wdev
->netdev
)) {
220 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
) {
224 if (wdev
->conn
->params
.bssid
) {
225 memcpy(bssid_buf
, wdev
->conn
->params
.bssid
, ETH_ALEN
);
228 if (cfg80211_conn_do_work(wdev
))
229 __cfg80211_connect_result(
232 WLAN_STATUS_UNSPECIFIED_FAILURE
,
237 mutex_unlock(&rdev
->devlist_mtx
);
238 cfg80211_unlock_rdev(rdev
);
242 static struct cfg80211_bss
*cfg80211_get_conn_bss(struct wireless_dev
*wdev
)
244 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
245 struct cfg80211_bss
*bss
;
246 u16 capa
= WLAN_CAPABILITY_ESS
;
248 ASSERT_WDEV_LOCK(wdev
);
250 if (wdev
->conn
->params
.privacy
)
251 capa
|= WLAN_CAPABILITY_PRIVACY
;
253 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, wdev
->conn
->params
.bssid
,
254 wdev
->conn
->params
.ssid
,
255 wdev
->conn
->params
.ssid_len
,
256 WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_PRIVACY
,
261 memcpy(wdev
->conn
->bssid
, bss
->bssid
, ETH_ALEN
);
262 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
263 wdev
->conn
->params
.channel
= bss
->channel
;
264 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
265 schedule_work(&rdev
->conn_work
);
270 static void __cfg80211_sme_scan_done(struct net_device
*dev
)
272 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
273 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
274 struct cfg80211_bss
*bss
;
276 ASSERT_WDEV_LOCK(wdev
);
278 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
284 if (wdev
->conn
->state
!= CFG80211_CONN_SCANNING
&&
285 wdev
->conn
->state
!= CFG80211_CONN_SCAN_AGAIN
)
288 bss
= cfg80211_get_conn_bss(wdev
);
290 cfg80211_put_bss(bss
);
293 if (wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)
294 schedule_work(&rdev
->conn_work
);
296 __cfg80211_connect_result(
298 wdev
->conn
->params
.bssid
,
300 WLAN_STATUS_UNSPECIFIED_FAILURE
,
305 void cfg80211_sme_scan_done(struct net_device
*dev
)
307 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
309 mutex_lock(&wiphy_to_dev(wdev
->wiphy
)->devlist_mtx
);
311 __cfg80211_sme_scan_done(dev
);
313 mutex_unlock(&wiphy_to_dev(wdev
->wiphy
)->devlist_mtx
);
316 void cfg80211_sme_rx_auth(struct net_device
*dev
,
317 const u8
*buf
, size_t len
)
319 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
320 struct wiphy
*wiphy
= wdev
->wiphy
;
321 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
322 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
323 u16 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
325 ASSERT_WDEV_LOCK(wdev
);
327 /* should only RX auth frames when connecting */
328 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
331 if (WARN_ON(!wdev
->conn
))
334 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
335 wdev
->conn
->auto_auth
&&
336 wdev
->conn
->params
.auth_type
!= NL80211_AUTHTYPE_NETWORK_EAP
) {
337 /* select automatically between only open, shared, leap */
338 switch (wdev
->conn
->params
.auth_type
) {
339 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
340 if (wdev
->connect_keys
)
341 wdev
->conn
->params
.auth_type
=
342 NL80211_AUTHTYPE_SHARED_KEY
;
344 wdev
->conn
->params
.auth_type
=
345 NL80211_AUTHTYPE_NETWORK_EAP
;
347 case NL80211_AUTHTYPE_SHARED_KEY
:
348 wdev
->conn
->params
.auth_type
=
349 NL80211_AUTHTYPE_NETWORK_EAP
;
353 wdev
->conn
->params
.auth_type
=
354 NL80211_AUTHTYPE_OPEN_SYSTEM
;
357 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
358 schedule_work(&rdev
->conn_work
);
359 } else if (status_code
!= WLAN_STATUS_SUCCESS
) {
360 __cfg80211_connect_result(dev
, mgmt
->bssid
, NULL
, 0, NULL
, 0,
361 status_code
, false, NULL
);
362 } else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
363 wdev
->conn
->state
== CFG80211_CONN_AUTHENTICATING
) {
364 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
365 schedule_work(&rdev
->conn_work
);
369 bool cfg80211_sme_failed_reassoc(struct wireless_dev
*wdev
)
371 struct wiphy
*wiphy
= wdev
->wiphy
;
372 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
374 if (WARN_ON(!wdev
->conn
))
377 if (!wdev
->conn
->prev_bssid_valid
)
381 * Some stupid APs don't accept reassoc, so we
382 * need to fall back to trying regular assoc.
384 wdev
->conn
->prev_bssid_valid
= false;
385 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
386 schedule_work(&rdev
->conn_work
);
391 void cfg80211_sme_failed_assoc(struct wireless_dev
*wdev
)
393 struct wiphy
*wiphy
= wdev
->wiphy
;
394 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
396 wdev
->conn
->state
= CFG80211_CONN_DEAUTH_ASSOC_FAIL
;
397 schedule_work(&rdev
->conn_work
);
400 void __cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
401 const u8
*req_ie
, size_t req_ie_len
,
402 const u8
*resp_ie
, size_t resp_ie_len
,
403 u16 status
, bool wextev
,
404 struct cfg80211_bss
*bss
)
406 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
408 #ifdef CONFIG_CFG80211_WEXT
409 union iwreq_data wrqu
;
412 ASSERT_WDEV_LOCK(wdev
);
414 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
417 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
420 nl80211_send_connect_result(wiphy_to_dev(wdev
->wiphy
), dev
,
421 bssid
, req_ie
, req_ie_len
,
422 resp_ie
, resp_ie_len
,
425 #ifdef CONFIG_CFG80211_WEXT
427 if (req_ie
&& status
== WLAN_STATUS_SUCCESS
) {
428 memset(&wrqu
, 0, sizeof(wrqu
));
429 wrqu
.data
.length
= req_ie_len
;
430 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, req_ie
);
433 if (resp_ie
&& status
== WLAN_STATUS_SUCCESS
) {
434 memset(&wrqu
, 0, sizeof(wrqu
));
435 wrqu
.data
.length
= resp_ie_len
;
436 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, resp_ie
);
439 memset(&wrqu
, 0, sizeof(wrqu
));
440 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
441 if (bssid
&& status
== WLAN_STATUS_SUCCESS
) {
442 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
443 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
444 wdev
->wext
.prev_bssid_valid
= true;
446 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
450 if (wdev
->current_bss
) {
451 cfg80211_unhold_bss(wdev
->current_bss
);
452 cfg80211_put_bss(&wdev
->current_bss
->pub
);
453 wdev
->current_bss
= NULL
;
457 wdev
->conn
->state
= CFG80211_CONN_IDLE
;
459 if (status
!= WLAN_STATUS_SUCCESS
) {
460 wdev
->sme_state
= CFG80211_SME_IDLE
;
462 kfree(wdev
->conn
->ie
);
465 kfree(wdev
->connect_keys
);
466 wdev
->connect_keys
= NULL
;
472 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, bssid
,
473 wdev
->ssid
, wdev
->ssid_len
,
475 WLAN_CAPABILITY_ESS
);
480 cfg80211_hold_bss(bss_from_pub(bss
));
481 wdev
->current_bss
= bss_from_pub(bss
);
483 wdev
->sme_state
= CFG80211_SME_CONNECTED
;
484 cfg80211_upload_connect_keys(wdev
);
486 country_ie
= (u8
*) ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
492 * ieee80211_bss_get_ie() ensures we can access:
493 * - country_ie + 2, the start of the country ie data, and
494 * - and country_ie[1] which is the IE length
496 regulatory_hint_11d(wdev
->wiphy
,
502 void cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
503 const u8
*req_ie
, size_t req_ie_len
,
504 const u8
*resp_ie
, size_t resp_ie_len
,
505 u16 status
, gfp_t gfp
)
507 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
508 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
509 struct cfg80211_event
*ev
;
512 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTING
);
514 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
518 ev
->type
= EVENT_CONNECT_RESULT
;
520 memcpy(ev
->cr
.bssid
, bssid
, ETH_ALEN
);
522 ev
->cr
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
523 ev
->cr
.req_ie_len
= req_ie_len
;
524 memcpy((void *)ev
->cr
.req_ie
, req_ie
, req_ie_len
);
527 ev
->cr
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
528 ev
->cr
.resp_ie_len
= resp_ie_len
;
529 memcpy((void *)ev
->cr
.resp_ie
, resp_ie
, resp_ie_len
);
531 ev
->cr
.status
= status
;
533 spin_lock_irqsave(&wdev
->event_lock
, flags
);
534 list_add_tail(&ev
->list
, &wdev
->event_list
);
535 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
536 queue_work(cfg80211_wq
, &rdev
->event_work
);
538 EXPORT_SYMBOL(cfg80211_connect_result
);
540 void __cfg80211_roamed(struct wireless_dev
*wdev
, const u8
*bssid
,
541 const u8
*req_ie
, size_t req_ie_len
,
542 const u8
*resp_ie
, size_t resp_ie_len
)
544 struct cfg80211_bss
*bss
;
545 #ifdef CONFIG_CFG80211_WEXT
546 union iwreq_data wrqu
;
549 ASSERT_WDEV_LOCK(wdev
);
551 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
554 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
557 /* internal error -- how did we get to CONNECTED w/o BSS? */
558 if (WARN_ON(!wdev
->current_bss
)) {
562 cfg80211_unhold_bss(wdev
->current_bss
);
563 cfg80211_put_bss(&wdev
->current_bss
->pub
);
564 wdev
->current_bss
= NULL
;
566 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, bssid
,
567 wdev
->ssid
, wdev
->ssid_len
,
568 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
573 cfg80211_hold_bss(bss_from_pub(bss
));
574 wdev
->current_bss
= bss_from_pub(bss
);
576 nl80211_send_roamed(wiphy_to_dev(wdev
->wiphy
), wdev
->netdev
, bssid
,
577 req_ie
, req_ie_len
, resp_ie
, resp_ie_len
,
580 #ifdef CONFIG_CFG80211_WEXT
582 memset(&wrqu
, 0, sizeof(wrqu
));
583 wrqu
.data
.length
= req_ie_len
;
584 wireless_send_event(wdev
->netdev
, IWEVASSOCREQIE
,
589 memset(&wrqu
, 0, sizeof(wrqu
));
590 wrqu
.data
.length
= resp_ie_len
;
591 wireless_send_event(wdev
->netdev
, IWEVASSOCRESPIE
,
595 memset(&wrqu
, 0, sizeof(wrqu
));
596 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
597 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
598 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
599 wdev
->wext
.prev_bssid_valid
= true;
600 wireless_send_event(wdev
->netdev
, SIOCGIWAP
, &wrqu
, NULL
);
604 void cfg80211_roamed(struct net_device
*dev
, const u8
*bssid
,
605 const u8
*req_ie
, size_t req_ie_len
,
606 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
608 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
609 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
610 struct cfg80211_event
*ev
;
613 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
615 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
619 ev
->type
= EVENT_ROAMED
;
620 memcpy(ev
->rm
.bssid
, bssid
, ETH_ALEN
);
621 ev
->rm
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
622 ev
->rm
.req_ie_len
= req_ie_len
;
623 memcpy((void *)ev
->rm
.req_ie
, req_ie
, req_ie_len
);
624 ev
->rm
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
625 ev
->rm
.resp_ie_len
= resp_ie_len
;
626 memcpy((void *)ev
->rm
.resp_ie
, resp_ie
, resp_ie_len
);
628 spin_lock_irqsave(&wdev
->event_lock
, flags
);
629 list_add_tail(&ev
->list
, &wdev
->event_list
);
630 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
631 queue_work(cfg80211_wq
, &rdev
->event_work
);
633 EXPORT_SYMBOL(cfg80211_roamed
);
635 void __cfg80211_disconnected(struct net_device
*dev
, const u8
*ie
,
636 size_t ie_len
, u16 reason
, bool from_ap
)
638 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
639 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
641 #ifdef CONFIG_CFG80211_WEXT
642 union iwreq_data wrqu
;
645 ASSERT_WDEV_LOCK(wdev
);
647 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
650 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
653 if (wdev
->current_bss
) {
654 cfg80211_unhold_bss(wdev
->current_bss
);
655 cfg80211_put_bss(&wdev
->current_bss
->pub
);
658 wdev
->current_bss
= NULL
;
659 wdev
->sme_state
= CFG80211_SME_IDLE
;
666 kfree(wdev
->conn
->ie
);
667 wdev
->conn
->ie
= NULL
;
672 * If this disconnect was due to a disassoc, we
673 * we might still have an auth BSS around. For
674 * the userspace SME that's currently expected,
675 * but for the kernel SME (nl80211 CONNECT or
676 * wireless extensions) we want to clear up all
679 for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
680 if (!wdev
->auth_bsses
[i
])
682 bssid
= wdev
->auth_bsses
[i
]->pub
.bssid
;
683 ret
= __cfg80211_mlme_deauth(rdev
, dev
, bssid
, NULL
, 0,
684 WLAN_REASON_DEAUTH_LEAVING
,
686 WARN(ret
, "deauth failed: %d\n", ret
);
690 nl80211_send_disconnected(rdev
, dev
, reason
, ie
, ie_len
, from_ap
);
693 * Delete all the keys ... pairwise keys can't really
694 * exist any more anyway, but default keys might.
696 if (rdev
->ops
->del_key
)
697 for (i
= 0; i
< 6; i
++)
698 rdev
->ops
->del_key(wdev
->wiphy
, dev
, i
, NULL
);
700 #ifdef CONFIG_CFG80211_WEXT
701 memset(&wrqu
, 0, sizeof(wrqu
));
702 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
703 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
704 wdev
->wext
.connect
.ssid_len
= 0;
707 schedule_work(&cfg80211_disconnect_work
);
710 void cfg80211_disconnected(struct net_device
*dev
, u16 reason
,
711 u8
*ie
, size_t ie_len
, gfp_t gfp
)
713 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
714 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
715 struct cfg80211_event
*ev
;
718 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
720 ev
= kzalloc(sizeof(*ev
) + ie_len
, gfp
);
724 ev
->type
= EVENT_DISCONNECTED
;
725 ev
->dc
.ie
= ((u8
*)ev
) + sizeof(*ev
);
726 ev
->dc
.ie_len
= ie_len
;
727 memcpy((void *)ev
->dc
.ie
, ie
, ie_len
);
728 ev
->dc
.reason
= reason
;
730 spin_lock_irqsave(&wdev
->event_lock
, flags
);
731 list_add_tail(&ev
->list
, &wdev
->event_list
);
732 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
733 queue_work(cfg80211_wq
, &rdev
->event_work
);
735 EXPORT_SYMBOL(cfg80211_disconnected
);
737 int __cfg80211_connect(struct cfg80211_registered_device
*rdev
,
738 struct net_device
*dev
,
739 struct cfg80211_connect_params
*connect
,
740 struct cfg80211_cached_keys
*connkeys
,
741 const u8
*prev_bssid
)
743 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
744 struct ieee80211_channel
*chan
;
745 struct cfg80211_bss
*bss
= NULL
;
748 ASSERT_WDEV_LOCK(wdev
);
750 if (wdev
->sme_state
!= CFG80211_SME_IDLE
)
753 chan
= rdev_fixed_channel(rdev
, wdev
);
754 if (chan
&& chan
!= connect
->channel
)
757 if (WARN_ON(wdev
->connect_keys
)) {
758 kfree(wdev
->connect_keys
);
759 wdev
->connect_keys
= NULL
;
762 if (connkeys
&& connkeys
->def
>= 0) {
767 cipher
= connkeys
->params
[idx
].cipher
;
768 /* If given a WEP key we may need it for shared key auth */
769 if (cipher
== WLAN_CIPHER_SUITE_WEP40
||
770 cipher
== WLAN_CIPHER_SUITE_WEP104
) {
771 connect
->key_idx
= idx
;
772 connect
->key
= connkeys
->params
[idx
].key
;
773 connect
->key_len
= connkeys
->params
[idx
].key_len
;
776 * If ciphers are not set (e.g. when going through
777 * iwconfig), we have to set them appropriately here.
779 if (connect
->crypto
.cipher_group
== 0)
780 connect
->crypto
.cipher_group
= cipher
;
782 if (connect
->crypto
.n_ciphers_pairwise
== 0) {
783 connect
->crypto
.n_ciphers_pairwise
= 1;
784 connect
->crypto
.ciphers_pairwise
[0] = cipher
;
789 if (!rdev
->ops
->connect
) {
790 if (!rdev
->ops
->auth
|| !rdev
->ops
->assoc
)
793 if (WARN_ON(wdev
->conn
))
796 wdev
->conn
= kzalloc(sizeof(*wdev
->conn
), GFP_KERNEL
);
801 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
803 memcpy(&wdev
->conn
->params
, connect
, sizeof(*connect
));
804 if (connect
->bssid
) {
805 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
806 memcpy(wdev
->conn
->bssid
, connect
->bssid
, ETH_ALEN
);
810 wdev
->conn
->ie
= kmemdup(connect
->ie
, connect
->ie_len
,
812 wdev
->conn
->params
.ie
= wdev
->conn
->ie
;
813 if (!wdev
->conn
->ie
) {
820 if (connect
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) {
821 wdev
->conn
->auto_auth
= true;
822 /* start with open system ... should mostly work */
823 wdev
->conn
->params
.auth_type
=
824 NL80211_AUTHTYPE_OPEN_SYSTEM
;
826 wdev
->conn
->auto_auth
= false;
829 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
830 wdev
->ssid_len
= connect
->ssid_len
;
831 wdev
->conn
->params
.ssid
= wdev
->ssid
;
832 wdev
->conn
->params
.ssid_len
= connect
->ssid_len
;
834 /* see if we have the bss already */
835 bss
= cfg80211_get_conn_bss(wdev
);
837 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
838 wdev
->connect_keys
= connkeys
;
841 memcpy(wdev
->conn
->prev_bssid
, prev_bssid
, ETH_ALEN
);
842 wdev
->conn
->prev_bssid_valid
= true;
845 /* we're good if we have a matching bss struct */
847 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
848 err
= cfg80211_conn_do_work(wdev
);
849 cfg80211_put_bss(bss
);
851 /* otherwise we'll need to scan for the AP first */
852 err
= cfg80211_conn_scan(wdev
);
854 * If we can't scan right now, then we need to scan again
855 * after the current scan finished, since the parameters
856 * changed (unless we find a good AP anyway).
860 wdev
->conn
->state
= CFG80211_CONN_SCAN_AGAIN
;
864 kfree(wdev
->conn
->ie
);
867 wdev
->sme_state
= CFG80211_SME_IDLE
;
868 wdev
->connect_keys
= NULL
;
874 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
875 wdev
->connect_keys
= connkeys
;
876 err
= rdev
->ops
->connect(&rdev
->wiphy
, dev
, connect
);
878 wdev
->connect_keys
= NULL
;
879 wdev
->sme_state
= CFG80211_SME_IDLE
;
883 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
884 wdev
->ssid_len
= connect
->ssid_len
;
890 int cfg80211_connect(struct cfg80211_registered_device
*rdev
,
891 struct net_device
*dev
,
892 struct cfg80211_connect_params
*connect
,
893 struct cfg80211_cached_keys
*connkeys
)
897 mutex_lock(&rdev
->devlist_mtx
);
898 wdev_lock(dev
->ieee80211_ptr
);
899 err
= __cfg80211_connect(rdev
, dev
, connect
, connkeys
, NULL
);
900 wdev_unlock(dev
->ieee80211_ptr
);
901 mutex_unlock(&rdev
->devlist_mtx
);
906 int __cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
907 struct net_device
*dev
, u16 reason
, bool wextev
)
909 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
912 ASSERT_WDEV_LOCK(wdev
);
914 if (wdev
->sme_state
== CFG80211_SME_IDLE
)
917 kfree(wdev
->connect_keys
);
918 wdev
->connect_keys
= NULL
;
920 if (!rdev
->ops
->disconnect
) {
921 if (!rdev
->ops
->deauth
)
924 /* was it connected by userspace SME? */
926 cfg80211_mlme_down(rdev
, dev
);
930 if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
931 (wdev
->conn
->state
== CFG80211_CONN_SCANNING
||
932 wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)) {
933 wdev
->sme_state
= CFG80211_SME_IDLE
;
934 kfree(wdev
->conn
->ie
);
941 /* wdev->conn->params.bssid must be set if > SCANNING */
942 err
= __cfg80211_mlme_deauth(rdev
, dev
,
943 wdev
->conn
->params
.bssid
,
944 NULL
, 0, reason
, false);
948 err
= rdev
->ops
->disconnect(&rdev
->wiphy
, dev
, reason
);
953 if (wdev
->sme_state
== CFG80211_SME_CONNECTED
)
954 __cfg80211_disconnected(dev
, NULL
, 0, 0, false);
955 else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
)
956 __cfg80211_connect_result(dev
, NULL
, NULL
, 0, NULL
, 0,
957 WLAN_STATUS_UNSPECIFIED_FAILURE
,
963 int cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
964 struct net_device
*dev
,
965 u16 reason
, bool wextev
)
969 wdev_lock(dev
->ieee80211_ptr
);
970 err
= __cfg80211_disconnect(rdev
, dev
, reason
, wextev
);
971 wdev_unlock(dev
->ieee80211_ptr
);
976 void cfg80211_sme_disassoc(struct net_device
*dev
, int idx
)
978 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
979 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
982 ASSERT_WDEV_LOCK(wdev
);
987 if (wdev
->conn
->state
== CFG80211_CONN_IDLE
)
991 * Ok, so the association was made by this SME -- we don't
992 * want it any more so deauthenticate too.
995 if (!wdev
->auth_bsses
[idx
])
998 memcpy(bssid
, wdev
->auth_bsses
[idx
]->pub
.bssid
, ETH_ALEN
);
999 if (__cfg80211_mlme_deauth(rdev
, dev
, bssid
,
1000 NULL
, 0, WLAN_REASON_DEAUTH_LEAVING
,
1002 /* whatever -- assume gone anyway */
1003 cfg80211_unhold_bss(wdev
->auth_bsses
[idx
]);
1004 cfg80211_put_bss(&wdev
->auth_bsses
[idx
]->pub
);
1005 wdev
->auth_bsses
[idx
] = NULL
;