From marcelo at kvack.org  Sun Jul  2 02:28:04 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Sun, 2 Jul 2006 03:28:04 -0300
Subject: Transmit under power save mode
In-Reply-To: <D1575D47310FC94D902C8675241E8E3E01CDDABF@msiexch01.marvell.com>
References: <D1575D47310FC94D902C8675241E8E3E01CDDABF@msiexch01.marvell.com>
Message-ID: <20060702062804.GA3104@dmt>

On Thu, Jun 29, 2006 at 02:04:48PM -0700, Ronak Chokshi wrote:
> Hi Marcelo,
> 
> The USB driver should follow the general PS driver Tx/Rx rule just like
> other interfaces.
> 
>  
> 
> The FW implementation for USB has some difference from others. During
> sleep state, the CPU and USB interface are not power off. This is to
> maintain the USB bus connection alive while the device is asleep. But it
> is not for data transfer. The FW can process some USP specific
> interrupt, but the data packet is blocked.
> 
>  
> 
> And another related question is, do you have implementation of driver
> code for different buses?
> 
> >> Not sure what you mean by this. Yes, we do have driver implementation
> for other buses but they are pretty much the same from PS mode
> stand-point.

Do you plan to submit them for inclusion in the mainline kernel?



From marcelo at kvack.org  Mon Jul  3 09:41:51 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Mon, 3 Jul 2006 10:41:51 -0300
Subject: wireless extensions improvement tasks
In-Reply-To: <1151598329.20455.13.camel@localhost.localdomain>
References: <1151598329.20455.13.camel@localhost.localdomain>
Message-ID: <20060703134151.GA2840@dmt>

Hi Dan,

On Thu, Jun 29, 2006 at 12:25:29PM -0400, Dan Williams wrote:
> Hi,
> 
> Some points to start with for WEXT cleanups:
> 
> a) Need to separate the ENCODE handler into WPA and non-WPA sections;
> the WPA sections should be handled by an ENCODEEXT handler and an AUTH
> handler, rather than overloading the ENCODE handler for WPA too
> 
> b) Need to fix the non-WPA ENCODE handler to turn the key on when you
> just set 'iwconfig eth1 essid bar key <foo>' instead of requiring a
> separate 'iwconfig eth1 key on'.  I've got a patch for this already in
> the works.
> 
> c) Need to convert more of the private ioctl() calls over to WEXT where
> appropriate (WLANSCAN_TYPE, WLANSETWPAIE, etc)
> 
> d) Turn on reassociation by default
> 
> e) Ensure bitrate reporting works correctly when reported via WEXT calls
> (Wasn't seeing it change in iwconfig when signal quality changed
> drastically)

I removed bitrate reporting via iwpriv interface (redundant), but both
interfaces use the same code.

> f) Send more WEXT events to userspace (HandleMICFailureEvent() call
> should report via IWEVMICHAELMICFAILURE rather than IWEVCUSTOM)

g) Convert wlanconfig ioctl's to generic or debug interfaces whenever possible.

Thanks!

> Cheers,
> Dan
> 
> PS - For those of you who may not know who I am...
> 
> My name is Dan Williams and I work for Red Hat on OLPC.  Previously to
> being on the RH OLPC team I worked quite a bit on Linux wireless
> networking, including driver cleanups for conformance to the Linux
> Wireless Extensions "standard".


From andreas at fjortis.info  Mon Jul  3 20:27:32 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Tue, 4 Jul 2006 02:27:32 +0200
Subject: [PATCH] libertas: gcc 4.1 compile fix.
Message-ID: <20060704002732.GA21683@scream.fjortis.info>

gcc version 4.1.2 20060630 (prerelease) (Debian 4.1.1-7)


CC [M]  drivers/net/wireless/libertas/if_usb.o
drivers/net/wireless/libertas/if_usb.c:58: error: initializer element is not constant
drivers/net/wireless/libertas/if_usb.c:58: error: (near initialization for 'if_usb_table[0].driver_info')
drivers/net/wireless/libertas/if_usb.c:60: error: initializer element is not constant
drivers/net/wireless/libertas/if_usb.c:60: error: (near initialization for 'if_usb_table[1].driver_info')
make[1]: *** [drivers/net/wireless/libertas/if_usb.o] Error 1


(I left the device_info-part commented out, since it's probably wrong on
64bit machines. Other drivers uses flags to indicate card. There's also
lots of warnings about using int/u32 and pointers when compiling on x86_64.)

Signed-off-by: Andreas Henriksson <andreas at fjortis.info>


diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 7a2d424..4f5d7b5 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -36,10 +36,6 @@ #include	"if_usb.h"
 
 #include	<linux/firmware.h>
 
-#define MARVELL_USB_DEVICE(vid, pid, name) \
-           USB_DEVICE(vid, pid),  \
-           .driver_info = (u32)name
-
 /* Context definition for Interrupt simulation */
 #define TX_SUCCESS	1
 #define RX_SUCCESS	2
@@ -55,12 +51,15 @@ static u8 usb_int_cause = 0;
 /** struct This structure contains the device signature */
 struct usb_device_id if_usb_table[] = {
 	/* Enter the device signature inside */
-	{MARVELL_USB_DEVICE
-	 (USB8388_VID_1, USB8388_PID_1, "Marvell WLAN USB Adapter")},
-	{MARVELL_USB_DEVICE
-	 (USB8388_VID_2, USB8388_PID_2, "Marvell WLAN USB Adapter")},
-	/* Terminating entry */
-	{},
+	{
+		USB_DEVICE(USB8388_VID_1, USB8388_PID_1),
+		//.device_info = "Marvell WLAN USB Adapter",
+	},
+	{
+		USB_DEVICE(USB8388_VID_2, USB8388_PID_2),
+		//.device_info = "Marvell WLAN USB Adapter",
+	},
+	{}	/* Terminating entry */
 };
 
 int if_prog_firmware(wlan_private * priv);


From marcelo at kvack.org  Mon Jul  3 21:56:19 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Mon, 3 Jul 2006 22:56:19 -0300
Subject: [PATCH] libertas: gcc 4.1 compile fix.
In-Reply-To: <20060704002732.GA21683@scream.fjortis.info>
References: <20060704002732.GA21683@scream.fjortis.info>
Message-ID: <20060704015619.GA9212@dmt>


Andreas, 

On Tue, Jul 04, 2006 at 02:27:32AM +0200, Andreas Henriksson wrote:
> gcc version 4.1.2 20060630 (prerelease) (Debian 4.1.1-7)
> 
> 
> CC [M]  drivers/net/wireless/libertas/if_usb.o
> drivers/net/wireless/libertas/if_usb.c:58: error: initializer element is not constant
> drivers/net/wireless/libertas/if_usb.c:58: error: (near initialization for 'if_usb_table[0].driver_info')
> drivers/net/wireless/libertas/if_usb.c:60: error: initializer element is not constant
> drivers/net/wireless/libertas/if_usb.c:60: error: (near initialization for 'if_usb_table[1].driver_info')
> make[1]: *** [drivers/net/wireless/libertas/if_usb.o] Error 1
> 
> 
> (I left the device_info-part commented out, since it's probably wrong on
> 64bit machines. Other drivers uses flags to indicate card. 

I committed your patch without .device_info commented entries. Since
they are unused there is no point in keeping them around.

> There's also lots of warnings about using int/u32 and pointers when
> compiling on x86_64.)

Can you post them, please?

Thanks!


From andreas at fjortis.info  Tue Jul  4 02:45:54 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Tue, 4 Jul 2006 08:45:54 +0200
Subject: [PATCH] libertas: gcc 4.1 compile fix.
In-Reply-To: <20060704015619.GA9212@dmt>
References: <20060704002732.GA21683@scream.fjortis.info>
	<20060704015619.GA9212@dmt>
Message-ID: <20060704064554.GA25248@scream.fjortis.info>

  LD      drivers/net/wireless/libertas/built-in.o
  CC [M]  drivers/net/wireless/libertas/wlan_main.o
  CC [M]  drivers/net/wireless/libertas/wlan_fw.o
  CC [M]  drivers/net/wireless/libertas/wlan_wext.o
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_linkmode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3279: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_radiomode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3314: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_debugmode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3347: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_do_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:4013: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4091: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4238: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4255: warning: cast to pointer from integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4259: warning: cast to pointer from integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4263: warning: cast to pointer from integer of different size
  CC [M]  drivers/net/wireless/libertas/wlan_rx.o
  CC [M]  drivers/net/wireless/libertas/wlan_tx.o
  CC [M]  drivers/net/wireless/libertas/wlan_cmd.o
  CC [M]  drivers/net/wireless/libertas/wlan_cmdresp.o
  CC [M]  drivers/net/wireless/libertas/wlan_proc.o
  CC [M]  drivers/net/wireless/libertas/wlan_scan.o
  CC [M]  drivers/net/wireless/libertas/wlan_join.o
  CC [M]  drivers/net/wireless/libertas/wlan_11d.o
  CC [M]  drivers/net/wireless/libertas/if_usb.o
  LD [M]  drivers/net/wireless/libertas/usb8xxx.o



From andreas at fjortis.info  Tue Jul  4 13:02:26 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Tue, 4 Jul 2006 19:02:26 +0200
Subject: warnings when compiling on x86_64
Message-ID: <20060704170226.GA26571@scream.fjortis.info>


  LD      drivers/net/wireless/libertas/built-in.o
  CC [M]  drivers/net/wireless/libertas/wlan_main.o
  CC [M]  drivers/net/wireless/libertas/wlan_fw.o
  CC [M]  drivers/net/wireless/libertas/wlan_wext.o
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_get_range':
drivers/net/wireless/libertas/wlan_wext.c:1672: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_get_snr':
drivers/net/wireless/libertas/wlan_wext.c:2590: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_linkmode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3279: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_radiomode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3314: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_set_debugmode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3347: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_get_tsf_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3440: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_sleep_params_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3678: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_scan_type_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3753: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_scan_mode_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:3815: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_do_ioctl':
drivers/net/wireless/libertas/wlan_wext.c:4013: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4091: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4105: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_wext.c:4238: warning: cast from pointer to integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4255: warning: cast to pointer from integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4259: warning: cast to pointer from integer of different size
drivers/net/wireless/libertas/wlan_wext.c:4263: warning: cast to pointer from integer of different size
drivers/net/wireless/libertas/wlan_wext.c: In function 'wlan_get_essid':
drivers/net/wireless/libertas/wlan_wext.c:5164: warning: comparison of distinct pointer types lacks a cast
  CC [M]  drivers/net/wireless/libertas/wlan_rx.o
  CC [M]  drivers/net/wireless/libertas/wlan_tx.o
  CC [M]  drivers/net/wireless/libertas/wlan_cmd.o
  CC [M]  drivers/net/wireless/libertas/wlan_cmdresp.o
  CC [M]  drivers/net/wireless/libertas/wlan_proc.o
  CC [M]  drivers/net/wireless/libertas/wlan_scan.o
drivers/net/wireless/libertas/wlan_scan.c: In function 'InterpretBSSDescriptionWithIE':
drivers/net/wireless/libertas/wlan_scan.c:1236: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_scan.c:1248: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_scan.c: In function 'wlan_set_user_scan_ioctl':
drivers/net/wireless/libertas/wlan_scan.c:2072: warning: comparison of distinct pointer types lacks a cast
  CC [M]  drivers/net/wireless/libertas/wlan_join.o
drivers/net/wireless/libertas/wlan_join.c: In function 'get_common_rates':
drivers/net/wireless/libertas/wlan_join.c:66: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_join.c:66: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_join.c: In function 'wlan_cmd_802_11_associate':
drivers/net/wireless/libertas/wlan_join.c:863: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_join.c:886: warning: comparison of distinct pointer types lacks a cast
drivers/net/wireless/libertas/wlan_join.c:886: warning: comparison of distinct pointer types lacks a cast
  CC [M]  drivers/net/wireless/libertas/wlan_11d.o
  CC [M]  drivers/net/wireless/libertas/if_usb.o
  LD [M]  drivers/net/wireless/libertas/usb8xxx.o


Regards,
Andreas Henriksson


From marcelo at kvack.org  Tue Jul  4 10:57:02 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Tue, 4 Jul 2006 11:57:02 -0300
Subject: [PATCH] libertas: cleanup - remove some private defines.
In-Reply-To: <20060704065754.GA25279@scream.fjortis.info>
References: <20060704065754.GA25279@scream.fjortis.info>
Message-ID: <20060704145702.GB13967@dmt>

On Tue, Jul 04, 2006 at 08:57:54AM +0200, Andreas Henriksson wrote:
> No real changes...
> 
> replace MRVDRV_ETH_ADDR_LEN with globally defined ETH_ALEN
> replace MRVDRV_MAXIMUM_ETH_PACKET_SIZE with globally defined ETH_FRAME_LEN
> remove unused MRVDRV_TIMER_*
> replace/remove TRUE/FALSE
> 
> Signed-off-by: Andreas Henriksson <andreas at fjortis.info>

Applied, thanks.



From marcelo at kvack.org  Wed Jul  5 09:55:04 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Wed, 5 Jul 2006 10:55:04 -0300
Subject: Current changes
Message-ID: <20060705135504.GB3548@dmt>


FYI - here's the current list of changes.

Getting better, still a lot of work to do be for a merge, though.

----

Andreas Henriksson:
      libertas: gcc 4.1 compile fix
      libertas: cleanup - remove some private defines.

Arnd Bergmann:
      libertas: avoid a few gcc warnings
      libertas: directly include linux headers
      libertas: directly include our own headers
      libertas: make some functions static
      libertas: make more functions static

Dan Williams:
      wireless/libertas: miscellaneous fixes
      Removes the static variables pwlanpriv and usb_cardp.  pwlanpriv was
      Bound suspend/resume stuff with CONFIG_PM like zd1201 driver.

Marcelo Tosatti:
      Convert __ATTRIB_PACK__ to direct __attribute__((packed)) usage.
      Get rid of standard types typedef's
      Get rid of standard types typedef's
      Get rid of "os_get_time()" macro, use jiffies directly.
      Get rid of OS_INT_{DIS,EN}ABLE macros
      Remove unnecessary aligned attribute
      Get rid of struct typedef's
      Libertas: Get rid of tx queue
      Libertas: Get rid of rx queue
      Libertas: Kill more os macros
      Libertas: Missed netif_stop_queue/carrier_off conversion
      Libertas: Fix debug option
      Libertas: remove useless HIS_TxDnLdRdy flag
      Libertas: Run scripts/Lindent
      Libertas: Remove unused struct definitions, remove typedefs from if_usb.h
      Libertas: Remove handling of firmware download from main RX callback
      Libertas: Kill URBs on suspend
      Libertas: Get rid of try_module_get/module_put
      Libertas: Fix if_usb_receive_fwload memcpy() screwup
      Libertas: Update and use include/net/ieee80211_radiotap.h
      Libertas: Get rid of timer abstraction, use Linux functions directly
      Libertas: Get rid of unused os_queue_is_active
      Libertas: Get rid of OS_SET_THREAD_STATE macro
      Libertas: fix if_usb label identation
      Libertas: Fix wlan_fw.c label identation
      Libertas: per-card fw_ready
      Libertas: Kill tx_urb_pending variable, simplify if_usb_free()
      Libertas: if_usb.c cosmetic cleanups
      Libertas: Handle power save mode without TX queue
      Libertas: wlan_cmdresp.c cleanup
      wireless/libertas: scan results WE fixes (Dan Williams)
      Libertas: remove unused spinlocks
      Libertas: Keep TX watchdog happy in PS mode
      Libertas: Libertas: Keep TX watchdog happy in PS mode, part 2
      Libertas: Switch get_wireless_stats to new iw_handler_def location
      Libertas: if_prog_firmware kmalloc "struct FWData" instead of placing on stack
      Libertas: Simple TX queue for PS mode
      Libertas: Remove "Local/Global Function/Variable" sections
      Libertas: Remove unused helper_name parameter
      Libertas: Remove wlan_getrate_ioctl
      Libertas: Fix wlanconfig.c compilation
      Libertas: Fix flaky firmware download
      Libertas: Remove handling of older WIRELESS_EXT version
      Libertas: Comment out unused union definitions in hostcmd.h
      Libertas: Wakeup queue even in sleep state
      Libertas: Avoid event notification from being lost (from Marvell)
      Libertas: Remove struct typedefs from .c files
      Libertas: Get rid of more struct typedefs
      Libertas: Remove wlan_11d.h struct typedefs
      Libertas: Remove enum mv_sd_type typedef
      Libertas: Remove wlan_defs.h struct typedefs
      Libertas: Comment out unused MRV_BSSID_IE_LIST struct
      Libertas: Remove struct typedefs from wlan_scan.h
      Libertas: Remove typedefs from wlan_thread.h
      Libertas: Remove struct typedefs from wlan_types.h
      Libertas: Remove unneded packet/aligned attributes from if_usb.h
      libertas: More min()->min_t() conversion fixups
      libertas: header cleanup tweaks

Peter Jones:
      - just drop the marvell in wholesale
      - er... actually add the marvell stuff in?
      - does cg-add -r not actually work?
      - use find instead of 'cg-add -r'
      - move everything so there's no silly subdirs
      - get rid of release_version.h completely; it serves no purpose.
      - use sane types for helper_name/fw_name
      - so I don't lose what was here
      - add define formerly in makefile
      - fix include path
      - actually, those can't be static
      - move the wlanconfig stuff to a closer directory, and make it build
      - get rid of some "BOOLEAN" types
      - attack with lindent and such
      - add -Wpacked, which makes the build very noisy, and shows lots of places
      - comment out -Wpacked for now
      Remove unused type WLAN_802_11_MAC_ADDRESS
      Remove use of macro for align attributes.
      Get rid of semaphore macros
      Get rid of "os_sched" macros, use msleep.
      Get rid of empty macros
      Fix 2 missing "struct" keywords from RxPD -> struct RxDP conversion.
      Merge suspend/resume code for usb interface.
      - Merge update from Marvell


From andreas at fjortis.info  Wed Jul  5 14:10:19 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Wed, 5 Jul 2006 20:10:19 +0200
Subject: [PATCH] libertas: cleanup - if-related codingstyle.
Message-ID: <20060705181018.GA3922@scream.fjortis.info>


Convert "if ((foo = alloc()) == NULL)" to "foo = alloc(); if (!foo)" and
similar coding-style cleanups related to if's.

Signed-off-by: Andreas Henriksson <andreas at fjortis.info>

diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index b43aea1..56df05b 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -237,9 +237,8 @@ static int if_usb_probe(struct usb_inter
 			/* we found a bulk in endpoint */
 			PRINTM(INFO, "Bulk in size is %d\n",
 			       endpoint->wMaxPacketSize);
-			if (!
-			    (usb_cardp->rx_urb =
-			     usb_alloc_urb(0, GFP_KERNEL))) {
+			usb_cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
+			if (!usb_cardp->rx_urb) {
 				PRINTM(INFO,
 				       "Rx URB allocation failed\n");
 				goto dealloc;
@@ -261,9 +260,8 @@ static int if_usb_probe(struct usb_inter
 		    && ((endpoint->bmAttributes & BULK_ENDPOINT_MASK) ==
 			BULK_ENDPOINT_FOUND)) {
 			/* We found bulk out endpoint */
-			if (!
-			    (usb_cardp->tx_urb =
-			     usb_alloc_urb(0, GFP_KERNEL))) {
+			usb_cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
+			if (!usb_cardp->tx_urb) {
 				PRINTM(INFO,
 				       "Tx URB allocation failed\n");
 				goto dealloc;
@@ -293,9 +291,9 @@ static int if_usb_probe(struct usb_inter
 	 * about keeping pwlanpriv around since it will be set on our
 	 * usb device data in -> add() -> sbi_register_dev().
 	 */
-	if (!(pwlanpriv = usb_cardp->add(usb_cardp))) {
+	pwlanpriv = usb_cardp->add(usb_cardp);
+	if (!pwlanpriv)
 		goto dealloc;
-	}
 
 	usb_get_dev(udev);
 	usb_set_intfdata(intf, usb_cardp);
@@ -334,9 +332,8 @@ static void if_usb_disconnect(struct usb
 	 * Update Surprie removed to TRUE  
 	 *  Free all the URB's allocated 
 	 */
-	if (!Adapter->SurpriseRemoved) {
+	if (!Adapter->SurpriseRemoved)
 		Adapter->SurpriseRemoved = 1;
-	}
 
 	/* Unlink and free urb */
 	if_usb_free(cardp);
@@ -384,7 +381,8 @@ static int usb_tx_block(wlan_private * p
 
 	cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
 
-	if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
+	ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC);
+	if (ret) {
 		/*  transfer failed */
 		PRINTM(INFO, "usb_submit_urb Failed\n");
 
@@ -443,12 +441,14 @@ static int __if_usb_submit_rx_urb(wlan_p
 
 	ENTER();
 
-	if (!(rinfo = kmalloc(sizeof(struct read_cb_info), GFP_ATOMIC))) {
+	rinfo = kmalloc(sizeof(struct read_cb_info), GFP_ATOMIC);
+	if (!rinfo) {
 		PRINTM(FATAL, "No free read_callback_info\n");
 		goto rx_ret;
 	}
 
-	if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
+	skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
+	if (!skb) {
 		PRINTM(FATAL, "No free skb\n");
 		kfree(rinfo);
 		goto rx_ret;
@@ -468,7 +468,8 @@ static int __if_usb_submit_rx_urb(wlan_p
 	cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
 
 	PRINTM(INFO, "Pointer for rx_urb %p\n", cardp->rx_urb);
-	if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
+	ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC);
+	if (ret) {
 		/* handle failure conditions */
 		PRINTM(INFO, "Submit Rx URB failed\n");
 		ret = WLAN_STATUS_FAILURE;
diff --git a/drivers/net/wireless/libertas/wlan_11d.c b/drivers/net/wireless/libertas/wlan_11d.c
index ce5468f..31db3ce 100644
--- a/drivers/net/wireless/libertas/wlan_11d.c
+++ b/drivers/net/wireless/libertas/wlan_11d.c
@@ -341,9 +341,9 @@ static u8 wlan_region_chan_supported_11d
 
 	ENTER();
 
-	if ((cfp = wlan_get_region_cfp_table(region, band, &cfp_no)) == NULL) {
+	cfp = wlan_get_region_cfp_table(region, band, &cfp_no);
+	if (!cfp)
 		return 0;
-	}
 
 	for (idx = 0; idx < cfp_no; idx++) {
 		if (chan == (cfp + idx)->Channel) {
diff --git a/drivers/net/wireless/libertas/wlan_cmd.c b/drivers/net/wireless/libertas/wlan_cmd.c
index 98f4f84..354ee75 100644
--- a/drivers/net/wireless/libertas/wlan_cmd.c
+++ b/drivers/net/wireless/libertas/wlan_cmd.c
@@ -1780,7 +1780,8 @@ int AllocateCmdBuffer(wlan_private * pri
 	/* Allocate and initialize CmdCtrlNode */
 	ulBufSize = sizeof(struct CmdCtrlNode) * MRVDRV_NUM_OF_CMD_BUFFER;
 
-	if (!(TempCmdArray = kmalloc(ulBufSize, GFP_KERNEL))) {
+	TempCmdArray = kmalloc(ulBufSize, GFP_KERNEL);
+	if (!TempCmdArray) {
 		PRINTM(INFO,
 		       "ALLOC_CMD_BUF: Failed to allocate TempCmdArray\n");
 		ret = WLAN_STATUS_FAILURE;
@@ -1793,7 +1794,8 @@ int AllocateCmdBuffer(wlan_private * pri
 	/* Allocate and initialize command buffers */
 	ulBufSize = MRVDRV_SIZE_OF_CMD_BUFFER;
 	for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
-		if (!(pTempVirtualAddr = kmalloc(ulBufSize, GFP_KERNEL))) {
+		pTempVirtualAddr = kmalloc(ulBufSize, GFP_KERNEL);
+		if (!pTempVirtualAddr) {
 			PRINTM(INFO,
 			       "ALLOC_CMD_BUF: pTempVirtualAddr: out of memory\n");
 			ret = WLAN_STATUS_FAILURE;
diff --git a/drivers/net/wireless/libertas/wlan_cmdresp.c b/drivers/net/wireless/libertas/wlan_cmdresp.c
index 509272a..bbd28c3 100644
--- a/drivers/net/wireless/libertas/wlan_cmdresp.c
+++ b/drivers/net/wireless/libertas/wlan_cmdresp.c
@@ -908,7 +908,7 @@ int wlan_process_rx_command(wlan_private
 	}
 
 	/* If the command is not successful, cleanup and return failure */
-	if ((Result != HostCmd_RESULT_OK || !(RespCmd & 0x8000))) {
+	if (Result != HostCmd_RESULT_OK || !(RespCmd & 0x8000)) {
 		PRINTM(INFO, "CMD_RESP: command reply %#x result=%#x\n",
 		       resp->Command, resp->Result);
 		/*
diff --git a/drivers/net/wireless/libertas/wlan_fw.c b/drivers/net/wireless/libertas/wlan_fw.c
index db310d0..3a6094f 100644
--- a/drivers/net/wireless/libertas/wlan_fw.c
+++ b/drivers/net/wireless/libertas/wlan_fw.c
@@ -66,8 +66,9 @@ static int wlan_setup_station_hw(wlan_pr
 
 	sbi_disable_host_int(priv);
 
-	if ((ret = request_firmware(&priv->firmware, fw_name,
-				    priv->hotplug_device)) < 0) {
+	ret = request_firmware(&priv->firmware, fw_name,
+			priv->hotplug_device);
+	if (ret < 0) {
 		PRINTM(MSG, "request_firmware() failed, error code = %#x\n",
 		       ret);
 		PRINTM(MSG, "%s not found in /lib/firmware\n", fw_name);
@@ -143,7 +144,8 @@ static int wlan_allocate_adapter(wlan_pr
 
 	/* Allocate buffer to store the BSSID list */
 	ulBufSize = sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST;
-	if (!(pTempScanTable = kmalloc(ulBufSize, GFP_KERNEL))) {
+	pTempScanTable = kmalloc(ulBufSize, GFP_KERNEL);
+	if (!pTempScanTable) {
 		wlan_free_adapter(priv);
 		return WLAN_STATUS_FAILURE;
 	}
@@ -290,9 +292,9 @@ int wlan_init_fw(wlan_private * priv)
 	ENTER();
 
 	/* Allocate adapter structure */
-	if ((ret = wlan_allocate_adapter(priv)) != WLAN_STATUS_SUCCESS) {
+	ret = wlan_allocate_adapter(priv);
+	if (ret != WLAN_STATUS_SUCCESS)
 		goto done;
-	}
 
 	/* init adapter structure */
 	wlan_init_adapter(priv);
@@ -308,7 +310,8 @@ #ifdef REASSOCIATION
 #endif                          /* REASSOCIATION */
 
 	/* download fimrware etc. */
-	if ((ret = wlan_setup_station_hw(priv)) != WLAN_STATUS_SUCCESS) {
+	ret = wlan_setup_station_hw(priv);
+	if (ret != WLAN_STATUS_SUCCESS) {
 		ret = WLAN_STATUS_FAILURE;
 		goto done;
 	}


From arnd at arndb.de  Wed Jul  5 14:21:50 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 05 Jul 2006 20:21:50 +0200
Subject: [PATCH 0/3] more libertas cleanups
Message-ID: <20060705182150.572600000@klappe.arndb.de>

here's another bunch of simple updates.

	Arnd <><


--



From arnd at arndb.de  Wed Jul  5 14:21:52 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 05 Jul 2006 20:21:52 +0200
Subject: [PATCH 2/3] libertas: fix namespace pollution, part 2
References: <20060705182150.572600000@klappe.arndb.de>
Message-ID: <20060705183949.739132000@klappe.arndb.de>

An embedded and charset-unspecified text was scrubbed...
Name: libertas-more-namespace.diff
Url: http://lists.infradead.org/pipermail/libertas-dev/attachments/20060705/92759811/attachment.pl 

From arnd at arndb.de  Wed Jul  5 14:21:53 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 05 Jul 2006 20:21:53 +0200
Subject: [PATCH 3/3] libertas: fix usage of inline functions
References: <20060705182150.572600000@klappe.arndb.de>
Message-ID: <20060705183949.858785000@klappe.arndb.de>

An embedded and charset-unspecified text was scrubbed...
Name: libertas-inline.diff
Url: http://lists.infradead.org/pipermail/libertas-dev/attachments/20060705/75ebc2f6/attachment.pl 

From arnd at arndb.de  Wed Jul  5 14:21:51 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 05 Jul 2006 20:21:51 +0200
Subject: [PATCH 1/3] libertas: fix namespace pollution, part 1
References: <20060705182150.572600000@klappe.arndb.de>
Message-ID: <20060705183949.482505000@klappe.arndb.de>

An embedded and charset-unspecified text was scrubbed...
Name: libertas-namespace.diff
Url: http://lists.infradead.org/pipermail/libertas-dev/attachments/20060705/0b459d49/attachment.pl 

From arnd at arndb.de  Wed Jul  5 15:48:43 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 5 Jul 2006 21:48:43 +0200
Subject: [PATCH] libertas: split ioctl handling from wireless extensions
In-Reply-To: <20060705182150.572600000@klappe.arndb.de>
References: <20060705182150.572600000@klappe.arndb.de>
Message-ID: <200607052148.43751.arnd@arndb.de>

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 */


From andreas at fjortis.info  Tue Jul  4 02:57:54 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Tue, 4 Jul 2006 08:57:54 +0200
Subject: [PATCH] libertas: cleanup - remove some private defines.
Message-ID: <20060704065754.GA25279@scream.fjortis.info>

No real changes...

replace MRVDRV_ETH_ADDR_LEN with globally defined ETH_ALEN
replace MRVDRV_MAXIMUM_ETH_PACKET_SIZE with globally defined ETH_FRAME_LEN
remove unused MRVDRV_TIMER_*
replace/remove TRUE/FALSE

Signed-off-by: Andreas Henriksson <andreas at fjortis.info>

diff --git a/drivers/net/wireless/libertas/hostcmd.h b/drivers/net/wireless/libertas/hostcmd.h
index 2e32230..126d7a2 100644
--- a/drivers/net/wireless/libertas/hostcmd.h
+++ b/drivers/net/wireless/libertas/hostcmd.h
@@ -347,7 +347,7 @@ struct HostCmd_DS_MAC_CONTROL {
 struct HostCmd_DS_MAC_MULTICAST_ADR {
 	u16 Action;
 	u16 NumOfAdrs;
-	u8 MACList[MRVDRV_ETH_ADDR_LEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
+	u8 MACList[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
 };
 
 /* HostCmd_CMD_802_11_AUTHENTICATE */
@@ -400,7 +400,7 @@ struct HostCmd_DS_802_11_ASSOCIATE_RSP {
 /* HostCmd_RET_802_11_AD_HOC_JOIN */
 struct HostCmd_DS_802_11_AD_HOC_RESULT {
 	u8 PAD[3];
-	u8 BSSID[MRVDRV_ETH_ADDR_LEN];
+	u8 BSSID[ETH_ALEN];
 };
 
 /* HostCmd_CMD_802_11_SET_WEP */
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 7a2d424..83326fa 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -239,7 +239,7 @@ static int if_usb_probe(struct usb_inter
 				       "Rx URB allocation failed\n");
 				goto dealloc;
 			}
-			usb_cardp->rx_urb_recall = FALSE;
+			usb_cardp->rx_urb_recall = 0;
 
 			usb_cardp->bulk_in_size =
 			    endpoint->wMaxPacketSize;
@@ -330,7 +330,7 @@ static void if_usb_disconnect(struct usb
 	 *  Free all the URB's allocated 
 	 */
 	if (!Adapter->SurpriseRemoved) {
-		Adapter->SurpriseRemoved = TRUE;
+		Adapter->SurpriseRemoved = 1;
 	}
 
 	/* Unlink and free urb */
@@ -510,16 +510,16 @@ static void if_usb_receive_fwload(struct
 		PRINTM(INFO, "FW received Blk with correct CRC\n");
 		PRINTM(INFO, "FW received Blk SeqNum = %d\n",
 		       SyncFWHeader->SeqNum);
-		cardp->CRC_OK = TRUE;
+		cardp->CRC_OK = 1;
 	} else {
 		PRINTM(INFO, "FW received Blk with CRC error\n");
-		cardp->CRC_OK = FALSE;
+		cardp->CRC_OK = 0;
 	}
 
 	kfree_skb(skb);
 
 	if (cardp->FWFinalBlk) {
-		cardp->FwDnldOver = TRUE;
+		cardp->FwDnldOver = 1;
 		goto exit;
 	}
 
@@ -574,7 +574,7 @@ #define MRVDRV_MIN_PKT_LEN	30
 	} else if (urb->status) {
 		if (!cardp->rx_urb_recall) {
 			PRINTM(INFO, "Card Is Removed\n");
-			priv->adapter->SurpriseRemoved = TRUE;
+			priv->adapter->SurpriseRemoved = 1;
 			// Wake up main thread to handle card removal.
 			if_usb_interrupt(priv, 0, 0);
 		}
@@ -952,7 +952,7 @@ int if_prog_firmware(wlan_private * priv
 		PRINTM(INFO, "Donwloading FW JUMP BLOCK\n");
 		memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
 		usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
-		cardp->FWFinalBlk = TRUE;
+		cardp->FWFinalBlk = 1;
 	}
 
 	PRINTM(INFO, "The firmware download is done size is %d\n",
@@ -978,15 +978,15 @@ int sbi_prog_firmware(wlan_private * pri
 	ENTER();
 
 restart:
-	priv->adapter->fw_ready = FALSE;
+	priv->adapter->fw_ready = 0;
 
 	cardp->TotalBytes = 0;
 	cardp->FwLastBlkSent = 0;
-	cardp->CRC_OK = TRUE;
-	cardp->FwDnldOver = FALSE;
+	cardp->CRC_OK = 1;
+	cardp->FwDnldOver = 0;
 	cardp->FWSeqNum = -1;
 	cardp->TotalBytes = 0;
-	cardp->FWFinalBlk = FALSE;
+	cardp->FWFinalBlk = 0;
 
 	if_prog_firmware(priv);
 
@@ -1016,7 +1016,7 @@ restart:
 	/* Delay 200 ms to waiting for the FW ready */
 	msleep_interruptible(200);
 
-	priv->adapter->fw_ready = TRUE;
+	priv->adapter->fw_ready = 1;
 
 	LEAVE();
 	return WLAN_STATUS_SUCCESS;
@@ -1081,7 +1081,7 @@ static int if_usb_suspend(struct usb_int
 	usb_kill_urb(cardp->tx_urb);
 	usb_kill_urb(cardp->rx_urb);
 
-	cardp->rx_urb_recall = TRUE;
+	cardp->rx_urb_recall = 1;
 
 	LEAVE();
 	return 0;
@@ -1093,7 +1093,7 @@ static int if_usb_resume(struct usb_inte
 
 	ENTER();
 
-	cardp->rx_urb_recall = FALSE;
+	cardp->rx_urb_recall = 0;
 
 	if_usb_submit_rx_urb(cardp->priv);
 
diff --git a/drivers/net/wireless/libertas/wlan_11d.c b/drivers/net/wireless/libertas/wlan_11d.c
index 25c3436..1455f5b 100644
--- a/drivers/net/wireless/libertas/wlan_11d.c
+++ b/drivers/net/wireless/libertas/wlan_11d.c
@@ -169,12 +169,12 @@ static u8 wlan_get_chan_11d(u8 band, u8 
 		/*if beyond the boundary */
 		if (i + NoOfChan < cfp_no) {
 			*chan = (cfp + i + NoOfChan)->Channel;
-			return TRUE;
+			return 1;
 		}
 	}
 
 	LEAVE();
-	return FALSE;
+	return 0;
 }
 
 /** 
@@ -198,13 +198,13 @@ u8 wlan_channel_known_11d(u8 chan,
 		if (chan == chanPwr[i].chan) {
 			PRINTM(INFO, "11D: Found Chan:%d\n", chan);
 			LEAVE();
-			return TRUE;
+			return 1;
 		}
 	}
 
 	PRINTM(INFO, "11D: Not Find Chan:%d\n", chan);
 	LEAVE();
-	return FALSE;
+	return 0;
 }
 
 /** 
@@ -373,23 +373,23 @@ u8 wlan_region_chan_supported_11d(u8 reg
 	ENTER();
 
 	if ((cfp = wlan_get_region_cfp_table(region, band, &cfp_no)) == NULL) {
-		return FALSE;
+		return 0;
 	}
 
 	for (idx = 0; idx < cfp_no; idx++) {
 		if (chan == (cfp + idx)->Channel) {
 			/* If Mrvl Chip Supported? */
 			if ((cfp + idx)->Unsupported) {
-				return FALSE;
+				return 0;
 			} else {
-				return TRUE;
+				return 1;
 			}
 		}
 	}
 
 	/*chan is not in the region table */
 	LEAVE();
-	return FALSE;
+	return 0;
 }
 
 /** 
@@ -463,8 +463,7 @@ int wlan_parse_domain_info_11d(struct IE
 		for (i = 0; idx < MAX_NO_OF_CHAN && i < NoOfChan; i++) {
 			/*step4: channel is supported? */
 
-			if (wlan_get_chan_11d(band, firstChan, i, &curChan)
-			    == FALSE) {
+			if (!wlan_get_chan_11d(band, firstChan, i, &curChan)) {
 				/* Chan is not found in UN table */
 				PRINTM(INFO, "chan is not supported: %d \n", i);
 				break;
@@ -636,7 +635,7 @@ int wlan_set_universaltable(wlan_private
 		       Adapter->universal_channel[i].NrCFP);
 
 		Adapter->universal_channel[i].CFP = channel_freq_power_UN_BG;
-		Adapter->universal_channel[i].Valid = TRUE;
+		Adapter->universal_channel[i].Valid = 1;
 		Adapter->universal_channel[i].Region = UNIVERSAL_REGION_CODE;
 		Adapter->universal_channel[i].Band = band;
 		i++;
diff --git a/drivers/net/wireless/libertas/wlan_cmd.c b/drivers/net/wireless/libertas/wlan_cmd.c
index ea17c02..db211b4 100644
--- a/drivers/net/wireless/libertas/wlan_cmd.c
+++ b/drivers/net/wireless/libertas/wlan_cmd.c
@@ -56,10 +56,10 @@ static u8 Is_Command_Allowed_In_PS(u16 C
 
 	for (i = 0; i < count; i++) {
 		if (Command == wlan_cpu_to_le16(Commands_Allowed_In_PS[i]))
-			return TRUE;
+			return 1;
 	}
 
-	return FALSE;
+	return 0;
 }
 
 /** 
@@ -1203,7 +1203,7 @@ void QueueCmd(wlan_adapter * Adapter, st
 		struct HostCmd_DS_802_11_PS_MODE *psm = &CmdPtr->params.psmode;
 		if (psm->Action == HostCmd_SubCmd_Exit_PS) {
 			if (Adapter->PSState != PS_STATE_FULL_POWER)
-				addtail = FALSE;
+				addtail = 0;
 		}
 	}
 
@@ -1283,7 +1283,7 @@ static int DownloadCommandToStation(wlan
 
 	Command = wlan_cpu_to_le16(CmdPtr->Command);
 
-	CmdNode->CmdWaitQWoken = FALSE;
+	CmdNode->CmdWaitQWoken = 0;
 	CmdSize = wlan_cpu_to_le16(CmdSize);
 
 	ret = sbi_host_to_card(priv, MVMS_CMD, (u8 *) CmdPtr, CmdSize);
@@ -1722,9 +1722,9 @@ #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS
 		goto done;
 	}
 
-	CmdNode->CmdWaitQWoken = FALSE;
+	CmdNode->CmdWaitQWoken = 0;
 
-	QueueCmd(Adapter, CmdNode, TRUE);
+	QueueCmd(Adapter, CmdNode, 1);
 	wake_up_interruptible(&priv->MainThread.waitQ);
 
 	sbi_reenable_host_interrupt(priv, 0x00);
@@ -1903,7 +1903,7 @@ void CleanUpCmdCtrlNode(struct CmdCtrlNo
 
 	if (!pTempNode)
 		return;
-	pTempNode->CmdWaitQWoken = TRUE;
+	pTempNode->CmdWaitQWoken = 1;
 	wake_up_interruptible(&pTempNode->cmdwait_q);
 	pTempNode->Status = 0;
 	pTempNode->cmd_oid = (u32) 0;
@@ -2022,7 +2022,7 @@ int ExecuteNextCommand(wlan_private * pr
 				    ) {
 					/* w/ new scheme, it will not reach here.
 					   since it is blocked in main_thread. */
-					Adapter->NeedToWakeup = TRUE;
+					Adapter->NeedToWakeup = 1;
 				} else
 					PSWakeup(priv, 0);
 
@@ -2057,7 +2057,7 @@ int ExecuteNextCommand(wlan_private * pr
 					       "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
 					list_del((struct list_head *)CmdNode);
 					CleanupAndInsertCmd(priv, CmdNode);
-					Adapter->NeedToWakeup = TRUE;
+					Adapter->NeedToWakeup = 1;
 
 					ret = WLAN_STATUS_SUCCESS;
 					goto done;
diff --git a/drivers/net/wireless/libertas/wlan_cmdresp.c b/drivers/net/wireless/libertas/wlan_cmdresp.c
index 195d3c6..da58c8d 100644
--- a/drivers/net/wireless/libertas/wlan_cmdresp.c
+++ b/drivers/net/wireless/libertas/wlan_cmdresp.c
@@ -93,10 +93,10 @@ void MacEventDisconnected(wlan_private *
 	       Adapter->PreviousSSID.Ssid, Adapter->PreviousSSID.SsidLength);
 
 	/* reset internal flags */
-	Adapter->AdHocCreated = FALSE;
+	Adapter->AdHocCreated = 0;
 
-	Adapter->SecInfo.WPAEnabled = FALSE;
-	Adapter->SecInfo.WPA2Enabled = FALSE;
+	Adapter->SecInfo.WPAEnabled = 0;
+	Adapter->SecInfo.WPA2Enabled = 0;
 	Adapter->Wpa_ie_len = 0;
 	Adapter->SecInfo.Auth1XAlg = WLAN_1X_AUTH_ALG_NONE;
 	Adapter->SecInfo.EncryptionMode = CIPHER_NONE;
@@ -111,7 +111,7 @@ void MacEventDisconnected(wlan_private *
 	memcpy(&Adapter->PreviousSSID,
 	       &Adapter->CurBssParams.ssid, sizeof(struct WLAN_802_11_SSID));
 	memcpy(Adapter->PreviousBSSID,
-	       Adapter->CurBssParams.bssid, MRVDRV_ETH_ADDR_LEN);
+	       Adapter->CurBssParams.bssid, ETH_ALEN);
 
 	/* need to erase the current SSID and BSSID info */
 	Adapter->pAttemptedBSSDesc = 0;
@@ -142,7 +142,7 @@ static void HandleDisconnectEvent(wlan_p
 	if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
 		MacEventDisconnected(priv);
 #ifdef REASSOCIATION
-		if (Adapter->Reassoc_on == TRUE) {
+		if (Adapter->Reassoc_on) {
 			PRINTM(INFO, "RE-ASSOC: trigger the timer\n");
 			mod_timer(&Adapter->reassoc_timer, 0);
 		}
@@ -291,7 +291,7 @@ static int wlan_ret_get_hw_spec(wlan_pri
 
 	if (Adapter->CurrentAddr[0] == 0xff) {
 		memmove(Adapter->CurrentAddr, hwspec->PermanentAddr,
-			MRVDRV_ETH_ADDR_LEN);
+			ETH_ALEN);
 	}
 
 	memcpy(priv->wlan_dev.netdev->dev_addr, Adapter->CurrentAddr, ETH_ALEN);
@@ -508,7 +508,7 @@ static int wlan_ret_802_11_key_material(
 	ENTER();
 
 	if (pKey->Action == HostCmd_ACT_SET)
-		Adapter->IsGTK_SET = TRUE;
+		Adapter->IsGTK_SET = 1;
 
 	memcpy(Adapter->aeskey.KeyParamSet.Key, pKey->KeyParamSet.Key,
 	       sizeof(pKey->KeyParamSet.Key));
@@ -856,7 +856,7 @@ int wlan_process_rx_command(wlan_private
 					    Wlan802_11PowerModeCAM;
 			}
 		} else if (psmode->Action == HostCmd_SubCmd_Enter_PS) {
-			Adapter->NeedToWakeup = FALSE;
+			Adapter->NeedToWakeup = 0;
 			Adapter->PSState = PS_STATE_AWAKE;
 
 			PRINTM(INFO, "CMD_RESP: Enter_PS command response\n");
@@ -871,7 +871,7 @@ int wlan_process_rx_command(wlan_private
 				PSWakeup(priv, 0);
 			}
 		} else if (psmode->Action == HostCmd_SubCmd_Exit_PS) {
-			Adapter->NeedToWakeup = FALSE;
+			Adapter->NeedToWakeup = 0;
 			Adapter->PSState = PS_STATE_FULL_POWER;
 			PRINTM(INFO, "CMD_RESP: Exit_PS command response\n");
 		} else {
@@ -1162,7 +1162,7 @@ int wlan_process_event(wlan_private * pr
 		}
 
 		Adapter->TxLockFlag = 0;
-		if (TRUE == CheckLastPacketIndication(priv)) {
+		if (CheckLastPacketIndication(priv)) {
 			if (Adapter->gen_null_pkg) {
 				SendNullPacket(priv,
 					       MRVDRV_TxPD_POWER_MGMT_NULL_PACKET
@@ -1174,7 +1174,7 @@ int wlan_process_event(wlan_private * pr
 
 		Adapter->PSState = PS_STATE_AWAKE;
 
-		if (Adapter->NeedToWakeup == TRUE) {
+		if (Adapter->NeedToWakeup) {
 			/*
 			 * wait for the command processing to finish
 			 * before resuming sending 
diff --git a/drivers/net/wireless/libertas/wlan_debug.c b/drivers/net/wireless/libertas/wlan_debug.c
index fb613eb..96d79d1 100644
--- a/drivers/net/wireless/libertas/wlan_debug.c
+++ b/drivers/net/wireless/libertas/wlan_debug.c
@@ -165,7 +165,7 @@ static int wlan_debug_write(struct file 
 			else if (d[i].size == 4)
 				*((u32 *) d[i].addr) = (u32) r;
 			break;
-		} while (TRUE);
+		} while (1);
 	}
 	kfree(pdata);
 
diff --git a/drivers/net/wireless/libertas/wlan_defs.h b/drivers/net/wireless/libertas/wlan_defs.h
index 994b362..e3aa2e5 100644
--- a/drivers/net/wireless/libertas/wlan_defs.h
+++ b/drivers/net/wireless/libertas/wlan_defs.h
@@ -156,17 +156,6 @@ #else
 #define HEXDUMP(x,y,z)
 #endif
 
-#ifndef	TRUE
-#define TRUE			1
-#endif
-#ifndef	FALSE
-#define	FALSE			0
-#endif
-
-#ifndef MIN
-#define MIN(a,b)		((a) < (b) ? (a) : (b))
-#endif
-
 #ifndef NELEMENTS
 #define NELEMENTS(x) (sizeof(x)/sizeof(x[0]))
 #endif
@@ -193,21 +182,12 @@ #define MRVDRV_NUM_OF_CMD_BUFFER        
 #define MRVDRV_SIZE_OF_CMD_BUFFER       (2 * 1024)
 #define MRVDRV_MAX_CHANNEL_SIZE		14
 #define MRVDRV_MAX_BSSID_LIST		64
-#define MRVDRV_TIMER_10S		10000
-#define MRVDRV_TIMER_5S			5000
-#define MRVDRV_TIMER_1S			1000
 #define MRVDRV_ASSOCIATION_TIME_OUT	255
 #define MRVDRV_SNAP_HEADER_LEN          8
-#define MRVDRV_ETH_ADDR_LEN             6
-#define MRVDRV_ETH_HEADER_SIZE          14
 
 #define	WLAN_UPLD_SIZE			2312
 #define DEV_NAME_LEN			32
 
-#ifndef	ETH_ALEN
-#define ETH_ALEN			6
-#endif
-
 /** Misc constants */
 /* This section defines 802.11 specific contants */
 
@@ -281,13 +261,12 @@ #define MRVL_FIXED_IE_SIZE      12
 
 /* This is for firmware specific length */
 #define EXTRA_LEN	36
-#define MRVDRV_MAXIMUM_ETH_PACKET_SIZE	1514
 
 #define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
-	(MRVDRV_MAXIMUM_ETH_PACKET_SIZE + sizeof(struct TxPD) + EXTRA_LEN)
+	(ETH_FRAME_LEN + sizeof(struct TxPD) + EXTRA_LEN)
 
 #define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
-	(MRVDRV_MAXIMUM_ETH_PACKET_SIZE + sizeof(struct RxPD) \
+	(ETH_FRAME_LEN + sizeof(struct RxPD) \
 	 + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
 
 #define	CMD_F_HOSTCMD		(1 << 0)
diff --git a/drivers/net/wireless/libertas/wlan_dev.h b/drivers/net/wireless/libertas/wlan_dev.h
index 1e7aa86..5a29d6a 100644
--- a/drivers/net/wireless/libertas/wlan_dev.h
+++ b/drivers/net/wireless/libertas/wlan_dev.h
@@ -94,7 +94,7 @@ struct wlan_802_11_security {
 struct current_bss_params {
 	struct bss_descriptor BSSDescriptor;
 	/** bssid */
-	u8 bssid[MRVDRV_ETH_ADDR_LEN];
+	u8 bssid[ETH_ALEN];
 	/** ssid */
 	struct WLAN_802_11_SSID ssid;
 
@@ -235,7 +235,7 @@ #endif				/* REASSOCIATION */
 
 	struct WLAN_802_11_SSID AttemptedSSIDBeforeScan;
 	struct WLAN_802_11_SSID PreviousSSID;
-	u8 PreviousBSSID[MRVDRV_ETH_ADDR_LEN];
+	u8 PreviousBSSID[ETH_ALEN];
 
 	struct bss_descriptor *ScanTable;
 	u32 NumInScanTable;
@@ -258,9 +258,8 @@ #endif				/* REASSOCIATION */
 	u8 ATIMEnabled;
 
 	/** MAC address information */
-	u8 CurrentAddr[MRVDRV_ETH_ADDR_LEN];
-	u8 MulticastList[MRVDRV_MAX_MULTICAST_LIST_SIZE]
-	    [MRVDRV_ETH_ADDR_LEN];
+	u8 CurrentAddr[ETH_ALEN];
+	u8 MulticastList[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
 	u32 NumOfMulticastMACAddr;
 
 	/** 802.11 statistics */
diff --git a/drivers/net/wireless/libertas/wlan_fw.c b/drivers/net/wireless/libertas/wlan_fw.c
index 80108f3..5ee8478 100644
--- a/drivers/net/wireless/libertas/wlan_fw.c
+++ b/drivers/net/wireless/libertas/wlan_fw.c
@@ -92,7 +92,7 @@ #define RF_REG_VALUE  0xc8
 	/*
 	 * Read MAC address from HW
 	 */
-	memset(adapter->CurrentAddr, 0xff, MRVDRV_ETH_ADDR_LEN);
+	memset(adapter->CurrentAddr, 0xff, ETH_ALEN);
 
 	ret = PrepareAndSendCommand(priv, HostCmd_CMD_GET_HW_SPEC,
 				    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);
@@ -182,11 +182,11 @@ static void wlan_init_adapter(wlan_priva
 
 	/* ATIM params */
 	Adapter->AtimWindow = 0;
-	Adapter->ATIMEnabled = FALSE;
+	Adapter->ATIMEnabled = 0;
 
 	Adapter->MediaConnectStatus = WlanMediaStateDisconnected;
 	Adapter->LinkSpeed = MRVDRV_LINK_SPEED_1mbps;
-	memset(Adapter->CurrentAddr, 0xff, MRVDRV_ETH_ADDR_LEN);
+	memset(Adapter->CurrentAddr, 0xff, ETH_ALEN);
 
 	/* Status variables */
 	Adapter->HardwareStatus = WlanHardwareStatusInitializing;
@@ -219,19 +219,19 @@ #endif
 	memset(&Adapter->CurBssParams, 0, sizeof(Adapter->CurBssParams));
 
 	/* PnP and power profile */
-	Adapter->SurpriseRemoved = FALSE;
+	Adapter->SurpriseRemoved = 0;
 
 	Adapter->CurrentPacketFilter =
 	    HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON;
 
 	Adapter->RadioOn = RADIO_ON;
 #ifdef REASSOCIATION
-	Adapter->Reassoc_on = TRUE;
+	Adapter->Reassoc_on = 1;
 #endif				/* REASSOCIATION */
 	Adapter->TxAntenna = RF_ANTENNA_2;
 	Adapter->RxAntenna = RF_ANTENNA_AUTO;
 
-	Adapter->Is_DataRate_Auto = TRUE;
+	Adapter->Is_DataRate_Auto = 1;
 	Adapter->BeaconPeriod = MRVDRV_BEACON_INTERVAL;
 
 	// set default value of capInfo.
@@ -247,12 +247,12 @@ #define SHORT_PREAMBLE_ALLOWED		1
 	Adapter->ListenInterval = MRVDRV_DEFAULT_LISTEN_INTERVAL;
 
 	Adapter->PSState = PS_STATE_FULL_POWER;
-	Adapter->NeedToWakeup = FALSE;
+	Adapter->NeedToWakeup = 0;
 	Adapter->LocalListenInterval = 0;	/* default value in firmware will be used */
 
 	Adapter->DataRate = 0;	// Initially indicate the rate as auto 
 
-	Adapter->adhoc_grate_enabled = FALSE;
+	Adapter->adhoc_grate_enabled = 0;
 
 	Adapter->IntCounter = Adapter->IntCounterSaved = 0;
 
@@ -388,7 +388,7 @@ void command_timer_fn(unsigned long data
 	spin_unlock_irqrestore(&Adapter->QueueSpinLock, flags);
 
 	PRINTM(INFO, "Re-sending same command as it timeout...!\n");
-	QueueCmd(Adapter, pTempNode, FALSE);
+	QueueCmd(Adapter, pTempNode, 0);
 
 	wake_up_interruptible(&priv->MainThread.waitQ);
 
diff --git a/drivers/net/wireless/libertas/wlan_join.c b/drivers/net/wireless/libertas/wlan_join.c
index 3fcb08e..a97c17d 100644
--- a/drivers/net/wireless/libertas/wlan_join.c
+++ b/drivers/net/wireless/libertas/wlan_join.c
@@ -63,7 +63,7 @@ static int get_common_rates(wlan_adapter
 	int i;
 
 	memset(&tmp, 0, sizeof(tmp));
-	memcpy(&tmp, rate1, MIN(rate1_size, sizeof(tmp)));
+	memcpy(&tmp, rate1, min(rate1_size, sizeof(tmp)));
 	memset(rate1, 0, rate1_size);
 
 	/* Mask the top bit of the original values */
@@ -235,7 +235,7 @@ #endif				/* REASSOCIATION */
 			}
 		}
 		if (Adapter->Prescan)
-			SendSpecificSSIDScan(priv, &reqSSID, TRUE);
+			SendSpecificSSIDScan(priv, &reqSSID, 1);
 		i = FindSSIDInList(Adapter, &reqSSID, NULL,
 				   Wlan802_11Infrastructure);
 		if (i >= 0) {
@@ -275,7 +275,7 @@ #endif				/* REASSOCIATION */
 		/* Scan for the network, do not save previous results.  Stale
 		 *   scan data will cause us to join a non-existant adhoc network
 		 */
-		SendSpecificSSIDScan(priv, &reqSSID, FALSE);
+		SendSpecificSSIDScan(priv, &reqSSID, 0);
 
 		/* Search for the requested SSID in the scan table */
 		i = FindSSIDInList(Adapter, &reqSSID, NULL, Wlan802_11IBSS);
@@ -452,7 +452,7 @@ int StartAdhocNetwork(wlan_private * pri
 
 	ENTER();
 
-	Adapter->AdhocCreate = TRUE;
+	Adapter->AdhocCreate = 1;
 
 	if (!Adapter->capInfo.ShortPreamble) {
 		PRINTM(INFO, "AdhocStart: Long Preamble\n");
@@ -529,7 +529,7 @@ int JoinAdhocNetwork(wlan_private * priv
 	       Adapter->CurBssParams.channel);
 	PRINTM(INFO, "CurBssParams.band = %c\n", Adapter->CurBssParams.band);
 
-	Adapter->AdhocCreate = FALSE;
+	Adapter->AdhocCreate = 0;
 
 	// store the SSID info temporarily
 	memset(&Adapter->AttemptedSSIDBeforeScan, 0,
@@ -609,7 +609,7 @@ int wlanidle_off(wlan_private * priv)
 					SendSpecificBSSIDScan(priv,
 							      Adapter->
 							      PreviousBSSID,
-							      TRUE);
+							      1);
 					i = FindSSIDInList(Adapter,
 							   &Adapter->
 							   PreviousSSID,
@@ -632,7 +632,7 @@ int wlanidle_off(wlan_private * priv)
 					SendSpecificSSIDScan(priv,
 							     &Adapter->
 							     PreviousSSID,
-							     TRUE);
+							     1);
 					i = FindSSIDInList(Adapter,
 							   &Adapter->
 							   PreviousSSID, NULL,
@@ -723,7 +723,7 @@ int wlan_cmd_802_11_authenticate(wlan_pr
 			     + S_DS_GEN);
 
 	pAuthenticate->AuthType = Adapter->SecInfo.AuthenticationMode;
-	memcpy(pAuthenticate->MacAddr, bssid, MRVDRV_ETH_ADDR_LEN);
+	memcpy(pAuthenticate->MacAddr, bssid, ETH_ALEN);
 
 	PRINTM(INFO, "AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
 	       bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
@@ -753,7 +753,7 @@ int wlan_cmd_802_11_deauthenticate(wlan_
 
 	/* set AP MAC address */
 	memmove(dauth->MacAddr, Adapter->CurBssParams.bssid,
-		MRVDRV_ETH_ADDR_LEN);
+		ETH_ALEN);
 
 	/* Reason code 3 = Station is leaving */
 #define REASON_CODE_STA_LEAVING 3
@@ -860,7 +860,7 @@ int wlan_cmd_802_11_associate(wlan_priva
 		goto done;
 	}
 
-	rates->Header.Len = MIN(strlen(rates->Rates), WLAN_SUPPORTED_RATES);
+	rates->Header.Len = min(strlen(rates->Rates), WLAN_SUPPORTED_RATES);
 	Adapter->CurBssParams.NumOfRates = rates->Header.Len;
 
 	pos += sizeof(rates->Header) + rates->Header.Len;
@@ -884,7 +884,7 @@ int wlan_cmd_802_11_associate(wlan_priva
 
 	/* Copy the infra. association rates into Current BSS state structure */
 	memcpy(&Adapter->CurBssParams.DataRates, &rates->Rates,
-	       MIN(sizeof(Adapter->CurBssParams.DataRates), rates->Header.Len));
+	       min(sizeof(Adapter->CurBssParams.DataRates), rates->Header.Len));
 
 	PRINTM(INFO, "ASSOC_CMD: rates->Header.Len = %d\n", rates->Header.Len);
 
@@ -1032,12 +1032,12 @@ #define AD_HOC_CAP_PRIVACY_ON 1
 
 	memset(adhs->DataRate, 0, sizeof(adhs->DataRate));
 
-	if (Adapter->adhoc_grate_enabled == TRUE) {
+	if (Adapter->adhoc_grate_enabled) {
 		memcpy(adhs->DataRate, AdhocRates_G,
-		       MIN(sizeof(adhs->DataRate), sizeof(AdhocRates_G)));
+		       min(sizeof(adhs->DataRate), sizeof(AdhocRates_G)));
 	} else {
 		memcpy(adhs->DataRate, AdhocRates_B,
-		       MIN(sizeof(adhs->DataRate), sizeof(AdhocRates_B)));
+		       min(sizeof(adhs->DataRate), sizeof(AdhocRates_B)));
 	}
 
 	/* Find the last non zero */
@@ -1126,7 +1126,7 @@ int wlan_cmd_802_11_ad_hoc_join(wlan_pri
 	pAdHocJoin->BssDescriptor.BeaconPeriod = pBSSDesc->BeaconPeriod;
 
 	memcpy(&pAdHocJoin->BssDescriptor.BSSID,
-	       &pBSSDesc->MacAddress, MRVDRV_ETH_ADDR_LEN);
+	       &pBSSDesc->MacAddress, ETH_ALEN);
 
 	memcpy(&pAdHocJoin->BssDescriptor.SSID,
 	       &pBSSDesc->Ssid.Ssid, pBSSDesc->Ssid.SsidLength);
@@ -1171,7 +1171,7 @@ int wlan_cmd_802_11_ad_hoc_join(wlan_pri
 	memset(pAdHocJoin->BssDescriptor.DataRates, 0,
 	       sizeof(pAdHocJoin->BssDescriptor.DataRates));
 	memcpy(pAdHocJoin->BssDescriptor.DataRates, pBSSDesc->DataRates,
-	       MIN(sizeof(pAdHocJoin->BssDescriptor.DataRates),
+	       min(sizeof(pAdHocJoin->BssDescriptor.DataRates),
 		   sizeof(pBSSDesc->DataRates)));
 
 	card_rates = SupportedRates;
@@ -1309,7 +1309,7 @@ int wlan_ret_802_11_associate(wlan_priva
 
 	/* Set the new BSSID (AP's MAC address) to current BSSID */
 	memcpy(Adapter->CurBssParams.bssid,
-	       pBSSDesc->MacAddress, MRVDRV_ETH_ADDR_LEN);
+	       pBSSDesc->MacAddress, ETH_ALEN);
 
 	/* Make a copy of current BSSID descriptor */
 	memcpy(&Adapter->CurBssParams.BSSDescriptor,
@@ -1321,7 +1321,7 @@ int wlan_ret_802_11_associate(wlan_priva
 	Adapter->MediaConnectStatus = WlanMediaStateConnected;
 
 	if (Adapter->SecInfo.WPAEnabled || Adapter->SecInfo.WPA2Enabled)
-		Adapter->IsGTK_SET = FALSE;
+		Adapter->IsGTK_SET = 0;
 
 	Adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
 	Adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
@@ -1405,7 +1405,7 @@ int wlan_ret_802_11_ad_hoc_start(wlan_pr
 		memset(&Adapter->CurBssParams.BSSDescriptor,
 		       0x00, sizeof(Adapter->CurBssParams.BSSDescriptor));
 
-		Adapter->AdHocFailed = TRUE;
+		Adapter->AdHocFailed = 1;
 		LEAVE();
 		return WLAN_STATUS_FAILURE;
 	}
@@ -1421,11 +1421,11 @@ int wlan_ret_802_11_ad_hoc_start(wlan_pr
 	Adapter->LinkSpeed = MRVDRV_LINK_SPEED_11mbps;
 
 	if (Command == HostCmd_RET_802_11_AD_HOC_START) {
-		Adapter->AdHocCreated = TRUE;
+		Adapter->AdHocCreated = 1;
 
 		/* Update the created network descriptor with the new BSSID */
 		memcpy(pBSSDesc->MacAddress,
-		       pAdHocResult->BSSID, MRVDRV_ETH_ADDR_LEN);
+		       pAdHocResult->BSSID, ETH_ALEN);
 	} else {
 
 		/* Make a copy of current BSSID descriptor, only needed for join since
@@ -1437,7 +1437,7 @@ int wlan_ret_802_11_ad_hoc_start(wlan_pr
 
 	/* Set the BSSID from the joined/started descriptor */
 	memcpy(&Adapter->CurBssParams.bssid,
-	       pBSSDesc->MacAddress, MRVDRV_ETH_ADDR_LEN);
+	       pBSSDesc->MacAddress, ETH_ALEN);
 
 	/* Set the new SSID to current SSID */
 	memcpy(&Adapter->CurBssParams.ssid,
@@ -1553,7 +1553,7 @@ int wlan_reassociation_thread(void *data
 		PRINTM(INFO, "Reassoc: Performing Active Scan @ %lu\n",
 		       jiffies);
 
-		SendSpecificSSIDScan(priv, &Adapter->PreviousSSID, TRUE);
+		SendSpecificSSIDScan(priv, &Adapter->PreviousSSID, 1);
 
 		/* Try to find the specific BSSID we were associated to first */
 		i = FindSSIDInList(Adapter,
diff --git a/drivers/net/wireless/libertas/wlan_main.c b/drivers/net/wireless/libertas/wlan_main.c
index ec75ffd..3836340 100644
--- a/drivers/net/wireless/libertas/wlan_main.c
+++ b/drivers/net/wireless/libertas/wlan_main.c
@@ -242,7 +242,7 @@ static int wlan_open(struct net_device *
 		return WLAN_STATUS_FAILURE;
 	}
 
-	priv->open = TRUE;
+	priv->open = 1;
 
 	if (adapter->MediaConnectStatus == WlanMediaStateConnected) {
 		netif_carrier_on(priv->wlan_dev.netdev);
@@ -269,7 +269,7 @@ static int wlan_close(struct net_device 
 	netif_stop_queue(priv->wlan_dev.netdev);
 	netif_carrier_off(priv->wlan_dev.netdev);
 
-	priv->open = FALSE;
+	priv->open = 0;
 
 	LEAVE();
 	return WLAN_STATUS_SUCCESS;
@@ -475,7 +475,7 @@ static int wlan_set_mac_address(struct n
 
 	ENTER();
 
-	memset(Adapter->CurrentAddr, 0, MRVDRV_ETH_ADDR_LEN);
+	memset(Adapter->CurrentAddr, 0, ETH_ALEN);
 
 	/* dev->dev_addr is 8 bytes */
 	HEXDUMP("dev->dev_addr:", dev->dev_addr, ETH_ALEN);
@@ -951,7 +951,7 @@ #endif
 	netif_stop_queue(priv->wlan_dev.netdev);
 	netif_carrier_off(priv->wlan_dev.netdev);
 
-	Adapter->SurpriseRemoved = TRUE;
+	Adapter->SurpriseRemoved = 1;
 
 	/* Stop the thread servicing the interrupts */
 	wake_up_interruptible(&priv->MainThread.waitQ);
@@ -1052,7 +1052,7 @@ int wlan_set_regiontable(wlan_private * 
 			       region);
 			return WLAN_STATUS_FAILURE;
 		}
-		Adapter->region_channel[i].Valid = TRUE;
+		Adapter->region_channel[i].Valid = 1;
 		Adapter->region_channel[i].Region = region;
 		Adapter->region_channel[i].Band = band;
 		i++;
diff --git a/drivers/net/wireless/libertas/wlan_rx.c b/drivers/net/wireless/libertas/wlan_rx.c
index 27f2ad6..f9cc379 100644
--- a/drivers/net/wireless/libertas/wlan_rx.c
+++ b/drivers/net/wireless/libertas/wlan_rx.c
@@ -180,7 +180,7 @@ int ProcessRxedPacket(wlan_private * pri
 	ENTER();
 
 	if (priv->adapter->debugmode & MRVDRV_DEBUG_RX_PATH)
-		HEXDUMP("RX packet: ", skb->data, MIN(skb->len, 100));
+		HEXDUMP("RX packet: ", skb->data, min(skb->len, 100));
 
 	if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
 		return ProcessRxed_802_11_Packet(priv, skb);
@@ -188,7 +188,7 @@ int ProcessRxedPacket(wlan_private * pri
 	pRxPkt = (struct RxPacketHdr *) skb->data;
 	pRxPD = &pRxPkt->rx_pd;
 
-	HEXDUMP("RX Data: Before chop RxPD", skb->data, MIN(skb->len, 100));
+	HEXDUMP("RX Data: Before chop RxPD", skb->data, min(skb->len, 100));
 
 	if (skb->len < (ETH_HLEN + 8 + sizeof(struct RxPD))) {
 		PRINTM(INFO, "RX Error: FRAME RECEIVED WITH BAD LENGTH\n");
@@ -346,7 +346,7 @@ int ProcessRxed_802_11_Packet(wlan_priva
 	pRxPkt = (struct Rx80211PacketHdr *) skb->data;
 	pRxPD = &pRxPkt->rx_pd;
 
-	// HEXDUMP("RX Data: Before chop RxPD", skb->data, MIN(skb->len, 100));
+	// HEXDUMP("RX Data: Before chop RxPD", skb->data, min(skb->len, 100));
 
 	if (skb->len < (ETH_HLEN + 8 + sizeof(struct RxPD))) {
 		PRINTM(INFO, "RX Error: FRAME RECEIVED WITH BAD LENGTH\n");
@@ -395,7 +395,7 @@ int ProcessRxed_802_11_Packet(wlan_priva
 			radiotap_hdr.rx_flags |= IEEE80211_RADIOTAP_F_RX_BADFCS;
 		//memset(radiotap_hdr.pad, 0x11, IEEE80211_RADIOTAP_HDRLEN - 18);
 
-		// HEXDUMP1("RX radiomode packet BEF: ", skb->data, MIN(skb->len, 100));
+		// HEXDUMP1("RX radiomode packet BEF: ", skb->data, min(skb->len, 100));
 
 		/* chop the RxPD */
 		skb_pull(skb, sizeof(struct RxPD));
@@ -414,7 +414,7 @@ int ProcessRxed_802_11_Packet(wlan_priva
 							    RxRadiotapHdr));
 		memcpy(pradiotap_hdr, &radiotap_hdr,
 		       sizeof(struct RxRadiotapHdr));
-		//HEXDUMP1("RX radiomode packet AFT: ", skb->data, MIN(skb->len, 100));
+		//HEXDUMP1("RX radiomode packet AFT: ", skb->data, min(skb->len, 100));
 		break;
 
 	default:
diff --git a/drivers/net/wireless/libertas/wlan_scan.c b/drivers/net/wireless/libertas/wlan_scan.c
index e788616..829bbf8 100644
--- a/drivers/net/wireless/libertas/wlan_scan.c
+++ b/drivers/net/wireless/libertas/wlan_scan.c
@@ -83,7 +83,7 @@ #define MRVDRV_ACTIVE_SCAN_CHAN_TIME   1
 #ifdef DISCARD_BAD_SSID
 #define CHECK_SSID_IS_VALID(x) ssid_valid(&bssidEntry.Ssid)
 #else
-#define CHECK_SSID_IS_VALID(x) TRUE
+#define CHECK_SSID_IS_VALID(x) 1 
 #endif
 
 /**
@@ -248,11 +248,11 @@ static u8 ssid_valid(struct WLAN_802_11_
 
 	for (ssidIdx = 0; ssidIdx < pSsid->SsidLength; ssidIdx++) {
 		if (!isprint(pSsid->Ssid[ssidIdx])) {
-			return FALSE;
+			return 0;
 		}
 	}
 
-	return TRUE;
+	return 1;
 }
 
 /**
@@ -275,7 +275,7 @@ static void wlan_scan_process_results(wl
 	int foundCurrent;
 	int i;
 
-	foundCurrent = FALSE;
+	foundCurrent = 0;
 
 	if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
 		/* try to find the current BSSID in the new scan list */
@@ -284,8 +284,8 @@ static void wlan_scan_process_results(wl
 				     &Adapter->CurBssParams.ssid) &&
 			    !memcmp(Adapter->CurBssParams.bssid,
 				    Adapter->ScanTable[i].MacAddress,
-				    MRVDRV_ETH_ADDR_LEN)) {
-				foundCurrent = TRUE;
+				    ETH_ALEN)) {
+				foundCurrent = 1;
 			}
 		}
 
@@ -393,20 +393,20 @@ static void wlan_scan_create_channel_lis
 				    wlan_cpu_to_le16
 				    (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
 				scanChanList[chanIdx].ChanScanMode.PassiveScan =
-				    TRUE;
+				    1;
 			} else {
 				scanChanList[chanIdx].MaxScanTime =
 				    wlan_cpu_to_le16
 				    (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
 				scanChanList[chanIdx].ChanScanMode.PassiveScan =
-				    FALSE;
+				    0;
 			}
 
 			scanChanList[chanIdx].ChanNumber = cfp->Channel;
 
 			if (filteredScan) {
 				scanChanList[chanIdx].ChanScanMode.
-				    DisableChanFilt = TRUE;
+				    DisableChanFilt = 1;
 			}
 		}
 	}
@@ -496,13 +496,13 @@ void wlan_scan_setup_scan_config(wlan_pr
 	/* Initialize the scan as un-filtered by firmware, set to TRUE below if
 	 *   a SSID or BSSID filter is sent in the command
 	 */
-	*pFilteredScan = FALSE;
+	*pFilteredScan = 0; 
 
 	/* Initialize the scan as not being only on the current channel.  If
 	 *   the channel list is customized, only contains one channel, and
 	 *   is the active channel, this is set true and data flow is not halted.
 	 */
-	*pScanCurrentOnly = FALSE;
+	*pScanCurrentOnly = 0;
 
 	if (pUserScanIn) {
 
@@ -545,7 +545,7 @@ void wlan_scan_setup_scan_config(wlan_pr
 		if (ssidLen || (memcmp(pScanCfgOut->specificBSSID,
 				       &zeroMac, sizeof(zeroMac)) != 0)) {
 			*pMaxChanPerScan = MRVDRV_MAX_CHANNELS_PER_SCAN;
-			*pFilteredScan = TRUE;
+			*pFilteredScan = 1;
 		}
 	} else {
 		pScanCfgOut->bssType = Adapter->ScanMode;
@@ -593,10 +593,10 @@ void wlan_scan_setup_scan_config(wlan_pr
 
 			if (scanType == HostCmd_SCAN_TYPE_PASSIVE) {
 				(pScanChanList +
-				 chanIdx)->ChanScanMode.PassiveScan = TRUE;
+				 chanIdx)->ChanScanMode.PassiveScan = 1;
 			} else {
 				(pScanChanList +
-				 chanIdx)->ChanScanMode.PassiveScan = FALSE;
+				 chanIdx)->ChanScanMode.PassiveScan = 0;
 			}
 
 			if (pUserScanIn->chanList[chanIdx].scanTime) {
@@ -620,7 +620,7 @@ void wlan_scan_setup_scan_config(wlan_pr
 		if ((chanIdx == 1) && (pUserScanIn->chanList[0].chanNumber
 				       ==
 				       priv->adapter->CurBssParams.channel)) {
-			*pScanCurrentOnly = TRUE;
+			*pScanCurrentOnly = 1;
 			PRINTM(INFO, "Scan: Scanning current channel only");
 		}
 
@@ -692,7 +692,7 @@ static int wlan_scan_channel_list(wlan_p
 		pChanTlvOut->Header.Len = 0;
 		scanBand = pTmpChan->RadioType;
 		pStartChan = pTmpChan;
-		doneEarly = FALSE;
+		doneEarly = 0;
 
 		/* Construct the Channel TLV for the scan command.  Continue to
 		 *  insert channel TLVs until:
@@ -735,7 +735,7 @@ static int wlan_scan_channel_list(wlan_p
 			/* Increment the index to the channel tlv we are constructing */
 			tlvIdx++;
 
-			doneEarly = FALSE;
+			doneEarly = 0;
 
 			/* Stop the loop if the *current* channel is in the 1,6,11 set
 			 *   and we are not filtering on a BSSID or SSID.
@@ -743,7 +743,7 @@ static int wlan_scan_channel_list(wlan_p
 			if (!filteredScan && (pTmpChan->ChanNumber == 1
 					      || pTmpChan->ChanNumber == 6
 					      || pTmpChan->ChanNumber == 11)) {
-				doneEarly = TRUE;
+				doneEarly = 1;
 			}
 
 			/* Increment the tmp pointer to the next channel to be scanned */
@@ -756,7 +756,7 @@ static int wlan_scan_channel_list(wlan_p
 			if (!filteredScan && (pTmpChan->ChanNumber == 1
 					      || pTmpChan->ChanNumber == 6
 					      || pTmpChan->ChanNumber == 11)) {
-				doneEarly = TRUE;
+				doneEarly = 1;
 			}
 		}
 
@@ -807,7 +807,7 @@ static int wlan_scan_networks(wlan_priva
 	memset(scanChanList, 0x00, sizeof(scanChanList));
 	memset(&scanCfgOut, 0x00, sizeof(scanCfgOut));
 
-	keepPreviousScan = FALSE;
+	keepPreviousScan = 0;
 
 	wlan_scan_setup_scan_config(priv,
 				    pUserScanIn,
@@ -821,7 +821,7 @@ static int wlan_scan_networks(wlan_priva
 		keepPreviousScan = pUserScanIn->keepPreviousScan;
 	}
 
-	if (keepPreviousScan == FALSE) {
+	if (!keepPreviousScan) {
 		memset(Adapter->ScanTable, 0x00,
 		       sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST);
 		Adapter->NumInScanTable = 0;
@@ -1002,7 +1002,7 @@ static int InterpretBSSDescriptionWithIE
 
 	ENTER();
 
-	foundDataRateIE = FALSE;
+	foundDataRateIE = 0;
 	rateSize = 0;
 	beaconSize = 0;
 
@@ -1034,14 +1034,14 @@ static int InterpretBSSDescriptionWithIE
 	pwpa_supplicant = &pBSSEntry->wpa_supplicant;
 	pwpa2_supplicant = &pBSSEntry->wpa2_supplicant;
 
-	memcpy(pBSSEntry->MacAddress, pCurrentPtr, MRVDRV_ETH_ADDR_LEN);
+	memcpy(pBSSEntry->MacAddress, pCurrentPtr, ETH_ALEN);
 	PRINTM(INFO, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
 	       pBSSEntry->MacAddress[0], pBSSEntry->MacAddress[1],
 	       pBSSEntry->MacAddress[2], pBSSEntry->MacAddress[3],
 	       pBSSEntry->MacAddress[4], pBSSEntry->MacAddress[5]);
 
-	pCurrentPtr += MRVDRV_ETH_ADDR_LEN;
-	bytesLeftForCurrentBeacon -= MRVDRV_ETH_ADDR_LEN;
+	pCurrentPtr += ETH_ALEN;
+	bytesLeftForCurrentBeacon -= ETH_ALEN;
 
 	if (bytesLeftForCurrentBeacon < 12) {
 		PRINTM(INFO, "InterpretIE: Not enough bytes left\n");
@@ -1128,7 +1128,7 @@ static int InterpretBSSDescriptionWithIE
 			memmove(pBSSEntry->SupportedRates, (pCurrentPtr + 2),
 				elemLen);
 			rateSize = elemLen;
-			foundDataRateIE = TRUE;
+			foundDataRateIE = 1;
 			break;
 
 		case EXTRA_IE:
@@ -1233,7 +1233,7 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 
 			if (!memcmp(pIe->oui, oui01, sizeof(oui01))) {
 				pwpa_supplicant->Wpa_ie_len
-				    = MIN(elemLen + IE_ID_LEN_FIELDS_BYTES,
+				    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
 					  sizeof(pwpa_supplicant->Wpa_ie));
 				memcpy(pwpa_supplicant->Wpa_ie,
 				       pCurrentPtr,
@@ -1245,7 +1245,7 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 		case WPA2_IE:
 			pIe = (struct IE_WPA *)pCurrentPtr;
 			pwpa2_supplicant->Wpa_ie_len
-			    = MIN(elemLen + IE_ID_LEN_FIELDS_BYTES,
+			    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
 				  sizeof(pwpa2_supplicant->Wpa_ie));
 			memcpy(pwpa2_supplicant->Wpa_ie,
 			       pCurrentPtr, pwpa2_supplicant->Wpa_ie_len);
@@ -1704,7 +1704,7 @@ #define RSSI_DIFF    ((u8)(PERFECT_RSSI 
 			continue;
 		}
 
-		if (ssid_valid(&Adapter->ScanTable[i].Ssid) == FALSE) {
+		if (!ssid_valid(&Adapter->ScanTable[i].Ssid)) {
 			continue;
 		}
 
@@ -2069,7 +2069,7 @@ int wlan_set_user_scan_ioctl(wlan_privat
 
 	if (copy_from_user(&scanReq,
 			   wrq->u.data.pointer,
-			   MIN(wrq->u.data.length, sizeof(scanReq))) != 0) {
+			   min(wrq->u.data.length, sizeof(scanReq))) != 0) {
 		/* copy_from_user failed  */
 		PRINTM(INFO, "SetUserScan: copy from user failed\n");
 		retcode = -EFAULT;
@@ -2340,7 +2340,7 @@ int wlan_extscan_ioctl(wlan_private * pr
 		LEAVE();
 		return -EFAULT;
 	}
-	SendSpecificSSIDScan(priv, &Ext_Scan_SSID, TRUE);
+	SendSpecificSSIDScan(priv, &Ext_Scan_SSID, 1);
 
 	memset(&wrqu, 0, sizeof(union iwreq_data));
 	wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
diff --git a/drivers/net/wireless/libertas/wlan_scan.h b/drivers/net/wireless/libertas/wlan_scan.h
index a6ee332..d967825 100644
--- a/drivers/net/wireless/libertas/wlan_scan.h
+++ b/drivers/net/wireless/libertas/wlan_scan.h
@@ -77,7 +77,7 @@ struct wlan_scan_cmd_config {
     /**
      *  @brief Specific BSSID used to filter scan results in the firmware
      */
-	u8 specificBSSID[MRVDRV_ETH_ADDR_LEN];
+	u8 specificBSSID[ETH_ALEN];
 
     /**
      *  @brief Length of TLVs sent in command starting at tlvBuffer
@@ -146,7 +146,7 @@ struct wlan_ioctl_user_scan_cfg {
     /**
      *  @brief BSSID filter sent in the firmware command to limit the results
      */
-	u8 specificBSSID[MRVDRV_ETH_ADDR_LEN];
+	u8 specificBSSID[ETH_ALEN];
 
     /**
      *  @brief SSID filter sent in the firmware command to limit the results
diff --git a/drivers/net/wireless/libertas/wlan_tx.c b/drivers/net/wireless/libertas/wlan_tx.c
index 0e760bc..9299ed6 100644
--- a/drivers/net/wireless/libertas/wlan_tx.c
+++ b/drivers/net/wireless/libertas/wlan_tx.c
@@ -88,7 +88,7 @@ static int SendSinglePacket(wlan_private
 	ENTER();
 
 	if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
-		HEXDUMP("TX packet: ", skb->data, MIN(skb->len, 100));
+		HEXDUMP("TX packet: ", skb->data, min(skb->len, 100));
 
 	if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
 		PRINTM(INFO, "Tx Error: Bad skb length %d : %d\n",
@@ -102,7 +102,7 @@ static int SendSinglePacket(wlan_private
 	pLocalTxPD->TxPacketLength = skb->len;
 
 	if (Adapter->PSState != PS_STATE_FULL_POWER) {
-		if (TRUE == CheckLastPacketIndication(priv)) {
+		if (CheckLastPacketIndication(priv)) {
 			Adapter->TxLockFlag = 1;
 			pLocalTxPD->PowerMgmt =
 			    MRVDRV_TxPD_POWER_MGMT_LAST_PACKET;
@@ -136,11 +136,9 @@ static int SendSinglePacket(wlan_private
 	}
 	/* copy destination address from 802.3 or 802.11 header */
 	if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
-		memcpy(pLocalTxPD->TxDestAddrHigh, p802x_hdr + 4,
-		       MRVDRV_ETH_ADDR_LEN);
+		memcpy(pLocalTxPD->TxDestAddrHigh, p802x_hdr + 4, ETH_ALEN);
 	else
-		memcpy(pLocalTxPD->TxDestAddrHigh, p802x_hdr,
-		       MRVDRV_ETH_ADDR_LEN);
+		memcpy(pLocalTxPD->TxDestAddrHigh, p802x_hdr, ETH_ALEN);
 
 	HEXDUMP("TxPD", (u8 *) pLocalTxPD, sizeof(struct TxPD));
 
@@ -234,7 +232,7 @@ int wlan_process_tx(wlan_private * priv,
 
 	ENTER();
 
-	HEXDUMP("TX Data", skb->data, MIN(skb->len, 100));
+	HEXDUMP("TX Data", skb->data, min(skb->len, 100));
 
 	if (priv->wlan_dev.dnld_sent) {
 		PRINTM(MSG, "TX Error: dnld_sent = %d, not sending\n",
@@ -272,7 +270,7 @@ int SendNullPacket(wlan_private * priv, 
 
 	ENTER();
 
-	if (priv->adapter->SurpriseRemoved == TRUE) {
+	if (priv->adapter->SurpriseRemoved) {
 		ret = WLAN_STATUS_FAILURE;
 		goto done;
 	}
@@ -313,7 +311,7 @@ int SendNullPacket(wlan_private * priv, 
 u8 CheckLastPacketIndication(wlan_private * priv)
 {
 	wlan_adapter *Adapter = priv->adapter;
-	u8 ret = FALSE;
+	u8 ret = 0;
 	if (Adapter->sleep_period.period == 0)
 		goto done;
       done:
@@ -345,7 +343,7 @@ void SendTxFeedback(wlan_private * priv)
 
 	if ((Adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
 		HEXDUMP("TX feedback: ", (u8 *) radiotap_hdr,
-			MIN(Adapter->CurrentTxSkb->len, 100));
+			min(Adapter->CurrentTxSkb->len, 100));
 
 	txfail = (status >> 24);
 
diff --git a/drivers/net/wireless/libertas/wlan_wext.c b/drivers/net/wireless/libertas/wlan_wext.c
index 9b5e4a9..b25001d 100644
--- a/drivers/net/wireless/libertas/wlan_wext.c
+++ b/drivers/net/wireless/libertas/wlan_wext.c
@@ -338,7 +338,7 @@ static int ChangeAdhocChannel(wlan_priva
 		/* Scan for the network, do not save previous results.  Stale
 		 *   scan data will cause us to join a non-existant adhoc network
 		 */
-		SendSpecificSSIDScan(priv, &curAdhocSsid, FALSE);
+		SendSpecificSSIDScan(priv, &curAdhocSsid, 0);
 
 		// find out the BSSID that matches the current SSID 
 		i = FindSSIDInList(Adapter, &curAdhocSsid, NULL,
@@ -789,7 +789,7 @@ static int reassociation_on(wlan_private
 
 	ENTER();
 
-	Adapter->Reassoc_on = TRUE;
+	Adapter->Reassoc_on = 1;
 
 	LEAVE();
 	return WLAN_STATUS_SUCCESS;
@@ -809,7 +809,7 @@ static int reassociation_off(wlan_privat
 
 	del_timer(&Adapter->reassoc_timer);
 
-	Adapter->Reassoc_on = FALSE;
+	Adapter->Reassoc_on = 0;
 
 	LEAVE();
 	return WLAN_STATUS_SUCCESS;
@@ -1656,7 +1656,7 @@ static int wlan_get_range(struct net_dev
 	struct chan_freq_power *cfp;
 	u8 rates[WLAN_SUPPORTED_RATES];
 
-	u8 flag = FALSE;
+	u8 flag = 0;
 
 	ENTER();
 
@@ -1669,7 +1669,7 @@ static int wlan_get_range(struct net_dev
 	memset(rates, 0, sizeof(rates));
 	range->num_bitrates = get_active_data_rates(Adapter, rates);
 
-	for (i = 0; i < MIN(range->num_bitrates, IW_MAX_BITRATES) && rates[i];
+	for (i = 0; i < min(range->num_bitrates, IW_MAX_BITRATES) && rates[i];
 	     i++) {
 		range->bitrate[i] = (rates[i] & 0x7f) * 500000;
 	}
@@ -1705,7 +1705,7 @@ static int wlan_get_range(struct net_dev
 			range->freq[range->num_frequency].e = 1;
 			range->num_frequency++;
 		}
-		flag = TRUE;
+		flag = 1;
 	}
 	if (!flag) {
 		for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
@@ -2520,12 +2520,12 @@ static int wlan_hostcmd_ioctl(struct net
 
 	PRINTM(INFO, "HOSTCMD Command: 0x%04x Size: %d SeqNum: %d\n",
 	       pCmdPtr->Command, pCmdPtr->Size, pCmdPtr->SeqNum);
-	HEXDUMP("Command Data", (u8 *) (pCmdPtr), MIN(32, pCmdPtr->Size));
+	HEXDUMP("Command Data", (u8 *) (pCmdPtr), min(32, pCmdPtr->Size));
 	PRINTM(INFO, "Copying data from : (user)0x%p -> 0x%p(driver)\n",
 	       req->ifr_data, pCmdPtr);
 
-	pCmdNode->CmdWaitQWoken = FALSE;
-	QueueCmd(Adapter, pCmdNode, TRUE);
+	pCmdNode->CmdWaitQWoken = 0;
+	QueueCmd(Adapter, pCmdNode, 1);
 	wake_up_interruptible(&priv->MainThread.waitQ);
 
 	if (wait_option & HostCmd_OPTION_WAITFORRSP) {
@@ -2587,7 +2587,7 @@ static int wlan_get_snr(wlan_private * p
 	if (wrq->u.data.length) {
 		if (copy_from_user
 		    (data, wrq->u.data.pointer,
-		     MIN(wrq->u.data.length, 4) * sizeof(int))) {
+		     min(wrq->u.data.length, 4) * sizeof(int))) {
 			PRINTM(INFO, "Copy from user failed\n");
 			return -EFAULT;
 		}
@@ -2848,7 +2848,7 @@ static int wlan_get_adhoc_status_ioctl(w
 	switch (Adapter->InfrastructureMode) {
 	case Wlan802_11IBSS:
 		if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
-			if (Adapter->AdhocCreate == TRUE)
+			if (Adapter->AdhocCreate)
 				memcpy(&status, "AdhocStarted", sizeof(status));
 			else
 				memcpy(&status, "AdhocJoined", sizeof(status));
@@ -3054,20 +3054,20 @@ static int wlan_setwpaie_ioctl(wlan_priv
 		       Adapter->Wpa_ie[0]);
 		HEXDUMP("Wpa_ie", Adapter->Wpa_ie, Adapter->Wpa_ie_len);
 		if (Adapter->Wpa_ie[0] == WPA_IE)
-			Adapter->SecInfo.WPAEnabled = TRUE;
+			Adapter->SecInfo.WPAEnabled = 1;
 		else if (Adapter->Wpa_ie[0] == WPA2_IE)
-			Adapter->SecInfo.WPA2Enabled = TRUE;
+			Adapter->SecInfo.WPA2Enabled = 1;
 		else {
-			Adapter->SecInfo.WPAEnabled = FALSE;
-			Adapter->SecInfo.WPA2Enabled = FALSE;
+			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 = FALSE;
-		Adapter->SecInfo.WPA2Enabled = FALSE;
+		Adapter->SecInfo.WPAEnabled = 0;
+		Adapter->SecInfo.WPA2Enabled = 0;
 	}
 
 	// enable/disable RSN in firmware if WPA is enabled/disabled
@@ -3098,10 +3098,10 @@ static int wlan_subcmd_setprescan_ioctl(
 	PRINTM(INFO, "WLAN_SUBCMD_SET_PRESCAN %d\n", data);
 	switch (data) {
 	case CMD_ENABLED:
-		Adapter->Prescan = TRUE;
+		Adapter->Prescan = 1;
 		break;
 	case CMD_DISABLED:
-		Adapter->Prescan = FALSE;
+		Adapter->Prescan = 0;
 		break;
 	default:
 		break;
@@ -3259,7 +3259,7 @@ static void adjust_mtu(wlan_private * pr
 	if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP)
 		mtu_increment += max(sizeof(struct TxRadiotapHdr),
 				     sizeof(struct RxRadiotapHdr));
-	priv->wlan_dev.netdev->mtu = MRVDRV_MAXIMUM_ETH_PACKET_SIZE
+	priv->wlan_dev.netdev->mtu = ETH_FRAME_LEN
 	    - sizeof(struct EthII_Hdr)
 	    + mtu_increment;
 }
@@ -3437,7 +3437,7 @@ static int wlan_get_tsf_ioctl(wlan_priva
 	} else {
 		if (copy_to_user(wrq->u.data.pointer,
 				 &tsfVal,
-				 MIN(wrq->u.data.length,
+				 min(wrq->u.data.length,
 				     sizeof(tsfVal))) != 0) {
 
 			PRINTM(INFO, "IOCTL: Get TSF; Copy to user failed\n");
@@ -3675,7 +3675,7 @@ static int wlan_sleep_params_ioctl(wlan_
 	memset(&sp, 0, sizeof(sp));
 
 	if (copy_from_user(&sp, wrq->u.data.pointer,
-			   MIN(sizeof(sp), wrq->u.data.length))) {
+			   min(sizeof(sp), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -3750,7 +3750,7 @@ static int wlan_scan_type_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, MIN(sizeof(buf),
+	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
 							 wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
@@ -3812,7 +3812,7 @@ static int wlan_scan_mode_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, MIN(sizeof(buf),
+	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
 							 wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
@@ -3886,10 +3886,10 @@ static int wlan_do_set_grate_ioctl(wlan_
 	data1 = *((int *)(wrq->u.name + SUBCMD_OFFSET));
 	switch (data1) {
 	case 0:
-		Adapter->adhoc_grate_enabled = FALSE;
+		Adapter->adhoc_grate_enabled = 0;
 		break;
 	case 1:
-		Adapter->adhoc_grate_enabled = TRUE;
+		Adapter->adhoc_grate_enabled = 1;
 		break;
 	case 2:
 		break;
@@ -4102,7 +4102,7 @@ #define MAX_U16_VAL	65535
 		case WLAN_SET_ATIM_WINDOW:
 			Adapter->AtimWindow =
 			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			Adapter->AtimWindow = MIN(Adapter->AtimWindow, 50);
+			Adapter->AtimWindow = min(Adapter->AtimWindow, 50);
 			break;
 		case WLANSETBCNAVG:
 			Adapter->bcn_avg_factor =
@@ -4847,7 +4847,7 @@ int wlan_set_rate(struct net_device *dev
 
 	if (vwrq->value == -1) {
 		action = HostCmd_ACT_SET_TX_AUTO;	// Auto
-		Adapter->Is_DataRate_Auto = TRUE;
+		Adapter->Is_DataRate_Auto = 1;
 		Adapter->DataRate = 0;
 	} else {
 		if (vwrq->value % 100000) {
@@ -4874,7 +4874,7 @@ int wlan_set_rate(struct net_device *dev
 
 		Adapter->DataRate = data_rate;
 		action = HostCmd_ACT_SET_TX_FIX_RATE;
-		Adapter->Is_DataRate_Auto = FALSE;
+		Adapter->Is_DataRate_Auto = 0;
 	}
 
 	ret = PrepareAndSendCommand(priv, HostCmd_CMD_802_11_DATA_RATE,
@@ -5161,7 +5161,7 @@ int wlan_get_essid(struct net_device *de
 
 	/* To make the driver backward compatible with WPA supplicant v0.2.4 */
 	if (dwrq->length == 32)	/* check with WPA supplicant buffer size */
-		dwrq->length = MIN(Adapter->CurBssParams.ssid.SsidLength,
+		dwrq->length = min(Adapter->CurBssParams.ssid.SsidLength,
 				   IW_ESSID_MAX_SIZE);
 	else
 		dwrq->length = Adapter->CurBssParams.ssid.SsidLength + 1;
diff --git a/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c b/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
index 472cede..3fb90be 100644
--- a/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
+++ b/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
@@ -90,10 +90,6 @@ #include    "wlan_scan.h"
 #include	"wlan_wext.h"
 #include	"wlanconfig.h"
 
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif /* MIN */
-
 enum COMMANDS {
 	CMD_HOSTCMD,
 	CMD_RDMAC,
@@ -581,7 +577,7 @@ static int wlan_get_hostcmd_data(FILE *f
 			}
 			*pos3 = '\0';
 			memset(buf, 0, len);
-			memmove(buf, pos2, MIN(strlen(pos2),len));
+			memmove(buf, pos2, min(strlen(pos2),len));
 			buf += len;
 		}
 		else if (*pos2 == '\'') {
@@ -1292,7 +1288,7 @@ static int process_setuserscan(int argc,
     char chanScratch[10];
     char* pScratch;
     int tmpIdx;
-	unsigned int mac[MRVDRV_ETH_ADDR_LEN];
+	unsigned int mac[ETH_ALEN];
     int scanTime;
 
     memset(&scanReq, 0x00, sizeof(scanReq));


From andreas at fjortis.info  Tue Jul  4 16:07:01 2006
From: andreas at fjortis.info (Andreas Henriksson)
Date: Tue, 4 Jul 2006 22:07:01 +0200
Subject: [PATCH] fix min() warnings
In-Reply-To: <20060704145702.GB13967@dmt>
References: <20060704065754.GA25279@scream.fjortis.info>
	<20060704145702.GB13967@dmt>
Message-ID: <20060704200701.GB26571@scream.fjortis.info>


Here's an attempt to fix the warnings introduced when converting from
MIN()/MAX() to min()/max(), by using min_t() where needed.

"warning: comparison of distinct pointer types lacks a cast"

(still not fixed: "warning: cast from pointer to integer of different size")

Please verify if it's correctly done.

Signed-off-by: Andreas Henriksson <andreas at fjortis.info>

diff --git a/drivers/net/wireless/libertas/wlan_join.c b/drivers/net/wireless/libertas/wlan_join.c
index a97c17d..75bae76 100644
--- a/drivers/net/wireless/libertas/wlan_join.c
+++ b/drivers/net/wireless/libertas/wlan_join.c
@@ -63,7 +63,7 @@ static int get_common_rates(wlan_adapter
 	int i;
 
 	memset(&tmp, 0, sizeof(tmp));
-	memcpy(&tmp, rate1, min(rate1_size, sizeof(tmp)));
+	memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
 	memset(rate1, 0, rate1_size);
 
 	/* Mask the top bit of the original values */
@@ -860,7 +860,8 @@ int wlan_cmd_802_11_associate(wlan_priva
 		goto done;
 	}
 
-	rates->Header.Len = min(strlen(rates->Rates), WLAN_SUPPORTED_RATES);
+	rates->Header.Len = min_t(u16, strlen(rates->Rates),
+			WLAN_SUPPORTED_RATES);
 	Adapter->CurBssParams.NumOfRates = rates->Header.Len;
 
 	pos += sizeof(rates->Header) + rates->Header.Len;
@@ -884,7 +885,8 @@ int wlan_cmd_802_11_associate(wlan_priva
 
 	/* Copy the infra. association rates into Current BSS state structure */
 	memcpy(&Adapter->CurBssParams.DataRates, &rates->Rates,
-	       min(sizeof(Adapter->CurBssParams.DataRates), rates->Header.Len));
+			min_t(size_t, sizeof(Adapter->CurBssParams.DataRates),
+					rates->Header.Len));
 
 	PRINTM(INFO, "ASSOC_CMD: rates->Header.Len = %d\n", rates->Header.Len);
 
diff --git a/drivers/net/wireless/libertas/wlan_scan.c b/drivers/net/wireless/libertas/wlan_scan.c
index 829bbf8..a303c9a 100644
--- a/drivers/net/wireless/libertas/wlan_scan.c
+++ b/drivers/net/wireless/libertas/wlan_scan.c
@@ -1232,9 +1232,9 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 			pIe = (struct IE_WPA *)pCurrentPtr;
 
 			if (!memcmp(pIe->oui, oui01, sizeof(oui01))) {
-				pwpa_supplicant->Wpa_ie_len
-				    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
-					  sizeof(pwpa_supplicant->Wpa_ie));
+				pwpa_supplicant->Wpa_ie_len = min_t(size_t,
+						elemLen + IE_ID_LEN_FIELDS_BYTES,
+						sizeof(pwpa_supplicant->Wpa_ie));
 				memcpy(pwpa_supplicant->Wpa_ie,
 				       pCurrentPtr,
 				       pwpa_supplicant->Wpa_ie_len);
@@ -1244,9 +1244,9 @@ #define IE_ID_LEN_FIELDS_BYTES 2
 			break;
 		case WPA2_IE:
 			pIe = (struct IE_WPA *)pCurrentPtr;
-			pwpa2_supplicant->Wpa_ie_len
-			    = min(elemLen + IE_ID_LEN_FIELDS_BYTES,
-				  sizeof(pwpa2_supplicant->Wpa_ie));
+			pwpa2_supplicant->Wpa_ie_len = min_t(size_t,
+					elemLen + IE_ID_LEN_FIELDS_BYTES,
+					sizeof(pwpa2_supplicant->Wpa_ie));
 			memcpy(pwpa2_supplicant->Wpa_ie,
 			       pCurrentPtr, pwpa2_supplicant->Wpa_ie_len);
 
@@ -2067,9 +2067,9 @@ int wlan_set_user_scan_ioctl(wlan_privat
 	int retcode;
 	union iwreq_data wrqu;
 
-	if (copy_from_user(&scanReq,
-			   wrq->u.data.pointer,
-			   min(wrq->u.data.length, sizeof(scanReq))) != 0) {
+	if (copy_from_user(&scanReq, wrq->u.data.pointer,
+			min_t(unsigned, wrq->u.data.length,
+					sizeof(scanReq)))) {
 		/* copy_from_user failed  */
 		PRINTM(INFO, "SetUserScan: copy from user failed\n");
 		retcode = -EFAULT;
diff --git a/drivers/net/wireless/libertas/wlan_wext.c b/drivers/net/wireless/libertas/wlan_wext.c
index b25001d..5d8dcc4 100644
--- a/drivers/net/wireless/libertas/wlan_wext.c
+++ b/drivers/net/wireless/libertas/wlan_wext.c
@@ -1669,8 +1669,8 @@ static int wlan_get_range(struct net_dev
 	memset(rates, 0, sizeof(rates));
 	range->num_bitrates = get_active_data_rates(Adapter, rates);
 
-	for (i = 0; i < min(range->num_bitrates, IW_MAX_BITRATES) && rates[i];
-	     i++) {
+	for (i = 0; i < min_t(int, range->num_bitrates,
+			IW_MAX_BITRATES) && rates[i]; i++) {
 		range->bitrate[i] = (rates[i] & 0x7f) * 500000;
 	}
 	range->num_bitrates = i;
@@ -2585,9 +2585,9 @@ static int wlan_get_snr(wlan_private * p
 	ENTER();
 	memset(data, 0, sizeof(data));
 	if (wrq->u.data.length) {
-		if (copy_from_user
-		    (data, wrq->u.data.pointer,
-		     min(wrq->u.data.length, 4) * sizeof(int))) {
+		if (copy_from_user(data, wrq->u.data.pointer,
+				min_t(unsigned, wrq->u.data.length, 4) *
+					sizeof(int))) {
 			PRINTM(INFO, "Copy from user failed\n");
 			return -EFAULT;
 		}
@@ -3435,11 +3435,9 @@ static int wlan_get_tsf_ioctl(wlan_priva
 		PRINTM(INFO, "IOCTL: Get TSF; Command exec failed\n");
 		ret = -EFAULT;
 	} else {
-		if (copy_to_user(wrq->u.data.pointer,
-				 &tsfVal,
-				 min(wrq->u.data.length,
-				     sizeof(tsfVal))) != 0) {
-
+		if (copy_to_user(wrq->u.data.pointer, &tsfVal,
+				min_t(unsigned, wrq->u.data.length,
+					sizeof(tsfVal)))) {
 			PRINTM(INFO, "IOCTL: Get TSF; Copy to user failed\n");
 			ret = -EFAULT;
 		} else {
@@ -3675,7 +3673,7 @@ static int wlan_sleep_params_ioctl(wlan_
 	memset(&sp, 0, sizeof(sp));
 
 	if (copy_from_user(&sp, wrq->u.data.pointer,
-			   min(sizeof(sp), wrq->u.data.length))) {
+			   min_t(unsigned, sizeof(sp), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -3750,8 +3748,8 @@ static int wlan_scan_type_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
-							 wrq->u.data.length))) {
+	if (copy_from_user(buf, wrq->u.data.pointer,
+			min_t(unsigned, sizeof(buf), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -3812,8 +3810,8 @@ static int wlan_scan_mode_ioctl(wlan_pri
 
 	memset(buf, 0, sizeof(buf));
 
-	if (copy_from_user(buf, wrq->u.data.pointer, min(sizeof(buf),
-							 wrq->u.data.length))) {
+	if (copy_from_user(buf, wrq->u.data.pointer,
+			min_t(unsigned, sizeof(buf), wrq->u.data.length))) {
 		PRINTM(INFO, "Copy from user failed\n");
 		return -EFAULT;
 	}
@@ -4102,7 +4100,8 @@ #define MAX_U16_VAL	65535
 		case WLAN_SET_ATIM_WINDOW:
 			Adapter->AtimWindow =
 			    *((int *)(wrq->u.name + SUBCMD_OFFSET));
-			Adapter->AtimWindow = min(Adapter->AtimWindow, 50);
+			Adapter->AtimWindow = min_t(u16,
+					Adapter->AtimWindow, 50);
 			break;
 		case WLANSETBCNAVG:
 			Adapter->bcn_avg_factor =
@@ -5161,8 +5160,9 @@ int wlan_get_essid(struct net_device *de
 
 	/* To make the driver backward compatible with WPA supplicant v0.2.4 */
 	if (dwrq->length == 32)	/* check with WPA supplicant buffer size */
-		dwrq->length = min(Adapter->CurBssParams.ssid.SsidLength,
-				   IW_ESSID_MAX_SIZE);
+		dwrq->length = min_t(u32,
+				Adapter->CurBssParams.ssid.SsidLength,
+				IW_ESSID_MAX_SIZE);
 	else
 		dwrq->length = Adapter->CurBssParams.ssid.SsidLength + 1;
 


From arnd at arndb.de  Wed Jul  5 16:21:37 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Wed, 5 Jul 2006 22:21:37 +0200
Subject: [PATCH] libertas: fix wlanconfig
In-Reply-To: <20060705182150.572600000@klappe.arndb.de>
References: <20060705182150.572600000@klappe.arndb.de>
Message-ID: <200607052221.38020.arnd@arndb.de>

Some of the cleanups broke the shared header files for use by
user space wlanconfig. This does enough to get it to compile
without warnings again.

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

Index: linus-2.6/drivers/net/wireless/libertas/wlan_11d.h
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_11d.h
+++ linus-2.6/drivers/net/wireless/libertas/wlan_11d.h
@@ -27,8 +27,10 @@ Change log:
 #ifndef _WLAN_11D_
 #define _WLAN_11D_
 
+#ifdef __KERNEL__
 #include "wlan_types.h"
 #include "wlan_defs.h"
+#endif
 
 #define MAX_CHAN_NUM				255
 
@@ -132,6 +134,7 @@ int wlan_parse_domain_info_11d(struct IE
 				*parsed_region_chan);
 #endif
 
+#ifdef __KERNEL__
 u8 libertas_get_scan_type_11d(u8 chan,
 			  struct parsed_region_chan_11d *parsed_region_chan);
 
@@ -157,4 +160,6 @@ int libertas_parse_dnld_countryinfo_11d(
 
 int libertas_create_dnld_countryinfo_11d(wlan_private * priv);
 
+#endif
+
 #endif				/* _WLAN_11D_ */
Index: linus-2.6/drivers/net/wireless/libertas/wlan_defs.h
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_defs.h
+++ linus-2.6/drivers/net/wireless/libertas/wlan_defs.h
@@ -370,6 +370,7 @@ static inline void HEXDUMP(char *prompt,
 #define wlan_cpu_to_le32(x) x
 #define wlan_cpu_to_le64(x) x
 
+#ifdef __KERNEL__
 /** Global Varibale Declaration */
 typedef struct _wlan_private wlan_private;
 typedef struct _wlan_adapter wlan_adapter;
@@ -385,6 +386,7 @@ extern u8 libertas_supported_rates[G_SUP
 extern u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES];
 
 extern u8 libertas_adhoc_rates_b[4];
+#endif
 
 /** ENUM definition*/
 /** SNRNF_TYPE */
Index: linus-2.6/drivers/net/wireless/libertas/wlan_scan.h
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_scan.h
+++ linus-2.6/drivers/net/wireless/libertas/wlan_scan.h
@@ -236,6 +236,7 @@ struct wlan_ioctl_get_scan_table_info {
 
 } __attribute__ ((packed));
 
+#ifdef __KERNEL__
 /**
  *  @brief Structure used to store information for each beacon/probe response
  */
@@ -306,7 +307,6 @@ extern int libertas_ret_80211_scan(wlan_
 struct ifreq;
 extern int libertas_extscan_ioctl(wlan_private * priv, struct ifreq *req);
 
-#ifdef __KERNEL__
 struct iw_point;
 struct iw_param;
 struct iw_request_info;
Index: linus-2.6/drivers/net/wireless/libertas/wlan_types.h
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlan_types.h
+++ linus-2.6/drivers/net/wireless/libertas/wlan_types.h
@@ -31,7 +31,9 @@ Change log:
 #ifndef _WLAN_TYPES_
 #define _WLAN_TYPES_
 
+#ifdef __KERNEL__
 #include <linux/if_ether.h>
+#endif
 
 /** IEEE Type definitions  */
 enum IEEEtypes_ElementId {
@@ -305,7 +307,7 @@ struct MrvlIEtypes_FailureCount {
 } __attribute__ ((packed));
 
 /** MrvlIEtypes_BeaconsMissed */
-struct _rvlIEtypes_BeaconsMissed {
+struct MrvlIEtypes_BeaconsMissed {
 	struct MrvlIEtypesHeader Header;
 	u8 BeaconMissed;
 	u8 Reserved;
Index: linus-2.6/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
===================================================================
--- linus-2.6.orig/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
+++ linus-2.6/drivers/net/wireless/libertas/wlanconfig/wlanconfig.c
@@ -577,7 +577,9 @@ static int wlan_get_hostcmd_data(FILE *f
 			}
 			*pos3 = '\0';
 			memset(buf, 0, len);
-			memmove(buf, pos2, min(strlen(pos2),len));
+			if (len > strlen(pos2))
+				len = strlen(pos2);
+			memmove(buf, pos2, len);
 			buf += len;
 		}
 		else if (*pos2 == '\'') {
@@ -704,53 +706,53 @@ static int process_host_cmd(int argc, ch
 				int len = S_DS_GEN + sizeof(struct HostCmd_DS_802_11_SUBSCRIBE_EVENT);
 				printf("\nEvent\t\tValue\tFreq\tsubscribed\n\n");
 				while (len < hostcmd->Size) {
-					MrvlIEtypesHeader_t *header = (MrvlIEtypesHeader_t *)(buf + len);
+					struct MrvlIEtypesHeader *header = (struct MrvlIEtypesHeader *)(buf + len);
 					switch (header->Type) {
 					case TLV_TYPE_RSSI_LOW:
 					{
-						MrvlIEtypes_RssiParamSet_t *LowRssi = (MrvlIEtypes_RssiParamSet_t *)(buf + len);
+						struct MrvlIEtypes_RssiThreshold *LowRssi = (struct MrvlIEtypes_RssiThreshold *)(buf + len);
 						printf("Low RSSI\t%d\t%d\t%s\n",LowRssi->RSSIValue,LowRssi->RSSIFreq,(se->Events & 0x0001)?"yes":"no");
-						len += sizeof(MrvlIEtypes_RssiParamSet_t);
+						len += sizeof(struct MrvlIEtypes_RssiThreshold);
 						break;
 					}
 					case TLV_TYPE_SNR_LOW:
 					{
-						MrvlIEtypes_SnrThreshold_t *LowSnr = (MrvlIEtypes_SnrThreshold_t *)(buf + len);
+						struct MrvlIEtypes_SnrThreshold *LowSnr = (struct MrvlIEtypes_SnrThreshold *)(buf + len);
 						printf("Low SNR\t\t%d\t%d\t%s\n",LowSnr->SNRValue,LowSnr->SNRFreq,(se->Events & 0x0002)?"yes":"no");
-						len += sizeof(MrvlIEtypes_SnrThreshold_t);
+						len += sizeof(struct MrvlIEtypes_SnrThreshold);
 						break;
 					}
 					case TLV_TYPE_FAILCOUNT:
 					{
-						MrvlIEtypes_FailureCount_t *FailureCount = (MrvlIEtypes_FailureCount_t *)(buf + len);
+						struct MrvlIEtypes_FailureCount *FailureCount = (struct MrvlIEtypes_FailureCount *)(buf + len);
 						printf("Failure Count\t%d\t%d\t%s\n",FailureCount->FailValue,FailureCount->FailFreq,(se->Events & 0x0004)?"yes":"no");
-						len += sizeof(MrvlIEtypes_FailureCount_t);
+						len += sizeof(struct MrvlIEtypes_FailureCount);
 						break;
 					}
 					case TLV_TYPE_BCNMISS:
 					{
-						MrvlIEtypes_BeaconsMissed_t *BcnMissed = (MrvlIEtypes_BeaconsMissed_t *)(buf + len);
+						struct MrvlIEtypes_BeaconsMissed *BcnMissed = (struct MrvlIEtypes_BeaconsMissed *)(buf + len);
 						printf("Beacon Missed\t%d\tN/A\t%s\n",BcnMissed->BeaconMissed,(se->Events & 0x0008)?"yes":"no");
-						len += sizeof(MrvlIEtypes_BeaconsMissed_t);
+						len += sizeof(struct MrvlIEtypes_BeaconsMissed);
 						break;
 					}
 					case TLV_TYPE_RSSI_HIGH:
 					{
-						MrvlIEtypes_RssiParamSet_t *HighRssi = (MrvlIEtypes_RssiParamSet_t *)(buf + len);
+						struct MrvlIEtypes_RssiThreshold *HighRssi = (struct MrvlIEtypes_RssiThreshold *)(buf + len);
 						printf("High RSSI\t%d\t%d\t%s\n",HighRssi->RSSIValue,HighRssi->RSSIFreq,(se->Events & 0x0010)?"yes":"no");
-						len += sizeof(MrvlIEtypes_RssiParamSet_t);
+						len += sizeof(struct MrvlIEtypes_RssiThreshold);
 						break;
 					}
 					case TLV_TYPE_SNR_HIGH:
 					{
-						MrvlIEtypes_SnrThreshold_t *HighSnr = (MrvlIEtypes_SnrThreshold_t *)(buf + len);
+						struct MrvlIEtypes_SnrThreshold *HighSnr = (struct MrvlIEtypes_SnrThreshold *)(buf + len);
 						printf("High SNR\t%d\t%d\t%s\n",HighSnr->SNRValue,HighSnr->SNRFreq,(se->Events & 0x0020)?"yes":"no");
-						len += sizeof(MrvlIEtypes_SnrThreshold_t);
+						len += sizeof(struct MrvlIEtypes_SnrThreshold);
 						break;
 					}
 					default:
 						printf("unknown subscribed event TLV Type=%#x, Len=%d\n", header->Type, header->Len);
-						len += sizeof(MrvlIEtypesHeader_t) + header->Len;
+						len += sizeof(struct MrvlIEtypesHeader) + header->Len;
 						break;
 					}
 				}
@@ -1083,21 +1085,21 @@ static int process_getscantable(int argc
 
     u8* pCurrent;
     u8* pNext;
-    IEEEtypes_ElementId_e* pElementId;
+    enum IEEEtypes_ElementId* pElementId;
     u8* pElementLen;
     int bssInfoLen;
     int ssidIdx;
     u16 tmpCap;
     u8* pByte;
 
-    IEEEtypes_CapInfo_t capInfo;
+    struct IEEEtypes_CapInfo capInfo;
     u8 tsf[8];
     u16 beaconInterval;
 
-    wlan_ioctl_get_scan_table_info* pRspInfo;
-    wlan_ioctl_get_scan_table_entry* pRspEntry;
+    struct wlan_ioctl_get_scan_table_info* pRspInfo;
+    struct wlan_ioctl_get_scan_table_entry* pRspEntry;
 
-    pRspInfo = (wlan_ioctl_get_scan_table_info*)scanRspBuffer;
+    pRspInfo = (struct wlan_ioctl_get_scan_table_info*)scanRspBuffer;
     
     if (get_priv_ioctl("getscantable", 
                        &ioctl_val, &subioctl_val) == WLAN_STATUS_FAILURE) {
@@ -1139,7 +1141,7 @@ static int process_getscantable(int argc
              */
             pCurrent = pNext;  
 
-            pRspEntry = (wlan_ioctl_get_scan_table_entry*)pCurrent;
+            pRspEntry = (struct wlan_ioctl_get_scan_table_entry*)pCurrent;
             
             printf("%02u| %03d | %03d | %02x:%02x:%02x:%02x:%02x:%02x |",
                    scanStart + idx,
@@ -1194,7 +1196,7 @@ static int process_getscantable(int argc
             }
 
             while (bssInfoLen >= 2) {
-                pElementId  = (IEEEtypes_ElementId_e*)pCurrent;
+                pElementId  = (enum IEEEtypes_ElementId*)pCurrent;
                 pElementLen = pCurrent + 1;
                 pCurrent   += 2;
                 
@@ -1275,7 +1277,7 @@ static int process_getscantable(int argc
  */
 static int process_setuserscan(int argc, char *argv[]) 
 {
-    wlan_ioctl_user_scan_cfg scanReq;
+    struct wlan_ioctl_user_scan_cfg scanReq;
     int ioctl_val, subioctl_val;
 	struct iwreq iwr;
     char* pArgTok;


From arnd.bergmann at de.ibm.com  Thu Jul  6 07:11:46 2006
From: arnd.bergmann at de.ibm.com (Arnd Bergmann)
Date: Thu, 6 Jul 2006 13:11:46 +0200
Subject: libertas private ioctl handlers
Message-ID: <200607061311.46547.arnd.bergmann@de.ibm.com>

I tried to get an overview of which of the nonstandard ioctl numbers
that the driver defines (there are roughly 50 of them!) are actually
used, so we can get rid of the others.

Now it turns out that there are only six numbers that are both defined
and used in wlanconfig.c:

WLANEXTSCAN
WLAN_GET_SCAN_TABLE
WLAN_SET_USER_SCAN
WLANSLEEPPARAMS
WLANHOSTCMD
WLANREGRDWR

There are also five ioctls that wlanconfig tries to call but that
don't seem to be implemented at all:

WLAN_GET_RATE
WLANCMD52RDWR
WLANCMD53RDWR
WLANREGCFRDWR
"bca-ts"

Can anyone explain this mismatch? Can we just remove all the functions
that are not used in wlanconfig, or is there another tool that we
need?

	Arnd <><


From dcbw at redhat.com  Thu Jul  6 09:48:40 2006
From: dcbw at redhat.com (Dan Williams)
Date: Thu, 06 Jul 2006 09:48:40 -0400
Subject: libertas private ioctl handlers
In-Reply-To: <200607061311.46547.arnd.bergmann@de.ibm.com>
References: <200607061311.46547.arnd.bergmann@de.ibm.com>
Message-ID: <1152193720.26411.2.camel@localhost.localdomain>

On Thu, 2006-07-06 at 13:11 +0200, Arnd Bergmann wrote:
> I tried to get an overview of which of the nonstandard ioctl numbers
> that the driver defines (there are roughly 50 of them!) are actually
> used, so we can get rid of the others.

> Can anyone explain this mismatch? Can we just remove all the functions
> that are not used in wlanconfig, or is there another tool that we
> need?

I guess I'd say leave them for the moment, for two reasons.  First,
we'll need some of that code to fold into WEXT routines (some of the WPA
stuff, beacon timing, scan mode, etc).  Second, we'll need to check with
Michail to see what stuff the mesh mode would need.  It's quite possible
that wlanconfig hasn't been updated for a lot of the mesh functionality
that's in the OLPC firmware.

Dan




From arnd at arndb.de  Thu Jul  6 14:49:27 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Thu, 6 Jul 2006 20:49:27 +0200
Subject: libertas private ioctl handlers
In-Reply-To: <1152193720.26411.2.camel@localhost.localdomain>
References: <200607061311.46547.arnd.bergmann@de.ibm.com>
	<1152193720.26411.2.camel@localhost.localdomain>
Message-ID: <200607062049.28131.arnd@arndb.de>

On Thursday 06 July 2006 15:48, Dan Williams wrote:
> I guess I'd say leave them for the moment, for two reasons. ?First,
> we'll need some of that code to fold into WEXT routines (some of the WPA
> stuff, beacon timing, scan mode, etc).

Removing the code now wouldn't mean that it's gone forever, you can
always look back in the git history to find those parts. It does
however bitrot when there are no users and we try to clean up those
handlers anyway, as it's impossible to tell why some parts of it
need to be implemented in the way they are.

In particular, some calls need to be changed before upstream
integration because the interface is not 64 bit safe.

> Second, we'll need to check with 
> Michail to see what stuff the mesh mode would need. ?It's quite possible
> that wlanconfig hasn't been updated for a lot of the mesh functionality
> that's in the OLPC firmware.

Yes, that makes sense. We definitely need all the code that is required
to make mesh networking work. Having the code in wlanconfig would be
good in order to understand if there are problems with the implementation
though.

	Arnd <><


From mbletsas at laptop.org  Thu Jul  6 21:46:14 2006
From: mbletsas at laptop.org (Michail Bletsas)
Date: Thu, 6 Jul 2006 21:46:14 -0400
Subject: libertas private ioctl handlers
In-Reply-To: <200607062049.28131.arnd@arndb.de>
Message-ID: <OFF51216FE.D02F9A5D-ON852571A4.00095BF8-852571A4.00099FEB@notes-mail.media.mit.edu>

> 
> > Second, we'll need to check with 
> > Michail to see what stuff the mesh mode would need.  It's quite 
possible
> > that wlanconfig hasn't been updated for a lot of the mesh 
functionality
> > that's in the OLPC firmware.
> 
> Yes, that makes sense. We definitely need all the code that is required
> to make mesh networking work. Having the code in wlanconfig would be
> good in order to understand if there are problems with the 
implementation
> though.
> 

The 802.11s mesh network code is going to be running completely on the 
firmware so the only pieces exposed to the host CPU are going to be the 
various controls and diagnostic APIs. 
For the moment mesh network specific controls are implemented via iwpriv 
commands.
In general what should be going to wlanconfig and what to iwpriv?

M.




From arnd at arndb.de  Fri Jul  7 05:23:53 2006
From: arnd at arndb.de (Arnd Bergmann)
Date: Fri, 7 Jul 2006 11:23:53 +0200
Subject: libertas private ioctl handlers
In-Reply-To: <OFF51216FE.D02F9A5D-ON852571A4.00095BF8-852571A4.00099FEB@notes-mail.media.mit.edu>
References: <OFF51216FE.D02F9A5D-ON852571A4.00095BF8-852571A4.00099FEB@notes-mail.media.mit.edu>
Message-ID: <200607071123.53347.arnd@arndb.de>

On Friday 07 July 2006 03:46, Michail Bletsas wrote:

> The 802.11s mesh network code is going to be running completely on the 
> firmware so the only pieces exposed to the host CPU are going to be the 
> various controls and diagnostic APIs. 
> For the moment mesh network specific controls are implemented via iwpriv 
> commands.
> In general what should be going to wlanconfig and what to iwpriv?

I just found the archived discussion from
http://lists.infradead.org/pipermail/libertas-dev/2006-June/000020.html

Following the reasoning there, I'd suggest we try to get rid of wlanconfig
completely eventually, so the answer is that everything we need should
go into iwpriv. Configuration file handling hopefully can be done with
simple scripts that in turn call iwpriv. 

Now still the number of iwpriv commands (I didn't know how iwpriv works
until I looked that up now) is very large, at some point we should
probably audit them to see which ones are actually needed there.

	Arnd <><


From maray at inf.utfsm.cl  Mon Jul 10 20:00:45 2006
From: maray at inf.utfsm.cl (Mauricio =?iso-8859-1?Q?A=2E_Araya_L=F3pez?=)
Date: Mon, 10 Jul 2006 20:00:45 -0400
Subject: Kernel crash on loading libertas driver
Message-ID: <20060711000045.GA27523@alumnos.inf.utfsm.cl>

Hi all,

I am using kernel patches from Marcelo's git tree, to get support
for the Marvell Wlan chip on an OLPC Test-A board. I have some 
problems with the .config, and I get this error while booting.

usb 1-4: new high speed USB device using ehci_hcd and address 3
usb 1-4: Product: MARVELL Wireless Device
usb 1-4: Manufacturer: Marvell
usb 1-4: configuration #1 chosen from 1 choice
drivers/usb/cire/urb.c: BOGUS urb flags, 40 --> 0
usbcore: deregistering driver usb8xxx

And all USB system fails, getting the system stalled... which is fatal
in this case because all input devices (keyboard, mouse) and usb-storage
devices fails with it.

Bye,

-- 
Mauricio Araya L. 
ACS-UTFSM Team Leader, cel: 09 3469 128
Est. Magister en Ciencias de la Informatica UTFSM, Valparaiso, Chile
counter.li.org: #249395, http://www.inf.utfsm.cl/~maray 


From brian at cozybit.com  Thu Jul 13 17:07:22 2006
From: brian at cozybit.com (Brian Cavagnolo)
Date: Thu, 13 Jul 2006 14:07:22 -0700
Subject: [PATCH] Addressed some issues related to multiple cards with one
	driver
Message-ID: <a00437e00607131407s2c232bfela4e52e53a46b806@mail.gmail.com>

Made remove_card function use per-card wlan_private struct instead of
single global one.

Made one proc entry per card instead of one global proc entry.

P.S.  I'm an engineer for cozybit helping with the libertas
integration.  Please let me know if I'm following the right procedure
to submit patches.

Signed-off-by: Brian Cavagnolo <brian at cozybit.com>
---
 drivers/net/wireless/libertas/if_usb.c    |   11 +++++++
 drivers/net/wireless/libertas/sbi.h       |    1 +
 drivers/net/wireless/libertas/wlan_decl.h |    2 +
 drivers/net/wireless/libertas/wlan_main.c |   24 +++++++++------
 drivers/net/wireless/libertas/wlan_proc.c |   45 ++++++++++++++++++++++++-----
 5 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/libertas/if_usb.c
b/drivers/net/wireless/libertas/if_usb.c
index b815569..23c5fd5 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -1026,6 +1026,17 @@ int libertas_sbi_disable_host_int(wlan_p
 	return WLAN_STATUS_SUCCESS;
 }

+/**
+ *  @brief Given a usb_card_rec return its wlan_private
+ *  @param card		pointer to a usb_card_rec
+ *  @return 	   	pointer to wlan_private
+ */
+wlan_private *libertas_sbi_get_priv(void *card)
+{
+	struct usb_card_rec *cardp = (struct usb_card_rec *)card;
+	return (wlan_private *)cardp->priv;
+}
+
 #ifdef ENABLE_PM
 /**
  *  @brief This is a dummy function
diff --git a/drivers/net/wireless/libertas/sbi.h
b/drivers/net/wireless/libertas/sbi.h
index 4ad7aaf..8c8c3f8 100644
--- a/drivers/net/wireless/libertas/sbi.h
+++ b/drivers/net/wireless/libertas/sbi.h
@@ -104,6 +104,7 @@ int libertas_sbi_read_event_cause(wlan_p
 int libertas_sbi_reenable_host_interrupt(wlan_private *, u8);
 int libertas_sbi_host_to_card(wlan_private * priv, u8 type, u8 *
payload, u16 nb);
 int libertas_sbi_enable_host_int(wlan_private *);
+wlan_private *libertas_sbi_get_priv(void *card);

 #ifdef ENABLE_PM
 int libertas_sbi_suspend(wlan_private *);
diff --git a/drivers/net/wireless/libertas/wlan_decl.h
b/drivers/net/wireless/libertas/wlan_decl.h
index b3f42f8..6af060d 100644
--- a/drivers/net/wireless/libertas/wlan_decl.h
+++ b/drivers/net/wireless/libertas/wlan_decl.h
@@ -73,6 +73,8 @@ void libertas_get_version(wlan_adapter *
 int libertas_upload_rx_packet(wlan_private * priv, struct sk_buff *skb);

 /** The proc fs interface */
+void libertas_proc_init(void);
+void libertas_proc_cleanup(void);
 void libertas_proc_entry(wlan_private * priv, struct net_device *dev);
 void libertas_proc_remove(wlan_private * priv);
 void libertas_debug_entry(wlan_private * priv, struct net_device *dev);
diff --git a/drivers/net/wireless/libertas/wlan_main.c
b/drivers/net/wireless/libertas/wlan_main.c
index 5083697..2a680e3 100644
--- a/drivers/net/wireless/libertas/wlan_main.c
+++ b/drivers/net/wireless/libertas/wlan_main.c
@@ -867,15 +867,6 @@ #endif				/* REASSOCIATION */
 		goto err_registerdev;
 	}

-	PRINTM(WARN, "%s: Marvell Wlan 802.11 Adapter "
-	       "revision 0x%02X at IRQ %i\n", dev->name,
-	       priv->adapter->chip_rev, dev->irq);
-
-	libertas_proc_entry(priv, dev);
-#ifdef PROC_DEBUG
-	libertas_debug_entry(priv, dev);
-#endif
-
 	/* Get the CIS Table */
 	libertas_sbi_get_cis_info(priv);

@@ -890,6 +881,15 @@ #endif
 		goto err_init_fw;
 	}

+	PRINTM(WARN, "%s: Marvell Wlan 802.11 Adapter "
+	       "revision 0x%02X at IRQ %i\n", dev->name,
+	       priv->adapter->chip_rev, dev->irq);
+
+	libertas_proc_entry(priv, dev);
+#ifdef PROC_DEBUG
+	libertas_debug_entry(priv, dev);
+#endif
+
 	LEAVE();
 	return priv;

@@ -922,7 +922,7 @@ #endif				/* REASSOCIATION */
  */
 static int wlan_remove_card(void *card)
 {
-	wlan_private *priv = wlanpriv;
+	wlan_private *priv = libertas_sbi_get_priv(card);
 	wlan_adapter *Adapter;
 	struct net_device *dev;
 	union iwreq_data wrqu;
@@ -1127,6 +1127,8 @@ static int wlan_init_module(void)

 	ENTER();

+	libertas_proc_init();
+
 	if (libertas_fw_name == NULL) {
 		libertas_fw_name = default_fw_name;
 	}
@@ -1153,6 +1155,8 @@ static void wlan_cleanup_module(void)

 	libertas_sbi_unregister();

+	libertas_proc_cleanup();
+
 	LEAVE();
 }

diff --git a/drivers/net/wireless/libertas/wlan_proc.c
b/drivers/net/wireless/libertas/wlan_proc.c
index 282a147..00336e4 100644
--- a/drivers/net/wireless/libertas/wlan_proc.c
+++ b/drivers/net/wireless/libertas/wlan_proc.c
@@ -43,6 +43,8 @@ static char *szStates[] = {
 	"Disconnected"
 };

+static struct proc_dir_entry *libertas_proc_base = NULL;
+
 /**
  *  @brief proc read function
  *
@@ -126,7 +128,36 @@ #endif
 }

 /**
- *  @brief create wlan proc file
+ *  @brief create wlan base dir in /proc/net
+ *
+ *  @return 	   N/A
+ */
+void libertas_proc_init(void)
+{
+#ifdef CONFIG_PROC_FS
+	if (!libertas_proc_base) {
+		PRINTM(INFO, "Creating Proc Base\n");
+		libertas_proc_base = proc_mkdir("wlan", proc_net);
+	}
+#endif
+}
+
+/**
+ *  @brief remove wlan based dir in /proc/net
+ *
+ *  @return 	   N/A
+ */
+void libertas_proc_cleanup(void)
+{
+#ifdef CONFIG_PROC_FS
+	if (libertas_proc_base) {
+		remove_proc_entry("wlan", proc_net);
+	}
+#endif
+}
+
+/**
+ *  @brief add card entry to /proc/net
  *
  *  @param priv	   pointer wlan_private
  *  @param dev     pointer net_device
@@ -135,15 +166,15 @@ #endif
 void libertas_proc_entry(wlan_private * priv, struct net_device *dev)
 {

-#ifdef	CONFIG_PROC_FS
-	PRINTM(INFO, "Creating Proc Interface\n");
+#ifdef	CONFIG_PROC_FS
+	PRINTM(INFO, "Adding Proc Dev Entry For %s\n", dev->name);

 	if (!priv->proc_entry) {
-		priv->proc_entry = proc_mkdir("wlan", proc_net);
+		priv->proc_entry = libertas_proc_base;

 		if (priv->proc_entry) {
 			priv->proc_dev = create_proc_read_entry
-			    ("info", 0, priv->proc_entry, wlan_proc_read, dev);
+			    (dev->name, 0, priv->proc_entry, wlan_proc_read, dev);
 		}
 	}
 #endif
@@ -159,7 +190,7 @@ void libertas_proc_remove(wlan_private *
 {
 #ifdef CONFIG_PROC_FS
 	if (priv->proc_entry)
-		remove_proc_entry("info", priv->proc_entry);
-	remove_proc_entry("wlan", proc_net);
+		remove_proc_entry(priv->wlan_dev.netdev->name,
+				  priv->proc_entry);
 #endif
 }
-- 
1.4.0


From arnd.bergmann at de.ibm.com  Thu Jul 13 18:27:54 2006
From: arnd.bergmann at de.ibm.com (Arnd Bergmann)
Date: Fri, 14 Jul 2006 00:27:54 +0200
Subject: [PATCH] Addressed some issues related to multiple cards with one
	driver
In-Reply-To: <a00437e00607131407s2c232bfela4e52e53a46b806@mail.gmail.com>
References: <a00437e00607131407s2c232bfela4e52e53a46b806@mail.gmail.com>
Message-ID: <200607140027.54607.arnd.bergmann@de.ibm.com>

On Thursday 13 July 2006 23:07, Brian Cavagnolo wrote:
> Made remove_card function use per-card wlan_private struct instead of
> single global one.
> 
> Made one proc entry per card instead of one global proc entry.
> 
I don't mean to turn down steps that go in the right direction,
but shouldn't we rather aim to remove the need to procfs in libertas
completely?

	Arnd <><


From brian at cozybit.com  Fri Jul 14 18:01:31 2006
From: brian at cozybit.com (Brian Cavagnolo)
Date: Fri, 14 Jul 2006 15:01:31 -0700
Subject: [PATCH] Addressed some issues related to multiple cards with one
	driver
In-Reply-To: <200607140027.54607.arnd.bergmann@de.ibm.com>
References: <a00437e00607131407s2c232bfela4e52e53a46b806@mail.gmail.com>
	<200607140027.54607.arnd.bergmann@de.ibm.com>
Message-ID: <a00437e00607141501w4fff46dckb0c73fbc4a35b4b0@mail.gmail.com>

On 7/13/06, Arnd Bergmann <arnd.bergmann at de.ibm.com> wrote:
> On Thursday 13 July 2006 23:07, Brian Cavagnolo wrote:
> > Made remove_card function use per-card wlan_private struct instead of
> > single global one.
> >
> > Made one proc entry per card instead of one global proc entry.
> >
> I don't mean to turn down steps that go in the right direction,
> but shouldn't we rather aim to remove the need to procfs in libertas
> completely?

This was a fix that we implemented to be able to support multiple cards
on a single host.  We don't use the procfs and don't plan to add anything to
it, so if anyone wants to remove it in the future, it's fine with us.

Ciao,
Brian


From marcelo at kvack.org  Thu Jul 20 09:39:48 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Thu, 20 Jul 2006 10:39:48 -0300
Subject: Kernel crash on loading libertas driver
In-Reply-To: <20060711000045.GA27523@alumnos.inf.utfsm.cl>
References: <20060711000045.GA27523@alumnos.inf.utfsm.cl>
Message-ID: <20060720133948.GA13946@dmt>

On Mon, Jul 10, 2006 at 08:00:45PM -0400, Mauricio A. Araya L?pez wrote:
> Hi all,
> 
> I am using kernel patches from Marcelo's git tree, to get support
> for the Marvell Wlan chip on an OLPC Test-A board. I have some 
> problems with the .config, and I get this error while booting.
> 
> usb 1-4: new high speed USB device using ehci_hcd and address 3
> usb 1-4: Product: MARVELL Wireless Device
> usb 1-4: Manufacturer: Marvell
> usb 1-4: configuration #1 chosen from 1 choice
> drivers/usb/cire/urb.c: BOGUS urb flags, 40 --> 0
> usbcore: deregistering driver usb8xxx
> 
> And all USB system fails, getting the system stalled... which is fatal
> in this case because all input devices (keyboard, mouse) and usb-storage
> devices fails with it.

Hi Mauricio,

Disable CONFIG_USB_DEBUG for now to get the driver working.

Someone needs to investigate the problem: USB core dislikes
URB_ZERO_PACKET flag for bulk pipes. Such flag is set to send a final
zero packet to finish the transfer.

Now I have no idea if such packet is needed by some host controllers, or
simply unnecessary.

Thanks!


From marcelo at kvack.org  Sat Jul 22 18:10:25 2006
From: marcelo at kvack.org (Marcelo Tosatti)
Date: Sat, 22 Jul 2006 19:10:25 -0300
Subject: OLPC wireless driver.
In-Reply-To: <yd31wsdqtq4.fsf@islay.ra.phy.cam.ac.uk>
References: <yd31wsdqtq4.fsf@islay.ra.phy.cam.ac.uk>
Message-ID: <20060722221025.GA3243@dmt>

On Sat, Jul 22, 2006 at 09:18:11PM +0100, Chris Ball wrote:

> Hi, Marcelo.
> 
> I'd love to help out with the libertas driver for OLPC, but I'm not sure
> what's needed.  Do you have a TODO for the driver anywhere?
> 
> Thanks!

Hi Chris,

Here are a few items of my list:

* Source documentation
  Convert to kernel-style doc
  Documentation/kernel-doc-nano-HOWTO.txt

* Test suspend/resume

* Check correct endianness handling

* Verify 64-bit correctness
http://lists.infradead.org/pipermail/libertas-dev/2006-July/000046.html

* Check the necessity for the packed attribute on a large number of 
structure defitinions.

* Fixup the ioctl mess 
http://lists.infradead.org/pipermail/libertas-dev/2006-July/000058.html

* Lack of proper synchronization between different contexts

Help is welcome!


From brian at cozybit.com  Fri Jul 28 18:04:48 2006
From: brian at cozybit.com (Brian Cavagnolo)
Date: Fri, 28 Jul 2006 15:04:48 -0700
Subject: Upcoming FWT Firmware Features
Message-ID: <a00437e00607281504j2a03d9b2w76d8ac395ebfc5c0@mail.gmail.com>

Hello,

We (cozybit) are maintaining a git tree at:

http://git.infradead.org/?p=users/jcardona/libertas-fwt;a=summary

Our purpose is to add support for the upcoming FWT features in the
Marvell firmware.  The FWT (or ForWarding Table) features are a set of
iwpriv commands to edit and inspect the firmware table used to
implement mesh network routing.  More detail on the iwpriv commands
can be found in drivers/net/wireless/libertas/README of the afore
mentioned git tree.  The FWT features are not available in the current
Marvell firmware release [1] but will be available in the future.

The above tree is a clone of Marcelo's tree.  To ease integration of
the FWT features, and to keep our public tree up-to-date, we will
continue to pull any changes that appear there.

Thanks,
Brian

[1] https://www.marvell.com/drivers/driverDisplay.do?dId=160&pId=38


