blob: 4605bd3a26ba369dc410fbe46ca9ddcd0ed2c78a [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/* Copyright (C) 2006, Red Hat, Inc. */
2
3#include <linux/bitops.h>
4#include <net/ieee80211.h>
5
6#include "assoc.h"
7#include "join.h"
8#include "decl.h"
9#include "hostcmd.h"
10#include "host.h"
11
12
13static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
14static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
15
16static int assoc_helper_essid(wlan_private *priv,
17 struct assoc_request * assoc_req)
18{
19 wlan_adapter *adapter = priv->adapter;
20 int ret = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040021 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022
Holger Schurig9012b282007-05-25 11:27:16 -040023 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024
Holger Schurig9012b282007-05-25 11:27:16 -040025 lbs_deb_assoc("New SSID requested: %s\n", assoc_req->ssid.ssid);
Dan Williams0dc5a292007-05-10 22:58:02 -040026 if (assoc_req->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027 if (adapter->prescan) {
28 libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
29 }
30
Dan Williamsfcdb53d2007-05-25 16:15:56 -040031 bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
Dan Williams0dc5a292007-05-10 22:58:02 -040032 NULL, IW_MODE_INFRA);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040033 if (bss != NULL) {
34 lbs_deb_assoc("SSID found in scan list, associating\n");
35 ret = wlan_associate(priv, bss);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020036 if (ret == 0) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -040037 memcpy(&assoc_req->bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020038 }
39 } else {
Holger Schurig9012b282007-05-25 11:27:16 -040040 lbs_deb_assoc("SSID '%s' not found; cannot associate\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041 assoc_req->ssid.ssid);
42 }
Dan Williams0dc5a292007-05-10 22:58:02 -040043 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020044 /* Scan for the network, do not save previous results. Stale
45 * scan data will cause us to join a non-existant adhoc network
46 */
47 libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
48
49 /* Search for the requested SSID in the scan table */
Dan Williamsfcdb53d2007-05-25 16:15:56 -040050 bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
Dan Williams0dc5a292007-05-10 22:58:02 -040051 IW_MODE_ADHOC);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040052 if (bss != NULL) {
53 lbs_deb_assoc("SSID found joining\n");
54 libertas_join_adhoc_network(priv, bss);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 } else {
56 /* else send START command */
Holger Schurig9012b282007-05-25 11:27:16 -040057 lbs_deb_assoc("SSID not found in list, so creating adhoc"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020058 " with SSID '%s'\n", assoc_req->ssid.ssid);
59 libertas_start_adhoc_network(priv, &assoc_req->ssid);
60 }
61 memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN);
62 }
63
Holger Schurig9012b282007-05-25 11:27:16 -040064 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 return ret;
66}
67
68
69static int assoc_helper_bssid(wlan_private *priv,
70 struct assoc_request * assoc_req)
71{
72 wlan_adapter *adapter = priv->adapter;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040073 int ret = 0;
74 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075
Holger Schurig9012b282007-05-25 11:27:16 -040076 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID" MAC_FMT "\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077 MAC_ARG(assoc_req->bssid));
78
79 /* Search for index position in list for requested MAC */
Dan Williamsfcdb53d2007-05-25 16:15:56 -040080 bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020081 assoc_req->mode);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040082 if (bss == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -040083 lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084 "cannot associate.\n", MAC_ARG(assoc_req->bssid));
85 goto out;
86 }
87
Dan Williams0dc5a292007-05-10 22:58:02 -040088 if (assoc_req->mode == IW_MODE_INFRA) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -040089 ret = wlan_associate(priv, bss);
90 lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret);
Dan Williams0dc5a292007-05-10 22:58:02 -040091 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -040092 libertas_join_adhoc_network(priv, bss);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -040094 memcpy(&assoc_req->ssid, &bss->ssid, sizeof(struct WLAN_802_11_SSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095
96out:
Holger Schurig9012b282007-05-25 11:27:16 -040097 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098 return ret;
99}
100
101
102static int assoc_helper_associate(wlan_private *priv,
103 struct assoc_request * assoc_req)
104{
105 int ret = 0, done = 0;
106
107 /* If we're given and 'any' BSSID, try associating based on SSID */
108
109 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
110 if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN)
111 && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) {
112 ret = assoc_helper_bssid(priv, assoc_req);
113 done = 1;
114 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400115 lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116 }
117 }
118 }
119
120 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
121 ret = assoc_helper_essid(priv, assoc_req);
122 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400123 lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 }
125 }
126
127 return ret;
128}
129
130
131static int assoc_helper_mode(wlan_private *priv,
132 struct assoc_request * assoc_req)
133{
134 wlan_adapter *adapter = priv->adapter;
135 int ret = 0;
136
Holger Schurig9012b282007-05-25 11:27:16 -0400137 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138
Holger Schurig9012b282007-05-25 11:27:16 -0400139 if (assoc_req->mode == adapter->mode)
140 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141
Dan Williams0dc5a292007-05-10 22:58:02 -0400142 if (assoc_req->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 if (adapter->psstate != PS_STATE_FULL_POWER)
144 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
145 adapter->psmode = wlan802_11powermodecam;
146 }
147
Dan Williams0dc5a292007-05-10 22:58:02 -0400148 adapter->mode = assoc_req->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 ret = libertas_prepare_and_send_command(priv,
150 cmd_802_11_snmp_mib,
151 0, cmd_option_waitforrsp,
152 OID_802_11_INFRASTRUCTURE_MODE,
Dan Williams0dc5a292007-05-10 22:58:02 -0400153 (void *) (size_t) assoc_req->mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154
Holger Schurig9012b282007-05-25 11:27:16 -0400155done:
156 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157 return ret;
158}
159
160
161static int assoc_helper_wep_keys(wlan_private *priv,
162 struct assoc_request * assoc_req)
163{
164 wlan_adapter *adapter = priv->adapter;
165 int i;
166 int ret = 0;
167
Holger Schurig9012b282007-05-25 11:27:16 -0400168 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169
170 /* Set or remove WEP keys */
171 if ( assoc_req->wep_keys[0].len
172 || assoc_req->wep_keys[1].len
173 || assoc_req->wep_keys[2].len
174 || assoc_req->wep_keys[3].len) {
175 ret = libertas_prepare_and_send_command(priv,
176 cmd_802_11_set_wep,
177 cmd_act_add,
178 cmd_option_waitforrsp,
179 0, assoc_req);
180 } else {
181 ret = libertas_prepare_and_send_command(priv,
182 cmd_802_11_set_wep,
183 cmd_act_remove,
184 cmd_option_waitforrsp,
185 0, NULL);
186 }
187
188 if (ret)
189 goto out;
190
191 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400192 if (assoc_req->secinfo.wep_enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200193 adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
194 else
195 adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
196 ret = libertas_set_mac_packet_filter(priv);
197 if (ret)
198 goto out;
199
200 mutex_lock(&adapter->lock);
201
202 /* Copy WEP keys into adapter wep key fields */
203 for (i = 0; i < 4; i++) {
204 memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
205 sizeof(struct WLAN_802_11_KEY));
206 }
207 adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
208
209 mutex_unlock(&adapter->lock);
210
211out:
Holger Schurig9012b282007-05-25 11:27:16 -0400212 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213 return ret;
214}
215
216static int assoc_helper_secinfo(wlan_private *priv,
217 struct assoc_request * assoc_req)
218{
219 wlan_adapter *adapter = priv->adapter;
220 int ret = 0;
221
Holger Schurig9012b282007-05-25 11:27:16 -0400222 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223
224 memcpy(&adapter->secinfo, &assoc_req->secinfo,
225 sizeof(struct wlan_802_11_security));
226
227 ret = libertas_set_mac_packet_filter(priv);
228
Holger Schurig9012b282007-05-25 11:27:16 -0400229 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230 return ret;
231}
232
233
234static int assoc_helper_wpa_keys(wlan_private *priv,
235 struct assoc_request * assoc_req)
236{
237 int ret = 0;
238
Holger Schurig9012b282007-05-25 11:27:16 -0400239 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
241 /* enable/Disable RSN */
242 ret = libertas_prepare_and_send_command(priv,
243 cmd_802_11_enable_rsn,
244 cmd_act_set,
245 cmd_option_waitforrsp,
246 0, assoc_req);
247 if (ret)
248 goto out;
249
250 ret = libertas_prepare_and_send_command(priv,
251 cmd_802_11_key_material,
252 cmd_act_set,
253 cmd_option_waitforrsp,
254 0, assoc_req);
255
256out:
Holger Schurig9012b282007-05-25 11:27:16 -0400257 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258 return ret;
259}
260
261
262static int assoc_helper_wpa_ie(wlan_private *priv,
263 struct assoc_request * assoc_req)
264{
265 wlan_adapter *adapter = priv->adapter;
266 int ret = 0;
267
Holger Schurig9012b282007-05-25 11:27:16 -0400268 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269
270 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
271 memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
272 adapter->wpa_ie_len = assoc_req->wpa_ie_len;
273 } else {
274 memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
275 adapter->wpa_ie_len = 0;
276 }
277
Holger Schurig9012b282007-05-25 11:27:16 -0400278 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279 return ret;
280}
281
282
283static int should_deauth_infrastructure(wlan_adapter *adapter,
284 struct assoc_request * assoc_req)
285{
286 if (adapter->connect_status != libertas_connected)
287 return 0;
288
289 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400290 lbs_deb_assoc("Deauthenticating due to new SSID in "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291 " configuration request.\n");
292 return 1;
293 }
294
295 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
Dan Williams6affe782007-05-10 22:56:42 -0400296 if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig9012b282007-05-25 11:27:16 -0400297 lbs_deb_assoc("Deauthenticating due to updated security "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 "info in configuration request.\n");
299 return 1;
300 }
301 }
302
303 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400304 lbs_deb_assoc("Deauthenticating due to new BSSID in "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 " configuration request.\n");
306 return 1;
307 }
308
309 /* FIXME: deal with 'auto' mode somehow */
310 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400311 if (assoc_req->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 return 1;
313 }
314
315 return 0;
316}
317
318
319static int should_stop_adhoc(wlan_adapter *adapter,
320 struct assoc_request * assoc_req)
321{
322 if (adapter->connect_status != libertas_connected)
323 return 0;
324
325 if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
326 return 1;
327 if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
Dan Williamsad1f3292007-05-10 22:52:37 -0400328 adapter->curbssparams.ssid.ssidlength))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329 return 1;
330
331 /* FIXME: deal with 'auto' mode somehow */
332 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400333 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 return 1;
335 }
336
337 return 0;
338}
339
340
Holger Schurigeb3ce632007-05-24 23:41:15 -0400341void libertas_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342{
343 wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
344 wlan_adapter *adapter = priv->adapter;
345 struct assoc_request * assoc_req = NULL;
346 int ret = 0;
347 int find_any_ssid = 0;
348
Holger Schurig9012b282007-05-25 11:27:16 -0400349 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350
351 mutex_lock(&adapter->lock);
352 assoc_req = adapter->assoc_req;
353 adapter->assoc_req = NULL;
354 mutex_unlock(&adapter->lock);
355
Holger Schurig9012b282007-05-25 11:27:16 -0400356 if (!assoc_req)
357 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
Holger Schurig9012b282007-05-25 11:27:16 -0400359 lbs_deb_assoc("ASSOC: starting new association request: flags = 0x%lX\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360 assoc_req->flags);
361
362 /* If 'any' SSID was specified, find an SSID to associate with */
363 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
364 && !assoc_req->ssid.ssidlength)
365 find_any_ssid = 1;
366
367 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
368 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
369 if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN)
370 && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN))
371 find_any_ssid = 0;
372 }
373
374 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400375 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376
377 ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
378 assoc_req->mode, &new_mode);
379 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400380 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381 ret = -ENETUNREACH;
382 goto out;
383 }
384
385 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400386 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
388 assoc_req->mode = new_mode;
389 }
390 }
391
392 /*
393 * Check if the attributes being changing require deauthentication
394 * from the currently associated infrastructure access point.
395 */
Dan Williams0dc5a292007-05-10 22:58:02 -0400396 if (adapter->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397 if (should_deauth_infrastructure(adapter, assoc_req)) {
398 ret = libertas_send_deauthentication(priv);
399 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400400 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401 "configuration request failed: %d\n",
402 ret);
403 }
404 }
Dan Williams0dc5a292007-05-10 22:58:02 -0400405 } else if (adapter->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 if (should_stop_adhoc(adapter, assoc_req)) {
407 ret = libertas_stop_adhoc_network(priv);
408 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400409 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 "new configuration request failed: %d\n",
411 ret);
412 }
413
414 }
415 }
416
417 /* Send the various configuration bits to the firmware */
418 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
419 ret = assoc_helper_mode(priv, assoc_req);
420 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400421lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422 goto out;
423 }
424 }
425
426 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
427 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
428 ret = assoc_helper_wep_keys(priv, assoc_req);
429 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400430lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 goto out;
432 }
433 }
434
435 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
436 ret = assoc_helper_secinfo(priv, assoc_req);
437 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400438lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 goto out;
440 }
441 }
442
443 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
444 ret = assoc_helper_wpa_ie(priv, assoc_req);
445 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400446lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 goto out;
448 }
449 }
450
451 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
452 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
453 ret = assoc_helper_wpa_keys(priv, assoc_req);
454 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400455lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200456 goto out;
457 }
458 }
459
460 /* SSID/BSSID should be the _last_ config option set, because they
461 * trigger the association attempt.
462 */
463 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
464 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
465 int success = 1;
466
467 ret = assoc_helper_associate(priv, assoc_req);
468 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400469 lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 ret);
471 success = 0;
472 }
473
474 if (adapter->connect_status != libertas_connected) {
Holger Schurig9012b282007-05-25 11:27:16 -0400475 lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 "not connected.\n");
477 success = 0;
478 }
479
480 if (success) {
Holger Schurig9012b282007-05-25 11:27:16 -0400481 lbs_deb_assoc("ASSOC: association attempt successful. "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200482 "Associated to '%s' (" MAC_FMT ")\n",
483 assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid));
484 libertas_prepare_and_send_command(priv,
485 cmd_802_11_rssi,
486 0, cmd_option_waitforrsp, 0, NULL);
487
488 libertas_prepare_and_send_command(priv,
489 cmd_802_11_get_log,
490 0, cmd_option_waitforrsp, 0, NULL);
491 } else {
492
493 ret = -1;
494 }
495 }
496
497out:
498 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400499 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500 ret);
501 }
502 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400503
504done:
505 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200506}
507
508
509/*
510 * Caller MUST hold any necessary locks
511 */
512struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
513{
514 struct assoc_request * assoc_req;
515
516 if (!adapter->assoc_req) {
517 adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL);
518 if (!adapter->assoc_req) {
519 lbs_pr_info("Not enough memory to allocate association"
520 " request!\n");
521 return NULL;
522 }
523 }
524
525 /* Copy current configuration attributes to the association request,
526 * but don't overwrite any that are already set.
527 */
528 assoc_req = adapter->assoc_req;
529 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
530 memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid,
531 adapter->curbssparams.ssid.ssidlength);
532 }
533
534 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
535 assoc_req->channel = adapter->curbssparams.channel;
536
537 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
Dan Williams0dc5a292007-05-10 22:58:02 -0400538 assoc_req->mode = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539
540 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
541 memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
542 ETH_ALEN);
543 }
544
545 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
546 int i;
547 for (i = 0; i < 4; i++) {
548 memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
549 sizeof(struct WLAN_802_11_KEY));
550 }
551 }
552
553 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
554 assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
555
556 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
557 memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
558 sizeof(struct WLAN_802_11_KEY));
559 }
560
561 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
562 memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
563 sizeof(struct WLAN_802_11_KEY));
564 }
565
566 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
567 memcpy(&assoc_req->secinfo, &adapter->secinfo,
568 sizeof(struct wlan_802_11_security));
569 }
570
571 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
572 memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
573 MAX_WPA_IE_LEN);
574 assoc_req->wpa_ie_len = adapter->wpa_ie_len;
575 }
576
577 return assoc_req;
578}
579
580