iwl3945: Use iwlcore scan code
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / net / wireless / iwlwifi / iwl-scan.c
index c89365e2ca58e3f4c5d142e9f9d11ed75d7642cc..0ce122a1734161e06e6b3a675e52cfb89e0e8b11 100644 (file)
@@ -2,7 +2,7 @@
  *
  * GPL LICENSE SUMMARY
  *
- * Copyright(c) 2008 Intel Corporation. All rights reserved.
+ * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of version 2 of the GNU General Public License as
  * in the file called LICENSE.GPL.
  *
  * Contact Information:
- * Tomas Winkler <tomas.winkler@intel.com>
+ *  Intel Linux Wireless <ilw@linux.intel.com>
  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  *****************************************************************************/
-#include <net/mac80211.h>
+#include <linux/types.h>
 #include <linux/etherdevice.h>
+#include <net/lib80211.h>
+#include <net/mac80211.h>
 
 #include "iwl-eeprom.h"
 #include "iwl-dev.h"
 #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
 #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
 
-/* For faster active scanning, scan will move to the next channel if fewer than
- * PLCP_QUIET_THRESH packets are heard on this channel within
- * ACTIVE_QUIET_TIME after sending probe request.  This shortens the dwell
- * time if it's a quiet channel (nothing responded to our probe, and there's
- * no other traffic).
- * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
-#define IWL_PLCP_QUIET_THRESH       __constant_cpu_to_le16(1)  /* packets */
-#define IWL_ACTIVE_QUIET_TIME       __constant_cpu_to_le16(10)  /* msec */
-
 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  * Must be set longer than active dwell time.
  * For the most reliable scan, set > AP beacon interval (typically 100msec). */
 #define IWL_PASSIVE_DWELL_BASE      (100)
 #define IWL_CHANNEL_TUNE_TIME       5
 
-#define IWL_SCAN_PROBE_MASK(n)         cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
-
-
-static int scan_tx_ant[3] = {
-       RATE_MCS_ANT_A_MSK, RATE_MCS_ANT_B_MSK, RATE_MCS_ANT_C_MSK
-};
-
-
-
-static int iwl_is_empty_essid(const char *essid, int essid_len)
-{
-       /* Single white space is for Linksys APs */
-       if (essid_len == 1 && essid[0] == ' ')
-               return 1;
-
-       /* Otherwise, if the entire essid is 0, we assume it is hidden */
-       while (essid_len) {
-               essid_len--;
-               if (essid[essid_len] != '\0')
-                       return 0;
-       }
-
-       return 1;
-}
 
 
-
-static const char *iwl_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 (iwl_is_empty_essid(essid, essid_len)) {
-               memcpy(escaped, "<hidden>", sizeof("<hidden>"));
-               return escaped;
-       }
-
-       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;
-}
-
 /**
  * iwl_scan_cancel - Cancel any currently executing HW scan
  *
@@ -342,9 +286,9 @@ void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
 }
 EXPORT_SYMBOL(iwl_setup_rx_scan_handlers);
 
-static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
-                                           enum ieee80211_band band,
-                                           u8 n_probes)
+inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
+                                    enum ieee80211_band band,
+                                    u8 n_probes)
 {
        if (band == IEEE80211_BAND_5GHZ)
                return IWL_ACTIVE_DWELL_TIME_52 +
@@ -353,9 +297,10 @@ static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
                return IWL_ACTIVE_DWELL_TIME_24 +
                        IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
 }
+EXPORT_SYMBOL(iwl_get_active_dwell_time);
 
-static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
-                                     enum ieee80211_band band)
+u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
+                              enum ieee80211_band band)
 {
        u16 passive = (band == IEEE80211_BAND_2GHZ) ?
            IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
@@ -373,6 +318,7 @@ static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
 
        return passive;
 }
+EXPORT_SYMBOL(iwl_get_passive_dwell_time);
 
 static int iwl_get_channels_for_scan(struct iwl_priv *priv,
                                     enum ieee80211_band band,
@@ -455,10 +401,11 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
 
 void iwl_init_scan_params(struct iwl_priv *priv)
 {
+       u8 ant_idx = fls(priv->hw_params.valid_tx_ant) - 1;
        if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
-               priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = RATE_MCS_ANT_INIT_IND;
+               priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
        if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
-               priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = RATE_MCS_ANT_INIT_IND;
+               priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
 }
 
 int iwl_scan_initiate(struct iwl_priv *priv)
@@ -495,7 +442,7 @@ EXPORT_SYMBOL(iwl_scan_initiate);
 
 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
 
-static void iwl_bg_scan_check(struct work_struct *data)
+void iwl_bg_scan_check(struct work_struct *data)
 {
        struct iwl_priv *priv =
            container_of(data, struct iwl_priv, scan_check.work);
@@ -515,6 +462,8 @@ static void iwl_bg_scan_check(struct work_struct *data)
        }
        mutex_unlock(&priv->mutex);
 }
+EXPORT_SYMBOL(iwl_bg_scan_check);
+
 /**
  * iwl_supported_rate_to_ie - fill in the supported rate in IE field
  *
@@ -550,7 +499,7 @@ static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
 {
        struct ieee80211_ht_cap *ht_cap;
 
-       if (!sband || !sband->ht_info.ht_supported)
+       if (!sband || !sband->ht_cap.ht_supported)
                return;
 
        if (*left < sizeof(struct ieee80211_ht_cap))
@@ -559,12 +508,12 @@ static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
        *pos++ = sizeof(struct ieee80211_ht_cap);
        ht_cap = (struct ieee80211_ht_cap *) pos;
 
-       ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
-       memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
+       ht_cap->cap_info = cpu_to_le16(sband->ht_cap.cap);
+       memcpy(&ht_cap->mcs, &sband->ht_cap.mcs, 16);
        ht_cap->ampdu_params_info =
-               (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
-               ((sband->ht_info.ampdu_density << 2) &
-                       IEEE80211_HT_CAP_AMPDU_DENSITY);
+               (sband->ht_cap.ampdu_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) |
+               ((sband->ht_cap.ampdu_density << 2) &
+                       IEEE80211_HT_AMPDU_PARM_DENSITY);
        *left -= sizeof(struct ieee80211_ht_cap);
 }
 
@@ -572,10 +521,10 @@ static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  * iwl_fill_probe_req - fill in all required fields and IE for probe request
  */
 
-static u16 iwl_fill_probe_req(struct iwl_priv *priv,
-                                 enum ieee80211_band band,
-                                 struct ieee80211_mgmt *frame,
-                                 int left)
+u16 iwl_fill_probe_req(struct iwl_priv *priv,
+                      enum ieee80211_band band,
+                      struct ieee80211_mgmt *frame,
+                      int left)
 {
        int len = 0;
        u8 *pos = NULL;
@@ -669,23 +618,7 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv,
 
        return (u16)len;
 }
-
-static u32 iwl_scan_tx_ant(struct iwl_priv *priv, enum ieee80211_band band)
-{
-       int i, ind;
-
-       ind = priv->scan_tx_ant[band];
-       for (i = 0; i < priv->hw_params.tx_chains_num; i++) {
-               ind = (ind+1) >= priv->hw_params.tx_chains_num ? 0 : ind+1;
-               if (priv->hw_params.valid_tx_ant & (1 << ind)) {
-                       priv->scan_tx_ant[band] = ind;
-                       break;
-               }
-       }
-       IWL_DEBUG_SCAN("select TX ANT = %c\n", 'A' + ind);
-       return scan_tx_ant[ind];
-}
-
+EXPORT_SYMBOL(iwl_fill_probe_req);
 
 static void iwl_bg_request_scan(struct work_struct *data)
 {
@@ -699,22 +632,24 @@ static void iwl_bg_request_scan(struct work_struct *data)
        struct iwl_scan_cmd *scan;
        struct ieee80211_conf *conf = NULL;
        int ret = 0;
-       u32 tx_ant;
+       u32 rate_flags = 0;
        u16 cmd_len;
        enum ieee80211_band band;
        u8 n_probes = 2;
        u8 rx_chain = priv->hw_params.valid_rx_ant;
+       u8 rate;
+       DECLARE_SSID_BUF(ssid);
 
        conf = ieee80211_get_hw_conf(priv->hw);
 
        mutex_lock(&priv->mutex);
 
        if (!iwl_is_ready(priv)) {
-               IWL_WARNING("request scan called when driver not ready.\n");
+               IWL_WARN(priv, "request scan called when driver not ready.\n");
                goto done;
        }
 
-       /* Make sure the scan wasn't cancelled before this queued work
+       /* Make sure the scan wasn't canceled before this queued work
         * was given the chance to run... */
        if (!test_bit(STATUS_SCANNING, &priv->status))
                goto done;
@@ -796,20 +731,13 @@ static void iwl_bg_request_scan(struct work_struct *data)
        /* We should add the ability for user to lock to PASSIVE ONLY */
        if (priv->one_direct_scan) {
                IWL_DEBUG_SCAN("Start direct scan for '%s'\n",
-                               iwl_escape_essid(priv->direct_ssid,
-                               priv->direct_ssid_len));
+                               print_ssid(ssid, priv->direct_ssid,
+                                          priv->direct_ssid_len));
                scan->direct_scan[0].id = WLAN_EID_SSID;
                scan->direct_scan[0].len = priv->direct_ssid_len;
                memcpy(scan->direct_scan[0].ssid,
                       priv->direct_ssid, priv->direct_ssid_len);
                n_probes++;
-       } else if (!iwl_is_associated(priv) && priv->essid_len) {
-               IWL_DEBUG_SCAN("Start direct scan for '%s' (not associated)\n",
-                               iwl_escape_essid(priv->essid, priv->essid_len));
-               scan->direct_scan[0].id = WLAN_EID_SSID;
-               scan->direct_scan[0].len = priv->essid_len;
-               memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
-               n_probes++;
        } else {
                IWL_DEBUG_SCAN("Start indirect scan.\n");
        }
@@ -822,23 +750,16 @@ static void iwl_bg_request_scan(struct work_struct *data)
        if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
                band = IEEE80211_BAND_2GHZ;
                scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
-               tx_ant = iwl_scan_tx_ant(priv, band);
-               if (priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK)
-                       scan->tx_cmd.rate_n_flags =
-                               iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
-                                                       tx_ant);
-               else
-                       scan->tx_cmd.rate_n_flags =
-                               iwl_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
-                                                       tx_ant |
-                                                       RATE_MCS_CCK_MSK);
+               if (priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) {
+                       rate = IWL_RATE_6M_PLCP;
+               } else {
+                       rate = IWL_RATE_1M_PLCP;
+                       rate_flags = RATE_MCS_CCK_MSK;
+               }
                scan->good_CRC_th = 0;
        } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
                band = IEEE80211_BAND_5GHZ;
-               tx_ant = iwl_scan_tx_ant(priv, band);
-               scan->tx_cmd.rate_n_flags =
-                               iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
-                                                       tx_ant);
+               rate = IWL_RATE_6M_PLCP;
                scan->good_CRC_th = IWL_GOOD_CRC_TH;
 
                /* Force use of chains B and C (0x6) for scan Rx for 4965
@@ -847,10 +768,15 @@ static void iwl_bg_request_scan(struct work_struct *data)
                if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
                        rx_chain = 0x6;
        } else {
-               IWL_WARNING("Invalid scan band count\n");
+               IWL_WARN(priv, "Invalid scan band count\n");
                goto done;
        }
 
+       priv->scan_tx_ant[band] =
+                        iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band]);
+       rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
+       scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
+
        /* MIMO is not used here, but value is required */
        scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
                                cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
@@ -908,7 +834,7 @@ static void iwl_bg_request_scan(struct work_struct *data)
        mutex_unlock(&priv->mutex);
 }
 
-static void iwl_bg_abort_scan(struct work_struct *work)
+void iwl_bg_abort_scan(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
 
@@ -922,8 +848,9 @@ static void iwl_bg_abort_scan(struct work_struct *work)
 
        mutex_unlock(&priv->mutex);
 }
+EXPORT_SYMBOL(iwl_bg_abort_scan);
 
-static void iwl_bg_scan_completed(struct work_struct *work)
+void iwl_bg_scan_completed(struct work_struct *work)
 {
        struct iwl_priv *priv =
            container_of(work, struct iwl_priv, scan_completed);
@@ -941,7 +868,7 @@ static void iwl_bg_scan_completed(struct work_struct *work)
        iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
        mutex_unlock(&priv->mutex);
 }
-
+EXPORT_SYMBOL(iwl_bg_scan_completed);
 
 void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
 {