blob: 340934f714b2df619bddda570c013476ea760e8d [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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-07-07 03:56:11 +0200179 }
Johannes Berg6829c872009-07-02 09:13:27 +0200180 if (cfg80211_conn_do_work(wdev))
Johannes Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-07-07 03:56:11 +0200255void cfg80211_sme_scan_done(struct net_device *dev)
256{
257 struct wireless_dev *wdev = dev->ieee80211_ptr;
258
259 wdev_lock(wdev);
260 __cfg80211_sme_scan_done(dev);
261 wdev_unlock(wdev);
262}
263
264void cfg80211_sme_rx_auth(struct net_device *dev,
265 const u8 *buf, size_t len)
Johannes Berg6829c872009-07-02 09:13:27 +0200266{
267 struct wireless_dev *wdev = dev->ieee80211_ptr;
268 struct wiphy *wiphy = wdev->wiphy;
269 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
270 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
271 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
272
Johannes Berg667503dd2009-07-07 03:56:11 +0200273 ASSERT_WDEV_LOCK(wdev);
274
Johannes Berg6829c872009-07-02 09:13:27 +0200275 /* should only RX auth frames when connecting */
276 if (wdev->sme_state != CFG80211_SME_CONNECTING)
277 return;
278
279 if (WARN_ON(!wdev->conn))
280 return;
281
282 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
283 wdev->conn->auto_auth &&
284 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
285 /* select automatically between only open, shared, leap */
286 switch (wdev->conn->params.auth_type) {
287 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Johannes Bergfffd0932009-07-08 14:22:54 +0200288 if (wdev->connect_keys)
289 wdev->conn->params.auth_type =
290 NL80211_AUTHTYPE_SHARED_KEY;
291 else
292 wdev->conn->params.auth_type =
293 NL80211_AUTHTYPE_NETWORK_EAP;
Johannes Berg6829c872009-07-02 09:13:27 +0200294 break;
295 case NL80211_AUTHTYPE_SHARED_KEY:
296 wdev->conn->params.auth_type =
297 NL80211_AUTHTYPE_NETWORK_EAP;
298 break;
299 default:
300 /* huh? */
301 wdev->conn->params.auth_type =
302 NL80211_AUTHTYPE_OPEN_SYSTEM;
303 break;
304 }
305 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
306 schedule_work(&rdev->conn_work);
Johannes Berg19957bb2009-07-02 17:20:43 +0200307 } else if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Berg4bde0f72009-07-07 23:46:51 +0200308 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200309 status_code, false, NULL);
Johannes Berg19957bb2009-07-02 17:20:43 +0200310 } else if (wdev->sme_state == CFG80211_SME_CONNECTING &&
Johannes Berg6829c872009-07-02 09:13:27 +0200311 wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
312 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
313 schedule_work(&rdev->conn_work);
314 }
315}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200316
Johannes Berg667503dd2009-07-07 03:56:11 +0200317void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
318 const u8 *req_ie, size_t req_ie_len,
319 const u8 *resp_ie, size_t resp_ie_len,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200320 u16 status, bool wextev,
321 struct cfg80211_bss *bss)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200322{
323 struct wireless_dev *wdev = dev->ieee80211_ptr;
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700324 u8 *country_ie;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200325#ifdef CONFIG_WIRELESS_EXT
326 union iwreq_data wrqu;
327#endif
328
Johannes Berg667503dd2009-07-07 03:56:11 +0200329 ASSERT_WDEV_LOCK(wdev);
330
Samuel Ortizb23aa672009-07-01 21:26:54 +0200331 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
332 return;
333
Johannes Berge45cd822009-07-02 09:58:04 +0200334 if (wdev->sme_state == CFG80211_SME_CONNECTED)
335 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), dev,
336 bssid, req_ie, req_ie_len,
Johannes Berg667503dd2009-07-07 03:56:11 +0200337 resp_ie, resp_ie_len, GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200338 else
339 nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev,
340 bssid, req_ie, req_ie_len,
341 resp_ie, resp_ie_len,
Johannes Berg667503dd2009-07-07 03:56:11 +0200342 status, GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200343
344#ifdef CONFIG_WIRELESS_EXT
345 if (wextev) {
346 if (req_ie && status == WLAN_STATUS_SUCCESS) {
347 memset(&wrqu, 0, sizeof(wrqu));
348 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800349 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200350 }
351
352 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
353 memset(&wrqu, 0, sizeof(wrqu));
354 wrqu.data.length = resp_ie_len;
355 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
356 }
357
358 memset(&wrqu, 0, sizeof(wrqu));
359 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
360 if (bssid && status == WLAN_STATUS_SUCCESS)
361 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
362 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
363 }
364#endif
365
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200366 if (wdev->current_bss) {
367 cfg80211_unhold_bss(wdev->current_bss);
368 cfg80211_put_bss(&wdev->current_bss->pub);
369 wdev->current_bss = NULL;
370 }
371
Johannes Berge45cd822009-07-02 09:58:04 +0200372 if (status == WLAN_STATUS_SUCCESS &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200373 wdev->sme_state == CFG80211_SME_IDLE)
374 goto success;
Johannes Berge45cd822009-07-02 09:58:04 +0200375
Johannes Berg6829c872009-07-02 09:13:27 +0200376 if (wdev->sme_state != CFG80211_SME_CONNECTING)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200377 return;
378
Johannes Berg19957bb2009-07-02 17:20:43 +0200379 if (wdev->conn)
380 wdev->conn->state = CFG80211_CONN_IDLE;
381
Johannes Bergfffd0932009-07-08 14:22:54 +0200382 if (status != WLAN_STATUS_SUCCESS) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200383 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg19957bb2009-07-02 17:20:43 +0200384 kfree(wdev->conn);
385 wdev->conn = NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200386 kfree(wdev->connect_keys);
387 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200388 wdev->ssid_len = 0;
Johannes Bergfffd0932009-07-08 14:22:54 +0200389 return;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200390 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200391
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200392 success:
393 if (!bss)
394 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
395 wdev->ssid, wdev->ssid_len,
396 WLAN_CAPABILITY_ESS,
397 WLAN_CAPABILITY_ESS);
Johannes Bergfffd0932009-07-08 14:22:54 +0200398
399 if (WARN_ON(!bss))
400 return;
401
402 cfg80211_hold_bss(bss_from_pub(bss));
403 wdev->current_bss = bss_from_pub(bss);
404
Johannes Bergfffd0932009-07-08 14:22:54 +0200405 wdev->sme_state = CFG80211_SME_CONNECTED;
406 cfg80211_upload_connect_keys(wdev);
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700407
408 country_ie = (u8 *) ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
409
410 if (!country_ie)
411 return;
412
413 /*
414 * ieee80211_bss_get_ie() ensures we can access:
415 * - country_ie + 2, the start of the country ie data, and
416 * - and country_ie[1] which is the IE length
417 */
418 regulatory_hint_11d(wdev->wiphy,
419 country_ie + 2,
420 country_ie[1]);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200421}
Johannes Bergf2129352009-07-01 21:26:56 +0200422
423void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
424 const u8 *req_ie, size_t req_ie_len,
425 const u8 *resp_ie, size_t resp_ie_len,
426 u16 status, gfp_t gfp)
427{
Johannes Berg667503dd2009-07-07 03:56:11 +0200428 struct wireless_dev *wdev = dev->ieee80211_ptr;
429 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
430 struct cfg80211_event *ev;
431 unsigned long flags;
432
433 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
434 if (!ev)
435 return;
436
437 ev->type = EVENT_CONNECT_RESULT;
438 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
439 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
440 ev->cr.req_ie_len = req_ie_len;
441 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
442 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
443 ev->cr.resp_ie_len = resp_ie_len;
444 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
445 ev->cr.status = status;
446
447 spin_lock_irqsave(&wdev->event_lock, flags);
448 list_add_tail(&ev->list, &wdev->event_list);
449 spin_unlock_irqrestore(&wdev->event_lock, flags);
450 schedule_work(&rdev->event_work);
Johannes Bergf2129352009-07-01 21:26:56 +0200451}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200452EXPORT_SYMBOL(cfg80211_connect_result);
453
Johannes Berg667503dd2009-07-07 03:56:11 +0200454void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
455 const u8 *req_ie, size_t req_ie_len,
456 const u8 *resp_ie, size_t resp_ie_len)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200457{
Samuel Ortizb23aa672009-07-01 21:26:54 +0200458 struct cfg80211_bss *bss;
459#ifdef CONFIG_WIRELESS_EXT
460 union iwreq_data wrqu;
461#endif
462
Johannes Berg667503dd2009-07-07 03:56:11 +0200463 ASSERT_WDEV_LOCK(wdev);
464
Samuel Ortizb23aa672009-07-01 21:26:54 +0200465 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
466 return;
467
468 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
469 return;
470
471 /* internal error -- how did we get to CONNECTED w/o BSS? */
472 if (WARN_ON(!wdev->current_bss)) {
473 return;
474 }
475
476 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200477 cfg80211_put_bss(&wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200478 wdev->current_bss = NULL;
479
480 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
481 wdev->ssid, wdev->ssid_len,
482 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
483
484 if (WARN_ON(!bss))
485 return;
486
Johannes Berg19957bb2009-07-02 17:20:43 +0200487 cfg80211_hold_bss(bss_from_pub(bss));
488 wdev->current_bss = bss_from_pub(bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200489
Johannes Berg667503dd2009-07-07 03:56:11 +0200490 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid,
491 req_ie, req_ie_len, resp_ie, resp_ie_len,
492 GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200493
494#ifdef CONFIG_WIRELESS_EXT
495 if (req_ie) {
496 memset(&wrqu, 0, sizeof(wrqu));
497 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800498 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
Johannes Berg667503dd2009-07-07 03:56:11 +0200499 &wrqu, req_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200500 }
501
502 if (resp_ie) {
503 memset(&wrqu, 0, sizeof(wrqu));
504 wrqu.data.length = resp_ie_len;
Johannes Berg667503dd2009-07-07 03:56:11 +0200505 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
506 &wrqu, resp_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200507 }
508
509 memset(&wrqu, 0, sizeof(wrqu));
510 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
511 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
Johannes Berg667503dd2009-07-07 03:56:11 +0200512 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200513#endif
514}
Johannes Berg667503dd2009-07-07 03:56:11 +0200515
516void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
517 const u8 *req_ie, size_t req_ie_len,
518 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
519{
520 struct wireless_dev *wdev = dev->ieee80211_ptr;
521 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
522 struct cfg80211_event *ev;
523 unsigned long flags;
524
525 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
526 if (!ev)
527 return;
528
529 ev->type = EVENT_ROAMED;
530 memcpy(ev->rm.bssid, bssid, ETH_ALEN);
531 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
532 ev->rm.req_ie_len = req_ie_len;
533 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
534 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
535 ev->rm.resp_ie_len = resp_ie_len;
536 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
537
538 spin_lock_irqsave(&wdev->event_lock, flags);
539 list_add_tail(&ev->list, &wdev->event_list);
540 spin_unlock_irqrestore(&wdev->event_lock, flags);
541 schedule_work(&rdev->event_work);
542}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200543EXPORT_SYMBOL(cfg80211_roamed);
544
Johannes Berg667503dd2009-07-07 03:56:11 +0200545void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
Johannes Berg6829c872009-07-02 09:13:27 +0200546 size_t ie_len, u16 reason, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200547{
548 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200549 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
550 int i;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200551#ifdef CONFIG_WIRELESS_EXT
552 union iwreq_data wrqu;
553#endif
554
Johannes Berg667503dd2009-07-07 03:56:11 +0200555 ASSERT_WDEV_LOCK(wdev);
556
Samuel Ortizb23aa672009-07-01 21:26:54 +0200557 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
558 return;
559
560 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
561 return;
562
563 if (wdev->current_bss) {
564 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg19957bb2009-07-02 17:20:43 +0200565 cfg80211_put_bss(&wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200566 }
567
568 wdev->current_bss = NULL;
569 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200570 wdev->ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200571
Johannes Berg6829c872009-07-02 09:13:27 +0200572 if (wdev->conn) {
Johannes Bergb6f0b632009-08-06 20:41:34 +0200573 const u8 *bssid;
574 int ret;
575
Johannes Berg6829c872009-07-02 09:13:27 +0200576 kfree(wdev->conn->ie);
577 wdev->conn->ie = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +0200578 kfree(wdev->conn);
579 wdev->conn = NULL;
Johannes Bergb6f0b632009-08-06 20:41:34 +0200580
581 /*
582 * If this disconnect was due to a disassoc, we
583 * we might still have an auth BSS around. For
584 * the userspace SME that's currently expected,
585 * but for the kernel SME (nl80211 CONNECT or
586 * wireless extensions) we want to clear up all
587 * state.
588 */
589 for (i = 0; i < MAX_AUTH_BSSES; i++) {
590 if (!wdev->auth_bsses[i])
591 continue;
592 bssid = wdev->auth_bsses[i]->pub.bssid;
593 ret = __cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
594 WLAN_REASON_DEAUTH_LEAVING);
595 WARN(ret, "deauth failed: %d\n", ret);
596 }
Johannes Berg6829c872009-07-02 09:13:27 +0200597 }
598
Johannes Bergfffd0932009-07-08 14:22:54 +0200599 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
600
601 /*
602 * Delete all the keys ... pairwise keys can't really
603 * exist any more anyway, but default keys might.
604 */
605 if (rdev->ops->del_key)
606 for (i = 0; i < 6; i++)
607 rdev->ops->del_key(wdev->wiphy, dev, i, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200608
609#ifdef CONFIG_WIRELESS_EXT
610 memset(&wrqu, 0, sizeof(wrqu));
611 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
612 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
613#endif
614}
615
616void cfg80211_disconnected(struct net_device *dev, u16 reason,
617 u8 *ie, size_t ie_len, gfp_t gfp)
618{
Johannes Berg667503dd2009-07-07 03:56:11 +0200619 struct wireless_dev *wdev = dev->ieee80211_ptr;
620 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
621 struct cfg80211_event *ev;
622 unsigned long flags;
623
624 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
625 if (!ev)
626 return;
627
628 ev->type = EVENT_DISCONNECTED;
629 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
630 ev->dc.ie_len = ie_len;
631 memcpy((void *)ev->dc.ie, ie, ie_len);
632 ev->dc.reason = reason;
633
634 spin_lock_irqsave(&wdev->event_lock, flags);
635 list_add_tail(&ev->list, &wdev->event_list);
636 spin_unlock_irqrestore(&wdev->event_lock, flags);
637 schedule_work(&rdev->event_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200638}
639EXPORT_SYMBOL(cfg80211_disconnected);
640
Johannes Berg667503dd2009-07-07 03:56:11 +0200641int __cfg80211_connect(struct cfg80211_registered_device *rdev,
642 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200643 struct cfg80211_connect_params *connect,
644 struct cfg80211_cached_keys *connkeys)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200645{
Samuel Ortizb23aa672009-07-01 21:26:54 +0200646 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg667503dd2009-07-07 03:56:11 +0200647 int err;
648
649 ASSERT_WDEV_LOCK(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200650
651 if (wdev->sme_state != CFG80211_SME_IDLE)
652 return -EALREADY;
653
Johannes Bergfffd0932009-07-08 14:22:54 +0200654 if (WARN_ON(wdev->connect_keys)) {
655 kfree(wdev->connect_keys);
656 wdev->connect_keys = NULL;
657 }
658
659 if (connkeys && connkeys->def >= 0) {
660 int idx;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200661 u32 cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +0200662
663 idx = connkeys->def;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200664 cipher = connkeys->params[idx].cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +0200665 /* If given a WEP key we may need it for shared key auth */
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200666 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
667 cipher == WLAN_CIPHER_SUITE_WEP104) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200668 connect->key_idx = idx;
669 connect->key = connkeys->params[idx].key;
670 connect->key_len = connkeys->params[idx].key_len;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +0200671
672 /*
673 * If ciphers are not set (e.g. when going through
674 * iwconfig), we have to set them appropriately here.
675 */
676 if (connect->crypto.cipher_group == 0)
677 connect->crypto.cipher_group = cipher;
678
679 if (connect->crypto.n_ciphers_pairwise == 0) {
680 connect->crypto.n_ciphers_pairwise = 1;
681 connect->crypto.ciphers_pairwise[0] = cipher;
682 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200683 }
684 }
685
Samuel Ortizb23aa672009-07-01 21:26:54 +0200686 if (!rdev->ops->connect) {
Johannes Berg6829c872009-07-02 09:13:27 +0200687 if (!rdev->ops->auth || !rdev->ops->assoc)
688 return -EOPNOTSUPP;
689
Johannes Berg19957bb2009-07-02 17:20:43 +0200690 if (WARN_ON(wdev->conn))
691 return -EINPROGRESS;
692
693 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
694 if (!wdev->conn)
695 return -ENOMEM;
Johannes Berg6829c872009-07-02 09:13:27 +0200696
697 /*
698 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
699 */
700 memcpy(&wdev->conn->params, connect, sizeof(*connect));
701 if (connect->bssid) {
702 wdev->conn->params.bssid = wdev->conn->bssid;
703 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
704 }
705
706 if (connect->ie) {
707 wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
708 GFP_KERNEL);
709 wdev->conn->params.ie = wdev->conn->ie;
Johannes Berg19957bb2009-07-02 17:20:43 +0200710 if (!wdev->conn->ie) {
711 kfree(wdev->conn);
712 wdev->conn = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200713 return -ENOMEM;
Johannes Berg19957bb2009-07-02 17:20:43 +0200714 }
Johannes Berg6829c872009-07-02 09:13:27 +0200715 }
716
717 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
718 wdev->conn->auto_auth = true;
719 /* start with open system ... should mostly work */
720 wdev->conn->params.auth_type =
721 NL80211_AUTHTYPE_OPEN_SYSTEM;
722 } else {
723 wdev->conn->auto_auth = false;
724 }
725
726 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
727 wdev->ssid_len = connect->ssid_len;
728 wdev->conn->params.ssid = wdev->ssid;
729 wdev->conn->params.ssid_len = connect->ssid_len;
730
731 /* don't care about result -- but fill bssid & channel */
732 if (!wdev->conn->params.bssid || !wdev->conn->params.channel)
733 cfg80211_get_conn_bss(wdev);
734
735 wdev->sme_state = CFG80211_SME_CONNECTING;
Johannes Bergfffd0932009-07-08 14:22:54 +0200736 wdev->connect_keys = connkeys;
Johannes Berg6829c872009-07-02 09:13:27 +0200737
738 /* we're good if we have both BSSID and channel */
739 if (wdev->conn->params.bssid && wdev->conn->params.channel) {
740 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
741 err = cfg80211_conn_do_work(wdev);
742 } else {
743 /* otherwise we'll need to scan for the AP first */
744 err = cfg80211_conn_scan(wdev);
745 /*
746 * If we can't scan right now, then we need to scan again
747 * after the current scan finished, since the parameters
748 * changed (unless we find a good AP anyway).
749 */
750 if (err == -EBUSY) {
751 err = 0;
752 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
753 }
754 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200755 if (err) {
756 kfree(wdev->conn);
757 wdev->conn = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200758 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Bergfffd0932009-07-08 14:22:54 +0200759 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200760 wdev->ssid_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +0200761 }
Johannes Berg6829c872009-07-02 09:13:27 +0200762
763 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200764 } else {
765 wdev->sme_state = CFG80211_SME_CONNECTING;
Johannes Bergfffd0932009-07-08 14:22:54 +0200766 wdev->connect_keys = connkeys;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200767 err = rdev->ops->connect(&rdev->wiphy, dev, connect);
768 if (err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200769 wdev->connect_keys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200770 wdev->sme_state = CFG80211_SME_IDLE;
771 return err;
772 }
Johannes Berg6829c872009-07-02 09:13:27 +0200773
774 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
775 wdev->ssid_len = connect->ssid_len;
776
777 return 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200778 }
Samuel Ortizb23aa672009-07-01 21:26:54 +0200779}
780
Johannes Berg667503dd2009-07-07 03:56:11 +0200781int cfg80211_connect(struct cfg80211_registered_device *rdev,
782 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200783 struct cfg80211_connect_params *connect,
784 struct cfg80211_cached_keys *connkeys)
Johannes Berg667503dd2009-07-07 03:56:11 +0200785{
786 int err;
787
788 wdev_lock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +0200789 err = __cfg80211_connect(rdev, dev, connect, connkeys);
Johannes Berg667503dd2009-07-07 03:56:11 +0200790 wdev_unlock(dev->ieee80211_ptr);
791
792 return err;
793}
794
795int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
796 struct net_device *dev, u16 reason, bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200797{
Johannes Berg6829c872009-07-02 09:13:27 +0200798 struct wireless_dev *wdev = dev->ieee80211_ptr;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200799 int err;
800
Johannes Berg667503dd2009-07-07 03:56:11 +0200801 ASSERT_WDEV_LOCK(wdev);
802
Johannes Berg6829c872009-07-02 09:13:27 +0200803 if (wdev->sme_state == CFG80211_SME_IDLE)
804 return -EINVAL;
805
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 kfree(wdev->connect_keys);
807 wdev->connect_keys = NULL;
808
Samuel Ortizb23aa672009-07-01 21:26:54 +0200809 if (!rdev->ops->disconnect) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200810 if (!rdev->ops->deauth)
811 return -EOPNOTSUPP;
Johannes Berg6829c872009-07-02 09:13:27 +0200812
Johannes Berg19957bb2009-07-02 17:20:43 +0200813 /* was it connected by userspace SME? */
814 if (!wdev->conn) {
815 cfg80211_mlme_down(rdev, dev);
816 return 0;
817 }
Johannes Berg6829c872009-07-02 09:13:27 +0200818
819 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
820 (wdev->conn->state == CFG80211_CONN_SCANNING ||
821 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) {
822 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Berg19957bb2009-07-02 17:20:43 +0200823 kfree(wdev->conn);
824 wdev->conn = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200825 wdev->ssid_len = 0;
Johannes Berg6829c872009-07-02 09:13:27 +0200826 return 0;
827 }
828
Johannes Berg6829c872009-07-02 09:13:27 +0200829 /* wdev->conn->params.bssid must be set if > SCANNING */
Johannes Berg667503dd2009-07-07 03:56:11 +0200830 err = __cfg80211_mlme_deauth(rdev, dev,
831 wdev->conn->params.bssid,
832 NULL, 0, reason);
Johannes Berg6829c872009-07-02 09:13:27 +0200833 if (err)
834 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200835 } else {
836 err = rdev->ops->disconnect(&rdev->wiphy, dev, reason);
837 if (err)
838 return err;
839 }
840
Johannes Berg6829c872009-07-02 09:13:27 +0200841 if (wdev->sme_state == CFG80211_SME_CONNECTED)
Johannes Berg667503dd2009-07-07 03:56:11 +0200842 __cfg80211_disconnected(dev, NULL, 0, 0, false);
Johannes Berg6829c872009-07-02 09:13:27 +0200843 else if (wdev->sme_state == CFG80211_SME_CONNECTING)
Johannes Bergf2129352009-07-01 21:26:56 +0200844 __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0,
845 WLAN_STATUS_UNSPECIFIED_FAILURE,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200846 wextev, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200847
848 return 0;
849}
Johannes Berg19957bb2009-07-02 17:20:43 +0200850
Johannes Berg667503dd2009-07-07 03:56:11 +0200851int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
852 struct net_device *dev,
853 u16 reason, bool wextev)
854{
855 int err;
856
857 wdev_lock(dev->ieee80211_ptr);
858 err = __cfg80211_disconnect(rdev, dev, reason, wextev);
859 wdev_unlock(dev->ieee80211_ptr);
860
861 return err;
862}
863
Johannes Berg19957bb2009-07-02 17:20:43 +0200864void cfg80211_sme_disassoc(struct net_device *dev, int idx)
865{
866 struct wireless_dev *wdev = dev->ieee80211_ptr;
867 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
868 u8 bssid[ETH_ALEN];
869
Johannes Berg667503dd2009-07-07 03:56:11 +0200870 ASSERT_WDEV_LOCK(wdev);
871
Johannes Berg19957bb2009-07-02 17:20:43 +0200872 if (!wdev->conn)
873 return;
874
875 if (wdev->conn->state == CFG80211_CONN_IDLE)
876 return;
877
878 /*
879 * Ok, so the association was made by this SME -- we don't
880 * want it any more so deauthenticate too.
881 */
882
883 if (!wdev->auth_bsses[idx])
884 return;
885
886 memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN);
Johannes Bergec3f1492009-07-10 02:45:38 +0200887 if (__cfg80211_mlme_deauth(rdev, dev, bssid,
888 NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) {
Johannes Berg19957bb2009-07-02 17:20:43 +0200889 /* whatever -- assume gone anyway */
890 cfg80211_unhold_bss(wdev->auth_bsses[idx]);
891 cfg80211_put_bss(&wdev->auth_bsses[idx]->pub);
892 wdev->auth_bsses[idx] = NULL;
893 }
894}