blob: 219c3bc2c37d3c1a3bf88a0b5aae1b11751d2602 [file] [log] [blame]
Samuel Ortizb23aa672009-07-01 21:26:54 +02001/*
2 * SME code for cfg80211's connect emulation.
3 *
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 */
7
8#include <linux/etherdevice.h>
9#include <linux/if_arp.h>
10#include <linux/workqueue.h>
Johannes Berga9a11622009-07-27 12:01:53 +020011#include <linux/wireless.h>
12#include <net/iw_handler.h>
Samuel Ortizb23aa672009-07-01 21:26:54 +020013#include <net/cfg80211.h>
14#include <net/rtnetlink.h>
15#include "nl80211.h"
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -070016#include "reg.h"
Samuel Ortizb23aa672009-07-01 21:26:54 +020017
Johannes Berg6829c872009-07-02 09:13:27 +020018struct cfg80211_conn {
19 struct cfg80211_connect_params params;
20 /* these are sub-states of the _CONNECTING sme_state */
21 enum {
22 CFG80211_CONN_IDLE,
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,
29 } state;
30 u8 bssid[ETH_ALEN];
31 u8 *ie;
32 size_t ie_len;
33 bool auto_auth;
34};
35
36
37static int cfg80211_conn_scan(struct wireless_dev *wdev)
38{
Johannes Berg79c97e92009-07-07 03:56:12 +020039 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020040 struct cfg80211_scan_request *request;
41 int n_channels, err;
42
43 ASSERT_RTNL();
Johannes Berg79c97e92009-07-07 03:56:12 +020044 ASSERT_RDEV_LOCK(rdev);
Johannes Berg667503d2009-07-07 03:56:11 +020045 ASSERT_WDEV_LOCK(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +020046
Johannes Berg79c97e92009-07-07 03:56:12 +020047 if (rdev->scan_req)
Johannes Berg6829c872009-07-02 09:13:27 +020048 return -EBUSY;
49
50 if (wdev->conn->params.channel) {
51 n_channels = 1;
52 } else {
53 enum ieee80211_band band;
54 n_channels = 0;
55
56 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
57 if (!wdev->wiphy->bands[band])
58 continue;
59 n_channels += wdev->wiphy->bands[band]->n_channels;
60 }
61 }
62 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
63 sizeof(request->channels[0]) * n_channels,
64 GFP_KERNEL);
65 if (!request)
66 return -ENOMEM;
67
68 request->channels = (void *)((char *)request + sizeof(*request));
69 if (wdev->conn->params.channel)
70 request->channels[0] = wdev->conn->params.channel;
71 else {
72 int i = 0, j;
73 enum ieee80211_band band;
74
75 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
76 if (!wdev->wiphy->bands[band])
77 continue;
78 for (j = 0; j < wdev->wiphy->bands[band]->n_channels;
79 i++, j++)
80 request->channels[i] =
81 &wdev->wiphy->bands[band]->channels[j];
82 }
83 }
84 request->n_channels = n_channels;
85 request->ssids = (void *)(request->channels + n_channels);
86 request->n_ssids = 1;
87
88 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
89 wdev->conn->params.ssid_len);
90 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
91
Johannes Berg463d0182009-07-14 00:33:35 +020092 request->dev = wdev->netdev;
Johannes Berg79c97e92009-07-07 03:56:12 +020093 request->wiphy = &rdev->wiphy;
Johannes Berg6829c872009-07-02 09:13:27 +020094
Johannes Berg79c97e92009-07-07 03:56:12 +020095 rdev->scan_req = request;
Johannes Berg6829c872009-07-02 09:13:27 +020096
Johannes Berg79c97e92009-07-07 03:56:12 +020097 err = rdev->ops->scan(wdev->wiphy, wdev->netdev, request);
Johannes Berg6829c872009-07-02 09:13:27 +020098 if (!err) {
99 wdev->conn->state = CFG80211_CONN_SCANNING;
Johannes Berg79c97e92009-07-07 03:56:12 +0200100 nl80211_send_scan_start(rdev, wdev->netdev);
Johannes Berg463d0182009-07-14 00:33:35 +0200101 dev_hold(wdev->netdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200102 } else {
Johannes Berg79c97e92009-07-07 03:56:12 +0200103 rdev->scan_req = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200104 kfree(request);
105 }
106 return err;
107}
108
109static int cfg80211_conn_do_work(struct wireless_dev *wdev)
110{
Johannes Berg79c97e92009-07-07 03:56:12 +0200111 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200112 struct cfg80211_connect_params *params;
113 int err;
Johannes Berg6829c872009-07-02 09:13:27 +0200114
Johannes Berg667503d2009-07-07 03:56:11 +0200115 ASSERT_WDEV_LOCK(wdev);
116
Johannes Berg6829c872009-07-02 09:13:27 +0200117 if (!wdev->conn)
118 return 0;
119
Johannes Berg19957bb2009-07-02 17:20:43 +0200120 params = &wdev->conn->params;
121
Johannes Berg6829c872009-07-02 09:13:27 +0200122 switch (wdev->conn->state) {
123 case CFG80211_CONN_SCAN_AGAIN:
124 return cfg80211_conn_scan(wdev);
125 case CFG80211_CONN_AUTHENTICATE_NEXT:
Johannes Berg79c97e92009-07-07 03:56:12 +0200126 BUG_ON(!rdev->ops->auth);
Johannes Berg19957bb2009-07-02 17:20:43 +0200127 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
Johannes Berg79c97e92009-07-07 03:56:12 +0200128 return __cfg80211_mlme_auth(rdev, wdev->netdev,
Johannes Berg667503d2009-07-07 03:56:11 +0200129 params->channel, params->auth_type,
130 params->bssid,
131 params->ssid, params->ssid_len,
Johannes Bergfffd0932009-07-08 14:22:54 +0200132 NULL, 0,
133 params->key, params->key_len,
134 params->key_idx);
Johannes Berg6829c872009-07-02 09:13:27 +0200135 case CFG80211_CONN_ASSOCIATE_NEXT:
Johannes Berg79c97e92009-07-07 03:56:12 +0200136 BUG_ON(!rdev->ops->assoc);
Johannes Berg19957bb2009-07-02 17:20:43 +0200137 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
Johannes Berg3e5d7642009-07-07 14:37:26 +0200138 /*
139 * We could, later, implement roaming here and then actually
140 * set prev_bssid to non-NULL. But then we need to be aware
141 * that some APs don't like that -- so we'd need to retry
142 * the association.
143 */
Johannes Berg79c97e92009-07-07 03:56:12 +0200144 err = __cfg80211_mlme_assoc(rdev, wdev->netdev,
Johannes Berg667503d2009-07-07 03:56:11 +0200145 params->channel, params->bssid,
146 NULL,
147 params->ssid, params->ssid_len,
148 params->ie, params->ie_len,
149 false, &params->crypto);
Johannes Berg19957bb2009-07-02 17:20:43 +0200150 if (err)
Johannes Berg79c97e92009-07-07 03:56:12 +0200151 __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +0200152 NULL, 0,
153 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg19957bb2009-07-02 17:20:43 +0200154 return err;
Johannes Berg6829c872009-07-02 09:13:27 +0200155 default:
156 return 0;
157 }
158}
159
160void cfg80211_conn_work(struct work_struct *work)
161{
Johannes Berg79c97e92009-07-07 03:56:12 +0200162 struct cfg80211_registered_device *rdev =
Johannes Berg6829c872009-07-02 09:13:27 +0200163 container_of(work, struct cfg80211_registered_device, conn_work);
164 struct wireless_dev *wdev;
165
166 rtnl_lock();
Johannes Berg79c97e92009-07-07 03:56:12 +0200167 cfg80211_lock_rdev(rdev);
168 mutex_lock(&rdev->devlist_mtx);
Johannes Berg6829c872009-07-02 09:13:27 +0200169
Johannes Berg79c97e92009-07-07 03:56:12 +0200170 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Berg667503d2009-07-07 03:56:11 +0200171 wdev_lock(wdev);
172 if (!netif_running(wdev->netdev)) {
173 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200174 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200175 }
176 if (wdev->sme_state != CFG80211_SME_CONNECTING) {
177 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200178 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200179 }
Johannes Berg6829c872009-07-02 09:13:27 +0200180 if (cfg80211_conn_do_work(wdev))
Johannes Berg667503d2009-07-07 03:56:11 +0200181 __cfg80211_connect_result(
182 wdev->netdev,
183 wdev->conn->params.bssid,
184 NULL, 0, NULL, 0,
185 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200186 false, NULL);
Johannes Berg667503d2009-07-07 03:56:11 +0200187 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200188 }
189
Johannes Berg79c97e92009-07-07 03:56:12 +0200190 mutex_unlock(&rdev->devlist_mtx);
191 cfg80211_unlock_rdev(rdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200192 rtnl_unlock();
193}
194
195static bool cfg80211_get_conn_bss(struct wireless_dev *wdev)
196{
Johannes Berg79c97e92009-07-07 03:56:12 +0200197 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200198 struct cfg80211_bss *bss;
199 u16 capa = WLAN_CAPABILITY_ESS;
200
Johannes Berg667503d2009-07-07 03:56:11 +0200201 ASSERT_WDEV_LOCK(wdev);
202
Johannes Berg6829c872009-07-02 09:13:27 +0200203 if (wdev->conn->params.privacy)
204 capa |= WLAN_CAPABILITY_PRIVACY;
205
206 bss = cfg80211_get_bss(wdev->wiphy, NULL, wdev->conn->params.bssid,
207 wdev->conn->params.ssid,
208 wdev->conn->params.ssid_len,
209 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
210 capa);
Johannes Berg6829c872009-07-02 09:13:27 +0200211 if (!bss)
212 return false;
213
214 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
215 wdev->conn->params.bssid = wdev->conn->bssid;
216 wdev->conn->params.channel = bss->channel;
217 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
Johannes Berg79c97e92009-07-07 03:56:12 +0200218 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200219
220 cfg80211_put_bss(bss);
221 return true;
222}
223
Johannes Berg667503d2009-07-07 03:56:11 +0200224static void __cfg80211_sme_scan_done(struct net_device *dev)
Johannes Berg6829c872009-07-02 09:13:27 +0200225{
226 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg79c97e92009-07-07 03:56:12 +0200227 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200228
Johannes Berg667503d2009-07-07 03:56:11 +0200229 ASSERT_WDEV_LOCK(wdev);
230
Johannes Berg6829c872009-07-02 09:13:27 +0200231 if (wdev->sme_state != CFG80211_SME_CONNECTING)
232 return;
233
Zhu Yid4b1a682009-07-16 17:34:14 +0800234 if (!wdev->conn)
Johannes Berg6829c872009-07-02 09:13:27 +0200235 return;
236
237 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
238 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
239 return;
240
241 if (!cfg80211_get_conn_bss(wdev)) {
242 /* not found */
243 if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)
Johannes Berg79c97e92009-07-07 03:56:12 +0200244 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200245 else
Johannes Berg667503d2009-07-07 03:56:11 +0200246 __cfg80211_connect_result(
247 wdev->netdev,
248 wdev->conn->params.bssid,
249 NULL, 0, NULL, 0,
250 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200251 false, NULL);
Johannes Berg6829c872009-07-02 09:13:27 +0200252 }
253}
254
Johannes Berg667503d2009-07-07 03:56:11 +0200255void cfg80211_sme_scan_done(struct net_device *dev)
256{
257 struct wireless_dev *wdev = dev->ieee80211_ptr;
258
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200259 mutex_lock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx);
Johannes Berg667503d2009-07-07 03:56:11 +0200260 wdev_lock(wdev);
261 __cfg80211_sme_scan_done(dev);
262 wdev_unlock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200263 mutex_unlock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx);
Johannes Berg667503d2009-07-07 03:56:11 +0200264}
265
266void cfg80211_sme_rx_auth(struct net_device *dev,
267 const u8 *buf, size_t len)
Johannes Berg6829c872009-07-02 09:13:27 +0200268{
269 struct wireless_dev *wdev = dev->ieee80211_ptr;
270 struct wiphy *wiphy = wdev->wiphy;
271 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
272 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
273 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
274
Johannes Berg667503d2009-07-07 03:56:11 +0200275 ASSERT_WDEV_LOCK(wdev);
276
Johannes Berg6829c872009-07-02 09:13:27 +0200277 /* should only RX auth frames when connecting */
278 if (wdev->sme_state != CFG80211_SME_CONNECTING)
279 return;
280
281 if (WARN_ON(!wdev->conn))
282 return;
283
284 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
285 wdev->conn->auto_auth &&
286 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
287 /* select automatically between only open, shared, leap */
288 switch (wdev->conn->params.auth_type) {
289 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Johannes Bergfffd0932009-07-08 14:22:54 +0200290 if (wdev->connect_keys)
291 wdev->conn->params.auth_type =
292 NL80211_AUTHTYPE_SHARED_KEY;
293 else
294 wdev->conn->params.auth_type =
295 NL80211_AUTHTYPE_NETWORK_EAP;
Johannes Berg6829c872009-07-02 09:13:27 +0200296 break;
297 case NL80211_AUTHTYPE_SHARED_KEY:
298 wdev->conn->params.auth_type =
299 NL80211_AUTHTYPE_NETWORK_EAP;
300 break;
301 default:
302 /* huh? */
303 wdev->conn->params.auth_type =
304 NL80211_AUTHTYPE_OPEN_SYSTEM;
305 break;
306 }
307 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
308 schedule_work(&rdev->conn_work);
Johannes Berg19957bb2009-07-02 17:20:43 +0200309 } else if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Berg4bde0f72009-07-07 23:46:51 +0200310 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200311 status_code, false, NULL);
Johannes Berg19957bb2009-07-02 17:20:43 +0200312 } else if (wdev->sme_state == CFG80211_SME_CONNECTING &&
Johannes Berg6829c872009-07-02 09:13:27 +0200313 wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
314 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
315 schedule_work(&rdev->conn_work);
316 }
317}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200318
Johannes Berg667503d2009-07-07 03:56:11 +0200319void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
320 const u8 *req_ie, size_t req_ie_len,
321 const u8 *resp_ie, size_t resp_ie_len,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200322 u16 status, bool wextev,
323 struct cfg80211_bss *bss)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200324{
325 struct wireless_dev *wdev = dev->ieee80211_ptr;
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700326 u8 *country_ie;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200327#ifdef CONFIG_WIRELESS_EXT
328 union iwreq_data wrqu;
329#endif
330
Johannes Berg667503d2009-07-07 03:56:11 +0200331 ASSERT_WDEV_LOCK(wdev);
332
Samuel Ortizb23aa672009-07-01 21:26:54 +0200333 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
334 return;
335
Johannes Berge45cd822009-07-02 09:58:04 +0200336 if (wdev->sme_state == CFG80211_SME_CONNECTED)
337 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), dev,
338 bssid, req_ie, req_ie_len,
Johannes Berg667503d2009-07-07 03:56:11 +0200339 resp_ie, resp_ie_len, GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200340 else
341 nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev,
342 bssid, req_ie, req_ie_len,
343 resp_ie, resp_ie_len,
Johannes Berg667503d2009-07-07 03:56:11 +0200344 status, GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200345
346#ifdef CONFIG_WIRELESS_EXT
347 if (wextev) {
348 if (req_ie && status == WLAN_STATUS_SUCCESS) {
349 memset(&wrqu, 0, sizeof(wrqu));
350 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800351 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200352 }
353
354 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
355 memset(&wrqu, 0, sizeof(wrqu));
356 wrqu.data.length = resp_ie_len;
357 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
358 }
359
360 memset(&wrqu, 0, sizeof(wrqu));
361 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
362 if (bssid && status == WLAN_STATUS_SUCCESS)
363 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
364 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
365 }
366#endif
367
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200368 if (wdev->current_bss) {
369 cfg80211_unhold_bss(wdev->current_bss);
370 cfg80211_put_bss(&wdev->current_bss->pub);
371 wdev->current_bss = NULL;
372 }
373
Johannes Berge45cd822009-07-02 09:58:04 +0200374 if (status == WLAN_STATUS_SUCCESS &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200375 wdev->sme_state == CFG80211_SME_IDLE)
376 goto success;
Johannes Berge45cd822009-07-02 09:58:04 +0200377
Johannes Berg6829c872009-07-02 09:13:27 +0200378 if (wdev->sme_state != CFG80211_SME_CONNECTING)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200379 return;
380
Johannes Berg19957bb2009-07-02 17:20:43 +0200381 if (wdev->conn)
382 wdev->conn->state = CFG80211_CONN_IDLE;
383
Johannes Bergfffd0932009-07-08 14:22:54 +0200384 if (status != WLAN_STATUS_SUCCESS) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200385 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg19957bb2009-07-02 17:20:43 +0200386 kfree(wdev->conn);
387 wdev->conn = NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200388 kfree(wdev->connect_keys);
389 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200390 wdev->ssid_len = 0;
Johannes Bergfffd0932009-07-08 14:22:54 +0200391 return;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200392 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200393
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200394 success:
395 if (!bss)
396 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
397 wdev->ssid, wdev->ssid_len,
398 WLAN_CAPABILITY_ESS,
399 WLAN_CAPABILITY_ESS);
Johannes Bergfffd0932009-07-08 14:22:54 +0200400
401 if (WARN_ON(!bss))
402 return;
403
404 cfg80211_hold_bss(bss_from_pub(bss));
405 wdev->current_bss = bss_from_pub(bss);
406
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 wdev->sme_state = CFG80211_SME_CONNECTED;
408 cfg80211_upload_connect_keys(wdev);
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700409
410 country_ie = (u8 *) ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
411
412 if (!country_ie)
413 return;
414
415 /*
416 * ieee80211_bss_get_ie() ensures we can access:
417 * - country_ie + 2, the start of the country ie data, and
418 * - and country_ie[1] which is the IE length
419 */
420 regulatory_hint_11d(wdev->wiphy,
421 country_ie + 2,
422 country_ie[1]);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200423}
Johannes Bergf2129352009-07-01 21:26:56 +0200424
425void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
426 const u8 *req_ie, size_t req_ie_len,
427 const u8 *resp_ie, size_t resp_ie_len,
428 u16 status, gfp_t gfp)
429{
Johannes Berg667503d2009-07-07 03:56:11 +0200430 struct wireless_dev *wdev = dev->ieee80211_ptr;
431 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
432 struct cfg80211_event *ev;
433 unsigned long flags;
434
435 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
436 if (!ev)
437 return;
438
439 ev->type = EVENT_CONNECT_RESULT;
440 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
441 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
442 ev->cr.req_ie_len = req_ie_len;
443 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
444 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
445 ev->cr.resp_ie_len = resp_ie_len;
446 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
447 ev->cr.status = status;
448
449 spin_lock_irqsave(&wdev->event_lock, flags);
450 list_add_tail(&ev->list, &wdev->event_list);
451 spin_unlock_irqrestore(&wdev->event_lock, flags);
452 schedule_work(&rdev->event_work);
Johannes Bergf2129352009-07-01 21:26:56 +0200453}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200454EXPORT_SYMBOL(cfg80211_connect_result);
455
Johannes Berg667503d2009-07-07 03:56:11 +0200456void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
457 const u8 *req_ie, size_t req_ie_len,
458 const u8 *resp_ie, size_t resp_ie_len)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200459{
Samuel Ortizb23aa672009-07-01 21:26:54 +0200460 struct cfg80211_bss *bss;
461#ifdef CONFIG_WIRELESS_EXT
462 union iwreq_data wrqu;
463#endif
464
Johannes Berg667503d2009-07-07 03:56:11 +0200465 ASSERT_WDEV_LOCK(wdev);
466
Samuel Ortizb23aa672009-07-01 21:26:54 +0200467 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
468 return;
469
470 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
471 return;
472
473 /* internal error -- how did we get to CONNECTED w/o BSS? */
474 if (WARN_ON(!wdev->current_bss)) {
475 return;
476 }
477
478 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200479 cfg80211_put_bss(&wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200480 wdev->current_bss = NULL;
481
482 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
483 wdev->ssid, wdev->ssid_len,
484 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
485
486 if (WARN_ON(!bss))
487 return;
488
Johannes Berg19957bb2009-07-02 17:20:43 +0200489 cfg80211_hold_bss(bss_from_pub(bss));
490 wdev->current_bss = bss_from_pub(bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200491
Johannes Berg667503d2009-07-07 03:56:11 +0200492 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid,
493 req_ie, req_ie_len, resp_ie, resp_ie_len,
494 GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200495
496#ifdef CONFIG_WIRELESS_EXT
497 if (req_ie) {
498 memset(&wrqu, 0, sizeof(wrqu));
499 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800500 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
Johannes Berg667503d2009-07-07 03:56:11 +0200501 &wrqu, req_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200502 }
503
504 if (resp_ie) {
505 memset(&wrqu, 0, sizeof(wrqu));
506 wrqu.data.length = resp_ie_len;
Johannes Berg667503d2009-07-07 03:56:11 +0200507 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
508 &wrqu, resp_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200509 }
510
511 memset(&wrqu, 0, sizeof(wrqu));
512 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
513 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
Johannes Berg667503d2009-07-07 03:56:11 +0200514 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200515#endif
516}
Johannes Berg667503d2009-07-07 03:56:11 +0200517
518void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
519 const u8 *req_ie, size_t req_ie_len,
520 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
521{
522 struct wireless_dev *wdev = dev->ieee80211_ptr;
523 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
524 struct cfg80211_event *ev;
525 unsigned long flags;
526
527 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
528 if (!ev)
529 return;
530
531 ev->type = EVENT_ROAMED;
532 memcpy(ev->rm.bssid, bssid, ETH_ALEN);
533 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
534 ev->rm.req_ie_len = req_ie_len;
535 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
536 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
537 ev->rm.resp_ie_len = resp_ie_len;
538 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
539
540 spin_lock_irqsave(&wdev->event_lock, flags);
541 list_add_tail(&ev->list, &wdev->event_list);
542 spin_unlock_irqrestore(&wdev->event_lock, flags);
543 schedule_work(&rdev->event_work);
544}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200545EXPORT_SYMBOL(cfg80211_roamed);
546
Johannes Berg667503d2009-07-07 03:56:11 +0200547void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
Johannes Berg6829c872009-07-02 09:13:27 +0200548 size_t ie_len, u16 reason, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200549{
550 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200551 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
552 int i;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200553#ifdef CONFIG_WIRELESS_EXT
554 union iwreq_data wrqu;
555#endif
556
Johannes Berg667503d2009-07-07 03:56:11 +0200557 ASSERT_WDEV_LOCK(wdev);
558
Samuel Ortizb23aa672009-07-01 21:26:54 +0200559 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
560 return;
561
562 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
563 return;
564
565 if (wdev->current_bss) {
566 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200567 cfg80211_put_bss(&wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200568 }
569
570 wdev->current_bss = NULL;
571 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200572 wdev->ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200573
Johannes Berg6829c872009-07-02 09:13:27 +0200574 if (wdev->conn) {
Johannes Bergb6f0b632009-08-06 20:41:34 +0200575 const u8 *bssid;
576 int ret;
577
Johannes Berg6829c872009-07-02 09:13:27 +0200578 kfree(wdev->conn->ie);
579 wdev->conn->ie = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200580 kfree(wdev->conn);
581 wdev->conn = NULL;
Johannes Bergb6f0b632009-08-06 20:41:34 +0200582
583 /*
584 * If this disconnect was due to a disassoc, we
585 * we might still have an auth BSS around. For
586 * the userspace SME that's currently expected,
587 * but for the kernel SME (nl80211 CONNECT or
588 * wireless extensions) we want to clear up all
589 * state.
590 */
591 for (i = 0; i < MAX_AUTH_BSSES; i++) {
592 if (!wdev->auth_bsses[i])
593 continue;
594 bssid = wdev->auth_bsses[i]->pub.bssid;
595 ret = __cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
596 WLAN_REASON_DEAUTH_LEAVING);
597 WARN(ret, "deauth failed: %d\n", ret);
598 }
Johannes Berg6829c872009-07-02 09:13:27 +0200599 }
600
Johannes Bergfffd0932009-07-08 14:22:54 +0200601 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
602
603 /*
604 * Delete all the keys ... pairwise keys can't really
605 * exist any more anyway, but default keys might.
606 */
607 if (rdev->ops->del_key)
608 for (i = 0; i < 6; i++)
609 rdev->ops->del_key(wdev->wiphy, dev, i, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200610
611#ifdef CONFIG_WIRELESS_EXT
612 memset(&wrqu, 0, sizeof(wrqu));
613 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
614 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
615#endif
616}
617
618void cfg80211_disconnected(struct net_device *dev, u16 reason,
619 u8 *ie, size_t ie_len, gfp_t gfp)
620{
Johannes Berg667503d2009-07-07 03:56:11 +0200621 struct wireless_dev *wdev = dev->ieee80211_ptr;
622 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
623 struct cfg80211_event *ev;
624 unsigned long flags;
625
626 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
627 if (!ev)
628 return;
629
630 ev->type = EVENT_DISCONNECTED;
631 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
632 ev->dc.ie_len = ie_len;
633 memcpy((void *)ev->dc.ie, ie, ie_len);
634 ev->dc.reason = reason;
635
636 spin_lock_irqsave(&wdev->event_lock, flags);
637 list_add_tail(&ev->list, &wdev->event_list);
638 spin_unlock_irqrestore(&wdev->event_lock, flags);
639 schedule_work(&rdev->event_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200640}
641EXPORT_SYMBOL(cfg80211_disconnected);
642
Johannes Berg667503d2009-07-07 03:56:11 +0200643int __cfg80211_connect(struct cfg80211_registered_device *rdev,
644 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200645 struct cfg80211_connect_params *connect,
646 struct cfg80211_cached_keys *connkeys)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200647{
Samuel Ortizb23aa672009-07-01 21:26:54 +0200648 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200649 struct ieee80211_channel *chan;
Johannes Berg667503d2009-07-07 03:56:11 +0200650 int err;
651
652 ASSERT_WDEV_LOCK(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200653
654 if (wdev->sme_state != CFG80211_SME_IDLE)
655 return -EALREADY;
656
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200657 chan = rdev_fixed_channel(rdev, wdev);
658 if (chan && chan != connect->channel)
659 return -EBUSY;
660
Johannes Bergfffd0932009-07-08 14:22:54 +0200661 if (WARN_ON(wdev->connect_keys)) {
662 kfree(wdev->connect_keys);
663 wdev->connect_keys = NULL;
664 }
665
666 if (connkeys && connkeys->def >= 0) {
667 int idx;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200668 u32 cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +0200669
670 idx = connkeys->def;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200671 cipher = connkeys->params[idx].cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +0200672 /* If given a WEP key we may need it for shared key auth */
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200673 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
674 cipher == WLAN_CIPHER_SUITE_WEP104) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200675 connect->key_idx = idx;
676 connect->key = connkeys->params[idx].key;
677 connect->key_len = connkeys->params[idx].key_len;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200678
679 /*
680 * If ciphers are not set (e.g. when going through
681 * iwconfig), we have to set them appropriately here.
682 */
683 if (connect->crypto.cipher_group == 0)
684 connect->crypto.cipher_group = cipher;
685
686 if (connect->crypto.n_ciphers_pairwise == 0) {
687 connect->crypto.n_ciphers_pairwise = 1;
688 connect->crypto.ciphers_pairwise[0] = cipher;
689 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200690 }
691 }
692
Samuel Ortizb23aa672009-07-01 21:26:54 +0200693 if (!rdev->ops->connect) {
Johannes Berg6829c872009-07-02 09:13:27 +0200694 if (!rdev->ops->auth || !rdev->ops->assoc)
695 return -EOPNOTSUPP;
696
Johannes Berg19957bb2009-07-02 17:20:43 +0200697 if (WARN_ON(wdev->conn))
698 return -EINPROGRESS;
699
700 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
701 if (!wdev->conn)
702 return -ENOMEM;
Johannes Berg6829c872009-07-02 09:13:27 +0200703
704 /*
705 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
706 */
707 memcpy(&wdev->conn->params, connect, sizeof(*connect));
708 if (connect->bssid) {
709 wdev->conn->params.bssid = wdev->conn->bssid;
710 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
711 }
712
713 if (connect->ie) {
714 wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
715 GFP_KERNEL);
716 wdev->conn->params.ie = wdev->conn->ie;
Johannes Berg19957bb2009-07-02 17:20:43 +0200717 if (!wdev->conn->ie) {
718 kfree(wdev->conn);
719 wdev->conn = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200720 return -ENOMEM;
Johannes Berg19957bb2009-07-02 17:20:43 +0200721 }
Johannes Berg6829c872009-07-02 09:13:27 +0200722 }
723
724 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
725 wdev->conn->auto_auth = true;
726 /* start with open system ... should mostly work */
727 wdev->conn->params.auth_type =
728 NL80211_AUTHTYPE_OPEN_SYSTEM;
729 } else {
730 wdev->conn->auto_auth = false;
731 }
732
733 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
734 wdev->ssid_len = connect->ssid_len;
735 wdev->conn->params.ssid = wdev->ssid;
736 wdev->conn->params.ssid_len = connect->ssid_len;
737
738 /* don't care about result -- but fill bssid & channel */
739 if (!wdev->conn->params.bssid || !wdev->conn->params.channel)
740 cfg80211_get_conn_bss(wdev);
741
742 wdev->sme_state = CFG80211_SME_CONNECTING;
Johannes Bergfffd0932009-07-08 14:22:54 +0200743 wdev->connect_keys = connkeys;
Johannes Berg6829c872009-07-02 09:13:27 +0200744
745 /* we're good if we have both BSSID and channel */
746 if (wdev->conn->params.bssid && wdev->conn->params.channel) {
747 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
748 err = cfg80211_conn_do_work(wdev);
749 } else {
750 /* otherwise we'll need to scan for the AP first */
751 err = cfg80211_conn_scan(wdev);
752 /*
753 * If we can't scan right now, then we need to scan again
754 * after the current scan finished, since the parameters
755 * changed (unless we find a good AP anyway).
756 */
757 if (err == -EBUSY) {
758 err = 0;
759 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
760 }
761 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200762 if (err) {
763 kfree(wdev->conn);
764 wdev->conn = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200765 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Bergfffd0932009-07-08 14:22:54 +0200766 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200767 wdev->ssid_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200768 }
Johannes Berg6829c872009-07-02 09:13:27 +0200769
770 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200771 } else {
772 wdev->sme_state = CFG80211_SME_CONNECTING;
Johannes Bergfffd0932009-07-08 14:22:54 +0200773 wdev->connect_keys = connkeys;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200774 err = rdev->ops->connect(&rdev->wiphy, dev, connect);
775 if (err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200776 wdev->connect_keys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200777 wdev->sme_state = CFG80211_SME_IDLE;
778 return err;
779 }
Johannes Berg6829c872009-07-02 09:13:27 +0200780
781 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
782 wdev->ssid_len = connect->ssid_len;
783
784 return 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200785 }
Samuel Ortizb23aa672009-07-01 21:26:54 +0200786}
787
Johannes Berg667503d2009-07-07 03:56:11 +0200788int cfg80211_connect(struct cfg80211_registered_device *rdev,
789 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200790 struct cfg80211_connect_params *connect,
791 struct cfg80211_cached_keys *connkeys)
Johannes Berg667503d2009-07-07 03:56:11 +0200792{
793 int err;
794
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200795 mutex_lock(&rdev->devlist_mtx);
Johannes Berg667503d2009-07-07 03:56:11 +0200796 wdev_lock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +0200797 err = __cfg80211_connect(rdev, dev, connect, connkeys);
Johannes Berg667503d2009-07-07 03:56:11 +0200798 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200799 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg667503d2009-07-07 03:56:11 +0200800
801 return err;
802}
803
804int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
805 struct net_device *dev, u16 reason, bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200806{
Johannes Berg6829c872009-07-02 09:13:27 +0200807 struct wireless_dev *wdev = dev->ieee80211_ptr;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200808 int err;
809
Johannes Berg667503d2009-07-07 03:56:11 +0200810 ASSERT_WDEV_LOCK(wdev);
811
Johannes Berg6829c872009-07-02 09:13:27 +0200812 if (wdev->sme_state == CFG80211_SME_IDLE)
813 return -EINVAL;
814
Johannes Bergfffd0932009-07-08 14:22:54 +0200815 kfree(wdev->connect_keys);
816 wdev->connect_keys = NULL;
817
Samuel Ortizb23aa672009-07-01 21:26:54 +0200818 if (!rdev->ops->disconnect) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200819 if (!rdev->ops->deauth)
820 return -EOPNOTSUPP;
Johannes Berg6829c872009-07-02 09:13:27 +0200821
Johannes Berg19957bb2009-07-02 17:20:43 +0200822 /* was it connected by userspace SME? */
823 if (!wdev->conn) {
824 cfg80211_mlme_down(rdev, dev);
825 return 0;
826 }
Johannes Berg6829c872009-07-02 09:13:27 +0200827
828 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
829 (wdev->conn->state == CFG80211_CONN_SCANNING ||
830 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) {
831 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg19957bb2009-07-02 17:20:43 +0200832 kfree(wdev->conn);
833 wdev->conn = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200834 wdev->ssid_len = 0;
Johannes Berg6829c872009-07-02 09:13:27 +0200835 return 0;
836 }
837
Johannes Berg6829c872009-07-02 09:13:27 +0200838 /* wdev->conn->params.bssid must be set if > SCANNING */
Johannes Berg667503d2009-07-07 03:56:11 +0200839 err = __cfg80211_mlme_deauth(rdev, dev,
840 wdev->conn->params.bssid,
841 NULL, 0, reason);
Johannes Berg6829c872009-07-02 09:13:27 +0200842 if (err)
843 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200844 } else {
845 err = rdev->ops->disconnect(&rdev->wiphy, dev, reason);
846 if (err)
847 return err;
848 }
849
Johannes Berg6829c872009-07-02 09:13:27 +0200850 if (wdev->sme_state == CFG80211_SME_CONNECTED)
Johannes Berg667503d2009-07-07 03:56:11 +0200851 __cfg80211_disconnected(dev, NULL, 0, 0, false);
Johannes Berg6829c872009-07-02 09:13:27 +0200852 else if (wdev->sme_state == CFG80211_SME_CONNECTING)
Johannes Bergf2129352009-07-01 21:26:56 +0200853 __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0,
854 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200855 wextev, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200856
857 return 0;
858}
Johannes Berg19957bb2009-07-02 17:20:43 +0200859
Johannes Berg667503d2009-07-07 03:56:11 +0200860int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
861 struct net_device *dev,
862 u16 reason, bool wextev)
863{
864 int err;
865
866 wdev_lock(dev->ieee80211_ptr);
867 err = __cfg80211_disconnect(rdev, dev, reason, wextev);
868 wdev_unlock(dev->ieee80211_ptr);
869
870 return err;
871}
872
Johannes Berg19957bb2009-07-02 17:20:43 +0200873void cfg80211_sme_disassoc(struct net_device *dev, int idx)
874{
875 struct wireless_dev *wdev = dev->ieee80211_ptr;
876 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
877 u8 bssid[ETH_ALEN];
878
Johannes Berg667503d2009-07-07 03:56:11 +0200879 ASSERT_WDEV_LOCK(wdev);
880
Johannes Berg19957bb2009-07-02 17:20:43 +0200881 if (!wdev->conn)
882 return;
883
884 if (wdev->conn->state == CFG80211_CONN_IDLE)
885 return;
886
887 /*
888 * Ok, so the association was made by this SME -- we don't
889 * want it any more so deauthenticate too.
890 */
891
892 if (!wdev->auth_bsses[idx])
893 return;
894
895 memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN);
Johannes Bergec3f1492009-07-10 02:45:38 +0200896 if (__cfg80211_mlme_deauth(rdev, dev, bssid,
897 NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200898 /* whatever -- assume gone anyway */
899 cfg80211_unhold_bss(wdev->auth_bsses[idx]);
900 cfg80211_put_bss(&wdev->auth_bsses[idx]->pub);
901 wdev->auth_bsses[idx] = NULL;
902 }
903}