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/workqueue.h>
11 #include <linux/wireless.h>
12 #include <net/iw_handler.h>
13 #include <net/cfg80211.h>
14 #include <net/rtnetlink.h>
18 struct cfg80211_conn
{
19 struct cfg80211_connect_params params
;
20 /* these are sub-states of the _CONNECTING sme_state */
23 CFG80211_CONN_SCANNING
,
24 CFG80211_CONN_SCAN_AGAIN
,
25 CFG80211_CONN_AUTHENTICATE_NEXT
,
26 CFG80211_CONN_AUTHENTICATING
,
27 CFG80211_CONN_ASSOCIATE_NEXT
,
28 CFG80211_CONN_ASSOCIATING
,
30 u8 bssid
[ETH_ALEN
], prev_bssid
[ETH_ALEN
];
33 bool auto_auth
, prev_bssid_valid
;
37 static int cfg80211_conn_scan(struct wireless_dev
*wdev
)
39 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
40 struct cfg80211_scan_request
*request
;
44 ASSERT_RDEV_LOCK(rdev
);
45 ASSERT_WDEV_LOCK(wdev
);
50 if (wdev
->conn
->params
.channel
) {
53 enum ieee80211_band band
;
56 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
57 if (!wdev
->wiphy
->bands
[band
])
59 n_channels
+= wdev
->wiphy
->bands
[band
]->n_channels
;
62 request
= kzalloc(sizeof(*request
) + sizeof(request
->ssids
[0]) +
63 sizeof(request
->channels
[0]) * n_channels
,
68 if (wdev
->conn
->params
.channel
)
69 request
->channels
[0] = wdev
->conn
->params
.channel
;
72 enum ieee80211_band band
;
74 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
75 if (!wdev
->wiphy
->bands
[band
])
77 for (j
= 0; j
< wdev
->wiphy
->bands
[band
]->n_channels
;
79 request
->channels
[i
] =
80 &wdev
->wiphy
->bands
[band
]->channels
[j
];
83 request
->n_channels
= n_channels
;
84 request
->ssids
= (void *)&request
->channels
[n_channels
];
87 memcpy(request
->ssids
[0].ssid
, wdev
->conn
->params
.ssid
,
88 wdev
->conn
->params
.ssid_len
);
89 request
->ssids
[0].ssid_len
= wdev
->conn
->params
.ssid_len
;
91 request
->dev
= wdev
->netdev
;
92 request
->wiphy
= &rdev
->wiphy
;
94 rdev
->scan_req
= request
;
96 err
= rdev
->ops
->scan(wdev
->wiphy
, wdev
->netdev
, request
);
98 wdev
->conn
->state
= CFG80211_CONN_SCANNING
;
99 nl80211_send_scan_start(rdev
, wdev
->netdev
);
100 dev_hold(wdev
->netdev
);
102 rdev
->scan_req
= NULL
;
108 static int cfg80211_conn_do_work(struct wireless_dev
*wdev
)
110 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
111 struct cfg80211_connect_params
*params
;
112 const u8
*prev_bssid
= NULL
;
115 ASSERT_WDEV_LOCK(wdev
);
120 params
= &wdev
->conn
->params
;
122 switch (wdev
->conn
->state
) {
123 case CFG80211_CONN_SCAN_AGAIN
:
124 return cfg80211_conn_scan(wdev
);
125 case CFG80211_CONN_AUTHENTICATE_NEXT
:
126 BUG_ON(!rdev
->ops
->auth
);
127 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATING
;
128 return __cfg80211_mlme_auth(rdev
, wdev
->netdev
,
129 params
->channel
, params
->auth_type
,
131 params
->ssid
, params
->ssid_len
,
133 params
->key
, params
->key_len
,
135 case CFG80211_CONN_ASSOCIATE_NEXT
:
136 BUG_ON(!rdev
->ops
->assoc
);
137 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATING
;
138 if (wdev
->conn
->prev_bssid_valid
)
139 prev_bssid
= wdev
->conn
->prev_bssid
;
140 err
= __cfg80211_mlme_assoc(rdev
, wdev
->netdev
,
141 params
->channel
, params
->bssid
,
143 params
->ssid
, params
->ssid_len
,
144 params
->ie
, params
->ie_len
,
145 false, ¶ms
->crypto
);
147 __cfg80211_mlme_deauth(rdev
, wdev
->netdev
, params
->bssid
,
149 WLAN_REASON_DEAUTH_LEAVING
);
156 void cfg80211_conn_work(struct work_struct
*work
)
158 struct cfg80211_registered_device
*rdev
=
159 container_of(work
, struct cfg80211_registered_device
, conn_work
);
160 struct wireless_dev
*wdev
;
163 cfg80211_lock_rdev(rdev
);
164 mutex_lock(&rdev
->devlist_mtx
);
166 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
168 if (!netif_running(wdev
->netdev
)) {
172 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
) {
176 if (cfg80211_conn_do_work(wdev
))
177 __cfg80211_connect_result(
179 wdev
->conn
->params
.bssid
,
181 WLAN_STATUS_UNSPECIFIED_FAILURE
,
186 mutex_unlock(&rdev
->devlist_mtx
);
187 cfg80211_unlock_rdev(rdev
);
191 static struct cfg80211_bss
*cfg80211_get_conn_bss(struct wireless_dev
*wdev
)
193 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
194 struct cfg80211_bss
*bss
;
195 u16 capa
= WLAN_CAPABILITY_ESS
;
197 ASSERT_WDEV_LOCK(wdev
);
199 if (wdev
->conn
->params
.privacy
)
200 capa
|= WLAN_CAPABILITY_PRIVACY
;
202 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, wdev
->conn
->params
.bssid
,
203 wdev
->conn
->params
.ssid
,
204 wdev
->conn
->params
.ssid_len
,
205 WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_PRIVACY
,
210 memcpy(wdev
->conn
->bssid
, bss
->bssid
, ETH_ALEN
);
211 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
212 wdev
->conn
->params
.channel
= bss
->channel
;
213 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
214 schedule_work(&rdev
->conn_work
);
219 static void __cfg80211_sme_scan_done(struct net_device
*dev
)
221 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
222 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
223 struct cfg80211_bss
*bss
;
225 ASSERT_WDEV_LOCK(wdev
);
227 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
233 if (wdev
->conn
->state
!= CFG80211_CONN_SCANNING
&&
234 wdev
->conn
->state
!= CFG80211_CONN_SCAN_AGAIN
)
237 bss
= cfg80211_get_conn_bss(wdev
);
239 cfg80211_put_bss(bss
);
242 if (wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)
243 schedule_work(&rdev
->conn_work
);
245 __cfg80211_connect_result(
247 wdev
->conn
->params
.bssid
,
249 WLAN_STATUS_UNSPECIFIED_FAILURE
,
254 void cfg80211_sme_scan_done(struct net_device
*dev
)
256 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
258 mutex_lock(&wiphy_to_dev(wdev
->wiphy
)->devlist_mtx
);
260 __cfg80211_sme_scan_done(dev
);
262 mutex_unlock(&wiphy_to_dev(wdev
->wiphy
)->devlist_mtx
);
265 void cfg80211_sme_rx_auth(struct net_device
*dev
,
266 const u8
*buf
, size_t len
)
268 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
269 struct wiphy
*wiphy
= wdev
->wiphy
;
270 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
271 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buf
;
272 u16 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
274 ASSERT_WDEV_LOCK(wdev
);
276 /* should only RX auth frames when connecting */
277 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
280 if (WARN_ON(!wdev
->conn
))
283 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
284 wdev
->conn
->auto_auth
&&
285 wdev
->conn
->params
.auth_type
!= NL80211_AUTHTYPE_NETWORK_EAP
) {
286 /* select automatically between only open, shared, leap */
287 switch (wdev
->conn
->params
.auth_type
) {
288 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
289 if (wdev
->connect_keys
)
290 wdev
->conn
->params
.auth_type
=
291 NL80211_AUTHTYPE_SHARED_KEY
;
293 wdev
->conn
->params
.auth_type
=
294 NL80211_AUTHTYPE_NETWORK_EAP
;
296 case NL80211_AUTHTYPE_SHARED_KEY
:
297 wdev
->conn
->params
.auth_type
=
298 NL80211_AUTHTYPE_NETWORK_EAP
;
302 wdev
->conn
->params
.auth_type
=
303 NL80211_AUTHTYPE_OPEN_SYSTEM
;
306 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
307 schedule_work(&rdev
->conn_work
);
308 } else if (status_code
!= WLAN_STATUS_SUCCESS
) {
309 __cfg80211_connect_result(dev
, mgmt
->bssid
, NULL
, 0, NULL
, 0,
310 status_code
, false, NULL
);
311 } else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
312 wdev
->conn
->state
== CFG80211_CONN_AUTHENTICATING
) {
313 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
314 schedule_work(&rdev
->conn_work
);
318 bool cfg80211_sme_failed_reassoc(struct wireless_dev
*wdev
)
320 struct wiphy
*wiphy
= wdev
->wiphy
;
321 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
323 if (WARN_ON(!wdev
->conn
))
326 if (!wdev
->conn
->prev_bssid_valid
)
330 * Some stupid APs don't accept reassoc, so we
331 * need to fall back to trying regular assoc.
333 wdev
->conn
->prev_bssid_valid
= false;
334 wdev
->conn
->state
= CFG80211_CONN_ASSOCIATE_NEXT
;
335 schedule_work(&rdev
->conn_work
);
340 void __cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
341 const u8
*req_ie
, size_t req_ie_len
,
342 const u8
*resp_ie
, size_t resp_ie_len
,
343 u16 status
, bool wextev
,
344 struct cfg80211_bss
*bss
)
346 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
348 #ifdef CONFIG_CFG80211_WEXT
349 union iwreq_data wrqu
;
352 ASSERT_WDEV_LOCK(wdev
);
354 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
357 if (wdev
->sme_state
!= CFG80211_SME_CONNECTING
)
360 nl80211_send_connect_result(wiphy_to_dev(wdev
->wiphy
), dev
,
361 bssid
, req_ie
, req_ie_len
,
362 resp_ie
, resp_ie_len
,
365 #ifdef CONFIG_CFG80211_WEXT
367 if (req_ie
&& status
== WLAN_STATUS_SUCCESS
) {
368 memset(&wrqu
, 0, sizeof(wrqu
));
369 wrqu
.data
.length
= req_ie_len
;
370 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, req_ie
);
373 if (resp_ie
&& status
== WLAN_STATUS_SUCCESS
) {
374 memset(&wrqu
, 0, sizeof(wrqu
));
375 wrqu
.data
.length
= resp_ie_len
;
376 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, resp_ie
);
379 memset(&wrqu
, 0, sizeof(wrqu
));
380 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
381 if (bssid
&& status
== WLAN_STATUS_SUCCESS
) {
382 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
383 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
384 wdev
->wext
.prev_bssid_valid
= true;
386 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
390 if (wdev
->current_bss
) {
391 cfg80211_unhold_bss(wdev
->current_bss
);
392 cfg80211_put_bss(&wdev
->current_bss
->pub
);
393 wdev
->current_bss
= NULL
;
397 wdev
->conn
->state
= CFG80211_CONN_IDLE
;
399 if (status
!= WLAN_STATUS_SUCCESS
) {
400 wdev
->sme_state
= CFG80211_SME_IDLE
;
402 kfree(wdev
->conn
->ie
);
405 kfree(wdev
->connect_keys
);
406 wdev
->connect_keys
= NULL
;
412 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, bssid
,
413 wdev
->ssid
, wdev
->ssid_len
,
415 WLAN_CAPABILITY_ESS
);
420 cfg80211_hold_bss(bss_from_pub(bss
));
421 wdev
->current_bss
= bss_from_pub(bss
);
423 wdev
->sme_state
= CFG80211_SME_CONNECTED
;
424 cfg80211_upload_connect_keys(wdev
);
426 country_ie
= (u8
*) ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
432 * ieee80211_bss_get_ie() ensures we can access:
433 * - country_ie + 2, the start of the country ie data, and
434 * - and country_ie[1] which is the IE length
436 regulatory_hint_11d(wdev
->wiphy
,
441 void cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
442 const u8
*req_ie
, size_t req_ie_len
,
443 const u8
*resp_ie
, size_t resp_ie_len
,
444 u16 status
, gfp_t gfp
)
446 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
447 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
448 struct cfg80211_event
*ev
;
451 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTING
);
453 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
457 ev
->type
= EVENT_CONNECT_RESULT
;
459 memcpy(ev
->cr
.bssid
, bssid
, ETH_ALEN
);
460 ev
->cr
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
461 ev
->cr
.req_ie_len
= req_ie_len
;
462 memcpy((void *)ev
->cr
.req_ie
, req_ie
, req_ie_len
);
463 ev
->cr
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
464 ev
->cr
.resp_ie_len
= resp_ie_len
;
465 memcpy((void *)ev
->cr
.resp_ie
, resp_ie
, resp_ie_len
);
466 ev
->cr
.status
= status
;
468 spin_lock_irqsave(&wdev
->event_lock
, flags
);
469 list_add_tail(&ev
->list
, &wdev
->event_list
);
470 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
471 schedule_work(&rdev
->event_work
);
473 EXPORT_SYMBOL(cfg80211_connect_result
);
475 void __cfg80211_roamed(struct wireless_dev
*wdev
, const u8
*bssid
,
476 const u8
*req_ie
, size_t req_ie_len
,
477 const u8
*resp_ie
, size_t resp_ie_len
)
479 struct cfg80211_bss
*bss
;
480 #ifdef CONFIG_CFG80211_WEXT
481 union iwreq_data wrqu
;
484 ASSERT_WDEV_LOCK(wdev
);
486 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
489 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
492 /* internal error -- how did we get to CONNECTED w/o BSS? */
493 if (WARN_ON(!wdev
->current_bss
)) {
497 cfg80211_unhold_bss(wdev
->current_bss
);
498 cfg80211_put_bss(&wdev
->current_bss
->pub
);
499 wdev
->current_bss
= NULL
;
501 bss
= cfg80211_get_bss(wdev
->wiphy
, NULL
, bssid
,
502 wdev
->ssid
, wdev
->ssid_len
,
503 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
508 cfg80211_hold_bss(bss_from_pub(bss
));
509 wdev
->current_bss
= bss_from_pub(bss
);
511 nl80211_send_roamed(wiphy_to_dev(wdev
->wiphy
), wdev
->netdev
, bssid
,
512 req_ie
, req_ie_len
, resp_ie
, resp_ie_len
,
515 #ifdef CONFIG_CFG80211_WEXT
517 memset(&wrqu
, 0, sizeof(wrqu
));
518 wrqu
.data
.length
= req_ie_len
;
519 wireless_send_event(wdev
->netdev
, IWEVASSOCREQIE
,
524 memset(&wrqu
, 0, sizeof(wrqu
));
525 wrqu
.data
.length
= resp_ie_len
;
526 wireless_send_event(wdev
->netdev
, IWEVASSOCRESPIE
,
530 memset(&wrqu
, 0, sizeof(wrqu
));
531 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
532 memcpy(wrqu
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
533 memcpy(wdev
->wext
.prev_bssid
, bssid
, ETH_ALEN
);
534 wdev
->wext
.prev_bssid_valid
= true;
535 wireless_send_event(wdev
->netdev
, SIOCGIWAP
, &wrqu
, NULL
);
539 void cfg80211_roamed(struct net_device
*dev
, const u8
*bssid
,
540 const u8
*req_ie
, size_t req_ie_len
,
541 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
543 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
544 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
545 struct cfg80211_event
*ev
;
548 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
550 ev
= kzalloc(sizeof(*ev
) + req_ie_len
+ resp_ie_len
, gfp
);
554 ev
->type
= EVENT_ROAMED
;
555 memcpy(ev
->rm
.bssid
, bssid
, ETH_ALEN
);
556 ev
->rm
.req_ie
= ((u8
*)ev
) + sizeof(*ev
);
557 ev
->rm
.req_ie_len
= req_ie_len
;
558 memcpy((void *)ev
->rm
.req_ie
, req_ie
, req_ie_len
);
559 ev
->rm
.resp_ie
= ((u8
*)ev
) + sizeof(*ev
) + req_ie_len
;
560 ev
->rm
.resp_ie_len
= resp_ie_len
;
561 memcpy((void *)ev
->rm
.resp_ie
, resp_ie
, resp_ie_len
);
563 spin_lock_irqsave(&wdev
->event_lock
, flags
);
564 list_add_tail(&ev
->list
, &wdev
->event_list
);
565 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
566 schedule_work(&rdev
->event_work
);
568 EXPORT_SYMBOL(cfg80211_roamed
);
570 void __cfg80211_disconnected(struct net_device
*dev
, const u8
*ie
,
571 size_t ie_len
, u16 reason
, bool from_ap
)
573 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
574 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
576 #ifdef CONFIG_CFG80211_WEXT
577 union iwreq_data wrqu
;
580 ASSERT_WDEV_LOCK(wdev
);
582 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_STATION
))
585 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
588 if (wdev
->current_bss
) {
589 cfg80211_unhold_bss(wdev
->current_bss
);
590 cfg80211_put_bss(&wdev
->current_bss
->pub
);
593 wdev
->current_bss
= NULL
;
594 wdev
->sme_state
= CFG80211_SME_IDLE
;
601 kfree(wdev
->conn
->ie
);
602 wdev
->conn
->ie
= NULL
;
607 * If this disconnect was due to a disassoc, we
608 * we might still have an auth BSS around. For
609 * the userspace SME that's currently expected,
610 * but for the kernel SME (nl80211 CONNECT or
611 * wireless extensions) we want to clear up all
614 for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
615 if (!wdev
->auth_bsses
[i
])
617 bssid
= wdev
->auth_bsses
[i
]->pub
.bssid
;
618 ret
= __cfg80211_mlme_deauth(rdev
, dev
, bssid
, NULL
, 0,
619 WLAN_REASON_DEAUTH_LEAVING
);
620 WARN(ret
, "deauth failed: %d\n", ret
);
624 nl80211_send_disconnected(rdev
, dev
, reason
, ie
, ie_len
, from_ap
);
627 * Delete all the keys ... pairwise keys can't really
628 * exist any more anyway, but default keys might.
630 if (rdev
->ops
->del_key
)
631 for (i
= 0; i
< 6; i
++)
632 rdev
->ops
->del_key(wdev
->wiphy
, dev
, i
, NULL
);
634 #ifdef CONFIG_CFG80211_WEXT
635 memset(&wrqu
, 0, sizeof(wrqu
));
636 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
637 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
641 void cfg80211_disconnected(struct net_device
*dev
, u16 reason
,
642 u8
*ie
, size_t ie_len
, gfp_t gfp
)
644 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
645 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
646 struct cfg80211_event
*ev
;
649 CFG80211_DEV_WARN_ON(wdev
->sme_state
!= CFG80211_SME_CONNECTED
);
651 ev
= kzalloc(sizeof(*ev
) + ie_len
, gfp
);
655 ev
->type
= EVENT_DISCONNECTED
;
656 ev
->dc
.ie
= ((u8
*)ev
) + sizeof(*ev
);
657 ev
->dc
.ie_len
= ie_len
;
658 memcpy((void *)ev
->dc
.ie
, ie
, ie_len
);
659 ev
->dc
.reason
= reason
;
661 spin_lock_irqsave(&wdev
->event_lock
, flags
);
662 list_add_tail(&ev
->list
, &wdev
->event_list
);
663 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
664 schedule_work(&rdev
->event_work
);
666 EXPORT_SYMBOL(cfg80211_disconnected
);
668 int __cfg80211_connect(struct cfg80211_registered_device
*rdev
,
669 struct net_device
*dev
,
670 struct cfg80211_connect_params
*connect
,
671 struct cfg80211_cached_keys
*connkeys
,
672 const u8
*prev_bssid
)
674 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
675 struct ieee80211_channel
*chan
;
676 struct cfg80211_bss
*bss
= NULL
;
679 ASSERT_WDEV_LOCK(wdev
);
681 if (wdev
->sme_state
!= CFG80211_SME_IDLE
)
684 chan
= rdev_fixed_channel(rdev
, wdev
);
685 if (chan
&& chan
!= connect
->channel
)
688 if (WARN_ON(wdev
->connect_keys
)) {
689 kfree(wdev
->connect_keys
);
690 wdev
->connect_keys
= NULL
;
693 if (connkeys
&& connkeys
->def
>= 0) {
698 cipher
= connkeys
->params
[idx
].cipher
;
699 /* If given a WEP key we may need it for shared key auth */
700 if (cipher
== WLAN_CIPHER_SUITE_WEP40
||
701 cipher
== WLAN_CIPHER_SUITE_WEP104
) {
702 connect
->key_idx
= idx
;
703 connect
->key
= connkeys
->params
[idx
].key
;
704 connect
->key_len
= connkeys
->params
[idx
].key_len
;
707 * If ciphers are not set (e.g. when going through
708 * iwconfig), we have to set them appropriately here.
710 if (connect
->crypto
.cipher_group
== 0)
711 connect
->crypto
.cipher_group
= cipher
;
713 if (connect
->crypto
.n_ciphers_pairwise
== 0) {
714 connect
->crypto
.n_ciphers_pairwise
= 1;
715 connect
->crypto
.ciphers_pairwise
[0] = cipher
;
720 if (!rdev
->ops
->connect
) {
721 if (!rdev
->ops
->auth
|| !rdev
->ops
->assoc
)
724 if (WARN_ON(wdev
->conn
))
727 wdev
->conn
= kzalloc(sizeof(*wdev
->conn
), GFP_KERNEL
);
732 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
734 memcpy(&wdev
->conn
->params
, connect
, sizeof(*connect
));
735 if (connect
->bssid
) {
736 wdev
->conn
->params
.bssid
= wdev
->conn
->bssid
;
737 memcpy(wdev
->conn
->bssid
, connect
->bssid
, ETH_ALEN
);
741 wdev
->conn
->ie
= kmemdup(connect
->ie
, connect
->ie_len
,
743 wdev
->conn
->params
.ie
= wdev
->conn
->ie
;
744 if (!wdev
->conn
->ie
) {
751 if (connect
->auth_type
== NL80211_AUTHTYPE_AUTOMATIC
) {
752 wdev
->conn
->auto_auth
= true;
753 /* start with open system ... should mostly work */
754 wdev
->conn
->params
.auth_type
=
755 NL80211_AUTHTYPE_OPEN_SYSTEM
;
757 wdev
->conn
->auto_auth
= false;
760 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
761 wdev
->ssid_len
= connect
->ssid_len
;
762 wdev
->conn
->params
.ssid
= wdev
->ssid
;
763 wdev
->conn
->params
.ssid_len
= connect
->ssid_len
;
765 /* see if we have the bss already */
766 bss
= cfg80211_get_conn_bss(wdev
);
768 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
769 wdev
->connect_keys
= connkeys
;
772 memcpy(wdev
->conn
->prev_bssid
, prev_bssid
, ETH_ALEN
);
773 wdev
->conn
->prev_bssid_valid
= true;
776 /* we're good if we have a matching bss struct */
778 wdev
->conn
->state
= CFG80211_CONN_AUTHENTICATE_NEXT
;
779 err
= cfg80211_conn_do_work(wdev
);
780 cfg80211_put_bss(bss
);
782 /* otherwise we'll need to scan for the AP first */
783 err
= cfg80211_conn_scan(wdev
);
785 * If we can't scan right now, then we need to scan again
786 * after the current scan finished, since the parameters
787 * changed (unless we find a good AP anyway).
791 wdev
->conn
->state
= CFG80211_CONN_SCAN_AGAIN
;
795 kfree(wdev
->conn
->ie
);
798 wdev
->sme_state
= CFG80211_SME_IDLE
;
799 wdev
->connect_keys
= NULL
;
805 wdev
->sme_state
= CFG80211_SME_CONNECTING
;
806 wdev
->connect_keys
= connkeys
;
807 err
= rdev
->ops
->connect(&rdev
->wiphy
, dev
, connect
);
809 wdev
->connect_keys
= NULL
;
810 wdev
->sme_state
= CFG80211_SME_IDLE
;
814 memcpy(wdev
->ssid
, connect
->ssid
, connect
->ssid_len
);
815 wdev
->ssid_len
= connect
->ssid_len
;
821 int cfg80211_connect(struct cfg80211_registered_device
*rdev
,
822 struct net_device
*dev
,
823 struct cfg80211_connect_params
*connect
,
824 struct cfg80211_cached_keys
*connkeys
)
828 mutex_lock(&rdev
->devlist_mtx
);
829 wdev_lock(dev
->ieee80211_ptr
);
830 err
= __cfg80211_connect(rdev
, dev
, connect
, connkeys
, NULL
);
831 wdev_unlock(dev
->ieee80211_ptr
);
832 mutex_unlock(&rdev
->devlist_mtx
);
837 int __cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
838 struct net_device
*dev
, u16 reason
, bool wextev
)
840 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
843 ASSERT_WDEV_LOCK(wdev
);
845 if (wdev
->sme_state
== CFG80211_SME_IDLE
)
848 kfree(wdev
->connect_keys
);
849 wdev
->connect_keys
= NULL
;
851 if (!rdev
->ops
->disconnect
) {
852 if (!rdev
->ops
->deauth
)
855 /* was it connected by userspace SME? */
857 cfg80211_mlme_down(rdev
, dev
);
861 if (wdev
->sme_state
== CFG80211_SME_CONNECTING
&&
862 (wdev
->conn
->state
== CFG80211_CONN_SCANNING
||
863 wdev
->conn
->state
== CFG80211_CONN_SCAN_AGAIN
)) {
864 wdev
->sme_state
= CFG80211_SME_IDLE
;
865 kfree(wdev
->conn
->ie
);
872 /* wdev->conn->params.bssid must be set if > SCANNING */
873 err
= __cfg80211_mlme_deauth(rdev
, dev
,
874 wdev
->conn
->params
.bssid
,
879 err
= rdev
->ops
->disconnect(&rdev
->wiphy
, dev
, reason
);
884 if (wdev
->sme_state
== CFG80211_SME_CONNECTED
)
885 __cfg80211_disconnected(dev
, NULL
, 0, 0, false);
886 else if (wdev
->sme_state
== CFG80211_SME_CONNECTING
)
887 __cfg80211_connect_result(dev
, NULL
, NULL
, 0, NULL
, 0,
888 WLAN_STATUS_UNSPECIFIED_FAILURE
,
894 int cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
895 struct net_device
*dev
,
896 u16 reason
, bool wextev
)
900 wdev_lock(dev
->ieee80211_ptr
);
901 err
= __cfg80211_disconnect(rdev
, dev
, reason
, wextev
);
902 wdev_unlock(dev
->ieee80211_ptr
);
907 void cfg80211_sme_disassoc(struct net_device
*dev
, int idx
)
909 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
910 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
913 ASSERT_WDEV_LOCK(wdev
);
918 if (wdev
->conn
->state
== CFG80211_CONN_IDLE
)
922 * Ok, so the association was made by this SME -- we don't
923 * want it any more so deauthenticate too.
926 if (!wdev
->auth_bsses
[idx
])
929 memcpy(bssid
, wdev
->auth_bsses
[idx
]->pub
.bssid
, ETH_ALEN
);
930 if (__cfg80211_mlme_deauth(rdev
, dev
, bssid
,
931 NULL
, 0, WLAN_REASON_DEAUTH_LEAVING
)) {
932 /* whatever -- assume gone anyway */
933 cfg80211_unhold_bss(wdev
->auth_bsses
[idx
]);
934 cfg80211_put_bss(&wdev
->auth_bsses
[idx
]->pub
);
935 wdev
->auth_bsses
[idx
] = NULL
;