the scheduled rc80211-simple.c removal
[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
69f9032d 184static int assoc_helper_channel(struct lbs_private *priv,
ef9a264b
DW
185 struct assoc_request * assoc_req)
186{
ef9a264b
DW
187 int ret = 0;
188
189 lbs_deb_enter(LBS_DEB_ASSOC);
190
9f462577 191 ret = lbs_update_channel(priv);
d1a469fd 192 if (ret) {
23d36eec 193 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
d1a469fd 194 goto done;
ef9a264b
DW
195 }
196
aa21c004 197 if (assoc_req->channel == priv->curbssparams.channel)
ef9a264b
DW
198 goto done;
199
8642f1f0 200 if (priv->mesh_dev) {
86062134
DW
201 /* Change mesh channel first; 21.p21 firmware won't let
202 you change channel otherwise (even though it'll return
203 an error to this */
204 lbs_mesh_config(priv, 0, assoc_req->channel);
8642f1f0
DW
205 }
206
ef9a264b 207 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
86062134 208 priv->curbssparams.channel, assoc_req->channel);
ef9a264b 209
2dd4b262
DW
210 ret = lbs_set_channel(priv, assoc_req->channel);
211 if (ret < 0)
23d36eec 212 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
ef9a264b 213
2dd4b262
DW
214 /* FIXME: shouldn't need to grab the channel _again_ after setting
215 * it since the firmware is supposed to return the new channel, but
216 * whatever... */
9f462577 217 ret = lbs_update_channel(priv);
d1a469fd 218 if (ret) {
23d36eec 219 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
d1a469fd
DW
220 goto done;
221 }
ef9a264b 222
aa21c004 223 if (assoc_req->channel != priv->curbssparams.channel) {
88ae2915 224 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
ef9a264b 225 assoc_req->channel);
8642f1f0 226 goto restore_mesh;
ef9a264b
DW
227 }
228
229 if ( assoc_req->secinfo.wep_enabled
230 && (assoc_req->wep_keys[0].len
231 || assoc_req->wep_keys[1].len
232 || assoc_req->wep_keys[2].len
233 || assoc_req->wep_keys[3].len)) {
234 /* Make sure WEP keys are re-sent to firmware */
235 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
236 }
237
238 /* Must restart/rejoin adhoc networks after channel change */
23d36eec 239 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
ef9a264b 240
8642f1f0
DW
241 restore_mesh:
242 if (priv->mesh_dev)
86062134 243 lbs_mesh_config(priv, 1, priv->curbssparams.channel);
8642f1f0
DW
244
245 done:
ef9a264b
DW
246 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
247 return ret;
248}
249
250
69f9032d 251static int assoc_helper_wep_keys(struct lbs_private *priv,
f70dd451 252 struct assoc_request *assoc_req)
876c9d3a 253{
876c9d3a
MT
254 int i;
255 int ret = 0;
256
9012b28a 257 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a
MT
258
259 /* Set or remove WEP keys */
f70dd451
DW
260 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
261 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
262 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
263 else
264 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
876c9d3a
MT
265
266 if (ret)
267 goto out;
268
269 /* enable/disable the MAC's WEP packet filter */
889c05bd 270 if (assoc_req->secinfo.wep_enabled)
aa21c004 271 priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
876c9d3a 272 else
aa21c004 273 priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
f70dd451 274
10078321 275 ret = lbs_set_mac_packet_filter(priv);
876c9d3a
MT
276 if (ret)
277 goto out;
278
aa21c004 279 mutex_lock(&priv->lock);
876c9d3a 280
aa21c004 281 /* Copy WEP keys into priv wep key fields */
876c9d3a 282 for (i = 0; i < 4; i++) {
aa21c004 283 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
f70dd451 284 sizeof(struct enc_key));
876c9d3a 285 }
aa21c004 286 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
876c9d3a 287
aa21c004 288 mutex_unlock(&priv->lock);
876c9d3a
MT
289
290out:
9012b28a 291 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
292 return ret;
293}
294
69f9032d 295static int assoc_helper_secinfo(struct lbs_private *priv,
876c9d3a
MT
296 struct assoc_request * assoc_req)
297{
876c9d3a 298 int ret = 0;
4f59abf1
DW
299 uint16_t do_wpa;
300 uint16_t rsn = 0;
876c9d3a 301
9012b28a 302 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 303
aa21c004 304 memcpy(&priv->secinfo, &assoc_req->secinfo,
10078321 305 sizeof(struct lbs_802_11_security));
876c9d3a 306
10078321 307 ret = lbs_set_mac_packet_filter(priv);
90a42210
DW
308 if (ret)
309 goto out;
876c9d3a 310
18c96c34
DW
311 /* If RSN is already enabled, don't try to enable it again, since
312 * ENABLE_RSN resets internal state machines and will clobber the
313 * 4-way WPA handshake.
314 */
315
316 /* Get RSN enabled/disabled */
4f59abf1 317 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
18c96c34 318 if (ret) {
23d36eec 319 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
18c96c34
DW
320 goto out;
321 }
322
323 /* Don't re-enable RSN if it's already enabled */
4f59abf1 324 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
18c96c34
DW
325 if (do_wpa == rsn)
326 goto out;
327
328 /* Set RSN enabled/disabled */
4f59abf1 329 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
90a42210
DW
330
331out:
9012b28a 332 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
333 return ret;
334}
335
336
69f9032d 337static int assoc_helper_wpa_keys(struct lbs_private *priv,
876c9d3a
MT
338 struct assoc_request * assoc_req)
339{
340 int ret = 0;
2bcde51d 341 unsigned int flags = assoc_req->flags;
876c9d3a 342
9012b28a 343 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 344
2bcde51d
DW
345 /* Work around older firmware bug where WPA unicast and multicast
346 * keys must be set independently. Seen in SDIO parts with firmware
347 * version 5.0.11p0.
348 */
876c9d3a 349
2bcde51d
DW
350 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
351 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
9e1228d0 352 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
2bcde51d
DW
353 assoc_req->flags = flags;
354 }
355
356 if (ret)
357 goto out;
358
359 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
360 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
361
9e1228d0 362 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
2bcde51d
DW
363 assoc_req->flags = flags;
364 }
365
366out:
9012b28a 367 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
368 return ret;
369}
370
371
69f9032d 372static int assoc_helper_wpa_ie(struct lbs_private *priv,
876c9d3a
MT
373 struct assoc_request * assoc_req)
374{
876c9d3a
MT
375 int ret = 0;
376
9012b28a 377 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a
MT
378
379 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
aa21c004
DW
380 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
381 priv->wpa_ie_len = assoc_req->wpa_ie_len;
876c9d3a 382 } else {
aa21c004
DW
383 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
384 priv->wpa_ie_len = 0;
876c9d3a
MT
385 }
386
9012b28a 387 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
876c9d3a
MT
388 return ret;
389}
390
391
aa21c004 392static int should_deauth_infrastructure(struct lbs_private *priv,
876c9d3a
MT
393 struct assoc_request * assoc_req)
394{
0765af44
HS
395 int ret = 0;
396
aa21c004 397 if (priv->connect_status != LBS_CONNECTED)
876c9d3a
MT
398 return 0;
399
52507c20 400 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 401 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
0765af44
HS
402 lbs_deb_assoc("Deauthenticating due to new SSID\n");
403 ret = 1;
404 goto out;
876c9d3a
MT
405 }
406
407 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
aa21c004 408 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
0765af44
HS
409 lbs_deb_assoc("Deauthenticating due to new security\n");
410 ret = 1;
411 goto out;
876c9d3a
MT
412 }
413 }
414
415 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
0765af44
HS
416 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
417 ret = 1;
418 goto out;
876c9d3a
MT
419 }
420
fff47f10 421 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
0765af44
HS
422 lbs_deb_assoc("Deauthenticating due to channel switch\n");
423 ret = 1;
424 goto out;
fff47f10
LCCR
425 }
426
876c9d3a
MT
427 /* FIXME: deal with 'auto' mode somehow */
428 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
0765af44
HS
429 if (assoc_req->mode != IW_MODE_INFRA) {
430 lbs_deb_assoc("Deauthenticating due to leaving "
431 "infra mode\n");
432 ret = 1;
433 goto out;
434 }
876c9d3a
MT
435 }
436
0765af44
HS
437out:
438 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
52507c20 439 return ret;
876c9d3a
MT
440}
441
442
aa21c004 443static int should_stop_adhoc(struct lbs_private *priv,
876c9d3a
MT
444 struct assoc_request * assoc_req)
445{
0765af44
HS
446 lbs_deb_enter(LBS_DEB_ASSOC);
447
aa21c004 448 if (priv->connect_status != LBS_CONNECTED)
876c9d3a
MT
449 return 0;
450
aa21c004
DW
451 if (lbs_ssid_cmp(priv->curbssparams.ssid,
452 priv->curbssparams.ssid_len,
d8efea25 453 assoc_req->ssid, assoc_req->ssid_len) != 0)
876c9d3a
MT
454 return 1;
455
456 /* FIXME: deal with 'auto' mode somehow */
457 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
0dc5a290 458 if (assoc_req->mode != IW_MODE_ADHOC)
876c9d3a
MT
459 return 1;
460 }
461
ef9a264b 462 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
aa21c004 463 if (assoc_req->channel != priv->curbssparams.channel)
ef9a264b
DW
464 return 1;
465 }
466
0765af44 467 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
468 return 0;
469}
470
471
10078321 472void lbs_association_worker(struct work_struct *work)
876c9d3a 473{
69f9032d
HS
474 struct lbs_private *priv = container_of(work, struct lbs_private,
475 assoc_work.work);
876c9d3a
MT
476 struct assoc_request * assoc_req = NULL;
477 int ret = 0;
478 int find_any_ssid = 0;
0795af57 479 DECLARE_MAC_BUF(mac);
876c9d3a 480
9012b28a 481 lbs_deb_enter(LBS_DEB_ASSOC);
876c9d3a 482
aa21c004
DW
483 mutex_lock(&priv->lock);
484 assoc_req = priv->pending_assoc_req;
485 priv->pending_assoc_req = NULL;
486 priv->in_progress_assoc_req = assoc_req;
487 mutex_unlock(&priv->lock);
876c9d3a 488
9012b28a
HS
489 if (!assoc_req)
490 goto done;
876c9d3a 491
0765af44
HS
492 lbs_deb_assoc(
493 "Association Request:\n"
494 " flags: 0x%08lx\n"
495 " SSID: '%s'\n"
496 " chann: %d\n"
497 " band: %d\n"
498 " mode: %d\n"
499 " BSSID: %s\n"
500 " secinfo: %s%s%s\n"
501 " auth_mode: %d\n",
502 assoc_req->flags,
503 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
504 assoc_req->channel, assoc_req->band, assoc_req->mode,
505 print_mac(mac, assoc_req->bssid),
506 assoc_req->secinfo.WPAenabled ? " WPA" : "",
507 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
508 assoc_req->secinfo.wep_enabled ? " WEP" : "",
509 assoc_req->secinfo.auth_mode);
876c9d3a
MT
510
511 /* If 'any' SSID was specified, find an SSID to associate with */
512 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
d8efea25 513 && !assoc_req->ssid_len)
876c9d3a
MT
514 find_any_ssid = 1;
515
516 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
517 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
3cf20931
DW
518 if (compare_ether_addr(assoc_req->bssid, bssid_any)
519 && compare_ether_addr(assoc_req->bssid, bssid_off))
876c9d3a
MT
520 find_any_ssid = 0;
521 }
522
523 if (find_any_ssid) {
0dc5a290 524 u8 new_mode;
876c9d3a 525
10078321 526 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
d8efea25 527 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
876c9d3a 528 if (ret) {
9012b28a 529 lbs_deb_assoc("Could not find best network\n");
876c9d3a
MT
530 ret = -ENETUNREACH;
531 goto out;
532 }
533
534 /* Ensure we switch to the mode of the AP */
0dc5a290 535 if (assoc_req->mode == IW_MODE_AUTO) {
876c9d3a
MT
536 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
537 assoc_req->mode = new_mode;
538 }
539 }
540
541 /*
542 * Check if the attributes being changing require deauthentication
543 * from the currently associated infrastructure access point.
544 */
aa21c004
DW
545 if (priv->mode == IW_MODE_INFRA) {
546 if (should_deauth_infrastructure(priv, assoc_req)) {
10078321 547 ret = lbs_send_deauthentication(priv);
876c9d3a 548 if (ret) {
9012b28a 549 lbs_deb_assoc("Deauthentication due to new "
876c9d3a
MT
550 "configuration request failed: %d\n",
551 ret);
552 }
553 }
aa21c004
DW
554 } else if (priv->mode == IW_MODE_ADHOC) {
555 if (should_stop_adhoc(priv, assoc_req)) {
10078321 556 ret = lbs_stop_adhoc_network(priv);
876c9d3a 557 if (ret) {
9012b28a 558 lbs_deb_assoc("Teardown of AdHoc network due to "
876c9d3a
MT
559 "new configuration request failed: %d\n",
560 ret);
561 }
562
563 }
564 }
565
566 /* Send the various configuration bits to the firmware */
567 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
568 ret = assoc_helper_mode(priv, assoc_req);
0765af44 569 if (ret)
876c9d3a 570 goto out;
876c9d3a
MT
571 }
572
ef9a264b
DW
573 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
574 ret = assoc_helper_channel(priv, assoc_req);
0765af44 575 if (ret)
ef9a264b 576 goto out;
ef9a264b
DW
577 }
578
876c9d3a
MT
579 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
580 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
581 ret = assoc_helper_wep_keys(priv, assoc_req);
0765af44 582 if (ret)
876c9d3a 583 goto out;
876c9d3a
MT
584 }
585
586 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
587 ret = assoc_helper_secinfo(priv, assoc_req);
0765af44 588 if (ret)
876c9d3a 589 goto out;
876c9d3a
MT
590 }
591
592 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
593 ret = assoc_helper_wpa_ie(priv, assoc_req);
0765af44 594 if (ret)
876c9d3a 595 goto out;
876c9d3a
MT
596 }
597
598 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
599 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
600 ret = assoc_helper_wpa_keys(priv, assoc_req);
0765af44 601 if (ret)
876c9d3a 602 goto out;
876c9d3a
MT
603 }
604
605 /* SSID/BSSID should be the _last_ config option set, because they
606 * trigger the association attempt.
607 */
608 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
609 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
610 int success = 1;
611
612 ret = assoc_helper_associate(priv, assoc_req);
613 if (ret) {
91843463 614 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
876c9d3a
MT
615 ret);
616 success = 0;
617 }
618
aa21c004 619 if (priv->connect_status != LBS_CONNECTED) {
91843463
HS
620 lbs_deb_assoc("ASSOC: association unsuccessful, "
621 "not connected\n");
876c9d3a
MT
622 success = 0;
623 }
624
625 if (success) {
52507c20 626 lbs_deb_assoc("associated to %s\n",
aa21c004 627 print_mac(mac, priv->curbssparams.bssid));
10078321 628 lbs_prepare_and_send_command(priv,
0aef64d7
DW
629 CMD_802_11_RSSI,
630 0, CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 631
10078321 632 lbs_prepare_and_send_command(priv,
0aef64d7
DW
633 CMD_802_11_GET_LOG,
634 0, CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 635 } else {
876c9d3a
MT
636 ret = -1;
637 }
638 }
639
640out:
641 if (ret) {
9012b28a 642 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
876c9d3a
MT
643 ret);
644 }
e76850d6 645
aa21c004
DW
646 mutex_lock(&priv->lock);
647 priv->in_progress_assoc_req = NULL;
648 mutex_unlock(&priv->lock);
876c9d3a 649 kfree(assoc_req);
9012b28a
HS
650
651done:
652 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
653}
654
655
656/*
657 * Caller MUST hold any necessary locks
658 */
aa21c004 659struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
876c9d3a
MT
660{
661 struct assoc_request * assoc_req;
662
0765af44 663 lbs_deb_enter(LBS_DEB_ASSOC);
aa21c004
DW
664 if (!priv->pending_assoc_req) {
665 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
e76850d6 666 GFP_KERNEL);
aa21c004 667 if (!priv->pending_assoc_req) {
876c9d3a
MT
668 lbs_pr_info("Not enough memory to allocate association"
669 " request!\n");
670 return NULL;
671 }
672 }
673
674 /* Copy current configuration attributes to the association request,
675 * but don't overwrite any that are already set.
676 */
aa21c004 677 assoc_req = priv->pending_assoc_req;
876c9d3a 678 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
aa21c004 679 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
d8efea25 680 IW_ESSID_MAX_SIZE);
aa21c004 681 assoc_req->ssid_len = priv->curbssparams.ssid_len;
876c9d3a
MT
682 }
683
684 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
aa21c004 685 assoc_req->channel = priv->curbssparams.channel;
876c9d3a 686
e76850d6 687 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
aa21c004 688 assoc_req->band = priv->curbssparams.band;
e76850d6 689
876c9d3a 690 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
aa21c004 691 assoc_req->mode = priv->mode;
876c9d3a
MT
692
693 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
aa21c004 694 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
876c9d3a
MT
695 ETH_ALEN);
696 }
697
698 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
699 int i;
700 for (i = 0; i < 4; i++) {
aa21c004 701 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
1443b653 702 sizeof(struct enc_key));
876c9d3a
MT
703 }
704 }
705
706 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
aa21c004 707 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
876c9d3a
MT
708
709 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
aa21c004 710 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
1443b653 711 sizeof(struct enc_key));
876c9d3a
MT
712 }
713
714 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
aa21c004 715 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
1443b653 716 sizeof(struct enc_key));
876c9d3a
MT
717 }
718
719 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
aa21c004 720 memcpy(&assoc_req->secinfo, &priv->secinfo,
10078321 721 sizeof(struct lbs_802_11_security));
876c9d3a
MT
722 }
723
724 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
aa21c004 725 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
876c9d3a 726 MAX_WPA_IE_LEN);
aa21c004 727 assoc_req->wpa_ie_len = priv->wpa_ie_len;
876c9d3a
MT
728 }
729
0765af44 730 lbs_deb_leave(LBS_DEB_ASSOC);
876c9d3a
MT
731 return assoc_req;
732}
This page took 0.260902 seconds and 5 git commands to generate.