Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[deliverable/linux.git] / drivers / net / wireless / libertas / assoc.c
CommitLineData
876c9d3a
MT
1/* Copyright (C) 2006, Red Hat, Inc. */
2
3#include <linux/bitops.h>
4#include <net/ieee80211.h>
3cf20931 5#include <linux/etherdevice.h>
876c9d3a
MT
6
7#include "assoc.h"
8#include "join.h"
9#include "decl.h"
10#include "hostcmd.h"
11#include "host.h"
2dd4b262 12#include "cmd.h"
876c9d3a
MT
13
14
5a6e0434
IH
15static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) =
16 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
17static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) =
18 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
876c9d3a 19
e76850d6 20
69f9032d 21static int assoc_helper_essid(struct lbs_private *priv,
876c9d3a
MT
22 struct assoc_request * assoc_req)
23{
876c9d3a 24 int ret = 0;
fcdb53db 25 struct bss_descriptor * bss;
aeea0ab4 26 int channel = -1;
876c9d3a 27
9012b28a 28 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 29
ef9a264b
DW
30 /* FIXME: take channel into account when picking SSIDs if a channel
31 * is set.
32 */
33
aeea0ab4
DW
34 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
35 channel = assoc_req->channel;
36
0765af44 37 lbs_deb_assoc("SSID '%s' requested\n",
d8efea25 38 escape_essid(assoc_req->ssid, assoc_req->ssid_len));
0dc5a290 39 if (assoc_req->mode == IW_MODE_INFRA) {
10078321 40 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
6e22a855 41 assoc_req->ssid_len, 0);
876c9d3a 42
aa21c004 43 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
d8efea25 44 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
fcdb53db 45 if (bss != NULL) {
e76850d6 46 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
10078321 47 ret = lbs_associate(priv, assoc_req);
876c9d3a 48 } else {
d8efea25 49 lbs_deb_assoc("SSID not found; cannot associate\n");
876c9d3a 50 }
0dc5a290 51 } else if (assoc_req->mode == IW_MODE_ADHOC) {
876c9d3a
MT
52 /* Scan for the network, do not save previous results. Stale
53 * scan data will cause us to join a non-existant adhoc network
54 */
10078321 55 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
d8efea25 56 assoc_req->ssid_len, 1);
876c9d3a
MT
57
58 /* Search for the requested SSID in the scan table */
aa21c004 59 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
d8efea25 60 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
fcdb53db 61 if (bss != NULL) {
d8efea25 62 lbs_deb_assoc("SSID found, will join\n");
e76850d6 63 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
10078321 64 lbs_join_adhoc_network(priv, assoc_req);
876c9d3a
MT
65 } else {
66 /* else send START command */
d8efea25 67 lbs_deb_assoc("SSID not found, creating adhoc network\n");
e76850d6 68 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
d8efea25
DW
69 IW_ESSID_MAX_SIZE);
70 assoc_req->bss.ssid_len = assoc_req->ssid_len;
10078321 71 lbs_start_adhoc_network(priv, assoc_req);
876c9d3a 72 }
876c9d3a
MT
73 }
74
9012b28a 75 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
76 return ret;
77}
78
79
69f9032d 80static int assoc_helper_bssid(struct lbs_private *priv,
876c9d3a
MT
81 struct assoc_request * assoc_req)
82{
fcdb53db
DW
83 int ret = 0;
84 struct bss_descriptor * bss;
0795af57 85 DECLARE_MAC_BUF(mac);
876c9d3a 86
0795af57
JP
87 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s",
88 print_mac(mac, assoc_req->bssid));
876c9d3a
MT
89
90 /* Search for index position in list for requested MAC */
aa21c004 91 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
876c9d3a 92 assoc_req->mode);
fcdb53db 93 if (bss == NULL) {
0795af57
JP
94 lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, "
95 "cannot associate.\n", print_mac(mac, assoc_req->bssid));
876c9d3a
MT
96 goto out;
97 }
98
e76850d6 99 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
0dc5a290 100 if (assoc_req->mode == IW_MODE_INFRA) {
10078321
HS
101 ret = lbs_associate(priv, assoc_req);
102 lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret);
0dc5a290 103 } else if (assoc_req->mode == IW_MODE_ADHOC) {
10078321 104 lbs_join_adhoc_network(priv, assoc_req);
876c9d3a 105 }
876c9d3a
MT
106
107out:
9012b28a 108 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
109 return ret;
110}
111
112
69f9032d 113static int assoc_helper_associate(struct lbs_private *priv,
876c9d3a
MT
114 struct assoc_request * assoc_req)
115{
116 int ret = 0, done = 0;
117
0765af44
HS
118 lbs_deb_enter(LBS_DEB_ASSOC);
119
876c9d3a
MT
120 /* If we're given and 'any' BSSID, try associating based on SSID */
121
122 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
3cf20931
DW
123 if (compare_ether_addr(bssid_any, assoc_req->bssid)
124 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
876c9d3a
MT
125 ret = assoc_helper_bssid(priv, assoc_req);
126 done = 1;
876c9d3a
MT
127 }
128 }
129
130 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
131 ret = assoc_helper_essid(priv, assoc_req);
876c9d3a
MT
132 }
133
0765af44 134 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
135 return ret;
136}
137
138
69f9032d 139static int assoc_helper_mode(struct lbs_private *priv,
876c9d3a
MT
140 struct assoc_request * assoc_req)
141{
876c9d3a
MT
142 int ret = 0;
143
9012b28a 144 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 145
aa21c004 146 if (assoc_req->mode == priv->mode)
9012b28a 147 goto done;
876c9d3a 148
0dc5a290 149 if (assoc_req->mode == IW_MODE_INFRA) {
aa21c004 150 if (priv->psstate != PS_STATE_FULL_POWER)
10078321 151 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
aa21c004 152 priv->psmode = LBS802_11POWERMODECAM;
876c9d3a
MT
153 }
154
aa21c004 155 priv->mode = assoc_req->mode;
10078321 156 ret = lbs_prepare_and_send_command(priv,
0aef64d7
DW
157 CMD_802_11_SNMP_MIB,
158 0, CMD_OPTION_WAITFORRSP,
876c9d3a 159 OID_802_11_INFRASTRUCTURE_MODE,
981f187b 160 /* Shoot me now */ (void *) (size_t) assoc_req->mode);
876c9d3a 161
9012b28a
HS
162done:
163 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
164 return ret;
165}
166
167
9f462577 168int lbs_update_channel(struct lbs_private *priv)
ef9a264b 169{
0765af44 170 int ret;
2dd4b262 171
d1a469fd 172 /* the channel in f/w could be out of sync; get the current channel */
0765af44 173 lbs_deb_enter(LBS_DEB_ASSOC);
2dd4b262
DW
174
175 ret = lbs_get_channel(priv);
d1a469fd
DW
176 if (ret > 0) {
177 priv->curbssparams.channel = ret;
178 ret = 0;
179 }
0765af44
HS
180 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
181 return ret;
ef9a264b
DW
182}
183
10078321 184void lbs_sync_channel(struct work_struct *work)
b8bedefd 185{
69f9032d
HS
186 struct lbs_private *priv = container_of(work, struct lbs_private,
187 sync_channel);
b8bedefd 188
0765af44 189 lbs_deb_enter(LBS_DEB_ASSOC);
9f462577 190 if (lbs_update_channel(priv))
b8bedefd 191 lbs_pr_info("Channel synchronization failed.");
0765af44 192 lbs_deb_leave(LBS_DEB_ASSOC);
b8bedefd
LCCR
193}
194
69f9032d 195static int assoc_helper_channel(struct lbs_private *priv,
ef9a264b
DW
196 struct assoc_request * assoc_req)
197{
ef9a264b
DW
198 int ret = 0;
199
200 lbs_deb_enter(LBS_DEB_ASSOC);
201
9f462577 202 ret = lbs_update_channel(priv);
d1a469fd 203 if (ret) {
23d36eec 204 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
d1a469fd 205 goto done;
ef9a264b
DW
206 }
207
aa21c004 208 if (assoc_req->channel == priv->curbssparams.channel)
ef9a264b
DW
209 goto done;
210
8642f1f0 211 if (priv->mesh_dev) {
86062134
DW
212 /* Change mesh channel first; 21.p21 firmware won't let
213 you change channel otherwise (even though it'll return
214 an error to this */
215 lbs_mesh_config(priv, 0, assoc_req->channel);
8642f1f0
DW
216 }
217
ef9a264b 218 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
86062134 219 priv->curbssparams.channel, assoc_req->channel);
ef9a264b 220
2dd4b262
DW
221 ret = lbs_set_channel(priv, assoc_req->channel);
222 if (ret < 0)
23d36eec 223 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
ef9a264b 224
2dd4b262
DW
225 /* FIXME: shouldn't need to grab the channel _again_ after setting
226 * it since the firmware is supposed to return the new channel, but
227 * whatever... */
9f462577 228 ret = lbs_update_channel(priv);
d1a469fd 229 if (ret) {
23d36eec 230 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
d1a469fd
DW
231 goto done;
232 }
ef9a264b 233
aa21c004 234 if (assoc_req->channel != priv->curbssparams.channel) {
88ae2915 235 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
ef9a264b 236 assoc_req->channel);
8642f1f0 237 goto restore_mesh;
ef9a264b
DW
238 }
239
240 if ( assoc_req->secinfo.wep_enabled
241 && (assoc_req->wep_keys[0].len
242 || assoc_req->wep_keys[1].len
243 || assoc_req->wep_keys[2].len
244 || assoc_req->wep_keys[3].len)) {
245 /* Make sure WEP keys are re-sent to firmware */
246 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
247 }
248
249 /* Must restart/rejoin adhoc networks after channel change */
23d36eec 250 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
ef9a264b 251
8642f1f0
DW
252 restore_mesh:
253 if (priv->mesh_dev)
86062134 254 lbs_mesh_config(priv, 1, priv->curbssparams.channel);
8642f1f0
DW
255
256 done:
ef9a264b
DW
257 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
258 return ret;
259}
260
261
69f9032d 262static int assoc_helper_wep_keys(struct lbs_private *priv,
f70dd451 263 struct assoc_request *assoc_req)
876c9d3a 264{
876c9d3a
MT
265 int i;
266 int ret = 0;
267
9012b28a 268 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a
MT
269
270 /* Set or remove WEP keys */
f70dd451
DW
271 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
272 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
273 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
274 else
275 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
876c9d3a
MT
276
277 if (ret)
278 goto out;
279
280 /* enable/disable the MAC's WEP packet filter */
889c05bd 281 if (assoc_req->secinfo.wep_enabled)
aa21c004 282 priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
876c9d3a 283 else
aa21c004 284 priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
f70dd451 285
10078321 286 ret = lbs_set_mac_packet_filter(priv);
876c9d3a
MT
287 if (ret)
288 goto out;
289
aa21c004 290 mutex_lock(&priv->lock);
876c9d3a 291
aa21c004 292 /* Copy WEP keys into priv wep key fields */
876c9d3a 293 for (i = 0; i < 4; i++) {
aa21c004 294 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
f70dd451 295 sizeof(struct enc_key));
876c9d3a 296 }
aa21c004 297 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
876c9d3a 298
aa21c004 299 mutex_unlock(&priv->lock);
876c9d3a
MT
300
301out:
9012b28a 302 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
303 return ret;
304}
305
69f9032d 306static int assoc_helper_secinfo(struct lbs_private *priv,
876c9d3a
MT
307 struct assoc_request * assoc_req)
308{
876c9d3a 309 int ret = 0;
4f59abf1
DW
310 uint16_t do_wpa;
311 uint16_t rsn = 0;
876c9d3a 312
9012b28a 313 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 314
aa21c004 315 memcpy(&priv->secinfo, &assoc_req->secinfo,
10078321 316 sizeof(struct lbs_802_11_security));
876c9d3a 317
10078321 318 ret = lbs_set_mac_packet_filter(priv);
90a42210
DW
319 if (ret)
320 goto out;
876c9d3a 321
18c96c34
DW
322 /* If RSN is already enabled, don't try to enable it again, since
323 * ENABLE_RSN resets internal state machines and will clobber the
324 * 4-way WPA handshake.
325 */
326
327 /* Get RSN enabled/disabled */
4f59abf1 328 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
18c96c34 329 if (ret) {
23d36eec 330 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
18c96c34
DW
331 goto out;
332 }
333
334 /* Don't re-enable RSN if it's already enabled */
4f59abf1 335 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
18c96c34
DW
336 if (do_wpa == rsn)
337 goto out;
338
339 /* Set RSN enabled/disabled */
4f59abf1 340 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
90a42210
DW
341
342out:
9012b28a 343 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
344 return ret;
345}
346
347
69f9032d 348static int assoc_helper_wpa_keys(struct lbs_private *priv,
876c9d3a
MT
349 struct assoc_request * assoc_req)
350{
351 int ret = 0;
2bcde51d 352 unsigned int flags = assoc_req->flags;
876c9d3a 353
9012b28a 354 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 355
2bcde51d
DW
356 /* Work around older firmware bug where WPA unicast and multicast
357 * keys must be set independently. Seen in SDIO parts with firmware
358 * version 5.0.11p0.
359 */
876c9d3a 360
2bcde51d
DW
361 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
362 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
10078321 363 ret = lbs_prepare_and_send_command(priv,
2bcde51d
DW
364 CMD_802_11_KEY_MATERIAL,
365 CMD_ACT_SET,
366 CMD_OPTION_WAITFORRSP,
367 0, assoc_req);
368 assoc_req->flags = flags;
369 }
370
371 if (ret)
372 goto out;
373
374 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
375 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
376
10078321 377 ret = lbs_prepare_and_send_command(priv,
2bcde51d
DW
378 CMD_802_11_KEY_MATERIAL,
379 CMD_ACT_SET,
380 CMD_OPTION_WAITFORRSP,
381 0, assoc_req);
382 assoc_req->flags = flags;
383 }
384
385out:
9012b28a 386 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
387 return ret;
388}
389
390
69f9032d 391static int assoc_helper_wpa_ie(struct lbs_private *priv,
876c9d3a
MT
392 struct assoc_request * assoc_req)
393{
876c9d3a
MT
394 int ret = 0;
395
9012b28a 396 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a
MT
397
398 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
aa21c004
DW
399 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
400 priv->wpa_ie_len = assoc_req->wpa_ie_len;
876c9d3a 401 } else {
aa21c004
DW
402 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
403 priv->wpa_ie_len = 0;
876c9d3a
MT
404 }
405
9012b28a 406 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
407 return ret;
408}
409
410
aa21c004 411static int should_deauth_infrastructure(struct lbs_private *priv,
876c9d3a
MT
412 struct assoc_request * assoc_req)
413{
0765af44
HS
414 int ret = 0;
415
416 lbs_deb_enter(LBS_DEB_ASSOC);
417
aa21c004 418 if (priv->connect_status != LBS_CONNECTED)
876c9d3a
MT
419 return 0;
420
421 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
0765af44
HS
422 lbs_deb_assoc("Deauthenticating due to new SSID\n");
423 ret = 1;
424 goto out;
876c9d3a
MT
425 }
426
427 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
aa21c004 428 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
0765af44
HS
429 lbs_deb_assoc("Deauthenticating due to new security\n");
430 ret = 1;
431 goto out;
876c9d3a
MT
432 }
433 }
434
435 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
0765af44
HS
436 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
437 ret = 1;
438 goto out;
876c9d3a
MT
439 }
440
fff47f10 441 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
0765af44
HS
442 lbs_deb_assoc("Deauthenticating due to channel switch\n");
443 ret = 1;
444 goto out;
fff47f10
LCCR
445 }
446
876c9d3a
MT
447 /* FIXME: deal with 'auto' mode somehow */
448 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
0765af44
HS
449 if (assoc_req->mode != IW_MODE_INFRA) {
450 lbs_deb_assoc("Deauthenticating due to leaving "
451 "infra mode\n");
452 ret = 1;
453 goto out;
454 }
876c9d3a
MT
455 }
456
0765af44
HS
457out:
458 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
459 return 0;
460}
461
462
aa21c004 463static int should_stop_adhoc(struct lbs_private *priv,
876c9d3a
MT
464 struct assoc_request * assoc_req)
465{
0765af44
HS
466 lbs_deb_enter(LBS_DEB_ASSOC);
467
aa21c004 468 if (priv->connect_status != LBS_CONNECTED)
876c9d3a
MT
469 return 0;
470
aa21c004
DW
471 if (lbs_ssid_cmp(priv->curbssparams.ssid,
472 priv->curbssparams.ssid_len,
d8efea25 473 assoc_req->ssid, assoc_req->ssid_len) != 0)
876c9d3a
MT
474 return 1;
475
476 /* FIXME: deal with 'auto' mode somehow */
477 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
0dc5a290 478 if (assoc_req->mode != IW_MODE_ADHOC)
876c9d3a
MT
479 return 1;
480 }
481
ef9a264b 482 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
aa21c004 483 if (assoc_req->channel != priv->curbssparams.channel)
ef9a264b
DW
484 return 1;
485 }
486
0765af44 487 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
488 return 0;
489}
490
491
10078321 492void lbs_association_worker(struct work_struct *work)
876c9d3a 493{
69f9032d
HS
494 struct lbs_private *priv = container_of(work, struct lbs_private,
495 assoc_work.work);
876c9d3a
MT
496 struct assoc_request * assoc_req = NULL;
497 int ret = 0;
498 int find_any_ssid = 0;
0795af57 499 DECLARE_MAC_BUF(mac);
876c9d3a 500
9012b28a 501 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 502
aa21c004
DW
503 mutex_lock(&priv->lock);
504 assoc_req = priv->pending_assoc_req;
505 priv->pending_assoc_req = NULL;
506 priv->in_progress_assoc_req = assoc_req;
507 mutex_unlock(&priv->lock);
876c9d3a 508
9012b28a
HS
509 if (!assoc_req)
510 goto done;
876c9d3a 511
0765af44
HS
512 lbs_deb_assoc(
513 "Association Request:\n"
514 " flags: 0x%08lx\n"
515 " SSID: '%s'\n"
516 " chann: %d\n"
517 " band: %d\n"
518 " mode: %d\n"
519 " BSSID: %s\n"
520 " secinfo: %s%s%s\n"
521 " auth_mode: %d\n",
522 assoc_req->flags,
523 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
524 assoc_req->channel, assoc_req->band, assoc_req->mode,
525 print_mac(mac, assoc_req->bssid),
526 assoc_req->secinfo.WPAenabled ? " WPA" : "",
527 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
528 assoc_req->secinfo.wep_enabled ? " WEP" : "",
529 assoc_req->secinfo.auth_mode);
876c9d3a
MT
530
531 /* If 'any' SSID was specified, find an SSID to associate with */
532 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
d8efea25 533 && !assoc_req->ssid_len)
876c9d3a
MT
534 find_any_ssid = 1;
535
536 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
537 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
3cf20931
DW
538 if (compare_ether_addr(assoc_req->bssid, bssid_any)
539 && compare_ether_addr(assoc_req->bssid, bssid_off))
876c9d3a
MT
540 find_any_ssid = 0;
541 }
542
543 if (find_any_ssid) {
877cb0d4 544 u8 new_mode = assoc_req->mode;
876c9d3a 545
10078321 546 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
d8efea25 547 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
876c9d3a 548 if (ret) {
9012b28a 549 lbs_deb_assoc("Could not find best network\n");
876c9d3a
MT
550 ret = -ENETUNREACH;
551 goto out;
552 }
553
554 /* Ensure we switch to the mode of the AP */
0dc5a290 555 if (assoc_req->mode == IW_MODE_AUTO) {
876c9d3a
MT
556 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
557 assoc_req->mode = new_mode;
558 }
559 }
560
561 /*
562 * Check if the attributes being changing require deauthentication
563 * from the currently associated infrastructure access point.
564 */
aa21c004
DW
565 if (priv->mode == IW_MODE_INFRA) {
566 if (should_deauth_infrastructure(priv, assoc_req)) {
10078321 567 ret = lbs_send_deauthentication(priv);
876c9d3a 568 if (ret) {
9012b28a 569 lbs_deb_assoc("Deauthentication due to new "
876c9d3a
MT
570 "configuration request failed: %d\n",
571 ret);
572 }
573 }
aa21c004
DW
574 } else if (priv->mode == IW_MODE_ADHOC) {
575 if (should_stop_adhoc(priv, assoc_req)) {
10078321 576 ret = lbs_stop_adhoc_network(priv);
876c9d3a 577 if (ret) {
9012b28a 578 lbs_deb_assoc("Teardown of AdHoc network due to "
876c9d3a
MT
579 "new configuration request failed: %d\n",
580 ret);
581 }
582
583 }
584 }
585
586 /* Send the various configuration bits to the firmware */
587 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
588 ret = assoc_helper_mode(priv, assoc_req);
0765af44 589 if (ret)
876c9d3a 590 goto out;
876c9d3a
MT
591 }
592
ef9a264b
DW
593 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
594 ret = assoc_helper_channel(priv, assoc_req);
0765af44 595 if (ret)
ef9a264b 596 goto out;
ef9a264b
DW
597 }
598
876c9d3a
MT
599 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
600 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
601 ret = assoc_helper_wep_keys(priv, assoc_req);
0765af44 602 if (ret)
876c9d3a 603 goto out;
876c9d3a
MT
604 }
605
606 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
607 ret = assoc_helper_secinfo(priv, assoc_req);
0765af44 608 if (ret)
876c9d3a 609 goto out;
876c9d3a
MT
610 }
611
612 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
613 ret = assoc_helper_wpa_ie(priv, assoc_req);
0765af44 614 if (ret)
876c9d3a 615 goto out;
876c9d3a
MT
616 }
617
618 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
619 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
620 ret = assoc_helper_wpa_keys(priv, assoc_req);
0765af44 621 if (ret)
876c9d3a 622 goto out;
876c9d3a
MT
623 }
624
625 /* SSID/BSSID should be the _last_ config option set, because they
626 * trigger the association attempt.
627 */
628 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
629 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
630 int success = 1;
631
632 ret = assoc_helper_associate(priv, assoc_req);
633 if (ret) {
91843463 634 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
876c9d3a
MT
635 ret);
636 success = 0;
637 }
638
aa21c004 639 if (priv->connect_status != LBS_CONNECTED) {
91843463
HS
640 lbs_deb_assoc("ASSOC: association unsuccessful, "
641 "not connected\n");
876c9d3a
MT
642 success = 0;
643 }
644
645 if (success) {
91843463 646 lbs_deb_assoc("ASSOC: associated to '%s', %s\n",
aa21c004
DW
647 escape_essid(priv->curbssparams.ssid,
648 priv->curbssparams.ssid_len),
649 print_mac(mac, priv->curbssparams.bssid));
10078321 650 lbs_prepare_and_send_command(priv,
0aef64d7
DW
651 CMD_802_11_RSSI,
652 0, CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 653
10078321 654 lbs_prepare_and_send_command(priv,
0aef64d7
DW
655 CMD_802_11_GET_LOG,
656 0, CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 657 } else {
876c9d3a
MT
658 ret = -1;
659 }
660 }
661
662out:
663 if (ret) {
9012b28a 664 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
876c9d3a
MT
665 ret);
666 }
e76850d6 667
aa21c004
DW
668 mutex_lock(&priv->lock);
669 priv->in_progress_assoc_req = NULL;
670 mutex_unlock(&priv->lock);
876c9d3a 671 kfree(assoc_req);
9012b28a
HS
672
673done:
674 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
675}
676
677
678/*
679 * Caller MUST hold any necessary locks
680 */
aa21c004 681struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
876c9d3a
MT
682{
683 struct assoc_request * assoc_req;
684
0765af44 685 lbs_deb_enter(LBS_DEB_ASSOC);
aa21c004
DW
686 if (!priv->pending_assoc_req) {
687 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
e76850d6 688 GFP_KERNEL);
aa21c004 689 if (!priv->pending_assoc_req) {
876c9d3a
MT
690 lbs_pr_info("Not enough memory to allocate association"
691 " request!\n");
692 return NULL;
693 }
694 }
695
696 /* Copy current configuration attributes to the association request,
697 * but don't overwrite any that are already set.
698 */
aa21c004 699 assoc_req = priv->pending_assoc_req;
876c9d3a 700 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
aa21c004 701 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
d8efea25 702 IW_ESSID_MAX_SIZE);
aa21c004 703 assoc_req->ssid_len = priv->curbssparams.ssid_len;
876c9d3a
MT
704 }
705
706 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
aa21c004 707 assoc_req->channel = priv->curbssparams.channel;
876c9d3a 708
e76850d6 709 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
aa21c004 710 assoc_req->band = priv->curbssparams.band;
e76850d6 711
876c9d3a 712 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
aa21c004 713 assoc_req->mode = priv->mode;
876c9d3a
MT
714
715 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
aa21c004 716 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
876c9d3a
MT
717 ETH_ALEN);
718 }
719
720 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
721 int i;
722 for (i = 0; i < 4; i++) {
aa21c004 723 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
1443b653 724 sizeof(struct enc_key));
876c9d3a
MT
725 }
726 }
727
728 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
aa21c004 729 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
876c9d3a
MT
730
731 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
aa21c004 732 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
1443b653 733 sizeof(struct enc_key));
876c9d3a
MT
734 }
735
736 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
aa21c004 737 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
1443b653 738 sizeof(struct enc_key));
876c9d3a
MT
739 }
740
741 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
aa21c004 742 memcpy(&assoc_req->secinfo, &priv->secinfo,
10078321 743 sizeof(struct lbs_802_11_security));
876c9d3a
MT
744 }
745
746 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
aa21c004 747 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
876c9d3a 748 MAX_WPA_IE_LEN);
aa21c004 749 assoc_req->wpa_ie_len = priv->wpa_ie_len;
876c9d3a
MT
750 }
751
0765af44 752 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
753 return assoc_req;
754}
This page took 0.416005 seconds and 5 git commands to generate.