]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/libertas/assoc.c
[PATCH] libertas: debug print spacing fixes in assoc.c
[linux-2.6] / drivers / net / wireless / libertas / assoc.c
index b55c7f57aca8d34a4fc7c333e0d2ddf522f9752d..48fc6d171d5854e4c487a76d142e9018cc75bdd7 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <linux/bitops.h>
 #include <net/ieee80211.h>
+#include <linux/etherdevice.h>
 
 #include "assoc.h"
 #include "join.h"
 static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
+/* From ieee80211_module.c */
+static const char *libertas_escape_essid(const char *essid, u8 essid_len)
+{
+       static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
+       const char *s = essid;
+       char *d = escaped;
+
+       if (ieee80211_is_empty_essid(essid, essid_len))
+               return "";
+
+       essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
+       while (essid_len--) {
+               if (*s == '\0') {
+                       *d++ = '\\';
+                       *d++ = '0';
+                       s++;
+               } else {
+                       *d++ = *s++;
+               }
+       }
+       *d = '\0';
+       return escaped;
+}
+
+static void print_assoc_req(const char * extra, struct assoc_request * assoc_req)
+{
+       lbs_deb_assoc(
+              "#### Association Request: %s\n"
+              "       flags:      0x%08lX\n"
+              "       SSID:       '%s'\n"
+              "       channel:    %d\n"
+              "       band:       %d\n"
+              "       mode:       %d\n"
+              "       BSSID:      " MAC_FMT "\n"
+              "       WPA:        %d\n"
+              "       WPA2:       %d\n"
+              "       WEP status: %d\n"
+              "       auth:       %d\n"
+              "       auth_alg:   %d\n"
+              "       encmode:    %d\n",
+              extra, assoc_req->flags,
+              libertas_escape_essid(assoc_req->ssid.ssid, assoc_req->ssid.ssidlength),
+              assoc_req->channel, assoc_req->band, assoc_req->mode,
+              MAC_ARG(assoc_req->bssid), assoc_req->secinfo.WPAenabled,
+              assoc_req->secinfo.WPA2enabled, assoc_req->secinfo.WEPstatus,
+              assoc_req->secinfo.authmode, assoc_req->secinfo.auth1xalg,
+              assoc_req->secinfo.Encryptionmode);
+}
+
+
 static int assoc_helper_essid(wlan_private *priv,
                               struct assoc_request * assoc_req)
 {
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
-       int i;
+       struct bss_descriptor * bss;
+       int channel = -1;
+
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
-       ENTER();
+       /* FIXME: take channel into account when picking SSIDs if a channel
+        * is set.
+        */
+
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
+               channel = assoc_req->channel;
 
-       lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid);
-       if (assoc_req->mode == wlan802_11infrastructure) {
+       lbs_deb_assoc("New SSID requested: %s\n", assoc_req->ssid.ssid);
+       if (assoc_req->mode == IW_MODE_INFRA) {
                if (adapter->prescan) {
-                       libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
+                       libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
                }
 
-               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
-                               NULL, wlan802_11infrastructure);
-               if (i >= 0) {
-                       lbs_pr_debug(1,
-                              "SSID found in scan list ... associating...\n");
-
-                       ret = wlan_associate(priv, &adapter->scantable[i]);
-                       if (ret == 0) {
-                               memcpy(&assoc_req->bssid,
-                                      &adapter->scantable[i].macaddress,
-                                      ETH_ALEN);
-                       }
+               bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
+                               NULL, IW_MODE_INFRA, channel);
+               if (bss != NULL) {
+                       lbs_deb_assoc("SSID found in scan list, associating\n");
+                       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+                       ret = wlan_associate(priv, assoc_req);
                } else {
-                       lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n",
+                       lbs_deb_assoc("SSID '%s' not found; cannot associate\n",
                                assoc_req->ssid.ssid);
                }
-       } else if (assoc_req->mode == wlan802_11ibss) {
+       } else if (assoc_req->mode == IW_MODE_ADHOC) {
                /* Scan for the network, do not save previous results.  Stale
                 *   scan data will cause us to join a non-existant adhoc network
                 */
-               libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
+               libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
 
                /* Search for the requested SSID in the scan table */
-               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
-                               wlan802_11ibss);
-               if (i >= 0) {
-                       lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret);
-                       libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+               bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
+                               IW_MODE_ADHOC, channel);
+               if (bss != NULL) {
+                       lbs_deb_assoc("SSID found joining\n");
+                       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+                       libertas_join_adhoc_network(priv, assoc_req);
                } else {
                        /* else send START command */
-                       lbs_pr_debug(1, "SSID not found in list, so creating adhoc"
+                       lbs_deb_assoc("SSID not found in list, so creating adhoc"
                                " with SSID '%s'\n", assoc_req->ssid.ssid);
-                       libertas_start_adhoc_network(priv, &assoc_req->ssid);
+                       memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
+                               sizeof(struct WLAN_802_11_SSID));
+                       libertas_start_adhoc_network(priv, assoc_req);
                }
-               memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN);
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -74,33 +129,31 @@ static int assoc_helper_bssid(wlan_private *priv,
                               struct assoc_request * assoc_req)
 {
        wlan_adapter *adapter = priv->adapter;
-       int i, ret = 0;
-
-       ENTER();
+       int ret = 0;
+       struct bss_descriptor * bss;
 
-       lbs_pr_debug(1, "ASSOC: WAP: BSSID = " MAC_FMT "\n",
+       lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID " MAC_FMT "\n",
                MAC_ARG(assoc_req->bssid));
 
        /* Search for index position in list for requested MAC */
-       i = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
+       bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
                            assoc_req->mode);
-       if (i < 0) {
-               lbs_pr_debug(1, "ASSOC: WAP: BSSID " MAC_FMT " not found, "
+       if (bss == NULL) {
+               lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
                        "cannot associate.\n", MAC_ARG(assoc_req->bssid));
                goto out;
        }
 
-       if (assoc_req->mode == wlan802_11infrastructure) {
-               ret = wlan_associate(priv, &adapter->scantable[i]);
-               lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret);
-       } else if (assoc_req->mode == wlan802_11ibss) {
-               libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+       memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
+       if (assoc_req->mode == IW_MODE_INFRA) {
+               ret = wlan_associate(priv, assoc_req);
+               lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret);
+       } else if (assoc_req->mode == IW_MODE_ADHOC) {
+               libertas_join_adhoc_network(priv, assoc_req);
        }
-       memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid,
-               sizeof(struct WLAN_802_11_SSID));
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -113,12 +166,12 @@ static int assoc_helper_associate(wlan_private *priv,
        /* If we're given and 'any' BSSID, try associating based on SSID */
 
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN)
-                   && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) {
+               if (compare_ether_addr(bssid_any, assoc_req->bssid)
+                   && compare_ether_addr(bssid_off, assoc_req->bssid)) {
                        ret = assoc_helper_bssid(priv, assoc_req);
                        done = 1;
                        if (ret) {
-                               lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+                               lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
                        }
                }
        }
@@ -126,7 +179,7 @@ static int assoc_helper_associate(wlan_private *priv,
        if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
                ret = assoc_helper_essid(priv, assoc_req);
                if (ret) {
-                       lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+                       lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
                }
        }
 
@@ -140,27 +193,89 @@ static int assoc_helper_mode(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
-       if (assoc_req->mode == adapter->inframode) {
-               LEAVE();
-               return 0;
-       }
+       if (assoc_req->mode == adapter->mode)
+               goto done;
 
-       if (assoc_req->mode == wlan802_11infrastructure) {
+       if (assoc_req->mode == IW_MODE_INFRA) {
                if (adapter->psstate != PS_STATE_FULL_POWER)
                        libertas_ps_wakeup(priv, cmd_option_waitforrsp);
                adapter->psmode = wlan802_11powermodecam;
        }
 
-       adapter->inframode = assoc_req->mode;
+       adapter->mode = assoc_req->mode;
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_snmp_mib,
                                    0, cmd_option_waitforrsp,
                                    OID_802_11_INFRASTRUCTURE_MODE,
-                                   (void *) assoc_req->mode);
+                                   (void *) (size_t) assoc_req->mode);
 
-       LEAVE();
+done:
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
+       return ret;
+}
+
+
+static int update_channel(wlan_private * priv)
+{
+       /* the channel in f/w could be out of sync, get the current channel */
+       return libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+                                   cmd_opt_802_11_rf_channel_get,
+                                   cmd_option_waitforrsp, 0, NULL);
+}
+
+static int assoc_helper_channel(wlan_private *priv,
+                                struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       lbs_deb_enter(LBS_DEB_ASSOC);
+
+       ret = update_channel(priv);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error getting channel.");
+       }
+
+       if (assoc_req->channel == adapter->curbssparams.channel)
+               goto done;
+
+       lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
+              adapter->curbssparams.channel, assoc_req->channel);
+
+       ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
+                               cmd_opt_802_11_rf_channel_set,
+                               cmd_option_waitforrsp, 0, &assoc_req->channel);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error setting channel.");
+       }
+
+       ret = update_channel(priv);
+       if (ret < 0) {
+               lbs_deb_assoc("ASSOC: channel: error getting channel.");
+       }
+
+       if (assoc_req->channel != adapter->curbssparams.channel) {
+               lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
+                             assoc_req->channel);
+               goto done;
+       }
+
+       if (   assoc_req->secinfo.wep_enabled
+           &&   (assoc_req->wep_keys[0].len
+              || assoc_req->wep_keys[1].len
+              || assoc_req->wep_keys[2].len
+              || assoc_req->wep_keys[3].len)) {
+               /* Make sure WEP keys are re-sent to firmware */
+               set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
+       }
+
+       /* Must restart/rejoin adhoc networks after channel change */
+       set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
+
+done:
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -172,7 +287,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
        int i;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        /* Set or remove WEP keys */
        if (   assoc_req->wep_keys[0].len
@@ -196,7 +311,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
                goto out;
 
        /* enable/disable the MAC's WEP packet filter */
-       if (assoc_req->secinfo.WEPstatus == wlan802_11WEPenabled)
+       if (assoc_req->secinfo.wep_enabled)
                adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
        else
                adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
@@ -216,7 +331,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
        mutex_unlock(&adapter->lock);
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -226,14 +341,14 @@ static int assoc_helper_secinfo(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        memcpy(&adapter->secinfo, &assoc_req->secinfo,
                sizeof(struct wlan_802_11_security));
 
        ret = libertas_set_mac_packet_filter(priv);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -243,7 +358,7 @@ static int assoc_helper_wpa_keys(wlan_private *priv,
 {
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        /* enable/Disable RSN */
        ret = libertas_prepare_and_send_command(priv,
@@ -261,7 +376,7 @@ static int assoc_helper_wpa_keys(wlan_private *priv,
                                    0, assoc_req);
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -272,7 +387,7 @@ static int assoc_helper_wpa_ie(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
                memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
@@ -282,7 +397,7 @@ static int assoc_helper_wpa_ie(wlan_private *priv,
                adapter->wpa_ie_len = 0;
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
 
@@ -294,29 +409,28 @@ static int should_deauth_infrastructure(wlan_adapter *adapter,
                return 0;
 
        if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-               lbs_pr_debug(1, "Deauthenticating due to new SSID in "
+               lbs_deb_assoc("Deauthenticating due to new SSID in "
                        " configuration request.\n");
                return 1;
        }
 
        if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
-               if (adapter->secinfo.authmode !=
-                   assoc_req->secinfo.authmode) {
-                       lbs_pr_debug(1, "Deauthenticating due to updated security "
+               if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
+                       lbs_deb_assoc("Deauthenticating due to updated security "
                                "info in configuration request.\n");
                        return 1;
                }
        }
 
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               lbs_pr_debug(1, "Deauthenticating due to new BSSID in "
+               lbs_deb_assoc("Deauthenticating due to new BSSID in "
                        " configuration request.\n");
                return 1;
        }
 
        /* FIXME: deal with 'auto' mode somehow */
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
-               if (assoc_req->mode != wlan802_11infrastructure)
+               if (assoc_req->mode != IW_MODE_INFRA)
                        return 1;
        }
 
@@ -333,12 +447,17 @@ static int should_stop_adhoc(wlan_adapter *adapter,
        if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
                return 1;
        if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
-                       sizeof(struct WLAN_802_11_SSID)))
+                       adapter->curbssparams.ssid.ssidlength))
                return 1;
 
        /* FIXME: deal with 'auto' mode somehow */
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
-               if (assoc_req->mode != wlan802_11ibss)
+               if (assoc_req->mode != IW_MODE_ADHOC)
+                       return 1;
+       }
+
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               if (assoc_req->channel != adapter->curbssparams.channel)
                        return 1;
        }
 
@@ -346,7 +465,7 @@ static int should_stop_adhoc(wlan_adapter *adapter,
 }
 
 
-void wlan_association_worker(struct work_struct *work)
+void libertas_association_worker(struct work_struct *work)
 {
        wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
        wlan_adapter *adapter = priv->adapter;
@@ -354,20 +473,18 @@ void wlan_association_worker(struct work_struct *work)
        int ret = 0;
        int find_any_ssid = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_ASSOC);
 
        mutex_lock(&adapter->lock);
-       assoc_req = adapter->assoc_req;
-       adapter->assoc_req = NULL;
+       assoc_req = adapter->pending_assoc_req;
+       adapter->pending_assoc_req = NULL;
+       adapter->in_progress_assoc_req = assoc_req;
        mutex_unlock(&adapter->lock);
 
-       if (!assoc_req) {
-               LEAVE();
-               return;
-       }
+       if (!assoc_req)
+               goto done;
 
-       lbs_pr_debug(1, "ASSOC: starting new association request: flags = 0x%lX\n",
-               assoc_req->flags);
+       print_assoc_req(__func__, assoc_req);
 
        /* If 'any' SSID was specified, find an SSID to associate with */
        if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
@@ -376,24 +493,24 @@ void wlan_association_worker(struct work_struct *work)
 
        /* But don't use 'any' SSID if there's a valid locked BSSID to use */
        if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
-               if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN)
-                   && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN))
+               if (compare_ether_addr(assoc_req->bssid, bssid_any)
+                   && compare_ether_addr(assoc_req->bssid, bssid_off))
                        find_any_ssid = 0;
        }
 
        if (find_any_ssid) {
-               enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode;
+               u8 new_mode;
 
                ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
                                assoc_req->mode, &new_mode);
                if (ret) {
-                       lbs_pr_debug(1, "Could not find best network\n");
+                       lbs_deb_assoc("Could not find best network\n");
                        ret = -ENETUNREACH;
                        goto out;
                }
 
                /* Ensure we switch to the mode of the AP */
-               if (assoc_req->mode == wlan802_11autounknown) {
+               if (assoc_req->mode == IW_MODE_AUTO) {
                        set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
                        assoc_req->mode = new_mode;
                }
@@ -403,20 +520,20 @@ void wlan_association_worker(struct work_struct *work)
         * Check if the attributes being changing require deauthentication
         * from the currently associated infrastructure access point.
         */
-       if (adapter->inframode == wlan802_11infrastructure) {
+       if (adapter->mode == IW_MODE_INFRA) {
                if (should_deauth_infrastructure(adapter, assoc_req)) {
                        ret = libertas_send_deauthentication(priv);
                        if (ret) {
-                               lbs_pr_debug(1, "Deauthentication due to new "
+                               lbs_deb_assoc("Deauthentication due to new "
                                        "configuration request failed: %d\n",
                                        ret);
                        }
                }
-       } else if (adapter->inframode == wlan802_11ibss) {
+       } else if (adapter->mode == IW_MODE_ADHOC) {
                if (should_stop_adhoc(adapter, assoc_req)) {
                        ret = libertas_stop_adhoc_network(priv);
                        if (ret) {
-                               lbs_pr_debug(1, "Teardown of AdHoc network due to "
+                               lbs_deb_assoc("Teardown of AdHoc network due to "
                                        "new configuration request failed: %d\n",
                                        ret);
                        }
@@ -428,7 +545,16 @@ void wlan_association_worker(struct work_struct *work)
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
                ret = assoc_helper_mode(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               ret = assoc_helper_channel(priv, assoc_req);
+               if (ret) {
+                       lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
+                                     __LINE__, ret);
                        goto out;
                }
        }
@@ -437,7 +563,7 @@ lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
            || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
                ret = assoc_helper_wep_keys(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -445,7 +571,7 @@ lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
        if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
                ret = assoc_helper_secinfo(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -453,7 +579,7 @@ lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
        if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
                ret = assoc_helper_wpa_ie(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -462,7 +588,7 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
            || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
                ret = assoc_helper_wpa_keys(priv, assoc_req);
                if (ret) {
-lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
+lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                        goto out;
                }
        }
@@ -476,21 +602,23 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
 
                ret = assoc_helper_associate(priv, assoc_req);
                if (ret) {
-                       lbs_pr_debug(1, "ASSOC: association attempt unsuccessful: %d\n",
+                       lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
                                ret);
                        success = 0;
                }
 
                if (adapter->connect_status != libertas_connected) {
-                       lbs_pr_debug(1, "ASSOC: assoication attempt unsuccessful, "
+                       lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
                                "not connected.\n");
                        success = 0;
                }
 
                if (success) {
-                       lbs_pr_debug(1, "ASSOC: association attempt successful. "
+                       lbs_deb_assoc("ASSOC: association attempt successful. "
                                "Associated to '%s' (" MAC_FMT ")\n",
-                               assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid));
+                               libertas_escape_essid(adapter->curbssparams.ssid.ssid,
+                                            adapter->curbssparams.ssid.ssidlength),
+                               MAC_ARG(adapter->curbssparams.bssid));
                        libertas_prepare_and_send_command(priv,
                                cmd_802_11_rssi,
                                0, cmd_option_waitforrsp, 0, NULL);
@@ -499,18 +627,23 @@ lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                                cmd_802_11_get_log,
                                0, cmd_option_waitforrsp, 0, NULL);
                } else {
-
                        ret = -1;
                }
        }
 
 out:
        if (ret) {
-               lbs_pr_debug(1, "ASSOC: reconfiguration attempt unsuccessful: %d\n",
+               lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
                        ret);
        }
+
+       mutex_lock(&adapter->lock);
+       adapter->in_progress_assoc_req = NULL;
+       mutex_unlock(&adapter->lock);
        kfree(assoc_req);
-       LEAVE();
+
+done:
+       lbs_deb_leave(LBS_DEB_ASSOC);
 }
 
 
@@ -521,9 +654,10 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
 {
        struct assoc_request * assoc_req;
 
-       if (!adapter->assoc_req) {
-               adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL);
-               if (!adapter->assoc_req) {
+       if (!adapter->pending_assoc_req) {
+               adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
+                                                    GFP_KERNEL);
+               if (!adapter->pending_assoc_req) {
                        lbs_pr_info("Not enough memory to allocate association"
                                " request!\n");
                        return NULL;
@@ -533,17 +667,20 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
        /* Copy current configuration attributes to the association request,
         * but don't overwrite any that are already set.
         */
-       assoc_req = adapter->assoc_req;
+       assoc_req = adapter->pending_assoc_req;
        if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
-               memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid,
-                       adapter->curbssparams.ssid.ssidlength);
+               memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
+                      sizeof(struct WLAN_802_11_SSID));
        }
 
        if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
                assoc_req->channel = adapter->curbssparams.channel;
 
+       if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
+               assoc_req->band = adapter->curbssparams.band;
+
        if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
-               assoc_req->mode = adapter->inframode;
+               assoc_req->mode = adapter->mode;
 
        if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
                memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
@@ -582,7 +719,7 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
                assoc_req->wpa_ie_len = adapter->wpa_ie_len;
        }
 
+       print_assoc_req(__func__, assoc_req);
+
        return assoc_req;
 }
-
-