libertas: move SIOCGIWAP calls to wext.c
[safe/jmp/linux-2.6] / drivers / net / wireless / libertas / wext.c
index cded4bb..dc63b33 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/wireless.h>
 #include <linux/bitops.h>
 
-#include <net/ieee80211.h>
+#include <net/lib80211.h>
 #include <net/iw_handler.h>
 
 #include "host.h"
@@ -16,8 +16,8 @@
 #include "decl.h"
 #include "defs.h"
 #include "dev.h"
-#include "join.h"
 #include "wext.h"
+#include "scan.h"
 #include "assoc.h"
 #include "cmd.h"
 
@@ -30,6 +30,14 @@ static inline void lbs_postpone_association_work(struct lbs_private *priv)
        queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
 }
 
+static inline void lbs_do_association_work(struct lbs_private *priv)
+{
+       if (priv->surpriseremoved)
+               return;
+       cancel_delayed_work(&priv->assoc_work);
+       queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
+}
+
 static inline void lbs_cancel_association_work(struct lbs_private *priv)
 {
        cancel_delayed_work(&priv->assoc_work);
@@ -37,6 +45,38 @@ static inline void lbs_cancel_association_work(struct lbs_private *priv)
        priv->pending_assoc_req = NULL;
 }
 
+void lbs_send_disconnect_notification(struct lbs_private *priv)
+{
+       union iwreq_data wrqu;
+
+       memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
+       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+       wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
+}
+
+void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
+{
+       union iwreq_data iwrq;
+       u8 buf[50];
+
+       lbs_deb_enter(LBS_DEB_WEXT);
+
+       memset(&iwrq, 0, sizeof(union iwreq_data));
+       memset(buf, 0, sizeof(buf));
+
+       snprintf(buf, sizeof(buf) - 1, "%s", str);
+
+       iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
+
+       /* Send Event to upper layer */
+       lbs_deb_wext("event indication string %s\n", (char *)buf);
+       lbs_deb_wext("event indication length %d\n", iwrq.data.length);
+       lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
+
+       wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
+
+       lbs_deb_leave(LBS_DEB_WEXT);
+}
 
 /**
  *  @brief Find the channel frequency power info with specific channel
@@ -58,8 +98,6 @@ struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
        for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
                rc = &priv->region_channel[j];
 
-               if (priv->enable11d)
-                       rc = &priv->universal_channel[j];
                if (!rc->valid || !rc->CFP)
                        continue;
                if (rc->band != band)
@@ -99,8 +137,6 @@ static struct chan_freq_power *find_cfp_by_band_and_freq(
        for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
                rc = &priv->region_channel[j];
 
-               if (priv->enable11d)
-                       rc = &priv->universal_channel[j];
                if (!rc->valid || !rc->CFP)
                        continue;
                if (rc->band != band)
@@ -120,34 +156,6 @@ static struct chan_freq_power *find_cfp_by_band_and_freq(
        return cfp;
 }
 
-
-/**
- *  @brief Set Radio On/OFF
- *
- *  @param priv                 A pointer to struct lbs_private structure
- *  @option                    Radio Option
- *  @return                    0 --success, otherwise fail
- */
-static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
-{
-       int ret = 0;
-
-       lbs_deb_enter(LBS_DEB_WEXT);
-
-       if (priv->radioon != option) {
-               lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
-               priv->radioon = option;
-
-               ret = lbs_prepare_and_send_command(priv,
-                                           CMD_802_11_RADIO_CONTROL,
-                                           CMD_ACT_SET,
-                                           CMD_OPTION_WAITFORRSP, 0, NULL);
-       }
-
-       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
-       return ret;
-}
-
 /**
  *  @brief Copy active data rates based on adapter mode and status
  *
@@ -183,18 +191,18 @@ static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
                         struct iw_freq *fwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct chan_freq_power *cfp;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
        cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
-                                          priv->curbssparams.channel);
+                                          priv->channel);
 
        if (!cfp) {
-               if (priv->curbssparams.channel)
+               if (priv->channel)
                        lbs_deb_wext("invalid channel %d\n",
-                              priv->curbssparams.channel);
+                              priv->channel);
                return -EINVAL;
        }
 
@@ -209,7 +217,7 @@ static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
                        struct sockaddr *awrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -227,7 +235,7 @@ static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
                         struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -251,7 +259,7 @@ static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
                         struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -268,7 +276,7 @@ static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
                         struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -293,22 +301,18 @@ static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
                        struct iw_param *vwrq, char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
-       u32 rthr = vwrq->value;
+       struct lbs_private *priv = dev->ml_priv;
+       u32 val = vwrq->value;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (vwrq->disabled) {
-               priv->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
-       } else {
-               if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
-                       return -EINVAL;
-               priv->rtsthsd = rthr;
-       }
+       if (vwrq->disabled)
+               val = MRVDRV_RTS_MAX_VALUE;
+
+       if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
+               return -EINVAL;
 
-       ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
-                                   CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
-                                   OID_802_11_RTS_THRESHOLD, &rthr);
+       ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
 
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
@@ -317,21 +321,18 @@ static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
                        struct iw_param *vwrq, char *extra)
 {
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       u16 val = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       priv->rtsthsd = 0;
-       ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
-                                   CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
-                                   OID_802_11_RTS_THRESHOLD, NULL);
+       ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
        if (ret)
                goto out;
 
-       vwrq->value = priv->rtsthsd;
-       vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
-                         || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
+       vwrq->value = val;
+       vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
        vwrq->fixed = 1;
 
 out:
@@ -342,24 +343,19 @@ out:
 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
                         struct iw_param *vwrq, char *extra)
 {
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
-       u32 fthr = vwrq->value;
-       struct lbs_private *priv = dev->priv;
+       u32 val = vwrq->value;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (vwrq->disabled) {
-               priv->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
-       } else {
-               if (fthr < MRVDRV_FRAG_MIN_VALUE
-                   || fthr > MRVDRV_FRAG_MAX_VALUE)
-                       return -EINVAL;
-               priv->fragthsd = fthr;
-       }
+       if (vwrq->disabled)
+               val = MRVDRV_FRAG_MAX_VALUE;
+
+       if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
+               return -EINVAL;
 
-       ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
-                                   CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
-                                   OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
+       ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
 
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
@@ -368,22 +364,19 @@ static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
                         struct iw_param *vwrq, char *extra)
 {
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       u16 val = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       priv->fragthsd = 0;
-       ret = lbs_prepare_and_send_command(priv,
-                                   CMD_802_11_SNMP_MIB,
-                                   CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
-                                   OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
+       ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
        if (ret)
                goto out;
 
-       vwrq->value = priv->fragthsd;
-       vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
-                         || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
+       vwrq->value = val;
+       vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
+                         || (val > MRVDRV_FRAG_MAX_VALUE));
        vwrq->fixed = 1;
 
 out:
@@ -394,7 +387,7 @@ out:
 static int lbs_get_mode(struct net_device *dev,
                         struct iw_request_info *info, u32 * uwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -410,7 +403,7 @@ static int mesh_wlan_get_mode(struct net_device *dev,
 {
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       *uwrq = IW_MODE_REPEAT ;
+       *uwrq = IW_MODE_REPEAT;
 
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
@@ -420,28 +413,30 @@ static int lbs_get_txpow(struct net_device *dev,
                          struct iw_request_info *info,
                          struct iw_param *vwrq, char *extra)
 {
+       struct lbs_private *priv = dev->ml_priv;
+       s16 curlevel = 0;
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       ret = lbs_prepare_and_send_command(priv,
-                                   CMD_802_11_RF_TX_POWER,
-                                   CMD_ACT_TX_POWER_OPT_GET,
-                                   CMD_OPTION_WAITFORRSP, 0, NULL);
+       if (!priv->radio_on) {
+               lbs_deb_wext("tx power off\n");
+               vwrq->value = 0;
+               vwrq->disabled = 1;
+               goto out;
+       }
 
+       ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
        if (ret)
                goto out;
 
-       lbs_deb_wext("tx power level %d dbm\n", priv->txpowerlevel);
-       vwrq->value = priv->txpowerlevel;
+       lbs_deb_wext("tx power level %d dbm\n", curlevel);
+       priv->txpower_cur = curlevel;
+
+       vwrq->value = curlevel;
        vwrq->fixed = 1;
-       if (priv->radioon) {
-               vwrq->disabled = 0;
-               vwrq->flags = IW_TXPOW_DBM;
-       } else {
-               vwrq->disabled = 1;
-       }
+       vwrq->disabled = 0;
+       vwrq->flags = IW_TXPOW_DBM;
 
 out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
@@ -451,31 +446,44 @@ out:
 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
                          struct iw_param *vwrq, char *extra)
 {
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       u16 slimit = 0, llimit = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (vwrq->flags == IW_RETRY_LIMIT) {
-               /* The MAC has a 4-bit Total_Tx_Count register
-                  Total_Tx_Count = 1 + Tx_Retry_Count */
+        if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
+                return -EOPNOTSUPP;
+
+       /* The MAC has a 4-bit Total_Tx_Count register
+          Total_Tx_Count = 1 + Tx_Retry_Count */
 #define TX_RETRY_MIN 0
 #define TX_RETRY_MAX 14
-               if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
-                       return -EINVAL;
+       if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
+               return -EINVAL;
 
-               /* Adding 1 to convert retry count to try count */
-               priv->txretrycount = vwrq->value + 1;
+       /* Add 1 to convert retry count to try count */
+       if (vwrq->flags & IW_RETRY_SHORT)
+               slimit = (u16) (vwrq->value + 1);
+       else if (vwrq->flags & IW_RETRY_LONG)
+               llimit = (u16) (vwrq->value + 1);
+       else
+               slimit = llimit = (u16) (vwrq->value + 1); /* set both */
 
-               ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
-                                           CMD_ACT_SET,
-                                           CMD_OPTION_WAITFORRSP,
-                                           OID_802_11_TX_RETRYCOUNT, NULL);
+       if (llimit) {
+               ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
+                                      llimit);
+               if (ret)
+                       goto out;
+       }
 
+       if (slimit) {
+               /* txretrycount follows the short retry limit */
+               priv->txretrycount = slimit;
+               ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
+                                      slimit);
                if (ret)
                        goto out;
-       } else {
-               return -EOPNOTSUPP;
        }
 
 out:
@@ -486,24 +494,32 @@ out:
 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
                          struct iw_param *vwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
+       u16 val = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       priv->txretrycount = 0;
-       ret = lbs_prepare_and_send_command(priv,
-                                   CMD_802_11_SNMP_MIB,
-                                   CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
-                                   OID_802_11_TX_RETRYCOUNT, NULL);
-       if (ret)
-               goto out;
-
        vwrq->disabled = 0;
-       if (!vwrq->flags) {
-               vwrq->flags = IW_RETRY_LIMIT;
+
+       if (vwrq->flags & IW_RETRY_LONG) {
+               ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
+               if (ret)
+                       goto out;
+
                /* Subtract 1 to convert try count to retry count */
-               vwrq->value = priv->txretrycount - 1;
+               vwrq->value = val - 1;
+               vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
+       } else {
+               ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
+               if (ret)
+                       goto out;
+
+               /* txretry count follows the short retry limit */
+               priv->txretrycount = val;
+               /* Subtract 1 to convert try count to retry count */
+               vwrq->value = val - 1;
+               vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
        }
 
 out:
@@ -554,13 +570,11 @@ static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
                          struct iw_point *dwrq, char *extra)
 {
        int i, j;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct iw_range *range = (struct iw_range *)extra;
        struct chan_freq_power *cfp;
        u8 rates[MAX_RATES + 1];
 
-       u8 flag = 0;
-
        lbs_deb_enter(LBS_DEB_WEXT);
 
        dwrq->length = sizeof(struct iw_range);
@@ -582,52 +596,21 @@ static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
 
        range->scan_capa = IW_SCAN_CAPA_ESSID;
 
-       if (priv->enable11d &&
-           (priv->connect_status == LBS_CONNECTED ||
-           priv->mesh_connect_status == LBS_CONNECTED)) {
-               u8 chan_no;
-               u8 band;
-
-               struct parsed_region_chan_11d *parsed_region_chan =
-                   &priv->parsed_region_chan;
-
-               if (parsed_region_chan == NULL) {
-                       lbs_deb_wext("11d: parsed_region_chan is NULL\n");
-                       goto out;
-               }
-               band = parsed_region_chan->band;
-               lbs_deb_wext("band %d, nr_char %d\n", band,
-                      parsed_region_chan->nr_chan);
-
+       for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
+            && (j < ARRAY_SIZE(priv->region_channel)); j++) {
+               cfp = priv->region_channel[j].CFP;
                for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
-                    && (i < parsed_region_chan->nr_chan); i++) {
-                       chan_no = parsed_region_chan->chanpwr[i].chan;
-                       lbs_deb_wext("chan_no %d\n", chan_no);
-                       range->freq[range->num_frequency].i = (long)chan_no;
+                    && priv->region_channel[j].valid
+                    && cfp
+                    && (i < priv->region_channel[j].nrcfp); i++) {
+                       range->freq[range->num_frequency].i =
+                           (long)cfp->channel;
                        range->freq[range->num_frequency].m =
-                           (long)lbs_chan_2_freq(chan_no, band) * 100000;
+                           (long)cfp->freq * 100000;
                        range->freq[range->num_frequency].e = 1;
+                       cfp++;
                        range->num_frequency++;
                }
-               flag = 1;
-       }
-       if (!flag) {
-               for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
-                    && (j < ARRAY_SIZE(priv->region_channel)); j++) {
-                       cfp = priv->region_channel[j].CFP;
-                       for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
-                            && priv->region_channel[j].valid
-                            && cfp
-                            && (i < priv->region_channel[j].nrcfp); i++) {
-                               range->freq[range->num_frequency].i =
-                                   (long)cfp->channel;
-                               range->freq[range->num_frequency].m =
-                                   (long)cfp->freq * 100000;
-                               range->freq[range->num_frequency].e = 1;
-                               cfp++;
-                               range->num_frequency++;
-                       }
-               }
        }
 
        lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
@@ -656,13 +639,10 @@ static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
        range->num_encoding_sizes = 2;
        range->max_encoding_tokens = 4;
 
-       range->min_pmp = 1000000;
-       range->max_pmp = 120000000;
-       range->min_pmt = 1000;
-       range->max_pmt = 1000000;
-       range->pmp_flags = IW_POWER_PERIOD;
-       range->pmt_flags = IW_POWER_TIMEOUT;
-       range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
+       /*
+        * Right now we support only "iwconfig ethX power on|off"
+        */
+       range->pm_capa = IW_POWER_ON;
 
        /*
         * Minimum version we recommend
@@ -696,22 +676,12 @@ static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
 
        range->sensitivity = 0;
 
-       /*
-        * Setup the supported power level ranges
-        */
+       /* Setup the supported power level ranges */
        memset(range->txpower, 0, sizeof(range->txpower));
-       range->txpower[0] = 5;
-       range->txpower[1] = 7;
-       range->txpower[2] = 9;
-       range->txpower[3] = 11;
-       range->txpower[4] = 13;
-       range->txpower[5] = 15;
-       range->txpower[6] = 17;
-       range->txpower[7] = 19;
-
-       range->num_txpower = 8;
-       range->txpower_capa = IW_TXPOW_DBM;
-       range->txpower_capa |= IW_TXPOW_RANGE;
+       range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
+       range->txpower[0] = priv->txpower_min;
+       range->txpower[1] = priv->txpower_max;
+       range->num_txpower = 2;
 
        range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
                                IW_EVENT_CAPA_MASK(SIOCGIWAP) |
@@ -725,7 +695,6 @@ static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
                                  | IW_ENC_CAPA_CIPHER_CCMP;
        }
 
-out:
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
@@ -733,11 +702,12 @@ out:
 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
                          struct iw_param *vwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
+       int ret = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       if (!priv->ps_supported) {
+       if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
                if (vwrq->disabled)
                        return 0;
                else
@@ -762,8 +732,54 @@ static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
                       "setting power timeout is not supported\n");
                return -EINVAL;
        } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
-               lbs_deb_wext("setting power period not supported\n");
-               return -EINVAL;
+               vwrq->value = vwrq->value / 1000;
+               if (!priv->enter_deep_sleep) {
+                       lbs_pr_err("deep sleep feature is not implemented "
+                                       "for this interface driver\n");
+                       return -EINVAL;
+               }
+
+               if (priv->connect_status == LBS_CONNECTED) {
+                       if ((priv->is_auto_deep_sleep_enabled) &&
+                                               (vwrq->value == -1000)) {
+                               lbs_exit_auto_deep_sleep(priv);
+                               return 0;
+                       } else {
+                               lbs_pr_err("can't use deep sleep cmd in "
+                                               "connected state\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if ((vwrq->value < 0) && (vwrq->value != -1000)) {
+                       lbs_pr_err("unknown option\n");
+                       return -EINVAL;
+               }
+
+               if (vwrq->value > 0) {
+                       if (!priv->is_auto_deep_sleep_enabled) {
+                               priv->is_activity_detected = 0;
+                               priv->auto_deep_sleep_timeout = vwrq->value;
+                               lbs_enter_auto_deep_sleep(priv);
+                       } else {
+                               priv->auto_deep_sleep_timeout = vwrq->value;
+                               lbs_deb_debugfs("auto deep sleep: "
+                                               "already enabled\n");
+                       }
+                       return 0;
+               } else {
+                       if (priv->is_auto_deep_sleep_enabled) {
+                               lbs_exit_auto_deep_sleep(priv);
+                               /* Try to exit deep sleep if auto */
+                               /*deep sleep disabled */
+                               ret = lbs_set_deep_sleep(priv, 0);
+                       }
+                       if (vwrq->value == 0)
+                               ret = lbs_set_deep_sleep(priv, 1);
+                       else if (vwrq->value == -1000)
+                               ret = lbs_set_deep_sleep(priv, 0);
+                       return ret;
+               }
        }
 
        if (priv->psmode != LBS802_11POWERMODECAM) {
@@ -777,28 +793,22 @@ static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
        }
 
        lbs_deb_leave(LBS_DEB_WEXT);
+
        return 0;
 }
 
 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
                          struct iw_param *vwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
-       int mode;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
-       mode = priv->psmode;
-
-       if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
-           || priv->connect_status == LBS_DISCONNECTED)
-       {
-               goto out;
-       }
-
        vwrq->value = 0;
+       vwrq->flags = 0;
+       vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
+               || priv->connect_status == LBS_DISCONNECTED;
 
-out:
        lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
@@ -813,13 +823,14 @@ static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
                EXCELLENT = 95,
                PERFECT = 100
        };
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        u32 rssi_qual;
        u32 tx_qual;
        u32 quality = 0;
-       int stats_valid = 0;
+       int ret, stats_valid = 0;
        u8 rssi;
        u32 tx_retries;
+       struct cmd_ds_802_11_get_log log;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -861,9 +872,15 @@ static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
        quality = rssi_qual;
 
        /* Quality by TX errors */
-       priv->wstats.discard.retries = priv->stats.tx_errors;
+       priv->wstats.discard.retries = dev->stats.tx_errors;
+
+       memset(&log, 0, sizeof(log));
+       log.hdr.size = cpu_to_le16(sizeof(log));
+       ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
+       if (ret)
+               goto out;
 
-       tx_retries = le32_to_cpu(priv->logmsg.retry);
+       tx_retries = le32_to_cpu(log.retry);
 
        if (tx_retries > 75)
                tx_qual = (90 - tx_retries) * POOR / 15;
@@ -879,10 +896,9 @@ static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
                    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
        quality = min(quality, tx_qual);
 
-       priv->wstats.discard.code = le32_to_cpu(priv->logmsg.wepundecryptable);
-       priv->wstats.discard.fragment = le32_to_cpu(priv->logmsg.rxfrag);
+       priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
        priv->wstats.discard.retries = tx_retries;
-       priv->wstats.discard.misc = le32_to_cpu(priv->logmsg.ackfailure);
+       priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
 
        /* Calculate quality */
        priv->wstats.qual.qual = min_t(u8, quality, 100);
@@ -890,10 +906,10 @@ static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
        stats_valid = 1;
 
        /* update stats asynchronously for future calls */
-       lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
-                                       0, 0, NULL);
-       lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
+       ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
                                        0, 0, NULL);
+       if (ret)
+               lbs_pr_err("RSSI command failed\n");
 out:
        if (!stats_valid) {
                priv->wstats.miss.beacon = 0;
@@ -916,7 +932,7 @@ static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
                  struct iw_freq *fwrq, char *extra)
 {
        int ret = -EINVAL;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct chan_freq_power *cfp;
        struct assoc_request * assoc_req;
 
@@ -973,7 +989,7 @@ static int lbs_mesh_set_freq(struct net_device *dev,
                             struct iw_request_info *info,
                             struct iw_freq *fwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct chan_freq_power *cfp;
        int ret = -EINVAL;
 
@@ -1003,14 +1019,16 @@ static int lbs_mesh_set_freq(struct net_device *dev,
                goto out;
        }
 
-       if (fwrq->m != priv->curbssparams.channel) {
+       if (fwrq->m != priv->channel) {
                lbs_deb_wext("mesh channel change forces eth disconnect\n");
                if (priv->mode == IW_MODE_INFRA)
-                       lbs_send_deauthentication(priv);
+                       lbs_cmd_80211_deauthenticate(priv,
+                                                    priv->curbssparams.bssid,
+                                                    WLAN_REASON_DEAUTH_LEAVING);
                else if (priv->mode == IW_MODE_ADHOC)
-                       lbs_stop_adhoc_network(priv);
+                       lbs_adhoc_stop(priv);
        }
-       lbs_mesh_config(priv, 1, fwrq->m);
+       lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
        lbs_update_channel(priv);
        ret = 0;
 
@@ -1022,36 +1040,58 @@ out:
 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
                  struct iw_param *vwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        u8 new_rate = 0;
        int ret = -EINVAL;
        u8 rates[MAX_RATES + 1];
 
        lbs_deb_enter(LBS_DEB_WEXT);
+
        lbs_deb_wext("vwrq->value %d\n", vwrq->value);
+       lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
+
+       if (vwrq->fixed && vwrq->value == -1)
+               goto out;
 
        /* Auto rate? */
-       if (vwrq->value == -1) {
-               priv->auto_rate = 1;
+       priv->enablehwauto = !vwrq->fixed;
+
+       if (vwrq->value == -1)
                priv->cur_rate = 0;
-       else {
+       else {
                if (vwrq->value % 100000)
                        goto out;
 
+               new_rate = vwrq->value / 500000;
+               priv->cur_rate = new_rate;
+               /* the rest is only needed for lbs_set_data_rate() */
                memset(rates, 0, sizeof(rates));
                copy_active_data_rates(priv, 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;
                }
-
-               priv->cur_rate = new_rate;
-               priv->auto_rate = 0;
+               if (priv->fwrelease < 0x09000000) {
+                       ret = lbs_set_power_adapt_cfg(priv, 0,
+                                       POW_ADAPT_DEFAULT_P0,
+                                       POW_ADAPT_DEFAULT_P1,
+                                       POW_ADAPT_DEFAULT_P2);
+                       if (ret)
+                               goto out;
+               }
+               ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
+                               TPC_DEFAULT_P2, 1);
+               if (ret)
+                       goto out;
        }
 
-       ret = lbs_set_data_rate(priv, new_rate);
+       /* Try the newer command first (Firmware Spec 5.1 and above) */
+       ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
+
+       /* Fallback to older version */
+       if (ret)
+               ret = lbs_set_data_rate(priv, new_rate);
 
 out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
@@ -1061,14 +1101,14 @@ out:
 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
                  struct iw_param *vwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
        if (priv->connect_status == LBS_CONNECTED) {
                vwrq->value = priv->cur_rate * 500000;
 
-               if (priv->auto_rate)
+               if (priv->enablehwauto)
                        vwrq->fixed = 0;
                else
                        vwrq->fixed = 1;
@@ -1086,7 +1126,7 @@ static int lbs_set_mode(struct net_device *dev,
                  struct iw_request_info *info, u32 * uwrq, char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct assoc_request * assoc_req;
 
        lbs_deb_enter(LBS_DEB_WEXT);
@@ -1131,7 +1171,7 @@ static int lbs_get_encode(struct net_device *dev,
                           struct iw_request_info *info,
                           struct iw_point *dwrq, u8 * extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
 
        lbs_deb_enter(LBS_DEB_WEXT);
@@ -1326,7 +1366,7 @@ static int lbs_set_encode(struct net_device *dev,
                    struct iw_point *dwrq, char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct assoc_request * assoc_req;
        u16 is_default = 0, index = 0, set_tx_key = 0;
 
@@ -1402,7 +1442,7 @@ static int lbs_get_encodeext(struct net_device *dev,
                              char *extra)
 {
        int ret = -EINVAL;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
        int index, max_key_len;
 
@@ -1508,7 +1548,7 @@ static int lbs_set_encodeext(struct net_device *dev,
                              char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
        int alg = ext->alg;
        struct assoc_request * assoc_req;
@@ -1611,12 +1651,26 @@ static int lbs_set_encodeext(struct net_device *dev,
                        set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
                }
 
-               disable_wep (assoc_req);
+               /* Only disable wep if necessary: can't waste time here. */
+               if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
+                       disable_wep(assoc_req);
        }
 
 out:
        if (ret == 0) {
-               lbs_postpone_association_work(priv);
+               /* 802.1x and WPA rekeying must happen as quickly as possible,
+                * especially during the 4-way handshake; thus if in
+                * infrastructure mode, and either (a) 802.1x is enabled or
+                * (b) WPA is being used, set the key right away.
+                */
+               if (assoc_req->mode == IW_MODE_INFRA &&
+                   ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
+                    (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
+                     assoc_req->secinfo.WPAenabled ||
+                     assoc_req->secinfo.WPA2enabled)) {
+                       lbs_do_association_work(priv);
+               } else
+                       lbs_postpone_association_work(priv);
        } else {
                lbs_cancel_association_work(priv);
        }
@@ -1632,7 +1686,7 @@ static int lbs_set_genie(struct net_device *dev,
                          struct iw_point *dwrq,
                          char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
        struct assoc_request * assoc_req;
 
@@ -1678,7 +1732,7 @@ static int lbs_get_genie(struct net_device *dev,
                          char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -1706,7 +1760,7 @@ static int lbs_set_auth(struct net_device *dev,
                         struct iw_param *dwrq,
                         char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct assoc_request * assoc_req;
        int ret = 0;
        int updated = 0;
@@ -1721,16 +1775,22 @@ static int lbs_set_auth(struct net_device *dev,
        }
 
        switch (dwrq->flags & IW_AUTH_INDEX) {
+       case IW_AUTH_PRIVACY_INVOKED:
+       case IW_AUTH_RX_UNENCRYPTED_EAPOL:
        case IW_AUTH_TKIP_COUNTERMEASURES:
        case IW_AUTH_CIPHER_PAIRWISE:
        case IW_AUTH_CIPHER_GROUP:
-       case IW_AUTH_KEY_MGMT:
        case IW_AUTH_DROP_UNENCRYPTED:
                /*
                 * libertas does not use these parameters
                 */
                break;
 
+       case IW_AUTH_KEY_MGMT:
+               assoc_req->secinfo.key_mgmt = dwrq->value;
+               updated = 1;
+               break;
+
        case IW_AUTH_WPA_VERSION:
                if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
                        assoc_req->secinfo.WPAenabled = 0;
@@ -1805,11 +1865,15 @@ static int lbs_get_auth(struct net_device *dev,
                         char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
        switch (dwrq->flags & IW_AUTH_INDEX) {
+       case IW_AUTH_KEY_MGMT:
+               dwrq->value = priv->secinfo.key_mgmt;
+               break;
+
        case IW_AUTH_WPA_VERSION:
                dwrq->value = 0;
                if (priv->secinfo.WPAenabled)
@@ -1842,40 +1906,78 @@ static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
                   struct iw_param *vwrq, char *extra)
 {
        int ret = 0;
-       struct lbs_private *priv = dev->priv;
-
-       u16 dbm;
+       struct lbs_private *priv = dev->ml_priv;
+       s16 dbm = (s16) vwrq->value;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
        if (vwrq->disabled) {
-               lbs_radio_ioctl(priv, RADIO_OFF);
-               return 0;
+               lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
+               goto out;
        }
 
-       priv->preamble = CMD_TYPE_AUTO_PREAMBLE;
-
-       lbs_radio_ioctl(priv, RADIO_ON);
+       if (vwrq->fixed == 0) {
+               /* User requests automatic tx power control, however there are
+                * many auto tx settings.  For now use firmware defaults until
+                * we come up with a good way to expose these to the user. */
+               if (priv->fwrelease < 0x09000000) {
+                       ret = lbs_set_power_adapt_cfg(priv, 1,
+                                       POW_ADAPT_DEFAULT_P0,
+                                       POW_ADAPT_DEFAULT_P1,
+                                       POW_ADAPT_DEFAULT_P2);
+                       if (ret)
+                               goto out;
+               }
+               ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
+                               TPC_DEFAULT_P2, 1);
+               if (ret)
+                       goto out;
+               dbm = priv->txpower_max;
+       } else {
+               /* 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_DBM) {
+                       ret = -EOPNOTSUPP;
+                       goto out;
+               }
 
-       /* 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) {
-               return -EOPNOTSUPP;
-       } else
-               dbm = (u16) vwrq->value;
+               /* Validate requested power level against firmware allowed
+                * levels */
+               if (priv->txpower_min && (dbm < priv->txpower_min)) {
+                       ret = -EINVAL;
+                       goto out;
+               }
 
-       /* auto tx power control */
+               if (priv->txpower_max && (dbm > priv->txpower_max)) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               if (priv->fwrelease < 0x09000000) {
+                       ret = lbs_set_power_adapt_cfg(priv, 0,
+                                       POW_ADAPT_DEFAULT_P0,
+                                       POW_ADAPT_DEFAULT_P1,
+                                       POW_ADAPT_DEFAULT_P2);
+                       if (ret)
+                               goto out;
+               }
+               ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
+                               TPC_DEFAULT_P2, 1);
+               if (ret)
+                       goto out;
+       }
 
-       if (vwrq->fixed == 0)
-               dbm = 0xffff;
+       /* If the radio was off, turn it on */
+       if (!priv->radio_on) {
+               ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
+               if (ret)
+                       goto out;
+       }
 
-       lbs_deb_wext("txpower set %d dbm\n", dbm);
+       lbs_deb_wext("txpower set %d dBm\n", dbm);
 
-       ret = lbs_prepare_and_send_command(priv,
-                                   CMD_802_11_RF_TX_POWER,
-                                   CMD_ACT_TX_POWER_OPT_SET_LOW,
-                                   CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
+       ret = lbs_set_tx_power(priv, dbm);
 
+out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
@@ -1883,7 +1985,7 @@ static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
                   struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -1918,17 +2020,23 @@ static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
                   struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
-       u8 ssid[IW_ESSID_MAX_SIZE];
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
        u8 ssid_len = 0;
        struct assoc_request * assoc_req;
        int in_ssid_len = dwrq->length;
+       DECLARE_SSID_BUF(ssid_buf);
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
+       if (!priv->radio_on) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        /* Check the size of the string */
-       if (in_ssid_len > IW_ESSID_MAX_SIZE) {
+       if (in_ssid_len > IEEE80211_MAX_SSID_LEN) {
                ret = -E2BIG;
                goto out;
        }
@@ -1947,7 +2055,7 @@ static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
                lbs_deb_wext("requested any SSID\n");
        } else {
                lbs_deb_wext("requested SSID '%s'\n",
-                            escape_essid(ssid, ssid_len));
+                            print_ssid(ssid_buf, ssid, ssid_len));
        }
 
 out:
@@ -1959,7 +2067,7 @@ out:
                        ret = -ENOMEM;
                } else {
                        /* Copy the SSID to the association request */
-                       memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
+                       memcpy(&assoc_req->ssid, &ssid, IEEE80211_MAX_SSID_LEN);
                        assoc_req->ssid_len = ssid_len;
                        set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
                        lbs_postpone_association_work(priv);
@@ -1981,7 +2089,7 @@ static int lbs_mesh_get_essid(struct net_device *dev,
                              struct iw_request_info *info,
                              struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
@@ -1999,13 +2107,18 @@ static int lbs_mesh_set_essid(struct net_device *dev,
                              struct iw_request_info *info,
                              struct iw_point *dwrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        int ret = 0;
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
+       if (!priv->radio_on) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        /* Check the size of the string */
-       if (dwrq->length > IW_ESSID_MAX_SIZE) {
+       if (dwrq->length > IEEE80211_MAX_SSID_LEN) {
                ret = -E2BIG;
                goto out;
        }
@@ -2019,7 +2132,8 @@ static int lbs_mesh_set_essid(struct net_device *dev,
                priv->mesh_ssid_len = dwrq->length;
        }
 
-       lbs_mesh_config(priv, 1, priv->curbssparams.channel);
+       lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
+                       priv->channel);
  out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
@@ -2037,17 +2151,19 @@ static int lbs_mesh_set_essid(struct net_device *dev,
 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
                 struct sockaddr *awrq, char *extra)
 {
-       struct lbs_private *priv = dev->priv;
+       struct lbs_private *priv = dev->ml_priv;
        struct assoc_request * assoc_req;
        int ret = 0;
-       DECLARE_MAC_BUF(mac);
 
        lbs_deb_enter(LBS_DEB_WEXT);
 
+       if (!priv->radio_on)
+               return -EINVAL;
+
        if (awrq->sa_family != ARPHRD_ETHER)
                return -EINVAL;
 
-       lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
+       lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
 
        mutex_lock(&priv->lock);
 
@@ -2068,23 +2184,6 @@ static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
        return ret;
 }
 
-void lbs_get_fwversion(struct lbs_private *priv, char *fwversion, int maxlen)
-{
-       char fwver[32];
-
-       mutex_lock(&priv->lock);
-
-       sprintf(fwver, "%u.%u.%u.p%u",
-               priv->fwrelease >> 24 & 0xff,
-               priv->fwrelease >> 16 & 0xff,
-               priv->fwrelease >>  8 & 0xff,
-               priv->fwrelease       & 0xff);
-
-       mutex_unlock(&priv->lock);
-       snprintf(fwversion, maxlen, fwver);
-}
-
-
 /*
  * iwconfig settable callbacks
  */