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