[PATCH] libertas: split ioctl handling from wireless extensions

Arnd Bergmann arnd at arndb.de
Wed Jul 5 15:48:43 EDT 2006


The wlan_wext.c file implements two sets of interfaces: the generic
wireless extensions that are common to all drivers and its own
set of ioctls, which is rather broken by design.

This patch moves the private ioctl handlers into a different
file so it becomes easier to tell the difference.

I've done some minor reformatting where I absolutely couldn't
resist, but the functionality should not change at all.

The patch applies on top of the previous set of cleanups, which
still appears to be stuck in moderation.

Signed-off-by: Arnd Bergmann <arnd at arndb.de>

Index: linus-2.6/drivers/net/wireless/libertas/Makefile
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/Makefile
+++ linus-2.6/drivers/net/wireless/libertas/Makefile
@@ -4,7 +4,7 @@ usb8xxx-objs := wlan_main.o wlan_fw.o wl
 		wlan_rx.o wlan_tx.o \
 		wlan_cmd.o wlan_cmdresp.o \
 		wlan_proc.o wlan_scan.o wlan_join.o \
-		wlan_11d.o
+		wlan_11d.o wlan_ioctl.o
 
 ifeq ($(CONFIG_LIBERTAS_USB_DEBUG), y)
 usb8xxx-objs += wlan_debug.o
Index: linus-2.6/drivers/net/wireless/libertas/wlan_ioctl.c
===================================================================
--- /dev/null
+++ linus-2.6/drivers/net/wireless/libertas/wlan_ioctl.c
@@ -0,0 +1,2776 @@
+/** @file  wlan_wext.c
+  * @brief This file contains ioctl functions
+  *
+  * (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.
+  *
+  */
+
+/*
+ * Editor's comment:
+ *
+ * This whole file is a total mess, the author needs some education
+ * about ioctl handling.
+ *
+ * For now it probably needs to stay in order not to break existing
+ * tools, but we need to come up with some proper replacement for
+ * those calls that are actually needed.
+ *
+ * 	-arnd
+ */
+
+#include <linux/ctype.h>
+#include <linux/delay.h>
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/wireless.h>
+
+#include <net/iw_handler.h>
+
+#include "host.h"
+#include "radiotap.h"
+#include "wlan_decl.h"
+#include "wlan_defs.h"
+#include "wlan_dev.h"
+#include "wlan_join.h"
+#include "wlan_wext.h"
+
+#define MAX_SCAN_CELL_SIZE      (IW_EV_ADDR_LEN + \
+				MRVDRV_MAX_SSID_LENGTH + \
+				IW_EV_UINT_LEN + IW_EV_FREQ_LEN + \
+				IW_EV_QUAL_LEN + MRVDRV_MAX_SSID_LENGTH + \
+				IW_EV_PARAM_LEN + 40)	/* 40 for WPAIE */
+
+#define WAIT_FOR_SCAN_RRESULT_MAX_TIME (10 * HZ)
+
+/**
+ *  @brief Set RX Antenna
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param Mode			RF antenna mode
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int SetRxAntenna(wlan_private * priv, int Mode)
+{
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_adapter *Adapter = priv->adapter;
+
+	if (Mode != RF_ANTENNA_1 && Mode != RF_ANTENNA_2
+	    && Mode != RF_ANTENNA_AUTO) {
+		return -EINVAL;
+	}
+
+	Adapter->RxAntennaMode = Mode;
+
+	PRINTM(INFO, "SET RX Antenna Mode to 0x%04x\n", Adapter->RxAntennaMode);
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
+				    HostCmd_ACT_SET_RX,
+				    HostCmd_OPTION_WAITFORRSP, 0,
+				    &Adapter->RxAntennaMode);
+	return ret;
+}
+
+/**
+ *  @brief Set TX Antenna
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param Mode			RF antenna mode
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int SetTxAntenna(wlan_private * priv, int Mode)
+{
+	int ret = 0;
+	wlan_adapter *Adapter = priv->adapter;
+
+	if ((Mode != RF_ANTENNA_1) && (Mode != RF_ANTENNA_2)
+	    && (Mode != RF_ANTENNA_AUTO)) {
+		return -EINVAL;
+	}
+
+	Adapter->TxAntennaMode = Mode;
+
+	PRINTM(INFO, "SET TX Antenna Mode to 0x%04x\n", Adapter->TxAntennaMode);
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
+				    HostCmd_ACT_SET_TX,
+				    HostCmd_OPTION_WAITFORRSP, 0,
+				    &Adapter->TxAntennaMode);
+
+	return ret;
+}
+
+/**
+ *  @brief Get RX Antenna
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param buf			A pointer to recieve antenna mode
+ *  @return 	   		length of buf
+ */
+static int GetRxAntenna(wlan_private * priv, char *buf)
+{
+	int ret = 0;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	// clear it, so we will know if the value
+	// returned below is correct or not.
+	Adapter->RxAntennaMode = 0;
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
+				    HostCmd_ACT_GET_RX,
+				    HostCmd_OPTION_WAITFORRSP, 0, NULL);
+
+	if (ret) {
+		LEAVE();
+		return ret;
+	}
+
+	PRINTM(INFO, "Get Rx Antenna Mode:0x%04x\n", Adapter->RxAntennaMode);
+
+	LEAVE();
+
+	return sprintf(buf, "0x%04x", Adapter->RxAntennaMode) + 1;
+}
+
+/**
+ *  @brief Get TX Antenna
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param buf			A pointer to recieve antenna mode
+ *  @return 	   		length of buf
+ */
+static int GetTxAntenna(wlan_private * priv, char *buf)
+{
+	int ret = 0;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	// clear it, so we will know if the value
+	// returned below is correct or not.
+	Adapter->TxAntennaMode = 0;
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
+				    HostCmd_ACT_GET_TX,
+				    HostCmd_OPTION_WAITFORRSP, 0, NULL);
+
+	if (ret) {
+		LEAVE();
+		return ret;
+	}
+
+	PRINTM(INFO, "Get Tx Antenna Mode:0x%04x\n", Adapter->TxAntennaMode);
+
+	LEAVE();
+
+	return sprintf(buf, "0x%04x", Adapter->TxAntennaMode) + 1;
+}
+
+/**
+ *  @brief Set Region
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param region_code		region code
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set_region(wlan_private * priv, u16 region_code)
+{
+	int i;
+
+	ENTER();
+
+	for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
+		// use the region code to search for the index
+		if (region_code == libertas_region_code_to_index[i]) {
+			priv->adapter->RegionTableIndex = (u16) i;
+			priv->adapter->RegionCode = region_code;
+			break;
+		}
+	}
+
+	// if it's unidentified region code
+	if (i >= MRVDRV_MAX_REGION_CODE) {
+		PRINTM(INFO, "Region Code not identified\n");
+		LEAVE();
+		return WLAN_STATUS_FAILURE;
+	}
+
+	if (libertas_set_regiontable(priv, priv->adapter->RegionCode, 0)) {
+		LEAVE();
+		return -EINVAL;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get/Set Firmware wakeup method
+ *
+ *  @param priv		A pointer to wlan_private structure
+ *  @param wrq	   	A pointer to user data
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+static int wlan_txcontrol(wlan_private * priv, struct iwreq *wrq)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	int data;
+	ENTER();
+
+	if ((int)wrq->u.data.length == 0) {
+		if (copy_to_user
+		    (wrq->u.data.pointer, &Adapter->PktTxCtrl, sizeof(u32))) {
+			PRINTM(MSG, "copy_to_user failed!\n");
+			return -EFAULT;
+		}
+	} else {
+		if ((int)wrq->u.data.length > 1) {
+			PRINTM(MSG, "ioctl too many args!\n");
+			return -EFAULT;
+		}
+		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		Adapter->PktTxCtrl = (u32) data;
+	}
+
+	wrq->u.data.length = 1;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get/Set NULL Package generation interval
+ *
+ *  @param priv		A pointer to wlan_private structure
+ *  @param wrq	   	A pointer to user data
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+static int wlan_null_pkt_interval(wlan_private * priv, struct iwreq *wrq)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	int data;
+	ENTER();
+
+	if ((int)wrq->u.data.length == 0) {
+		data = Adapter->NullPktInterval;
+
+		if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
+			PRINTM(MSG, "copy_to_user failed!\n");
+			return -EFAULT;
+		}
+	} else {
+		if ((int)wrq->u.data.length > 1) {
+			PRINTM(MSG, "ioctl too many args!\n");
+			return -EFAULT;
+		}
+		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		Adapter->NullPktInterval = data;
+	}
+
+	wrq->u.data.length = 1;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief wlan hostcmd ioctl handler
+ *
+ *  @param dev                  A pointer to net_device structure
+ *  @param req		        A pointer to ifreq structure
+ *  @param cmd			command
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_hostcmd_ioctl(struct net_device *dev, struct ifreq *req,
+			      int cmd)
+{
+	u8 *tempResponseBuffer;
+	struct CmdCtrlNode *pCmdNode;
+	struct HostCmd_DS_GEN *gencmd, *pCmdPtr;
+	wlan_private *priv = dev->priv;
+	wlan_adapter *Adapter = priv->adapter;
+	u16 wait_option = 0;
+
+	ENTER();
+
+	/*
+	 * Get a free command control node
+	 */
+	if (!(pCmdNode = libertas_get_free_cmd_ctrl_node(priv))) {
+		PRINTM(INFO, "Failed libertas_get_free_cmd_ctrl_node\n");
+		return -ENOMEM;
+	}
+
+	if (!(tempResponseBuffer = kmalloc(3000, GFP_KERNEL))) {
+		PRINTM(INFO, "ERROR: Failed to allocate response buffer!\n");
+		return -ENOMEM;
+	}
+
+	wait_option |= HostCmd_OPTION_WAITFORRSP;
+
+	libertas_set_cmd_ctrl_node(priv, pCmdNode, 0, wait_option, NULL);
+	init_waitqueue_head(&pCmdNode->cmdwait_q);
+
+	pCmdPtr = (struct HostCmd_DS_GEN *)pCmdNode->BufVirtualAddr;
+	gencmd = (struct HostCmd_DS_GEN *)req->ifr_data;
+
+	/*
+	 * Copy the whole command into the command buffer
+	 */
+	if (copy_from_user(pCmdPtr, req->ifr_data, gencmd->Size)) {
+		PRINTM(INFO, "Copy from user failed\n");
+		kfree(tempResponseBuffer);
+		return -EFAULT;
+	}
+
+	pCmdNode->pdata_buf = tempResponseBuffer;
+	pCmdNode->CmdFlags |= CMD_F_HOSTCMD;
+
+	pCmdPtr->SeqNum = ++priv->adapter->SeqNum;
+	pCmdPtr->Result = 0;
+
+	PRINTM(INFO, "HOSTCMD Command: 0x%04x Size: %d SeqNum: %d\n",
+	       pCmdPtr->Command, pCmdPtr->Size, pCmdPtr->SeqNum);
+	HEXDUMP("Command Data", (u8 *) (pCmdPtr),
+		min_t(u16, 32, pCmdPtr->Size));
+	PRINTM(INFO, "Copying data from : (user)0x%p -> 0x%p(driver)\n",
+	       req->ifr_data, pCmdPtr);
+
+	pCmdNode->CmdWaitQWoken = 0;
+	libertas_queue_cmd(Adapter, pCmdNode, 1);
+	wake_up_interruptible(&priv->MainThread.waitQ);
+
+	if (wait_option & HostCmd_OPTION_WAITFORRSP) {
+		/* Sleep until response is generated by FW */
+		wait_event_interruptible(pCmdNode->cmdwait_q,
+					 pCmdNode->CmdWaitQWoken);
+	}
+
+	/* Copy the response back to user space */
+	pCmdPtr = (struct HostCmd_DS_GEN *)tempResponseBuffer;
+
+	if (copy_to_user(req->ifr_data, tempResponseBuffer, pCmdPtr->Size))
+		PRINTM(INFO, "ERROR: copy_to_user failed!\n");
+
+	kfree(tempResponseBuffer);
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get Rx Info
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wreq		        A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success
+ */
+static int wlan_get_rxinfo(wlan_private * priv, struct iwreq *wrq)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	int data[2];
+	ENTER();
+	data[0] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
+	data[1] = Adapter->RxPDRate;
+	if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
+		PRINTM(INFO, "Copy to user failed\n");
+		return -EFAULT;
+	}
+	wrq->u.data.length = 2;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get SNR
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wreq		        A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_get_snr(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_adapter *Adapter = priv->adapter;
+	int data[4];
+
+	ENTER();
+	memset(data, 0, sizeof(data));
+	if (wrq->u.data.length) {
+		if (copy_from_user
+		    (data, wrq->u.data.pointer,
+		     min_t(size_t, wrq->u.data.length, 4) * sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+	}
+	if ((wrq->u.data.length == 0) || (data[0] == 0) || (data[0] == 1)) {
+		if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
+			ret = libertas_prepare_and_send_command(priv,
+						    HostCmd_CMD_802_11_RSSI,
+						    0,
+						    HostCmd_OPTION_WAITFORRSP,
+						    0, NULL);
+
+			if (ret) {
+				LEAVE();
+				return ret;
+			}
+		}
+	}
+
+	if (wrq->u.data.length == 0) {
+		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
+		data[1] = Adapter->SNR[TYPE_BEACON][TYPE_AVG];
+		data[2] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
+		data[3] = Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 4)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = 4;
+	} else if (data[0] == 0) {
+		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = 1;
+	} else if (data[0] == 1) {
+		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_AVG];
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = 1;
+	} else if (data[0] == 2) {
+		data[0] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = 1;
+	} else if (data[0] == 3) {
+		data[0] = Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = 1;
+	} else {
+		return -ENOTSUPP;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get/Set Adhoc beacon Interval
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wreq		        A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_beacon_interval(wlan_private * priv, struct iwreq *wrq)
+{
+	int data;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	if (wrq->u.data.length > 0) {
+		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		PRINTM(INFO, "WLAN SET BEACON INTERVAL: %d\n", data);
+		if ((data > MRVDRV_MAX_BEACON_INTERVAL)
+		    || (data < MRVDRV_MIN_BEACON_INTERVAL))
+			return -ENOTSUPP;
+		Adapter->BeaconPeriod = data;
+	}
+	data = Adapter->BeaconPeriod;
+	if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
+		PRINTM(INFO, "Copy to user failed\n");
+		return -EFAULT;
+	}
+
+	wrq->u.data.length = 1;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get RSSI
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wreq		        A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_get_rssi(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_adapter *Adapter = priv->adapter;
+	int temp;
+	int data = 0;
+	int *val;
+
+	ENTER();
+	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	if ((data == 0) || (data == 1)) {
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_RSSI,
+					    0, HostCmd_OPTION_WAITFORRSP,
+					    0, NULL);
+		if (ret) {
+			LEAVE();
+			return ret;
+		}
+	}
+
+	switch (data) {
+	case 0:
+
+		temp = CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
+				Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
+		break;
+	case 1:
+		temp = CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_AVG],
+				Adapter->NF[TYPE_BEACON][TYPE_AVG]);
+		break;
+	case 2:
+		temp = CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_NOAVG],
+				Adapter->NF[TYPE_RXPD][TYPE_NOAVG]);
+		break;
+	case 3:
+		temp = CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
+				Adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
+		break;
+	default:
+		return -ENOTSUPP;
+	}
+	val = (int *)wrq->u.name;
+	*val = temp;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get NF
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wreq		        A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_get_nf(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_adapter *Adapter = priv->adapter;
+	int temp;
+	int data = 0;
+	int *val;
+
+	ENTER();
+	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	if ((data == 0) || (data == 1)) {
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_RSSI,
+					    0, HostCmd_OPTION_WAITFORRSP,
+					    0, NULL);
+
+		if (ret) {
+			LEAVE();
+			return ret;
+		}
+	}
+
+	switch (data) {
+	case 0:
+		temp = Adapter->NF[TYPE_BEACON][TYPE_NOAVG];
+		break;
+	case 1:
+		temp = Adapter->NF[TYPE_BEACON][TYPE_AVG];
+		break;
+	case 2:
+		temp = Adapter->NF[TYPE_RXPD][TYPE_NOAVG];
+		break;
+	case 3:
+		temp = Adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
+		break;
+	default:
+		return -ENOTSUPP;
+	}
+
+	temp = CAL_NF(temp);
+
+	PRINTM(INFO, "***temp = %d\n", temp);
+	val = (int *)wrq->u.name;
+	*val = temp;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get TxRate
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_get_txrate_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	int *pdata;
+	struct iwreq *wrq = (struct iwreq *)req;
+	int ret = WLAN_STATUS_SUCCESS;
+	ENTER();
+	Adapter->TxRate = 0;
+	PRINTM(INFO, "wlan_get_txrate_ioctl\n");
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
+				    HostCmd_ACT_GET, HostCmd_OPTION_WAITFORRSP,
+				    0, NULL);
+	if (ret) {
+		LEAVE();
+		return ret;
+	}
+	pdata = (int *)wrq->u.name;
+	*pdata = (int)Adapter->TxRate;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get Adhoc Status
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_get_adhoc_status_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	char status[64];
+	wlan_adapter *Adapter = priv->adapter;
+
+	memset(status, 0, sizeof(status));
+
+	switch (Adapter->InfrastructureMode) {
+	case Wlan802_11IBSS:
+		if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
+			if (Adapter->AdhocCreate)
+				memcpy(&status, "AdhocStarted", sizeof(status));
+			else
+				memcpy(&status, "AdhocJoined", sizeof(status));
+		} else {
+			memcpy(&status, "AdhocIdle", sizeof(status));
+		}
+		break;
+	case Wlan802_11Infrastructure:
+		memcpy(&status, "InfraMode", sizeof(status));
+		break;
+	default:
+		memcpy(&status, "AutoUnknownMode", sizeof(status));
+		break;
+	}
+
+	PRINTM(INFO, "Status = %s\n", status);
+	wrq->u.data.length = strlen(status) + 1;
+
+	if (wrq->u.data.pointer) {
+		if (copy_to_user(wrq->u.data.pointer,
+				 &status, wrq->u.data.length))
+			return -EFAULT;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get Driver Version
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_version_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int len;
+	char buf[128];
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	libertas_get_version(priv->adapter, buf, sizeof(buf) - 1);
+
+	len = strlen(buf);
+	if (wrq->u.data.pointer) {
+		if (copy_to_user(wrq->u.data.pointer, buf, len)) {
+			PRINTM(INFO, "CopyToUser failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = len;
+	}
+
+	PRINTM(INFO, "wlan version: %s\n", buf);
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Read/Write adapter registers
+ *
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_regrdwr_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	wlan_ioctl_regrdwr regrdwr;
+	struct wlan_offset_value offval;
+	wlan_adapter *Adapter = priv->adapter;
+	int ret = WLAN_STATUS_SUCCESS;
+
+	ENTER();
+
+	if (copy_from_user(&regrdwr, req->ifr_data, sizeof(regrdwr))) {
+		PRINTM(INFO,
+		       "copy of regrdwr for wlan_regrdwr_ioctl from user failed \n");
+		LEAVE();
+		return -EFAULT;
+	}
+
+	if (regrdwr.WhichReg == REG_EEPROM) {
+		PRINTM(MSG, "Inside RDEEPROM\n");
+		Adapter->pRdeeprom =
+		    (char *)kmalloc((regrdwr.NOB + sizeof(regrdwr)),
+				    GFP_KERNEL);
+		if (!Adapter->pRdeeprom)
+			return -ENOMEM;
+		memcpy(Adapter->pRdeeprom, &regrdwr, sizeof(regrdwr));
+		/* +14 is for Action, Offset, and NOB in
+		 * response */
+		PRINTM(INFO, "Action:%d Offset: %x NOB: %02x\n",
+		       regrdwr.Action, regrdwr.Offset, regrdwr.NOB);
+
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_EEPROM_ACCESS,
+					    regrdwr.Action,
+					    HostCmd_OPTION_WAITFORRSP, 0,
+					    &regrdwr);
+
+		if (ret) {
+			if (Adapter->pRdeeprom)
+				kfree(Adapter->pRdeeprom);
+			LEAVE();
+			return ret;
+		}
+
+		mdelay(10);
+
+		/*
+		 * Return the result back to the user
+		 */
+
+		if (regrdwr.Action == HostCmd_ACT_GEN_READ) {
+			if (copy_to_user
+			    (req->ifr_data, Adapter->pRdeeprom,
+			     sizeof(regrdwr) + regrdwr.NOB)) {
+				if (Adapter->pRdeeprom)
+					kfree(Adapter->pRdeeprom);
+				PRINTM(INFO,
+				       "copy of regrdwr for wlan_regrdwr_ioctl to user failed \n");
+				LEAVE();
+				return -EFAULT;
+			}
+		}
+
+		if (Adapter->pRdeeprom)
+			kfree(Adapter->pRdeeprom);
+
+		return WLAN_STATUS_SUCCESS;
+	}
+
+	offval.offset = regrdwr.Offset;
+	offval.value = (regrdwr.Action) ? regrdwr.Value : 0x00;
+
+	PRINTM(INFO, "RegAccess: %02x Action:%d "
+	       "Offset: %04x Value: %04x\n",
+	       regrdwr.WhichReg, regrdwr.Action, offval.offset, offval.value);
+
+	/*
+	 * regrdwr.WhichReg should contain the command that
+	 * corresponds to which register access is to be
+	 * performed HostCmd_CMD_MAC_REG_ACCESS 0x0019
+	 * HostCmd_CMD_BBP_REG_ACCESS 0x001a
+	 * HostCmd_CMD_RF_REG_ACCESS 0x001b
+	 */
+	ret = libertas_prepare_and_send_command(priv, regrdwr.WhichReg,
+				    regrdwr.Action, HostCmd_OPTION_WAITFORRSP,
+				    0, &offval);
+
+	if (ret) {
+		LEAVE();
+		return ret;
+	}
+
+	mdelay(10);
+
+	/*
+	 * Return the result back to the user
+	 */
+	regrdwr.Value = Adapter->OffsetValue.value;
+	if (regrdwr.Action == HostCmd_ACT_GEN_READ) {
+		if (copy_to_user(req->ifr_data, &regrdwr, sizeof(regrdwr))) {
+			PRINTM(INFO,
+			       "copy of regrdwr for wlan_regrdwr_ioctl to user failed \n");
+			LEAVE();
+			return -EFAULT;
+		}
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set/Get WPA IE
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_setwpaie_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	wlan_adapter *Adapter = priv->adapter;
+	int ret = WLAN_STATUS_SUCCESS;
+
+	ENTER();
+
+	if (wrq->u.data.length) {
+		if (wrq->u.data.length > sizeof(Adapter->Wpa_ie)) {
+			PRINTM(INFO, "failed to copy WPA IE, too big \n");
+			return -EFAULT;
+		}
+		if (copy_from_user(Adapter->Wpa_ie, wrq->u.data.pointer,
+				   wrq->u.data.length)) {
+			PRINTM(INFO, "failed to copy WPA IE \n");
+			return -EFAULT;
+		}
+		Adapter->Wpa_ie_len = wrq->u.data.length;
+		PRINTM(INFO, "Set Wpa_ie_len=%d IE=%#x\n", Adapter->Wpa_ie_len,
+		       Adapter->Wpa_ie[0]);
+		HEXDUMP("Wpa_ie", Adapter->Wpa_ie, Adapter->Wpa_ie_len);
+		if (Adapter->Wpa_ie[0] == WPA_IE)
+			Adapter->SecInfo.WPAEnabled = 1;
+		else if (Adapter->Wpa_ie[0] == WPA2_IE)
+			Adapter->SecInfo.WPA2Enabled = 1;
+		else {
+			Adapter->SecInfo.WPAEnabled = 0;
+			Adapter->SecInfo.WPA2Enabled = 0;
+		}
+	} else {
+		memset(Adapter->Wpa_ie, 0, sizeof(Adapter->Wpa_ie));
+		Adapter->Wpa_ie_len = wrq->u.data.length;
+		PRINTM(INFO, "Reset Wpa_ie_len=%d IE=%#x\n",
+		       Adapter->Wpa_ie_len, Adapter->Wpa_ie[0]);
+		Adapter->SecInfo.WPAEnabled = 0;
+		Adapter->SecInfo.WPA2Enabled = 0;
+	}
+
+	// enable/disable RSN in firmware if WPA is enabled/disabled
+	// depending on variable Adapter->SecInfo.WPAEnabled is set or not
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_ENABLE_RSN,
+				    HostCmd_ACT_SET, HostCmd_OPTION_WAITFORRSP,
+				    0, NULL);
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Set Auto Prescan
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_subcmd_setprescan_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	int data;
+	wlan_adapter *Adapter = priv->adapter;
+	int *val;
+
+	ENTER();
+
+	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	PRINTM(INFO, "WLAN_SUBCMD_SET_PRESCAN %d\n", data);
+	switch (data) {
+	case CMD_ENABLED:
+		Adapter->Prescan = 1;
+		break;
+	case CMD_DISABLED:
+		Adapter->Prescan = 0;
+		break;
+	default:
+		break;
+	}
+
+	data = Adapter->Prescan;
+	val = (int *)wrq->u.name;
+	*val = data;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set multiple dtim
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set_multiple_dtim_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	u32 mdtim;
+	int idata;
+	int ret = -EINVAL;
+
+	ENTER();
+
+	idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	mdtim = (u32) idata;
+	if (((mdtim >= MRVDRV_MIN_MULTIPLE_DTIM)
+	     && (mdtim <= MRVDRV_MAX_MULTIPLE_DTIM))
+	    || (mdtim == MRVDRV_IGNORE_MULTIPLE_DTIM)) {
+		priv->adapter->MultipleDtim = mdtim;
+		ret = WLAN_STATUS_SUCCESS;
+	}
+	if (ret)
+		PRINTM(INFO, "Invalid parameter, MultipleDtim not changed.\n");
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Set authentication mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_setauthalg_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int alg;
+	struct iwreq *wrq = (struct iwreq *)req;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	if (wrq->u.data.flags == 0) {
+		//from iwpriv subcmd
+		alg = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	} else {
+		//from wpa_supplicant subcmd
+		if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(alg))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+	}
+
+	PRINTM(INFO, "auth alg is %#x\n", alg);
+
+	switch (alg) {
+	case AUTH_ALG_SHARED_KEY:
+		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeShared;
+		break;
+	case AUTH_ALG_NETWORK_EAP:
+		Adapter->SecInfo.AuthenticationMode =
+		    Wlan802_11AuthModeNetworkEAP;
+		break;
+	case AUTH_ALG_OPEN_SYSTEM:
+	default:
+		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeOpen;
+		break;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set 802.1x authentication mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set8021xauthalg_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int alg;
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	if (wrq->u.data.flags == 0) {
+		//from iwpriv subcmd
+		alg = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	} else {
+		//from wpa_supplicant subcmd
+		if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+	}
+	PRINTM(INFO, "802.1x auth alg is %#x\n", alg);
+	priv->adapter->SecInfo.Auth1XAlg = alg;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set Encryption mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_setencryptionmode_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int mode;
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	if (wrq->u.data.flags == 0) {
+		//from iwpriv subcmd
+		mode = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	} else {
+		//from wpa_supplicant subcmd
+		if (copy_from_user(&mode, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+	}
+	PRINTM(INFO, "encryption mode is %#x\n", mode);
+	priv->adapter->SecInfo.EncryptionMode = mode;
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+static void adjust_mtu(wlan_private * priv)
+{
+	int mtu_increment = 0;
+
+	if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
+		mtu_increment += sizeof(struct IEEE80211_Hdr);
+
+	if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP)
+		mtu_increment += max(sizeof(struct TxRadiotapHdr),
+				     sizeof(struct RxRadiotapHdr));
+	priv->wlan_dev.netdev->mtu = ETH_FRAME_LEN
+	    - sizeof(struct EthII_Hdr)
+	    + mtu_increment;
+}
+
+/**
+ *  @brief Set Link-Layer Layer mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set_linkmode_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int mode;
+
+	ENTER();
+
+	mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
+
+	switch (mode) {
+	case WLAN_LINKMODE_802_3:
+		priv->adapter->linkmode = mode;
+		break;
+	case WLAN_LINKMODE_802_11:
+		priv->adapter->linkmode = mode;
+		break;
+	default:
+		PRINTM(FATAL, "usb8388-5: invalid link-layer mode (%#x)\n",
+		       mode);
+		return WLAN_STATUS_NOT_ACCEPTED;
+		break;
+	}
+	PRINTM(INFO, "usb8388-5: link-layer mode is %#x\n", mode);
+
+	adjust_mtu(priv);
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set Radio Header mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set_radiomode_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int mode;
+
+	ENTER();
+
+	mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
+
+	switch (mode) {
+	case WLAN_RADIOMODE_NONE:
+		priv->adapter->radiomode = mode;
+		break;
+	case WLAN_RADIOMODE_RADIOTAP:
+		priv->adapter->radiomode = mode;
+		break;
+	default:
+		PRINTM(INFO, "usb8388-5: invalid radio header mode (%#x)\n",
+		       mode);
+		return WLAN_STATUS_NOT_ACCEPTED;
+		break;
+	}
+	PRINTM(INFO, "usb8388-5: radio-header mode is %#x\n", mode);
+
+	adjust_mtu(priv);
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Set Debug Header mode
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_set_debugmode_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	ENTER();
+	priv->adapter->debugmode = (int)((struct ifreq *)
+					 ((u8 *) req + 4))->ifr_data;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get Rx antenna
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_subcmd_getrxantenna_ioctl(wlan_private * priv,
+					  struct ifreq *req)
+{
+	int len;
+	char buf[8];
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	PRINTM(INFO, "WLAN_SUBCMD_GETRXANTENNA\n");
+	len = GetRxAntenna(priv, buf);
+
+	wrq->u.data.length = len;
+	if (wrq->u.data.pointer) {
+		if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
+			PRINTM(INFO, "CopyToUser failed\n");
+			return -EFAULT;
+		}
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get Tx antenna
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_subcmd_gettxantenna_ioctl(wlan_private * priv,
+					  struct ifreq *req)
+{
+	int len;
+	char buf[8];
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	PRINTM(INFO, "WLAN_SUBCMD_GETTXANTENNA\n");
+	len = GetTxAntenna(priv, buf);
+
+	wrq->u.data.length = len;
+	if (wrq->u.data.pointer) {
+		if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
+			PRINTM(INFO, "CopyToUser failed\n");
+			return -EFAULT;
+		}
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief Get the MAC TSF value from the firmware
+ *
+ *  @param priv         A pointer to wlan_private structure
+ *  @param wrq          A pointer to iwreq structure containing buffer
+ *                      space to store a TSF value retrieved from the firmware
+ *
+ *  @return             0 if successful; IOCTL error code otherwise
+ */
+static int wlan_get_tsf_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	u64 tsfVal;
+	int ret;
+
+	ENTER();
+
+	ret = libertas_prepare_and_send_command(priv,
+				    HostCmd_CMD_GET_TSF,
+				    0, HostCmd_OPTION_WAITFORRSP, 0, &tsfVal);
+
+	PRINTM(INFO, "IOCTL: Get TSF = 0x%016llx\n", tsfVal);
+
+	if (ret != WLAN_STATUS_SUCCESS) {
+		PRINTM(INFO, "IOCTL: Get TSF; Command exec failed\n");
+		ret = -EFAULT;
+	} else {
+		if (copy_to_user(wrq->u.data.pointer,
+				 &tsfVal,
+				 min_t(size_t, wrq->u.data.length,
+				     sizeof(tsfVal))) != 0) {
+
+			PRINTM(INFO, "IOCTL: Get TSF; Copy to user failed\n");
+			ret = -EFAULT;
+		} else {
+			ret = 0;
+		}
+	}
+
+	LEAVE();
+
+	return ret;
+}
+
+/**
+ *  @brief Get/Set sleep period
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_sleep_period(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret;
+	int data;
+	wlan_adapter *Adapter = priv->adapter;
+	struct HostCmd_DS_802_11_SLEEP_PERIOD sleeppd;
+
+	ENTER();
+
+	if (wrq->u.data.length > 1)
+		return -ENOTSUPP;
+
+	memset(&sleeppd, 0, sizeof(sleeppd));
+	memset(&Adapter->sleep_period, 0, sizeof(struct sleep_period));
+
+	if (wrq->u.data.length == 0) {
+		sleeppd.Action = wlan_cpu_to_le16(HostCmd_ACT_GEN_GET);
+	} else {
+		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		/* sleep period is between 0 or 10 ... 60 */
+		if ((data <= 60 && data >= 10) || (data == 0)) {
+			sleeppd.Action = wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
+			sleeppd.Period = data;
+		} else
+			return -EINVAL;
+	}
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_SLEEP_PERIOD,
+				    0, HostCmd_OPTION_WAITFORRSP,
+				    0, (void *)&sleeppd);
+
+	data = (int)Adapter->sleep_period.period;
+	if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
+		PRINTM(INFO, "Copy to user failed\n");
+		return -EFAULT;
+	}
+	wrq->u.data.length = 1;
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Get/Set adapt rate
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_adapt_rateset(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret;
+	wlan_adapter *Adapter = priv->adapter;
+	int data[2];
+
+	ENTER();
+	memset(data, 0, sizeof(data));
+	if (!wrq->u.data.length) {
+		PRINTM(INFO, "Get ADAPT RATE SET\n");
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
+					    HostCmd_ACT_GEN_GET,
+					    HostCmd_OPTION_WAITFORRSP, 0, NULL);
+		data[0] = Adapter->EnableHwAuto;
+		data[1] = Adapter->RateBitmap;
+		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+#define GET_TWO_INT	2
+		wrq->u.data.length = GET_TWO_INT;
+	} else {
+		PRINTM(INFO, "Set ADAPT RATE SET\n");
+		if (wrq->u.data.length > 2)
+			return -EINVAL;
+		if (copy_from_user
+		    (data, wrq->u.data.pointer,
+		     sizeof(int) * wrq->u.data.length)) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		Adapter->EnableHwAuto = data[0];
+		Adapter->RateBitmap = data[1];
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
+					    HostCmd_ACT_GEN_SET,
+					    HostCmd_OPTION_WAITFORRSP, 0, NULL);
+	}
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Get/Set inactivity timeout
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_inactivity_timeout(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret;
+	int data = 0;
+	u16 timeout = 0;
+
+	ENTER();
+	if (wrq->u.data.length > 1)
+		return -ENOTSUPP;
+
+	if (wrq->u.data.length == 0) {
+		/* Get */
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_INACTIVITY_TIMEOUT,
+					    HostCmd_ACT_GET,
+					    HostCmd_OPTION_WAITFORRSP, 0,
+					    &timeout);
+		data = timeout;
+		if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+	} else {
+		/* Set */
+		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
+			PRINTM(INFO, "Copy from user failed\n");
+			return -EFAULT;
+		}
+
+		timeout = data;
+		ret = libertas_prepare_and_send_command(priv,
+					    HostCmd_CMD_802_11_INACTIVITY_TIMEOUT,
+					    HostCmd_ACT_SET,
+					    HostCmd_OPTION_WAITFORRSP, 0,
+					    &timeout);
+	}
+
+	wrq->u.data.length = 1;
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Get LOG
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param wrq			A pointer to iwreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_do_getlog_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret;
+	char buf[GETLOG_BUFSIZE - 1];
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	PRINTM(INFO, " GET STATS\n");
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_GET_LOG,
+				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
+
+	if (ret) {
+		LEAVE();
+		return ret;
+	}
+
+	if (wrq->u.data.pointer) {
+		sprintf(buf, "\n  mcasttxframe %u failed %u retry %u "
+			"multiretry %u framedup %u "
+			"rtssuccess %u rtsfailure %u ackfailure %u\n"
+			"rxfrag %u mcastrxframe %u fcserror %u "
+			"txframe %u wepundecryptable %u ",
+			Adapter->LogMsg.mcasttxframe,
+			Adapter->LogMsg.failed,
+			Adapter->LogMsg.retry,
+			Adapter->LogMsg.multiretry,
+			Adapter->LogMsg.framedup,
+			Adapter->LogMsg.rtssuccess,
+			Adapter->LogMsg.rtsfailure,
+			Adapter->LogMsg.ackfailure,
+			Adapter->LogMsg.rxfrag,
+			Adapter->LogMsg.mcastrxframe,
+			Adapter->LogMsg.fcserror,
+			Adapter->LogMsg.txframe,
+			Adapter->LogMsg.wepundecryptable);
+		wrq->u.data.length = strlen(buf) + 1;
+		if (copy_to_user(wrq->u.data.pointer, buf, wrq->u.data.length)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief config sleep parameters
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_sleep_params_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	int ret;
+	wlan_adapter *Adapter = priv->adapter;
+	wlan_ioctl_sleep_params_config sp;
+
+	ENTER();
+
+	memset(&sp, 0, sizeof(sp));
+
+	if (copy_from_user(&sp, wrq->u.data.pointer,
+			   min_t(size_t, sizeof(sp), wrq->u.data.length))) {
+		PRINTM(INFO, "Copy from user failed\n");
+		return -EFAULT;
+	}
+
+	memcpy(&Adapter->sp, &sp.Error, sizeof(struct sleep_params));
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_SLEEP_PARAMS,
+				    sp.Action, HostCmd_OPTION_WAITFORRSP,
+				    0, NULL);
+
+	if (!ret && !sp.Action && wrq->u.data.pointer) {
+		memcpy(&sp.Error, &Adapter->sp, sizeof(struct sleep_params));
+		if (copy_to_user(wrq->u.data.pointer, &sp, sizeof(sp))) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = sizeof(sp);
+	}
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Read the CIS Table
+ *  @param priv                 A pointer to wlan_private structure
+ *  @param req			A pointer to ifreq structure
+ *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_do_getcis_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int ret = WLAN_STATUS_SUCCESS;
+	struct iwreq *wrq = (struct iwreq *)req;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	if (wrq->u.data.pointer) {
+		if (copy_to_user(wrq->u.data.pointer, Adapter->CisInfoBuf,
+				 Adapter->CisInfoLen)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			return -EFAULT;
+		}
+		wrq->u.data.length = Adapter->CisInfoLen;
+	}
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Set scan type
+ *
+ *  @param priv		A pointer to wlan_private structure
+ *  @param wrq	   	A pointer to user data
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+static int wlan_scan_type_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	u8 buf[12];
+	u8 *option[] = { "active", "passive", "get", };
+	int i, max_options = (sizeof(option) / sizeof(option[0]));
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_adapter *Adapter = priv->adapter;
+
+	ENTER();
+
+	if (libertas_get_state_11d(priv) == ENABLE_11D) {
+		PRINTM(INFO, "11D: Cannot set scantype when 11D enabled\n");
+		return -EFAULT;
+	}
+
+	memset(buf, 0, sizeof(buf));
+
+	if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
+							 wrq->u.data.length))) {
+		PRINTM(INFO, "Copy from user failed\n");
+		return -EFAULT;
+	}
+
+	PRINTM(INFO, "Scan Type Option = %s\n", buf);
+
+	buf[sizeof(buf) - 1] = '\0';
+
+	for (i = 0; i < max_options; i++) {
+		if (!strcmp(buf, option[i]))
+			break;
+	}
+
+	switch (i) {
+	case 0:
+		Adapter->ScanType = HostCmd_SCAN_TYPE_ACTIVE;
+		break;
+	case 1:
+		Adapter->ScanType = HostCmd_SCAN_TYPE_PASSIVE;
+		break;
+	case 2:
+		wrq->u.data.length = strlen(option[Adapter->ScanType]) + 1;
+
+		if (copy_to_user(wrq->u.data.pointer,
+				 option[Adapter->ScanType],
+				 wrq->u.data.length)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			ret = -EFAULT;
+		}
+
+		break;
+	default:
+		PRINTM(INFO, "Invalid Scan Type Ioctl Option\n");
+		ret = -EINVAL;
+		break;
+	}
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Set scan mode
+ *
+ *  @param priv		A pointer to wlan_private structure
+ *  @param wrq	   	A pointer to user data
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+static int wlan_scan_mode_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	u8 buf[12];
+	u8 *option[] = { "bss", "ibss", "any", "get" };
+	int i, max_options = (sizeof(option) / sizeof(option[0]));
+	int ret = WLAN_STATUS_SUCCESS;
+
+	ENTER();
+
+	memset(buf, 0, sizeof(buf));
+
+	if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
+							 wrq->u.data.length))) {
+		PRINTM(INFO, "Copy from user failed\n");
+		return -EFAULT;
+	}
+
+	PRINTM(INFO, "Scan Mode Option = %s\n", buf);
+
+	buf[sizeof(buf) - 1] = '\0';
+
+	for (i = 0; i < max_options; i++) {
+		if (!strcmp(buf, option[i]))
+			break;
+	}
+
+	switch (i) {
+
+	case 0:
+		Adapter->ScanMode = HostCmd_BSS_TYPE_BSS;
+		break;
+	case 1:
+		Adapter->ScanMode = HostCmd_BSS_TYPE_IBSS;
+		break;
+	case 2:
+		Adapter->ScanMode = HostCmd_BSS_TYPE_ANY;
+		break;
+	case 3:
+
+		wrq->u.data.length = strlen(option[Adapter->ScanMode - 1]) + 1;
+
+		PRINTM(INFO, "Get Scan Mode Option = %s\n",
+		       option[Adapter->ScanMode - 1]);
+
+		PRINTM(INFO, "Scan Mode Length %d\n", wrq->u.data.length);
+
+		if (copy_to_user(wrq->u.data.pointer,
+				 option[Adapter->ScanMode - 1],
+				 wrq->u.data.length)) {
+			PRINTM(INFO, "Copy to user failed\n");
+			ret = -EFAULT;
+		}
+		PRINTM(INFO, "GET Scan Type Option after copy = %s\n",
+		       (char *)wrq->u.data.pointer);
+
+		break;
+
+	default:
+		PRINTM(INFO, "Invalid Scan Mode Ioctl Option\n");
+		ret = -EINVAL;
+		break;
+	}
+
+	LEAVE();
+	return ret;
+}
+
+/**
+ *  @brief Get/Set Adhoc G Rate
+ *
+ *  @param priv		A pointer to wlan_private structure
+ *  @param wrq	   	A pointer to user data
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+static int wlan_do_set_grate_ioctl(wlan_private * priv, struct iwreq *wrq)
+{
+	wlan_adapter *Adapter = priv->adapter;
+	int data, data1;
+	int *val;
+
+	ENTER();
+
+	data1 = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+	switch (data1) {
+	case 0:
+		Adapter->adhoc_grate_enabled = 0;
+		break;
+	case 1:
+		Adapter->adhoc_grate_enabled = 1;
+		break;
+	case 2:
+		break;
+	default:
+		return -EINVAL;
+	}
+	data = Adapter->adhoc_grate_enabled;
+	val = (int *)wrq->u.name;
+	*val = data;
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+static inline int hex2int(char c)
+{
+	if (c >= '0' && c <= '9')
+		return (c - '0');
+	if (c >= 'a' && c <= 'f')
+		return (c - 'a' + 10);
+	if (c >= 'A' && c <= 'F')
+		return (c - 'A' + 10);
+	return -1;
+}
+
+/* Convert a string representation of a MAC address ("xx:xx:xx:xx:xx:xx")
+   into binary format (6 bytes).
+
+   This function expects that each byte is represented with 2 characters
+   (e.g., 11:2:11:11:11:11 is invalid)
+
+ */
+static char *eth_str2addr(char *ethstr, u8 * addr)
+{
+	int i, val, val2;
+	char *pos = ethstr;
+
+	/* get rid of initial blanks */
+	while (*pos == ' ' || *pos == '\t')
+		++pos;
+
+	for (i = 0; i < 6; i++) {
+		val = hex2int(*pos++);
+		if (val < 0)
+			return NULL;
+		val2 = hex2int(*pos++);
+		if (val2 < 0)
+			return NULL;
+		addr[i] = (val * 16 + val2) & 0xff;
+
+		if (i < 5 && *pos++ != ':')
+			return NULL;
+	}
+	return pos;
+}
+
+/* this writes xx:xx:xx:xx:xx:xx into ethstr
+   (ethstr must have space for 18 chars) */
+static int eth_addr2str(u8 * addr, char *ethstr)
+{
+	int i;
+	char *pos = ethstr;
+
+	for (i = 0; i < 6; i++) {
+		sprintf(pos, "%02x", addr[i] & 0xff);
+		pos += 2;
+		if (i < 5)
+			*pos++ = ':';
+	}
+	return 17;
+}
+
+/**
+ *  @brief          Add an entry to the DFT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_dft_add_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	char ethaddrs_str[36];
+	char *pos;
+	u8 ethaddrs[2 * ETH_ALEN];
+#define ethaddr1 (ethaddrs+0)
+#define ethaddr2 (ethaddrs+6)
+
+	ENTER();
+	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
+			   sizeof(ethaddrs_str)))
+		return -EFAULT;
+
+	if ((pos = eth_str2addr(ethaddrs_str, ethaddr1)) == NULL) {
+		PRINTM(FATAL, "DFT_ADD: Invalid MAC address 1\n");
+		return -EINVAL;
+	}
+
+	if (eth_str2addr(pos, ethaddr2) == NULL) {
+		PRINTM(FATAL, "DFT_ADD: Invalid MAC address 2\n");
+		return -EINVAL;
+	}
+#ifdef DEBUG_LEVEL4
+	{
+		char ethaddr1_str[18], ethaddr2_str[18];
+		PRINTM(INFO, "DFT: adding %s\n", ethaddrs_str);
+		eth_addr2str(ethaddr1, ethaddr1_str);
+		eth_addr2str(ethaddr2, ethaddr2_str);
+		PRINTM(INFO, "DFT: adding (%s,%s)\n", ethaddr1_str,
+		       ethaddr2_str);
+	}
+#endif
+
+	LEAVE();
+	return (libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_DFT_ACCESS_ADD,
+				      HostCmd_OPTION_WAITFORRSP, 0, ethaddrs));
+}
+
+/**
+ *  @brief          Delete an entry from the DFT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_dft_del_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	char ethaddrs_str[18];
+	u8 ethaddr[ETH_ALEN];
+	char *pos;
+
+	ENTER();
+	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
+			   sizeof(ethaddrs_str)))
+		return -EFAULT;
+
+	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
+		PRINTM(FATAL, "Invalid MAC address\n");
+		return -EINVAL;
+	}
+
+	PRINTM(INFO, "DFT: deleting %s\n", ethaddrs_str);
+
+	LEAVE();
+	return (libertas_prepare_and_send_command(priv,
+				      HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_DFT_ACCESS_DEL,
+				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
+}
+
+/**
+ *  @brief          Reset all entries from the DFT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_dft_reset_ioctl(wlan_private * priv)
+{
+	ENTER();
+
+	PRINTM(MSG, "DFT: resetting\n");
+
+	LEAVE();
+	return (libertas_prepare_and_send_command(priv,
+				      HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_DFT_ACCESS_RESET,
+				      HostCmd_OPTION_WAITFORRSP, 0, NULL));
+}
+
+/**
+ *  @brief          List an entry from the DFT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_dft_list_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int pos;
+	char *addr1, *addr2;
+	struct iwreq *wrq = (struct iwreq *)req;
+	/* used to pass id and store the dft entry returned by the FW */
+	union {
+		int id;
+		char addr1addr2[2 * ETH_ALEN];
+	} param;
+	static char outstr[64];
+	char *pbuf = outstr;
+	int ret;
+
+	ENTER();
+
+	if (copy_from_user(outstr, wrq->u.data.pointer, sizeof(outstr))) {
+		PRINTM(INFO, "Copy from user failed\n");
+		return WLAN_STATUS_FAILURE;
+	}
+	param.id = simple_strtoul(outstr, NULL, 10);
+	pos = sprintf(pbuf, "%d: ", param.id);
+	pbuf += pos;
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
+				    HostCmd_ACT_DFT_ACCESS_LIST,
+				    HostCmd_OPTION_WAITFORRSP, 0,
+				    (char *)&param);
+
+	if (ret == WLAN_STATUS_SUCCESS) {
+		addr1 = param.addr1addr2;
+		addr2 = param.addr1addr2 + ETH_ALEN;
+
+		pos = sprintf(pbuf, "da ");
+		pbuf += pos;
+		pos = eth_addr2str(addr1, pbuf);
+		pbuf += pos;
+		pos = sprintf(pbuf, "    next hop ");
+		pbuf += pos;
+		pos = eth_addr2str(addr2, pbuf);
+		pbuf += pos;
+	} else {
+		sprintf(pbuf, "(null)");
+		pbuf += pos;
+	}
+	wrq->u.data.length = strlen(outstr);
+	if (copy_to_user(wrq->u.data.pointer, (char *)outstr,
+			 wrq->u.data.length)) {
+		PRINTM(INFO, "DFT_LIST: Copy to user failed!\n");
+		return -EFAULT;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief          Add an entry to the BT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_bt_add_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	char ethaddrs_str[18];
+	char *pos;
+	u8 ethaddr[ETH_ALEN];
+
+	ENTER();
+	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
+			   sizeof(ethaddrs_str)))
+		return -EFAULT;
+
+	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
+		PRINTM(FATAL, "BT_ADD: Invalid MAC address\n");
+		return -EINVAL;
+	}
+
+	PRINTM(INFO, "BT: adding %s\n", ethaddrs_str);
+	LEAVE();
+	return (libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_BT_ACCESS_ADD,
+				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
+}
+
+/**
+ *  @brief          Delete an entry from the BT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_bt_del_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	struct iwreq *wrq = (struct iwreq *)req;
+	char ethaddrs_str[18];
+	u8 ethaddr[ETH_ALEN];
+	char *pos;
+
+	ENTER();
+	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
+			   sizeof(ethaddrs_str)))
+		return -EFAULT;
+
+	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
+		PRINTM(FATAL, "Invalid MAC address\n");
+		return -EINVAL;
+	}
+
+	PRINTM(INFO, "BT: deleting %s\n", ethaddrs_str);
+
+	return (libertas_prepare_and_send_command(priv,
+				      HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_BT_ACCESS_DEL,
+				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief          Reset all entries from the BT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_bt_reset_ioctl(wlan_private * priv)
+{
+	ENTER();
+
+	PRINTM(MSG, "BT: resetting\n");
+
+	return (libertas_prepare_and_send_command(priv,
+				      HostCmd_CMD_DFT_ACCESS,
+				      HostCmd_ACT_BT_ACCESS_RESET,
+				      HostCmd_OPTION_WAITFORRSP, 0, NULL));
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+
+/**
+ *  @brief          List an entry from the BT table
+ *  @param priv     A pointer to wlan_private structure
+ *  @param req      A pointer to ifreq structure
+ *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
+ */
+static int wlan_bt_list_ioctl(wlan_private * priv, struct ifreq *req)
+{
+	int pos;
+	char *addr1;
+	struct iwreq *wrq = (struct iwreq *)req;
+	/* used to pass id and store the bt entry returned by the FW */
+	union {
+		int id;
+		char addr1addr2[2 * ETH_ALEN];
+	} param;
+	static char outstr[64];
+	char *pbuf = outstr;
+	int ret;
+
+	ENTER();
+
+	if (copy_from_user(outstr, wrq->u.data.pointer, sizeof(outstr))) {
+		PRINTM(INFO, "Copy from user failed\n");
+		return WLAN_STATUS_FAILURE;
+	}
+	param.id = simple_strtoul(outstr, NULL, 10);
+	pos = sprintf(pbuf, "%d: ", param.id);
+	pbuf += pos;
+
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
+				    HostCmd_ACT_BT_ACCESS_LIST,
+				    HostCmd_OPTION_WAITFORRSP, 0,
+				    (char *)&param);
+
+	if (ret == WLAN_STATUS_SUCCESS) {
+		addr1 = param.addr1addr2;
+
+		pos = sprintf(pbuf, "ignoring traffic from ");
+		pbuf += pos;
+		pos = eth_addr2str(addr1, pbuf);
+		pbuf += pos;
+	} else {
+		sprintf(pbuf, "(null)");
+		pbuf += pos;
+	}
+
+	wrq->u.data.length = strlen(outstr);
+	if (copy_to_user(wrq->u.data.pointer, (char *)outstr,
+			 wrq->u.data.length)) {
+		PRINTM(INFO, "BT_LIST: Copy to user failed!\n");
+		return -EFAULT;
+	}
+
+	LEAVE();
+	return WLAN_STATUS_SUCCESS;
+}
+/**
+ *  @brief ioctl function - entry point
+ *
+ *  @param dev		A pointer to net_device structure
+ *  @param req	   	A pointer to ifreq structure
+ *  @param cmd 		command
+ *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
+ */
+int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+	int subcmd = 0;
+	int idata = 0;
+	int *pdata;
+	int ret = WLAN_STATUS_SUCCESS;
+	wlan_private *priv = dev->priv;
+	wlan_adapter *Adapter = priv->adapter;
+	struct iwreq *wrq = (struct iwreq *)req;
+
+	ENTER();
+
+	PRINTM(INFO, "libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd);
+	switch (cmd) {
+	case WLANEXTSCAN:
+		ret = libertas_extscan_ioctl(priv, req);
+		break;
+	case WLANHOSTCMD:
+		ret = wlan_hostcmd_ioctl(dev, req, cmd);
+		break;
+
+	case WLANCISDUMP:	/* Read CIS Table  */
+		ret = wlan_do_getcis_ioctl(priv, req);
+		break;
+
+	case WLANSCAN_TYPE:
+		PRINTM(INFO, "Scan Type Ioctl\n");
+		ret = wlan_scan_type_ioctl(priv, wrq);
+		break;
+
+	case WLANREGRDWR:	/* Register read write command */
+		ret = wlan_regrdwr_ioctl(priv, req);
+		break;
+
+	/* FIXME: this really should be handled by wireless extensions
+		  already, so it can probably be dropped here. */
+	case SIOCSIWENCODE:	/* set encoding token & mode for WPA */
+		ret = wlan_set_encode(dev, NULL, &(wrq->u.data),
+				      wrq->u.data.pointer);
+		break;
+
+	case WLAN_SETNONE_GETNONE:	/* set WPA mode on/off ioctl #20 */
+		switch (wrq->u.data.flags) {
+		case WLANDEAUTH:
+			PRINTM(INFO, "Deauth\n");
+			libertas_send_deauth(priv);
+			break;
+
+		case WLANADHOCSTOP:
+			PRINTM(INFO, "Adhoc stop\n");
+			ret = libertas_do_adhocstop_ioctl(priv);
+			break;
+
+		case WLANRADIOON:
+			wlan_radio_ioctl(priv, RADIO_ON);
+			break;
+
+		case WLANRADIOOFF:
+			wlan_radio_ioctl(priv, RADIO_OFF);
+			break;
+#ifdef REASSOCIATION
+		case WLANREASSOCIATIONAUTO:
+			reassociation_on(priv);
+			break;
+		case WLANREASSOCIATIONUSER:
+			reassociation_off(priv);
+			break;
+#endif				/* REASSOCIATION */
+		case WLANWLANIDLEON:
+			libertas_idle_on(priv);
+			break;
+		case WLANWLANIDLEOFF:
+			libertas_idle_off(priv);
+			break;
+		case WLAN_SUBCMD_DFT_RESET:	/* dft_reset */
+			wlan_dft_reset_ioctl(priv);
+			break;
+		case WLAN_SUBCMD_BT_RESET:	/* bt_reset */
+			wlan_bt_reset_ioctl(priv);
+			break;
+		}		/* End of switch */
+		break;
+
+	case WLAN_SETWORDCHAR_GETNONE:
+		switch (wrq->u.data.flags) {
+		}
+		break;
+
+	case WLAN_SETNONE_GETWORDCHAR:
+		switch (wrq->u.data.flags) {
+		case WLANVERSION:	/* Get driver version */
+			ret = wlan_version_ioctl(priv, req);
+			break;
+		}
+		break;
+	case WLANSETWPAIE:
+		ret = wlan_setwpaie_ioctl(priv, req);
+		break;
+	case WLAN_SETINT_GETINT:
+		/* The first 4 bytes of req->ifr_data is sub-ioctl number
+		 * after 4 bytes sits the payload.
+		 */
+		subcmd = (int)req->ifr_data;	//from iwpriv subcmd
+		switch (subcmd) {
+		case WLANNF:
+			ret = wlan_get_nf(priv, wrq);
+			break;
+		case WLANRSSI:
+			ret = wlan_get_rssi(priv, wrq);
+			break;
+		case WLANENABLE11D:
+			ret = libertas_cmd_enable_11d(priv, wrq);
+			break;
+		case WLANADHOCGRATE:
+			ret = wlan_do_set_grate_ioctl(priv, wrq);
+			break;
+		case WLAN_SUBCMD_SET_PRESCAN:
+			ret = wlan_subcmd_setprescan_ioctl(priv, wrq);
+			break;
+		}
+		break;
+
+	case WLAN_SETONEINT_GETONEINT:
+		switch (wrq->u.data.flags) {
+		case WLAN_BEACON_INTERVAL:
+			ret = wlan_beacon_interval(priv, wrq);
+			break;
+
+		case WLAN_LISTENINTRVL:
+			if (!wrq->u.data.length) {
+				int data;
+				PRINTM(INFO, "Get LocalListenInterval Value\n");
+#define GET_ONE_INT	1
+				data = Adapter->LocalListenInterval;
+				if (copy_to_user(wrq->u.data.pointer,
+						 &data, sizeof(int))) {
+					PRINTM(INFO, "Copy to user failed\n");
+					return -EFAULT;
+				}
+
+				wrq->u.data.length = GET_ONE_INT;
+			} else {
+				int data;
+				if (copy_from_user
+				    (&data, wrq->u.data.pointer, sizeof(int))) {
+					PRINTM(INFO, "Copy from user failed\n");
+					return -EFAULT;
+				}
+
+				PRINTM(INFO, "Set LocalListenInterval = %d\n",
+				       data);
+#define MAX_U16_VAL	65535
+				if (data > MAX_U16_VAL) {
+					PRINTM(INFO, "Exceeds U16 value\n");
+					return -EINVAL;
+				}
+				Adapter->LocalListenInterval = data;
+			}
+			break;
+		case WLAN_TXCONTROL:
+			ret = wlan_txcontrol(priv, wrq);	//adds for txcontrol ioctl
+			break;
+
+		case WLAN_NULLPKTINTERVAL:
+			ret = wlan_null_pkt_interval(priv, wrq);
+			break;
+
+		default:
+			ret = -EOPNOTSUPP;
+			break;
+		}
+		break;
+
+	case WLAN_SETONEINT_GETNONE:
+		/* The first 4 bytes of req->ifr_data is sub-ioctl number
+		 * after 4 bytes sits the payload.
+		 */
+		subcmd = wrq->u.data.flags;	//from wpa_supplicant subcmd
+
+		if (!subcmd)
+			subcmd = (int)req->ifr_data;	//from iwpriv subcmd
+
+		switch (subcmd) {
+		case WLAN_SUBCMD_SETRXANTENNA:	/* SETRXANTENNA */
+			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			ret = SetRxAntenna(priv, idata);
+			break;
+		case WLAN_SUBCMD_SETTXANTENNA:	/* SETTXANTENNA */
+			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			ret = SetTxAntenna(priv, idata);
+			break;
+		case WLAN_SET_ATIM_WINDOW:
+			Adapter->AtimWindow =
+			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			Adapter->AtimWindow = min_t(__u16, Adapter->AtimWindow, 50);
+			break;
+		case WLANSETBCNAVG:
+			Adapter->bcn_avg_factor =
+			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			if (Adapter->bcn_avg_factor == 0)
+				Adapter->bcn_avg_factor =
+				    DEFAULT_BCN_AVG_FACTOR;
+			if (Adapter->bcn_avg_factor > DEFAULT_BCN_AVG_FACTOR)
+				Adapter->bcn_avg_factor =
+				    DEFAULT_BCN_AVG_FACTOR;
+			break;
+		case WLANSETDATAAVG:
+			Adapter->data_avg_factor =
+			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			if (Adapter->data_avg_factor == 0)
+				Adapter->data_avg_factor =
+				    DEFAULT_DATA_AVG_FACTOR;
+			if (Adapter->data_avg_factor > DEFAULT_DATA_AVG_FACTOR)
+				Adapter->data_avg_factor =
+				    DEFAULT_DATA_AVG_FACTOR;
+			break;
+		case WLANSETREGION:
+			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			ret = wlan_set_region(priv, (u16) idata);
+			break;
+
+		case WLAN_SET_LISTEN_INTERVAL:
+			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
+			Adapter->ListenInterval = (u16) idata;
+			break;
+
+		case WLAN_SET_MULTIPLE_DTIM:
+			ret = wlan_set_multiple_dtim_ioctl(priv, req);
+			break;
+
+		case WLANSETAUTHALG:
+			ret = wlan_setauthalg_ioctl(priv, req);
+			break;
+
+		case WLANSET8021XAUTHALG:
+			ret = wlan_set8021xauthalg_ioctl(priv, req);
+			break;
+
+		case WLANSETENCRYPTIONMODE:
+			ret = wlan_setencryptionmode_ioctl(priv, req);
+			break;
+
+		case WLAN_SET_LINKMODE:
+			ret = wlan_set_linkmode_ioctl(priv, req);
+			break;
+
+		case WLAN_SET_RADIOMODE:
+			ret = wlan_set_radiomode_ioctl(priv, req);
+			break;
+
+		case WLAN_SET_DEBUGMODE:
+			ret = wlan_set_debugmode_ioctl(priv, req);
+			break;
+
+		default:
+			ret = -EOPNOTSUPP;
+			break;
+		}
+
+		break;
+
+	case WLAN_SETNONE_GETTWELVE_CHAR:	/* Get Antenna settings */
+		/*
+		 * We've not used IW_PRIV_TYPE_FIXED so sub-ioctl number is
+		 * in flags of iwreq structure, otherwise it will be in
+		 * mode member of iwreq structure.
+		 */
+		switch ((int)wrq->u.data.flags) {
+		case WLAN_SUBCMD_GETRXANTENNA:	/* Get Rx Antenna */
+			ret = wlan_subcmd_getrxantenna_ioctl(priv, req);
+			break;
+
+		case WLAN_SUBCMD_GETTXANTENNA:	/* Get Tx Antenna */
+			ret = wlan_subcmd_gettxantenna_ioctl(priv, req);
+			break;
+
+		case WLAN_GET_TSF:
+			ret = wlan_get_tsf_ioctl(priv, wrq);
+			break;
+		}
+		break;
+
+	case WLAN_SET64CHAR_GET64CHAR:
+		switch ((int)wrq->u.data.flags) {
+
+		case WLANSLEEPPARAMS:
+			ret = wlan_sleep_params_ioctl(priv, wrq);
+			break;
+
+		case WLANSCAN_MODE:
+			PRINTM(INFO, "Scan Mode Ioctl\n");
+			ret = wlan_scan_mode_ioctl(priv, wrq);
+			break;
+
+		case WLAN_GET_ADHOC_STATUS:
+			ret = wlan_get_adhoc_status_ioctl(priv, wrq);
+			break;
+		case WLAN_SUBCMD_DFT_ADD:
+			ret = wlan_dft_add_ioctl(priv, req);
+			break;
+		case WLAN_SUBCMD_DFT_DEL:
+			ret = wlan_dft_del_ioctl(priv, req);
+			break;
+		case WLAN_SUBCMD_DFT_LIST:
+			ret = wlan_dft_list_ioctl(priv, req);
+			break;
+		case WLAN_SUBCMD_BT_ADD:
+			ret = wlan_bt_add_ioctl(priv, req);
+			break;
+		case WLAN_SUBCMD_BT_DEL:
+			ret = wlan_bt_del_ioctl(priv, req);
+			break;
+		case WLAN_SUBCMD_BT_LIST:
+			ret = wlan_bt_list_ioctl(priv, req);
+			break;
+		}
+		break;
+
+	case WLAN_SETCONF_GETCONF:
+		PRINTM(INFO, "The WLAN_SETCONF_GETCONF=0x%x is %d\n",
+		       WLAN_SETCONF_GETCONF, *(u8 *) req->ifr_data);
+		switch (*(u8 *) req->ifr_data) {
+
+		}
+		break;
+
+	case WLAN_SETNONE_GETONEINT:
+		switch ((int)req->ifr_data) {
+		case WLANGETBCNAVG:
+			pdata = (int *)wrq->u.name;
+			*pdata = (int)Adapter->bcn_avg_factor;
+			break;
+
+		case WLANGETREGION:
+			pdata = (int *)wrq->u.name;
+			*pdata = (int)Adapter->RegionCode;
+			break;
+
+		case WLAN_GET_LISTEN_INTERVAL:
+			pdata = (int *)wrq->u.name;
+			*pdata = (int)Adapter->ListenInterval;
+			break;
+
+		case WLAN_GET_LINKMODE:
+			req->ifr_data = (char *)((u32) Adapter->linkmode);
+			break;
+
+		case WLAN_GET_RADIOMODE:
+			req->ifr_data = (char *)((u32) Adapter->radiomode);
+			break;
+
+		case WLAN_GET_DEBUGMODE:
+			req->ifr_data = (char *)((u32) Adapter->debugmode);
+			break;
+
+		case WLAN_GET_MULTIPLE_DTIM:
+			pdata = (int *)wrq->u.name;
+			*pdata = (int)Adapter->MultipleDtim;
+			break;
+		case WLAN_GET_TX_RATE:
+			ret = wlan_get_txrate_ioctl(priv, req);
+			break;
+		default:
+			ret = -EOPNOTSUPP;
+
+		}
+
+		break;
+
+	case WLAN_SETTENCHAR_GETNONE:
+		switch ((int)wrq->u.data.flags) {
+
+		}
+		break;
+
+	case WLAN_SETNONE_GETTENCHAR:
+		switch ((int)wrq->u.data.flags) {
+		}
+		break;
+
+	case WLANGETLOG:
+		ret = wlan_do_getlog_ioctl(priv, wrq);
+		break;
+
+	case WLAN_SET_GET_SIXTEEN_INT:
+		switch ((int)wrq->u.data.flags) {
+		case WLAN_TPCCFG:
+			{
+				int data[5];
+				struct HostCmd_DS_802_11_TPC_CFG cfg;
+				memset(&cfg, 0, sizeof(cfg));
+				if ((wrq->u.data.length > 1)
+				    && (wrq->u.data.length != 5))
+					return WLAN_STATUS_FAILURE;
+
+				if (wrq->u.data.length == 0) {
+					cfg.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_GET);
+				} else {
+					if (copy_from_user
+					    (data, wrq->u.data.pointer,
+					     sizeof(int) * 5)) {
+						PRINTM(INFO,
+						       "Copy from user failed\n");
+						return -EFAULT;
+					}
+
+					cfg.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_SET);
+					cfg.Enable = data[0];
+					cfg.UseSNR = data[1];
+					cfg.P0 = data[2];
+					cfg.P1 = data[3];
+					cfg.P2 = data[4];
+				}
+
+				ret =
+				    libertas_prepare_and_send_command(priv,
+							  HostCmd_CMD_802_11_TPC_CFG,
+							  0,
+							  HostCmd_OPTION_WAITFORRSP,
+							  0, (void *)&cfg);
+
+				data[0] = cfg.Enable;
+				data[1] = cfg.UseSNR;
+				data[2] = cfg.P0;
+				data[3] = cfg.P1;
+				data[4] = cfg.P2;
+				if (copy_to_user
+				    (wrq->u.data.pointer, data,
+				     sizeof(int) * 5)) {
+					PRINTM(INFO, "Copy to user failed\n");
+					return -EFAULT;
+				}
+
+				wrq->u.data.length = 5;
+			}
+			break;
+
+		case WLAN_POWERCFG:
+			{
+				int data[4];
+				struct HostCmd_DS_802_11_PWR_CFG cfg;
+				memset(&cfg, 0, sizeof(cfg));
+				if ((wrq->u.data.length > 1)
+				    && (wrq->u.data.length != 4))
+					return WLAN_STATUS_FAILURE;
+				if (wrq->u.data.length == 0) {
+					cfg.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_GET);
+				} else {
+					if (copy_from_user
+					    (data, wrq->u.data.pointer,
+					     sizeof(int) * 4)) {
+						PRINTM(INFO,
+						       "Copy from user failed\n");
+						return -EFAULT;
+					}
+
+					cfg.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_SET);
+					cfg.Enable = data[0];
+					cfg.PA_P0 = data[1];
+					cfg.PA_P1 = data[2];
+					cfg.PA_P2 = data[3];
+				}
+				ret =
+				    libertas_prepare_and_send_command(priv,
+							  HostCmd_CMD_802_11_PWR_CFG,
+							  0,
+							  HostCmd_OPTION_WAITFORRSP,
+							  0, (void *)&cfg);
+				data[0] = cfg.Enable;
+				data[1] = cfg.PA_P0;
+				data[2] = cfg.PA_P1;
+				data[3] = cfg.PA_P2;
+				if (copy_to_user
+				    (wrq->u.data.pointer, data,
+				     sizeof(int) * 4)) {
+					PRINTM(INFO, "Copy to user failed\n");
+					return -EFAULT;
+				}
+
+				wrq->u.data.length = 4;
+			}
+			break;
+		case WLAN_AUTO_FREQ_SET:
+			{
+				int data[3];
+				struct HostCmd_DS_802_11_AFC afc;
+				memset(&afc, 0, sizeof(afc));
+				if (wrq->u.data.length != 3)
+					return WLAN_STATUS_FAILURE;
+				if (copy_from_user
+				    (data, wrq->u.data.pointer,
+				     sizeof(int) * 3)) {
+					PRINTM(INFO, "Copy from user failed\n");
+					return -EFAULT;
+				}
+				afc.afc_auto = data[0];
+
+				if (afc.afc_auto != 0) {
+					afc.afc_thre = data[1];
+					afc.afc_period = data[2];
+				} else {
+					afc.afc_toff = data[1];
+					afc.afc_foff = data[2];
+				}
+				ret =
+				    libertas_prepare_and_send_command(priv,
+							  HostCmd_CMD_802_11_SET_AFC,
+							  0,
+							  HostCmd_OPTION_WAITFORRSP,
+							  0, (void *)&afc);
+			}
+			break;
+		case WLAN_AUTO_FREQ_GET:
+			{
+				int data[3];
+				struct HostCmd_DS_802_11_AFC afc;
+				memset(&afc, 0, sizeof(afc));
+				ret =
+				    libertas_prepare_and_send_command(priv,
+							  HostCmd_CMD_802_11_GET_AFC,
+							  0,
+							  HostCmd_OPTION_WAITFORRSP,
+							  0, (void *)&afc);
+				data[0] = afc.afc_auto;
+				data[1] = afc.afc_toff;
+				data[2] = afc.afc_foff;
+				if (copy_to_user
+				    (wrq->u.data.pointer, data,
+				     sizeof(int) * 3)) {
+					PRINTM(INFO, "Copy to user failed\n");
+					return -EFAULT;
+				}
+
+				wrq->u.data.length = 3;
+			}
+			break;
+		case WLAN_SCANPROBES:
+			{
+				int data;
+				if (wrq->u.data.length > 0) {
+					if (copy_from_user
+					    (&data, wrq->u.data.pointer,
+					     sizeof(int))) {
+						PRINTM(INFO,
+						       "Copy from user failed\n");
+						return -EFAULT;
+					}
+
+					Adapter->ScanProbes = data;
+				} else {
+					data = Adapter->ScanProbes;
+					if (copy_to_user
+					    (wrq->u.data.pointer, &data,
+					     sizeof(int))) {
+						PRINTM(INFO,
+						       "Copy to user failed\n");
+						return -EFAULT;
+					}
+				}
+				wrq->u.data.length = 1;
+			}
+			break;
+		case WLAN_LED_GPIO_CTRL:
+			{
+				int i;
+				int data[16];
+
+				struct HostCmd_DS_802_11_LED_CTRL ctrl;
+				struct MrvlIEtypes_LedGpio *gpio =
+				    (struct MrvlIEtypes_LedGpio *) ctrl.data;
+
+				memset(&ctrl, 0, sizeof(ctrl));
+				if (wrq->u.data.length > MAX_LEDS * 2)
+					return -ENOTSUPP;
+				if ((wrq->u.data.length % 2) != 0)
+					return -ENOTSUPP;
+				if (wrq->u.data.length == 0) {
+					ctrl.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_GET);
+				} else {
+					if (copy_from_user
+					    (data, wrq->u.data.pointer,
+					     sizeof(int) *
+					     wrq->u.data.length)) {
+						PRINTM(INFO,
+						       "Copy from user failed\n");
+						return -EFAULT;
+					}
+
+					ctrl.Action =
+					    wlan_cpu_to_le16
+					    (HostCmd_ACT_GEN_SET);
+					ctrl.NumLed = wlan_cpu_to_le16(0);
+					gpio->Header.Type =
+					    wlan_cpu_to_le16(TLV_TYPE_LED_GPIO);
+					gpio->Header.Len = wrq->u.data.length;
+					for (i = 0; i < wrq->u.data.length;
+					     i += 2) {
+						gpio->LedPin[i / 2].Led =
+						    data[i];
+						gpio->LedPin[i / 2].Pin =
+						    data[i + 1];
+					}
+				}
+				ret =
+				    libertas_prepare_and_send_command(priv,
+							  HostCmd_CMD_802_11_LED_GPIO_CTRL,
+							  0,
+							  HostCmd_OPTION_WAITFORRSP,
+							  0, (void *)&ctrl);
+				for (i = 0; i < gpio->Header.Len; i += 2) {
+					data[i] = gpio->LedPin[i / 2].Led;
+					data[i + 1] = gpio->LedPin[i / 2].Pin;
+				}
+				if (copy_to_user(wrq->u.data.pointer, data,
+						 sizeof(int) *
+						 gpio->Header.Len)) {
+					PRINTM(INFO, "Copy to user failed\n");
+					return -EFAULT;
+				}
+
+				wrq->u.data.length = gpio->Header.Len;
+			}
+			break;
+		case WLAN_SLEEP_PERIOD:
+			ret = wlan_sleep_period(priv, wrq);
+			break;
+		case WLAN_ADAPT_RATESET:
+			ret = wlan_adapt_rateset(priv, wrq);
+			break;
+		case WLAN_INACTIVITY_TIMEOUT:
+			ret = wlan_inactivity_timeout(priv, wrq);
+			break;
+		case WLANSNR:
+			ret = wlan_get_snr(priv, wrq);
+			break;
+		case WLAN_GET_RXINFO:
+			ret = wlan_get_rxinfo(priv, wrq);
+		}
+		break;
+
+	case WLAN_SET_GET_2K:
+		switch ((int)wrq->u.data.flags) {
+		case WLAN_SET_USER_SCAN:
+			ret = libertas_set_user_scan_ioctl(priv, wrq);
+			break;
+		case WLAN_GET_SCAN_TABLE:
+			ret = libertas_get_scan_table_ioctl(priv, wrq);
+			break;
+
+		default:
+			ret = -EOPNOTSUPP;
+		}
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	LEAVE();
+	return ret;
+}
+
+
Index: linus-2.6/drivers/net/wireless/libertas/wlan_wext.c
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_wext.c
+++ linus-2.6/drivers/net/wireless/libertas/wlan_wext.c
@@ -51,16 +51,6 @@ Change log:
 #include "wlan_version.h"
 #include "wlan_wext.h"
 
-#define GETLOG_BUFSIZE  300
-
-#define MAX_SCAN_CELL_SIZE      (IW_EV_ADDR_LEN + \
-				MRVDRV_MAX_SSID_LENGTH + \
-				IW_EV_UINT_LEN + IW_EV_FREQ_LEN + \
-				IW_EV_QUAL_LEN + MRVDRV_MAX_SSID_LENGTH + \
-				IW_EV_PARAM_LEN + 40)	/* 40 for WPAIE */
-
-#define WAIT_FOR_SCAN_RRESULT_MAX_TIME (10 * HZ)
-
 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
 			 struct iw_param *vwrq, char *extra);
 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
@@ -79,8 +69,6 @@ static int wlan_set_mode(struct net_devi
 static int wlan_get_mode(struct net_device *dev, struct iw_request_info *info,
 			 u32 * uwrq, char *extra);
 
-static int wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
-			   struct iw_point *dwrq, char *extra);
 static int wlan_get_encode(struct net_device *dev, struct iw_request_info *info,
 			   struct iw_point *dwrq, u8 * extra);
 
@@ -91,18 +79,6 @@ static int wlan_get_txpow(struct net_dev
 
 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev);
 
-/* DFT function declaration */
-static int wlan_dft_add_ioctl(wlan_private * priv, struct ifreq *req);
-static int wlan_dft_del_ioctl(wlan_private * priv, struct ifreq *req);
-static int wlan_dft_reset_ioctl(wlan_private * priv);
-static int wlan_dft_list_ioctl(wlan_private * priv, struct ifreq *req);
-
-/* BT function declaration */
-static int wlan_bt_add_ioctl(wlan_private * priv, struct ifreq *req);
-static int wlan_bt_del_ioctl(wlan_private * priv, struct ifreq *req);
-static int wlan_bt_reset_ioctl(wlan_private * priv);
-static int wlan_bt_list_ioctl(wlan_private * priv, struct ifreq *req);
-
 /** 
  *  @brief Find a character in a string.
  *   
@@ -639,138 +615,13 @@ static int wlan_set_encode_nonwpa(struct
 }
 
 /** 
- *  @brief Set RX Antenna
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param Mode			RF antenna mode
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int SetRxAntenna(wlan_private * priv, int Mode)
-{
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_adapter *Adapter = priv->adapter;
-
-	if (Mode != RF_ANTENNA_1 && Mode != RF_ANTENNA_2
-	    && Mode != RF_ANTENNA_AUTO) {
-		return -EINVAL;
-	}
-
-	Adapter->RxAntennaMode = Mode;
-
-	PRINTM(INFO, "SET RX Antenna Mode to 0x%04x\n", Adapter->RxAntennaMode);
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
-				    HostCmd_ACT_SET_RX,
-				    HostCmd_OPTION_WAITFORRSP, 0,
-				    &Adapter->RxAntennaMode);
-	return ret;
-}
-
-/** 
- *  @brief Set TX Antenna
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param Mode			RF antenna mode
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int SetTxAntenna(wlan_private * priv, int Mode)
-{
-	int ret = 0;
-	wlan_adapter *Adapter = priv->adapter;
-
-	if ((Mode != RF_ANTENNA_1) && (Mode != RF_ANTENNA_2)
-	    && (Mode != RF_ANTENNA_AUTO)) {
-		return -EINVAL;
-	}
-
-	Adapter->TxAntennaMode = Mode;
-
-	PRINTM(INFO, "SET TX Antenna Mode to 0x%04x\n", Adapter->TxAntennaMode);
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
-				    HostCmd_ACT_SET_TX,
-				    HostCmd_OPTION_WAITFORRSP, 0,
-				    &Adapter->TxAntennaMode);
-
-	return ret;
-}
-
-/** 
- *  @brief Get RX Antenna
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param buf			A pointer to recieve antenna mode
- *  @return 	   		length of buf 
- */
-static int GetRxAntenna(wlan_private * priv, char *buf)
-{
-	int ret = 0;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	// clear it, so we will know if the value 
-	// returned below is correct or not.
-	Adapter->RxAntennaMode = 0;
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
-				    HostCmd_ACT_GET_RX,
-				    HostCmd_OPTION_WAITFORRSP, 0, NULL);
-
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
-
-	PRINTM(INFO, "Get Rx Antenna Mode:0x%04x\n", Adapter->RxAntennaMode);
-
-	LEAVE();
-
-	return sprintf(buf, "0x%04x", Adapter->RxAntennaMode) + 1;
-}
-
-/** 
- *  @brief Get TX Antenna
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param buf			A pointer to recieve antenna mode
- *  @return 	   		length of buf 
- */
-static int GetTxAntenna(wlan_private * priv, char *buf)
-{
-	int ret = 0;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	// clear it, so we will know if the value 
-	// returned below is correct or not.
-	Adapter->TxAntennaMode = 0;
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_RF_ANTENNA,
-				    HostCmd_ACT_GET_TX,
-				    HostCmd_OPTION_WAITFORRSP, 0, NULL);
-
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
-
-	PRINTM(INFO, "Get Tx Antenna Mode:0x%04x\n", Adapter->TxAntennaMode);
-
-	LEAVE();
-
-	return sprintf(buf, "0x%04x", Adapter->TxAntennaMode) + 1;
-}
-
-/** 
  *  @brief Set Radio On/OFF
  *   
  *  @param priv                 A pointer to wlan_private structure
  *  @option 			Radio Option
  *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail 
  */
-static int wlan_radio_ioctl(wlan_private * priv, u8 option)
+int wlan_radio_ioctl(wlan_private * priv, u8 option)
 {
 	int ret = 0;
 	wlan_adapter *Adapter = priv->adapter;
@@ -832,44 +683,6 @@ static int reassociation_off(wlan_privat
 #endif				/* REASSOCIATION */
 
 /** 
- *  @brief Set Region
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param region_code		region code
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail 
- */
-static int wlan_set_region(wlan_private * priv, u16 region_code)
-{
-	int i;
-
-	ENTER();
-
-	for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
-		// use the region code to search for the index
-		if (region_code == libertas_region_code_to_index[i]) {
-			priv->adapter->RegionTableIndex = (u16) i;
-			priv->adapter->RegionCode = region_code;
-			break;
-		}
-	}
-
-	// if it's unidentified region code
-	if (i >= MRVDRV_MAX_REGION_CODE) {
-		PRINTM(INFO, "Region Code not identified\n");
-		LEAVE();
-		return WLAN_STATUS_FAILURE;
-	}
-
-	if (libertas_set_regiontable(priv, priv->adapter->RegionCode, 0)) {
-		LEAVE();
-		return -EINVAL;
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
  *  @brief Copy Rates
  *   
  *  @param dest                 A pointer to Dest Buf
@@ -927,83 +740,6 @@ static int get_active_data_rates(wlan_ad
 }
 
 /** 
- *  @brief Get/Set Firmware wakeup method
- *  
- *  @param priv		A pointer to wlan_private structure
- *  @param wrq	   	A pointer to user data
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-static int wlan_txcontrol(wlan_private * priv, struct iwreq *wrq)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	int data;
-	ENTER();
-
-	if ((int)wrq->u.data.length == 0) {
-		if (copy_to_user
-		    (wrq->u.data.pointer, &Adapter->PktTxCtrl, sizeof(u32))) {
-			PRINTM(MSG, "copy_to_user failed!\n");
-			return -EFAULT;
-		}
-	} else {
-		if ((int)wrq->u.data.length > 1) {
-			PRINTM(MSG, "ioctl too many args!\n");
-			return -EFAULT;
-		}
-		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		Adapter->PktTxCtrl = (u32) data;
-	}
-
-	wrq->u.data.length = 1;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get/Set NULL Package generation interval
- *  
- *  @param priv		A pointer to wlan_private structure
- *  @param wrq	   	A pointer to user data
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-static int wlan_null_pkt_interval(wlan_private * priv, struct iwreq *wrq)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	int data;
-	ENTER();
-
-	if ((int)wrq->u.data.length == 0) {
-		data = Adapter->NullPktInterval;
-
-		if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
-			PRINTM(MSG, "copy_to_user failed!\n");
-			return -EFAULT;
-		}
-	} else {
-		if ((int)wrq->u.data.length > 1) {
-			PRINTM(MSG, "ioctl too many args!\n");
-			return -EFAULT;
-		}
-		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		Adapter->NullPktInterval = data;
-	}
-
-	wrq->u.data.length = 1;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
  *  @brief Commit handler: called after a bunch of SET operations
  *   
  *  @param dev                  A pointer to net_device structure
@@ -2478,2245 +2214,127 @@ struct iw_handler_def libertas_handler_d
 };
 
 /** 
- *  @brief wlan hostcmd ioctl handler
- *   
- *  @param dev                  A pointer to net_device structure
- *  @param req		        A pointer to ifreq structure
- *  @param cmd			command 
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
+ *  @brief Get wireless statistics
+ *
+ *  @param dev		A pointer to net_device structure
+ *  @return 	   	A pointer to iw_statistics buf
  */
-static int wlan_hostcmd_ioctl(struct net_device *dev, struct ifreq *req,
-			      int cmd)
+static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
 {
-	u8 *tempResponseBuffer;
-	struct CmdCtrlNode *pCmdNode;
-	struct HostCmd_DS_GEN *gencmd, *pCmdPtr;
+	enum {
+		POOR = 30,
+		FAIR = 60,
+		GOOD = 80,
+		VERY_GOOD = 90,
+		EXCELLENT = 95,
+		PERFECT = 100
+	};
 	wlan_private *priv = dev->priv;
 	wlan_adapter *Adapter = priv->adapter;
-	u16 wait_option = 0;
+	int ret = WLAN_STATUS_SUCCESS;
+	u32 rssi_qual;
+	u32 tx_qual;
+	u32 quality = 0;
+	int stats_valid = 0;
+	u8 rssi;
 
 	ENTER();
 
-	/*
-	 * Get a free command control node 
-	 */
-	if (!(pCmdNode = libertas_get_free_cmd_ctrl_node(priv))) {
-		PRINTM(INFO, "Failed libertas_get_free_cmd_ctrl_node\n");
-		return -ENOMEM;
-	}
-
-	if (!(tempResponseBuffer = kmalloc(3000, GFP_KERNEL))) {
-		PRINTM(INFO, "ERROR: Failed to allocate response buffer!\n");
-		return -ENOMEM;
-	}
+	priv->wstats.status = Adapter->InfrastructureMode;
 
-	wait_option |= HostCmd_OPTION_WAITFORRSP;
+	/* If we're not associated, all quality values are meaningless */
+	if (Adapter->MediaConnectStatus != WlanMediaStateConnected)
+		goto out;
 
-	libertas_set_cmd_ctrl_node(priv, pCmdNode, 0, wait_option, NULL);
-	init_waitqueue_head(&pCmdNode->cmdwait_q);
+	/* send RSSI command to get beacon RSSI/NF, valid only if associated */
+	ret = libertas_prepare_and_send_command(priv,
+				    HostCmd_CMD_802_11_RSSI,
+				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
+	if (ret)
+		goto out;
 
-	pCmdPtr = (struct HostCmd_DS_GEN *)pCmdNode->BufVirtualAddr;
-	gencmd = (struct HostCmd_DS_GEN *)req->ifr_data;
+	/* Quality by RSSI */
+	priv->wstats.qual.level =
+	    CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
+	     Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
 
-	/*
-	 * Copy the whole command into the command buffer 
-	 */
-	if (copy_from_user(pCmdPtr, req->ifr_data, gencmd->Size)) {
-		PRINTM(INFO, "Copy from user failed\n");
-		kfree(tempResponseBuffer);
-		return -EFAULT;
+	if (Adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
+		priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
+	} else {
+		priv->wstats.qual.noise =
+		    CAL_NF(Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
 	}
 
-	pCmdNode->pdata_buf = tempResponseBuffer;
-	pCmdNode->CmdFlags |= CMD_F_HOSTCMD;
+	PRINTM(INFO, "Signal Level = %#x\n", priv->wstats.qual.level);
+	PRINTM(INFO, "Noise = %#x\n", priv->wstats.qual.noise);
 
-	pCmdPtr->SeqNum = ++priv->adapter->SeqNum;
-	pCmdPtr->Result = 0;
+	rssi = priv->wstats.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
+	if (rssi < 15)
+		rssi_qual = rssi * POOR / 10;
+	else if (rssi < 20)
+		rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
+	else if (rssi < 30)
+		rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
+	else if (rssi < 40)
+		rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
+		    10 + GOOD;
+	else
+		rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
+		    10 + VERY_GOOD;
+	quality = rssi_qual;
 
-	PRINTM(INFO, "HOSTCMD Command: 0x%04x Size: %d SeqNum: %d\n",
-	       pCmdPtr->Command, pCmdPtr->Size, pCmdPtr->SeqNum);
-	HEXDUMP("Command Data", (u8 *) (pCmdPtr),
-		min_t(u16, 32, pCmdPtr->Size));
-	PRINTM(INFO, "Copying data from : (user)0x%p -> 0x%p(driver)\n",
-	       req->ifr_data, pCmdPtr);
+	/* Quality by TX errors */
+	priv->wstats.discard.retries = priv->stats.tx_errors;
+	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_GET_LOG,
+				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
+	if (!ret) {
+		u32 tx_retries = Adapter->LogMsg.retry;
 
-	pCmdNode->CmdWaitQWoken = 0;
-	libertas_queue_cmd(Adapter, pCmdNode, 1);
-	wake_up_interruptible(&priv->MainThread.waitQ);
+		if (tx_retries > 75)
+			tx_qual = (90 - tx_retries) * POOR / 15;
+		else if (tx_retries > 70)
+			tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
+		else if (tx_retries > 65)
+			tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
+		else if (tx_retries > 50)
+			tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
+			    15 + GOOD;
+		else
+			tx_qual = (50 - tx_retries) *
+			    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
+		quality = min(quality, tx_qual);
 
-	if (wait_option & HostCmd_OPTION_WAITFORRSP) {
-		/* Sleep until response is generated by FW */
-		wait_event_interruptible(pCmdNode->cmdwait_q,
-					 pCmdNode->CmdWaitQWoken);
+		priv->wstats.discard.code = Adapter->LogMsg.wepundecryptable;
+		priv->wstats.discard.fragment = Adapter->LogMsg.fcserror;
+		priv->wstats.discard.retries = tx_retries;
+		priv->wstats.discard.misc = Adapter->LogMsg.ackfailure;
 	}
 
-	/* Copy the response back to user space */
-	pCmdPtr = (struct HostCmd_DS_GEN *)tempResponseBuffer;
+	/* Calculate quality */
+	priv->wstats.qual.qual = max(quality, (u32)100);
+	priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
+	stats_valid = 1;
+
+out:
+	if (!stats_valid) {
+		priv->wstats.miss.beacon = 0;
+		priv->wstats.discard.retries = 0;
+		priv->wstats.qual.qual = 0;
+		priv->wstats.qual.level = 0;
+		priv->wstats.qual.noise = 0;
+		priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
+		priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
+		    IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
+	}
 
-	if (copy_to_user(req->ifr_data, tempResponseBuffer, pCmdPtr->Size))
-		PRINTM(INFO, "ERROR: copy_to_user failed!\n");
+	LEAVE ();
+	return &priv->wstats;
 
-	kfree(tempResponseBuffer);
 
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
 }
 
 /** 
- *  @brief Get Rx Info 
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wreq		        A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success
- */
-static int wlan_get_rxinfo(wlan_private * priv, struct iwreq *wrq)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	int data[2];
-	ENTER();
-	data[0] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
-	data[1] = Adapter->RxPDRate;
-	if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
-		PRINTM(INFO, "Copy to user failed\n");
-		return -EFAULT;
-	}
-	wrq->u.data.length = 2;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get SNR 
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wreq		        A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_get_snr(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_adapter *Adapter = priv->adapter;
-	int data[4];
-
-	ENTER();
-	memset(data, 0, sizeof(data));
-	if (wrq->u.data.length) {
-		if (copy_from_user
-		    (data, wrq->u.data.pointer,
-		     min_t(size_t, wrq->u.data.length, 4) * sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-	}
-	if ((wrq->u.data.length == 0) || (data[0] == 0) || (data[0] == 1)) {
-		if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
-			ret = libertas_prepare_and_send_command(priv,
-						    HostCmd_CMD_802_11_RSSI,
-						    0,
-						    HostCmd_OPTION_WAITFORRSP,
-						    0, NULL);
-
-			if (ret) {
-				LEAVE();
-				return ret;
-			}
-		}
-	}
-
-	if (wrq->u.data.length == 0) {
-		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
-		data[1] = Adapter->SNR[TYPE_BEACON][TYPE_AVG];
-		data[2] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
-		data[3] = Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 4)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = 4;
-	} else if (data[0] == 0) {
-		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = 1;
-	} else if (data[0] == 1) {
-		data[0] = Adapter->SNR[TYPE_BEACON][TYPE_AVG];
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = 1;
-	} else if (data[0] == 2) {
-		data[0] = Adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = 1;
-	} else if (data[0] == 3) {
-		data[0] = Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = 1;
-	} else {
-		return -ENOTSUPP;
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get/Set Adhoc beacon Interval 
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wreq		        A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_beacon_interval(wlan_private * priv, struct iwreq *wrq)
-{
-	int data;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	if (wrq->u.data.length > 0) {
-		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		PRINTM(INFO, "WLAN SET BEACON INTERVAL: %d\n", data);
-		if ((data > MRVDRV_MAX_BEACON_INTERVAL)
-		    || (data < MRVDRV_MIN_BEACON_INTERVAL))
-			return -ENOTSUPP;
-		Adapter->BeaconPeriod = data;
-	}
-	data = Adapter->BeaconPeriod;
-	if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
-		PRINTM(INFO, "Copy to user failed\n");
-		return -EFAULT;
-	}
-
-	wrq->u.data.length = 1;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get RSSI 
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wreq		        A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_get_rssi(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_adapter *Adapter = priv->adapter;
-	int temp;
-	int data = 0;
-	int *val;
-
-	ENTER();
-	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	if ((data == 0) || (data == 1)) {
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_RSSI,
-					    0, HostCmd_OPTION_WAITFORRSP,
-					    0, NULL);
-		if (ret) {
-			LEAVE();
-			return ret;
-		}
-	}
-
-	switch (data) {
-	case 0:
-
-		temp = CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
-				Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
-		break;
-	case 1:
-		temp = CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_AVG],
-				Adapter->NF[TYPE_BEACON][TYPE_AVG]);
-		break;
-	case 2:
-		temp = CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_NOAVG],
-				Adapter->NF[TYPE_RXPD][TYPE_NOAVG]);
-		break;
-	case 3:
-		temp = CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
-				Adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
-		break;
-	default:
-		return -ENOTSUPP;
-	}
-	val = (int *)wrq->u.name;
-	*val = temp;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get NF
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wreq		        A pointer to iwreq structure 
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_get_nf(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_adapter *Adapter = priv->adapter;
-	int temp;
-	int data = 0;
-	int *val;
-
-	ENTER();
-	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	if ((data == 0) || (data == 1)) {
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_RSSI,
-					    0, HostCmd_OPTION_WAITFORRSP,
-					    0, NULL);
-
-		if (ret) {
-			LEAVE();
-			return ret;
-		}
-	}
-
-	switch (data) {
-	case 0:
-		temp = Adapter->NF[TYPE_BEACON][TYPE_NOAVG];
-		break;
-	case 1:
-		temp = Adapter->NF[TYPE_BEACON][TYPE_AVG];
-		break;
-	case 2:
-		temp = Adapter->NF[TYPE_RXPD][TYPE_NOAVG];
-		break;
-	case 3:
-		temp = Adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
-		break;
-	default:
-		return -ENOTSUPP;
-	}
-
-	temp = CAL_NF(temp);
-
-	PRINTM(INFO, "***temp = %d\n", temp);
-	val = (int *)wrq->u.name;
-	*val = temp;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get TxRate
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_get_txrate_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	int *pdata;
-	struct iwreq *wrq = (struct iwreq *)req;
-	int ret = WLAN_STATUS_SUCCESS;
-	ENTER();
-	Adapter->TxRate = 0;
-	PRINTM(INFO, "wlan_get_txrate_ioctl\n");
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
-				    HostCmd_ACT_GET, HostCmd_OPTION_WAITFORRSP,
-				    0, NULL);
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
-	pdata = (int *)wrq->u.name;
-	*pdata = (int)Adapter->TxRate;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get Adhoc Status
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_get_adhoc_status_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	char status[64];
-	wlan_adapter *Adapter = priv->adapter;
-
-	memset(status, 0, sizeof(status));
-
-	switch (Adapter->InfrastructureMode) {
-	case Wlan802_11IBSS:
-		if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
-			if (Adapter->AdhocCreate)
-				memcpy(&status, "AdhocStarted", sizeof(status));
-			else
-				memcpy(&status, "AdhocJoined", sizeof(status));
-		} else {
-			memcpy(&status, "AdhocIdle", sizeof(status));
-		}
-		break;
-	case Wlan802_11Infrastructure:
-		memcpy(&status, "InfraMode", sizeof(status));
-		break;
-	default:
-		memcpy(&status, "AutoUnknownMode", sizeof(status));
-		break;
-	}
-
-	PRINTM(INFO, "Status = %s\n", status);
-	wrq->u.data.length = strlen(status) + 1;
-
-	if (wrq->u.data.pointer) {
-		if (copy_to_user(wrq->u.data.pointer,
-				 &status, wrq->u.data.length))
-			return -EFAULT;
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get Driver Version
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_version_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int len;
-	char buf[128];
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	libertas_get_version(priv->adapter, buf, sizeof(buf) - 1);
-
-	len = strlen(buf);
-	if (wrq->u.data.pointer) {
-		if (copy_to_user(wrq->u.data.pointer, buf, len)) {
-			PRINTM(INFO, "CopyToUser failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = len;
-	}
-
-	PRINTM(INFO, "wlan version: %s\n", buf);
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Read/Write adapter registers
- *   
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_regrdwr_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	wlan_ioctl_regrdwr regrdwr;
-	struct wlan_offset_value offval;
-	wlan_adapter *Adapter = priv->adapter;
-	int ret = WLAN_STATUS_SUCCESS;
-
-	ENTER();
-
-	if (copy_from_user(&regrdwr, req->ifr_data, sizeof(regrdwr))) {
-		PRINTM(INFO,
-		       "copy of regrdwr for wlan_regrdwr_ioctl from user failed \n");
-		LEAVE();
-		return -EFAULT;
-	}
-
-	if (regrdwr.WhichReg == REG_EEPROM) {
-		PRINTM(MSG, "Inside RDEEPROM\n");
-		Adapter->pRdeeprom =
-		    (char *)kmalloc((regrdwr.NOB + sizeof(regrdwr)),
-				    GFP_KERNEL);
-		if (!Adapter->pRdeeprom)
-			return -ENOMEM;
-		memcpy(Adapter->pRdeeprom, &regrdwr, sizeof(regrdwr));
-		/* +14 is for Action, Offset, and NOB in 
-		 * response */
-		PRINTM(INFO, "Action:%d Offset: %x NOB: %02x\n",
-		       regrdwr.Action, regrdwr.Offset, regrdwr.NOB);
-
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_EEPROM_ACCESS,
-					    regrdwr.Action,
-					    HostCmd_OPTION_WAITFORRSP, 0,
-					    &regrdwr);
-
-		if (ret) {
-			if (Adapter->pRdeeprom)
-				kfree(Adapter->pRdeeprom);
-			LEAVE();
-			return ret;
-		}
-
-		mdelay(10);
-
-		/*
-		 * Return the result back to the user 
-		 */
-
-		if (regrdwr.Action == HostCmd_ACT_GEN_READ) {
-			if (copy_to_user
-			    (req->ifr_data, Adapter->pRdeeprom,
-			     sizeof(regrdwr) + regrdwr.NOB)) {
-				if (Adapter->pRdeeprom)
-					kfree(Adapter->pRdeeprom);
-				PRINTM(INFO,
-				       "copy of regrdwr for wlan_regrdwr_ioctl to user failed \n");
-				LEAVE();
-				return -EFAULT;
-			}
-		}
-
-		if (Adapter->pRdeeprom)
-			kfree(Adapter->pRdeeprom);
-
-		return WLAN_STATUS_SUCCESS;
-	}
-
-	offval.offset = regrdwr.Offset;
-	offval.value = (regrdwr.Action) ? regrdwr.Value : 0x00;
-
-	PRINTM(INFO, "RegAccess: %02x Action:%d "
-	       "Offset: %04x Value: %04x\n",
-	       regrdwr.WhichReg, regrdwr.Action, offval.offset, offval.value);
-
-	/*
-	 * regrdwr.WhichReg should contain the command that
-	 * corresponds to which register access is to be 
-	 * performed HostCmd_CMD_MAC_REG_ACCESS 0x0019
-	 * HostCmd_CMD_BBP_REG_ACCESS 0x001a 
-	 * HostCmd_CMD_RF_REG_ACCESS 0x001b 
-	 */
-	ret = libertas_prepare_and_send_command(priv, regrdwr.WhichReg,
-				    regrdwr.Action, HostCmd_OPTION_WAITFORRSP,
-				    0, &offval);
-
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
-
-	mdelay(10);
-
-	/*
-	 * Return the result back to the user 
-	 */
-	regrdwr.Value = Adapter->OffsetValue.value;
-	if (regrdwr.Action == HostCmd_ACT_GEN_READ) {
-		if (copy_to_user(req->ifr_data, &regrdwr, sizeof(regrdwr))) {
-			PRINTM(INFO,
-			       "copy of regrdwr for wlan_regrdwr_ioctl to user failed \n");
-			LEAVE();
-			return -EFAULT;
-		}
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set/Get WPA IE   
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_setwpaie_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	wlan_adapter *Adapter = priv->adapter;
-	int ret = WLAN_STATUS_SUCCESS;
-
-	ENTER();
-
-	if (wrq->u.data.length) {
-		if (wrq->u.data.length > sizeof(Adapter->Wpa_ie)) {
-			PRINTM(INFO, "failed to copy WPA IE, too big \n");
-			return -EFAULT;
-		}
-		if (copy_from_user(Adapter->Wpa_ie, wrq->u.data.pointer,
-				   wrq->u.data.length)) {
-			PRINTM(INFO, "failed to copy WPA IE \n");
-			return -EFAULT;
-		}
-		Adapter->Wpa_ie_len = wrq->u.data.length;
-		PRINTM(INFO, "Set Wpa_ie_len=%d IE=%#x\n", Adapter->Wpa_ie_len,
-		       Adapter->Wpa_ie[0]);
-		HEXDUMP("Wpa_ie", Adapter->Wpa_ie, Adapter->Wpa_ie_len);
-		if (Adapter->Wpa_ie[0] == WPA_IE)
-			Adapter->SecInfo.WPAEnabled = 1;
-		else if (Adapter->Wpa_ie[0] == WPA2_IE)
-			Adapter->SecInfo.WPA2Enabled = 1;
-		else {
-			Adapter->SecInfo.WPAEnabled = 0;
-			Adapter->SecInfo.WPA2Enabled = 0;
-		}
-	} else {
-		memset(Adapter->Wpa_ie, 0, sizeof(Adapter->Wpa_ie));
-		Adapter->Wpa_ie_len = wrq->u.data.length;
-		PRINTM(INFO, "Reset Wpa_ie_len=%d IE=%#x\n",
-		       Adapter->Wpa_ie_len, Adapter->Wpa_ie[0]);
-		Adapter->SecInfo.WPAEnabled = 0;
-		Adapter->SecInfo.WPA2Enabled = 0;
-	}
-
-	// enable/disable RSN in firmware if WPA is enabled/disabled
-	// depending on variable Adapter->SecInfo.WPAEnabled is set or not
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_ENABLE_RSN,
-				    HostCmd_ACT_SET, HostCmd_OPTION_WAITFORRSP,
-				    0, NULL);
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Set Auto Prescan
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_subcmd_setprescan_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	int data;
-	wlan_adapter *Adapter = priv->adapter;
-	int *val;
-
-	ENTER();
-
-	data = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	PRINTM(INFO, "WLAN_SUBCMD_SET_PRESCAN %d\n", data);
-	switch (data) {
-	case CMD_ENABLED:
-		Adapter->Prescan = 1;
-		break;
-	case CMD_DISABLED:
-		Adapter->Prescan = 0;
-		break;
-	default:
-		break;
-	}
-
-	data = Adapter->Prescan;
-	val = (int *)wrq->u.name;
-	*val = data;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set multiple dtim
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_set_multiple_dtim_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	u32 mdtim;
-	int idata;
-	int ret = -EINVAL;
-
-	ENTER();
-
-	idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	mdtim = (u32) idata;
-	if (((mdtim >= MRVDRV_MIN_MULTIPLE_DTIM)
-	     && (mdtim <= MRVDRV_MAX_MULTIPLE_DTIM))
-	    || (mdtim == MRVDRV_IGNORE_MULTIPLE_DTIM)) {
-		priv->adapter->MultipleDtim = mdtim;
-		ret = WLAN_STATUS_SUCCESS;
-	}
-	if (ret)
-		PRINTM(INFO, "Invalid parameter, MultipleDtim not changed.\n");
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Set authentication mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_setauthalg_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int alg;
-	struct iwreq *wrq = (struct iwreq *)req;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	if (wrq->u.data.flags == 0) {
-		//from iwpriv subcmd
-		alg = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	} else {
-		//from wpa_supplicant subcmd
-		if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(alg))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-	}
-
-	PRINTM(INFO, "auth alg is %#x\n", alg);
-
-	switch (alg) {
-	case AUTH_ALG_SHARED_KEY:
-		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeShared;
-		break;
-	case AUTH_ALG_NETWORK_EAP:
-		Adapter->SecInfo.AuthenticationMode =
-		    Wlan802_11AuthModeNetworkEAP;
-		break;
-	case AUTH_ALG_OPEN_SYSTEM:
-	default:
-		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeOpen;
-		break;
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set 802.1x authentication mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_set8021xauthalg_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int alg;
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	if (wrq->u.data.flags == 0) {
-		//from iwpriv subcmd
-		alg = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	} else {
-		//from wpa_supplicant subcmd
-		if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-	}
-	PRINTM(INFO, "802.1x auth alg is %#x\n", alg);
-	priv->adapter->SecInfo.Auth1XAlg = alg;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set Encryption mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_setencryptionmode_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int mode;
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	if (wrq->u.data.flags == 0) {
-		//from iwpriv subcmd
-		mode = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	} else {
-		//from wpa_supplicant subcmd
-		if (copy_from_user(&mode, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-	}
-	PRINTM(INFO, "encryption mode is %#x\n", mode);
-	priv->adapter->SecInfo.EncryptionMode = mode;
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-static void adjust_mtu(wlan_private * priv)
-{
-	int mtu_increment = 0;
-
-	if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
-		mtu_increment += sizeof(struct IEEE80211_Hdr);
-
-	if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP)
-		mtu_increment += max(sizeof(struct TxRadiotapHdr),
-				     sizeof(struct RxRadiotapHdr));
-	priv->wlan_dev.netdev->mtu = ETH_FRAME_LEN
-	    - sizeof(struct EthII_Hdr)
-	    + mtu_increment;
-}
-
-/** 
- *  @brief Set Link-Layer Layer mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_set_linkmode_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int mode;
-
-	ENTER();
-
-	mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
-
-	switch (mode) {
-	case WLAN_LINKMODE_802_3:
-		priv->adapter->linkmode = mode;
-		break;
-	case WLAN_LINKMODE_802_11:
-		priv->adapter->linkmode = mode;
-		break;
-	default:
-		PRINTM(FATAL, "usb8388-5: invalid link-layer mode (%#x)\n",
-		       mode);
-		return WLAN_STATUS_NOT_ACCEPTED;
-		break;
-	}
-	PRINTM(INFO, "usb8388-5: link-layer mode is %#x\n", mode);
-
-	adjust_mtu(priv);
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set Radio Header mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_set_radiomode_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int mode;
-
-	ENTER();
-
-	mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
-
-	switch (mode) {
-	case WLAN_RADIOMODE_NONE:
-		priv->adapter->radiomode = mode;
-		break;
-	case WLAN_RADIOMODE_RADIOTAP:
-		priv->adapter->radiomode = mode;
-		break;
-	default:
-		PRINTM(INFO, "usb8388-5: invalid radio header mode (%#x)\n",
-		       mode);
-		return WLAN_STATUS_NOT_ACCEPTED;
-		break;
-	}
-	PRINTM(INFO, "usb8388-5: radio-header mode is %#x\n", mode);
-
-	adjust_mtu(priv);
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Set Debug Header mode
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_set_debugmode_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	ENTER();
-	priv->adapter->debugmode = (int)((struct ifreq *)
-					 ((u8 *) req + 4))->ifr_data;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get Rx antenna
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_subcmd_getrxantenna_ioctl(wlan_private * priv,
-					  struct ifreq *req)
-{
-	int len;
-	char buf[8];
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	PRINTM(INFO, "WLAN_SUBCMD_GETRXANTENNA\n");
-	len = GetRxAntenna(priv, buf);
-
-	wrq->u.data.length = len;
-	if (wrq->u.data.pointer) {
-		if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
-			PRINTM(INFO, "CopyToUser failed\n");
-			return -EFAULT;
-		}
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get Tx antenna
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_subcmd_gettxantenna_ioctl(wlan_private * priv,
-					  struct ifreq *req)
-{
-	int len;
-	char buf[8];
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	PRINTM(INFO, "WLAN_SUBCMD_GETTXANTENNA\n");
-	len = GetTxAntenna(priv, buf);
-
-	wrq->u.data.length = len;
-	if (wrq->u.data.pointer) {
-		if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
-			PRINTM(INFO, "CopyToUser failed\n");
-			return -EFAULT;
-		}
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief Get the MAC TSF value from the firmware
- *
- *  @param priv         A pointer to wlan_private structure
- *  @param wrq          A pointer to iwreq structure containing buffer
- *                      space to store a TSF value retrieved from the firmware
- *
- *  @return             0 if successful; IOCTL error code otherwise
- */
-static int wlan_get_tsf_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	u64 tsfVal;
-	int ret;
-
-	ENTER();
-
-	ret = libertas_prepare_and_send_command(priv,
-				    HostCmd_CMD_GET_TSF,
-				    0, HostCmd_OPTION_WAITFORRSP, 0, &tsfVal);
-
-	PRINTM(INFO, "IOCTL: Get TSF = 0x%016llx\n", tsfVal);
-
-	if (ret != WLAN_STATUS_SUCCESS) {
-		PRINTM(INFO, "IOCTL: Get TSF; Command exec failed\n");
-		ret = -EFAULT;
-	} else {
-		if (copy_to_user(wrq->u.data.pointer,
-				 &tsfVal,
-				 min_t(size_t, wrq->u.data.length,
-				     sizeof(tsfVal))) != 0) {
-
-			PRINTM(INFO, "IOCTL: Get TSF; Copy to user failed\n");
-			ret = -EFAULT;
-		} else {
-			ret = 0;
-		}
-	}
-
-	LEAVE();
-
-	return ret;
-}
-
-/** 
- *  @brief Get/Set sleep period 
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_sleep_period(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret;
-	int data;
-	wlan_adapter *Adapter = priv->adapter;
-	struct HostCmd_DS_802_11_SLEEP_PERIOD sleeppd;
-
-	ENTER();
-
-	if (wrq->u.data.length > 1)
-		return -ENOTSUPP;
-
-	memset(&sleeppd, 0, sizeof(sleeppd));
-	memset(&Adapter->sleep_period, 0, sizeof(struct sleep_period));
-
-	if (wrq->u.data.length == 0) {
-		sleeppd.Action = wlan_cpu_to_le16(HostCmd_ACT_GEN_GET);
-	} else {
-		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		/* sleep period is between 0 or 10 ... 60 */
-		if ((data <= 60 && data >= 10) || (data == 0)) {
-			sleeppd.Action = wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
-			sleeppd.Period = data;
-		} else
-			return -EINVAL;
-	}
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_SLEEP_PERIOD,
-				    0, HostCmd_OPTION_WAITFORRSP,
-				    0, (void *)&sleeppd);
-
-	data = (int)Adapter->sleep_period.period;
-	if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
-		PRINTM(INFO, "Copy to user failed\n");
-		return -EFAULT;
-	}
-	wrq->u.data.length = 1;
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Get/Set adapt rate 
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_adapt_rateset(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret;
-	wlan_adapter *Adapter = priv->adapter;
-	int data[2];
-
-	ENTER();
-	memset(data, 0, sizeof(data));
-	if (!wrq->u.data.length) {
-		PRINTM(INFO, "Get ADAPT RATE SET\n");
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
-					    HostCmd_ACT_GEN_GET,
-					    HostCmd_OPTION_WAITFORRSP, 0, NULL);
-		data[0] = Adapter->EnableHwAuto;
-		data[1] = Adapter->RateBitmap;
-		if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-#define GET_TWO_INT	2
-		wrq->u.data.length = GET_TWO_INT;
-	} else {
-		PRINTM(INFO, "Set ADAPT RATE SET\n");
-		if (wrq->u.data.length > 2)
-			return -EINVAL;
-		if (copy_from_user
-		    (data, wrq->u.data.pointer,
-		     sizeof(int) * wrq->u.data.length)) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		Adapter->EnableHwAuto = data[0];
-		Adapter->RateBitmap = data[1];
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
-					    HostCmd_ACT_GEN_SET,
-					    HostCmd_OPTION_WAITFORRSP, 0, NULL);
-	}
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Get/Set inactivity timeout
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_inactivity_timeout(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret;
-	int data = 0;
-	u16 timeout = 0;
-
-	ENTER();
-	if (wrq->u.data.length > 1)
-		return -ENOTSUPP;
-
-	if (wrq->u.data.length == 0) {
-		/* Get */
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_INACTIVITY_TIMEOUT,
-					    HostCmd_ACT_GET,
-					    HostCmd_OPTION_WAITFORRSP, 0,
-					    &timeout);
-		data = timeout;
-		if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-	} else {
-		/* Set */
-		if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
-			PRINTM(INFO, "Copy from user failed\n");
-			return -EFAULT;
-		}
-
-		timeout = data;
-		ret = libertas_prepare_and_send_command(priv,
-					    HostCmd_CMD_802_11_INACTIVITY_TIMEOUT,
-					    HostCmd_ACT_SET,
-					    HostCmd_OPTION_WAITFORRSP, 0,
-					    &timeout);
-	}
-
-	wrq->u.data.length = 1;
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Get LOG
- *  @param priv                 A pointer to wlan_private structure
- *  @param wrq			A pointer to iwreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_do_getlog_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret;
-	char buf[GETLOG_BUFSIZE - 1];
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	PRINTM(INFO, " GET STATS\n");
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_GET_LOG,
-				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
-
-	if (ret) {
-		LEAVE();
-		return ret;
-	}
-
-	if (wrq->u.data.pointer) {
-		sprintf(buf, "\n  mcasttxframe %u failed %u retry %u "
-			"multiretry %u framedup %u "
-			"rtssuccess %u rtsfailure %u ackfailure %u\n"
-			"rxfrag %u mcastrxframe %u fcserror %u "
-			"txframe %u wepundecryptable %u ",
-			Adapter->LogMsg.mcasttxframe,
-			Adapter->LogMsg.failed,
-			Adapter->LogMsg.retry,
-			Adapter->LogMsg.multiretry,
-			Adapter->LogMsg.framedup,
-			Adapter->LogMsg.rtssuccess,
-			Adapter->LogMsg.rtsfailure,
-			Adapter->LogMsg.ackfailure,
-			Adapter->LogMsg.rxfrag,
-			Adapter->LogMsg.mcastrxframe,
-			Adapter->LogMsg.fcserror,
-			Adapter->LogMsg.txframe,
-			Adapter->LogMsg.wepundecryptable);
-		wrq->u.data.length = strlen(buf) + 1;
-		if (copy_to_user(wrq->u.data.pointer, buf, wrq->u.data.length)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief config sleep parameters
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_sleep_params_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	int ret;
-	wlan_adapter *Adapter = priv->adapter;
-	wlan_ioctl_sleep_params_config sp;
-
-	ENTER();
-
-	memset(&sp, 0, sizeof(sp));
-
-	if (copy_from_user(&sp, wrq->u.data.pointer,
-			   min_t(size_t, sizeof(sp), wrq->u.data.length))) {
-		PRINTM(INFO, "Copy from user failed\n");
-		return -EFAULT;
-	}
-
-	memcpy(&Adapter->sp, &sp.Error, sizeof(struct sleep_params));
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_SLEEP_PARAMS,
-				    sp.Action, HostCmd_OPTION_WAITFORRSP,
-				    0, NULL);
-
-	if (!ret && !sp.Action && wrq->u.data.pointer) {
-		memcpy(&sp.Error, &Adapter->sp, sizeof(struct sleep_params));
-		if (copy_to_user(wrq->u.data.pointer, &sp, sizeof(sp))) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = sizeof(sp);
-	}
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Read the CIS Table
- *  @param priv                 A pointer to wlan_private structure
- *  @param req			A pointer to ifreq structure
- *  @return 	   		WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_do_getcis_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int ret = WLAN_STATUS_SUCCESS;
-	struct iwreq *wrq = (struct iwreq *)req;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	if (wrq->u.data.pointer) {
-		if (copy_to_user(wrq->u.data.pointer, Adapter->CisInfoBuf,
-				 Adapter->CisInfoLen)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			return -EFAULT;
-		}
-		wrq->u.data.length = Adapter->CisInfoLen;
-	}
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Set scan type
- *  
- *  @param priv		A pointer to wlan_private structure
- *  @param wrq	   	A pointer to user data
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-static int wlan_scan_type_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	u8 buf[12];
-	u8 *option[] = { "active", "passive", "get", };
-	int i, max_options = (sizeof(option) / sizeof(option[0]));
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_adapter *Adapter = priv->adapter;
-
-	ENTER();
-
-	if (libertas_get_state_11d(priv) == ENABLE_11D) {
-		PRINTM(INFO, "11D: Cannot set scantype when 11D enabled\n");
-		return -EFAULT;
-	}
-
-	memset(buf, 0, sizeof(buf));
-
-	if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
-							 wrq->u.data.length))) {
-		PRINTM(INFO, "Copy from user failed\n");
-		return -EFAULT;
-	}
-
-	PRINTM(INFO, "Scan Type Option = %s\n", buf);
-
-	buf[sizeof(buf) - 1] = '\0';
-
-	for (i = 0; i < max_options; i++) {
-		if (!strcmp(buf, option[i]))
-			break;
-	}
-
-	switch (i) {
-	case 0:
-		Adapter->ScanType = HostCmd_SCAN_TYPE_ACTIVE;
-		break;
-	case 1:
-		Adapter->ScanType = HostCmd_SCAN_TYPE_PASSIVE;
-		break;
-	case 2:
-		wrq->u.data.length = strlen(option[Adapter->ScanType]) + 1;
-
-		if (copy_to_user(wrq->u.data.pointer,
-				 option[Adapter->ScanType],
-				 wrq->u.data.length)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			ret = -EFAULT;
-		}
-
-		break;
-	default:
-		PRINTM(INFO, "Invalid Scan Type Ioctl Option\n");
-		ret = -EINVAL;
-		break;
-	}
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Set scan mode
- *  
- *  @param priv		A pointer to wlan_private structure
- *  @param wrq	   	A pointer to user data
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-static int wlan_scan_mode_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	u8 buf[12];
-	u8 *option[] = { "bss", "ibss", "any", "get" };
-	int i, max_options = (sizeof(option) / sizeof(option[0]));
-	int ret = WLAN_STATUS_SUCCESS;
-
-	ENTER();
-
-	memset(buf, 0, sizeof(buf));
-
-	if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
-							 wrq->u.data.length))) {
-		PRINTM(INFO, "Copy from user failed\n");
-		return -EFAULT;
-	}
-
-	PRINTM(INFO, "Scan Mode Option = %s\n", buf);
-
-	buf[sizeof(buf) - 1] = '\0';
-
-	for (i = 0; i < max_options; i++) {
-		if (!strcmp(buf, option[i]))
-			break;
-	}
-
-	switch (i) {
-
-	case 0:
-		Adapter->ScanMode = HostCmd_BSS_TYPE_BSS;
-		break;
-	case 1:
-		Adapter->ScanMode = HostCmd_BSS_TYPE_IBSS;
-		break;
-	case 2:
-		Adapter->ScanMode = HostCmd_BSS_TYPE_ANY;
-		break;
-	case 3:
-
-		wrq->u.data.length = strlen(option[Adapter->ScanMode - 1]) + 1;
-
-		PRINTM(INFO, "Get Scan Mode Option = %s\n",
-		       option[Adapter->ScanMode - 1]);
-
-		PRINTM(INFO, "Scan Mode Length %d\n", wrq->u.data.length);
-
-		if (copy_to_user(wrq->u.data.pointer,
-				 option[Adapter->ScanMode - 1],
-				 wrq->u.data.length)) {
-			PRINTM(INFO, "Copy to user failed\n");
-			ret = -EFAULT;
-		}
-		PRINTM(INFO, "GET Scan Type Option after copy = %s\n",
-		       (char *)wrq->u.data.pointer);
-
-		break;
-
-	default:
-		PRINTM(INFO, "Invalid Scan Mode Ioctl Option\n");
-		ret = -EINVAL;
-		break;
-	}
-
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Get/Set Adhoc G Rate
- *  
- *  @param priv		A pointer to wlan_private structure
- *  @param wrq	   	A pointer to user data
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-static int wlan_do_set_grate_ioctl(wlan_private * priv, struct iwreq *wrq)
-{
-	wlan_adapter *Adapter = priv->adapter;
-	int data, data1;
-	int *val;
-
-	ENTER();
-
-	data1 = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-	switch (data1) {
-	case 0:
-		Adapter->adhoc_grate_enabled = 0;
-		break;
-	case 1:
-		Adapter->adhoc_grate_enabled = 1;
-		break;
-	case 2:
-		break;
-	default:
-		return -EINVAL;
-	}
-	data = Adapter->adhoc_grate_enabled;
-	val = (int *)wrq->u.name;
-	*val = data;
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief ioctl function - entry point
- *  
- *  @param dev		A pointer to net_device structure
- *  @param req	   	A pointer to ifreq structure
- *  @param cmd 		command
- *  @return 	   	WLAN_STATUS_SUCCESS--success, otherwise fail
- */
-int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
-{
-	int subcmd = 0;
-	int idata = 0;
-	int *pdata;
-	int ret = WLAN_STATUS_SUCCESS;
-	wlan_private *priv = dev->priv;
-	wlan_adapter *Adapter = priv->adapter;
-	struct iwreq *wrq = (struct iwreq *)req;
-
-	ENTER();
-
-	PRINTM(INFO, "libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd);
-	switch (cmd) {
-	case WLANEXTSCAN:
-		ret = libertas_extscan_ioctl(priv, req);
-		break;
-	case WLANHOSTCMD:
-		ret = wlan_hostcmd_ioctl(dev, req, cmd);
-		break;
-
-	case WLANCISDUMP:	/* Read CIS Table  */
-		ret = wlan_do_getcis_ioctl(priv, req);
-		break;
-
-	case WLANSCAN_TYPE:
-		PRINTM(INFO, "Scan Type Ioctl\n");
-		ret = wlan_scan_type_ioctl(priv, wrq);
-		break;
-
-	case WLANREGRDWR:	/* Register read write command */
-		ret = wlan_regrdwr_ioctl(priv, req);
-		break;
-
-	case SIOCSIWENCODE:	/* set encoding token & mode for WPA */
-		ret = wlan_set_encode(dev, NULL, &(wrq->u.data),
-				      wrq->u.data.pointer);
-		break;
-	case WLAN_SETNONE_GETNONE:	/* set WPA mode on/off ioctl #20 */
-		switch (wrq->u.data.flags) {
-		case WLANDEAUTH:
-			PRINTM(INFO, "Deauth\n");
-			libertas_send_deauth(priv);
-			break;
-
-		case WLANADHOCSTOP:
-			PRINTM(INFO, "Adhoc stop\n");
-			ret = libertas_do_adhocstop_ioctl(priv);
-			break;
-
-		case WLANRADIOON:
-			wlan_radio_ioctl(priv, RADIO_ON);
-			break;
-
-		case WLANRADIOOFF:
-			wlan_radio_ioctl(priv, RADIO_OFF);
-			break;
-#ifdef REASSOCIATION
-		case WLANREASSOCIATIONAUTO:
-			reassociation_on(priv);
-			break;
-		case WLANREASSOCIATIONUSER:
-			reassociation_off(priv);
-			break;
-#endif				/* REASSOCIATION */
-		case WLANWLANIDLEON:
-			libertas_idle_on(priv);
-			break;
-		case WLANWLANIDLEOFF:
-			libertas_idle_off(priv);
-			break;
-		case WLAN_SUBCMD_DFT_RESET:	/* dft_reset */
-			wlan_dft_reset_ioctl(priv);
-			break;
-		case WLAN_SUBCMD_BT_RESET:	/* bt_reset */
-			wlan_bt_reset_ioctl(priv);
-			break;
-		}		/* End of switch */
-		break;
-
-	case WLAN_SETWORDCHAR_GETNONE:
-		switch (wrq->u.data.flags) {
-		}
-		break;
-
-	case WLAN_SETNONE_GETWORDCHAR:
-		switch (wrq->u.data.flags) {
-		case WLANVERSION:	/* Get driver version */
-			ret = wlan_version_ioctl(priv, req);
-			break;
-		}
-		break;
-	case WLANSETWPAIE:
-		ret = wlan_setwpaie_ioctl(priv, req);
-		break;
-	case WLAN_SETINT_GETINT:
-		/* The first 4 bytes of req->ifr_data is sub-ioctl number
-		 * after 4 bytes sits the payload.
-		 */
-		subcmd = (int)req->ifr_data;	//from iwpriv subcmd
-		switch (subcmd) {
-		case WLANNF:
-			ret = wlan_get_nf(priv, wrq);
-			break;
-		case WLANRSSI:
-			ret = wlan_get_rssi(priv, wrq);
-			break;
-		case WLANENABLE11D:
-			ret = libertas_cmd_enable_11d(priv, wrq);
-			break;
-		case WLANADHOCGRATE:
-			ret = wlan_do_set_grate_ioctl(priv, wrq);
-			break;
-		case WLAN_SUBCMD_SET_PRESCAN:
-			ret = wlan_subcmd_setprescan_ioctl(priv, wrq);
-			break;
-		}
-		break;
-
-	case WLAN_SETONEINT_GETONEINT:
-		switch (wrq->u.data.flags) {
-		case WLAN_BEACON_INTERVAL:
-			ret = wlan_beacon_interval(priv, wrq);
-			break;
-
-		case WLAN_LISTENINTRVL:
-			if (!wrq->u.data.length) {
-				int data;
-				PRINTM(INFO, "Get LocalListenInterval Value\n");
-#define GET_ONE_INT	1
-				data = Adapter->LocalListenInterval;
-				if (copy_to_user(wrq->u.data.pointer,
-						 &data, sizeof(int))) {
-					PRINTM(INFO, "Copy to user failed\n");
-					return -EFAULT;
-				}
-
-				wrq->u.data.length = GET_ONE_INT;
-			} else {
-				int data;
-				if (copy_from_user
-				    (&data, wrq->u.data.pointer, sizeof(int))) {
-					PRINTM(INFO, "Copy from user failed\n");
-					return -EFAULT;
-				}
-
-				PRINTM(INFO, "Set LocalListenInterval = %d\n",
-				       data);
-#define MAX_U16_VAL	65535
-				if (data > MAX_U16_VAL) {
-					PRINTM(INFO, "Exceeds U16 value\n");
-					return -EINVAL;
-				}
-				Adapter->LocalListenInterval = data;
-			}
-			break;
-		case WLAN_TXCONTROL:
-			ret = wlan_txcontrol(priv, wrq);	//adds for txcontrol ioctl
-			break;
-
-		case WLAN_NULLPKTINTERVAL:
-			ret = wlan_null_pkt_interval(priv, wrq);
-			break;
-
-		default:
-			ret = -EOPNOTSUPP;
-			break;
-		}
-		break;
-
-	case WLAN_SETONEINT_GETNONE:
-		/* The first 4 bytes of req->ifr_data is sub-ioctl number
-		 * after 4 bytes sits the payload.
-		 */
-		subcmd = wrq->u.data.flags;	//from wpa_supplicant subcmd
-
-		if (!subcmd)
-			subcmd = (int)req->ifr_data;	//from iwpriv subcmd
-
-		switch (subcmd) {
-		case WLAN_SUBCMD_SETRXANTENNA:	/* SETRXANTENNA */
-			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			ret = SetRxAntenna(priv, idata);
-			break;
-		case WLAN_SUBCMD_SETTXANTENNA:	/* SETTXANTENNA */
-			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			ret = SetTxAntenna(priv, idata);
-			break;
-		case WLAN_SET_ATIM_WINDOW:
-			Adapter->AtimWindow =
-			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			Adapter->AtimWindow = min_t(__u16, Adapter->AtimWindow, 50);
-			break;
-		case WLANSETBCNAVG:
-			Adapter->bcn_avg_factor =
-			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			if (Adapter->bcn_avg_factor == 0)
-				Adapter->bcn_avg_factor =
-				    DEFAULT_BCN_AVG_FACTOR;
-			if (Adapter->bcn_avg_factor > DEFAULT_BCN_AVG_FACTOR)
-				Adapter->bcn_avg_factor =
-				    DEFAULT_BCN_AVG_FACTOR;
-			break;
-		case WLANSETDATAAVG:
-			Adapter->data_avg_factor =
-			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			if (Adapter->data_avg_factor == 0)
-				Adapter->data_avg_factor =
-				    DEFAULT_DATA_AVG_FACTOR;
-			if (Adapter->data_avg_factor > DEFAULT_DATA_AVG_FACTOR)
-				Adapter->data_avg_factor =
-				    DEFAULT_DATA_AVG_FACTOR;
-			break;
-		case WLANSETREGION:
-			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			ret = wlan_set_region(priv, (u16) idata);
-			break;
-
-		case WLAN_SET_LISTEN_INTERVAL:
-			idata = *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			Adapter->ListenInterval = (u16) idata;
-			break;
-
-		case WLAN_SET_MULTIPLE_DTIM:
-			ret = wlan_set_multiple_dtim_ioctl(priv, req);
-			break;
-
-		case WLANSETAUTHALG:
-			ret = wlan_setauthalg_ioctl(priv, req);
-			break;
-
-		case WLANSET8021XAUTHALG:
-			ret = wlan_set8021xauthalg_ioctl(priv, req);
-			break;
-
-		case WLANSETENCRYPTIONMODE:
-			ret = wlan_setencryptionmode_ioctl(priv, req);
-			break;
-
-		case WLAN_SET_LINKMODE:
-			ret = wlan_set_linkmode_ioctl(priv, req);
-			break;
-
-		case WLAN_SET_RADIOMODE:
-			ret = wlan_set_radiomode_ioctl(priv, req);
-			break;
-
-		case WLAN_SET_DEBUGMODE:
-			ret = wlan_set_debugmode_ioctl(priv, req);
-			break;
-
-		default:
-			ret = -EOPNOTSUPP;
-			break;
-		}
-
-		break;
-
-	case WLAN_SETNONE_GETTWELVE_CHAR:	/* Get Antenna settings */
-		/* 
-		 * We've not used IW_PRIV_TYPE_FIXED so sub-ioctl number is
-		 * in flags of iwreq structure, otherwise it will be in
-		 * mode member of iwreq structure.
-		 */
-		switch ((int)wrq->u.data.flags) {
-		case WLAN_SUBCMD_GETRXANTENNA:	/* Get Rx Antenna */
-			ret = wlan_subcmd_getrxantenna_ioctl(priv, req);
-			break;
-
-		case WLAN_SUBCMD_GETTXANTENNA:	/* Get Tx Antenna */
-			ret = wlan_subcmd_gettxantenna_ioctl(priv, req);
-			break;
-
-		case WLAN_GET_TSF:
-			ret = wlan_get_tsf_ioctl(priv, wrq);
-			break;
-		}
-		break;
-
-	case WLAN_SET64CHAR_GET64CHAR:
-		switch ((int)wrq->u.data.flags) {
-
-		case WLANSLEEPPARAMS:
-			ret = wlan_sleep_params_ioctl(priv, wrq);
-			break;
-
-		case WLANSCAN_MODE:
-			PRINTM(INFO, "Scan Mode Ioctl\n");
-			ret = wlan_scan_mode_ioctl(priv, wrq);
-			break;
-
-		case WLAN_GET_ADHOC_STATUS:
-			ret = wlan_get_adhoc_status_ioctl(priv, wrq);
-			break;
-		case WLAN_SUBCMD_DFT_ADD:
-			ret = wlan_dft_add_ioctl(priv, req);
-			break;
-		case WLAN_SUBCMD_DFT_DEL:
-			ret = wlan_dft_del_ioctl(priv, req);
-			break;
-		case WLAN_SUBCMD_DFT_LIST:
-			ret = wlan_dft_list_ioctl(priv, req);
-			break;
-		case WLAN_SUBCMD_BT_ADD:
-			ret = wlan_bt_add_ioctl(priv, req);
-			break;
-		case WLAN_SUBCMD_BT_DEL:
-			ret = wlan_bt_del_ioctl(priv, req);
-			break;
-		case WLAN_SUBCMD_BT_LIST:
-			ret = wlan_bt_list_ioctl(priv, req);
-			break;
-		}
-		break;
-
-	case WLAN_SETCONF_GETCONF:
-		PRINTM(INFO, "The WLAN_SETCONF_GETCONF=0x%x is %d\n",
-		       WLAN_SETCONF_GETCONF, *(u8 *) req->ifr_data);
-		switch (*(u8 *) req->ifr_data) {
-
-		}
-		break;
-
-	case WLAN_SETNONE_GETONEINT:
-		switch ((int)req->ifr_data) {
-		case WLANGETBCNAVG:
-			pdata = (int *)wrq->u.name;
-			*pdata = (int)Adapter->bcn_avg_factor;
-			break;
-
-		case WLANGETREGION:
-			pdata = (int *)wrq->u.name;
-			*pdata = (int)Adapter->RegionCode;
-			break;
-
-		case WLAN_GET_LISTEN_INTERVAL:
-			pdata = (int *)wrq->u.name;
-			*pdata = (int)Adapter->ListenInterval;
-			break;
-
-		case WLAN_GET_LINKMODE:
-			req->ifr_data = (char *)((u32) Adapter->linkmode);
-			break;
-
-		case WLAN_GET_RADIOMODE:
-			req->ifr_data = (char *)((u32) Adapter->radiomode);
-			break;
-
-		case WLAN_GET_DEBUGMODE:
-			req->ifr_data = (char *)((u32) Adapter->debugmode);
-			break;
-
-		case WLAN_GET_MULTIPLE_DTIM:
-			pdata = (int *)wrq->u.name;
-			*pdata = (int)Adapter->MultipleDtim;
-			break;
-		case WLAN_GET_TX_RATE:
-			ret = wlan_get_txrate_ioctl(priv, req);
-			break;
-		default:
-			ret = -EOPNOTSUPP;
-
-		}
-
-		break;
-
-	case WLAN_SETTENCHAR_GETNONE:
-		switch ((int)wrq->u.data.flags) {
-
-		}
-		break;
-
-	case WLAN_SETNONE_GETTENCHAR:
-		switch ((int)wrq->u.data.flags) {
-		}
-		break;
-
-	case WLANGETLOG:
-		ret = wlan_do_getlog_ioctl(priv, wrq);
-		break;
-
-	case WLAN_SET_GET_SIXTEEN_INT:
-		switch ((int)wrq->u.data.flags) {
-		case WLAN_TPCCFG:
-			{
-				int data[5];
-				struct HostCmd_DS_802_11_TPC_CFG cfg;
-				memset(&cfg, 0, sizeof(cfg));
-				if ((wrq->u.data.length > 1)
-				    && (wrq->u.data.length != 5))
-					return WLAN_STATUS_FAILURE;
-
-				if (wrq->u.data.length == 0) {
-					cfg.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_GET);
-				} else {
-					if (copy_from_user
-					    (data, wrq->u.data.pointer,
-					     sizeof(int) * 5)) {
-						PRINTM(INFO,
-						       "Copy from user failed\n");
-						return -EFAULT;
-					}
-
-					cfg.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_SET);
-					cfg.Enable = data[0];
-					cfg.UseSNR = data[1];
-					cfg.P0 = data[2];
-					cfg.P1 = data[3];
-					cfg.P2 = data[4];
-				}
-
-				ret =
-				    libertas_prepare_and_send_command(priv,
-							  HostCmd_CMD_802_11_TPC_CFG,
-							  0,
-							  HostCmd_OPTION_WAITFORRSP,
-							  0, (void *)&cfg);
-
-				data[0] = cfg.Enable;
-				data[1] = cfg.UseSNR;
-				data[2] = cfg.P0;
-				data[3] = cfg.P1;
-				data[4] = cfg.P2;
-				if (copy_to_user
-				    (wrq->u.data.pointer, data,
-				     sizeof(int) * 5)) {
-					PRINTM(INFO, "Copy to user failed\n");
-					return -EFAULT;
-				}
-
-				wrq->u.data.length = 5;
-			}
-			break;
-
-		case WLAN_POWERCFG:
-			{
-				int data[4];
-				struct HostCmd_DS_802_11_PWR_CFG cfg;
-				memset(&cfg, 0, sizeof(cfg));
-				if ((wrq->u.data.length > 1)
-				    && (wrq->u.data.length != 4))
-					return WLAN_STATUS_FAILURE;
-				if (wrq->u.data.length == 0) {
-					cfg.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_GET);
-				} else {
-					if (copy_from_user
-					    (data, wrq->u.data.pointer,
-					     sizeof(int) * 4)) {
-						PRINTM(INFO,
-						       "Copy from user failed\n");
-						return -EFAULT;
-					}
-
-					cfg.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_SET);
-					cfg.Enable = data[0];
-					cfg.PA_P0 = data[1];
-					cfg.PA_P1 = data[2];
-					cfg.PA_P2 = data[3];
-				}
-				ret =
-				    libertas_prepare_and_send_command(priv,
-							  HostCmd_CMD_802_11_PWR_CFG,
-							  0,
-							  HostCmd_OPTION_WAITFORRSP,
-							  0, (void *)&cfg);
-				data[0] = cfg.Enable;
-				data[1] = cfg.PA_P0;
-				data[2] = cfg.PA_P1;
-				data[3] = cfg.PA_P2;
-				if (copy_to_user
-				    (wrq->u.data.pointer, data,
-				     sizeof(int) * 4)) {
-					PRINTM(INFO, "Copy to user failed\n");
-					return -EFAULT;
-				}
-
-				wrq->u.data.length = 4;
-			}
-			break;
-		case WLAN_AUTO_FREQ_SET:
-			{
-				int data[3];
-				struct HostCmd_DS_802_11_AFC afc;
-				memset(&afc, 0, sizeof(afc));
-				if (wrq->u.data.length != 3)
-					return WLAN_STATUS_FAILURE;
-				if (copy_from_user
-				    (data, wrq->u.data.pointer,
-				     sizeof(int) * 3)) {
-					PRINTM(INFO, "Copy from user failed\n");
-					return -EFAULT;
-				}
-				afc.afc_auto = data[0];
-
-				if (afc.afc_auto != 0) {
-					afc.afc_thre = data[1];
-					afc.afc_period = data[2];
-				} else {
-					afc.afc_toff = data[1];
-					afc.afc_foff = data[2];
-				}
-				ret =
-				    libertas_prepare_and_send_command(priv,
-							  HostCmd_CMD_802_11_SET_AFC,
-							  0,
-							  HostCmd_OPTION_WAITFORRSP,
-							  0, (void *)&afc);
-			}
-			break;
-		case WLAN_AUTO_FREQ_GET:
-			{
-				int data[3];
-				struct HostCmd_DS_802_11_AFC afc;
-				memset(&afc, 0, sizeof(afc));
-				ret =
-				    libertas_prepare_and_send_command(priv,
-							  HostCmd_CMD_802_11_GET_AFC,
-							  0,
-							  HostCmd_OPTION_WAITFORRSP,
-							  0, (void *)&afc);
-				data[0] = afc.afc_auto;
-				data[1] = afc.afc_toff;
-				data[2] = afc.afc_foff;
-				if (copy_to_user
-				    (wrq->u.data.pointer, data,
-				     sizeof(int) * 3)) {
-					PRINTM(INFO, "Copy to user failed\n");
-					return -EFAULT;
-				}
-
-				wrq->u.data.length = 3;
-			}
-			break;
-		case WLAN_SCANPROBES:
-			{
-				int data;
-				if (wrq->u.data.length > 0) {
-					if (copy_from_user
-					    (&data, wrq->u.data.pointer,
-					     sizeof(int))) {
-						PRINTM(INFO,
-						       "Copy from user failed\n");
-						return -EFAULT;
-					}
-
-					Adapter->ScanProbes = data;
-				} else {
-					data = Adapter->ScanProbes;
-					if (copy_to_user
-					    (wrq->u.data.pointer, &data,
-					     sizeof(int))) {
-						PRINTM(INFO,
-						       "Copy to user failed\n");
-						return -EFAULT;
-					}
-				}
-				wrq->u.data.length = 1;
-			}
-			break;
-		case WLAN_LED_GPIO_CTRL:
-			{
-				int i;
-				int data[16];
-
-				struct HostCmd_DS_802_11_LED_CTRL ctrl;
-				struct MrvlIEtypes_LedGpio *gpio =
-				    (struct MrvlIEtypes_LedGpio *) ctrl.data;
-
-				memset(&ctrl, 0, sizeof(ctrl));
-				if (wrq->u.data.length > MAX_LEDS * 2)
-					return -ENOTSUPP;
-				if ((wrq->u.data.length % 2) != 0)
-					return -ENOTSUPP;
-				if (wrq->u.data.length == 0) {
-					ctrl.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_GET);
-				} else {
-					if (copy_from_user
-					    (data, wrq->u.data.pointer,
-					     sizeof(int) *
-					     wrq->u.data.length)) {
-						PRINTM(INFO,
-						       "Copy from user failed\n");
-						return -EFAULT;
-					}
-
-					ctrl.Action =
-					    wlan_cpu_to_le16
-					    (HostCmd_ACT_GEN_SET);
-					ctrl.NumLed = wlan_cpu_to_le16(0);
-					gpio->Header.Type =
-					    wlan_cpu_to_le16(TLV_TYPE_LED_GPIO);
-					gpio->Header.Len = wrq->u.data.length;
-					for (i = 0; i < wrq->u.data.length;
-					     i += 2) {
-						gpio->LedPin[i / 2].Led =
-						    data[i];
-						gpio->LedPin[i / 2].Pin =
-						    data[i + 1];
-					}
-				}
-				ret =
-				    libertas_prepare_and_send_command(priv,
-							  HostCmd_CMD_802_11_LED_GPIO_CTRL,
-							  0,
-							  HostCmd_OPTION_WAITFORRSP,
-							  0, (void *)&ctrl);
-				for (i = 0; i < gpio->Header.Len; i += 2) {
-					data[i] = gpio->LedPin[i / 2].Led;
-					data[i + 1] = gpio->LedPin[i / 2].Pin;
-				}
-				if (copy_to_user(wrq->u.data.pointer, data,
-						 sizeof(int) *
-						 gpio->Header.Len)) {
-					PRINTM(INFO, "Copy to user failed\n");
-					return -EFAULT;
-				}
-
-				wrq->u.data.length = gpio->Header.Len;
-			}
-			break;
-		case WLAN_SLEEP_PERIOD:
-			ret = wlan_sleep_period(priv, wrq);
-			break;
-		case WLAN_ADAPT_RATESET:
-			ret = wlan_adapt_rateset(priv, wrq);
-			break;
-		case WLAN_INACTIVITY_TIMEOUT:
-			ret = wlan_inactivity_timeout(priv, wrq);
-			break;
-		case WLANSNR:
-			ret = wlan_get_snr(priv, wrq);
-			break;
-		case WLAN_GET_RXINFO:
-			ret = wlan_get_rxinfo(priv, wrq);
-		}
-		break;
-
-	case WLAN_SET_GET_2K:
-		switch ((int)wrq->u.data.flags) {
-		case WLAN_SET_USER_SCAN:
-			ret = libertas_set_user_scan_ioctl(priv, wrq);
-			break;
-		case WLAN_GET_SCAN_TABLE:
-			ret = libertas_get_scan_table_ioctl(priv, wrq);
-			break;
-
-		default:
-			ret = -EOPNOTSUPP;
-		}
-		break;
-	default:
-		ret = -EINVAL;
-		break;
-	}
-	LEAVE();
-	return ret;
-}
-
-/** 
- *  @brief Get wireless statistics
- *  
- *  @param dev		A pointer to net_device structure
- *  @return 	   	A pointer to iw_statistics buf
- */
-static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
-{
-	enum {
-		POOR = 30,
-		FAIR = 60,
-		GOOD = 80,
-		VERY_GOOD = 90,
-		EXCELLENT = 95,
-		PERFECT = 100
-	};
-	wlan_private *priv = dev->priv;
-	wlan_adapter *Adapter = priv->adapter;
-	int ret = WLAN_STATUS_SUCCESS;
-	u32 rssi_qual;
-	u32 tx_qual;
-	u32 quality = 0;
-	int stats_valid = 0;
-	u8 rssi;
-
-	ENTER();
-
-	priv->wstats.status = Adapter->InfrastructureMode;
-
-	/* If we're not associated, all quality values are meaningless */
-	if (Adapter->MediaConnectStatus != WlanMediaStateConnected)
-		goto out;
-
-	/* send RSSI command to get beacon RSSI/NF, valid only if associated */
-	ret = libertas_prepare_and_send_command(priv,
-				    HostCmd_CMD_802_11_RSSI,
-				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
-	if (ret)
-		goto out;
-
-	/* Quality by RSSI */
-	priv->wstats.qual.level =
-	    CAL_RSSI(Adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
-	     Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
-
-	if (Adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
-		priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
-	} else {
-		priv->wstats.qual.noise =
-		    CAL_NF(Adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
-	}
-
-	PRINTM(INFO, "Signal Level = %#x\n", priv->wstats.qual.level);
-	PRINTM(INFO, "Noise = %#x\n", priv->wstats.qual.noise);
-
-	rssi = priv->wstats.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
-	if (rssi < 15)
-		rssi_qual = rssi * POOR / 10;
-	else if (rssi < 20)
-		rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
-	else if (rssi < 30)
-		rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
-	else if (rssi < 40)
-		rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
-		    10 + GOOD;
-	else
-		rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
-		    10 + VERY_GOOD;
-	quality = rssi_qual;
-
-	/* Quality by TX errors */
-	priv->wstats.discard.retries = priv->stats.tx_errors;
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_802_11_GET_LOG,
-				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
-	if (!ret) {
-		u32 tx_retries = Adapter->LogMsg.retry;
-
-		if (tx_retries > 75)
-			tx_qual = (90 - tx_retries) * POOR / 15;
-		else if (tx_retries > 70)
-			tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
-		else if (tx_retries > 65)
-			tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
-		else if (tx_retries > 50)
-			tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
-			    15 + GOOD;
-		else
-			tx_qual = (50 - tx_retries) *
-			    (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
-		quality = min(quality, tx_qual);
-
-		priv->wstats.discard.code = Adapter->LogMsg.wepundecryptable;
-		priv->wstats.discard.fragment = Adapter->LogMsg.fcserror;
-		priv->wstats.discard.retries = tx_retries;
-		priv->wstats.discard.misc = Adapter->LogMsg.ackfailure;
-	}
-
-	/* Calculate quality */
-	priv->wstats.qual.qual = max(quality, (u32)100);
-	priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
-	stats_valid = 1;
-
-out:
-	if (!stats_valid) {
-		priv->wstats.miss.beacon = 0;
-		priv->wstats.discard.retries = 0;
-		priv->wstats.qual.qual = 0;
-		priv->wstats.qual.level = 0;
-		priv->wstats.qual.noise = 0;
-		priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
-		priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
-		    IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
-	}
-
-	LEAVE ();
-	return &priv->wstats;
-
-
-}
-
-/** 
- *  @brief Set frequency
+ *  @brief Set frequency
  *   
  *  @param priv 		A pointer to wlan_private structure
  *  @param info			A pointer to iw_request_info structure 
@@ -5103,8 +2721,6 @@ int wlan_set_txpow(struct net_device *de
 	wlan_private *priv = dev->priv;
 	wlan_adapter *Adapter = priv->adapter;
 
-	int wlan_radio_ioctl(wlan_private * priv, u8 option);
-
 	u16 dbm;
 
 	ENTER();
@@ -5214,359 +2830,4 @@ void libertas_get_version(wlan_adapter *
 	snprintf(version, maxlen, libertas_driver_version, fwver);
 }
 
-static inline int hex2int(char c)
-{
-	if (c >= '0' && c <= '9')
-		return (c - '0');
-	if (c >= 'a' && c <= 'f')
-		return (c - 'a' + 10);
-	if (c >= 'A' && c <= 'F')
-		return (c - 'A' + 10);
-	return -1;
-}
-
-/* Convert a string representation of a MAC address ("xx:xx:xx:xx:xx:xx")
-   into binary format (6 bytes).
-
-   This function expects that each byte is represented with 2 characters
-   (e.g., 11:2:11:11:11:11 is invalid) 
-
- */
-static char *eth_str2addr(char *ethstr, u8 * addr)
-{
-	int i, val, val2;
-	char *pos = ethstr;
-
-	/* get rid of initial blanks */
-	while (*pos == ' ' || *pos == '\t')
-		++pos;
-
-	for (i = 0; i < 6; i++) {
-		val = hex2int(*pos++);
-		if (val < 0)
-			return NULL;
-		val2 = hex2int(*pos++);
-		if (val2 < 0)
-			return NULL;
-		addr[i] = (val * 16 + val2) & 0xff;
-
-		if (i < 5 && *pos++ != ':')
-			return NULL;
-	}
-	return pos;
-}
-
-/* this writes xx:xx:xx:xx:xx:xx into ethstr 
-   (ethstr must have space for 18 chars) */
-static int eth_addr2str(u8 * addr, char *ethstr)
-{
-	int i;
-	char *pos = ethstr;
-
-	for (i = 0; i < 6; i++) {
-		sprintf(pos, "%02x", addr[i] & 0xff);
-		pos += 2;
-		if (i < 5)
-			*pos++ = ':';
-	}
-	return 17;
-}
-
-/** 
- *  @brief          Add an entry to the DFT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_dft_add_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	char ethaddrs_str[36];
-	char *pos;
-	u8 ethaddrs[2 * ETH_ALEN];
-#define ethaddr1 (ethaddrs+0)
-#define ethaddr2 (ethaddrs+6)
-
-	ENTER();
-	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
-			   sizeof(ethaddrs_str)))
-		return -EFAULT;
-
-	if ((pos = eth_str2addr(ethaddrs_str, ethaddr1)) == NULL) {
-		PRINTM(FATAL, "DFT_ADD: Invalid MAC address 1\n");
-		return -EINVAL;
-	}
-
-	if (eth_str2addr(pos, ethaddr2) == NULL) {
-		PRINTM(FATAL, "DFT_ADD: Invalid MAC address 2\n");
-		return -EINVAL;
-	}
-#ifdef DEBUG_LEVEL4
-	{
-		char ethaddr1_str[18], ethaddr2_str[18];
-		PRINTM(INFO, "DFT: adding %s\n", ethaddrs_str);
-		eth_addr2str(ethaddr1, ethaddr1_str);
-		eth_addr2str(ethaddr2, ethaddr2_str);
-		PRINTM(INFO, "DFT: adding (%s,%s)\n", ethaddr1_str,
-		       ethaddr2_str);
-	}
-#endif
-
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_DFT_ACCESS_ADD,
-				      HostCmd_OPTION_WAITFORRSP, 0, ethaddrs));
-}
-
-/** 
- *  @brief          Delete an entry from the DFT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_dft_del_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	char ethaddrs_str[18];
-	u8 ethaddr[ETH_ALEN];
-	char *pos;
-
-	ENTER();
-	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
-			   sizeof(ethaddrs_str)))
-		return -EFAULT;
-
-	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
-		PRINTM(FATAL, "Invalid MAC address\n");
-		return -EINVAL;
-	}
-
-	PRINTM(INFO, "DFT: deleting %s\n", ethaddrs_str);
-
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv,
-				      HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_DFT_ACCESS_DEL,
-				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
-}
-
-/** 
- *  @brief          Reset all entries from the DFT table
- *  @param priv     A pointer to wlan_private structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_dft_reset_ioctl(wlan_private * priv)
-{
-	ENTER();
-
-	PRINTM(MSG, "DFT: resetting\n");
-
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv,
-				      HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_DFT_ACCESS_RESET,
-				      HostCmd_OPTION_WAITFORRSP, 0, NULL));
-}
-
-/** 
- *  @brief          List an entry from the DFT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_dft_list_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int pos;
-	char *addr1, *addr2;
-	struct iwreq *wrq = (struct iwreq *)req;
-	/* used to pass id and store the dft entry returned by the FW */
-	union {
-		int id;
-		char addr1addr2[2 * ETH_ALEN];
-	} param;
-	static char outstr[64];
-	char *pbuf = outstr;
-	int ret;
-
-	ENTER();
-
-	if (copy_from_user(outstr, wrq->u.data.pointer, sizeof(outstr))) {
-		PRINTM(INFO, "Copy from user failed\n");
-		return WLAN_STATUS_FAILURE;
-	}
-	param.id = simple_strtoul(outstr, NULL, 10);
-	pos = sprintf(pbuf, "%d: ", param.id);
-	pbuf += pos;
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
-				    HostCmd_ACT_DFT_ACCESS_LIST,
-				    HostCmd_OPTION_WAITFORRSP, 0,
-				    (char *)&param);
-
-	if (ret == WLAN_STATUS_SUCCESS) {
-		addr1 = param.addr1addr2;
-		addr2 = param.addr1addr2 + ETH_ALEN;
-
-		pos = sprintf(pbuf, "da ");
-		pbuf += pos;
-		pos = eth_addr2str(addr1, pbuf);
-		pbuf += pos;
-		pos = sprintf(pbuf, "    next hop ");
-		pbuf += pos;
-		pos = eth_addr2str(addr2, pbuf);
-		pbuf += pos;
-	} else {
-		sprintf(pbuf, "(null)");
-		pbuf += pos;
-	}
-	wrq->u.data.length = strlen(outstr);
-	if (copy_to_user(wrq->u.data.pointer, (char *)outstr,
-			 wrq->u.data.length)) {
-		PRINTM(INFO, "DFT_LIST: Copy to user failed!\n");
-		return -EFAULT;
-	}
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief          Add an entry to the BT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_bt_add_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	char ethaddrs_str[18];
-	char *pos;
-	u8 ethaddr[ETH_ALEN];
-
-	ENTER();
-	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
-			   sizeof(ethaddrs_str)))
-		return -EFAULT;
-
-	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
-		PRINTM(FATAL, "BT_ADD: Invalid MAC address\n");
-		return -EINVAL;
-	}
-
-	PRINTM(INFO, "BT: adding %s\n", ethaddrs_str);
-	LEAVE();
-	return (libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_BT_ACCESS_ADD,
-				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
-}
-
-/** 
- *  @brief          Delete an entry from the BT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_bt_del_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	struct iwreq *wrq = (struct iwreq *)req;
-	char ethaddrs_str[18];
-	u8 ethaddr[ETH_ALEN];
-	char *pos;
-
-	ENTER();
-	if (copy_from_user(ethaddrs_str, wrq->u.data.pointer,
-			   sizeof(ethaddrs_str)))
-		return -EFAULT;
-
-	if ((pos = eth_str2addr(ethaddrs_str, ethaddr)) == NULL) {
-		PRINTM(FATAL, "Invalid MAC address\n");
-		return -EINVAL;
-	}
-
-	PRINTM(INFO, "BT: deleting %s\n", ethaddrs_str);
-
-	return (libertas_prepare_and_send_command(priv,
-				      HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_BT_ACCESS_DEL,
-				      HostCmd_OPTION_WAITFORRSP, 0, ethaddr));
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief          Reset all entries from the BT table
- *  @param priv     A pointer to wlan_private structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_bt_reset_ioctl(wlan_private * priv)
-{
-	ENTER();
-
-	PRINTM(MSG, "BT: resetting\n");
-
-	return (libertas_prepare_and_send_command(priv,
-				      HostCmd_CMD_DFT_ACCESS,
-				      HostCmd_ACT_BT_ACCESS_RESET,
-				      HostCmd_OPTION_WAITFORRSP, 0, NULL));
-
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
-
-/** 
- *  @brief          List an entry from the BT table
- *  @param priv     A pointer to wlan_private structure
- *  @param req      A pointer to ifreq structure
- *  @return         WLAN_STATUS_SUCCESS --success, otherwise fail
- */
-static int wlan_bt_list_ioctl(wlan_private * priv, struct ifreq *req)
-{
-	int pos;
-	char *addr1;
-	struct iwreq *wrq = (struct iwreq *)req;
-	/* used to pass id and store the bt entry returned by the FW */
-	union {
-		int id;
-		char addr1addr2[2 * ETH_ALEN];
-	} param;
-	static char outstr[64];
-	char *pbuf = outstr;
-	int ret;
-
-	ENTER();
-
-	if (copy_from_user(outstr, wrq->u.data.pointer, sizeof(outstr))) {
-		PRINTM(INFO, "Copy from user failed\n");
-		return WLAN_STATUS_FAILURE;
-	}
-	param.id = simple_strtoul(outstr, NULL, 10);
-	pos = sprintf(pbuf, "%d: ", param.id);
-	pbuf += pos;
-
-	ret = libertas_prepare_and_send_command(priv, HostCmd_CMD_DFT_ACCESS,
-				    HostCmd_ACT_BT_ACCESS_LIST,
-				    HostCmd_OPTION_WAITFORRSP, 0,
-				    (char *)&param);
-
-	if (ret == WLAN_STATUS_SUCCESS) {
-		addr1 = param.addr1addr2;
-
-		pos = sprintf(pbuf, "ignoring traffic from ");
-		pbuf += pos;
-		pos = eth_addr2str(addr1, pbuf);
-		pbuf += pos;
-	} else {
-		sprintf(pbuf, "(null)");
-		pbuf += pos;
-	}
-
-	wrq->u.data.length = strlen(outstr);
-	if (copy_to_user(wrq->u.data.pointer, (char *)outstr,
-			 wrq->u.data.length)) {
-		PRINTM(INFO, "BT_LIST: Copy to user failed!\n");
-		return -EFAULT;
-	}
 
-	LEAVE();
-	return WLAN_STATUS_SUCCESS;
-}
Index: linus-2.6/drivers/net/wireless/libertas/wlan_wext.h
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_wext.h
+++ linus-2.6/drivers/net/wireless/libertas/wlan_wext.h
@@ -70,6 +70,8 @@ Change log:
 #define WLANGETLOG                  	(WLANIOCTL + 9)
 #define WLAN_SETCONF_GETCONF		(WLANIOCTL + 10)
 
+#define GETLOG_BUFSIZE  300
+
 #define WLANSCAN_TYPE			(WLANIOCTL + 11)
 
 #define WLAN_SET_GET_2K         (WLANIOCTL + 13)
@@ -239,6 +241,10 @@ typedef struct _wlan_ioctl_adhoc_key_inf
 #ifdef __KERNEL__
 extern struct iw_handler_def libertas_handler_def;
 int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int i);
+int wlan_radio_ioctl(wlan_private * priv, u8 option);
+/* this one should not be needed in do_ioctl */
+int wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
+			   struct iw_point *dwrq, char *extra);
 #endif
 
 /** sleep_params */



More information about the libertas-dev mailing list