[PATCH] libertas: fix 'keep previous scan' behavior
[pandora-kernel.git] / drivers / net / wireless / libertas / wext.c
index 69f52b6..518371a 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
  *
@@ -102,8 +110,8 @@ struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * ada
        }
 
        if (!cfp && channel)
-               lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find "
-                      "cfp by band %d & channel %d\n", band, channel);
+               lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
+                      "cfp by band %d / channel %d\n", band, channel);
 
        return cfp;
 }
@@ -143,8 +151,8 @@ static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
        }
 
        if (!cfp && freq)
-               lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
-                      "band %d & freq %d\n", band, freq);
+               lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
+                      "band %d / freq %d\n", band, freq);
 
        return cfp;
 }
@@ -160,7 +168,7 @@ static int updatecurrentchannel(wlan_private * priv)
                                    cmd_opt_802_11_rf_channel_get,
                                    cmd_option_waitforrsp, 0, NULL);
 
-       lbs_pr_debug(1, "Current channel = %d\n",
+       lbs_deb_wext("current channel %d\n",
               priv->adapter->curbssparams.channel);
 
        return ret;
@@ -168,7 +176,7 @@ static int updatecurrentchannel(wlan_private * priv)
 
 static int setcurrentchannel(wlan_private * priv, int channel)
 {
-       lbs_pr_debug(1, "Set channel = %d\n", channel);
+       lbs_deb_wext("set channel %d\n", channel);
 
        /*
         **  Current channel is not set to adhocchannel requested, set channel
@@ -181,6 +189,8 @@ static int setcurrentchannel(wlan_private * priv, int channel)
 static int changeadhocchannel(wlan_private * priv, int channel)
 {
        int ret = 0;
+       struct WLAN_802_11_SSID curadhocssid;
+       struct bss_descriptor * join_bss = NULL;
        wlan_adapter *adapter = priv->adapter;
 
        adapter->adhocchannel = channel;
@@ -189,11 +199,10 @@ static int changeadhocchannel(wlan_private * priv, int channel)
 
        if (adapter->curbssparams.channel == adapter->adhocchannel) {
                /* adhocchannel is set to the current channel already */
-               LEAVE();
-               return 0;
+               goto out;
        }
 
-       lbs_pr_debug(1, "Updating channel from %d to %d\n",
+       lbs_deb_wext("updating channel from %d to %d\n",
               adapter->curbssparams.channel, adapter->adhocchannel);
 
        setcurrentchannel(priv, adapter->adhocchannel);
@@ -201,54 +210,49 @@ static int changeadhocchannel(wlan_private * priv, int channel)
        updatecurrentchannel(priv);
 
        if (adapter->curbssparams.channel != adapter->adhocchannel) {
-               lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n",
+               lbs_deb_wext("failed to updated channel to %d, channel = %d\n",
                       adapter->adhocchannel, adapter->curbssparams.channel);
-               LEAVE();
-               return -1;
+               ret = -1;
+               goto out;
        }
 
-       if (adapter->connect_status == libertas_connected) {
-               int i;
-               struct WLAN_802_11_SSID curadhocssid;
+       if (adapter->connect_status != libertas_connected)
+               goto out;
 
-               lbs_pr_debug(1, "channel Changed while in an IBSS\n");
+       lbs_deb_wext("channel changed while in IBSS\n");
 
-               /* Copy the current ssid */
-               memcpy(&curadhocssid, &adapter->curbssparams.ssid,
-                      sizeof(struct WLAN_802_11_SSID));
+       /* Copy the current ssid */
+       memcpy(&curadhocssid, &adapter->curbssparams.ssid,
+              sizeof(struct WLAN_802_11_SSID));
 
-               /* Exit Adhoc mode */
-               lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
-               ret = libertas_stop_adhoc_network(priv);
+       /* Exit Adhoc mode */
+       lbs_deb_wext("in changeadhocchannel(): sending Adhoc stop\n");
+       ret = libertas_stop_adhoc_network(priv);
+       if (ret)
+               goto out;
 
-               if (ret) {
-                       LEAVE();
-                       return ret;
-               }
-               /* 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, &curadhocssid, 0);
+       /* 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, &curadhocssid, 1);
 
-               // find out the BSSID that matches the current SSID
-               i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
-                                  IW_MODE_ADHOC);
+       /* find out the BSSID that matches the current SSID */
+       join_bss = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
+                          IW_MODE_ADHOC);
 
-               if (i >= 0) {
-                       lbs_pr_debug(1, "SSID found at %d in List,"
-                              "so join\n", i);
-                       libertas_join_adhoc_network(priv, &adapter->scantable[i]);
-               } else {
-                       // else send START command
-                       lbs_pr_debug(1, "SSID not found in list, "
-                              "so creating adhoc with ssid = %s\n",
-                              curadhocssid.ssid);
-                       libertas_start_adhoc_network(priv, &curadhocssid);
-               }               // end of else (START command)
+       if (join_bss) {
+               lbs_deb_wext("SSID found in list, so join\n");
+               libertas_join_adhoc_network(priv, join_bss);
+       } else {
+               lbs_deb_wext("SSID not found in list, "
+                      "creating AdHoc with SSID '%s'\n",
+                      curadhocssid.ssid);
+               libertas_start_adhoc_network(priv, &curadhocssid);
        }
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 /**
@@ -263,10 +267,10 @@ int wlan_radio_ioctl(wlan_private * priv, u8 option)
        int ret = 0;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (adapter->radioon != option) {
-               lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
+               lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
                adapter->radioon = option;
 
                ret = libertas_prepare_and_send_command(priv,
@@ -275,7 +279,7 @@ int wlan_radio_ioctl(wlan_private * priv, u8 option)
                                            cmd_option_waitforrsp, 0, NULL);
        }
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -312,15 +316,15 @@ static int get_active_data_rates(wlan_adapter * adapter,
 {
        int k = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (adapter->connect_status != libertas_connected) {
                if (adapter->mode == IW_MODE_INFRA) {
-                       lbs_pr_debug(1, "Infra\n");
+                       lbs_deb_wext("infra\n");
                        k = copyrates(rates, k, libertas_supported_rates,
                                      sizeof(libertas_supported_rates));
                } else {
-                       lbs_pr_debug(1, "Adhoc G\n");
+                       lbs_deb_wext("Adhoc G\n");
                        k = copyrates(rates, k, libertas_adhoc_rates_g,
                                      sizeof(libertas_adhoc_rates_g));
                }
@@ -329,8 +333,7 @@ static int get_active_data_rates(wlan_adapter * adapter,
                              adapter->curbssparams.numofrates);
        }
 
-       LEAVE();
-
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
        return k;
 }
 
@@ -342,7 +345,7 @@ static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
        char mrvl[6] = { "MRVL-" };
        int cnt;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        strcpy(cwrq, mrvl);
 
@@ -360,8 +363,7 @@ static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
        }
        *cwrq = '\0';
 
-       LEAVE();
-
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -372,14 +374,14 @@ static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        struct chan_freq_power *cfp;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
                                           adapter->curbssparams.channel);
 
        if (!cfp) {
                if (adapter->curbssparams.channel)
-                       lbs_pr_debug(1, "Invalid channel=%d\n",
+                       lbs_deb_wext("invalid channel %d\n",
                               adapter->curbssparams.channel);
                return -EINVAL;
        }
@@ -387,9 +389,8 @@ static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
        fwrq->m = (long)cfp->freq * 100000;
        fwrq->e = 1;
 
-       lbs_pr_debug(1, "freq=%u\n", fwrq->m);
-
-       LEAVE();
+       lbs_deb_wext("freq %u\n", fwrq->m);
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -399,7 +400,7 @@ static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (adapter->connect_status == libertas_connected) {
                memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
@@ -408,7 +409,7 @@ static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
        }
        awrq->sa_family = ARPHRD_ETHER;
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -418,7 +419,7 @@ static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /*
         * Check the size of the string
@@ -433,7 +434,7 @@ static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
        memcpy(adapter->nodename, extra, dwrq->length);
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -443,7 +444,7 @@ static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /*
         * Get the Nick Name saved
@@ -464,7 +465,7 @@ static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
         */
        dwrq->length = strlen(extra) + 1;
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -476,7 +477,7 @@ static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        int rthr = vwrq->value;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (vwrq->disabled) {
                adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
@@ -490,7 +491,7 @@ static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
                                    cmd_act_set, cmd_option_waitforrsp,
                                    OID_802_11_RTS_THRESHOLD, &rthr);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -501,24 +502,23 @@ static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        adapter->rtsthsd = 0;
        ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
                                    cmd_act_get, cmd_option_waitforrsp,
                                    OID_802_11_RTS_THRESHOLD, NULL);
-       if (ret) {
-               LEAVE();
-               return ret;
-       }
+       if (ret)
+               goto out;
 
        vwrq->value = adapter->rtsthsd;
        vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
                          || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
        vwrq->fixed = 1;
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
@@ -529,7 +529,7 @@ static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (vwrq->disabled) {
                adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
@@ -543,7 +543,8 @@ static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
        ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
                                    cmd_act_set, cmd_option_waitforrsp,
                                    OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
-       LEAVE();
+
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -554,24 +555,23 @@ static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        adapter->fragthsd = 0;
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_snmp_mib,
                                    cmd_act_get, cmd_option_waitforrsp,
                                    OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
-       if (ret) {
-               LEAVE();
-               return ret;
-       }
+       if (ret)
+               goto out;
 
        vwrq->value = adapter->fragthsd;
        vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
                          || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
        vwrq->fixed = 1;
 
-       LEAVE();
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -581,11 +581,11 @@ static int wlan_get_mode(struct net_device *dev,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        *uwrq = adapter->mode;
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -597,19 +597,17 @@ static int wlan_get_txpow(struct net_device *dev,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_rf_tx_power,
                                    cmd_act_tx_power_opt_get,
                                    cmd_option_waitforrsp, 0, NULL);
 
-       if (ret) {
-               LEAVE();
-               return ret;
-       }
+       if (ret)
+               goto out;
 
-       lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
+       lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
        vwrq->value = adapter->txpowerlevel;
        vwrq->fixed = 1;
        if (adapter->radioon) {
@@ -619,8 +617,9 @@ static int wlan_get_txpow(struct net_device *dev,
                vwrq->disabled = 1;
        }
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
@@ -630,7 +629,7 @@ static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (vwrq->flags == IW_RETRY_LIMIT) {
                /* The MAC has a 4-bit Total_Tx_Count register
@@ -648,16 +647,15 @@ static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
                                            cmd_option_waitforrsp,
                                            OID_802_11_TX_RETRYCOUNT, NULL);
 
-               if (ret) {
-                       LEAVE();
-                       return ret;
-               }
+               if (ret)
+                       goto out;
        } else {
                return -EOPNOTSUPP;
        }
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
@@ -667,16 +665,16 @@ static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
+
        adapter->txretrycount = 0;
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_snmp_mib,
                                    cmd_act_get, cmd_option_waitforrsp,
                                    OID_802_11_TX_RETRYCOUNT, NULL);
-       if (ret) {
-               LEAVE();
-               return ret;
-       }
+       if (ret)
+               goto out;
+
        vwrq->disabled = 0;
        if (!vwrq->flags) {
                vwrq->flags = IW_RETRY_LIMIT;
@@ -684,8 +682,9 @@ static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
                vwrq->value = adapter->txretrycount - 1;
        }
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 static inline void sort_channels(struct iw_freq *freq, int num)
@@ -739,7 +738,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
 
        u8 flag = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        dwrq->length = sizeof(struct iw_range);
        memset(range, 0, sizeof(struct iw_range));
@@ -755,7 +754,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
                range->bitrate[i] = (rates[i] & 0x7f) * 500000;
        }
        range->num_bitrates = i;
-       lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
+       lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
               range->num_bitrates);
 
        range->num_frequency = 0;
@@ -768,18 +767,17 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
                    &adapter->parsed_region_chan;
 
                if (parsed_region_chan == NULL) {
-                       lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
-                       LEAVE();
-                       return 0;
+                       lbs_deb_wext("11d: parsed_region_chan is NULL\n");
+                       goto out;
                }
                band = parsed_region_chan->band;
-               lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
+               lbs_deb_wext("band %d, nr_char %d\n", band,
                       parsed_region_chan->nr_chan);
 
                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_pr_debug(1, "chan_no=%d\n", chan_no);
+                       lbs_deb_wext("chan_no %d\n", chan_no);
                        range->freq[range->num_frequency].i = (long)chan_no;
                        range->freq[range->num_frequency].m =
                            (long)libertas_chan_2_freq(chan_no, band) * 100000;
@@ -808,7 +806,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
                }
        }
 
-       lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
+       lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
               IW_MAX_FREQUENCIES, range->num_frequency);
 
        range->num_channels = range->num_frequency;
@@ -903,7 +901,8 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
                                  | IW_ENC_CAPA_CIPHER_CCMP;
        }
 
-       LEAVE();
+out:
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -913,7 +912,7 @@ static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /* PS is currently supported only in Infrastructure mode
         * Remove this check if it is to be supported in IBSS mode also
@@ -929,11 +928,11 @@ static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
        }
 
        if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
-               lbs_pr_debug(1,
-                      "Setting power timeout command is not supported\n");
+               lbs_deb_wext(
+                      "setting power timeout is not supported\n");
                return -EINVAL;
        } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
-               lbs_pr_debug(1, "Setting power period command is not supported\n");
+               lbs_deb_wext("setting power period not supported\n");
                return -EINVAL;
        }
 
@@ -947,7 +946,7 @@ static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
                libertas_ps_sleep(priv, cmd_option_waitforrsp);
        }
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -958,19 +957,20 @@ static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
        wlan_adapter *adapter = priv->adapter;
        int mode;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        mode = adapter->psmode;
 
        if ((vwrq->disabled = (mode == wlan802_11powermodecam))
-           || adapter->connect_status == libertas_disconnected) {
-               LEAVE();
-               return 0;
+           || adapter->connect_status == libertas_disconnected)
+       {
+               goto out;
        }
 
        vwrq->value = 0;
 
-       LEAVE();
+out:
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -1063,6 +1063,16 @@ static const struct iw_priv_args wlan_private_args[] = {
         IW_PRIV_TYPE_CHAR | 128,
         IW_PRIV_TYPE_CHAR | 128,
         "bt_list"},
+       {
+        WLAN_SUBCMD_BT_SET_INVERT,
+        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+        IW_PRIV_TYPE_NONE,
+        "bt_set_invert"},
+       {
+        WLAN_SUBCMD_BT_GET_INVERT,
+        IW_PRIV_TYPE_NONE,
+        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+        "bt_get_invert"},
        /* FWT Management */
        {
         WLAN_SUBCMD_FWT_ADD,
@@ -1125,7 +1135,7 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
        u8 rssi;
        u32 tx_retries;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        priv->wstats.status = adapter->mode;
 
@@ -1145,8 +1155,8 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
                    CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
        }
 
-       lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
-       lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
+       lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
+       lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
 
        rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
        if (rssi < 15)
@@ -1183,7 +1193,7 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
        quality = min(quality, tx_qual);
 
        priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
-       priv->wstats.discard.fragment = adapter->logmsg.fcserror;
+       priv->wstats.discard.fragment = adapter->logmsg.rxfrag;
        priv->wstats.discard.retries = tx_retries;
        priv->wstats.discard.misc = adapter->logmsg.ackfailure;
 
@@ -1209,7 +1219,7 @@ out:
                    IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
        }
 
-       LEAVE ();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return &priv->wstats;
 
 
@@ -1224,7 +1234,7 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
        int rc = -EINPROGRESS;  /* Call commit handler */
        struct chan_freq_power *cfp;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /*
         * If setting by frequency, convert to a channel
@@ -1236,7 +1246,7 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
 
                cfp = find_cfp_by_band_and_freq(adapter, 0, f);
                if (!cfp) {
-                       lbs_pr_debug(1, "Invalid freq=%ld\n", f);
+                       lbs_deb_wext("invalid freq %ld\n", f);
                        return -EINVAL;
                }
 
@@ -1267,7 +1277,7 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
                                 *  command to set WEP in firmware
                                 */
                                if (adapter->secinfo.wep_enabled) {
-                                       lbs_pr_debug(1, "set_freq: WEP enabled\n");
+                                       lbs_deb_wext("set_freq: WEP enabled\n");
                                        ret = libertas_prepare_and_send_command(priv,
                                                                    cmd_802_11_set_wep,
                                                                    cmd_act_add,
@@ -1276,8 +1286,8 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
                                                                    NULL);
 
                                        if (ret) {
-                                               LEAVE();
-                                               return ret;
+                                               rc = ret;
+                                               goto out;
                                        }
 
                                        adapter->currentpacketfilter |=
@@ -1291,7 +1301,8 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
                }
        }
 
-       LEAVE();
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", rc);
        return rc;
 }
 
@@ -1338,9 +1349,9 @@ static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
        u8 rates[WLAN_SUPPORTED_RATES];
        u8 *rate;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
-       lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
+       lbs_deb_wext("vwrq->value %d\n", vwrq->value);
 
        if (vwrq->value == -1) {
                action = cmd_act_set_tx_auto;   // Auto
@@ -1357,15 +1368,15 @@ static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
                get_active_data_rates(adapter, rates);
                rate = rates;
                while (*rate) {
-                       lbs_pr_debug(1, "Rate=0x%X  Wanted=0x%X\n", *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( "The fixed data rate 0x%X is out "
-                              "of range.\n", data_rate);
+                       lbs_pr_alert("fixed data rate 0x%X out "
+                              "of range\n", data_rate);
                        return -EINVAL;
                }
 
@@ -1377,7 +1388,7 @@ static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
        ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
                                    action, cmd_option_waitforrsp, 0, NULL);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1387,7 +1398,7 @@ static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (adapter->is_datarate_auto) {
                vwrq->fixed = 0;
@@ -1397,7 +1408,7 @@ static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
 
        vwrq->value = adapter->datarate * 500000;
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -1409,12 +1420,12 @@ static int wlan_set_mode(struct net_device *dev,
        wlan_adapter *adapter = priv->adapter;
        struct assoc_request * assoc_req;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (   (*uwrq != IW_MODE_ADHOC)
            && (*uwrq != IW_MODE_INFRA)
            && (*uwrq != IW_MODE_AUTO)) {
-               lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
+               lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
                ret = -EINVAL;
                goto out;
        }
@@ -1428,12 +1439,12 @@ static int wlan_set_mode(struct net_device *dev,
                assoc_req->mode = *uwrq;
                set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
                wlan_postpone_association_work(priv);
-               lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
+               lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
        }
        mutex_unlock(&adapter->lock);
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1455,9 +1466,9 @@ static int wlan_get_encode(struct net_device *dev,
        wlan_adapter *adapter = priv->adapter;
        int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
-       lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
+       lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
               dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
 
        dwrq->flags = 0;
@@ -1513,13 +1524,13 @@ static int wlan_get_encode(struct net_device *dev,
 
        dwrq->flags |= IW_ENCODE_NOKEY;
 
-       lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
+       lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
               extra[0], extra[1], extra[2],
               extra[3], extra[4], extra[5], dwrq->length);
 
-       lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
+       lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -1539,20 +1550,21 @@ static int wlan_set_wep_key(struct assoc_request *assoc_req,
                            u16 index,
                            int set_tx_key)
 {
+       int ret = 0;
        struct WLAN_802_11_KEY *pkey;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /* Paranoid validation of key index */
        if (index > 3) {
-               LEAVE();
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out;
        }
 
        /* validate max key length */
        if (key_length > KEY_LEN_WEP_104) {
-               LEAVE();
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out;
        }
 
        pkey = &assoc_req->wep_keys[index];
@@ -1570,17 +1582,18 @@ static int wlan_set_wep_key(struct assoc_request *assoc_req,
        if (set_tx_key) {
                /* Ensure the chosen key is valid */
                if (!pkey->len) {
-                       lbs_pr_debug(1, "key not set, so cannot enable it\n");
-                       LEAVE();
-                       return -EINVAL;
+                       lbs_deb_wext("key not set, so cannot enable it\n");
+                       ret = -EINVAL;
+                       goto out;
                }
                assoc_req->wep_tx_keyidx = index;
        }
 
        assoc_req->secinfo.wep_enabled = 1;
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 static int validate_key_index(u16 def_index, u16 raw_index,
@@ -1636,7 +1649,7 @@ static int wlan_set_encode(struct net_device *dev,
        struct assoc_request * assoc_req;
        u16 is_default = 0, index = 0, set_tx_key = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        mutex_lock(&adapter->lock);
        assoc_req = wlan_get_association_request(adapter);
@@ -1688,7 +1701,7 @@ out:
        }
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1712,7 +1725,7 @@ static int wlan_get_encodeext(struct net_device *dev,
        struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
        int index, max_key_len;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        max_key_len = dwrq->length - sizeof(*ext);
        if (max_key_len < 0)
@@ -1775,7 +1788,7 @@ static int wlan_get_encodeext(struct net_device *dev,
        ret = 0;
 
 out:
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1800,7 +1813,7 @@ static int wlan_set_encodeext(struct net_device *dev,
        int alg = ext->alg;
        struct assoc_request * assoc_req;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        mutex_lock(&adapter->lock);
        assoc_req = wlan_get_association_request(adapter);
@@ -1855,8 +1868,8 @@ static int wlan_set_encodeext(struct net_device *dev,
                        && (ext->key_len != KEY_LEN_WPA_TKIP))
                    || ((alg == IW_ENCODE_ALG_CCMP)
                        && (ext->key_len != KEY_LEN_WPA_AES))) {
-                               lbs_pr_debug(1, "Invalid size %d for key of alg"
-                                      "type %d.\n",
+                               lbs_deb_wext("invalid size %d for key of alg"
+                                      "type %d\n",
                                       ext->key_len,
                                       alg);
                                ret = -EINVAL;
@@ -1905,7 +1918,7 @@ out:
        }
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1920,7 +1933,7 @@ static int wlan_set_genie(struct net_device *dev,
        int ret = 0;
        struct assoc_request * assoc_req;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        mutex_lock(&adapter->lock);
        assoc_req = wlan_get_association_request(adapter);
@@ -1952,7 +1965,7 @@ out:
        }
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -1961,27 +1974,28 @@ static int wlan_get_genie(struct net_device *dev,
                          struct iw_point *dwrq,
                          char *extra)
 {
+       int ret = 0;
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (adapter->wpa_ie_len == 0) {
                dwrq->length = 0;
-               LEAVE();
-               return 0;
+               goto out;
        }
 
        if (dwrq->length < adapter->wpa_ie_len) {
-               LEAVE();
-               return -E2BIG;
+               ret = -E2BIG;
+               goto out;
        }
 
        dwrq->length = adapter->wpa_ie_len;
        memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
 
-       LEAVE();
-       return 0;
+out:
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 
@@ -1996,7 +2010,7 @@ static int wlan_set_auth(struct net_device *dev,
        int ret = 0;
        int updated = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        mutex_lock(&adapter->lock);
        assoc_req = wlan_get_association_request(adapter);
@@ -2088,7 +2102,7 @@ out:
        }
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -2097,10 +2111,11 @@ static int wlan_get_auth(struct net_device *dev,
                         struct iw_param *dwrq,
                         char *extra)
 {
+       int ret = 0;
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        switch (dwrq->flags & IW_AUTH_INDEX) {
        case IW_AUTH_WPA_VERSION:
@@ -2130,12 +2145,11 @@ static int wlan_get_auth(struct net_device *dev,
                break;
 
        default:
-               LEAVE();
-               return -EOPNOTSUPP;
+               ret = -EOPNOTSUPP;
        }
 
-       LEAVE();
-       return 0;
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
+       return ret;
 }
 
 
@@ -2148,7 +2162,7 @@ static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
 
        u16 dbm;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (vwrq->disabled) {
                wlan_radio_ioctl(priv, RADIO_OFF);
@@ -2169,14 +2183,14 @@ static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
        if (vwrq->fixed == 0)
                dbm = 0xffff;
 
-       lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
+       lbs_deb_wext("txpower set %d dbm\n", dbm);
 
        ret = libertas_prepare_and_send_command(priv,
                                    cmd_802_11_rf_tx_power,
                                    cmd_act_tx_power_opt_set_low,
                                    cmd_option_waitforrsp, 0, (void *)&dbm);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -2186,7 +2200,8 @@ static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
        wlan_private *priv = dev->priv;
        wlan_adapter *adapter = priv->adapter;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
+
        /*
         * Note : if dwrq->flags != 0, we should get the relevant SSID from
         * the SSID list...
@@ -2216,7 +2231,7 @@ static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
 
        dwrq->flags = 1;        /* active */
 
-       LEAVE();
+       lbs_deb_leave(LBS_DEB_WEXT);
        return 0;
 }
 
@@ -2230,7 +2245,7 @@ static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
        struct assoc_request * assoc_req;
        int ssid_len = dwrq->length;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        /*
         * WE-20 and earlier NULL pad the end of the SSID and increment
@@ -2256,7 +2271,7 @@ static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
                ssid.ssidlength = ssid_len;
        }
 
-       lbs_pr_debug(1, "Requested new SSID = %s\n",
+       lbs_deb_wext("requested new SSID '%s'\n",
               (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
 
 out:
@@ -2281,7 +2296,7 @@ out:
 
        mutex_unlock(&adapter->lock);
 
-       LEAVE();
+       lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
        return ret;
 }
 
@@ -2302,12 +2317,12 @@ static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
        struct assoc_request * assoc_req;
        int ret = 0;
 
-       ENTER();
+       lbs_deb_enter(LBS_DEB_WEXT);
 
        if (awrq->sa_family != ARPHRD_ETHER)
                return -EINVAL;
 
-       lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
+       lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
 
        mutex_lock(&adapter->lock);