[PATCH] Marvell Libertas 8388 802.11b/g USB driver
Marcelo Tosatti [Sat, 10 Feb 2007 14:25:27 +0000 (12:25 -0200)]
Add the Marvell Libertas 8388 802.11 USB driver.

Signed-off-by: Marcelo Tosatti <marcelo@kvack.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

40 files changed:
drivers/net/wireless/Kconfig
drivers/net/wireless/Makefile
drivers/net/wireless/libertas/11d.c [new file with mode: 0644]
drivers/net/wireless/libertas/11d.h [new file with mode: 0644]
drivers/net/wireless/libertas/LICENSE [new file with mode: 0644]
drivers/net/wireless/libertas/Makefile [new file with mode: 0644]
drivers/net/wireless/libertas/README [new file with mode: 0644]
drivers/net/wireless/libertas/assoc.c [new file with mode: 0644]
drivers/net/wireless/libertas/assoc.h [new file with mode: 0644]
drivers/net/wireless/libertas/cmd.c [new file with mode: 0644]
drivers/net/wireless/libertas/cmdresp.c [new file with mode: 0644]
drivers/net/wireless/libertas/debugfs.c [new file with mode: 0644]
drivers/net/wireless/libertas/debugfs.h [new file with mode: 0644]
drivers/net/wireless/libertas/decl.h [new file with mode: 0644]
drivers/net/wireless/libertas/defs.h [new file with mode: 0644]
drivers/net/wireless/libertas/dev.h [new file with mode: 0644]
drivers/net/wireless/libertas/ethtool.c [new file with mode: 0644]
drivers/net/wireless/libertas/fw.c [new file with mode: 0644]
drivers/net/wireless/libertas/fw.h [new file with mode: 0644]
drivers/net/wireless/libertas/host.h [new file with mode: 0644]
drivers/net/wireless/libertas/hostcmd.h [new file with mode: 0644]
drivers/net/wireless/libertas/if_bootcmd.c [new file with mode: 0644]
drivers/net/wireless/libertas/if_usb.c [new file with mode: 0644]
drivers/net/wireless/libertas/if_usb.h [new file with mode: 0644]
drivers/net/wireless/libertas/ioctl.c [new file with mode: 0644]
drivers/net/wireless/libertas/join.c [new file with mode: 0644]
drivers/net/wireless/libertas/join.h [new file with mode: 0644]
drivers/net/wireless/libertas/main.c [new file with mode: 0644]
drivers/net/wireless/libertas/radiotap.h [new file with mode: 0644]
drivers/net/wireless/libertas/rx.c [new file with mode: 0644]
drivers/net/wireless/libertas/sbi.h [new file with mode: 0644]
drivers/net/wireless/libertas/scan.c [new file with mode: 0644]
drivers/net/wireless/libertas/scan.h [new file with mode: 0644]
drivers/net/wireless/libertas/thread.h [new file with mode: 0644]
drivers/net/wireless/libertas/tx.c [new file with mode: 0644]
drivers/net/wireless/libertas/types.h [new file with mode: 0644]
drivers/net/wireless/libertas/version.h [new file with mode: 0644]
drivers/net/wireless/libertas/wext.c [new file with mode: 0644]
drivers/net/wireless/libertas/wext.h [new file with mode: 0644]
include/net/ieee80211_radiotap.h

index 4426841..c4b3dc2 100644 (file)
@@ -265,6 +265,19 @@ config IPW2200_DEBUG
 
          If you are not sure, say N here.
 
+config LIBERTAS_USB
+       tristate "Marvell Libertas 8388 802.11a/b/g cards"
+       depends on NET_RADIO && USB
+       select FW_LOADER
+       ---help---
+         A driver for Marvell Libertas 8388 USB devices.
+
+config LIBERTAS_USB_DEBUG
+       bool "Enable full debugging output in the Libertas USB module."
+       depends on LIBERTAS_USB
+       ---help---
+         Debugging support.
+
 config AIRO
        tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards"
        depends on ISA_DMA_API && WLAN_80211 && (PCI || BROKEN)
index c613af1..d212460 100644 (file)
@@ -43,3 +43,4 @@ obj-$(CONFIG_PCMCIA_RAYCS)    += ray_cs.o
 obj-$(CONFIG_PCMCIA_WL3501)    += wl3501_cs.o
 
 obj-$(CONFIG_USB_ZD1201)       += zd1201.o
+obj-$(CONFIG_LIBERTAS_USB)     += libertas/
diff --git a/drivers/net/wireless/libertas/11d.c b/drivers/net/wireless/libertas/11d.c
new file mode 100644 (file)
index 0000000..e0ecc4d
--- /dev/null
@@ -0,0 +1,754 @@
+/**
+  * This file contains functions for 802.11D.
+  */
+#include <linux/ctype.h>
+#include <linux/kernel.h>
+#include <linux/wireless.h>
+
+#include "host.h"
+#include "decl.h"
+#include "11d.h"
+#include "dev.h"
+#include "wext.h"
+
+#define TX_PWR_DEFAULT 10
+
+static struct region_code_mapping region_code_mapping[] = {
+       {"US ", 0x10},          /* US FCC      */
+       {"CA ", 0x10},          /* IC Canada   */
+       {"SG ", 0x10},          /* Singapore   */
+       {"EU ", 0x30},          /* ETSI        */
+       {"AU ", 0x30},          /* Australia   */
+       {"KR ", 0x30},          /* Republic Of Korea */
+       {"ES ", 0x31},          /* Spain       */
+       {"FR ", 0x32},          /* France      */
+       {"JP ", 0x40},          /* Japan       */
+};
+
+/* Following 2 structure defines the supported channels */
+static struct chan_freq_power channel_freq_power_UN_BG[] = {
+       {1, 2412, TX_PWR_DEFAULT},
+       {2, 2417, TX_PWR_DEFAULT},
+       {3, 2422, TX_PWR_DEFAULT},
+       {4, 2427, TX_PWR_DEFAULT},
+       {5, 2432, TX_PWR_DEFAULT},
+       {6, 2437, TX_PWR_DEFAULT},
+       {7, 2442, TX_PWR_DEFAULT},
+       {8, 2447, TX_PWR_DEFAULT},
+       {9, 2452, TX_PWR_DEFAULT},
+       {10, 2457, TX_PWR_DEFAULT},
+       {11, 2462, TX_PWR_DEFAULT},
+       {12, 2467, TX_PWR_DEFAULT},
+       {13, 2472, TX_PWR_DEFAULT},
+       {14, 2484, TX_PWR_DEFAULT}
+};
+
+static u8 wlan_region_2_code(u8 * region)
+{
+       u8 i;
+       u8 size = sizeof(region_code_mapping)/
+                 sizeof(struct region_code_mapping);
+
+       for (i = 0; region[i] && i < COUNTRY_CODE_LEN; i++)
+               region[i] = toupper(region[i]);
+
+       for (i = 0; i < size; i++) {
+               if (!memcmp(region, region_code_mapping[i].region,
+                           COUNTRY_CODE_LEN))
+                       return (region_code_mapping[i].code);
+       }
+
+       /* default is US */
+       return (region_code_mapping[0].code);
+}
+
+static u8 *wlan_code_2_region(u8 code)
+{
+       u8 i;
+       u8 size = sizeof(region_code_mapping)
+                 / sizeof(struct region_code_mapping);
+       for (i = 0; i < size; i++) {
+               if (region_code_mapping[i].code == code)
+                       return (region_code_mapping[i].region);
+       }
+       /* default is US */
+       return (region_code_mapping[0].region);
+}
+
+/**
+ *  @brief This function finds the nrchan-th chan after the firstchan
+ *  @param band       band
+ *  @param firstchan  first channel number
+ *  @param nrchan   number of channels
+ *  @return          the nrchan-th chan number
+*/
+static u8 wlan_get_chan_11d(u8 band, u8 firstchan, u8 nrchan, u8 * chan)
+/*find the nrchan-th chan after the firstchan*/
+{
+       u8 i;
+       struct chan_freq_power *cfp;
+       u8 cfp_no;
+
+       cfp = channel_freq_power_UN_BG;
+       cfp_no = sizeof(channel_freq_power_UN_BG) /
+           sizeof(struct chan_freq_power);
+
+       for (i = 0; i < cfp_no; i++) {
+               if ((cfp + i)->channel == firstchan) {
+                       lbs_pr_debug(1, "firstchan found\n");
+                       break;
+               }
+       }
+
+       if (i < cfp_no) {
+               /*if beyond the boundary */
+               if (i + nrchan < cfp_no) {
+                       *chan = (cfp + i + nrchan)->channel;
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+/**
+ *  @brief This function Checks if chan txpwr is learned from AP/IBSS
+ *  @param chan                 chan number
+ *  @param parsed_region_chan   pointer to parsed_region_chan_11d
+ *  @return                    TRUE; FALSE
+*/
+static u8 wlan_channel_known_11d(u8 chan,
+                         struct parsed_region_chan_11d * parsed_region_chan)
+{
+       struct chan_power_11d *chanpwr = parsed_region_chan->chanpwr;
+       u8 nr_chan = parsed_region_chan->nr_chan;
+       u8 i = 0;
+
+       lbs_dbg_hex("11D:parsed_region_chan:", (char *)chanpwr,
+               sizeof(struct chan_power_11d) * nr_chan);
+
+       for (i = 0; i < nr_chan; i++) {
+               if (chan == chanpwr[i].chan) {
+                       lbs_pr_debug(1, "11D: Found Chan:%d\n", chan);
+                       return 1;
+               }
+       }
+
+       lbs_pr_debug(1, "11D: Not Find Chan:%d\n", chan);
+       return 0;
+}
+
+u32 libertas_chan_2_freq(u8 chan, u8 band)
+{
+       struct chan_freq_power *cf;
+       u16 cnt;
+       u16 i;
+       u32 freq = 0;
+
+       cf = channel_freq_power_UN_BG;
+       cnt =
+           sizeof(channel_freq_power_UN_BG) /
+           sizeof(struct chan_freq_power);
+
+       for (i = 0; i < cnt; i++) {
+               if (chan == cf[i].channel)
+                       freq = cf[i].freq;
+       }
+
+       return freq;
+}
+
+static int generate_domain_info_11d(struct parsed_region_chan_11d
+                                 *parsed_region_chan,
+                                 struct wlan_802_11d_domain_reg * domaininfo)
+{
+       u8 nr_subband = 0;
+
+       u8 nr_chan = parsed_region_chan->nr_chan;
+       u8 nr_parsedchan = 0;
+
+       u8 firstchan = 0, nextchan = 0, maxpwr = 0;
+
+       u8 i, flag = 0;
+
+       memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
+              COUNTRY_CODE_LEN);
+
+       lbs_pr_debug(1, "11D:nrchan=%d\n", nr_chan);
+       lbs_dbg_hex("11D:parsed_region_chan:", (char *)parsed_region_chan,
+               sizeof(struct parsed_region_chan_11d));
+
+       for (i = 0; i < nr_chan; i++) {
+               if (!flag) {
+                       flag = 1;
+                       nextchan = firstchan =
+                           parsed_region_chan->chanpwr[i].chan;
+                       maxpwr = parsed_region_chan->chanpwr[i].pwr;
+                       nr_parsedchan = 1;
+                       continue;
+               }
+
+               if (parsed_region_chan->chanpwr[i].chan == nextchan + 1 &&
+                   parsed_region_chan->chanpwr[i].pwr == maxpwr) {
+                       nextchan++;
+                       nr_parsedchan++;
+               } else {
+                       domaininfo->subband[nr_subband].firstchan = firstchan;
+                       domaininfo->subband[nr_subband].nrchan =
+                           nr_parsedchan;
+                       domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
+                       nr_subband++;
+                       nextchan = firstchan =
+                           parsed_region_chan->chanpwr[i].chan;
+                       maxpwr = parsed_region_chan->chanpwr[i].pwr;
+               }
+       }
+
+       if (flag) {
+               domaininfo->subband[nr_subband].firstchan = firstchan;
+               domaininfo->subband[nr_subband].nrchan = nr_parsedchan;
+               domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
+               nr_subband++;
+       }
+       domaininfo->nr_subband = nr_subband;
+
+       lbs_pr_debug(1, "nr_subband=%x\n", domaininfo->nr_subband);
+       lbs_dbg_hex("11D:domaininfo:", (char *)domaininfo,
+               COUNTRY_CODE_LEN + 1 +
+               sizeof(struct ieeetypes_subbandset) * nr_subband);
+       return 0;
+}
+
+/**
+ *  @brief This function generates parsed_region_chan from Domain Info learned from AP/IBSS
+ *  @param region_chan          pointer to struct region_channel
+ *  @param *parsed_region_chan  pointer to parsed_region_chan_11d
+ *  @return                    N/A
+*/
+static void wlan_generate_parsed_region_chan_11d(struct region_channel * region_chan,
+                                         struct parsed_region_chan_11d *
+                                         parsed_region_chan)
+{
+       u8 i;
+       struct chan_freq_power *cfp;
+
+       if (region_chan == NULL) {
+               lbs_pr_debug(1, "11D: region_chan is NULL\n");
+               return;
+       }
+
+       cfp = region_chan->CFP;
+       if (cfp == NULL) {
+               lbs_pr_debug(1, "11D: cfp equal NULL \n");
+               return;
+       }
+
+       parsed_region_chan->band = region_chan->band;
+       parsed_region_chan->region = region_chan->region;
+       memcpy(parsed_region_chan->countrycode,
+              wlan_code_2_region(region_chan->region), COUNTRY_CODE_LEN);
+
+       lbs_pr_debug(1, "11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
+              parsed_region_chan->band);
+
+       for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
+               parsed_region_chan->chanpwr[i].chan = cfp->channel;
+               parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
+               lbs_pr_debug(1, "11D: Chan[%d] Pwr[%d]\n",
+                      parsed_region_chan->chanpwr[i].chan,
+                      parsed_region_chan->chanpwr[i].pwr);
+       }
+       parsed_region_chan->nr_chan = region_chan->nrcfp;
+
+       lbs_pr_debug(1, "11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
+
+       return;
+}
+
+/**
+ *  @brief generate parsed_region_chan from Domain Info learned from AP/IBSS
+ *  @param region               region ID
+ *  @param band                 band
+ *  @param chan                 chan
+ *  @return                    TRUE;FALSE
+*/
+static u8 wlan_region_chan_supported_11d(u8 region, u8 band, u8 chan)
+{
+       struct chan_freq_power *cfp;
+       int cfp_no;
+       u8 idx;
+
+       ENTER();
+
+       cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
+       if (cfp == NULL)
+               return 0;
+
+       for (idx = 0; idx < cfp_no; idx++) {
+               if (chan == (cfp + idx)->channel) {
+                       /* If Mrvl Chip Supported? */
+                       if ((cfp + idx)->unsupported) {
+                               return 0;
+                       } else {
+                               return 1;
+                       }
+               }
+       }
+
+       /*chan is not in the region table */
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  @brief This function checks if chan txpwr is learned from AP/IBSS
+ *  @param chan                 chan number
+ *  @param parsed_region_chan   pointer to parsed_region_chan_11d
+ *  @return                    0
+*/
+static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
+                                countryinfo,
+                                u8 band,
+                                struct parsed_region_chan_11d *
+                                parsed_region_chan)
+{
+       u8 nr_subband, nrchan;
+       u8 lastchan, firstchan;
+       u8 region;
+       u8 curchan = 0;
+
+       u8 idx = 0;             /*chan index in parsed_region_chan */
+
+       u8 j, i;
+
+       ENTER();
+
+       /*validation Rules:
+          1. valid region Code
+          2. First Chan increment
+          3. channel range no overlap
+          4. channel is valid?
+          5. channel is supported by region?
+          6. Others
+        */
+
+       lbs_dbg_hex("CountryInfo:", (u8 *) countryinfo, 30);
+
+       if ((*(countryinfo->countrycode)) == 0
+           || (countryinfo->len <= COUNTRY_CODE_LEN)) {
+               /* No region Info or Wrong region info: treat as No 11D info */
+               LEAVE();
+               return 0;
+       }
+
+       /*Step1: check region_code */
+       parsed_region_chan->region = region =
+           wlan_region_2_code(countryinfo->countrycode);
+
+       lbs_pr_debug(1, "regioncode=%x\n", (u8) parsed_region_chan->region);
+       lbs_dbg_hex("CountryCode:", (char *)countryinfo->countrycode,
+               COUNTRY_CODE_LEN);
+
+       parsed_region_chan->band = band;
+
+       memcpy(parsed_region_chan->countrycode, countryinfo->countrycode,
+              COUNTRY_CODE_LEN);
+
+       nr_subband = (countryinfo->len - COUNTRY_CODE_LEN) /
+           sizeof(struct ieeetypes_subbandset);
+
+       for (j = 0, lastchan = 0; j < nr_subband; j++) {
+
+               if (countryinfo->subband[j].firstchan <= lastchan) {
+                       /*Step2&3. Check First Chan Num increment and no overlap */
+                       lbs_pr_debug(1, "11D: Chan[%d>%d] Overlap\n",
+                              countryinfo->subband[j].firstchan, lastchan);
+                       continue;
+               }
+
+               firstchan = countryinfo->subband[j].firstchan;
+               nrchan = countryinfo->subband[j].nrchan;
+
+               for (i = 0; idx < MAX_NO_OF_CHAN && i < nrchan; i++) {
+                       /*step4: channel is supported? */
+
+                       if (!wlan_get_chan_11d(band, firstchan, i, &curchan)) {
+                               /* Chan is not found in UN table */
+                               lbs_pr_debug(1, "chan is not supported: %d \n", i);
+                               break;
+                       }
+
+                       lastchan = curchan;
+
+                       if (wlan_region_chan_supported_11d
+                           (region, band, curchan)) {
+                               /*step5: Check if curchan is supported by mrvl in region */
+                               parsed_region_chan->chanpwr[idx].chan = curchan;
+                               parsed_region_chan->chanpwr[idx].pwr =
+                                   countryinfo->subband[j].maxtxpwr;
+                               idx++;
+                       } else {
+                               /*not supported and ignore the chan */
+                               lbs_pr_debug(1,
+                                      "11D:i[%d] chan[%d] unsupported in region[%x] band[%d]\n",
+                                      i, curchan, region, band);
+                       }
+               }
+
+               /*Step6: Add other checking if any */
+
+       }
+
+       parsed_region_chan->nr_chan = idx;
+
+       lbs_pr_debug(1, "nrchan=%x\n", parsed_region_chan->nr_chan);
+       lbs_dbg_hex("11D:parsed_region_chan:", (u8 *) parsed_region_chan,
+               2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);
+
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  @brief This function calculates the scan type for channels
+ *  @param chan                 chan number
+ *  @param parsed_region_chan   pointer to parsed_region_chan_11d
+ *  @return                    PASSIVE if chan is unknown; ACTIVE if chan is known
+*/
+u8 libertas_get_scan_type_11d(u8 chan,
+                         struct parsed_region_chan_11d * parsed_region_chan)
+{
+       u8 scan_type = cmd_scan_type_passive;
+
+       ENTER();
+
+       if (wlan_channel_known_11d(chan, parsed_region_chan)) {
+               lbs_pr_debug(1, "11D: Found and do Active Scan\n");
+               scan_type = cmd_scan_type_active;
+       } else {
+               lbs_pr_debug(1, "11D: Not Find and do Passive Scan\n");
+       }
+
+       LEAVE();
+       return scan_type;
+
+}
+
+void libertas_init_11d(wlan_private * priv)
+{
+       priv->adapter->enable11d = 0;
+       memset(&(priv->adapter->parsed_region_chan), 0,
+              sizeof(struct parsed_region_chan_11d));
+       return;
+}
+
+static int wlan_enable_11d(wlan_private * priv, u8 flag)
+{
+       int ret;
+
+       priv->adapter->enable11d = flag;
+
+       /* send cmd to FW to enable/disable 11D function in FW */
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_snmp_mib,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   OID_802_11D_ENABLE,
+                                   &priv->adapter->enable11d);
+       if (ret)
+               lbs_pr_debug(1, "11D: Fail to enable 11D \n");
+
+       return 0;
+}
+
+/**
+ *  @brief This function sets DOMAIN INFO to FW
+ *  @param priv       pointer to wlan_private
+ *  @return          0; -1
+*/
+static int set_domain_info_11d(wlan_private * priv)
+{
+       int ret;
+
+       if (!priv->adapter->enable11d) {
+               lbs_pr_debug(1, "11D: dnld domain Info with 11d disabled\n");
+               return 0;
+       }
+
+       ret = libertas_prepare_and_send_command(priv, cmd_802_11d_domain_info,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp, 0, NULL);
+       if (ret)
+               lbs_pr_debug(1, "11D: Fail to dnld domain Info\n");
+
+       return ret;
+}
+
+/**
+ *  @brief This function setups scan channels
+ *  @param priv       pointer to wlan_private
+ *  @param band       band
+ *  @return          0
+*/
+int libertas_set_universaltable(wlan_private * priv, u8 band)
+{
+       wlan_adapter *adapter = priv->adapter;
+       u16 size = sizeof(struct chan_freq_power);
+       u16 i = 0;
+
+       memset(adapter->universal_channel, 0,
+              sizeof(adapter->universal_channel));
+
+       adapter->universal_channel[i].nrcfp =
+           sizeof(channel_freq_power_UN_BG) / size;
+       lbs_pr_debug(1, "11D: BG-band nrcfp=%d\n",
+              adapter->universal_channel[i].nrcfp);
+
+       adapter->universal_channel[i].CFP = channel_freq_power_UN_BG;
+       adapter->universal_channel[i].valid = 1;
+       adapter->universal_channel[i].region = UNIVERSAL_REGION_CODE;
+       adapter->universal_channel[i].band = band;
+       i++;
+
+       return 0;
+}
+
+/**
+ *  @brief This function implements command CMD_802_11D_DOMAIN_INFO
+ *  @param priv       pointer to wlan_private
+ *  @param cmd        pointer to cmd buffer
+ *  @param cmdno      cmd ID
+ *  @param cmdOption  cmd action
+ *  @return          0
+*/
+int libertas_cmd_802_11d_domain_info(wlan_private * priv,
+                                struct cmd_ds_command *cmd, u16 cmdno,
+                                u16 cmdoption)
+{
+       struct cmd_ds_802_11d_domain_info *pdomaininfo =
+           &cmd->params.domaininfo;
+       struct mrvlietypes_domainparamset *domain = &pdomaininfo->domain;
+       wlan_adapter *adapter = priv->adapter;
+       u8 nr_subband = adapter->domainreg.nr_subband;
+
+       ENTER();
+
+       lbs_pr_debug(1, "nr_subband=%x\n", nr_subband);
+
+       cmd->command = cpu_to_le16(cmdno);
+       pdomaininfo->action = cpu_to_le16(cmdoption);
+       if (cmdoption == cmd_act_get) {
+               cmd->size =
+                   cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
+               lbs_dbg_hex("11D: 802_11D_DOMAIN_INFO:", (u8 *) cmd,
+                       (int)(cmd->size));
+               LEAVE();
+               return 0;
+       }
+
+       domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
+       memcpy(domain->countrycode, adapter->domainreg.countrycode,
+              sizeof(domain->countrycode));
+
+       domain->header.len =
+           cpu_to_le16(nr_subband * sizeof(struct ieeetypes_subbandset) +
+                            sizeof(domain->countrycode));
+
+       if (nr_subband) {
+               memcpy(domain->subband, adapter->domainreg.subband,
+                      nr_subband * sizeof(struct ieeetypes_subbandset));
+
+               cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) +
+                                            domain->header.len +
+                                            sizeof(struct mrvlietypesheader) +
+                                            S_DS_GEN);
+       } else {
+               cmd->size =
+                   cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
+       }
+
+       lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, (int)(cmd->size));
+
+       LEAVE();
+
+       return 0;
+}
+
+/**
+ *  @brief This function implements private cmd: enable/disable 11D
+ *  @param priv    pointer to wlan_private
+ *  @param wrq     pointer to user data
+ *  @return       0 or -1
+ */
+int libertas_cmd_enable_11d(wlan_private * priv, struct iwreq *wrq)
+{
+       int data = 0;
+       int *val;
+
+       ENTER();
+       data = SUBCMD_DATA(wrq);
+
+       lbs_pr_debug(1, "enable 11D: %s\n",
+              (data == 1) ? "enable" : "Disable");
+
+       wlan_enable_11d(priv, data);
+       val = (int *)wrq->u.name;
+       *val = priv->adapter->enable11d;
+
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  @brief This function parses countryinfo from AP and download country info to FW
+ *  @param priv    pointer to wlan_private
+ *  @param resp    pointer to command response buffer
+ *  @return       0; -1
+ */
+int libertas_ret_802_11d_domain_info(wlan_private * priv,
+                                struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11d_domain_info
+       *domaininfo = &resp->params.domaininforesp;
+       struct mrvlietypes_domainparamset *domain = &domaininfo->domain;
+       u16 action = le16_to_cpu(domaininfo->action);
+       s16 ret = 0;
+       u8 nr_subband = 0;
+
+       ENTER();
+
+       lbs_dbg_hex("11D DOMAIN Info Rsp Data:", (u8 *) resp,
+               (int)le16_to_cpu(resp->size));
+
+       nr_subband = (domain->header.len - 3) / sizeof(struct ieeetypes_subbandset);
+       /* countrycode 3 bytes */
+
+       lbs_pr_debug(1, "11D Domain Info Resp: nr_subband=%d\n", nr_subband);
+
+       if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
+               lbs_pr_debug(1, "Invalid Numrer of Subband returned!!\n");
+               return -1;
+       }
+
+       switch (action) {
+       case cmd_act_set:       /*Proc Set action */
+               break;
+
+       case cmd_act_get:
+               break;
+       default:
+               lbs_pr_debug(1, "Invalid action:%d\n", domaininfo->action);
+               ret = -1;
+               break;
+       }
+
+       LEAVE();
+       return ret;
+}
+
+/**
+ *  @brief This function parses countryinfo from AP and download country info to FW
+ *  @param priv    pointer to wlan_private
+ *  @return       0; -1
+ */
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv)
+{
+       int ret;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+       if (priv->adapter->enable11d) {
+               memset(&adapter->parsed_region_chan, 0,
+                      sizeof(struct parsed_region_chan_11d));
+               ret = parse_domain_info_11d(&adapter->pattemptedbssdesc->
+                                              countryinfo, 0,
+                                              &adapter->parsed_region_chan);
+
+               if (ret == -1) {
+                       lbs_pr_debug(1, "11D: Err Parse domain_info from AP..\n");
+                       LEAVE();
+                       return ret;
+               }
+
+               memset(&adapter->domainreg, 0,
+                      sizeof(struct wlan_802_11d_domain_reg));
+               generate_domain_info_11d(&adapter->parsed_region_chan,
+                                     &adapter->domainreg);
+
+               ret = set_domain_info_11d(priv);
+
+               if (ret) {
+                       lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
+                       LEAVE();
+                       return ret;
+               }
+       }
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  @brief This function generates 11D info from user specified regioncode and download to FW
+ *  @param priv    pointer to wlan_private
+ *  @return       0; -1
+ */
+int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
+{
+       int ret;
+       wlan_adapter *adapter = priv->adapter;
+       struct region_channel *region_chan;
+       u8 j;
+
+       ENTER();
+       lbs_pr_debug(1, "11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
+
+       if (priv->adapter->enable11d) {
+               /* update parsed_region_chan_11; dnld domaininf to FW */
+
+               for (j = 0; j < sizeof(adapter->region_channel) /
+                    sizeof(adapter->region_channel[0]); j++) {
+                       region_chan = &adapter->region_channel[j];
+
+                       lbs_pr_debug(1, "11D:[%d] region_chan->band[%d]\n", j,
+                              region_chan->band);
+
+                       if (!region_chan || !region_chan->valid
+                           || !region_chan->CFP)
+                               continue;
+                       if (region_chan->band != adapter->curbssparams.band)
+                               continue;
+                       break;
+               }
+
+               if (j >= sizeof(adapter->region_channel) /
+                   sizeof(adapter->region_channel[0])) {
+                       lbs_pr_debug(1, "11D:region_chan not found. band[%d]\n",
+                              adapter->curbssparams.band);
+                       LEAVE();
+                       return -1;
+               }
+
+               memset(&adapter->parsed_region_chan, 0,
+                      sizeof(struct parsed_region_chan_11d));
+               wlan_generate_parsed_region_chan_11d(region_chan,
+                                                    &adapter->
+                                                    parsed_region_chan);
+
+               memset(&adapter->domainreg, 0,
+                      sizeof(struct wlan_802_11d_domain_reg));
+               generate_domain_info_11d(&adapter->parsed_region_chan,
+                                        &adapter->domainreg);
+
+               ret = set_domain_info_11d(priv);
+
+               if (ret) {
+                       lbs_pr_debug(1, "11D: Err set domainInfo to FW\n");
+                       LEAVE();
+                       return ret;
+               }
+
+       }
+
+       LEAVE();
+       return 0;
+}
diff --git a/drivers/net/wireless/libertas/11d.h b/drivers/net/wireless/libertas/11d.h
new file mode 100644 (file)
index 0000000..db2ebea
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+  * This header file contains data structures and
+  * function declarations of 802.11d
+  */
+#ifndef _WLAN_11D_
+#define _WLAN_11D_
+
+#include "types.h"
+#include "defs.h"
+
+#define UNIVERSAL_REGION_CODE                  0xff
+
+/** (Beaconsize(256)-5(IEId,len,contrystr(3))/3(FirstChan,NoOfChan,MaxPwr)
+ */
+#define MRVDRV_MAX_SUBBAND_802_11D             83
+
+#define COUNTRY_CODE_LEN                       3
+#define MAX_NO_OF_CHAN                                 40
+
+struct cmd_ds_command;
+
+/** Data structure for Country IE*/
+struct ieeetypes_subbandset {
+       u8 firstchan;
+       u8 nrchan;
+       u8 maxtxpwr;
+} __attribute__ ((packed));
+
+struct ieeetypes_countryinfoset {
+       u8 element_id;
+       u8 len;
+       u8 countrycode[COUNTRY_CODE_LEN];
+       struct ieeetypes_subbandset subband[1];
+};
+
+struct ieeetypes_countryinfofullset {
+       u8 element_id;
+       u8 len;
+       u8 countrycode[COUNTRY_CODE_LEN];
+       struct ieeetypes_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D];
+} __attribute__ ((packed));
+
+struct mrvlietypes_domainparamset {
+       struct mrvlietypesheader header;
+       u8 countrycode[COUNTRY_CODE_LEN];
+       struct ieeetypes_subbandset subband[1];
+} __attribute__ ((packed));
+
+struct cmd_ds_802_11d_domain_info {
+       u16 action;
+       struct mrvlietypes_domainparamset domain;
+} __attribute__ ((packed));
+
+/** domain regulatory information */
+struct wlan_802_11d_domain_reg {
+       /** country Code*/
+       u8 countrycode[COUNTRY_CODE_LEN];
+       /** No. of subband*/
+       u8 nr_subband;
+       struct ieeetypes_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D];
+};
+
+struct chan_power_11d {
+       u8 chan;
+       u8 pwr;
+} __attribute__ ((packed));
+
+struct parsed_region_chan_11d {
+       u8 band;
+       u8 region;
+       s8 countrycode[COUNTRY_CODE_LEN];
+       struct chan_power_11d chanpwr[MAX_NO_OF_CHAN];
+       u8 nr_chan;
+} __attribute__ ((packed));
+
+struct region_code_mapping {
+       u8 region[COUNTRY_CODE_LEN];
+       u8 code;
+};
+
+u8 libertas_get_scan_type_11d(u8 chan,
+                         struct parsed_region_chan_11d *parsed_region_chan);
+
+u32 libertas_chan_2_freq(u8 chan, u8 band);
+
+enum state_11d libertas_get_state_11d(wlan_private * priv);
+
+void libertas_init_11d(wlan_private * priv);
+
+int libertas_set_universaltable(wlan_private * priv, u8 band);
+
+int libertas_cmd_802_11d_domain_info(wlan_private * priv,
+                                struct cmd_ds_command *cmd, u16 cmdno,
+                                u16 cmdOption);
+
+int libertas_cmd_enable_11d(wlan_private * priv, struct iwreq *wrq);
+
+int libertas_ret_802_11d_domain_info(wlan_private * priv,
+                                struct cmd_ds_command *resp);
+
+int libertas_parse_dnld_countryinfo_11d(wlan_private * priv);
+
+int libertas_create_dnld_countryinfo_11d(wlan_private * priv);
+
+#endif                         /* _WLAN_11D_ */
diff --git a/drivers/net/wireless/libertas/LICENSE b/drivers/net/wireless/libertas/LICENSE
new file mode 100644 (file)
index 0000000..8862742
--- /dev/null
@@ -0,0 +1,16 @@
+  Copyright (c) 2003-2006, Marvell International Ltd.
+  All Rights Reserved
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of version 2 of the GNU General Public License as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc., 59
+  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
diff --git a/drivers/net/wireless/libertas/Makefile b/drivers/net/wireless/libertas/Makefile
new file mode 100644 (file)
index 0000000..19c9350
--- /dev/null
@@ -0,0 +1,21 @@
+# EXTRA_CFLAGS += -Wpacked
+
+usb8xxx-objs := main.o fw.o wext.o \
+               rx.o tx.o cmd.o           \
+               cmdresp.o scan.o          \
+               join.o 11d.o              \
+               ioctl.o debugfs.o         \
+               ethtool.o assoc.o
+
+ifeq ($(CONFIG_LIBERTAS_USB_DEBUG), y)
+EXTRA_CFLAGS += -DDEBUG -DPROC_DEBUG
+endif
+
+
+# This is needed to support the newer boot2 bootloader (v >= 3104)
+EXTRA_CFLAGS += -DSUPPORT_BOOT_COMMAND
+usb8xxx-objs += if_bootcmd.o
+usb8xxx-objs += if_usb.o
+
+obj-$(CONFIG_LIBERTAS_USB) += usb8xxx.o
+
diff --git a/drivers/net/wireless/libertas/README b/drivers/net/wireless/libertas/README
new file mode 100644 (file)
index 0000000..688da4c
--- /dev/null
@@ -0,0 +1,1044 @@
+================================================================================
+                       README for USB8388
+
+ (c) Copyright © 2003-2006, Marvell International Ltd.
+ All Rights Reserved
+
+ This software file (the "File") is distributed by Marvell International
+ Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ (the "License").  You may use, redistribute and/or modify this File in
+ accordance with the terms and conditions of the License, a copy of which
+ is available along with the File in the license.txt file or by writing to
+ the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 or on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
+
+ THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
+ this warranty disclaimer.
+================================================================================
+
+=====================
+DRIVER LOADING
+=====================
+
+       o. Copy the firmware image (e.g. usb8388.bin) to /lib/firmware/
+
+       o. Load driver by using the following command:
+
+               insmod usb8388.ko [fw_name=usb8388.bin]
+
+=====================
+IWPRIV COMMAND
+=====================
+
+NAME
+       This manual describes the usage of private commands used in Marvell WLAN
+       Linux Driver. All the commands available in Wlanconfig will not be available
+       in the iwpriv.
+
+SYNOPSIS
+       iwpriv <ethX> <command> [sub-command] ...
+
+       iwpriv ethX version
+       iwpriv ethX scantype [sub-command]
+       iwpriv ethX getSNR <n>
+       iwpriv ethX getNF <n>
+       iwpriv ethX getRSSI <n>
+       iwpriv ethX setrxant <n>
+       iwpriv ethX getrxant
+       iwpriv ethX settxant <n>
+       iwpriv ethX gettxant
+       iwpriv ethX authalgs <n>
+       iwpriv ethX pre-TBTT <n>
+       iwpriv ethX 8021xauthalgs <n>
+       iwpriv ethX encryptionmode <n>
+       iwpriv ethX setregioncode <n>
+       iwpriv ethX getregioncode
+       iwpriv ethX setbcnavg <n>
+       iwpriv ethX getbcnavg
+       iwpriv ethX setdataavg <n>
+       iwpriv ethX setlisteninter <n>
+       iwpriv ethX getlisteninter
+       iwpriv ethX setmultipledtim <n>
+       iwpriv ethX getmultipledtim
+       iwpriv ethX atimwindow <n>
+       iwpriv ethX deauth
+       iwpriv ethX adhocstop
+       iwpriv ethX radioon
+       iwpriv ethX radiooff
+       iwpriv ethX reasso-on
+       iwpriv ethX reasso-off
+       iwpriv ethX scanmode  [sub-command]
+       iwpriv ethX setwpaie <n>
+       iwpriv ethX wlanidle-off
+       iwpriv ethX wlanidle-on
+       iwpriv ethX getcis
+       iwpriv ethX getlog
+       iwpriv ethX getadhocstatus
+       iwpriv ethX adhocgrate <n>
+
+Version 4 Command:
+       iwpriv ethX inactvityto <n>
+       iwpriv ethX sleeppd <n>
+       iwpriv ethX enable11d <n>
+       iwpriv ethX tpccfg <n>
+       iwpriv ethX powercfg <n>
+       iwpriv ethX setafc <n>
+       iwpriv ethX getafc
+
+Version 5 Command:
+       iwpriv ethX ledgpio <n>
+       iwpriv ethX scanprobes <n>
+       iwpriv ethX lolisteninter <n>
+       iwpriv ethX rateadapt <n> <m>
+       iwpriv ethX txcontrol <n>
+       iwpriv ethX psnullinterval <n>
+       iwpriv ethX prescan <n>
+       iwpriv ethX getrxinfo
+       iwpriv ethX gettxrate
+       iwpriv ethX beaconinterval
+
+BT Commands:
+       The blinding table (BT) contains a list of mac addresses that should be
+       ignored by the firmware.  It is primarily used for debugging and
+       testing networks.  It can be edited and inspected with the following
+       commands:
+
+       iwpriv ethX bt_reset
+       iwpriv ethX bt_add <mac_address>
+       iwpriv ethX bt_del <mac_address>
+       iwpriv ethX bt_list <id>
+
+FWT Commands:
+       The forwarding table (FWT) is a feature used to manage mesh network
+       routing in the firmware.  The FWT is essentially a routing table that
+       associates a destination mac address (da) with a next hop receiver
+       address (ra).  The FWT can be inspected and edited with the following
+       iwpriv commands, which are described in greater detail below.
+       Eventually, the table will be automatically maintained by a custom
+       routing protocol.
+
+       NOTE: FWT commands replace the previous DFT commands.  What were the DFT
+       commands?, you might ask.  They were an earlier API to the firmware that
+       implemented a simple MAC-layer forwarding mechanism.  In the unlikely
+       event that you were using these commands, you must migrate to the new
+       FWT commands which can be used to achieve the same functionality.
+
+       iwpriv ethX fwt_add [parameters]
+       iwpriv ethX fwt_del [parameters]
+       iwpriv ethX fwt_lookup [parameters]
+       iwpriv ethX fwt_list [parameters]
+       iwpriv ethX fwt_list_route [parameters]
+       iwpriv ethX fwt_list_neigh [parameters]
+       iwpriv ethX fwt_reset [parameters]
+       iwpriv ethX fwt_cleanup
+       iwpriv ethX fwt_time
+
+MESH Commands:
+
+       The MESH commands are used to configure various features of the mesh
+       routing protocol.  The following commands are supported:
+
+       iwpriv ethX mesh_get_ttl
+       iwpriv ethX mesh_set_ttl ttl
+
+DESCRIPTION
+       Those commands are used to send additional commands to the Marvell WLAN
+       card via the Linux device driver.
+
+       The ethX parameter specifies the network device that is to be used to
+               perform this command on. it could be eth0, eth1 etc.
+
+version
+       This is used to get the current version of the driver and the firmware.
+
+scantype
+       This command is used to set the scan type to be used by the driver in
+       the scan command. This setting will not be used while performing a scan
+       for a specific SSID, as it is always done with scan type being active.
+
+       where the sub-commands are: -
+                       active  -- to set the scan type to active
+                       passive -- to set the scan type to passive
+                       get     -- to get the scan type set in the driver
+
+getSNR
+       This command gets the average and non average value of Signal to Noise
+       Ratio of Beacon and Data.
+
+       where value is:-
+                       0       -- Beacon non-average.
+                       1       -- Beacon average.
+                       2       -- Data non-average.
+                       3       -- Data average.
+
+       If no value is given, all four values are returned in the order mentioned
+       above.
+
+       Note: This command is available only when STA is connected.
+
+getRSSI
+       This command gets the average and non average value os Receive Signal
+       Strength of Beacon and Data.
+
+       where value is:-
+                       0       -- Beacon non-average.
+                       1       -- Beacon average.
+                       2       -- Data non-average.
+                       3       -- Data average.
+
+       Note: This command is available only when STA is connected.
+
+getNF
+       This command gets the average and non average value of Noise Floor of
+       Beacon and Data.
+
+       where value is:-
+                       0       -- Beacon non-average.
+                       1       -- Beacon average.
+                       2       -- Data non-average.
+                       3       -- Data average.
+
+       Note: This command is available only when STA is connected.
+
+setrxant
+       This command is used to set the mode for Rx antenna.
+
+       The options that can be sent are:-
+                       1       -- Antenna 1.
+                       2       -- Antenna 2.
+                       0xFFFF  -- Diversity.
+
+       Usage:
+               iwpriv ethX setrxant 0x01: select Antenna 1.
+
+getrxant
+       This command is used to get the mode for Rx antenna.
+
+
+settxant
+       This command is used to set the mode for Tx antenna.
+               The options that can be sent are:-
+                       1       -- Antenna 1.
+                       2       -- Antenna 2.
+                       0xFFFF  -- Diversity.
+       Usage:
+               iwpriv ethX settxant 0x01: select Antenna 1.
+
+gettxant
+       This command is used to get the mode for Tx antenna.
+
+authalgs
+       This command is used by the WPA supplicant to set the authentication
+       algorithms in the station.
+
+8021xauthalgs
+       This command is used by the WPA supplicant to set the 8021.x authentication algorithm type
+       station.
+
+       where values can be:-
+                       1       -- None
+                       2       -- LEAP
+                       4       -- TLS
+                       8       -- TTLs
+                       16      -- MD5
+
+
+encryptionmode
+       This command is used by the WPA supplicant to set the encryption algorithm.
+
+       where values can be:-
+                       0       -- NONE
+                       1       -- WEP40
+                       2       -- TKIP
+                       3       -- CCMP
+                       4       -- WEP104
+
+pre-TBTT
+       This command is used to set pre-TBTT time period where value is in microseconds.
+
+setregioncode
+       This command is used to set the region code in the station.
+       where value is 'region code' for various regions like
+       USA FCC, Canada IC, Spain, France, Europe ETSI, Japan ...
+
+       Usage:
+               iwpriv ethX setregioncode 0x10: set region code to USA (0x10).
+
+getregioncode
+       This command is used to get the region code information set in the
+       station.
+
+setbcnavg
+       Set the weighting factor for calculating RSSI.
+
+getbcnavg
+       Get weighting factor for calculating RSSI.
+
+setdataavg
+       Set the weighting factor for calculating SNR.
+
+setlisteninter
+       This command is used to set the listen interval in the
+       station.
+
+       where the value ranges between 1 - 255
+
+getlisteninter
+       This command is used to get the listen interval value set in the
+       station.
+
+setmultipledtim
+       This command is used to set the multiple dtim value in the
+       station.
+               where the value is 1,2,3,4,5,0xfffe
+               0xfffe means the firmware will use listen interval in association
+               command for waking up
+
+getmultipledtim
+       This command is used to get the multiple dtim value set in the station.
+
+atimwindow
+       This command is used to set the atim value in the
+       station.
+
+       where the value ranges between 0 - 50
+
+deauth
+       This command is used to send the de-authentication to the AP with which
+       the station is associated. This command is valid only when
+       station is in Infrastructure mode.
+
+       Note: This command is available only when STA is connected.
+
+adhocstop
+       This command is used to stop beacon transmission from the station and
+       go into idle state in ad-hoc mode.
+
+       Note: This command is available only when STA is connected.
+
+radioon
+       This command is used to turn on the RF antenna.
+
+radiooff
+       This command is sued to turn off the RF antenna.
+
+scanmode
+       This command is used to set the station to scan for either IBSS
+       networks or BSS networks or both BSS and IBSS networks. This
+       command can be used with sub commands,
+
+       where the value for
+                       bss     -- Scan All the BSS networks.
+                       ibss    -- Scan All the IBSS networks.
+                       any     -- Scan both BSS and IBSS networks.
+
+
+
+setwpaie
+       This command is used by WPA supplicant to send the WPA-IE to the driver.
+
+wlanidle-off
+       This command is used to get into idle state.
+
+       Note: This command is available only when STA is connected.
+
+wlanidle-on
+       This command is used to get off the idle state.
+
+       Note: This command is available only when STA is connected.
+
+
+getlog
+       This command is used to get the 802.11 statistics available in the
+               station.
+
+       Note: This command is available only when STA is connected.
+
+getadhocstatus
+       This command is used to get the ad-hoc Network Status.
+
+       The various status codes are:
+               AdhocStarted
+               AdhocJoined
+               AdhocIdle
+               InfraMode
+               AutoUnknownMode
+
+       Note: This command is available only when STA is connected.
+
+adhocgrate
+       This command is used to enable(1) g_rate, Disable(0) g_rate
+       and request(2) the status which g_rate is disabled/enabled,
+       for Ad-hoc creator.
+
+       where value is:-
+               0       -- Disabled
+               1       -- Enabled
+               2       -- Get
+
+ledgpio
+       This command is used to set/get LEDs.
+
+       iwpriv ethX ledgpio <LEDs>
+               will set the corresponding LED for the GPIO Line.
+
+       iwpriv ethX ledgpio
+               will give u which LEDs are Enabled.
+
+       Usage:
+               iwpriv eth1 ledgpio 1 0 2 1 3 4
+                       will enable
+                       LED 1 -> GPIO 0
+                       LED 2 -> GPIO 1
+                       LED 3 -> GPIO 4
+
+               iwpriv eth1 ledgpio
+                       shows LED information in the format as mentioned above.
+
+       Note: LED0 is invalid
+       Note: Maximum Number of LEDs are 16.
+
+inactivityto
+       This command is used by the host to set/get the inactivity timeout value,
+       which specifies when WLAN device is put to sleep.
+
+       Usage:
+               iwpriv ethX inactivityto [<timeout>]
+
+       where the parameter are:
+               timeout: timeout value in milliseconds.
+
+       Example:
+               iwpriv eth1 inactivityto
+                       "get the timeout value"
+
+               iwpriv eth1 inactivityto X
+                       "set timeout value to X ms"
+
+
+sleeppd
+       This command is used to configure the sleep period of the WLAN device.
+
+       Usage:
+               iwpriv ethX sleeppd [<sleep period>]
+
+       where the parameter are:
+               Period: sleep period in milliseconds. Range 10~60.
+
+       Example:
+               iwpriv eth1 sleeppd 10
+                       "set period as 10 ms"
+               iwpriv eth1 sleeppd
+                       "get the sleep period configuration"
+
+enable11d
+       This command is used to control 11d
+       where value is:-
+               1       -- Enabled
+               0       -- Disabled
+               2       -- Get
+
+
+
+
+tpccfg
+       Enables or disables automatic transmit power control.
+
+       The first parameter turns this feature on (1) or off (0).  When turning
+       on, the user must also supply four more parameters in the following
+       order:
+               -UseSNR (Use SNR (in addition to PER) for TPC algorithm),
+               -P0 (P0 power level for TPC),
+               -P1 (P1 power level for TPC),
+               -P2 (P2 power level for TPC).
+
+       Usage:
+               iwpriv ethX tpccfg: Get current configuration
+               iwpriv ethX tpccfg 0: disable auto TPC
+               iwpriv ethX tpccfg 0x01 0x00 0x05 0x0a 0x0d: enable auto TPC; do not use SNR;
+                                                            P0=0x05; P1=0x0a; P2=0x0d;
+               iwpriv ethX tpccfg 0x01 0x01 0x05 0x0a 0x0d: enable auto TPC; use SNR;
+                                                            P0=0x05; P1=0x0a; P2=0x0d.
+
+powercfg
+       Enables or disables power adaptation.
+
+       The first parameter turns this feature on (1) or off (0).  When turning
+       on, the user must also supply three more parameters in the following
+       order:
+               -P0 (P0 power level for Power Adaptation),
+               -P1 (P1 power level for Power Adaptation),
+               -P2 (P2 power level for Power Adaptation).
+
+       Usage:
+               iwpriv ethX powercfg: Get current configuration
+               iwpriv ethX powercfg 0: disable power adaptation
+               iwpriv ethX powercfg 1 0x0d 0x0f 0x12: enable power adaptation;
+                                                      P0=0x0d; P1=0x0f; P2=0x12.
+
+getafc
+       This command returns automatic frequency control parameters.  It returns
+       three integers:
+               -P0: automatic is on (1), or off (0),
+               -P1: current timing offset in PPM (part per million), and
+               -P2: current frequency offset in PPM.
+
+setafc
+       Set automatic frequency control options.
+
+       The first parameter turns automatic on (1) or off (0).
+       The user must supply two more parameters in either case, in the following
+  order:
+
+  When auto is on:
+
+               -P0 (automatic adjustment frequency threshold in PPM),
+               -P1 (automatic adjustment period in beacon period),
+
+  When auto is off:
+
+               -P0 (manual adjustment timing offset in PPM), and
+               -P1 (manual adjustment frequency offset in PPM).
+
+       Usage:
+               iwpriv ethX setafc 0 10 10: manual adjustment, both timing and frequcncy
+    offset are 10 PPM.
+
+               iwpriv ethX setafc 1 10 10 enable afc, automatic adjustment,
+    frequency threshold 10 PPM, for every 10 beacon periods.
+
+
+
+scanprobes
+       This command sets number of probe requests per channel.
+
+       Usage:
+               iwpriv ethX scanprobes 3 (set scan probes to 3)
+               iwpriv ethX scanprobes   (get scan probes)
+
+lolisteninter
+       This command sets the value of listen interval.
+
+       Usage:
+       iwpriv ethX lolisteninter 234 (set the lolisteninter to 234)
+       iwpriv ethX lolisteninter     (get the lolisteninter value)
+
+rateadapt
+       This command sets the data rates bitmap.
+       Where <n>
+               0: Disable auto rate adapt
+               1: Enable auto rate adapt
+
+             <m>
+                data rate bitmap
+                       Bit     Data rate
+                       0       1 Mbps
+                       1       2 Mbps
+                       2       5.5 Mbps
+                       3       11 Mbps
+                       4       Reserved
+                       5       6 Mbps
+                       6       9 Mbps
+                       7       12 Mbps
+                       8       18 Mbps
+                       9       24 Mbps
+                       10      36 Mbps
+                       11      48 Mbps
+                       12      54 Mbps
+                       12-15   Reserved
+
+       Usage:
+       iwpriv ethX rateadapt
+                       read the currect data rate setting
+       iwpriv ethX rateadapt 1 0x07
+                       enable auto data rate adapt and
+                       data rates are 1Mbps, 2Mbsp and 5.5Mbps
+
+
+txcontrol
+       This command is used to set the Tx rate, ack policy, and retry limit on a per packet basis.
+
+       Where value <n> is:
+           if bit[4] == 1:
+               bit[3:0]        -- 0   1   2   3   4   5   6   7   8   9   10   11   12   13-16
+               Data Rate(Mbps) -- 1   2   5.5 11  Rsv 6   9   12  18  24  36   48   54   Rsv
+
+           bit[12:8]
+               if bit[12] == 1, bit[11:8] specifies the Tx retry limit.
+
+           bit[14:13] specifies per packet ack policy:
+               bit[14:13]
+                    1  0       use immediate ack policy for this packet
+                    1  1       use no ack policy for this packet
+                    0  x       use the per-packet ack policy setting
+
+       Usage:
+       iwpriv ethX txcontrol 0x7513
+                       Use no-ack policy, 5 retires for Tx, 11Mbps rate
+
+
+
+psnullinterval
+       This command is used to set/request NULL package interval for Power Save
+       under infrastructure mode.
+
+       where value is:-
+               -1      -- Disabled
+               n>0     -- Set interval as n (seconds)
+
+prescan
+       This command is used to enable (1)/disable(0) auto prescan before assoicate to the ap
+
+       where value is:-
+               0       -- Disabled
+               1       -- Enabled
+               2       -- Get
+
+getrxinfo
+       This command gets non average value of Signal to Noise Ratio of Data and rate index.
+
+       The following table shows RateIndex and Rate
+
+                    RateIndex  Data rate
+                       0       1 Mbps
+                       1       2 Mbps
+                       2       5.5 Mbps
+                       3       11 Mbps
+                       4       Reserved
+                       5       6 Mbps
+                       6       9 Mbps
+                       7       12 Mbps
+                       8       18 Mbps
+                       9       24 Mbps
+                       10      36 Mbps
+                       11      48 Mbps
+                       12      54 Mbps
+                       13-15   Reserved
+
+gettxrate
+       This command gets current Tx rate index of the first packet associated with Rate Adaptation.
+
+       The following table shows RateIndex and Rate
+
+                    RateIndex  Data rate
+                       0       1 Mbps
+                       1       2 Mbps
+                       2       5.5 Mbps
+                       3       11 Mbps
+                       4       Reserved
+                       5       6 Mbps
+                       6       9 Mbps
+                       7       12 Mbps
+                       8       18 Mbps
+                       9       24 Mbps
+                       10      36 Mbps
+                       11      48 Mbps
+                       12      54 Mbps
+                       13-15   Reserved
+
+bcninterval
+       This command is used to sets beacon interval in adhoc mode when an argument is given, and gets current adhoc
+       beacon interval when no argument is given. The valid beacon interval is between 20 - 1000,
+       default beacon interval is 100.
+
+       Usage:
+               iwpriv ethX bcninterval 100  (set adhoc beacon interval to 100)
+               iwpriv ethX bcninterval      (get adhoc beacon interval)
+
+fwt_add
+       This command is used to insert an entry into the FWT table. The list of
+       parameters must follow the following structure:
+
+       iwpriv ethX fwt_add da ra [metric dir ssn dsn hopcount ttl expiration sleepmode snr]
+
+       The parameters between brackets are optional, but they must appear in
+       the order specified.  For example, if you want to specify the metric,
+       you must also specify the dir, ssn, and dsn but you need not specify the
+       hopcount, expiration, sleepmode, or snr.  Any unspecified parameters
+       will be assigned the defaults specified below.
+
+       The different parameters are:-
+               da              -- DA MAC address in the form 00:11:22:33:44:55
+               ra              -- RA MAC address in the form 00:11:22:33:44:55
+               metric          -- route metric (cost: smaller-metric routes are
+                                  preferred, default is 0)
+               dir             -- direction (1 for direct, 0 for reverse,
+                                  default is 1)
+               ssn             -- Source Sequence Number (time at the RA for
+                                  reverse routes.  Default is 0)
+               dsn             -- Destination Sequence Number (time at the DA
+                                  for direct routes.  Default is 0)
+               hopcount        -- hop count (currently unused, default is 0)
+               ttl             -- TTL (Only used in reverse entries)
+               expiration      -- entry expiration (in ticks, where a tick is
+                                  1024us, or ~ 1ms. Use 0 for an indefinite
+                                  entry, default is 0)
+               sleepmode       -- RA's sleep mode (currently unused, default is
+                                  0)
+               snr             -- SNR in the link to RA (currently unused,
+                                  default is 0)
+
+       The command does not return anything.
+
+fwt_del
+       This command is used to remove an entry to the FWT table. The list of
+       parameters must follow the following structure:
+
+               iwpriv ethX fwt_del da ra [dir]
+
+       where the different parameters are:-
+               da              -- DA MAC address (in the form "00:11:22:33:44:55")
+               ra              -- RA MAC address (in the form "00:11:22:33:44:55")
+               dir             -- direction (1 for direct, 0 for reverse,
+                                  default is 1)
+
+       The command does not return anything.
+
+fwt_lookup
+       This command is used to get the best route in the FWT table to a given
+       host. The only parameter is the MAC address of the host that is being
+       looked for.
+
+               iwpriv ethX fwt_lookup da
+
+       where:-
+               da              -- DA MAC address (in the form "00:11:22:33:44:55")
+
+       The command returns an output string identical to the one returned by
+       fwt_list described below.
+
+
+fwt_list
+       This command is used to list a route from the FWT table. The only
+       parameter is the index into the table. If you want to list all the
+       routes in a table, start with index=0, and keep listing until you get a
+       "(null)" string.  Note that the indicies may change as the fwt is
+       updated.  It is expected that most users will not use fwt_list directly,
+       but that a utility similar to the traditional route command will be used
+       to invoke fwt_list over and over.
+
+               iwpriv ethX fwt_list index
+
+       The output is a string of the following form:
+
+               da ra metric dir ssn dsn hopcount ttl expiration sleepmode snr
+
+       where the different fields are:-
+               da              -- DA MAC address (in the form "00:11:22:33:44:55")
+               ra              -- RA MAC address (in the form "00:11:22:33:44:55")
+               metric          -- route metric (cost: smaller-metric routes are preferred)
+               dir             -- direction (1 for direct, 0 for reverse)
+               ssn             -- Source Sequence Number (time at the RA for reverse routes)
+               dsn             -- Destination Sequence Number (time at the DA for direct routes)
+               hopcount        -- hop count (currently unused)
+               ttl             -- TTL (only used in reverse entries)
+               expiration      -- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
+               sleepmode       -- RA's sleep mode (currently unused)
+               snr             -- SNR in the link to RA (currently unused)
+
+fwt_list_route
+       This command is used to list a route from the FWT table. The only
+       parameter is the route ID. If you want to list all the routes in a
+       table, start with rid=0, and keep incrementing rid until you get a
+       "(null)" string. This function is similar to fwt_list. The only
+       difference is the output format.  Also note that this command is meant
+       for debugging.  It is expected that users will use fwt_lookup and
+       fwt_list.  One important reason for this is that the route id may change
+       as the route table is altered.
+
+               iwpriv ethX fwt_list_route rid
+
+       The output is a string of the following form:
+
+               da metric dir nid ssn dsn hopcount ttl expiration
+
+       where the different fields are:-
+               da              -- DA MAC address (in the form "00:11:22:33:44:55")
+               metric          -- route metric (cost: smaller-metric routes are preferred)
+               dir             -- direction (1 for direct, 0 for reverse)
+               nid             -- Next-hop (neighbor) host ID (nid)
+               ssn             -- Source Sequence Number (time at the RA for reverse routes)
+               dsn             -- Destination Sequence Number (time at the DA for direct routes)
+               hopcount        -- hop count (currently unused)
+               ttl             -- TTL count (only used in reverse entries)
+               expiration      -- entry expiration (in ticks, where a tick is 1024us, or ~ 1ms. Use 0 for an indefinite entry)
+
+fwt_list_neigh
+       This command is used to list a neighbor from the FWT table. The only
+       parameter is the neighbor ID. If you want to list all the neighbors in a
+       table, start with nid=0, and keep incrementing nid until you get a
+       "(null)" string.  Note that the nid from a fwt_list_route command can be
+       used as an input to this command.  Also note that this command is meant
+       mostly for debugging.  It is expected that users will use fwt_lookup.
+       One important reason for this is that the neighbor id may change as the
+       neighbor table is altered.
+
+               iwpriv ethX fwt_list_neigh nid
+
+       The output is a string of the following form:
+
+               ra sleepmode snr references
+
+       where the different fields are:-
+               ra              -- RA MAC address (in the form "00:11:22:33:44:55")
+               sleepmode       -- RA's sleep mode (currently unused)
+               snr             -- SNR in the link to RA (currently unused)
+               references      -- RA's reference counter
+
+fwt_reset
+       This command is used to reset the FWT table, getting rid of all the
+       entries. There are no input parameters.
+
+               iwpriv ethX fwt_reset
+
+       The command does not return anything.
+
+fwt_cleanup
+       This command is used to perform user-based garbage recollection. The
+       FWT table is checked, and all the entries that are expired or invalid
+       are cleaned. Note that this is exported to the driver for debugging
+       purposes, as garbage collection is also fired by the firmware when in
+       space problems. There are no input parameters.
+
+               iwpriv ethX fwt_cleanup
+
+       The command does returns the number of invalid/expired routes deleted.
+
+fwt_time
+       This command returns a card's internal time representation.  It is this
+       time that is used to represent the expiration times of FWT entries.  The
+       number is not consistent from card to card; it is simply a timer count.
+       The fwt_time command is used to inspect the timer so that expiration
+       times reported by fwt_list can be properly interpreted.
+
+               iwpriv ethX fwt_time
+
+mesh_get_ttl
+
+       The mesh ttl is the number of hops a mesh packet can traverse before it
+       is dropped.  This parameter is used to prevent infinite loops in the
+       mesh network.  The value returned by this function is the ttl assigned
+       to all mesh packets.  Currently there is no way to control the ttl on a
+       per packet or per socket basis.
+
+       iwpriv ethX mesh_get_ttl
+
+mesh_set_ttl ttl
+
+       Set the ttl.  The argument must be between 0 and 255.
+
+       iwpriv ethX mesh_set_ttl <ttl>
+
+=========================
+ETHTOOL
+=========================
+
+
+Use the -i option to retrieve version information from the driver.
+
+# ethtool -i eth0
+driver: libertas
+version: COMM-USB8388-318.p4
+firmware-version: 5.110.7
+bus-info:
+
+Use the -e option to read the EEPROM contents of the card.
+
+       Usage:
+       ethtool -e ethX [raw on|off] [offset N] [length N]
+
+       -e     retrieves and prints an EEPROM dump for the  specified  ethernet
+              device.   When raw is enabled, then it dumps the raw EEPROM data
+              to stdout. The length and offset parameters allow  dumping  cer-
+              tain portions of the EEPROM.  Default is to dump the entire EEP-
+              ROM.
+
+# ethtool -e eth0 offset 0 length 16
+Offset          Values
+------          ------
+0x0000          38 33 30 58 00 00 34 f4 00 00 10 00 00 c4 17 00
+
+========================
+DEBUGFS COMMANDS
+========================
+
+those commands are used via debugfs interface
+
+===========
+rdmac
+rdbbp
+rdrf
+       These commands are used to read the MAC, BBP and RF registers from the
+       card.  These commands take one parameter that specifies the offset
+       location that is to be read.  This parameter must be specified in
+       hexadecimal (its possible to preceed preceding the number with a "0x").
+
+       Path: /debugfs/libertas_wireless/ethX/registers/
+
+       Usage:
+               echo "0xa123" > rdmac ; cat rdmac
+               echo "0xa123" > rdbbp ; cat rdbbp
+               echo "0xa123" > rdrf ; cat rdrf
+wrmac
+wrbbp
+wrrf
+       These commands are used to write the MAC, BBP and RF registers in the
+       card.  These commands take two parameters that specify the offset
+       location and the value that is to be written. This parameters must
+       be specified in hexadecimal (its possible to preceed the number
+       with a "0x").
+
+       Usage:
+               echo "0xa123 0xaa" > wrmac
+               echo "0xa123 0xaa" > wrbbp
+               echo "0xa123 0xaa" > wrrf
+
+sleepparams
+       This command is used to set the sleepclock configurations
+
+       Path: /debugfs/libertas_wireless/ethX/
+
+       Usage:
+               cat sleepparams: reads the current sleepclock configuration
+
+               echo "p1 p2 p3 p4 p5 p6" > sleepparams: writes the sleepclock configuration.
+
+               where:
+                       p1 is Sleep clock error in ppm (0-65535)
+                       p2 is Wakeup offset in usec (0-65535)
+                       p3 is Clock stabilization time in usec (0-65535)
+                       p4 is Control periodic calibration (0-2)
+                       p5 is Control the use of external sleep clock (0-2)
+                       p6 is reserved for debug (0-65535)
+
+subscribed_events
+
+       The subscribed_events directory contains the interface for the
+       subscribed events API.
+
+       Path: /debugfs/libertas_wireless/ethX/subscribed_events/
+
+       Each event is represented by a filename. Each filename consists of the
+       following three fields:
+       Value Frequency Subscribed
+
+       To read the current values for a given event, do:
+               cat event
+       To set the current values, do:
+               echo "60 2 1" > event
+
+       Frequency field specifies the reporting frequency for this event.
+       If it is set to 0, then the event is reported only once, and then
+       automatically unsubscribed. If it is set to 1, then the event is
+       reported every time it occurs. If it is set to N, then the event is
+       reported every Nth time it occurs.
+
+       beacon_missed
+       Value field specifies the number of consecutive missing beacons which
+       triggers the LINK_LOSS event. This event is generated only once after
+       which the firmware resets its state. At initialization, the LINK_LOSS
+       event is subscribed by default. The default value of MissedBeacons is
+       60.
+
+       failure_count
+       Value field specifies the consecutive failure count threshold which
+       triggers the generation of the MAX_FAIL event. Once this event is
+       generated, the consecutive failure count is reset to 0.
+       At initialization, the MAX_FAIL event is NOT subscribed by
+       default.
+
+       high_rssi
+       This event is generated when the average received RSSI in beacons goes
+       above a threshold, specified by Value.
+
+       low_rssi
+       This event is generated when the average received RSSI in beacons goes
+       below a threshold, specified by Value.
+
+       high_snr
+       This event is generated when the average received SNR in beacons goes
+       above a threshold, specified by Value.
+
+       low_snr
+       This event is generated when the average received SNR in beacons goes
+       below a threshold, specified by Value.
+
+extscan
+       This command is used to do a specific scan.
+
+       Path: /debugfs/libertas_wireless/ethX/
+
+       Usage: echo "SSID" > extscan
+
+       Example:
+               echo "LINKSYS-AP" > extscan
+
+       To see the results of use getscantable command.
+
+getscantable
+
+       Display the current contents of the driver scan table (ie. get the
+       scan results).
+
+       Path: /debugfs/libertas_wireless/ethX/
+
+       Usage:
+               cat getscantable
+
+setuserscan
+       Initiate a customized scan and retrieve the results
+
+
+       Path: /debugfs/libertas_wireless/ethX/
+
+    Usage:
+       echo "[ARGS]" > setuserscan
+
+         where [ARGS]:
+
+      chan=[chan#][band][mode] where band is [a,b,g] and mode is
+                               blank for active or 'p' for passive
+      bssid=xx:xx:xx:xx:xx:xx  specify a BSSID filter for the scan
+      ssid="[SSID]"            specify a SSID filter for the scan
+      keep=[0 or 1]            keep the previous scan results (1), discard (0)
+      dur=[scan time]          time to scan for each channel in milliseconds
+      probes=[#]               number of probe requests to send on each chan
+      type=[1,2,3]             BSS type: 1 (Infra), 2(Adhoc), 3(Any)
+
+    Any combination of the above arguments can be supplied on the command line.
+      If the chan token is absent, a full channel scan will be completed by
+      the driver.  If the dur or probes tokens are absent, the driver default
+      setting will be used.  The bssid and ssid fields, if blank,
+      will produce an unfiltered scan. The type field will default to 3 (Any)
+      and the keep field will default to 0 (Discard).
+
+    Examples:
+    1) Perform an active scan on channels 1, 6, and 11 in the 'g' band:
+            echo "chan=1g,6g,11g" > setuserscan
+
+    2) Perform a passive scan on channel 11 for 20 ms:
+            echo "chan=11gp dur=20" > setuserscan
+
+    3) Perform an active scan on channels 1, 6, and 11; and a passive scan on
+       channel 36 in the 'a' band:
+
+            echo "chan=1g,6g,11g,36ap" > setuserscan
+
+    4) Perform an active scan on channel 6 and 36 for a specific SSID:
+            echo "chan=6g,36a ssid="TestAP"" > setuserscan
+
+    5) Scan all available channels (B/G, A bands) for a specific BSSID, keep
+       the current scan table intact, update existing or append new scan data:
+            echo "bssid=00:50:43:20:12:82 keep=1" > setuserscan
+
+    6) Scan channel 6, for all infrastructure networks, sending two probe
+       requests.  Keep the previous scan table intact. Update any duplicate
+       BSSID/SSID matches with the new scan data:
+            echo "chan=6g type=1 probes=2 keep=1" > setuserscan
+
+    All entries in the scan table (not just the new scan data when keep=1)
+    will be displayed upon completion by use of the getscantable ioctl.
+
+==============================================================================
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
new file mode 100644 (file)
index 0000000..b55c7f5
--- /dev/null
@@ -0,0 +1,588 @@
+/* Copyright (C) 2006, Red Hat, Inc. */
+
+#include <linux/bitops.h>
+#include <net/ieee80211.h>
+
+#include "assoc.h"
+#include "join.h"
+#include "decl.h"
+#include "hostcmd.h"
+#include "host.h"
+
+
+static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+static int assoc_helper_essid(wlan_private *priv,
+                              struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+       int i;
+
+       ENTER();
+
+       lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid);
+       if (assoc_req->mode == wlan802_11infrastructure) {
+               if (adapter->prescan) {
+                       libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
+               }
+
+               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
+                               NULL, wlan802_11infrastructure);
+               if (i >= 0) {
+                       lbs_pr_debug(1,
+                              "SSID found in scan list ... associating...\n");
+
+                       ret = wlan_associate(priv, &adapter->scantable[i]);
+                       if (ret == 0) {
+                               memcpy(&assoc_req->bssid,
+                                      &adapter->scantable[i].macaddress,
+                                      ETH_ALEN);
+                       }
+               } else {
+                       lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n",
+                               assoc_req->ssid.ssid);
+               }
+       } else if (assoc_req->mode == wlan802_11ibss) {
+               /* Scan for the network, do not save previous results.  Stale
+                *   scan data will cause us to join a non-existant adhoc network
+                */
+               libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0);
+
+               /* Search for the requested SSID in the scan table */
+               i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
+                               wlan802_11ibss);
+               if (i >= 0) {
+                       lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret);
+                       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", assoc_req->ssid.ssid);
+                       libertas_start_adhoc_network(priv, &assoc_req->ssid);
+               }
+               memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN);
+       }
+
+       LEAVE();
+       return ret;
+}
+
+
+static int assoc_helper_bssid(wlan_private *priv,
+                              struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int i, ret = 0;
+
+       ENTER();
+
+       lbs_pr_debug(1, "ASSOC: WAP: BSSID = " MAC_FMT "\n",
+               MAC_ARG(assoc_req->bssid));
+
+       /* Search for index position in list for requested MAC */
+       i = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
+                           assoc_req->mode);
+       if (i < 0) {
+               lbs_pr_debug(1, "ASSOC: WAP: BSSID " MAC_FMT " not found, "
+                       "cannot associate.\n", MAC_ARG(assoc_req->bssid));
+               goto out;
+       }
+
+       if (assoc_req->mode == wlan802_11infrastructure) {
+               ret = wlan_associate(priv, &adapter->scantable[i]);
+               lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret);
+       } else if (assoc_req->mode == wlan802_11ibss) {
+               libertas_join_adhoc_network(priv, &adapter->scantable[i]);
+       }
+       memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid,
+               sizeof(struct WLAN_802_11_SSID));
+
+out:
+       LEAVE();
+       return ret;
+}
+
+
+static int assoc_helper_associate(wlan_private *priv,
+                                  struct assoc_request * assoc_req)
+{
+       int ret = 0, done = 0;
+
+       /* If we're given and 'any' BSSID, try associating based on SSID */
+
+       if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
+               if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN)
+                   && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) {
+                       ret = assoc_helper_bssid(priv, assoc_req);
+                       done = 1;
+                       if (ret) {
+                               lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+                       }
+               }
+       }
+
+       if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
+               ret = assoc_helper_essid(priv, assoc_req);
+               if (ret) {
+                       lbs_pr_debug(1, "ASSOC: bssid: ret = %d\n", ret);
+               }
+       }
+
+       return ret;
+}
+
+
+static int assoc_helper_mode(wlan_private *priv,
+                             struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       ENTER();
+
+       if (assoc_req->mode == adapter->inframode) {
+               LEAVE();
+               return 0;
+       }
+
+       if (assoc_req->mode == wlan802_11infrastructure) {
+               if (adapter->psstate != PS_STATE_FULL_POWER)
+                       libertas_ps_wakeup(priv, cmd_option_waitforrsp);
+               adapter->psmode = wlan802_11powermodecam;
+       }
+
+       adapter->inframode = assoc_req->mode;
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_snmp_mib,
+                                   0, cmd_option_waitforrsp,
+                                   OID_802_11_INFRASTRUCTURE_MODE,
+                                   (void *) assoc_req->mode);
+
+       LEAVE();
+       return ret;
+}
+
+
+static int assoc_helper_wep_keys(wlan_private *priv,
+                                 struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int i;
+       int ret = 0;
+
+       ENTER();
+
+       /* Set or remove WEP keys */
+       if (   assoc_req->wep_keys[0].len
+           || assoc_req->wep_keys[1].len
+           || assoc_req->wep_keys[2].len
+           || assoc_req->wep_keys[3].len) {
+               ret = libertas_prepare_and_send_command(priv,
+                                           cmd_802_11_set_wep,
+                                           cmd_act_add,
+                                           cmd_option_waitforrsp,
+                                           0, assoc_req);
+       } else {
+               ret = libertas_prepare_and_send_command(priv,
+                                           cmd_802_11_set_wep,
+                                           cmd_act_remove,
+                                           cmd_option_waitforrsp,
+                                           0, NULL);
+       }
+
+       if (ret)
+               goto out;
+
+       /* enable/disable the MAC's WEP packet filter */
+       if (assoc_req->secinfo.WEPstatus == wlan802_11WEPenabled)
+               adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
+       else
+               adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
+       ret = libertas_set_mac_packet_filter(priv);
+       if (ret)
+               goto out;
+
+       mutex_lock(&adapter->lock);
+
+       /* Copy WEP keys into adapter wep key fields */
+       for (i = 0; i < 4; i++) {
+               memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
+                       sizeof(struct WLAN_802_11_KEY));
+       }
+       adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
+
+       mutex_unlock(&adapter->lock);
+
+out:
+       LEAVE();
+       return ret;
+}
+
+static int assoc_helper_secinfo(wlan_private *priv,
+                                struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       ENTER();
+
+       memcpy(&adapter->secinfo, &assoc_req->secinfo,
+               sizeof(struct wlan_802_11_security));
+
+       ret = libertas_set_mac_packet_filter(priv);
+
+       LEAVE();
+       return ret;
+}
+
+
+static int assoc_helper_wpa_keys(wlan_private *priv,
+                                 struct assoc_request * assoc_req)
+{
+       int ret = 0;
+
+       ENTER();
+
+       /* enable/Disable RSN */
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_enable_rsn,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   0, assoc_req);
+       if (ret)
+               goto out;
+
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_key_material,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp,
+                                   0, assoc_req);
+
+out:
+       LEAVE();
+       return ret;
+}
+
+
+static int assoc_helper_wpa_ie(wlan_private *priv,
+                               struct assoc_request * assoc_req)
+{
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       ENTER();
+
+       if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
+               memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
+               adapter->wpa_ie_len = assoc_req->wpa_ie_len;
+       } else {
+               memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
+               adapter->wpa_ie_len = 0;
+       }
+
+       LEAVE();
+       return ret;
+}
+
+
+static int should_deauth_infrastructure(wlan_adapter *adapter,
+                                        struct assoc_request * assoc_req)
+{
+       if (adapter->connect_status != libertas_connected)
+               return 0;
+
+       if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
+               lbs_pr_debug(1, "Deauthenticating due to new SSID in "
+                       " configuration request.\n");
+               return 1;
+       }
+
+       if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
+               if (adapter->secinfo.authmode !=
+                   assoc_req->secinfo.authmode) {
+                       lbs_pr_debug(1, "Deauthenticating due to updated security "
+                               "info in configuration request.\n");
+                       return 1;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
+               lbs_pr_debug(1, "Deauthenticating due to new BSSID in "
+                       " configuration request.\n");
+               return 1;
+       }
+
+       /* FIXME: deal with 'auto' mode somehow */
+       if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
+               if (assoc_req->mode != wlan802_11infrastructure)
+                       return 1;
+       }
+
+       return 0;
+}
+
+
+static int should_stop_adhoc(wlan_adapter *adapter,
+                             struct assoc_request * assoc_req)
+{
+       if (adapter->connect_status != libertas_connected)
+               return 0;
+
+       if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
+               return 1;
+       if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
+                       sizeof(struct WLAN_802_11_SSID)))
+               return 1;
+
+       /* FIXME: deal with 'auto' mode somehow */
+       if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
+               if (assoc_req->mode != wlan802_11ibss)
+                       return 1;
+       }
+
+       return 0;
+}
+
+
+void wlan_association_worker(struct work_struct *work)
+{
+       wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
+       wlan_adapter *adapter = priv->adapter;
+       struct assoc_request * assoc_req = NULL;
+       int ret = 0;
+       int find_any_ssid = 0;
+
+       ENTER();
+
+       mutex_lock(&adapter->lock);
+       assoc_req = adapter->assoc_req;
+       adapter->assoc_req = NULL;
+       mutex_unlock(&adapter->lock);
+
+       if (!assoc_req) {
+               LEAVE();
+               return;
+       }
+
+       lbs_pr_debug(1, "ASSOC: starting new association request: flags = 0x%lX\n",
+               assoc_req->flags);
+
+       /* If 'any' SSID was specified, find an SSID to associate with */
+       if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
+           && !assoc_req->ssid.ssidlength)
+               find_any_ssid = 1;
+
+       /* But don't use 'any' SSID if there's a valid locked BSSID to use */
+       if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
+               if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN)
+                   && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN))
+                       find_any_ssid = 0;
+       }
+
+       if (find_any_ssid) {
+               enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode;
+
+               ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
+                               assoc_req->mode, &new_mode);
+               if (ret) {
+                       lbs_pr_debug(1, "Could not find best network\n");
+                       ret = -ENETUNREACH;
+                       goto out;
+               }
+
+               /* Ensure we switch to the mode of the AP */
+               if (assoc_req->mode == wlan802_11autounknown) {
+                       set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
+                       assoc_req->mode = new_mode;
+               }
+       }
+
+       /*
+        * Check if the attributes being changing require deauthentication
+        * from the currently associated infrastructure access point.
+        */
+       if (adapter->inframode == wlan802_11infrastructure) {
+               if (should_deauth_infrastructure(adapter, assoc_req)) {
+                       ret = libertas_send_deauthentication(priv);
+                       if (ret) {
+                               lbs_pr_debug(1, "Deauthentication due to new "
+                                       "configuration request failed: %d\n",
+                                       ret);
+                       }
+               }
+       } else if (adapter->inframode == wlan802_11ibss) {
+               if (should_stop_adhoc(adapter, assoc_req)) {
+                       ret = libertas_stop_adhoc_network(priv);
+                       if (ret) {
+                               lbs_pr_debug(1, "Teardown of AdHoc network due to "
+                                       "new configuration request failed: %d\n",
+                                       ret);
+                       }
+
+               }
+       }
+
+       /* Send the various configuration bits to the firmware */
+       if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
+               ret = assoc_helper_mode(priv, assoc_req);
+               if (ret) {
+lbs_pr_debug(1, "ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (   test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
+           || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
+               ret = assoc_helper_wep_keys(priv, assoc_req);
+               if (ret) {
+lbs_pr_debug(1, "ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
+               ret = assoc_helper_secinfo(priv, assoc_req);
+               if (ret) {
+lbs_pr_debug(1, "ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
+               ret = assoc_helper_wpa_ie(priv, assoc_req);
+               if (ret) {
+lbs_pr_debug(1, "ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
+           || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
+               ret = assoc_helper_wpa_keys(priv, assoc_req);
+               if (ret) {
+lbs_pr_debug(1, "ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
+                       goto out;
+               }
+       }
+
+       /* SSID/BSSID should be the _last_ config option set, because they
+        * trigger the association attempt.
+        */
+       if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
+           || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
+               int success = 1;
+
+               ret = assoc_helper_associate(priv, assoc_req);
+               if (ret) {
+                       lbs_pr_debug(1, "ASSOC: association attempt unsuccessful: %d\n",
+                               ret);
+                       success = 0;
+               }
+
+               if (adapter->connect_status != libertas_connected) {
+                       lbs_pr_debug(1, "ASSOC: assoication attempt unsuccessful, "
+                               "not connected.\n");
+                       success = 0;
+               }
+
+               if (success) {
+                       lbs_pr_debug(1, "ASSOC: association attempt successful. "
+                               "Associated to '%s' (" MAC_FMT ")\n",
+                               assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid));
+                       libertas_prepare_and_send_command(priv,
+                               cmd_802_11_rssi,
+                               0, cmd_option_waitforrsp, 0, NULL);
+
+                       libertas_prepare_and_send_command(priv,
+                               cmd_802_11_get_log,
+                               0, cmd_option_waitforrsp, 0, NULL);
+               } else {
+
+                       ret = -1;
+               }
+       }
+
+out:
+       if (ret) {
+               lbs_pr_debug(1, "ASSOC: reconfiguration attempt unsuccessful: %d\n",
+                       ret);
+       }
+       kfree(assoc_req);
+       LEAVE();
+}
+
+
+/*
+ * Caller MUST hold any necessary locks
+ */
+struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
+{
+       struct assoc_request * assoc_req;
+
+       if (!adapter->assoc_req) {
+               adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL);
+               if (!adapter->assoc_req) {
+                       lbs_pr_info("Not enough memory to allocate association"
+                               " request!\n");
+                       return NULL;
+               }
+       }
+
+       /* Copy current configuration attributes to the association request,
+        * but don't overwrite any that are already set.
+        */
+       assoc_req = adapter->assoc_req;
+       if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
+               memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid,
+                       adapter->curbssparams.ssid.ssidlength);
+       }
+
+       if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
+               assoc_req->channel = adapter->curbssparams.channel;
+
+       if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
+               assoc_req->mode = adapter->inframode;
+
+       if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
+               memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
+                       ETH_ALEN);
+       }
+
+       if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
+               int i;
+               for (i = 0; i < 4; i++) {
+                       memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
+                               sizeof(struct WLAN_802_11_KEY));
+               }
+       }
+
+       if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
+               assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
+
+       if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
+               memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
+                       sizeof(struct WLAN_802_11_KEY));
+       }
+
+       if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
+               memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
+                       sizeof(struct WLAN_802_11_KEY));
+       }
+
+       if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
+               memcpy(&assoc_req->secinfo, &adapter->secinfo,
+                       sizeof(struct wlan_802_11_security));
+       }
+
+       if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
+               memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
+                       MAX_WPA_IE_LEN);
+               assoc_req->wpa_ie_len = adapter->wpa_ie_len;
+       }
+
+       return assoc_req;
+}
+
+
diff --git a/drivers/net/wireless/libertas/assoc.h b/drivers/net/wireless/libertas/assoc.h
new file mode 100644 (file)
index 0000000..2ffd82d
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 2006, Red Hat, Inc. */
+
+#ifndef _WLAN_ASSOC_H_
+#define _WLAN_ASSOC_H_
+
+#include "dev.h"
+
+void wlan_association_worker(struct work_struct *work);
+
+struct assoc_request * wlan_get_association_request(wlan_adapter *adapter);
+
+#define ASSOC_DELAY (HZ / 2)
+static inline void wlan_postpone_association_work(wlan_private *priv)
+{
+       if (priv->adapter->surpriseremoved)
+               return;
+       cancel_delayed_work(&priv->assoc_work);
+       queue_delayed_work(priv->assoc_thread, &priv->assoc_work, ASSOC_DELAY);
+}
+
+static inline void wlan_cancel_association_work(wlan_private *priv)
+{
+       cancel_delayed_work(&priv->assoc_work);
+       if (priv->adapter->assoc_req) {
+               kfree(priv->adapter->assoc_req);
+               priv->adapter->assoc_req = NULL;
+       }
+}
+
+#endif /* _WLAN_ASSOC_H */
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
new file mode 100644 (file)
index 0000000..bfdac58
--- /dev/null
@@ -0,0 +1,1958 @@
+/**
+  * This file contains the handling of command.
+  * It prepares command and sends it to firmware when it is ready.
+  */
+
+#include <net/iw_handler.h>
+#include "host.h"
+#include "hostcmd.h"
+#include "sbi.h"
+#include "decl.h"
+#include "defs.h"
+#include "dev.h"
+#include "join.h"
+#include "wext.h"
+
+static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
+
+static u16 commands_allowed_in_ps[] = {
+       cmd_802_11_rssi,
+};
+
+/**
+ *  @brief This function checks if the commans is allowed
+ *  in PS mode not.
+ *
+ *  @param command the command ID
+ *  @return       TRUE or FALSE
+ */
+static u8 is_command_allowed_in_ps(u16 command)
+{
+       int count = sizeof(commands_allowed_in_ps)
+           / sizeof(commands_allowed_in_ps[0]);
+       int i;
+
+       for (i = 0; i < count; i++) {
+               if (command == cpu_to_le16(commands_allowed_in_ps[i]))
+                       return 1;
+       }
+
+       return 0;
+}
+
+static int wlan_cmd_hw_spec(wlan_private * priv, struct cmd_ds_command *cmd)
+{
+       struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_get_hw_spec);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
+       memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_ps_mode(wlan_private * priv,
+                                  struct cmd_ds_command *cmd,
+                                  u16 cmd_action)
+{
+       struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
+       u16 action = cmd_action;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
+                            S_DS_GEN);
+       psm->action = cpu_to_le16(cmd_action);
+       psm->multipledtim = 0;
+       switch (action) {
+       case cmd_subcmd_enter_ps:
+               lbs_pr_debug(1, "PS command:" "SubCode- Enter PS\n");
+               lbs_pr_debug(1, "locallisteninterval = %d\n",
+                      adapter->locallisteninterval);
+
+               psm->locallisteninterval =
+                   cpu_to_le16(adapter->locallisteninterval);
+               psm->nullpktinterval =
+                   cpu_to_le16(adapter->nullpktinterval);
+               psm->multipledtim =
+                   cpu_to_le16(priv->adapter->multipledtim);
+               break;
+
+       case cmd_subcmd_exit_ps:
+               lbs_pr_debug(1, "PS command:" "SubCode- Exit PS\n");
+               break;
+
+       case cmd_subcmd_sleep_confirmed:
+               lbs_pr_debug(1, "PS command: SubCode- sleep confirm\n");
+               break;
+
+       default:
+               break;
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
+                                             struct cmd_ds_command *cmd,
+                                             u16 cmd_action, void *pdata_buf)
+{
+       u16 *timeout = pdata_buf;
+
+       cmd->command = cpu_to_le16(cmd_802_11_inactivity_timeout);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
+                            + S_DS_GEN);
+
+       cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
+
+       if (cmd_action)
+               cmd->params.inactivity_timeout.timeout =
+                   cpu_to_le16(*timeout);
+       else
+               cmd->params.inactivity_timeout.timeout = 0;
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
+                                       struct cmd_ds_command *cmd,
+                                       u16 cmd_action)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
+
+       ENTER();
+
+       cmd->size =
+           cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
+                            S_DS_GEN);
+       cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
+
+       if (cmd_action == cmd_act_get) {
+               memset(&adapter->sp, 0, sizeof(struct sleep_params));
+               memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
+               sp->action = cpu_to_le16(cmd_action);
+       } else if (cmd_action == cmd_act_set) {
+               sp->action = cpu_to_le16(cmd_action);
+               sp->error = cpu_to_le16(adapter->sp.sp_error);
+               sp->offset = cpu_to_le16(adapter->sp.sp_offset);
+               sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
+               sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
+               sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
+               sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_set_wep(wlan_private * priv,
+                                   struct cmd_ds_command *cmd,
+                                   u32 cmd_act,
+                                   void * pdata_buf)
+{
+       struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+       struct assoc_request * assoc_req = pdata_buf;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_802_11_set_wep);
+       cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_set_wep))
+                                    + S_DS_GEN);
+
+       if (cmd_act == cmd_act_add) {
+               int i;
+
+               if (!assoc_req) {
+                       lbs_pr_debug(1, "Invalid association request!");
+                       ret = -1;
+                       goto done;
+               }
+
+               wep->action = cpu_to_le16(cmd_act_add);
+
+               /* default tx key index */
+               wep->keyindex = cpu_to_le16((u16)
+                                                (assoc_req->wep_tx_keyidx &
+                                                (u32)cmd_WEP_KEY_INDEX_MASK));
+
+               lbs_pr_debug(1, "Tx key Index: %u\n", wep->keyindex);
+
+               /* Copy key types and material to host command structure */
+               for (i = 0; i < 4; i++) {
+                       struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
+
+                       switch (pkey->len) {
+                       case KEY_LEN_WEP_40:
+                               wep->keytype[i] = cmd_type_wep_40_bit;
+                               memmove(&wep->keymaterial[i], pkey->key,
+                                       pkey->len);
+                               break;
+                       case KEY_LEN_WEP_104:
+                               wep->keytype[i] = cmd_type_wep_104_bit;
+                               memmove(&wep->keymaterial[i], pkey->key,
+                                       pkey->len);
+                               break;
+                       case 0:
+                               break;
+                       default:
+                               lbs_pr_debug(1, "Invalid WEP key %d length of %d\n",
+                                      i, pkey->len);
+                               ret = -1;
+                               goto done;
+                               break;
+                       }
+               }
+       } else if (cmd_act == cmd_act_remove) {
+               /* ACT_REMOVE clears _all_ WEP keys */
+               wep->action = cpu_to_le16(cmd_act_remove);
+
+               /* default tx key index */
+               wep->keyindex = cpu_to_le16((u16)
+                                                (adapter->wep_tx_keyidx &
+                                                (u32)cmd_WEP_KEY_INDEX_MASK));
+       }
+
+       ret = 0;
+
+done:
+       LEAVE();
+       return ret;
+}
+
+static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
+                                     struct cmd_ds_command *cmd,
+                                     u16 cmd_action)
+{
+       struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
+       wlan_adapter *adapter = priv->adapter;
+
+       cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_enable_rsn) +
+                            S_DS_GEN);
+       penableRSN->action = cpu_to_le16(cmd_action);
+       if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
+               penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
+       } else {
+               penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
+       }
+
+       return 0;
+}
+
+
+static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
+                            struct WLAN_802_11_KEY * pkey)
+{
+       pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
+
+       if (pkey->flags & KEY_INFO_WPA_ENABLED) {
+               pkeyparamset->keyinfo = cpu_to_le16(KEY_INFO_WPA_ENABLED);
+       } else {
+               pkeyparamset->keyinfo = cpu_to_le16(!KEY_INFO_WPA_ENABLED);
+       }
+
+       if (pkey->flags & KEY_INFO_WPA_UNICAST) {
+               pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
+       } else if (pkey->flags & KEY_INFO_WPA_MCAST) {
+               pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
+       }
+
+       pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
+       pkeyparamset->keylen = cpu_to_le16(pkey->len);
+       memcpy(pkeyparamset->key, pkey->key, pkey->len);
+       pkeyparamset->length = cpu_to_le16(  sizeof(pkeyparamset->keytypeid)
+                                               + sizeof(pkeyparamset->keyinfo)
+                                               + sizeof(pkeyparamset->keylen)
+                                               + sizeof(pkeyparamset->key));
+}
+
+static int wlan_cmd_802_11_key_material(wlan_private * priv,
+                                       struct cmd_ds_command *cmd,
+                                       u16 cmd_action,
+                                       u32 cmd_oid, void *pdata_buf)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ds_802_11_key_material *pkeymaterial =
+           &cmd->params.keymaterial;
+       int ret = 0;
+       int index = 0;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_802_11_key_material);
+       pkeymaterial->action = cpu_to_le16(cmd_action);
+
+       if (cmd_action == cmd_act_get) {
+               cmd->size = cpu_to_le16(  S_DS_GEN
+                                            + sizeof (pkeymaterial->action));
+               ret = 0;
+               goto done;
+       }
+
+       memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
+
+       if (adapter->wpa_unicast_key.len) {
+               set_one_wpa_key(&pkeymaterial->keyParamSet[index],
+                               &adapter->wpa_unicast_key);
+               index++;
+       }
+
+       if (adapter->wpa_mcast_key.len) {
+               set_one_wpa_key(&pkeymaterial->keyParamSet[index],
+                               &adapter->wpa_mcast_key);
+               index++;
+       }
+
+       cmd->size = cpu_to_le16(  S_DS_GEN
+                                    + sizeof (pkeymaterial->action)
+                                    + index * sizeof(struct MrvlIEtype_keyParamSet));
+
+       ret = 0;
+
+done:
+       LEAVE();
+       return ret;
+}
+
+static int wlan_cmd_802_11_reset(wlan_private * priv,
+                                struct cmd_ds_command *cmd, int cmd_action)
+{
+       struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
+
+       cmd->command = cpu_to_le16(cmd_802_11_reset);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
+       reset->action = cpu_to_le16(cmd_action);
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_get_log(wlan_private * priv,
+                                  struct cmd_ds_command *cmd)
+{
+       cmd->command = cpu_to_le16(cmd_802_11_get_log);
+       cmd->size =
+               cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_get_stat(wlan_private * priv,
+                                   struct cmd_ds_command *cmd)
+{
+       cmd->command = cpu_to_le16(cmd_802_11_get_stat);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) +
+                            S_DS_GEN);
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
+                                   struct cmd_ds_command *cmd,
+                                   int cmd_action,
+                                   int cmd_oid, void *pdata_buf)
+{
+       struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
+       wlan_adapter *adapter = priv->adapter;
+       u8 ucTemp;
+
+       ENTER();
+
+       lbs_pr_debug(1, "SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
+
+       cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_snmp_mib) +
+                            S_DS_GEN);
+
+       switch (cmd_oid) {
+       case OID_802_11_INFRASTRUCTURE_MODE:
+       {
+               enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode =
+                       (enum WLAN_802_11_NETWORK_INFRASTRUCTURE) pdata_buf;
+               pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
+               pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
+               pSNMPMIB->bufsize = sizeof(u8);
+               if (mode == wlan802_11infrastructure)
+                       ucTemp = SNMP_MIB_VALUE_INFRA;
+               else
+                       ucTemp = SNMP_MIB_VALUE_ADHOC;
+
+               memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
+
+               break;
+       }
+
+       case OID_802_11D_ENABLE:
+               {
+                       u32 ulTemp;
+
+                       pSNMPMIB->oid = cpu_to_le16((u16) dot11d_i);
+
+                       if (cmd_action == cmd_act_set) {
+                               pSNMPMIB->querytype = cmd_act_set;
+                               pSNMPMIB->bufsize = sizeof(u16);
+                               ulTemp = *(u32 *)pdata_buf;
+                               *((unsigned short *)(pSNMPMIB->value)) =
+                                   cpu_to_le16((u16) ulTemp);
+                       }
+                       break;
+               }
+
+       case OID_802_11_FRAGMENTATION_THRESHOLD:
+               {
+                       u32 ulTemp;
+
+                       pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
+
+                       if (cmd_action == cmd_act_get) {
+                               pSNMPMIB->querytype =
+                                   cpu_to_le16(cmd_act_get);
+                       } else if (cmd_action == cmd_act_set) {
+                               pSNMPMIB->querytype =
+                                   cpu_to_le16(cmd_act_set);
+                               pSNMPMIB->bufsize =
+                                   cpu_to_le16(sizeof(u16));
+                               ulTemp = *((u32 *) pdata_buf);
+                               *((unsigned short *)(pSNMPMIB->value)) =
+                                   cpu_to_le16((u16) ulTemp);
+
+                       }
+
+                       break;
+               }
+
+       case OID_802_11_RTS_THRESHOLD:
+               {
+
+                       u32 ulTemp;
+                       pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
+
+                       if (cmd_action == cmd_act_get) {
+                               pSNMPMIB->querytype =
+                                   cpu_to_le16(cmd_act_get);
+                       } else if (cmd_action == cmd_act_set) {
+                               pSNMPMIB->querytype =
+                                   cpu_to_le16(cmd_act_set);
+                               pSNMPMIB->bufsize =
+                                   cpu_to_le16(sizeof(u16));
+                               ulTemp = *((u32 *)
+                                          pdata_buf);
+                               *(unsigned short *)(pSNMPMIB->value) =
+                                   cpu_to_le16((u16) ulTemp);
+
+                       }
+                       break;
+               }
+       case OID_802_11_TX_RETRYCOUNT:
+               pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
+
+               if (cmd_action == cmd_act_get) {
+                       pSNMPMIB->querytype =
+                           cpu_to_le16(cmd_act_get);
+               } else if (cmd_action == cmd_act_set) {
+                       pSNMPMIB->querytype =
+                           cpu_to_le16(cmd_act_set);
+                       pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
+                       *((unsigned short *)(pSNMPMIB->value)) =
+                           cpu_to_le16((u16) adapter->txretrycount);
+               }
+
+               break;
+       default:
+               break;
+       }
+
+       lbs_pr_debug(1,
+              "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
+              cmd->command, cmd->size, cmd->seqnum, cmd->result);
+
+       lbs_pr_debug(1,
+              "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
+              pSNMPMIB->querytype, pSNMPMIB->oid, pSNMPMIB->bufsize,
+              *(u16 *) pSNMPMIB->value);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_radio_control(wlan_private * priv,
+                                        struct cmd_ds_command *cmd,
+                                        int cmd_action)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ds_802_11_radio_control *pradiocontrol =
+           &cmd->params.radio;
+
+       ENTER();
+
+       cmd->size =
+           cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
+                            S_DS_GEN);
+       cmd->command = cpu_to_le16(cmd_802_11_radio_control);
+
+       pradiocontrol->action = cpu_to_le16(cmd_action);
+
+       switch (adapter->preamble) {
+       case cmd_type_short_preamble:
+               pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
+               break;
+
+       case cmd_type_long_preamble:
+               pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
+               break;
+
+       case cmd_type_auto_preamble:
+       default:
+               pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
+               break;
+       }
+
+       if (adapter->radioon)
+               pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
+       else
+               pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
+                                      struct cmd_ds_command *cmd,
+                                      u16 cmd_action, void *pdata_buf)
+{
+
+       struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
+
+       ENTER();
+
+       cmd->size =
+           cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) +
+                            S_DS_GEN);
+       cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
+       prtp->action = cmd_action;
+
+       lbs_pr_debug(1, "RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", cmd->size,
+              cmd->command, prtp->action);
+
+       switch (cmd_action) {
+       case cmd_act_tx_power_opt_get:
+               prtp->action = cpu_to_le16(cmd_act_get);
+               prtp->currentlevel = 0;
+               break;
+
+       case cmd_act_tx_power_opt_set_high:
+               prtp->action = cpu_to_le16(cmd_act_set);
+               prtp->currentlevel =
+                   cpu_to_le16(cmd_act_tx_power_index_high);
+               break;
+
+       case cmd_act_tx_power_opt_set_mid:
+               prtp->action = cpu_to_le16(cmd_act_set);
+               prtp->currentlevel =
+                   cpu_to_le16(cmd_act_tx_power_index_mid);
+               break;
+
+       case cmd_act_tx_power_opt_set_low:
+               prtp->action = cpu_to_le16(cmd_act_set);
+               prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
+               break;
+       }
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
+                                     struct cmd_ds_command *cmd,
+                                     u16 cmd_action, void *pdata_buf)
+{
+       struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
+
+       cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
+                            S_DS_GEN);
+
+       rant->action = cpu_to_le16(cmd_action);
+       if ((cmd_action == cmd_act_set_rx) ||
+           (cmd_action == cmd_act_set_tx)) {
+               rant->antennamode =
+                   cpu_to_le16((u16) (*(u32 *) pdata_buf));
+       }
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
+                                             struct cmd_ds_command *cmd,
+                                             u16 cmd_action)
+{
+       struct cmd_ds_802_11_rate_adapt_rateset
+       *rateadapt = &cmd->params.rateset;
+       wlan_adapter *adapter = priv->adapter;
+
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
+                            + S_DS_GEN);
+       cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
+
+       ENTER();
+
+       rateadapt->action = cmd_action;
+       rateadapt->enablehwauto = adapter->enablehwauto;
+       rateadapt->bitmap = adapter->ratebitmap;
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_data_rate(wlan_private * priv,
+                                    struct cmd_ds_command *cmd,
+                                    u16 cmd_action)
+{
+       struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
+       wlan_adapter *adapter = priv->adapter;
+       u16 action = cmd_action;
+
+       ENTER();
+
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
+                            S_DS_GEN);
+
+       cmd->command = cpu_to_le16(cmd_802_11_data_rate);
+
+       memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
+
+       pdatarate->action = cpu_to_le16(cmd_action);
+
+       if (action == cmd_act_set_tx_fix_rate) {
+               pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
+               lbs_pr_debug(1, "Setting FW for fixed rate 0x%02X\n",
+                      adapter->datarate);
+       } else if (action == cmd_act_set_tx_auto) {
+               lbs_pr_debug(1, "Setting FW for AUTO rate\n");
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
+                                     struct cmd_ds_command *cmd,
+                                     u16 cmd_action)
+{
+       struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
+       wlan_adapter *adapter = priv->adapter;
+
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
+                            S_DS_GEN);
+       cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
+
+       pMCastAdr->action = cpu_to_le16(cmd_action);
+       pMCastAdr->nr_of_adrs =
+           cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
+       memcpy(pMCastAdr->maclist, adapter->multicastlist,
+              adapter->nr_of_multicastmacaddr * ETH_ALEN);
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
+                                     struct cmd_ds_command *cmd,
+                                     int option, void *pdata_buf)
+{
+       struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
+
+       cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel)
+                                    + S_DS_GEN);
+
+       if (option == cmd_opt_802_11_rf_channel_set) {
+               rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
+       }
+
+       rfchan->action = cpu_to_le16(option);
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_rssi(wlan_private * priv,
+                               struct cmd_ds_command *cmd)
+{
+       wlan_adapter *adapter = priv->adapter;
+
+       cmd->command = cpu_to_le16(cmd_802_11_rssi);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
+       cmd->params.rssi.N = priv->adapter->bcn_avg_factor;
+
+       /* reset Beacon SNR/NF/RSSI values */
+       adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
+       adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
+       adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
+       adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
+       adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
+       adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
+
+       return 0;
+}
+
+static int wlan_cmd_reg_access(wlan_private * priv,
+                              struct cmd_ds_command *cmdptr,
+                              u8 cmd_action, void *pdata_buf)
+{
+       struct wlan_offset_value *offval;
+
+       ENTER();
+
+       offval = (struct wlan_offset_value *)pdata_buf;
+
+       switch (cmdptr->command) {
+       case cmd_mac_reg_access:
+               {
+                       struct cmd_ds_mac_reg_access *macreg;
+
+                       cmdptr->size =
+                           cpu_to_le16(sizeof
+                                            (struct cmd_ds_mac_reg_access)
+                                            + S_DS_GEN);
+                       macreg =
+                           (struct cmd_ds_mac_reg_access *)&cmdptr->params.
+                           macreg;
+
+                       macreg->action = cpu_to_le16(cmd_action);
+                       macreg->offset = cpu_to_le16((u16) offval->offset);
+                       macreg->value = cpu_to_le32(offval->value);
+
+                       break;
+               }
+
+       case cmd_bbp_reg_access:
+               {
+                       struct cmd_ds_bbp_reg_access *bbpreg;
+
+                       cmdptr->size =
+                           cpu_to_le16(sizeof
+                                            (struct cmd_ds_bbp_reg_access)
+                                            + S_DS_GEN);
+                       bbpreg =
+                           (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
+                           bbpreg;
+
+                       bbpreg->action = cpu_to_le16(cmd_action);
+                       bbpreg->offset = cpu_to_le16((u16) offval->offset);
+                       bbpreg->value = (u8) offval->value;
+
+                       break;
+               }
+
+       case cmd_rf_reg_access:
+               {
+                       struct cmd_ds_rf_reg_access *rfreg;
+
+                       cmdptr->size =
+                           cpu_to_le16(sizeof
+                                            (struct cmd_ds_rf_reg_access) +
+                                            S_DS_GEN);
+                       rfreg =
+                           (struct cmd_ds_rf_reg_access *)&cmdptr->params.
+                           rfreg;
+
+                       rfreg->action = cpu_to_le16(cmd_action);
+                       rfreg->offset = cpu_to_le16((u16) offval->offset);
+                       rfreg->value = (u8) offval->value;
+
+                       break;
+               }
+
+       default:
+               break;
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_cmd_802_11_mac_address(wlan_private * priv,
+                                      struct cmd_ds_command *cmd,
+                                      u16 cmd_action)
+{
+       wlan_adapter *adapter = priv->adapter;
+
+       cmd->command = cpu_to_le16(cmd_802_11_mac_address);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
+                            S_DS_GEN);
+       cmd->result = 0;
+
+       cmd->params.macadd.action = cpu_to_le16(cmd_action);
+
+       if (cmd_action == cmd_act_set) {
+               memcpy(cmd->params.macadd.macadd,
+                      adapter->current_addr, ETH_ALEN);
+               lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
+       }
+
+       return 0;
+}
+
+static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
+                                        struct cmd_ds_command *cmd,
+                                        int cmd_action, void *pdata_buf)
+{
+       struct wlan_ioctl_regrdwr *ea = pdata_buf;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
+                            S_DS_GEN);
+       cmd->result = 0;
+
+       cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
+       cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
+       cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
+       cmd->params.rdeeprom.value = 0;
+
+       return 0;
+}
+
+static int wlan_cmd_bt_access(wlan_private * priv,
+                              struct cmd_ds_command *cmd,
+                              u16 cmd_action, void *pdata_buf)
+{
+       struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
+       lbs_pr_debug(1, "BT CMD(%d)\n", cmd_action);
+
+       cmd->command = cpu_to_le16(cmd_bt_access);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access)
+                                    + S_DS_GEN);
+       cmd->result = 0;
+       bt_access->action = cpu_to_le16(cmd_action);
+
+       switch (cmd_action) {
+       case cmd_act_bt_access_add:
+               memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
+               lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
+               break;
+       case cmd_act_bt_access_del:
+               memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
+               lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
+               break;
+       case cmd_act_bt_access_list:
+               bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
+               break;
+       case cmd_act_bt_access_reset:
+               break;
+       default:
+               break;
+       }
+       return 0;
+}
+
+static int wlan_cmd_fwt_access(wlan_private * priv,
+                              struct cmd_ds_command *cmd,
+                              u16 cmd_action, void *pdata_buf)
+{
+       struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
+       lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+
+       cmd->command = cpu_to_le16(cmd_fwt_access);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access)
+                                    + S_DS_GEN);
+       cmd->result = 0;
+
+       if (pdata_buf)
+               memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
+       else
+               memset(fwt_access, 0, sizeof(*fwt_access));
+
+       fwt_access->action = cpu_to_le16(cmd_action);
+
+       return 0;
+}
+
+static int wlan_cmd_mesh_access(wlan_private * priv,
+                               struct cmd_ds_command *cmd,
+                               u16 cmd_action, void *pdata_buf)
+{
+       struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
+       lbs_pr_debug(1, "FWT CMD(%d)\n", cmd_action);
+
+       cmd->command = cpu_to_le16(cmd_mesh_access);
+       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access)
+                                    + S_DS_GEN);
+       cmd->result = 0;
+
+       if (pdata_buf)
+               memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
+       else
+               memset(mesh_access, 0, sizeof(*mesh_access));
+
+       mesh_access->action = cpu_to_le16(cmd_action);
+
+       return 0;
+}
+
+void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
+{
+       unsigned long flags;
+       struct cmd_ds_command *cmdptr;
+
+       ENTER();
+
+       if (!cmdnode) {
+               lbs_pr_debug(1, "QUEUE_CMD: cmdnode is NULL\n");
+               goto done;
+       }
+
+       cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
+       if (!cmdptr) {
+               lbs_pr_debug(1, "QUEUE_CMD: cmdptr is NULL\n");
+               goto done;
+       }
+
+       /* Exit_PS command needs to be queued in the header always. */
+       if (cmdptr->command == cmd_802_11_ps_mode) {
+               struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
+               if (psm->action == cmd_subcmd_exit_ps) {
+                       if (adapter->psstate != PS_STATE_FULL_POWER)
+                               addtail = 0;
+               }
+       }
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+
+       if (addtail)
+               list_add_tail((struct list_head *)cmdnode,
+                             &adapter->cmdpendingq);
+       else
+               list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
+
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       lbs_pr_debug(1, "QUEUE_CMD: Inserted node=0x%x, cmd=0x%x in cmdpendingq\n",
+              (u32) cmdnode,
+              ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
+
+done:
+       LEAVE();
+       return;
+}
+
+/*
+ * TODO: Fix the issue when DownloadcommandToStation is being called the
+ * second time when the command timesout. All the cmdptr->xxx are in little
+ * endian and therefore all the comparissions will fail.
+ * For now - we are not performing the endian conversion the second time - but
+ * for PS and DEEP_SLEEP we need to worry
+ */
+static int DownloadcommandToStation(wlan_private * priv,
+                                   struct cmd_ctrl_node *cmdnode)
+{
+       unsigned long flags;
+       struct cmd_ds_command *cmdptr;
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+       u16 cmdsize;
+       u16 command;
+
+       ENTER();
+
+       if (!adapter || !cmdnode) {
+               lbs_pr_debug(1, "DNLD_CMD: adapter = %#x, cmdnode = %#x\n",
+                      (int)adapter, (int)cmdnode);
+               if (cmdnode) {
+                       spin_lock_irqsave(&adapter->driver_lock, flags);
+                       __libertas_cleanup_and_insert_cmd(priv, cmdnode);
+                       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               }
+               ret = -1;
+               goto done;
+       }
+
+       cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
+
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+       if (!cmdptr || !cmdptr->size) {
+               lbs_pr_debug(1, "DNLD_CMD: cmdptr is Null or cmd size is Zero, "
+                      "Not sending\n");
+               __libertas_cleanup_and_insert_cmd(priv, cmdnode);
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               ret = -1;
+               goto done;
+       }
+
+       adapter->cur_cmd = cmdnode;
+       adapter->cur_cmd_retcode = 0;
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+       lbs_pr_debug(1, "DNLD_CMD:: Before download, size of cmd = %d\n",
+              cmdptr->size);
+
+       cmdsize = cmdptr->size;
+
+       command = cpu_to_le16(cmdptr->command);
+
+       cmdnode->cmdwaitqwoken = 0;
+       cmdsize = cpu_to_le16(cmdsize);
+
+       ret = libertas_sbi_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
+
+       if (ret != 0) {
+               lbs_pr_debug(1, "DNLD_CMD: Host to Card failed\n");
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
+               adapter->cur_cmd = NULL;
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               ret = -1;
+               goto done;
+       }
+
+       lbs_pr_debug(1, "DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
+       lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
+
+       /* Setup the timer after transmit command */
+       if (command == cmd_802_11_scan
+           || command == cmd_802_11_authenticate
+           || command == cmd_802_11_associate)
+               mod_timer(&adapter->command_timer, jiffies + (10*HZ));
+       else
+               mod_timer(&adapter->command_timer, jiffies + (5*HZ));
+
+       ret = 0;
+
+      done:
+       LEAVE();
+       return ret;
+}
+
+static int wlan_cmd_mac_control(wlan_private * priv,
+                               struct cmd_ds_command *cmd)
+{
+       struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
+
+       ENTER();
+
+       cmd->command = cpu_to_le16(cmd_mac_control);
+       cmd->size =
+           cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
+       mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
+
+       lbs_pr_debug(1, "wlan_cmd_mac_control(): action=0x%X size=%d\n",
+              mac->action, cmd->size);
+
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  This function inserts command node to cmdfreeq
+ *  after cleans it. Requires adapter->driver_lock held.
+ */
+void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
+{
+       wlan_adapter *adapter = priv->adapter;
+
+       if (!ptempcmd)
+               goto done;
+
+       cleanup_cmdnode(ptempcmd);
+       list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
+done:
+       return;
+}
+
+void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&priv->adapter->driver_lock, flags);
+       __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
+       spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
+}
+
+int libertas_set_radio_control(wlan_private * priv)
+{
+       int ret = 0;
+
+       ENTER();
+
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_802_11_radio_control,
+                                   cmd_act_set,
+                                   cmd_option_waitforrsp, 0, NULL);
+
+       lbs_pr_debug(1, "RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
+              priv->adapter->radioon, priv->adapter->preamble);
+
+       LEAVE();
+       return ret;
+}
+
+int libertas_set_mac_packet_filter(wlan_private * priv)
+{
+       int ret = 0;
+
+       ENTER();
+
+       lbs_pr_debug(1, "libertas_set_mac_packet_filter value = %x\n",
+              priv->adapter->currentpacketfilter);
+
+       /* Send MAC control command to station */
+       ret = libertas_prepare_and_send_command(priv,
+                                   cmd_mac_control, 0, 0, 0, NULL);
+
+       LEAVE();
+       return ret;
+}
+
+/**
+ *  @brief This function prepare the command before send to firmware.
+ *
+ *  @param priv                A pointer to wlan_private structure
+ *  @param cmd_no      command number
+ *  @param cmd_action  command action: GET or SET
+ *  @param wait_option wait option: wait response or not
+ *  @param cmd_oid     cmd oid: treated as sub command
+ *  @param pdata_buf   A pointer to informaion buffer
+ *  @return            0 or -1
+ */
+int libertas_prepare_and_send_command(wlan_private * priv,
+                         u16 cmd_no,
+                         u16 cmd_action,
+                         u16 wait_option, u32 cmd_oid, void *pdata_buf)
+{
+       int ret = 0;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *cmdnode;
+       struct cmd_ds_command *cmdptr;
+       unsigned long flags;
+
+       ENTER();
+
+       if (!adapter) {
+               lbs_pr_debug(1, "PREP_CMD: adapter is Null\n");
+               ret = -1;
+               goto done;
+       }
+
+       if (adapter->surpriseremoved) {
+               lbs_pr_debug(1, "PREP_CMD: Card is Removed\n");
+               ret = -1;
+               goto done;
+       }
+
+       cmdnode = libertas_get_free_cmd_ctrl_node(priv);
+
+       if (cmdnode == NULL) {
+               lbs_pr_debug(1, "PREP_CMD: No free cmdnode\n");
+
+               /* Wake up main thread to execute next command */
+               wake_up_interruptible(&priv->mainthread.waitq);
+               ret = -1;
+               goto done;
+       }
+
+       libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
+
+       cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
+
+       lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr =0x%x, command=0x%X\n",
+              (u32) cmdptr, cmd_no);
+
+       if (!cmdptr) {
+               lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
+               libertas_cleanup_and_insert_cmd(priv, cmdnode);
+               ret = -1;
+               goto done;
+       }
+
+       /* Set sequence number, command and INT option */
+       adapter->seqnum++;
+       cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
+
+       cmdptr->command = cmd_no;
+       cmdptr->result = 0;
+
+       switch (cmd_no) {
+       case cmd_get_hw_spec:
+               ret = wlan_cmd_hw_spec(priv, cmdptr);
+               break;
+       case cmd_802_11_ps_mode:
+               ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_scan:
+               ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
+               break;
+
+       case cmd_mac_control:
+               ret = wlan_cmd_mac_control(priv, cmdptr);
+               break;
+
+       case cmd_802_11_associate:
+       case cmd_802_11_reassociate:
+               ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
+               break;
+
+       case cmd_802_11_deauthenticate:
+               ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
+               break;
+
+       case cmd_802_11_set_wep:
+               ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_ad_hoc_start:
+               ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
+               break;
+       case cmd_code_dnld:
+               break;
+
+       case cmd_802_11_reset:
+               ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_get_log:
+               ret = wlan_cmd_802_11_get_log(priv, cmdptr);
+               break;
+
+       case cmd_802_11_authenticate:
+               ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
+               break;
+
+       case cmd_802_11_get_stat:
+               ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
+               break;
+
+       case cmd_802_11_snmp_mib:
+               ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
+                                              cmd_action, cmd_oid, pdata_buf);
+               break;
+
+       case cmd_mac_reg_access:
+       case cmd_bbp_reg_access:
+       case cmd_rf_reg_access:
+               ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_rf_channel:
+               ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
+                                                cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_rf_tx_power:
+               ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
+                                                 cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_radio_control:
+               ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_rf_antenna:
+               ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
+                                                cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_data_rate:
+               ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
+               break;
+       case cmd_802_11_rate_adapt_rateset:
+               ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
+                                                        cmdptr, cmd_action);
+               break;
+
+       case cmd_mac_multicast_adr:
+               ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_ad_hoc_join:
+               ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
+               break;
+
+       case cmd_802_11_rssi:
+               ret = wlan_cmd_802_11_rssi(priv, cmdptr);
+               break;
+
+       case cmd_802_11_ad_hoc_stop:
+               ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
+               break;
+
+       case cmd_802_11_enable_rsn:
+               ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_key_material:
+               ret = wlan_cmd_802_11_key_material(priv, cmdptr,
+                                                  cmd_action, cmd_oid,
+                                                  pdata_buf);
+               break;
+
+       case cmd_802_11_pairwise_tsc:
+               break;
+       case cmd_802_11_group_tsc:
+               break;
+
+       case cmd_802_11_mac_address:
+               ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
+               break;
+
+       case cmd_802_11_eeprom_access:
+               ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
+                                                   cmd_action, pdata_buf);
+               break;
+
+       case cmd_802_11_set_afc:
+       case cmd_802_11_get_afc:
+
+               cmdptr->command = cpu_to_le16(cmd_no);
+               cmdptr->size =
+                   cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
+                                    S_DS_GEN);
+
+               memmove(&cmdptr->params.afc,
+                       pdata_buf, sizeof(struct cmd_ds_802_11_afc));
+
+               ret = 0;
+               goto done;
+
+       case cmd_802_11d_domain_info:
+               ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
+                                                  cmd_no, cmd_action);
+               break;
+
+       case cmd_802_11_sleep_params:
+               ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
+               break;
+       case cmd_802_11_inactivity_timeout:
+               ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
+                                                        cmd_action, pdata_buf);
+               libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
+               break;
+
+       case cmd_802_11_tpc_cfg:
+               cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
+               cmdptr->size =
+                   cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
+                                    S_DS_GEN);
+
+               memmove(&cmdptr->params.tpccfg,
+                       pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
+
+               ret = 0;
+               break;
+       case cmd_802_11_led_gpio_ctrl:
+               {
+                       struct mrvlietypes_ledgpio *gpio =
+                           (struct mrvlietypes_ledgpio*)
+                           cmdptr->params.ledgpio.data;
+
+                       memmove(&cmdptr->params.ledgpio,
+                               pdata_buf,
+                               sizeof(struct cmd_ds_802_11_led_ctrl));
+
+                       cmdptr->command =
+                           cpu_to_le16(cmd_802_11_led_gpio_ctrl);
+
+#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
+                       cmdptr->size =
+                           cpu_to_le16(gpio->header.len + S_DS_GEN +
+                                            ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
+                       gpio->header.len = cpu_to_le16(gpio->header.len);
+
+                       ret = 0;
+                       break;
+               }
+       case cmd_802_11_pwr_cfg:
+               cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
+               cmdptr->size =
+                   cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
+                                    S_DS_GEN);
+               memmove(&cmdptr->params.pwrcfg, pdata_buf,
+                       sizeof(struct cmd_ds_802_11_pwr_cfg));
+
+               ret = 0;
+               break;
+       case cmd_bt_access:
+               ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
+               break;
+
+       case cmd_fwt_access:
+               ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
+               break;
+
+       case cmd_mesh_access:
+               ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
+               break;
+
+       case cmd_get_tsf:
+               cmdptr->command = cpu_to_le16(cmd_get_tsf);
+               cmdptr->size =
+                   cpu_to_le16(sizeof(struct cmd_ds_get_tsf)
+                                    + S_DS_GEN);
+               ret = 0;
+               break;
+       case cmd_802_11_tx_rate_query:
+               cmdptr->command =
+                   cpu_to_le16(cmd_802_11_tx_rate_query);
+               cmdptr->size =
+                   cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
+                                    S_DS_GEN);
+               adapter->txrate = 0;
+               ret = 0;
+               break;
+       default:
+               lbs_pr_debug(1, "PREP_CMD: unknown command- %#x\n", cmd_no);
+               ret = -1;
+               break;
+       }
+
+       /* return error, since the command preparation failed */
+       if (ret != 0) {
+               lbs_pr_debug(1, "PREP_CMD: command preparation failed\n");
+               libertas_cleanup_and_insert_cmd(priv, cmdnode);
+               ret = -1;
+               goto done;
+       }
+
+       cmdnode->cmdwaitqwoken = 0;
+
+       libertas_queue_cmd(adapter, cmdnode, 1);
+       adapter->nr_cmd_pending++;
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       if (wait_option & cmd_option_waitforrsp) {
+               lbs_pr_debug(1, "PREP_CMD: Wait for CMD response\n");
+               might_sleep();
+               wait_event_interruptible(cmdnode->cmdwait_q,
+                                        cmdnode->cmdwaitqwoken);
+       }
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+       if (adapter->cur_cmd_retcode) {
+               lbs_pr_debug(1, "PREP_CMD: command failed with return code=%d\n",
+                      adapter->cur_cmd_retcode);
+               adapter->cur_cmd_retcode = 0;
+               ret = -1;
+       }
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+done:
+       LEAVE();
+       return ret;
+}
+
+/**
+ *  @brief This function allocates the command buffer and link
+ *  it to command free queue.
+ *
+ *  @param priv                A pointer to wlan_private structure
+ *  @return            0 or -1
+ */
+int libertas_allocate_cmd_buffer(wlan_private * priv)
+{
+       int ret = 0;
+       u32 ulbufsize;
+       u32 i;
+       struct cmd_ctrl_node *tempcmd_array;
+       u8 *ptempvirtualaddr;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       /* Allocate and initialize cmdCtrlNode */
+       ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
+
+       if (!(tempcmd_array = kmalloc(ulbufsize, GFP_KERNEL))) {
+               lbs_pr_debug(1,
+                      "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
+               ret = -1;
+               goto done;
+       }
+
+       adapter->cmd_array = tempcmd_array;
+       memset(adapter->cmd_array, 0, ulbufsize);
+
+       /* Allocate and initialize command buffers */
+       ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
+       for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
+               if (!(ptempvirtualaddr = kmalloc(ulbufsize, GFP_KERNEL))) {
+                       lbs_pr_debug(1,
+                              "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
+                       ret = -1;
+                       goto done;
+               }
+
+               memset(ptempvirtualaddr, 0, ulbufsize);
+
+               /* Update command buffer virtual */
+               tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
+       }
+
+       for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
+               init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
+               libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
+       }
+
+       ret = 0;
+      done:
+       LEAVE();
+       return ret;
+}
+
+/**
+ *  @brief This function frees the command buffer.
+ *
+ *  @param priv                A pointer to wlan_private structure
+ *  @return            0 or -1
+ */
+int libertas_free_cmd_buffer(wlan_private * priv)
+{
+       u32 ulbufsize;
+       unsigned int i;
+       struct cmd_ctrl_node *tempcmd_array;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       /* need to check if cmd array is allocated or not */
+       if (adapter->cmd_array == NULL) {
+               lbs_pr_debug(1, "FREE_CMD_BUF: cmd_array is Null\n");
+               goto done;
+       }
+
+       tempcmd_array = adapter->cmd_array;
+
+       /* Release shared memory buffers */
+       ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
+       for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
+               if (tempcmd_array[i].bufvirtualaddr) {
+                       lbs_pr_debug(1, "Free all the array\n");
+                       kfree(tempcmd_array[i].bufvirtualaddr);
+                       tempcmd_array[i].bufvirtualaddr = NULL;
+               }
+       }
+
+       /* Release cmd_ctrl_node */
+       if (adapter->cmd_array) {
+               lbs_pr_debug(1, "Free cmd_array\n");
+               kfree(adapter->cmd_array);
+               adapter->cmd_array = NULL;
+       }
+
+done:
+       LEAVE();
+       return 0;
+}
+
+/**
+ *  @brief This function gets a free command node if available in
+ *  command free queue.
+ *
+ *  @param priv                A pointer to wlan_private structure
+ *  @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
+ */
+struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
+{
+       struct cmd_ctrl_node *tempnode;
+       wlan_adapter *adapter = priv->adapter;
+       unsigned long flags;
+
+       if (!adapter)
+               return NULL;
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+
+       if (!list_empty(&adapter->cmdfreeq)) {
+               tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
+               list_del((struct list_head *)tempnode);
+       } else {
+               lbs_pr_debug(1, "GET_CMD_NODE: cmd_ctrl_node is not available\n");
+               tempnode = NULL;
+       }
+
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       if (tempnode) {
+               lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
+               lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
+                      tempnode);
+               cleanup_cmdnode(tempnode);
+       }
+
+       return tempnode;
+}
+
+/**
+ *  @brief This function cleans command node.
+ *
+ *  @param ptempnode   A pointer to cmdCtrlNode structure
+ *  @return            n/a
+ */
+static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
+{
+       if (!ptempnode)
+               return;
+       ptempnode->cmdwaitqwoken = 1;
+       wake_up_interruptible(&ptempnode->cmdwait_q);
+       ptempnode->status = 0;
+       ptempnode->cmd_oid = (u32) 0;
+       ptempnode->wait_option = 0;
+       ptempnode->pdata_buf = NULL;
+
+       if (ptempnode->bufvirtualaddr != NULL)
+               memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
+       return;
+}
+
+/**
+ *  @brief This function initializes the command node.
+ *
+ *  @param priv                A pointer to wlan_private structure
+ *  @param ptempnode   A pointer to cmd_ctrl_node structure
+ *  @param cmd_oid     cmd oid: treated as sub command
+ *  @param wait_option wait option: wait response or not
+ *  @param pdata_buf   A pointer to informaion buffer
+ *  @return            0 or -1
+ */
+void libertas_set_cmd_ctrl_node(wlan_private * priv,
+                   struct cmd_ctrl_node *ptempnode,
+                   u32 cmd_oid, u16 wait_option, void *pdata_buf)
+{
+       ENTER();
+
+       if (!ptempnode)
+               return;
+
+       ptempnode->cmd_oid = cmd_oid;
+       ptempnode->wait_option = wait_option;
+       ptempnode->pdata_buf = pdata_buf;
+
+       LEAVE();
+}
+
+/**
+ *  @brief This function executes next command in command
+ *  pending queue. It will put fimware back to PS mode
+ *  if applicable.
+ *
+ *  @param priv     A pointer to wlan_private structure
+ *  @return       0 or -1
+ */
+int libertas_execute_next_command(wlan_private * priv)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *cmdnode = NULL;
+       struct cmd_ds_command *cmdptr;
+       unsigned long flags;
+       int ret = 0;
+
+       lbs_pr_debug(1, "libertas_execute_next_command\n");
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+
+       if (adapter->cur_cmd) {
+               lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               ret = -1;
+               goto done;
+       }
+
+       if (!list_empty(&adapter->cmdpendingq)) {
+               cmdnode = (struct cmd_ctrl_node *)
+                   adapter->cmdpendingq.next;
+       }
+
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       if (cmdnode) {
+               lbs_pr_debug(1,
+                      "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
+               cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
+
+               if (is_command_allowed_in_ps(cmdptr->command)) {
+                       if ((adapter->psstate == PS_STATE_SLEEP)
+                           || (adapter->psstate == PS_STATE_PRE_SLEEP)
+                           ) {
+                               lbs_pr_debug(1,
+                                      "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
+                                      cmdptr->command, adapter->psstate);
+                               ret = -1;
+                               goto done;
+                       }
+                       lbs_pr_debug(1, "EXEC_NEXT_CMD: OK to send command "
+                              "0x%x in psstate %d\n",
+                              cmdptr->command, adapter->psstate);
+               } else if (adapter->psstate != PS_STATE_FULL_POWER) {
+                       /*
+                        * 1. Non-PS command:
+                        * Queue it. set needtowakeup to TRUE if current state
+                        * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
+                        * 2. PS command but not Exit_PS:
+                        * Ignore it.
+                        * 3. PS command Exit_PS:
+                        * Set needtowakeup to TRUE if current state is SLEEP,
+                        * otherwise send this command down to firmware
+                        * immediately.
+                        */
+                       if (cmdptr->command !=
+                           cpu_to_le16(cmd_802_11_ps_mode)) {
+                               /*  Prepare to send Exit PS,
+                                *  this non PS command will be sent later */
+                               if ((adapter->psstate == PS_STATE_SLEEP)
+                                   || (adapter->psstate == PS_STATE_PRE_SLEEP)
+                                   ) {
+                                       /* w/ new scheme, it will not reach here.
+                                          since it is blocked in main_thread. */
+                                       adapter->needtowakeup = 1;
+                               } else
+                                       libertas_ps_wakeup(priv, 0);
+
+                               ret = 0;
+                               goto done;
+                       } else {
+                               /*
+                                * PS command. Ignore it if it is not Exit_PS.
+                                * otherwise send it down immediately.
+                                */
+                               struct cmd_ds_802_11_ps_mode *psm =
+                                   &cmdptr->params.psmode;
+
+                               lbs_pr_debug(1,
+                                      "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
+                                      psm->action);
+                               if (psm->action !=
+                                   cpu_to_le16(cmd_subcmd_exit_ps)) {
+                                       lbs_pr_debug(1,
+                                              "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
+                                       list_del((struct list_head *)cmdnode);
+                                       libertas_cleanup_and_insert_cmd(priv, cmdnode);
+
+                                       ret = 0;
+                                       goto done;
+                               }
+
+                               if ((adapter->psstate == PS_STATE_SLEEP)
+                                   || (adapter->psstate == PS_STATE_PRE_SLEEP)
+                                   ) {
+                                       lbs_pr_debug(1,
+                                              "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
+                                       list_del((struct list_head *)cmdnode);
+                                       libertas_cleanup_and_insert_cmd(priv, cmdnode);
+                                       adapter->needtowakeup = 1;
+
+                                       ret = 0;
+                                       goto done;
+                               }
+
+                               lbs_pr_debug(1,
+                                      "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
+                       }
+               }
+               list_del((struct list_head *)cmdnode);
+               lbs_pr_debug(1, "EXEC_NEXT_CMD: Sending 0x%04X command\n",
+                      cmdptr->command);
+               DownloadcommandToStation(priv, cmdnode);
+       } else {
+               /*
+                * check if in power save mode, if yes, put the device back
+                * to PS mode
+                */
+               if ((adapter->psmode != wlan802_11powermodecam) &&
+                   (adapter->psstate == PS_STATE_FULL_POWER) &&
+                   (adapter->connect_status == libertas_connected)) {
+                       if (adapter->secinfo.WPAenabled
+                           || adapter->secinfo.WPA2enabled) {
+                               /* check for valid WPA group keys */
+                               if (adapter->wpa_mcast_key.len
+                                   || adapter->wpa_unicast_key.len) {
+                                       lbs_pr_debug(1,
+                                              "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
+                                              " go back to PS_SLEEP");
+                                       libertas_ps_sleep(priv, 0);
+                               }
+                       } else {
+                               lbs_pr_debug(1,
+                                      "EXEC_NEXT_CMD: command PendQ is empty,"
+                                      " go back to PS_SLEEP");
+                               libertas_ps_sleep(priv, 0);
+                       }
+               }
+       }
+
+       ret = 0;
+done:
+       return ret;
+}
+
+void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
+{
+       union iwreq_data iwrq;
+       u8 buf[50];
+
+       ENTER();
+
+       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_pr_debug(1, "Event Indication string = %s\n",
+              (char *)buf);
+       lbs_pr_debug(1, "Event Indication String length = %d\n", iwrq.data.length);
+
+       lbs_pr_debug(1, "Sending wireless event IWEVCUSTOM for %s\n", str);
+       wireless_send_event(priv->wlan_dev.netdev, IWEVCUSTOM, &iwrq, buf);
+
+       LEAVE();
+       return;
+}
+
+static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
+{
+       unsigned long flags;
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       ENTER();
+
+       lbs_pr_debug(1, "SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
+              size);
+
+       lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
+
+       ret = libertas_sbi_host_to_card(priv, MVMS_CMD, cmdptr, size);
+       priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+       if (adapter->intcounter || adapter->currenttxskb)
+               lbs_pr_debug(1, "SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
+                      adapter->intcounter, adapter->currenttxskb);
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       if (ret) {
+               lbs_pr_alert(
+                      "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
+       } else {
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               if (!adapter->intcounter) {
+                       adapter->psstate = PS_STATE_SLEEP;
+               } else {
+                       lbs_pr_debug(1, "SEND_SLEEPC_CMD: After sent,IntC=%d\n",
+                              adapter->intcounter);
+               }
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+               lbs_pr_debug(1, "SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
+               lbs_pr_debug(1, "+");
+       }
+
+       LEAVE();
+       return ret;
+}
+
+void libertas_ps_sleep(wlan_private * priv, int wait_option)
+{
+
+       ENTER();
+
+       /*
+        * PS is currently supported only in Infrastructure mode
+        * Remove this check if it is to be supported in IBSS mode also
+        */
+
+       libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
+                             cmd_subcmd_enter_ps, wait_option, 0, NULL);
+
+       LEAVE();
+       return;
+}
+
+/**
+ *  @brief This function sends Eixt_PS command to firmware.
+ *
+ *  @param priv        A pointer to wlan_private structure
+ *  @param wait_option wait response or not
+ *  @return            n/a
+ */
+void libertas_ps_wakeup(wlan_private * priv, int wait_option)
+{
+       enum WLAN_802_11_POWER_MODE Localpsmode;
+
+       ENTER();
+
+       Localpsmode = wlan802_11powermodecam;
+
+       lbs_pr_debug(1, "Exit_PS: Localpsmode = %d\n", Localpsmode);
+
+       libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
+                             cmd_subcmd_exit_ps,
+                             wait_option, 0, &Localpsmode);
+
+       LEAVE();
+       return;
+}
+
+/**
+ *  @brief This function checks condition and prepares to
+ *  send sleep confirm command to firmware if ok.
+ *
+ *  @param priv        A pointer to wlan_private structure
+ *  @param psmode      Power Saving mode
+ *  @return            n/a
+ */
+void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
+{
+       unsigned long flags =0;
+       wlan_adapter *adapter = priv->adapter;
+       u8 allowed = 1;
+
+       ENTER();
+
+       if (priv->wlan_dev.dnld_sent) {
+               allowed = 0;
+               lbs_pr_debug(1, "D");
+       }
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+       if (adapter->cur_cmd) {
+               allowed = 0;
+               lbs_pr_debug(1, "C");
+       }
+       if (adapter->intcounter > 0) {
+               allowed = 0;
+               lbs_pr_debug(1, "I%d", adapter->intcounter);
+       }
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       if (allowed) {
+               lbs_pr_debug(1, "Sending libertas_ps_confirm_sleep\n");
+               sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
+                                sizeof(struct PS_CMD_ConfirmSleep));
+       } else {
+               lbs_pr_debug(1, "Sleep Confirm has been delayed\n");
+       }
+
+       LEAVE();
+}
diff --git a/drivers/net/wireless/libertas/cmdresp.c b/drivers/net/wireless/libertas/cmdresp.c
new file mode 100644 (file)
index 0000000..cdb012c
--- /dev/null
@@ -0,0 +1,1031 @@
+/**
+  * This file contains the handling of command
+  * responses as well as events generated by firmware.
+  */
+#include <linux/delay.h>
+#include <linux/if_arp.h>
+#include <linux/netdevice.h>
+
+#include <net/iw_handler.h>
+
+#include "host.h"
+#include "sbi.h"
+#include "decl.h"
+#include "defs.h"
+#include "dev.h"
+#include "join.h"
+#include "wext.h"
+
+/**
+ *  @brief This function handles disconnect event. it
+ *  reports disconnect to upper layer, clean tx/rx packets,
+ *  reset link state etc.
+ *
+ *  @param priv    A pointer to wlan_private structure
+ *  @return       n/a
+ */
+void libertas_mac_event_disconnected(wlan_private * priv)
+{
+       wlan_adapter *adapter = priv->adapter;
+       union iwreq_data wrqu;
+
+       if (adapter->connect_status != libertas_connected)
+               return;
+
+       lbs_pr_debug(1, "Handles disconnect event.\n");
+
+       memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
+       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+
+       /*
+        * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
+        * It causes problem in the Supplicant
+        */
+
+       msleep_interruptible(1000);
+       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
+
+       /* Free Tx and Rx packets */
+       kfree_skb(priv->adapter->currenttxskb);
+       priv->adapter->currenttxskb = NULL;
+
+       /* report disconnect to upper layer */
+       netif_stop_queue(priv->wlan_dev.netdev);
+       netif_carrier_off(priv->wlan_dev.netdev);
+
+       /* reset SNR/NF/RSSI values */
+       memset(adapter->SNR, 0x00, sizeof(adapter->SNR));
+       memset(adapter->NF, 0x00, sizeof(adapter->NF));
+       memset(adapter->RSSI, 0x00, sizeof(adapter->RSSI));
+       memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
+       memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
+       adapter->nextSNRNF = 0;
+       adapter->numSNRNF = 0;
+       adapter->rxpd_rate = 0;
+       lbs_pr_debug(1, "Current SSID=%s, ssid length=%u\n",
+              adapter->curbssparams.ssid.ssid,
+              adapter->curbssparams.ssid.ssidlength);
+       lbs_pr_debug(1, "Previous SSID=%s, ssid length=%u\n",
+              adapter->previousssid.ssid, adapter->previousssid.ssidlength);
+
+       /* reset internal flags */
+       adapter->secinfo.WPAenabled = 0;
+       adapter->secinfo.WPA2enabled = 0;
+       adapter->wpa_ie_len = 0;
+       adapter->secinfo.auth1xalg = WLAN_1X_AUTH_ALG_NONE;
+       adapter->secinfo.Encryptionmode = CIPHER_NONE;
+
+       adapter->connect_status = libertas_disconnected;
+
+       /*
+        * memorize the previous SSID and BSSID
+        * it could be used for re-assoc
+        */
+       memcpy(&adapter->previousssid,
+              &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID));
+       memcpy(adapter->previousbssid,
+              adapter->curbssparams.bssid, ETH_ALEN);
+
+       /* need to erase the current SSID and BSSID info */
+       adapter->pattemptedbssdesc = NULL;
+       memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
+
+       if (adapter->psstate != PS_STATE_FULL_POWER) {
+               /* make firmware to exit PS mode */
+               lbs_pr_debug(1, "Disconnected, so exit PS mode.\n");
+               libertas_ps_wakeup(priv, 0);
+       }
+}
+
+/**
+ *  @brief This function handles MIC failure event.
+ *
+ *  @param priv    A pointer to wlan_private structure
+ *  @para  event   the event id
+ *  @return       n/a
+ */
+static void handle_mic_failureevent(wlan_private * priv, u32 event)
+{
+       char buf[50];
+
+       memset(buf, 0, sizeof(buf));
+
+       sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
+
+       if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) {
+               strcat(buf, "unicast ");
+       } else {
+               strcat(buf, "multicast ");
+       }
+
+       libertas_send_iwevcustom_event(priv, buf);
+}
+
+static int wlan_ret_reg_access(wlan_private * priv,
+                              u16 type, struct cmd_ds_command *resp)
+{
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       switch (type) {
+       case cmd_ret_mac_reg_access:
+               {
+                       struct cmd_ds_mac_reg_access *reg;
+
+                       reg =
+                           (struct cmd_ds_mac_reg_access *)&resp->params.
+                           macreg;
+
+                       adapter->offsetvalue.offset = reg->offset;
+                       adapter->offsetvalue.value = reg->value;
+                       break;
+               }
+
+       case cmd_ret_bbp_reg_access:
+               {
+                       struct cmd_ds_bbp_reg_access *reg;
+                       reg =
+                           (struct cmd_ds_bbp_reg_access *)&resp->params.
+                           bbpreg;
+
+                       adapter->offsetvalue.offset = reg->offset;
+                       adapter->offsetvalue.value = reg->value;
+                       break;
+               }
+
+       case cmd_ret_rf_reg_access:
+               {
+                       struct cmd_ds_rf_reg_access *reg;
+                       reg =
+                           (struct cmd_ds_rf_reg_access *)&resp->params.
+                           rfreg;
+
+                       adapter->offsetvalue.offset = reg->offset;
+                       adapter->offsetvalue.value = reg->value;
+                       break;
+               }
+
+       default:
+               LEAVE();
+               return -1;
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_get_hw_spec(wlan_private * priv,
+                               struct cmd_ds_command *resp)
+{
+       u32 i;
+       struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec;
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+
+       ENTER();
+
+       adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo);
+
+       adapter->fwreleasenumber = hwspec->fwreleasenumber;
+
+       lbs_pr_debug(1, "GET_HW_SPEC: FWReleaseVersion- 0x%X\n",
+              adapter->fwreleasenumber);
+       lbs_pr_debug(1, "GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n",
+              hwspec->permanentaddr[0], hwspec->permanentaddr[1],
+              hwspec->permanentaddr[2], hwspec->permanentaddr[3],
+              hwspec->permanentaddr[4], hwspec->permanentaddr[5]);
+       lbs_pr_debug(1, "GET_HW_SPEC: hwifversion=0x%X  version=0x%X\n",
+              hwspec->hwifversion, hwspec->version);
+
+       adapter->regioncode = le16_to_cpu(hwspec->regioncode);
+
+       for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
+               /* use the region code to search for the index */
+               if (adapter->regioncode == libertas_region_code_to_index[i]) {
+                       adapter->regiontableindex = (u16) i;
+                       break;
+               }
+       }
+
+       /* if it's unidentified region code, use the default (USA) */
+       if (i >= MRVDRV_MAX_REGION_CODE) {
+               adapter->regioncode = 0x10;
+               adapter->regiontableindex = 0;
+               lbs_pr_info(
+                      "unidentified region code, use the default (USA)\n");
+       }
+
+       if (adapter->current_addr[0] == 0xff) {
+               memmove(adapter->current_addr, hwspec->permanentaddr,
+                       ETH_ALEN);
+       }
+
+       memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN);
+       memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
+
+       if (libertas_set_regiontable(priv, adapter->regioncode, 0)) {
+               ret = -1;
+               goto done;
+       }
+
+       if (libertas_set_universaltable(priv, 0)) {
+               ret = -1;
+               goto done;
+       }
+
+      done:
+       LEAVE();
+       return ret;
+}
+
+static int wlan_ret_802_11_sleep_params(wlan_private * priv,
+                                       struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       lbs_pr_debug(1, "error=%x offset=%x stabletime=%x calcontrol=%x\n"
+              " extsleepclk=%x\n", sp->error, sp->offset,
+              sp->stabletime, sp->calcontrol, sp->externalsleepclk);
+       adapter->sp.sp_error = le16_to_cpu(sp->error);
+       adapter->sp.sp_offset = le16_to_cpu(sp->offset);
+       adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime);
+       adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol);
+       adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk);
+       adapter->sp.sp_reserved = le16_to_cpu(sp->reserved);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_stat(wlan_private * priv,
+                               struct cmd_ds_command *resp)
+{
+/*     currently adapter->wlan802_11Stat is unused
+
+       struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
+       wlan_adapter *adapter = priv->adapter;
+
+       // TODO Convert it to Big endian befor copy
+       memcpy(&adapter->wlan802_11Stat,
+              p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
+*/
+       return 0;
+}
+
+static int wlan_ret_802_11_snmp_mib(wlan_private * priv,
+                                   struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
+       u16 oid = le16_to_cpu(smib->oid);
+       u16 querytype = le16_to_cpu(smib->querytype);
+
+       ENTER();
+
+       lbs_pr_debug(1, "SNMP_RESP: value of the oid = %x, querytype=%x\n", oid,
+              querytype);
+       lbs_pr_debug(1, "SNMP_RESP: Buf size  = %x\n",
+              le16_to_cpu(smib->bufsize));
+
+       if (querytype == cmd_act_get) {
+               switch (oid) {
+               case fragthresh_i:
+                       priv->adapter->fragthsd =
+                           le16_to_cpu(*
+                                            ((unsigned short *)(smib->value)));
+                       lbs_pr_debug(1, "SNMP_RESP: fragthsd =%u\n",
+                              priv->adapter->fragthsd);
+                       break;
+               case rtsthresh_i:
+                       priv->adapter->rtsthsd =
+                           le16_to_cpu(*
+                                            ((unsigned short *)(smib->value)));
+                       lbs_pr_debug(1, "SNMP_RESP: rtsthsd =%u\n",
+                              priv->adapter->rtsthsd);
+                       break;
+               case short_retrylim_i:
+                       priv->adapter->txretrycount =
+                           le16_to_cpu(*
+                                            ((unsigned short *)(smib->value)));
+                       lbs_pr_debug(1, "SNMP_RESP: txretrycount =%u\n",
+                              priv->adapter->rtsthsd);
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_key_material(wlan_private * priv,
+                                       struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_key_material *pkeymaterial =
+           &resp->params.keymaterial;
+       wlan_adapter *adapter = priv->adapter;
+       u16 action = le16_to_cpu(pkeymaterial->action);
+
+       ENTER();
+
+       /* Copy the returned key to driver private data */
+       if (action == cmd_act_get) {
+               u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet;
+               u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size));
+
+               while (buf_ptr < resp_end) {
+                       struct MrvlIEtype_keyParamSet * pkeyparamset =
+                           (struct MrvlIEtype_keyParamSet *) buf_ptr;
+                       struct WLAN_802_11_KEY * pkey;
+                       u16 key_info = le16_to_cpu(pkeyparamset->keyinfo);
+                       u16 param_set_len = le16_to_cpu(pkeyparamset->length);
+                       u8 * end;
+                       u16 key_len = le16_to_cpu(pkeyparamset->keylen);
+
+                       end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type)
+                                                 + sizeof (pkeyparamset->length)
+                                                 + param_set_len;
+                       /* Make sure we don't access past the end of the IEs */
+                       if (end > resp_end)
+                               break;
+
+                       if (key_info & KEY_INFO_WPA_UNICAST)
+                               pkey = &adapter->wpa_unicast_key;
+                       else if (key_info & KEY_INFO_WPA_MCAST)
+                               pkey = &adapter->wpa_mcast_key;
+                       else
+                               break;
+
+                       /* Copy returned key into driver */
+                       memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
+                       if (key_len > sizeof(pkey->key))
+                               break;
+                       pkey->type = le16_to_cpu(pkeyparamset->keytypeid);
+                       pkey->flags = le16_to_cpu(pkeyparamset->keyinfo);
+                       pkey->len = le16_to_cpu(pkeyparamset->keylen);
+                       memcpy(pkey->key, pkeyparamset->key, pkey->len);
+
+                       buf_ptr = end + 1;
+               }
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_mac_address(wlan_private * priv,
+                                      struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_rf_tx_power(wlan_private * priv,
+                                      struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel);
+
+       lbs_pr_debug(1, "Current TxPower Level = %d\n", adapter->txpowerlevel);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_rf_antenna(wlan_private * priv,
+                                     struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant;
+       wlan_adapter *adapter = priv->adapter;
+       u16 action = le16_to_cpu(pAntenna->action);
+
+       if (action == cmd_act_get_rx)
+               adapter->rxantennamode =
+                   le16_to_cpu(pAntenna->antennamode);
+
+       if (action == cmd_act_get_tx)
+               adapter->txantennamode =
+                   le16_to_cpu(pAntenna->antennamode);
+
+       lbs_pr_debug(1, "RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n",
+              action, le16_to_cpu(pAntenna->antennamode));
+
+       return 0;
+}
+
+static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv,
+                                             struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_rate_adapt_rateset *rates =
+           &resp->params.rateset;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       if (rates->action == cmd_act_get) {
+               adapter->enablehwauto = rates->enablehwauto;
+               adapter->ratebitmap = rates->bitmap;
+       }
+
+       LEAVE();
+
+       return 0;
+}
+
+static int wlan_ret_802_11_data_rate(wlan_private * priv,
+                                    struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
+       wlan_adapter *adapter = priv->adapter;
+       u8 dot11datarate;
+
+       ENTER();
+
+       lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
+               (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
+
+       dot11datarate = pdatarate->datarate[0];
+       if (pdatarate->action == cmd_act_get_tx_rate) {
+               memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
+                      sizeof(adapter->libertas_supported_rates));
+       }
+       adapter->datarate = libertas_index_to_data_rate(dot11datarate);
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_rf_channel(wlan_private * priv,
+                                     struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_rf_channel *rfchannel =
+           &resp->params.rfchannel;
+       wlan_adapter *adapter = priv->adapter;
+       u16 action = le16_to_cpu(rfchannel->action);
+       u16 newchannel = le16_to_cpu(rfchannel->currentchannel);
+
+       ENTER();
+
+       if (action == cmd_opt_802_11_rf_channel_get
+           && adapter->curbssparams.channel != newchannel) {
+               lbs_pr_debug(1, "channel Switch: %d to %d\n",
+                      adapter->curbssparams.channel, newchannel);
+
+               /* Update the channel again */
+               adapter->curbssparams.channel = newchannel;
+       }
+
+       LEAVE();
+       return 0;
+}
+
+static int wlan_ret_802_11_rssi(wlan_private * priv,
+                               struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
+       wlan_adapter *adapter = priv->adapter;
+
+       /* store the non average value */
+       adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR);
+       adapter->NF[TYPE_BEACON][TYPE_NOAVG] =
+           le16_to_cpu(rssirsp->noisefloor);
+
+       adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR);
+       adapter->NF[TYPE_BEACON][TYPE_AVG] =
+           le16_to_cpu(rssirsp->avgnoisefloor);
+
+       adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] =
+           CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
+                    adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
+
+       adapter->RSSI[TYPE_BEACON][TYPE_AVG] =
+           CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
+                    adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
+
+       lbs_pr_debug(1, "Beacon RSSI value = 0x%x\n",
+              adapter->RSSI[TYPE_BEACON][TYPE_AVG]);
+
+       return 0;
+}
+
+static int wlan_ret_802_11_eeprom_access(wlan_private * priv,
+                                 struct cmd_ds_command *resp)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct wlan_ioctl_regrdwr *pbuf;
+       pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom;
+
+       lbs_pr_debug(1, "eeprom read len=%x\n",
+              le16_to_cpu(resp->params.rdeeprom.bytecount));
+       if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) {
+               pbuf->NOB = 0;
+               lbs_pr_debug(1, "eeprom read return length is too big\n");
+               return -1;
+       }
+       pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount);
+       if (pbuf->NOB > 0) {
+
+               memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value,
+                      le16_to_cpu(resp->params.rdeeprom.bytecount));
+               lbs_dbg_hex("adapter", (char *)&pbuf->value,
+                       le16_to_cpu(resp->params.rdeeprom.bytecount));
+       }
+       return 0;
+}
+
+static int wlan_ret_get_log(wlan_private * priv,
+                           struct cmd_ds_command *resp)
+{
+       struct cmd_ds_802_11_get_log *logmessage =
+           (struct cmd_ds_802_11_get_log *)&resp->params.glog;
+       wlan_adapter *adapter = priv->adapter;
+
+       ENTER();
+
+       /* TODO Convert it to Big Endian before copy */
+       memcpy(&adapter->logmsg, logmessage,
+              sizeof(struct cmd_ds_802_11_get_log));
+
+       LEAVE();
+       return 0;
+}
+
+static inline int handle_cmd_response(u16 respcmd,
+                                     struct cmd_ds_command *resp,
+                                     wlan_private *priv)
+{
+       int ret = 0;
+       unsigned long flags;
+       wlan_adapter *adapter = priv->adapter;
+
+       switch (respcmd) {
+       case cmd_ret_mac_reg_access:
+       case cmd_ret_bbp_reg_access:
+       case cmd_ret_rf_reg_access:
+               ret = wlan_ret_reg_access(priv, respcmd, resp);
+               break;
+
+       case cmd_ret_hw_spec_info:
+               ret = wlan_ret_get_hw_spec(priv, resp);
+               break;
+
+       case cmd_ret_802_11_scan:
+               ret = libertas_ret_80211_scan(priv, resp);
+               break;
+
+       case cmd_ret_802_11_get_log:
+               ret = wlan_ret_get_log(priv, resp);
+               break;
+
+       case cmd_ret_802_11_associate:
+       case cmd_ret_802_11_reassociate:
+               ret = libertas_ret_80211_associate(priv, resp);
+               break;
+
+       case cmd_ret_802_11_disassociate:
+       case cmd_ret_802_11_deauthenticate:
+               ret = libertas_ret_80211_disassociate(priv, resp);
+               break;
+
+       case cmd_ret_802_11_ad_hoc_start:
+       case cmd_ret_802_11_ad_hoc_join:
+               ret = libertas_ret_80211_ad_hoc_start(priv, resp);
+               break;
+
+       case cmd_ret_802_11_stat:
+               ret = wlan_ret_802_11_stat(priv, resp);
+               break;
+
+       case cmd_ret_802_11_snmp_mib:
+               ret = wlan_ret_802_11_snmp_mib(priv, resp);
+               break;
+
+       case cmd_ret_802_11_rf_tx_power:
+               ret = wlan_ret_802_11_rf_tx_power(priv, resp);
+               break;
+
+       case cmd_ret_802_11_set_afc:
+       case cmd_ret_802_11_get_afc:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               memmove(adapter->cur_cmd->pdata_buf,
+                       &resp->params.afc,
+                       sizeof(struct cmd_ds_802_11_afc));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+               break;
+       case cmd_ret_802_11_rf_antenna:
+               ret = wlan_ret_802_11_rf_antenna(priv, resp);
+               break;
+
+       case cmd_ret_mac_multicast_adr:
+       case cmd_ret_mac_control:
+       case cmd_ret_802_11_set_wep:
+       case cmd_ret_802_11_reset:
+       case cmd_ret_802_11_authenticate:
+       case cmd_ret_802_11_radio_control:
+       case cmd_ret_802_11_beacon_stop:
+       case cmd_ret_802_11_enable_rsn:
+               break;
+
+       case cmd_ret_802_11_data_rate:
+               ret = wlan_ret_802_11_data_rate(priv, resp);
+               break;
+       case cmd_ret_802_11_rate_adapt_rateset:
+               ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp);
+               break;
+       case cmd_ret_802_11_rf_channel:
+               ret = wlan_ret_802_11_rf_channel(priv, resp);
+               break;
+
+       case cmd_ret_802_11_rssi:
+               ret = wlan_ret_802_11_rssi(priv, resp);
+               break;
+
+       case cmd_ret_802_11_mac_address:
+               ret = wlan_ret_802_11_mac_address(priv, resp);
+               break;
+
+       case cmd_ret_802_11_ad_hoc_stop:
+               ret = libertas_ret_80211_ad_hoc_stop(priv, resp);
+               break;
+
+       case cmd_ret_802_11_key_material:
+               lbs_pr_debug(1, "CMD_RESP: KEY_MATERIAL command response\n");
+               ret = wlan_ret_802_11_key_material(priv, resp);
+               break;
+
+       case cmd_ret_802_11_eeprom_access:
+               ret = wlan_ret_802_11_eeprom_access(priv, resp);
+               break;
+
+       case cmd_ret_802_11d_domain_info:
+               ret = libertas_ret_802_11d_domain_info(priv, resp);
+               break;
+
+       case cmd_ret_802_11_sleep_params:
+               ret = wlan_ret_802_11_sleep_params(priv, resp);
+               break;
+       case cmd_ret_802_11_inactivity_timeout:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               *((u16 *) adapter->cur_cmd->pdata_buf) =
+                   le16_to_cpu(resp->params.inactivity_timeout.timeout);
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+
+       case cmd_ret_802_11_tpc_cfg:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               memmove(adapter->cur_cmd->pdata_buf,
+                       &resp->params.tpccfg,
+                       sizeof(struct cmd_ds_802_11_tpc_cfg));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+       case cmd_ret_802_11_led_gpio_ctrl:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               memmove(adapter->cur_cmd->pdata_buf,
+                       &resp->params.ledgpio,
+                       sizeof(struct cmd_ds_802_11_led_ctrl));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+       case cmd_ret_802_11_pwr_cfg:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               memmove(adapter->cur_cmd->pdata_buf,
+                       &resp->params.pwrcfg,
+                       sizeof(struct cmd_ds_802_11_pwr_cfg));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+               break;
+
+       case cmd_ret_get_tsf:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               memcpy(priv->adapter->cur_cmd->pdata_buf,
+                      &resp->params.gettsf.tsfvalue, sizeof(u64));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+       case cmd_ret_bt_access:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               if (adapter->cur_cmd->pdata_buf)
+                       memcpy(adapter->cur_cmd->pdata_buf,
+                              &resp->params.bt.addr1, 2 * ETH_ALEN);
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+       case cmd_ret_fwt_access:
+               spin_lock_irqsave(&adapter->driver_lock, flags);
+               if (adapter->cur_cmd->pdata_buf)
+                       memcpy(adapter->cur_cmd->pdata_buf,
+                              &resp->params.fwt,
+                               sizeof(resp->params.fwt));
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               break;
+       case cmd_ret_mesh_access:
+               if (adapter->cur_cmd->pdata_buf)
+                       memcpy(adapter->cur_cmd->pdata_buf,
+                              &resp->params.mesh,
+                              sizeof(resp->params.mesh));
+               break;
+       case cmd_rte_802_11_tx_rate_query:
+               priv->adapter->txrate = resp->params.txrate.txrate;
+               break;
+       default:
+               lbs_pr_debug(1, "CMD_RESP: Unknown command response %#x\n",
+                      resp->command);
+               break;
+       }
+       return ret;
+}
+
+int libertas_process_rx_command(wlan_private * priv)
+{
+       u16 respcmd;
+       struct cmd_ds_command *resp;
+       wlan_adapter *adapter = priv->adapter;
+       int ret = 0;
+       ulong flags;
+       u16 result;
+
+       ENTER();
+
+       lbs_pr_debug(1, "CMD_RESP: @ %lu\n", jiffies);
+
+       /* Now we got response from FW, cancel the command timer */
+       del_timer(&adapter->command_timer);
+
+       mutex_lock(&adapter->lock);
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+
+       if (!adapter->cur_cmd) {
+               lbs_pr_debug(1, "CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd);
+               ret = -1;
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               goto done;
+       }
+       resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr);
+
+       lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr,
+               priv->wlan_dev.upld_len);
+
+       respcmd = le16_to_cpu(resp->command);
+
+       result = le16_to_cpu(resp->result);
+
+       lbs_pr_debug(1, "CMD_RESP: %x result: %d length: %d\n", respcmd,
+              result, priv->wlan_dev.upld_len);
+
+       if (!(respcmd & 0x8000)) {
+               lbs_pr_debug(1, "Invalid response to command!");
+               adapter->cur_cmd_retcode = -1;
+               __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
+               adapter->nr_cmd_pending--;
+               adapter->cur_cmd = NULL;
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+               ret = -1;
+               goto done;
+       }
+
+       /* Store the response code to cur_cmd_retcode. */
+       adapter->cur_cmd_retcode = le16_to_cpu(resp->result);
+
+       if (respcmd == cmd_ret_802_11_ps_mode) {
+               struct cmd_ds_802_11_ps_mode *psmode;
+
+               psmode = &resp->params.psmode;
+               lbs_pr_debug(1,
+                      "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n",
+                      resp->result, psmode->action);
+               psmode->action = cpu_to_le16(psmode->action);
+
+               if (result) {
+                       lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
+                              resp->result);
+                       if (adapter->inframode == wlan802_11ibss) {
+                               /*
+                                * We should not re-try enter-ps command in
+                                * ad-hoc mode. It takes place in
+                                * libertas_execute_next_command().
+                                */
+                               if (psmode->action == cmd_subcmd_enter_ps)
+                                       adapter->psmode =
+                                           wlan802_11powermodecam;
+                       }
+               } else if (psmode->action == cmd_subcmd_enter_ps) {
+                       adapter->needtowakeup = 0;
+                       adapter->psstate = PS_STATE_AWAKE;
+
+                       lbs_pr_debug(1, "CMD_RESP: Enter_PS command response\n");
+                       if (adapter->connect_status != libertas_connected) {
+                               /*
+                                * When Deauth Event received before Enter_PS command
+                                * response, We need to wake up the firmware.
+                                */
+                               lbs_pr_debug(1,
+                                      "Disconnected, Going to invoke libertas_ps_wakeup\n");
+
+                               mutex_unlock(&adapter->lock);
+                               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+                               libertas_ps_wakeup(priv, 0);
+                               mutex_lock(&adapter->lock);
+                               spin_lock_irqsave(&adapter->driver_lock, flags);
+                       }
+               } else if (psmode->action == cmd_subcmd_exit_ps) {
+                       adapter->needtowakeup = 0;
+                       adapter->psstate = PS_STATE_FULL_POWER;
+                       lbs_pr_debug(1, "CMD_RESP: Exit_PS command response\n");
+               } else {
+                       lbs_pr_debug(1, "CMD_RESP: PS- action=0x%X\n",
+                              psmode->action);
+               }
+
+               __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
+               adapter->nr_cmd_pending--;
+               adapter->cur_cmd = NULL;
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+               ret = 0;
+               goto done;
+       }
+
+       if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) {
+               /* Copy the response back to response buffer */
+               memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size);
+
+               adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD;
+       }
+
+       /* If the command is not successful, cleanup and return failure */
+       if ((result != 0 || !(respcmd & 0x8000))) {
+               lbs_pr_debug(1, "CMD_RESP: command reply %#x result=%#x\n",
+                      resp->command, resp->result);
+               /*
+                * Handling errors here
+                */
+               switch (respcmd) {
+               case cmd_ret_hw_spec_info:
+               case cmd_ret_802_11_reset:
+                       lbs_pr_debug(1, "CMD_RESP: Reset command failed\n");
+                       break;
+
+               }
+
+               __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
+               adapter->nr_cmd_pending--;
+               adapter->cur_cmd = NULL;
+               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+               ret = -1;
+               goto done;
+       }
+
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       ret = handle_cmd_response(respcmd, resp, priv);
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+       if (adapter->cur_cmd) {
+               /* Clean up and Put current command back to cmdfreeq */
+               __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
+               adapter->nr_cmd_pending--;
+               WARN_ON(adapter->nr_cmd_pending > 128);
+               adapter->cur_cmd = NULL;
+       }
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+done:
+       mutex_unlock(&adapter->lock);
+       LEAVE();
+       return ret;
+}
+
+int libertas_process_event(wlan_private * priv)
+{
+       int ret = 0;
+       wlan_adapter *adapter = priv->adapter;
+       u32 eventcause;
+
+       spin_lock_irq(&adapter->driver_lock);
+       eventcause = adapter->eventcause;
+       spin_unlock_irq(&adapter->driver_lock);
+
+       ENTER();
+
+       lbs_pr_debug(1, "EVENT Cause %x\n", eventcause);
+
+       switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) {
+       case MACREG_INT_CODE_LINK_SENSED:
+               lbs_pr_debug(1, "EVENT: MACREG_INT_CODE_LINK_SENSED\n");
+               break;
+
+       case MACREG_INT_CODE_DEAUTHENTICATED:
+               lbs_pr_debug(1, "EVENT: Deauthenticated\n");
+               libertas_mac_event_disconnected(priv);
+               break;
+
+       case MACREG_INT_CODE_DISASSOCIATED:
+               lbs_pr_debug(1, "EVENT: Disassociated\n");
+               libertas_mac_event_disconnected(priv);
+               break;
+
+       case MACREG_INT_CODE_LINK_LOSE_NO_SCAN:
+               lbs_pr_debug(1, "EVENT: Link lost\n");
+               libertas_mac_event_disconnected(priv);
+               break;
+
+       case MACREG_INT_CODE_PS_SLEEP:
+               lbs_pr_debug(1, "EVENT: SLEEP\n");
+               lbs_pr_debug(1, "_");
+
+               /* handle unexpected PS SLEEP event */
+               if (adapter->psstate == PS_STATE_FULL_POWER) {
+                       lbs_pr_debug(1,
+                              "EVENT: In FULL POWER mode - ignore PS SLEEP\n");
+                       break;
+               }
+               adapter->psstate = PS_STATE_PRE_SLEEP;
+
+               libertas_ps_confirm_sleep(priv, (u16) adapter->psmode);
+
+               break;
+
+       case MACREG_INT_CODE_PS_AWAKE:
+               lbs_pr_debug(1, "EVENT: AWAKE \n");
+               lbs_pr_debug(1, "|");
+
+               /* handle unexpected PS AWAKE event */
+               if (adapter->psstate == PS_STATE_FULL_POWER) {
+                       lbs_pr_debug(1,
+                              "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
+                       break;
+               }
+
+               adapter->psstate = PS_STATE_AWAKE;
+
+               if (adapter->needtowakeup) {
+                       /*
+                        * wait for the command processing to finish
+                        * before resuming sending
+                        * adapter->needtowakeup will be set to FALSE
+                        * in libertas_ps_wakeup()
+                        */
+                       lbs_pr_debug(1, "Waking up...\n");
+                       libertas_ps_wakeup(priv, 0);
+               }
+               break;
+
+       case MACREG_INT_CODE_MIC_ERR_UNICAST:
+               lbs_pr_debug(1, "EVENT: UNICAST MIC ERROR\n");
+               handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST);
+               break;
+
+       case MACREG_INT_CODE_MIC_ERR_MULTICAST:
+               lbs_pr_debug(1, "EVENT: MULTICAST MIC ERROR\n");
+               handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST);
+               break;
+       case MACREG_INT_CODE_MIB_CHANGED:
+       case MACREG_INT_CODE_INIT_DONE:
+               break;
+
+       case MACREG_INT_CODE_ADHOC_BCN_LOST:
+               lbs_pr_debug(1, "EVENT: HWAC - ADHOC BCN LOST\n");
+               break;
+
+       case MACREG_INT_CODE_RSSI_LOW:
+               lbs_pr_alert( "EVENT: RSSI_LOW\n");
+               break;
+       case MACREG_INT_CODE_SNR_LOW:
+               lbs_pr_alert( "EVENT: SNR_LOW\n");
+               break;
+       case MACREG_INT_CODE_MAX_FAIL:
+               lbs_pr_alert( "EVENT: MAX_FAIL\n");
+               break;
+       case MACREG_INT_CODE_RSSI_HIGH:
+               lbs_pr_alert( "EVENT: RSSI_HIGH\n");
+               break;
+       case MACREG_INT_CODE_SNR_HIGH:
+               lbs_pr_alert( "EVENT: SNR_HIGH\n");
+               break;
+
+       default:
+               lbs_pr_alert( "EVENT: unknown event id: %#x\n",
+                      eventcause >> SBI_EVENT_CAUSE_SHIFT);
+               break;
+       }
+
+       spin_lock_irq(&adapter->driver_lock);
+       adapter->eventcause = 0;
+       spin_unlock_irq(&adapter->driver_lock);
+       LEAVE();
+       return ret;
+}
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
new file mode 100644 (file)
index 0000000..3ad1e03
--- /dev/null
@@ -0,0 +1,1968 @@
+#include <linux/module.h>
+#include <linux/dcache.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/mm.h>
+#include <net/iw_handler.h>
+#include "dev.h"
+#include "decl.h"
+#include "host.h"
+
+static struct dentry *libertas_dir = NULL;
+static char *szStates[] = {
+       "Connected",
+       "Disconnected"
+};
+
+void libertas_debug_init(wlan_private * priv, struct net_device *dev);
+
+static int open_file_generic(struct inode *inode, struct file *file)
+{
+       file->private_data = inode->i_private;
+       return 0;
+}
+
+static ssize_t write_file_dummy(struct file *file, const char __user *buf,
+                                size_t count, loff_t *ppos)
+{
+        return -EINVAL;
+}
+
+static const size_t len = PAGE_SIZE;
+
+static ssize_t libertas_dev_info(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       size_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+       ssize_t res;
+
+       pos += snprintf(buf+pos, len-pos, "state = %s\n",
+                               szStates[priv->adapter->connect_status]);
+       pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
+                               (u32) priv->adapter->regioncode);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+
+       free_page(addr);
+       return res;
+}
+
+
+static ssize_t libertas_getscantable(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       size_t pos = 0;
+       int numscansdone = 0, res;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       pos += snprintf(buf+pos, len-pos,
+                       "---------------------------------------");
+       pos += snprintf(buf+pos, len-pos,
+                       "---------------------------------------\n");
+       pos += snprintf(buf+pos, len-pos,
+               "# | ch  | ss  |       bssid       |   cap    |    TSF   | Qual | SSID \n");
+       pos += snprintf(buf+pos, len-pos,
+               "---------------------------------------");
+       pos += snprintf(buf+pos, len-pos,
+               "---------------------------------------\n");
+
+       while (numscansdone < priv->adapter->numinscantable) {
+               struct bss_descriptor *pbssinfo;
+               u16 cap;
+
+               pbssinfo = &priv->adapter->scantable[numscansdone];
+               memcpy(&cap, &pbssinfo->cap, sizeof(cap));
+               pos += snprintf(buf+pos, len-pos,
+                       "%02u| %03d | %03ld | %02x:%02x:%02x:%02x:%02x:%02x |",
+                       numscansdone, pbssinfo->channel, pbssinfo->rssi,
+                       pbssinfo->macaddress[0], pbssinfo->macaddress[1],
+                       pbssinfo->macaddress[2], pbssinfo->macaddress[3],
+                       pbssinfo->macaddress[4], pbssinfo->macaddress[5]);
+               pos += snprintf(buf+pos, len-pos, " %04x-", cap);
+               pos += snprintf(buf+pos, len-pos, "%c%c%c |",
+                               pbssinfo->cap.ibss ? 'A' : 'I',
+                               pbssinfo->cap.privacy ? 'P' : ' ',
+                               pbssinfo->cap.spectrummgmt ? 'S' : ' ');
+               pos += snprintf(buf+pos, len-pos, " %08llx |", pbssinfo->networktsf);
+               pos += snprintf(buf+pos, len-pos, " %d |",
+                       SCAN_RSSI(priv->adapter->scantable[numscansdone].rssi));
+
+               pos += snprintf(buf+pos, len-pos, " %s\n", pbssinfo->ssid.ssid);
+
+               numscansdone++;
+       }
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_sleepparams_write(struct file *file,
+                               const char __user *user_buf, size_t count,
+                               loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t buf_size, res;
+       int p1, p2, p3, p4, p5, p6;
+       struct sleep_params sp;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, user_buf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
+       if (res != 6) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       sp.sp_error = p1;
+       sp.sp_offset = p2;
+       sp.sp_stabletime = p3;
+       sp.sp_calcontrol = p4;
+       sp.sp_extsleepclk = p5;
+       sp.sp_reserved = p6;
+
+       memcpy(&priv->adapter->sp, &sp, sizeof(struct sleep_params));
+
+        res = libertas_prepare_and_send_command(priv,
+                               cmd_802_11_sleep_params,
+                               cmd_act_set,
+                               cmd_option_waitforrsp, 0, NULL);
+
+       if (!res)
+               res = count;
+       else
+               res = -EINVAL;
+
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_sleepparams_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res;
+       size_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+        res = libertas_prepare_and_send_command(priv,
+                               cmd_802_11_sleep_params,
+                               cmd_act_get,
+                               cmd_option_waitforrsp, 0, NULL);
+       if (res) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
+                       adapter->sp.sp_offset, adapter->sp.sp_stabletime,
+                       adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
+                       adapter->sp.sp_reserved);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_extscan(struct file *file, const char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       struct WLAN_802_11_SSID extscan_ssid;
+       union iwreq_data wrqu;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       memcpy(&extscan_ssid.ssid, buf, strlen(buf)-1);
+       extscan_ssid.ssidlength = strlen(buf)-1;
+
+       libertas_send_specific_SSID_scan(priv, &extscan_ssid, 1);
+
+       memset(&wrqu, 0, sizeof(union iwreq_data));
+       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+
+out_unlock:
+       free_page(addr);
+       return count;
+}
+
+static int libertas_parse_chan(char *buf, size_t count,
+                       struct wlan_ioctl_user_scan_cfg *scan_cfg, int dur)
+{
+       char *start, *end, *hold, *str;
+       int i = 0;
+
+       start = strstr(buf, "chan=");
+       if (!start)
+               return -EINVAL;
+       start += 5;
+       end = strstr(start, " ");
+       if (!end)
+               end = buf + count;
+       hold = kzalloc((end - start)+1, GFP_KERNEL);
+       if (!hold)
+               return -ENOMEM;
+       strncpy(hold, start, end - start);
+       hold[(end-start)+1] = '\0';
+       while(hold && (str = strsep(&hold, ","))) {
+               int chan;
+               char band, passive = 0;
+               sscanf(str, "%d%c%c", &chan, &band, &passive);
+               scan_cfg->chanlist[i].channumber = chan;
+               scan_cfg->chanlist[i].scantype = passive ? 1 : 0;
+               if (band == 'b' || band == 'g')
+                       scan_cfg->chanlist[i].radiotype = 0;
+               else if (band == 'a')
+                       scan_cfg->chanlist[i].radiotype = 1;
+
+               scan_cfg->chanlist[i].scantime = dur;
+               i++;
+       }
+
+       kfree(hold);
+       return i;
+}
+
+static void libertas_parse_bssid(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold;
+       unsigned int mac[ETH_ALEN];
+       int i;
+
+       hold = strstr(buf, "bssid=");
+       if (!hold)
+               return;
+       hold += 6;
+       sscanf(hold, "%2x:%2x:%2x:%2x:%2x:%2x", mac, mac+1, mac+2, mac+3,
+                       mac+4, mac+5);
+       for(i=0;i<ETH_ALEN;i++)
+               scan_cfg->specificBSSID[i] = mac[i];
+}
+
+static void libertas_parse_ssid(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold, *end;
+       ssize_t size;
+
+       hold = strstr(buf, "ssid=");
+       if (!hold)
+               return;
+       hold += 5;
+       end = strstr(hold, " ");
+       if (!end)
+               end = buf + count - 1;
+
+       size = min(IW_ESSID_MAX_SIZE, end - hold);
+       strncpy(scan_cfg->specificSSID, hold, size);
+
+       return;
+}
+
+static void libertas_parse_keep(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold;
+       int val;
+
+       hold = strstr(buf, "keep=");
+       if (!hold)
+               return;
+       hold += 5;
+       sscanf(hold, "%d", &val);
+
+       if (val != 0)
+               val = 1;
+
+       scan_cfg->keeppreviousscan = val;
+       return;
+}
+
+static int libertas_parse_dur(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold;
+       int val;
+
+       hold = strstr(buf, "dur=");
+       if (!hold)
+               return 0;
+       hold += 4;
+       sscanf(hold, "%d", &val);
+
+       return val;
+}
+
+static void libertas_parse_probes(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold;
+       int val;
+
+       hold = strstr(buf, "probes=");
+       if (!hold)
+               return;
+       hold += 7;
+       sscanf(hold, "%d", &val);
+
+       scan_cfg->numprobes = val;
+
+       return;
+}
+
+static void libertas_parse_type(char *buf, size_t count,
+                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
+{
+       char *hold;
+       int val;
+
+       hold = strstr(buf, "type=");
+       if (!hold)
+               return;
+       hold += 5;
+       sscanf(hold, "%d", &val);
+
+       /* type=1,2 or 3 */
+       if (val < 1 || val > 3)
+               return;
+
+       scan_cfg->bsstype = val;
+
+       return;
+}
+
+static ssize_t libertas_setuserscan(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       struct wlan_ioctl_user_scan_cfg *scan_cfg;
+       union iwreq_data wrqu;
+       int dur;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       scan_cfg = kzalloc(sizeof(struct wlan_ioctl_user_scan_cfg), GFP_KERNEL);
+       if (!scan_cfg)
+               return -ENOMEM;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       scan_cfg->bsstype = WLAN_SCAN_BSS_TYPE_ANY;
+
+       dur = libertas_parse_dur(buf, count, scan_cfg);
+       libertas_parse_chan(buf, count, scan_cfg, dur);
+       libertas_parse_bssid(buf, count, scan_cfg);
+       libertas_parse_ssid(buf, count, scan_cfg);
+       libertas_parse_keep(buf, count, scan_cfg);
+       libertas_parse_probes(buf, count, scan_cfg);
+       libertas_parse_type(buf, count, scan_cfg);
+
+       wlan_scan_networks(priv, scan_cfg);
+       wait_event_interruptible(priv->adapter->cmd_pending,
+                                !priv->adapter->nr_cmd_pending);
+
+       memset(&wrqu, 0x00, sizeof(union iwreq_data));
+       wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
+
+out_unlock:
+       free_page(addr);
+       kfree(scan_cfg);
+       return count;
+}
+
+static int libertas_event_initcmd(wlan_private *priv, void **response_buf,
+                       struct cmd_ctrl_node **cmdnode,
+                       struct cmd_ds_command **cmd)
+{
+       u16 wait_option = cmd_option_waitforrsp;
+
+       if (!(*cmdnode = libertas_get_free_cmd_ctrl_node(priv))) {
+               lbs_pr_debug(1, "failed libertas_get_free_cmd_ctrl_node\n");
+               return -ENOMEM;
+       }
+       if (!(*response_buf = kmalloc(3000, GFP_KERNEL))) {
+               lbs_pr_debug(1, "failed to allocate response buffer!\n");
+               return -ENOMEM;
+       }
+       libertas_set_cmd_ctrl_node(priv, *cmdnode, 0, wait_option, NULL);
+       init_waitqueue_head(&(*cmdnode)->cmdwait_q);
+       (*cmdnode)->pdata_buf = *response_buf;
+       (*cmdnode)->cmdflags |= CMD_F_HOSTCMD;
+       (*cmdnode)->cmdwaitqwoken = 0;
+       *cmd = (struct cmd_ds_command *)(*cmdnode)->bufvirtualaddr;
+       (*cmd)->command = cmd_802_11_subscribe_event;
+       (*cmd)->seqnum = ++priv->adapter->seqnum;
+       (*cmd)->result = 0;
+       return 0;
+}
+
+static ssize_t libertas_lowrssi_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_rssithreshold  *Lowrssi;
+               case TLV_TYPE_RSSI_LOW:
+               Lowrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                               Lowrssi->rssivalue,
+                               Lowrssi->rssifreq,
+                               (event->events & 0x0001)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_snrthreshold);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static u16 libertas_get_events_bitmap(wlan_private *priv)
+{
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res;
+       u16 event_bitmap;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               return res;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               return 0;
+       }
+
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       event_bitmap = event->events;
+       kfree(response_buf);
+       return event_bitmap;
+}
+
+static ssize_t libertas_lowrssi_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_rssithreshold *rssi_threshold;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_rssithreshold));
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
+       rssi_threshold->header.type = cpu_to_le16(0x0104);
+       rssi_threshold->header.len = 2;
+       rssi_threshold->rssivalue = cpu_to_le16(value);
+       rssi_threshold->rssifreq = cpu_to_le16(freq);
+       event_bitmap |= subscribed ? 0x0001 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_lowsnr_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_snrthreshold *LowSnr;
+               case TLV_TYPE_SNR_LOW:
+               LowSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                               LowSnr->snrvalue,
+                               LowSnr->snrfreq,
+                               (event->events & 0x0002)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_snrthreshold);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_lowsnr_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_snrthreshold *snr_threshold;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_snrthreshold));
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
+       snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_LOW);
+       snr_threshold->header.len = 2;
+       snr_threshold->snrvalue = cpu_to_le16(value);
+       snr_threshold->snrfreq = cpu_to_le16(freq);
+       event_bitmap |= subscribed ? 0x0002 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       res = count;
+
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_failcount_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_failurecount *failcount;
+               case TLV_TYPE_FAILCOUNT:
+               failcount = (struct mrvlietypes_failurecount *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                               failcount->failvalue,
+                               failcount->Failfreq,
+                               (event->events & 0x0004)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_failurecount);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_failcount_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_failurecount *failcount;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_failurecount));
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       failcount = (struct mrvlietypes_failurecount *)(ptr);
+       failcount->header.type = cpu_to_le16(TLV_TYPE_FAILCOUNT);
+       failcount->header.len = 2;
+       failcount->failvalue = cpu_to_le16(value);
+       failcount->Failfreq = cpu_to_le16(freq);
+       event_bitmap |= subscribed ? 0x0004 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = (struct cmd_ds_command *)response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_bcnmiss_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               free_page(addr);
+               kfree(response_buf);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               free_page(addr);
+               kfree(response_buf);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_beaconsmissed *bcnmiss;
+               case TLV_TYPE_BCNMISS:
+               bcnmiss = (struct mrvlietypes_beaconsmissed *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
+                               bcnmiss->beaconmissed,
+                               (event->events & 0x0008)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_beaconsmissed);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_bcnmiss_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_beaconsmissed *bcnmiss;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_beaconsmissed));
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       bcnmiss = (struct mrvlietypes_beaconsmissed *)(ptr);
+       bcnmiss->header.type = cpu_to_le16(TLV_TYPE_BCNMISS);
+       bcnmiss->header.len = 2;
+       bcnmiss->beaconmissed = cpu_to_le16(value);
+       event_bitmap |= subscribed ? 0x0008 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               free_page(addr);
+               kfree(response_buf);
+               return 0;
+       }
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_highrssi_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_rssithreshold  *Highrssi;
+               case TLV_TYPE_RSSI_HIGH:
+               Highrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                               Highrssi->rssivalue,
+                               Highrssi->rssifreq,
+                               (event->events & 0x0010)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_snrthreshold);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_highrssi_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_rssithreshold *rssi_threshold;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_rssithreshold));
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
+       rssi_threshold->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
+       rssi_threshold->header.len = 2;
+       rssi_threshold->rssivalue = cpu_to_le16(value);
+       rssi_threshold->rssifreq = cpu_to_le16(freq);
+       event_bitmap |= subscribed ? 0x0010 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               return 0;
+       }
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_highsnr_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       void *response_buf;
+       int res, cmd_len;
+       ssize_t pos = 0;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0) {
+               free_page(addr);
+               return res;
+       }
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_get;
+       pcmdptr->size =
+       cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
+       while (cmd_len < pcmdptr->size) {
+               struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
+               switch(header->type) {
+               struct mrvlietypes_snrthreshold *HighSnr;
+               case TLV_TYPE_SNR_HIGH:
+               HighSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
+               pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
+                               HighSnr->snrvalue,
+                               HighSnr->snrfreq,
+                               (event->events & 0x0020)?1:0);
+               default:
+                       cmd_len += sizeof(struct mrvlietypes_snrthreshold);
+                       break;
+               }
+       }
+
+       kfree(response_buf);
+
+       res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_highsnr_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       ssize_t res, buf_size;
+       int value, freq, subscribed, cmd_len;
+       struct cmd_ctrl_node *pcmdnode;
+       struct cmd_ds_command *pcmdptr;
+       struct cmd_ds_802_11_subscribe_event *event;
+       struct mrvlietypes_snrthreshold *snr_threshold;
+       void *response_buf;
+       u16 event_bitmap;
+       u8 *ptr;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
+       if (res != 3) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       event_bitmap = libertas_get_events_bitmap(priv);
+
+       res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
+       if (res < 0)
+               goto out_unlock;
+
+       event = &pcmdptr->params.subscribe_event;
+       event->action = cmd_act_set;
+       pcmdptr->size = cpu_to_le16(S_DS_GEN +
+               sizeof(struct cmd_ds_802_11_subscribe_event) +
+               sizeof(struct mrvlietypes_snrthreshold));
+       cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
+       ptr = (u8*) pcmdptr+cmd_len;
+       snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
+       snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_HIGH);
+       snr_threshold->header.len = 2;
+       snr_threshold->snrvalue = cpu_to_le16(value);
+       snr_threshold->snrfreq = cpu_to_le16(freq);
+       event_bitmap |= subscribed ? 0x0020 : 0x0;
+       event->events = event_bitmap;
+
+       libertas_queue_cmd(adapter, pcmdnode, 1);
+       wake_up_interruptible(&priv->mainthread.waitq);
+
+       /* Sleep until response is generated by FW */
+       wait_event_interruptible(pcmdnode->cmdwait_q,
+                               pcmdnode->cmdwaitqwoken);
+
+       pcmdptr = response_buf;
+
+       if (pcmdptr->result) {
+               lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
+                       pcmdptr->result);
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
+               lbs_pr_err("command response incorrect!\n");
+               kfree(response_buf);
+               free_page(addr);
+               return 0;
+       }
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_rdmac_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct wlan_offset_value offval;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       offval.offset = priv->mac_offset;
+       offval.value = 0;
+
+       ret = libertas_prepare_and_send_command(priv,
+                               cmd_mac_reg_access, 0,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+       pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
+                               priv->mac_offset, adapter->offsetvalue.value);
+
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+       return ret;
+}
+
+static ssize_t libertas_rdmac_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_wrmac_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       u32 offset, value;
+       struct wlan_offset_value offval;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       offval.offset = offset;
+       offval.value = value;
+       res = libertas_prepare_and_send_command(priv,
+                               cmd_mac_reg_access, 1,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_rdbbp_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct wlan_offset_value offval;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       offval.offset = priv->bbp_offset;
+       offval.value = 0;
+
+       ret = libertas_prepare_and_send_command(priv,
+                               cmd_bbp_reg_access, 0,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+       pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
+                               priv->bbp_offset, adapter->offsetvalue.value);
+
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+
+       return ret;
+}
+
+static ssize_t libertas_rdbbp_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_wrbbp_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       u32 offset, value;
+       struct wlan_offset_value offval;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       offval.offset = offset;
+       offval.value = value;
+       res = libertas_prepare_and_send_command(priv,
+                               cmd_bbp_reg_access, 1,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_rdrf_read(struct file *file, char __user *userbuf,
+                                 size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       wlan_adapter *adapter = priv->adapter;
+       struct wlan_offset_value offval;
+       ssize_t pos = 0;
+       int ret;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       offval.offset = priv->rf_offset;
+       offval.value = 0;
+
+       ret = libertas_prepare_and_send_command(priv,
+                               cmd_rf_reg_access, 0,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+       pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
+                               priv->rf_offset, adapter->offsetvalue.value);
+
+       ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+       free_page(addr);
+
+       return ret;
+}
+
+static ssize_t libertas_rdrf_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+static ssize_t libertas_wrrf_write(struct file *file,
+                                   const char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+
+       wlan_private *priv = file->private_data;
+       ssize_t res, buf_size;
+       u32 offset, value;
+       struct wlan_offset_value offval;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       buf_size = min(count, len - 1);
+       if (copy_from_user(buf, userbuf, buf_size)) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+       res = sscanf(buf, "%x %x", &offset, &value);
+       if (res != 2) {
+               res = -EFAULT;
+               goto out_unlock;
+       }
+
+       offval.offset = offset;
+       offval.value = value;
+       res = libertas_prepare_and_send_command(priv,
+                               cmd_rf_reg_access, 1,
+                               cmd_option_waitforrsp, 0, &offval);
+       mdelay(10);
+
+       res = count;
+out_unlock:
+       free_page(addr);
+       return res;
+}
+
+#define FOPS(fread, fwrite) { \
+       .owner = THIS_MODULE, \
+       .open = open_file_generic, \
+       .read = (fread), \
+       .write = (fwrite), \
+}
+
+struct libertas_debugfs_files {
+       char *name;
+       int perm;
+       struct file_operations fops;
+};
+
+struct libertas_debugfs_files debugfs_files[] = {
+       { "info", 0444, FOPS(libertas_dev_info, write_file_dummy), },
+       { "getscantable", 0444, FOPS(libertas_getscantable,
+                                       write_file_dummy), },
+       { "sleepparams", 0644, FOPS(libertas_sleepparams_read,
+                               libertas_sleepparams_write), },
+       { "extscan", 0600, FOPS(NULL, libertas_extscan), },
+       { "setuserscan", 0600, FOPS(NULL, libertas_setuserscan), },
+};
+
+struct libertas_debugfs_files debugfs_events_files[] = {
+       {"low_rssi", 0644, FOPS(libertas_lowrssi_read,
+                               libertas_lowrssi_write), },
+       {"low_snr", 0644, FOPS(libertas_lowsnr_read,
+                               libertas_lowsnr_write), },
+       {"failure_count", 0644, FOPS(libertas_failcount_read,
+                               libertas_failcount_write), },
+       {"beacon_missed", 0644, FOPS(libertas_bcnmiss_read,
+                               libertas_bcnmiss_write), },
+       {"high_rssi", 0644, FOPS(libertas_highrssi_read,
+                               libertas_highrssi_write), },
+       {"high_snr", 0644, FOPS(libertas_highsnr_read,
+                               libertas_highsnr_write), },
+};
+
+struct libertas_debugfs_files debugfs_regs_files[] = {
+       {"rdmac", 0644, FOPS(libertas_rdmac_read, libertas_rdmac_write), },
+       {"wrmac", 0600, FOPS(NULL, libertas_wrmac_write), },
+       {"rdbbp", 0644, FOPS(libertas_rdbbp_read, libertas_rdbbp_write), },
+       {"wrbbp", 0600, FOPS(NULL, libertas_wrbbp_write), },
+       {"rdrf", 0644, FOPS(libertas_rdrf_read, libertas_rdrf_write), },
+       {"wrrf", 0600, FOPS(NULL, libertas_wrrf_write), },
+};
+
+void libertas_debugfs_init(void)
+{
+       if (!libertas_dir)
+               libertas_dir = debugfs_create_dir("libertas_wireless", NULL);
+
+       return;
+}
+
+void libertas_debugfs_remove(void)
+{
+       if (libertas_dir)
+                debugfs_remove(libertas_dir);
+       return;
+}
+
+void libertas_debugfs_init_one(wlan_private *priv, struct net_device *dev)
+{
+       int i;
+       struct libertas_debugfs_files *files;
+       if (!libertas_dir)
+               goto exit;
+
+       priv->debugfs_dir = debugfs_create_dir(dev->name, libertas_dir);
+       if (!priv->debugfs_dir)
+               goto exit;
+
+       for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
+               files = &debugfs_files[i];
+               priv->debugfs_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->debugfs_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+
+       priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
+       if (!priv->events_dir)
+               goto exit;
+
+       for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
+               files = &debugfs_events_files[i];
+               priv->debugfs_events_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->events_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+
+       priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
+       if (!priv->regs_dir)
+               goto exit;
+
+       for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
+               files = &debugfs_regs_files[i];
+               priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
+                                                            files->perm,
+                                                            priv->regs_dir,
+                                                            priv,
+                                                            &files->fops);
+       }
+
+#ifdef PROC_DEBUG
+       libertas_debug_init(priv, dev);
+#endif
+exit:
+       return;
+}
+
+void libertas_debugfs_remove_one(wlan_private *priv)
+{
+       int i;
+
+       for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
+               debugfs_remove(priv->debugfs_regs_files[i]);
+
+       debugfs_remove(priv->regs_dir);
+
+       for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
+               debugfs_remove(priv->debugfs_events_files[i]);
+
+       debugfs_remove(priv->events_dir);
+#ifdef PROC_DEBUG
+       debugfs_remove(priv->debugfs_debug);
+#endif
+       for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
+               debugfs_remove(priv->debugfs_files[i]);
+}
+
+/* debug entry */
+
+#define item_size(n) (sizeof ((wlan_adapter *)0)->n)
+#define item_addr(n) ((u32) &((wlan_adapter *)0)->n)
+
+struct debug_data {
+       char name[32];
+       u32 size;
+       u32 addr;
+};
+
+/* To debug any member of wlan_adapter, simply add one line here.
+ */
+static struct debug_data items[] = {
+       {"intcounter", item_size(intcounter), item_addr(intcounter)},
+       {"psmode", item_size(psmode), item_addr(psmode)},
+       {"psstate", item_size(psstate), item_addr(psstate)},
+};
+
+static int num_of_items = sizeof(items) / sizeof(items[0]);
+
+/**
+ *  @brief convert string to number
+ *
+ *  @param s              pointer to numbered string
+ *  @return       converted number from string s
+ */
+static int string_to_number(char *s)
+{
+       int r = 0;
+       int base = 0;
+
+       if ((strncmp(s, "0x", 2) == 0) || (strncmp(s, "0X", 2) == 0))
+               base = 16;
+       else
+               base = 10;
+
+       if (base == 16)
+               s += 2;
+
+       for (s = s; *s != 0; s++) {
+               if ((*s >= 48) && (*s <= 57))
+                       r = (r * base) + (*s - 48);
+               else if ((*s >= 65) && (*s <= 70))
+                       r = (r * base) + (*s - 55);
+               else if ((*s >= 97) && (*s <= 102))
+                       r = (r * base) + (*s - 87);
+               else
+                       break;
+       }
+
+       return r;
+}
+
+/**
+ *  @brief proc read function
+ *
+ *  @param page           pointer to buffer
+ *  @param s       read data starting position
+ *  @param off     offset
+ *  @param cnt     counter
+ *  @param eof     end of file flag
+ *  @param data    data to output
+ *  @return       number of output data
+ */
+static ssize_t wlan_debugfs_read(struct file *file, char __user *userbuf,
+                       size_t count, loff_t *ppos)
+{
+       int val = 0;
+       size_t pos = 0;
+       ssize_t res;
+       char *p;
+       int i;
+       struct debug_data *d;
+       unsigned long addr = get_zeroed_page(GFP_KERNEL);
+       char *buf = (char *)addr;
+
+       p = buf;
+
+       d = (struct debug_data *)file->private_data;
+
+       for (i = 0; i < num_of_items; i++) {
+               if (d[i].size == 1)
+                       val = *((u8 *) d[i].addr);
+               else if (d[i].size == 2)
+                       val = *((u16 *) d[i].addr);
+               else if (d[i].size == 4)
+                       val = *((u32 *) d[i].addr);
+
+               pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
+       }
+
+       res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
+
+       free_page(addr);
+       return res;
+}
+
+/**
+ *  @brief proc write function
+ *
+ *  @param f      file pointer
+ *  @param buf     pointer to data buffer
+ *  @param cnt     data number to write
+ *  @param data    data to write
+ *  @return       number of data
+ */
+static int wlan_debugfs_write(struct file *f, const char __user *buf,
+                           size_t cnt, loff_t *ppos)
+{
+       int r, i;
+       char *pdata;
+       char *p;
+       char *p0;
+       char *p1;
+       char *p2;
+       struct debug_data *d = (struct debug_data *)f->private_data;
+
+       pdata = (char *)kmalloc(cnt, GFP_KERNEL);
+       if (pdata == NULL)
+               return 0;
+
+       if (copy_from_user(pdata, buf, cnt)) {
+               lbs_pr_debug(1, "Copy from user failed\n");
+               kfree(pdata);
+               return 0;
+       }
+
+       p0 = pdata;
+       for (i = 0; i < num_of_items; i++) {
+               do {
+                       p = strstr(p0, d[i].name);
+                       if (p == NULL)
+                               break;
+                       p1 = strchr(p, '\n');
+                       if (p1 == NULL)
+                               break;
+                       p0 = p1++;
+                       p2 = strchr(p, '=');
+                       if (!p2)
+                               break;
+                       p2++;
+                       r = string_to_number(p2);
+                       if (d[i].size == 1)
+                               *((u8 *) d[i].addr) = (u8) r;
+                       else if (d[i].size == 2)
+                               *((u16 *) d[i].addr) = (u16) r;
+                       else if (d[i].size == 4)
+                               *((u32 *) d[i].addr) = (u32) r;
+                       break;
+               } while (1);
+       }
+       kfree(pdata);
+
+       return cnt;
+}
+
+static struct file_operations libertas_debug_fops = {
+       .owner = THIS_MODULE,
+       .open = open_file_generic,
+       .write = wlan_debugfs_write,
+       .read = wlan_debugfs_read,
+};
+
+/**
+ *  @brief create debug proc file
+ *
+ *  @param priv           pointer wlan_private
+ *  @param dev     pointer net_device
+ *  @return       N/A
+ */
+void libertas_debug_init(wlan_private * priv, struct net_device *dev)
+{
+       int i;
+
+       if (!priv->debugfs_dir)
+               return;
+
+       for (i = 0; i < num_of_items; i++)
+               items[i].addr += (u32) priv->adapter;
+
+       priv->debugfs_debug = debugfs_create_file("debug", 0644,
+                                                 priv->debugfs_dir, &items[0],
+                                                 &libertas_debug_fops);
+}
+
+/**
+ *  @brief remove proc file
+ *
+ *  @param priv           pointer wlan_private
+ *  @return       N/A
+ */
+void libertas_debug_remove(wlan_private * priv)
+{
+       debugfs_remove(priv->debugfs_debug);
+}
diff --git a/drivers/net/wireless/libertas/debugfs.h b/drivers/net/wireless/libertas/debugfs.h
new file mode 100644 (file)
index 0000000..880a11b
--- /dev/null
@@ -0,0 +1,6 @@
+void libertas_debugfs_init(void);
+void libertas_debugfs_remove(void);
+
+void libertas_debugfs_init_one(wlan_private *priv, struct net_device *dev);
+void libertas_debugfs_remove_one(wlan_private *priv);
+
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
new file mode 100644 (file)
index 0000000..606bdd0
--- /dev/null
@@ -0,0 +1,83 @@
+/**
+  *  This file contains declaration referring to
+  *  functions defined in other source files
+  */
+
+#ifndef _WLAN_DECL_H_
+#define _WLAN_DECL_H_
+
+#include "defs.h"
+
+/** Function Prototype Declaration */
+struct wlan_private;
+struct sk_buff;
+struct net_device;
+
+extern char *libertas_fw_name;
+
+void libertas_free_adapter(wlan_private * priv);
+int libertas_set_mac_packet_filter(wlan_private * priv);
+
+int libertas_send_null_packet(wlan_private * priv, u8 pwr_mgmt);
+void libertas_send_tx_feedback(wlan_private * priv);
+u8 libertas_check_last_packet_indication(wlan_private * priv);
+
+int libertas_free_cmd_buffer(wlan_private * priv);
+struct cmd_ctrl_node;
+struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv);
+
+void libertas_set_cmd_ctrl_node(wlan_private * priv,
+                   struct cmd_ctrl_node *ptempnode,
+                   u32 cmd_oid, u16 wait_option, void *pdata_buf);
+
+int libertas_prepare_and_send_command(wlan_private * priv,
+                         u16 cmd_no,
+                         u16 cmd_action,
+                         u16 wait_option, u32 cmd_oid, void *pdata_buf);
+
+void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail);
+
+int libertas_allocate_cmd_buffer(wlan_private * priv);
+int libertas_execute_next_command(wlan_private * priv);
+int libertas_process_event(wlan_private * priv);
+void libertas_interrupt(struct net_device *);
+int libertas_set_radio_control(wlan_private * priv);
+u32 libertas_index_to_data_rate(u8 index);
+u8 libertas_data_rate_to_index(u32 rate);
+void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen);
+
+int libertas_upload_rx_packet(wlan_private * priv, struct sk_buff *skb);
+
+/** The proc fs interface */
+int libertas_process_rx_command(wlan_private * priv);
+int libertas_process_tx(wlan_private * priv, struct sk_buff *skb);
+void libertas_cleanup_and_insert_cmd(wlan_private * priv,
+                                       struct cmd_ctrl_node *ptempcmd);
+void __libertas_cleanup_and_insert_cmd(wlan_private * priv,
+                                       struct cmd_ctrl_node *ptempcmd);
+
+int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band);
+
+int libertas_process_rxed_packet(wlan_private * priv, struct sk_buff *);
+
+void libertas_ps_sleep(wlan_private * priv, int wait_option);
+void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode);
+void libertas_ps_wakeup(wlan_private * priv, int wait_option);
+
+void libertas_tx_runqueue(wlan_private *priv);
+
+extern struct chan_freq_power *libertas_find_cfp_by_band_and_channel(
+                               wlan_adapter * adapter, u8 band, u16 channel);
+
+extern void libertas_mac_event_disconnected(wlan_private * priv);
+
+void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str);
+
+int reset_device(wlan_private *priv);
+/* main.c */
+extern struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band,
+                                                            int *cfp_no);
+wlan_private *wlan_add_card(void *card);
+int wlan_remove_card(void *card);
+
+#endif                         /* _WLAN_DECL_H_ */
diff --git a/drivers/net/wireless/libertas/defs.h b/drivers/net/wireless/libertas/defs.h
new file mode 100644 (file)
index 0000000..fb1478c
--- /dev/null
@@ -0,0 +1,369 @@
+/**
+  * This header file contains global constant/enum definitions,
+  * global variable declaration.
+  */
+#ifndef _WLAN_DEFS_H_
+#define _WLAN_DEFS_H_
+
+#include <linux/spinlock.h>
+
+extern unsigned int libertas_debug;
+
+#define DRV_NAME               "usb8xxx"
+
+#define lbs_pr_info(format, args...) \
+       printk(KERN_INFO DRV_NAME": " format, ## args)
+#define lbs_pr_err(format, args...) \
+       printk(KERN_ERR DRV_NAME": " format, ## args)
+#define lbs_pr_alert(format, args...) \
+       printk(KERN_ALERT DRV_NAME": " format, ## args)
+
+#ifdef DEBUG
+#define lbs_pr_debug(level, format, args...) \
+       do { if (libertas_debug >= level) \
+       printk(KERN_INFO DRV_NAME": " format, ##args); } while (0)
+#define lbs_dev_dbg(level, device, format, args...) \
+        lbs_pr_debug(level, "%s: " format, \
+        (device)->bus_id , ## args)
+
+static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
+{
+       int i = 0;
+
+       if (!libertas_debug)
+               return;
+
+       printk(KERN_DEBUG "%s: ", prompt);
+       for (i = 1; i <= len; i++) {
+               printk(KERN_DEBUG "%02x ", (u8) * buf);
+               buf++;
+       }
+       printk("\n");
+}
+#else
+#define lbs_pr_debug(level, format, args...)           do {} while (0)
+#define lbs_dev_dbg(level, device, format, args...)    do {} while (0)
+#define lbs_dbg_hex(x,y,z)                             do {} while (0)
+#endif
+
+#define        ENTER()                 lbs_pr_debug(1, "Enter: %s, %s:%i\n", \
+                                       __FUNCTION__, __FILE__, __LINE__)
+#define        LEAVE()                 lbs_pr_debug(1, "Leave: %s, %s:%i\n", \
+                                       __FUNCTION__, __FILE__, __LINE__)
+
+/** Buffer Constants */
+
+/*     The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
+*      addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
+*      driver has more local TxPDs. Each TxPD on the host memory is associated
+*      with a Tx control node. The driver maintains 8 RxPD descriptors for
+*      station firmware to store Rx packet information.
+*
+*      Current version of MAC has a 32x6 multicast address buffer.
+*
+*      802.11b can have up to  14 channels, the driver keeps the
+*      BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
+*/
+
+#define MRVDRV_MAX_MULTICAST_LIST_SIZE 32
+#define MRVDRV_NUM_OF_CMD_BUFFER        10
+#define MRVDRV_SIZE_OF_CMD_BUFFER       (2 * 1024)
+#define MRVDRV_MAX_CHANNEL_SIZE                14
+#define MRVDRV_MAX_BSSID_LIST          64
+#define MRVDRV_ASSOCIATION_TIME_OUT    255
+#define MRVDRV_SNAP_HEADER_LEN          8
+
+#define        WLAN_UPLD_SIZE                  2312
+#define DEV_NAME_LEN                   32
+
+/** Misc constants */
+/* This section defines 802.11 specific contants */
+
+#define MRVDRV_MAX_BSS_DESCRIPTS               16
+#define MRVDRV_MAX_REGION_CODE                 6
+
+#define MRVDRV_IGNORE_MULTIPLE_DTIM            0xfffe
+#define MRVDRV_MIN_MULTIPLE_DTIM               1
+#define MRVDRV_MAX_MULTIPLE_DTIM               5
+#define MRVDRV_DEFAULT_MULTIPLE_DTIM           1
+
+#define MRVDRV_DEFAULT_LISTEN_INTERVAL         10
+
+#define        MRVDRV_CHANNELS_PER_SCAN                4
+#define        MRVDRV_MAX_CHANNELS_PER_SCAN            14
+
+#define MRVDRV_DEBUG_RX_PATH           0x00000001
+#define MRVDRV_DEBUG_TX_PATH           0x00000002
+
+#define MRVDRV_MIN_BEACON_INTERVAL             20
+#define MRVDRV_MAX_BEACON_INTERVAL             1000
+#define MRVDRV_BEACON_INTERVAL                 100
+
+/** TxPD status */
+
+/*     Station firmware use TxPD status field to report final Tx transmit
+*      result, Bit masks are used to present combined situations.
+*/
+
+#define MRVDRV_TxPD_POWER_MGMT_NULL_PACKET 0x01
+#define MRVDRV_TxPD_POWER_MGMT_LAST_PACKET 0x08
+
+/** Tx mesh flag */
+/* Currently we are using normal WDS flag as mesh flag.
+ * TODO: change to proper mesh flag when MAC understands it.
+ */
+#define TxPD_CONTROL_WDS_FRAME (1<<17)
+#define TxPD_MESH_FRAME TxPD_CONTROL_WDS_FRAME
+
+/** RxPD status */
+
+#define MRVDRV_RXPD_STATUS_OK                0x0001
+
+/** RxPD status - Received packet types */
+/** Rx mesh flag */
+/* Currently we are using normal WDS flag as mesh flag.
+ * TODO: change to proper mesh flag when MAC understands it.
+ */
+#define RxPD_CONTROL_WDS_FRAME (0x40)
+#define RxPD_MESH_FRAME RxPD_CONTROL_WDS_FRAME
+
+/** RSSI-related defines */
+/*     RSSI constants are used to implement 802.11 RSSI threshold
+*      indication. if the Rx packet signal got too weak for 5 consecutive
+*      times, miniport driver (driver) will report this event to wrapper
+*/
+
+#define MRVDRV_NF_DEFAULT_SCAN_VALUE           (-96)
+
+/** RTS/FRAG related defines */
+#define MRVDRV_RTS_MIN_VALUE           0
+#define MRVDRV_RTS_MAX_VALUE           2347
+#define MRVDRV_FRAG_MIN_VALUE          256
+#define MRVDRV_FRAG_MAX_VALUE          2346
+
+/* This is for firmware specific length */
+#define EXTRA_LEN      36
+
+#define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
+       (ETH_FRAME_LEN + sizeof(struct txpd) + EXTRA_LEN)
+
+#define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
+       (ETH_FRAME_LEN + sizeof(struct rxpd) \
+        + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
+
+#define        CMD_F_HOSTCMD           (1 << 0)
+#define FW_CAPINFO_WPA         (1 << 0)
+
+/** WPA key LENGTH*/
+#define MRVL_MAX_KEY_WPA_KEY_LENGTH     32
+
+#define KEY_LEN_WPA_AES                        16
+#define KEY_LEN_WPA_TKIP               32
+#define KEY_LEN_WEP_104                        13
+#define KEY_LEN_WEP_40                 5
+
+#define RF_ANTENNA_1           0x1
+#define RF_ANTENNA_2           0x2
+#define RF_ANTENNA_AUTO                0xFFFF
+
+#define        BAND_B                  (0x01)
+#define        BAND_G                  (0x02)
+#define ALL_802_11_BANDS       (BAND_B | BAND_G)
+
+/** MACRO DEFINITIONS */
+#define CAL_NF(NF)                     ((s32)(-(s32)(NF)))
+#define CAL_RSSI(SNR, NF)              ((s32)((s32)(SNR) + CAL_NF(NF)))
+#define SCAN_RSSI(RSSI)                        (0x100 - ((u8)(RSSI)))
+
+#define DEFAULT_BCN_AVG_FACTOR         8
+#define DEFAULT_DATA_AVG_FACTOR                8
+#define AVG_SCALE                      100
+#define CAL_AVG_SNR_NF(AVG, SNRNF, N)         \
+                        (((AVG) == 0) ? ((u16)(SNRNF) * AVG_SCALE) : \
+                        ((((int)(AVG) * (N -1)) + ((u16)(SNRNF) * \
+                        AVG_SCALE))  / N))
+
+#define B_SUPPORTED_RATES              8
+#define G_SUPPORTED_RATES              14
+
+#define        WLAN_SUPPORTED_RATES            14
+
+#define        MAX_LEDS                        8
+
+#define IS_MESH_FRAME(x) (x->cb[6])
+#define SET_MESH_FRAME(x) (x->cb[6]=1)
+#define UNSET_MESH_FRAME(x) (x->cb[6]=0)
+
+/** Global Variable Declaration */
+typedef struct _wlan_private wlan_private;
+typedef struct _wlan_adapter wlan_adapter;
+extern const char libertas_driver_version[];
+extern u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE];
+
+extern u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES];
+
+extern u8 libertas_supported_rates[G_SUPPORTED_RATES];
+
+extern u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES];
+
+extern u8 libertas_adhoc_rates_b[4];
+
+/** ENUM definition*/
+/** SNRNF_TYPE */
+enum SNRNF_TYPE {
+       TYPE_BEACON = 0,
+       TYPE_RXPD,
+       MAX_TYPE_B
+};
+
+/** SNRNF_DATA*/
+enum SNRNF_DATA {
+       TYPE_NOAVG = 0,
+       TYPE_AVG,
+       MAX_TYPE_AVG
+};
+
+/** WLAN_802_11_AUTH_ALG*/
+enum WLAN_802_11_AUTH_ALG {
+       AUTH_ALG_OPEN_SYSTEM = 1,
+       AUTH_ALG_SHARED_KEY = 2,
+       AUTH_ALG_NETWORK_EAP = 8,
+};
+
+/** WLAN_802_1X_AUTH_ALG */
+enum WLAN_802_1X_AUTH_ALG {
+       WLAN_1X_AUTH_ALG_NONE = 1,
+       WLAN_1X_AUTH_ALG_LEAP = 2,
+       WLAN_1X_AUTH_ALG_TLS = 4,
+       WLAN_1X_AUTH_ALG_TTLS = 8,
+       WLAN_1X_AUTH_ALG_MD5 = 16,
+};
+
+/** WLAN_802_11_ENCRYPTION_MODE */
+enum WLAN_802_11_ENCRYPTION_MODE {
+       CIPHER_NONE,
+       CIPHER_WEP40,
+       CIPHER_TKIP,
+       CIPHER_CCMP,
+       CIPHER_WEP104,
+};
+
+/** WLAN_802_11_POWER_MODE */
+enum WLAN_802_11_POWER_MODE {
+       wlan802_11powermodecam,
+       wlan802_11powermodemax_psp,
+       wlan802_11Powermodefast_psp,
+       /*not a real mode, defined as an upper bound */
+       wlan802_11powemodemax
+};
+
+/** PS_STATE */
+enum PS_STATE {
+       PS_STATE_FULL_POWER,
+       PS_STATE_AWAKE,
+       PS_STATE_PRE_SLEEP,
+       PS_STATE_SLEEP
+};
+
+/** DNLD_STATE */
+enum DNLD_STATE {
+       DNLD_RES_RECEIVED,
+       DNLD_DATA_SENT,
+       DNLD_CMD_SENT
+};
+
+/** WLAN_MEDIA_STATE */
+enum WLAN_MEDIA_STATE {
+       libertas_connected,
+       libertas_disconnected
+};
+
+/** WLAN_802_11_PRIVACY_FILTER */
+enum WLAN_802_11_PRIVACY_FILTER {
+       wlan802_11privfilteracceptall,
+       wlan802_11privfilter8021xWEP
+};
+
+/** mv_ms_type */
+enum mv_ms_type {
+       MVMS_DAT = 0,
+       MVMS_CMD = 1,
+       MVMS_TXDONE = 2,
+       MVMS_EVENT
+};
+
+/** WLAN_802_11_NETWORK_INFRASTRUCTURE */
+enum WLAN_802_11_NETWORK_INFRASTRUCTURE {
+       wlan802_11ibss,
+       wlan802_11infrastructure,
+       wlan802_11autounknown,
+       /*defined as upper bound */
+       wlan802_11infrastructuremax
+};
+
+/** WLAN_802_11_AUTHENTICATION_MODE */
+enum WLAN_802_11_AUTHENTICATION_MODE {
+       wlan802_11authmodeopen = 0x00,
+       wlan802_11authmodeshared = 0x01,
+       wlan802_11authmodenetworkEAP = 0x80,
+};
+
+/** WLAN_802_11_WEP_STATUS */
+enum WLAN_802_11_WEP_STATUS {
+       wlan802_11WEPenabled,
+       wlan802_11WEPdisabled,
+};
+
+/** SNMP_MIB_INDEX_e */
+enum SNMP_MIB_INDEX_e {
+       desired_bsstype_i = 0,
+       op_rateset_i,
+       bcnperiod_i,
+       dtimperiod_i,
+       assocrsp_timeout_i,
+       rtsthresh_i,
+       short_retrylim_i,
+       long_retrylim_i,
+       fragthresh_i,
+       dot11d_i,
+       dot11h_i,
+       manufid_i,
+       prodID_i,
+       manuf_oui_i,
+       manuf_name_i,
+       manuf_prodname_i,
+       manuf_prodver_i,
+};
+
+/** KEY_TYPE_ID */
+enum KEY_TYPE_ID {
+       KEY_TYPE_ID_WEP = 0,
+       KEY_TYPE_ID_TKIP,
+       KEY_TYPE_ID_AES
+};
+
+/** KEY_INFO_WPA (applies to both TKIP and AES/CCMP) */
+enum KEY_INFO_WPA {
+       KEY_INFO_WPA_MCAST = 0x01,
+       KEY_INFO_WPA_UNICAST = 0x02,
+       KEY_INFO_WPA_ENABLED = 0x04
+};
+
+/** SNMP_MIB_VALUE_e */
+enum SNMP_MIB_VALUE_e {
+       SNMP_MIB_VALUE_INFRA = 1,
+       SNMP_MIB_VALUE_ADHOC
+};
+
+/* Default values for fwt commands. */
+#define FWT_DEFAULT_METRIC 0
+#define FWT_DEFAULT_DIR 1
+#define FWT_DEFAULT_SSN 0xffffffff
+#define FWT_DEFAULT_DSN 0
+#define FWT_DEFAULT_HOPCOUNT 0
+#define FWT_DEFAULT_TTL 0
+#define FWT_DEFAULT_EXPIRATION 0
+#define FWT_DEFAULT_SLEEPMODE 0
+#define FWT_DEFAULT_SNR 0
+
+#endif                         /* _WLAN_DEFS_H_ */
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
new file mode 100644 (file)
index 0000000..b1f876f
--- /dev/null
@@ -0,0 +1,403 @@
+/**
+  * This file contains definitions and data structures specific
+  * to Marvell 802.11 NIC. It contains the Device Information
+  * structure wlan_adapter.
+  */
+#ifndef _WLAN_DEV_H_
+#define _WLAN_DEV_H_
+
+#include <linux/netdevice.h>
+#include <linux/wireless.h>
+#include <linux/ethtool.h>
+#include <linux/debugfs.h>
+
+#include "defs.h"
+#include "scan.h"
+#include "thread.h"
+
+extern struct ethtool_ops libertas_ethtool_ops;
+
+#define        MAX_BSSID_PER_CHANNEL           16
+
+#define NR_TX_QUEUE                    3
+
+/* For the extended Scan */
+#define MAX_EXTENDED_SCAN_BSSID_LIST    MAX_BSSID_PER_CHANNEL * \
+                                               MRVDRV_MAX_CHANNEL_SIZE + 1
+
+#define        MAX_REGION_CHANNEL_NUM  2
+
+/** Chan-freq-TxPower mapping table*/
+struct chan_freq_power {
+       /** channel Number              */
+       u16 channel;
+       /** frequency of this channel   */
+       u32 freq;
+       /** Max allowed Tx power level  */
+       u16 maxtxpower;
+       /** TRUE:channel unsupported;  FLASE:supported*/
+       u8 unsupported;
+};
+
+/** region-band mapping table*/
+struct region_channel {
+       /** TRUE if this entry is valid              */
+       u8 valid;
+       /** region code for US, Japan ...            */
+       u8 region;
+       /** band B/G/A, used for BAND_CONFIG cmd             */
+       u8 band;
+       /** Actual No. of elements in the array below */
+       u8 nrcfp;
+       /** chan-freq-txpower mapping table*/
+       struct chan_freq_power *CFP;
+};
+
+struct wlan_802_11_security {
+       u8 WPAenabled;
+       u8 WPA2enabled;
+       enum WLAN_802_11_WEP_STATUS WEPstatus;
+       enum WLAN_802_11_AUTHENTICATION_MODE authmode;
+       enum WLAN_802_1X_AUTH_ALG auth1xalg;
+       enum WLAN_802_11_ENCRYPTION_MODE Encryptionmode;
+};
+
+/** Current Basic Service Set State Structure */
+struct current_bss_params {
+       struct bss_descriptor bssdescriptor;
+       /** bssid */
+       u8 bssid[ETH_ALEN];
+       /** ssid */
+       struct WLAN_802_11_SSID ssid;
+
+       /** band */
+       u8 band;
+       /** channel */
+       u8 channel;
+       /** number of rates supported */
+       int numofrates;
+       /** supported rates*/
+       u8 datarates[WLAN_SUPPORTED_RATES];
+};
+
+/** sleep_params */
+struct sleep_params {
+       u16 sp_error;
+       u16 sp_offset;
+       u16 sp_stabletime;
+       u8 sp_calcontrol;
+       u8 sp_extsleepclk;
+       u16 sp_reserved;
+};
+
+/** Data structure for the Marvell WLAN device */
+typedef struct _wlan_dev {
+       /** device name */
+       char name[DEV_NAME_LEN];
+       /** card pointer */
+       void *card;
+       /** IO port */
+       u32 ioport;
+       /** Upload received */
+       u32 upld_rcv;
+       /** Upload type */
+       u32 upld_typ;
+       /** Upload length */
+       u32 upld_len;
+       /** netdev pointer */
+       struct net_device *netdev;
+       /* Upload buffer */
+       u8 upld_buf[WLAN_UPLD_SIZE];
+       /* Download sent:
+          bit0 1/0=data_sent/data_tx_done,
+          bit1 1/0=cmd_sent/cmd_tx_done,
+          all other bits reserved 0 */
+       u8 dnld_sent;
+} wlan_dev_t, *pwlan_dev_t;
+
+/* Mesh statistics */
+struct wlan_mesh_stats {
+       u32     fwd_bcast_cnt;          /* Fwd: Broadcast counter */
+       u32     fwd_unicast_cnt;        /* Fwd: Unicast counter */
+       u32     fwd_drop_ttl;           /* Fwd: TTL zero */
+       u32     fwd_drop_rbt;           /* Fwd: Recently Broadcasted */
+       u32     fwd_drop_noroute;       /* Fwd: No route to Destination */
+       u32     fwd_drop_nobuf;         /* Fwd: Run out of internal buffers */
+       u32     drop_blind;             /* Rx:  Dropped by blinding table */
+};
+
+/** Private structure for the MV device */
+struct _wlan_private {
+       int open;
+       int mesh_open;
+       int infra_open;
+
+       wlan_adapter *adapter;
+       wlan_dev_t wlan_dev;
+
+       struct net_device_stats stats;
+       struct net_device *mesh_dev ; /* Virtual device */
+
+       struct iw_statistics wstats;
+       struct wlan_mesh_stats mstats;
+       struct dentry *debugfs_dir;
+       struct dentry *debugfs_debug;
+       struct dentry *debugfs_files[6];
+
+       struct dentry *events_dir;
+       struct dentry *debugfs_events_files[6];
+
+       struct dentry *regs_dir;
+       struct dentry *debugfs_regs_files[6];
+
+       u32 mac_offset;
+       u32 bbp_offset;
+       u32 rf_offset;
+
+       const struct firmware *firmware;
+       struct device *hotplug_device;
+
+       /** thread to service interrupts */
+       struct wlan_thread mainthread;
+
+       struct delayed_work assoc_work;
+       struct workqueue_struct *assoc_thread;
+};
+
+/** Association request
+ *
+ * Encapsulates all the options that describe a specific assocation request
+ * or configuration of the wireless card's radio, mode, and security settings.
+ */
+struct assoc_request {
+#define ASSOC_FLAG_SSID                        1
+#define ASSOC_FLAG_CHANNEL             2
+#define ASSOC_FLAG_MODE                        3
+#define ASSOC_FLAG_BSSID               4
+#define ASSOC_FLAG_WEP_KEYS            5
+#define ASSOC_FLAG_WEP_TX_KEYIDX       6
+#define ASSOC_FLAG_WPA_MCAST_KEY       7
+#define ASSOC_FLAG_WPA_UCAST_KEY       8
+#define ASSOC_FLAG_SECINFO             9
+#define ASSOC_FLAG_WPA_IE              10
+       unsigned long flags;
+
+       struct WLAN_802_11_SSID ssid;
+       u8 channel;
+       enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode;
+       u8 bssid[ETH_ALEN];
+
+       /** WEP keys */
+       struct WLAN_802_11_KEY wep_keys[4];
+       u16 wep_tx_keyidx;
+
+       /** WPA keys */
+       struct WLAN_802_11_KEY wpa_mcast_key;
+       struct WLAN_802_11_KEY wpa_unicast_key;
+
+       struct wlan_802_11_security secinfo;
+
+       /** WPA Information Elements*/
+#define MAX_WPA_IE_LEN 64
+       u8 wpa_ie[MAX_WPA_IE_LEN];
+       u8 wpa_ie_len;
+};
+
+/** Wlan adapter data structure*/
+struct _wlan_adapter {
+       /** STATUS variables */
+       u32 fwreleasenumber;
+       u32 fwcapinfo;
+       /* protected with big lock */
+
+       struct mutex lock;
+
+       u8 tmptxbuf[WLAN_UPLD_SIZE];
+       /* protected by hard_start_xmit serialization */
+
+       /** command-related variables */
+       u16 seqnum;
+       /* protected by big lock */
+
+       struct cmd_ctrl_node *cmd_array;
+       /** Current command */
+       struct cmd_ctrl_node *cur_cmd;
+       int cur_cmd_retcode;
+       /** command Queues */
+       /** Free command buffers */
+       struct list_head cmdfreeq;
+       /** Pending command buffers */
+       struct list_head cmdpendingq;
+
+       wait_queue_head_t cmd_pending;
+       u8 nr_cmd_pending;
+       /* command related variables protected by adapter->driver_lock */
+
+       /** Async and Sync Event variables */
+       u32 intcounter;
+       u32 eventcause;
+       u8 nodename[16];        /* nickname */
+
+       /** spin locks */
+       spinlock_t driver_lock;
+
+       /** Timers */
+       struct timer_list command_timer;
+
+       /* TX queue used in PS mode */
+       spinlock_t txqueue_lock;
+       struct sk_buff *tx_queue_ps[NR_TX_QUEUE];
+       unsigned int tx_queue_idx;
+
+       u8 hisregcpy;
+
+       /** current ssid/bssid related parameters*/
+       struct current_bss_params curbssparams;
+
+       enum WLAN_802_11_NETWORK_INFRASTRUCTURE inframode;
+
+       struct bss_descriptor *pattemptedbssdesc;
+
+       struct WLAN_802_11_SSID previousssid;
+       u8 previousbssid[ETH_ALEN];
+
+       struct bss_descriptor *scantable;
+       u32 numinscantable;
+
+       u8 scantype;
+       u32 scanmode;
+
+       u16 beaconperiod;
+       u8 adhoccreate;
+
+       /** capability Info used in Association, start, join */
+       struct ieeetypes_capinfo capinfo;
+
+       /** MAC address information */
+       u8 current_addr[ETH_ALEN];
+       u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
+       u32 nr_of_multicastmacaddr;
+
+       /** 802.11 statistics */
+//     struct cmd_DS_802_11_GET_STAT wlan802_11Stat;
+
+       u16 enablehwauto;
+       u16 ratebitmap;
+       /** control G rates */
+       u8 adhoc_grate_enabled;
+
+       u32 txantenna;
+       u32 rxantenna;
+
+       u8 adhocchannel;
+       u32 fragthsd;
+       u32 rtsthsd;
+
+       u32 datarate;
+       u8 is_datarate_auto;
+
+       u16 listeninterval;
+       u16 prescan;
+       u8 txretrycount;
+
+       /** Tx-related variables (for single packet tx) */
+       struct sk_buff *currenttxskb;
+       u16 TxLockFlag;
+
+       /** NIC Operation characteristics */
+       u16 currentpacketfilter;
+       u32 connect_status;
+       u16 regioncode;
+       u16 regiontableindex;
+       u16 txpowerlevel;
+
+       /** POWER MANAGEMENT AND PnP SUPPORT */
+       u8 surpriseremoved;
+       u16 atimwindow;
+
+       u16 psmode;             /* Wlan802_11PowermodeCAM=disable