]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/libertas/assoc.c
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / libertas / assoc.c
index b18464224b952eeb55c82ea306f0042744748ddd..afd5617dd92b9e1cce0bf51612ac4a5843344333 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(
@@ -47,19 +24,16 @@ static void print_assoc_req(const char * extra, struct assoc_request * assoc_req
               "       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",
+              "       Encryption:%s%s%s\n"
+              "       auth:       %d\n",
               extra, assoc_req->flags,
-              libertas_escape_essid(assoc_req->ssid.ssid, assoc_req->ssid.ssidlength),
+              escape_essid(assoc_req->ssid, assoc_req->ssid_len),
               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);
+              MAC_ARG(assoc_req->bssid),
+              assoc_req->secinfo.WPAenabled ? " WPA" : "",
+              assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
+              assoc_req->secinfo.wep_enabled ? " WEP" : "",
+              assoc_req->secinfo.auth_mode);
 }
 
 
@@ -69,6 +43,7 @@ static int assoc_helper_essid(wlan_private *priv,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
        struct bss_descriptor * bss;
+       int channel = -1;
 
        lbs_deb_enter(LBS_DEB_ASSOC);
 
@@ -76,41 +51,46 @@ static int assoc_helper_essid(wlan_private *priv,
         * is set.
         */
 
-       lbs_deb_assoc("New SSID requested: %s\n", assoc_req->ssid.ssid);
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
+               channel = assoc_req->channel;
+
+       lbs_deb_assoc("New SSID requested: '%s'\n",
+                     escape_essid(assoc_req->ssid, assoc_req->ssid_len));
        if (assoc_req->mode == IW_MODE_INFRA) {
                if (adapter->prescan) {
-                       libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
+                       libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+                               assoc_req->ssid_len, 0);
                }
 
-               bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
-                               NULL, IW_MODE_INFRA);
+               bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+                               assoc_req->ssid_len, 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_deb_assoc("SSID '%s' not found; cannot associate\n",
-                               assoc_req->ssid.ssid);
+                       lbs_deb_assoc("SSID not found; cannot associate\n");
                }
        } 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, 1);
+               libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
+                       assoc_req->ssid_len, 1);
 
                /* Search for the requested SSID in the scan table */
-               bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
-                               IW_MODE_ADHOC);
+               bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
+                               assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
                if (bss != NULL) {
-                       lbs_deb_assoc("SSID found joining\n");
+                       lbs_deb_assoc("SSID found, will join\n");
                        memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
                        libertas_join_adhoc_network(priv, assoc_req);
                } else {
                        /* else send START command */
-                       lbs_deb_assoc("SSID not found in list, so creating adhoc"
-                               " with SSID '%s'\n", assoc_req->ssid.ssid);
+                       lbs_deb_assoc("SSID not found, creating adhoc network\n");
                        memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
-                               sizeof(struct WLAN_802_11_SSID));
+                               IW_ESSID_MAX_SIZE);
+                       assoc_req->bss.ssid_len = assoc_req->ssid_len;
                        libertas_start_adhoc_network(priv, assoc_req);
                }
        }
@@ -127,11 +107,11 @@ static int assoc_helper_bssid(wlan_private *priv,
        int ret = 0;
        struct bss_descriptor * bss;
 
-       lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID" MAC_FMT "\n",
+       lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID " MAC_FMT,
                MAC_ARG(assoc_req->bssid));
 
        /* Search for index position in list for requested MAC */
-       bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
+       bss = libertas_find_bssid_in_list(adapter, assoc_req->bssid,
                            assoc_req->mode);
        if (bss == NULL) {
                lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
@@ -161,8 +141,8 @@ 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) {
@@ -204,7 +184,7 @@ static int assoc_helper_mode(wlan_private *priv,
                                    cmd_802_11_snmp_mib,
                                    0, cmd_option_waitforrsp,
                                    OID_802_11_INFRASTRUCTURE_MODE,
-                                   (void *) (size_t) assoc_req->mode);
+               /* Shoot me now */  (void *) (size_t) assoc_req->mode);
 
 done:
        lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
@@ -220,6 +200,14 @@ static int update_channel(wlan_private * priv)
                                    cmd_option_waitforrsp, 0, NULL);
 }
 
+void libertas_sync_channel(struct work_struct *work)
+{
+       wlan_private *priv = container_of(work, wlan_private, sync_channel);
+
+       if (update_channel(priv) != 0)
+               lbs_pr_info("Channel synchronization failed.");
+}
+
 static int assoc_helper_channel(wlan_private *priv,
                                 struct assoc_request * assoc_req)
 {
@@ -335,6 +323,8 @@ static int assoc_helper_secinfo(wlan_private *priv,
 {
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
+       u32 do_wpa;
+       u32 rsn = 0;
 
        lbs_deb_enter(LBS_DEB_ASSOC);
 
@@ -342,7 +332,39 @@ static int assoc_helper_secinfo(wlan_private *priv,
                sizeof(struct wlan_802_11_security));
 
        ret = libertas_set_mac_packet_filter(priv);
+       if (ret)
+               goto out;
+
+       /* If RSN is already enabled, don't try to enable it again, since
+        * ENABLE_RSN resets internal state machines and will clobber the
+        * 4-way WPA handshake.
+        */
+
+       /* Get RSN enabled/disabled */
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_enable_rsn,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   0, &rsn);
+       if (ret) {
+               lbs_deb_assoc("Failed to get RSN status: %d", ret);
+               goto out;
+       }
 
+       /* Don't re-enable RSN if it's already enabled */
+       do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
+       if (do_wpa == rsn)
+               goto out;
+
+       /* Set RSN enabled/disabled */
+       rsn = do_wpa;
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_enable_rsn,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   0, &rsn);
+
+out:
        lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
@@ -355,22 +377,12 @@ static int assoc_helper_wpa_keys(wlan_private *priv,
 
        lbs_deb_enter(LBS_DEB_ASSOC);
 
-       /* enable/Disable RSN */
-       ret = libertas_prepare_and_send_command(priv,
-                                   cmd_802_11_enable_rsn,
-                                   cmd_act_set,
-                                   cmd_option_waitforrsp,
-                                   0, assoc_req);
-       if (ret)
-               goto out;
-
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_key_material,
                                    cmd_act_set,
                                    cmd_option_waitforrsp,
                                    0, assoc_req);
 
-out:
        lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
        return ret;
 }
@@ -423,6 +435,11 @@ static int should_deauth_infrastructure(wlan_adapter *adapter,
                return 1;
        }
 
+       if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
+               lbs_deb_assoc("Deauthenticating due to channel switch.\n");
+               return 1;
+       }
+
        /* FIXME: deal with 'auto' mode somehow */
        if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
                if (assoc_req->mode != IW_MODE_INFRA)
@@ -439,10 +456,9 @@ static int should_stop_adhoc(wlan_adapter *adapter,
        if (adapter->connect_status != libertas_connected)
                return 0;
 
-       if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
-               return 1;
-       if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
-                       adapter->curbssparams.ssid.ssidlength))
+       if (libertas_ssid_cmp(adapter->curbssparams.ssid,
+                             adapter->curbssparams.ssid_len,
+                             assoc_req->ssid, assoc_req->ssid_len) != 0)
                return 1;
 
        /* FIXME: deal with 'auto' mode somehow */
@@ -483,21 +499,21 @@ void libertas_association_worker(struct work_struct *work)
 
        /* If 'any' SSID was specified, find an SSID to associate with */
        if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
-           && !assoc_req->ssid.ssidlength)
+           && !assoc_req->ssid_len)
                find_any_ssid = 1;
 
        /* 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) {
                u8 new_mode;
 
-               ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
-                               assoc_req->mode, &new_mode);
+               ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
+                               &assoc_req->ssid_len, assoc_req->mode, &new_mode);
                if (ret) {
                        lbs_deb_assoc("Could not find best network\n");
                        ret = -ENETUNREACH;
@@ -611,8 +627,8 @@ lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                if (success) {
                        lbs_deb_assoc("ASSOC: association attempt successful. "
                                "Associated to '%s' (" MAC_FMT ")\n",
-                               libertas_escape_essid(adapter->curbssparams.ssid.ssid,
-                                            adapter->curbssparams.ssid.ssidlength),
+                               escape_essid(adapter->curbssparams.ssid,
+                                            adapter->curbssparams.ssid_len),
                                MAC_ARG(adapter->curbssparams.bssid));
                        libertas_prepare_and_send_command(priv,
                                cmd_802_11_rssi,
@@ -622,7 +638,6 @@ lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
                                cmd_802_11_get_log,
                                0, cmd_option_waitforrsp, 0, NULL);
                } else {
-
                        ret = -1;
                }
        }
@@ -666,7 +681,8 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
        assoc_req = adapter->pending_assoc_req;
        if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
                memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
-                      sizeof(struct WLAN_802_11_SSID));
+                      IW_ESSID_MAX_SIZE);
+               assoc_req->ssid_len = adapter->curbssparams.ssid_len;
        }
 
        if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))