]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/libertas/wext.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / libertas / wext.c
index 7cfca5f3a5ef7b705bf1fbcd3ac9176e94e5320d..c6f5aa3cb465c4394d2140559eb1cec9c0e1de8b 100644 (file)
 #include "assoc.h"
 
 
-/**
- * the rates supported by the card
- */
-static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
-    { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
-      0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
-};
-
-/**
- *  @brief Convert mw value to dbm value
- *
- *  @param mw     the value of mw
- *  @return       the value of dbm
- */
-static int mw_to_dbm(int mw)
-{
-       if (mw < 2)
-               return 0;
-       else if (mw < 3)
-               return 3;
-       else if (mw < 4)
-               return 5;
-       else if (mw < 6)
-               return 7;
-       else if (mw < 7)
-               return 8;
-       else if (mw < 8)
-               return 9;
-       else if (mw < 10)
-               return 10;
-       else if (mw < 13)
-               return 11;
-       else if (mw < 16)
-               return 12;
-       else if (mw < 20)
-               return 13;
-       else if (mw < 25)
-               return 14;
-       else if (mw < 32)
-               return 15;
-       else if (mw < 40)
-               return 16;
-       else if (mw < 50)
-               return 17;
-       else if (mw < 63)
-               return 18;
-       else if (mw < 79)
-               return 19;
-       else if (mw < 100)
-               return 20;
-       else
-               return 21;
-}
-
 /**
  *  @brief Find the channel frequency power info with specific channel
  *
@@ -165,7 +111,7 @@ static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
  *  @option                    Radio Option
  *  @return                    0 --success, otherwise fail
  */
-int wlan_radio_ioctl(wlan_private * priv, u8 option)
+static int wlan_radio_ioctl(wlan_private * priv, u8 option)
 {
        int ret = 0;
        wlan_adapter *adapter = priv->adapter;
@@ -187,84 +133,31 @@ int wlan_radio_ioctl(wlan_private * priv, u8 option)
 }
 
 /**
- *  @brief Copy rates
- *
- *  @param dest                 A pointer to Dest Buf
- *  @param src                 A pointer to Src Buf
- *  @param len                  The len of Src Buf
- *  @return                    Number of rates copyed
- */
-static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
-{
-       int i;
-
-       for (i = 0; i < len && src[i]; i++, pos++) {
-               if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
-                       break;
-               dest[pos] = src[i];
-       }
-
-       return pos;
-}
-
-/**
- *  @brief Get active data rates
+ *  @brief Copy active data rates based on adapter mode and status
  *
  *  @param adapter              A pointer to wlan_adapter structure
  *  @param rate                        The buf to return the active rates
- *  @return                    The number of rates
  */
-static int get_active_data_rates(wlan_adapter * adapter,
-                                u8* rates)
+static void copy_active_data_rates(wlan_adapter * adapter, u8 * rates)
 {
-       int k = 0;
-
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (adapter->connect_status != LIBERTAS_CONNECTED) {
-               if (adapter->mode == IW_MODE_INFRA) {
-                       lbs_deb_wext("infra\n");
-                       k = copyrates(rates, k, libertas_supported_rates,
-                                     sizeof(libertas_supported_rates));
-               } else {
-                       lbs_deb_wext("Adhoc G\n");
-                       k = copyrates(rates, k, libertas_adhoc_rates_g,
-                                     sizeof(libertas_adhoc_rates_g));
-               }
-       } else {
-               k = copyrates(rates, 0, adapter->curbssparams.datarates,
-                             adapter->curbssparams.numofrates);
-       }
+       if (adapter->connect_status != LIBERTAS_CONNECTED)
+               memcpy(rates, libertas_bg_rates, MAX_RATES);
+       else
+               memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
 
-       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
-       return k;
+       lbs_deb_leave(LBS_DEB_WEXT);
 }
 
 static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
                         char *cwrq, char *extra)
 {
-       const char *cp;
-       char comm[6] = { "COMM-" };
-       char mrvl[6] = { "MRVL-" };
-       int cnt;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       strcpy(cwrq, mrvl);
-
-       cp = strstr(libertas_driver_version, comm);
-       if (cp == libertas_driver_version)      //skip leading "COMM-"
-               cp = libertas_driver_version + strlen(comm);
-       else
-               cp = libertas_driver_version;
-
-       cnt = strlen(mrvl);
-       cwrq += cnt;
-       while (cnt < 16 && (*cp != '-')) {
-               *cwrq++ = toupper(*cp++);
-               cnt++;
-       }
-       *cwrq = '\0';
+       /* We could add support for 802.11n here as needed. Jean II */
+       snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
 
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
@@ -349,24 +242,11 @@ static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       /*
-        * Get the Nick Name saved
-        */
-
-       mutex_lock(&adapter->lock);
-       strncpy(extra, adapter->nodename, 16);
-       mutex_unlock(&adapter->lock);
-
-       extra[16] = '\0';
+       dwrq->length = strlen(adapter->nodename);
+       memcpy(extra, adapter->nodename, dwrq->length);
+       extra[dwrq->length] = '\0';
 
-       /*
-        * If none, we may want to get the one that was set
-        */
-
-       /*
-        * Push it out !
-        */
-       dwrq->length = strlen(extra) + 1;
+       dwrq->flags = 1;        /* active */
 
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
@@ -385,17 +265,18 @@ static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
        if (adapter->connect_status == LIBERTAS_CONNECTED) {
                strncpy(extra, "Mesh", 12);
                extra[12] = '\0';
-               dwrq->length = strlen(extra) + 1;
+               dwrq->length = strlen(extra);
        }
 
        else {
                extra[0] = '\0';
-               dwrq->length = ;
+               dwrq->length = 0;
        }
 
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
+
 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
                        struct iw_param *vwrq, char *extra)
 {
@@ -673,7 +554,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        struct iw_range *range = (struct iw_range *)extra;
        struct chan_freq_power *cfp;
-       u8 rates[WLAN_SUPPORTED_RATES];
+       u8 rates[MAX_RATES + 1];
 
        u8 flag = 0;
 
@@ -686,12 +567,10 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
        range->max_nwid = 0;
 
        memset(rates, 0, sizeof(rates));
-       range->num_bitrates = get_active_data_rates(adapter, rates);
-
-       for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
-            i++) {
-               range->bitrate[i] = (rates[i] & 0x7f) * 500000;
-       }
+       copy_active_data_rates(adapter, rates);
+       range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
+       for (i = 0; i < range->num_bitrates; i++)
+               range->bitrate[i] = rates[i] * 500000;
        range->num_bitrates = i;
        lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
               range->num_bitrates);
@@ -973,7 +852,7 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
        /* Quality by TX errors */
        priv->wstats.discard.retries = priv->stats.tx_errors;
 
-       tx_retries = le16_to_cpu(adapter->logmsg.retry);
+       tx_retries = le32_to_cpu(adapter->logmsg.retry);
 
        if (tx_retries > 75)
                tx_qual = (90 - tx_retries) * POOR / 15;
@@ -989,13 +868,13 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
                    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
        quality = min(quality, tx_qual);
 
-       priv->wstats.discard.code = le16_to_cpu(adapter->logmsg.wepundecryptable);
-       priv->wstats.discard.fragment = le16_to_cpu(adapter->logmsg.rxfrag);
+       priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
+       priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
        priv->wstats.discard.retries = tx_retries;
-       priv->wstats.discard.misc = le16_to_cpu(adapter->logmsg.ackfailure);
+       priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
 
        /* Calculate quality */
-       priv->wstats.qual.qual = max(quality, (u32)100);
+       priv->wstats.qual.qual = min_t(u8, quality, 100);
        priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
        stats_valid = 1;
 
@@ -1080,88 +959,46 @@ out:
        return ret;
 }
 
-/**
- *  @brief use index to get the data rate
- *
- *  @param index                The index of data rate
- *  @return                    data rate or 0
- */
-u32 libertas_index_to_data_rate(u8 index)
-{
-       if (index >= sizeof(libertas_wlan_data_rates))
-               index = 0;
-
-       return libertas_wlan_data_rates[index];
-}
-
-/**
- *  @brief use rate to get the index
- *
- *  @param rate                 data rate
- *  @return                    index or 0
- */
-u8 libertas_data_rate_to_index(u32 rate)
-{
-       u8 *ptr;
-
-       if (rate)
-               if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
-                                 sizeof(libertas_wlan_data_rates))))
-                       return (ptr - libertas_wlan_data_rates);
-
-       return 0;
-}
-
 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
                  struct iw_param *vwrq, char *extra)
 {
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
-       u32 data_rate;
+       u32 new_rate;
        u16 action;
-       int ret = 0;
-       u8 rates[WLAN_SUPPORTED_RATES];
-       u8 *rate;
+       int ret = -EINVAL;
+       u8 rates[MAX_RATES + 1];
 
        lbs_deb_enter(LBS_DEB_WEXT);
-
        lbs_deb_wext("vwrq->value %d\n", vwrq->value);
 
+       /* Auto rate? */
        if (vwrq->value == -1) {
-               action = CMD_ACT_SET_tx_auto;   // Auto
-               adapter->is_datarate_auto = 1;
-               adapter->datarate = 0;
+               action = CMD_ACT_SET_TX_AUTO;
+               adapter->auto_rate = 1;
+               adapter->cur_rate = 0;
        } else {
-               if (vwrq->value % 100000) {
-                       return -EINVAL;
-               }
-
-               data_rate = vwrq->value / 500000;
+               if (vwrq->value % 100000)
+                       goto out;
 
                memset(rates, 0, sizeof(rates));
-               get_active_data_rates(adapter, rates);
-               rate = rates;
-               while (*rate) {
-                       lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
-                              data_rate);
-                       if ((*rate & 0x7f) == (data_rate & 0x7f))
-                               break;
-                       rate++;
-               }
-               if (!*rate) {
-                       lbs_pr_alert("fixed data rate 0x%X out "
-                              "of range\n", data_rate);
-                       return -EINVAL;
+               copy_active_data_rates(adapter, rates);
+               new_rate = vwrq->value / 500000;
+               if (!memchr(rates, new_rate, sizeof(rates))) {
+                       lbs_pr_alert("fixed data rate 0x%X out of range\n",
+                               new_rate);
+                       goto out;
                }
 
-               adapter->datarate = data_rate;
-               action = CMD_ACT_SET_tx_fix_rate;
-               adapter->is_datarate_auto = 0;
+               adapter->cur_rate = new_rate;
+               action = CMD_ACT_SET_TX_FIX_RATE;
+               adapter->auto_rate = 0;
        }
 
        ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
                                    action, CMD_OPTION_WAITFORRSP, 0, NULL);
 
+out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
@@ -1174,14 +1011,19 @@ static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (adapter->is_datarate_auto) {
-               vwrq->fixed = 0;
+       if (adapter->connect_status == LIBERTAS_CONNECTED) {
+               vwrq->value = adapter->cur_rate * 500000;
+
+               if (adapter->auto_rate)
+                       vwrq->fixed = 0;
+               else
+                       vwrq->fixed = 1;
+
        } else {
-               vwrq->fixed = 1;
+               vwrq->fixed = 0;
+               vwrq->value = 0;
        }
 
-       vwrq->value = adapter->datarate * 500000;
-
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
@@ -1298,7 +1140,7 @@ static int wlan_get_encode(struct net_device *dev,
 
        dwrq->flags |= IW_ENCODE_NOKEY;
 
-       lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
+       lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
               extra[0], extra[1], extra[2],
               extra[3], extra[4], extra[5], dwrq->length);
 
@@ -1980,8 +1822,10 @@ static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
 
        wlan_radio_ioctl(priv, RADIO_ON);
 
+       /* Userspace check in iwrange if it should use dBm or mW,
+        * therefore this should never happen... Jean II */
        if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
-               dbm = (u16) mw_to_dbm(vwrq->value);
+               return -EOPNOTSUPP;
        } else
                dbm = (u16) vwrq->value;
 
@@ -2029,12 +1873,7 @@ static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
         * If none, we may want to get the one that was set
         */
 
-       /* To make the driver backward compatible with WPA supplicant v0.2.4 */
-       if (dwrq->length == 32) /* check with WPA supplicant buffer size */
-               dwrq->length = min_t(size_t, adapter->curbssparams.ssid_len,
-                                  IW_ESSID_MAX_SIZE);
-       else
-               dwrq->length = adapter->curbssparams.ssid_len + 1;
+       dwrq->length = adapter->curbssparams.ssid_len;
 
        dwrq->flags = 1;        /* active */
 
@@ -2055,14 +1894,6 @@ static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       /*
-        * WE-20 and earlier NULL pad the end of the SSID and increment
-        * SSID length so it can be used like a string.  WE-21 and later don't,
-        * but some userspace tools aren't able to cope with the change.
-        */
-       if ((in_ssid_len > 0) && (extra[in_ssid_len - 1] == '\0'))
-               in_ssid_len--;
-
        /* Check the size of the string */
        if (in_ssid_len > IW_ESSID_MAX_SIZE) {
                ret = -E2BIG;
@@ -2129,13 +1960,14 @@ static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        struct assoc_request * assoc_req;
        int ret = 0;
+       DECLARE_MAC_BUF(mac);
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
        if (awrq->sa_family != ARPHRD_ETHER)
                return -EINVAL;
 
-       lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
+       lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
 
        mutex_lock(&adapter->lock);
 
@@ -2298,13 +2130,13 @@ static const iw_handler mesh_wlan_handler[] = {
        (iw_handler) NULL,              /* SIOCSIWPMKSA */
 };
 struct iw_handler_def libertas_handler_def = {
-       .num_standard   = sizeof(wlan_handler) / sizeof(iw_handler),
+       .num_standard   = ARRAY_SIZE(wlan_handler),
        .standard       = (iw_handler *) wlan_handler,
        .get_wireless_stats = wlan_get_wireless_stats,
 };
 
 struct iw_handler_def mesh_handler_def = {
-       .num_standard   = sizeof(mesh_wlan_handler) / sizeof(iw_handler),
+       .num_standard   = ARRAY_SIZE(mesh_wlan_handler),
        .standard       = (iw_handler *) mesh_wlan_handler,
        .get_wireless_stats = wlan_get_wireless_stats,
 };