nozomi: bcmdhd reimplement from sony
diff --git a/drivers/net/wireless/bcmdhd/Makefile b/drivers/net/wireless/bcmdhd/Makefile
index e82c985..6cd6d43 100644
--- a/drivers/net/wireless/bcmdhd/Makefile
+++ b/drivers/net/wireless/bcmdhd/Makefile
@@ -3,17 +3,24 @@
 	-DBCMDONGLEHOST -DUNRELEASEDCHIP -DBCMDMA32 -DWLBTAMP -DBCMFILEIMAGE  \
 	-DDHDTHREAD -DDHD_GPL -DDHD_SCHED -DDHD_DEBUG -DSDTEST -DBDC -DTOE    \
 	-DDHD_BCMEVENTS -DSHOW_EVENTS -DDONGLEOVERLAYS -DBCMDBG               \
-	-DCUSTOMER_HW2 -DCUSTOM_OOB_GPIO_NUM=2 -DOOB_INTR_ONLY -DHW_OOB       \
-	-DMMC_SDIO_ABORT -DBCMSDIO -DBCMLXSDMMC -DBCMPLATFORM_BUS -DWLP2P     \
+	-DCUSTOMER_HW -DCUSTOM_OOB_GPIO_NUM=128  \
+	-DOOB_INTR_ONLY -DHW_OOB -DMMC_SDIO_ABORT                            \
+	-DBCMSDIO -DBCMLXSDMMC -DBCMPLATFORM_BUS            \
+	-DCONFIG_WIFI_CONTROL_FUNC -DGET_CUSTOM_MAC_ENABLE -DWAPI            \
+	-DWL_CFG80211 -DWLP2P -DPNO_SUPPORT                                  \
 	-DNEW_COMPAT_WIRELESS -DWIFI_ACT_FRAME -DARP_OFFLOAD_SUPPORT          \
-	-DKEEP_ALIVE -DCSCAN -DGET_CUSTOM_MAC_ENABLE -DPKT_FILTER_SUPPORT     \
-	-DEMBEDDED_PLATFORM -DENABLE_INSMOD_NO_FW_LOAD -DPNO_SUPPORT          \
+	-DKEEP_ALIVE -DCSCAN -DPKT_FILTER_SUPPORT     \
+	-DEMBEDDED_PLATFORM -DENABLE_INSMOD_NO_FW_LOAD         \
 	-Idrivers/net/wireless/bcmdhd -Idrivers/net/wireless/bcmdhd/include
 
+
+
 DHDOFILES = aiutils.o bcmsdh_sdmmc_linux.o dhd_linux.o siutils.o bcmutils.o   \
 	dhd_linux_sched.o bcmwifi.o dhd_sdio.o bcmevent.o dhd_bta.o hndpmu.o  \
 	bcmsdh.o dhd_cdc.o bcmsdh_linux.o dhd_common.o linux_osl.o            \
-	bcmsdh_sdmmc.o dhd_custom_gpio.o sbutils.o wldev_common.o wl_android.o
+	bcmsdh_sdmmc.o dhd_custom_gpio.o sbutils.o wldev_common.o wl_android.o\
+	wldev_common.o wl_cfg80211.o  dhd_cfg80211.o wl_cfgp2p.o wl_linux_mon.o
+
 
 obj-$(CONFIG_BCMDHD) += bcmdhd.o
 bcmdhd-objs += $(DHDOFILES)
@@ -21,10 +28,6 @@
 bcmdhd-objs += wl_iw.o
 DHDCFLAGS += -DSOFTAP
 endif
-ifneq ($(CONFIG_CFG80211),)
-bcmdhd-objs += wl_cfg80211.o wl_cfgp2p.o dhd_linux_mon.o
-DHDCFLAGS += -DWL_CFG80211
-endif
 EXTRA_CFLAGS = $(DHDCFLAGS)
 ifeq ($(CONFIG_BCMDHD),m)
 EXTRA_LDFLAGS += --strip-debug
diff --git a/drivers/net/wireless/bcmdhd/aiutils.c b/drivers/net/wireless/bcmdhd/aiutils.c
index 059df89..a53bed2 100644
--- a/drivers/net/wireless/bcmdhd/aiutils.c
+++ b/drivers/net/wireless/bcmdhd/aiutils.c
@@ -3,13 +3,13 @@
  * of the SiliconBackplane-based Broadcom chips.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: aiutils.c,v 1.26.2.1 2010-03-09 18:41:21 Exp $
+ * $Id: aiutils.c 275693 2011-08-04 19:59:34Z $
  */
 
 
@@ -85,7 +85,7 @@
 	if (((asd & ER_TAG1) != ER_ADD) ||
 	    (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
 	    ((asd & AD_ST_MASK) != st)) {
-		
+
 		(*eromptr)--;
 		return 0;
 	}
@@ -131,10 +131,10 @@
 		break;
 
 	case PCI_BUS:
-		
+
 		sii->curwrap = (void *)((uintptr)regs + SI_CORE_SIZE);
 
-		
+
 		OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase);
 		eromptr = regs;
 		break;
@@ -163,7 +163,7 @@
 
 		br = FALSE;
 
-		
+
 		cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
 		if (cia == (ER_END | ER_VALID)) {
 			SI_VMSG(("Found END of erom after %d cores\n", sii->numcores));
@@ -193,7 +193,7 @@
 		if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
 			continue;
 		if ((nmw + nsw == 0)) {
-			
+
 			if (cid == OOB_ROUTER_CORE_ID) {
 				asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
 					&addrl, &addrh, &sizel, &sizeh);
@@ -221,10 +221,10 @@
 			         (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT));
 		}
 
-		
+
 		asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh);
 		if (asd == 0) {
-			
+
 			asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh,
 			              &sizel, &sizeh);
 			if (asd != 0)
@@ -238,7 +238,7 @@
 		}
 		sii->coresba[idx] = addrl;
 		sii->coresba_size[idx] = sizel;
-		
+
 		j = 1;
 		do {
 			asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh,
@@ -250,7 +250,7 @@
 			j++;
 		} while (asd != 0);
 
-		
+
 		for (i = 1; i < nsp; i++) {
 			j = 0;
 			do {
@@ -263,7 +263,7 @@
 			}
 		}
 
-		
+
 		for (i = 0; i < nmw; i++) {
 			asd = get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl, &addrh,
 			              &sizel, &sizeh);
@@ -279,7 +279,7 @@
 				sii->wrapba[idx] = addrl;
 		}
 
-		
+
 		for (i = 0; i < nsw; i++) {
 			uint fwp = (nsp == 1) ? 0 : 1;
 			asd = get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP, &addrl, &addrh,
@@ -296,11 +296,11 @@
 				sii->wrapba[idx] = addrl;
 		}
 
-		
+
 		if (br)
 			continue;
 
-		
+
 		sii->numcores++;
 	}
 
@@ -323,12 +323,12 @@
 	if (coreidx >= sii->numcores)
 		return (NULL);
 
-	
+
 	ASSERT((sii->intrsenabled_fn == NULL) || !(*(sii)->intrsenabled_fn)((sii)->intr_arg));
 
 	switch (BUSTYPE(sih->bustype)) {
 	case SI_BUS:
-		
+
 		if (!sii->regs[coreidx]) {
 			sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE);
 			ASSERT(GOODREGS(sii->regs[coreidx]));
@@ -499,9 +499,9 @@
 		return 0;
 
 	if (BUSTYPE(sih->bustype) == SI_BUS) {
-		
+
 		fast = TRUE;
-		
+
 		if (!sii->regs[coreidx]) {
 			sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx],
 			                            SI_CORE_SIZE);
@@ -509,15 +509,15 @@
 		}
 		r = (uint32 *)((uchar *)sii->regs[coreidx] + regoff);
 	} else if (BUSTYPE(sih->bustype) == PCI_BUS) {
-		
+
 
 		if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
-			
+
 
 			fast = TRUE;
 			r = (uint32 *)((char *)sii->curmap + PCI_16KB0_CCREGS_OFFSET + regoff);
 		} else if (sii->pub.buscoreidx == coreidx) {
-			
+
 			fast = TRUE;
 			if (SI_FAST(sii))
 				r = (uint32 *)((char *)sii->curmap +
@@ -533,25 +533,25 @@
 	if (!fast) {
 		INTR_OFF(sii, intr_val);
 
-		
+
 		origidx = si_coreidx(&sii->pub);
 
-		
+
 		r = (uint32*) ((uchar*) ai_setcoreidx(&sii->pub, coreidx) + regoff);
 	}
 	ASSERT(r != NULL);
 
-	
+
 	if (mask || val) {
 		w = (R_REG(sii->osh, r) & ~mask) | val;
 		W_REG(sii->osh, r, w);
 	}
 
-	
+
 	w = R_REG(sii->osh, r);
 
 	if (!fast) {
-		
+
 		if (origidx != coreidx)
 			ai_setcoreidx(&sii->pub, origidx);
 
@@ -573,7 +573,7 @@
 	ASSERT(GOODREGS(sii->curwrap));
 	ai = sii->curwrap;
 
-	
+
 	if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET)
 		return;
 
@@ -597,10 +597,10 @@
 	ASSERT(GOODREGS(sii->curwrap));
 	ai = sii->curwrap;
 
-	
+
 	ai_core_disable(sih, (bits | resetbits));
 
-	
+
 	W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
 	dummy = R_REG(sii->osh, &ai->ioctrl);
 	W_REG(sii->osh, &ai->resetctrl, 0);
diff --git a/drivers/net/wireless/bcmdhd/bcmevent.c b/drivers/net/wireless/bcmdhd/bcmevent.c
index 24581dd..d1c94fe 100644
--- a/drivers/net/wireless/bcmdhd/bcmevent.c
+++ b/drivers/net/wireless/bcmdhd/bcmevent.c
@@ -2,13 +2,13 @@
  * bcmevent read-only data shared by kernel or app layers
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,11 +16,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: bcmevent.c,v 1.8.2.7 2011-02-01 06:23:39 Exp $
+ * $Id: bcmevent.c 275693 2011-08-04 19:59:34Z $
  */
 
 #include <typedefs.h>
@@ -96,6 +96,10 @@
 	{ WLC_E_ACTION_FRAME_RX, "ACTION_FRAME_RX" },
 	{ WLC_E_ACTION_FRAME_COMPLETE, "ACTION_FRAME_COMPLETE" },
 #endif
+#ifdef WAPI
+	{ WLC_E_WAI_STA_EVENT, "WAI_STA_EVENT" },
+	{ WLC_E_WAI_MSG, "WAI_MSG" },
+#endif /* WAPI */
 	{ WLC_E_ESCAN_RESULT, "WLC_E_ESCAN_RESULT" },
 	{ WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE, "WLC_E_AF_OFF_CHAN_COMPLETE" },
 #ifdef WLP2P
diff --git a/drivers/net/wireless/bcmdhd/bcmsdh.c b/drivers/net/wireless/bcmdhd/bcmsdh.c
index 918c8e6..5766bf5 100644
--- a/drivers/net/wireless/bcmdhd/bcmsdh.c
+++ b/drivers/net/wireless/bcmdhd/bcmsdh.c
@@ -3,13 +3,13 @@
  *  implement bcmsdh API for SDIOH driver
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,7 +17,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -688,3 +688,39 @@
 	return BCME_UNSUPPORTED;
 #endif
 }
+
+int
+bcmsdh_gpio_init(void *sdh)
+{
+	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
+	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
+
+	return sdioh_gpio_init(sd);
+}
+
+bool
+bcmsdh_gpioin(void *sdh, uint32 gpio)
+{
+	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
+	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
+
+	return sdioh_gpioin(sd, gpio);
+}
+
+int
+bcmsdh_gpioouten(void *sdh, uint32 gpio)
+{
+	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
+	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
+
+	return sdioh_gpioouten(sd, gpio);
+}
+
+int
+bcmsdh_gpioout(void *sdh, uint32 gpio, bool enab)
+{
+	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
+	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
+
+	return sdioh_gpioout(sd, gpio, enab);
+}
diff --git a/drivers/net/wireless/bcmdhd/bcmsdh_linux.c b/drivers/net/wireless/bcmdhd/bcmsdh_linux.c
index 04c43a3..943f19a 100644
--- a/drivers/net/wireless/bcmdhd/bcmsdh_linux.c
+++ b/drivers/net/wireless/bcmdhd/bcmsdh_linux.c
@@ -2,13 +2,13 @@
  * SDIO access interface for drivers - linux specific (pci only)
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdh_linux.c,v 1.72.6.5 2010-12-23 01:13:15 Exp $
+ * $Id: bcmsdh_linux.c 290375 2011-10-18 09:28:42Z $
  */
 
 /**
@@ -147,17 +147,6 @@
 #endif /* BCMLXSDMMC */
 
 #ifndef BCMLXSDMMC
-static struct device_driver bcmsdh_driver = {
-	.name		= "pxa2xx-mci",
-	.bus		= &platform_bus_type,
-	.probe		= bcmsdh_probe,
-	.remove		= bcmsdh_remove,
-	.suspend	= NULL,
-	.resume		= NULL,
-	};
-#endif /* BCMLXSDMMC */
-
-#ifndef BCMLXSDMMC
 static
 #endif /* BCMLXSDMMC */
 int bcmsdh_probe(struct device *dev)
@@ -238,9 +227,9 @@
 	/* chain SDIO Host Controller info together */
 	sdhc->next = sdhcinfo;
 	sdhcinfo = sdhc;
+
 	/* Read the vendor/device ID from the CIS */
 	vendevid = bcmsdh_query_device(sdh);
-
 	/* try to attach to the target device */
 	if (!(sdhc->ch = drvinfo.attach((vendevid >> 16),
 	                                 (vendevid & 0xFFFF), 0, 0, 0, 0,
@@ -274,6 +263,7 @@
 	sdhc = sdhcinfo;
 	drvinfo.detach(sdhc->ch);
 	bcmsdh_detach(sdhc->osh, sdhc->sdh);
+
 	/* find the SDIO Host Controller state for this pdev and take it out from the list */
 	for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
 		if (sdhc->dev == (void *)dev) {
@@ -290,7 +280,6 @@
 		return 0;
 	}
 
-
 	/* release SDIO Host Controller info */
 	osh = sdhc->osh;
 	MFREE(osh, sdhc, sizeof(bcmsdh_hc_t));
@@ -523,6 +512,21 @@
 
 extern int sdio_function_init(void);
 
+extern int sdio_func_reg_notify(void* semaphore);
+extern void sdio_func_unreg_notify(void);
+
+#if defined(BCMLXSDMMC)
+int bcmsdh_reg_sdio_notify(void* semaphore)
+{
+	return sdio_func_reg_notify(semaphore);
+}
+
+void bcmsdh_unreg_sdio_notify(void)
+{
+	sdio_func_unreg_notify();
+}
+#endif /* defined(BCMLXSDMMC) */
+
 int
 bcmsdh_register(bcmsdh_driver_t *driver)
 {
@@ -531,13 +535,8 @@
 	drvinfo = *driver;
 
 #if defined(BCMPLATFORM_BUS)
-#if defined(BCMLXSDMMC)
 	SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
 	error = sdio_function_init();
-#else
-	SDLX_MSG(("Intel PXA270 SDIO Driver\n"));
-	error = driver_register(&bcmsdh_driver);
-#endif /* defined(BCMLXSDMMC) */
 	return error;
 #endif /* defined(BCMPLATFORM_BUS) */
 
@@ -565,14 +564,12 @@
 	if (bcmsdh_pci_driver.node.next)
 #endif
 
-#if defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC)
-		driver_unregister(&bcmsdh_driver);
-#endif
 #if defined(BCMLXSDMMC)
 	sdio_function_cleanup();
 #endif /* BCMLXSDMMC */
+
 #if !defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC)
-		pci_unregister_driver(&bcmsdh_pci_driver);
+	pci_unregister_driver(&bcmsdh_pci_driver);
 #endif /* BCMPLATFORM_BUS */
 }
 
@@ -611,13 +608,6 @@
 	return IRQ_HANDLED;
 }
 
-void *bcmsdh_get_drvdata(void)
-{
-	if (!sdhcinfo)
-		return NULL;
-	return dev_get_drvdata(sdhcinfo->dev);
-}
-
 int bcmsdh_register_oob_intr(void * dhdp)
 {
 	int error = 0;
@@ -671,6 +661,16 @@
 	}
 }
 #endif /* defined(OOB_INTR_ONLY) */
+
+#if defined(BCMLXSDMMC)
+void *bcmsdh_get_drvdata(void)
+{
+	if (!sdhcinfo)
+		return NULL;
+	return dev_get_drvdata(sdhcinfo->dev);
+}
+#endif
+
 /* Module parameters specific to each host-controller driver */
 
 extern uint sd_msglevel;	/* Debug message level */
@@ -694,6 +694,10 @@
 extern uint sd_f2_blocksize;
 module_param(sd_f2_blocksize, int, 0);
 
+#ifdef BCMSDIOH_STD
+extern int sd_uhsimode;
+module_param(sd_uhsimode, int, 0);
+#endif
 
 #ifdef BCMSDH_MODULE
 EXPORT_SYMBOL(bcmsdh_attach);
diff --git a/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc.c b/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc.c
index 70bacbd3..74d1668 100644
--- a/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc.c
+++ b/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc.c
@@ -2,13 +2,13 @@
  * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -35,6 +35,7 @@
 #include <sdiovar.h>	/* ioctl/iovars */
 
 #include <linux/mmc/core.h>
+#include <linux/mmc/card.h>
 #include <linux/mmc/sdio_func.h>
 #include <linux/mmc/sdio_ids.h>
 
@@ -148,6 +149,7 @@
 	sd->sd_blockmode = TRUE;
 	sd->use_client_ints = TRUE;
 	sd->client_block_size[0] = 64;
+	sd->use_rxchain = FALSE;
 
 	gInstance->sd = sd;
 
@@ -448,6 +450,7 @@
 		bcopy(params, &int_val, sizeof(int_val));
 
 	bool_val = (int_val != 0) ? TRUE : FALSE;
+	BCM_REFERENCE(bool_val);
 
 	actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
 	switch (actionid) {
@@ -511,7 +514,7 @@
 	}
 
 	case IOV_GVAL(IOV_RXCHAIN):
-		int_val = FALSE;
+		int_val = (int32)si->use_rxchain;
 		bcopy(&int_val, arg, val_size);
 		break;
 
@@ -678,15 +681,10 @@
 	uint8 data;
 
 	if (enable)
-		data = SDIO_SEPINT_MASK | SDIO_SEPINT_OE;	/* enable hw oob interrupt */
+		data = SDIO_SEPINT_MASK | SDIO_SEPINT_OE | SDIO_SEPINT_ACT_HI;
 	else
 		data = SDIO_SEPINT_ACT_HI;	/* disable hw oob interrupt */
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
-	/* Needed for Android Linux Kernel 2.6.35 */
-	data |= SDIO_SEPINT_ACT_HI; 		/* Active HIGH */
-#endif
-
 	status = sdioh_request_byte(sd, SDIOH_WRITE, 0, SDIOD_CCCR_BRCM_SEPINT, &data);
 	return status;
 }
@@ -901,8 +899,12 @@
 	bool fifo = (fix_inc == SDIOH_DATA_FIX);
 	uint32	SGCount = 0;
 	int err_ret = 0;
-
-	void *pnext;
+	void *pnext, *pprev;
+	uint ttl_len, dma_len, lft_len, xfred_len, pkt_len;
+	uint blk_num;
+	struct mmc_request mmc_req;
+	struct mmc_command mmc_cmd;
+	struct mmc_data mmc_dat;
 
 	sd_trace(("%s: Enter\n", __FUNCTION__));
 
@@ -910,66 +912,148 @@
 	DHD_PM_RESUME_WAIT(sdioh_request_packet_wait);
 	DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
 
-	/* Claim host controller */
-	sdio_claim_host(gInstance->func[func]);
-	for (pnext = pkt; pnext; pnext = PKTNEXT(sd->osh, pnext)) {
-		uint pkt_len = PKTLEN(sd->osh, pnext);
-		pkt_len += 3;
-		pkt_len &= 0xFFFFFFFC;
+	ttl_len = xfred_len = 0;
+	/* at least 4 bytes alignment of skb buff is guaranteed */
+	for (pnext = pkt; pnext; pnext = PKTNEXT(sd->osh, pnext))
+		ttl_len += PKTLEN(sd->osh, pnext);
 
-#ifdef CONFIG_MMC_MSM7X00A
-		if ((pkt_len % 64) == 32) {
-			sd_trace(("%s: Rounding up TX packet +=32\n", __FUNCTION__));
-			pkt_len += 32;
-		}
-#endif /* CONFIG_MMC_MSM7X00A */
-		/* Make sure the packet is aligned properly. If it isn't, then this
-		 * is the fault of sdioh_request_buffer() which is supposed to give
-		 * us something we can work with.
-		 */
-		ASSERT(((uint32)(PKTDATA(sd->osh, pkt)) & DMA_ALIGN_MASK) == 0);
+	if (!sd->use_rxchain || ttl_len <= sd->client_block_size[func]) {
+		blk_num = 0;
+		dma_len = 0;
+	} else {
+		blk_num = ttl_len / sd->client_block_size[func];
+		dma_len = blk_num * sd->client_block_size[func];
+	}
+	lft_len = ttl_len - dma_len;
 
-		if ((write) && (!fifo)) {
-			err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
-				((uint8*)PKTDATA(sd->osh, pnext)),
+	sd_trace(("%s: %s %dB to func%d:%08x, %d blks with DMA, %dB leftover\n",
+		__FUNCTION__, write ? "W" : "R",
+		ttl_len, func, addr, blk_num, lft_len));
+
+	if (0 != dma_len) {
+		memset(&mmc_req, 0, sizeof(struct mmc_request));
+		memset(&mmc_cmd, 0, sizeof(struct mmc_command));
+		memset(&mmc_dat, 0, sizeof(struct mmc_data));
+
+		/* Set up DMA descriptors */
+		pprev = pkt;
+		for (pnext = pkt;
+		     pnext && dma_len;
+		     pnext = PKTNEXT(sd->osh, pnext)) {
+			pkt_len = PKTLEN(sd->osh, pnext);
+
+			if (dma_len > pkt_len)
+				dma_len -= pkt_len;
+			else {
+				pkt_len = xfred_len = dma_len;
+				dma_len = 0;
+				pkt = pnext;
+			}
+
+			sg_set_buf(&sd->sg_list[SGCount++],
+				(uint8*)PKTDATA(sd->osh, pnext),
 				pkt_len);
-		} else if (write) {
-			err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
-				((uint8*)PKTDATA(sd->osh, pnext)),
-				pkt_len);
-		} else if (fifo) {
-			err_ret = sdio_readsb(gInstance->func[func],
-				((uint8*)PKTDATA(sd->osh, pnext)),
-				addr,
-				pkt_len);
-		} else {
-			err_ret = sdio_memcpy_fromio(gInstance->func[func],
-				((uint8*)PKTDATA(sd->osh, pnext)),
-				addr,
-				pkt_len);
+
+			if (SGCount >= SDIOH_SDMMC_MAX_SG_ENTRIES) {
+				sd_err(("%s: sg list entries exceed limit\n",
+					__FUNCTION__));
+				return (SDIOH_API_RC_FAIL);
+			}
 		}
 
-		if (err_ret) {
-			sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d, ERR=0x%08x\n",
-				__FUNCTION__,
-				(write) ? "TX" : "RX",
-				pnext, SGCount, addr, pkt_len, err_ret));
-		} else {
-			sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
-				__FUNCTION__,
-				(write) ? "TX" : "RX",
-				pnext, SGCount, addr, pkt_len));
-		}
+		mmc_dat.sg = sd->sg_list;
+		mmc_dat.sg_len = SGCount;
+		mmc_dat.blksz = sd->client_block_size[func];
+		mmc_dat.blocks = blk_num;
+		mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
 
-		if (!fifo) {
-			addr += pkt_len;
-		}
-		SGCount ++;
+		mmc_cmd.opcode = 53;		/* SD_IO_RW_EXTENDED */
+		mmc_cmd.arg = write ? 1<<31 : 0;
+		mmc_cmd.arg |= (func & 0x7) << 28;
+		mmc_cmd.arg |= 1<<27;
+		mmc_cmd.arg |= fifo ? 0 : 1<<26;
+		mmc_cmd.arg |= (addr & 0x1FFFF) << 9;
+		mmc_cmd.arg |= blk_num & 0x1FF;
+		mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
 
+		mmc_req.cmd = &mmc_cmd;
+		mmc_req.data = &mmc_dat;
+
+		sdio_claim_host(gInstance->func[func]);
+		mmc_set_data_timeout(&mmc_dat, gInstance->func[func]->card);
+		mmc_wait_for_req(gInstance->func[func]->card->host, &mmc_req);
+		sdio_release_host(gInstance->func[func]);
+
+		err_ret = mmc_cmd.error? mmc_cmd.error : mmc_dat.error;
+		if (0 != err_ret) {
+			sd_err(("%s:CMD53 %s failed with code %d\n",
+			       __FUNCTION__,
+			       write ? "write" : "read",
+			       err_ret));
+			sd_err(("%s:Disabling rxchain and fire it with PIO\n",
+			       __FUNCTION__));
+			sd->use_rxchain = FALSE;
+			pkt = pprev;
+			lft_len = ttl_len;
+		} else if (!fifo) {
+			addr = addr + ttl_len - lft_len - dma_len;
+		}
 	}
 
-	/* Release host controller */
-	sdio_release_host(gInstance->func[func]);
+	/* PIO mode */
+	if (0 != lft_len) {
+		/* Claim host controller */
+		sdio_claim_host(gInstance->func[func]);
+		for (pnext = pkt; pnext; pnext = PKTNEXT(sd->osh, pnext)) {
+			uint8 *buf = (uint8*)PKTDATA(sd->osh, pnext) +
+				xfred_len;
+			pkt_len = PKTLEN(sd->osh, pnext);
+			if (0 != xfred_len) {
+				pkt_len -= xfred_len;
+				xfred_len = 0;
+			}
+			pkt_len = (pkt_len + 3) & 0xFFFFFFFC;
+#ifdef CONFIG_MMC_MSM7X00A
+			if ((pkt_len % 64) == 32) {
+				sd_trace(("%s: Rounding up TX packet +=32\n", __FUNCTION__));
+				pkt_len += 32;
+			}
+#endif /* CONFIG_MMC_MSM7X00A */
+
+			if ((write) && (!fifo))
+				err_ret = sdio_memcpy_toio(
+						gInstance->func[func],
+						addr, buf, pkt_len);
+			else if (write)
+				err_ret = sdio_memcpy_toio(
+						gInstance->func[func],
+						addr, buf, pkt_len);
+			else if (fifo)
+				err_ret = sdio_readsb(
+						gInstance->func[func],
+						buf, addr, pkt_len);
+			else
+				err_ret = sdio_memcpy_fromio(
+						gInstance->func[func],
+						buf, addr, pkt_len);
+
+			if (err_ret)
+				sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d, ERR=%d\n",
+				       __FUNCTION__,
+				       (write) ? "TX" : "RX",
+				       pnext, SGCount, addr, pkt_len, err_ret));
+			else
+				sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
+					__FUNCTION__,
+					(write) ? "TX" : "RX",
+					pnext, SGCount, addr, pkt_len));
+
+			if (!fifo)
+				addr += pkt_len;
+			SGCount ++;
+		}
+		sdio_release_host(gInstance->func[func]);
+	}
 
 	sd_trace(("%s: Exit\n", __FUNCTION__));
 	return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
@@ -1002,11 +1086,11 @@
 	if (pkt == NULL) {
 		sd_data(("%s: Creating new %s Packet, len=%d\n",
 		         __FUNCTION__, write ? "TX" : "RX", buflen_u));
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 		if (!(mypkt = PKTGET_STATIC(sd->osh, buflen_u, write ? TRUE : FALSE))) {
 #else
 		if (!(mypkt = PKTGET(sd->osh, buflen_u, write ? TRUE : FALSE))) {
-#endif /* DHD_USE_STATIC_BUF */
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 			sd_err(("%s: PKTGET failed: len %d\n",
 			           __FUNCTION__, buflen_u));
 			return SDIOH_API_RC_FAIL;
@@ -1023,11 +1107,11 @@
 		if (!write) {
 			bcopy(PKTDATA(sd->osh, mypkt), buffer, buflen_u);
 		}
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 		PKTFREE_STATIC(sd->osh, mypkt, write ? TRUE : FALSE);
 #else
 		PKTFREE(sd->osh, mypkt, write ? TRUE : FALSE);
-#endif /* DHD_USE_STATIC_BUF */
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 	} else if (((uint32)(PKTDATA(sd->osh, pkt)) & DMA_ALIGN_MASK) != 0) {
 		/* Case 2: We have a packet, but it is unaligned. */
 
@@ -1036,11 +1120,11 @@
 
 		sd_data(("%s: Creating aligned %s Packet, len=%d\n",
 		         __FUNCTION__, write ? "TX" : "RX", PKTLEN(sd->osh, pkt)));
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 		if (!(mypkt = PKTGET_STATIC(sd->osh, PKTLEN(sd->osh, pkt), write ? TRUE : FALSE))) {
 #else
 		if (!(mypkt = PKTGET(sd->osh, PKTLEN(sd->osh, pkt), write ? TRUE : FALSE))) {
-#endif /* DHD_USE_STATIC_BUF */
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 			sd_err(("%s: PKTGET failed: len %d\n",
 			           __FUNCTION__, PKTLEN(sd->osh, pkt)));
 			return SDIOH_API_RC_FAIL;
@@ -1061,11 +1145,11 @@
 			      PKTDATA(sd->osh, pkt),
 			      PKTLEN(sd->osh, mypkt));
 		}
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 		PKTFREE_STATIC(sd->osh, mypkt, write ? TRUE : FALSE);
 #else
 		PKTFREE(sd->osh, mypkt, write ? TRUE : FALSE);
-#endif /* DHD_USE_STATIC_BUF */
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 	} else { /* case 3: We have a packet and it is aligned. */
 		sd_data(("%s: Aligned %s Packet, direct DMA\n",
 		         __FUNCTION__, write ? "Tx" : "Rx"));
@@ -1179,6 +1263,7 @@
 	sd = gInstance->sd;
 
 	ASSERT(sd != NULL);
+	BCM_REFERENCE(sd);
 }
 #endif /* !defined(OOB_INTR_ONLY) */
 
@@ -1230,8 +1315,10 @@
 		   2.6.27. The implementation prior to that is buggy, and needs broadcom's
 		   patch for it
 		*/
-		if ((ret = sdio_reset_comm(gInstance->func[0]->card)))
+		if ((ret = sdio_reset_comm(gInstance->func[0]->card))) {
 			sd_err(("%s Failed, error = %d\n", __FUNCTION__, ret));
+			return ret;
+		}
 		else {
 			sd->num_funcs = 2;
 			sd->sd_blockmode = TRUE;
@@ -1318,3 +1405,28 @@
 {
 	return (1);
 }
+
+
+SDIOH_API_RC
+sdioh_gpioouten(sdioh_info_t *sd, uint32 gpio)
+{
+	return SDIOH_API_RC_FAIL;
+}
+
+SDIOH_API_RC
+sdioh_gpioout(sdioh_info_t *sd, uint32 gpio, bool enab)
+{
+	return SDIOH_API_RC_FAIL;
+}
+
+bool
+sdioh_gpioin(sdioh_info_t *sd, uint32 gpio)
+{
+	return FALSE;
+}
+
+SDIOH_API_RC
+sdioh_gpio_init(sdioh_info_t *sd)
+{
+	return SDIOH_API_RC_FAIL;
+}
diff --git a/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.c b/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.c
index 726b639..09160c09 100644
--- a/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.c
+++ b/drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.c
@@ -2,13 +2,13 @@
  * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdh_sdmmc_linux.c,v 1.8.6.2 2011-02-01 18:38:36 Exp $
+ * $Id: bcmsdh_sdmmc_linux.c 292402 2011-10-27 00:03:30Z $
  */
 
 #include <typedefs.h>
@@ -31,11 +31,13 @@
 #include <sdiovar.h>	/* to get msglevel bit values */
 
 #include <linux/sched.h>	/* request_irq() */
+#include <linux/kernel.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/card.h>
 #include <linux/mmc/sdio_func.h>
 #include <linux/mmc/sdio_ids.h>
+#include <linux/mmc/host.h>
 
 #if !defined(SDIO_VENDOR_ID_BROADCOM)
 #define SDIO_VENDOR_ID_BROADCOM		0x02d0
@@ -55,13 +57,26 @@
 #if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
 #define SDIO_DEVICE_ID_BROADCOM_4319	0x4319
 #endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4319) */
+#if !defined(SDIO_DEVICE_ID_BROADCOM_4330)
+#define SDIO_DEVICE_ID_BROADCOM_4330	0x4330
+#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4330) */
+#if !defined(SDIO_DEVICE_ID_BROADCOM_4334)
+#define SDIO_DEVICE_ID_BROADCOM_4334    0x4334
+#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4334) */
+#if !defined(SDIO_DEVICE_ID_BROADCOM_4324)
+#define SDIO_DEVICE_ID_BROADCOM_4324    0x4324
+#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_4324) */
+#if !defined(SDIO_DEVICE_ID_BROADCOM_43239)
+#define SDIO_DEVICE_ID_BROADCOM_43239    43239
+#endif /* !defined(SDIO_DEVICE_ID_BROADCOM_43239) */
+
 
 #include <bcmsdh_sdmmc.h>
 
 #include <dhd_dbg.h>
 
 #ifdef WL_CFG80211
-extern void wl_cfg80211_set_sdio_func(void *func);
+extern void wl_cfg80211_set_parent_dev(void *dev);
 #endif
 
 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
@@ -89,7 +104,6 @@
 
 extern int bcmsdh_probe(struct device *dev);
 extern int bcmsdh_remove(struct device *dev);
-
 extern volatile bool dhd_mmc_suspend;
 
 static int bcmsdh_sdmmc_probe(struct sdio_func *func,
@@ -118,7 +132,7 @@
 
 	if (func->num == 2) {
 #ifdef WL_CFG80211
-		wl_cfg80211_set_sdio_func(func);
+		wl_cfg80211_set_parent_dev(&func->dev);
 #endif
 		sd_trace(("F2 found, calling bcmsdh_probe...\n"));
 		ret = bcmsdh_probe(&func->dev);
@@ -153,6 +167,10 @@
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325) },
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329) },
 	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319) },
+	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330) },
+	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334) },
+	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4324) },
+	{ SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_43239) },
 	{ SDIO_DEVICE_CLASS(SDIO_CLASS_NONE)		},
 	{ /* end: all zeroes */				},
 };
@@ -163,14 +181,23 @@
 static int bcmsdh_sdmmc_suspend(struct device *pdev)
 {
 	struct sdio_func *func = dev_to_sdio_func(pdev);
-
+	int err = 0;
+	
 	if (func->num != 2)
 		return 0;
+
+	sd_trace(("%s Enter\n", __FUNCTION__));
+	err = sdio_set_host_pm_flags(gInstance->func[1], MMC_PM_KEEP_POWER);
+	if(err) {
+		DHD_ERROR((KERN_ERR "%s:Failed to set pm_flags(err=%d)\n", __func__, err));
+		return err;
+	}
+
 	if (dhd_os_check_wakelock(bcmsdh_get_drvdata()))
 		return -EBUSY;
 #if defined(OOB_INTR_ONLY)
 	bcmsdh_oob_intr_set(0);
-#endif
+#endif	/* defined(OOB_INTR_ONLY) */
 	dhd_mmc_suspend = TRUE;
 	smp_mb();
 
@@ -179,15 +206,16 @@
 
 static int bcmsdh_sdmmc_resume(struct device *pdev)
 {
+#if defined(OOB_INTR_ONLY)
 	struct sdio_func *func = dev_to_sdio_func(pdev);
-
-	if (func->num != 2)
-		return 0;
+#endif
+	sd_trace(("%s Enter\n", __FUNCTION__));
 	dhd_mmc_suspend = FALSE;
 #if defined(OOB_INTR_ONLY)
-	if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
+	if ((func->num == 2) && dhd_os_check_if_up(bcmsdh_get_drvdata()))
 		bcmsdh_oob_intr_set(1);
-#endif
+#endif /* (OOB_INTR_ONLY) */
+
 	smp_mb();
 	return 0;
 }
@@ -196,7 +224,42 @@
 	.suspend	= bcmsdh_sdmmc_suspend,
 	.resume		= bcmsdh_sdmmc_resume,
 };
-#endif
+#endif  /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
+
+#if defined(BCMLXSDMMC)
+static struct semaphore *notify_semaphore = NULL;
+
+static int dummy_probe(struct sdio_func *func,
+                              const struct sdio_device_id *id)
+{
+	if (notify_semaphore)
+		up(notify_semaphore);
+	return 0;
+}
+
+static void dummy_remove(struct sdio_func *func)
+{
+}
+
+static struct sdio_driver dummy_sdmmc_driver = {
+	.probe		= dummy_probe,
+	.remove		= dummy_remove,
+	.name		= "dummy_sdmmc",
+	.id_table	= bcmsdh_sdmmc_ids,
+	};
+
+int sdio_func_reg_notify(void* semaphore)
+{
+	notify_semaphore = semaphore;
+	return sdio_register_driver(&dummy_sdmmc_driver);
+}
+
+void sdio_func_unreg_notify(void)
+{
+	sdio_unregister_driver(&dummy_sdmmc_driver);
+}
+
+#endif /* defined(BCMLXSDMMC) */
 
 static struct sdio_driver bcmsdh_sdmmc_driver = {
 	.probe		= bcmsdh_sdmmc_probe,
@@ -205,10 +268,10 @@
 	.id_table	= bcmsdh_sdmmc_ids,
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM)
 	.drv = {
-		.pm	= &bcmsdh_sdmmc_pm_ops,
+	.pm	= &bcmsdh_sdmmc_pm_ops,
 	},
-#endif
-};
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM) */
+	};
 
 struct sdos_info {
 	sdioh_info_t *sd;
diff --git a/drivers/net/wireless/bcmdhd/bcmutils.c b/drivers/net/wireless/bcmdhd/bcmutils.c
index fbdd7cd..007009c 100644
--- a/drivers/net/wireless/bcmdhd/bcmutils.c
+++ b/drivers/net/wireless/bcmdhd/bcmutils.c
@@ -2,13 +2,13 @@
  * Driver O/S-independent utility routines
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,11 +16,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: bcmutils.c,v 1.277.2.18 2011-01-26 02:32:08 Exp $
+ * $Id: bcmutils.c 275693 2011-08-04 19:59:34Z $
  */
 
 #include <typedefs.h>
@@ -919,7 +919,7 @@
 	for (p = p0; p; p = PKTNEXT(osh, p))
 		prhex(NULL, PKTDATA(osh, p), PKTLEN(osh, p));
 }
-#endif  
+#endif
 
 /* Takes an Ethernet frame and sets out-of-bound PKTPRIO.
  * Also updates the inplace vlan tag if requested.
@@ -1523,7 +1523,7 @@
 
 	return (int)(p - buf);
 }
-#endif 
+#endif
 
 #if defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || defined(WLMSG_ASSOC) || \
 	defined(DHD_DEBUG) || defined(WLMEDIA_PEAKRATE)
@@ -1541,7 +1541,7 @@
 	}
 	return (int)(p - str);
 }
-#endif 
+#endif
 
 /* pretty hex print a contiguous buffer */
 void
@@ -1592,6 +1592,9 @@
 	"UNDEF",
 	"UNDEF",
 	"UNDEF",
+#ifdef WAPI
+	"WAPI",
+#endif /* WAPI */
 	"UNDEF"
 };
 
@@ -1907,7 +1910,7 @@
 
 	return (int)(p - buf);
 }
-#endif 
+#endif
 
 #endif /* BCMDRIVER */
 
diff --git a/drivers/net/wireless/bcmdhd/bcmwifi.c b/drivers/net/wireless/bcmdhd/bcmwifi.c
index 7072217..2955e27 100644
--- a/drivers/net/wireless/bcmdhd/bcmwifi.c
+++ b/drivers/net/wireless/bcmdhd/bcmwifi.c
@@ -4,13 +4,13 @@
  * software that might want wifi things as it grows.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -18,11 +18,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: bcmwifi.c,v 1.31.8.1 2010-08-03 17:47:05 Exp $
+ * $Id: bcmwifi.c 275693 2011-08-04 19:59:34Z $
  */
 
 
@@ -40,11 +40,11 @@
 #ifndef ASSERT
 #define ASSERT(exp)
 #endif
-#endif 
+#endif
 #include <bcmwifi.h>
 
 #if defined(WIN32) && (defined(BCMDLL) || defined(WLMDLL))
-#include <bcmstdlib.h> 	
+#include <bcmstdlib.h>
 #endif
 
 
@@ -61,7 +61,7 @@
 	bw = "";
 	sb = "";
 	channel = CHSPEC_CHANNEL(chspec);
-	
+
 	if ((CHSPEC_IS2G(chspec) && channel > CH_MAX_2G_CHANNEL) ||
 	    (CHSPEC_IS5G(chspec) && channel <= CH_MAX_2G_CHANNEL))
 		band = (CHSPEC_IS2G(chspec)) ? "b" : "a";
@@ -77,7 +77,7 @@
 		bw = "n";
 	}
 
-	
+
 	snprintf(buf, 6, "%d%s%s%s", channel, band, bw, sb);
 	return (buf);
 }
@@ -92,7 +92,7 @@
 
 	channel = strtoul(a, &endp, 10);
 
-	
+
 	if (endp == a)
 		return 0;
 
@@ -109,7 +109,7 @@
 	if (c == '\0')
 		goto done;
 
-	
+
 	if (c == 'a' || c == 'b') {
 		band = (c == 'a') ? WL_CHANSPEC_BAND_5G : WL_CHANSPEC_BAND_2G;
 		a++;
@@ -118,13 +118,13 @@
 			goto done;
 	}
 
-	
+
 	if (c == 'n') {
 		bw = WL_CHANSPEC_BW_10;
 	} else if (c == 'l') {
 		bw = WL_CHANSPEC_BW_40;
 		ctl_sb = WL_CHANSPEC_CTL_SB_LOWER;
-		
+
 		if (channel <= (MAXCHANNEL - CH_20MHZ_APART))
 			channel += CH_10MHZ_APART;
 		else
@@ -132,7 +132,7 @@
 	} else if (c == 'u') {
 		bw = WL_CHANSPEC_BW_40;
 		ctl_sb = WL_CHANSPEC_CTL_SB_UPPER;
-		
+
 		if (channel > CH_20MHZ_APART)
 			channel -= CH_10MHZ_APART;
 		else
@@ -149,14 +149,14 @@
 bool
 wf_chspec_malformed(chanspec_t chanspec)
 {
-	
+
 	if (!CHSPEC_IS5G(chanspec) && !CHSPEC_IS2G(chanspec))
 		return TRUE;
-	
+
 	if (!CHSPEC_IS40(chanspec) && !CHSPEC_IS20(chanspec))
 		return TRUE;
 
-	
+
 	if (CHSPEC_IS20_UNCOND(chanspec)) {
 		if (!CHSPEC_SB_NONE(chanspec))
 			return TRUE;
@@ -174,19 +174,19 @@
 {
 	uint8 ctl_chan;
 
-	
+
 	if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_NONE) {
 		return CHSPEC_CHANNEL(chspec);
 	} else {
-		
+
 		ASSERT(CHSPEC_BW(chspec) == WL_CHANSPEC_BW_40);
-		
+
 		if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_UPPER) {
-			
+
 			ctl_chan = UPPER_20_SB(CHSPEC_CHANNEL(chspec));
 		} else {
 			ASSERT(CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_LOWER);
-			
+
 			ctl_chan = LOWER_20_SB(CHSPEC_CHANNEL(chspec));
 		}
 	}
@@ -202,7 +202,7 @@
 
 	ASSERT(!wf_chspec_malformed(chspec));
 
-	
+
 	if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_NONE) {
 		return chspec;
 	} else {
@@ -225,7 +225,7 @@
 	uint base;
 	int offset;
 
-	
+
 	if (start_factor == 0) {
 		if (freq >= 2400 && freq <= 2500)
 			start_factor = WF_CHAN_FACTOR_2_4_G;
@@ -238,18 +238,18 @@
 
 	base = start_factor / 2;
 
-	
+
 	if ((freq < base) || (freq > base + 1000))
 		return -1;
 
 	offset = freq - base;
 	ch = offset / 5;
 
-	
+
 	if (offset != (ch * 5))
 		return -1;
 
-	
+
 	if (start_factor == WF_CHAN_FACTOR_2_4_G && (ch < 1 || ch > 13))
 		return -1;
 
diff --git a/drivers/net/wireless/bcmdhd/dhd.h b/drivers/net/wireless/bcmdhd/dhd.h
index c87f6cf..178f80f 100644
--- a/drivers/net/wireless/bcmdhd/dhd.h
+++ b/drivers/net/wireless/bcmdhd/dhd.h
@@ -5,13 +5,13 @@
  * DHD OS, bus, and protocol modules.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd.h 290844 2011-10-20 08:54:39Z $
+ * $Id: dhd.h 292298 2011-10-26 20:02:21Z $
  */
 
 /****************
@@ -34,9 +34,6 @@
 #ifndef _dhd_h_
 #define _dhd_h_
 
-#if defined(CHROMIUMOS_COMPAT_WIRELESS)
-#include <linux/sched.h>
-#endif
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -74,6 +71,7 @@
 	DHD_BUS_DATA		/* Ready for frame transfers */
 };
 
+
 /* Firmware requested operation mode */
 #define STA_MASK			0x0001
 #define HOSTAPD_MASK			0x0002
@@ -83,6 +81,9 @@
 /* max sequential rxcntl timeouts to set HANG event */
 #define MAX_CNTL_TIMEOUT  2
 
+#define DHD_SCAN_ACTIVE_TIME	 40 /* ms : Embedded default Active setting from DHD Driver */
+#define DHD_SCAN_PASSIVE_TIME	130 /* ms: Embedded default Passive setting from DHD Driver */
+
 enum dhd_bus_wake_state {
 	WAKE_LOCK_OFF,
 	WAKE_LOCK_PRIV,
@@ -116,7 +117,7 @@
 } dhd_if_state_t;
 
 
-#if defined(DHD_USE_STATIC_BUF)
+#if defined(CONFIG_DHD_USE_STATIC_BUF)
 
 uint8* dhd_os_prealloc(void *osh, int section, uint size);
 void dhd_os_prefree(void *osh, void *addr, uint size);
@@ -128,7 +129,7 @@
 #define DHD_OS_PREALLOC(osh, section, size) MALLOC(osh, size)
 #define DHD_OS_PREFREE(osh, addr, size) MFREE(osh, addr, size)
 
-#endif /* defined(DHD_USE_STATIC_BUF) */
+#endif /* defined(CONFIG_DHD_USE_STATIC_BUF) */
 
 /* Packet alignment for most efficient SDIO (can change based on platform) */
 #ifndef DHD_SDALIGN
@@ -205,10 +206,10 @@
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_HAS_WAKELOCK)
 	struct wake_lock 	wakelock[WAKE_LOCK_MAX];
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined (CONFIG_HAS_WAKELOCK) */
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 	struct mutex 	wl_start_stop_lock; /* lock/unlock for Android start/stop */
 	struct mutex 	wl_softap_lock;		 /* lock/unlock for any SoftAP/STA settings */
-#endif 
+#endif
 
 	uint16	maxdatablks;
 #ifdef PROP_TXSTATUS
@@ -290,21 +291,21 @@
 
 inline static void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 	mutex_init(&dhdp->wl_softap_lock);
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
 }
 
 inline static void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 	mutex_lock(&dhdp->wl_softap_lock);
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
 }
 
 inline static void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 	mutex_unlock(&dhdp->wl_softap_lock);
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
 }
@@ -365,6 +366,11 @@
  * bus_hdrlen specifies required headroom for bus module header.
  */
 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
+#if defined(WLP2P) && defined(WL_CFG80211)
+/* To allow attach/detach calls corresponding to p2p0 interface  */
+extern int dhd_attach_p2p(dhd_pub_t *);
+extern int dhd_detach_p2p(dhd_pub_t *);
+#endif /* WLP2P && WL_CFG80211 */
 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
 
 /* Indication from bus module regarding removal/absence of dongle */
@@ -407,10 +413,14 @@
 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
-extern int dhd_custom_get_mac_address(unsigned char *buf);
+extern int  dhd_custom_get_mac_address(unsigned char *buf);
+extern int  dhd_ether_aton(const char *orig, size_t len, unsigned char *eth);
 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
+extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
+
+#ifdef PNO_SUPPORT
 extern int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled);
 extern int dhd_pno_clean(dhd_pub_t *dhd);
 extern int dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t* ssids_local, int nssid,
@@ -421,9 +431,7 @@
                            int nssid, ushort  scan_fr, int pno_repeat, int pno_freq_expo_max);
 extern int dhd_dev_pno_enable(struct net_device *dev,  int pfn_enabled);
 extern int dhd_dev_get_pno_status(struct net_device *dev);
-extern int dhd_get_dtim_skip(dhd_pub_t *dhd);
-extern bool dhd_check_ap_wfd_mode_set(dhd_pub_t *dhd);
-extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
+#endif /* PNO_SUPPORT */
 
 #define DHD_UNICAST_FILTER_NUM		0
 #define DHD_BROADCAST_FILTER_NUM	1
@@ -432,6 +440,10 @@
 extern int net_os_set_packet_filter(struct net_device *dev, int val);
 extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
 
+extern int dhd_get_dtim_skip(dhd_pub_t *dhd);
+extern bool dhd_check_ap_wfd_mode_set(dhd_pub_t *dhd);
+
+
 #ifdef DHD_DEBUG
 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
 #endif /* DHD_DEBUG */
@@ -453,7 +465,7 @@
 
 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
 extern int dhd_net2idx(struct dhd_info *dhd, struct net_device *net);
-extern struct net_device * dhd_idx2net(struct dhd_pub *dhd_pub, int ifidx);
+extern struct net_device * dhd_idx2net(void *pub, int ifidx);
 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata,
                          wl_event_msg_t *, void **data_ptr);
 extern void wl_event_to_host_order(wl_event_msg_t * evt);
@@ -730,4 +742,15 @@
 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr);
 #endif /* ARP_OFFLOAD_SUPPORT */
 
+#ifdef DHD_BCM_WIFI_HDMI
+/* Wireless HDMI run-time enable flag */
+extern bool dhd_bcm_whdmi_enable;
+
+/* Network interface created for the Wireless HDMI soft AP */
+#define DHD_WHDMI_SOFTAP_IF_NAME	"wl0.2"
+#define DHD_WHDMI_SOFTAP_IF_NAME_LEN	5
+#define DHD_WHDMI_SOFTAP_IF_NUM		2
+
+#endif /* DHD_BCM_WIFI_HDMI */
+
 #endif /* _dhd_h_ */
diff --git a/drivers/net/wireless/bcmdhd/dhd_bta.c b/drivers/net/wireless/bcmdhd/dhd_bta.c
index 6b782ea..409f621 100644
--- a/drivers/net/wireless/bcmdhd/dhd_bta.c
+++ b/drivers/net/wireless/bcmdhd/dhd_bta.c
@@ -1,335 +1,335 @@
-/*
- * BT-AMP support routines
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: dhd_bta.c,v 1.10.4.2 2010-12-22 23:47:23 Exp $
- */
-
-#include <typedefs.h>
-#include <osl.h>
-#include <bcmcdc.h>
-#include <bcmutils.h>
-#include <bcmendian.h>
-#include <proto/802.11.h>
-#include <proto/802.11_bta.h>
-#include <proto/bt_amp_hci.h>
-#include <dngl_stats.h>
-#include <dhd.h>
-#include <dhd_bus.h>
-#include <dhd_proto.h>
-#include <dhdioctl.h>
-#include <dhd_dbg.h>
-
-#include <dhd_bta.h>
-
-
-#ifdef SEND_HCI_CMD_VIA_IOCTL
-#define BTA_HCI_CMD_MAX_LEN HCI_CMD_PREAMBLE_SIZE + HCI_CMD_DATA_SIZE
-
-/* Send HCI cmd via wl iovar HCI_cmd to the dongle. */
-int
-dhd_bta_docmd(dhd_pub_t *pub, void *cmd_buf, uint cmd_len)
-{
-	amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)cmd_buf;
-	uint8 buf[BTA_HCI_CMD_MAX_LEN + 16];
-	uint len = sizeof(buf);
-	wl_ioctl_t ioc;
-
-	if (cmd_len < HCI_CMD_PREAMBLE_SIZE)
-		return BCME_BADLEN;
-
-	if ((uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE > cmd_len)
-		return BCME_BADLEN;
-
-	len = bcm_mkiovar("HCI_cmd",
-		(char *)cmd, (uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE, (char *)buf, len);
-
-
-	memset(&ioc, 0, sizeof(ioc));
-
-	ioc.cmd = WLC_SET_VAR;
-	ioc.buf = buf;
-	ioc.len = len;
-	ioc.set = TRUE;
-
-	return dhd_wl_ioctl(pub, &ioc, ioc.buf, ioc.len);
-}
-#else /* !SEND_HCI_CMD_VIA_IOCTL */
-
-static void
-dhd_bta_flush_hcidata(dhd_pub_t *pub, uint16 llh)
-{
-	int prec;
-	struct pktq *q;
-	uint count = 0;
-
-	q = dhd_bus_txq(pub->bus);
-	if (q == NULL)
-		return;
-
-	DHD_BTA(("dhd: flushing HCI ACL data for logical link %u...\n", llh));
-
-	dhd_os_sdlock_txq(pub);
-
-	/* Walk through the txq and toss all HCI ACL data packets */
-	PKTQ_PREC_ITER(q, prec) {
-		void *head_pkt = NULL;
-
-		while (pktq_ppeek(q, prec) != head_pkt) {
-			void *pkt = pktq_pdeq(q, prec);
-			int ifidx;
-
-			PKTPULL(pub->osh, pkt, dhd_bus_hdrlen(pub->bus));
-			dhd_prot_hdrpull(pub, &ifidx, pkt);
-
-			if (PKTLEN(pub->osh, pkt) >= RFC1042_HDR_LEN) {
-				struct ether_header *eh =
-				        (struct ether_header *)PKTDATA(pub->osh, pkt);
-
-				if (ntoh16(eh->ether_type) < ETHER_TYPE_MIN) {
-					struct dot11_llc_snap_header *lsh =
-					        (struct dot11_llc_snap_header *)&eh[1];
-
-					if (bcmp(lsh, BT_SIG_SNAP_MPROT,
-					         DOT11_LLC_SNAP_HDR_LEN - 2) == 0 &&
-					    ntoh16(lsh->type) == BTA_PROT_L2CAP) {
-						amp_hci_ACL_data_t *ACL_data =
-						        (amp_hci_ACL_data_t *)&lsh[1];
-						uint16 handle = ltoh16(ACL_data->handle);
-
-						if (HCI_ACL_DATA_HANDLE(handle) == llh) {
-							PKTFREE(pub->osh, pkt, TRUE);
-							count ++;
-							continue;
-						}
-					}
-				}
-			}
-
-			dhd_prot_hdrpush(pub, ifidx, pkt);
-			PKTPUSH(pub->osh, pkt, dhd_bus_hdrlen(pub->bus));
-
-			if (head_pkt == NULL)
-				head_pkt = pkt;
-			pktq_penq(q, prec, pkt);
-		}
-	}
-
-	dhd_os_sdunlock_txq(pub);
-
-	DHD_BTA(("dhd: flushed %u packet(s) for logical link %u...\n", count, llh));
-}
-
-/* Handle HCI cmd locally.
- * Return 0: continue to send the cmd across SDIO
- *        < 0: stop, fail
- *        > 0: stop, succuess
- */
-static int
-_dhd_bta_docmd(dhd_pub_t *pub, amp_hci_cmd_t *cmd)
-{
-	int status = 0;
-
-	switch (ltoh16_ua((uint8 *)&cmd->opcode)) {
-	case HCI_Enhanced_Flush: {
-		eflush_cmd_parms_t *cmdparms = (eflush_cmd_parms_t *)cmd->parms;
-		dhd_bta_flush_hcidata(pub, ltoh16_ua(cmdparms->llh));
-		break;
-	}
-	default:
-		break;
-	}
-
-	return status;
-}
-
-/* Send HCI cmd encapsulated in BT-SIG frame via data channel to the dongle. */
-int
-dhd_bta_docmd(dhd_pub_t *pub, void *cmd_buf, uint cmd_len)
-{
-	amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)cmd_buf;
-	struct ether_header *eh;
-	struct dot11_llc_snap_header *lsh;
-	osl_t *osh = pub->osh;
-	uint len;
-	void *p;
-	int status;
-
-	if (cmd_len < HCI_CMD_PREAMBLE_SIZE) {
-		DHD_ERROR(("dhd_bta_docmd: short command, cmd_len %u\n", cmd_len));
-		return BCME_BADLEN;
-	}
-
-	if ((len = (uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE) > cmd_len) {
-		DHD_ERROR(("dhd_bta_docmd: malformed command, len %u cmd_len %u\n",
-		           len, cmd_len));
-		/* return BCME_BADLEN; */
-	}
-
-	p = PKTGET(osh, pub->hdrlen + RFC1042_HDR_LEN + len, TRUE);
-	if (p == NULL) {
-		DHD_ERROR(("dhd_bta_docmd: out of memory\n"));
-		return BCME_NOMEM;
-	}
-
-
-	/* intercept and handle the HCI cmd locally */
-	if ((status = _dhd_bta_docmd(pub, cmd)) > 0)
-		return 0;
-	else if (status < 0)
-		return status;
-
-	/* copy in HCI cmd */
-	PKTPULL(osh, p, pub->hdrlen + RFC1042_HDR_LEN);
-	bcopy(cmd, PKTDATA(osh, p), len);
-
-	/* copy in partial Ethernet header with BT-SIG LLC/SNAP header */
-	PKTPUSH(osh, p, RFC1042_HDR_LEN);
-	eh = (struct ether_header *)PKTDATA(osh, p);
-	bzero(eh->ether_dhost, ETHER_ADDR_LEN);
-	ETHER_SET_LOCALADDR(eh->ether_dhost);
-	bcopy(&pub->mac, eh->ether_shost, ETHER_ADDR_LEN);
-	eh->ether_type = hton16(len + DOT11_LLC_SNAP_HDR_LEN);
-	lsh = (struct dot11_llc_snap_header *)&eh[1];
-	bcopy(BT_SIG_SNAP_MPROT, lsh, DOT11_LLC_SNAP_HDR_LEN - 2);
-	lsh->type = 0;
-
-	return dhd_sendpkt(pub, 0, p);
-}
-#endif /* !SEND_HCI_CMD_VIA_IOCTL */
-
-/* Send HCI ACL data to dongle via data channel */
-int
-dhd_bta_tx_hcidata(dhd_pub_t *pub, void *data_buf, uint data_len)
-{
-	amp_hci_ACL_data_t *data = (amp_hci_ACL_data_t *)data_buf;
-	struct ether_header *eh;
-	struct dot11_llc_snap_header *lsh;
-	osl_t *osh = pub->osh;
-	uint len;
-	void *p;
-
-	if (data_len < HCI_ACL_DATA_PREAMBLE_SIZE) {
-		DHD_ERROR(("dhd_bta_tx_hcidata: short data_buf, data_len %u\n", data_len));
-		return BCME_BADLEN;
-	}
-
-	if ((len = (uint)ltoh16(data->dlen) + HCI_ACL_DATA_PREAMBLE_SIZE) > data_len) {
-		DHD_ERROR(("dhd_bta_tx_hcidata: malformed hci data, len %u data_len %u\n",
-		           len, data_len));
-		/* return BCME_BADLEN; */
-	}
-
-	p = PKTGET(osh, pub->hdrlen + RFC1042_HDR_LEN + len, TRUE);
-	if (p == NULL) {
-		DHD_ERROR(("dhd_bta_tx_hcidata: out of memory\n"));
-		return BCME_NOMEM;
-	}
-
-
-	/* copy in HCI ACL data header and HCI ACL data */
-	PKTPULL(osh, p, pub->hdrlen + RFC1042_HDR_LEN);
-	bcopy(data, PKTDATA(osh, p), len);
-
-	/* copy in partial Ethernet header with BT-SIG LLC/SNAP header */
-	PKTPUSH(osh, p, RFC1042_HDR_LEN);
-	eh = (struct ether_header *)PKTDATA(osh, p);
-	bzero(eh->ether_dhost, ETHER_ADDR_LEN);
-	bcopy(&pub->mac, eh->ether_shost, ETHER_ADDR_LEN);
-	eh->ether_type = hton16(len + DOT11_LLC_SNAP_HDR_LEN);
-	lsh = (struct dot11_llc_snap_header *)&eh[1];
-	bcopy(BT_SIG_SNAP_MPROT, lsh, DOT11_LLC_SNAP_HDR_LEN - 2);
-	lsh->type = HTON16(BTA_PROT_L2CAP);
-
-	return dhd_sendpkt(pub, 0, p);
-}
-
-/* txcomplete callback */
-void
-dhd_bta_tx_hcidata_complete(dhd_pub_t *dhdp, void *txp, bool success)
-{
-	uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, txp);
-	amp_hci_ACL_data_t *ACL_data = (amp_hci_ACL_data_t *)(pktdata + RFC1042_HDR_LEN);
-	uint16 handle = ltoh16(ACL_data->handle);
-	uint16 llh = HCI_ACL_DATA_HANDLE(handle);
-
-	wl_event_msg_t event;
-	uint8 data[HCI_EVT_PREAMBLE_SIZE + sizeof(num_completed_data_blocks_evt_parms_t)];
-	amp_hci_event_t *evt;
-	num_completed_data_blocks_evt_parms_t *parms;
-
-	uint16 len = HCI_EVT_PREAMBLE_SIZE + sizeof(num_completed_data_blocks_evt_parms_t);
-
-	/* update the event struct */
-	memset(&event, 0, sizeof(event));
-	event.version = hton16(BCM_EVENT_MSG_VERSION);
-	event.event_type = hton32(WLC_E_BTA_HCI_EVENT);
-	event.status = 0;
-	event.reason = 0;
-	event.auth_type = 0;
-	event.datalen = hton32(len);
-	event.flags = 0;
-
-	/* generate Number of Completed Blocks event */
-	evt = (amp_hci_event_t *)data;
-	evt->ecode = HCI_Number_of_Completed_Data_Blocks;
-	evt->plen = sizeof(num_completed_data_blocks_evt_parms_t);
-
-	parms = (num_completed_data_blocks_evt_parms_t *)evt->parms;
-	htol16_ua_store(dhdp->maxdatablks, (uint8 *)&parms->num_blocks);
-	parms->num_handles = 1;
-	htol16_ua_store(llh, (uint8 *)&parms->completed[0].handle);
-	parms->completed[0].pkts = 1;
-	parms->completed[0].blocks = 1;
-
-	dhd_sendup_event_common(dhdp, &event, data);
-}
-
-/* event callback */
-void
-dhd_bta_doevt(dhd_pub_t *dhdp, void *data_buf, uint data_len)
-{
-	amp_hci_event_t *evt = (amp_hci_event_t *)data_buf;
-
-	switch (evt->ecode) {
-	case HCI_Command_Complete: {
-		cmd_complete_parms_t *parms = (cmd_complete_parms_t *)evt->parms;
-		switch (ltoh16_ua((uint8 *)&parms->opcode)) {
-		case HCI_Read_Data_Block_Size: {
-			read_data_block_size_evt_parms_t *parms2 =
-			        (read_data_block_size_evt_parms_t *)parms->parms;
-			dhdp->maxdatablks = ltoh16_ua((uint8 *)&parms2->data_block_num);
-			break;
-		}
-		}
-		break;
-	}
-
-	case HCI_Flush_Occurred: {
-		flush_occurred_evt_parms_t *evt_parms = (flush_occurred_evt_parms_t *)evt->parms;
-		dhd_bta_flush_hcidata(dhdp, ltoh16_ua((uint8 *)&evt_parms->handle));
-		break;
-	}
-	default:
-		break;
-	}
-}
+/*

+ * BT-AMP support routines

+ *

+ * Copyright (C) 1999-2011, Broadcom Corporation

+ *

+ *         Unless you and Broadcom execute a separate written software license

+ * agreement governing use of this software, this software is licensed to you

+ * under the terms of the GNU General Public License version 2 (the "GPL"),

+ * available at http://www.broadcom.com/licenses/GPLv2.php, with the

+ * following added to such license:

+ *

+ *      As a special exception, the copyright holders of this software give you

+ * permission to link this software with independent modules, and to copy and

+ * distribute the resulting executable under terms of your choice, provided that

+ * you also meet, for each linked independent module, the terms and conditions of

+ * the license of that module.  An independent module is a module which is not

+ * derived from this software.  The special exception does not apply to any

+ * modifications of the software.

+ *

+ *      Notwithstanding the above, under no circumstances may you combine this

+ * software in any way with any other Broadcom software provided under a license

+ * other than the GPL, without Broadcom's express prior written consent.

+ *

+ * $Id: dhd_bta.c 285377 2011-09-21 17:57:59Z $

+ */

+

+#include <typedefs.h>

+#include <osl.h>

+#include <bcmcdc.h>

+#include <bcmutils.h>

+#include <bcmendian.h>

+#include <proto/802.11.h>

+#include <proto/802.11_bta.h>

+#include <proto/bt_amp_hci.h>

+#include <dngl_stats.h>

+#include <dhd.h>

+#include <dhd_bus.h>

+#include <dhd_proto.h>

+#include <dhdioctl.h>

+#include <dhd_dbg.h>

+

+#include <dhd_bta.h>

+

+

+#ifdef SEND_HCI_CMD_VIA_IOCTL

+#define BTA_HCI_CMD_MAX_LEN HCI_CMD_PREAMBLE_SIZE + HCI_CMD_DATA_SIZE

+

+/* Send HCI cmd via wl iovar HCI_cmd to the dongle. */

+int

+dhd_bta_docmd(dhd_pub_t *pub, void *cmd_buf, uint cmd_len)

+{

+	amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)cmd_buf;

+	uint8 buf[BTA_HCI_CMD_MAX_LEN + 16];

+	uint len = sizeof(buf);

+	wl_ioctl_t ioc;

+

+	if (cmd_len < HCI_CMD_PREAMBLE_SIZE)

+		return BCME_BADLEN;

+

+	if ((uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE > cmd_len)

+		return BCME_BADLEN;

+

+	len = bcm_mkiovar("HCI_cmd",

+		(char *)cmd, (uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE, (char *)buf, len);

+

+

+	memset(&ioc, 0, sizeof(ioc));

+

+	ioc.cmd = WLC_SET_VAR;

+	ioc.buf = buf;

+	ioc.len = len;

+	ioc.set = TRUE;

+

+	return dhd_wl_ioctl(pub, &ioc, ioc.buf, ioc.len);

+}

+#else /* !SEND_HCI_CMD_VIA_IOCTL */

+

+static void

+dhd_bta_flush_hcidata(dhd_pub_t *pub, uint16 llh)

+{

+	int prec;

+	struct pktq *q;

+	uint count = 0;

+

+	q = dhd_bus_txq(pub->bus);

+	if (q == NULL)

+		return;

+

+	DHD_BTA(("dhd: flushing HCI ACL data for logical link %u...\n", llh));

+

+	dhd_os_sdlock_txq(pub);

+

+	/* Walk through the txq and toss all HCI ACL data packets */

+	PKTQ_PREC_ITER(q, prec) {

+		void *head_pkt = NULL;

+

+		while (pktq_ppeek(q, prec) != head_pkt) {

+			void *pkt = pktq_pdeq(q, prec);

+			int ifidx;

+

+			PKTPULL(pub->osh, pkt, dhd_bus_hdrlen(pub->bus));

+			dhd_prot_hdrpull(pub, &ifidx, pkt);

+

+			if (PKTLEN(pub->osh, pkt) >= RFC1042_HDR_LEN) {

+				struct ether_header *eh =

+				        (struct ether_header *)PKTDATA(pub->osh, pkt);

+

+				if (ntoh16(eh->ether_type) < ETHER_TYPE_MIN) {

+					struct dot11_llc_snap_header *lsh =

+					        (struct dot11_llc_snap_header *)&eh[1];

+

+					if (bcmp(lsh, BT_SIG_SNAP_MPROT,

+					         DOT11_LLC_SNAP_HDR_LEN - 2) == 0 &&

+					    ntoh16(lsh->type) == BTA_PROT_L2CAP) {

+						amp_hci_ACL_data_t *ACL_data =

+						        (amp_hci_ACL_data_t *)&lsh[1];

+						uint16 handle = ltoh16(ACL_data->handle);

+

+						if (HCI_ACL_DATA_HANDLE(handle) == llh) {

+							PKTFREE(pub->osh, pkt, TRUE);

+							count ++;

+							continue;

+						}

+					}

+				}

+			}

+

+			dhd_prot_hdrpush(pub, ifidx, pkt);

+			PKTPUSH(pub->osh, pkt, dhd_bus_hdrlen(pub->bus));

+

+			if (head_pkt == NULL)

+				head_pkt = pkt;

+			pktq_penq(q, prec, pkt);

+		}

+	}

+

+	dhd_os_sdunlock_txq(pub);

+

+	DHD_BTA(("dhd: flushed %u packet(s) for logical link %u...\n", count, llh));

+}

+

+/* Handle HCI cmd locally.

+ * Return 0: continue to send the cmd across SDIO

+ *        < 0: stop, fail

+ *        > 0: stop, succuess

+ */

+static int

+_dhd_bta_docmd(dhd_pub_t *pub, amp_hci_cmd_t *cmd)

+{

+	int status = 0;

+

+	switch (ltoh16_ua((uint8 *)&cmd->opcode)) {

+	case HCI_Enhanced_Flush: {

+		eflush_cmd_parms_t *cmdparms = (eflush_cmd_parms_t *)cmd->parms;

+		dhd_bta_flush_hcidata(pub, ltoh16_ua(cmdparms->llh));

+		break;

+	}

+	default:

+		break;

+	}

+

+	return status;

+}

+

+/* Send HCI cmd encapsulated in BT-SIG frame via data channel to the dongle. */

+int

+dhd_bta_docmd(dhd_pub_t *pub, void *cmd_buf, uint cmd_len)

+{

+	amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)cmd_buf;

+	struct ether_header *eh;

+	struct dot11_llc_snap_header *lsh;

+	osl_t *osh = pub->osh;

+	uint len;

+	void *p;

+	int status;

+

+	if (cmd_len < HCI_CMD_PREAMBLE_SIZE) {

+		DHD_ERROR(("dhd_bta_docmd: short command, cmd_len %u\n", cmd_len));

+		return BCME_BADLEN;

+	}

+

+	if ((len = (uint)cmd->plen + HCI_CMD_PREAMBLE_SIZE) > cmd_len) {

+		DHD_ERROR(("dhd_bta_docmd: malformed command, len %u cmd_len %u\n",

+		           len, cmd_len));

+		/* return BCME_BADLEN; */

+	}

+

+	p = PKTGET(osh, pub->hdrlen + RFC1042_HDR_LEN + len, TRUE);

+	if (p == NULL) {

+		DHD_ERROR(("dhd_bta_docmd: out of memory\n"));

+		return BCME_NOMEM;

+	}

+

+

+	/* intercept and handle the HCI cmd locally */

+	if ((status = _dhd_bta_docmd(pub, cmd)) > 0)

+		return 0;

+	else if (status < 0)

+		return status;

+

+	/* copy in HCI cmd */

+	PKTPULL(osh, p, pub->hdrlen + RFC1042_HDR_LEN);

+	bcopy(cmd, PKTDATA(osh, p), len);

+

+	/* copy in partial Ethernet header with BT-SIG LLC/SNAP header */

+	PKTPUSH(osh, p, RFC1042_HDR_LEN);

+	eh = (struct ether_header *)PKTDATA(osh, p);

+	bzero(eh->ether_dhost, ETHER_ADDR_LEN);

+	ETHER_SET_LOCALADDR(eh->ether_dhost);

+	bcopy(&pub->mac, eh->ether_shost, ETHER_ADDR_LEN);

+	eh->ether_type = hton16(len + DOT11_LLC_SNAP_HDR_LEN);

+	lsh = (struct dot11_llc_snap_header *)&eh[1];

+	bcopy(BT_SIG_SNAP_MPROT, lsh, DOT11_LLC_SNAP_HDR_LEN - 2);

+	lsh->type = 0;

+

+	return dhd_sendpkt(pub, 0, p);

+}

+#endif /* !SEND_HCI_CMD_VIA_IOCTL */

+

+/* Send HCI ACL data to dongle via data channel */

+int

+dhd_bta_tx_hcidata(dhd_pub_t *pub, void *data_buf, uint data_len)

+{

+	amp_hci_ACL_data_t *data = (amp_hci_ACL_data_t *)data_buf;

+	struct ether_header *eh;

+	struct dot11_llc_snap_header *lsh;

+	osl_t *osh = pub->osh;

+	uint len;

+	void *p;

+

+	if (data_len < HCI_ACL_DATA_PREAMBLE_SIZE) {

+		DHD_ERROR(("dhd_bta_tx_hcidata: short data_buf, data_len %u\n", data_len));

+		return BCME_BADLEN;

+	}

+

+	if ((len = (uint)ltoh16(data->dlen) + HCI_ACL_DATA_PREAMBLE_SIZE) > data_len) {

+		DHD_ERROR(("dhd_bta_tx_hcidata: malformed hci data, len %u data_len %u\n",

+		           len, data_len));

+		/* return BCME_BADLEN; */

+	}

+

+	p = PKTGET(osh, pub->hdrlen + RFC1042_HDR_LEN + len, TRUE);

+	if (p == NULL) {

+		DHD_ERROR(("dhd_bta_tx_hcidata: out of memory\n"));

+		return BCME_NOMEM;

+	}

+

+

+	/* copy in HCI ACL data header and HCI ACL data */

+	PKTPULL(osh, p, pub->hdrlen + RFC1042_HDR_LEN);

+	bcopy(data, PKTDATA(osh, p), len);

+

+	/* copy in partial Ethernet header with BT-SIG LLC/SNAP header */

+	PKTPUSH(osh, p, RFC1042_HDR_LEN);

+	eh = (struct ether_header *)PKTDATA(osh, p);

+	bzero(eh->ether_dhost, ETHER_ADDR_LEN);

+	bcopy(&pub->mac, eh->ether_shost, ETHER_ADDR_LEN);

+	eh->ether_type = hton16(len + DOT11_LLC_SNAP_HDR_LEN);

+	lsh = (struct dot11_llc_snap_header *)&eh[1];

+	bcopy(BT_SIG_SNAP_MPROT, lsh, DOT11_LLC_SNAP_HDR_LEN - 2);

+	lsh->type = HTON16(BTA_PROT_L2CAP);

+

+	return dhd_sendpkt(pub, 0, p);

+}

+

+/* txcomplete callback */

+void

+dhd_bta_tx_hcidata_complete(dhd_pub_t *dhdp, void *txp, bool success)

+{

+	uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, txp);

+	amp_hci_ACL_data_t *ACL_data = (amp_hci_ACL_data_t *)(pktdata + RFC1042_HDR_LEN);

+	uint16 handle = ltoh16(ACL_data->handle);

+	uint16 llh = HCI_ACL_DATA_HANDLE(handle);

+

+	wl_event_msg_t event;

+	uint8 data[HCI_EVT_PREAMBLE_SIZE + sizeof(num_completed_data_blocks_evt_parms_t)];

+	amp_hci_event_t *evt;

+	num_completed_data_blocks_evt_parms_t *parms;

+

+	uint16 len = HCI_EVT_PREAMBLE_SIZE + sizeof(num_completed_data_blocks_evt_parms_t);

+

+	/* update the event struct */

+	memset(&event, 0, sizeof(event));

+	event.version = hton16(BCM_EVENT_MSG_VERSION);

+	event.event_type = hton32(WLC_E_BTA_HCI_EVENT);

+	event.status = 0;

+	event.reason = 0;

+	event.auth_type = 0;

+	event.datalen = hton32(len);

+	event.flags = 0;

+

+	/* generate Number of Completed Blocks event */

+	evt = (amp_hci_event_t *)data;

+	evt->ecode = HCI_Number_of_Completed_Data_Blocks;

+	evt->plen = sizeof(num_completed_data_blocks_evt_parms_t);

+

+	parms = (num_completed_data_blocks_evt_parms_t *)evt->parms;

+	htol16_ua_store(dhdp->maxdatablks, (uint8 *)&parms->num_blocks);

+	parms->num_handles = 1;

+	htol16_ua_store(llh, (uint8 *)&parms->completed[0].handle);

+	parms->completed[0].pkts = 1;

+	parms->completed[0].blocks = 1;

+

+	dhd_sendup_event_common(dhdp, &event, data);

+}

+

+/* event callback */

+void

+dhd_bta_doevt(dhd_pub_t *dhdp, void *data_buf, uint data_len)

+{

+	amp_hci_event_t *evt = (amp_hci_event_t *)data_buf;

+

+	switch (evt->ecode) {

+	case HCI_Command_Complete: {

+		cmd_complete_parms_t *parms = (cmd_complete_parms_t *)evt->parms;

+		switch (ltoh16_ua((uint8 *)&parms->opcode)) {

+		case HCI_Read_Data_Block_Size: {

+			read_data_block_size_evt_parms_t *parms2 =

+			        (read_data_block_size_evt_parms_t *)parms->parms;

+			dhdp->maxdatablks = ltoh16_ua((uint8 *)&parms2->data_block_num);

+			break;

+		}

+		}

+		break;

+	}

+

+	case HCI_Flush_Occurred: {

+		flush_occurred_evt_parms_t *evt_parms = (flush_occurred_evt_parms_t *)evt->parms;

+		dhd_bta_flush_hcidata(dhdp, ltoh16_ua((uint8 *)&evt_parms->handle));

+		break;

+	}

+	default:

+		break;

+	}

+}

diff --git a/drivers/net/wireless/bcmdhd/dhd_bta.h b/drivers/net/wireless/bcmdhd/dhd_bta.h
index 07d9ceb..eb5e7d8d 100644
--- a/drivers/net/wireless/bcmdhd/dhd_bta.h
+++ b/drivers/net/wireless/bcmdhd/dhd_bta.h
@@ -1,39 +1,39 @@
-/*
- * BT-AMP support routines
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: dhd_bta.h,v 1.2 2009-02-26 22:35:56 Exp $
- */
-#ifndef __dhd_bta_h__
-#define __dhd_bta_h__
-
-struct dhd_pub;
-
-extern int dhd_bta_docmd(struct dhd_pub *pub, void *cmd_buf, uint cmd_len);
-
-extern void dhd_bta_doevt(struct dhd_pub *pub, void *data_buf, uint data_len);
-
-extern int dhd_bta_tx_hcidata(struct dhd_pub *pub, void *data_buf, uint data_len);
-extern void dhd_bta_tx_hcidata_complete(struct dhd_pub *dhdp, void *txp, bool success);
-
-
-#endif /* __dhd_bta_h__ */
+/*

+ * BT-AMP support routines

+ *

+ * Copyright (C) 1999-2011, Broadcom Corporation

+ *

+ *         Unless you and Broadcom execute a separate written software license

+ * agreement governing use of this software, this software is licensed to you

+ * under the terms of the GNU General Public License version 2 (the "GPL"),

+ * available at http://www.broadcom.com/licenses/GPLv2.php, with the

+ * following added to such license:

+ *

+ *      As a special exception, the copyright holders of this software give you

+ * permission to link this software with independent modules, and to copy and

+ * distribute the resulting executable under terms of your choice, provided that

+ * you also meet, for each linked independent module, the terms and conditions of

+ * the license of that module.  An independent module is a module which is not

+ * derived from this software.  The special exception does not apply to any

+ * modifications of the software.

+ *

+ *      Notwithstanding the above, under no circumstances may you combine this

+ * software in any way with any other Broadcom software provided under a license

+ * other than the GPL, without Broadcom's express prior written consent.

+ *

+ * $Id: dhd_bta.h 275786 2011-08-04 22:42:42Z $

+ */

+#ifndef __dhd_bta_h__

+#define __dhd_bta_h__

+

+struct dhd_pub;

+

+extern int dhd_bta_docmd(struct dhd_pub *pub, void *cmd_buf, uint cmd_len);

+

+extern void dhd_bta_doevt(struct dhd_pub *pub, void *data_buf, uint data_len);

+

+extern int dhd_bta_tx_hcidata(struct dhd_pub *pub, void *data_buf, uint data_len);

+extern void dhd_bta_tx_hcidata_complete(struct dhd_pub *dhdp, void *txp, bool success);

+

+

+#endif /* __dhd_bta_h__ */

diff --git a/drivers/net/wireless/bcmdhd/dhd_bus.h b/drivers/net/wireless/bcmdhd/dhd_bus.h
index bccb8b6..42a5a3b 100644
--- a/drivers/net/wireless/bcmdhd/dhd_bus.h
+++ b/drivers/net/wireless/bcmdhd/dhd_bus.h
@@ -5,13 +5,13 @@
  * DHD OS, bus, and protocol modules.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_bus.h,v 1.14.28.1 2010-12-23 01:13:17 Exp $
+ * $Id: dhd_bus.h 285377 2011-09-21 17:57:59Z $
  */
 
 #ifndef _dhd_bus_h_
@@ -51,8 +51,9 @@
 /* Get the Bus Idle Time */
 extern void dhd_bus_getidletime(dhd_pub_t *dhdp, int *idletime);
 
-/* Set the Bus Idle Time*/
+/* Set the Bus Idle Time */
 extern void dhd_bus_setidletime(dhd_pub_t *dhdp, int idle_time);
+
 /* Send a data frame to the dongle.  Callee disposes of txp. */
 extern int dhd_bus_txdata(struct dhd_bus *bus, void *txp);
 
diff --git a/drivers/net/wireless/bcmdhd/dhd_cdc.c b/drivers/net/wireless/bcmdhd/dhd_cdc.c
index 3a4de96..607f7dc 100644
--- a/drivers/net/wireless/bcmdhd/dhd_cdc.c
+++ b/drivers/net/wireless/bcmdhd/dhd_cdc.c
@@ -2,13 +2,13 @@
  * DHD Protocol Module for CDC and BDC.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_cdc.c,v 1.51.6.31 2011-02-09 14:31:43 Exp $
+ * $Id: dhd_cdc.c 288105 2011-10-06 01:58:02Z $
  *
  * BDC is like CDC, except it includes a header for data packets to convey
  * packet priority over the bus, and flags (e.g. to indicate checksum status
@@ -2460,10 +2460,10 @@
 	return 0;
 
 fail:
-#ifndef DHD_USE_STATIC_BUF
+#ifndef CONFIG_DHD_USE_STATIC_BUF
 	if (cdc != NULL)
 		MFREE(dhd->osh, cdc, sizeof(dhd_prot_t));
-#endif
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 	return BCME_NOMEM;
 }
 
@@ -2474,9 +2474,9 @@
 #ifdef PROP_TXSTATUS
 	dhd_wlfc_deinit(dhd);
 #endif
-#ifndef DHD_USE_STATIC_BUF
+#ifndef CONFIG_DHD_USE_STATIC_BUF
 	MFREE(dhd->osh, dhd->prot, sizeof(dhd_prot_t));
-#endif
+#endif /* CONFIG_DHD_USE_STATIC_BUF */
 	dhd->prot = NULL;
 }
 
@@ -2512,9 +2512,10 @@
 	ret = dhd_wlfc_init(dhd);
 #endif
 
-#if !defined(WL_CFG80211)
-	ret = dhd_preinit_ioctls(dhd);
-#endif /* WL_CFG80211 */
+#if defined(WL_CFG80211)
+	if (dhd_download_fw_on_driverload)
+#endif /* defined(WL_CFG80211) */
+		ret = dhd_preinit_ioctls(dhd);
 
 	/* Always assumes wl for now */
 	dhd->iswl = TRUE;
diff --git a/drivers/net/wireless/bcmdhd/dhd_cfg80211.c b/drivers/net/wireless/bcmdhd/dhd_cfg80211.c
new file mode 100644
index 0000000..f9cf75c
--- /dev/null
+++ b/drivers/net/wireless/bcmdhd/dhd_cfg80211.c
@@ -0,0 +1,594 @@
+/*
+ * Linux cfg80211 driver - Dongle Host Driver (DHD) related
+ *
+ * Copyright (C) 1999-2011, Broadcom Corporation
+ *
+ *         Unless you and Broadcom execute a separate written software license
+ * agreement governing use of this software, this software is licensed to you
+ * under the terms of the GNU General Public License version 2 (the "GPL"),
+ * available at http://www.broadcom.com/licenses/GPLv2.php, with the
+ * following added to such license:
+ *
+ *      As a special exception, the copyright holders of this software give you
+ * permission to link this software with independent modules, and to copy and
+ * distribute the resulting executable under terms of your choice, provided that
+ * you also meet, for each linked independent module, the terms and conditions of
+ * the license of that module.  An independent module is a module which is not
+ * derived from this software.  The special exception does not apply to any
+ * modifications of the software.
+ *
+ *      Notwithstanding the above, under no circumstances may you combine this
+ * software in any way with any other Broadcom software provided under a license
+ * other than the GPL, without Broadcom's express prior written consent.
+ *
+ * $Id: wl_cfg80211.c,v 1.1.4.1.2.14 2011/02/09 01:40:07 Exp $
+ */
+
+#include <net/rtnetlink.h>
+
+#include <bcmutils.h>
+#include <wldev_common.h>
+#include <wl_cfg80211.h>
+#include <dhd_cfg80211.h>
+
+extern struct wl_priv *wlcfg_drv_priv;
+static int dhd_dongle_up = FALSE;
+
+static s32 wl_dongle_up(struct net_device *ndev, u32 up);
+/**
+ * Function implementations
+ */
+
+s32 dhd_cfg80211_init(struct wl_priv *wl)
+{
+	dhd_dongle_up = FALSE;
+	return 0;
+}
+
+s32 dhd_cfg80211_deinit(struct wl_priv *wl)
+{
+	dhd_dongle_up = FALSE;
+	return 0;
+}
+
+s32 dhd_cfg80211_down(struct wl_priv *wl)
+{
+	dhd_dongle_up = FALSE;
+	return 0;
+}
+
+static s32 wl_dongle_up(struct net_device *ndev, u32 up)
+{
+	s32 err = 0;
+
+	err = wldev_ioctl(ndev, WLC_UP, &up, sizeof(up), true);
+	if (unlikely(err)) {
+		WL_ERR(("WLC_UP error (%d)\n", err));
+	}
+	return err;
+}
+
+s32 dhd_config_dongle(struct wl_priv *wl, bool need_lock)
+{
+#ifndef DHD_SDALIGN
+#define DHD_SDALIGN	32
+#endif
+	struct net_device *ndev;
+	s32 err = 0;
+
+	WL_TRACE(("In\n"));
+	if (dhd_dongle_up) {
+		WL_ERR(("Dongle is already up\n"));
+		return err;
+	}
+
+	ndev = wl_to_prmry_ndev(wl);
+
+	if (need_lock)
+		rtnl_lock();
+
+	err = wl_dongle_up(ndev, 0);
+	if (unlikely(err)) {
+		WL_ERR(("wl_dongle_up failed\n"));
+		goto default_conf_out;
+	}
+	dhd_dongle_up = true;
+
+default_conf_out:
+	if (need_lock)
+		rtnl_unlock();
+	return err;
+
+}
+
+
+/* TODO: clean up the BT-Coex code, it still have some legacy ioctl/iovar functions */
+#define COEX_DHCP
+
+#if defined(COEX_DHCP)
+
+/* use New SCO/eSCO smart YG suppression */
+#define BT_DHCP_eSCO_FIX
+/* this flag boost wifi pkt priority to max, caution: -not fair to sco */
+#define BT_DHCP_USE_FLAGS
+/* T1 start SCO/ESCo priority suppression */
+#define BT_DHCP_OPPR_WIN_TIME	2500
+/* T2 turn off SCO/SCO supperesion is (timeout) */
+#define BT_DHCP_FLAG_FORCE_TIME 5500
+
+enum wl_cfg80211_btcoex_status {
+	BT_DHCP_IDLE,
+	BT_DHCP_START,
+	BT_DHCP_OPPR_WIN,
+	BT_DHCP_FLAG_FORCE_TIMEOUT
+};
+
+/*
+ * get named driver variable to uint register value and return error indication
+ * calling example: dev_wlc_intvar_get_reg(dev, "btc_params",66, &reg_value)
+ */
+static int
+dev_wlc_intvar_get_reg(struct net_device *dev, char *name,
+	uint reg, int *retval)
+{
+	union {
+		char buf[WLC_IOCTL_SMLEN];
+		int val;
+	} var;
+	int error;
+
+	bcm_mkiovar(name, (char *)(&reg), sizeof(reg),
+		(char *)(&var), sizeof(var.buf));
+	error = wldev_ioctl(dev, WLC_GET_VAR, (char *)(&var), sizeof(var.buf), false);
+
+	*retval = dtoh32(var.val);
+	return (error);
+}
+
+static int
+dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
+	char ioctlbuf_local[1024];
+#else
+	static char ioctlbuf_local[1024];
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
+
+	bcm_mkiovar(name, buf, len, ioctlbuf_local, sizeof(ioctlbuf_local));
+
+	return (wldev_ioctl(dev, WLC_SET_VAR, ioctlbuf_local, sizeof(ioctlbuf_local), true));
+}
+/*
+get named driver variable to uint register value and return error indication
+calling example: dev_wlc_intvar_set_reg(dev, "btc_params",66, value)
+*/
+static int
+dev_wlc_intvar_set_reg(struct net_device *dev, char *name, char *addr, char * val)
+{
+	char reg_addr[8];
+
+	memset(reg_addr, 0, sizeof(reg_addr));
+	memcpy((char *)&reg_addr[0], (char *)addr, 4);
+	memcpy((char *)&reg_addr[4], (char *)val, 4);
+
+	return (dev_wlc_bufvar_set(dev, name, (char *)&reg_addr[0], sizeof(reg_addr)));
+}
+
+static bool btcoex_is_sco_active(struct net_device *dev)
+{
+	int ioc_res = 0;
+	bool res = FALSE;
+	int sco_id_cnt = 0;
+	int param27;
+	int i;
+
+	for (i = 0; i < 12; i++) {
+
+		ioc_res = dev_wlc_intvar_get_reg(dev, "btc_params", 27, &param27);
+
+		WL_TRACE(("%s, sample[%d], btc params: 27:%x\n",
+			__FUNCTION__, i, param27));
+
+		if (ioc_res < 0) {
+			WL_ERR(("%s ioc read btc params error\n", __FUNCTION__));
+			break;
+		}
+
+		if ((param27 & 0x6) == 2) { /* count both sco & esco  */
+			sco_id_cnt++;
+		}
+
+		if (sco_id_cnt > 2) {
+			WL_TRACE(("%s, sco/esco detected, pkt id_cnt:%d  samples:%d\n",
+				__FUNCTION__, sco_id_cnt, i));
+			res = TRUE;
+			break;
+		}
+
+		msleep(5);
+	}
+
+	return res;
+}
+
+#if defined(BT_DHCP_eSCO_FIX)
+/* Enhanced BT COEX settings for eSCO compatibility during DHCP window */
+static int set_btc_esco_params(struct net_device *dev, bool trump_sco)
+{
+	static bool saved_status = FALSE;
+
+	char buf_reg50va_dhcp_on[8] =
+		{ 50, 00, 00, 00, 0x22, 0x80, 0x00, 0x00 };
+	char buf_reg51va_dhcp_on[8] =
+		{ 51, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
+	char buf_reg64va_dhcp_on[8] =
+		{ 64, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
+	char buf_reg65va_dhcp_on[8] =
+		{ 65, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
+	char buf_reg71va_dhcp_on[8] =
+		{ 71, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
+	uint32 regaddr;
+	static uint32 saved_reg50;
+	static uint32 saved_reg51;
+	static uint32 saved_reg64;
+	static uint32 saved_reg65;
+	static uint32 saved_reg71;
+
+	if (trump_sco) {
+		/* this should reduce eSCO agressive retransmit
+		 * w/o breaking it
+		 */
+
+		/* 1st save current */
+		WL_TRACE(("Do new SCO/eSCO coex algo {save &"
+			  "override}\n"));
+		if ((!dev_wlc_intvar_get_reg(dev, "btc_params", 50, &saved_reg50)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 51, &saved_reg51)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 64, &saved_reg64)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 65, &saved_reg65)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 71, &saved_reg71))) {
+			saved_status = TRUE;
+			WL_TRACE(("%s saved bt_params[50,51,64,65,71]:"
+				  "0x%x 0x%x 0x%x 0x%x 0x%x\n",
+				  __FUNCTION__, saved_reg50, saved_reg51,
+				  saved_reg64, saved_reg65, saved_reg71));
+		} else {
+			WL_ERR((":%s: save btc_params failed\n",
+				__FUNCTION__));
+			saved_status = FALSE;
+			return -1;
+		}
+
+		WL_TRACE(("override with [50,51,64,65,71]:"
+			  "0x%x 0x%x 0x%x 0x%x 0x%x\n",
+			  *(u32 *)(buf_reg50va_dhcp_on+4),
+			  *(u32 *)(buf_reg51va_dhcp_on+4),
+			  *(u32 *)(buf_reg64va_dhcp_on+4),
+			  *(u32 *)(buf_reg65va_dhcp_on+4),
+			  *(u32 *)(buf_reg71va_dhcp_on+4)));
+
+		dev_wlc_bufvar_set(dev, "btc_params",
+			(char *)&buf_reg50va_dhcp_on[0], 8);
+		dev_wlc_bufvar_set(dev, "btc_params",
+			(char *)&buf_reg51va_dhcp_on[0], 8);
+		dev_wlc_bufvar_set(dev, "btc_params",
+			(char *)&buf_reg64va_dhcp_on[0], 8);
+		dev_wlc_bufvar_set(dev, "btc_params",
+			(char *)&buf_reg65va_dhcp_on[0], 8);
+		dev_wlc_bufvar_set(dev, "btc_params",
+			(char *)&buf_reg71va_dhcp_on[0], 8);
+
+		saved_status = TRUE;
+	} else if (saved_status) {
+		/* restore previously saved bt params */
+		WL_TRACE(("Do new SCO/eSCO coex algo {save &"
+			  "override}\n"));
+
+		regaddr = 50;
+		dev_wlc_intvar_set_reg(dev, "btc_params",
+			(char *)&regaddr, (char *)&saved_reg50);
+		regaddr = 51;
+		dev_wlc_intvar_set_reg(dev, "btc_params",
+			(char *)&regaddr, (char *)&saved_reg51);
+		regaddr = 64;
+		dev_wlc_intvar_set_reg(dev, "btc_params",
+			(char *)&regaddr, (char *)&saved_reg64);
+		regaddr = 65;
+		dev_wlc_intvar_set_reg(dev, "btc_params",
+			(char *)&regaddr, (char *)&saved_reg65);
+		regaddr = 71;
+		dev_wlc_intvar_set_reg(dev, "btc_params",
+			(char *)&regaddr, (char *)&saved_reg71);
+
+		WL_TRACE(("restore bt_params[50,51,64,65,71]:"
+			"0x%x 0x%x 0x%x 0x%x 0x%x\n",
+			saved_reg50, saved_reg51, saved_reg64,
+			saved_reg65, saved_reg71));
+
+		saved_status = FALSE;
+	} else {
+		WL_ERR((":%s att to restore not saved BTCOEX params\n",
+			__FUNCTION__));
+		return -1;
+	}
+	return 0;
+}
+#endif /* BT_DHCP_eSCO_FIX */
+
+static void
+wl_cfg80211_bt_setflag(struct net_device *dev, bool set)
+{
+#if defined(BT_DHCP_USE_FLAGS)
+	char buf_flag7_dhcp_on[8] = { 7, 00, 00, 00, 0x1, 0x0, 0x00, 0x00 };
+	char buf_flag7_default[8]   = { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
+#endif
+
+
+#if defined(BT_DHCP_eSCO_FIX)
+	/* set = 1, save & turn on  0 - off & restore prev settings */
+	set_btc_esco_params(dev, set);
+#endif
+
+#if defined(BT_DHCP_USE_FLAGS)
+	WL_TRACE(("WI-FI priority boost via bt flags, set:%d\n", set));
+	if (set == TRUE)
+		/* Forcing bt_flag7  */
+		dev_wlc_bufvar_set(dev, "btc_flags",
+			(char *)&buf_flag7_dhcp_on[0],
+			sizeof(buf_flag7_dhcp_on));
+	else
+		/* Restoring default bt flag7 */
+		dev_wlc_bufvar_set(dev, "btc_flags",
+			(char *)&buf_flag7_default[0],
+			sizeof(buf_flag7_default));
+#endif
+}
+
+static void wl_cfg80211_bt_timerfunc(ulong data)
+{
+	struct btcoex_info *bt_local = (struct btcoex_info *)data;
+	WL_TRACE(("%s\n", __FUNCTION__));
+	bt_local->timer_on = 0;
+	schedule_work(&bt_local->work);
+}
+
+static void wl_cfg80211_bt_handler(struct work_struct *work)
+{
+	struct btcoex_info *btcx_inf;
+
+	btcx_inf = container_of(work, struct btcoex_info, work);
+
+	if (btcx_inf->timer_on) {
+		btcx_inf->timer_on = 0;
+		del_timer_sync(&btcx_inf->timer);
+	}
+
+	switch (btcx_inf->bt_state) {
+		case BT_DHCP_START:
+			/* DHCP started
+			 * provide OPPORTUNITY window to get DHCP address
+			 */
+			WL_TRACE(("%s bt_dhcp stm: started \n",
+				__FUNCTION__));
+			btcx_inf->bt_state = BT_DHCP_OPPR_WIN;
+			mod_timer(&btcx_inf->timer,
+				jiffies + BT_DHCP_OPPR_WIN_TIME*HZ/1000);
+			btcx_inf->timer_on = 1;
+			break;
+
+		case BT_DHCP_OPPR_WIN:
+			if (btcx_inf->dhcp_done) {
+				WL_TRACE(("%s DHCP Done before T1 expiration\n",
+					__FUNCTION__));
+				goto btc_coex_idle;
+			}
+
+			/* DHCP is not over yet, start lowering BT priority
+			 * enforce btc_params + flags if necessary
+			 */
+			WL_TRACE(("%s DHCP T1:%d expired\n", __FUNCTION__,
+				BT_DHCP_OPPR_WIN_TIME));
+			if (btcx_inf->dev)
+				wl_cfg80211_bt_setflag(btcx_inf->dev, TRUE);
+			btcx_inf->bt_state = BT_DHCP_FLAG_FORCE_TIMEOUT;
+			mod_timer(&btcx_inf->timer,
+				jiffies + BT_DHCP_FLAG_FORCE_TIME*HZ/1000);
+			btcx_inf->timer_on = 1;
+			break;
+
+		case BT_DHCP_FLAG_FORCE_TIMEOUT:
+			if (btcx_inf->dhcp_done) {
+				WL_TRACE(("%s DHCP Done before T2 expiration\n",
+					__FUNCTION__));
+			} else {
+				/* Noo dhcp during T1+T2, restore BT priority */
+				WL_TRACE(("%s DHCP wait interval T2:%d"
+					  "msec expired\n", __FUNCTION__,
+					  BT_DHCP_FLAG_FORCE_TIME));
+			}
+
+			/* Restoring default bt priority */
+			if (btcx_inf->dev)
+				wl_cfg80211_bt_setflag(btcx_inf->dev, FALSE);
+btc_coex_idle:
+			btcx_inf->bt_state = BT_DHCP_IDLE;
+			btcx_inf->timer_on = 0;
+			break;
+
+		default:
+			WL_ERR(("%s error g_status=%d !!!\n", __FUNCTION__,
+				btcx_inf->bt_state));
+			if (btcx_inf->dev)
+				wl_cfg80211_bt_setflag(btcx_inf->dev, FALSE);
+			btcx_inf->bt_state = BT_DHCP_IDLE;
+			btcx_inf->timer_on = 0;
+			break;
+	}
+
+	net_os_wake_unlock(btcx_inf->dev);
+}
+
+int wl_cfg80211_btcoex_init(struct wl_priv *wl)
+{
+	struct btcoex_info *btco_inf = NULL;
+
+	btco_inf = kmalloc(sizeof(struct btcoex_info), GFP_KERNEL);
+	if (!btco_inf)
+		return -ENOMEM;
+
+	btco_inf->bt_state = BT_DHCP_IDLE;
+	btco_inf->ts_dhcp_start = 0;
+	btco_inf->ts_dhcp_ok = 0;
+	/* Set up timer for BT  */
+	btco_inf->timer_ms = 10;
+	init_timer(&btco_inf->timer);
+	btco_inf->timer.data = (ulong)btco_inf;
+	btco_inf->timer.function = wl_cfg80211_bt_timerfunc;
+
+	btco_inf->dev = wl->wdev->netdev;
+
+	INIT_WORK(&btco_inf->work, wl_cfg80211_bt_handler);
+
+	wl->btcoex_info = btco_inf;
+	return 0;
+}
+
+void wl_cfg80211_btcoex_deinit(struct wl_priv *wl)
+{
+	if (!wl->btcoex_info)
+		return;
+
+	if (!wl->btcoex_info->timer_on) {
+		wl->btcoex_info->timer_on = 0;
+		del_timer_sync(&wl->btcoex_info->timer);
+	}
+
+	cancel_work_sync(&wl->btcoex_info->work);
+
+	kfree(wl->btcoex_info);
+	wl->btcoex_info = NULL;
+}
+#endif
+
+int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, char *command)
+{
+
+	struct wl_priv *wl = wlcfg_drv_priv;
+	char powermode_val = 0;
+	char buf_reg66va_dhcp_on[8] = { 66, 00, 00, 00, 0x10, 0x27, 0x00, 0x00 };
+	char buf_reg41va_dhcp_on[8] = { 41, 00, 00, 00, 0x33, 0x00, 0x00, 0x00 };
+	char buf_reg68va_dhcp_on[8] = { 68, 00, 00, 00, 0x90, 0x01, 0x00, 0x00 };
+
+	uint32 regaddr;
+	static uint32 saved_reg66;
+	static uint32 saved_reg41;
+	static uint32 saved_reg68;
+	static bool saved_status = FALSE;
+
+#ifdef COEX_DHCP
+	char buf_flag7_default[8] =   { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
+	struct btcoex_info *btco_inf = wl->btcoex_info;
+#endif /* COEX_DHCP */
+
+	/* Figure out powermode 1 or o command */
+	strncpy((char *)&powermode_val, command + strlen("BTCOEXMODE") +1, 1);
+
+	if (strnicmp((char *)&powermode_val, "1", strlen("1")) == 0) {
+
+		WL_TRACE(("%s: DHCP session starts\n", __FUNCTION__));
+
+		/* Retrieve and saved orig regs value */
+		if ((saved_status == FALSE) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 66,  &saved_reg66)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 41,  &saved_reg41)) &&
+			(!dev_wlc_intvar_get_reg(dev, "btc_params", 68,  &saved_reg68)))   {
+				saved_status = TRUE;
+				WL_TRACE(("Saved 0x%x 0x%x 0x%x\n",
+					saved_reg66, saved_reg41, saved_reg68));
+
+				/* Disable PM mode during dhpc session */
+
+				/* Disable PM mode during dhpc session */
+#ifdef COEX_DHCP
+				/* Start  BT timer only for SCO connection */
+				if (btcoex_is_sco_active(dev)) {
+					/* btc_params 66 */
+					dev_wlc_bufvar_set(dev, "btc_params",
+						(char *)&buf_reg66va_dhcp_on[0],
+						sizeof(buf_reg66va_dhcp_on));
+					/* btc_params 41 0x33 */
+					dev_wlc_bufvar_set(dev, "btc_params",
+						(char *)&buf_reg41va_dhcp_on[0],
+						sizeof(buf_reg41va_dhcp_on));
+					/* btc_params 68 0x190 */
+					dev_wlc_bufvar_set(dev, "btc_params",
+						(char *)&buf_reg68va_dhcp_on[0],
+						sizeof(buf_reg68va_dhcp_on));
+					saved_status = TRUE;
+
+					btco_inf->bt_state = BT_DHCP_START;
+					btco_inf->timer_on = 1;
+					mod_timer(&btco_inf->timer, btco_inf->timer.expires);
+					WL_TRACE(("%s enable BT DHCP Timer\n",
+					__FUNCTION__));
+				}
+#endif /* COEX_DHCP */
+		}
+		else if (saved_status == TRUE) {
+			WL_ERR(("%s was called w/o DHCP OFF. Continue\n", __FUNCTION__));
+		}
+	}
+	else if (strnicmp((char *)&powermode_val, "2", strlen("2")) == 0) {
+
+
+		/* Restoring PM mode */
+
+#ifdef COEX_DHCP
+		/* Stop any bt timer because DHCP session is done */
+		WL_TRACE(("%s disable BT DHCP Timer\n", __FUNCTION__));
+		if (btco_inf->timer_on) {
+			btco_inf->timer_on = 0;
+			del_timer_sync(&btco_inf->timer);
+
+			if (btco_inf->bt_state != BT_DHCP_IDLE) {
+			/* need to restore original btc flags & extra btc params */
+				WL_TRACE(("%s bt->bt_state:%d\n",
+					__FUNCTION__, btco_inf->bt_state));
+				/* wake up btcoex thread to restore btlags+params  */
+				schedule_work(&btco_inf->work);
+			}
+		}
+
+		/* Restoring btc_flag paramter anyway */
+		if (saved_status == TRUE)
+			dev_wlc_bufvar_set(dev, "btc_flags",
+				(char *)&buf_flag7_default[0], sizeof(buf_flag7_default));
+#endif /* COEX_DHCP */
+
+		/* Restore original values */
+		if (saved_status == TRUE) {
+			regaddr = 66;
+			dev_wlc_intvar_set_reg(dev, "btc_params",
+				(char *)&regaddr, (char *)&saved_reg66);
+			regaddr = 41;
+			dev_wlc_intvar_set_reg(dev, "btc_params",
+				(char *)&regaddr, (char *)&saved_reg41);
+			regaddr = 68;
+			dev_wlc_intvar_set_reg(dev, "btc_params",
+				(char *)&regaddr, (char *)&saved_reg68);
+
+			WL_TRACE(("restore regs {66,41,68} <- 0x%x 0x%x 0x%x\n",
+				saved_reg66, saved_reg41, saved_reg68));
+		}
+		saved_status = FALSE;
+
+	}
+	else {
+		WL_ERR(("%s Unkwown yet power setting, ignored\n",
+			__FUNCTION__));
+	}
+
+	snprintf(command, 3, "OK");
+
+	return (strlen("OK"));
+}
diff --git a/drivers/net/wireless/bcmdhd/dhd_cfg80211.h b/drivers/net/wireless/bcmdhd/dhd_cfg80211.h
new file mode 100644
index 0000000..c53a25c
--- /dev/null
+++ b/drivers/net/wireless/bcmdhd/dhd_cfg80211.h
@@ -0,0 +1,42 @@
+/*
+ * Linux cfg80211 driver - Dongle Host Driver (DHD) related
+ *
+ * Copyright (C) 1999-2011, Broadcom Corporation
+ *
+ *         Unless you and Broadcom execute a separate written software license
+ * agreement governing use of this software, this software is licensed to you
+ * under the terms of the GNU General Public License version 2 (the "GPL"),
+ * available at http://www.broadcom.com/licenses/GPLv2.php, with the
+ * following added to such license:
+ *
+ *      As a special exception, the copyright holders of this software give you
+ * permission to link this software with independent modules, and to copy and
+ * distribute the resulting executable under terms of your choice, provided that
+ * you also meet, for each linked independent module, the terms and conditions of
+ * the license of that module.  An independent module is a module which is not
+ * derived from this software.  The special exception does not apply to any
+ * modifications of the software.
+ *
+ *      Notwithstanding the above, under no circumstances may you combine this
+ * software in any way with any other Broadcom software provided under a license
+ * other than the GPL, without Broadcom's express prior written consent.
+ *
+ * $Id: wl_cfg80211.c,v 1.1.4.1.2.14 2011/02/09 01:40:07 Exp $
+ */
+
+
+#ifndef __DHD_CFG80211__
+#define __DHD_CFG80211__
+
+#include <wl_cfg80211.h>
+#include <wl_cfgp2p.h>
+
+s32 dhd_cfg80211_init(struct wl_priv *wl);
+s32 dhd_cfg80211_deinit(struct wl_priv *wl);
+s32 dhd_cfg80211_down(struct wl_priv *wl);
+s32 dhd_config_dongle(struct wl_priv *wl, bool need_lock);
+
+int wl_cfg80211_btcoex_init(struct wl_priv *wl);
+void wl_cfg80211_btcoex_deinit(struct wl_priv *wl);
+
+#endif /* __DHD_CFG80211__ */
diff --git a/drivers/net/wireless/bcmdhd/dhd_common.c b/drivers/net/wireless/bcmdhd/dhd_common.c
index a29c2fa..19af6f3 100644
--- a/drivers/net/wireless/bcmdhd/dhd_common.c
+++ b/drivers/net/wireless/bcmdhd/dhd_common.c
@@ -2,13 +2,13 @@
  * Broadcom Dongle Host Driver (DHD), common DHD core.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -82,6 +82,7 @@
 #define htod16(i) i
 #define dtoh32(i) i
 #define dtoh16(i) i
+#define  P2P_IFNAME "p2pif"
 extern int dhd_iscan_request(void * dhdp, uint16 action);
 extern void dhd_ind_scan_confirm(void *h, bool status);
 extern int dhd_iscan_in_progress(void *h);
@@ -336,6 +337,11 @@
 
 	case IOV_SVAL(IOV_MSGLEVEL):
 		dhd_msg_level = int_val;
+#ifdef WL_CFG80211
+		/* Enable DHD and WL logs in oneshot */
+		if (dhd_msg_level & DHD_WL_VAL)
+			wl_cfg80211_enable_trace(dhd_msg_level);
+#endif
 		break;
 	case IOV_GVAL(IOV_BCMERRORSTR):
 		bcm_strncpy_s((char *)arg, len, bcmerrorstr(dhd_pub->bcmerror), BCME_STRLEN);
@@ -1038,6 +1044,14 @@
 #endif /* WL_CFG80211 */
 				if (ifevent->ifidx > 0 && ifevent->ifidx < DHD_MAX_IFS) {
 					if (ifevent->action == WLC_E_IF_ADD) {
+						if (!ap_fw_loaded) {
+							char p2piface_name[IFNAMSIZ];
+							snprintf(p2piface_name, IFNAMSIZ, "%s%d", P2P_IFNAME,
+							ifevent->ifidx);
+							strncpy(event->ifname, p2piface_name, IFNAMSIZ);
+							memcpy(&pvt_data->event, event, sizeof(wl_event_msg_t));
+						}
+
 						if (dhd_add_if(dhd_pub->info, ifevent->ifidx,
 							NULL, event->ifname,
 							event->addr.octet,
@@ -1489,7 +1503,7 @@
 		return -1;
 
 	iov_len = bcm_mkiovar("arp_hostip", 0, 0, buf, buflen);
-	retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, buflen, TRUE, 0);
+	retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, buflen, FALSE, 0);
 
 	if (retcode) {
 		DHD_TRACE(("%s: ioctl WLC_GET_VAR error %d\n",
@@ -1902,6 +1916,7 @@
 	if ((!dhd) && (!ssids_local)) {
 		DHD_ERROR(("%s error exit\n", __FUNCTION__));
 		err = -1;
+		return err;
 	}
 
 	if (dhd_check_ap_wfd_mode_set(dhd) == TRUE)
@@ -2040,7 +2055,7 @@
 	mkeep_alive_pkt.keep_alive_id = 0;
 	mkeep_alive_pkt.len_bytes = 0;
 	buf_len += WL_MKEEP_ALIVE_FIXED_LEN;
-	/* Keep-alive attributes are set in local variable (mkeep_alive_pkt), and
+	/* Keep-alive attributes are set in local	variable (mkeep_alive_pkt), and
 	 * then memcpy'ed into buffer (mkeep_alive_pktp) since there is no
 	 * guarantee that the buffer is properly aligned.
 	 */
@@ -2155,14 +2170,14 @@
 int
 wl_iw_parse_ssid_list_tlv(char** list_str, wlc_ssid_t* ssid, int max, int *bytes_left)
 {
-	char* str =  *list_str;
+	char* str;
 	int idx = 0;
 
 	if ((list_str == NULL) || (*list_str == NULL) || (*bytes_left < 0)) {
 		DHD_ERROR(("%s error paramters\n", __FUNCTION__));
 		return -1;
 	}
-
+	str = *list_str;
 	while (*bytes_left > 0) {
 
 		if (str[0] != CSCAN_TLV_TYPE_SSID_IE) {
diff --git a/drivers/net/wireless/bcmdhd/dhd_custom_gpio.c b/drivers/net/wireless/bcmdhd/dhd_custom_gpio.c
index 9750eeb..6680c8a 100644
--- a/drivers/net/wireless/bcmdhd/dhd_custom_gpio.c
+++ b/drivers/net/wireless/bcmdhd/dhd_custom_gpio.c
@@ -1,13 +1,14 @@
 /*
 * Customer code to add GPIO control during WLAN start/stop
 * Copyright (C) 1999-2011, Broadcom Corporation
-* 
+* Copyright (C) 2012 Sony Mobile Communications AB.
+*
 *         Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2 (the "GPL"),
 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
 * following added to such license:
-* 
+*
 *      As a special exception, the copyright holders of this software give you
 * permission to link this software with independent modules, and to copy and
 * distribute the resulting executable under terms of your choice, provided that
@@ -15,12 +16,17 @@
 * the license of that module.  An independent module is a module which is not
 * derived from this software.  The special exception does not apply to any
 * modifications of the software.
-* 
+*
 *      Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a license
 * other than the GPL, without Broadcom's express prior written consent.
 *
-* $Id: dhd_custom_gpio.c,v 1.2.42.1 2010-10-19 00:41:09 Exp $
+* $Id: dhd_custom_gpio.c 275786 2011-08-04 22:42:42Z $
+*
+* NOTE: This file has been modified by Sony Mobile Communications AB.
+* Modifications are licensed under the Sony Mobile Communications AB.
+* End User License Agreement ("EULA"). Any use of the modifications is subject
+* to the terms of the EULA.
 */
 
 #include <typedefs.h>
@@ -33,27 +39,23 @@
 
 #include <wlioctl.h>
 #include <wl_iw.h>
+#include <wl_android.h>
+
+#include <asm/gpio.h>
 
 #define WL_ERROR(x) printf x
 #define WL_TRACE(x)
 
+#ifdef GET_CUSTOM_MAC_ENABLE
+#define MAC_LEN 6
+#define MACADDR_BUF_LEN            64
+#define MACADDR_PATH "/data/etc/wifi/fw"
+#endif /* GET_CUSTOM_MAC_ENABLE */
+
 #ifdef CUSTOMER_HW
-extern  void bcm_wlan_power_off(int);
-extern  void bcm_wlan_power_on(int);
-#endif /* CUSTOMER_HW */
-#if defined(CUSTOMER_HW2)
-#ifdef CONFIG_WIFI_CONTROL_FUNC
-int wifi_set_power(int on, unsigned long msec);
-int wifi_get_irq_number(unsigned long *irq_flags_ptr);
-int wifi_get_mac_addr(unsigned char *buf);
-void *wifi_get_country_code(char *ccode);
-#else
-int wifi_set_power(int on, unsigned long msec) { return -1; }
-int wifi_get_irq_number(unsigned long *irq_flags_ptr) { return -1; }
-int wifi_get_mac_addr(unsigned char *buf) { return -1; }
-void *wifi_get_country_code(char *ccode) { return NULL; }
-#endif /* CONFIG_WIFI_CONTROL_FUNC */
-#endif /* CUSTOMER_HW2 */
+#define WL_RST_N (130)
+int wifi_set_carddetect(int on);
+#endif
 
 #if defined(OOB_INTR_ONLY)
 
@@ -86,15 +88,11 @@
 {
 	int  host_oob_irq = 0;
 
-#ifdef CUSTOMER_HW2
-	host_oob_irq = wifi_get_irq_number(irq_flags_ptr);
-
-#else
 #if defined(CUSTOM_OOB_GPIO_NUM)
 	if (dhd_oob_gpio_num < 0) {
 		dhd_oob_gpio_num = CUSTOM_OOB_GPIO_NUM;
 	}
-#endif /* CUSTOMER_HW2 */
+#endif
 
 	if (dhd_oob_gpio_num < 0) {
 		WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined \n",
@@ -106,13 +104,10 @@
 	         __FUNCTION__, dhd_oob_gpio_num));
 
 #if defined CUSTOMER_HW
+	gpio_request(dhd_oob_gpio_num, "WL_HOST_WAKEUP");
 	host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
-#elif defined CUSTOMER_HW3
-	gpio_request(dhd_oob_gpio_num, "oob irq");
-	host_oob_irq = gpio_to_irq(dhd_oob_gpio_num);
 	gpio_direction_input(dhd_oob_gpio_num);
 #endif /* CUSTOMER_HW */
-#endif /* CUSTOMER_HW2 */
 
 	return (host_oob_irq);
 }
@@ -124,34 +119,28 @@
 {
 	switch (onoff) {
 		case WLAN_RESET_OFF:
-			WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n",
+			WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET_OFF\n",
 				__FUNCTION__));
 #ifdef CUSTOMER_HW
-			bcm_wlan_power_off(2);
+			gpio_set_value(WL_RST_N, 0);
 #endif /* CUSTOMER_HW */
-#ifdef CUSTOMER_HW2
-			wifi_set_power(0, 0);
-#endif
-			WL_ERROR(("=========== WLAN placed in RESET ========\n"));
+			WL_TRACE(("=========== WLAN placed in RESET ========\n"));
 		break;
 
 		case WLAN_RESET_ON:
-			WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n",
+			WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET_ON\n",
 				__FUNCTION__));
 #ifdef CUSTOMER_HW
-			bcm_wlan_power_on(2);
+			gpio_set_value(WL_RST_N, 1);
 #endif /* CUSTOMER_HW */
-#ifdef CUSTOMER_HW2
-			wifi_set_power(1, 0);
-#endif
-			WL_ERROR(("=========== WLAN going back to live  ========\n"));
+			WL_TRACE(("=========== WLAN going back to live  ========\n"));
 		break;
 
 		case WLAN_POWER_OFF:
-			WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n",
+			WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_OFF\n",
 				__FUNCTION__));
 #ifdef CUSTOMER_HW
-			bcm_wlan_power_off(1);
+			gpio_set_value(WL_RST_N, 0);
 #endif /* CUSTOMER_HW */
 		break;
 
@@ -159,12 +148,14 @@
 			WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n",
 				__FUNCTION__));
 #ifdef CUSTOMER_HW
-			bcm_wlan_power_on(1);
-			/* Lets customer power to get stable */
-			OSL_DELAY(200);
+			gpio_set_value(WL_RST_N, 1);
 #endif /* CUSTOMER_HW */
 		break;
 	}
+
+	/* Lets customer power to get stable */
+	OSL_DELAY(200);
+
 }
 
 #ifdef GET_CUSTOM_MAC_ENABLE
@@ -173,26 +164,112 @@
 dhd_custom_get_mac_address(unsigned char *buf)
 {
 	int ret = 0;
+	int length;
+	mm_segment_t oldfs;
+	struct file *filp;
+	struct inode *inode = NULL;
+	unsigned char macaddr_buf[MACADDR_BUF_LEN];
 
 	WL_TRACE(("%s Enter\n", __FUNCTION__));
 	if (!buf)
 		return -EINVAL;
 
-	/* Customer access to MAC address stored outside of DHD driver */
-#if defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
-	ret = wifi_get_mac_addr(buf);
-#endif
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
 
-#ifdef EXAMPLE_GET_MAC
-	/* EXAMPLE code */
-	{
-		struct ether_addr ea_example = {{0x00, 0x11, 0x22, 0x33, 0x44, 0xFF}};
-		bcopy((char *)&ea_example, buf, sizeof(struct ether_addr));
+	filp = filp_open(MACADDR_PATH, O_RDONLY, S_IRUSR);
+	if (IS_ERR(filp)) {
+		WL_ERROR(("%s: file filp_open error\n", __FUNCTION__));
+		set_fs(oldfs);
+		return -1;
 	}
-#endif /* EXAMPLE_GET_MAC */
+	if (!filp->f_op) {
+		WL_ERROR(("%s: File Operation Method Error\n", __FUNCTION__));
+		filp_close(filp, NULL);
+		set_fs(oldfs);
+		return -1;
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
+	inode = filp->f_path.dentry->d_inode;
+#else
+	inode = filp->f_dentry->d_inode;
+#endif
+	if (!inode) {
+		WL_ERROR(("%s: Get inode from filp failed\n", __FUNCTION__));
+		filp_close(filp, NULL);
+		set_fs(oldfs);
+		return -1;
+	}
+
+	/* check file size */
+	length = i_size_read(inode->i_mapping->host);
+	if (length+1 > MACADDR_BUF_LEN) {
+		WL_ERROR(("%s: MAC file's size is not as expected\n", __FUNCTION__));
+		filp_close(filp, NULL);
+		set_fs(oldfs);
+		return -1;
+	}
+
+	/* read mac address */
+	if (filp->f_op->read(filp, macaddr_buf, length, &filp->f_pos) != length) {
+		WL_ERROR(("%s: file read error\n", __FUNCTION__));
+		filp_close(filp, NULL);
+		set_fs(oldfs);
+		return -1;
+	}
+	macaddr_buf[length] = '\0';
+
+	/* read mac address success */
+	filp_close(filp, NULL);
+	set_fs(oldfs);
+
+	/* convert mac address */
+	if (!dhd_ether_aton(macaddr_buf, length, buf)) {
+		WL_ERROR(("%s: convert mac value fail\n", __FUNCTION__));
+		return -1;
+	}
 
 	return ret;
 }
+
+int
+dhd_ether_aton(const char *orig, size_t len, unsigned char *eth)
+{
+	const char *bufp;
+	int i;
+
+	i = 0;
+	for(bufp = orig; bufp!=orig+len && *bufp; ++bufp) {
+		unsigned int val;
+		unsigned char c = *bufp++;
+
+		if (c >= '0' && c <= '9') val = c - '0';
+		else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
+		else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
+		else {
+			WL_ERROR(("%s: MAC value is invalid\n", __FUNCTION__));
+			break;
+		}
+
+		val <<= 4;
+		c = *bufp++;
+		if (c >= '0' && c <= '9') val |= c - '0';
+		else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
+		else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
+		else {
+			WL_ERROR(("%s: MAC value is invalid\n", __FUNCTION__));
+			break;
+		}
+
+		eth[i] = (unsigned char) (val & 0377);
+		if(++i == MAC_LEN) {
+			return 1;
+		}
+		if (*bufp != ':')
+			break;
+	}
+	return 0;
+}
 #endif /* GET_CUSTOM_MAC_ENABLE */
 
 /* Customized Locale table : OPTIONAL feature */
@@ -289,5 +366,5 @@
 	cspec->rev = translate_custom_table[0].custom_locale_rev;
 #endif /* EXMAPLE_TABLE */
 	return;
-#endif /* defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
+#endif /* defined(CUSTOMER_HW2) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) */
 }
diff --git a/drivers/net/wireless/bcmdhd/dhd_dbg.h b/drivers/net/wireless/bcmdhd/dhd_dbg.h
index a195cbe..bfb7819 100644
--- a/drivers/net/wireless/bcmdhd/dhd_dbg.h
+++ b/drivers/net/wireless/bcmdhd/dhd_dbg.h
@@ -2,13 +2,13 @@
  * Debug/trace/assert driver definitions for Dongle Host Driver.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -91,7 +91,7 @@
 #define DHD_BTA_ON()		0
 #define DHD_ISCAN_ON()		0
 #define DHD_ARPOE_ON()		0
-#endif 
+#endif
 
 #define DHD_LOG(args)
 
diff --git a/drivers/net/wireless/bcmdhd/dhd_linux.c b/drivers/net/wireless/bcmdhd/dhd_linux.c
index 92cdc9b..29b31cd 100644
--- a/drivers/net/wireless/bcmdhd/dhd_linux.c
+++ b/drivers/net/wireless/bcmdhd/dhd_linux.c
@@ -3,13 +3,16 @@
  * Basically selected code segments from usb-cdc.c and usb-rndis.c
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ * Copyright (C) 2011 Sony Ericsson Mobile Communications AB.
+ * Copyright (C) 2012 Sony Ericsson Communications AB.
+ * Copyright (C) 2012 Sony Mobile Communications AB.
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +20,17 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_linux.c 291449 2011-10-22 12:16:26Z $
+ * $Id: dhd_linux.c 292298 2011-10-26 20:02:21Z $
+ *
+ * NOTE: This file has been modified by Sony Ericsson Mobile Communications AB /
+ * Sony Mobile Communications AB. Modifications are licensed under the Sony Mobile
+ * Communications AB End User License Agreement ("EULA").
+ * Any use of the modifications is subject to the terms of the EULA.
  */
 
 #include <typedefs.h>
@@ -42,6 +50,7 @@
 #include <linux/ethtool.h>
 #include <linux/fcntl.h>
 #include <linux/fs.h>
+#include <linux/suspend.h>
 
 #include <asm/uaccess.h>
 #include <asm/unaligned.h>
@@ -61,6 +70,7 @@
 #endif
 #ifdef WL_CFG80211
 #include <wl_cfg80211.h>
+#include <wl_android.h>
 #endif
 
 #include <proto/802.11_bta.h>
@@ -109,6 +119,7 @@
 #include <wl_android.h>
 
 #ifdef ARP_OFFLOAD_SUPPORT
+void aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add);
 static int dhd_device_event(struct notifier_block *this,
 	unsigned long event,
 	void *ptr);
@@ -155,10 +166,12 @@
 
 #if defined(CONFIG_HAS_EARLYSUSPEND)
 #include <linux/earlysuspend.h>
-extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
+//extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
 extern int dhd_get_dtim_skip(dhd_pub_t *dhd);
 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
 
+extern int dhdcdc_set_ioctl(dhd_pub_t *, int, uint, void *, uint);
+
 #ifdef PKT_FILTER_SUPPORT
 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
@@ -246,7 +259,9 @@
 	bool dhd_tasklet_create;
 #endif /* DHDTHREAD */
 	tsk_ctl_t	thr_sysioc_ctl;
-
+	/* locks  mac ioctl funcs which are in sys_ioc thr context  */
+	struct semaphore mac_ioc_sema;
+#define LOCK_TRACE(x)
 	/* Wakelocks */
 #if defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 	struct wake_lock wl_wifi;   /* Wifi wakelock */
@@ -269,10 +284,15 @@
 	wait_queue_head_t ctrl_wait;
 	atomic_t pend_8021x_cnt;
 	dhd_attach_states_t dhd_state;
+	struct notifier_block pm_notifier;
 
 #ifdef CONFIG_HAS_EARLYSUSPEND
 	struct early_suspend early_suspend;
 #endif /* CONFIG_HAS_EARLYSUSPEND */
+
+#ifdef ARP_OFFLOAD_SUPPORT
+	u32 pend_ipaddr;
+#endif /* ARP_OFFLOAD_SUPPORT */
 } dhd_info_t;
 
 /* Definitions to provide path to the firmware and nvram
@@ -327,7 +347,7 @@
 
 /* Pkt filter mode control */
 uint dhd_master_mode = TRUE;
-module_param(dhd_master_mode, uint, 0);
+module_param(dhd_master_mode, uint, 1);
 
 #ifdef DHDTHREAD
 /* Watchdog thread priority, -1 to use kernel timer */
@@ -375,6 +395,7 @@
 
 /* IOCTL response timeout */
 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
+dhd_info_t *g_dhd = NULL;
 
 /* Idle timeout for backplane clock */
 int dhd_idletime = DHD_IDLETIME_TICKS;
@@ -472,37 +493,7 @@
 
 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
                              wl_event_msg_t *event_ptr, void **data_ptr);
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
-static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
-{
-	int ret = NOTIFY_DONE;
-
-#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39))
-	switch (action) {
-		case PM_HIBERNATION_PREPARE:
-		case PM_SUSPEND_PREPARE:
-			dhd_mmc_suspend = TRUE;
-			ret = NOTIFY_OK;
-		break;
-		case PM_POST_HIBERNATION:
-		case PM_POST_SUSPEND:
-			dhd_mmc_suspend = FALSE;
-			ret = NOTIFY_OK;
-		break;
-	}
-	smp_mb();
-#endif
-	return ret;
-}
-
-static struct notifier_block dhd_sleep_pm_notifier = {
-	.notifier_call = dhd_sleep_pm_callback,
-	.priority = 0
-};
-extern int register_pm_notifier(struct notifier_block *nb);
-extern int unregister_pm_notifier(struct notifier_block *nb);
-#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
+static void dhd_watchdog(ulong data);
 
 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
 {
@@ -522,7 +513,9 @@
 #endif
 }
 
-#if defined(CONFIG_HAS_EARLYSUSPEND)
+#if defined(CONFIG_HAS_EARLYSUSPEND) || \
+	((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && \
+	defined(CONFIG_PM_SLEEP))
 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
 {
 	int power_mode = PM_MAX;
@@ -598,24 +591,70 @@
 	DHD_OS_WAKE_UNLOCK(dhdp);
 }
 
+static int dhd_sleep_pm_callback(struct notifier_block *nfb,
+				unsigned long action, void *ignored)
+{
+	struct dhd_info *dhd = container_of(nfb, struct dhd_info, pm_notifier);
+	int ret = NOTIFY_DONE;
+
+	pr_debug("%s: action %ld\n", __func__, action);
+
+	switch (action) {
+	case PM_HIBERNATION_PREPARE:
+	case PM_SUSPEND_PREPARE:
+		if (dhd) {
+			dhd_suspend_resume_helper(dhd, 1);
+			del_timer_sync(&dhd->timer);
+			dhd->wd_timer_valid = FALSE;
+			dhd_watchdog((unsigned long)dhd);
+		}
+		dhd_mmc_suspend = TRUE;
+		smp_mb();
+		ret = NOTIFY_OK;
+		break;
+	case PM_POST_HIBERNATION:
+	case PM_POST_SUSPEND:
+		dhd_mmc_suspend = FALSE;
+		smp_mb();
+		if (dhd) {
+			dhd_suspend_resume_helper(dhd, 0);
+			dhd->wd_timer_valid = TRUE;
+			mod_timer(&dhd->timer,
+				jiffies + dhd_watchdog_ms * HZ / 1000);
+		}
+		ret = NOTIFY_OK;
+		break;
+	}
+	return ret;
+}
+
+static struct notifier_block dhd_sleep_pm_notifier = {
+	.notifier_call = dhd_sleep_pm_callback,
+	.priority = 0
+};
+#endif /* defined (CONFIG_HAS_EARLYSUSPEND) || \
+	((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && \
+	defined(CONFIG_PM_SLEEP)) */
+
+#if defined(CONFIG_HAS_EARLYSUSPEND)
 static void dhd_early_suspend(struct early_suspend *h)
 {
-	struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
+	//struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
 
 	DHD_TRACE(("%s: enter\n", __FUNCTION__));
 
-	if (dhd)
-		dhd_suspend_resume_helper(dhd, 1);
+	//if (dhd)
+	//	dhd_suspend_resume_helper(dhd, 1);
 }
 
 static void dhd_late_resume(struct early_suspend *h)
 {
-	struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
+	//struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
 
 	DHD_TRACE(("%s: enter\n", __FUNCTION__));
 
-	if (dhd)
-		dhd_suspend_resume_helper(dhd, 0);
+	//if (dhd)
+	//	dhd_suspend_resume_helper(dhd, 0);
 }
 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
 
@@ -693,8 +732,9 @@
 	return DHD_BAD_IF;
 }
 
-struct net_device * dhd_idx2net(struct dhd_pub *dhd_pub, int ifidx)
+struct net_device * dhd_idx2net(void *pub, int ifidx)
 {
+	struct dhd_pub *dhd_pub = (struct dhd_pub *)pub;
 	struct dhd_info *dhd_info;
 
 	if (!dhd_pub || ifidx < 0 || ifidx >= DHD_MAX_IFS)
@@ -922,6 +962,7 @@
 		DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
 	} else {
 		memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
+		memcpy(dhd->pub.mac.octet, addr, ETHER_ADDR_LEN);
 	}
 
 	return ret;
@@ -941,8 +982,9 @@
 	unsigned long flags;
 #endif
 
+	if (!ifp || !ifp->info || !ifp->idx)
+		return;
 	ASSERT(ifp && ifp->info && ifp->idx);	/* Virtual interfaces only */
-
 	dhd = ifp->info;
 
 	DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
@@ -977,7 +1019,7 @@
 #ifdef WL_CFG80211
 			if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)
 				if (!wl_cfg80211_notify_ifadd(ifp->net, ifp->idx, ifp->bssidx,
-					dhd_net_attach)) {
+					(void*)dhd_net_attach)) {
 					ifp->state = DHD_IF_NONE;
 					return;
 				}
@@ -1013,12 +1055,17 @@
 			DHD_TRACE(("\n%s: got 'DHD_IF_DEL' state\n", __FUNCTION__));
 #ifdef WL_CFG80211
 			if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
-				wl_cfg80211_notify_ifdel(ifp->net);
+				wl_cfg80211_ifdel_ops(ifp->net);
 			}
 #endif
 			netif_stop_queue(ifp->net);
 			unregister_netdev(ifp->net);
 			ret = DHD_DEL_IF;	/* Make sure the free_netdev() is called */
+#ifdef WL_CFG80211
+			if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
+				wl_cfg80211_notify_ifdel();
+			}
+#endif
 		}
 		break;
 	case DHD_IF_DELETING:
@@ -1033,6 +1080,7 @@
 		ifp->set_multicast = FALSE;
 		if (ifp->net) {
 			free_netdev(ifp->net);
+			ifp->net = NULL;
 		}
 		dhd->iflist[ifp->idx] = NULL;
 #ifdef SOFTAP
@@ -1103,6 +1151,22 @@
 					continue;
 				}
 #endif /* SOFTAP */
+
+				LOCK_TRACE(("%s: grabing mac_ioc_sema ...\n", __FUNCTION__));
+				if (down_interruptible(&dhd->mac_ioc_sema) == 0) {
+					SMP_RD_BARRIER_DEPENDS();
+					if (tsk->terminated) {
+						LOCK_TRACE(("%s: GOT mac_ioc sema, "
+							"but thr terminated\n", __FUNCTION__));
+						up(&dhd->mac_ioc_sema);
+						break;
+					}
+				} else {
+					LOCK_TRACE(("%s: didn't get mac_sema,"
+						" interrupted by sig\n", __FUNCTION__));
+					break;
+				}
+
 				if (dhd->iflist[i]->set_multicast) {
 					dhd->iflist[i]->set_multicast = FALSE;
 					_dhd_set_multicast_list(dhd, i);
@@ -1111,6 +1175,8 @@
 					dhd->set_macaddress = FALSE;
 					_dhd_set_mac_address(dhd, i, &dhd->macvalue);
 				}
+				/* release mac ioc sema  */
+				up(&dhd->mac_ioc_sema);
 			}
 		}
 
@@ -1134,7 +1200,7 @@
 	if (ifidx == DHD_BAD_IF)
 		return -1;
 
-	ASSERT(&dhd->thr_sysioc_ctl.thr_pid >= 0);
+	ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
 	memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
 	dhd->set_macaddress = TRUE;
 	up(&dhd->thr_sysioc_ctl.sema);
@@ -1152,7 +1218,7 @@
 	if (ifidx == DHD_BAD_IF)
 		return;
 
-	ASSERT(&dhd->thr_sysioc_ctl.thr_pid >= 0);
+	ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
 	dhd->iflist[ifidx]->set_multicast = TRUE;
 	up(&dhd->thr_sysioc_ctl.sema);
 }
@@ -1171,6 +1237,8 @@
 dhd_os_wlfc_unblock(dhd_pub_t *pub)
 {
 	dhd_info_t *di = (dhd_info_t *)(pub->info);
+
+	(void)di;
 	ASSERT(di != NULL);
 	spin_unlock_bh(&di->wlfc_spinlock);
 	return 1;
@@ -1196,7 +1264,7 @@
 	}
 
 	/* Update multicast statistic */
-	if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_ADDR_LEN) {
+	if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_HDR_LEN) {
 		uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
 		eh = (struct ether_header *)pktdata;
 
@@ -1204,6 +1272,9 @@
 			dhdp->tx_multicast++;
 		if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
 			atomic_inc(&dhd->pend_8021x_cnt);
+	} else {
+			PKTFREE(dhd->pub.osh, pktbuf, TRUE);
+			return BCME_ERROR;
 	}
 
 	/* Look into the packet and update the packet priority */
@@ -1399,6 +1470,8 @@
 	wl_event_msg_t event;
 	int tout = DHD_PACKET_TIMEOUT;
 
+
+	(void)tout;
 	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
 
 	save_pktbuf = pktbuf;
@@ -1414,7 +1487,7 @@
 			PKTFREE(dhdp->osh, pktbuf, TRUE);
 			continue;
 		}
-
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 		/* Dropping packets before registering net device to avoid kernel panic */
 		if (!ifp->net || ifp->net->reg_state != NETREG_REGISTERED ||
 			!dhd->pub.up) {
@@ -1423,6 +1496,7 @@
 			PKTFREE(dhdp->osh, pktbuf, TRUE);
 			continue;
 		}
+#endif
 
 		pnext = PKTNEXT(dhdp->osh, pktbuf);
 		PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
@@ -1588,8 +1662,10 @@
 	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
 
 	ifidx = dhd_net2idx(dhd, net);
-	if (ifidx == DHD_BAD_IF)
+	if (ifidx == DHD_BAD_IF) {
+		DHD_ERROR(("%s: BAD_IF\n", __FUNCTION__));
 		return NULL;
+	}
 
 	ifp = dhd->iflist[ifidx];
 	ASSERT(dhd && ifp);
@@ -1663,7 +1739,7 @@
 			DHD_OS_WAKE_UNLOCK(&dhd->pub);
 		} else {
 			break;
-		}
+	}
 
 	complete_and_exit(&tsk->completed, 0);
 }
@@ -2038,6 +2114,7 @@
 	DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
 
 	if (ifidx == DHD_BAD_IF) {
+		DHD_ERROR(("%s: BAD IF\n", __FUNCTION__));
 		DHD_OS_WAKE_UNLOCK(&dhd->pub);
 		return -1;
 	}
@@ -2241,7 +2318,9 @@
 				(dhd->iflist[i]->state != DHD_IF_DELETING)) {
 				dhd->iflist[i]->state = DHD_IF_DEL;
 				dhd->iflist[i]->idx = i;
+				dhd_net_if_lock_local(dhd);
 				dhd_op_if(dhd->iflist[i]);
+				dhd_net_if_unlock_local(dhd);
 			}
 		}
 	}
@@ -2261,7 +2340,7 @@
 	int ifidx;
 	dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
 	DHD_OS_WAKE_LOCK(&dhd->pub);
-	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
+	DHD_TRACE(("%s: Enter %p\n", __FUNCTION__, net));
 	if (dhd->pub.up == 0) {
 		goto exit;
 	}
@@ -2269,7 +2348,7 @@
 
 #ifdef WL_CFG80211
 	if (ifidx == 0) {
-		wl_cfg80211_down();
+		wl_cfg80211_down(NULL);
 
 		/*
 		 * For CFG80211: Clean up all the left over virtual interfaces
@@ -2305,6 +2384,58 @@
 	return 0;
 }
 
+#ifdef DHD_BCM_WIFI_HDMI
+bool dhd_bcm_whdmi_enable = FALSE;
+
+/* Check for the presence of a given kernel parameter string,
+ * eg. "wifi=4330_whdmi".  Returns 0 if found.
+ */
+static int
+dhd_check_kernel_param(dhd_info_t *dhd, const char *str)
+{
+#define DHD_KPARAM_LEN 1024
+	int bcmerror = -1;
+	uint len;
+	void *fp = NULL;
+	char *kparam = NULL;
+
+	DHD_INFO(("%s\n", __FUNCTION__));
+
+	fp = dhd_os_open_image("/proc/cmdline");
+	if (fp == NULL)
+		goto err;
+
+	kparam = MALLOC(dhd->pub.osh, DHD_KPARAM_LEN);
+	if (kparam == NULL) {
+		DHD_ERROR(("%s: MALLOC of %u bytes failed!\n",
+			__FUNCTION__, DHD_KPARAM_LEN));
+		goto err;
+	}
+
+	/* Read the kernel cmdline and search for a matching string */
+	len = dhd_os_get_image_block(kparam, DHD_KPARAM_LEN, fp);
+	if (len > 0) {
+		kparam[DHD_KPARAM_LEN - 1] = '\0';
+		if (strstr(kparam, str) != NULL) {
+			bcmerror = 0;
+		}
+		/*
+		DHD_ERROR(("%s: err=%d len=%u kparam=%s\n",
+			__FUNCTION__, bcmerror, len, kparam));
+		*/
+	}
+
+err:
+	if (kparam) {
+		MFREE(dhd->pub.osh, kparam, DHD_KPARAM_LEN);
+	}
+
+	dhd_os_close_image(fp);
+
+	return bcmerror;
+}
+#endif /* DHD_BCM_WIFI_HDMI */
+
 static int
 dhd_open(struct net_device *net)
 {
@@ -2355,10 +2486,9 @@
 		DHD_ERROR(("\n%s\n", dhd_version));
 		if (!dhd_download_fw_on_driverload)
 			wl_android_wifi_on(net);
-#endif /* defined(WL_CFG80211) */
+#endif
 
 		if (dhd->pub.busstate != DHD_BUS_DATA) {
-			int ret;
 
 			/* try to bring up bus */
 			if ((ret = dhd_bus_start(&dhd->pub)) != 0) {
@@ -2381,7 +2511,7 @@
 #endif /* TOE */
 
 #if defined(WL_CFG80211)
-		if (unlikely(wl_cfg80211_up())) {
+		if (unlikely(wl_cfg80211_up(NULL))) {
 			DHD_ERROR(("%s: failed to bring up cfg80211\n", __FUNCTION__));
 			ret = -1;
 			goto exit;
@@ -2456,7 +2586,7 @@
 		ifp->state = DHD_IF_ADD;
 		ifp->idx = ifidx;
 		ifp->bssidx = bssidx;
-		ASSERT(&dhd->thr_sysioc_ctl.thr_pid >= 0);
+		ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
 		up(&dhd->thr_sysioc_ctl.sema);
 	} else
 		ifp->net = (struct net_device *)handle;
@@ -2480,10 +2610,30 @@
 
 	ifp->state = DHD_IF_DEL;
 	ifp->idx = ifidx;
-	ASSERT(&dhd->thr_sysioc_ctl.thr_pid >= 0);
+	ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
 	up(&dhd->thr_sysioc_ctl.sema);
 }
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
+static struct net_device_ops dhd_ops_pri = {
+	.ndo_open = dhd_open,
+	.ndo_stop = dhd_stop,
+	.ndo_get_stats = dhd_get_stats,
+	.ndo_do_ioctl = dhd_ioctl_entry,
+	.ndo_start_xmit = dhd_start_xmit,
+	.ndo_set_mac_address = dhd_set_mac_address,
+	.ndo_set_multicast_list = dhd_set_multicast_list,
+};
+
+static struct net_device_ops dhd_ops_virt = {
+	.ndo_get_stats = dhd_get_stats,
+	.ndo_do_ioctl = dhd_ioctl_entry,
+	.ndo_start_xmit = dhd_start_xmit,
+	.ndo_set_mac_address = dhd_set_mac_address,
+	.ndo_set_multicast_list = dhd_set_multicast_list,
+};
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) */
+
 dhd_pub_t *
 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
 {
@@ -2513,6 +2663,11 @@
 	}
 	memset(dhd, 0, sizeof(dhd_info_t));
 
+	/*   save ptr to dhd , we'll need it in module exit */
+	g_dhd = dhd;
+	/* semaphore to protect critical section in sysioc thread */
+	sema_init(&dhd->mac_ioc_sema, 1);
+
 #ifdef DHDTHREAD
 	dhd->thr_dpc_ctl.thr_pid = DHD_PID_KT_TL_INVALID;
 	dhd->thr_wdt_ctl.thr_pid = DHD_PID_KT_INVALID;
@@ -2664,7 +2819,8 @@
 	memcpy(netdev_priv(net), &dhd, sizeof(dhd));
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
-	register_pm_notifier(&dhd_sleep_pm_notifier);
+	dhd->pm_notifier = dhd_sleep_pm_notifier;
+	register_pm_notifier(&dhd->pm_notifier);
 #endif /*  (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
 
 #ifdef CONFIG_HAS_EARLYSUSPEND
@@ -2676,6 +2832,7 @@
 #endif
 
 #ifdef ARP_OFFLOAD_SUPPORT
+	dhd->pend_ipaddr = 0;
 	register_inetaddr_notifier(&dhd_notifier);
 #endif /* ARP_OFFLOAD_SUPPORT */
 
@@ -2709,27 +2866,31 @@
 	DHD_TRACE(("Enter %s:\n", __FUNCTION__));
 
 #ifdef DHDTHREAD
-	dhd_os_sdlock(dhdp);
+	if (dhd->threads_only)
+		dhd_os_sdlock(dhdp);
 #endif /* DHDTHREAD */
 
+
 	/* try to download image and nvram to the dongle */
 	if  ((dhd->pub.busstate == DHD_BUS_DOWN) &&
-		(fw_path != NULL) && (fw_path[0] != '\0') &&
-		(nv_path != NULL) && (nv_path[0] != '\0')) {
+		(fw_path[0] != '\0') &&
+		(nv_path[0] != '\0')) {
 		/* wake lock moved to dhdsdio_download_firmware */
 		if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
 		                                fw_path, nv_path))) {
 			DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n",
 			           __FUNCTION__, fw_path, nv_path));
 #ifdef DHDTHREAD
-			dhd_os_sdunlock(dhdp);
+			if (dhd->threads_only)
+				dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 			return -1;
 		}
 	}
 	if (dhd->pub.busstate != DHD_BUS_LOAD) {
 #ifdef DHDTHREAD
-		dhd_os_sdunlock(dhdp);
+		if (dhd->threads_only)
+			dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 		return -ENETDOWN;
 	}
@@ -2743,7 +2904,8 @@
 
 		DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
 #ifdef DHDTHREAD
-		dhd_os_sdunlock(dhdp);
+		if (dhd->threads_only)
+			dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 		return ret;
 	}
@@ -2759,7 +2921,8 @@
 
 		DHD_ERROR(("%s Host failed to register for OOB\n", __FUNCTION__));
 #ifdef DHDTHREAD
-		dhd_os_sdunlock(dhdp);
+		if (dhd->threads_only)
+			dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 		return -ENODEV;
 	}
@@ -2776,13 +2939,15 @@
 		del_timer_sync(&dhd->timer);
 		DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
 #ifdef DHDTHREAD
-		dhd_os_sdunlock(dhdp);
+		if (dhd->threads_only)
+			dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 		return -ENODEV;
 	}
 
 #ifdef DHDTHREAD
-	dhd_os_sdunlock(dhdp);
+	if (dhd->threads_only)
+		dhd_os_sdunlock(dhdp);
 #endif /* DHDTHREAD */
 
 #ifdef READ_MACADDR
@@ -2797,6 +2962,15 @@
 	dhd_write_macaddr(dhd->pub.mac.octet);
 #endif
 
+#ifdef ARP_OFFLOAD_SUPPORT
+	if (dhd->pend_ipaddr) {
+#ifdef AOE_IP_ALIAS_SUPPORT
+		aoe_update_host_ipv4_table(&dhd->pub, dhd->pend_ipaddr, TRUE);
+#endif /* AOE_IP_ALIAS_SUPPORT */
+		dhd->pend_ipaddr = 0;
+	}
+#endif /* ARP_OFFLOAD_SUPPORT */
+
 	return 0;
 }
 
@@ -2813,25 +2987,29 @@
 	uint32 glom = 0;
 	uint bcn_timeout = 4;
 	uint retry_max = 3;
+	int sgi_tx = -1;
+	int sgi_rx = 1;
+	int mimo_preamble = -1;
 #if defined(ARP_OFFLOAD_SUPPORT)
 	int arpoe = 1;
 #endif
-	int scan_assoc_time = 40;
+	int scan_assoc_time = DHD_SCAN_ACTIVE_TIME;
 	int scan_unassoc_time = 40;
-	int scan_passive_time = 130;
+	int scan_passive_time = DHD_SCAN_PASSIVE_TIME;
 	char buf[WLC_IOCTL_SMLEN];
 	char *ptr;
 	uint32 listen_interval = LISTEN_INTERVAL; /* Default Listen Interval in Beacons */
 #if defined(SOFTAP)
 	uint dtim = 1;
 #endif
-#if (defined(AP) && !defined(WLP2P)) || (!defined(AP) && defined(WL_CFG80211))
+#if (defined(AP) && !defined(WLP2P)) || (!defined(AP) && defined(WL_CFG80211)) || \
+	defined(DHD_BCM_WIFI_HDMI)
 	uint32 mpc = 0; /* Turn MPC off for AP/APSTA mode */
 #endif
 
-#if defined(AP) || defined(WLP2P)
+#if defined(AP) || defined(WLP2P) || defined(DHD_BCM_WIFI_HDMI)
 	uint32 apsta = 1; /* Enable APSTA mode */
-#endif /* defined(AP) || defined(WLP2P) */
+#endif /* defined(AP) || defined(WLP2P) || defined(DHD_BCM_WIFI_HDMI) */
 #ifdef GET_CUSTOM_MAC_ENABLE
 	struct ether_addr ea_addr;
 #endif /* GET_CUSTOM_MAC_ENABLE */
@@ -2846,8 +3024,8 @@
 		ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
 		if (ret < 0) {
 			DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
-			return BCME_NOTUP;
-		}
+		} else
+			memcpy(dhd->mac.octet, (void *)&ea_addr, ETHER_ADDR_LEN);
 	} else {
 #endif /* GET_CUSTOM_MAC_ENABLE */
 		/* Get the default device MAC address directly from firmware */
@@ -2860,6 +3038,7 @@
 		}
 		/* Update public MAC address after reading from Firmware */
 		memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN);
+
 #ifdef GET_CUSTOM_MAC_ENABLE
 	}
 #endif /* GET_CUSTOM_MAC_ENABLE */
@@ -2947,6 +3126,16 @@
 	if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
 		DHD_ERROR(("%s assoc_listen failed %d\n", __FUNCTION__, ret));
 
+	/* Set Short GI */
+	bcm_mkiovar("sgi_tx", (char *)&sgi_tx, 4, iovbuf, sizeof(iovbuf));
+	dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+	bcm_mkiovar("sgi_rx", (char *)&sgi_rx, 4, iovbuf, sizeof(iovbuf));
+	dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+
+	/* Set Green Field */
+	bcm_mkiovar("mimo_preamble", (char *)& mimo_preamble, 4, iovbuf, sizeof(iovbuf));
+	dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+
 	/* Set PowerSave mode */
 	dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode), TRUE, 0);
 
@@ -2972,6 +3161,20 @@
 	dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
 #endif /* defined(AP) && !defined(WLP2P) */
 
+#ifdef DHD_BCM_WIFI_HDMI
+	/* Check if WHDMI or APSTA firmware is being used */
+	if (strstr(fw_path, "whdmi") != NULL || strstr(fw_path, "apsta") != NULL) {
+		apsta = 1;
+		bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
+		dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+	}
+	/* Parse kernel parameters for WHDMI enable flag */
+	if (dhd_check_kernel_param(dhd->info, "wifi=4330_whdmi") == 0) {
+		printf("kernel 'wifi=4330_whdmi' parameter indicates WHDMI is on.\n");
+		dhd_bcm_whdmi_enable = TRUE;
+	}
+#endif /* DHD_BCM_WIFI_HDMI */
+
 #if defined(SOFTAP)
 	if (ap_fw_loaded == TRUE) {
 		dhd_wl_ioctl_cmd(dhd, WLC_SET_DTIMPRD, (char *)&dtim, sizeof(dtim), TRUE, 0);
@@ -2992,6 +3195,7 @@
 	}
 #endif /* defined(KEEP_ALIVE) */
 
+
 	/* Read event_msgs mask */
 	bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
 	if ((ret  = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0)) < 0) {
@@ -3059,7 +3263,7 @@
 	if (arpoe && !ap_fw_loaded) {
 #else
 	if (arpoe) {
-#endif 
+#endif
 		dhd_arp_offload_set(dhd, dhd_arp_mode);
 		dhd_arp_offload_enable(dhd, arpoe);
 	} else {
@@ -3087,6 +3291,32 @@
 #endif /* defined(SOFTAP) */
 #endif /* PKT_FILTER_SUPPORT */
 
+#if defined(DHD_BCM_WIFI_HDMI)
+	if (dhd_bcm_whdmi_enable) {
+		DHD_ERROR(("DHD WiFi HDMI is enabled\n"));
+
+		/* Turn off MPC, turn on APSTA */
+		/* APSTA can only be set before wl up */
+		bcm_mkiovar("mpc", (char *)&mpc, 4, iovbuf, sizeof(iovbuf));
+		dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+		bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
+		dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
+
+		/* Disable legacy power save modes */
+		power_mode = PM_OFF;
+		dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char*)&power_mode, sizeof(power_mode), TRUE, 0);
+
+#ifdef ARP_OFFLOAD_SUPPORT
+		/* Disable ARP offload */
+		dhd_arp_offload_set(dhd, 0);
+		dhd_arp_offload_enable(dhd, FALSE);
+#endif /* ARP_OFFLOAD_SUPPORT */
+
+	} else {
+		DHD_INFO(("DHD WiFi HDMI is NOT enabled\n"));
+	}
+#endif /* defined(DHD_BCM_WIFI_HDMI) */
+
 	/* Force STA UP */
 	if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_UP, (char *)&up, sizeof(up), TRUE, 0)) < 0) {
 		DHD_ERROR(("%s Setting WL UP failed %d\n", __FUNCTION__, ret));
@@ -3136,26 +3366,6 @@
 	return ret;
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
-static struct net_device_ops dhd_ops_pri = {
-	.ndo_open = dhd_open,
-	.ndo_stop = dhd_stop,
-	.ndo_get_stats = dhd_get_stats,
-	.ndo_do_ioctl = dhd_ioctl_entry,
-	.ndo_start_xmit = dhd_start_xmit,
-	.ndo_set_mac_address = dhd_set_mac_address,
-	.ndo_set_multicast_list = dhd_set_multicast_list,
-};
-
-static struct net_device_ops dhd_ops_virt = {
-	.ndo_get_stats = dhd_get_stats,
-	.ndo_do_ioctl = dhd_ioctl_entry,
-	.ndo_start_xmit = dhd_start_xmit,
-	.ndo_set_mac_address = dhd_set_mac_address,
-	.ndo_set_multicast_list = dhd_set_multicast_list,
-};
-#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) */
-
 int dhd_change_mtu(dhd_pub_t *dhdp, int new_mtu, int ifidx)
 {
 	struct dhd_info *dhd = dhdp->info;
@@ -3260,8 +3470,13 @@
 				__FUNCTION__, ifa->ifa_label, ifa->ifa_address));
 
 			/* firmware not downloaded, do nothing */
-			if (dhd->pub.busstate == DHD_BUS_DOWN) {
-				DHD_ERROR(("%s: bus is down, exit\n", __FUNCTION__));
+			if (dhd->pub.busstate != DHD_BUS_DATA) {
+				DHD_ERROR(("%s: bus not ready, exit\n", __FUNCTION__));
+				if (dhd->pend_ipaddr) {
+					DHD_ERROR(("%s: overwrite pending ipaddr: 0x%x\n",
+						__FUNCTION__, dhd->pend_ipaddr));
+				}
+				dhd->pend_ipaddr = ifa->ifa_address;
 				break;
 			}
 
@@ -3279,7 +3494,7 @@
 		case NETDEV_DOWN:
 			DHD_ARPOE(("%s: [%s] Down IP: 0x%x\n",
 				__FUNCTION__, ifa->ifa_label, ifa->ifa_address));
-
+			dhd->pend_ipaddr = 0;
 #ifdef AOE_IP_ALIAS_SUPPORT
 		if (!(ifa->ifa_label[strlen(ifa->ifa_label)-2] == 0x3a)) {
 				DHD_ARPOE(("%s: primary interface is down, AOE clr all\n",
@@ -3330,7 +3545,7 @@
 #else
 	ASSERT(!net->netdev_ops);
 	net->netdev_ops = &dhd_ops_virt;
-#endif
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
 
 	/* Ok, link into the network layer... */
 	if (ifidx == 0) {
@@ -3342,7 +3557,7 @@
 		net->stop = dhd_stop;
 #else
 		net->netdev_ops = &dhd_ops_pri;
-#endif
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
 	} else {
 		/*
 		 * We have to use the primary MAC for virtual interfaces
@@ -3353,7 +3568,8 @@
 		 * portable hotspot.  This will not work in simultaneous AP/STA mode,
 		 * nor with P2P.  Need to set the Donlge's MAC address, and then use that.
 		 */
-		if (ifidx > 0) {
+		if (!memcmp(temp_addr, dhd->iflist[0]->mac_addr,
+			ETHER_ADDR_LEN)) {
 			DHD_ERROR(("%s interface [%s]: set locally administered bit in MAC\n",
 			__func__, net->name));
 			temp_addr[0] |= 0x02;
@@ -3389,11 +3605,13 @@
 		net->dev_addr[3], net->dev_addr[4], net->dev_addr[5]);
 
 #if defined(SOFTAP) && defined(CONFIG_WIRELESS_EXT) && !defined(WL_CFG80211)
+	if (ifidx == 0)
 		wl_iw_iscan_set_scan_broadcast_prep(net, 1);
 #endif
 
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
+	/* If P2P is enabled, then do the semaphore up after p2p0 registration */
 	if (ifidx == 0) {
 		up(&dhd_registration_sem);
 	}
@@ -3473,6 +3691,7 @@
 	}
 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
 
+
 #if defined(CONFIG_WIRELESS_EXT)
 	if (dhd->dhd_state & DHD_ATTACH_STATE_WL_ATTACH) {
 		/* Detatch and unlink in the iw */
@@ -3480,7 +3699,11 @@
 	}
 #endif /* defined(CONFIG_WIRELESS_EXT) */
 
-	if (&dhd->thr_sysioc_ctl.thr_pid >= 0) {
+	dhd->thr_sysioc_ctl.terminated = TRUE;
+	up(&dhd->mac_ioc_sema);
+	LOCK_TRACE(("released mac_sema & stop thr_sysioc_ctl) \n"));
+
+	if (dhd->thr_sysioc_ctl.thr_pid >= 0) {
 		PROC_STOP(&dhd->thr_sysioc_ctl);
 	}
 
@@ -3514,6 +3737,7 @@
 			}
 			MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
 			dhd->iflist[0] = NULL;
+
 		}
 	}
 
@@ -3547,14 +3771,16 @@
 
 #ifdef WL_CFG80211
 	if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
-		wl_cfg80211_detach();
+		wl_cfg80211_detach(NULL);
 		dhd_monitor_uninit();
 	}
 #endif
 
+
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
-		unregister_pm_notifier(&dhd_sleep_pm_notifier);
+		unregister_pm_notifier(&dhd->pm_notifier);
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
+	/* && defined(CONFIG_PM_SLEEP) */
 
 	if (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) {
 #ifdef CONFIG_HAS_WAKELOCK
@@ -3583,6 +3809,17 @@
 {
 	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
 
+	LOCK_TRACE(("%s: grabing mac_ioc_sema ...  \n", __FUNCTION__));
+
+	ASSERT(g_dhd != NULL);
+
+	if (g_dhd && down_interruptible(&g_dhd->mac_ioc_sema) == 0) {
+		LOCK_TRACE(("%s: GOT mac_ioc_sema  \n", __FUNCTION__));
+	} else {
+		DHD_ERROR(("%s, didn't get  mac _sema,"
+			" interrupted by sig)\n", __FUNCTION__));
+	}
+
 	dhd_bus_unregister();
 
 #if defined(CONFIG_WIFI_CONTROL_FUNC)
@@ -3653,18 +3890,18 @@
 		}
 #endif
 #if defined(WL_CFG80211)
-	error = wl_android_post_init();
+	wl_android_post_init();
 #endif
 
 	return error;
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 fail_2:
 	dhd_bus_unregister();
 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
 fail_1:
 #if defined(CONFIG_WIFI_CONTROL_FUNC)
 	wl_android_wifictrl_func_del();
-#endif 
+#endif
 
 	/* Call customer gpio to turn off power with WL_REG_ON signal */
 	dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
@@ -3672,7 +3909,11 @@
 	return error;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 late_initcall(dhd_module_init);
+#else
+module_init(dhd_module_init);
+#endif
 module_exit(dhd_module_cleanup);
 
 /*
@@ -3915,7 +4156,7 @@
 	dhd_os_sdunlock(pub);
 }
 
-#if defined(DHD_USE_STATIC_BUF)
+#if defined(CONFIG_DHD_USE_STATIC_BUF)
 uint8* dhd_os_prealloc(void *osh, int section, uint size)
 {
 	return (uint8*)wl_android_prealloc(section, size);
@@ -4122,17 +4363,11 @@
 int
 dhd_dev_reset(struct net_device *dev, uint8 flag)
 {
-	int ret;
-
 	dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 
-	ret = dhd_bus_devreset(&dhd->pub, flag);
-	if (ret) {
-		DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
-		return ret;
-	}
+	dhd_bus_devreset(&dhd->pub, flag);
 
-	return ret;
+	return 1;
 }
 
 int net_os_set_suspend_disable(struct net_device *dev, int val)
@@ -4311,7 +4546,7 @@
 
 static void dhd_net_if_lock_local(dhd_info_t *dhd)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
 	if (dhd)
 		mutex_lock(&dhd->dhd_net_if_mutex);
 #endif
@@ -4319,7 +4554,7 @@
 
 static void dhd_net_if_unlock_local(dhd_info_t *dhd)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
 	if (dhd)
 		mutex_unlock(&dhd->dhd_net_if_mutex);
 #endif
@@ -4387,7 +4622,7 @@
 
 	/* open file to write */
 	fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
-	if (!fp) {
+	if (IS_ERR(fp)) {
 		printf("%s: open file error\n", __FUNCTION__);
 		ret = -1;
 		goto exit;
@@ -4400,7 +4635,7 @@
 	/* free buf before return */
 	MFREE(dhd->osh, buf, size);
 	/* close file before return */
-	if (fp)
+	if (!IS_ERR(fp))
 		filp_close(fp, current->files);
 	/* restore previous address limit */
 	set_fs(old_fs);
@@ -4529,16 +4764,6 @@
 #endif
 	return 0;
 }
-
-int dhd_os_check_if_up(void *dhdp)
-{
-	dhd_pub_t *pub = (dhd_pub_t *)dhdp;
-
-	if (!pub)
-		return 0;
-	return pub->up;
-}
-
 int net_os_wake_unlock(struct net_device *dev)
 {
 	dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
@@ -4549,6 +4774,14 @@
 	return ret;
 }
 
+int dhd_os_check_if_up(void *dhdp)
+{
+	dhd_pub_t *pub = (dhd_pub_t *)dhdp;
+
+	if (!pub)
+		return 0;
+	return pub->up;
+}
 int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd)
 {
 	int ifidx;
diff --git a/drivers/net/wireless/bcmdhd/dhd_linux_sched.c b/drivers/net/wireless/bcmdhd/dhd_linux_sched.c
index aadd122..4b54708 100644
--- a/drivers/net/wireless/bcmdhd/dhd_linux_sched.c
+++ b/drivers/net/wireless/bcmdhd/dhd_linux_sched.c
@@ -2,13 +2,13 @@
  * Expose some of the kernel scheduler routines
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_linux_sched.c,v 1.3 2009-04-10 04:14:49 Exp $
+ * $Id: dhd_linux_sched.c 279742 2011-08-25 17:24:48Z $
  */
 #include <linux/kernel.h>
 #include <linux/module.h>
diff --git a/drivers/net/wireless/bcmdhd/dhd_proto.h b/drivers/net/wireless/bcmdhd/dhd_proto.h
index e0a54ad..0fbdc1f 100644
--- a/drivers/net/wireless/bcmdhd/dhd_proto.h
+++ b/drivers/net/wireless/bcmdhd/dhd_proto.h
@@ -5,13 +5,13 @@
  * DHD OS, bus, and protocol modules.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_proto.h,v 1.8.10.6 2010-12-22 23:47:24 Exp $
+ * $Id: dhd_proto.h 275786 2011-08-04 22:42:42Z $
  */
 
 #ifndef _dhd_proto_h_
@@ -34,7 +34,7 @@
 #include <wlioctl.h>
 
 #ifndef IOCTL_RESP_TIMEOUT
-#define IOCTL_RESP_TIMEOUT  20000 /* In milli second */
+#define IOCTL_RESP_TIMEOUT  2000 /* In milli second */
 #endif
 
 /*
diff --git a/drivers/net/wireless/bcmdhd/dhd_sdio.c b/drivers/net/wireless/bcmdhd/dhd_sdio.c
index 2930115..81784b3 100644
--- a/drivers/net/wireless/bcmdhd/dhd_sdio.c
+++ b/drivers/net/wireless/bcmdhd/dhd_sdio.c
@@ -2,13 +2,13 @@
  * DHD Bus Module for SDIO
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -380,9 +380,10 @@
 /* Try doing readahead */
 static bool dhd_readahead;
 
+
 /* To check if there's window offered */
 #define DATAOK(bus) \
-	(((uint8)(bus->tx_max - bus->tx_seq) > 2) && \
+	(((uint8)(bus->tx_max - bus->tx_seq) > 1) && \
 	(((uint8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
 
 /* To check if there's window offered for ctrl frame */
@@ -851,8 +852,10 @@
 		                 SBSDIO_FORCE_HW_CLKREQ_OFF, NULL);
 
 		/* Isolate the bus */
-		bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-		                 SBSDIO_DEVCTL_PADS_ISO, NULL);
+		if (bus->sih->chip != BCM4329_CHIP_ID && bus->sih->chip != BCM4319_CHIP_ID) {
+			bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
+				SBSDIO_DEVCTL_PADS_ISO, NULL);
+		}
 
 		/* Change state */
 		bus->sleeping = TRUE;
@@ -1520,7 +1523,7 @@
 #ifdef DHD_DEBUG
 	IOV_CHECKDIED,
 	IOV_SERIALCONS,
-#endif
+#endif /* DHD_DEBUG */
 	IOV_DOWNLOAD,
 	IOV_SOCRAM_STATE,
 	IOV_FORCEEVEN,
@@ -2199,7 +2202,7 @@
 
 	return (int_val & CC_PLL_CHIPCTRL_SERIAL_ENAB);
 }
-#endif 
+#endif
 
 static int
 dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, uint32 actionid, const char *name,
@@ -3058,6 +3061,8 @@
 	bus->rxskip = FALSE;
 	bus->tx_seq = bus->rx_seq = 0;
 
+	bus->tx_max = 4;
+
 	if (enforce_mutex)
 		dhd_os_sdunlock(bus->dhd);
 }
@@ -4713,7 +4718,7 @@
 #else
 	bus->dpc_sched = TRUE;
 	dhd_sched_dpc(bus->dhd);
-#endif 
+#endif
 
 }
 
@@ -5592,6 +5597,22 @@
 
 	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
 
+	if (bus->sih->chip == BCM4330_CHIP_ID) {
+		int chiprev = bus->sih->chiprev;
+		char *p_fw;
+
+		/* If B1 chip, switch firmware */
+		if (chiprev == 3) {
+			if (strstr(fw_path, "apsta") == NULL) {
+				p_fw = "/system/etc/firmware/fw_bcm4330b1.bin";
+				strcpy(fw_path, p_fw);
+			} else{
+				p_fw = "/system/etc/firmware/fw_bcm4330b1_apsta.bin";
+				strcpy(fw_path, p_fw);
+			}
+		}
+	}
+
 #ifdef SDTEST
 	dhdsdio_pktgen_init(bus);
 #endif /* SDTEST */
@@ -5736,7 +5757,7 @@
 		return;
 
 	if (bus->rxbuf) {
-#ifndef DHD_USE_STATIC_BUF
+#ifndef CONFIG_DHD_USE_STATIC_BUF
 		MFREE(osh, bus->rxbuf, bus->rxblen);
 #endif
 		bus->rxctl = bus->rxbuf = NULL;
@@ -5744,7 +5765,7 @@
 	}
 
 	if (bus->databuf) {
-#ifndef DHD_USE_STATIC_BUF
+#ifndef CONFIG_DHD_USE_STATIC_BUF
 		MFREE(osh, bus->databuf, MAX_DATA_BUF);
 #endif
 		bus->databuf = NULL;
@@ -6234,7 +6255,7 @@
 #if !defined(IGNORE_ETH0_DOWN)
 						/* Restore flow control  */
 						dhd_txflowcontrol(bus->dhd, ALL_INTERFACES, OFF);
-#endif 
+#endif
 						dhd_os_wd_timer(dhdp, dhd_watchdog_ms);
 
 						DHD_TRACE(("%s: WLAN ON DONE\n", __FUNCTION__));
diff --git a/drivers/net/wireless/bcmdhd/dhd_wlfc.h b/drivers/net/wireless/bcmdhd/dhd_wlfc.h
index 59d018b..fdc4b09 100644
--- a/drivers/net/wireless/bcmdhd/dhd_wlfc.h
+++ b/drivers/net/wireless/bcmdhd/dhd_wlfc.h
@@ -1,12 +1,12 @@
 /*
 * Copyright (C) 1999-2011, Broadcom Corporation
-* 
+*
 *         Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2 (the "GPL"),
 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
 * following added to such license:
-* 
+*
 *      As a special exception, the copyright holders of this software give you
 * permission to link this software with independent modules, and to copy and
 * distribute the resulting executable under terms of your choice, provided that
@@ -14,11 +14,11 @@
 * the license of that module.  An independent module is a module which is not
 * derived from this software.  The special exception does not apply to any
 * modifications of the software.
-* 
+*
 *      Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a license
 * other than the GPL, without Broadcom's express prior written consent.
-* $Id: dhd_wlfc.h,v 1.1.8.1 2010-09-09 22:41:08 Exp $
+* $Id: dhd_wlfc.h 280556 2011-08-30 01:59:16Z $
 *
 */
 #ifndef __wlfc_host_driver_definitions_h__
@@ -201,6 +201,7 @@
 #define WLFC_FCMODE_IMPLIED_CREDIT		1
 #define WLFC_FCMODE_EXPLICIT_CREDIT		2
 
+/* How long to defer borrowing in milliseconds */
 #define WLFC_BORROW_DEFER_PERIOD_MS 100
 
 /* Mask to represent available ACs (note: BC/MC is ignored */
@@ -261,6 +262,7 @@
 
 	/* Timestamp to compute how long to defer borrowing for */
 	uint32  borrow_defer_timestamp;
+
 } athost_wl_status_info_t;
 
 #endif /* __wlfc_host_driver_definitions_h__ */
diff --git a/drivers/net/wireless/bcmdhd/dngl_stats.h b/drivers/net/wireless/bcmdhd/dngl_stats.h
index 9cdf718..5ef9661 100644
--- a/drivers/net/wireless/bcmdhd/dngl_stats.h
+++ b/drivers/net/wireless/bcmdhd/dngl_stats.h
@@ -3,13 +3,13 @@
  * ports
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dngl_stats.h,v 1.5 2008-06-02 16:56:20 Exp $
+ * $Id: dngl_stats.h,v 1.5 2008-06-02 16:56:20 $
  */
 
 #ifndef _dngl_stats_h_
diff --git a/drivers/net/wireless/bcmdhd/dngl_wlhdr.h b/drivers/net/wireless/bcmdhd/dngl_wlhdr.h
index 8b39b9e..3d22c47 100644
--- a/drivers/net/wireless/bcmdhd/dngl_wlhdr.h
+++ b/drivers/net/wireless/bcmdhd/dngl_wlhdr.h
@@ -2,13 +2,13 @@
  * Dongle WL Header definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dngl_wlhdr.h,v 1.1 2009-01-08 01:21:12 Exp $
+ * $Id: dngl_wlhdr.h,v 1.1 2009-01-08 01:21:12 $
  */
 
 #ifndef _dngl_wlhdr_h_
diff --git a/drivers/net/wireless/bcmdhd/hndpmu.c b/drivers/net/wireless/bcmdhd/hndpmu.c
index b9586e4..0e5f3dc 100644
--- a/drivers/net/wireless/bcmdhd/hndpmu.c
+++ b/drivers/net/wireless/bcmdhd/hndpmu.c
@@ -3,13 +3,13 @@
  * of the SiliconBackplane-based Broadcom chips.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: hndpmu.c,v 1.228.2.56 2011-02-11 22:49:07 Exp $
+ * $Id: hndpmu.c 279296 2011-08-23 23:17:20Z $
  */
 
 #include <typedefs.h>
diff --git a/drivers/net/wireless/bcmdhd/include/Makefile b/drivers/net/wireless/bcmdhd/include/Makefile
deleted file mode 100644
index c07266f..0000000
--- a/drivers/net/wireless/bcmdhd/include/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/bin/bash
-#
-# This script serves following purpose:
-#
-# 1. It generates native version information by querying
-#    automerger maintained database to see where src/include
-#    came from
-# 2. For select components, as listed in compvers.sh
-#    it generates component version files
-#
-# Copyright 2005, Broadcom, Inc.
-#
-# $Id: Makefile 241702 2011-02-19 00:41:03Z automrgr $
-#
-
-SRCBASE := ..
-
-TARGETS := epivers.h
-
-ifdef VERBOSE
-export VERBOSE
-endif
-
-all release: epivers compvers
-
-# Generate epivers.h for native branch version
-epivers:
-	bash epivers.sh
-
-# Generate epivers.h for native branch version
-compvers:
-	@if [ -s "compvers.sh" ]; then \
-		echo "Generating component versions, if any"; \
-		bash compvers.sh; \
-	else \
-		echo "Skipping component version generation"; \
-	fi
-
-# Generate epivers.h for native branch version
-clean_compvers:
-	@if [ -s "compvers.sh" ]; then \
-		echo "bash compvers.sh clean"; \
-		bash compvers.sh clean; \
-	else \
-		echo "Skipping component version clean"; \
-	fi
-
-clean:
-	rm -f $(TARGETS) *.prev
-
-clean_all: clean clean_compvers
-
-.PHONY: all release clean epivers compvers clean_compvers
diff --git a/drivers/net/wireless/bcmdhd/include/aidmp.h b/drivers/net/wireless/bcmdhd/include/aidmp.h
index 375df44..7832b7a 100644
--- a/drivers/net/wireless/bcmdhd/include/aidmp.h
+++ b/drivers/net/wireless/bcmdhd/include/aidmp.h
@@ -2,13 +2,13 @@
  * Broadcom AMBA Interconnect definitions.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: aidmp.h,v 13.4.14.1 2010-03-09 18:40:06 Exp $
+ * $Id: aidmp.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -104,7 +104,7 @@
 #define	AD_SZ_SZD		0x00000030
 #define	AD_AG32			0x00000008
 #define	AD_ADDR_ALIGN		0x00000fff
-#define	AD_SZ_BASE		0x00001000	
+#define	AD_SZ_BASE		0x00001000
 
 
 #define	SD_SZ_MASK		0xfffff000
@@ -115,124 +115,124 @@
 #ifndef _LANGUAGE_ASSEMBLY
 
 typedef volatile struct _aidmp {
-	uint32	oobselina30;	
-	uint32	oobselina74;	
+	uint32	oobselina30;
+	uint32	oobselina74;
 	uint32	PAD[6];
-	uint32	oobselinb30;	
-	uint32	oobselinb74;	
+	uint32	oobselinb30;
+	uint32	oobselinb74;
 	uint32	PAD[6];
-	uint32	oobselinc30;	
-	uint32	oobselinc74;	
+	uint32	oobselinc30;
+	uint32	oobselinc74;
 	uint32	PAD[6];
-	uint32	oobselind30;	
-	uint32	oobselind74;	
+	uint32	oobselind30;
+	uint32	oobselind74;
 	uint32	PAD[38];
-	uint32	oobselouta30;	
-	uint32	oobselouta74;	
+	uint32	oobselouta30;
+	uint32	oobselouta74;
 	uint32	PAD[6];
-	uint32	oobseloutb30;	
-	uint32	oobseloutb74;	
+	uint32	oobseloutb30;
+	uint32	oobseloutb74;
 	uint32	PAD[6];
-	uint32	oobseloutc30;	
-	uint32	oobseloutc74;	
+	uint32	oobseloutc30;
+	uint32	oobseloutc74;
 	uint32	PAD[6];
-	uint32	oobseloutd30;	
-	uint32	oobseloutd74;	
+	uint32	oobseloutd30;
+	uint32	oobseloutd74;
 	uint32	PAD[38];
-	uint32	oobsynca;	
-	uint32	oobseloutaen;	
+	uint32	oobsynca;
+	uint32	oobseloutaen;
 	uint32	PAD[6];
-	uint32	oobsyncb;	
-	uint32	oobseloutben;	
+	uint32	oobsyncb;
+	uint32	oobseloutben;
 	uint32	PAD[6];
-	uint32	oobsyncc;	
-	uint32	oobseloutcen;	
+	uint32	oobsyncc;
+	uint32	oobseloutcen;
 	uint32	PAD[6];
-	uint32	oobsyncd;	
-	uint32	oobseloutden;	
+	uint32	oobsyncd;
+	uint32	oobseloutden;
 	uint32	PAD[38];
-	uint32	oobaextwidth;	
-	uint32	oobainwidth;	
-	uint32	oobaoutwidth;	
+	uint32	oobaextwidth;
+	uint32	oobainwidth;
+	uint32	oobaoutwidth;
 	uint32	PAD[5];
-	uint32	oobbextwidth;	
-	uint32	oobbinwidth;	
-	uint32	oobboutwidth;	
+	uint32	oobbextwidth;
+	uint32	oobbinwidth;
+	uint32	oobboutwidth;
 	uint32	PAD[5];
-	uint32	oobcextwidth;	
-	uint32	oobcinwidth;	
-	uint32	oobcoutwidth;	
+	uint32	oobcextwidth;
+	uint32	oobcinwidth;
+	uint32	oobcoutwidth;
 	uint32	PAD[5];
-	uint32	oobdextwidth;	
-	uint32	oobdinwidth;	
-	uint32	oobdoutwidth;	
+	uint32	oobdextwidth;
+	uint32	oobdinwidth;
+	uint32	oobdoutwidth;
 	uint32	PAD[37];
-	uint32	ioctrlset;	
-	uint32	ioctrlclear;	
-	uint32	ioctrl;		
+	uint32	ioctrlset;
+	uint32	ioctrlclear;
+	uint32	ioctrl;
 	uint32	PAD[61];
-	uint32	iostatus;	
+	uint32	iostatus;
 	uint32	PAD[127];
-	uint32	ioctrlwidth;	
-	uint32	iostatuswidth;	
+	uint32	ioctrlwidth;
+	uint32	iostatuswidth;
 	uint32	PAD[62];
-	uint32	resetctrl;	
-	uint32	resetstatus;	
-	uint32	resetreadid;	
-	uint32	resetwriteid;	
+	uint32	resetctrl;
+	uint32	resetstatus;
+	uint32	resetreadid;
+	uint32	resetwriteid;
 	uint32	PAD[60];
-	uint32	errlogctrl;	
-	uint32	errlogdone;	
-	uint32	errlogstatus;	
-	uint32	errlogaddrlo;	
-	uint32	errlogaddrhi;	
-	uint32	errlogid;	
-	uint32	errloguser;	
-	uint32	errlogflags;	
+	uint32	errlogctrl;
+	uint32	errlogdone;
+	uint32	errlogstatus;
+	uint32	errlogaddrlo;
+	uint32	errlogaddrhi;
+	uint32	errlogid;
+	uint32	errloguser;
+	uint32	errlogflags;
 	uint32	PAD[56];
-	uint32	intstatus;	
+	uint32	intstatus;
 	uint32	PAD[127];
-	uint32	config;		
+	uint32	config;
 	uint32	PAD[63];
-	uint32	itcr;		
+	uint32	itcr;
 	uint32	PAD[3];
-	uint32	itipooba;	
-	uint32	itipoobb;	
-	uint32	itipoobc;	
-	uint32	itipoobd;	
+	uint32	itipooba;
+	uint32	itipoobb;
+	uint32	itipoobc;
+	uint32	itipoobd;
 	uint32	PAD[4];
-	uint32	itipoobaout;	
-	uint32	itipoobbout;	
-	uint32	itipoobcout;	
-	uint32	itipoobdout;	
+	uint32	itipoobaout;
+	uint32	itipoobbout;
+	uint32	itipoobcout;
+	uint32	itipoobdout;
 	uint32	PAD[4];
-	uint32	itopooba;	
-	uint32	itopoobb;	
-	uint32	itopoobc;	
-	uint32	itopoobd;	
+	uint32	itopooba;
+	uint32	itopoobb;
+	uint32	itopoobc;
+	uint32	itopoobd;
 	uint32	PAD[4];
-	uint32	itopoobain;	
-	uint32	itopoobbin;	
-	uint32	itopoobcin;	
-	uint32	itopoobdin;	
+	uint32	itopoobain;
+	uint32	itopoobbin;
+	uint32	itopoobcin;
+	uint32	itopoobdin;
 	uint32	PAD[4];
-	uint32	itopreset;	
+	uint32	itopreset;
 	uint32	PAD[15];
-	uint32	peripherialid4;	
-	uint32	peripherialid5;	
-	uint32	peripherialid6;	
-	uint32	peripherialid7;	
-	uint32	peripherialid0;	
-	uint32	peripherialid1;	
-	uint32	peripherialid2;	
-	uint32	peripherialid3;	
-	uint32	componentid0;	
-	uint32	componentid1;	
-	uint32	componentid2;	
-	uint32	componentid3;	
+	uint32	peripherialid4;
+	uint32	peripherialid5;
+	uint32	peripherialid6;
+	uint32	peripherialid7;
+	uint32	peripherialid0;
+	uint32	peripherialid1;
+	uint32	peripherialid2;
+	uint32	peripherialid3;
+	uint32	componentid0;
+	uint32	componentid1;
+	uint32	componentid2;
+	uint32	componentid3;
 } aidmp_t;
 
-#endif 
+#endif
 
 
 #define	OOB_BUSCONFIG		0x020
@@ -374,4 +374,4 @@
 #define OOB_SEL_OUTEN_B_5	15
 #define OOB_SEL_OUTEN_B_6	23
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmcdc.h b/drivers/net/wireless/bcmdhd/include/bcmcdc.h
index ce45c50..68449e4 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmcdc.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmcdc.h
@@ -5,13 +5,13 @@
  * Definitions subject to change without notice.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmcdc.h,v 13.25.10.3 2010-12-22 23:47:26 Exp $
+ * $Id: bcmcdc.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef _bcmcdc_h_
@@ -32,34 +32,34 @@
 #include <proto/ethernet.h>
 
 typedef struct cdc_ioctl {
-	uint32 cmd;      
-	uint32 len;      
-	uint32 flags;    
-	uint32 status;   
+	uint32 cmd;
+	uint32 len;
+	uint32 flags;
+	uint32 status;
 } cdc_ioctl_t;
 
 
 #define CDC_MAX_MSG_SIZE   ETHER_MAX_LEN
 
 
-#define CDCL_IOC_OUTLEN_MASK   0x0000FFFF  
-					   
+#define CDCL_IOC_OUTLEN_MASK   0x0000FFFF
+
 #define CDCL_IOC_OUTLEN_SHIFT  0
-#define CDCL_IOC_INLEN_MASK    0xFFFF0000   
+#define CDCL_IOC_INLEN_MASK    0xFFFF0000
 #define CDCL_IOC_INLEN_SHIFT   16
 
 
-#define CDCF_IOC_ERROR		0x01	
-#define CDCF_IOC_SET		0x02	
-#define CDCF_IOC_OVL_IDX_MASK	0x3c	
-#define CDCF_IOC_OVL_RSV	0x40	
-#define CDCF_IOC_OVL		0x80	
-#define CDCF_IOC_ACTION_MASK	0xfe	
-#define CDCF_IOC_ACTION_SHIFT	1	
-#define CDCF_IOC_IF_MASK	0xF000	
+#define CDCF_IOC_ERROR		0x01
+#define CDCF_IOC_SET		0x02
+#define CDCF_IOC_OVL_IDX_MASK	0x3c
+#define CDCF_IOC_OVL_RSV	0x40
+#define CDCF_IOC_OVL		0x80
+#define CDCF_IOC_ACTION_MASK	0xfe
+#define CDCF_IOC_ACTION_SHIFT	1
+#define CDCF_IOC_IF_MASK	0xF000
 #define CDCF_IOC_IF_SHIFT	12
-#define CDCF_IOC_ID_MASK	0xFFFF0000	
-#define CDCF_IOC_ID_SHIFT	16		
+#define CDCF_IOC_ID_MASK	0xFFFF0000
+#define CDCF_IOC_ID_SHIFT	16
 
 #define CDC_IOC_IF_IDX(flags)	(((flags) & CDCF_IOC_IF_MASK) >> CDCF_IOC_IF_SHIFT)
 #define CDC_IOC_ID(flags)	(((flags) & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT)
@@ -73,23 +73,23 @@
 
 #define	BDC_HEADER_LEN		4
 
-#define BDC_PROTO_VER_1		1	
-#define BDC_PROTO_VER		2	
+#define BDC_PROTO_VER_1		1
+#define BDC_PROTO_VER		2
 
-#define BDC_FLAG_VER_MASK	0xf0	
-#define BDC_FLAG_VER_SHIFT	4	
+#define BDC_FLAG_VER_MASK	0xf0
+#define BDC_FLAG_VER_SHIFT	4
 
-#define BDC_FLAG__UNUSED	0x03	
-#define BDC_FLAG_SUM_GOOD	0x04	
-#define BDC_FLAG_SUM_NEEDED	0x08	
+#define BDC_FLAG__UNUSED	0x03
+#define BDC_FLAG_SUM_GOOD	0x04
+#define BDC_FLAG_SUM_NEEDED	0x08
 
 #define BDC_PRIORITY_MASK	0x7
 
-#define BDC_FLAG2_FC_FLAG	0x10	
-									
-#define BDC_PRIORITY_FC_SHIFT	4		
+#define BDC_FLAG2_FC_FLAG	0x10
 
-#define BDC_FLAG2_IF_MASK	0x0f	
+#define BDC_PRIORITY_FC_SHIFT	4
+
+#define BDC_FLAG2_IF_MASK	0x0f
 #define BDC_FLAG2_IF_SHIFT	0
 #define BDC_FLAG2_PAD_MASK		0xf0
 #define BDC_FLAG_PAD_MASK		0x03
@@ -112,10 +112,10 @@
 	((hdr)->flags2 = (((hdr)->flags2 & ~BDC_FLAG2_IF_MASK) | ((idx) << BDC_FLAG2_IF_SHIFT)))
 
 struct bdc_header {
-	uint8	flags;			
-	uint8	priority;		
+	uint8	flags;
+	uint8	priority;
 	uint8	flags2;
 	uint8	dataOffset;
 };
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmdefs.h b/drivers/net/wireless/bcmdhd/include/bcmdefs.h
index da1fd5e..8e460b4 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmdefs.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmdefs.h
@@ -2,13 +2,13 @@
  * Misc system wide definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmdefs.h,v 13.68.2.8 2011-01-08 04:04:19 Exp $
+ * $Id: bcmdefs.h 279291 2011-08-23 23:10:02Z $
  */
 
 
@@ -30,12 +30,26 @@
 
 
 
+
+#define BCM_REFERENCE(data)	((void)(data))
+
+
+
 #define bcmreclaimed 		0
 #define _data	_data
 #define _fn	_fn
+#define BCMPREATTACHDATA(_data)	_data
+#define BCMPREATTACHFN(_fn)	_fn
 #define _data	_data
 #define _fn		_fn
 #define _fn	_fn
+#define	BCMNMIATTACHFN(_fn)	_fn
+#define	BCMNMIATTACHDATA(_data)	_data
+#define BCMOVERLAY0DATA(_sym)	_sym
+#define BCMOVERLAY0FN(_fn)	_fn
+#define BCMOVERLAY1DATA(_sym)	_sym
+#define BCMOVERLAY1FN(_fn)	_fn
+#define BCMOVERLAYERRFN(_fn)	_fn
 #define CONST	const
 #define BCMFASTPATH
 
@@ -43,19 +57,40 @@
 
 
 #define _data	_data
+#define BCMROMDAT_NAME(_data)	_data
 #define _fn		_fn
 #define _fn	_fn
 #define STATIC	static
+#define BCMROMDAT_ARYSIZ(data)	ARRAYSIZE(data)
+#define BCMROMDAT_SIZEOF(data)	sizeof(data)
+#define BCMROMDAT_APATCH(data)
+#define BCMROMDAT_SPATCH(data)
 
 
-#define	SI_BUS			0	
-#define	PCI_BUS			1	
-#define	PCMCIA_BUS		2	
-#define SDIO_BUS		3	
-#define JTAG_BUS		4	
-#define USB_BUS			5	
-#define SPI_BUS			6	
-#define RPC_BUS			7	
+
+#define OVERLAY_INLINE
+#define OSTATIC			static
+#define BCMOVERLAYDATA(_ovly, _sym)	_sym
+#define BCMOVERLAYFN(_ovly, _fn)	_fn
+#define BCMOVERLAYERRFN(_fn)	_fn
+#define BCMROMOVERLAYDATA(_ovly, _data)	_data
+#define BCMROMOVERLAYFN(_ovly, _fn)		_fn
+#define BCMATTACHOVERLAYDATA(_ovly, _sym)	_sym
+#define BCMATTACHOVERLAYFN(_ovly, _fn)		_fn
+#define BCMINITOVERLAYDATA(_ovly, _sym)		_sym
+#define BCMINITOVERLAYFN(_ovly, _fn)		_fn
+#define BCMUNINITOVERLAYFN(_ovly, _fn)		_fn
+
+
+
+#define	SI_BUS			0
+#define	PCI_BUS			1
+#define	PCMCIA_BUS		2
+#define SDIO_BUS		3
+#define JTAG_BUS		4
+#define USB_BUS			5
+#define SPI_BUS			6
+#define RPC_BUS			7
 
 
 #ifdef BCMBUSTYPE
@@ -95,14 +130,14 @@
 #endif
 
 
-#define DMADDR_MASK_32 0x0		
-#define DMADDR_MASK_30 0xc0000000	
-#define DMADDR_MASK_0  0xffffffff	
+#define DMADDR_MASK_32 0x0
+#define DMADDR_MASK_30 0xc0000000
+#define DMADDR_MASK_0  0xffffffff
 
-#define	DMADDRWIDTH_30  30 
-#define	DMADDRWIDTH_32  32 
-#define	DMADDRWIDTH_63  63 
-#define	DMADDRWIDTH_64  64 
+#define	DMADDRWIDTH_30  30
+#define	DMADDRWIDTH_32  32
+#define	DMADDRWIDTH_63  63
+#define	DMADDRWIDTH_64  64
 
 #ifdef BCMDMA64OSL
 typedef struct {
@@ -131,7 +166,7 @@
 	do { \
 		(_pa) = (_val);			\
 	} while (0)
-#endif 
+#endif
 
 
 typedef struct  {
@@ -143,8 +178,8 @@
 
 
 typedef struct {
-	void *oshdmah; 
-	uint origsize; 
+	void *oshdmah;
+	uint origsize;
 	uint nsegs;
 	hnddma_seg_t segs[MAX_DMA_SEGS];
 } hnddma_seg_map_t;
@@ -168,7 +203,7 @@
 
 #if defined(BCMASSERT_LOG)
 #define BCMASSERT_SUPPORT
-#endif 
+#endif
 
 
 #define BITFIELD_MASK(width) \
@@ -182,10 +217,10 @@
 
 #ifdef BCMSMALL
 #undef	BCMSPACE
-#define bcmspace	FALSE	
+#define bcmspace	FALSE
 #else
 #define	BCMSPACE
-#define bcmspace	TRUE	
+#define bcmspace	TRUE
 #endif
 
 
@@ -193,4 +228,4 @@
 
 #define LOCATOR_EXTERN static
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmdevs.h b/drivers/net/wireless/bcmdhd/include/bcmdevs.h
index 4f707c0..417338e 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmdevs.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmdevs.h
@@ -2,13 +2,13 @@
  * Broadcom device-specific manifest constants.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmdevs.h,v 13.285.2.39 2011-02-04 05:03:16 Exp $
+ * $Id: bcmdevs.h 290020 2011-10-15 00:57:00Z $
  */
 
 
@@ -31,9 +31,9 @@
 
 #define	VENDOR_EPIGRAM		0xfeda
 #define	VENDOR_BROADCOM		0x14e4
-#define VENDOR_SI_IMAGE		0x1095		
-#define VENDOR_TI		0x104c		
-#define VENDOR_RICOH		0x1180		
+#define VENDOR_SI_IMAGE		0x1095
+#define VENDOR_TI		0x104c
+#define VENDOR_RICOH		0x1180
 #define VENDOR_JMICRON		0x197b
 
 
@@ -54,129 +54,129 @@
 #define BCM_DNGL_BL_PID_43239   0xbd1b
 #define BCM_DNGL_BDC_PID	0x0bdc
 #define BCM_DNGL_JTAG_PID	0x4a44
-#define	BCM4325_D11DUAL_ID	0x431b		
-#define	BCM4325_D11G_ID		0x431c		
-#define	BCM4325_D11A_ID		0x431d		
-#define	BCM4321_D11N_ID		0x4328		
-#define	BCM4321_D11N2G_ID	0x4329		
-#define	BCM4321_D11N5G_ID	0x432a		
-#define BCM4322_D11N_ID		0x432b		
-#define BCM4322_D11N2G_ID	0x432c		
-#define BCM4322_D11N5G_ID	0x432d		
-#define BCM4329_D11N_ID		0x432e		
-#define BCM4329_D11N2G_ID	0x432f		
-#define BCM4329_D11N5G_ID	0x4330		
-#define	BCM4315_D11DUAL_ID	0x4334		
-#define	BCM4315_D11G_ID		0x4335		
-#define	BCM4315_D11A_ID		0x4336		
-#define BCM4319_D11N_ID		0x4337		
-#define BCM4319_D11N2G_ID	0x4338		
-#define BCM4319_D11N5G_ID	0x4339		
-#define BCM43231_D11N2G_ID	0x4340		
-#define BCM43221_D11N2G_ID	0x4341		
-#define BCM43222_D11N_ID	0x4350		
-#define BCM43222_D11N2G_ID	0x4351		
-#define BCM43222_D11N5G_ID	0x4352		
-#define BCM43224_D11N_ID	0x4353		
-#define BCM43224_D11N_ID_VEN1	0x0576		
-#define BCM43226_D11N_ID	0x4354		
-#define BCM43236_D11N_ID	0x4346		
-#define BCM43236_D11N2G_ID	0x4347		
-#define BCM43236_D11N5G_ID	0x4348		
-#define BCM43225_D11N2G_ID	0x4357		
-#define BCM43421_D11N_ID	0xA99D		
-#define BCM4313_D11N2G_ID	0x4727		
-#define BCM4330_D11N_ID         0x4360          
-#define BCM4330_D11N2G_ID       0x4361          
-#define BCM4330_D11N5G_ID       0x4362          
-#define BCM4336_D11N_ID		0x4343		
-#define BCM6362_D11N_ID		0x435f		
-#define BCM4331_D11N_ID		0x4331		
-#define BCM4331_D11N2G_ID	0x4332		
-#define BCM4331_D11N5G_ID	0x4333		
-#define BCM43237_D11N_ID	0x4355		
-#define BCM43237_D11N5G_ID	0x4356		
-#define BCM43227_D11N2G_ID	0x4358		
-#define BCM43228_D11N_ID		0x4359		
-#define BCM43228_D11N5G_ID	0x435a		 
-#define BCM43362_D11N_ID	0x4363		
-#define BCM43239_D11N_ID	0x4370		
+#define	BCM4325_D11DUAL_ID	0x431b
+#define	BCM4325_D11G_ID		0x431c
+#define	BCM4325_D11A_ID		0x431d
+#define	BCM4321_D11N_ID		0x4328
+#define	BCM4321_D11N2G_ID	0x4329
+#define	BCM4321_D11N5G_ID	0x432a
+#define BCM4322_D11N_ID		0x432b
+#define BCM4322_D11N2G_ID	0x432c
+#define BCM4322_D11N5G_ID	0x432d
+#define BCM4329_D11N_ID		0x432e
+#define BCM4329_D11N2G_ID	0x432f
+#define BCM4329_D11N5G_ID	0x4330
+#define	BCM4315_D11DUAL_ID	0x4334
+#define	BCM4315_D11G_ID		0x4335
+#define	BCM4315_D11A_ID		0x4336
+#define BCM4319_D11N_ID		0x4337
+#define BCM4319_D11N2G_ID	0x4338
+#define BCM4319_D11N5G_ID	0x4339
+#define BCM43231_D11N2G_ID	0x4340
+#define BCM43221_D11N2G_ID	0x4341
+#define BCM43222_D11N_ID	0x4350
+#define BCM43222_D11N2G_ID	0x4351
+#define BCM43222_D11N5G_ID	0x4352
+#define BCM43224_D11N_ID	0x4353
+#define BCM43224_D11N_ID_VEN1	0x0576
+#define BCM43226_D11N_ID	0x4354
+#define BCM43236_D11N_ID	0x4346
+#define BCM43236_D11N2G_ID	0x4347
+#define BCM43236_D11N5G_ID	0x4348
+#define BCM43225_D11N2G_ID	0x4357
+#define BCM43421_D11N_ID	0xA99D
+#define BCM4313_D11N2G_ID	0x4727
+#define BCM4330_D11N_ID         0x4360
+#define BCM4330_D11N2G_ID       0x4361
+#define BCM4330_D11N5G_ID       0x4362
+#define BCM4336_D11N_ID		0x4343
+#define BCM6362_D11N_ID		0x435f
+#define BCM4331_D11N_ID		0x4331
+#define BCM4331_D11N2G_ID	0x4332
+#define BCM4331_D11N5G_ID	0x4333
+#define BCM43237_D11N_ID	0x4355
+#define BCM43237_D11N5G_ID	0x4356
+#define BCM43227_D11N2G_ID	0x4358
+#define BCM43228_D11N_ID		0x4359
+#define BCM43228_D11N5G_ID	0x435a
+#define BCM43362_D11N_ID	0x4363
+#define BCM43239_D11N_ID	0x4370
 
 
-#define SDIOH_FPGA_ID		0x43f2		
-#define SPIH_FPGA_ID		0x43f5		
-#define	BCM4710_DEVICE_ID	0x4710		
-#define BCM27XX_SDIOH_ID	0x2702		
-#define PCIXX21_FLASHMEDIA0_ID	0x8033		
-#define PCIXX21_SDIOH0_ID	0x8034		
-#define PCIXX21_FLASHMEDIA_ID	0x803b		
-#define PCIXX21_SDIOH_ID	0x803c		
-#define R5C822_SDIOH_ID		0x0822		
-#define JMICRON_SDIOH_ID	0x2381		
+#define SDIOH_FPGA_ID		0x43f2
+#define SPIH_FPGA_ID		0x43f5
+#define	BCM4710_DEVICE_ID	0x4710
+#define BCM27XX_SDIOH_ID	0x2702
+#define PCIXX21_FLASHMEDIA0_ID	0x8033
+#define PCIXX21_SDIOH0_ID	0x8034
+#define PCIXX21_FLASHMEDIA_ID	0x803b
+#define PCIXX21_SDIOH_ID	0x803c
+#define R5C822_SDIOH_ID		0x0822
+#define JMICRON_SDIOH_ID	0x2381
 
 
-#define	BCM4306_CHIP_ID		0x4306		
-#define	BCM4311_CHIP_ID		0x4311		
-#define	BCM43111_CHIP_ID	43111		
-#define	BCM43112_CHIP_ID	43112		
-#define	BCM4312_CHIP_ID		0x4312		
-#define BCM4313_CHIP_ID		0x4313		
-#define	BCM4315_CHIP_ID		0x4315		
-#define	BCM4318_CHIP_ID		0x4318		
-#define	BCM4319_CHIP_ID		0x4319		
-#define	BCM4320_CHIP_ID		0x4320		
-#define	BCM4321_CHIP_ID		0x4321		
-#define	BCM4322_CHIP_ID		0x4322		
-#define	BCM43221_CHIP_ID	43221		
-#define	BCM43222_CHIP_ID	43222		
-#define	BCM43224_CHIP_ID	43224		
-#define	BCM43225_CHIP_ID	43225		
-#define	BCM43227_CHIP_ID	43227		
-#define	BCM43228_CHIP_ID	43228		
-#define	BCM43226_CHIP_ID	43226		
-#define	BCM43231_CHIP_ID	43231		
-#define	BCM43234_CHIP_ID	43234		
-#define	BCM43235_CHIP_ID	43235		
-#define	BCM43236_CHIP_ID	43236		
-#define	BCM43237_CHIP_ID	43237		
-#define	BCM43238_CHIP_ID	43238		
-#define	BCM43239_CHIP_ID	43239		
-#define	BCM43420_CHIP_ID	43420		
-#define	BCM43421_CHIP_ID	43421		
-#define	BCM43428_CHIP_ID	43428		
-#define	BCM43431_CHIP_ID	43431		
-#define	BCM4325_CHIP_ID		0x4325		
-#define	BCM4328_CHIP_ID		0x4328		
-#define	BCM4329_CHIP_ID		0x4329		
-#define	BCM4331_CHIP_ID		0x4331		
-#define BCM4336_CHIP_ID		0x4336		
-#define BCM43362_CHIP_ID	43362		
-#define BCM4330_CHIP_ID		0x4330		
-#define	BCM4402_CHIP_ID		0x4402		
-#define	BCM4704_CHIP_ID		0x4704		
-#define	BCM4710_CHIP_ID		0x4710		
-#define	BCM4712_CHIP_ID		0x4712		
-#define BCM4785_CHIP_ID		0x4785		
-#define	BCM5350_CHIP_ID		0x5350		
-#define	BCM5352_CHIP_ID		0x5352		
-#define	BCM5354_CHIP_ID		0x5354		
-#define BCM5365_CHIP_ID		0x5365		
+#define	BCM4306_CHIP_ID		0x4306
+#define	BCM4311_CHIP_ID		0x4311
+#define	BCM43111_CHIP_ID	43111
+#define	BCM43112_CHIP_ID	43112
+#define	BCM4312_CHIP_ID		0x4312
+#define BCM4313_CHIP_ID		0x4313
+#define	BCM4315_CHIP_ID		0x4315
+#define	BCM4318_CHIP_ID		0x4318
+#define	BCM4319_CHIP_ID		0x4319
+#define	BCM4320_CHIP_ID		0x4320
+#define	BCM4321_CHIP_ID		0x4321
+#define	BCM4322_CHIP_ID		0x4322
+#define	BCM43221_CHIP_ID	43221
+#define	BCM43222_CHIP_ID	43222
+#define	BCM43224_CHIP_ID	43224
+#define	BCM43225_CHIP_ID	43225
+#define	BCM43227_CHIP_ID	43227
+#define	BCM43228_CHIP_ID	43228
+#define	BCM43226_CHIP_ID	43226
+#define	BCM43231_CHIP_ID	43231
+#define	BCM43234_CHIP_ID	43234
+#define	BCM43235_CHIP_ID	43235
+#define	BCM43236_CHIP_ID	43236
+#define	BCM43237_CHIP_ID	43237
+#define	BCM43238_CHIP_ID	43238
+#define	BCM43239_CHIP_ID	43239
+#define	BCM43420_CHIP_ID	43420
+#define	BCM43421_CHIP_ID	43421
+#define	BCM43428_CHIP_ID	43428
+#define	BCM43431_CHIP_ID	43431
+#define	BCM4325_CHIP_ID		0x4325
+#define	BCM4328_CHIP_ID		0x4328
+#define	BCM4329_CHIP_ID		0x4329
+#define	BCM4331_CHIP_ID		0x4331
+#define BCM4336_CHIP_ID		0x4336
+#define BCM43362_CHIP_ID	43362
+#define BCM4330_CHIP_ID		0x4330
+#define	BCM4402_CHIP_ID		0x4402
+#define	BCM4704_CHIP_ID		0x4704
+#define	BCM4710_CHIP_ID		0x4710
+#define	BCM4712_CHIP_ID		0x4712
+#define BCM4785_CHIP_ID		0x4785
+#define	BCM5350_CHIP_ID		0x5350
+#define	BCM5352_CHIP_ID		0x5352
+#define	BCM5354_CHIP_ID		0x5354
+#define BCM5365_CHIP_ID		0x5365
 
 
-#define	BCM4303_PKG_ID		2		
-#define	BCM4309_PKG_ID		1		
-#define	BCM4712LARGE_PKG_ID	0		
-#define	BCM4712SMALL_PKG_ID	1		
-#define	BCM4712MID_PKG_ID	2		
-#define BCM4328USBD11G_PKG_ID	2		
-#define BCM4328USBDUAL_PKG_ID	3		
-#define BCM4328SDIOD11G_PKG_ID	4		
-#define BCM4328SDIODUAL_PKG_ID	5		
-#define BCM4329_289PIN_PKG_ID	0		
-#define BCM4329_182PIN_PKG_ID	1		
-#define BCM5354E_PKG_ID		1		
-#define HDLSIM5350_PKG_ID	1		
-#define HDLSIM_PKG_ID		14		
-#define HWSIM_PKG_ID		15		
+#define	BCM4303_PKG_ID		2
+#define	BCM4309_PKG_ID		1
+#define	BCM4712LARGE_PKG_ID	0
+#define	BCM4712SMALL_PKG_ID	1
+#define	BCM4712MID_PKG_ID	2
+#define BCM4328USBD11G_PKG_ID	2
+#define BCM4328USBDUAL_PKG_ID	3
+#define BCM4328SDIOD11G_PKG_ID	4
+#define BCM4328SDIODUAL_PKG_ID	5
+#define BCM4329_289PIN_PKG_ID	0
+#define BCM4329_182PIN_PKG_ID	1
+#define BCM5354E_PKG_ID		1
+#define HDLSIM5350_PKG_ID	1
+#define HDLSIM_PKG_ID		14
+#define HWSIM_PKG_ID		15
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmendian.h b/drivers/net/wireless/bcmdhd/include/bcmendian.h
index 04b07ec..da867b8 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmendian.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmendian.h
@@ -2,13 +2,13 @@
  * Byte order utilities
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- *  $Id: bcmendian.h,v 1.36 2009-11-09 05:29:43 Exp $
+ *  $Id: bcmendian.h 275703 2011-08-04 20:20:27Z $
  *
  * This file by default provides proper behavior on little-endian architectures.
  * On big-endian architectures, IL_BIGENDIAN should be defined.
@@ -68,7 +68,7 @@
 #define htol16(i) (i)
 #define HTOL32(i) (i)
 #define htol32(i) (i)
-#endif 
+#endif
 
 #define ltoh16_buf(buf, i)
 #define htol16_buf(buf, i)
@@ -176,7 +176,7 @@
 	_NTOH32_UA(_bytes); \
 })
 
-#else 
+#else
 
 
 static INLINE uint16
@@ -275,5 +275,5 @@
 	return _NTOH32_UA((const uint8 *)bytes);
 }
 
-#endif 
-#endif 
+#endif
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmpcispi.h b/drivers/net/wireless/bcmdhd/include/bcmpcispi.h
deleted file mode 100644
index fd148c5..0000000
--- a/drivers/net/wireless/bcmdhd/include/bcmpcispi.h
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Broadcom PCI-SPI Host Controller Register Definitions
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: bcmpcispi.h,v 13.15.112.1 2010-11-15 18:22:12 Exp $
- */
-#ifndef	_BCM_PCI_SPI_H
-#define	_BCM_PCI_SPI_H
-
-/* cpp contortions to concatenate w/arg prescan */
-#ifndef PAD
-#define	_PADLINE(line)	pad ## line
-#define	_XSTR(line)	_PADLINE(line)
-#define	PAD		_XSTR(__LINE__)
-#endif	/* PAD */
-
-
-typedef volatile struct {
-	uint32 spih_ctrl;		/* 0x00 SPI Control Register */
-	uint32 spih_stat;		/* 0x04 SPI Status Register */
-	uint32 spih_data;		/* 0x08 SPI Data Register, 32-bits wide */
-	uint32 spih_ext;		/* 0x0C SPI Extension Register */
-	uint32 PAD[4];			/* 0x10-0x1F PADDING */
-
-	uint32 spih_gpio_ctrl;		/* 0x20 SPI GPIO Control Register */
-	uint32 spih_gpio_data;		/* 0x24 SPI GPIO Data Register */
-	uint32 PAD[6];			/* 0x28-0x3F PADDING */
-
-	uint32 spih_int_edge;		/* 0x40 SPI Interrupt Edge Register (0=Level, 1=Edge) */
-	uint32 spih_int_pol;		/* 0x44 SPI Interrupt Polarity Register (0=Active Low, */
-							/* 1=Active High) */
-	uint32 spih_int_mask;		/* 0x48 SPI Interrupt Mask */
-	uint32 spih_int_status;		/* 0x4C SPI Interrupt Status */
-	uint32 PAD[4];			/* 0x50-0x5F PADDING */
-
-	uint32 spih_hex_disp;		/* 0x60 SPI 4-digit hex display value */
-	uint32 spih_current_ma;		/* 0x64 SPI SD card current consumption in mA */
-	uint32 PAD[1];			/* 0x68 PADDING */
-	uint32 spih_disp_sel;		/* 0x6c SPI 4-digit hex display mode select (1=current) */
-	uint32 PAD[4];			/* 0x70-0x7F PADDING */
-	uint32 PAD[8];			/* 0x80-0x9F PADDING */
-	uint32 PAD[8];			/* 0xA0-0xBF PADDING */
-	uint32 spih_pll_ctrl;	/* 0xC0 PLL Control Register */
-	uint32 spih_pll_status;	/* 0xC4 PLL Status Register */
-	uint32 spih_xtal_freq;	/* 0xC8 External Clock Frequency in units of 10000Hz */
-	uint32 spih_clk_count;	/* 0xCC External Clock Count Register */
-
-} spih_regs_t;
-
-typedef volatile struct {
-	uint32 cfg_space[0x40];		/* 0x000-0x0FF PCI Configuration Space (Read Only) */
-	uint32 P_IMG_CTRL0;		/* 0x100 PCI Image0 Control Register */
-
-	uint32 P_BA0;			/* 0x104 32 R/W PCI Image0 Base Address register */
-	uint32 P_AM0;			/* 0x108 32 R/W PCI Image0 Address Mask register */
-	uint32 P_TA0;			/* 0x10C 32 R/W PCI Image0 Translation Address register */
-	uint32 P_IMG_CTRL1;		/* 0x110 32 R/W PCI Image1 Control register */
-	uint32 P_BA1;			/* 0x114 32 R/W PCI Image1 Base Address register */
-	uint32 P_AM1;			/* 0x118 32 R/W PCI Image1 Address Mask register */
-	uint32 P_TA1;			/* 0x11C 32 R/W PCI Image1 Translation Address register */
-	uint32 P_IMG_CTRL2;		/* 0x120 32 R/W PCI Image2 Control register */
-	uint32 P_BA2;			/* 0x124 32 R/W PCI Image2 Base Address register */
-	uint32 P_AM2;			/* 0x128 32 R/W PCI Image2 Address Mask register */
-	uint32 P_TA2;			/* 0x12C 32 R/W PCI Image2 Translation Address register */
-	uint32 P_IMG_CTRL3;		/* 0x130 32 R/W PCI Image3 Control register */
-	uint32 P_BA3;			/* 0x134 32 R/W PCI Image3 Base Address register */
-	uint32 P_AM3;			/* 0x138 32 R/W PCI Image3 Address Mask register */
-	uint32 P_TA3;			/* 0x13C 32 R/W PCI Image3 Translation Address register */
-	uint32 P_IMG_CTRL4;		/* 0x140 32 R/W PCI Image4 Control register */
-	uint32 P_BA4;			/* 0x144 32 R/W PCI Image4 Base Address register */
-	uint32 P_AM4;			/* 0x148 32 R/W PCI Image4 Address Mask register */
-	uint32 P_TA4;			/* 0x14C 32 R/W PCI Image4 Translation Address register */
-	uint32 P_IMG_CTRL5;		/* 0x150 32 R/W PCI Image5 Control register */
-	uint32 P_BA5;			/* 0x154 32 R/W PCI Image5 Base Address register */
-	uint32 P_AM5;			/* 0x158 32 R/W PCI Image5 Address Mask register */
-	uint32 P_TA5;			/* 0x15C 32 R/W PCI Image5 Translation Address register */
-	uint32 P_ERR_CS;		/* 0x160 32 R/W PCI Error Control and Status register */
-	uint32 P_ERR_ADDR;		/* 0x164 32 R PCI Erroneous Address register */
-	uint32 P_ERR_DATA;		/* 0x168 32 R PCI Erroneous Data register */
-
-	uint32 PAD[5];			/* 0x16C-0x17F PADDING */
-
-	uint32 WB_CONF_SPC_BAR;		/* 0x180 32 R WISHBONE Configuration Space Base Address */
-	uint32 W_IMG_CTRL1;		/* 0x184 32 R/W WISHBONE Image1 Control register */
-	uint32 W_BA1;			/* 0x188 32 R/W WISHBONE Image1 Base Address register */
-	uint32 W_AM1;			/* 0x18C 32 R/W WISHBONE Image1 Address Mask register */
-	uint32 W_TA1;			/* 0x190 32 R/W WISHBONE Image1 Translation Address reg */
-	uint32 W_IMG_CTRL2;		/* 0x194 32 R/W WISHBONE Image2 Control register */
-	uint32 W_BA2;			/* 0x198 32 R/W WISHBONE Image2 Base Address register */
-	uint32 W_AM2;			/* 0x19C 32 R/W WISHBONE Image2 Address Mask register */
-	uint32 W_TA2;			/* 0x1A0 32 R/W WISHBONE Image2 Translation Address reg */
-	uint32 W_IMG_CTRL3;		/* 0x1A4 32 R/W WISHBONE Image3 Control register */
-	uint32 W_BA3;			/* 0x1A8 32 R/W WISHBONE Image3 Base Address register */
-	uint32 W_AM3;			/* 0x1AC 32 R/W WISHBONE Image3 Address Mask register */
-	uint32 W_TA3;			/* 0x1B0 32 R/W WISHBONE Image3 Translation Address reg */
-	uint32 W_IMG_CTRL4;		/* 0x1B4 32 R/W WISHBONE Image4 Control register */
-	uint32 W_BA4;			/* 0x1B8 32 R/W WISHBONE Image4 Base Address register */
-	uint32 W_AM4;			/* 0x1BC 32 R/W WISHBONE Image4 Address Mask register */
-	uint32 W_TA4;			/* 0x1C0 32 R/W WISHBONE Image4 Translation Address reg */
-	uint32 W_IMG_CTRL5;		/* 0x1C4 32 R/W WISHBONE Image5 Control register */
-	uint32 W_BA5;			/* 0x1C8 32 R/W WISHBONE Image5 Base Address register */
-	uint32 W_AM5;			/* 0x1CC 32 R/W WISHBONE Image5 Address Mask register */
-	uint32 W_TA5;			/* 0x1D0 32 R/W WISHBONE Image5 Translation Address reg */
-	uint32 W_ERR_CS;		/* 0x1D4 32 R/W WISHBONE Error Control and Status reg */
-	uint32 W_ERR_ADDR;		/* 0x1D8 32 R WISHBONE Erroneous Address register */
-	uint32 W_ERR_DATA;		/* 0x1DC 32 R WISHBONE Erroneous Data register */
-	uint32 CNF_ADDR;		/* 0x1E0 32 R/W Configuration Cycle register */
-	uint32 CNF_DATA;		/* 0x1E4 32 R/W Configuration Cycle Generation Data reg */
-
-	uint32 INT_ACK;			/* 0x1E8 32 R Interrupt Acknowledge register */
-	uint32 ICR;			/* 0x1EC 32 R/W Interrupt Control register */
-	uint32 ISR;			/* 0x1F0 32 R/W Interrupt Status register */
-} spih_pciregs_t;
-
-/*
- * PCI Core interrupt enable and status bit definitions.
- */
-
-/* PCI Core ICR Register bit definitions */
-#define PCI_INT_PROP_EN		(1 << 0)	/* Interrupt Propagation Enable */
-#define PCI_WB_ERR_INT_EN	(1 << 1)	/* Wishbone Error Interrupt Enable */
-#define PCI_PCI_ERR_INT_EN	(1 << 2)	/* PCI Error Interrupt Enable */
-#define PCI_PAR_ERR_INT_EN	(1 << 3)	/* Parity Error Interrupt Enable */
-#define PCI_SYS_ERR_INT_EN	(1 << 4)	/* System Error Interrupt Enable */
-#define PCI_SOFTWARE_RESET	(1U << 31)	/* Software reset of the PCI Core. */
-
-
-/* PCI Core ISR Register bit definitions */
-#define PCI_INT_PROP_ST		(1 << 0)	/* Interrupt Propagation Status */
-#define PCI_WB_ERR_INT_ST	(1 << 1)	/* Wishbone Error Interrupt Status */
-#define PCI_PCI_ERR_INT_ST	(1 << 2)	/* PCI Error Interrupt Status */
-#define PCI_PAR_ERR_INT_ST	(1 << 3)	/* Parity Error Interrupt Status */
-#define PCI_SYS_ERR_INT_ST	(1 << 4)	/* System Error Interrupt Status */
-
-
-/* Registers on the Wishbone bus */
-#define SPIH_CTLR_INTR		(1 << 0)	/* SPI Host Controller Core Interrupt */
-#define SPIH_DEV_INTR		(1 << 1)	/* SPI Device Interrupt */
-#define SPIH_WFIFO_INTR		(1 << 2)	/* SPI Tx FIFO Empty Intr (FPGA Rev >= 8) */
-
-/* GPIO Bit definitions */
-#define SPIH_CS			(1 << 0)	/* SPI Chip Select (active low) */
-#define SPIH_SLOT_POWER		(1 << 1)	/* SD Card Slot Power Enable */
-#define SPIH_CARD_DETECT	(1 << 2)	/* SD Card Detect */
-
-/* SPI Status Register Bit definitions */
-#define SPIH_STATE_MASK		0x30		/* SPI Transfer State Machine state mask */
-#define SPIH_STATE_SHIFT	4		/* SPI Transfer State Machine state shift */
-#define SPIH_WFFULL		(1 << 3)	/* SPI Write FIFO Full */
-#define SPIH_WFEMPTY		(1 << 2)	/* SPI Write FIFO Empty */
-#define SPIH_RFFULL		(1 << 1)	/* SPI Read FIFO Full */
-#define SPIH_RFEMPTY		(1 << 0)	/* SPI Read FIFO Empty */
-
-#define SPIH_EXT_CLK		(1U << 31)	/* Use External Clock as PLL Clock source. */
-
-#define SPIH_PLL_NO_CLK		(1 << 1)	/* Set to 1 if the PLL's input clock is lost. */
-#define SPIH_PLL_LOCKED		(1 << 3)	/* Set to 1 when the PLL is locked. */
-
-/* Spin bit loop bound check */
-#define SPI_SPIN_BOUND		0xf4240		/* 1 million */
-
-#endif /* _BCM_PCI_SPI_H */
diff --git a/drivers/net/wireless/bcmdhd/include/bcmperf.h b/drivers/net/wireless/bcmdhd/include/bcmperf.h
index a3985cf..01195ca 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmperf.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmperf.h
@@ -2,13 +2,13 @@
  * Performance counters software interface.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmperf.h,v 13.5 2007-09-14 22:00:59 Exp $
+ * $Id: bcmperf.h 275703 2011-08-04 20:20:27Z $
  */
 /* essai */
 #ifndef _BCMPERF_H_
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdbus.h b/drivers/net/wireless/bcmdhd/include/bcmsdbus.h
index 5fda5e9..fc6a23a 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmsdbus.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmsdbus.h
@@ -3,13 +3,13 @@
  * host controller drivers.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdbus.h,v 13.17.86.2 2010-12-23 01:13:20 Exp $
+ * $Id: bcmsdbus.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_sdio_api_h_
@@ -117,4 +117,12 @@
 
 
 
+extern SDIOH_API_RC sdioh_sleep(sdioh_info_t *si, bool enab);
+
+/* GPIO support */
+extern SDIOH_API_RC sdioh_gpio_init(sdioh_info_t *sd);
+extern bool sdioh_gpioin(sdioh_info_t *sd, uint32 gpio);
+extern SDIOH_API_RC sdioh_gpioouten(sdioh_info_t *sd, uint32 gpio);
+extern SDIOH_API_RC sdioh_gpioout(sdioh_info_t *sd, uint32 gpio, bool enab);
+
 #endif /* _sdio_api_h_ */
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdh.h b/drivers/net/wireless/bcmdhd/include/bcmsdh.h
index 6131d8a..49aa3a5 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmsdh.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmsdh.h
@@ -4,13 +4,13 @@
  *     abstract OS and BUS specific details of SDIO
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -18,12 +18,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdh.h,v 13.46.52.3 2010-10-19 00:41:44 Exp $
+ * $Id: bcmsdh.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_bcmsdh_h_
@@ -208,4 +208,12 @@
 extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev);
 
 
+extern int bcmsdh_sleep(void *sdh, bool enab);
+
+/* GPIO support */
+extern int bcmsdh_gpio_init(void *sd);
+extern bool bcmsdh_gpioin(void *sd, uint32 gpio);
+extern int bcmsdh_gpioouten(void *sd, uint32 gpio);
+extern int bcmsdh_gpioout(void *sd, uint32 gpio, bool enab);
+
 #endif	/* _bcmsdh_h_ */
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdh_sdmmc.h b/drivers/net/wireless/bcmdhd/include/bcmsdh_sdmmc.h
index d188c4e..af72e7b 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmsdh_sdmmc.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmsdh_sdmmc.h
@@ -2,13 +2,13 @@
  * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdh_sdmmc.h,v 13.5.88.1 2010-12-23 01:13:20 Exp $
+ * $Id: bcmsdh_sdmmc.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef __BCMSDH_SDMMC_H__
@@ -82,9 +82,10 @@
 	uint8 		num_funcs;		/* Supported funcs on client */
 	uint32 		com_cis_ptr;
 	uint32 		func_cis_ptr[SDIOD_MAX_IOFUNCS];
-	uint		max_dma_len;
-	uint		max_dma_descriptors;	/* DMA Descriptors supported by this controller. */
-//	SDDMA_DESCRIPTOR	SGList[32];	/* Scatter/Gather DMA List */
+
+#define SDIOH_SDMMC_MAX_SG_ENTRIES	32
+	struct scatterlist sg_list[SDIOH_SDMMC_MAX_SG_ENTRIES];
+	bool		use_rxchain;
 };
 
 /************************************************************
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdpcm.h b/drivers/net/wireless/bcmdhd/include/bcmsdpcm.h
index ee29b5c..eb1165e 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmsdpcm.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmsdpcm.h
@@ -3,13 +3,13 @@
  * Software-specific definitions shared between device and host side
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmsdpcm.h,v 13.4.90.2 2010-05-12 04:14:25 Exp $
+ * $Id: bcmsdpcm.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_bcmsdpcm_h_
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdspi.h b/drivers/net/wireless/bcmdhd/include/bcmsdspi.h
deleted file mode 100644
index 0bff355..0000000
--- a/drivers/net/wireless/bcmdhd/include/bcmsdspi.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * SD-SPI Protocol Conversion - BCMSDH->SPI Translation Layer
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: bcmsdspi.h,v 13.11.86.1 2010-11-15 18:14:56 Exp $
- */
-#ifndef	_BCM_SD_SPI_H
-#define	_BCM_SD_SPI_H
-
-/* global msglevel for debug messages - bitvals come from sdiovar.h */
-
-#define sd_err(x)
-#define sd_trace(x)
-#define sd_info(x)
-#define sd_debug(x)
-#define sd_data(x)
-#define sd_ctrl(x)
-
-#define sd_log(x)
-
-#define SDIOH_ASSERT(exp) \
-	do { if (!(exp)) \
-		printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
-	} while (0)
-
-#define BLOCK_SIZE_4318 64
-#define BLOCK_SIZE_4328 512
-
-/* internal return code */
-#define SUCCESS	0
-#undef ERROR
-#define ERROR	1
-
-/* private bus modes */
-#define SDIOH_MODE_SPI		0
-
-#define USE_BLOCKMODE		0x2	/* Block mode can be single block or multi */
-#define USE_MULTIBLOCK		0x4
-
-struct sdioh_info {
-	uint cfg_bar;                   	/* pci cfg address for bar */
-	uint32 caps;                    	/* cached value of capabilities reg */
-	uint		bar0;			/* BAR0 for PCI Device */
-	osl_t 		*osh;			/* osh handler */
-	void		*controller;	/* Pointer to SPI Controller's private data struct */
-
-	uint		lockcount; 		/* nest count of sdspi_lock() calls */
-	bool		client_intr_enabled;	/* interrupt connnected flag */
-	bool		intr_handler_valid;	/* client driver interrupt handler valid */
-	sdioh_cb_fn_t	intr_handler;		/* registered interrupt handler */
-	void		*intr_handler_arg;	/* argument to call interrupt handler */
-	bool		initialized;		/* card initialized */
-	uint32		target_dev;		/* Target device ID */
-	uint32		intmask;		/* Current active interrupts */
-	void		*sdos_info;		/* Pointer to per-OS private data */
-
-	uint32		controller_type;	/* Host controller type */
-	uint8		version;		/* Host Controller Spec Compliance Version */
-	uint 		irq;			/* Client irq */
-	uint32 		intrcount;		/* Client interrupts */
-	uint32 		local_intrcount;	/* Controller interrupts */
-	bool 		host_init_done;		/* Controller initted */
-	bool 		card_init_done;		/* Client SDIO interface initted */
-	bool 		polled_mode;		/* polling for command completion */
-
-	bool		sd_use_dma;		/* DMA on CMD53 */
-	bool 		sd_blockmode;		/* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
-						/*  Must be on for sd_multiblock to be effective */
-	bool 		use_client_ints;	/* If this is false, make sure to restore */
-	bool		got_hcint;		/* Host Controller interrupt. */
-						/*  polling hack in wl_linux.c:wl_timer() */
-	int 		adapter_slot;		/* Maybe dealing with multiple slots/controllers */
-	int 		sd_mode;		/* SD1/SD4/SPI */
-	int 		client_block_size[SDIOD_MAX_IOFUNCS];		/* Blocksize */
-	uint32 		data_xfer_count;	/* Current register transfer size */
-	uint32		cmd53_wr_data;		/* Used to pass CMD53 write data */
-	uint32		card_response;		/* Used to pass back response status byte */
-	uint32		card_rsp_data;		/* Used to pass back response data word */
-	uint16 		card_rca;		/* Current Address */
-	uint8 		num_funcs;		/* Supported funcs on client */
-	uint32 		com_cis_ptr;
-	uint32 		func_cis_ptr[SDIOD_MAX_IOFUNCS];
-	void		*dma_buf;
-	ulong		dma_phys;
-	int 		r_cnt;			/* rx count */
-	int 		t_cnt;			/* tx_count */
-};
-
-/************************************************************
- * Internal interfaces: per-port references into bcmsdspi.c
- */
-
-/* Global message bits */
-extern uint sd_msglevel;
-
-/**************************************************************
- * Internal interfaces: bcmsdspi.c references to per-port code
- */
-
-/* Register mapping routines */
-extern uint32 *spi_reg_map(osl_t *osh, uintptr addr, int size);
-extern void spi_reg_unmap(osl_t *osh, uintptr addr, int size);
-
-/* Interrupt (de)registration routines */
-extern int spi_register_irq(sdioh_info_t *sd, uint irq);
-extern void spi_free_irq(uint irq, sdioh_info_t *sd);
-
-/* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
-extern void spi_lock(sdioh_info_t *sd);
-extern void spi_unlock(sdioh_info_t *sd);
-
-/* Allocate/init/free per-OS private data */
-extern int spi_osinit(sdioh_info_t *sd);
-extern void spi_osfree(sdioh_info_t *sd);
-
-#endif /* _BCM_SD_SPI_H */
diff --git a/drivers/net/wireless/bcmdhd/include/bcmsdstd.h b/drivers/net/wireless/bcmdhd/include/bcmsdstd.h
deleted file mode 100644
index 0f4c026..0000000
--- a/drivers/net/wireless/bcmdhd/include/bcmsdstd.h
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- *  'Standard' SDIO HOST CONTROLLER driver
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: bcmsdstd.h,v 13.21.2.6 2010-11-15 18:14:01 Exp $
- */
-#ifndef	_BCM_SD_STD_H
-#define	_BCM_SD_STD_H
-
-/* global msglevel for debug messages - bitvals come from sdiovar.h */
-#define sd_err(x)	do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
-#define sd_trace(x)
-#define sd_info(x)
-#define sd_debug(x)
-#define sd_data(x)
-#define sd_ctrl(x)
-#define sd_dma(x)
-
-#define sd_sync_dma(sd, read, nbytes)
-#define sd_init_dma(sd)
-#define sd_ack_intr(sd)
-#define sd_wakeup(sd);
-/* Allocate/init/free per-OS private data */
-extern int sdstd_osinit(sdioh_info_t *sd);
-extern void sdstd_osfree(sdioh_info_t *sd);
-
-#define sd_log(x)
-
-#define SDIOH_ASSERT(exp) \
-	do { if (!(exp)) \
-		printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
-	} while (0)
-
-#define BLOCK_SIZE_4318 64
-#define BLOCK_SIZE_4328 512
-
-/* internal return code */
-#define SUCCESS	0
-#define ERROR	1
-
-/* private bus modes */
-#define SDIOH_MODE_SPI		0
-#define SDIOH_MODE_SD1		1
-#define SDIOH_MODE_SD4		2
-
-#define MAX_SLOTS 6 	/* For PCI: Only 6 BAR entries => 6 slots */
-#define SDIOH_REG_WINSZ	0x100 /* Number of registers in Standard Host Controller */
-
-#define SDIOH_TYPE_ARASAN_HDK	1
-#define SDIOH_TYPE_BCM27XX	2
-#define SDIOH_TYPE_TI_PCIXX21	4	/* TI PCIxx21 Standard Host Controller */
-#define SDIOH_TYPE_RICOH_R5C822	5	/* Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter */
-#define SDIOH_TYPE_JMICRON	6	/* JMicron Standard SDIO Host Controller */
-
-/* For linux, allow yielding for dongle */
-#define BCMSDYIELD
-
-/* Expected card status value for CMD7 */
-#define SDIOH_CMD7_EXP_STATUS   0x00001E00
-
-#define RETRIES_LARGE 100000
-#define RETRIES_SMALL 100
-
-
-#define USE_BLOCKMODE		0x2	/* Block mode can be single block or multi */
-#define USE_MULTIBLOCK		0x4
-
-#define USE_FIFO		0x8	/* Fifo vs non-fifo */
-
-#define CLIENT_INTR 		0x100	/* Get rid of this! */
-
-#define HC_INTR_RETUNING	0x1000
-
-
-struct sdioh_info {
-	uint cfg_bar;                   	/* pci cfg address for bar */
-	uint32 caps;                    	/* cached value of capabilities reg */
-	uint32 curr_caps;                    	/* max current capabilities reg */
-
-	osl_t 		*osh;			/* osh handler */
-	volatile char 	*mem_space;		/* pci device memory va */
-	uint		lockcount; 		/* nest count of sdstd_lock() calls */
-	bool		client_intr_enabled;	/* interrupt connnected flag */
-	bool		intr_handler_valid;	/* client driver interrupt handler valid */
-	sdioh_cb_fn_t	intr_handler;		/* registered interrupt handler */
-	void		*intr_handler_arg;	/* argument to call interrupt handler */
-	bool		initialized;		/* card initialized */
-	uint		target_dev;		/* Target device ID */
-	uint16		intmask;		/* Current active interrupts */
-	void		*sdos_info;		/* Pointer to per-OS private data */
-
-	uint32		controller_type;	/* Host controller type */
-	uint8		version;		/* Host Controller Spec Compliance Version */
-	uint 		irq;			/* Client irq */
-	int 		intrcount;		/* Client interrupts */
-	int 		local_intrcount;	/* Controller interrupts */
-	bool 		host_init_done;		/* Controller initted */
-	bool 		card_init_done;		/* Client SDIO interface initted */
-	bool 		polled_mode;		/* polling for command completion */
-
-	bool 		sd_blockmode;		/* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
-						/*  Must be on for sd_multiblock to be effective */
-	bool 		use_client_ints;	/* If this is false, make sure to restore */
-						/*  polling hack in wl_linux.c:wl_timer() */
-	int 		adapter_slot;		/* Maybe dealing with multiple slots/controllers */
-	int 		sd_mode;		/* SD1/SD4/SPI */
-	int 		client_block_size[SDIOD_MAX_IOFUNCS];		/* Blocksize */
-	uint32 		data_xfer_count;	/* Current transfer */
-	uint16 		card_rca;		/* Current Address */
-	int8		sd_dma_mode;		/* DMA Mode (PIO, SDMA, ... ADMA2) on CMD53 */
-	uint8 		num_funcs;		/* Supported funcs on client */
-	uint32 		com_cis_ptr;
-	uint32 		func_cis_ptr[SDIOD_MAX_IOFUNCS];
-	void		*dma_buf;		/* DMA Buffer virtual address */
-	ulong		dma_phys;		/* DMA Buffer physical address */
-	void		*adma2_dscr_buf;	/* ADMA2 Descriptor Buffer virtual address */
-	ulong		adma2_dscr_phys;	/* ADMA2 Descriptor Buffer physical address */
-
-	/* adjustments needed to make the dma align properly */
-	void		*dma_start_buf;
-	ulong		dma_start_phys;
-	uint		alloced_dma_size;
-	void		*adma2_dscr_start_buf;
-	ulong		adma2_dscr_start_phys;
-	uint		alloced_adma2_dscr_size;
-
-	int 		r_cnt;			/* rx count */
-	int 		t_cnt;			/* tx_count */
-	bool		got_hcint;		/* local interrupt flag */
-	uint16		last_intrstatus;	/* to cache intrstatus */
-	int 	host_UHSISupported;		/* whether UHSI is supported for HC. */
-	int 	card_UHSI_voltage_Supported; 	/* whether UHSI is supported for 
-						 * Card in terms of Voltage [1.8 or 3.3]. 
-						 */
-	int	global_UHSI_Supp;	/* type of UHSI support in both host and card.
-					 * HOST_SDR_UNSUPP: capabilities not supported/matched
-					 * HOST_SDR_12_25: SDR12 and SDR25 supported
-					 * HOST_SDR_50_104_DDR: one of SDR50/SDR104 or DDR50 supptd
-					 */
-	int	sd3_dat_state; 		/* data transfer state used for retuning check */
-	int	sd3_tun_state; 		/* tuning state used for retuning check */
-	bool	sd3_tuning_reqd; 	/* tuning requirement parameter */
-	uint32	caps3;			/* cached value of 32 MSbits capabilities reg (SDIO 3.0) */
-};
-
-#define DMA_MODE_NONE	0
-#define DMA_MODE_SDMA	1
-#define DMA_MODE_ADMA1	2
-#define DMA_MODE_ADMA2	3
-#define DMA_MODE_ADMA2_64 4
-#define DMA_MODE_AUTO	-1
-
-#define USE_DMA(sd)		((bool)((sd->sd_dma_mode > 0) ? TRUE : FALSE))
-
-/* SDIO Host Control Register DMA Mode Definitions */
-#define SDIOH_SDMA_MODE			0
-#define SDIOH_ADMA1_MODE		1
-#define SDIOH_ADMA2_MODE		2
-#define SDIOH_ADMA2_64_MODE		3
-
-#define ADMA2_ATTRIBUTE_VALID		(1 << 0)	/* ADMA Descriptor line valid */
-#define ADMA2_ATTRIBUTE_END			(1 << 1)	/* End of Descriptor */
-#define ADMA2_ATTRIBUTE_INT			(1 << 2)	/* Interrupt when line is done */
-#define ADMA2_ATTRIBUTE_ACT_NOP		(0 << 4)	/* Skip current line, go to next. */
-#define ADMA2_ATTRIBUTE_ACT_RSV		(1 << 4)	/* Same as NOP */
-#define ADMA1_ATTRIBUTE_ACT_SET		(1 << 4)	/* ADMA1 Only - set transfer length */
-#define ADMA2_ATTRIBUTE_ACT_TRAN	(2 << 4)	/* Transfer Data of one descriptor line. */
-#define ADMA2_ATTRIBUTE_ACT_LINK	(3 << 4)	/* Link Descriptor */
-
-/* States for Tuning and corr data */
-#define TUNING_IDLE 			0
-#define TUNING_START 			1
-#define TUNING_START_AFTER_DAT 	2
-#define TUNING_ONGOING 			3
-
-#define DATA_TRANSFER_IDLE 		0
-#define DATA_TRANSFER_ONGOING	1
-
-/* ADMA2 Descriptor Table Entry for 32-bit Address */
-typedef struct adma2_dscr_32b {
-	uint32 len_attr;
-	uint32 phys_addr;
-} adma2_dscr_32b_t;
-
-/* ADMA1 Descriptor Table Entry */
-typedef struct adma1_dscr {
-	uint32 phys_addr_attr;
-} adma1_dscr_t;
-
-/************************************************************
- * Internal interfaces: per-port references into bcmsdstd.c
- */
-
-/* Global message bits */
-extern uint sd_msglevel;
-
-/* OS-independent interrupt handler */
-extern bool check_client_intr(sdioh_info_t *sd);
-
-/* Core interrupt enable/disable of device interrupts */
-extern void sdstd_devintr_on(sdioh_info_t *sd);
-extern void sdstd_devintr_off(sdioh_info_t *sd);
-
-/* Enable/disable interrupts for local controller events */
-extern void sdstd_intrs_on(sdioh_info_t *sd, uint16 norm, uint16 err);
-extern void sdstd_intrs_off(sdioh_info_t *sd, uint16 norm, uint16 err);
-
-/* Wait for specified interrupt and error bits to be set */
-extern void sdstd_spinbits(sdioh_info_t *sd, uint16 norm, uint16 err);
-
-
-/**************************************************************
- * Internal interfaces: bcmsdstd.c references to per-port code
- */
-
-/* Register mapping routines */
-extern uint32 *sdstd_reg_map(osl_t *osh, int32 addr, int size);
-extern void sdstd_reg_unmap(osl_t *osh, int32 addr, int size);
-
-/* Interrupt (de)registration routines */
-extern int sdstd_register_irq(sdioh_info_t *sd, uint irq);
-extern void sdstd_free_irq(uint irq, sdioh_info_t *sd);
-
-/* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
-extern void sdstd_lock(sdioh_info_t *sd);
-extern void sdstd_unlock(sdioh_info_t *sd);
-extern void sdstd_waitlockfree(sdioh_info_t *sd);
-
-/* OS-specific wait-for-interrupt-or-status */
-extern int sdstd_waitbits(sdioh_info_t *sd, uint16 norm, uint16 err, bool yield, uint16 *bits);
-
-/* used by bcmsdstd_linux [implemented in sdstd] */
-extern void sdstd_3_enable_retuning_int(sdioh_info_t *sd);
-extern void sdstd_3_disable_retuning_int(sdioh_info_t *sd);
-extern bool sdstd_3_is_retuning_int_set(sdioh_info_t *sd);
-extern bool sdstd_3_check_and_set_retuning(sdioh_info_t *sd);
-extern int sdstd_3_get_tune_state(sdioh_info_t *sd);
-extern void sdstd_3_set_tune_state(sdioh_info_t *sd, int state);
-extern uint8 sdstd_3_get_tuning_exp(sdioh_info_t *sd);
-extern uint32 sdstd_3_get_uhsi_clkmode(sdioh_info_t *sd);
-extern int sdstd_3_clk_tuning(sdioh_info_t *sd, uint32 sd3ClkMode);
-
-/* used by sdstd [implemented in bcmsdstd_linux/ndis] */
-extern void sdstd_3_start_tuning(sdioh_info_t *sd);
-extern void sdstd_3_osinit_tuning(sdioh_info_t *sd);
-extern void sdstd_3_osclean_tuning(sdioh_info_t *sd);
-
-#endif /* _BCM_SD_STD_H */
diff --git a/drivers/net/wireless/bcmdhd/include/bcmutils.h b/drivers/net/wireless/bcmdhd/include/bcmutils.h
index 530036f..e38d129 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmutils.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmutils.h
@@ -2,13 +2,13 @@
  * Misc useful os-independent macros and functions.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmutils.h,v 13.236.2.16 2011-01-26 00:45:06 Exp $
+ * $Id: bcmutils.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -37,14 +37,14 @@
 #endif
 
 
-#define _BCM_U	0x01	
-#define _BCM_L	0x02	
-#define _BCM_D	0x04	
-#define _BCM_C	0x08	
-#define _BCM_P	0x10	
-#define _BCM_S	0x20	
-#define _BCM_X	0x40	
-#define _BCM_SP	0x80	
+#define _BCM_U	0x01
+#define _BCM_L	0x02
+#define _BCM_D	0x04
+#define _BCM_C	0x08
+#define _BCM_P	0x10
+#define _BCM_S	0x20
+#define _BCM_X	0x40
+#define _BCM_SP	0x80
 
 extern const unsigned char bcm_ctype[];
 #define bcm_ismask(x)	(bcm_ctype[(int)(unsigned char)(x)])
@@ -66,17 +66,17 @@
 
 
 struct bcmstrbuf {
-	char *buf;	
-	unsigned int size;	
-	char *origbuf;	
-	unsigned int origsize;	
+	char *buf;
+	unsigned int size;
+	char *origbuf;
+	unsigned int origsize;
 };
 
 
 #ifdef BCMDRIVER
 #include <osl.h>
 
-#define GPIO_PIN_NOTDEFINED 	0x20	
+#define GPIO_PIN_NOTDEFINED 	0x20
 
 
 #define SPINWAIT(exp, us) { \
@@ -89,37 +89,37 @@
 
 
 #ifndef PKTQ_LEN_DEFAULT
-#define PKTQ_LEN_DEFAULT        128	
+#define PKTQ_LEN_DEFAULT        128
 #endif
 #ifndef PKTQ_MAX_PREC
-#define PKTQ_MAX_PREC           16	
+#define PKTQ_MAX_PREC           16
 #endif
 
 typedef struct pktq_prec {
-	void *head;     
-	void *tail;     
-	uint16 len;     
-	uint16 max;     
+	void *head;
+	void *tail;
+	uint16 len;
+	uint16 max;
 } pktq_prec_t;
 
 
 
 struct pktq {
-	uint16 num_prec;        
-	uint16 hi_prec;         
-	uint16 max;             
-	uint16 len;             
-	
+	uint16 num_prec;
+	uint16 hi_prec;
+	uint16 max;
+	uint16 len;
+
 	struct pktq_prec q[PKTQ_MAX_PREC];
 };
 
 
 struct spktq {
-	uint16 num_prec;        
-	uint16 hi_prec;         
-	uint16 max;             
-	uint16 len;             
-	
+	uint16 num_prec;
+	uint16 hi_prec;
+	uint16 max;
+	uint16 len;
+
 	struct pktq_prec q[1];
 };
 
@@ -134,11 +134,11 @@
 #define SHARED_POOL		(pktpool_shared_ptr)
 #else
 #define SHARED_POOL		(pktpool_shared)
-#endif 
-#else 
+#endif
+#else
 #define POOL_ENAB(bus)		0
 #define SHARED_POOL		((struct pktpool *)NULL)
-#endif 
+#endif
 
 #ifndef PKTPOOL_LEN_MAX
 #define PKTPOOL_LEN_MAX		40
@@ -170,15 +170,15 @@
 } pktpool_dbg_t;
 
 typedef struct {
-	uint8 txdh;	
-	uint8 txd11;	
-	uint8 enq;	
-	uint8 rxdh;	
-	uint8 rxd11;	
-	uint8 rxfill;	
-	uint8 idle;	
+	uint8 txdh;
+	uint8 txd11;
+	uint8 enq;
+	uint8 rxdh;
+	uint8 rxd11;
+	uint8 rxfill;
+	uint8 idle;
 } pktpool_stats_t;
-#endif 
+#endif
 
 typedef struct pktpool {
 	bool inited;
@@ -209,7 +209,7 @@
 extern pktpool_t *pktpool_shared_ptr;
 #else
 extern pktpool_t *pktpool_shared;
-#endif 
+#endif
 
 extern int pktpool_init(osl_t *osh, pktpool_t *pktp, int *pktplen, int plen, bool istx);
 extern int pktpool_deinit(osl_t *osh, pktpool_t *pktp);
@@ -234,7 +234,7 @@
 extern int pktpool_dbg_dump(pktpool_t *pktp);
 extern int pktpool_dbg_notify(pktpool_t *pktp);
 extern int pktpool_stats_dump(pktpool_t *pktp, pktpool_stats_t *stats);
-#endif 
+#endif
 
 
 
@@ -302,10 +302,10 @@
 
 
 extern uint pktsetprio(void *pkt, bool update_vtag);
-#define	PKTPRIO_VDSCP	0x100		
-#define	PKTPRIO_VLAN	0x200		
-#define	PKTPRIO_UPD	0x400		
-#define	PKTPRIO_DSCP	0x800		
+#define	PKTPRIO_VDSCP	0x100
+#define	PKTPRIO_VLAN	0x200
+#define	PKTPRIO_UPD	0x400
+#define	PKTPRIO_DSCP	0x800
 
 
 extern int bcm_atoi(char *s);
@@ -330,6 +330,9 @@
 
 extern void bcm_mdelay(uint ms);
 
+#define NVRAM_RECLAIM_CHECK(name)
+
+
 extern char *getvar(char *vars, const char *name);
 extern int getintvar(char *vars, const char *name);
 extern int getintvararray(char *vars, const char *name, int index);
@@ -352,18 +355,18 @@
 
 
 typedef struct bcm_iovar {
-	const char *name;	
-	uint16 varid;		
-	uint16 flags;		
-	uint16 type;		
-	uint16 minlen;		
+	const char *name;
+	uint16 varid;
+	uint16 flags;
+	uint16 type;
+	uint16 minlen;
 } bcm_iovar_t;
 
 
 
 
-#define IOV_GET 0 
-#define IOV_SET 1 
+#define IOV_GET 0
+#define IOV_SET 1
 
 
 #define IOV_GVAL(id)		((id)*2)
@@ -378,19 +381,19 @@
 #if defined(WLTINYDUMP) || defined(WLMSG_INFORM) || defined(WLMSG_ASSOC) || \
 	defined(WLMSG_PRPKT) || defined(WLMSG_WSEC)
 extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len);
-#endif 
-#endif	
+#endif
+#endif
 
 
-#define IOVT_VOID	0	
-#define IOVT_BOOL	1	
-#define IOVT_INT8	2	
-#define IOVT_UINT8	3	
-#define IOVT_INT16	4	
-#define IOVT_UINT16	5	
-#define IOVT_INT32	6	
-#define IOVT_UINT32	7	
-#define IOVT_BUFFER	8	
+#define IOVT_VOID	0
+#define IOVT_BOOL	1
+#define IOVT_INT8	2
+#define IOVT_UINT8	3
+#define IOVT_INT16	4
+#define IOVT_UINT16	5
+#define IOVT_INT32	6
+#define IOVT_UINT32	7
+#define IOVT_BUFFER	8
 #define BCM_IOVT_VALID(type) (((unsigned int)(type)) <= IOVT_BUFFER)
 
 
@@ -417,55 +420,55 @@
 
 
 
-#define BCME_STRLEN 		64	
+#define BCME_STRLEN 		64
 #define VALID_BCMERROR(e)  ((e <= 0) && (e >= BCME_LAST))
 
 
 
 
-#define BCME_OK				0	
-#define BCME_ERROR			-1	
-#define BCME_BADARG			-2	
-#define BCME_BADOPTION			-3	
-#define BCME_NOTUP			-4	
-#define BCME_NOTDOWN			-5	
-#define BCME_NOTAP			-6	
-#define BCME_NOTSTA			-7	
-#define BCME_BADKEYIDX			-8	
-#define BCME_RADIOOFF 			-9	
-#define BCME_NOTBANDLOCKED		-10	
-#define BCME_NOCLK			-11	
-#define BCME_BADRATESET			-12	
-#define BCME_BADBAND			-13	
-#define BCME_BUFTOOSHORT		-14	
-#define BCME_BUFTOOLONG			-15	
-#define BCME_BUSY			-16	
-#define BCME_NOTASSOCIATED		-17	
-#define BCME_BADSSIDLEN			-18	
-#define BCME_OUTOFRANGECHAN		-19	
-#define BCME_BADCHAN			-20	
-#define BCME_BADADDR			-21	
-#define BCME_NORESOURCE			-22	
-#define BCME_UNSUPPORTED		-23	
-#define BCME_BADLEN			-24	
-#define BCME_NOTREADY			-25	
-#define BCME_EPERM			-26	
-#define BCME_NOMEM			-27	
-#define BCME_ASSOCIATED			-28	
-#define BCME_RANGE			-29	
-#define BCME_NOTFOUND			-30	
-#define BCME_WME_NOT_ENABLED		-31	
-#define BCME_TSPEC_NOTFOUND		-32	
-#define BCME_ACM_NOTSUPPORTED		-33	
-#define BCME_NOT_WME_ASSOCIATION	-34	
-#define BCME_SDIO_ERROR			-35	
-#define BCME_DONGLE_DOWN		-36	
-#define BCME_VERSION			-37 	
-#define BCME_TXFAIL			-38 	
-#define BCME_RXFAIL			-39	
-#define BCME_NODEVICE			-40 	
-#define BCME_NMODE_DISABLED		-41 	
-#define BCME_NONRESIDENT		-42 
+#define BCME_OK				0
+#define BCME_ERROR			-1
+#define BCME_BADARG			-2
+#define BCME_BADOPTION			-3
+#define BCME_NOTUP			-4
+#define BCME_NOTDOWN			-5
+#define BCME_NOTAP			-6
+#define BCME_NOTSTA			-7
+#define BCME_BADKEYIDX			-8
+#define BCME_RADIOOFF 			-9
+#define BCME_NOTBANDLOCKED		-10
+#define BCME_NOCLK			-11
+#define BCME_BADRATESET			-12
+#define BCME_BADBAND			-13
+#define BCME_BUFTOOSHORT		-14
+#define BCME_BUFTOOLONG			-15
+#define BCME_BUSY			-16
+#define BCME_NOTASSOCIATED		-17
+#define BCME_BADSSIDLEN			-18
+#define BCME_OUTOFRANGECHAN		-19
+#define BCME_BADCHAN			-20
+#define BCME_BADADDR			-21
+#define BCME_NORESOURCE			-22
+#define BCME_UNSUPPORTED		-23
+#define BCME_BADLEN			-24
+#define BCME_NOTREADY			-25
+#define BCME_EPERM			-26
+#define BCME_NOMEM			-27
+#define BCME_ASSOCIATED			-28
+#define BCME_RANGE			-29
+#define BCME_NOTFOUND			-30
+#define BCME_WME_NOT_ENABLED		-31
+#define BCME_TSPEC_NOTFOUND		-32
+#define BCME_ACM_NOTSUPPORTED		-33
+#define BCME_NOT_WME_ASSOCIATION	-34
+#define BCME_SDIO_ERROR			-35
+#define BCME_DONGLE_DOWN		-36
+#define BCME_VERSION			-37
+#define BCME_TXFAIL			-38
+#define BCME_RXFAIL			-39
+#define BCME_NODEVICE			-40
+#define BCME_NMODE_DISABLED		-41
+#define BCME_NONRESIDENT		-42
 #define BCME_LAST			BCME_NONRESIDENT
 
 
@@ -517,15 +520,15 @@
 
 #ifndef ABS
 #define	ABS(a)			(((a) < 0)?-(a):(a))
-#endif 
+#endif
 
 #ifndef MIN
 #define	MIN(a, b)		(((a) < (b))?(a):(b))
-#endif 
+#endif
 
 #ifndef MAX
 #define	MAX(a, b)		(((a) > (b))?(a):(b))
-#endif 
+#endif
 
 #define CEIL(x, y)		(((x) + ((y)-1)) / (y))
 #define	ROUNDUP(x, y)		((((x)+((y)-1))/(y))*(y))
@@ -536,7 +539,7 @@
 #define VALID_MASK(mask)	!((mask) & ((mask) + 1))
 #ifndef OFFSETOF
 #define	OFFSETOF(type, member)	((uint)(uintptr)&((type *)0)->member)
-#endif 
+#endif
 #ifndef ARRAYSIZE
 #define ARRAYSIZE(a)		(sizeof(a)/sizeof(a[0]))
 #endif
@@ -547,14 +550,14 @@
 
 
 #ifndef setbit
-#ifndef NBBY		      
-#define	NBBY	8	
-#endif 
+#ifndef NBBY
+#define	NBBY	8
+#endif
 #define	setbit(a, i)	(((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
 #define	clrbit(a, i)	(((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
 #define	isset(a, i)	(((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
 #define	isclr(a, i)	((((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
-#endif 
+#endif
 
 #define	NBITS(type)	(sizeof(type) * 8)
 #define NBITVAL(nbits)	(1 << (nbits))
@@ -584,12 +587,12 @@
 #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
 
 
-#define CRC8_INIT_VALUE  0xff		
-#define CRC8_GOOD_VALUE  0x9f		
-#define CRC16_INIT_VALUE 0xffff		
-#define CRC16_GOOD_VALUE 0xf0b8		
-#define CRC32_INIT_VALUE 0xffffffff	
-#define CRC32_GOOD_VALUE 0xdebb20e3	
+#define CRC8_INIT_VALUE  0xff
+#define CRC8_GOOD_VALUE  0x9f
+#define CRC16_INIT_VALUE 0xffff
+#define CRC16_GOOD_VALUE 0xf0b8
+#define CRC32_INIT_VALUE 0xffffffff
+#define CRC32_GOOD_VALUE 0xdebb20e3
 
 
 typedef struct bcm_bit_desc {
@@ -608,7 +611,7 @@
 #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
 
 
-#define ETHER_ADDR_STR_LEN	18	
+#define ETHER_ADDR_STR_LEN	18
 
 
 
@@ -620,14 +623,14 @@
 	    1 ||
 #endif
 	    (((uintptr)src1 | (uintptr)src2 | (uintptr)dst) & 3) == 0) {
-		
-		
+
+
 		((uint32 *)dst)[0] = ((const uint32 *)src1)[0] ^ ((const uint32 *)src2)[0];
 		((uint32 *)dst)[1] = ((const uint32 *)src1)[1] ^ ((const uint32 *)src2)[1];
 		((uint32 *)dst)[2] = ((const uint32 *)src1)[2] ^ ((const uint32 *)src2)[2];
 		((uint32 *)dst)[3] = ((const uint32 *)src1)[3] ^ ((const uint32 *)src2)[3];
 	} else {
-		
+
 		int k;
 		for (k = 0; k < 16; k++)
 			dst[k] = src1[k] ^ src2[k];
@@ -666,9 +669,9 @@
 
 
 typedef uint32 mbool;
-#define mboolset(mb, bit)		((mb) |= (bit))		
-#define mboolclr(mb, bit)		((mb) &= ~(bit))	
-#define mboolisset(mb, bit)		(((mb) & (bit)) != 0)	
+#define mboolset(mb, bit)		((mb) |= (bit))
+#define mboolclr(mb, bit)		((mb) &= ~(bit))
+#define mboolisset(mb, bit)		(((mb) & (bit)) != 0)
 #define	mboolmaskset(mb, mask, val)	((mb) = (((mb) & ~(mask)) | (val)))
 
 
@@ -705,4 +708,4 @@
 	}
 #endif
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmwifi.h b/drivers/net/wireless/bcmdhd/include/bcmwifi.h
index 45f3c03..c66fbae 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmwifi.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmwifi.h
@@ -4,13 +4,13 @@
  * both the wl driver, tools & Apps.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -18,12 +18,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmwifi.h,v 1.29.6.3 2010-08-03 17:47:04 Exp $
+ * $Id: bcmwifi.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -40,10 +40,10 @@
 #define CH_EWA_VALID			0x04
 #define CH_20MHZ_APART			4
 #define CH_10MHZ_APART			2
-#define CH_5MHZ_APART			1	
-#define CH_MAX_2G_CHANNEL		14	
-#define WLC_MAX_2G_CHANNEL		CH_MAX_2G_CHANNEL 
-#define	MAXCHANNEL		224	
+#define CH_5MHZ_APART			1
+#define CH_MAX_2G_CHANNEL		14
+#define WLC_MAX_2G_CHANNEL		CH_MAX_2G_CHANNEL
+#define	MAXCHANNEL		224
 
 #define WL_CHANSPEC_CHAN_MASK		0x00ff
 #define WL_CHANSPEC_CHAN_SHIFT		0
@@ -67,9 +67,9 @@
 #define INVCHANSPEC			255
 
 
-#define WF_CHAN_FACTOR_2_4_G		4814	
-#define WF_CHAN_FACTOR_5_G		10000	
-#define WF_CHAN_FACTOR_4_G		8000	
+#define WF_CHAN_FACTOR_2_4_G		4814
+#define WF_CHAN_FACTOR_5_G		10000
+#define WF_CHAN_FACTOR_4_G		8000
 
 
 #define LOWER_20_SB(channel)	(((channel) > CH_10MHZ_APART) ? ((channel) - CH_10MHZ_APART) : 0)
@@ -100,7 +100,7 @@
 #define CHSPEC_IS40(chspec)	0
 #endif
 
-#else 
+#else
 
 #define CHSPEC_IS10(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
 #define CHSPEC_IS20(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
@@ -108,7 +108,7 @@
 #define CHSPEC_IS40(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
 #endif
 
-#endif 
+#endif
 
 #define CHSPEC_IS20_UNCOND(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
 
@@ -125,21 +125,21 @@
 #define CHANSPEC_STR_LEN    8
 
 
-#define WLC_MAXRATE	108	
-#define WLC_RATE_1M	2	
-#define WLC_RATE_2M	4	
-#define WLC_RATE_5M5	11	
-#define WLC_RATE_11M	22	
-#define WLC_RATE_6M	12	
-#define WLC_RATE_9M	18	
-#define WLC_RATE_12M	24	
-#define WLC_RATE_18M	36	
-#define WLC_RATE_24M	48	
-#define WLC_RATE_36M	72	
-#define WLC_RATE_48M	96	
-#define WLC_RATE_54M	108	
+#define WLC_MAXRATE	108
+#define WLC_RATE_1M	2
+#define WLC_RATE_2M	4
+#define WLC_RATE_5M5	11
+#define WLC_RATE_11M	22
+#define WLC_RATE_6M	12
+#define WLC_RATE_9M	18
+#define WLC_RATE_12M	24
+#define WLC_RATE_18M	36
+#define WLC_RATE_24M	48
+#define WLC_RATE_36M	72
+#define WLC_RATE_48M	96
+#define WLC_RATE_54M	108
 
-#define WLC_2G_25MHZ_OFFSET		5	
+#define WLC_2G_25MHZ_OFFSET		5
 
 
 extern char * wf_chspec_ntoa(chanspec_t chspec, char *buf);
@@ -162,4 +162,4 @@
 
 extern int wf_channel2mhz(uint channel, uint start_factor);
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/bcmspi.h b/drivers/net/wireless/bcmdhd/include/bcmwifi_channels.h
similarity index 60%
rename from drivers/net/wireless/bcmdhd/include/bcmspi.h
rename to drivers/net/wireless/bcmdhd/include/bcmwifi_channels.h
index 0eb2a30..4627a9a 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmspi.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmwifi_channels.h
@@ -1,14 +1,14 @@
 /*
- * Broadcom SPI Low-Level Hardware Driver API
+ * Transitional compatibility translation from old name to new.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,25 +16,18 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmspi.h,v 13.5.112.1 2010-11-15 18:13:09 Exp $
+ * $Id:$
  */
-#ifndef	_BCM_SPI_H
-#define	_BCM_SPI_H
 
-extern void spi_devintr_off(sdioh_info_t *sd);
-extern void spi_devintr_on(sdioh_info_t *sd);
-extern bool spi_start_clock(sdioh_info_t *sd, uint16 new_sd_divisor);
-extern bool spi_controller_highspeed_mode(sdioh_info_t *sd, bool hsmode);
-extern bool spi_check_client_intr(sdioh_info_t *sd, int *is_dev_intr);
-extern bool spi_hw_attach(sdioh_info_t *sd);
-extern bool spi_hw_detach(sdioh_info_t *sd);
-extern void spi_sendrecv(sdioh_info_t *sd, uint8 *msg_out, uint8 *msg_in, int msglen);
-extern void spi_spinbits(sdioh_info_t *sd);
-extern void spi_waitbits(sdioh_info_t *sd, bool yield);
 
-#endif /* _BCM_SPI_H */
+#ifndef	_bcmwifi_channels_h_
+#define	_bcmwifi_channels_h_
+
+#include "bcmwifi.h"
+
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/dhdioctl.h b/drivers/net/wireless/bcmdhd/include/dhdioctl.h
index 9661dac..f84cb7f 100644
--- a/drivers/net/wireless/bcmdhd/include/dhdioctl.h
+++ b/drivers/net/wireless/bcmdhd/include/dhdioctl.h
@@ -6,13 +6,13 @@
  * Definitions subject to change without notice.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -20,12 +20,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhdioctl.h,v 13.11.10.1 2010-12-22 23:47:26 Exp $
+ * $Id: dhdioctl.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef _dhdioctl_h_
@@ -87,6 +87,7 @@
 #define DHD_BTA_VAL	0x1000
 #define DHD_ISCAN_VAL	0x2000
 #define DHD_ARPOE_VAL	0x4000
+#define DHD_WL_VAL		0x8000
 
 #ifdef SDTEST
 /* For pktgen iovar */
diff --git a/drivers/net/wireless/bcmdhd/include/epivers.h b/drivers/net/wireless/bcmdhd/include/epivers.h
index ae1f975..2784b20 100644
--- a/drivers/net/wireless/bcmdhd/include/epivers.h
+++ b/drivers/net/wireless/bcmdhd/include/epivers.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,7 +14,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -33,17 +33,17 @@
 
 #define	EPI_RC_NUMBER		125
 
-#define	EPI_INCREMENTAL_NUMBER	94
+#define	EPI_INCREMENTAL_NUMBER	129
 
 #define	EPI_BUILD_NUMBER	0
 
-#define	EPI_VERSION		5, 90, 125, 94
+#define	EPI_VERSION		5, 90, 125, 129
 
-#define	EPI_VERSION_NUM		0x055a7d5e
+#define	EPI_VERSION_NUM		0x055a7d81
 
 #define EPI_VERSION_DEV		5.90.125
 
 
-#define	EPI_VERSION_STR		"5.90.125.94"
+#define	EPI_VERSION_STR		"5.90.125.129"
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/hndpmu.h b/drivers/net/wireless/bcmdhd/include/hndpmu.h
index 51c51b9..f536f58 100644
--- a/drivers/net/wireless/bcmdhd/include/hndpmu.h
+++ b/drivers/net/wireless/bcmdhd/include/hndpmu.h
@@ -2,13 +2,13 @@
  * HND SiliconBackplane PMU support.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: hndpmu.h,v 13.35.8.5 2011-02-11 00:56:32 Exp $
+ * $Id: hndpmu.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef _hndpmu_h_
diff --git a/drivers/net/wireless/bcmdhd/include/hndrte_armtrap.h b/drivers/net/wireless/bcmdhd/include/hndrte_armtrap.h
index 8b9615c..e22ad29 100644
--- a/drivers/net/wireless/bcmdhd/include/hndrte_armtrap.h
+++ b/drivers/net/wireless/bcmdhd/include/hndrte_armtrap.h
@@ -2,13 +2,13 @@
  * HNDRTE arm trap handling.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: hndrte_armtrap.h,v 13.4.14.1 2011-02-05 00:04:30 Exp $
+ * $Id: hndrte_armtrap.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_hndrte_armtrap_h
diff --git a/drivers/net/wireless/bcmdhd/include/hndrte_cons.h b/drivers/net/wireless/bcmdhd/include/hndrte_cons.h
index b9ede53..9b8edf1 100644
--- a/drivers/net/wireless/bcmdhd/include/hndrte_cons.h
+++ b/drivers/net/wireless/bcmdhd/include/hndrte_cons.h
@@ -2,13 +2,13 @@
  * Console support for hndrte.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: hndrte_cons.h,v 13.4.10.4 2011-02-05 00:08:20 Exp $
+ * $Id: hndrte_cons.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_HNDRTE_CONS_H
diff --git a/drivers/net/wireless/bcmdhd/include/hndsoc.h b/drivers/net/wireless/bcmdhd/include/hndsoc.h
index 4e26121..ac0f048 100644
--- a/drivers/net/wireless/bcmdhd/include/hndsoc.h
+++ b/drivers/net/wireless/bcmdhd/include/hndsoc.h
@@ -2,13 +2,13 @@
  * Broadcom HND chip & on-chip-interconnect-related definitions.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: hndsoc.h,v 13.11 2009-12-03 23:52:31 Exp $
+ * $Id: hndsoc.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_HNDSOC_H
diff --git a/drivers/net/wireless/bcmdhd/include/htsf.h b/drivers/net/wireless/bcmdhd/include/htsf.h
index 379fbbe..5177608 100644
--- a/drivers/net/wireless/bcmdhd/include/htsf.h
+++ b/drivers/net/wireless/bcmdhd/include/htsf.h
@@ -1,14 +1,14 @@
 /*
- * Time stamps for latency measurements 
+ * Time stamps for latency measurements
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: htsf.h,v 1.1.2.4 2011-01-21 08:27:03 Exp $
+ * $Id: htsf.h 275703 2011-08-04 20:20:27Z $
  */
 #ifndef _HTSF_H_
 #define _HTSF_H_
diff --git a/drivers/net/wireless/bcmdhd/include/linux_osl.h b/drivers/net/wireless/bcmdhd/include/linux_osl.h
index 1ec136e..e88a951 100644
--- a/drivers/net/wireless/bcmdhd/include/linux_osl.h
+++ b/drivers/net/wireless/bcmdhd/include/linux_osl.h
@@ -2,13 +2,13 @@
  * Linux OS Independent Layer
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: linux_osl.h,v 13.158.6.3 2010-12-22 23:47:26 Exp $
+ * $Id: linux_osl.h 284903 2011-09-20 02:36:51Z $
  */
 
 
@@ -57,11 +57,11 @@
 		#if GCC_VERSION > 30100
 			#define ASSERT(exp)	do {} while (0)
 		#else
-			
+
 			#define ASSERT(exp)
-		#endif 
-	#endif 
-#endif 
+		#endif
+	#endif
+#endif
 
 
 #define	OSL_DELAY(usec)		osl_delay(usec)
@@ -91,10 +91,10 @@
 
 typedef struct {
 	bool pkttag;
-	uint pktalloced; 	
-	bool mmbus;		
-	pktfree_cb_fn_t tx_fn;  
-	void *tx_ctx;		
+	uint pktalloced;
+	bool mmbus;
+	pktfree_cb_fn_t tx_fn;
+	void *tx_ctx;
 } osl_pubinfo_t;
 
 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx)		\
@@ -131,8 +131,8 @@
 extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
 
 
-#define	DMA_TX	1	
-#define	DMA_RX	2	
+#define	DMA_TX	1
+#define	DMA_RX	2
 
 
 #define	DMA_MAP(osh, va, size, direction, p, dmah) \
@@ -159,14 +159,14 @@
 extern int osl_error(int bcmerror);
 
 
-#define	PKTBUFSZ	2048   
+#define	PKTBUFSZ	2048
 
 
 
 #define OSL_SYSUPTIME()		((uint32)jiffies * (1000 / HZ))
 #define	printf(fmt, args...)	printk(fmt , ## args)
-#include <linux/kernel.h>	
-#include <linux/string.h>	
+#include <linux/kernel.h>
+#include <linux/string.h>
 
 #define	bcopy(src, dst, len)	memcpy((dst), (src), (len))
 #define	bcmp(b1, b2, len)	memcmp((b1), (b2), (len))
@@ -180,7 +180,7 @@
 	sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
 	readl((volatile uint32*)(r)), OSL_READ_REG(osh, r)) \
 )
-#else 
+#else
 #define R_REG(osh, r) (\
 	SELECT_BUS_READ(osh, \
 		({ \
@@ -205,7 +205,7 @@
 			__osl_v; \
 		})) \
 )
-#endif 
+#endif
 
 #define W_REG(osh, r, v) do { \
 	SELECT_BUS_WRITE(osh,  \
@@ -234,14 +234,14 @@
 #else
 #define OSL_UNCACHED(va)	((void *)va)
 #define OSL_CACHED(va)		((void *)va)
-#endif 
+#endif
 
 
 #if defined(__i386__)
 #define	OSL_GETCYCLES(x)	rdtscl((x))
 #else
 #define OSL_GETCYCLES(x)	((x) = 0)
-#endif 
+#endif
 
 
 #define	BUSPROBE(val, addr)	({ (val) = R_REG(NULL, (addr)); 0; })
@@ -251,7 +251,7 @@
 #define	REG_MAP(pa, size)	ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
 #else
 #define REG_MAP(pa, size)       (void *)(0)
-#endif 
+#endif
 #define	REG_UNMAP(va)		iounmap((va))
 
 
@@ -260,7 +260,7 @@
 #define	BZERO_SM(r, len)	memset((r), '\0', (len))
 
 
-#include <linuxver.h>		
+#include <linuxver.h>
 
 
 #define	PKTGET(osh, len, send)		osl_pktget((osh), (len))
@@ -268,7 +268,7 @@
 #define PKTLIST_DUMP(osh, buf)
 #define PKTDBG_TRACE(osh, pkt, bit)
 #define	PKTFREE(osh, skb, send)		osl_pktfree((osh), (skb), (send))
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 #define	PKTGET_STATIC(osh, len, send)		osl_pktget_static((osh), (len))
 #define	PKTFREE_STATIC(osh, skb, send)		osl_pktfree_static((osh), (skb), (send))
 #endif
@@ -320,7 +320,7 @@
 #define	PKTISFAST(osh, skb)	((((struct sk_buff*)(skb))->__unused) & FASTBUF)
 #define	PKTISCTF(osh, skb)	((((struct sk_buff*)(skb))->__unused) & CTFBUF)
 #define	PKTFAST(osh, skb)	(((struct sk_buff*)(skb))->__unused)
-#endif 
+#endif
 
 #define	CTFPOOLPTR(osh, skb)	(((struct sk_buff*)(skb))->sk)
 #define	CTFPOOLHEAD(osh, skb)	(((ctfpool_t *)((struct sk_buff*)(skb))->sk)->head)
@@ -330,7 +330,7 @@
 extern int32 osl_ctfpool_init(osl_t *osh, uint numobj, uint size);
 extern void osl_ctfpool_cleanup(osl_t *osh);
 extern void osl_ctfpool_stats(osl_t *osh, void *b);
-#endif 
+#endif
 
 #ifdef HNDCTF
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
@@ -338,17 +338,17 @@
 #define	PKTSETSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len |= SKIPCT)
 #define	PKTCLRSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len &= (~SKIPCT))
 #define	PKTSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len & SKIPCT)
-#else 
+#else
 #define	SKIPCT	(1 << 2)
 #define	PKTSETSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused |= SKIPCT)
 #define	PKTCLRSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused &= (~SKIPCT))
 #define	PKTSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused & SKIPCT)
-#endif 
-#else 
+#endif
+#else
 #define	PKTSETSKIPCT(osh, skb)
 #define	PKTCLRSKIPCT(osh, skb)
 #define	PKTSKIPCT(osh, skb)
-#endif 
+#endif
 
 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
 extern void *osl_pktget_static(osl_t *osh, uint len);
@@ -366,7 +366,7 @@
 	if (osh->pkttag)
 		bzero((void*)((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
 
-	
+
 	for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
 		osh->pktalloced++;
 	}
@@ -384,7 +384,7 @@
 	if (osh->pkttag)
 		bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
 
-	
+
 	for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
 		osh->pktalloced--;
 	}
@@ -405,7 +405,7 @@
 
 
 
-#else 
+#else
 
 
 
@@ -426,6 +426,6 @@
 extern void bcopy(const void *src, void *dst, size_t len);
 extern int bcmp(const void *b1, const void *b2, size_t len);
 extern void bzero(void *b, size_t len);
-#endif 
+#endif
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/linuxver.h b/drivers/net/wireless/bcmdhd/include/linuxver.h
index 96844db..0c7041f 100644
--- a/drivers/net/wireless/bcmdhd/include/linuxver.h
+++ b/drivers/net/wireless/bcmdhd/include/linuxver.h
@@ -3,13 +3,13 @@
  * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: linuxver.h,v 13.53.2.2 2010-12-22 23:47:26 Exp $
+ * $Id: linuxver.h 275790 2011-08-04 23:02:47Z $
  */
 
 
@@ -38,7 +38,7 @@
 #else
 #include <linux/autoconf.h>
 #endif
-#endif 
+#endif
 #include <linux/module.h>
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
@@ -48,7 +48,7 @@
 #else
 #define __NO_VERSION__
 #endif
-#endif	
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
 #define module_param(_name_, _type_, _perm_)	MODULE_PARM(_name_, "i")
@@ -72,10 +72,10 @@
 #include <linux/netdevice.h>
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 #include <linux/semaphore.h>
-#endif 
+#endif
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
 #undef IP_TOS
-#endif 
+#endif
 #include <asm/io.h>
 
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
@@ -94,14 +94,14 @@
 #ifndef flush_scheduled_work
 #define flush_scheduled_work() flush_scheduled_tasks()
 #endif
-#endif	
+#endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
 #define	MY_INIT_WORK(_work, _func)	INIT_WORK(_work, _func)
 #else
 #define	MY_INIT_WORK(_work, _func)	INIT_WORK(_work, _func, _work)
 typedef void (*work_func_t)(void *work);
-#endif	
+#endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
 
@@ -113,22 +113,22 @@
 #endif
 #else
 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
-#endif	
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
 #define IRQF_SHARED	SA_SHIRQ
-#endif 
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
 #ifdef	CONFIG_NET_RADIO
-#define	CONFIG_WIRELESS_EXT
+//#define	CONFIG_WIRELESS_EXT
 #endif
-#endif	
+#endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
 #define MOD_INC_USE_COUNT
 #define MOD_DEC_USE_COUNT
-#endif 
+#endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
 #include <linux/sched.h>
@@ -143,7 +143,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
 #include <net/ieee80211.h>
 #endif
-#endif 
+#endif
 
 
 #ifndef __exit
@@ -170,21 +170,21 @@
 
 
 struct pci_device_id {
-	unsigned int vendor, device;		
-	unsigned int subvendor, subdevice;	
-	unsigned int class, class_mask;		
-	unsigned long driver_data;		
+	unsigned int vendor, device;
+	unsigned int subvendor, subdevice;
+	unsigned int class, class_mask;
+	unsigned long driver_data;
 };
 
 struct pci_driver {
 	struct list_head node;
 	char *name;
-	const struct pci_device_id *id_table;	
+	const struct pci_device_id *id_table;
 	int (*probe)(struct pci_dev *dev,
-	             const struct pci_device_id *id); 
-	void (*remove)(struct pci_dev *dev);	
-	void (*suspend)(struct pci_dev *dev);	
-	void (*resume)(struct pci_dev *dev);	
+	             const struct pci_device_id *id);
+	void (*remove)(struct pci_dev *dev);
+	void (*suspend)(struct pci_dev *dev);
+	void (*resume)(struct pci_dev *dev);
 };
 
 #define MODULE_DEVICE_TABLE(type, name)
@@ -195,7 +195,7 @@
 extern int pci_register_driver(struct pci_driver *drv);
 extern void pci_unregister_driver(struct pci_driver *drv);
 
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
 #define pci_module_init pci_register_driver
@@ -209,7 +209,7 @@
 #define module_init(x)	__initcall(x);
 #define module_exit(x)	__exitcall(x);
 #endif
-#endif	
+#endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
 #define WL_USE_NETDEV_OPS
@@ -289,7 +289,7 @@
 #define pci_map_single(cookie, address, size, dir)	virt_to_bus(address)
 #define pci_unmap_single(cookie, address, size, dir)
 
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
 
@@ -316,7 +316,7 @@
 #define netif_queue_stopped(dev)	(dev)->tbusy
 #define netif_running(dev)		(dev)->start
 
-#endif 
+#endif
 
 #define netif_device_attach(dev)	netif_start_queue(dev)
 #define netif_device_detach(dev)	netif_stop_queue(dev)
@@ -347,7 +347,7 @@
 
 #define netif_down(dev)
 
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
 
@@ -366,7 +366,7 @@
 		PREPARE_TQUEUE((_tq), (_routine), (_data));	\
 	} while (0)
 
-#endif	
+#endif
 
 
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
@@ -398,7 +398,7 @@
 		for (i = 0; i < 16; i++)
 			pci_write_config_dword(dev, i * 4, buffer[i]);
 	}
-	
+
 	else {
 		for (i = 0; i < 6; i ++)
 			pci_write_config_dword(dev,
@@ -408,7 +408,7 @@
 	}
 	return 0;
 }
-#endif 
+#endif
 
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
@@ -425,7 +425,7 @@
 #define OLD_MOD_INC_USE_COUNT		do {} while (0)
 #define OLD_MOD_DEC_USE_COUNT		do {} while (0)
 #endif
-#else 
+#else
 #ifndef SET_MODULE_OWNER
 #define SET_MODULE_OWNER(dev)		do {} while (0)
 #endif
@@ -437,7 +437,7 @@
 #endif
 #define OLD_MOD_INC_USE_COUNT		MOD_INC_USE_COUNT
 #define OLD_MOD_DEC_USE_COUNT		MOD_DEC_USE_COUNT
-#endif 
+#endif
 
 #ifndef SET_NETDEV_DEV
 #define SET_NETDEV_DEV(net, pdev)	do {} while (0)
@@ -464,10 +464,10 @@
 #endif
 
 typedef struct {
-	void 	*parent;  
+	void 	*parent;
 	struct	task_struct *p_task;
 	long 	thr_pid;
-	int 	prio; 
+	int 	prio;
 	struct	semaphore sema;
 	bool	terminated;
 	struct	completion completed;
@@ -482,7 +482,11 @@
 #define DBG_THR(x)
 #endif
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
+#define SMP_RD_BARRIER_DEPENDS(x) smp_read_barrier_depends(x)
+#else
 #define SMP_RD_BARRIER_DEPENDS(x) smp_rmb(x)
+#endif
 
 
 #define PROC_START(thread_func, owner, tsk_ctl, flags) \
@@ -533,7 +537,7 @@
 	kill_proc(pid, sig, 1); \
 }
 #endif
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
 #include <linux/time.h>
@@ -572,7 +576,7 @@
 	__ret;								\
 })
 
-#endif 
+#endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
 #define WL_DEV_IF(dev)          ((wl_if_t*)netdev_priv(dev))
@@ -584,10 +588,10 @@
 #define WL_ISR(i, d, p)         wl_isr((i), (d))
 #else
 #define WL_ISR(i, d, p)         wl_isr((i), (d), (p))
-#endif  
+#endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
 #define netdev_priv(dev) dev->priv
-#endif 
+#endif
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/miniopt.h b/drivers/net/wireless/bcmdhd/include/miniopt.h
deleted file mode 100644
index f468420..0000000
--- a/drivers/net/wireless/bcmdhd/include/miniopt.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Command line options parser.
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- * $Id: miniopt.h,v 1.3 2009-01-15 00:06:54 Exp $
- */
-
-
-#ifndef MINI_OPT_H
-#define MINI_OPT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* ---- Include Files ---------------------------------------------------- */
-/* ---- Constants and Types ---------------------------------------------- */
-
-#define MINIOPT_MAXKEY	128	/* Max options */
-typedef struct miniopt {
-
-	/* These are persistent after miniopt_init() */
-	const char* name;		/* name for prompt in error strings */
-	const char* flags;		/* option chars that take no args */
-	bool longflags;		/* long options may be flags */
-	bool opt_end;		/* at end of options (passed a "--") */
-
-	/* These are per-call to miniopt() */
-
-	int consumed;		/* number of argv entries cosumed in
-				 * the most recent call to miniopt()
-				 */
-	bool positional;
-	bool good_int;		/* 'val' member is the result of a sucessful
-				 * strtol conversion of the option value
-				 */
-	char opt;
-	char key[MINIOPT_MAXKEY];
-	char* valstr;		/* positional param, or value for the option,
-				 * or null if the option had
-				 * no accompanying value
-				 */
-	uint uval;		/* strtol translation of valstr */
-	int  val;		/* strtol translation of valstr */
-} miniopt_t;
-
-void miniopt_init(miniopt_t *t, const char* name, const char* flags, bool longflags);
-int miniopt(miniopt_t *t, char **argv);
-
-
-/* ---- Variable Externs ------------------------------------------------- */
-/* ---- Function Prototypes ---------------------------------------------- */
-
-
-#ifdef __cplusplus
-	}
-#endif
-
-#endif  /* MINI_OPT_H  */
diff --git a/drivers/net/wireless/bcmdhd/include/msgtrace.h b/drivers/net/wireless/bcmdhd/include/msgtrace.h
index 721d421..38f310b 100644
--- a/drivers/net/wireless/bcmdhd/include/msgtrace.h
+++ b/drivers/net/wireless/bcmdhd/include/msgtrace.h
@@ -2,13 +2,13 @@
  * Trace messages sent over HBUS
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: msgtrace.h,v 1.4 2009-04-10 04:15:32 Exp $
+ * $Id: msgtrace.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_MSGTRACE_H
@@ -51,7 +51,7 @@
 
 #define MSGTRACE_HDRLEN 	sizeof(msgtrace_hdr_t)
 
-/* The hbus driver generates traces when sending a trace message. This causes endless traces. 
+/* The hbus driver generates traces when sending a trace message. This causes endless traces.
  * This flag must be set to TRUE in any hbus traces. The flag is reset in the function msgtrace_put.
  * This prevents endless traces but generates hasardous lost of traces only in bus device code.
  * It is recommendat to set this flag in macro SD_TRACE but not in SD_ERROR for avoiding missing
diff --git a/drivers/net/wireless/bcmdhd/include/osl.h b/drivers/net/wireless/bcmdhd/include/osl.h
index 80248ee..a12b052 100644
--- a/drivers/net/wireless/bcmdhd/include/osl.h
+++ b/drivers/net/wireless/bcmdhd/include/osl.h
@@ -2,13 +2,13 @@
  * OS Abstraction Layer
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: osl.h,v 13.44.96.1 2010-05-20 11:09:18 Exp $
+ * $Id: osl.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -32,7 +32,7 @@
 typedef struct osl_info osl_t;
 typedef struct osl_dmainfo osldma_t;
 
-#define OSL_PKTTAG_SZ	32 
+#define OSL_PKTTAG_SZ	32
 
 
 typedef void (*pktfree_cb_fn_t)(void *ctx, void *pkt, unsigned int status);
@@ -50,17 +50,17 @@
 
 #ifndef AND_REG
 #define AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
-#endif   
+#endif
 
 #ifndef OR_REG
 #define OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
-#endif   
+#endif
 
 #if !defined(OSL_SYSUPTIME)
 #define OSL_SYSUPTIME() (0)
 #define OSL_SYSUPTIME_SUPPORT FALSE
 #else
 #define OSL_SYSUPTIME_SUPPORT TRUE
-#endif 
+#endif
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/packed_section_end.h b/drivers/net/wireless/bcmdhd/include/packed_section_end.h
index 5d4a876..be3c65f 100644
--- a/drivers/net/wireless/bcmdhd/include/packed_section_end.h
+++ b/drivers/net/wireless/bcmdhd/include/packed_section_end.h
@@ -16,13 +16,13 @@
  *
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -30,11 +30,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: packed_section_end.h,v 1.4 2008-12-09 23:43:22 Exp $
+ * $Id: packed_section_end.h 275703 2011-08-04 20:20:27Z $
  */
 
 
diff --git a/drivers/net/wireless/bcmdhd/include/packed_section_start.h b/drivers/net/wireless/bcmdhd/include/packed_section_start.h
index da2fed6..71bc834 100644
--- a/drivers/net/wireless/bcmdhd/include/packed_section_start.h
+++ b/drivers/net/wireless/bcmdhd/include/packed_section_start.h
@@ -16,13 +16,13 @@
  *
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -30,11 +30,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: packed_section_start.h,v 1.4.124.1 2010-09-17 00:47:03 Exp $
+ * $Id: packed_section_start.h 275703 2011-08-04 20:20:27Z $
  */
 
 
diff --git a/drivers/net/wireless/bcmdhd/include/pcicfg.h b/drivers/net/wireless/bcmdhd/include/pcicfg.h
index fae063a..afbbec0 100644
--- a/drivers/net/wireless/bcmdhd/include/pcicfg.h
+++ b/drivers/net/wireless/bcmdhd/include/pcicfg.h
@@ -2,13 +2,13 @@
  * pcicfg.h: PCI configuration constants and structures.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: pcicfg.h,v 1.50 2009-12-07 21:56:06 Exp $
+ * $Id: pcicfg.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -34,19 +34,19 @@
 #define	PCI_CFG_REV		8
 #define	PCI_CFG_BAR0		0x10
 #define	PCI_CFG_BAR1		0x14
-#define	PCI_BAR0_WIN		0x80	
-#define	PCI_INT_STATUS		0x90	
-#define	PCI_INT_MASK		0x94	
+#define	PCI_BAR0_WIN		0x80
+#define	PCI_INT_STATUS		0x90
+#define	PCI_INT_MASK		0x94
 
 #define PCIE_EXTCFG_OFFSET	0x100
-#define	PCI_BAR0_PCIREGS_OFFSET	(6 * 1024)	
-#define	PCI_BAR0_PCISBR_OFFSET	(4 * 1024)	
+#define	PCI_BAR0_PCIREGS_OFFSET	(6 * 1024)
+#define	PCI_BAR0_PCISBR_OFFSET	(4 * 1024)
 
-#define PCI_BAR0_WINSZ		(16 * 1024)	
+#define PCI_BAR0_WINSZ		(16 * 1024)
 
 
-#define	PCI_16KB0_PCIREGS_OFFSET (8 * 1024)	
-#define	PCI_16KB0_CCREGS_OFFSET	(12 * 1024)	
-#define PCI_16KBB0_WINSZ	(16 * 1024)	
+#define	PCI_16KB0_PCIREGS_OFFSET (8 * 1024)
+#define	PCI_16KB0_CCREGS_OFFSET	(12 * 1024)
+#define PCI_16KBB0_WINSZ	(16 * 1024)
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/802.11.h b/drivers/net/wireless/bcmdhd/include/proto/802.11.h
index 2342cb3..c641476 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/802.11.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/802.11.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,14 +14,14 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
  * Fundamental types and constants relating to 802.11
  *
- * $Id: 802.11.h,v 9.260.2.6 2010-12-15 21:41:14 Exp $
+ * $Id: 802.11.h,v 9.260.2.6 2010-12-15 21:41:14 $
  */
 
 
@@ -42,119 +42,119 @@
 #include <packed_section_start.h>
 
 
-#define DOT11_TU_TO_US          1024    
+#define DOT11_TU_TO_US          1024
 
 
-#define DOT11_A3_HDR_LEN        24  
-#define DOT11_A4_HDR_LEN        30  
-#define DOT11_MAC_HDR_LEN       DOT11_A3_HDR_LEN    
-#define DOT11_FCS_LEN           4   
-#define DOT11_ICV_LEN           4   
-#define DOT11_ICV_AES_LEN       8   
-#define DOT11_QOS_LEN           2   
-#define DOT11_HTC_LEN           4   
+#define DOT11_A3_HDR_LEN        24
+#define DOT11_A4_HDR_LEN        30
+#define DOT11_MAC_HDR_LEN       DOT11_A3_HDR_LEN
+#define DOT11_FCS_LEN           4
+#define DOT11_ICV_LEN           4
+#define DOT11_ICV_AES_LEN       8
+#define DOT11_QOS_LEN           2
+#define DOT11_HTC_LEN           4
 
-#define DOT11_KEY_INDEX_SHIFT       6   
-#define DOT11_IV_LEN            4   
-#define DOT11_IV_TKIP_LEN       8   
-#define DOT11_IV_AES_OCB_LEN        4   
-#define DOT11_IV_AES_CCM_LEN        8   
-#define DOT11_IV_MAX_LEN        8   
+#define DOT11_KEY_INDEX_SHIFT       6
+#define DOT11_IV_LEN            4
+#define DOT11_IV_TKIP_LEN       8
+#define DOT11_IV_AES_OCB_LEN        4
+#define DOT11_IV_AES_CCM_LEN        8
+#define DOT11_IV_MAX_LEN        8
 
 
-#define DOT11_MAX_MPDU_BODY_LEN     2304    
+#define DOT11_MAX_MPDU_BODY_LEN     2304
 
 #define DOT11_MAX_MPDU_LEN      (DOT11_A4_HDR_LEN + \
 					 DOT11_QOS_LEN + \
 					 DOT11_IV_AES_CCM_LEN + \
 					 DOT11_MAX_MPDU_BODY_LEN + \
 					 DOT11_ICV_LEN + \
-					 DOT11_FCS_LEN) 
+					 DOT11_FCS_LEN)
 
-#define DOT11_MAX_SSID_LEN      32  
+#define DOT11_MAX_SSID_LEN      32
 
 
-#define DOT11_DEFAULT_RTS_LEN       2347    
-#define DOT11_MAX_RTS_LEN       2347    
+#define DOT11_DEFAULT_RTS_LEN       2347
+#define DOT11_MAX_RTS_LEN       2347
 
 
-#define DOT11_MIN_FRAG_LEN      256 
-#define DOT11_MAX_FRAG_LEN      2346    
-#define DOT11_DEFAULT_FRAG_LEN      2346    
+#define DOT11_MIN_FRAG_LEN      256
+#define DOT11_MAX_FRAG_LEN      2346
+#define DOT11_DEFAULT_FRAG_LEN      2346
 
 
-#define DOT11_MIN_BEACON_PERIOD     1   
-#define DOT11_MAX_BEACON_PERIOD     0xFFFF  
+#define DOT11_MIN_BEACON_PERIOD     1
+#define DOT11_MAX_BEACON_PERIOD     0xFFFF
 
 
-#define DOT11_MIN_DTIM_PERIOD       1   
-#define DOT11_MAX_DTIM_PERIOD       0xFF    
+#define DOT11_MIN_DTIM_PERIOD       1
+#define DOT11_MAX_DTIM_PERIOD       0xFF
 
 
-#define DOT11_LLC_SNAP_HDR_LEN      8   
-#define DOT11_OUI_LEN           3   
+#define DOT11_LLC_SNAP_HDR_LEN      8
+#define DOT11_OUI_LEN           3
 BWL_PRE_PACKED_STRUCT struct dot11_llc_snap_header {
-	uint8   dsap;               
-	uint8   ssap;               
-	uint8   ctl;                
-	uint8   oui[DOT11_OUI_LEN];     
-	uint16  type;               
+	uint8   dsap;
+	uint8   ssap;
+	uint8   ctl;
+	uint8   oui[DOT11_OUI_LEN];
+	uint16  type;
 } BWL_POST_PACKED_STRUCT;
 
 
-#define RFC1042_HDR_LEN (ETHER_HDR_LEN + DOT11_LLC_SNAP_HDR_LEN)    
+#define RFC1042_HDR_LEN (ETHER_HDR_LEN + DOT11_LLC_SNAP_HDR_LEN)
 
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_header {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   a1;     
-	struct ether_addr   a2;     
-	struct ether_addr   a3;     
-	uint16          seq;        
-	struct ether_addr   a4;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   a1;
+	struct ether_addr   a2;
+	struct ether_addr   a3;
+	uint16          seq;
+	struct ether_addr   a4;
 } BWL_POST_PACKED_STRUCT;
 
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_rts_frame {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   ra;     
-	struct ether_addr   ta;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   ra;
+	struct ether_addr   ta;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_RTS_LEN       16      
+#define DOT11_RTS_LEN       16
 
 BWL_PRE_PACKED_STRUCT struct dot11_cts_frame {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   ra;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   ra;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_CTS_LEN       10      
+#define DOT11_CTS_LEN       10
 
 BWL_PRE_PACKED_STRUCT struct dot11_ack_frame {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   ra;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   ra;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_ACK_LEN       10      
+#define DOT11_ACK_LEN       10
 
 BWL_PRE_PACKED_STRUCT struct dot11_ps_poll_frame {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   bssid;      
-	struct ether_addr   ta;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   bssid;
+	struct ether_addr   ta;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_PS_POLL_LEN   16      
+#define DOT11_PS_POLL_LEN   16
 
 BWL_PRE_PACKED_STRUCT struct dot11_cf_end_frame {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   ra;     
-	struct ether_addr   bssid;      
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   ra;
+	struct ether_addr   bssid;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_CS_END_LEN    16      
+#define DOT11_CS_END_LEN    16
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_wifi_vendor_specific {
@@ -182,55 +182,55 @@
 #define BCM_ACTION_OUI_BYTE2    0x4c
 
 
-#define DOT11_BA_CTL_POLICY_NORMAL  0x0000  
-#define DOT11_BA_CTL_POLICY_NOACK   0x0001  
-#define DOT11_BA_CTL_POLICY_MASK    0x0001  
+#define DOT11_BA_CTL_POLICY_NORMAL  0x0000
+#define DOT11_BA_CTL_POLICY_NOACK   0x0001
+#define DOT11_BA_CTL_POLICY_MASK    0x0001
 
-#define DOT11_BA_CTL_MTID       0x0002  
-#define DOT11_BA_CTL_COMPRESSED     0x0004  
+#define DOT11_BA_CTL_MTID       0x0002
+#define DOT11_BA_CTL_COMPRESSED     0x0004
 
-#define DOT11_BA_CTL_NUMMSDU_MASK   0x0FC0  
-#define DOT11_BA_CTL_NUMMSDU_SHIFT  6   
+#define DOT11_BA_CTL_NUMMSDU_MASK   0x0FC0
+#define DOT11_BA_CTL_NUMMSDU_SHIFT  6
 
-#define DOT11_BA_CTL_TID_MASK       0xF000  
-#define DOT11_BA_CTL_TID_SHIFT      12  
+#define DOT11_BA_CTL_TID_MASK       0xF000
+#define DOT11_BA_CTL_TID_SHIFT      12
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_ctl_header {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   ra;     
-	struct ether_addr   ta;     
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   ra;
+	struct ether_addr   ta;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_CTL_HDR_LEN   16      
+#define DOT11_CTL_HDR_LEN   16
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_bar {
-	uint16          bar_control;    
-	uint16          seqnum;     
+	uint16          bar_control;
+	uint16          seqnum;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_BAR_LEN       4       
+#define DOT11_BAR_LEN       4
 
-#define DOT11_BA_BITMAP_LEN 128     
-#define DOT11_BA_CMP_BITMAP_LEN 8       
+#define DOT11_BA_BITMAP_LEN 128
+#define DOT11_BA_CMP_BITMAP_LEN 8
 
 BWL_PRE_PACKED_STRUCT struct dot11_ba {
-	uint16          ba_control; 
-	uint16          seqnum;     
-	uint8           bitmap[DOT11_BA_BITMAP_LEN];    
+	uint16          ba_control;
+	uint16          seqnum;
+	uint8           bitmap[DOT11_BA_BITMAP_LEN];
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_BA_LEN        4       
+#define DOT11_BA_LEN        4
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_management_header {
-	uint16          fc;     
-	uint16          durid;      
-	struct ether_addr   da;     
-	struct ether_addr   sa;     
-	struct ether_addr   bssid;      
-	uint16          seq;        
+	uint16          fc;
+	uint16          durid;
+	struct ether_addr   da;
+	struct ether_addr   sa;
+	struct ether_addr   bssid;
+	uint16          seq;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_MGMT_HDR_LEN  24      
+#define DOT11_MGMT_HDR_LEN  24
 
 
 
@@ -239,35 +239,35 @@
 	uint16          beacon_interval;
 	uint16          capability;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_BCN_PRB_LEN   12      
-#define DOT11_BCN_PRB_FIXED_LEN 12      
+#define DOT11_BCN_PRB_LEN   12
+#define DOT11_BCN_PRB_FIXED_LEN 12
 
 BWL_PRE_PACKED_STRUCT struct dot11_auth {
-	uint16          alg;        
-	uint16          seq;        
-	uint16          status;     
+	uint16          alg;
+	uint16          seq;
+	uint16          status;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_AUTH_FIXED_LEN    6       
+#define DOT11_AUTH_FIXED_LEN    6
 
 BWL_PRE_PACKED_STRUCT struct dot11_assoc_req {
-	uint16          capability; 
-	uint16          listen;     
+	uint16          capability;
+	uint16          listen;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_ASSOC_REQ_FIXED_LEN   4   
+#define DOT11_ASSOC_REQ_FIXED_LEN   4
 
 BWL_PRE_PACKED_STRUCT struct dot11_reassoc_req {
-	uint16          capability; 
-	uint16          listen;     
-	struct ether_addr   ap;     
+	uint16          capability;
+	uint16          listen;
+	struct ether_addr   ap;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_REASSOC_REQ_FIXED_LEN 10  
+#define DOT11_REASSOC_REQ_FIXED_LEN 10
 
 BWL_PRE_PACKED_STRUCT struct dot11_assoc_resp {
-	uint16          capability; 
-	uint16          status;     
-	uint16          aid;        
+	uint16          capability;
+	uint16          status;
+	uint16          aid;
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_ASSOC_RESP_FIXED_LEN  6   
+#define DOT11_ASSOC_RESP_FIXED_LEN  6
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_measure {
 	uint8   category;
@@ -275,7 +275,7 @@
 	uint8   token;
 	uint8   data[1];
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_ACTION_MEASURE_LEN    3   
+#define DOT11_ACTION_MEASURE_LEN    3
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_ht_ch_width {
 	uint8   category;
@@ -313,7 +313,7 @@
 	uint8 margin;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_tpc_rep dot11_tpc_rep_t;
-#define DOT11_MNG_IE_TPC_REPORT_LEN 2   
+#define DOT11_MNG_IE_TPC_REPORT_LEN 2
 
 BWL_PRE_PACKED_STRUCT struct dot11_supp_channels {
 	uint8 id;
@@ -325,28 +325,28 @@
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_extch {
-	uint8   id;     
-	uint8   len;        
+	uint8   id;
+	uint8   len;
 	uint8   extch;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_extch dot11_extch_ie_t;
 
 BWL_PRE_PACKED_STRUCT struct dot11_brcm_extch {
-	uint8   id;     
-	uint8   len;        
-	uint8   oui[3];     
-	uint8   type;           
+	uint8   id;
+	uint8   len;
+	uint8   oui[3];
+	uint8   type;
 	uint8   extch;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_brcm_extch dot11_brcm_extch_ie_t;
 
 #define BRCM_EXTCH_IE_LEN   5
-#define BRCM_EXTCH_IE_TYPE  53  
+#define BRCM_EXTCH_IE_TYPE  53
 #define DOT11_EXTCH_IE_LEN  1
-#define DOT11_EXT_CH_MASK   0x03    
-#define DOT11_EXT_CH_UPPER  0x01    
-#define DOT11_EXT_CH_LOWER  0x03    
-#define DOT11_EXT_CH_NONE   0x00    
+#define DOT11_EXT_CH_MASK   0x03
+#define DOT11_EXT_CH_UPPER  0x01
+#define DOT11_EXT_CH_LOWER  0x03
+#define DOT11_EXT_CH_NONE   0x00
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_frmhdr {
 	uint8   category;
@@ -357,52 +357,52 @@
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_channel_switch {
-	uint8 id;   
-	uint8 len;  
-	uint8 mode; 
-	uint8 channel;  
-	uint8 count;    
+	uint8 id;
+	uint8 len;
+	uint8 mode;
+	uint8 channel;
+	uint8 count;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_channel_switch dot11_chan_switch_ie_t;
 
-#define DOT11_SWITCH_IE_LEN 3   
+#define DOT11_SWITCH_IE_LEN 3
 
-#define DOT11_CSA_MODE_ADVISORY     0   
-#define DOT11_CSA_MODE_NO_TX        1   
+#define DOT11_CSA_MODE_ADVISORY     0
+#define DOT11_CSA_MODE_NO_TX        1
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_switch_channel {
 	uint8   category;
 	uint8   action;
-	dot11_chan_switch_ie_t chan_switch_ie;  
-	dot11_brcm_extch_ie_t extch_ie;     
+	dot11_chan_switch_ie_t chan_switch_ie;
+	dot11_brcm_extch_ie_t extch_ie;
 } BWL_POST_PACKED_STRUCT;
 
 BWL_PRE_PACKED_STRUCT struct dot11_csa_body {
-	uint8 mode; 
-	uint8 reg;  
-	uint8 channel;  
-	uint8 count;    
+	uint8 mode;
+	uint8 reg;
+	uint8 channel;
+	uint8 count;
 } BWL_POST_PACKED_STRUCT;
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_ext_csa {
-	uint8 id;   
-	uint8 len;  
-	struct dot11_csa_body b;    
+	uint8 id;
+	uint8 len;
+	struct dot11_csa_body b;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_ext_csa dot11_ext_csa_ie_t;
-#define DOT11_EXT_CSA_IE_LEN    4   
+#define DOT11_EXT_CSA_IE_LEN    4
 
 BWL_PRE_PACKED_STRUCT struct dot11_action_ext_csa {
 	uint8   category;
 	uint8   action;
-	dot11_ext_csa_ie_t chan_switch_ie;  
+	dot11_ext_csa_ie_t chan_switch_ie;
 } BWL_POST_PACKED_STRUCT;
 
 BWL_PRE_PACKED_STRUCT struct dot11y_action_ext_csa {
 	uint8   category;
 	uint8   action;
-	struct dot11_csa_body b;    
+	struct dot11_csa_body b;
 } BWL_POST_PACKED_STRUCT;
 
 BWL_PRE_PACKED_STRUCT struct dot11_obss_coex {
@@ -411,7 +411,7 @@
 	uint8   info;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_obss_coex dot11_obss_coex_t;
-#define DOT11_OBSS_COEXINFO_LEN 1   
+#define DOT11_OBSS_COEXINFO_LEN 1
 
 #define DOT11_OBSS_COEX_INFO_REQ        0x01
 #define DOT11_OBSS_COEX_40MHZ_INTOLERANT    0x02
@@ -424,7 +424,7 @@
 	uint8   chanlist[1];
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_obss_chanlist dot11_obss_chanlist_t;
-#define DOT11_OBSS_CHANLIST_FIXED_LEN   1   
+#define DOT11_OBSS_CHANLIST_FIXED_LEN   1
 
 BWL_PRE_PACKED_STRUCT struct dot11_extcap_ie {
 	uint8 id;
@@ -436,34 +436,34 @@
 
 
 
-#define DOT11_MEASURE_TYPE_BASIC    0   
-#define DOT11_MEASURE_TYPE_CCA      1   
-#define DOT11_MEASURE_TYPE_RPI      2   
-#define DOT11_MEASURE_TYPE_CHLOAD       3   
-#define DOT11_MEASURE_TYPE_NOISE        4   
-#define DOT11_MEASURE_TYPE_BEACON       5   
-#define DOT11_MEASURE_TYPE_FRAME    6   
-#define DOT11_MEASURE_TYPE_STATS        7   
-#define DOT11_MEASURE_TYPE_LCI      8   
-#define DOT11_MEASURE_TYPE_TXSTREAM     9   
-#define DOT11_MEASURE_TYPE_PAUSE        255 
+#define DOT11_MEASURE_TYPE_BASIC    0
+#define DOT11_MEASURE_TYPE_CCA      1
+#define DOT11_MEASURE_TYPE_RPI      2
+#define DOT11_MEASURE_TYPE_CHLOAD       3
+#define DOT11_MEASURE_TYPE_NOISE        4
+#define DOT11_MEASURE_TYPE_BEACON       5
+#define DOT11_MEASURE_TYPE_FRAME    6
+#define DOT11_MEASURE_TYPE_STATS        7
+#define DOT11_MEASURE_TYPE_LCI      8
+#define DOT11_MEASURE_TYPE_TXSTREAM     9
+#define DOT11_MEASURE_TYPE_PAUSE        255
 
 
-#define DOT11_MEASURE_MODE_PARALLEL     (1<<0)  
-#define DOT11_MEASURE_MODE_ENABLE   (1<<1)  
-#define DOT11_MEASURE_MODE_REQUEST  (1<<2)  
-#define DOT11_MEASURE_MODE_REPORT   (1<<3)  
-#define DOT11_MEASURE_MODE_DUR  (1<<4)  
+#define DOT11_MEASURE_MODE_PARALLEL     (1<<0)
+#define DOT11_MEASURE_MODE_ENABLE   (1<<1)
+#define DOT11_MEASURE_MODE_REQUEST  (1<<2)
+#define DOT11_MEASURE_MODE_REPORT   (1<<3)
+#define DOT11_MEASURE_MODE_DUR  (1<<4)
 
-#define DOT11_MEASURE_MODE_LATE     (1<<0)  
-#define DOT11_MEASURE_MODE_INCAPABLE    (1<<1)  
-#define DOT11_MEASURE_MODE_REFUSED  (1<<2)  
+#define DOT11_MEASURE_MODE_LATE     (1<<0)
+#define DOT11_MEASURE_MODE_INCAPABLE    (1<<1)
+#define DOT11_MEASURE_MODE_REFUSED  (1<<2)
 
-#define DOT11_MEASURE_BASIC_MAP_BSS ((uint8)(1<<0)) 
-#define DOT11_MEASURE_BASIC_MAP_OFDM    ((uint8)(1<<1)) 
-#define DOT11_MEASURE_BASIC_MAP_UKNOWN  ((uint8)(1<<2)) 
-#define DOT11_MEASURE_BASIC_MAP_RADAR   ((uint8)(1<<3)) 
-#define DOT11_MEASURE_BASIC_MAP_UNMEAS  ((uint8)(1<<4)) 
+#define DOT11_MEASURE_BASIC_MAP_BSS ((uint8)(1<<0))
+#define DOT11_MEASURE_BASIC_MAP_OFDM    ((uint8)(1<<1))
+#define DOT11_MEASURE_BASIC_MAP_UKNOWN  ((uint8)(1<<2))
+#define DOT11_MEASURE_BASIC_MAP_RADAR   ((uint8)(1<<3))
+#define DOT11_MEASURE_BASIC_MAP_UNMEAS  ((uint8)(1<<4))
 
 BWL_PRE_PACKED_STRUCT struct dot11_meas_req {
 	uint8 id;
@@ -476,9 +476,9 @@
 	uint16 duration;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_meas_req dot11_meas_req_t;
-#define DOT11_MNG_IE_MREQ_LEN 14    
+#define DOT11_MNG_IE_MREQ_LEN 14
 
-#define DOT11_MNG_IE_MREQ_FIXED_LEN 3   
+#define DOT11_MNG_IE_MREQ_FIXED_LEN 3
 
 BWL_PRE_PACKED_STRUCT struct dot11_meas_rep {
 	uint8 id;
@@ -500,7 +500,7 @@
 typedef struct dot11_meas_rep dot11_meas_rep_t;
 
 
-#define DOT11_MNG_IE_MREP_FIXED_LEN 3   
+#define DOT11_MNG_IE_MREP_FIXED_LEN 3
 
 BWL_PRE_PACKED_STRUCT struct dot11_meas_rep_basic {
 	uint8 channel;
@@ -509,15 +509,15 @@
 	uint8 map;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_meas_rep_basic dot11_meas_rep_basic_t;
-#define DOT11_MEASURE_BASIC_REP_LEN 12  
+#define DOT11_MEASURE_BASIC_REP_LEN 12
 
 BWL_PRE_PACKED_STRUCT struct dot11_quiet {
 	uint8 id;
 	uint8 len;
-	uint8 count;    
-	uint8 period;   
-	uint16 duration;    
-	uint16 offset;  
+	uint8 count;
+	uint8 period;
+	uint16 duration;
+	uint16 offset;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_quiet dot11_quiet_t;
 
@@ -537,26 +537,26 @@
 typedef struct dot11_ibss_dfs dot11_ibss_dfs_t;
 
 
-#define WME_OUI         "\x00\x50\xf2"  
+#define WME_OUI         "\x00\x50\xf2"
 #define WME_OUI_LEN     3
-#define WME_OUI_TYPE        2   
-#define WME_VER         1   
-#define WME_TYPE        2   
-#define WME_SUBTYPE_IE      0   
-#define WME_SUBTYPE_PARAM_IE    1   
-#define WME_SUBTYPE_TSPEC   2   
+#define WME_OUI_TYPE        2
+#define WME_VER         1
+#define WME_TYPE        2
+#define WME_SUBTYPE_IE      0
+#define WME_SUBTYPE_PARAM_IE    1
+#define WME_SUBTYPE_TSPEC   2
 
 
-#define AC_BE           0   
-#define AC_BK           1   
-#define AC_VI           2   
-#define AC_VO           3   
-#define AC_COUNT        4   
+#define AC_BE           0
+#define AC_BK           1
+#define AC_VI           2
+#define AC_VO           3
+#define AC_COUNT        4
 
-typedef uint8 ac_bitmap_t;  
+typedef uint8 ac_bitmap_t;
 
-#define AC_BITMAP_NONE      0x0 
-#define AC_BITMAP_ALL       0xf 
+#define AC_BITMAP_NONE      0x0
+#define AC_BITMAP_ALL       0xf
 #define AC_BITMAP_TST(ab, ac)   (((ab) & (1 << (ac))) != 0)
 #define AC_BITMAP_SET(ab, ac)   (((ab) |= (1 << (ac))))
 #define AC_BITMAP_RESET(ab, ac) (((ab) &= ~(1 << (ac))))
@@ -570,12 +570,12 @@
 	uint8 qosinfo;
 } BWL_POST_PACKED_STRUCT;
 typedef struct wme_ie wme_ie_t;
-#define WME_IE_LEN 7    
+#define WME_IE_LEN 7
 
 BWL_PRE_PACKED_STRUCT struct edcf_acparam {
 	uint8   ACI;
 	uint8   ECW;
-	uint16  TXOP;       
+	uint16  TXOP;
 } BWL_POST_PACKED_STRUCT;
 typedef struct edcf_acparam edcf_acparam_t;
 
@@ -590,80 +590,80 @@
 	edcf_acparam_t acparam[AC_COUNT];
 } BWL_POST_PACKED_STRUCT;
 typedef struct wme_param_ie wme_param_ie_t;
-#define WME_PARAM_IE_LEN            24          
+#define WME_PARAM_IE_LEN            24
 
 
-#define WME_QI_AP_APSD_MASK         0x80        
-#define WME_QI_AP_APSD_SHIFT        7           
-#define WME_QI_AP_COUNT_MASK        0x0f        
-#define WME_QI_AP_COUNT_SHIFT       0           
+#define WME_QI_AP_APSD_MASK         0x80
+#define WME_QI_AP_APSD_SHIFT        7
+#define WME_QI_AP_COUNT_MASK        0x0f
+#define WME_QI_AP_COUNT_SHIFT       0
 
 
-#define WME_QI_STA_MAXSPLEN_MASK    0x60        
-#define WME_QI_STA_MAXSPLEN_SHIFT   5           
-#define WME_QI_STA_APSD_ALL_MASK    0xf         
-#define WME_QI_STA_APSD_ALL_SHIFT   0           
-#define WME_QI_STA_APSD_BE_MASK     0x8         
-#define WME_QI_STA_APSD_BE_SHIFT    3           
-#define WME_QI_STA_APSD_BK_MASK     0x4         
-#define WME_QI_STA_APSD_BK_SHIFT    2           
-#define WME_QI_STA_APSD_VI_MASK     0x2         
-#define WME_QI_STA_APSD_VI_SHIFT    1           
-#define WME_QI_STA_APSD_VO_MASK     0x1         
-#define WME_QI_STA_APSD_VO_SHIFT    0           
+#define WME_QI_STA_MAXSPLEN_MASK    0x60
+#define WME_QI_STA_MAXSPLEN_SHIFT   5
+#define WME_QI_STA_APSD_ALL_MASK    0xf
+#define WME_QI_STA_APSD_ALL_SHIFT   0
+#define WME_QI_STA_APSD_BE_MASK     0x8
+#define WME_QI_STA_APSD_BE_SHIFT    3
+#define WME_QI_STA_APSD_BK_MASK     0x4
+#define WME_QI_STA_APSD_BK_SHIFT    2
+#define WME_QI_STA_APSD_VI_MASK     0x2
+#define WME_QI_STA_APSD_VI_SHIFT    1
+#define WME_QI_STA_APSD_VO_MASK     0x1
+#define WME_QI_STA_APSD_VO_SHIFT    0
 
 
-#define EDCF_AIFSN_MIN               1           
-#define EDCF_AIFSN_MAX               15          
-#define EDCF_AIFSN_MASK              0x0f        
-#define EDCF_ACM_MASK                0x10        
-#define EDCF_ACI_MASK                0x60        
-#define EDCF_ACI_SHIFT               5           
-#define EDCF_AIFSN_SHIFT             12          
+#define EDCF_AIFSN_MIN               1
+#define EDCF_AIFSN_MAX               15
+#define EDCF_AIFSN_MASK              0x0f
+#define EDCF_ACM_MASK                0x10
+#define EDCF_ACI_MASK                0x60
+#define EDCF_ACI_SHIFT               5
+#define EDCF_AIFSN_SHIFT             12
 
 
-#define EDCF_ECW_MIN                 0           
-#define EDCF_ECW_MAX                 15          
+#define EDCF_ECW_MIN                 0
+#define EDCF_ECW_MAX                 15
 #define EDCF_ECW2CW(exp)             ((1 << (exp)) - 1)
-#define EDCF_ECWMIN_MASK             0x0f        
-#define EDCF_ECWMAX_MASK             0xf0        
-#define EDCF_ECWMAX_SHIFT            4           
+#define EDCF_ECWMIN_MASK             0x0f
+#define EDCF_ECWMAX_MASK             0xf0
+#define EDCF_ECWMAX_SHIFT            4
 
 
-#define EDCF_TXOP_MIN                0           
-#define EDCF_TXOP_MAX                65535       
+#define EDCF_TXOP_MIN                0
+#define EDCF_TXOP_MAX                65535
 #define EDCF_TXOP2USEC(txop)         ((txop) << 5)
 
 
 #define NON_EDCF_AC_BE_ACI_STA          0x02
 
 
-#define EDCF_AC_BE_ACI_STA           0x03   
-#define EDCF_AC_BE_ECW_STA           0xA4   
-#define EDCF_AC_BE_TXOP_STA          0x0000 
-#define EDCF_AC_BK_ACI_STA           0x27   
-#define EDCF_AC_BK_ECW_STA           0xA4   
-#define EDCF_AC_BK_TXOP_STA          0x0000 
-#define EDCF_AC_VI_ACI_STA           0x42   
-#define EDCF_AC_VI_ECW_STA           0x43   
-#define EDCF_AC_VI_TXOP_STA          0x005e 
-#define EDCF_AC_VO_ACI_STA           0x62   
-#define EDCF_AC_VO_ECW_STA           0x32   
-#define EDCF_AC_VO_TXOP_STA          0x002f 
+#define EDCF_AC_BE_ACI_STA           0x03
+#define EDCF_AC_BE_ECW_STA           0xA4
+#define EDCF_AC_BE_TXOP_STA          0x0000
+#define EDCF_AC_BK_ACI_STA           0x27
+#define EDCF_AC_BK_ECW_STA           0xA4
+#define EDCF_AC_BK_TXOP_STA          0x0000
+#define EDCF_AC_VI_ACI_STA           0x42
+#define EDCF_AC_VI_ECW_STA           0x43
+#define EDCF_AC_VI_TXOP_STA          0x005e
+#define EDCF_AC_VO_ACI_STA           0x62
+#define EDCF_AC_VO_ECW_STA           0x32
+#define EDCF_AC_VO_TXOP_STA          0x002f
 
 
-#define EDCF_AC_BE_ACI_AP            0x03   
-#define EDCF_AC_BE_ECW_AP            0x64   
-#define EDCF_AC_BE_TXOP_AP           0x0000 
-#define EDCF_AC_BK_ACI_AP            0x27   
-#define EDCF_AC_BK_ECW_AP            0xA4   
-#define EDCF_AC_BK_TXOP_AP           0x0000 
-#define EDCF_AC_VI_ACI_AP            0x41   
-#define EDCF_AC_VI_ECW_AP            0x43   
-#define EDCF_AC_VI_TXOP_AP           0x005e 
-#define EDCF_AC_VO_ACI_AP            0x61   
-#define EDCF_AC_VO_ECW_AP            0x32   
-#define EDCF_AC_VO_TXOP_AP           0x002f 
+#define EDCF_AC_BE_ACI_AP            0x03
+#define EDCF_AC_BE_ECW_AP            0x64
+#define EDCF_AC_BE_TXOP_AP           0x0000
+#define EDCF_AC_BK_ACI_AP            0x27
+#define EDCF_AC_BK_ECW_AP            0xA4
+#define EDCF_AC_BK_TXOP_AP           0x0000
+#define EDCF_AC_VI_ACI_AP            0x41
+#define EDCF_AC_VI_ECW_AP            0x43
+#define EDCF_AC_VI_TXOP_AP           0x005e
+#define EDCF_AC_VO_ACI_AP            0x61
+#define EDCF_AC_VO_ECW_AP            0x32
+#define EDCF_AC_VO_TXOP_AP           0x002f
 
 
 BWL_PRE_PACKED_STRUCT struct edca_param_ie {
@@ -672,7 +672,7 @@
 	edcf_acparam_t acparam[AC_COUNT];
 } BWL_POST_PACKED_STRUCT;
 typedef struct edca_param_ie edca_param_ie_t;
-#define EDCA_PARAM_IE_LEN            18          
+#define EDCA_PARAM_IE_LEN            18
 
 
 BWL_PRE_PACKED_STRUCT struct qos_cap_ie {
@@ -681,131 +681,131 @@
 typedef struct qos_cap_ie qos_cap_ie_t;
 
 BWL_PRE_PACKED_STRUCT struct dot11_qbss_load_ie {
-	uint8 id;           
+	uint8 id;
 	uint8 length;
-	uint16 station_count;       
-	uint8 channel_utilization;  
-	uint16 aac;             
+	uint16 station_count;
+	uint8 channel_utilization;
+	uint16 aac;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_qbss_load_ie dot11_qbss_load_ie_t;
 
 
-#define FIXED_MSDU_SIZE 0x8000      
-#define MSDU_SIZE_MASK  0x7fff      
+#define FIXED_MSDU_SIZE 0x8000
+#define MSDU_SIZE_MASK  0x7fff
 
 
 
-#define INTEGER_SHIFT   13  
-#define FRACTION_MASK   0x1FFF  
+#define INTEGER_SHIFT   13
+#define FRACTION_MASK   0x1FFF
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_management_notification {
-	uint8 category;         
+	uint8 category;
 	uint8 action;
 	uint8 token;
 	uint8 status;
-	uint8 data[1];          
+	uint8 data[1];
 } BWL_POST_PACKED_STRUCT;
-#define DOT11_MGMT_NOTIFICATION_LEN 4   
+#define DOT11_MGMT_NOTIFICATION_LEN 4
 
 
-#define WME_ADDTS_REQUEST   0   
-#define WME_ADDTS_RESPONSE  1   
-#define WME_DELTS_REQUEST   2   
+#define WME_ADDTS_REQUEST   0
+#define WME_ADDTS_RESPONSE  1
+#define WME_DELTS_REQUEST   2
 
 
-#define WME_ADMISSION_ACCEPTED      0   
-#define WME_INVALID_PARAMETERS      1   
-#define WME_ADMISSION_REFUSED       3   
+#define WME_ADMISSION_ACCEPTED      0
+#define WME_INVALID_PARAMETERS      1
+#define WME_ADMISSION_REFUSED       3
 
 
 #define BCN_PRB_SSID(body) ((char*)(body) + DOT11_BCN_PRB_LEN)
 
 
-#define DOT11_OPEN_SYSTEM   0   
-#define DOT11_SHARED_KEY    1   
-#define DOT11_OPEN_SHARED   2   
-#define DOT11_FAST_BSS      3   
-#define DOT11_CHALLENGE_LEN 128 
+#define DOT11_OPEN_SYSTEM   0
+#define DOT11_SHARED_KEY    1
+#define DOT11_FAST_BSS		3
+#define DOT11_OPEN_SHARED	2
+#define DOT11_CHALLENGE_LEN 128
 
 
-#define FC_PVER_MASK        0x3 
-#define FC_PVER_SHIFT       0   
-#define FC_TYPE_MASK        0xC 
-#define FC_TYPE_SHIFT       2   
-#define FC_SUBTYPE_MASK     0xF0    
-#define FC_SUBTYPE_SHIFT    4   
-#define FC_TODS         0x100   
-#define FC_TODS_SHIFT       8   
-#define FC_FROMDS       0x200   
-#define FC_FROMDS_SHIFT     9   
-#define FC_MOREFRAG     0x400   
-#define FC_MOREFRAG_SHIFT   10  
-#define FC_RETRY        0x800   
-#define FC_RETRY_SHIFT      11  
-#define FC_PM           0x1000  
-#define FC_PM_SHIFT     12  
-#define FC_MOREDATA     0x2000  
-#define FC_MOREDATA_SHIFT   13  
-#define FC_WEP          0x4000  
-#define FC_WEP_SHIFT        14  
-#define FC_ORDER        0x8000  
-#define FC_ORDER_SHIFT      15  
+#define FC_PVER_MASK        0x3
+#define FC_PVER_SHIFT       0
+#define FC_TYPE_MASK        0xC
+#define FC_TYPE_SHIFT       2
+#define FC_SUBTYPE_MASK     0xF0
+#define FC_SUBTYPE_SHIFT    4
+#define FC_TODS         0x100
+#define FC_TODS_SHIFT       8
+#define FC_FROMDS       0x200
+#define FC_FROMDS_SHIFT     9
+#define FC_MOREFRAG     0x400
+#define FC_MOREFRAG_SHIFT   10
+#define FC_RETRY        0x800
+#define FC_RETRY_SHIFT      11
+#define FC_PM           0x1000
+#define FC_PM_SHIFT     12
+#define FC_MOREDATA     0x2000
+#define FC_MOREDATA_SHIFT   13
+#define FC_WEP          0x4000
+#define FC_WEP_SHIFT        14
+#define FC_ORDER        0x8000
+#define FC_ORDER_SHIFT      15
 
 
-#define SEQNUM_SHIFT        4   
-#define SEQNUM_MAX      0x1000  
-#define FRAGNUM_MASK        0xF 
+#define SEQNUM_SHIFT        4
+#define SEQNUM_MAX      0x1000
+#define FRAGNUM_MASK        0xF
 
 
 
 
-#define FC_TYPE_MNG     0   
-#define FC_TYPE_CTL     1   
-#define FC_TYPE_DATA        2   
+#define FC_TYPE_MNG     0
+#define FC_TYPE_CTL     1
+#define FC_TYPE_DATA        2
 
 
-#define FC_SUBTYPE_ASSOC_REQ        0   
-#define FC_SUBTYPE_ASSOC_RESP       1   
-#define FC_SUBTYPE_REASSOC_REQ      2   
-#define FC_SUBTYPE_REASSOC_RESP     3   
-#define FC_SUBTYPE_PROBE_REQ        4   
-#define FC_SUBTYPE_PROBE_RESP       5   
-#define FC_SUBTYPE_BEACON       8   
-#define FC_SUBTYPE_ATIM         9   
-#define FC_SUBTYPE_DISASSOC     10  
-#define FC_SUBTYPE_AUTH         11  
-#define FC_SUBTYPE_DEAUTH       12  
-#define FC_SUBTYPE_ACTION       13  
-#define FC_SUBTYPE_ACTION_NOACK     14  
+#define FC_SUBTYPE_ASSOC_REQ        0
+#define FC_SUBTYPE_ASSOC_RESP       1
+#define FC_SUBTYPE_REASSOC_REQ      2
+#define FC_SUBTYPE_REASSOC_RESP     3
+#define FC_SUBTYPE_PROBE_REQ        4
+#define FC_SUBTYPE_PROBE_RESP       5
+#define FC_SUBTYPE_BEACON       8
+#define FC_SUBTYPE_ATIM         9
+#define FC_SUBTYPE_DISASSOC     10
+#define FC_SUBTYPE_AUTH         11
+#define FC_SUBTYPE_DEAUTH       12
+#define FC_SUBTYPE_ACTION       13
+#define FC_SUBTYPE_ACTION_NOACK     14
 
 
-#define FC_SUBTYPE_CTL_WRAPPER      7   
-#define FC_SUBTYPE_BLOCKACK_REQ     8   
-#define FC_SUBTYPE_BLOCKACK     9   
-#define FC_SUBTYPE_PS_POLL      10  
-#define FC_SUBTYPE_RTS          11  
-#define FC_SUBTYPE_CTS          12  
-#define FC_SUBTYPE_ACK          13  
-#define FC_SUBTYPE_CF_END       14  
-#define FC_SUBTYPE_CF_END_ACK       15  
+#define FC_SUBTYPE_CTL_WRAPPER      7
+#define FC_SUBTYPE_BLOCKACK_REQ     8
+#define FC_SUBTYPE_BLOCKACK     9
+#define FC_SUBTYPE_PS_POLL      10
+#define FC_SUBTYPE_RTS          11
+#define FC_SUBTYPE_CTS          12
+#define FC_SUBTYPE_ACK          13
+#define FC_SUBTYPE_CF_END       14
+#define FC_SUBTYPE_CF_END_ACK       15
 
 
-#define FC_SUBTYPE_DATA         0   
-#define FC_SUBTYPE_DATA_CF_ACK      1   
-#define FC_SUBTYPE_DATA_CF_POLL     2   
-#define FC_SUBTYPE_DATA_CF_ACK_POLL 3   
-#define FC_SUBTYPE_NULL         4   
-#define FC_SUBTYPE_CF_ACK       5   
-#define FC_SUBTYPE_CF_POLL      6   
-#define FC_SUBTYPE_CF_ACK_POLL      7   
-#define FC_SUBTYPE_QOS_DATA     8   
-#define FC_SUBTYPE_QOS_DATA_CF_ACK  9   
-#define FC_SUBTYPE_QOS_DATA_CF_POLL 10  
-#define FC_SUBTYPE_QOS_DATA_CF_ACK_POLL 11  
-#define FC_SUBTYPE_QOS_NULL     12  
-#define FC_SUBTYPE_QOS_CF_POLL      14  
-#define FC_SUBTYPE_QOS_CF_ACK_POLL  15  
+#define FC_SUBTYPE_DATA         0
+#define FC_SUBTYPE_DATA_CF_ACK      1
+#define FC_SUBTYPE_DATA_CF_POLL     2
+#define FC_SUBTYPE_DATA_CF_ACK_POLL 3
+#define FC_SUBTYPE_NULL         4
+#define FC_SUBTYPE_CF_ACK       5
+#define FC_SUBTYPE_CF_POLL      6
+#define FC_SUBTYPE_CF_ACK_POLL      7
+#define FC_SUBTYPE_QOS_DATA     8
+#define FC_SUBTYPE_QOS_DATA_CF_ACK  9
+#define FC_SUBTYPE_QOS_DATA_CF_POLL 10
+#define FC_SUBTYPE_QOS_DATA_CF_ACK_POLL 11
+#define FC_SUBTYPE_QOS_NULL     12
+#define FC_SUBTYPE_QOS_CF_POLL      14
+#define FC_SUBTYPE_QOS_CF_ACK_POLL  15
 
 
 #define FC_SUBTYPE_ANY_QOS(s)       (((s) & 8) != 0)
@@ -814,341 +814,516 @@
 #define FC_SUBTYPE_ANY_CF_ACK(s)    (((s) & 1) != 0)
 
 
-#define FC_KIND_MASK        (FC_TYPE_MASK | FC_SUBTYPE_MASK)    
+#define FC_KIND_MASK        (FC_TYPE_MASK | FC_SUBTYPE_MASK)
 
-#define FC_KIND(t, s)   (((t) << FC_TYPE_SHIFT) | ((s) << FC_SUBTYPE_SHIFT))    
+#define FC_KIND(t, s)   (((t) << FC_TYPE_SHIFT) | ((s) << FC_SUBTYPE_SHIFT))
 
-#define FC_SUBTYPE(fc)  (((fc) & FC_SUBTYPE_MASK) >> FC_SUBTYPE_SHIFT)  
-#define FC_TYPE(fc) (((fc) & FC_TYPE_MASK) >> FC_TYPE_SHIFT)    
+#define FC_SUBTYPE(fc)  (((fc) & FC_SUBTYPE_MASK) >> FC_SUBTYPE_SHIFT)
+#define FC_TYPE(fc) (((fc) & FC_TYPE_MASK) >> FC_TYPE_SHIFT)
 
-#define FC_ASSOC_REQ    FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ASSOC_REQ)  
-#define FC_ASSOC_RESP   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ASSOC_RESP) 
-#define FC_REASSOC_REQ  FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_REASSOC_REQ)    
-#define FC_REASSOC_RESP FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_REASSOC_RESP)   
-#define FC_PROBE_REQ    FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_PROBE_REQ)  
-#define FC_PROBE_RESP   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_PROBE_RESP) 
-#define FC_BEACON   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_BEACON)     
-#define FC_DISASSOC FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_DISASSOC)   
-#define FC_AUTH     FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_AUTH)       
-#define FC_DEAUTH   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_DEAUTH)     
-#define FC_ACTION   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ACTION)     
-#define FC_ACTION_NOACK FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ACTION_NOACK)   
+#define FC_ASSOC_REQ    FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ASSOC_REQ)
+#define FC_ASSOC_RESP   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ASSOC_RESP)
+#define FC_REASSOC_REQ  FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_REASSOC_REQ)
+#define FC_REASSOC_RESP FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_REASSOC_RESP)
+#define FC_PROBE_REQ    FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_PROBE_REQ)
+#define FC_PROBE_RESP   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_PROBE_RESP)
+#define FC_BEACON   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_BEACON)
+#define FC_DISASSOC FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_DISASSOC)
+#define FC_AUTH     FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_AUTH)
+#define FC_DEAUTH   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_DEAUTH)
+#define FC_ACTION   FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ACTION)
+#define FC_ACTION_NOACK FC_KIND(FC_TYPE_MNG, FC_SUBTYPE_ACTION_NOACK)
 
-#define FC_CTL_WRAPPER  FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CTL_WRAPPER)    
-#define FC_BLOCKACK_REQ FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_BLOCKACK_REQ)   
-#define FC_BLOCKACK FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_BLOCKACK)   
-#define FC_PS_POLL  FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_PS_POLL)    
-#define FC_RTS      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_RTS)        
-#define FC_CTS      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CTS)        
-#define FC_ACK      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_ACK)        
-#define FC_CF_END   FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CF_END)     
-#define FC_CF_END_ACK   FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CF_END_ACK) 
+#define FC_CTL_WRAPPER  FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CTL_WRAPPER)
+#define FC_BLOCKACK_REQ FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_BLOCKACK_REQ)
+#define FC_BLOCKACK FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_BLOCKACK)
+#define FC_PS_POLL  FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_PS_POLL)
+#define FC_RTS      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_RTS)
+#define FC_CTS      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CTS)
+#define FC_ACK      FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_ACK)
+#define FC_CF_END   FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CF_END)
+#define FC_CF_END_ACK   FC_KIND(FC_TYPE_CTL, FC_SUBTYPE_CF_END_ACK)
 
-#define FC_DATA     FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_DATA)      
-#define FC_NULL_DATA    FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_NULL)      
-#define FC_DATA_CF_ACK  FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_DATA_CF_ACK)   
-#define FC_QOS_DATA FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_QOS_DATA)  
-#define FC_QOS_NULL FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_QOS_NULL)  
+#define FC_DATA     FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_DATA)
+#define FC_NULL_DATA    FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_NULL)
+#define FC_DATA_CF_ACK  FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_DATA_CF_ACK)
+#define FC_QOS_DATA FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_QOS_DATA)
+#define FC_QOS_NULL FC_KIND(FC_TYPE_DATA, FC_SUBTYPE_QOS_NULL)
 
 
 
 
-#define QOS_PRIO_SHIFT      0   
-#define QOS_PRIO_MASK       0x0007  
-#define QOS_PRIO(qos)       (((qos) & QOS_PRIO_MASK) >> QOS_PRIO_SHIFT) 
+#define QOS_PRIO_SHIFT      0
+#define QOS_PRIO_MASK       0x0007
+#define QOS_PRIO(qos)       (((qos) & QOS_PRIO_MASK) >> QOS_PRIO_SHIFT)
 
 
-#define QOS_TID_SHIFT       0   
-#define QOS_TID_MASK        0x000f  
-#define QOS_TID(qos)        (((qos) & QOS_TID_MASK) >> QOS_TID_SHIFT)   
+#define QOS_TID_SHIFT       0
+#define QOS_TID_MASK        0x000f
+#define QOS_TID(qos)        (((qos) & QOS_TID_MASK) >> QOS_TID_SHIFT)
 
 
-#define QOS_EOSP_SHIFT      4   
-#define QOS_EOSP_MASK       0x0010  
-#define QOS_EOSP(qos)       (((qos) & QOS_EOSP_MASK) >> QOS_EOSP_SHIFT) 
+#define QOS_EOSP_SHIFT      4
+#define QOS_EOSP_MASK       0x0010
+#define QOS_EOSP(qos)       (((qos) & QOS_EOSP_MASK) >> QOS_EOSP_SHIFT)
 
 
-#define QOS_ACK_NORMAL_ACK  0   
-#define QOS_ACK_NO_ACK      1   
-#define QOS_ACK_NO_EXP_ACK  2   
-#define QOS_ACK_BLOCK_ACK   3   
-#define QOS_ACK_SHIFT       5   
-#define QOS_ACK_MASK        0x0060  
-#define QOS_ACK(qos)        (((qos) & QOS_ACK_MASK) >> QOS_ACK_SHIFT)   
+#define QOS_ACK_NORMAL_ACK  0
+#define QOS_ACK_NO_ACK      1
+#define QOS_ACK_NO_EXP_ACK  2
+#define QOS_ACK_BLOCK_ACK   3
+#define QOS_ACK_SHIFT       5
+#define QOS_ACK_MASK        0x0060
+#define QOS_ACK(qos)        (((qos) & QOS_ACK_MASK) >> QOS_ACK_SHIFT)
 
 
-#define QOS_AMSDU_SHIFT     7   
-#define QOS_AMSDU_MASK      0x0080  
+#define QOS_AMSDU_SHIFT     7
+#define QOS_AMSDU_MASK      0x0080
 
 
 
 
 
 
-#define DOT11_MNG_AUTH_ALGO_LEN     2   
-#define DOT11_MNG_AUTH_SEQ_LEN      2   
-#define DOT11_MNG_BEACON_INT_LEN    2   
-#define DOT11_MNG_CAP_LEN       2   
-#define DOT11_MNG_AP_ADDR_LEN       6   
-#define DOT11_MNG_LISTEN_INT_LEN    2   
-#define DOT11_MNG_REASON_LEN        2   
-#define DOT11_MNG_AID_LEN       2   
-#define DOT11_MNG_STATUS_LEN        2   
-#define DOT11_MNG_TIMESTAMP_LEN     8   
+#define DOT11_MNG_AUTH_ALGO_LEN     2
+#define DOT11_MNG_AUTH_SEQ_LEN      2
+#define DOT11_MNG_BEACON_INT_LEN    2
+#define DOT11_MNG_CAP_LEN       2
+#define DOT11_MNG_AP_ADDR_LEN       6
+#define DOT11_MNG_LISTEN_INT_LEN    2
+#define DOT11_MNG_REASON_LEN        2
+#define DOT11_MNG_AID_LEN       2
+#define DOT11_MNG_STATUS_LEN        2
+#define DOT11_MNG_TIMESTAMP_LEN     8
 
 
-#define DOT11_AID_MASK          0x3fff  
+#define DOT11_AID_MASK          0x3fff
 
 
-#define DOT11_RC_RESERVED       0   
-#define DOT11_RC_UNSPECIFIED        1   
-#define DOT11_RC_AUTH_INVAL     2   
-#define DOT11_RC_DEAUTH_LEAVING     3   
-#define DOT11_RC_INACTIVITY     4   
-#define DOT11_RC_BUSY           5   
-#define DOT11_RC_INVAL_CLASS_2      6   
-#define DOT11_RC_INVAL_CLASS_3      7   
-#define DOT11_RC_DISASSOC_LEAVING   8   
-#define DOT11_RC_NOT_AUTH       9   
-#define DOT11_RC_BAD_PC         10  
-#define DOT11_RC_BAD_CHANNELS       11  
+#define DOT11_RC_RESERVED       0
+#define DOT11_RC_UNSPECIFIED        1
+#define DOT11_RC_AUTH_INVAL     2
+#define DOT11_RC_DEAUTH_LEAVING     3
+#define DOT11_RC_INACTIVITY     4
+#define DOT11_RC_BUSY           5
+#define DOT11_RC_INVAL_CLASS_2      6
+#define DOT11_RC_INVAL_CLASS_3      7
+#define DOT11_RC_DISASSOC_LEAVING   8
+#define DOT11_RC_NOT_AUTH       9
+#define DOT11_RC_BAD_PC         10
+#define DOT11_RC_BAD_CHANNELS       11
 
 
 
-#define DOT11_RC_UNSPECIFIED_QOS    32  
-#define DOT11_RC_INSUFFCIENT_BW     33  
-#define DOT11_RC_EXCESSIVE_FRAMES   34  
-#define DOT11_RC_TX_OUTSIDE_TXOP    35  
-#define DOT11_RC_LEAVING_QBSS       36  
-#define DOT11_RC_BAD_MECHANISM      37  
-#define DOT11_RC_SETUP_NEEDED       38  
-#define DOT11_RC_TIMEOUT        39  
+#define DOT11_RC_UNSPECIFIED_QOS    32
+#define DOT11_RC_INSUFFCIENT_BW     33
+#define DOT11_RC_EXCESSIVE_FRAMES   34
+#define DOT11_RC_TX_OUTSIDE_TXOP    35
+#define DOT11_RC_LEAVING_QBSS       36
+#define DOT11_RC_BAD_MECHANISM      37
+#define DOT11_RC_SETUP_NEEDED       38
+#define DOT11_RC_TIMEOUT        39
 
-#define DOT11_RC_MAX            23  
+#define DOT11_RC_MAX            23
 
 
-#define DOT11_SC_SUCCESS        0   
-#define DOT11_SC_FAILURE        1   
-#define DOT11_SC_CAP_MISMATCH       10  
-#define DOT11_SC_REASSOC_FAIL       11  
-#define DOT11_SC_ASSOC_FAIL     12  
-#define DOT11_SC_AUTH_MISMATCH      13  
-#define DOT11_SC_AUTH_SEQ       14  
-#define DOT11_SC_AUTH_CHALLENGE_FAIL    15  
-#define DOT11_SC_AUTH_TIMEOUT       16  
-#define DOT11_SC_ASSOC_BUSY_FAIL    17  
-#define DOT11_SC_ASSOC_RATE_MISMATCH    18  
-#define DOT11_SC_ASSOC_SHORT_REQUIRED   19  
-#define DOT11_SC_ASSOC_PBCC_REQUIRED    20  
-#define DOT11_SC_ASSOC_AGILITY_REQUIRED 21  
-#define DOT11_SC_ASSOC_SPECTRUM_REQUIRED    22  
-#define DOT11_SC_ASSOC_BAD_POWER_CAP    23  
-#define DOT11_SC_ASSOC_BAD_SUP_CHANNELS 24  
-#define DOT11_SC_ASSOC_SHORTSLOT_REQUIRED   25  
-#define DOT11_SC_ASSOC_ERPBCC_REQUIRED  26  
-#define DOT11_SC_ASSOC_DSSOFDM_REQUIRED 27  
+#define DOT11_SC_SUCCESS        0
+#define DOT11_SC_FAILURE        1
+#define DOT11_SC_CAP_MISMATCH       10
+#define DOT11_SC_REASSOC_FAIL       11
+#define DOT11_SC_ASSOC_FAIL     12
+#define DOT11_SC_AUTH_MISMATCH      13
+#define DOT11_SC_AUTH_SEQ       14
+#define DOT11_SC_AUTH_CHALLENGE_FAIL    15
+#define DOT11_SC_AUTH_TIMEOUT       16
+#define DOT11_SC_ASSOC_BUSY_FAIL    17
+#define DOT11_SC_ASSOC_RATE_MISMATCH    18
+#define DOT11_SC_ASSOC_SHORT_REQUIRED   19
+#define DOT11_SC_ASSOC_PBCC_REQUIRED    20
+#define DOT11_SC_ASSOC_AGILITY_REQUIRED 21
+#define DOT11_SC_ASSOC_SPECTRUM_REQUIRED    22
+#define DOT11_SC_ASSOC_BAD_POWER_CAP    23
+#define DOT11_SC_ASSOC_BAD_SUP_CHANNELS 24
+#define DOT11_SC_ASSOC_SHORTSLOT_REQUIRED   25
+#define DOT11_SC_ASSOC_ERPBCC_REQUIRED  26
+#define DOT11_SC_ASSOC_DSSOFDM_REQUIRED 27
+#define DOT11_SC_ASSOC_R0KH_UNREACHABLE	28
+#define DOT11_SC_ASSOC_TRY_LATER	30
+#define DOT11_SC_ASSOC_MFP_VIOLATION	31
 
-#define DOT11_SC_DECLINED       37  
-#define DOT11_SC_INVALID_PARAMS     38  
-#define DOT11_SC_INVALID_AKMP       43  
-#define DOT11_SC_INVALID_MDID       54  
-#define DOT11_SC_INVALID_FTIE       55  
+#define DOT11_SC_DECLINED       37
+#define DOT11_SC_INVALID_PARAMS     38
+#define DOT11_SC_INVALID_PAIRWISE_CIPHER	42
+#define DOT11_SC_INVALID_AKMP       43
+#define DOT11_SC_INVALID_RSNIE_CAP	45
+#define	DOT11_SC_INVALID_PMKID		53
+#define DOT11_SC_INVALID_MDID       54
+#define DOT11_SC_INVALID_FTIE       55
+
+#define DOT11_SC_UNEXP_MSG			70
+#define DOT11_SC_INVALID_SNONCE		71
+#define DOT11_SC_INVALID_RSNIE		72
+
+#define DOT11_MNG_DS_PARAM_LEN          1
+#define DOT11_MNG_IBSS_PARAM_LEN        2
 
 
-#define DOT11_MNG_DS_PARAM_LEN          1   
-#define DOT11_MNG_IBSS_PARAM_LEN        2   
+#define DOT11_MNG_TIM_FIXED_LEN         3
+#define DOT11_MNG_TIM_DTIM_COUNT        0
+#define DOT11_MNG_TIM_DTIM_PERIOD       1
+#define DOT11_MNG_TIM_BITMAP_CTL        2
+#define DOT11_MNG_TIM_PVB           3
 
 
-#define DOT11_MNG_TIM_FIXED_LEN         3   
-#define DOT11_MNG_TIM_DTIM_COUNT        0   
-#define DOT11_MNG_TIM_DTIM_PERIOD       1   
-#define DOT11_MNG_TIM_BITMAP_CTL        2   
-#define DOT11_MNG_TIM_PVB           3   
+#define TLV_TAG_OFF     0
+#define TLV_LEN_OFF     1
+#define TLV_HDR_LEN     2
+#define TLV_BODY_OFF        2
 
 
-#define TLV_TAG_OFF     0   
-#define TLV_LEN_OFF     1   
-#define TLV_HDR_LEN     2   
-#define TLV_BODY_OFF        2   
+#define DOT11_MNG_SSID_ID           0
+#define DOT11_MNG_RATES_ID          1
+#define DOT11_MNG_FH_PARMS_ID           2
+#define DOT11_MNG_DS_PARMS_ID           3
+#define DOT11_MNG_CF_PARMS_ID           4
+#define DOT11_MNG_TIM_ID            5
+#define DOT11_MNG_IBSS_PARMS_ID         6
+#define DOT11_MNG_COUNTRY_ID            7
+#define DOT11_MNG_HOPPING_PARMS_ID      8
+#define DOT11_MNG_HOPPING_TABLE_ID      9
+#define DOT11_MNG_REQUEST_ID            10
+#define DOT11_MNG_QBSS_LOAD_ID          11
+#define DOT11_MNG_EDCA_PARAM_ID         12
+#define DOT11_MNG_CHALLENGE_ID          16
+#define DOT11_MNG_PWR_CONSTRAINT_ID     32
+#define DOT11_MNG_PWR_CAP_ID            33
+#define DOT11_MNG_TPC_REQUEST_ID        34
+#define DOT11_MNG_TPC_REPORT_ID         35
+#define DOT11_MNG_SUPP_CHANNELS_ID      36
+#define DOT11_MNG_CHANNEL_SWITCH_ID     37
+#define DOT11_MNG_MEASURE_REQUEST_ID        38
+#define DOT11_MNG_MEASURE_REPORT_ID     39
+#define DOT11_MNG_QUIET_ID          40
+#define DOT11_MNG_IBSS_DFS_ID           41
+#define DOT11_MNG_ERP_ID            42
+#define DOT11_MNG_TS_DELAY_ID           43
+#define DOT11_MNG_HT_CAP            45
+#define DOT11_MNG_QOS_CAP_ID            46
+#define DOT11_MNG_NONERP_ID         47
+#define DOT11_MNG_RSN_ID            48
+#define DOT11_MNG_EXT_RATES_ID          50
+#define DOT11_MNG_AP_CHREP_ID       51
+#define DOT11_MNG_NBR_REP_ID        52
+#define DOT11_MNG_MDIE_ID       54
+#define DOT11_MNG_FTIE_ID       55
+#define DOT11_MNG_FT_TI_ID      56
+#define DOT11_MNG_RDE_ID			57
+#define DOT11_MNG_REGCLASS_ID           59
+#define DOT11_MNG_EXT_CSA_ID            60
+#define DOT11_MNG_HT_ADD            61
+#define DOT11_MNG_EXT_CHANNEL_OFFSET        62
+#ifdef WAPI
+#define DOT11_MNG_WAPI_ID				68
+#endif /* WAPI */
+
+#define DOT11_MNG_RRM_CAP_ID        70
+#define DOT11_MNG_HT_BSS_COEXINFO_ID        72
+#define DOT11_MNG_HT_BSS_CHANNEL_REPORT_ID  73
+#define DOT11_MNG_HT_OBSS_ID            74
+#define DOT11_MNG_EXT_CAP_ID           127
+#define DOT11_MNG_WPA_ID            221
+#define DOT11_MNG_PROPR_ID          221
+
+#define DOT11_MNG_VS_ID             221
 
 
-#define DOT11_MNG_SSID_ID           0   
-#define DOT11_MNG_RATES_ID          1   
-#define DOT11_MNG_FH_PARMS_ID           2   
-#define DOT11_MNG_DS_PARMS_ID           3   
-#define DOT11_MNG_CF_PARMS_ID           4   
-#define DOT11_MNG_TIM_ID            5   
-#define DOT11_MNG_IBSS_PARMS_ID         6   
-#define DOT11_MNG_COUNTRY_ID            7   
-#define DOT11_MNG_HOPPING_PARMS_ID      8   
-#define DOT11_MNG_HOPPING_TABLE_ID      9   
-#define DOT11_MNG_REQUEST_ID            10  
-#define DOT11_MNG_QBSS_LOAD_ID          11  
-#define DOT11_MNG_EDCA_PARAM_ID         12  
-#define DOT11_MNG_CHALLENGE_ID          16  
-#define DOT11_MNG_PWR_CONSTRAINT_ID     32  
-#define DOT11_MNG_PWR_CAP_ID            33  
-#define DOT11_MNG_TPC_REQUEST_ID        34  
-#define DOT11_MNG_TPC_REPORT_ID         35  
-#define DOT11_MNG_SUPP_CHANNELS_ID      36  
-#define DOT11_MNG_CHANNEL_SWITCH_ID     37  
-#define DOT11_MNG_MEASURE_REQUEST_ID        38  
-#define DOT11_MNG_MEASURE_REPORT_ID     39  
-#define DOT11_MNG_QUIET_ID          40  
-#define DOT11_MNG_IBSS_DFS_ID           41  
-#define DOT11_MNG_ERP_ID            42  
-#define DOT11_MNG_TS_DELAY_ID           43  
-#define DOT11_MNG_HT_CAP            45  
-#define DOT11_MNG_QOS_CAP_ID            46  
-#define DOT11_MNG_NONERP_ID         47  
-#define DOT11_MNG_RSN_ID            48  
-#define DOT11_MNG_EXT_RATES_ID          50  
-#define DOT11_MNG_AP_CHREP_ID       51  
-#define DOT11_MNG_NBR_REP_ID        52  
-#define DOT11_MNG_MDIE_ID       54  
-#define DOT11_MNG_FTIE_ID       55  
-#define DOT11_MNG_FT_TI_ID      56  
-#define DOT11_MNG_REGCLASS_ID           59  
-#define DOT11_MNG_EXT_CSA_ID            60  
-#define DOT11_MNG_HT_ADD            61  
-#define DOT11_MNG_EXT_CHANNEL_OFFSET        62  
+#define DOT11_RATE_BASIC            0x80
+#define DOT11_RATE_MASK             0x7F
 
 
-#define DOT11_MNG_RRM_CAP_ID        70  
-#define DOT11_MNG_HT_BSS_COEXINFO_ID        72  
-#define DOT11_MNG_HT_BSS_CHANNEL_REPORT_ID  73  
-#define DOT11_MNG_HT_OBSS_ID            74  
-#define DOT11_MNG_EXT_CAP           127 
-#define DOT11_MNG_WPA_ID            221 
-#define DOT11_MNG_PROPR_ID          221 
+#define DOT11_MNG_ERP_LEN           1
+#define DOT11_MNG_NONERP_PRESENT        0x01
+#define DOT11_MNG_USE_PROTECTION        0x02
+#define DOT11_MNG_BARKER_PREAMBLE       0x04
 
-#define DOT11_MNG_VS_ID             221 
+#define DOT11_MGN_TS_DELAY_LEN      4
+#define TS_DELAY_FIELD_SIZE         4
 
 
-#define DOT11_RATE_BASIC            0x80    
-#define DOT11_RATE_MASK             0x7F    
+#define DOT11_CAP_ESS               0x0001
+#define DOT11_CAP_IBSS              0x0002
+#define DOT11_CAP_POLLABLE          0x0004
+#define DOT11_CAP_POLL_RQ           0x0008
+#define DOT11_CAP_PRIVACY           0x0010
+#define DOT11_CAP_SHORT             0x0020
+#define DOT11_CAP_PBCC              0x0040
+#define DOT11_CAP_AGILITY           0x0080
+#define DOT11_CAP_SPECTRUM          0x0100
+#define DOT11_CAP_SHORTSLOT         0x0400
+#define DOT11_CAP_RRM           0x1000
+#define DOT11_CAP_CCK_OFDM          0x2000
 
 
-#define DOT11_MNG_ERP_LEN           1   
-#define DOT11_MNG_NONERP_PRESENT        0x01    
-#define DOT11_MNG_USE_PROTECTION        0x02    
-#define DOT11_MNG_BARKER_PREAMBLE       0x04    
-
-#define DOT11_MGN_TS_DELAY_LEN      4   
-#define TS_DELAY_FIELD_SIZE         4   
+#define DOT11_OBSS_COEX_MNG_SUPPORT 0x01
 
 
-#define DOT11_CAP_ESS               0x0001  
-#define DOT11_CAP_IBSS              0x0002  
-#define DOT11_CAP_POLLABLE          0x0004  
-#define DOT11_CAP_POLL_RQ           0x0008  
-#define DOT11_CAP_PRIVACY           0x0010  
-#define DOT11_CAP_SHORT             0x0020  
-#define DOT11_CAP_PBCC              0x0040  
-#define DOT11_CAP_AGILITY           0x0080  
-#define DOT11_CAP_SPECTRUM          0x0100  
-#define DOT11_CAP_SHORTSLOT         0x0400  
-#define DOT11_CAP_RRM           0x1000  
-#define DOT11_CAP_CCK_OFDM          0x2000  
+#define DOT11_ACTION_HDR_LEN        2
+#define DOT11_ACTION_CAT_OFF        0
+#define DOT11_ACTION_ACT_OFF        1
 
 
-#define DOT11_OBSS_COEX_MNG_SUPPORT 0x01    
-
-
-#define DOT11_ACTION_HDR_LEN        2   
-#define DOT11_ACTION_CAT_OFF        0   
-#define DOT11_ACTION_ACT_OFF        1   
-
-
-#define DOT11_ACTION_CAT_ERR_MASK   0x80    
-#define DOT11_ACTION_CAT_MASK       0x7F    
-#define DOT11_ACTION_CAT_SPECT_MNG  0   
-#define DOT11_ACTION_CAT_QOS        1   
-#define DOT11_ACTION_CAT_DLS        2   
-#define DOT11_ACTION_CAT_BLOCKACK   3   
-#define DOT11_ACTION_CAT_PUBLIC     4   
-#define DOT11_ACTION_CAT_RRM        5   
-#define DOT11_ACTION_CAT_FBT    6   
-#define DOT11_ACTION_CAT_HT     7   
-#define DOT11_ACTION_CAT_BSSMGMT    10  
+#define DOT11_ACTION_CAT_ERR_MASK   0x80
+#define DOT11_ACTION_CAT_MASK       0x7F
+#define DOT11_ACTION_CAT_SPECT_MNG  0
+#define DOT11_ACTION_CAT_QOS        1
+#define DOT11_ACTION_CAT_DLS        2
+#define DOT11_ACTION_CAT_BLOCKACK   3
+#define DOT11_ACTION_CAT_PUBLIC     4
+#define DOT11_ACTION_CAT_RRM        5
+#define DOT11_ACTION_CAT_FBT    6
+#define DOT11_ACTION_CAT_HT     7
+#if defined(MFP) || defined(WLFBT) || defined(WLWNM)
+#define	DOT11_ACTION_CAT_SA_QUERY	8
+#define	DOT11_ACTION_CAT_PDPA		9
+#define DOT11_ACTION_CAT_BSSMGMT    10
 #define DOT11_ACTION_NOTIFICATION   17
-#define DOT11_ACTION_CAT_VS     127 
+#define DOT11_ACTION_CAT_VSP		126
+#endif
+#define DOT11_ACTION_NOTIFICATION	17
+#define DOT11_ACTION_CAT_VS     127
 
 
-#define DOT11_SM_ACTION_M_REQ       0   
-#define DOT11_SM_ACTION_M_REP       1   
-#define DOT11_SM_ACTION_TPC_REQ     2   
-#define DOT11_SM_ACTION_TPC_REP     3   
-#define DOT11_SM_ACTION_CHANNEL_SWITCH  4   
-#define DOT11_SM_ACTION_EXT_CSA     5   
+#define DOT11_SM_ACTION_M_REQ       0
+#define DOT11_SM_ACTION_M_REP       1
+#define DOT11_SM_ACTION_TPC_REQ     2
+#define DOT11_SM_ACTION_TPC_REP     3
+#define DOT11_SM_ACTION_CHANNEL_SWITCH  4
+#define DOT11_SM_ACTION_EXT_CSA     5
 
 
-#define DOT11_ACTION_ID_HT_CH_WIDTH 0   
-#define DOT11_ACTION_ID_HT_MIMO_PS  1   
+#define DOT11_ACTION_ID_HT_CH_WIDTH 0
+#define DOT11_ACTION_ID_HT_MIMO_PS  1
 
 
-#define DOT11_PUB_ACTION_BSS_COEX_MNG   0   
-#define DOT11_PUB_ACTION_CHANNEL_SWITCH 4   
+#define DOT11_PUB_ACTION_BSS_COEX_MNG   0
+#define DOT11_PUB_ACTION_CHANNEL_SWITCH 4
 
 
-#define DOT11_BA_ACTION_ADDBA_REQ   0   
-#define DOT11_BA_ACTION_ADDBA_RESP  1   
-#define DOT11_BA_ACTION_DELBA       2   
+#define DOT11_BA_ACTION_ADDBA_REQ   0
+#define DOT11_BA_ACTION_ADDBA_RESP  1
+#define DOT11_BA_ACTION_DELBA       2
 
 
-#define DOT11_ADDBA_PARAM_AMSDU_SUP 0x0001  
-#define DOT11_ADDBA_PARAM_POLICY_MASK   0x0002  
-#define DOT11_ADDBA_PARAM_POLICY_SHIFT  1   
-#define DOT11_ADDBA_PARAM_TID_MASK  0x003c  
-#define DOT11_ADDBA_PARAM_TID_SHIFT 2   
-#define DOT11_ADDBA_PARAM_BSIZE_MASK    0xffc0  
-#define DOT11_ADDBA_PARAM_BSIZE_SHIFT   6   
+#define DOT11_ADDBA_PARAM_AMSDU_SUP 0x0001
+#define DOT11_ADDBA_PARAM_POLICY_MASK   0x0002
+#define DOT11_ADDBA_PARAM_POLICY_SHIFT  1
+#define DOT11_ADDBA_PARAM_TID_MASK  0x003c
+#define DOT11_ADDBA_PARAM_TID_SHIFT 2
+#define DOT11_ADDBA_PARAM_BSIZE_MASK    0xffc0
+#define DOT11_ADDBA_PARAM_BSIZE_SHIFT   6
 
-#define DOT11_ADDBA_POLICY_DELAYED  0   
-#define DOT11_ADDBA_POLICY_IMMEDIATE    1   
+#define DOT11_ADDBA_POLICY_DELAYED  0
+#define DOT11_ADDBA_POLICY_IMMEDIATE    1
 
+
+#define DOT11_FT_ACTION_FT_RESERVED		0
+#define DOT11_FT_ACTION_FT_REQ			1
+#define DOT11_FT_ACTION_FT_RES			2
+#define DOT11_FT_ACTION_FT_CON			3
+#define DOT11_FT_ACTION_FT_ACK			4
+
+
+
+#define DOT11_WNM_ACTION_EVENT_REQ			0
+#define DOT11_WNM_ACTION_EVENT_REP			1
+#define DOT11_WNM_ACTION_DIAG_REQ			2
+#define DOT11_WNM_ACTION_DIAG_REP			3
+#define DOT11_WNM_ACTION_LOC_CFG_REQ		4
+#define DOT11_WNM_ACTION_LOC_RFG_RESP		5
+#define DOT11_WNM_ACTION_BSS_TRANS_QURY		6
+#define DOT11_WNM_ACTION_BSS_TRANS_REQ		7
+#define DOT11_WNM_ACTION_BSS_TRANS_RESP		8
+#define DOT11_WNM_ACTION_FMS_REQ			9
+#define DOT11_WNM_ACTION_FMS_RESP			10
+#define DOT11_WNM_ACTION_COL_INTRFRNCE_REQ	11
+#define DOT11_WNM_ACTION_COL_INTRFRNCE_REP	12
+#define DOT11_WNM_ACTION_TFS_REQ			13
+#define DOT11_WNM_ACTION_TFS_RESP			14
+#define DOT11_WNM_ACTION_TFS_NOTIFY			15
+#define DOT11_WNM_ACTION_WNM_SLEEP_REQ		16
+#define DOT11_WNM_ACTION_WNM_SLEEP_RESP		17
+#define DOT11_WNM_ACTION_TIM_BCAST_REQ		18
+#define DOT11_WNM_ACTION_TIM_BCAST_RESP		19
+#define DOT11_WNM_ACTION_QOS_TRFC_CAP_UPD	20
+#define DOT11_WNM_ACTION_CHAN_USAGE_REQ		21
+#define DOT11_WNM_ACTION_CHAN_USAGE_RESP	22
+#define DOT11_WNM_ACTION_DMS_REQ			23
+#define DOT11_WNM_ACTION_DMS_RESP			24
+#define DOT11_WNM_ACTION_TMNG_MEASUR_REQ	25
+#define DOT11_WNM_ACTION_NOTFCTN_REQ		26
+#define DOT11_WNM_ACTION_NOTFCTN_RES		27
+
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_bss_trans_query {
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint8 reason;
+	uint8 data[1];
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_bss_trans_query dot11_bss_trans_query_t;
+#define DOT11_BSS_TRANS_QUERY_LEN 4
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_bss_trans_req {
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint8 reqmode;
+	uint16 disassoc_tmr;
+	uint8 validity_intrvl;
+	uint8 data[1];
+
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_bss_trans_req dot11_bss_trans_req_t;
+#define DOT11_BSS_TRANS_REQ_LEN 7
+
+#define DOT11_BSS_TERM_DUR_LEN 12
+
+
+
+#define DOT11_BSS_TRNS_REQMODE_PREF_LIST_INCL		0x01
+#define DOT11_BSS_TRNS_REQMODE_ABRIDGED				0x02
+#define DOT11_BSS_TRNS_REQMODE_DISASSOC_IMMINENT	0x04
+#define DOT11_BSS_TRNS_REQMODE_BSS_TERM_INCL		0x08
+#define DOT11_BSS_TRNS_REQMODE_ESS_DISASSOC_IMNT	0x10
+
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_bss_trans_res {
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint8 status;
+	uint8 term_delay;
+	uint8 data[1];
+
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_bss_trans_res dot11_bss_trans_res_t;
+#define DOT11_BSS_TRANS_RES_LEN 5
+
+
+#define DOT11_BSS_TRNS_RES_STATUS_ACCEPT				0
+#define DOT11_BSS_TRNS_RES_STATUS_REJECT				1
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_INSUFF_BCN		2
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_INSUFF_CAP		3
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_TERM_UNDESIRED	4
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_TERM_DELAY_REQ	5
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_BSS_LIST_PROVIDED	6
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_NO_SUITABLE_BSS	7
+#define DOT11_BSS_TRNS_RES_STATUS_REJ_LEAVING_ESS		8
+
+
+
+#define DOT11_NBR_RPRT_BSSID_INFO_REACHABILTY		0x0003
+#define DOT11_NBR_RPRT_BSSID_INFO_SEC				0x0004
+#define DOT11_NBR_RPRT_BSSID_INFO_KEY_SCOPE			0x0008
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP				0x03f0
+
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_SPEC_MGMT		0x0010
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_QOS			0x0020
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_APSD			0x0040
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_RDIO_MSMT		0x0080
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_DEL_BA		0x0100
+#define DOT11_NBR_RPRT_BSSID_INFO_CAP_IMM_BA		0x0200
+
+
+#define DOT11_NBR_RPRT_SUBELEM_BSS_CANDDT_PREF_ID	3
 BWL_PRE_PACKED_STRUCT struct dot11_addba_req {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
-	uint16 addba_param_set;         
-	uint16 timeout;             
-	uint16 start_seqnum;            
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint16 addba_param_set;
+	uint16 timeout;
+	uint16 start_seqnum;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_addba_req dot11_addba_req_t;
-#define DOT11_ADDBA_REQ_LEN     9   
+#define DOT11_ADDBA_REQ_LEN     9
 
 BWL_PRE_PACKED_STRUCT struct dot11_addba_resp {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
-	uint16 status;              
-	uint16 addba_param_set;         
-	uint16 timeout;             
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint16 status;
+	uint16 addba_param_set;
+	uint16 timeout;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_addba_resp dot11_addba_resp_t;
-#define DOT11_ADDBA_RESP_LEN        9   
+#define DOT11_ADDBA_RESP_LEN        9
 
 
-#define DOT11_DELBA_PARAM_INIT_MASK 0x0800  
-#define DOT11_DELBA_PARAM_INIT_SHIFT    11  
-#define DOT11_DELBA_PARAM_TID_MASK  0xf000  
-#define DOT11_DELBA_PARAM_TID_SHIFT 12  
+#define DOT11_DELBA_PARAM_INIT_MASK 0x0800
+#define DOT11_DELBA_PARAM_INIT_SHIFT    11
+#define DOT11_DELBA_PARAM_TID_MASK  0xf000
+#define DOT11_DELBA_PARAM_TID_SHIFT 12
 
 BWL_PRE_PACKED_STRUCT struct dot11_delba {
-	uint8 category;             
-	uint8 action;               
-	uint16 delba_param_set;         
-	uint16 reason;              
+	uint8 category;
+	uint8 action;
+	uint16 delba_param_set;
+	uint16 reason;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_delba dot11_delba_t;
-#define DOT11_DELBA_LEN         6   
+#define DOT11_DELBA_LEN         6
+
+
+#define SA_QUERY_REQUEST		0
+#define SA_QUERY_RESPONSE		1
+
+
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_ft_req {
+	uint8 category;
+	uint8 action;
+	uint8 sta_addr[ETHER_ADDR_LEN];
+	uint8 tgt_ap_addr[ETHER_ADDR_LEN];
+	uint8 data[1];
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_ft_req dot11_ft_req_t;
+#define DOT11_FT_REQ_FIXED_LEN 14
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_ft_res {
+	uint8 category;
+	uint8 action;
+	uint8 sta_addr[ETHER_ADDR_LEN];
+	uint8 tgt_ap_addr[ETHER_ADDR_LEN];
+	uint16 status;
+	uint8 data[1];
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_ft_res dot11_ft_res_t;
+#define DOT11_FT_RES_FIXED_LEN 16
+
+
+BWL_PRE_PACKED_STRUCT struct dot11_rde_ie {
+	uint8 id;
+	uint8 length;
+	uint8 rde_id;
+	uint8 rd_count;
+	uint16 status;
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_rde_ie dot11_rde_ie_t;
+
+
+#define DOT11_MNG_RDE_IE_LEN sizeof(dot11_rde_ie_t)
 
 
 
 
 
-#define DOT11_RRM_CAP_LEN       5   
+#define DOT11_RRM_CAP_LEN       5
 BWL_PRE_PACKED_STRUCT struct dot11_rrm_cap_ie {
 	uint8 cap[DOT11_RRM_CAP_LEN];
 } BWL_POST_PACKED_STRUCT;
@@ -1166,28 +1341,42 @@
 #define DOT11_RRM_CAP_AP_CHANREP    16
 
 
-#define DOT11_RM_ACTION_RM_REQ      0   
-#define DOT11_RM_ACTION_RM_REP      1   
-#define DOT11_RM_ACTION_LM_REQ      2   
-#define DOT11_RM_ACTION_LM_REP      3   
-#define DOT11_RM_ACTION_NR_REQ      4   
-#define DOT11_RM_ACTION_NR_REP      5   
+
+#define DOT11_EXT_CAP_LEN		4
+BWL_PRE_PACKED_STRUCT struct dot11_ext_cap_ie {
+	uint8 cap[DOT11_EXT_CAP_LEN];
+} BWL_POST_PACKED_STRUCT;
+typedef struct dot11_ext_cap_ie dot11_ext_cap_ie_t;
+
+
+#define DOT11_EXT_CAP_BSS_TRANSITION_MGMT	19
+
+
+#define DOT11_OP_CLASS_NONE			255
+
+
+#define DOT11_RM_ACTION_RM_REQ      0
+#define DOT11_RM_ACTION_RM_REP      1
+#define DOT11_RM_ACTION_LM_REQ      2
+#define DOT11_RM_ACTION_LM_REP      3
+#define DOT11_RM_ACTION_NR_REQ      4
+#define DOT11_RM_ACTION_NR_REP      5
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_rm_action {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
+	uint8 category;
+	uint8 action;
+	uint8 token;
 	uint8 data[1];
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_rm_action dot11_rm_action_t;
 #define DOT11_RM_ACTION_LEN 3
 
 BWL_PRE_PACKED_STRUCT struct dot11_rmreq {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
-	uint16 reps;                
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint16 reps;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_rmreq dot11_rmreq_t;
 #define DOT11_RMREQ_LEN 5
@@ -1207,7 +1396,7 @@
 #define DOT11_RMREQ_MODE_ENABLE     2
 #define DOT11_RMREQ_MODE_REQUEST    4
 #define DOT11_RMREQ_MODE_REPORT     8
-#define DOT11_RMREQ_MODE_DURMAND    0x10    
+#define DOT11_RMREQ_MODE_DURMAND    0x10
 
 
 #define DOT11_RMREP_MODE_LATE       1
@@ -1258,9 +1447,9 @@
 #define DOT11_RMREQ_BCN_APCHREP_ID  51
 
 
-#define DOT11_RMREQ_BCN_REPDET_FIXED    0   
-#define DOT11_RMREQ_BCN_REPDET_REQUEST  1   
-#define DOT11_RMREQ_BCN_REPDET_ALL  2   
+#define DOT11_RMREQ_BCN_REPDET_FIXED    0
+#define DOT11_RMREQ_BCN_REPDET_REQUEST  1
+#define DOT11_RMREQ_BCN_REPDET_ALL  2
 
 
 #define DOT11_RMREP_BCN_FRM_BODY    1
@@ -1277,43 +1466,43 @@
 #define DOT11_RMREP_NBR_LEN 13
 
 
-#define DOT11_BSSTYPE_INFRASTRUCTURE        0   
-#define DOT11_BSSTYPE_INDEPENDENT       1   
-#define DOT11_BSSTYPE_ANY           2   
-#define DOT11_SCANTYPE_ACTIVE           0   
-#define DOT11_SCANTYPE_PASSIVE          1   
+#define DOT11_BSSTYPE_INFRASTRUCTURE        0
+#define DOT11_BSSTYPE_INDEPENDENT       1
+#define DOT11_BSSTYPE_ANY           2
+#define DOT11_SCANTYPE_ACTIVE           0
+#define DOT11_SCANTYPE_PASSIVE          1
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_lmreq {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
-	uint8 txpwr;                
-	uint8 maxtxpwr;             
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	uint8 txpwr;
+	uint8 maxtxpwr;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_lmreq dot11_lmreq_t;
 #define DOT11_LMREQ_LEN 5
 
 BWL_PRE_PACKED_STRUCT struct dot11_lmrep {
-	uint8 category;             
-	uint8 action;               
-	uint8 token;                
-	dot11_tpc_rep_t tpc;            
-	uint8 rxant;                
-	uint8 txant;                
-	uint8 rcpi;             
-	uint8 rsni;             
+	uint8 category;
+	uint8 action;
+	uint8 token;
+	dot11_tpc_rep_t tpc;
+	uint8 rxant;
+	uint8 txant;
+	uint8 rcpi;
+	uint8 rsni;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_lmrep dot11_lmrep_t;
 #define DOT11_LMREP_LEN 11
 
 
-#define PREN_PREAMBLE       24  
-#define PREN_MM_EXT     12  
-#define PREN_PREAMBLE_EXT   4   
+#define PREN_PREAMBLE       24
+#define PREN_MM_EXT     12
+#define PREN_PREAMBLE_EXT   4
 
 
-#define RIFS_11N_TIME       2   
+#define RIFS_11N_TIME       2
 
 
 
@@ -1336,112 +1525,112 @@
 #define HT_SIG2_TAIL            0x1C0000
 
 
-#define APHY_SLOT_TIME      9   
-#define APHY_SIFS_TIME      16  
-#define APHY_DIFS_TIME      (APHY_SIFS_TIME + (2 * APHY_SLOT_TIME)) 
-#define APHY_PREAMBLE_TIME  16  
-#define APHY_SIGNAL_TIME    4   
-#define APHY_SYMBOL_TIME    4   
-#define APHY_SERVICE_NBITS  16  
-#define APHY_TAIL_NBITS     6   
-#define APHY_CWMIN      15  
+#define APHY_SLOT_TIME      9
+#define APHY_SIFS_TIME      16
+#define APHY_DIFS_TIME      (APHY_SIFS_TIME + (2 * APHY_SLOT_TIME))
+#define APHY_PREAMBLE_TIME  16
+#define APHY_SIGNAL_TIME    4
+#define APHY_SYMBOL_TIME    4
+#define APHY_SERVICE_NBITS  16
+#define APHY_TAIL_NBITS     6
+#define APHY_CWMIN      15
 
 
-#define BPHY_SLOT_TIME      20  
-#define BPHY_SIFS_TIME      10  
-#define BPHY_DIFS_TIME      50  
-#define BPHY_PLCP_TIME      192 
-#define BPHY_PLCP_SHORT_TIME    96  
-#define BPHY_CWMIN      31  
+#define BPHY_SLOT_TIME      20
+#define BPHY_SIFS_TIME      10
+#define BPHY_DIFS_TIME      50
+#define BPHY_PLCP_TIME      192
+#define BPHY_PLCP_SHORT_TIME    96
+#define BPHY_CWMIN      31
 
 
-#define DOT11_OFDM_SIGNAL_EXTENSION 6   
+#define DOT11_OFDM_SIGNAL_EXTENSION 6
 
-#define PHY_CWMAX       1023    
+#define PHY_CWMAX       1023
 
-#define DOT11_MAXNUMFRAGS   16  
+#define DOT11_MAXNUMFRAGS   16
 
 
 typedef struct d11cnt {
-	uint32      txfrag;     
-	uint32      txmulti;    
-	uint32      txfail;     
-	uint32      txretry;    
-	uint32      txretrie;   
-	uint32      rxdup;      
-	uint32      txrts;      
-	uint32      txnocts;    
-	uint32      txnoack;    
-	uint32      rxfrag;     
-	uint32      rxmulti;    
-	uint32      rxcrc;      
-	uint32      txfrmsnt;   
-	uint32      rxundec;    
+	uint32      txfrag;
+	uint32      txmulti;
+	uint32      txfail;
+	uint32      txretry;
+	uint32      txretrie;
+	uint32      rxdup;
+	uint32      txrts;
+	uint32      txnocts;
+	uint32      txnoack;
+	uint32      rxfrag;
+	uint32      rxmulti;
+	uint32      rxcrc;
+	uint32      txfrmsnt;
+	uint32      rxundec;
 } d11cnt_t;
 
 
-#define BRCM_PROP_OUI       "\x00\x90\x4C"  
+#define BRCM_PROP_OUI       "\x00\x90\x4C"
 
 
 
-#define BRCM_OUI        "\x00\x10\x18"  
+#define BRCM_OUI        "\x00\x10\x18"
 
 
 BWL_PRE_PACKED_STRUCT struct brcm_ie {
-	uint8   id;     
-	uint8   len;        
-	uint8   oui[3];     
-	uint8   ver;        
-	uint8   assoc;      
-	uint8   flags;      
-	uint8   flags1;     
-	uint16  amsdu_mtu_pref; 
+	uint8   id;
+	uint8   len;
+	uint8   oui[3];
+	uint8   ver;
+	uint8   assoc;
+	uint8   flags;
+	uint8   flags1;
+	uint16  amsdu_mtu_pref;
 } BWL_POST_PACKED_STRUCT;
 typedef struct brcm_ie brcm_ie_t;
-#define BRCM_IE_LEN     11  
-#define BRCM_IE_VER     2   
-#define BRCM_IE_LEGACY_AES_VER  1   
+#define BRCM_IE_LEN     11
+#define BRCM_IE_VER     2
+#define BRCM_IE_LEGACY_AES_VER  1
 
 
 #ifdef WLAFTERBURNER
-#define BRF_ABCAP       0x1 
-#define BRF_ABRQRD      0x2 
-#define BRF_ABCOUNTER_MASK  0xf0    
-#define BRF_ABCOUNTER_SHIFT 4   
-#endif 
-#define BRF_LZWDS       0x4 
-#define BRF_BLOCKACK        0x8 
+#define BRF_ABCAP       0x1
+#define BRF_ABRQRD      0x2
+#define BRF_ABCOUNTER_MASK  0xf0
+#define BRF_ABCOUNTER_SHIFT 4
+#endif
+#define BRF_LZWDS       0x4
+#define BRF_BLOCKACK        0x8
 
 
-#define BRF1_AMSDU      0x1 
-#define BRF1_WMEPS      0x4 
-#define BRF1_PSOFIX     0x8 
-#define BRF1_RX_LARGE_AGG   0x10    
-#define BRF1_SOFTAP             0x40    
+#define BRF1_AMSDU      0x1
+#define BRF1_WMEPS      0x4
+#define BRF1_PSOFIX     0x8
+#define BRF1_RX_LARGE_AGG   0x10
+#define BRF1_SOFTAP             0x40
 
 #ifdef WLAFTERBURNER
-#define AB_WDS_TIMEOUT_MAX  15  
-#define AB_WDS_TIMEOUT_MIN  1   
+#define AB_WDS_TIMEOUT_MAX  15
+#define AB_WDS_TIMEOUT_MIN  1
 #endif
 
-#define AB_GUARDCOUNT   10      
+#define AB_GUARDCOUNT   10
 
 
 BWL_PRE_PACKED_STRUCT struct vndr_ie {
 	uchar id;
 	uchar len;
 	uchar oui [3];
-	uchar data [1];     
+	uchar data [1];
 } BWL_POST_PACKED_STRUCT;
 typedef struct vndr_ie vndr_ie_t;
 
-#define VNDR_IE_HDR_LEN     2   
-#define VNDR_IE_MIN_LEN     3   
-#define VNDR_IE_MAX_LEN     256 
+#define VNDR_IE_HDR_LEN     2
+#define VNDR_IE_MIN_LEN     3
+#define VNDR_IE_MAX_LEN     256
 
 
-#define MCSSET_LEN  16  
-#define MAX_MCS_NUM (128)   
+#define MCSSET_LEN  16
+#define MAX_MCS_NUM (128)
 
 BWL_PRE_PACKED_STRUCT struct ht_cap_ie {
 	uint16  cap;
@@ -1456,77 +1645,77 @@
 
 
 BWL_PRE_PACKED_STRUCT struct ht_prop_cap_ie {
-	uint8   id;     
-	uint8   len;        
-	uint8   oui[3];     
-	uint8   type;           
+	uint8   id;
+	uint8   len;
+	uint8   oui[3];
+	uint8   type;
 	ht_cap_ie_t cap_ie;
 } BWL_POST_PACKED_STRUCT;
 typedef struct ht_prop_cap_ie ht_prop_cap_ie_t;
 
-#define HT_PROP_IE_OVERHEAD 4   
-#define HT_CAP_IE_LEN       26  
+#define HT_PROP_IE_OVERHEAD 4
+#define HT_CAP_IE_LEN       26
 #define HT_CAP_IE_TYPE      51
 
-#define HT_CAP_LDPC_CODING  0x0001  
-#define HT_CAP_40MHZ        0x0002  
-#define HT_CAP_MIMO_PS_MASK 0x000C  
-#define HT_CAP_MIMO_PS_SHIFT    0x0002  
-#define HT_CAP_MIMO_PS_OFF  0x0003  
-#define HT_CAP_MIMO_PS_RTS  0x0001  
-#define HT_CAP_MIMO_PS_ON   0x0000  
-#define HT_CAP_GF       0x0010  
-#define HT_CAP_SHORT_GI_20  0x0020  
-#define HT_CAP_SHORT_GI_40  0x0040  
-#define HT_CAP_TX_STBC      0x0080  
-#define HT_CAP_RX_STBC_MASK 0x0300  
-#define HT_CAP_RX_STBC_SHIFT    8   
-#define HT_CAP_DELAYED_BA   0x0400  
-#define HT_CAP_MAX_AMSDU    0x0800  
-#define HT_CAP_DSSS_CCK 0x1000  
-#define HT_CAP_PSMP     0x2000  
-#define HT_CAP_40MHZ_INTOLERANT 0x4000  
-#define HT_CAP_LSIG_TXOP    0x8000  
+#define HT_CAP_LDPC_CODING  0x0001
+#define HT_CAP_40MHZ        0x0002
+#define HT_CAP_MIMO_PS_MASK 0x000C
+#define HT_CAP_MIMO_PS_SHIFT    0x0002
+#define HT_CAP_MIMO_PS_OFF  0x0003
+#define HT_CAP_MIMO_PS_RTS  0x0001
+#define HT_CAP_MIMO_PS_ON   0x0000
+#define HT_CAP_GF       0x0010
+#define HT_CAP_SHORT_GI_20  0x0020
+#define HT_CAP_SHORT_GI_40  0x0040
+#define HT_CAP_TX_STBC      0x0080
+#define HT_CAP_RX_STBC_MASK 0x0300
+#define HT_CAP_RX_STBC_SHIFT    8
+#define HT_CAP_DELAYED_BA   0x0400
+#define HT_CAP_MAX_AMSDU    0x0800
+#define HT_CAP_DSSS_CCK 0x1000
+#define HT_CAP_PSMP     0x2000
+#define HT_CAP_40MHZ_INTOLERANT 0x4000
+#define HT_CAP_LSIG_TXOP    0x8000
 
-#define HT_CAP_RX_STBC_NO       0x0 
-#define HT_CAP_RX_STBC_ONE_STREAM   0x1 
-#define HT_CAP_RX_STBC_TWO_STREAM   0x2 
-#define HT_CAP_RX_STBC_THREE_STREAM 0x3 
+#define HT_CAP_RX_STBC_NO       0x0
+#define HT_CAP_RX_STBC_ONE_STREAM   0x1
+#define HT_CAP_RX_STBC_TWO_STREAM   0x2
+#define HT_CAP_RX_STBC_THREE_STREAM 0x3
 
-#define HT_MAX_AMSDU        7935    
-#define HT_MIN_AMSDU        3835    
+#define HT_MAX_AMSDU        7935
+#define HT_MIN_AMSDU        3835
 
-#define HT_PARAMS_RX_FACTOR_MASK    0x03    
-#define HT_PARAMS_DENSITY_MASK      0x1C    
-#define HT_PARAMS_DENSITY_SHIFT 2   
+#define HT_PARAMS_RX_FACTOR_MASK    0x03
+#define HT_PARAMS_DENSITY_MASK      0x1C
+#define HT_PARAMS_DENSITY_SHIFT 2
 
 
-#define AMPDU_MAX_MPDU_DENSITY  7   
-#define AMPDU_RX_FACTOR_8K  0   
-#define AMPDU_RX_FACTOR_16K 1   
-#define AMPDU_RX_FACTOR_32K 2   
-#define AMPDU_RX_FACTOR_64K 3   
-#define AMPDU_RX_FACTOR_BASE    8*1024  
+#define AMPDU_MAX_MPDU_DENSITY  7
+#define AMPDU_RX_FACTOR_8K  0
+#define AMPDU_RX_FACTOR_16K 1
+#define AMPDU_RX_FACTOR_32K 2
+#define AMPDU_RX_FACTOR_64K 3
+#define AMPDU_RX_FACTOR_BASE    8*1024
 
-#define AMPDU_DELIMITER_LEN 4   
-#define AMPDU_DELIMITER_LEN_MAX 63  
+#define AMPDU_DELIMITER_LEN 4
+#define AMPDU_DELIMITER_LEN_MAX 63
 
 BWL_PRE_PACKED_STRUCT struct ht_add_ie {
-	uint8   ctl_ch;         
-	uint8   byte1;          
-	uint16  opmode;         
-	uint16  misc_bits;      
-	uint8   basic_mcs[MCSSET_LEN];  
+	uint8   ctl_ch;
+	uint8   byte1;
+	uint16  opmode;
+	uint16  misc_bits;
+	uint8   basic_mcs[MCSSET_LEN];
 } BWL_POST_PACKED_STRUCT;
 typedef struct ht_add_ie ht_add_ie_t;
 
 
 
 BWL_PRE_PACKED_STRUCT struct ht_prop_add_ie {
-	uint8   id;     
-	uint8   len;        
-	uint8   oui[3];     
-	uint8   type;       
+	uint8   id;
+	uint8   len;
+	uint8   oui[3];
+	uint8   type;
 	ht_add_ie_t add_ie;
 } BWL_POST_PACKED_STRUCT;
 typedef struct ht_prop_add_ie ht_prop_add_ie_t;
@@ -1535,49 +1724,49 @@
 #define HT_ADD_IE_TYPE  52
 
 
-#define HT_BW_ANY       0x04    
-#define HT_RIFS_PERMITTED       0x08    
+#define HT_BW_ANY       0x04
+#define HT_RIFS_PERMITTED       0x08
 
 
-#define HT_OPMODE_MASK          0x0003  
-#define HT_OPMODE_SHIFT     0   
-#define HT_OPMODE_PURE      0x0000  
-#define HT_OPMODE_OPTIONAL  0x0001  
-#define HT_OPMODE_HT20IN40  0x0002  
-#define HT_OPMODE_MIXED 0x0003  
-#define HT_OPMODE_NONGF 0x0004  
-#define DOT11N_TXBURST      0x0008  
-#define DOT11N_OBSS_NONHT   0x0010  
+#define HT_OPMODE_MASK          0x0003
+#define HT_OPMODE_SHIFT     0
+#define HT_OPMODE_PURE      0x0000
+#define HT_OPMODE_OPTIONAL  0x0001
+#define HT_OPMODE_HT20IN40  0x0002
+#define HT_OPMODE_MIXED 0x0003
+#define HT_OPMODE_NONGF 0x0004
+#define DOT11N_TXBURST      0x0008
+#define DOT11N_OBSS_NONHT   0x0010
 
 
-#define HT_BASIC_STBC_MCS   0x007f  
-#define HT_DUAL_STBC_PROT   0x0080  
-#define HT_SECOND_BCN       0x0100  
-#define HT_LSIG_TXOP        0x0200  
-#define HT_PCO_ACTIVE       0x0400  
-#define HT_PCO_PHASE        0x0800  
+#define HT_BASIC_STBC_MCS   0x007f
+#define HT_DUAL_STBC_PROT   0x0080
+#define HT_SECOND_BCN       0x0100
+#define HT_LSIG_TXOP        0x0200
+#define HT_PCO_ACTIVE       0x0400
+#define HT_PCO_PHASE        0x0800
 
 
-#define DOT11N_2G_TXBURST_LIMIT 6160    
-#define DOT11N_5G_TXBURST_LIMIT 3080    
+#define DOT11N_2G_TXBURST_LIMIT 6160
+#define DOT11N_5G_TXBURST_LIMIT 3080
 
 
 #define GET_HT_OPMODE(add_ie)       ((ltoh16_ua(&add_ie->opmode) & HT_OPMODE_MASK) \
 					>> HT_OPMODE_SHIFT)
 #define HT_MIXEDMODE_PRESENT(add_ie)    ((ltoh16_ua(&add_ie->opmode) & HT_OPMODE_MASK) \
-					== HT_OPMODE_MIXED) 
+					== HT_OPMODE_MIXED)
 #define HT_HT20_PRESENT(add_ie) ((ltoh16_ua(&add_ie->opmode) & HT_OPMODE_MASK) \
-					== HT_OPMODE_HT20IN40)  
+					== HT_OPMODE_HT20IN40)
 #define HT_OPTIONAL_PRESENT(add_ie) ((ltoh16_ua(&add_ie->opmode) & HT_OPMODE_MASK) \
-					== HT_OPMODE_OPTIONAL)  
+					== HT_OPMODE_OPTIONAL)
 #define HT_USE_PROTECTION(add_ie)   (HT_HT20_PRESENT((add_ie)) || \
-					HT_MIXEDMODE_PRESENT((add_ie))) 
+					HT_MIXEDMODE_PRESENT((add_ie)))
 #define HT_NONGF_PRESENT(add_ie)    ((ltoh16_ua(&add_ie->opmode) & HT_OPMODE_NONGF) \
-					== HT_OPMODE_NONGF) 
+					== HT_OPMODE_NONGF)
 #define DOT11N_TXBURST_PRESENT(add_ie)  ((ltoh16_ua(&add_ie->opmode) & DOT11N_TXBURST) \
-					== DOT11N_TXBURST)  
+					== DOT11N_TXBURST)
 #define DOT11N_OBSS_NONHT_PRESENT(add_ie)   ((ltoh16_ua(&add_ie->opmode) & DOT11N_OBSS_NONHT) \
-					== DOT11N_OBSS_NONHT)   
+					== DOT11N_OBSS_NONHT)
 
 BWL_PRE_PACKED_STRUCT struct obss_params {
 	uint16  passive_dwell;
@@ -1596,58 +1785,58 @@
 	obss_params_t obss_params;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_obss_ie dot11_obss_ie_t;
-#define DOT11_OBSS_SCAN_IE_LEN  sizeof(obss_params_t)   
+#define DOT11_OBSS_SCAN_IE_LEN  sizeof(obss_params_t)
 
 
-#define HT_CTRL_LA_TRQ      0x00000002  
-#define HT_CTRL_LA_MAI      0x0000003C  
+#define HT_CTRL_LA_TRQ      0x00000002
+#define HT_CTRL_LA_MAI      0x0000003C
 #define HT_CTRL_LA_MAI_SHIFT    2
-#define HT_CTRL_LA_MAI_MRQ  0x00000004  
-#define HT_CTRL_LA_MAI_MSI  0x00000038  
-#define HT_CTRL_LA_MFSI     0x000001C0  
+#define HT_CTRL_LA_MAI_MRQ  0x00000004
+#define HT_CTRL_LA_MAI_MSI  0x00000038
+#define HT_CTRL_LA_MFSI     0x000001C0
 #define HT_CTRL_LA_MFSI_SHIFT   6
-#define HT_CTRL_LA_MFB_ASELC    0x0000FE00  
+#define HT_CTRL_LA_MFB_ASELC    0x0000FE00
 #define HT_CTRL_LA_MFB_ASELC_SH 9
-#define HT_CTRL_LA_ASELC_CMD    0x00000C00  
-#define HT_CTRL_LA_ASELC_DATA   0x0000F000  
-#define HT_CTRL_CAL_POS     0x00030000  
-#define HT_CTRL_CAL_SEQ     0x000C0000  
-#define HT_CTRL_CSI_STEERING    0x00C00000  
+#define HT_CTRL_LA_ASELC_CMD    0x00000C00
+#define HT_CTRL_LA_ASELC_DATA   0x0000F000
+#define HT_CTRL_CAL_POS     0x00030000
+#define HT_CTRL_CAL_SEQ     0x000C0000
+#define HT_CTRL_CSI_STEERING    0x00C00000
 #define HT_CTRL_CSI_STEER_SHIFT 22
-#define HT_CTRL_CSI_STEER_NFB   0       
-#define HT_CTRL_CSI_STEER_CSI   1       
-#define HT_CTRL_CSI_STEER_NCOM  2       
-#define HT_CTRL_CSI_STEER_COM   3       
-#define HT_CTRL_NDP_ANNOUNCE    0x01000000  
-#define HT_CTRL_AC_CONSTRAINT   0x40000000  
-#define HT_CTRL_RDG_MOREPPDU    0x80000000  
+#define HT_CTRL_CSI_STEER_NFB   0
+#define HT_CTRL_CSI_STEER_CSI   1
+#define HT_CTRL_CSI_STEER_NCOM  2
+#define HT_CTRL_CSI_STEER_COM   3
+#define HT_CTRL_NDP_ANNOUNCE    0x01000000
+#define HT_CTRL_AC_CONSTRAINT   0x40000000
+#define HT_CTRL_RDG_MOREPPDU    0x80000000
 
-#define HT_OPMODE_OPTIONAL  0x0001  
-#define HT_OPMODE_HT20IN40  0x0002  
-#define HT_OPMODE_MIXED 0x0003  
-#define HT_OPMODE_NONGF 0x0004  
-#define DOT11N_TXBURST      0x0008  
-#define DOT11N_OBSS_NONHT   0x0010  
+#define HT_OPMODE_OPTIONAL  0x0001
+#define HT_OPMODE_HT20IN40  0x0002
+#define HT_OPMODE_MIXED 0x0003
+#define HT_OPMODE_NONGF 0x0004
+#define DOT11N_TXBURST      0x0008
+#define DOT11N_OBSS_NONHT   0x0010
 
 
 
-#define WPA_OUI         "\x00\x50\xF2"  
-#define WPA_OUI_LEN     3       
+#define WPA_OUI         "\x00\x50\xF2"
+#define WPA_OUI_LEN     3
 #define WPA_OUI_TYPE        1
-#define WPA_VERSION     1   
-#define WPA2_OUI        "\x00\x0F\xAC"  
-#define WPA2_OUI_LEN        3       
-#define WPA2_VERSION        1   
-#define WPA2_VERSION_LEN    2   
+#define WPA_VERSION     1
+#define WPA2_OUI        "\x00\x0F\xAC"
+#define WPA2_OUI_LEN        3
+#define WPA2_VERSION        1
+#define WPA2_VERSION_LEN    2
 
 
-#define WPS_OUI         "\x00\x50\xF2"  
-#define WPS_OUI_LEN     3       
+#define WPS_OUI         "\x00\x50\xF2"
+#define WPS_OUI_LEN     3
 #define WPS_OUI_TYPE        4
 
 
-#define WFA_OUI         "\x50\x6F\x9A"  
-#define WFA_OUI_LEN 3   
+#define WFA_OUI         "\x50\x6F\x9A"
+#define WFA_OUI_LEN 3
 
 #define WFA_OUI_TYPE_WPA    1
 #define WFA_OUI_TYPE_WPS    4
@@ -1655,58 +1844,59 @@
 #define WFA_OUI_TYPE_P2P    9
 
 
-#define RSN_AKM_NONE        0   
-#define RSN_AKM_UNSPECIFIED 1   
-#define RSN_AKM_PSK     2   
-#define RSN_AKM_FBT_1X      3   
-#define RSN_AKM_FBT_PSK     4   
+#define RSN_AKM_NONE        0
+#define RSN_AKM_UNSPECIFIED 1
+#define RSN_AKM_PSK     2
+#define RSN_AKM_FBT_1X      3
+#define RSN_AKM_FBT_PSK     4
 
 
-#define DOT11_MAX_DEFAULT_KEYS  4   
-#define DOT11_MAX_KEY_SIZE  32  
-#define DOT11_MAX_IV_SIZE   16  
-#define DOT11_EXT_IV_FLAG   (1<<5)  
-#define DOT11_WPA_KEY_RSC_LEN   8       
+#define DOT11_MAX_DEFAULT_KEYS  4
+#define DOT11_MAX_KEY_SIZE  32
+#define DOT11_MAX_IV_SIZE   16
+#define DOT11_EXT_IV_FLAG   (1<<5)
+#define DOT11_WPA_KEY_RSC_LEN   8
 
-#define WEP1_KEY_SIZE       5   
-#define WEP1_KEY_HEX_SIZE   10  
-#define WEP128_KEY_SIZE     13  
-#define WEP128_KEY_HEX_SIZE 26  
-#define TKIP_MIC_SIZE       8   
-#define TKIP_EOM_SIZE       7   
-#define TKIP_EOM_FLAG       0x5a    
-#define TKIP_KEY_SIZE       32  
-#define TKIP_MIC_AUTH_TX    16  
-#define TKIP_MIC_AUTH_RX    24  
-#define TKIP_MIC_SUP_RX     TKIP_MIC_AUTH_TX    
-#define TKIP_MIC_SUP_TX     TKIP_MIC_AUTH_RX    
-#define AES_KEY_SIZE        16  
-#define AES_MIC_SIZE        8   
+#define WEP1_KEY_SIZE       5
+#define WEP1_KEY_HEX_SIZE   10
+#define WEP128_KEY_SIZE     13
+#define WEP128_KEY_HEX_SIZE 26
+#define TKIP_MIC_SIZE       8
+#define TKIP_EOM_SIZE       7
+#define TKIP_EOM_FLAG       0x5a
+#define TKIP_KEY_SIZE       32
+#define TKIP_MIC_AUTH_TX    16
+#define TKIP_MIC_AUTH_RX    24
+#define TKIP_MIC_SUP_RX     TKIP_MIC_AUTH_TX
+#define TKIP_MIC_SUP_TX     TKIP_MIC_AUTH_RX
+#define AES_KEY_SIZE        16
+#define AES_MIC_SIZE        8
 
 
-#define WCN_OUI         "\x00\x50\xf2"  
-#define WCN_TYPE        4   
+#define WCN_OUI         "\x00\x50\xf2"
+#define WCN_TYPE        4
 
-
-
-
+#ifdef WAPI
+#define SMS4_KEY_LEN        16
+#define SMS4_WPI_CBC_MAC_LEN    16
+#endif
 
 BWL_PRE_PACKED_STRUCT struct dot11_mdid_ie {
 	uint8 id;
 	uint8 len;
-	uint16 mdid;        
+	uint16 mdid;
 	uint8 cap;
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_mdid_ie dot11_mdid_ie_t;
 
-#define FBT_MDID_CAP_OVERDS 0x01    
-#define FBT_MDID_CAP_RRP    0x02    
+#define FBT_MDID_CAP_OVERDS 0x01
+#define FBT_MDID_CAP_RRP    0x02
 
 
 BWL_PRE_PACKED_STRUCT struct dot11_ft_ie {
 	uint8 id;
 	uint8 len;
-	uint16 mic_control;     
+	uint16 mic_control;
 	uint8 mic[16];
 	uint8 anonce[32];
 	uint8 snonce[32];
@@ -1724,8 +1914,17 @@
 } BWL_POST_PACKED_STRUCT;
 typedef struct dot11_gtk_ie dot11_gtk_ie_t;
 
+#define BSSID_INVALID           "\x00\x00\x00\x00\x00\x00"
+#define BSSID_BROADCAST         "\xFF\xFF\xFF\xFF\xFF\xFF"
 
+#ifdef WAPI
+#define WAPI_IE_MIN_LEN     20  /* WAPI IE min length */
+#define WAPI_VERSION        1   /* WAPI version */
+#define WAPI_VERSION_LEN    2   /* WAPI version length */
+#define WAPI_OUI        "\x00\x14\x72"  /* WAPI OUI */
+#define WAPI_OUI_LEN        DOT11_OUI_LEN   /* WAPI OUI length */
+#endif /* WAPI */
 
 #include <packed_section_end.h>
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/802.11_bta.h b/drivers/net/wireless/bcmdhd/include/proto/802.11_bta.h
index 4ccfab0..637b36b 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/802.11_bta.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/802.11_bta.h
@@ -2,13 +2,13 @@
  * BT-AMP (BlueTooth Alternate Mac and Phy) 802.11 PAL (Protocol Adaptation Layer)
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: 802.11_bta.h,v 9.2 2008-10-28 23:27:13 Exp $
+ * $Id: 802.11_bta.h,v 9.2 2008-10-28 23:27:13 $
 */
 
 #ifndef _802_11_BTA_H_
diff --git a/drivers/net/wireless/bcmdhd/include/proto/802.11e.h b/drivers/net/wireless/bcmdhd/include/proto/802.11e.h
index ce8ad08..706c2b8 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/802.11e.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/802.11e.h
@@ -2,13 +2,13 @@
  * 802.11e protocol header file
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: 802.11e.h,v 1.6 2008-12-01 22:55:11 Exp $
+ * $Id: 802.11e.h,v 1.6 2008-12-01 22:55:11 $
  */
 
 #ifndef _802_11e_H_
diff --git a/drivers/net/wireless/bcmdhd/include/proto/802.1d.h b/drivers/net/wireless/bcmdhd/include/proto/802.1d.h
index cf20625..43dd964 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/802.1d.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/802.1d.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,14 +14,14 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
  * Fundamental types and constants relating to 802.1D
  *
- * $Id: 802.1d.h,v 9.3 2007-04-10 21:33:06 Exp $
+ * $Id: 802.1d.h,v 9.3 2007-04-10 21:33:06 $
  */
 
 
@@ -29,21 +29,21 @@
 #define _802_1_D_
 
 
-#define	PRIO_8021D_NONE		2	
-#define	PRIO_8021D_BK		1	
-#define	PRIO_8021D_BE		0	
-#define	PRIO_8021D_EE		3	
-#define	PRIO_8021D_CL		4	
-#define	PRIO_8021D_VI		5	
-#define	PRIO_8021D_VO		6	
-#define	PRIO_8021D_NC		7	
-#define	MAXPRIO			7	
+#define	PRIO_8021D_NONE		2
+#define	PRIO_8021D_BK		1
+#define	PRIO_8021D_BE		0
+#define	PRIO_8021D_EE		3
+#define	PRIO_8021D_CL		4
+#define	PRIO_8021D_VI		5
+#define	PRIO_8021D_VO		6
+#define	PRIO_8021D_NC		7
+#define	MAXPRIO			7
 #define NUMPRIO			(MAXPRIO + 1)
 
-#define ALLPRIO		-1	
+#define ALLPRIO		-1
 
 
 #define PRIO2PREC(prio) \
 	(((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? ((prio^2)) : (prio))
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/bcmeth.h b/drivers/net/wireless/bcmdhd/include/proto/bcmeth.h
index 46fa4c9..04859bf 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/bcmeth.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/bcmeth.h
@@ -2,13 +2,13 @@
  * Broadcom Ethernettype  protocol definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bcmeth.h,v 9.12 2009-12-29 19:57:18 Exp $
+ * $Id: bcmeth.h,v 9.12 2009-12-29 19:57:18 $
  */
 
 
@@ -68,11 +68,11 @@
 
 typedef BWL_PRE_PACKED_STRUCT struct bcmeth_hdr
 {
-	uint16	subtype;	
+	uint16	subtype;
 	uint16	length;
-	uint8	version;	
-	uint8	oui[3];		
-	
+	uint8	version;
+	uint8	oui[3];
+
 	uint16	usr_subtype;
 } BWL_POST_PACKED_STRUCT bcmeth_hdr_t;
 
@@ -80,4 +80,4 @@
 
 #include <packed_section_end.h>
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/bcmevent.h b/drivers/net/wireless/bcmdhd/include/proto/bcmevent.h
index 30ec848..95e7cfa 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/bcmevent.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/bcmevent.h
@@ -2,13 +2,13 @@
  * Broadcom Event  protocol definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,14 +16,14 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
  * Dependencies: proto/bcmeth.h
  *
- * $Id: bcmevent.h,v 9.64.2.9 2011-02-01 06:24:21 Exp $
+ * $Id: bcmevent.h,v 9.64.2.9 2011-02-01 06:24:21 $
  *
  */
 
@@ -40,15 +40,15 @@
 
 #include <packed_section_start.h>
 
-#define BCM_EVENT_MSG_VERSION		2	
-#define BCM_MSG_IFNAME_MAX		16	
+#define BCM_EVENT_MSG_VERSION		2
+#define BCM_MSG_IFNAME_MAX		16
 
 
-#define WLC_EVENT_MSG_LINK		0x01	
-#define WLC_EVENT_MSG_FLUSHTXQ		0x02	
-#define WLC_EVENT_MSG_GROUP		0x04	
-#define WLC_EVENT_MSG_UNKBSS		0x08	
-#define WLC_EVENT_MSG_UNKIF		0x10	
+#define WLC_EVENT_MSG_LINK		0x01
+#define WLC_EVENT_MSG_FLUSHTXQ		0x02
+#define WLC_EVENT_MSG_GROUP		0x04
+#define WLC_EVENT_MSG_UNKBSS		0x08
+#define WLC_EVENT_MSG_UNKIF		0x10
 
 
 
@@ -56,30 +56,30 @@
 typedef BWL_PRE_PACKED_STRUCT struct
 {
 	uint16	version;
-	uint16	flags;			
-	uint32	event_type;		
-	uint32	status;			
-	uint32	reason;			
-	uint32	auth_type;		
-	uint32	datalen;		
-	struct ether_addr	addr;	
-	char	ifname[BCM_MSG_IFNAME_MAX]; 
+	uint16	flags;
+	uint32	event_type;
+	uint32	status;
+	uint32	reason;
+	uint32	auth_type;
+	uint32	datalen;
+	struct ether_addr	addr;
+	char	ifname[BCM_MSG_IFNAME_MAX];
 } BWL_POST_PACKED_STRUCT wl_event_msg_v1_t;
 
 
 typedef BWL_PRE_PACKED_STRUCT struct
 {
 	uint16	version;
-	uint16	flags;			
-	uint32	event_type;		
-	uint32	status;			
-	uint32	reason;			
-	uint32	auth_type;		
-	uint32	datalen;		
-	struct ether_addr	addr;	
-	char	ifname[BCM_MSG_IFNAME_MAX]; 
-	uint8	ifidx;			
-	uint8	bsscfgidx;		
+	uint16	flags;
+	uint32	event_type;
+	uint32	status;
+	uint32	reason;
+	uint32	auth_type;
+	uint32	datalen;
+	struct ether_addr	addr;
+	char	ifname[BCM_MSG_IFNAME_MAX];
+	uint8	ifidx;
+	uint8	bsscfgidx;
 } BWL_POST_PACKED_STRUCT wl_event_msg_t;
 
 
@@ -87,104 +87,105 @@
 	struct ether_header eth;
 	bcmeth_hdr_t		bcm_hdr;
 	wl_event_msg_t		event;
-	
+
 } BWL_POST_PACKED_STRUCT bcm_event_t;
 
 #define BCM_MSG_LEN	(sizeof(bcm_event_t) - sizeof(bcmeth_hdr_t) - sizeof(struct ether_header))
 
 
-#define WLC_E_SET_SSID		0	
-#define WLC_E_JOIN		1	
-#define WLC_E_START		2	
-#define WLC_E_AUTH		3	
-#define WLC_E_AUTH_IND		4	
-#define WLC_E_DEAUTH		5	
-#define WLC_E_DEAUTH_IND	6	
-#define WLC_E_ASSOC		7	
-#define WLC_E_ASSOC_IND		8	
-#define WLC_E_REASSOC		9	
-#define WLC_E_REASSOC_IND	10	
-#define WLC_E_DISASSOC		11	
-#define WLC_E_DISASSOC_IND	12	
-#define WLC_E_QUIET_START	13	
-#define WLC_E_QUIET_END		14	
-#define WLC_E_BEACON_RX		15	
-#define WLC_E_LINK		16	
-#define WLC_E_MIC_ERROR		17	
-#define WLC_E_NDIS_LINK		18	
-#define WLC_E_ROAM		19	
-#define WLC_E_TXFAIL		20	
-#define WLC_E_PMKID_CACHE	21	
-#define WLC_E_RETROGRADE_TSF	22	
-#define WLC_E_PRUNE		23	
-#define WLC_E_AUTOAUTH		24	
-#define WLC_E_EAPOL_MSG		25	
-#define WLC_E_SCAN_COMPLETE	26	
-#define WLC_E_ADDTS_IND		27	
-#define WLC_E_DELTS_IND		28	
-#define WLC_E_BCNSENT_IND	29	
-#define WLC_E_BCNRX_MSG		30	
-#define WLC_E_BCNLOST_MSG	31	
-#define WLC_E_ROAM_PREP		32	
-#define WLC_E_PFN_NET_FOUND	33	
-#define WLC_E_PFN_NET_LOST	34	
+#define WLC_E_SET_SSID		0
+#define WLC_E_JOIN		1
+#define WLC_E_START		2
+#define WLC_E_AUTH		3
+#define WLC_E_AUTH_IND		4
+#define WLC_E_DEAUTH		5
+#define WLC_E_DEAUTH_IND	6
+#define WLC_E_ASSOC		7
+#define WLC_E_ASSOC_IND		8
+#define WLC_E_REASSOC		9
+#define WLC_E_REASSOC_IND	10
+#define WLC_E_DISASSOC		11
+#define WLC_E_DISASSOC_IND	12
+#define WLC_E_QUIET_START	13
+#define WLC_E_QUIET_END		14
+#define WLC_E_BEACON_RX		15
+#define WLC_E_LINK		16
+#define WLC_E_MIC_ERROR		17
+#define WLC_E_NDIS_LINK		18
+#define WLC_E_ROAM		19
+#define WLC_E_TXFAIL		20
+#define WLC_E_PMKID_CACHE	21
+#define WLC_E_RETROGRADE_TSF	22
+#define WLC_E_PRUNE		23
+#define WLC_E_AUTOAUTH		24
+#define WLC_E_EAPOL_MSG		25
+#define WLC_E_SCAN_COMPLETE	26
+#define WLC_E_ADDTS_IND		27
+#define WLC_E_DELTS_IND		28
+#define WLC_E_BCNSENT_IND	29
+#define WLC_E_BCNRX_MSG		30
+#define WLC_E_BCNLOST_MSG	31
+#define WLC_E_ROAM_PREP		32
+#define WLC_E_PFN_NET_FOUND	33
+#define WLC_E_PFN_NET_LOST	34
 #define WLC_E_RESET_COMPLETE	35
 #define WLC_E_JOIN_START	36
 #define WLC_E_ROAM_START	37
 #define WLC_E_ASSOC_START	38
 #define WLC_E_IBSS_ASSOC	39
 #define WLC_E_RADIO		40
-#define WLC_E_PSM_WATCHDOG	41	
-#define WLC_E_PROBREQ_MSG       44      
+#define WLC_E_PSM_WATCHDOG	41
+#define WLC_E_PROBREQ_MSG       44
 #define WLC_E_SCAN_CONFIRM_IND  45
-#define WLC_E_PSK_SUP		46	
+#define WLC_E_PSK_SUP		46
 #define WLC_E_COUNTRY_CODE_CHANGED 47
-#define	WLC_E_EXCEEDED_MEDIUM_TIME 48	
-#define WLC_E_ICV_ERROR		49	
-#define WLC_E_UNICAST_DECODE_ERROR 50	
-#define WLC_E_MULTICAST_DECODE_ERROR 51 
+#define	WLC_E_EXCEEDED_MEDIUM_TIME 48
+#define WLC_E_ICV_ERROR		49
+#define WLC_E_UNICAST_DECODE_ERROR 50
+#define WLC_E_MULTICAST_DECODE_ERROR 51
 #define WLC_E_TRACE		52
-#define WLC_E_BTA_HCI_EVENT	53	
-#define WLC_E_IF		54	
+#define WLC_E_BTA_HCI_EVENT	53
+#define WLC_E_IF		54
 #ifdef WLP2P
-#define WLC_E_P2P_DISC_LISTEN_COMPLETE 	55	
+#define WLC_E_P2P_DISC_LISTEN_COMPLETE 	55
 #endif
-#define WLC_E_RSSI		56	
-#define WLC_E_PFN_SCAN_COMPLETE	57	
+#define WLC_E_RSSI		56
+#define WLC_E_PFN_SCAN_COMPLETE	57
 #define WLC_E_EXTLOG_MSG	58
-#define WLC_E_ACTION_FRAME      59 	
-#define WLC_E_ACTION_FRAME_COMPLETE 60	
-#define WLC_E_PRE_ASSOC_IND	61	
-#define WLC_E_PRE_REASSOC_IND	62	
+#define WLC_E_ACTION_FRAME      59
+#define WLC_E_ACTION_FRAME_COMPLETE 60
+#define WLC_E_PRE_ASSOC_IND	61
+#define WLC_E_PRE_REASSOC_IND	62
 #define WLC_E_CHANNEL_ADOPTED	63
-#define WLC_E_AP_STARTED	64	
-#define WLC_E_DFS_AP_STOP	65	
-#define WLC_E_DFS_AP_RESUME	66	
-#define WLC_E_WAI_STA_EVENT	67	
-#define WLC_E_WAI_MSG 		68	
-#define WLC_E_ESCAN_RESULT 	69	
-#define WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE 	70	
+#define WLC_E_AP_STARTED	64
+#define WLC_E_DFS_AP_STOP	65
+#define WLC_E_DFS_AP_RESUME	66
+#define WLC_E_WAI_STA_EVENT	67
+#define WLC_E_WAI_MSG 		68
+#define WLC_E_ESCAN_RESULT 	69
+#define WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE 	70
 #if defined(WLP2P)
-#define WLC_E_PROBRESP_MSG	71	
-#define WLC_E_P2P_PROBREQ_MSG	72	
+#define WLC_E_PROBRESP_MSG	71
+#define WLC_E_P2P_PROBREQ_MSG	72
 #endif
 #define WLC_E_DCS_REQUEST 73
 
-#define WLC_E_FIFO_CREDIT_MAP	74 
+#define WLC_E_FIFO_CREDIT_MAP	74
 
-#define WLC_E_ACTION_FRAME_RX	75	
-#define WLC_E_WAKE_EVENT	76	
-#define WLC_E_RM_COMPLETE	77	
-#define WLC_E_HTSFSYNC		78	
-#define WLC_E_OVERLAY_REQ	79	
+#define WLC_E_ACTION_FRAME_RX	75
+#define WLC_E_WAKE_EVENT	76
+#define WLC_E_RM_COMPLETE	77
+#define WLC_E_HTSFSYNC		78
+#define WLC_E_OVERLAY_REQ	79
 #define WLC_E_CSA_COMPLETE_IND  80
-#define WLC_E_EXCESS_PM_WAKE_EVENT	81	
-#define WLC_E_PFN_SCAN_NONE		82	
-#define WLC_E_PFN_SCAN_ALLGONE	83	
+#define WLC_E_EXCESS_PM_WAKE_EVENT	81
+#define WLC_E_PFN_SCAN_NONE		82
+#define WLC_E_PFN_SCAN_ALLGONE	83
 #define WLC_E_GTK_PLUMBED 84
 #define WLC_E_LAST	85
 
 
+
 typedef struct {
 	uint event;
 	const char *name;
@@ -194,78 +195,80 @@
 extern const int		bcmevent_names_size;
 
 
-#define WLC_E_STATUS_SUCCESS		0	
-#define WLC_E_STATUS_FAIL		1	
-#define WLC_E_STATUS_TIMEOUT		2	
-#define WLC_E_STATUS_NO_NETWORKS	3	
-#define WLC_E_STATUS_ABORT		4	
-#define WLC_E_STATUS_NO_ACK		5	
-#define WLC_E_STATUS_UNSOLICITED	6	
-#define WLC_E_STATUS_ATTEMPT		7	
-#define WLC_E_STATUS_PARTIAL		8	
-#define WLC_E_STATUS_NEWSCAN		9	
-#define WLC_E_STATUS_NEWASSOC		10	
-#define WLC_E_STATUS_11HQUIET		11	
-#define WLC_E_STATUS_SUPPRESS		12	
-#define WLC_E_STATUS_NOCHANS		13	
-#define WLC_E_STATUS_CS_ABORT		15	
-#define WLC_E_STATUS_ERROR		16	
+#define WLC_E_STATUS_SUCCESS		0
+#define WLC_E_STATUS_FAIL		1
+#define WLC_E_STATUS_TIMEOUT		2
+#define WLC_E_STATUS_NO_NETWORKS	3
+#define WLC_E_STATUS_ABORT		4
+#define WLC_E_STATUS_NO_ACK		5
+#define WLC_E_STATUS_UNSOLICITED	6
+#define WLC_E_STATUS_ATTEMPT		7
+#define WLC_E_STATUS_PARTIAL		8
+#define WLC_E_STATUS_NEWSCAN		9
+#define WLC_E_STATUS_NEWASSOC		10
+#define WLC_E_STATUS_11HQUIET		11
+#define WLC_E_STATUS_SUPPRESS		12
+#define WLC_E_STATUS_NOCHANS		13
+#define WLC_E_STATUS_CS_ABORT		15
+#define WLC_E_STATUS_ERROR		16
 
 
-#define WLC_E_REASON_INITIAL_ASSOC	0	
-#define WLC_E_REASON_LOW_RSSI		1	
-#define WLC_E_REASON_DEAUTH		2	
-#define WLC_E_REASON_DISASSOC		3	
-#define WLC_E_REASON_BCNS_LOST		4	
-#define WLC_E_REASON_MINTXRATE		9	
-#define WLC_E_REASON_TXFAIL		10	
+#define WLC_E_REASON_INITIAL_ASSOC	0
+#define WLC_E_REASON_LOW_RSSI		1
+#define WLC_E_REASON_DEAUTH		2
+#define WLC_E_REASON_DISASSOC		3
+#define WLC_E_REASON_BCNS_LOST		4
+#define WLC_E_REASON_MINTXRATE		9
+#define WLC_E_REASON_TXFAIL		10
 
 
-#define WLC_E_REASON_FAST_ROAM_FAILED	5	
-#define WLC_E_REASON_DIRECTED_ROAM	6	
-#define WLC_E_REASON_TSPEC_REJECTED	7	
-#define WLC_E_REASON_BETTER_AP		8	
+#define WLC_E_REASON_FAST_ROAM_FAILED	5
+#define WLC_E_REASON_DIRECTED_ROAM	6
+#define WLC_E_REASON_TSPEC_REJECTED	7
+#define WLC_E_REASON_BETTER_AP		8
+
+#define WLC_E_REASON_REQUESTED_ROAM 11
 
 
-#define WLC_E_PRUNE_ENCR_MISMATCH	1	
-#define WLC_E_PRUNE_BCAST_BSSID		2	
-#define WLC_E_PRUNE_MAC_DENY		3	
-#define WLC_E_PRUNE_MAC_NA		4	
-#define WLC_E_PRUNE_REG_PASSV		5	
-#define WLC_E_PRUNE_SPCT_MGMT		6	
-#define WLC_E_PRUNE_RADAR		7	
-#define WLC_E_RSN_MISMATCH		8	
-#define WLC_E_PRUNE_NO_COMMON_RATES	9	
-#define WLC_E_PRUNE_BASIC_RATES		10	
-#define WLC_E_PRUNE_CIPHER_NA		12	
-#define WLC_E_PRUNE_KNOWN_STA		13	
-#define WLC_E_PRUNE_WDS_PEER		15	
-#define WLC_E_PRUNE_QBSS_LOAD		16	
-#define WLC_E_PRUNE_HOME_AP		17	
+#define WLC_E_PRUNE_ENCR_MISMATCH	1
+#define WLC_E_PRUNE_BCAST_BSSID		2
+#define WLC_E_PRUNE_MAC_DENY		3
+#define WLC_E_PRUNE_MAC_NA		4
+#define WLC_E_PRUNE_REG_PASSV		5
+#define WLC_E_PRUNE_SPCT_MGMT		6
+#define WLC_E_PRUNE_RADAR		7
+#define WLC_E_RSN_MISMATCH		8
+#define WLC_E_PRUNE_NO_COMMON_RATES	9
+#define WLC_E_PRUNE_BASIC_RATES		10
+#define WLC_E_PRUNE_CIPHER_NA		12
+#define WLC_E_PRUNE_KNOWN_STA		13
+#define WLC_E_PRUNE_WDS_PEER		15
+#define WLC_E_PRUNE_QBSS_LOAD		16
+#define WLC_E_PRUNE_HOME_AP		17
 
 
-#define WLC_E_SUP_OTHER			0	
-#define WLC_E_SUP_DECRYPT_KEY_DATA	1	
-#define WLC_E_SUP_BAD_UCAST_WEP128	2	
-#define WLC_E_SUP_BAD_UCAST_WEP40	3	
-#define WLC_E_SUP_UNSUP_KEY_LEN		4	
-#define WLC_E_SUP_PW_KEY_CIPHER		5	
-#define WLC_E_SUP_MSG3_TOO_MANY_IE	6	
-#define WLC_E_SUP_MSG3_IE_MISMATCH	7	
-#define WLC_E_SUP_NO_INSTALL_FLAG	8	
-#define WLC_E_SUP_MSG3_NO_GTK		9	
-#define WLC_E_SUP_GRP_KEY_CIPHER	10	
-#define WLC_E_SUP_GRP_MSG1_NO_GTK	11	
-#define WLC_E_SUP_GTK_DECRYPT_FAIL	12	
-#define WLC_E_SUP_SEND_FAIL		13	
-#define WLC_E_SUP_DEAUTH		14	
-#define WLC_E_SUP_WPA_PSK_TMO		15	
+#define WLC_E_SUP_OTHER			0
+#define WLC_E_SUP_DECRYPT_KEY_DATA	1
+#define WLC_E_SUP_BAD_UCAST_WEP128	2
+#define WLC_E_SUP_BAD_UCAST_WEP40	3
+#define WLC_E_SUP_UNSUP_KEY_LEN		4
+#define WLC_E_SUP_PW_KEY_CIPHER		5
+#define WLC_E_SUP_MSG3_TOO_MANY_IE	6
+#define WLC_E_SUP_MSG3_IE_MISMATCH	7
+#define WLC_E_SUP_NO_INSTALL_FLAG	8
+#define WLC_E_SUP_MSG3_NO_GTK		9
+#define WLC_E_SUP_GRP_KEY_CIPHER	10
+#define WLC_E_SUP_GRP_MSG1_NO_GTK	11
+#define WLC_E_SUP_GTK_DECRYPT_FAIL	12
+#define WLC_E_SUP_SEND_FAIL		13
+#define WLC_E_SUP_DEAUTH		14
+#define WLC_E_SUP_WPA_PSK_TMO		15
 
 
 
 typedef BWL_PRE_PACKED_STRUCT struct wl_event_rx_frame_data {
 	uint16	version;
-	uint16	channel;	
+	uint16	channel;
 	int32	rssi;
 	uint32	mactime;
 	uint32	rate;
@@ -276,37 +279,37 @@
 
 typedef struct wl_event_data_if {
 	uint8 ifidx;
-	uint8 opcode;		
+	uint8 opcode;
 	uint8 reserved;
-	uint8 bssidx;		
-	uint8 role;		
+	uint8 bssidx;
+	uint8 role;
 } wl_event_data_if_t;
 
 
-#define WLC_E_IF_ADD		1	
-#define WLC_E_IF_DEL		2	
-#define WLC_E_IF_CHANGE		3	
+#define WLC_E_IF_ADD		1
+#define WLC_E_IF_DEL		2
+#define WLC_E_IF_CHANGE		3
 
 
-#define WLC_E_IF_ROLE_STA		0	
-#define WLC_E_IF_ROLE_AP		1	
-#define WLC_E_IF_ROLE_WDS		2	
-#define WLC_E_IF_ROLE_P2P_GO		3	
-#define WLC_E_IF_ROLE_P2P_CLIENT	4	
-#define WLC_E_IF_ROLE_BTA_CREATOR	5	
-#define WLC_E_IF_ROLE_BTA_ACCEPTOR	6	
+#define WLC_E_IF_ROLE_STA		0
+#define WLC_E_IF_ROLE_AP		1
+#define WLC_E_IF_ROLE_WDS		2
+#define WLC_E_IF_ROLE_P2P_GO		3
+#define WLC_E_IF_ROLE_P2P_CLIENT	4
+#define WLC_E_IF_ROLE_BTA_CREATOR	5
+#define WLC_E_IF_ROLE_BTA_ACCEPTOR	6
 
 
-#define WLC_E_LINK_BCN_LOSS	1	
-#define WLC_E_LINK_DISASSOC	2	
-#define WLC_E_LINK_ASSOC_REC	3	
-#define WLC_E_LINK_BSSCFG_DIS	4	
+#define WLC_E_LINK_BCN_LOSS	1
+#define WLC_E_LINK_DISASSOC	2
+#define WLC_E_LINK_ASSOC_REC	3
+#define WLC_E_LINK_BSSCFG_DIS	4
 
 
-#define WLC_E_OVL_DOWNLOAD	0	
-#define WLC_E_OVL_UPDATE_IND	1	
+#define WLC_E_OVL_DOWNLOAD	0
+#define WLC_E_OVL_UPDATE_IND	1
 
 
 #include <packed_section_end.h>
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/bcmip.h b/drivers/net/wireless/bcmdhd/include/proto/bcmip.h
index 8a8f314..eb61c28c6 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/bcmip.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/bcmip.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,14 +14,14 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
  * Fundamental constants relating to IP Protocol
  *
- * $Id: bcmip.h,v 9.19 2009-11-10 20:08:33 Exp $
+ * $Id: bcmip.h,v 9.19 2009-11-10 20:08:33 $
  */
 
 
@@ -37,38 +37,38 @@
 
 
 
-#define IP_VER_OFFSET		0x0	
-#define IP_VER_MASK		0xf0	
-#define IP_VER_SHIFT		4	
-#define IP_VER_4		4	
-#define IP_VER_6		6	
+#define IP_VER_OFFSET		0x0
+#define IP_VER_MASK		0xf0
+#define IP_VER_SHIFT		4
+#define IP_VER_4		4
+#define IP_VER_6		6
 
 #define IP_VER(ip_body) \
 	((((uint8 *)(ip_body))[IP_VER_OFFSET] & IP_VER_MASK) >> IP_VER_SHIFT)
 
-#define IP_PROT_ICMP		0x1	
-#define IP_PROT_TCP		0x6	
-#define IP_PROT_UDP		0x11	
+#define IP_PROT_ICMP		0x1
+#define IP_PROT_TCP		0x6
+#define IP_PROT_UDP		0x11
 
 
-#define IPV4_VER_HL_OFFSET	0	
-#define IPV4_TOS_OFFSET		1	
-#define IPV4_PKTLEN_OFFSET	2	
-#define IPV4_PKTFLAG_OFFSET	6	
-#define IPV4_PROT_OFFSET	9	
-#define IPV4_CHKSUM_OFFSET	10	
-#define IPV4_SRC_IP_OFFSET	12	
-#define IPV4_DEST_IP_OFFSET	16	
-#define IPV4_OPTIONS_OFFSET	20	
+#define IPV4_VER_HL_OFFSET	0
+#define IPV4_TOS_OFFSET		1
+#define IPV4_PKTLEN_OFFSET	2
+#define IPV4_PKTFLAG_OFFSET	6
+#define IPV4_PROT_OFFSET	9
+#define IPV4_CHKSUM_OFFSET	10
+#define IPV4_SRC_IP_OFFSET	12
+#define IPV4_DEST_IP_OFFSET	16
+#define IPV4_OPTIONS_OFFSET	20
 
 
-#define IPV4_VER_MASK		0xf0	
-#define IPV4_VER_SHIFT		4	
+#define IPV4_VER_MASK		0xf0
+#define IPV4_VER_SHIFT		4
 
-#define IPV4_HLEN_MASK		0x0f	
+#define IPV4_HLEN_MASK		0x0f
 #define IPV4_HLEN(ipv4_body)	(4 * (((uint8 *)(ipv4_body))[IPV4_VER_HL_OFFSET] & IPV4_HLEN_MASK))
 
-#define IPV4_ADDR_LEN		4	
+#define IPV4_ADDR_LEN		4
 
 #define IPV4_ADDR_NULL(a)	((((uint8 *)(a))[0] | ((uint8 *)(a))[1] | \
 				  ((uint8 *)(a))[2] | ((uint8 *)(a))[3]) == 0)
@@ -76,26 +76,26 @@
 #define IPV4_ADDR_BCAST(a)	((((uint8 *)(a))[0] & ((uint8 *)(a))[1] & \
 				  ((uint8 *)(a))[2] & ((uint8 *)(a))[3]) == 0xff)
 
-#define	IPV4_TOS_DSCP_MASK	0xfc	
-#define	IPV4_TOS_DSCP_SHIFT	2	
+#define	IPV4_TOS_DSCP_MASK	0xfc
+#define	IPV4_TOS_DSCP_SHIFT	2
 
 #define	IPV4_TOS(ipv4_body)	(((uint8 *)(ipv4_body))[IPV4_TOS_OFFSET])
 
-#define	IPV4_TOS_PREC_MASK	0xe0	
-#define	IPV4_TOS_PREC_SHIFT	5	
+#define	IPV4_TOS_PREC_MASK	0xe0
+#define	IPV4_TOS_PREC_SHIFT	5
 
-#define IPV4_TOS_LOWDELAY	0x10	
-#define IPV4_TOS_THROUGHPUT	0x8	
-#define IPV4_TOS_RELIABILITY	0x4	
+#define IPV4_TOS_LOWDELAY	0x10
+#define IPV4_TOS_THROUGHPUT	0x8
+#define IPV4_TOS_RELIABILITY	0x4
 
 #define IPV4_PROT(ipv4_body)	(((uint8 *)(ipv4_body))[IPV4_PROT_OFFSET])
 
-#define IPV4_FRAG_RESV		0x8000	
-#define IPV4_FRAG_DONT		0x4000	
-#define IPV4_FRAG_MORE		0x2000	
-#define IPV4_FRAG_OFFSET_MASK	0x1fff	
+#define IPV4_FRAG_RESV		0x8000
+#define IPV4_FRAG_DONT		0x4000
+#define IPV4_FRAG_MORE		0x2000
+#define IPV4_FRAG_OFFSET_MASK	0x1fff
 
-#define IPV4_ADDR_STR_LEN	16	
+#define IPV4_ADDR_STR_LEN	16
 
 
 BWL_PRE_PACKED_STRUCT struct ipv4_addr {
@@ -103,24 +103,24 @@
 } BWL_POST_PACKED_STRUCT;
 
 BWL_PRE_PACKED_STRUCT struct ipv4_hdr {
-	uint8	version_ihl;		
-	uint8	tos;			
-	uint16	tot_len;		
+	uint8	version_ihl;
+	uint8	tos;
+	uint16	tot_len;
 	uint16	id;
-	uint16	frag;			
-	uint8	ttl;			
-	uint8	prot;			
-	uint16	hdr_chksum;		
-	uint8	src_ip[IPV4_ADDR_LEN];	
-	uint8	dst_ip[IPV4_ADDR_LEN];	
+	uint16	frag;
+	uint8	ttl;
+	uint8	prot;
+	uint16	hdr_chksum;
+	uint8	src_ip[IPV4_ADDR_LEN];
+	uint8	dst_ip[IPV4_ADDR_LEN];
 } BWL_POST_PACKED_STRUCT;
 
 
-#define IPV6_PAYLOAD_LEN_OFFSET	4	
-#define IPV6_NEXT_HDR_OFFSET	6	
-#define IPV6_HOP_LIMIT_OFFSET	7	
-#define IPV6_SRC_IP_OFFSET	8	
-#define IPV6_DEST_IP_OFFSET	24	
+#define IPV6_PAYLOAD_LEN_OFFSET	4
+#define IPV6_NEXT_HDR_OFFSET	6
+#define IPV6_HOP_LIMIT_OFFSET	7
+#define IPV6_SRC_IP_OFFSET	8
+#define IPV6_DEST_IP_OFFSET	24
 
 
 #define IPV6_TRAFFIC_CLASS(ipv6_body) \
@@ -141,7 +141,7 @@
 
 #define IPV6_PROT(ipv6_body)	IPV6_NEXT_HDR(ipv6_body)
 
-#define IPV6_ADDR_LEN		16	
+#define IPV6_ADDR_LEN		16
 
 
 #define IP_TOS46(ip_body) \
@@ -151,4 +151,4 @@
 
 #include <packed_section_end.h>
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/bt_amp_hci.h b/drivers/net/wireless/bcmdhd/include/proto/bt_amp_hci.h
index 89c1181..89fcfb7 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/bt_amp_hci.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/bt_amp_hci.h
@@ -2,13 +2,13 @@
  * BT-AMP (BlueTooth Alternate Mac and Phy) HCI (Host/Controller Interface)
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: bt_amp_hci.h,v 9.14.8.2 2010-09-10 18:37:47 Exp $
+ * $Id: bt_amp_hci.h,v 9.14.8.2 2010-09-10 18:37:47 $
 */
 
 #ifndef _bt_amp_hci_h
diff --git a/drivers/net/wireless/bcmdhd/include/proto/eapol.h b/drivers/net/wireless/bcmdhd/include/proto/eapol.h
index 5781d13..aab3054 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/eapol.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/eapol.h
@@ -7,7 +7,7 @@
  *
  * Copyright (C) 2002 Broadcom Corporation
  *
- * $Id: eapol.h,v 9.23.86.1 2010-09-02 18:09:39 Exp $
+ * $Id: eapol.h,v 9.23.86.1 2010-09-02 18:09:39 $
  */
 
 #ifndef _eapol_h_
diff --git a/drivers/net/wireless/bcmdhd/include/proto/ethernet.h b/drivers/net/wireless/bcmdhd/include/proto/ethernet.h
index 6a6dd14..071751e 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/ethernet.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/ethernet.h
@@ -2,13 +2,13 @@
  * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,16 +16,16 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: ethernet.h,v 9.56 2009-10-15 22:54:58 Exp $
+ * $Id: ethernet.h,v 9.56 2009-10-15 22:54:58 $
  */
 
 
-#ifndef _NET_ETHERNET_H_	      
+#ifndef _NET_ETHERNET_H_
 #define _NET_ETHERNET_H_
 
 #ifndef _TYPEDEFS_H_
@@ -61,24 +61,24 @@
 #define	ETHER_MAX_DATA		1500
 
 
-#define ETHER_TYPE_MIN		0x0600		
-#define	ETHER_TYPE_IP		0x0800		
-#define ETHER_TYPE_ARP		0x0806		
-#define ETHER_TYPE_8021Q	0x8100		
-#define	ETHER_TYPE_BRCM		0x886c		
-#define	ETHER_TYPE_802_1X	0x888e		
-#define	ETHER_TYPE_802_1X_PREAUTH 0x88c7	
-#define ETHER_TYPE_WAI		0x88b4		
+#define ETHER_TYPE_MIN		0x0600
+#define	ETHER_TYPE_IP		0x0800
+#define ETHER_TYPE_ARP		0x0806
+#define ETHER_TYPE_8021Q	0x8100
+#define	ETHER_TYPE_BRCM		0x886c
+#define	ETHER_TYPE_802_1X	0x888e
+#define	ETHER_TYPE_802_1X_PREAUTH 0x88c7
+#define ETHER_TYPE_WAI		0x88b4
 
 
 
-#define	ETHER_BRCM_SUBTYPE_LEN	4	
-#define	ETHER_BRCM_CRAM		1	
+#define	ETHER_BRCM_SUBTYPE_LEN	4
+#define	ETHER_BRCM_CRAM		1
 
 
-#define ETHER_DEST_OFFSET	(0 * ETHER_ADDR_LEN)	
-#define ETHER_SRC_OFFSET	(1 * ETHER_ADDR_LEN)	
-#define ETHER_TYPE_OFFSET	(2 * ETHER_ADDR_LEN)	
+#define ETHER_DEST_OFFSET	(0 * ETHER_ADDR_LEN)
+#define ETHER_SRC_OFFSET	(1 * ETHER_ADDR_LEN)
+#define ETHER_TYPE_OFFSET	(2 * ETHER_ADDR_LEN)
 
 
 #define	ETHER_IS_VALID_LEN(foo)	\
@@ -93,7 +93,7 @@
 		((uint8 *)ea)[5] = ((mgrp_ip) >>  0) & 0xff;	\
 }
 
-#ifndef __INCif_etherh       
+#ifndef __INCif_etherh
 
 BWL_PRE_PACKED_STRUCT struct ether_header {
 	uint8	ether_dhost[ETHER_ADDR_LEN];
@@ -105,7 +105,7 @@
 BWL_PRE_PACKED_STRUCT struct	ether_addr {
 	uint8 octet[ETHER_ADDR_LEN];
 } BWL_POST_PACKED_STRUCT;
-#endif	
+#endif
 
 
 #define ETHER_SET_LOCALADDR(ea)	(((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
@@ -159,4 +159,4 @@
 
 #include <packed_section_end.h>
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/p2p.h b/drivers/net/wireless/bcmdhd/include/proto/p2p.h
index 4a0c9d1d..16ac7fd 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/p2p.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/p2p.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,14 +14,14 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
  * Fundamental types and constants relating to WFA P2P (aka WiFi Direct)
  *
- * $Id: p2p.h,v 9.17.2.4 2010-12-15 21:41:21 Exp $
+ * $Id: p2p.h,v 9.17.2.4 2010-12-15 21:41:21 $
  */
 
 #ifndef _P2P_H_
diff --git a/drivers/net/wireless/bcmdhd/include/proto/sdspi.h b/drivers/net/wireless/bcmdhd/include/proto/sdspi.h
deleted file mode 100644
index 7fe4fbc..0000000
--- a/drivers/net/wireless/bcmdhd/include/proto/sdspi.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SD-SPI Protocol Standard
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: sdspi.h,v 9.2.120.1 2010-11-15 17:56:25 Exp $
- */
-
-#ifndef	_SD_SPI_H
-#define	_SD_SPI_H
-
-#define SPI_START_M		BITFIELD_MASK(1)	/* Bit [31] 	- Start Bit */
-#define SPI_START_S		31
-#define SPI_DIR_M		BITFIELD_MASK(1)	/* Bit [30] 	- Direction */
-#define SPI_DIR_S		30
-#define SPI_CMD_INDEX_M		BITFIELD_MASK(6)	/* Bits [29:24] - Command number */
-#define SPI_CMD_INDEX_S		24
-#define SPI_RW_M		BITFIELD_MASK(1)	/* Bit [23] 	- Read=0, Write=1 */
-#define SPI_RW_S		23
-#define SPI_FUNC_M		BITFIELD_MASK(3)	/* Bits [22:20]	- Function Number */
-#define SPI_FUNC_S		20
-#define SPI_RAW_M		BITFIELD_MASK(1)	/* Bit [19] 	- Read After Wr */
-#define SPI_RAW_S		19
-#define SPI_STUFF_M		BITFIELD_MASK(1)	/* Bit [18] 	- Stuff bit */
-#define SPI_STUFF_S		18
-#define SPI_BLKMODE_M		BITFIELD_MASK(1)	/* Bit [19] 	- Blockmode 1=blk */
-#define SPI_BLKMODE_S		19
-#define SPI_OPCODE_M		BITFIELD_MASK(1)	/* Bit [18] 	- OP Code */
-#define SPI_OPCODE_S		18
-#define SPI_ADDR_M		BITFIELD_MASK(17)	/* Bits [17:1] 	- Address */
-#define SPI_ADDR_S		1
-#define SPI_STUFF0_M		BITFIELD_MASK(1)	/* Bit [0] 	- Stuff bit */
-#define SPI_STUFF0_S		0
-
-#define SPI_RSP_START_M		BITFIELD_MASK(1)	/* Bit [7] 	- Start Bit (always 0) */
-#define SPI_RSP_START_S		7
-#define SPI_RSP_PARAM_ERR_M	BITFIELD_MASK(1)	/* Bit [6] 	- Parameter Error */
-#define SPI_RSP_PARAM_ERR_S	6
-#define SPI_RSP_RFU5_M		BITFIELD_MASK(1)	/* Bit [5] 	- RFU (Always 0) */
-#define SPI_RSP_RFU5_S		5
-#define SPI_RSP_FUNC_ERR_M	BITFIELD_MASK(1)	/* Bit [4] 	- Function number error */
-#define SPI_RSP_FUNC_ERR_S	4
-#define SPI_RSP_CRC_ERR_M	BITFIELD_MASK(1)	/* Bit [3] 	- COM CRC Error */
-#define SPI_RSP_CRC_ERR_S	3
-#define SPI_RSP_ILL_CMD_M	BITFIELD_MASK(1)	/* Bit [2] 	- Illegal Command error */
-#define SPI_RSP_ILL_CMD_S	2
-#define SPI_RSP_RFU1_M		BITFIELD_MASK(1)	/* Bit [1] 	- RFU (Always 0) */
-#define SPI_RSP_RFU1_S		1
-#define SPI_RSP_IDLE_M		BITFIELD_MASK(1)	/* Bit [0] 	- In idle state */
-#define SPI_RSP_IDLE_S		0
-
-/* SD-SPI Protocol Definitions */
-#define SDSPI_COMMAND_LEN	6	/* Number of bytes in an SD command */
-#define SDSPI_START_BLOCK	0xFE	/* SD Start Block Token */
-#define SDSPI_IDLE_PAD		0xFF	/* SD-SPI idle value for MOSI */
-#define SDSPI_START_BIT_MASK	0x80
-
-#endif /* _SD_SPI_H */
diff --git a/drivers/net/wireless/bcmdhd/include/proto/vlan.h b/drivers/net/wireless/bcmdhd/include/proto/vlan.h
index 07fa7e4..ad31b2a 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/vlan.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/vlan.h
@@ -2,13 +2,13 @@
  * 802.1Q VLAN protocol definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: vlan.h,v 9.7 2009-03-13 01:11:50 Exp $
+ * $Id: vlan.h,v 9.7 2009-03-13 01:11:50 $
  */
 
 
@@ -35,22 +35,22 @@
 
 #include <packed_section_start.h>
 
-#define VLAN_VID_MASK		0xfff	
-#define	VLAN_CFI_SHIFT		12	
-#define VLAN_PRI_SHIFT		13	
+#define VLAN_VID_MASK		0xfff
+#define	VLAN_CFI_SHIFT		12
+#define VLAN_PRI_SHIFT		13
 
-#define VLAN_PRI_MASK		7	
+#define VLAN_PRI_MASK		7
 
 #define	VLAN_TAG_LEN		4
-#define	VLAN_TAG_OFFSET		(2 * ETHER_ADDR_LEN)	
+#define	VLAN_TAG_OFFSET		(2 * ETHER_ADDR_LEN)
 
-#define VLAN_TPID		0x8100	
+#define VLAN_TPID		0x8100
 
 struct ethervlan_header {
 	uint8	ether_dhost[ETHER_ADDR_LEN];
 	uint8	ether_shost[ETHER_ADDR_LEN];
-	uint16	vlan_type;		
-	uint16	vlan_tag;		
+	uint16	vlan_type;
+	uint16	vlan_tag;
 	uint16	ether_type;
 };
 
@@ -67,4 +67,4 @@
 	*(struct ethervlan_header *)(d) = t; \
 } while (0)
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/proto/wpa.h b/drivers/net/wireless/bcmdhd/include/proto/wpa.h
index 1ff06dc..ca32ac7 100644
--- a/drivers/net/wireless/bcmdhd/include/proto/wpa.h
+++ b/drivers/net/wireless/bcmdhd/include/proto/wpa.h
@@ -2,13 +2,13 @@
  * Fundamental types and constants relating to WPA
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wpa.h,v 1.19 2009-07-13 08:29:58 Exp $
+ * $Id: wpa.h,v 1.19 2009-07-13 08:29:58 $
  */
 
 
@@ -38,43 +38,43 @@
 
 
 
-#define DOT11_RC_INVALID_WPA_IE		13	
-#define DOT11_RC_MIC_FAILURE		14	
-#define DOT11_RC_4WH_TIMEOUT		15	
-#define DOT11_RC_GTK_UPDATE_TIMEOUT	16	
-#define DOT11_RC_WPA_IE_MISMATCH	17	
-#define DOT11_RC_INVALID_MC_CIPHER	18	
-#define DOT11_RC_INVALID_UC_CIPHER	19	
-#define DOT11_RC_INVALID_AKMP		20	
-#define DOT11_RC_BAD_WPA_VERSION	21	
-#define DOT11_RC_INVALID_WPA_CAP	22	
-#define DOT11_RC_8021X_AUTH_FAIL	23	
+#define DOT11_RC_INVALID_WPA_IE		13
+#define DOT11_RC_MIC_FAILURE		14
+#define DOT11_RC_4WH_TIMEOUT		15
+#define DOT11_RC_GTK_UPDATE_TIMEOUT	16
+#define DOT11_RC_WPA_IE_MISMATCH	17
+#define DOT11_RC_INVALID_MC_CIPHER	18
+#define DOT11_RC_INVALID_UC_CIPHER	19
+#define DOT11_RC_INVALID_AKMP		20
+#define DOT11_RC_BAD_WPA_VERSION	21
+#define DOT11_RC_INVALID_WPA_CAP	22
+#define DOT11_RC_8021X_AUTH_FAIL	23
 
 #define WPA2_PMKID_LEN	16
 
 
 typedef BWL_PRE_PACKED_STRUCT struct
 {
-	uint8 tag;	
-	uint8 length;	
-	uint8 oui[3];	
-	uint8 oui_type;	
+	uint8 tag;
+	uint8 length;
+	uint8 oui[3];
+	uint8 oui_type;
 	BWL_PRE_PACKED_STRUCT struct {
 		uint8 low;
 		uint8 high;
-	} BWL_POST_PACKED_STRUCT version;	
+	} BWL_POST_PACKED_STRUCT version;
 } BWL_POST_PACKED_STRUCT wpa_ie_fixed_t;
 #define WPA_IE_OUITYPE_LEN	4
 #define WPA_IE_FIXED_LEN	8
 #define WPA_IE_TAG_FIXED_LEN	6
 
 typedef BWL_PRE_PACKED_STRUCT struct {
-	uint8 tag;	
-	uint8 length;	
+	uint8 tag;
+	uint8 length;
 	BWL_PRE_PACKED_STRUCT struct {
 		uint8 low;
 		uint8 high;
-	} BWL_POST_PACKED_STRUCT version;	
+	} BWL_POST_PACKED_STRUCT version;
 } BWL_POST_PACKED_STRUCT wpa_rsn_ie_fixed_t;
 #define WPA_RSN_IE_FIXED_LEN	4
 #define WPA_RSN_IE_TAG_FIXED_LEN	2
@@ -108,27 +108,43 @@
 } BWL_POST_PACKED_STRUCT wpa_pmkid_list_t;
 
 
-#define WPA_CIPHER_NONE		0	
-#define WPA_CIPHER_WEP_40	1	
-#define WPA_CIPHER_TKIP		2	
-#define WPA_CIPHER_AES_OCB	3	
-#define WPA_CIPHER_AES_CCM	4	
-#define WPA_CIPHER_WEP_104	5	
+#define WPA_CIPHER_NONE		0
+#define WPA_CIPHER_WEP_40	1
+#define WPA_CIPHER_TKIP		2
+#define WPA_CIPHER_AES_OCB	3
+#define WPA_CIPHER_AES_CCM	4
+#define WPA_CIPHER_WEP_104	5
 
+#ifdef WAPI
+#define WAPI_CIPHER_NONE	WPA_CIPHER_NONE
+#define WAPI_CIPHER_SMS4	11
 
+#define WAPI_CSE_WPI_SMS4	1
+#endif /* WAPI */
 #define IS_WPA_CIPHER(cipher)	((cipher) == WPA_CIPHER_NONE || \
 				 (cipher) == WPA_CIPHER_WEP_40 || \
 				 (cipher) == WPA_CIPHER_WEP_104 || \
 				 (cipher) == WPA_CIPHER_TKIP || \
 				 (cipher) == WPA_CIPHER_AES_OCB || \
 				 (cipher) == WPA_CIPHER_AES_CCM)
+#ifdef WAPI
+#define IS_WAPI_CIPHER(cipher)	((cipher) == WAPI_CIPHER_NONE || \
+				 (cipher) == WAPI_CSE_WPI_SMS4)
+
+/* convert WAPI_CSE_WPI_XXX to WAPI_CIPHER_XXX */
+#define WAPI_CSE_WPI_2_CIPHER(cse) ((cse) == WAPI_CSE_WPI_SMS4 ? \
+				WAPI_CIPHER_SMS4 : WAPI_CIPHER_NONE)
+
+#define WAPI_CIPHER_2_CSE_WPI(cipher) ((cipher) == WAPI_CIPHER_SMS4 ? \
+				WAPI_CSE_WPI_SMS4 : WAPI_CIPHER_NONE)
+#endif /* WAPI */
 
 
-#define WPA_TKIP_CM_DETECT	60	
-#define WPA_TKIP_CM_BLOCK	60	
+#define WPA_TKIP_CM_DETECT	60
+#define WPA_TKIP_CM_BLOCK	60
 
 
-#define RSN_CAP_LEN		2	
+#define RSN_CAP_LEN		2
 
 
 #define RSN_CAP_PREAUTH			0x0001
@@ -149,12 +165,23 @@
 #define WPA_CAP_REPLAY_CNTR_MASK	RSN_CAP_PTK_REPLAY_CNTR_MASK
 
 
-#define WPA_CAP_LEN	RSN_CAP_LEN	
+#define WPA_CAP_LEN	RSN_CAP_LEN
 
 #define	WPA_CAP_WPA2_PREAUTH		RSN_CAP_PREAUTH
 
+#ifdef WAPI
+#define WAPI_CAP_PREAUTH		RSN_CAP_PREAUTH
 
+/* Other WAI definition */
+#define WAPI_WAI_REQUEST		0x00F1
+#define WAPI_UNICAST_REKEY		0x00F2
+#define WAPI_STA_AGING			0x00F3
+#define WAPI_MUTIL_REKEY		0x00F4
+#define WAPI_STA_STATS			0x00F5
 
+#define WAPI_USK_REKEY_COUNT		0x4000000 /* 0xA00000 */
+#define WAPI_MSK_REKEY_COUNT		0x4000000 /* 0xA00000 */
+#endif /* WAPI */
 #include <packed_section_end.h>
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sbchipc.h b/drivers/net/wireless/bcmdhd/include/sbchipc.h
index cbd3749..947b71e 100644
--- a/drivers/net/wireless/bcmdhd/include/sbchipc.h
+++ b/drivers/net/wireless/bcmdhd/include/sbchipc.h
@@ -5,16 +5,16 @@
  * JTAG, 0/1/2 UARTs, clock frequency control, a watchdog interrupt timer,
  * GPIO interface, extbus, and support for serial and parallel flashes.
  *
- * $Id: sbchipc.h,v 13.169.2.14 2011-02-10 23:43:55 Exp $
+ * $Id: sbchipc.h 275703 2011-08-04 20:20:27Z $
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -22,7 +22,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -39,109 +39,109 @@
 #define	_PADLINE(line)	pad ## line
 #define	_XSTR(line)	_PADLINE(line)
 #define	PAD		_XSTR(__LINE__)
-#endif	
+#endif
 
 typedef volatile struct {
-	uint32	chipid;			
+	uint32	chipid;
 	uint32	capabilities;
-	uint32	corecontrol;		
+	uint32	corecontrol;
 	uint32	bist;
 
-	
-	uint32	otpstatus;		
+
+	uint32	otpstatus;
 	uint32	otpcontrol;
 	uint32	otpprog;
-	uint32	otplayout;		
+	uint32	otplayout;
 
-	
-	uint32	intstatus;		
+
+	uint32	intstatus;
 	uint32	intmask;
 
-	
-	uint32	chipcontrol;		
-	uint32	chipstatus;		
 
-	
-	uint32	jtagcmd;		
+	uint32	chipcontrol;
+	uint32	chipstatus;
+
+
+	uint32	jtagcmd;
 	uint32	jtagir;
 	uint32	jtagdr;
 	uint32	jtagctrl;
 
-	
-	uint32	flashcontrol;		
+
+	uint32	flashcontrol;
 	uint32	flashaddress;
 	uint32	flashdata;
 	uint32	PAD[1];
 
-	
-	uint32	broadcastaddress;	
+
+	uint32	broadcastaddress;
 	uint32	broadcastdata;
 
-	
-	uint32	gpiopullup;		
-	uint32	gpiopulldown;		
-	uint32	gpioin;			
-	uint32	gpioout;		
-	uint32	gpioouten;		
-	uint32	gpiocontrol;		
-	uint32	gpiointpolarity;	
-	uint32	gpiointmask;		
 
-	
+	uint32	gpiopullup;
+	uint32	gpiopulldown;
+	uint32	gpioin;
+	uint32	gpioout;
+	uint32	gpioouten;
+	uint32	gpiocontrol;
+	uint32	gpiointpolarity;
+	uint32	gpiointmask;
+
+
 	uint32	gpioevent;
 	uint32	gpioeventintmask;
 
-	
-	uint32	watchdog;		
 
-	
+	uint32	watchdog;
+
+
 	uint32	gpioeventintpolarity;
 
-	
-	uint32  gpiotimerval;		
+
+	uint32  gpiotimerval;
 	uint32  gpiotimeroutmask;
 
-	
-	uint32	clockcontrol_n;		
-	uint32	clockcontrol_sb;	
-	uint32	clockcontrol_pci;	
-	uint32	clockcontrol_m2;	
-	uint32	clockcontrol_m3;	
-	uint32	clkdiv;			
-	uint32	gpiodebugsel;		
-	uint32	capabilities_ext;               	
 
-	
-	uint32	pll_on_delay;		
+	uint32	clockcontrol_n;
+	uint32	clockcontrol_sb;
+	uint32	clockcontrol_pci;
+	uint32	clockcontrol_m2;
+	uint32	clockcontrol_m3;
+	uint32	clkdiv;
+	uint32	gpiodebugsel;
+	uint32	capabilities_ext;
+
+
+	uint32	pll_on_delay;
 	uint32	fref_sel_delay;
-	uint32	slow_clk_ctl;		
+	uint32	slow_clk_ctl;
 	uint32	PAD;
 
-	
-	uint32	system_clk_ctl;		
+
+	uint32	system_clk_ctl;
 	uint32	clkstatestretch;
 	uint32	PAD[2];
 
-	
-	uint32	bp_addrlow;		
+
+	uint32	bp_addrlow;
 	uint32	bp_addrhigh;
 	uint32	bp_data;
 	uint32	PAD;
 	uint32	bp_indaccess;
-	
+
 	uint32	gsioctrl;
 	uint32	gsioaddress;
 	uint32	gsiodata;
 
-	
+
 	uint32	clkdiv2;
 	uint32	PAD[2];
 
-	
-	uint32	eromptr;		
 
-	
-	uint32	pcmcia_config;		
+	uint32	eromptr;
+
+
+	uint32	pcmcia_config;
 	uint32	pcmcia_memwait;
 	uint32	pcmcia_attrwait;
 	uint32	pcmcia_iowait;
@@ -156,14 +156,14 @@
 	uint32	PAD[4];
 	uint32	PAD[40];
 
-	
-	
-	uint32	clk_ctl_st;		
+
+
+	uint32	clk_ctl_st;
 	uint32	hw_war;
 	uint32	PAD[70];
 
-	
-	uint8	uart0data;		
+
+	uint8	uart0data;
 	uint8	uart0imr;
 	uint8	uart0fcr;
 	uint8	uart0lcr;
@@ -171,9 +171,9 @@
 	uint8	uart0lsr;
 	uint8	uart0msr;
 	uint8	uart0scratch;
-	uint8	PAD[248];		
+	uint8	PAD[248];
 
-	uint8	uart1data;		
+	uint8	uart1data;
 	uint8	uart1imr;
 	uint8	uart1fcr;
 	uint8	uart1lcr;
@@ -183,9 +183,9 @@
 	uint8	uart1scratch;
 	uint32	PAD[126];
 
-	
-	
-	uint32	pmucontrol;		
+
+
+	uint32	pmucontrol;
 	uint32	pmucapabilities;
 	uint32	pmustatus;
 	uint32	res_state;
@@ -199,25 +199,25 @@
 	uint32	res_timer;
 	uint32	clkstretch;
 	uint32	pmuwatchdog;
-	uint32	gpiosel;		
-	uint32	gpioenable;		
+	uint32	gpiosel;
+	uint32	gpioenable;
 	uint32	res_req_timer_sel;
 	uint32	res_req_timer;
 	uint32	res_req_mask;
 	uint32	PAD;
-	uint32	chipcontrol_addr;	
-	uint32	chipcontrol_data;	
+	uint32	chipcontrol_addr;
+	uint32	chipcontrol_data;
 	uint32	regcontrol_addr;
 	uint32	regcontrol_data;
 	uint32	pllcontrol_addr;
 	uint32	pllcontrol_data;
-	uint32	pmustrapopt;		
-	uint32	pmu_xtalfreq;		
+	uint32	pmustrapopt;
+	uint32	pmu_xtalfreq;
 	uint32	PAD[100];
 	uint16	sromotp[768];
 } chipcregs_t;
 
-#endif 
+#endif
 
 
 #define	CC_CHIPID		0
@@ -261,58 +261,58 @@
 #define PMU_REG_CONTROL_DATA	0x65C
 #define PMU_PLL_CONTROL_ADDR 	0x660
 #define PMU_PLL_CONTROL_DATA 	0x664
-#define	CC_SROM_OTP		0x800		
+#define	CC_SROM_OTP		0x800
 
 
-#define	CID_ID_MASK		0x0000ffff	
-#define	CID_REV_MASK		0x000f0000	
-#define	CID_REV_SHIFT		16		
-#define	CID_PKG_MASK		0x00f00000	
-#define	CID_PKG_SHIFT		20		
-#define	CID_CC_MASK		0x0f000000	
+#define	CID_ID_MASK		0x0000ffff
+#define	CID_REV_MASK		0x000f0000
+#define	CID_REV_SHIFT		16
+#define	CID_PKG_MASK		0x00f00000
+#define	CID_PKG_SHIFT		20
+#define	CID_CC_MASK		0x0f000000
 #define CID_CC_SHIFT		24
-#define	CID_TYPE_MASK		0xf0000000	
+#define	CID_TYPE_MASK		0xf0000000
 #define CID_TYPE_SHIFT		28
 
 
-#define	CC_CAP_UARTS_MASK	0x00000003	
-#define CC_CAP_MIPSEB		0x00000004	
-#define CC_CAP_UCLKSEL		0x00000018	
-#define CC_CAP_UINTCLK		0x00000008	
-#define CC_CAP_UARTGPIO		0x00000020	
-#define CC_CAP_EXTBUS_MASK	0x000000c0	
-#define CC_CAP_EXTBUS_NONE	0x00000000	
-#define CC_CAP_EXTBUS_FULL	0x00000040	
-#define CC_CAP_EXTBUS_PROG	0x00000080	
-#define	CC_CAP_FLASH_MASK	0x00000700	
-#define	CC_CAP_PLL_MASK		0x00038000	
-#define CC_CAP_PWR_CTL		0x00040000	
-#define CC_CAP_OTPSIZE		0x00380000	
-#define CC_CAP_OTPSIZE_SHIFT	19		
-#define CC_CAP_OTPSIZE_BASE	5		
-#define CC_CAP_JTAGP		0x00400000	
-#define CC_CAP_ROM		0x00800000	
-#define CC_CAP_BKPLN64		0x08000000	
-#define	CC_CAP_PMU		0x10000000	
-#define	CC_CAP_ECI		0x20000000	
-#define	CC_CAP_SROM		0x40000000	
-#define	CC_CAP_NFLASH		0x80000000	
+#define	CC_CAP_UARTS_MASK	0x00000003
+#define CC_CAP_MIPSEB		0x00000004
+#define CC_CAP_UCLKSEL		0x00000018
+#define CC_CAP_UINTCLK		0x00000008
+#define CC_CAP_UARTGPIO		0x00000020
+#define CC_CAP_EXTBUS_MASK	0x000000c0
+#define CC_CAP_EXTBUS_NONE	0x00000000
+#define CC_CAP_EXTBUS_FULL	0x00000040
+#define CC_CAP_EXTBUS_PROG	0x00000080
+#define	CC_CAP_FLASH_MASK	0x00000700
+#define	CC_CAP_PLL_MASK		0x00038000
+#define CC_CAP_PWR_CTL		0x00040000
+#define CC_CAP_OTPSIZE		0x00380000
+#define CC_CAP_OTPSIZE_SHIFT	19
+#define CC_CAP_OTPSIZE_BASE	5
+#define CC_CAP_JTAGP		0x00400000
+#define CC_CAP_ROM		0x00800000
+#define CC_CAP_BKPLN64		0x08000000
+#define	CC_CAP_PMU		0x10000000
+#define	CC_CAP_ECI		0x20000000
+#define	CC_CAP_SROM		0x40000000
+#define	CC_CAP_NFLASH		0x80000000
 
-#define	CC_CAP2_SECI		0x00000001	
-#define	CC_CAP2_GSIO		0x00000002	
+#define	CC_CAP2_SECI		0x00000001
+#define	CC_CAP2_GSIO		0x00000002
 
 
-#define CC_CAP_EXT_SECI_PRESENT   0x00000001    
+#define CC_CAP_EXT_SECI_PRESENT   0x00000001
 
 
 #define PLL_NONE		0x00000000
-#define PLL_TYPE1		0x00010000	
-#define PLL_TYPE2		0x00020000	
-#define PLL_TYPE3		0x00030000	
-#define PLL_TYPE4		0x00008000	
-#define PLL_TYPE5		0x00018000	
-#define PLL_TYPE6		0x00028000	
-#define PLL_TYPE7		0x00038000	
+#define PLL_TYPE1		0x00010000
+#define PLL_TYPE2		0x00020000
+#define PLL_TYPE3		0x00030000
+#define PLL_TYPE4		0x00008000
+#define PLL_TYPE5		0x00018000
+#define PLL_TYPE6		0x00028000
+#define PLL_TYPE7		0x00038000
 
 
 #define	ILP_CLOCK		32000
@@ -324,30 +324,30 @@
 #define	HT_CLOCK		80000000
 
 
-#define CC_UARTCLKO		0x00000001	
-#define	CC_SE			0x00000002	
-#define CC_ASYNCGPIO	0x00000004	
-#define CC_UARTCLKEN		0x00000008	
+#define CC_UARTCLKO		0x00000001
+#define	CC_SE			0x00000002
+#define CC_ASYNCGPIO	0x00000004
+#define CC_UARTCLKEN		0x00000008
 
 
 #define CHIPCTRL_4321A0_DEFAULT	0x3a4
 #define CHIPCTRL_4321A1_DEFAULT	0x0a4
-#define CHIPCTRL_4321_PLL_DOWN	0x800000	
+#define CHIPCTRL_4321_PLL_DOWN	0x800000
 
 
 #define OTPS_OL_MASK		0x000000ff
-#define OTPS_OL_MFG		0x00000001	
-#define OTPS_OL_OR1		0x00000002	
-#define OTPS_OL_OR2		0x00000004	
-#define OTPS_OL_GU		0x00000008	
+#define OTPS_OL_MFG		0x00000001
+#define OTPS_OL_OR1		0x00000002
+#define OTPS_OL_OR2		0x00000004
+#define OTPS_OL_GU		0x00000008
 #define OTPS_GUP_MASK		0x00000f00
 #define OTPS_GUP_SHIFT		8
-#define OTPS_GUP_HW		0x00000100	
-#define OTPS_GUP_SW		0x00000200	
-#define OTPS_GUP_CI		0x00000400	
-#define OTPS_GUP_FUSE		0x00000800	
+#define OTPS_GUP_HW		0x00000100
+#define OTPS_GUP_SW		0x00000200
+#define OTPS_GUP_CI		0x00000400
+#define OTPS_GUP_FUSE		0x00000800
 #define OTPS_READY		0x00001000
-#define OTPS_RV(x)		(1 << (16 + (x)))	
+#define OTPS_RV(x)		(1 << (16 + (x)))
 #define OTPS_RV_MASK		0x0fff0000
 
 
@@ -372,7 +372,7 @@
 #define OTPP_VALUE_MASK		0x20000000
 #define OTPP_VALUE_SHIFT	29
 #define OTPP_START_BUSY		0x80000000
-#define	OTPP_READ		0x40000000	
+#define	OTPP_READ		0x40000000
 
 
 #define OTP_CISFORMAT_NEW	0x80000000
@@ -390,18 +390,18 @@
 
 
 
-#define	JTAGM_CREV_OLD		10	
-#define	JTAGM_CREV_IRP		22	
-#define	JTAGM_CREV_RTI		28	
+#define	JTAGM_CREV_OLD		10
+#define	JTAGM_CREV_IRP		22
+#define	JTAGM_CREV_RTI		28
 
 
 #define JCMD_START		0x80000000
 #define JCMD_BUSY		0x80000000
 #define JCMD_STATE_MASK		0x60000000
-#define JCMD_STATE_TLR		0x00000000	
-#define JCMD_STATE_PIR		0x20000000	
-#define JCMD_STATE_PDR		0x40000000	
-#define JCMD_STATE_RTI		0x60000000	
+#define JCMD_STATE_TLR		0x00000000
+#define JCMD_STATE_PIR		0x20000000
+#define JCMD_STATE_PDR		0x40000000
+#define JCMD_STATE_RTI		0x60000000
 #define JCMD0_ACC_MASK		0x0000f000
 #define JCMD0_ACC_IRDR		0x00000000
 #define JCMD0_ACC_DR		0x00001000
@@ -410,7 +410,7 @@
 #define JCMD0_ACC_IRPDR		0x00004000
 #define JCMD0_ACC_PDR		0x00005000
 #define JCMD0_IRW_MASK		0x00000f00
-#define JCMD_ACC_MASK		0x000f0000	
+#define JCMD_ACC_MASK		0x000f0000
 #define JCMD_ACC_IRDR		0x00000000
 #define JCMD_ACC_DR		0x00010000
 #define JCMD_ACC_IR		0x00020000
@@ -418,16 +418,16 @@
 #define JCMD_ACC_IRPDR		0x00040000
 #define JCMD_ACC_PDR		0x00050000
 #define JCMD_ACC_PIR		0x00060000
-#define JCMD_ACC_IRDR_I		0x00070000	
-#define JCMD_ACC_DR_I		0x00080000	
+#define JCMD_ACC_IRDR_I		0x00070000
+#define JCMD_ACC_DR_I		0x00080000
 #define JCMD_IRW_MASK		0x00001f00
 #define JCMD_IRW_SHIFT		8
 #define JCMD_DRW_MASK		0x0000003f
 
 
-#define JCTRL_FORCE_CLK		4		
-#define JCTRL_EXT_EN		2		
-#define JCTRL_EN		1		
+#define JCTRL_FORCE_CLK		4
+#define JCTRL_EXT_EN		2
+#define JCTRL_EN		1
 
 
 #define	CLKD_SFLASH		0x0f000000
@@ -441,36 +441,36 @@
 #define	CLKD2_SROM		0x00000003
 
 
-#define	CI_GPIO			0x00000001	
-#define	CI_EI			0x00000002	
-#define	CI_TEMP			0x00000004	
-#define	CI_SIRQ			0x00000008	
-#define	CI_ECI			0x00000010	
-#define	CI_PMU			0x00000020	
-#define	CI_UART			0x00000040	
-#define	CI_WDRESET		0x80000000	
+#define	CI_GPIO			0x00000001
+#define	CI_EI			0x00000002
+#define	CI_TEMP			0x00000004
+#define	CI_SIRQ			0x00000008
+#define	CI_ECI			0x00000010
+#define	CI_PMU			0x00000020
+#define	CI_UART			0x00000040
+#define	CI_WDRESET		0x80000000
 
 
-#define SCC_SS_MASK		0x00000007	
-#define	SCC_SS_LPO		0x00000000	
-#define	SCC_SS_XTAL		0x00000001	
-#define	SCC_SS_PCI		0x00000002	
-#define SCC_LF			0x00000200	
-#define SCC_LP			0x00000400	
-#define SCC_FS			0x00000800	
-#define SCC_IP			0x00001000	
-#define SCC_XC			0x00002000	
-#define SCC_XP			0x00004000	
-#define SCC_CD_MASK		0xffff0000	
+#define SCC_SS_MASK		0x00000007
+#define	SCC_SS_LPO		0x00000000
+#define	SCC_SS_XTAL		0x00000001
+#define	SCC_SS_PCI		0x00000002
+#define SCC_LF			0x00000200
+#define SCC_LP			0x00000400
+#define SCC_FS			0x00000800
+#define SCC_IP			0x00001000
+#define SCC_XC			0x00002000
+#define SCC_XP			0x00004000
+#define SCC_CD_MASK		0xffff0000
 #define SCC_CD_SHIFT		16
 
 
-#define	SYCC_IE			0x00000001	
-#define	SYCC_AE			0x00000002	
-#define	SYCC_FP			0x00000004	
-#define	SYCC_AR			0x00000008	
-#define	SYCC_HR			0x00000010	
-#define SYCC_CD_MASK		0xffff0000	
+#define	SYCC_IE			0x00000001
+#define	SYCC_AE			0x00000002
+#define	SYCC_FP			0x00000004
+#define	SYCC_AR			0x00000008
+#define	SYCC_HR			0x00000010
+#define SYCC_CD_MASK		0xffff0000
 #define SYCC_CD_SHIFT		16
 
 
@@ -485,56 +485,56 @@
 #define	BPIA_ERROR		0x00000400
 
 
-#define	CF_EN			0x00000001	
-#define	CF_EM_MASK		0x0000000e	
+#define	CF_EN			0x00000001
+#define	CF_EM_MASK		0x0000000e
 #define	CF_EM_SHIFT		1
-#define	CF_EM_FLASH		0		
-#define	CF_EM_SYNC		2		
-#define	CF_EM_PCMCIA		4		
-#define	CF_DS			0x00000010	
-#define	CF_BS			0x00000020	
-#define	CF_CD_MASK		0x000000c0	
+#define	CF_EM_FLASH		0
+#define	CF_EM_SYNC		2
+#define	CF_EM_PCMCIA		4
+#define	CF_DS			0x00000010
+#define	CF_BS			0x00000020
+#define	CF_CD_MASK		0x000000c0
 #define	CF_CD_SHIFT		6
-#define	CF_CD_DIV2		0x00000000	
-#define	CF_CD_DIV3		0x00000040	
-#define	CF_CD_DIV4		0x00000080	
-#define	CF_CE			0x00000100	
-#define	CF_SB			0x00000200	
+#define	CF_CD_DIV2		0x00000000
+#define	CF_CD_DIV3		0x00000040
+#define	CF_CD_DIV4		0x00000080
+#define	CF_CE			0x00000100
+#define	CF_SB			0x00000200
 
 
-#define	PM_W0_MASK		0x0000003f	
-#define	PM_W1_MASK		0x00001f00	
+#define	PM_W0_MASK		0x0000003f
+#define	PM_W1_MASK		0x00001f00
 #define	PM_W1_SHIFT		8
-#define	PM_W2_MASK		0x001f0000	
+#define	PM_W2_MASK		0x001f0000
 #define	PM_W2_SHIFT		16
-#define	PM_W3_MASK		0x1f000000	
+#define	PM_W3_MASK		0x1f000000
 #define	PM_W3_SHIFT		24
 
 
-#define	PA_W0_MASK		0x0000003f	
-#define	PA_W1_MASK		0x00001f00	
+#define	PA_W0_MASK		0x0000003f
+#define	PA_W1_MASK		0x00001f00
 #define	PA_W1_SHIFT		8
-#define	PA_W2_MASK		0x001f0000	
+#define	PA_W2_MASK		0x001f0000
 #define	PA_W2_SHIFT		16
-#define	PA_W3_MASK		0x1f000000	
+#define	PA_W3_MASK		0x1f000000
 #define	PA_W3_SHIFT		24
 
 
-#define	PI_W0_MASK		0x0000003f	
-#define	PI_W1_MASK		0x00001f00	
+#define	PI_W0_MASK		0x0000003f
+#define	PI_W1_MASK		0x00001f00
 #define	PI_W1_SHIFT		8
-#define	PI_W2_MASK		0x001f0000	
+#define	PI_W2_MASK		0x001f0000
 #define	PI_W2_SHIFT		16
-#define	PI_W3_MASK		0x1f000000	
+#define	PI_W3_MASK		0x1f000000
 #define	PI_W3_SHIFT		24
 
 
-#define	PW_W0_MASK		0x0000001f	
-#define	PW_W1_MASK		0x00001f00	
+#define	PW_W0_MASK		0x0000001f
+#define	PW_W1_MASK		0x00001f00
 #define	PW_W1_SHIFT		8
-#define	PW_W2_MASK		0x001f0000	
+#define	PW_W2_MASK		0x001f0000
 #define	PW_W2_SHIFT		16
-#define	PW_W3_MASK		0x1f000000	
+#define	PW_W3_MASK		0x1f000000
 #define	PW_W3_SHIFT		24
 
 #define PW_W0       		0x0000000c
@@ -543,12 +543,12 @@
 #define PW_W3       		0x01000000
 
 
-#define	FW_W0_MASK		0x0000003f	
-#define	FW_W1_MASK		0x00001f00	
+#define	FW_W0_MASK		0x0000003f
+#define	FW_W1_MASK		0x00001f00
 #define	FW_W1_SHIFT		8
-#define	FW_W2_MASK		0x001f0000	
+#define	FW_W2_MASK		0x001f0000
 #define	FW_W2_SHIFT		16
-#define	FW_W3_MASK		0x1f000000	
+#define	FW_W3_MASK		0x1f000000
 #define	FW_W3_SHIFT		24
 
 
@@ -571,8 +571,8 @@
 
 #define	PCTL_ILP_DIV_MASK	0xffff0000
 #define	PCTL_ILP_DIV_SHIFT	16
-#define PCTL_PLL_PLLCTL_UPD	0x00000400	
-#define PCTL_NOILP_ON_WAIT	0x00000200	
+#define PCTL_PLL_PLLCTL_UPD	0x00000400
+#define PCTL_NOILP_ON_WAIT	0x00000200
 #define	PCTL_HT_REQ_EN		0x00000100
 #define	PCTL_ALP_REQ_EN		0x00000080
 #define	PCTL_XTALFREQ_MASK	0x0000007c
@@ -588,30 +588,30 @@
 #define GPIO_ONTIME_SHIFT	16
 
 
-#define	CN_N1_MASK		0x3f		
-#define	CN_N2_MASK		0x3f00		
+#define	CN_N1_MASK		0x3f
+#define	CN_N2_MASK		0x3f00
 #define	CN_N2_SHIFT		8
-#define	CN_PLLC_MASK		0xf0000		
+#define	CN_PLLC_MASK		0xf0000
 #define	CN_PLLC_SHIFT		16
 
 
-#define	CC_M1_MASK		0x3f		
-#define	CC_M2_MASK		0x3f00		
+#define	CC_M1_MASK		0x3f
+#define	CC_M2_MASK		0x3f00
 #define	CC_M2_SHIFT		8
-#define	CC_M3_MASK		0x3f0000	
+#define	CC_M3_MASK		0x3f0000
 #define	CC_M3_SHIFT		16
-#define	CC_MC_MASK		0x1f000000	
+#define	CC_MC_MASK		0x1f000000
 #define	CC_MC_SHIFT		24
 
 
-#define	CC_F6_2			0x02		
-#define	CC_F6_3			0x03		
-#define	CC_F6_4			0x05		
+#define	CC_F6_2			0x02
+#define	CC_F6_3			0x03
+#define	CC_F6_4			0x05
 #define	CC_F6_5			0x09
 #define	CC_F6_6			0x11
 #define	CC_F6_7			0x21
 
-#define	CC_F5_BIAS		5		
+#define	CC_F5_BIAS		5
 
 #define	CC_MC_BYPASS		0x08
 #define	CC_MC_M1		0x04
@@ -620,94 +620,94 @@
 #define	CC_MC_M1M3		0x11
 
 
-#define	CC_T2_BIAS		2		
-#define	CC_T2M2_BIAS		3		
+#define	CC_T2_BIAS		2
+#define	CC_T2M2_BIAS		3
 
 #define	CC_T2MC_M1BYP		1
 #define	CC_T2MC_M2BYP		2
 #define	CC_T2MC_M3BYP		4
 
 
-#define	CC_T6_MMASK		1		
-#define	CC_T6_M0		120000000	
-#define	CC_T6_M1		100000000	
+#define	CC_T6_MMASK		1
+#define	CC_T6_M0		120000000
+#define	CC_T6_M1		100000000
 #define	SB2MIPS_T6(sb)		(2 * (sb))
 
 
-#define	CC_CLOCK_BASE1		24000000	
-#define CC_CLOCK_BASE2		12500000	
+#define	CC_CLOCK_BASE1		24000000
+#define CC_CLOCK_BASE2		12500000
 
 
 #define	CLKC_5350_N		0x0311
 #define	CLKC_5350_M		0x04020009
 
 
-#define FLASH_NONE		0x000		
-#define SFLASH_ST		0x100		
-#define SFLASH_AT		0x200		
-#define	PFLASH			0x700		
+#define FLASH_NONE		0x000
+#define SFLASH_ST		0x100
+#define SFLASH_AT		0x200
+#define	PFLASH			0x700
 
 
-#define	CC_CFG_EN		0x0001		
-#define	CC_CFG_EM_MASK		0x000e		
-#define	CC_CFG_EM_ASYNC		0x0000		
-#define	CC_CFG_EM_SYNC		0x0002		
-#define	CC_CFG_EM_PCMCIA	0x0004		
-#define	CC_CFG_EM_IDE		0x0006		
-#define	CC_CFG_DS		0x0010		
-#define	CC_CFG_CD_MASK		0x00e0		
-#define	CC_CFG_CE		0x0100		
-#define	CC_CFG_SB		0x0200		
-#define	CC_CFG_IS		0x0400		
+#define	CC_CFG_EN		0x0001
+#define	CC_CFG_EM_MASK		0x000e
+#define	CC_CFG_EM_ASYNC		0x0000
+#define	CC_CFG_EM_SYNC		0x0002
+#define	CC_CFG_EM_PCMCIA	0x0004
+#define	CC_CFG_EM_IDE		0x0006
+#define	CC_CFG_DS		0x0010
+#define	CC_CFG_CD_MASK		0x00e0
+#define	CC_CFG_CE		0x0100
+#define	CC_CFG_SB		0x0200
+#define	CC_CFG_IS		0x0400
 
 
-#define	CC_EB_BASE		0x1a000000	
-#define	CC_EB_PCMCIA_MEM	0x1a000000	
-#define	CC_EB_PCMCIA_IO		0x1a200000	
-#define	CC_EB_PCMCIA_CFG	0x1a400000	
-#define	CC_EB_IDE		0x1a800000	
-#define	CC_EB_PCMCIA1_MEM	0x1a800000	
-#define	CC_EB_PCMCIA1_IO	0x1aa00000	
-#define	CC_EB_PCMCIA1_CFG	0x1ac00000	
-#define	CC_EB_PROGIF		0x1b000000	
+#define	CC_EB_BASE		0x1a000000
+#define	CC_EB_PCMCIA_MEM	0x1a000000
+#define	CC_EB_PCMCIA_IO		0x1a200000
+#define	CC_EB_PCMCIA_CFG	0x1a400000
+#define	CC_EB_IDE		0x1a800000
+#define	CC_EB_PCMCIA1_MEM	0x1a800000
+#define	CC_EB_PCMCIA1_IO	0x1aa00000
+#define	CC_EB_PCMCIA1_CFG	0x1ac00000
+#define	CC_EB_PROGIF		0x1b000000
 
 
 
 #define SFLASH_OPCODE		0x000000ff
 #define SFLASH_ACTION		0x00000700
-#define	SFLASH_CS_ACTIVE	0x00001000	
+#define	SFLASH_CS_ACTIVE	0x00001000
 #define SFLASH_START		0x80000000
 #define SFLASH_BUSY		SFLASH_START
 
 
-#define	SFLASH_ACT_OPONLY	0x0000		
-#define	SFLASH_ACT_OP1D		0x0100		
-#define	SFLASH_ACT_OP3A		0x0200		
-#define	SFLASH_ACT_OP3A1D	0x0300		
-#define	SFLASH_ACT_OP3A4D	0x0400		
-#define	SFLASH_ACT_OP3A4X4D	0x0500		
-#define	SFLASH_ACT_OP3A1X4D	0x0700		
+#define	SFLASH_ACT_OPONLY	0x0000
+#define	SFLASH_ACT_OP1D		0x0100
+#define	SFLASH_ACT_OP3A		0x0200
+#define	SFLASH_ACT_OP3A1D	0x0300
+#define	SFLASH_ACT_OP3A4D	0x0400
+#define	SFLASH_ACT_OP3A4X4D	0x0500
+#define	SFLASH_ACT_OP3A1X4D	0x0700
 
 
-#define SFLASH_ST_WREN		0x0006		
-#define SFLASH_ST_WRDIS		0x0004		
-#define SFLASH_ST_RDSR		0x0105		
-#define SFLASH_ST_WRSR		0x0101		
-#define SFLASH_ST_READ		0x0303		
-#define SFLASH_ST_PP		0x0302		
-#define SFLASH_ST_SE		0x02d8		
-#define SFLASH_ST_BE		0x00c7		
-#define SFLASH_ST_DP		0x00b9		
-#define SFLASH_ST_RES		0x03ab		
-#define SFLASH_ST_CSA		0x1000		
-#define SFLASH_ST_SSE		0x0220		
+#define SFLASH_ST_WREN		0x0006
+#define SFLASH_ST_WRDIS		0x0004
+#define SFLASH_ST_RDSR		0x0105
+#define SFLASH_ST_WRSR		0x0101
+#define SFLASH_ST_READ		0x0303
+#define SFLASH_ST_PP		0x0302
+#define SFLASH_ST_SE		0x02d8
+#define SFLASH_ST_BE		0x00c7
+#define SFLASH_ST_DP		0x00b9
+#define SFLASH_ST_RES		0x03ab
+#define SFLASH_ST_CSA		0x1000
+#define SFLASH_ST_SSE		0x0220
 
 
-#define SFLASH_ST_WIP		0x01		
-#define SFLASH_ST_WEL		0x02		
-#define SFLASH_ST_BP_MASK	0x1c		
+#define SFLASH_ST_WIP		0x01
+#define SFLASH_ST_WEL		0x02
+#define SFLASH_ST_BP_MASK	0x1c
 #define SFLASH_ST_BP_SHIFT	2
-#define SFLASH_ST_SRWD		0x80		
+#define SFLASH_ST_SRWD		0x80
 
 
 #define SFLASH_AT_READ				0x07e8
@@ -744,47 +744,47 @@
 
 
 
-#define UART_RX		0	
-#define UART_TX		0	
-#define UART_DLL	0	
-#define UART_IER	1	
-#define UART_DLM	1	
-#define UART_IIR	2	
-#define UART_FCR	2	
-#define UART_LCR	3	
-#define UART_MCR	4	
-#define UART_LSR	5	
-#define UART_MSR	6	
-#define UART_SCR	7	
-#define UART_LCR_DLAB	0x80	
-#define UART_LCR_WLEN8	0x03	
-#define UART_MCR_OUT2	0x08	
-#define UART_MCR_LOOP	0x10	
-#define UART_LSR_RX_FIFO 	0x80	
-#define UART_LSR_TDHR		0x40	
-#define UART_LSR_THRE		0x20	
-#define UART_LSR_BREAK		0x10	
-#define UART_LSR_FRAMING	0x08	
-#define UART_LSR_PARITY		0x04	
-#define UART_LSR_OVERRUN	0x02	
-#define UART_LSR_RXRDY		0x01	
-#define UART_FCR_FIFO_ENABLE 1	
+#define UART_RX		0
+#define UART_TX		0
+#define UART_DLL	0
+#define UART_IER	1
+#define UART_DLM	1
+#define UART_IIR	2
+#define UART_FCR	2
+#define UART_LCR	3
+#define UART_MCR	4
+#define UART_LSR	5
+#define UART_MSR	6
+#define UART_SCR	7
+#define UART_LCR_DLAB	0x80
+#define UART_LCR_WLEN8	0x03
+#define UART_MCR_OUT2	0x08
+#define UART_MCR_LOOP	0x10
+#define UART_LSR_RX_FIFO 	0x80
+#define UART_LSR_TDHR		0x40
+#define UART_LSR_THRE		0x20
+#define UART_LSR_BREAK		0x10
+#define UART_LSR_FRAMING	0x08
+#define UART_LSR_PARITY		0x04
+#define UART_LSR_OVERRUN	0x02
+#define UART_LSR_RXRDY		0x01
+#define UART_FCR_FIFO_ENABLE 1
 
 
-#define UART_IIR_FIFO_MASK	0xc0	
-#define UART_IIR_INT_MASK	0xf	
-#define UART_IIR_MDM_CHG	0x0	
-#define UART_IIR_NOINT		0x1	
-#define UART_IIR_THRE		0x2	
-#define UART_IIR_RCVD_DATA	0x4	
-#define UART_IIR_RCVR_STATUS 	0x6	
-#define UART_IIR_CHAR_TIME 	0xc	
+#define UART_IIR_FIFO_MASK	0xc0
+#define UART_IIR_INT_MASK	0xf
+#define UART_IIR_MDM_CHG	0x0
+#define UART_IIR_NOINT		0x1
+#define UART_IIR_THRE		0x2
+#define UART_IIR_RCVD_DATA	0x4
+#define UART_IIR_RCVR_STATUS 	0x6
+#define UART_IIR_CHAR_TIME 	0xc
 
 
-#define UART_IER_EDSSI	8	
-#define UART_IER_ELSI	4	
-#define UART_IER_ETBEI  2	
-#define UART_IER_ERBFI	1	
+#define UART_IER_EDSSI	8
+#define UART_IER_ELSI	4
+#define UART_IER_ETBEI  2
+#define UART_IER_ERBFI	1
 
 
 #define PST_EXTLPOAVAIL	0x0100
@@ -810,7 +810,7 @@
 #define PCAP_VC_SHIFT	21
 #define PCAP_CC_MASK	0x1e000000
 #define PCAP_CC_SHIFT	25
-#define PCAP5_PC_MASK	0x003e0000	
+#define PCAP5_PC_MASK	0x003e0000
 #define PCAP5_PC_SHIFT	17
 #define PCAP5_VC_MASK	0x07c00000
 #define PCAP5_VC_SHIFT	22
@@ -871,7 +871,7 @@
 #define PMU0_PLL0_PC0_DIV_ARM_110MHZ	0
 #define PMU0_PLL0_PC0_DIV_ARM_97_7MHZ	1
 #define PMU0_PLL0_PC0_DIV_ARM_88MHZ	2
-#define PMU0_PLL0_PC0_DIV_ARM_80MHZ	3 
+#define PMU0_PLL0_PC0_DIV_ARM_80MHZ	3
 #define PMU0_PLL0_PC0_DIV_ARM_73_3MHZ	4
 #define PMU0_PLL0_PC0_DIV_ARM_67_7MHZ	5
 #define PMU0_PLL0_PC0_DIV_ARM_62_9MHZ	6
@@ -930,7 +930,7 @@
 #define PMU1_PLL0_PC2_NDIV_MODE_MASK	0x000e0000
 #define PMU1_PLL0_PC2_NDIV_MODE_SHIFT	17
 #define PMU1_PLL0_PC2_NDIV_MODE_MASH	1
-#define PMU1_PLL0_PC2_NDIV_MODE_MFB	2	
+#define PMU1_PLL0_PC2_NDIV_MODE_MFB	2
 #define PMU1_PLL0_PC2_NDIV_INT_MASK	0x1ff00000
 #define PMU1_PLL0_PC2_NDIV_INT_SHIFT	20
 
@@ -1071,163 +1071,163 @@
 #define RES4716_PROC_HT_AVAIL		0x00000080
 
 
-#define CCTRL_471X_I2S_PINS_ENABLE	0x0080 
+#define CCTRL_471X_I2S_PINS_ENABLE	0x0080
 
 
 
-#define CCTRL_5357_I2S_PINS_ENABLE	0x00040000 
-#define CCTRL_5357_I2CSPI_PINS_ENABLE	0x00080000 
+#define CCTRL_5357_I2S_PINS_ENABLE	0x00040000
+#define CCTRL_5357_I2CSPI_PINS_ENABLE	0x00080000
 
 
-#define RES5354_EXT_SWITCHER_PWM	0	
-#define RES5354_BB_SWITCHER_PWM		1	
-#define RES5354_BB_SWITCHER_BURST	2	
-#define RES5354_BB_EXT_SWITCHER_BURST	3	
-#define RES5354_ILP_REQUEST		4	
-#define RES5354_RADIO_SWITCHER_PWM	5	
-#define RES5354_RADIO_SWITCHER_BURST	6	
-#define RES5354_ROM_SWITCH		7	
-#define RES5354_PA_REF_LDO		8	
-#define RES5354_RADIO_LDO		9	
-#define RES5354_AFE_LDO			10	
-#define RES5354_PLL_LDO			11	
-#define RES5354_BG_FILTBYP		12	
-#define RES5354_TX_FILTBYP		13	
-#define RES5354_RX_FILTBYP		14	
-#define RES5354_XTAL_PU			15	
-#define RES5354_XTAL_EN			16	
-#define RES5354_BB_PLL_FILTBYP		17	
-#define RES5354_RF_PLL_FILTBYP		18	
-#define RES5354_BB_PLL_PU		19	
+#define RES5354_EXT_SWITCHER_PWM	0
+#define RES5354_BB_SWITCHER_PWM		1
+#define RES5354_BB_SWITCHER_BURST	2
+#define RES5354_BB_EXT_SWITCHER_BURST	3
+#define RES5354_ILP_REQUEST		4
+#define RES5354_RADIO_SWITCHER_PWM	5
+#define RES5354_RADIO_SWITCHER_BURST	6
+#define RES5354_ROM_SWITCH		7
+#define RES5354_PA_REF_LDO		8
+#define RES5354_RADIO_LDO		9
+#define RES5354_AFE_LDO			10
+#define RES5354_PLL_LDO			11
+#define RES5354_BG_FILTBYP		12
+#define RES5354_TX_FILTBYP		13
+#define RES5354_RX_FILTBYP		14
+#define RES5354_XTAL_PU			15
+#define RES5354_XTAL_EN			16
+#define RES5354_BB_PLL_FILTBYP		17
+#define RES5354_RF_PLL_FILTBYP		18
+#define RES5354_BB_PLL_PU		19
 
 
-#define CCTRL5357_EXTPA                 (1<<14)  
-#define CCTRL5357_ANT_MUX_2o3		(1<<15)  
+#define CCTRL5357_EXTPA                 (1<<14)
+#define CCTRL5357_ANT_MUX_2o3		(1<<15)
 
 
-#define RES4328_EXT_SWITCHER_PWM	0	
-#define RES4328_BB_SWITCHER_PWM		1	
-#define RES4328_BB_SWITCHER_BURST	2	
-#define RES4328_BB_EXT_SWITCHER_BURST	3	
-#define RES4328_ILP_REQUEST		4	
-#define RES4328_RADIO_SWITCHER_PWM	5	
-#define RES4328_RADIO_SWITCHER_BURST	6	
-#define RES4328_ROM_SWITCH		7	
-#define RES4328_PA_REF_LDO		8	
-#define RES4328_RADIO_LDO		9	
-#define RES4328_AFE_LDO			10	
-#define RES4328_PLL_LDO			11	
-#define RES4328_BG_FILTBYP		12	
-#define RES4328_TX_FILTBYP		13	
-#define RES4328_RX_FILTBYP		14	
-#define RES4328_XTAL_PU			15	
-#define RES4328_XTAL_EN			16	
-#define RES4328_BB_PLL_FILTBYP		17	
-#define RES4328_RF_PLL_FILTBYP		18	
-#define RES4328_BB_PLL_PU		19	
+#define RES4328_EXT_SWITCHER_PWM	0
+#define RES4328_BB_SWITCHER_PWM		1
+#define RES4328_BB_SWITCHER_BURST	2
+#define RES4328_BB_EXT_SWITCHER_BURST	3
+#define RES4328_ILP_REQUEST		4
+#define RES4328_RADIO_SWITCHER_PWM	5
+#define RES4328_RADIO_SWITCHER_BURST	6
+#define RES4328_ROM_SWITCH		7
+#define RES4328_PA_REF_LDO		8
+#define RES4328_RADIO_LDO		9
+#define RES4328_AFE_LDO			10
+#define RES4328_PLL_LDO			11
+#define RES4328_BG_FILTBYP		12
+#define RES4328_TX_FILTBYP		13
+#define RES4328_RX_FILTBYP		14
+#define RES4328_XTAL_PU			15
+#define RES4328_XTAL_EN			16
+#define RES4328_BB_PLL_FILTBYP		17
+#define RES4328_RF_PLL_FILTBYP		18
+#define RES4328_BB_PLL_PU		19
 
 
-#define RES4325_BUCK_BOOST_BURST	0	
-#define RES4325_CBUCK_BURST		1	
-#define RES4325_CBUCK_PWM		2	
-#define RES4325_CLDO_CBUCK_BURST	3	
-#define RES4325_CLDO_CBUCK_PWM		4	
-#define RES4325_BUCK_BOOST_PWM		5	
-#define RES4325_ILP_REQUEST		6	
-#define RES4325_ABUCK_BURST		7	
-#define RES4325_ABUCK_PWM		8	
-#define RES4325_LNLDO1_PU		9	
-#define RES4325_OTP_PU			10	
-#define RES4325_LNLDO3_PU		11	
-#define RES4325_LNLDO4_PU		12	
-#define RES4325_XTAL_PU			13	
-#define RES4325_ALP_AVAIL		14	
-#define RES4325_RX_PWRSW_PU		15	
-#define RES4325_TX_PWRSW_PU		16	
-#define RES4325_RFPLL_PWRSW_PU		17	
-#define RES4325_LOGEN_PWRSW_PU		18	
-#define RES4325_AFE_PWRSW_PU		19	
-#define RES4325_BBPLL_PWRSW_PU		20	
-#define RES4325_HT_AVAIL		21	
+#define RES4325_BUCK_BOOST_BURST	0
+#define RES4325_CBUCK_BURST		1
+#define RES4325_CBUCK_PWM		2
+#define RES4325_CLDO_CBUCK_BURST	3
+#define RES4325_CLDO_CBUCK_PWM		4
+#define RES4325_BUCK_BOOST_PWM		5
+#define RES4325_ILP_REQUEST		6
+#define RES4325_ABUCK_BURST		7
+#define RES4325_ABUCK_PWM		8
+#define RES4325_LNLDO1_PU		9
+#define RES4325_OTP_PU			10
+#define RES4325_LNLDO3_PU		11
+#define RES4325_LNLDO4_PU		12
+#define RES4325_XTAL_PU			13
+#define RES4325_ALP_AVAIL		14
+#define RES4325_RX_PWRSW_PU		15
+#define RES4325_TX_PWRSW_PU		16
+#define RES4325_RFPLL_PWRSW_PU		17
+#define RES4325_LOGEN_PWRSW_PU		18
+#define RES4325_AFE_PWRSW_PU		19
+#define RES4325_BBPLL_PWRSW_PU		20
+#define RES4325_HT_AVAIL		21
 
 
-#define RES4325B0_CBUCK_LPOM		1	
-#define RES4325B0_CBUCK_BURST		2	
-#define RES4325B0_CBUCK_PWM		3	
-#define RES4325B0_CLDO_PU		4	
+#define RES4325B0_CBUCK_LPOM		1
+#define RES4325B0_CBUCK_BURST		2
+#define RES4325B0_CBUCK_PWM		3
+#define RES4325B0_CLDO_PU		4
 
 
-#define RES4325C1_LNLDO2_PU		12	
+#define RES4325C1_LNLDO2_PU		12
 
 
 #define CST4325_SPROM_OTP_SEL_MASK	0x00000003
-#define CST4325_DEFCIS_SEL		0	
-#define CST4325_SPROM_SEL		1	
-#define CST4325_OTP_SEL			2	
-#define CST4325_OTP_PWRDN		3	
+#define CST4325_DEFCIS_SEL		0
+#define CST4325_SPROM_SEL		1
+#define CST4325_OTP_SEL			2
+#define CST4325_OTP_PWRDN		3
 #define CST4325_SDIO_USB_MODE_MASK	0x00000004
 #define CST4325_SDIO_USB_MODE_SHIFT	2
 #define CST4325_RCAL_VALID_MASK		0x00000008
 #define CST4325_RCAL_VALID_SHIFT	3
 #define CST4325_RCAL_VALUE_MASK		0x000001f0
 #define CST4325_RCAL_VALUE_SHIFT	4
-#define CST4325_PMUTOP_2B_MASK 		0x00000200	
+#define CST4325_PMUTOP_2B_MASK 		0x00000200
 #define CST4325_PMUTOP_2B_SHIFT   	9
 
-#define RES4329_RESERVED0		0	
-#define RES4329_CBUCK_LPOM		1	
-#define RES4329_CBUCK_BURST		2	
-#define RES4329_CBUCK_PWM		3	
-#define RES4329_CLDO_PU			4	
-#define RES4329_PALDO_PU		5	
-#define RES4329_ILP_REQUEST		6	
-#define RES4329_RESERVED7		7	
-#define RES4329_RESERVED8		8	
-#define RES4329_LNLDO1_PU		9	
-#define RES4329_OTP_PU			10	
-#define RES4329_RESERVED11		11	
-#define RES4329_LNLDO2_PU		12	
-#define RES4329_XTAL_PU			13	
-#define RES4329_ALP_AVAIL		14	
-#define RES4329_RX_PWRSW_PU		15	
-#define RES4329_TX_PWRSW_PU		16	
-#define RES4329_RFPLL_PWRSW_PU		17	
-#define RES4329_LOGEN_PWRSW_PU		18	
-#define RES4329_AFE_PWRSW_PU		19	
-#define RES4329_BBPLL_PWRSW_PU		20	
-#define RES4329_HT_AVAIL		21	
+#define RES4329_RESERVED0		0
+#define RES4329_CBUCK_LPOM		1
+#define RES4329_CBUCK_BURST		2
+#define RES4329_CBUCK_PWM		3
+#define RES4329_CLDO_PU			4
+#define RES4329_PALDO_PU		5
+#define RES4329_ILP_REQUEST		6
+#define RES4329_RESERVED7		7
+#define RES4329_RESERVED8		8
+#define RES4329_LNLDO1_PU		9
+#define RES4329_OTP_PU			10
+#define RES4329_RESERVED11		11
+#define RES4329_LNLDO2_PU		12
+#define RES4329_XTAL_PU			13
+#define RES4329_ALP_AVAIL		14
+#define RES4329_RX_PWRSW_PU		15
+#define RES4329_TX_PWRSW_PU		16
+#define RES4329_RFPLL_PWRSW_PU		17
+#define RES4329_LOGEN_PWRSW_PU		18
+#define RES4329_AFE_PWRSW_PU		19
+#define RES4329_BBPLL_PWRSW_PU		20
+#define RES4329_HT_AVAIL		21
 
 #define CST4329_SPROM_OTP_SEL_MASK	0x00000003
-#define CST4329_DEFCIS_SEL		0	
-#define CST4329_SPROM_SEL		1	
-#define CST4329_OTP_SEL			2	
-#define CST4329_OTP_PWRDN		3	
+#define CST4329_DEFCIS_SEL		0
+#define CST4329_SPROM_SEL		1
+#define CST4329_OTP_SEL			2
+#define CST4329_OTP_PWRDN		3
 #define CST4329_SPI_SDIO_MODE_MASK	0x00000004
 #define CST4329_SPI_SDIO_MODE_SHIFT	2
 
 
 #define CST4312_SPROM_OTP_SEL_MASK	0x00000003
-#define CST4312_DEFCIS_SEL		0	
-#define CST4312_SPROM_SEL		1	
-#define CST4312_OTP_SEL			2	
-#define CST4312_OTP_BAD			3	
+#define CST4312_DEFCIS_SEL		0
+#define CST4312_SPROM_SEL		1
+#define CST4312_OTP_SEL			2
+#define CST4312_OTP_BAD			3
 
 
-#define RES4312_SWITCHER_BURST		0	
-#define RES4312_SWITCHER_PWM    	1	
-#define RES4312_PA_REF_LDO		2	
-#define RES4312_CORE_LDO_BURST		3	
-#define RES4312_CORE_LDO_PWM		4	
-#define RES4312_RADIO_LDO		5	
-#define RES4312_ILP_REQUEST		6	
-#define RES4312_BG_FILTBYP		7	
-#define RES4312_TX_FILTBYP		8	
-#define RES4312_RX_FILTBYP		9	
-#define RES4312_XTAL_PU			10	
-#define RES4312_ALP_AVAIL		11	
-#define RES4312_BB_PLL_FILTBYP		12	
-#define RES4312_RF_PLL_FILTBYP		13	
-#define RES4312_HT_AVAIL		14	
+#define RES4312_SWITCHER_BURST		0
+#define RES4312_SWITCHER_PWM    	1
+#define RES4312_PA_REF_LDO		2
+#define RES4312_CORE_LDO_BURST		3
+#define RES4312_CORE_LDO_PWM		4
+#define RES4312_RADIO_LDO		5
+#define RES4312_ILP_REQUEST		6
+#define RES4312_BG_FILTBYP		7
+#define RES4312_TX_FILTBYP		8
+#define RES4312_RX_FILTBYP		9
+#define RES4312_XTAL_PU			10
+#define RES4312_ALP_AVAIL		11
+#define RES4312_BB_PLL_FILTBYP		12
+#define RES4312_RF_PLL_FILTBYP		13
+#define RES4312_HT_AVAIL		14
 
 
 #define RES4322_RF_LDO			0
@@ -1244,36 +1244,36 @@
 #define CST4322_XTAL_FREQ_20_40MHZ	0x00000020
 #define CST4322_SPROM_OTP_SEL_MASK	0x000000c0
 #define CST4322_SPROM_OTP_SEL_SHIFT	6
-#define CST4322_NO_SPROM_OTP		0	
-#define CST4322_SPROM_PRESENT		1	
-#define CST4322_OTP_PRESENT		2	
+#define CST4322_NO_SPROM_OTP		0
+#define CST4322_SPROM_PRESENT		1
+#define CST4322_OTP_PRESENT		2
 #define CST4322_PCI_OR_USB		0x00000100
 #define CST4322_BOOT_MASK		0x00000600
 #define CST4322_BOOT_SHIFT		9
-#define CST4322_BOOT_FROM_SRAM		0	
-#define CST4322_BOOT_FROM_ROM		1	
-#define CST4322_BOOT_FROM_FLASH		2	
+#define CST4322_BOOT_FROM_SRAM		0
+#define CST4322_BOOT_FROM_ROM		1
+#define CST4322_BOOT_FROM_FLASH		2
 #define CST4322_BOOT_FROM_INVALID	3
 #define CST4322_ILP_DIV_EN		0x00000800
 #define CST4322_FLASH_TYPE_MASK		0x00001000
 #define CST4322_FLASH_TYPE_SHIFT	12
-#define CST4322_FLASH_TYPE_SHIFT_ST	0	
-#define CST4322_FLASH_TYPE_SHIFT_ATMEL	1	
+#define CST4322_FLASH_TYPE_SHIFT_ST	0
+#define CST4322_FLASH_TYPE_SHIFT_ATMEL	1
 #define CST4322_ARM_TAP_SEL		0x00002000
 #define CST4322_RES_INIT_MODE_MASK	0x0000c000
 #define CST4322_RES_INIT_MODE_SHIFT	14
-#define CST4322_RES_INIT_MODE_ILPAVAIL	0	
-#define CST4322_RES_INIT_MODE_ILPREQ	1	
-#define CST4322_RES_INIT_MODE_ALPAVAIL	2	
-#define CST4322_RES_INIT_MODE_HTAVAIL	3	
+#define CST4322_RES_INIT_MODE_ILPAVAIL	0
+#define CST4322_RES_INIT_MODE_ILPREQ	1
+#define CST4322_RES_INIT_MODE_ALPAVAIL	2
+#define CST4322_RES_INIT_MODE_HTAVAIL	3
 #define CST4322_PCIPLLCLK_GATING	0x00010000
 #define CST4322_CLK_SWITCH_PCI_TO_ALP	0x00020000
 #define CST4322_PCI_CARDBUS_MODE	0x00040000
 
 
-#define CCTRL43224_GPIO_TOGGLE          0x8000 
-#define CCTRL_43224A0_12MA_LED_DRIVE    0x00F000F0 
-#define CCTRL_43224B0_12MA_LED_DRIVE    0xF0    
+#define CCTRL43224_GPIO_TOGGLE          0x8000
+#define CCTRL_43224A0_12MA_LED_DRIVE    0x00F000F0
+#define CCTRL_43224B0_12MA_LED_DRIVE    0xF0
 
 
 #define RES43236_REGULATOR		0
@@ -1284,23 +1284,23 @@
 #define RES43236_HT_SI_AVAIL		5
 
 
-#define CCTRL43236_BT_COEXIST		(1<<0)	
-#define CCTRL43236_SECI			(1<<1)	
-#define CCTRL43236_EXT_LNA		(1<<2)	
-#define CCTRL43236_ANT_MUX_2o3          (1<<3)	
-#define CCTRL43236_GSIO			(1<<4)	
+#define CCTRL43236_BT_COEXIST		(1<<0)
+#define CCTRL43236_SECI			(1<<1)
+#define CCTRL43236_EXT_LNA		(1<<2)
+#define CCTRL43236_ANT_MUX_2o3          (1<<3)
+#define CCTRL43236_GSIO			(1<<4)
 
 
 #define CST43236_SFLASH_MASK		0x00000040
 #define CST43236_OTP_SEL_MASK		0x00000080
 #define CST43236_OTP_SEL_SHIFT		7
-#define CST43236_HSIC_MASK		0x00000100	
-#define CST43236_BP_CLK			0x00000200	
+#define CST43236_HSIC_MASK		0x00000100
+#define CST43236_BP_CLK			0x00000200
 #define CST43236_BOOT_MASK		0x00001800
 #define CST43236_BOOT_SHIFT		11
-#define CST43236_BOOT_FROM_SRAM		0	
-#define CST43236_BOOT_FROM_ROM		1	
-#define CST43236_BOOT_FROM_FLASH	2	
+#define CST43236_BOOT_FROM_SRAM		0
+#define CST43236_BOOT_FROM_ROM		1
+#define CST43236_BOOT_FROM_FLASH	2
 #define CST43236_BOOT_FROM_INVALID	3
 
 
@@ -1312,39 +1312,57 @@
 #define RES43237_HT_SI_AVAIL		5
 
 
-#define CCTRL43237_BT_COEXIST		(1<<0)	
-#define CCTRL43237_SECI			(1<<1)	
-#define CCTRL43237_EXT_LNA		(1<<2)	
-#define CCTRL43237_ANT_MUX_2o3          (1<<3)	
-#define CCTRL43237_GSIO			(1<<4)	
+#define CCTRL43237_BT_COEXIST		(1<<0)
+#define CCTRL43237_SECI			(1<<1)
+#define CCTRL43237_EXT_LNA		(1<<2)
+#define CCTRL43237_ANT_MUX_2o3          (1<<3)
+#define CCTRL43237_GSIO			(1<<4)
 
 
 #define CST43237_SFLASH_MASK		0x00000040
 #define CST43237_OTP_SEL_MASK		0x00000080
 #define CST43237_OTP_SEL_SHIFT		7
-#define CST43237_HSIC_MASK		0x00000100	
-#define CST43237_BP_CLK			0x00000200	
+#define CST43237_HSIC_MASK		0x00000100
+#define CST43237_BP_CLK			0x00000200
 #define CST43237_BOOT_MASK		0x00001800
 #define CST43237_BOOT_SHIFT		11
-#define CST43237_BOOT_FROM_SRAM		0	
-#define CST43237_BOOT_FROM_ROM		1	
-#define CST43237_BOOT_FROM_FLASH	2	
+#define CST43237_BOOT_FROM_SRAM		0
+#define CST43237_BOOT_FROM_ROM		1
+#define CST43237_BOOT_FROM_FLASH	2
 #define CST43237_BOOT_FROM_INVALID	3
 
 
+#define RES43239_CBUCK_LPOM		0
+#define RES43239_CBUCK_BURST		1
+#define RES43239_CBUCK_LP_PWM		2
+#define RES43239_CBUCK_PWM		3
+#define RES43239_CLDO_PU		4
+#define RES43239_DIS_INT_RESET_PD	5
+#define RES43239_ILP_REQUEST		6
+#define RES43239_LNLDO_PU		7
+#define RES43239_LDO3P3_PU		8
 #define RES43239_OTP_PU			9
+#define RES43239_XTAL_PU		10
+#define RES43239_ALP_AVAIL		11
+#define RES43239_RADIO_PU		12
 #define RES43239_MACPHY_CLKAVAIL	23
 #define RES43239_HT_AVAIL		24
+#define RES43239_XOLDO_PU		25
+#define RES43239_WL_XTAL_CTL_SEL	26
+#define RES43239_SR_CLK_STABLE		27
+#define RES43239_SR_SAVE_RESTORE	28
+#define RES43239_SR_PHY_PIC		29
+#define RES43239_SR_PHY_PWR_SW		30
 
 
 #define CST43239_SPROM_MASK			0x00000002
 #define CST43239_SFLASH_MASK		0x00000004
 #define	CST43239_RES_INIT_MODE_SHIFT	7
 #define	CST43239_RES_INIT_MODE_MASK		0x000001f0
-#define CST43239_CHIPMODE_SDIOD(cs)	((cs) & (1 << 15))	
-#define CST43239_CHIPMODE_USB20D(cs)	((cs) & !(1 << 15))	
-#define CST43239_CHIPMODE_SDIO(cs)	(((cs) & (1 << 0)) == 0)	
-#define CST43239_CHIPMODE_GSPI(cs)	(((cs) & (1 << 0)) == (1 << 0))	
+#define CST43239_CHIPMODE_SDIOD(cs)	((cs) & (1 << 15))
+#define CST43239_CHIPMODE_USB20D(cs)	(~(cs) & (1 << 15))
+#define CST43239_CHIPMODE_SDIO(cs)	(((cs) & (1 << 0)) == 0)
+#define CST43239_CHIPMODE_GSPI(cs)	(((cs) & (1 << 0)) == (1 << 0))
 
 
 #define CCTRL43239_XTAL_STRENGTH(ctl)	((ctl & 0x3F) << 12)
@@ -1352,77 +1370,77 @@
 
 
 
-#define RES4315_CBUCK_LPOM		1	
-#define RES4315_CBUCK_BURST		2	
-#define RES4315_CBUCK_PWM		3	
-#define RES4315_CLDO_PU			4	
-#define RES4315_PALDO_PU		5	
-#define RES4315_ILP_REQUEST		6	
-#define RES4315_LNLDO1_PU		9	
-#define RES4315_OTP_PU			10	
-#define RES4315_LNLDO2_PU		12	
-#define RES4315_XTAL_PU			13	
-#define RES4315_ALP_AVAIL		14	
-#define RES4315_RX_PWRSW_PU		15	
-#define RES4315_TX_PWRSW_PU		16	
-#define RES4315_RFPLL_PWRSW_PU		17	
-#define RES4315_LOGEN_PWRSW_PU		18	
-#define RES4315_AFE_PWRSW_PU		19	
-#define RES4315_BBPLL_PWRSW_PU		20	
-#define RES4315_HT_AVAIL		21	
+#define RES4315_CBUCK_LPOM		1
+#define RES4315_CBUCK_BURST		2
+#define RES4315_CBUCK_PWM		3
+#define RES4315_CLDO_PU			4
+#define RES4315_PALDO_PU		5
+#define RES4315_ILP_REQUEST		6
+#define RES4315_LNLDO1_PU		9
+#define RES4315_OTP_PU			10
+#define RES4315_LNLDO2_PU		12
+#define RES4315_XTAL_PU			13
+#define RES4315_ALP_AVAIL		14
+#define RES4315_RX_PWRSW_PU		15
+#define RES4315_TX_PWRSW_PU		16
+#define RES4315_RFPLL_PWRSW_PU		17
+#define RES4315_LOGEN_PWRSW_PU		18
+#define RES4315_AFE_PWRSW_PU		19
+#define RES4315_BBPLL_PWRSW_PU		20
+#define RES4315_HT_AVAIL		21
 
 
-#define CST4315_SPROM_OTP_SEL_MASK	0x00000003	
-#define CST4315_DEFCIS_SEL		0x00000000	
-#define CST4315_SPROM_SEL		0x00000001	
-#define CST4315_OTP_SEL			0x00000002	
-#define CST4315_OTP_PWRDN		0x00000003	
-#define CST4315_SDIO_MODE		0x00000004	
+#define CST4315_SPROM_OTP_SEL_MASK	0x00000003
+#define CST4315_DEFCIS_SEL		0x00000000
+#define CST4315_SPROM_SEL		0x00000001
+#define CST4315_OTP_SEL			0x00000002
+#define CST4315_OTP_PWRDN		0x00000003
+#define CST4315_SDIO_MODE		0x00000004
 #define CST4315_RCAL_VALID		0x00000008
 #define CST4315_RCAL_VALUE_MASK		0x000001f0
 #define CST4315_RCAL_VALUE_SHIFT	4
-#define CST4315_PALDO_EXTPNP		0x00000200	
+#define CST4315_PALDO_EXTPNP		0x00000200
 #define CST4315_CBUCK_MODE_MASK		0x00000c00
 #define CST4315_CBUCK_MODE_BURST	0x00000400
 #define CST4315_CBUCK_MODE_LPBURST	0x00000c00
 
 
-#define RES4319_CBUCK_LPOM		1	
-#define RES4319_CBUCK_BURST		2	
-#define RES4319_CBUCK_PWM		3	
-#define RES4319_CLDO_PU			4	
-#define RES4319_PALDO_PU		5	
-#define RES4319_ILP_REQUEST		6	
-#define RES4319_LNLDO1_PU		9	
-#define RES4319_OTP_PU			10	
-#define RES4319_LNLDO2_PU		12	
-#define RES4319_XTAL_PU			13	
-#define RES4319_ALP_AVAIL		14	
-#define RES4319_RX_PWRSW_PU		15	
-#define RES4319_TX_PWRSW_PU		16	
-#define RES4319_RFPLL_PWRSW_PU		17	
-#define RES4319_LOGEN_PWRSW_PU		18	
-#define RES4319_AFE_PWRSW_PU		19	
-#define RES4319_BBPLL_PWRSW_PU		20	
-#define RES4319_HT_AVAIL		21	
+#define RES4319_CBUCK_LPOM		1
+#define RES4319_CBUCK_BURST		2
+#define RES4319_CBUCK_PWM		3
+#define RES4319_CLDO_PU			4
+#define RES4319_PALDO_PU		5
+#define RES4319_ILP_REQUEST		6
+#define RES4319_LNLDO1_PU		9
+#define RES4319_OTP_PU			10
+#define RES4319_LNLDO2_PU		12
+#define RES4319_XTAL_PU			13
+#define RES4319_ALP_AVAIL		14
+#define RES4319_RX_PWRSW_PU		15
+#define RES4319_TX_PWRSW_PU		16
+#define RES4319_RFPLL_PWRSW_PU		17
+#define RES4319_LOGEN_PWRSW_PU		18
+#define RES4319_AFE_PWRSW_PU		19
+#define RES4319_BBPLL_PWRSW_PU		20
+#define RES4319_HT_AVAIL		21
 
 
 #define	CST4319_SPI_CPULESSUSB		0x00000001
 #define	CST4319_SPI_CLK_POL		0x00000002
 #define	CST4319_SPI_CLK_PH		0x00000008
-#define	CST4319_SPROM_OTP_SEL_MASK	0x000000c0	
+#define	CST4319_SPROM_OTP_SEL_MASK	0x000000c0
 #define	CST4319_SPROM_OTP_SEL_SHIFT	6
-#define	CST4319_DEFCIS_SEL		0x00000000	
-#define	CST4319_SPROM_SEL		0x00000040	
-#define	CST4319_OTP_SEL			0x00000080      
-#define	CST4319_OTP_PWRDN		0x000000c0      
-#define	CST4319_SDIO_USB_MODE		0x00000100	
+#define	CST4319_DEFCIS_SEL		0x00000000
+#define	CST4319_SPROM_SEL		0x00000040
+#define	CST4319_OTP_SEL			0x00000080
+#define	CST4319_OTP_PWRDN		0x000000c0
+#define	CST4319_SDIO_USB_MODE		0x00000100
 #define	CST4319_REMAP_SEL_MASK		0x00000600
 #define	CST4319_ILPDIV_EN		0x00000800
 #define	CST4319_XTAL_PD_POL		0x00001000
 #define	CST4319_LPO_SEL			0x00002000
 #define	CST4319_RES_INIT_MODE		0x0000c000
-#define	CST4319_PALDO_EXTPNP		0x00010000	
+#define	CST4319_PALDO_EXTPNP		0x00010000
 #define	CST4319_CBUCK_MODE_MASK		0x00060000
 #define CST4319_CBUCK_MODE_BURST	0x00020000
 #define CST4319_CBUCK_MODE_LPBURST	0x00060000
@@ -1516,16 +1534,16 @@
 #define	RES4330_5g_LOGEN_PWRSW_PU	27
 
 
-#define CST4330_CHIPMODE_SDIOD(cs)	(((cs) & 0x7) < 6)	
-#define CST4330_CHIPMODE_USB20D(cs)	(((cs) & 0x7) >= 6)	
-#define CST4330_CHIPMODE_SDIO(cs)	(((cs) & 0x4) == 0)	
-#define CST4330_CHIPMODE_GSPI(cs)	(((cs) & 0x6) == 4)	
-#define CST4330_CHIPMODE_USB(cs)	(((cs) & 0x7) == 6)	
-#define CST4330_CHIPMODE_USBDA(cs)	(((cs) & 0x7) == 7)	
+#define CST4330_CHIPMODE_SDIOD(cs)	(((cs) & 0x7) < 6)
+#define CST4330_CHIPMODE_USB20D(cs)	(((cs) & 0x7) >= 6)
+#define CST4330_CHIPMODE_SDIO(cs)	(((cs) & 0x4) == 0)
+#define CST4330_CHIPMODE_GSPI(cs)	(((cs) & 0x6) == 4)
+#define CST4330_CHIPMODE_USB(cs)	(((cs) & 0x7) == 6)
+#define CST4330_CHIPMODE_USBDA(cs)	(((cs) & 0x7) == 7)
 #define	CST4330_OTP_PRESENT		0x00000010
 #define	CST4330_LPO_AUTODET_EN		0x00000020
 #define	CST4330_ARMREMAP_0		0x00000040
-#define	CST4330_SPROM_PRESENT		0x00000080	
+#define	CST4330_SPROM_PRESENT		0x00000080
 #define	CST4330_ILPDIV_EN		0x00000100
 #define	CST4330_LPO_SEL			0x00000200
 #define	CST4330_RES_INIT_MODE_SHIFT	10
@@ -1541,10 +1559,10 @@
 #define PCTL_4330_SERIAL_ENAB	(1  << 24)
 
 
-#define CCTRL_4330_GPIO_SEL		0x00000001    
-#define CCTRL_4330_ERCX_SEL		0x00000002    
-#define CCTRL_4330_SDIO_HOST_WAKE	0x00000004    
-#define CCTRL_4330_JTAG_DISABLE	0x00000008    
+#define CCTRL_4330_GPIO_SEL		0x00000001
+#define CCTRL_4330_ERCX_SEL		0x00000002
+#define CCTRL_4330_SDIO_HOST_WAKE	0x00000004
+#define CCTRL_4330_JTAG_DISABLE	0x00000008
 
 
 #define	RES4313_BB_PU_RSRC		0
@@ -1571,7 +1589,7 @@
 #define	CST4313_SPROM_OTP_SEL_SHIFT		0
 
 
-#define CCTRL_4313_12MA_LED_DRIVE    0x00000007    
+#define CCTRL_4313_12MA_LED_DRIVE    0x00000007
 
 
 #define RES43228_NOT_USED		0
@@ -1612,4 +1630,4 @@
 #define WLAN_NUM_ANT1 TXANT_0
 #define WLAN_NUM_ANT2 TXANT_1
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sbconfig.h b/drivers/net/wireless/bcmdhd/include/sbconfig.h
index 76f05ae..9947acd 100644
--- a/drivers/net/wireless/bcmdhd/include/sbconfig.h
+++ b/drivers/net/wireless/bcmdhd/include/sbconfig.h
@@ -2,13 +2,13 @@
  * Broadcom SiliconBackplane hardware register definitions.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbconfig.h,v 13.70 2008-03-28 19:17:04 Exp $
+ * $Id: sbconfig.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -36,18 +36,18 @@
 #endif
 
 
-#define SB_BUS_SIZE		0x10000		
+#define SB_BUS_SIZE		0x10000
 #define SB_BUS_BASE(b)		(SI_ENUM_BASE + (b) * SB_BUS_SIZE)
-#define	SB_BUS_MAXCORES		(SB_BUS_SIZE / SI_CORE_SIZE)	
+#define	SB_BUS_MAXCORES		(SB_BUS_SIZE / SI_CORE_SIZE)
 
 
-#define	SBCONFIGOFF		0xf00		
-#define	SBCONFIGSIZE		256		
+#define	SBCONFIGOFF		0xf00
+#define	SBCONFIGSIZE		256
 
 #define SBIPSFLAG		0x08
 #define SBTPSFLAG		0x18
-#define	SBTMERRLOGA		0x48		
-#define	SBTMERRLOG		0x50		
+#define	SBTMERRLOGA		0x48
+#define	SBTMERRLOG		0x50
 #define SBADMATCH3		0x60
 #define SBADMATCH2		0x68
 #define SBADMATCH1		0x70
@@ -79,198 +79,198 @@
 
 typedef volatile struct _sbconfig {
 	uint32	PAD[2];
-	uint32	sbipsflag;		
+	uint32	sbipsflag;
 	uint32	PAD[3];
-	uint32	sbtpsflag;		
+	uint32	sbtpsflag;
 	uint32	PAD[11];
-	uint32	sbtmerrloga;		
+	uint32	sbtmerrloga;
 	uint32	PAD;
-	uint32	sbtmerrlog;		
+	uint32	sbtmerrlog;
 	uint32	PAD[3];
-	uint32	sbadmatch3;		
+	uint32	sbadmatch3;
 	uint32	PAD;
-	uint32	sbadmatch2;		
+	uint32	sbadmatch2;
 	uint32	PAD;
-	uint32	sbadmatch1;		
+	uint32	sbadmatch1;
 	uint32	PAD[7];
-	uint32	sbimstate;		
-	uint32	sbintvec;		
-	uint32	sbtmstatelow;		
-	uint32	sbtmstatehigh;		
-	uint32	sbbwa0;			
+	uint32	sbimstate;
+	uint32	sbintvec;
+	uint32	sbtmstatelow;
+	uint32	sbtmstatehigh;
+	uint32	sbbwa0;
 	uint32	PAD;
-	uint32	sbimconfiglow;		
-	uint32	sbimconfighigh;		
-	uint32	sbadmatch0;		
+	uint32	sbimconfiglow;
+	uint32	sbimconfighigh;
+	uint32	sbadmatch0;
 	uint32	PAD;
-	uint32	sbtmconfiglow;		
-	uint32	sbtmconfighigh;		
-	uint32	sbbconfig;		
+	uint32	sbtmconfiglow;
+	uint32	sbtmconfighigh;
+	uint32	sbbconfig;
 	uint32	PAD;
-	uint32	sbbstate;		
+	uint32	sbbstate;
 	uint32	PAD[3];
-	uint32	sbactcnfg;		
+	uint32	sbactcnfg;
 	uint32	PAD[3];
-	uint32	sbflagst;		
+	uint32	sbflagst;
 	uint32	PAD[3];
-	uint32	sbidlow;		
-	uint32	sbidhigh;		
+	uint32	sbidlow;
+	uint32	sbidhigh;
 } sbconfig_t;
 
-#endif 
+#endif
 
 
-#define	SBIPS_INT1_MASK		0x3f		
+#define	SBIPS_INT1_MASK		0x3f
 #define	SBIPS_INT1_SHIFT	0
-#define	SBIPS_INT2_MASK		0x3f00		
+#define	SBIPS_INT2_MASK		0x3f00
 #define	SBIPS_INT2_SHIFT	8
-#define	SBIPS_INT3_MASK		0x3f0000	
+#define	SBIPS_INT3_MASK		0x3f0000
 #define	SBIPS_INT3_SHIFT	16
-#define	SBIPS_INT4_MASK		0x3f000000	
+#define	SBIPS_INT4_MASK		0x3f000000
 #define	SBIPS_INT4_SHIFT	24
 
 
-#define	SBTPS_NUM0_MASK		0x3f		
-#define	SBTPS_F0EN0		0x40		
+#define	SBTPS_NUM0_MASK		0x3f
+#define	SBTPS_F0EN0		0x40
 
 
-#define	SBTMEL_CM		0x00000007	
-#define	SBTMEL_CI		0x0000ff00	
-#define	SBTMEL_EC		0x0f000000	
-#define	SBTMEL_ME		0x80000000	
+#define	SBTMEL_CM		0x00000007
+#define	SBTMEL_CI		0x0000ff00
+#define	SBTMEL_EC		0x0f000000
+#define	SBTMEL_ME		0x80000000
 
 
-#define	SBIM_PC			0xf		
-#define	SBIM_AP_MASK		0x30		
-#define	SBIM_AP_BOTH		0x00		
-#define	SBIM_AP_TS		0x10		
-#define	SBIM_AP_TK		0x20		
-#define	SBIM_AP_RSV		0x30		
-#define	SBIM_IBE		0x20000		
-#define	SBIM_TO			0x40000		
-#define	SBIM_BY			0x01800000	
-#define	SBIM_RJ			0x02000000	
+#define	SBIM_PC			0xf
+#define	SBIM_AP_MASK		0x30
+#define	SBIM_AP_BOTH		0x00
+#define	SBIM_AP_TS		0x10
+#define	SBIM_AP_TK		0x20
+#define	SBIM_AP_RSV		0x30
+#define	SBIM_IBE		0x20000
+#define	SBIM_TO			0x40000
+#define	SBIM_BY			0x01800000
+#define	SBIM_RJ			0x02000000
 
 
-#define	SBTML_RESET		0x0001		
-#define	SBTML_REJ_MASK		0x0006		
-#define	SBTML_REJ		0x0002		
-#define	SBTML_TMPREJ		0x0004		
+#define	SBTML_RESET		0x0001
+#define	SBTML_REJ_MASK		0x0006
+#define	SBTML_REJ		0x0002
+#define	SBTML_TMPREJ		0x0004
 
-#define	SBTML_SICF_SHIFT	16		
+#define	SBTML_SICF_SHIFT	16
 
 
-#define	SBTMH_SERR		0x0001		
-#define	SBTMH_INT		0x0002		
-#define	SBTMH_BUSY		0x0004		
-#define	SBTMH_TO		0x0020		
+#define	SBTMH_SERR		0x0001
+#define	SBTMH_INT		0x0002
+#define	SBTMH_BUSY		0x0004
+#define	SBTMH_TO		0x0020
 
-#define	SBTMH_SISF_SHIFT	16		
+#define	SBTMH_SISF_SHIFT	16
 
 
-#define	SBBWA_TAB0_MASK		0xffff		
-#define	SBBWA_TAB1_MASK		0xffff		
+#define	SBBWA_TAB0_MASK		0xffff
+#define	SBBWA_TAB1_MASK		0xffff
 #define	SBBWA_TAB1_SHIFT	16
 
 
-#define	SBIMCL_STO_MASK		0x7		
-#define	SBIMCL_RTO_MASK		0x70		
+#define	SBIMCL_STO_MASK		0x7
+#define	SBIMCL_RTO_MASK		0x70
 #define	SBIMCL_RTO_SHIFT	4
-#define	SBIMCL_CID_MASK		0xff0000	
+#define	SBIMCL_CID_MASK		0xff0000
 #define	SBIMCL_CID_SHIFT	16
 
 
-#define	SBIMCH_IEM_MASK		0xc		
-#define	SBIMCH_TEM_MASK		0x30		
+#define	SBIMCH_IEM_MASK		0xc
+#define	SBIMCH_TEM_MASK		0x30
 #define	SBIMCH_TEM_SHIFT	4
-#define	SBIMCH_BEM_MASK		0xc0		
+#define	SBIMCH_BEM_MASK		0xc0
 #define	SBIMCH_BEM_SHIFT	6
 
 
-#define	SBAM_TYPE_MASK		0x3		
-#define	SBAM_AD64		0x4		
-#define	SBAM_ADINT0_MASK	0xf8		
+#define	SBAM_TYPE_MASK		0x3
+#define	SBAM_AD64		0x4
+#define	SBAM_ADINT0_MASK	0xf8
 #define	SBAM_ADINT0_SHIFT	3
-#define	SBAM_ADINT1_MASK	0x1f8		
+#define	SBAM_ADINT1_MASK	0x1f8
 #define	SBAM_ADINT1_SHIFT	3
-#define	SBAM_ADINT2_MASK	0x1f8		
+#define	SBAM_ADINT2_MASK	0x1f8
 #define	SBAM_ADINT2_SHIFT	3
-#define	SBAM_ADEN		0x400		
-#define	SBAM_ADNEG		0x800		
-#define	SBAM_BASE0_MASK		0xffffff00	
+#define	SBAM_ADEN		0x400
+#define	SBAM_ADNEG		0x800
+#define	SBAM_BASE0_MASK		0xffffff00
 #define	SBAM_BASE0_SHIFT	8
-#define	SBAM_BASE1_MASK		0xfffff000	
+#define	SBAM_BASE1_MASK		0xfffff000
 #define	SBAM_BASE1_SHIFT	12
-#define	SBAM_BASE2_MASK		0xffff0000	
+#define	SBAM_BASE2_MASK		0xffff0000
 #define	SBAM_BASE2_SHIFT	16
 
 
-#define	SBTMCL_CD_MASK		0xff		
-#define	SBTMCL_CO_MASK		0xf800		
+#define	SBTMCL_CD_MASK		0xff
+#define	SBTMCL_CO_MASK		0xf800
 #define	SBTMCL_CO_SHIFT		11
-#define	SBTMCL_IF_MASK		0xfc0000	
+#define	SBTMCL_IF_MASK		0xfc0000
 #define	SBTMCL_IF_SHIFT		18
-#define	SBTMCL_IM_MASK		0x3000000	
+#define	SBTMCL_IM_MASK		0x3000000
 #define	SBTMCL_IM_SHIFT		24
 
 
-#define	SBTMCH_BM_MASK		0x3		
-#define	SBTMCH_RM_MASK		0x3		
+#define	SBTMCH_BM_MASK		0x3
+#define	SBTMCH_RM_MASK		0x3
 #define	SBTMCH_RM_SHIFT		2
-#define	SBTMCH_SM_MASK		0x30		
+#define	SBTMCH_SM_MASK		0x30
 #define	SBTMCH_SM_SHIFT		4
-#define	SBTMCH_EM_MASK		0x300		
+#define	SBTMCH_EM_MASK		0x300
 #define	SBTMCH_EM_SHIFT		8
-#define	SBTMCH_IM_MASK		0xc00		
+#define	SBTMCH_IM_MASK		0xc00
 #define	SBTMCH_IM_SHIFT		10
 
 
-#define	SBBC_LAT_MASK		0x3		
-#define	SBBC_MAX0_MASK		0xf0000		
+#define	SBBC_LAT_MASK		0x3
+#define	SBBC_MAX0_MASK		0xf0000
 #define	SBBC_MAX0_SHIFT		16
-#define	SBBC_MAX1_MASK		0xf00000	
+#define	SBBC_MAX1_MASK		0xf00000
 #define	SBBC_MAX1_SHIFT		20
 
 
-#define	SBBS_SRD		0x1		
-#define	SBBS_HRD		0x2		
+#define	SBBS_SRD		0x1
+#define	SBBS_HRD		0x2
 
 
-#define	SBIDL_CS_MASK		0x3		
-#define	SBIDL_AR_MASK		0x38		
+#define	SBIDL_CS_MASK		0x3
+#define	SBIDL_AR_MASK		0x38
 #define	SBIDL_AR_SHIFT		3
-#define	SBIDL_SYNCH		0x40		
-#define	SBIDL_INIT		0x80		
-#define	SBIDL_MINLAT_MASK	0xf00		
+#define	SBIDL_SYNCH		0x40
+#define	SBIDL_INIT		0x80
+#define	SBIDL_MINLAT_MASK	0xf00
 #define	SBIDL_MINLAT_SHIFT	8
-#define	SBIDL_MAXLAT		0xf000		
+#define	SBIDL_MAXLAT		0xf000
 #define	SBIDL_MAXLAT_SHIFT	12
-#define	SBIDL_FIRST		0x10000		
-#define	SBIDL_CW_MASK		0xc0000		
+#define	SBIDL_FIRST		0x10000
+#define	SBIDL_CW_MASK		0xc0000
 #define	SBIDL_CW_SHIFT		18
-#define	SBIDL_TP_MASK		0xf00000	
+#define	SBIDL_TP_MASK		0xf00000
 #define	SBIDL_TP_SHIFT		20
-#define	SBIDL_IP_MASK		0xf000000	
+#define	SBIDL_IP_MASK		0xf000000
 #define	SBIDL_IP_SHIFT		24
-#define	SBIDL_RV_MASK		0xf0000000	
+#define	SBIDL_RV_MASK		0xf0000000
 #define	SBIDL_RV_SHIFT		28
-#define	SBIDL_RV_2_2		0x00000000	
-#define	SBIDL_RV_2_3		0x10000000	
+#define	SBIDL_RV_2_2		0x00000000
+#define	SBIDL_RV_2_3		0x10000000
 
 
-#define	SBIDH_RC_MASK		0x000f		
-#define	SBIDH_RCE_MASK		0x7000		
+#define	SBIDH_RC_MASK		0x000f
+#define	SBIDH_RCE_MASK		0x7000
 #define	SBIDH_RCE_SHIFT		8
 #define	SBCOREREV(sbidh) \
 	((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK))
-#define	SBIDH_CC_MASK		0x8ff0		
+#define	SBIDH_CC_MASK		0x8ff0
 #define	SBIDH_CC_SHIFT		4
-#define	SBIDH_VC_MASK		0xffff0000	
+#define	SBIDH_VC_MASK		0xffff0000
 #define	SBIDH_VC_SHIFT		16
 
-#define	SB_COMMIT		0xfd8		
+#define	SB_COMMIT		0xfd8
 
 
-#define	SB_VEND_BCM		0x4243		
+#define	SB_VEND_BCM		0x4243
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sbhnddma.h b/drivers/net/wireless/bcmdhd/include/sbhnddma.h
index 05d0587..7ec518c 100644
--- a/drivers/net/wireless/bcmdhd/include/sbhnddma.h
+++ b/drivers/net/wireless/bcmdhd/include/sbhnddma.h
@@ -3,13 +3,13 @@
  * This supports the following chips: BCM42xx, 44xx, 47xx .
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbhnddma.h,v 13.20.2.3 2010-10-14 22:21:29 Exp $
+ * $Id: sbhnddma.h 281450 2011-09-02 01:38:29Z $
  */
 
 
@@ -36,28 +36,28 @@
 
 
 typedef volatile struct {
-	uint32	control;		
-	uint32	addr;			
-	uint32	ptr;			
-	uint32	status;			
+	uint32	control;
+	uint32	addr;
+	uint32	ptr;
+	uint32	status;
 } dma32regs_t;
 
 typedef volatile struct {
-	dma32regs_t	xmt;		
-	dma32regs_t	rcv;		
+	dma32regs_t	xmt;
+	dma32regs_t	rcv;
 } dma32regp_t;
 
-typedef volatile struct {	
-	uint32	fifoaddr;		
-	uint32	fifodatalow;		
-	uint32	fifodatahigh;		
-	uint32	pad;			
+typedef volatile struct {
+	uint32	fifoaddr;
+	uint32	fifodatalow;
+	uint32	fifodatahigh;
+	uint32	pad;
 } dma32diag_t;
 
 
 typedef volatile struct {
-	uint32	ctrl;		
-	uint32	addr;		
+	uint32	ctrl;
+	uint32	addr;
 } dma32dd_t;
 
 
@@ -68,96 +68,96 @@
 #define	D32MAXDD	(D32MAXRINGSZ / sizeof (dma32dd_t))
 
 
-#define	XC_XE		((uint32)1 << 0)	
-#define	XC_SE		((uint32)1 << 1)	
-#define	XC_LE		((uint32)1 << 2)	
-#define	XC_FL		((uint32)1 << 4)	
-#define	XC_PD		((uint32)1 << 11)	
-#define	XC_AE		((uint32)3 << 16)	
+#define	XC_XE		((uint32)1 << 0)
+#define	XC_SE		((uint32)1 << 1)
+#define	XC_LE		((uint32)1 << 2)
+#define	XC_FL		((uint32)1 << 4)
+#define	XC_PD		((uint32)1 << 11)
+#define	XC_AE		((uint32)3 << 16)
 #define	XC_AE_SHIFT	16
-#define XC_BL_MASK	0x001C0000			
+#define XC_BL_MASK	0x001C0000
 #define XC_BL_SHIFT	18
 
 
-#define	XP_LD_MASK	0xfff			
+#define	XP_LD_MASK	0xfff
 
 
-#define	XS_CD_MASK	0x0fff			
-#define	XS_XS_MASK	0xf000			
+#define	XS_CD_MASK	0x0fff
+#define	XS_XS_MASK	0xf000
 #define	XS_XS_SHIFT	12
-#define	XS_XS_DISABLED	0x0000			
-#define	XS_XS_ACTIVE	0x1000			
-#define	XS_XS_IDLE	0x2000			
-#define	XS_XS_STOPPED	0x3000			
-#define	XS_XS_SUSP	0x4000			
-#define	XS_XE_MASK	0xf0000			
+#define	XS_XS_DISABLED	0x0000
+#define	XS_XS_ACTIVE	0x1000
+#define	XS_XS_IDLE	0x2000
+#define	XS_XS_STOPPED	0x3000
+#define	XS_XS_SUSP	0x4000
+#define	XS_XE_MASK	0xf0000
 #define	XS_XE_SHIFT	16
-#define	XS_XE_NOERR	0x00000			
-#define	XS_XE_DPE	0x10000			
-#define	XS_XE_DFU	0x20000			
-#define	XS_XE_BEBR	0x30000			
-#define	XS_XE_BEDA	0x40000			
-#define	XS_AD_MASK	0xfff00000		
+#define	XS_XE_NOERR	0x00000
+#define	XS_XE_DPE	0x10000
+#define	XS_XE_DFU	0x20000
+#define	XS_XE_BEBR	0x30000
+#define	XS_XE_BEDA	0x40000
+#define	XS_AD_MASK	0xfff00000
 #define	XS_AD_SHIFT	20
 
 
-#define	RC_RE		((uint32)1 << 0)	
-#define	RC_RO_MASK	0xfe			
+#define	RC_RE		((uint32)1 << 0)
+#define	RC_RO_MASK	0xfe
 #define	RC_RO_SHIFT	1
-#define	RC_FM		((uint32)1 << 8)	
-#define	RC_SH		((uint32)1 << 9)	
-#define	RC_OC		((uint32)1 << 10)	
-#define	RC_PD		((uint32)1 << 11)	
-#define	RC_AE		((uint32)3 << 16)	
+#define	RC_FM		((uint32)1 << 8)
+#define	RC_SH		((uint32)1 << 9)
+#define	RC_OC		((uint32)1 << 10)
+#define	RC_PD		((uint32)1 << 11)
+#define	RC_AE		((uint32)3 << 16)
 #define	RC_AE_SHIFT	16
-#define RC_BL_MASK	0x001C0000			
+#define RC_BL_MASK	0x001C0000
 #define RC_BL_SHIFT	18
 
 
-#define	RP_LD_MASK	0xfff			
+#define	RP_LD_MASK	0xfff
 
 
-#define	RS_CD_MASK	0x0fff			
-#define	RS_RS_MASK	0xf000			
+#define	RS_CD_MASK	0x0fff
+#define	RS_RS_MASK	0xf000
 #define	RS_RS_SHIFT	12
-#define	RS_RS_DISABLED	0x0000			
-#define	RS_RS_ACTIVE	0x1000			
-#define	RS_RS_IDLE	0x2000			
-#define	RS_RS_STOPPED	0x3000			
-#define	RS_RE_MASK	0xf0000			
+#define	RS_RS_DISABLED	0x0000
+#define	RS_RS_ACTIVE	0x1000
+#define	RS_RS_IDLE	0x2000
+#define	RS_RS_STOPPED	0x3000
+#define	RS_RE_MASK	0xf0000
 #define	RS_RE_SHIFT	16
-#define	RS_RE_NOERR	0x00000			
-#define	RS_RE_DPE	0x10000			
-#define	RS_RE_DFO	0x20000			
-#define	RS_RE_BEBW	0x30000			
-#define	RS_RE_BEDA	0x40000			
-#define	RS_AD_MASK	0xfff00000		
+#define	RS_RE_NOERR	0x00000
+#define	RS_RE_DPE	0x10000
+#define	RS_RE_DFO	0x20000
+#define	RS_RE_BEBW	0x30000
+#define	RS_RE_BEDA	0x40000
+#define	RS_AD_MASK	0xfff00000
 #define	RS_AD_SHIFT	20
 
 
-#define	FA_OFF_MASK	0xffff			
-#define	FA_SEL_MASK	0xf0000			
+#define	FA_OFF_MASK	0xffff
+#define	FA_SEL_MASK	0xf0000
 #define	FA_SEL_SHIFT	16
-#define	FA_SEL_XDD	0x00000			
-#define	FA_SEL_XDP	0x10000			
-#define	FA_SEL_RDD	0x40000			
-#define	FA_SEL_RDP	0x50000			
-#define	FA_SEL_XFD	0x80000			
-#define	FA_SEL_XFP	0x90000			
-#define	FA_SEL_RFD	0xc0000			
-#define	FA_SEL_RFP	0xd0000			
-#define	FA_SEL_RSD	0xe0000			
-#define	FA_SEL_RSP	0xf0000			
+#define	FA_SEL_XDD	0x00000
+#define	FA_SEL_XDP	0x10000
+#define	FA_SEL_RDD	0x40000
+#define	FA_SEL_RDP	0x50000
+#define	FA_SEL_XFD	0x80000
+#define	FA_SEL_XFP	0x90000
+#define	FA_SEL_RFD	0xc0000
+#define	FA_SEL_RFP	0xd0000
+#define	FA_SEL_RSD	0xe0000
+#define	FA_SEL_RSP	0xf0000
 
 
-#define	CTRL_BC_MASK	0x00001fff		
-#define	CTRL_AE		((uint32)3 << 16)	
+#define	CTRL_BC_MASK	0x00001fff
+#define	CTRL_AE		((uint32)3 << 16)
 #define	CTRL_AE_SHIFT	16
-#define	CTRL_PARITY	((uint32)3 << 18)	
-#define	CTRL_EOT	((uint32)1 << 28)	
-#define	CTRL_IOC	((uint32)1 << 29)	
-#define	CTRL_EOF	((uint32)1 << 30)	
-#define	CTRL_SOF	((uint32)1 << 31)	
+#define	CTRL_PARITY	((uint32)3 << 18)
+#define	CTRL_EOT	((uint32)1 << 28)
+#define	CTRL_IOC	((uint32)1 << 29)
+#define	CTRL_EOF	((uint32)1 << 30)
+#define	CTRL_SOF	((uint32)1 << 31)
 
 
 #define	CTRL_CORE_MASK	0x0ff00000
@@ -166,32 +166,32 @@
 
 
 typedef volatile struct {
-	uint32	control;		
-	uint32	ptr;			
-	uint32	addrlow;		
-	uint32	addrhigh;		
-	uint32	status0;		
-	uint32	status1;		
+	uint32	control;
+	uint32	ptr;
+	uint32	addrlow;
+	uint32	addrhigh;
+	uint32	status0;
+	uint32	status1;
 } dma64regs_t;
 
 typedef volatile struct {
-	dma64regs_t	tx;		
-	dma64regs_t	rx;		
+	dma64regs_t	tx;
+	dma64regs_t	rx;
 } dma64regp_t;
 
-typedef volatile struct {		
-	uint32	fifoaddr;		
-	uint32	fifodatalow;		
-	uint32	fifodatahigh;		
-	uint32	pad;			
+typedef volatile struct {
+	uint32	fifoaddr;
+	uint32	fifodatalow;
+	uint32	fifodatahigh;
+	uint32	pad;
 } dma64diag_t;
 
 
 typedef volatile struct {
-	uint32	ctrl1;		
-	uint32	ctrl2;		
-	uint32	addrlow;	
-	uint32	addrhigh;	
+	uint32	ctrl1;
+	uint32	ctrl2;
+	uint32	addrlow;
+	uint32	addrhigh;
 } dma64dd_t;
 
 
@@ -206,117 +206,117 @@
 #define D64_DEF_SDIOBURSTLEN	1
 
 
-#define	D64_XC_XE		0x00000001	
-#define	D64_XC_SE		0x00000002	
-#define	D64_XC_LE		0x00000004	
-#define	D64_XC_FL		0x00000010	
-#define	D64_XC_PD		0x00000800	
-#define	D64_XC_AE		0x00030000	
+#define	D64_XC_XE		0x00000001
+#define	D64_XC_SE		0x00000002
+#define	D64_XC_LE		0x00000004
+#define	D64_XC_FL		0x00000010
+#define	D64_XC_PD		0x00000800
+#define	D64_XC_AE		0x00030000
 #define	D64_XC_AE_SHIFT		16
-#define D64_XC_BL_MASK	0x001C0000	
+#define D64_XC_BL_MASK	0x001C0000
 #define D64_XC_BL_SHIFT		18
 
 
-#define	D64_XP_LD_MASK		0x00000fff	
+#define	D64_XP_LD_MASK		0x00001fff
 
 
-#define	D64_XS0_CD_MASK		0x00001fff	
-#define	D64_XS0_XS_MASK		0xf0000000     	
+#define	D64_XS0_CD_MASK		0x00001fff
+#define	D64_XS0_XS_MASK		0xf0000000
 #define	D64_XS0_XS_SHIFT		28
-#define	D64_XS0_XS_DISABLED	0x00000000	
-#define	D64_XS0_XS_ACTIVE	0x10000000	
-#define	D64_XS0_XS_IDLE		0x20000000	
-#define	D64_XS0_XS_STOPPED	0x30000000	
-#define	D64_XS0_XS_SUSP		0x40000000	
+#define	D64_XS0_XS_DISABLED	0x00000000
+#define	D64_XS0_XS_ACTIVE	0x10000000
+#define	D64_XS0_XS_IDLE		0x20000000
+#define	D64_XS0_XS_STOPPED	0x30000000
+#define	D64_XS0_XS_SUSP		0x40000000
 
-#define	D64_XS1_AD_MASK		0x00001fff	
-#define	D64_XS1_XE_MASK		0xf0000000     	
+#define	D64_XS1_AD_MASK		0x00001fff
+#define	D64_XS1_XE_MASK		0xf0000000
 #define	D64_XS1_XE_SHIFT		28
-#define	D64_XS1_XE_NOERR	0x00000000	
-#define	D64_XS1_XE_DPE		0x10000000	
-#define	D64_XS1_XE_DFU		0x20000000	
-#define	D64_XS1_XE_DTE		0x30000000	
-#define	D64_XS1_XE_DESRE	0x40000000	
-#define	D64_XS1_XE_COREE	0x50000000	
+#define	D64_XS1_XE_NOERR	0x00000000
+#define	D64_XS1_XE_DPE		0x10000000
+#define	D64_XS1_XE_DFU		0x20000000
+#define	D64_XS1_XE_DTE		0x30000000
+#define	D64_XS1_XE_DESRE	0x40000000
+#define	D64_XS1_XE_COREE	0x50000000
 
 
-#define	D64_RC_RE		0x00000001	
-#define	D64_RC_RO_MASK		0x000000fe	
+#define	D64_RC_RE		0x00000001
+#define	D64_RC_RO_MASK		0x000000fe
 #define	D64_RC_RO_SHIFT		1
-#define	D64_RC_FM		0x00000100	
-#define	D64_RC_SH		0x00000200	
-#define	D64_RC_OC		0x00000400	
-#define	D64_RC_PD		0x00000800	
-#define	D64_RC_AE		0x00030000	
+#define	D64_RC_FM		0x00000100
+#define	D64_RC_SH		0x00000200
+#define	D64_RC_OC		0x00000400
+#define	D64_RC_PD		0x00000800
+#define	D64_RC_AE		0x00030000
 #define	D64_RC_AE_SHIFT		16
-#define D64_RC_BL_MASK	0x001C0000	
+#define D64_RC_BL_MASK	0x001C0000
 #define D64_RC_BL_SHIFT		18
 
 
-#define DMA_CTRL_PEN		(1 << 0)	
-#define DMA_CTRL_ROC		(1 << 1)	
-#define DMA_CTRL_RXMULTI	(1 << 2)	
-#define DMA_CTRL_UNFRAMED	(1 << 3)	
+#define DMA_CTRL_PEN		(1 << 0)
+#define DMA_CTRL_ROC		(1 << 1)
+#define DMA_CTRL_RXMULTI	(1 << 2)
+#define DMA_CTRL_UNFRAMED	(1 << 3)
 #define DMA_CTRL_USB_BOUNDRY4KB_WAR (1 << 4)
 
 
-#define	D64_RP_LD_MASK		0x00000fff	
+#define	D64_RP_LD_MASK		0x00001fff
 
 
-#define	D64_RS0_CD_MASK		0x00001fff	
-#define	D64_RS0_RS_MASK		0xf0000000     	
+#define	D64_RS0_CD_MASK		0x00001fff
+#define	D64_RS0_RS_MASK		0xf0000000
 #define	D64_RS0_RS_SHIFT		28
-#define	D64_RS0_RS_DISABLED	0x00000000	
-#define	D64_RS0_RS_ACTIVE	0x10000000	
-#define	D64_RS0_RS_IDLE		0x20000000	
-#define	D64_RS0_RS_STOPPED	0x30000000	
-#define	D64_RS0_RS_SUSP		0x40000000	
+#define	D64_RS0_RS_DISABLED	0x00000000
+#define	D64_RS0_RS_ACTIVE	0x10000000
+#define	D64_RS0_RS_IDLE		0x20000000
+#define	D64_RS0_RS_STOPPED	0x30000000
+#define	D64_RS0_RS_SUSP		0x40000000
 
-#define	D64_RS1_AD_MASK		0x0001ffff	
-#define	D64_RS1_RE_MASK		0xf0000000     	
+#define	D64_RS1_AD_MASK		0x0001ffff
+#define	D64_RS1_RE_MASK		0xf0000000
 #define	D64_RS1_RE_SHIFT		28
-#define	D64_RS1_RE_NOERR	0x00000000	
-#define	D64_RS1_RE_DPO		0x10000000	
-#define	D64_RS1_RE_DFU		0x20000000	
-#define	D64_RS1_RE_DTE		0x30000000	
-#define	D64_RS1_RE_DESRE	0x40000000	
-#define	D64_RS1_RE_COREE	0x50000000	
+#define	D64_RS1_RE_NOERR	0x00000000
+#define	D64_RS1_RE_DPO		0x10000000
+#define	D64_RS1_RE_DFU		0x20000000
+#define	D64_RS1_RE_DTE		0x30000000
+#define	D64_RS1_RE_DESRE	0x40000000
+#define	D64_RS1_RE_COREE	0x50000000
 
 
-#define	D64_FA_OFF_MASK		0xffff		
-#define	D64_FA_SEL_MASK		0xf0000		
+#define	D64_FA_OFF_MASK		0xffff
+#define	D64_FA_SEL_MASK		0xf0000
 #define	D64_FA_SEL_SHIFT	16
-#define	D64_FA_SEL_XDD		0x00000		
-#define	D64_FA_SEL_XDP		0x10000		
-#define	D64_FA_SEL_RDD		0x40000		
-#define	D64_FA_SEL_RDP		0x50000		
-#define	D64_FA_SEL_XFD		0x80000		
-#define	D64_FA_SEL_XFP		0x90000		
-#define	D64_FA_SEL_RFD		0xc0000		
-#define	D64_FA_SEL_RFP		0xd0000		
-#define	D64_FA_SEL_RSD		0xe0000		
-#define	D64_FA_SEL_RSP		0xf0000		
+#define	D64_FA_SEL_XDD		0x00000
+#define	D64_FA_SEL_XDP		0x10000
+#define	D64_FA_SEL_RDD		0x40000
+#define	D64_FA_SEL_RDP		0x50000
+#define	D64_FA_SEL_XFD		0x80000
+#define	D64_FA_SEL_XFP		0x90000
+#define	D64_FA_SEL_RFD		0xc0000
+#define	D64_FA_SEL_RFP		0xd0000
+#define	D64_FA_SEL_RSD		0xe0000
+#define	D64_FA_SEL_RSP		0xf0000
 
 
-#define D64_CTRL_COREFLAGS	0x0ff00000	
-#define	D64_CTRL1_EOT		((uint32)1 << 28)	
-#define	D64_CTRL1_IOC		((uint32)1 << 29)	
-#define	D64_CTRL1_EOF		((uint32)1 << 30)	
-#define	D64_CTRL1_SOF		((uint32)1 << 31)	
+#define D64_CTRL_COREFLAGS	0x0ff00000
+#define	D64_CTRL1_EOT		((uint32)1 << 28)
+#define	D64_CTRL1_IOC		((uint32)1 << 29)
+#define	D64_CTRL1_EOF		((uint32)1 << 30)
+#define	D64_CTRL1_SOF		((uint32)1 << 31)
 
 
-#define	D64_CTRL2_BC_MASK	0x00007fff	
-#define	D64_CTRL2_AE		0x00030000	
+#define	D64_CTRL2_BC_MASK	0x00007fff
+#define	D64_CTRL2_AE		0x00030000
 #define	D64_CTRL2_AE_SHIFT	16
-#define D64_CTRL2_PARITY	0x00040000      
+#define D64_CTRL2_PARITY	0x00040000
 
 
 #define	D64_CTRL_CORE_MASK	0x0ff00000
 
-#define D64_RX_FRM_STS_LEN	0x0000ffff	
-#define D64_RX_FRM_STS_OVFL	0x00800000	
-#define D64_RX_FRM_STS_DSCRCNT	0x0f000000	
-#define D64_RX_FRM_STS_DATATYPE	0xf0000000	
+#define D64_RX_FRM_STS_LEN	0x0000ffff
+#define D64_RX_FRM_STS_OVFL	0x00800000
+#define D64_RX_FRM_STS_DSCRCNT	0x0f000000
+#define D64_RX_FRM_STS_DATATYPE	0xf0000000
 
 
 typedef volatile struct {
@@ -324,4 +324,4 @@
 	uint16 flags;
 } dma_rxh_t;
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sbpcmcia.h b/drivers/net/wireless/bcmdhd/include/sbpcmcia.h
index aba914b..bbdbff3 100644
--- a/drivers/net/wireless/bcmdhd/include/sbpcmcia.h
+++ b/drivers/net/wireless/bcmdhd/include/sbpcmcia.h
@@ -2,13 +2,13 @@
  * BCM43XX Sonics SiliconBackplane PCMCIA core hardware definitions.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbpcmcia.h,v 13.48.12.6 2010-11-04 09:39:42 Exp $
+ * $Id: sbpcmcia.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -82,8 +82,8 @@
 #define SROM_DATAH		(0x073a / 2)
 #define SROM_ADDRL		(0x073c / 2)
 #define SROM_ADDRH		(0x073e / 2)
-#define	SROM_INFO2		(0x0772 / 2)	
-#define	SROM_INFO		(0x07be / 2)	
+#define	SROM_INFO2		(0x0772 / 2)
+#define	SROM_INFO		(0x07be / 2)
 
 
 #define SROM_IDLE		0
@@ -100,10 +100,10 @@
 
 
 
-#define SBTML_INT_ACK		0x40000		
-#define SBTML_INT_EN		0x20000		
+#define SBTML_INT_ACK		0x40000
+#define SBTML_INT_EN		0x20000
 
 
-#define SBTMH_INT_STATUS	0x40000		
+#define SBTMH_INT_STATUS	0x40000
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sbsdio.h b/drivers/net/wireless/bcmdhd/include/sbsdio.h
index 4280d5b..1bd9d3e 100644
--- a/drivers/net/wireless/bcmdhd/include/sbsdio.h
+++ b/drivers/net/wireless/bcmdhd/include/sbsdio.h
@@ -5,13 +5,13 @@
  * SDIO core support 1bit, 4 bit SDIO mode as well as SPI mode.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbsdio.h,v 13.34 2009-03-11 20:27:16 Exp $
+ * $Id: sbsdio.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_SBSDIO_H
diff --git a/drivers/net/wireless/bcmdhd/include/sbsdpcmdev.h b/drivers/net/wireless/bcmdhd/include/sbsdpcmdev.h
index 107a8b0..1c9f951 100644
--- a/drivers/net/wireless/bcmdhd/include/sbsdpcmdev.h
+++ b/drivers/net/wireless/bcmdhd/include/sbsdpcmdev.h
@@ -3,13 +3,13 @@
  * device core support
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbsdpcmdev.h,v 13.38 2009-09-22 22:56:45 Exp $
+ * $Id: sbsdpcmdev.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_sbsdpcmdev_h_
diff --git a/drivers/net/wireless/bcmdhd/include/sbsocram.h b/drivers/net/wireless/bcmdhd/include/sbsocram.h
index 1cba422..6239b53 100644
--- a/drivers/net/wireless/bcmdhd/include/sbsocram.h
+++ b/drivers/net/wireless/bcmdhd/include/sbsocram.h
@@ -2,13 +2,13 @@
  * BCM47XX Sonics SiliconBackplane embedded ram core
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbsocram.h,v 13.15 2009-10-02 16:55:44 Exp $
+ * $Id: sbsocram.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -35,7 +35,7 @@
 #define	_PADLINE(line)	pad ## line
 #define	_XSTR(line)	_PADLINE(line)
 #define	PAD		_XSTR(__LINE__)
-#endif	
+#endif
 
 
 typedef volatile struct sbsocramregs {
@@ -46,9 +46,9 @@
 	uint32	bankidx;
 	uint32	standbyctrl;
 
-	uint32	errlogstatus;	
-	uint32	errlogaddr;	
-	
+	uint32	errlogstatus;
+	uint32	errlogaddr;
+
 	uint32	cambankidx;
 	uint32	cambankstandbyctrl;
 	uint32	cambankpatchctrl;
@@ -57,7 +57,7 @@
 	uint32	cambankdatareg;
 	uint32	cambankmaskreg;
 	uint32	PAD[1];
-	uint32	bankinfo;	
+	uint32	bankinfo;
 	uint32	PAD[15];
 	uint32	extmemconfig;
 	uint32	extmemparitycsr;
@@ -66,15 +66,15 @@
 	uint32	extmemwrctrlandsize;
 	uint32	PAD[84];
 	uint32	workaround;
-	uint32	pwrctl;		
+	uint32	pwrctl;
 	uint32  PAD[133];
-	uint32  sr_control;     
-	uint32  sr_status;      
-	uint32  sr_address;     
-	uint32  sr_data;        
+	uint32  sr_control;
+	uint32  sr_status;
+	uint32  sr_address;
+	uint32  sr_data;
 } sbsocramregs_t;
 
-#endif	
+#endif
 
 
 #define	SR_COREINFO		0x00
@@ -85,7 +85,7 @@
 #define SR_PWRCTL		0x1e8
 
 
-#define	SRCI_PT_MASK		0x00070000	
+#define	SRCI_PT_MASK		0x00070000
 #define	SRCI_PT_SHIFT		16
 
 #define SRCI_PT_OCP_OCP		0
@@ -121,11 +121,11 @@
 #define	SRSC_SBYOVR_SHIFT	31
 #define	SRSC_SBYOVRVAL_MASK	0x60000000
 #define	SRSC_SBYOVRVAL_SHIFT	29
-#define	SRSC_SBYEN_MASK		0x01000000	
+#define	SRSC_SBYEN_MASK		0x01000000
 #define	SRSC_SBYEN_SHIFT	24
 
 
-#define SRPC_PMU_STBYDIS_MASK	0x00000010	
+#define SRPC_PMU_STBYDIS_MASK	0x00000010
 #define SRPC_PMU_STBYDIS_SHIFT	4
 #define SRPC_STBYOVRVAL_MASK	0x00000008
 #define SRPC_STBYOVRVAL_SHIFT	3
@@ -180,7 +180,7 @@
 
 
 #define	SOCRAM_BANKINFO_SZBASE		8192
-#define SOCRAM_BANKSIZE_SHIFT		13	
+#define SOCRAM_BANKSIZE_SHIFT		13
 
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/sdio.h b/drivers/net/wireless/bcmdhd/include/sdio.h
index ca93226..b587dc6 100644
--- a/drivers/net/wireless/bcmdhd/include/sdio.h
+++ b/drivers/net/wireless/bcmdhd/include/sdio.h
@@ -3,13 +3,13 @@
  * Protocol and standard (common) device definitions
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sdio.h,v 13.27.14.1 2010-09-07 13:37:45 Exp $
+ * $Id: sdio.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_SDIO_H
@@ -366,7 +366,7 @@
  *  SDIO Commands and responses
  *
  *  I/O only commands are:
- *      CMD0, CMD3, CMD5, CMD7, CMD15, CMD52, CMD53
+ *      CMD0, CMD3, CMD5, CMD7, CMD14, CMD15, CMD52, CMD53
  * ------------------------------------------------
  */
 
@@ -412,6 +412,7 @@
 
 #define CMD7_RCA_M		BITFIELD_MASK(16)
 #define CMD7_RCA_S		16
+
 #define CMD14_RCA_M		BITFIELD_MASK(16)
 #define CMD14_RCA_S		16
 #define CMD14_SLEEP_M		BITFIELD_MASK(1)
diff --git a/drivers/net/wireless/bcmdhd/include/sdioh.h b/drivers/net/wireless/bcmdhd/include/sdioh.h
index 3d37c7a..18e51f3 100644
--- a/drivers/net/wireless/bcmdhd/include/sdioh.h
+++ b/drivers/net/wireless/bcmdhd/include/sdioh.h
@@ -3,13 +3,13 @@
  * Register map and definitions for the Standard Host Controller
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sdioh.h,v 13.17.2.3 2011-01-08 05:28:21 Exp $
+ * $Id: sdioh.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_SDIOH_H
@@ -68,6 +68,10 @@
 #define SD_ADMA_SysAddr			0x58
 #define SD_SlotInterruptStatus		0x0FC
 #define SD_HostControllerVersion 	0x0FE
+#define	SD_GPIO_Reg			0x100
+#define	SD_GPIO_OE			0x104
+#define	SD_GPIO_Enable			0x108
+
 
 /* SD specific registers in PCI config space */
 #define SD_SlotInfo	0x40
@@ -409,4 +413,30 @@
 /* SD_SlotInterruptStatus: Offset 0x0FC , size = bytes */
 /* SD_HostControllerVersion : Offset 0x0FE , size = bytes */
 
+/* SDIO Host Control Register DMA Mode Definitions */
+#define SDIOH_SDMA_MODE			0
+#define SDIOH_ADMA1_MODE		1
+#define SDIOH_ADMA2_MODE		2
+#define SDIOH_ADMA2_64_MODE		3
+
+#define ADMA2_ATTRIBUTE_VALID		(1 << 0)	/* ADMA Descriptor line valid */
+#define ADMA2_ATTRIBUTE_END			(1 << 1)	/* End of Descriptor */
+#define ADMA2_ATTRIBUTE_INT			(1 << 2)	/* Interrupt when line is done */
+#define ADMA2_ATTRIBUTE_ACT_NOP		(0 << 4)	/* Skip current line, go to next. */
+#define ADMA2_ATTRIBUTE_ACT_RSV		(1 << 4)	/* Same as NOP */
+#define ADMA1_ATTRIBUTE_ACT_SET		(1 << 4)	/* ADMA1 Only - set transfer length */
+#define ADMA2_ATTRIBUTE_ACT_TRAN	(2 << 4)	/* Transfer Data of one descriptor line. */
+#define ADMA2_ATTRIBUTE_ACT_LINK	(3 << 4)	/* Link Descriptor */
+
+/* ADMA2 Descriptor Table Entry for 32-bit Address */
+typedef struct adma2_dscr_32b {
+	uint32 len_attr;
+	uint32 phys_addr;
+} adma2_dscr_32b_t;
+
+/* ADMA1 Descriptor Table Entry */
+typedef struct adma1_dscr {
+	uint32 phys_addr_attr;
+} adma1_dscr_t;
+
 #endif /* _SDIOH_H */
diff --git a/drivers/net/wireless/bcmdhd/include/sdiovar.h b/drivers/net/wireless/bcmdhd/include/sdiovar.h
index 2c5bcf9..24ae700 100644
--- a/drivers/net/wireless/bcmdhd/include/sdiovar.h
+++ b/drivers/net/wireless/bcmdhd/include/sdiovar.h
@@ -3,13 +3,13 @@
  * Pulled out separately so dhdu and wlu can both use it.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sdiovar.h,v 13.9 2009-12-08 22:30:15 Exp $
+ * $Id: sdiovar.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef _sdiovar_h_
diff --git a/drivers/net/wireless/bcmdhd/include/siutils.h b/drivers/net/wireless/bcmdhd/include/siutils.h
index c5a3383..631c8d7 100644
--- a/drivers/net/wireless/bcmdhd/include/siutils.h
+++ b/drivers/net/wireless/bcmdhd/include/siutils.h
@@ -3,13 +3,13 @@
  * of Broadcom HNBU chips.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: siutils.h,v 13.251.2.10 2011-02-04 05:06:32 Exp $
+ * $Id: siutils.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -31,27 +31,27 @@
 
 
 struct si_pub {
-	uint	socitype;		
+	uint	socitype;
 
-	uint	bustype;		
-	uint	buscoretype;		
-	uint	buscorerev;		
-	uint	buscoreidx;		
-	int	ccrev;			
-	uint32	cccaps;			
-	uint32  cccaps_ext;			
-	int	pmurev;			
-	uint32	pmucaps;		
-	uint	boardtype;		
-	uint	boardvendor;		
-	uint	boardflags;		
-	uint	boardflags2;		
-	uint	chip;			
-	uint	chiprev;		
-	uint	chippkg;		
-	uint32	chipst;			
-	bool	issim;			
-	uint    socirev;		
+	uint	bustype;
+	uint	buscoretype;
+	uint	buscorerev;
+	uint	buscoreidx;
+	int	ccrev;
+	uint32	cccaps;
+	uint32  cccaps_ext;
+	int	pmurev;
+	uint32	pmucaps;
+	uint	boardtype;
+	uint	boardvendor;
+	uint	boardflags;
+	uint	boardflags2;
+	uint	chip;
+	uint	chiprev;
+	uint	chippkg;
+	uint32	chipst;
+	bool	issim;
+	uint    socirev;
 	bool	pci_pr32414;
 
 };
@@ -60,34 +60,34 @@
 typedef const struct si_pub si_t;
 
 
-#define	SI_OSH		NULL	
+#define	SI_OSH		NULL
 
 #define	BADIDX		(SI_MAXCORES + 1)
 
 
-#define	XTAL			0x1	
-#define	PLL			0x2	
+#define	XTAL			0x1
+#define	PLL			0x2
 
 
-#define	CLK_FAST		0	
-#define	CLK_DYNAMIC		2	
+#define	CLK_FAST		0
+#define	CLK_DYNAMIC		2
 
 
-#define GPIO_DRV_PRIORITY	0	
-#define GPIO_APP_PRIORITY	1	
-#define GPIO_HI_PRIORITY	2	
+#define GPIO_DRV_PRIORITY	0
+#define GPIO_APP_PRIORITY	1
+#define GPIO_HI_PRIORITY	2
 
 
 #define GPIO_PULLUP		0
 #define GPIO_PULLDN		1
 
 
-#define GPIO_REGEVT		0	
-#define GPIO_REGEVT_INTMSK	1	
-#define GPIO_REGEVT_INTPOL	2	
+#define GPIO_REGEVT		0
+#define GPIO_REGEVT_INTMSK	1
+#define GPIO_REGEVT_INTPOL	2
 
 
-#define SI_DEVPATH_BUFSZ	16	
+#define SI_DEVPATH_BUFSZ	16
 
 
 #define	SI_DOATTACH	1
@@ -244,4 +244,4 @@
 
 char *si_getnvramflvar(si_t *sih, const char *name);
 
-#endif	
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/trxhdr.h b/drivers/net/wireless/bcmdhd/include/trxhdr.h
index 397006a..29c4eed 100644
--- a/drivers/net/wireless/bcmdhd/include/trxhdr.h
+++ b/drivers/net/wireless/bcmdhd/include/trxhdr.h
@@ -2,13 +2,13 @@
  * TRX image file header format.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: trxhdr.h,v 13.15.108.2 2010-11-15 17:57:30 Exp $
+ * $Id: trxhdr.h 275703 2011-08-04 20:20:27Z $
  */
 
 #ifndef	_TRX_HDR_H_
diff --git a/drivers/net/wireless/bcmdhd/include/typedefs.h b/drivers/net/wireless/bcmdhd/include/typedefs.h
index 228b5dc..cab8115 100644
--- a/drivers/net/wireless/bcmdhd/include/typedefs.h
+++ b/drivers/net/wireless/bcmdhd/include/typedefs.h
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -14,11 +14,11 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
- * $Id: typedefs.h,v 1.103.2.1 2010-05-11 18:19:28 Exp $
+ * $Id: typedefs.h 275703 2011-08-04 20:20:27Z $
  */
 
 
@@ -45,10 +45,10 @@
 #define TRUE	true
 #endif
 
-#else	
+#else
 
 
-#endif	
+#endif
 
 #if defined(__x86_64__)
 #define TYPEDEF_UINTPTR
@@ -78,21 +78,21 @@
 #ifndef TARGETENV_android
 #define TYPEDEF_USHORT
 #define TYPEDEF_ULONG
-#endif 
+#endif
 #ifdef __KERNEL__
 #include <linux/version.h>
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
 #define TYPEDEF_BOOL
-#endif	
+#endif
 
 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18))
 #include <linux/compiler.h>
 #ifdef noinline_for_stack
 #define TYPEDEF_BOOL
 #endif
-#endif	
-#endif	
-#endif  
+#endif
+#endif
+#endif
 
 
 
@@ -112,7 +112,7 @@
 #define TYPEDEF_UINT64
 #endif
 
-#endif 
+#endif
 
 #if !defined(__DJGPP__)
 
@@ -121,24 +121,24 @@
 
 
 #if !defined(LINUX_HYBRID) || defined(LINUX_PORT)
-#include <linux/types.h>	
-#endif 
+#include <linux/types.h>
+#endif
 
 #else
 
 
 #include <sys/types.h>
 
-#endif 
+#endif
 
-#endif 
+#endif
 
 
 
 
 #define USE_TYPEDEF_DEFAULTS
 
-#endif 
+#endif
 
 
 
@@ -222,11 +222,11 @@
 
 #if defined(FLOAT32)
 typedef float32 float_t;
-#else 
+#else
 typedef float64 float_t;
 #endif
 
-#endif 
+#endif
 
 
 
@@ -235,7 +235,7 @@
 #endif
 
 #ifndef TRUE
-#define TRUE	1  
+#define TRUE	1
 #endif
 
 #ifndef NULL
@@ -247,10 +247,10 @@
 #endif
 
 #ifndef ON
-#define	ON	1  
+#define	ON	1
 #endif
 
-#define	AUTO	(-1) 
+#define	AUTO	(-1)
 
 
 
@@ -266,7 +266,7 @@
 	#define BWL_COMPILER_ARMCC
 #else
 	#error "Unknown compiler!"
-#endif 
+#endif
 
 
 #ifndef INLINE
@@ -278,8 +278,8 @@
 		#define INLINE	__inline
 	#else
 		#define INLINE
-	#endif 
-#endif 
+	#endif
+#endif
 
 #undef TYPEDEF_BOOL
 #undef TYPEDEF_UCHAR
@@ -299,11 +299,11 @@
 #undef TYPEDEF_FLOAT64
 #undef TYPEDEF_FLOAT_T
 
-#endif 
+#endif
 
 
 #define UNUSED_PARAMETER(x) (void)(x)
 
 
 #include <bcmdefs.h>
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/include/wlfc_proto.h b/drivers/net/wireless/bcmdhd/include/wlfc_proto.h
index 7230d3b..0f95bc2 100644
--- a/drivers/net/wireless/bcmdhd/include/wlfc_proto.h
+++ b/drivers/net/wireless/bcmdhd/include/wlfc_proto.h
@@ -1,12 +1,12 @@
 /*
 * Copyright (C) 1999-2011, Broadcom Corporation
-* 
+*
 *         Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2 (the "GPL"),
 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
 * following added to such license:
-* 
+*
 *      As a special exception, the copyright holders of this software give you
 * permission to link this software with independent modules, and to copy and
 * distribute the resulting executable under terms of your choice, provided that
@@ -14,11 +14,11 @@
 * the license of that module.  An independent module is a module which is not
 * derived from this software.  The special exception does not apply to any
 * modifications of the software.
-* 
+*
 *      Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a license
 * other than the GPL, without Broadcom's express prior written consent.
-* $Id: wlfc_proto.h,v 1.1.6.2 2010-05-08 01:30:41 Exp $
+* $Id: wlfc_proto.h 275703 2011-08-04 20:20:27Z $
 *
 */
 #ifndef __wlfc_proto_definitions_h__
@@ -169,7 +169,7 @@
 #define WLFC_CTL_PKTFLAG_DISCARD		0
 /* D11 suppressed a packet */
 #define WLFC_CTL_PKTFLAG_D11SUPPRESS	1
-/* WL firmware suppressed a packet because MAC is 
+/* WL firmware suppressed a packet because MAC is
 	already in PSMode (short time window)
 */
 #define WLFC_CTL_PKTFLAG_WLSUPPRESS		2
diff --git a/drivers/net/wireless/bcmdhd/include/wlioctl.h b/drivers/net/wireless/bcmdhd/include/wlioctl.h
index 9357552..8ab974b 100644
--- a/drivers/net/wireless/bcmdhd/include/wlioctl.h
+++ b/drivers/net/wireless/bcmdhd/include/wlioctl.h
@@ -5,13 +5,13 @@
  * Definitions subject to change without notice.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -19,12 +19,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wlioctl.h,v 1.767.2.38 2011-02-01 23:04:28 Exp $
+ * $Id: wlioctl.h 287802 2011-10-04 22:44:46Z $
  */
 
 
@@ -86,75 +86,75 @@
 
 
 
-#define LEGACY2_WL_BSS_INFO_VERSION 108     
+#define LEGACY2_WL_BSS_INFO_VERSION 108
 
 
 typedef struct wl_bss_info_108 {
-	uint32      version;        
-	uint32      length;         
+	uint32      version;
+	uint32      length;
 	struct ether_addr BSSID;
-	uint16      beacon_period;      
-	uint16      capability;     
+	uint16      beacon_period;
+	uint16      capability;
 	uint8       SSID_len;
 	uint8       SSID[32];
 	struct {
-		uint    count;          
-		uint8   rates[16];      
-	} rateset;              
-	chanspec_t  chanspec;       
-	uint16      atim_window;        
-	uint8       dtim_period;        
-	int16       RSSI;           
-	int8        phy_noise;      
+		uint    count;
+		uint8   rates[16];
+	} rateset;
+	chanspec_t  chanspec;
+	uint16      atim_window;
+	uint8       dtim_period;
+	int16       RSSI;
+	int8        phy_noise;
 
-	uint8       n_cap;          
-	uint32      nbss_cap;       
-	uint8       ctl_ch;         
-	uint32      reserved32[1];      
-	uint8       flags;          
-	uint8       reserved[3];        
-	uint8       basic_mcs[MCSSET_LEN];  
+	uint8       n_cap;
+	uint32      nbss_cap;
+	uint8       ctl_ch;
+	uint32      reserved32[1];
+	uint8       flags;
+	uint8       reserved[3];
+	uint8       basic_mcs[MCSSET_LEN];
 
-	uint16      ie_offset;      
-	uint32      ie_length;      
-	
-	
+	uint16      ie_offset;
+	uint32      ie_length;
+
+
 } wl_bss_info_108_t;
 
-#define WL_BSS_INFO_VERSION 109     
+#define WL_BSS_INFO_VERSION 109
 
 
 typedef struct wl_bss_info {
-	uint32      version;        
-	uint32      length;         
+	uint32      version;
+	uint32      length;
 	struct ether_addr BSSID;
-	uint16      beacon_period;      
-	uint16      capability;     
+	uint16      beacon_period;
+	uint16      capability;
 	uint8       SSID_len;
 	uint8       SSID[32];
 	struct {
-		uint    count;          
-		uint8   rates[16];      
-	} rateset;              
-	chanspec_t  chanspec;       
-	uint16      atim_window;        
-	uint8       dtim_period;        
-	int16       RSSI;           
-	int8        phy_noise;      
+		uint    count;
+		uint8   rates[16];
+	} rateset;
+	chanspec_t  chanspec;
+	uint16      atim_window;
+	uint8       dtim_period;
+	int16       RSSI;
+	int8        phy_noise;
 
-	uint8       n_cap;          
-	uint32      nbss_cap;       
-	uint8       ctl_ch;         
-	uint32      reserved32[1];      
-	uint8       flags;          
-	uint8       reserved[3];        
-	uint8       basic_mcs[MCSSET_LEN];  
+	uint8       n_cap;
+	uint32      nbss_cap;
+	uint8       ctl_ch;
+	uint32      reserved32[1];
+	uint8       flags;
+	uint8       reserved[3];
+	uint8       basic_mcs[MCSSET_LEN];
 
-	uint16      ie_offset;      
-	uint32      ie_length;      
-	int16       SNR;            
-	
-	
+	uint16      ie_offset;
+	uint32      ie_length;
+	int16       SNR;
+
+
 } wl_bss_info_t;
 
 typedef struct wl_bsscfg {
@@ -186,22 +186,23 @@
 #define WL_BSSTYPE_ANY   2
 
 
-#define WL_SCANFLAGS_PASSIVE 0x01       
-#define WL_SCANFLAGS_RESERVED 0x02      
-#define WL_SCANFLAGS_PROHIBITED 0x04    
+#define WL_SCANFLAGS_PASSIVE 0x01
+#define WL_SCANFLAGS_RESERVED 0x02
+#define WL_SCANFLAGS_PROHIBITED 0x04
 
 #define WL_SCAN_PARAMS_SSID_MAX 	10
+
 typedef struct wl_scan_params {
-	wlc_ssid_t ssid;        
-	struct ether_addr bssid;    
-	int8 bss_type;          
-	uint8 scan_type;        
-	int32 nprobes;          
-	int32 active_time;      
-	int32 passive_time;     
-	int32 home_time;        
-	int32 channel_num;      
-	uint16 channel_list[1];     
+	wlc_ssid_t ssid;
+	struct ether_addr bssid;
+	int8 bss_type;
+	uint8 scan_type;
+	int32 nprobes;
+	int32 active_time;
+	int32 passive_time;
+	int32 home_time;
+	int32 channel_num;
+	uint16 channel_list[1];
 } wl_scan_params_t;
 
 
@@ -260,7 +261,7 @@
 	struct iscan_buf * next;
 	char   iscan_buf[WLC_IW_ISCAN_MAXLEN];
 } iscan_buf_t;
-#endif 
+#endif
 
 #define ESCAN_REQ_VERSION 1
 
@@ -299,32 +300,32 @@
 	struct ether_addr mac;
 } wl_probe_params_t;
 
-#define WL_NUMRATES     16  
+#define WL_NUMRATES     16
 typedef struct wl_rateset {
-	uint32  count;          
-	uint8   rates[WL_NUMRATES]; 
+	uint32  count;
+	uint8   rates[WL_NUMRATES];
 } wl_rateset_t;
 
 typedef struct wl_rateset_args {
-	uint32  count;          
-	uint8   rates[WL_NUMRATES]; 
-	uint8   mcs[MCSSET_LEN];        
+	uint32  count;
+	uint8   rates[WL_NUMRATES];
+	uint8   mcs[MCSSET_LEN];
 } wl_rateset_args_t;
 
 
 typedef struct wl_uint32_list {
-	
+
 	uint32 count;
-	
+
 	uint32 element[1];
 } wl_uint32_list_t;
 
 
 typedef struct wl_assoc_params {
-	struct ether_addr bssid;    
-	uint16 bssid_cnt;       
-	int32 chanspec_num;     
-	chanspec_t chanspec_list[1];    
+	struct ether_addr bssid;
+	uint16 bssid_cnt;
+	int32 chanspec_num;
+	chanspec_t chanspec_list[1];
 } wl_assoc_params_t;
 #define WL_ASSOC_PARAMS_FIXED_SIZE  (sizeof(wl_assoc_params_t) - sizeof(chanspec_t))
 
@@ -339,24 +340,24 @@
 
 typedef struct wl_join_params {
 	wlc_ssid_t ssid;
-	wl_assoc_params_t params;   
+	wl_assoc_params_t params;
 } wl_join_params_t;
 #define WL_JOIN_PARAMS_FIXED_SIZE   (sizeof(wl_join_params_t) - sizeof(chanspec_t))
 
 
 typedef struct wl_join_scan_params {
-	uint8 scan_type;                
-	int32 nprobes;                  
-	int32 active_time;              
-	int32 passive_time;             
-	int32 home_time;                
+	uint8 scan_type;
+	int32 nprobes;
+	int32 active_time;
+	int32 passive_time;
+	int32 home_time;
 } wl_join_scan_params_t;
 
 
 typedef struct wl_extjoin_params {
-	wlc_ssid_t ssid;                
+	wlc_ssid_t ssid;
 	wl_join_scan_params_t scan;
-	wl_join_assoc_params_t assoc;   
+	wl_join_assoc_params_t assoc;
 } wl_extjoin_params_t;
 #define WL_EXTJOIN_PARAMS_FIXED_SIZE    (sizeof(wl_extjoin_params_t) - sizeof(chanspec_t))
 
@@ -366,87 +367,87 @@
 } chanspec_list_t;
 
 
-#define NRATE_MCS_INUSE 0x00000080  
-#define NRATE_RATE_MASK 0x0000007f  
-#define NRATE_STF_MASK  0x0000ff00  
-#define NRATE_STF_SHIFT 8       
-#define NRATE_OVERRIDE  0x80000000  
-#define NRATE_OVERRIDE_MCS_ONLY 0x40000000 
-#define NRATE_SGI_MASK  0x00800000      
-#define NRATE_SGI_SHIFT 23              
-#define NRATE_LDPC_CODING 0x00400000    
-#define NRATE_LDPC_SHIFT 22             
+#define NRATE_MCS_INUSE 0x00000080
+#define NRATE_RATE_MASK 0x0000007f
+#define NRATE_STF_MASK  0x0000ff00
+#define NRATE_STF_SHIFT 8
+#define NRATE_OVERRIDE  0x80000000
+#define NRATE_OVERRIDE_MCS_ONLY 0x40000000
+#define NRATE_SGI_MASK  0x00800000
+#define NRATE_SGI_SHIFT 23
+#define NRATE_LDPC_CODING 0x00400000
+#define NRATE_LDPC_SHIFT 22
 
-#define NRATE_STF_SISO  0       
-#define NRATE_STF_CDD   1       
-#define NRATE_STF_STBC  2       
-#define NRATE_STF_SDM   3       
+#define NRATE_STF_SISO  0
+#define NRATE_STF_CDD   1
+#define NRATE_STF_STBC  2
+#define NRATE_STF_SDM   3
 
-#define ANTENNA_NUM_1   1       
+#define ANTENNA_NUM_1   1
 #define ANTENNA_NUM_2   2
 #define ANTENNA_NUM_3   3
 #define ANTENNA_NUM_4   4
 
-#define ANT_SELCFG_AUTO     0x80    
-#define ANT_SELCFG_MASK     0x33    
-#define ANT_SELCFG_MAX      4   
-#define ANT_SELCFG_TX_UNICAST   0   
-#define ANT_SELCFG_RX_UNICAST   1   
-#define ANT_SELCFG_TX_DEF   2   
-#define ANT_SELCFG_RX_DEF   3   
+#define ANT_SELCFG_AUTO     0x80
+#define ANT_SELCFG_MASK     0x33
+#define ANT_SELCFG_MAX      4
+#define ANT_SELCFG_TX_UNICAST   0
+#define ANT_SELCFG_RX_UNICAST   1
+#define ANT_SELCFG_TX_DEF   2
+#define ANT_SELCFG_RX_DEF   3
 
-#define MAX_STREAMS_SUPPORTED   4   
+#define MAX_STREAMS_SUPPORTED   4
 
 typedef struct {
-	uint8 ant_config[ANT_SELCFG_MAX];   
-	uint8 num_antcfg;   
+	uint8 ant_config[ANT_SELCFG_MAX];
+	uint8 num_antcfg;
 } wlc_antselcfg_t;
 
-#define HIGHEST_SINGLE_STREAM_MCS   7 
+#define HIGHEST_SINGLE_STREAM_MCS   7
 
-#define MAX_CCA_CHANNELS 38 
-#define MAX_CCA_SECS     60 
+#define MAX_CCA_CHANNELS 38
+#define MAX_CCA_SECS     60
 
-#define IBSS_MED        15  
-#define IBSS_HI         25  
+#define IBSS_MED        15
+#define IBSS_HI         25
 #define OBSS_MED        12
 #define OBSS_HI         25
 #define INTERFER_MED    5
 #define INTERFER_HI     10
 
-#define  CCA_FLAG_2G_ONLY       0x01    
-#define  CCA_FLAG_5G_ONLY       0x02    
-#define  CCA_FLAG_IGNORE_DURATION   0x04    
+#define  CCA_FLAG_2G_ONLY       0x01
+#define  CCA_FLAG_5G_ONLY       0x02
+#define  CCA_FLAG_IGNORE_DURATION   0x04
 #define  CCA_FLAGS_PREFER_1_6_11    0x10
-#define  CCA_FLAG_IGNORE_INTERFER   0x20 
+#define  CCA_FLAG_IGNORE_INTERFER   0x20
 
-#define CCA_ERRNO_BAND      1   
-#define CCA_ERRNO_DURATION  2   
-#define CCA_ERRNO_PREF_CHAN 3   
-#define CCA_ERRNO_INTERFER  4   
-#define CCA_ERRNO_TOO_FEW   5   
+#define CCA_ERRNO_BAND      1
+#define CCA_ERRNO_DURATION  2
+#define CCA_ERRNO_PREF_CHAN 3
+#define CCA_ERRNO_INTERFER  4
+#define CCA_ERRNO_TOO_FEW   5
 
 typedef struct {
-	uint32 duration;    
-	uint32 congest_ibss;    
-				
-	uint32 congest_obss;    
-	uint32 interference;    
-	uint32 timestamp;   
+	uint32 duration;
+	uint32 congest_ibss;
+
+	uint32 congest_obss;
+	uint32 interference;
+	uint32 timestamp;
 } cca_congest_t;
 
 typedef struct {
-	chanspec_t chanspec;    
-	uint8 num_secs;     
-	cca_congest_t  secs[1]; 
+	chanspec_t chanspec;
+	uint8 num_secs;
+	cca_congest_t  secs[1];
 } cca_congest_channel_req_t;
 
-#define WLC_CNTRY_BUF_SZ    4       
+#define WLC_CNTRY_BUF_SZ    4
 
 typedef struct wl_country {
-	char country_abbrev[WLC_CNTRY_BUF_SZ];  
-	int32 rev;              
-	char ccode[WLC_CNTRY_BUF_SZ];       
+	char country_abbrev[WLC_CNTRY_BUF_SZ];
+	int32 rev;
+	char ccode[WLC_CNTRY_BUF_SZ];
 } wl_country_t;
 
 typedef struct wl_channels_in_country {
@@ -480,18 +481,18 @@
 	int8    type;
 	int8    flags;
 	chanspec_t  chanspec;
-	uint32  token;      
-	uint32  tsf_h;      
-	uint32  tsf_l;      
-	uint32  dur;        
+	uint32  token;
+	uint32  tsf_h;
+	uint32  tsf_l;
+	uint32  dur;
 } wl_rm_req_elt_t;
 
 typedef struct wl_rm_req {
-	uint32  token;      
-	uint32  count;      
-	void    *cb;        
-	void    *cb_arg;    
-	wl_rm_req_elt_t req[1]; 
+	uint32  token;
+	uint32  count;
+	void    *cb;
+	void    *cb_arg;
+	wl_rm_req_elt_t req[1];
 } wl_rm_req_t;
 #define WL_RM_REQ_FIXED_LEN OFFSETOF(wl_rm_req_t, req)
 
@@ -499,14 +500,14 @@
 	int8    type;
 	int8    flags;
 	chanspec_t  chanspec;
-	uint32  token;      
-	uint32  tsf_h;      
-	uint32  tsf_l;      
-	uint32  dur;        
-	uint32  len;        
-	uint8   data[1];    
+	uint32  token;
+	uint32  tsf_h;
+	uint32  tsf_l;
+	uint32  dur;
+	uint32  len;
+	uint8   data[1];
 } wl_rm_rep_elt_t;
-#define WL_RM_REP_ELT_FIXED_LEN 24  
+#define WL_RM_REP_ELT_FIXED_LEN 24
 
 #define WL_RPI_REP_BIN_NUM 8
 typedef struct wl_rm_rpi_rep {
@@ -515,15 +516,15 @@
 } wl_rm_rpi_rep_t;
 
 typedef struct wl_rm_rep {
-	uint32  token;      
-	uint32  len;        
-	wl_rm_rep_elt_t rep[1]; 
+	uint32  token;
+	uint32  len;
+	wl_rm_rep_elt_t rep[1];
 } wl_rm_rep_t;
 #define WL_RM_REP_FIXED_LEN 8
 
 
 typedef enum sup_auth_status {
-	
+
 	WLC_SUP_DISCONNECTED = 0,
 	WLC_SUP_CONNECTING,
 	WLC_SUP_IDREQUIRED,
@@ -534,16 +535,16 @@
 	WLC_SUP_TIMEOUT,
 	WLC_SUP_LAST_BASIC_STATE,
 
-	
-	
+
+
 	WLC_SUP_KEYXCHANGE_WAIT_M1 = WLC_SUP_AUTHENTICATED,
-	
+
 	WLC_SUP_KEYXCHANGE_PREP_M2 = WLC_SUP_KEYXCHANGE,
-	
+
 	WLC_SUP_KEYXCHANGE_WAIT_M3 = WLC_SUP_LAST_BASIC_STATE,
-	WLC_SUP_KEYXCHANGE_PREP_M4, 
-	WLC_SUP_KEYXCHANGE_WAIT_G1, 
-	WLC_SUP_KEYXCHANGE_PREP_G2  
+	WLC_SUP_KEYXCHANGE_PREP_M4,
+	WLC_SUP_KEYXCHANGE_WAIT_G1,
+	WLC_SUP_KEYXCHANGE_PREP_G2
 } sup_auth_status_t;
 
 
@@ -555,36 +556,39 @@
 #define CRYPTO_ALGO_AES_OCB_MSDU    5
 #define CRYPTO_ALGO_AES_OCB_MPDU    6
 #define CRYPTO_ALGO_NALG        7
-#define CRYPTO_ALGO_PMK			12
+#ifdef WAPI
+#define CRYPTO_ALGO_SMS4        11
+#endif /* WAPI */
+#define CRYPTO_ALGO_PMK         12
 
 #define WSEC_GEN_MIC_ERROR  0x0001
 #define WSEC_GEN_REPLAY     0x0002
 #define WSEC_GEN_ICV_ERROR  0x0004
 
-#define WL_SOFT_KEY (1 << 0)    
-#define WL_PRIMARY_KEY  (1 << 1)    
-#define WL_KF_RES_4 (1 << 4)    
-#define WL_KF_RES_5 (1 << 5)    
-#define WL_IBSS_PEER_GROUP_KEY  (1 << 6)    
+#define WL_SOFT_KEY (1 << 0)
+#define WL_PRIMARY_KEY  (1 << 1)
+#define WL_KF_RES_4 (1 << 4)
+#define WL_KF_RES_5 (1 << 5)
+#define WL_IBSS_PEER_GROUP_KEY  (1 << 6)
 
 typedef struct wl_wsec_key {
-	uint32      index;      
-	uint32      len;        
-	uint8       data[DOT11_MAX_KEY_SIZE];   
+	uint32      index;
+	uint32      len;
+	uint8       data[DOT11_MAX_KEY_SIZE];
 	uint32      pad_1[18];
-	uint32      algo;       
-	uint32      flags;      
+	uint32      algo;
+	uint32      flags;
 	uint32      pad_2[2];
 	int     pad_3;
-	int     iv_initialized; 
+	int     iv_initialized;
 	int     pad_4;
-	
+
 	struct {
-		uint32  hi;     
-		uint16  lo;     
+		uint32  hi;
+		uint16  lo;
 	} rxiv;
 	uint32      pad_5[2];
-	struct ether_addr ea;       
+	struct ether_addr ea;
 } wl_wsec_key_t;
 
 #define WSEC_MIN_PSK_LEN    8
@@ -595,9 +599,9 @@
 
 
 typedef struct {
-	ushort  key_len;        
-	ushort  flags;          
-	uint8   key[WSEC_MAX_PSK_LEN];  
+	ushort  key_len;
+	ushort  flags;
+	uint8   key[WSEC_MAX_PSK_LEN];
 } wsec_pmk_t;
 
 
@@ -605,23 +609,32 @@
 #define TKIP_ENABLED        0x0002
 #define AES_ENABLED     0x0004
 #define WSEC_SWFLAG     0x0008
-#define SES_OW_ENABLED      0x0040  
+#define SES_OW_ENABLED      0x0040
+#ifdef WAPI
+#define SMS4_ENABLED		0x0100
+#endif /* WAPI */
 
+#define WPA_AUTH_DISABLED   0x0000
+#define WPA_AUTH_NONE       0x0001
+#define WPA_AUTH_UNSPECIFIED    0x0002
+#define WPA_AUTH_PSK        0x0004
 
-#define WPA_AUTH_DISABLED   0x0000  
-#define WPA_AUTH_NONE       0x0001  
-#define WPA_AUTH_UNSPECIFIED    0x0002  
-#define WPA_AUTH_PSK        0x0004  
- 
-#define WPA2_AUTH_UNSPECIFIED   0x0040  
-#define WPA2_AUTH_PSK       0x0080  
-#define BRCM_AUTH_PSK           0x0100  
-#define BRCM_AUTH_DPT       0x0200  
+#define WPA2_AUTH_UNSPECIFIED   0x0040
+#define WPA2_AUTH_PSK       0x0080
+#define BRCM_AUTH_PSK           0x0100
+#define BRCM_AUTH_DPT       0x0200
+
+#ifdef WAPI
+#define WPA_AUTH_WAPI           0x0400
+#define WAPI_AUTH_NONE      WPA_AUTH_NONE   /* none (IBSS) */
+#define WAPI_AUTH_UNSPECIFIED   0x0400  /* over AS */
+#define WAPI_AUTH_PSK       0x0800  /* Pre-shared key */
+#endif /* WAPI */
+
 #define WPA2_AUTH_MFP           0x1000
 #define WPA2_AUTH_TPK		0x2000
 #define WPA2_AUTH_FT		0x4000
 
-
 #define MAXPMKID        16
 
 typedef struct _pmkid {
@@ -658,23 +671,23 @@
 
 
 typedef struct {
-	uint16          ver;        
-	uint16          len;        
-	uint16          cap;        
-	uint32          flags;      
-	uint32          idle;       
-	struct ether_addr   ea;     
-	wl_rateset_t        rateset;    
-	uint32          in;     
-	uint32          listen_interval_inms; 
-	uint32          tx_pkts;    
-	uint32          tx_failures;    
-	uint32          rx_ucast_pkts;  
-	uint32          rx_mcast_pkts;  
-	uint32          tx_rate;    
-	uint32          rx_rate;    
-	uint32          rx_decrypt_succeeds;    
-	uint32          rx_decrypt_failures;    
+	uint16          ver;
+	uint16          len;
+	uint16          cap;
+	uint32          flags;
+	uint32          idle;
+	struct ether_addr   ea;
+	wl_rateset_t        rateset;
+	uint32          in;
+	uint32          listen_interval_inms;
+	uint32          tx_pkts;
+	uint32          tx_failures;
+	uint32          rx_ucast_pkts;
+	uint32          rx_mcast_pkts;
+	uint32          tx_rate;
+	uint32          rx_rate;
+	uint32          rx_decrypt_succeeds;
+	uint32          rx_decrypt_failures;
 } sta_info_t;
 
 #define WL_OLD_STAINFO_SIZE OFFSETOF(sta_info_t, tx_pkts)
@@ -682,23 +695,23 @@
 #define WL_STA_VER      3
 
 
-#define WL_STA_BRCM     0x1     
-#define WL_STA_WME      0x2     
+#define WL_STA_BRCM     0x1
+#define WL_STA_WME      0x2
 #define WL_STA_ABCAP        0x4
-#define WL_STA_AUTHE        0x8     
-#define WL_STA_ASSOC        0x10        
-#define WL_STA_AUTHO        0x20        
-#define WL_STA_WDS      0x40        
-#define WL_STA_WDS_LINKUP   0x80        
-#define WL_STA_PS       0x100       
-#define WL_STA_APSD_BE      0x200       
-#define WL_STA_APSD_BK      0x400       
-#define WL_STA_APSD_VI      0x800       
-#define WL_STA_APSD_VO      0x1000      
-#define WL_STA_N_CAP        0x2000      
-#define WL_STA_SCBSTATS     0x4000      
+#define WL_STA_AUTHE        0x8
+#define WL_STA_ASSOC        0x10
+#define WL_STA_AUTHO        0x20
+#define WL_STA_WDS      0x40
+#define WL_STA_WDS_LINKUP   0x80
+#define WL_STA_PS       0x100
+#define WL_STA_APSD_BE      0x200
+#define WL_STA_APSD_BK      0x400
+#define WL_STA_APSD_VI      0x800
+#define WL_STA_APSD_VO      0x1000
+#define WL_STA_N_CAP        0x2000
+#define WL_STA_SCBSTATS     0x4000
 
-#define WL_WDS_LINKUP       WL_STA_WDS_LINKUP   
+#define WL_WDS_LINKUP       WL_STA_WDS_LINKUP
 
 
 #define WLC_TXFILTER_OVERRIDE_DISABLED  0
@@ -725,8 +738,8 @@
 
 
 struct maclist {
-	uint count;         
-	struct ether_addr ea[1];    
+	uint count;
+	struct ether_addr ea[1];
 };
 
 
@@ -735,7 +748,7 @@
 	uint rx_bad_pkt;
 	uint tx_good_pkt;
 	uint tx_bad_pkt;
-	uint rx_ocast_good_pkt; 
+	uint rx_ocast_good_pkt;
 } get_pktcnt_t;
 
 #define WL_IOCTL_ACTION_GET				0x0
@@ -748,37 +761,37 @@
 
 
 typedef struct wl_ioctl {
-	uint cmd;   
-	void *buf;  
-	uint len;   
-	uint8 set;		
-	uint used;  
-	uint needed;    
+	uint cmd;
+	void *buf;
+	uint len;
+	uint8 set;
+	uint used;
+	uint needed;
 } wl_ioctl_t;
 
 
-#define ioctl_subtype   set     
-#define ioctl_pid   used        
-#define ioctl_status    needed      
+#define ioctl_subtype   set
+#define ioctl_pid   used
+#define ioctl_status    needed
 
 
 typedef struct wlc_rev_info {
-	uint        vendorid;   
-	uint        deviceid;   
-	uint        radiorev;   
-	uint        chiprev;    
-	uint        corerev;    
-	uint        boardid;    
-	uint        boardvendor;    
-	uint        boardrev;   
-	uint        driverrev;  
-	uint        ucoderev;   
-	uint        bus;        
-	uint        chipnum;    
-	uint        phytype;    
-	uint        phyrev;     
-	uint        anarev;     
-	uint        chippkg;    
+	uint        vendorid;
+	uint        deviceid;
+	uint        radiorev;
+	uint        chiprev;
+	uint        corerev;
+	uint        boardid;
+	uint        boardvendor;
+	uint        boardrev;
+	uint        driverrev;
+	uint        ucoderev;
+	uint        bus;
+	uint        chipnum;
+	uint        phytype;
+	uint        phyrev;
+	uint        anarev;
+	uint        chippkg;
 } wlc_rev_info_t;
 
 #define WL_REV_INFO_LEGACY_LENGTH   48
@@ -813,14 +826,14 @@
 
 #define WLC_IOCTL_VERSION   1
 
-#define WLC_IOCTL_MAXLEN        8192    
-#define WLC_IOCTL_SMLEN         256 
-#define WLC_IOCTL_MEDLEN        1536    
+#define WLC_IOCTL_MAXLEN        8192
+#define WLC_IOCTL_SMLEN         256
+#define WLC_IOCTL_MEDLEN        1536
 #ifdef WLC_HIGH_ONLY
-#define WLC_SAMPLECOLLECT_MAXLEN    1024    
+#define WLC_SAMPLECOLLECT_MAXLEN    1024
 #else
-#define WLC_SAMPLECOLLECT_MAXLEN    10240   
-#endif 
+#define WLC_SAMPLECOLLECT_MAXLEN    10240
+#endif
 
 
 #define WLC_GET_MAGIC               0
@@ -836,12 +849,12 @@
 #define WLC_SET_PROMISC             10
 #define WLC_OVERLAY_IOCTL           11
 #define WLC_GET_RATE                12
- 
+
 #define WLC_GET_INSTANCE            14
- 
- 
- 
- 
+
+
+
+
 #define WLC_GET_INFRA               19
 #define WLC_SET_INFRA               20
 #define WLC_GET_AUTH                21
@@ -851,7 +864,7 @@
 #define WLC_GET_SSID                25
 #define WLC_SET_SSID                26
 #define WLC_RESTART             27
- 
+
 #define WLC_GET_CHANNEL             29
 #define WLC_SET_CHANNEL             30
 #define WLC_GET_SRL             31
@@ -867,8 +880,8 @@
 #define WLC_SET_RATE_PARAMS         41
 #define WLC_GET_FIXRATE             42
 #define WLC_SET_FIXRATE             43
- 
- 
+
+
 #define WLC_GET_KEY             44
 #define WLC_SET_KEY             45
 #define WLC_GET_REGULATORY          46
@@ -885,20 +898,20 @@
 #define WLC_SET_ROAM_DELTA          57
 #define WLC_GET_ROAM_SCAN_PERIOD        58
 #define WLC_SET_ROAM_SCAN_PERIOD        59
-#define WLC_EVM                 60  
+#define WLC_EVM                 60
 #define WLC_GET_TXANT               61
 #define WLC_SET_TXANT               62
 #define WLC_GET_ANTDIV              63
 #define WLC_SET_ANTDIV              64
- 
- 
+
+
 #define WLC_GET_CLOSED              67
 #define WLC_SET_CLOSED              68
 #define WLC_GET_MACLIST             69
 #define WLC_SET_MACLIST             70
 #define WLC_GET_RATESET             71
 #define WLC_SET_RATESET             72
- 
+
 #define WLC_LONGTRAIN               74
 #define WLC_GET_BCNPRD              75
 #define WLC_SET_BCNPRD              76
@@ -914,11 +927,11 @@
 #define WLC_SET_PM              86
 #define WLC_GET_WAKE                87
 #define WLC_SET_WAKE                88
- 
-#define WLC_GET_FORCELINK           90  
-#define WLC_SET_FORCELINK           91  
-#define WLC_FREQ_ACCURACY           92  
-#define WLC_CARRIER_SUPPRESS            93  
+
+#define WLC_GET_FORCELINK           90
+#define WLC_SET_FORCELINK           91
+#define WLC_FREQ_ACCURACY           92
+#define WLC_CARRIER_SUPPRESS            93
 #define WLC_GET_PHYREG              94
 #define WLC_SET_PHYREG              95
 #define WLC_GET_RADIOREG            96
@@ -929,7 +942,7 @@
 #define WLC_R_REG               101
 #define WLC_W_REG               102
 
- 
+
 #define WLC_GET_MACMODE             105
 #define WLC_SET_MACMODE             106
 #define WLC_GET_MONITOR             107
@@ -939,7 +952,7 @@
 #define WLC_GET_LEGACY_ERP          111
 #define WLC_SET_LEGACY_ERP          112
 #define WLC_GET_RX_ANT              113
-#define WLC_GET_CURR_RATESET            114 
+#define WLC_GET_CURR_RATESET            114
 #define WLC_GET_SCANSUPPRESS            115
 #define WLC_SET_SCANSUPPRESS            116
 #define WLC_GET_AP              117
@@ -978,8 +991,8 @@
 #define WLC_GET_GMODE_PROTECTION_OVERRIDE   150
 #define WLC_SET_GMODE_PROTECTION_OVERRIDE   151
 #define WLC_UPGRADE             152
- 
- 
+
+
 #define WLC_GET_IGNORE_BCNS         155
 #define WLC_SET_IGNORE_BCNS         156
 #define WLC_GET_SCB_TIMEOUT         157
@@ -998,16 +1011,16 @@
 #define WLC_GET_TSSI                170
 #define WLC_GET_SUP_RATESET_OVERRIDE        171
 #define WLC_SET_SUP_RATESET_OVERRIDE        172
- 
- 
- 
- 
- 
+
+
+
+
+
 #define WLC_GET_PROTECTION_CONTROL      178
 #define WLC_SET_PROTECTION_CONTROL      179
 #define WLC_GET_PHYLIST             180
-#define WLC_ENCRYPT_STRENGTH            181 
-#define WLC_DECRYPT_STATUS          182 
+#define WLC_ENCRYPT_STRENGTH            181
+#define WLC_DECRYPT_STATUS          182
 #define WLC_GET_KEY_SEQ             183
 #define WLC_GET_SCAN_CHANNEL_TIME       184
 #define WLC_SET_SCAN_CHANNEL_TIME       185
@@ -1021,10 +1034,10 @@
 #define WLC_SET_PRB_RESP_TIMEOUT        193
 #define WLC_GET_ATTEN               194
 #define WLC_SET_ATTEN               195
-#define WLC_GET_SHMEM               196 
-#define WLC_SET_SHMEM               197 
- 
- 
+#define WLC_GET_SHMEM               196
+#define WLC_SET_SHMEM               197
+
+
 #define WLC_SET_WSEC_TEST           200
 #define WLC_SCB_DEAUTHENTICATE_FOR_REASON   201
 #define WLC_TKIP_COUNTERMEASURES        202
@@ -1058,11 +1071,11 @@
 #define WLC_GET_WET             230
 #define WLC_SET_WET             231
 #define WLC_GET_PUB             232
- 
- 
+
+
 #define WLC_GET_KEY_PRIMARY         235
 #define WLC_SET_KEY_PRIMARY         236
- 
+
 #define WLC_GET_ACI_ARGS            238
 #define WLC_SET_ACI_ARGS            239
 #define WLC_UNSET_CALLBACK          240
@@ -1071,7 +1084,7 @@
 #define WLC_SET_RADAR               243
 #define WLC_SET_SPECT_MANAGMENT         244
 #define WLC_GET_SPECT_MANAGMENT         245
-#define WLC_WDS_GET_REMOTE_HWADDR       246 
+#define WLC_WDS_GET_REMOTE_HWADDR       246
 #define WLC_WDS_GET_WPA_SUP         247
 #define WLC_SET_CS_SCAN_TIMER           248
 #define WLC_GET_CS_SCAN_TIMER           249
@@ -1087,9 +1100,9 @@
 #define WLC_LEGACY_LINK_BEHAVIOR        259
 #define WLC_GET_CHANNELS_IN_COUNTRY     260
 #define WLC_GET_COUNTRY_LIST            261
-#define WLC_GET_VAR             262 
-#define WLC_SET_VAR             263 
-#define WLC_NVRAM_GET               264 
+#define WLC_GET_VAR             262
+#define WLC_SET_VAR             263
+#define WLC_NVRAM_GET               264
 #define WLC_NVRAM_SET               265
 #define WLC_NVRAM_DUMP              266
 #define WLC_REBOOT              267
@@ -1098,7 +1111,7 @@
 #define WLC_SET_AUTH_MODE           270
 #define WLC_GET_WAKEENTRY           271
 #define WLC_SET_WAKEENTRY           272
-#define WLC_NDCONFIG_ITEM           273 
+#define WLC_NDCONFIG_ITEM           273
 #define WLC_NVOTPW              274
 #define WLC_OTPW                275
 #define WLC_IOV_BLOCK_GET           276
@@ -1109,39 +1122,43 @@
 #define WLC_GET_DESIRED_BSSID           281
 #define WLC_SET_DESIRED_BSSID           282
 #define WLC_DISASSOC_MYAP           283
-#define WLC_GET_NBANDS              284 
-#define WLC_GET_BANDSTATES          285 
-#define WLC_GET_WLC_BSS_INFO            286 
-#define WLC_GET_ASSOC_INFO          287 
-#define WLC_GET_OID_PHY             288 
-#define WLC_SET_OID_PHY             289 
-#define WLC_SET_ASSOC_TIME          290 
-#define WLC_GET_DESIRED_SSID            291 
-#define WLC_GET_CHANSPEC            292 
-#define WLC_GET_ASSOC_STATE         293 
-#define WLC_SET_PHY_STATE           294 
-#define WLC_GET_SCAN_PENDING            295 
-#define WLC_GET_SCANREQ_PENDING         296 
-#define WLC_GET_PREV_ROAM_REASON        297 
-#define WLC_SET_PREV_ROAM_REASON        298 
-#define WLC_GET_BANDSTATES_PI           299 
-#define WLC_GET_PHY_STATE           300 
-#define WLC_GET_BSS_WPA_RSN         301 
-#define WLC_GET_BSS_WPA2_RSN            302 
-#define WLC_GET_BSS_BCN_TS          303 
-#define WLC_GET_INT_DISASSOC            304 
-#define WLC_SET_NUM_PEERS           305     
-#define WLC_GET_NUM_BSS             306 
-#define WLC_NPHY_SAMPLE_COLLECT         307 
-#define WLC_UM_PRIV             308 
+#define WLC_GET_NBANDS              284
+#define WLC_GET_BANDSTATES          285
+#define WLC_GET_WLC_BSS_INFO            286
+#define WLC_GET_ASSOC_INFO          287
+#define WLC_GET_OID_PHY             288
+#define WLC_SET_OID_PHY             289
+#define WLC_SET_ASSOC_TIME          290
+#define WLC_GET_DESIRED_SSID            291
+#define WLC_GET_CHANSPEC            292
+#define WLC_GET_ASSOC_STATE         293
+#define WLC_SET_PHY_STATE           294
+#define WLC_GET_SCAN_PENDING            295
+#define WLC_GET_SCANREQ_PENDING         296
+#define WLC_GET_PREV_ROAM_REASON        297
+#define WLC_SET_PREV_ROAM_REASON        298
+#define WLC_GET_BANDSTATES_PI           299
+#define WLC_GET_PHY_STATE           300
+#define WLC_GET_BSS_WPA_RSN         301
+#define WLC_GET_BSS_WPA2_RSN            302
+#define WLC_GET_BSS_BCN_TS          303
+#define WLC_GET_INT_DISASSOC            304
+#define WLC_SET_NUM_PEERS           305
+#define WLC_GET_NUM_BSS             306
+#define WLC_NPHY_SAMPLE_COLLECT         307
+#define WLC_UM_PRIV             308
 #define WLC_GET_CMD             309
-  
-#define WLC_SET_INTERFERENCE_OVERRIDE_MODE  311 
-#define WLC_GET_INTERFERENCE_OVERRIDE_MODE  312 
-#define WLC_GET_WAI_RESTRICT            313 
-#define WLC_SET_WAI_RESTRICT            314 
-#define WLC_SET_WAI_REKEY           315 
-#define WLC_SET_PEAKRATE            316 
+
+#define WLC_SET_INTERFERENCE_OVERRIDE_MODE  311
+#define WLC_GET_INTERFERENCE_OVERRIDE_MODE  312
+
+#ifdef WAPI
+#define WLC_GET_WAI_RESTRICT            313 /* for WAPI */
+#define WLC_SET_WAI_RESTRICT            314 /* for WAPI */
+#define WLC_SET_WAI_REKEY           315 /* for WAPI */
+#endif /* WAPI */
+
+#define WLC_SET_PEAKRATE            316
 #define WLC_GET_PEAKRATE            317
 #define WLC_LAST                318
 
@@ -1201,15 +1218,15 @@
 
 
 
-#define WL_AUTH_OPEN_SYSTEM     0   
-#define WL_AUTH_SHARED_KEY      1   
-#define WL_AUTH_OPEN_SHARED     2   
+#define WL_AUTH_OPEN_SYSTEM     0
+#define WL_AUTH_SHARED_KEY      1
+#define WL_AUTH_OPEN_SHARED     2
 
 
 #define WL_RADIO_SW_DISABLE     (1<<0)
 #define WL_RADIO_HW_DISABLE     (1<<1)
 #define WL_RADIO_MPC_DISABLE        (1<<2)
-#define WL_RADIO_COUNTRY_DISABLE    (1<<3)  
+#define WL_RADIO_COUNTRY_DISABLE    (1<<3)
 
 #define WL_SPURAVOID_OFF    0
 #define WL_SPURAVOID_ON1    1
@@ -1219,22 +1236,22 @@
 #define WL_TXPWR_OVERRIDE   (1U<<31)
 #define WL_TXPWR_NEG   (1U<<30)
 
-#define WL_PHY_PAVARS_LEN   6   
+#define WL_PHY_PAVARS_LEN   6
 
-#define WL_PHY_PAVARS2_NUM	3	
-#define WL_PHY_PAVAR_VER	1	
+#define WL_PHY_PAVARS2_NUM	3
+#define WL_PHY_PAVAR_VER	1
 typedef struct wl_pavars2 {
-	uint16 ver;		
-	uint16 len;		
-	uint16 inuse;		
-	uint16 phy_type;	
+	uint16 ver;
+	uint16 len;
+	uint16 inuse;
+	uint16 phy_type;
 	uint16 bandrange;
 	uint16 chain;
-	uint16 inpa[WL_PHY_PAVARS2_NUM];	
+	uint16 inpa[WL_PHY_PAVARS2_NUM];
 } wl_pavars2_t;
 
 typedef struct wl_po {
-	uint16  phy_type;   
+	uint16  phy_type;
 	uint16  band;
 	uint16  cckpo;
 	uint32  ofdmpo;
@@ -1242,37 +1259,37 @@
 } wl_po_t;
 
 
-#define WLC_TXPWR_MAX       (127)   
+#define WLC_TXPWR_MAX       (127)
 
 
-#define WL_DIAG_INTERRUPT           1   
-#define WL_DIAG_LOOPBACK            2   
-#define WL_DIAG_MEMORY              3   
-#define WL_DIAG_LED             4   
-#define WL_DIAG_REG             5   
-#define WL_DIAG_SROM                6   
-#define WL_DIAG_DMA             7   
+#define WL_DIAG_INTERRUPT           1
+#define WL_DIAG_LOOPBACK            2
+#define WL_DIAG_MEMORY              3
+#define WL_DIAG_LED             4
+#define WL_DIAG_REG             5
+#define WL_DIAG_SROM                6
+#define WL_DIAG_DMA             7
 
 #define WL_DIAGERR_SUCCESS          0
-#define WL_DIAGERR_FAIL_TO_RUN          1   
-#define WL_DIAGERR_NOT_SUPPORTED        2   
-#define WL_DIAGERR_INTERRUPT_FAIL       3   
-#define WL_DIAGERR_LOOPBACK_FAIL        4   
-#define WL_DIAGERR_SROM_FAIL            5   
-#define WL_DIAGERR_SROM_BADCRC          6   
-#define WL_DIAGERR_REG_FAIL         7   
-#define WL_DIAGERR_MEMORY_FAIL          8   
-#define WL_DIAGERR_NOMEM            9   
-#define WL_DIAGERR_DMA_FAIL         10  
+#define WL_DIAGERR_FAIL_TO_RUN          1
+#define WL_DIAGERR_NOT_SUPPORTED        2
+#define WL_DIAGERR_INTERRUPT_FAIL       3
+#define WL_DIAGERR_LOOPBACK_FAIL        4
+#define WL_DIAGERR_SROM_FAIL            5
+#define WL_DIAGERR_SROM_BADCRC          6
+#define WL_DIAGERR_REG_FAIL         7
+#define WL_DIAGERR_MEMORY_FAIL          8
+#define WL_DIAGERR_NOMEM            9
+#define WL_DIAGERR_DMA_FAIL         10
 
-#define WL_DIAGERR_MEMORY_TIMEOUT       11  
-#define WL_DIAGERR_MEMORY_BADPATTERN        12  
+#define WL_DIAGERR_MEMORY_TIMEOUT       11
+#define WL_DIAGERR_MEMORY_BADPATTERN        12
 
 
-#define WLC_BAND_AUTO       0   
-#define WLC_BAND_5G     1   
-#define WLC_BAND_2G     2   
-#define WLC_BAND_ALL        3   
+#define WLC_BAND_AUTO       0
+#define WLC_BAND_5G     1
+#define WLC_BAND_2G     2
+#define WLC_BAND_ALL        3
 
 
 #define WL_CHAN_FREQ_RANGE_2G      0
@@ -1292,6 +1309,11 @@
 #define WL_CHAN_FREQ_RANGE_5GMH_5BAND    7
 #define WL_CHAN_FREQ_RANGE_5GH_5BAND     8
 
+#define WL_CHAN_FREQ_RANGE_5G_BAND0     1
+#define WL_CHAN_FREQ_RANGE_5G_BAND1     2
+#define WL_CHAN_FREQ_RANGE_5G_BAND2     3
+#define WL_CHAN_FREQ_RANGE_5G_BAND3     4
+
 
 #define WLC_PHY_TYPE_A      0
 #define WLC_PHY_TYPE_B      1
@@ -1304,9 +1326,9 @@
 #define WLC_PHY_TYPE_NULL   0xf
 
 
-#define WLC_MACMODE_DISABLED    0   
-#define WLC_MACMODE_DENY    1   
-#define WLC_MACMODE_ALLOW   2   
+#define WLC_MACMODE_DISABLED    0
+#define WLC_MACMODE_DENY    1
+#define WLC_MACMODE_ALLOW   2
 
 
 #define GMODE_LEGACY_B      0
@@ -1363,30 +1385,30 @@
 #define PM_MAX  1
 #define PM_FAST 2
 
-#define LISTEN_INTERVAL		10
+#define LISTEN_INTERVAL			10
 
-#define INTERFERE_OVRRIDE_OFF   -1  
-#define INTERFERE_NONE  0   
-#define NON_WLAN    1   
-#define WLAN_MANUAL 2   
-#define WLAN_AUTO   3   
-#define WLAN_AUTO_W_NOISE   4   
-#define AUTO_ACTIVE (1 << 7) 
+#define INTERFERE_OVRRIDE_OFF   -1
+#define INTERFERE_NONE  0
+#define NON_WLAN    1
+#define WLAN_MANUAL 2
+#define WLAN_AUTO   3
+#define WLAN_AUTO_W_NOISE   4
+#define AUTO_ACTIVE (1 << 7)
 
 typedef struct wl_aci_args {
-	int enter_aci_thresh; 
-	int exit_aci_thresh; 
-	int usec_spin; 
-	int glitch_delay; 
-	uint16 nphy_adcpwr_enter_thresh;    
-	uint16 nphy_adcpwr_exit_thresh; 
-	uint16 nphy_repeat_ctr;     
-	uint16 nphy_num_samples;    
-	uint16 nphy_undetect_window_sz; 
-	uint16 nphy_b_energy_lo_aci;    
-	uint16 nphy_b_energy_md_aci;    
-	uint16 nphy_b_energy_hi_aci;    
-	uint16 nphy_noise_noassoc_glitch_th_up; 
+	int enter_aci_thresh;
+	int exit_aci_thresh;
+	int usec_spin;
+	int glitch_delay;
+	uint16 nphy_adcpwr_enter_thresh;
+	uint16 nphy_adcpwr_exit_thresh;
+	uint16 nphy_repeat_ctr;
+	uint16 nphy_num_samples;
+	uint16 nphy_undetect_window_sz;
+	uint16 nphy_b_energy_lo_aci;
+	uint16 nphy_b_energy_md_aci;
+	uint16 nphy_b_energy_hi_aci;
+	uint16 nphy_noise_noassoc_glitch_th_up;
 	uint16 nphy_noise_noassoc_glitch_th_dn;
 	uint16 nphy_noise_assoc_glitch_th_up;
 	uint16 nphy_noise_assoc_glitch_th_dn;
@@ -1407,15 +1429,15 @@
 #define TRIGGER_BADFCS              0x08
 #define TRIGGER_BADPLCP             0x10
 #define TRIGGER_CRSGLITCH           0x20
-#define WL_ACI_ARGS_LEGACY_LENGTH   16  
-#define WL_SAMPLECOLLECT_T_VERSION  1   
+#define WL_ACI_ARGS_LEGACY_LENGTH   16
+#define WL_SAMPLECOLLECT_T_VERSION  1
 typedef struct wl_samplecollect_args {
-	
+
 	uint8 coll_us;
 	int cores;
-	
-	uint16 version;     
-	uint16 length;      
+
+	uint16 version;
+	uint16 length;
 	uint8 trigger;
 	uint16 timeout;
 	uint16 mode;
@@ -1424,25 +1446,25 @@
 	uint8 gpio_sel;
 	bool downsamp;
 	bool be_deaf;
-	bool agc;       
-	bool filter;        
+	bool agc;
+	bool filter;
 } wl_samplecollect_args_t;
 
 #define WL_SAMPLEDATA_HEADER_TYPE   1
-#define WL_SAMPLEDATA_HEADER_SIZE   80  
+#define WL_SAMPLEDATA_HEADER_SIZE   80
 #define WL_SAMPLEDATA_TYPE      2
-#define WL_SAMPLEDATA_SEQ       0xff    
-#define WL_SAMPLEDATA_MORE_DATA     0x100   
-#define WL_SAMPLEDATA_T_VERSION     1   
+#define WL_SAMPLEDATA_SEQ       0xff
+#define WL_SAMPLEDATA_MORE_DATA     0x100
+#define WL_SAMPLEDATA_T_VERSION     1
 
 #define WL_SAMPLEDATA_T_VERSION_SPEC_AN 2
 
 typedef struct wl_sampledata {
-	uint16 version; 
-	uint16 size;    
-	uint16 tag; 
-	uint16 length;  
-	uint32 flag;    
+	uint16 version;
+	uint16 size;
+	uint16 tag;
+	uint16 length;
+	uint32 flag;
 } wl_sampledata_t;
 
 
@@ -1458,17 +1480,17 @@
 #define WL_ASSOC_VAL        0x00000100
 #define WL_PRUSR_VAL        0x00000200
 #define WL_PS_VAL       0x00000400
-#define WL_TXPWR_VAL        0x00000800  
+#define WL_TXPWR_VAL        0x00000800
 #define WL_PORT_VAL     0x00001000
 #define WL_DUAL_VAL     0x00002000
 #define WL_WSEC_VAL     0x00004000
 #define WL_WSEC_DUMP_VAL    0x00008000
 #define WL_LOG_VAL      0x00010000
-#define WL_NRSSI_VAL        0x00020000  
-#define WL_LOFT_VAL     0x00040000  
+#define WL_NRSSI_VAL        0x00020000
+#define WL_LOFT_VAL     0x00040000
 #define WL_REGULATORY_VAL   0x00080000
-#define WL_PHYCAL_VAL       0x00100000  
-#define WL_RADAR_VAL        0x00200000  
+#define WL_PHYCAL_VAL       0x00100000
+#define WL_RADAR_VAL        0x00200000
 #define WL_MPC_VAL      0x00400000
 #define WL_APSTA_VAL        0x00800000
 #define WL_DFS_VAL      0x01000000
@@ -1489,52 +1511,52 @@
 #define WL_PROTO_VAL        0x00000020
 #define WL_BTA_VAL      0x00000040
 #define WL_CHANINT_VAL      0x00000080
-#define WL_THERMAL_VAL      0x00000100  
+#define WL_THERMAL_VAL      0x00000100
 #define WL_P2P_VAL      0x00000200
 #define WL_TXRX_VAL		0x00000400
 #define WL_MCHAN_VAL            0x00000800
 
 
-#define WL_LED_NUMGPIO      16  
+#define WL_LED_NUMGPIO      16
 
 
-#define WL_LED_OFF      0       
-#define WL_LED_ON       1       
-#define WL_LED_ACTIVITY     2       
-#define WL_LED_RADIO        3       
-#define WL_LED_ARADIO       4       
-#define WL_LED_BRADIO       5       
-#define WL_LED_BGMODE       6       
+#define WL_LED_OFF      0
+#define WL_LED_ON       1
+#define WL_LED_ACTIVITY     2
+#define WL_LED_RADIO        3
+#define WL_LED_ARADIO       4
+#define WL_LED_BRADIO       5
+#define WL_LED_BGMODE       6
 #define WL_LED_WI1      7
 #define WL_LED_WI2      8
 #define WL_LED_WI3      9
-#define WL_LED_ASSOC        10      
-#define WL_LED_INACTIVE     11      
-#define WL_LED_ASSOCACT     12      
+#define WL_LED_ASSOC        10
+#define WL_LED_INACTIVE     11
+#define WL_LED_ASSOCACT     12
 #define WL_LED_WI4      13
 #define WL_LED_WI5      14
-#define WL_LED_BLINKSLOW    15      
-#define WL_LED_BLINKMED     16      
-#define WL_LED_BLINKFAST    17      
-#define WL_LED_BLINKCUSTOM  18      
-#define WL_LED_BLINKPERIODIC    19      
-#define WL_LED_ASSOC_WITH_SEC   20      
-						
-#define WL_LED_START_OFF    21      
+#define WL_LED_BLINKSLOW    15
+#define WL_LED_BLINKMED     16
+#define WL_LED_BLINKFAST    17
+#define WL_LED_BLINKCUSTOM  18
+#define WL_LED_BLINKPERIODIC    19
+#define WL_LED_ASSOC_WITH_SEC   20
+
+#define WL_LED_START_OFF    21
 #define WL_LED_NUMBEHAVIOR  22
 
 
-#define WL_LED_BEH_MASK     0x7f        
-#define WL_LED_AL_MASK      0x80        
+#define WL_LED_BEH_MASK     0x7f
+#define WL_LED_AL_MASK      0x80
 
 
 #define WL_NUMCHANNELS      64
 #define WL_NUMCHANSPECS     100
 
 
-#define WL_WDS_WPA_ROLE_AUTH    0   
-#define WL_WDS_WPA_ROLE_SUP 1   
-#define WL_WDS_WPA_ROLE_AUTO    255 
+#define WL_WDS_WPA_ROLE_AUTH    0
+#define WL_WDS_WPA_ROLE_SUP 1
+#define WL_WDS_WPA_ROLE_AUTO    255
 
 
 #define WL_EVENTING_MASK_LEN    16
@@ -1542,14 +1564,14 @@
 
 
 
-#define WL_JOIN_PREF_RSSI   1   
-#define WL_JOIN_PREF_WPA    2   
-#define WL_JOIN_PREF_BAND   3   
-#define WL_JOIN_PREF_RSSI_DELTA 4   
+#define WL_JOIN_PREF_RSSI   1
+#define WL_JOIN_PREF_WPA    2
+#define WL_JOIN_PREF_BAND   3
+#define WL_JOIN_PREF_RSSI_DELTA 4
 #define WL_JOIN_PREF_TRANS_PREF	5
 
 
-#define WLJP_BAND_ASSOC_PREF    255 
+#define WLJP_BAND_ASSOC_PREF    255
 
 
 #define WL_WPA_ACP_MCS_ANY  "\x00\x00\x00\x00"
@@ -1558,218 +1580,218 @@
 	uint8 octets[3];
 };
 
-#define NFIFO           6   
+#define NFIFO           6
 
-#define WL_CNT_T_VERSION    6   
+#define WL_CNT_T_VERSION    6
 
 typedef struct {
-	uint16  version;    
-	uint16  length;     
+	uint16  version;
+	uint16  length;
 
-	
-	uint32  txframe;    
-	uint32  txbyte;     
-	uint32  txretrans;  
-	uint32  txerror;    
-	uint32  txctl;      
-	uint32  txprshort;  
-	uint32  txserr;     
-	uint32  txnobuf;    
-	uint32  txnoassoc;  
-	uint32  txrunt;     
-	uint32  txchit;     
-	uint32  txcmiss;    
 
-	
-	uint32  txuflo;     
-	uint32  txphyerr;   
+	uint32  txframe;
+	uint32  txbyte;
+	uint32  txretrans;
+	uint32  txerror;
+	uint32  txctl;
+	uint32  txprshort;
+	uint32  txserr;
+	uint32  txnobuf;
+	uint32  txnoassoc;
+	uint32  txrunt;
+	uint32  txchit;
+	uint32  txcmiss;
+
+
+	uint32  txuflo;
+	uint32  txphyerr;
 	uint32  txphycrs;
 
-	
-	uint32  rxframe;    
-	uint32  rxbyte;     
-	uint32  rxerror;    
-	uint32  rxctl;      
-	uint32  rxnobuf;    
-	uint32  rxnondata;  
-	uint32  rxbadds;    
-	uint32  rxbadcm;    
-	uint32  rxfragerr;  
-	uint32  rxrunt;     
-	uint32  rxgiant;    
-	uint32  rxnoscb;    
-	uint32  rxbadproto; 
-	uint32  rxbadsrcmac;    
-	uint32  rxbadda;    
-	uint32  rxfilter;   
 
-	
-	uint32  rxoflo;     
-	uint32  rxuflo[NFIFO];  
+	uint32  rxframe;
+	uint32  rxbyte;
+	uint32  rxerror;
+	uint32  rxctl;
+	uint32  rxnobuf;
+	uint32  rxnondata;
+	uint32  rxbadds;
+	uint32  rxbadcm;
+	uint32  rxfragerr;
+	uint32  rxrunt;
+	uint32  rxgiant;
+	uint32  rxnoscb;
+	uint32  rxbadproto;
+	uint32  rxbadsrcmac;
+	uint32  rxbadda;
+	uint32  rxfilter;
 
-	uint32  d11cnt_txrts_off;   
-	uint32  d11cnt_rxcrc_off;   
-	uint32  d11cnt_txnocts_off; 
 
-	
-	uint32  dmade;      
-	uint32  dmada;      
-	uint32  dmape;      
-	uint32  reset;      
-	uint32  tbtt;       
+	uint32  rxoflo;
+	uint32  rxuflo[NFIFO];
+
+	uint32  d11cnt_txrts_off;
+	uint32  d11cnt_rxcrc_off;
+	uint32  d11cnt_txnocts_off;
+
+
+	uint32  dmade;
+	uint32  dmada;
+	uint32  dmape;
+	uint32  reset;
+	uint32  tbtt;
 	uint32  txdmawar;
-	uint32  pkt_callback_reg_fail;  
+	uint32  pkt_callback_reg_fail;
 
-	
-	uint32  txallfrm;   
-	uint32  txrtsfrm;   
-	uint32  txctsfrm;   
-	uint32  txackfrm;   
-	uint32  txdnlfrm;   
-	uint32  txbcnfrm;   
-	uint32  txfunfl[8]; 
-	uint32  txtplunfl;  
-	uint32  txphyerror; 
-	uint32  rxfrmtoolong;   
-	uint32  rxfrmtooshrt;   
-	uint32  rxinvmachdr;    
-	uint32  rxbadfcs;   
-	uint32  rxbadplcp;  
-	uint32  rxcrsglitch;    
-	uint32  rxstrt;     
-	uint32  rxdfrmucastmbss; 
-	uint32  rxmfrmucastmbss; 
-	uint32  rxcfrmucast;    
-	uint32  rxrtsucast; 
-	uint32  rxctsucast; 
-	uint32  rxackucast; 
-	uint32  rxdfrmocast;    
-	uint32  rxmfrmocast;    
-	uint32  rxcfrmocast;    
-	uint32  rxrtsocast; 
-	uint32  rxctsocast; 
-	uint32  rxdfrmmcast;    
-	uint32  rxmfrmmcast;    
-	uint32  rxcfrmmcast;    
-	uint32  rxbeaconmbss;   
-	uint32  rxdfrmucastobss; 
-	uint32  rxbeaconobss;   
-	uint32  rxrsptmout; 
-	uint32  bcntxcancl; 
-	uint32  rxf0ovfl;   
-	uint32  rxf1ovfl;   
-	uint32  rxf2ovfl;   
-	uint32  txsfovfl;   
-	uint32  pmqovfl;    
-	uint32  rxcgprqfrm; 
-	uint32  rxcgprsqovfl;   
-	uint32  txcgprsfail;    
-	uint32  txcgprssuc; 
-	uint32  prs_timeout;    
+
+	uint32  txallfrm;
+	uint32  txrtsfrm;
+	uint32  txctsfrm;
+	uint32  txackfrm;
+	uint32  txdnlfrm;
+	uint32  txbcnfrm;
+	uint32  txfunfl[8];
+	uint32  txtplunfl;
+	uint32  txphyerror;
+	uint32  rxfrmtoolong;
+	uint32  rxfrmtooshrt;
+	uint32  rxinvmachdr;
+	uint32  rxbadfcs;
+	uint32  rxbadplcp;
+	uint32  rxcrsglitch;
+	uint32  rxstrt;
+	uint32  rxdfrmucastmbss;
+	uint32  rxmfrmucastmbss;
+	uint32  rxcfrmucast;
+	uint32  rxrtsucast;
+	uint32  rxctsucast;
+	uint32  rxackucast;
+	uint32  rxdfrmocast;
+	uint32  rxmfrmocast;
+	uint32  rxcfrmocast;
+	uint32  rxrtsocast;
+	uint32  rxctsocast;
+	uint32  rxdfrmmcast;
+	uint32  rxmfrmmcast;
+	uint32  rxcfrmmcast;
+	uint32  rxbeaconmbss;
+	uint32  rxdfrmucastobss;
+	uint32  rxbeaconobss;
+	uint32  rxrsptmout;
+	uint32  bcntxcancl;
+	uint32  rxf0ovfl;
+	uint32  rxf1ovfl;
+	uint32  rxf2ovfl;
+	uint32  txsfovfl;
+	uint32  pmqovfl;
+	uint32  rxcgprqfrm;
+	uint32  rxcgprsqovfl;
+	uint32  txcgprsfail;
+	uint32  txcgprssuc;
+	uint32  prs_timeout;
 	uint32  rxnack;
 	uint32  frmscons;
 	uint32  txnack;
-	uint32  txglitch_nack;  
-	uint32  txburst;    
+	uint32  txglitch_nack;
+	uint32  txburst;
 
-	
-	uint32  txfrag;     
-	uint32  txmulti;    
-	uint32  txfail;     
-	uint32  txretry;    
-	uint32  txretrie;   
-	uint32  rxdup;      
-	uint32  txrts;      
-	uint32  txnocts;    
-	uint32  txnoack;    
-	uint32  rxfrag;     
-	uint32  rxmulti;    
-	uint32  rxcrc;      
-	uint32  txfrmsnt;   
-	uint32  rxundec;    
 
-	
-	uint32  tkipmicfaill;   
-	uint32  tkipcntrmsr;    
-	uint32  tkipreplay; 
-	uint32  ccmpfmterr; 
-	uint32  ccmpreplay; 
-	uint32  ccmpundec;  
-	uint32  fourwayfail;    
-	uint32  wepundec;   
-	uint32  wepicverr;  
-	uint32  decsuccess; 
-	uint32  tkipicverr; 
-	uint32  wepexcluded;    
+	uint32  txfrag;
+	uint32  txmulti;
+	uint32  txfail;
+	uint32  txretry;
+	uint32  txretrie;
+	uint32  rxdup;
+	uint32  txrts;
+	uint32  txnocts;
+	uint32  txnoack;
+	uint32  rxfrag;
+	uint32  rxmulti;
+	uint32  rxcrc;
+	uint32  txfrmsnt;
+	uint32  rxundec;
 
-	uint32  rxundec_mcst;   
 
-	
-	uint32  tkipmicfaill_mcst;  
-	uint32  tkipcntrmsr_mcst;   
-	uint32  tkipreplay_mcst;    
-	uint32  ccmpfmterr_mcst;    
-	uint32  ccmpreplay_mcst;    
-	uint32  ccmpundec_mcst; 
-	uint32  fourwayfail_mcst;   
-	uint32  wepundec_mcst;  
-	uint32  wepicverr_mcst; 
-	uint32  decsuccess_mcst;    
-	uint32  tkipicverr_mcst;    
-	uint32  wepexcluded_mcst;   
+	uint32  tkipmicfaill;
+	uint32  tkipcntrmsr;
+	uint32  tkipreplay;
+	uint32  ccmpfmterr;
+	uint32  ccmpreplay;
+	uint32  ccmpundec;
+	uint32  fourwayfail;
+	uint32  wepundec;
+	uint32  wepicverr;
+	uint32  decsuccess;
+	uint32  tkipicverr;
+	uint32  wepexcluded;
 
-	uint32  txchanrej;  
-	uint32  txexptime;  
-	uint32  psmwds;     
-	uint32  phywatchdog;    
+	uint32  rxundec_mcst;
 
-	
-	uint32  prq_entries_handled;    
-	uint32  prq_undirected_entries; 
-	uint32  prq_bad_entries;    
-	uint32  atim_suppress_count;    
-	uint32  bcn_template_not_ready; 
-	uint32  bcn_template_not_ready_done; 
-	uint32  late_tbtt_dpc;  
 
-	
-	uint32  rx1mbps;    
-	uint32  rx2mbps;    
-	uint32  rx5mbps5;   
-	uint32  rx6mbps;    
-	uint32  rx9mbps;    
-	uint32  rx11mbps;   
-	uint32  rx12mbps;   
-	uint32  rx18mbps;   
-	uint32  rx24mbps;   
-	uint32  rx36mbps;   
-	uint32  rx48mbps;   
-	uint32  rx54mbps;   
-	uint32  rx108mbps;  
-	uint32  rx162mbps;  
-	uint32  rx216mbps;  
-	uint32  rx270mbps;  
-	uint32  rx324mbps;  
-	uint32  rx378mbps;  
-	uint32  rx432mbps;  
-	uint32  rx486mbps;  
-	uint32  rx540mbps;  
+	uint32  tkipmicfaill_mcst;
+	uint32  tkipcntrmsr_mcst;
+	uint32  tkipreplay_mcst;
+	uint32  ccmpfmterr_mcst;
+	uint32  ccmpreplay_mcst;
+	uint32  ccmpundec_mcst;
+	uint32  fourwayfail_mcst;
+	uint32  wepundec_mcst;
+	uint32  wepicverr_mcst;
+	uint32  decsuccess_mcst;
+	uint32  tkipicverr_mcst;
+	uint32  wepexcluded_mcst;
 
-	
-	uint32  pktengrxducast; 
-	uint32  pktengrxdmcast; 
+	uint32  txchanrej;
+	uint32  txexptime;
+	uint32  psmwds;
+	uint32  phywatchdog;
 
-	uint32  rfdisable;  
-	uint32  bphy_rxcrsglitch;   
 
-	uint32  txmpdu_sgi; 
-	uint32  rxmpdu_sgi; 
-	uint32  txmpdu_stbc;    
-	uint32  rxmpdu_stbc;    
+	uint32  prq_entries_handled;
+	uint32  prq_undirected_entries;
+	uint32  prq_bad_entries;
+	uint32  atim_suppress_count;
+	uint32  bcn_template_not_ready;
+	uint32  bcn_template_not_ready_done;
+	uint32  late_tbtt_dpc;
+
+
+	uint32  rx1mbps;
+	uint32  rx2mbps;
+	uint32  rx5mbps5;
+	uint32  rx6mbps;
+	uint32  rx9mbps;
+	uint32  rx11mbps;
+	uint32  rx12mbps;
+	uint32  rx18mbps;
+	uint32  rx24mbps;
+	uint32  rx36mbps;
+	uint32  rx48mbps;
+	uint32  rx54mbps;
+	uint32  rx108mbps;
+	uint32  rx162mbps;
+	uint32  rx216mbps;
+	uint32  rx270mbps;
+	uint32  rx324mbps;
+	uint32  rx378mbps;
+	uint32  rx432mbps;
+	uint32  rx486mbps;
+	uint32  rx540mbps;
+
+
+	uint32  pktengrxducast;
+	uint32  pktengrxdmcast;
+
+	uint32  rfdisable;
+	uint32  bphy_rxcrsglitch;
+
+	uint32  txmpdu_sgi;
+	uint32  rxmpdu_sgi;
+	uint32  txmpdu_stbc;
+	uint32  rxmpdu_stbc;
 } wl_cnt_t;
 
 
-#define WL_WME_CNT_VERSION  1   
+#define WL_WME_CNT_VERSION  1
 
 typedef struct {
 	uint32 packets;
@@ -1777,17 +1799,17 @@
 } wl_traffic_stats_t;
 
 typedef struct {
-	uint16  version;    
-	uint16  length;     
+	uint16  version;
+	uint16  length;
 
-	wl_traffic_stats_t tx[AC_COUNT];    
-	wl_traffic_stats_t tx_failed[AC_COUNT]; 
-	wl_traffic_stats_t rx[AC_COUNT];    
-	wl_traffic_stats_t rx_failed[AC_COUNT]; 
+	wl_traffic_stats_t tx[AC_COUNT];
+	wl_traffic_stats_t tx_failed[AC_COUNT];
+	wl_traffic_stats_t rx[AC_COUNT];
+	wl_traffic_stats_t rx_failed[AC_COUNT];
 
-	wl_traffic_stats_t forward[AC_COUNT];   
+	wl_traffic_stats_t forward[AC_COUNT];
 
-	wl_traffic_stats_t tx_expired[AC_COUNT];    
+	wl_traffic_stats_t tx_expired[AC_COUNT];
 
 } wl_wme_cnt_t;
 
@@ -1805,18 +1827,20 @@
 	uint8	data[1];
 } wl_mkeep_alive_pkt_t;
 
-#define WL_MKEEP_ALIVE_VERSION          1
-#define WL_MKEEP_ALIVE_FIXED_LEN        OFFSETOF(wl_mkeep_alive_pkt_t, data)
-#define WL_MKEEP_ALIVE_PRECISION        500
-
-#define WLC_ROAM_TRIGGER_DEFAULT    0 
-#define WLC_ROAM_TRIGGER_BANDWIDTH  1 
-#define WLC_ROAM_TRIGGER_DISTANCE   2 
-#define WLC_ROAM_TRIGGER_AUTO       3 
-#define WLC_ROAM_TRIGGER_MAX_VALUE  3 
+#define WL_MKEEP_ALIVE_VERSION		1
+#define WL_MKEEP_ALIVE_FIXED_LEN	OFFSETOF(wl_mkeep_alive_pkt_t, data)
+#define WL_MKEEP_ALIVE_PRECISION	500
 
 
-#define WPA_AUTH_PFN_ANY	0xffffffff	
+
+#define WLC_ROAM_TRIGGER_DEFAULT    0
+#define WLC_ROAM_TRIGGER_BANDWIDTH  1
+#define WLC_ROAM_TRIGGER_DISTANCE   2
+#define WLC_ROAM_TRIGGER_AUTO       3
+#define WLC_ROAM_TRIGGER_MAX_VALUE  3
+
+
+#define WPA_AUTH_PFN_ANY	0xffffffff
 
 enum {
 	PFN_LIST_ORDER,
@@ -1868,15 +1892,15 @@
 
 typedef struct wl_pfn_subnet_info {
 	struct ether_addr BSSID;
-	uint8	channel; 
+	uint8	channel;
 	uint8	SSID_len;
 	uint8	SSID[32];
 } wl_pfn_subnet_info_t;
 
 typedef struct wl_pfn_net_info {
 	wl_pfn_subnet_info_t pfnsubnet;
-	int16	RSSI; 
-	uint16	timestamp; 
+	int16	RSSI;
+	uint16	timestamp;
 } wl_pfn_net_info_t;
 
 typedef struct wl_pfn_scanresults {
@@ -1888,21 +1912,21 @@
 
 
 typedef struct wl_pfn_param {
-	int32 version;			
-	int32 scan_freq;		
-	int32 lost_network_timeout;	
-	int16 flags;			
-	int16 rssi_margin;		
-	uint8 bestn; 
-	uint8 mscan; 
-	uint8 repeat; 
-	uint8 exp; 
+	int32 version;
+	int32 scan_freq;
+	int32 lost_network_timeout;
+	int16 flags;
+	int16 rssi_margin;
+	uint8 bestn;
+	uint8 mscan;
+	uint8 repeat;
+	uint8 exp;
 	int32 slow_freq;
 } wl_pfn_param_t;
 
 typedef struct wl_pfn_bssid {
 	struct ether_addr 	macaddr;
-	
+
 	uint16				flags;
 } wl_pfn_bssid_t;
 #define WL_PFN_SUPPRESSFOUND_MASK	0x08
@@ -1918,17 +1942,17 @@
 #define WL_PFN_REPORT_BSSIDNET 	2
 
 typedef struct wl_pfn {
-	wlc_ssid_t		ssid;			
-	int32			flags;			
-	int32			infra;			
-	int32			auth;			
-	int32			wpa_auth;		
-	int32			wsec;			
+	wlc_ssid_t		ssid;
+	int32			flags;
+	int32			infra;
+	int32			auth;
+	int32			wpa_auth;
+	int32			wsec;
 } wl_pfn_t;
 #define WL_PFN_HIDDEN_BIT		2
-#define PNO_SCAN_MAX_FW		508*1000	
-#define PNO_SCAN_MAX_FW_SEC	PNO_SCAN_MAX_FW/1000 
-#define PNO_SCAN_MIN_FW_SEC	10			
+#define PNO_SCAN_MAX_FW		508*1000
+#define PNO_SCAN_MAX_FW_SEC	PNO_SCAN_MAX_FW/1000
+#define PNO_SCAN_MIN_FW_SEC	10
 #define WL_PFN_HIDDEN_MASK		0x4
 
 
@@ -1941,16 +1965,16 @@
 #define TOE_ERRTEST_RX_CSUM2    0x00000004
 
 struct toe_ol_stats_t {
-	
+
 	uint32 tx_summed;
 
-	
+
 	uint32 tx_iph_fill;
 	uint32 tx_tcp_fill;
 	uint32 tx_udp_fill;
 	uint32 tx_icmp_fill;
 
-	
+
 	uint32 rx_iph_good;
 	uint32 rx_iph_bad;
 	uint32 rx_tcp_good;
@@ -1960,12 +1984,12 @@
 	uint32 rx_icmp_good;
 	uint32 rx_icmp_bad;
 
-	
+
 	uint32 tx_tcp_errinj;
 	uint32 tx_udp_errinj;
 	uint32 tx_icmp_errinj;
 
-	
+
 	uint32 rx_tcp_errinj;
 	uint32 rx_udp_errinj;
 	uint32 rx_icmp_errinj;
@@ -1981,34 +2005,34 @@
 #define ARP_ERRTEST_REPLY_PEER  0x1
 #define ARP_ERRTEST_REPLY_HOST  0x2
 
-#define ARP_MULTIHOMING_MAX 8   
+#define ARP_MULTIHOMING_MAX 8
 
 
 struct arp_ol_stats_t {
-	uint32  host_ip_entries;    
-	uint32  host_ip_overflow;   
+	uint32  host_ip_entries;
+	uint32  host_ip_overflow;
 
-	uint32  arp_table_entries;  
-	uint32  arp_table_overflow; 
+	uint32  arp_table_entries;
+	uint32  arp_table_overflow;
 
-	uint32  host_request;       
-	uint32  host_reply;     
-	uint32  host_service;       
+	uint32  host_request;
+	uint32  host_reply;
+	uint32  host_service;
 
-	uint32  peer_request;       
-	uint32  peer_request_drop;  
-	uint32  peer_reply;     
-	uint32  peer_reply_drop;    
-	uint32  peer_service;       
+	uint32  peer_request;
+	uint32  peer_request_drop;
+	uint32  peer_reply;
+	uint32  peer_reply_drop;
+	uint32  peer_service;
 };
 
 
 
 
 typedef struct wl_keep_alive_pkt {
-	uint32  period_msec;    
-	uint16  len_bytes;  
-	uint8   data[1];    
+	uint32  period_msec;
+	uint16  len_bytes;
+	uint8   data[1];
 } wl_keep_alive_pkt_t;
 
 #define WL_KEEP_ALIVE_FIXED_LEN     OFFSETOF(wl_keep_alive_pkt_t, data)
@@ -2017,25 +2041,25 @@
 
 
 typedef enum wl_pkt_filter_type {
-	WL_PKT_FILTER_TYPE_PATTERN_MATCH    
+	WL_PKT_FILTER_TYPE_PATTERN_MATCH
 } wl_pkt_filter_type_t;
 
 #define WL_PKT_FILTER_TYPE wl_pkt_filter_type_t
 
 
 typedef struct wl_pkt_filter_pattern {
-	uint32  offset;     
-	uint32  size_bytes; 
-	uint8   mask_and_pattern[1]; 
+	uint32  offset;
+	uint32  size_bytes;
+	uint8   mask_and_pattern[1];
 } wl_pkt_filter_pattern_t;
 
 
 typedef struct wl_pkt_filter {
-	uint32  id;     
-	uint32  type;       
-	uint32  negate_match;   
-	union {         
-		wl_pkt_filter_pattern_t pattern;    
+	uint32  id;
+	uint32  type;
+	uint32  negate_match;
+	union {
+		wl_pkt_filter_pattern_t pattern;
 	} u;
 } wl_pkt_filter_t;
 
@@ -2044,29 +2068,29 @@
 
 
 typedef struct wl_pkt_filter_enable {
-	uint32  id;     
-	uint32  enable;     
+	uint32  id;
+	uint32  enable;
 } wl_pkt_filter_enable_t;
 
 
 typedef struct wl_pkt_filter_list {
-	uint32  num;        
-	wl_pkt_filter_t filter[1];  
+	uint32  num;
+	wl_pkt_filter_t filter[1];
 } wl_pkt_filter_list_t;
 
 #define WL_PKT_FILTER_LIST_FIXED_LEN      OFFSETOF(wl_pkt_filter_list_t, filter)
 
 
 typedef struct wl_pkt_filter_stats {
-	uint32  num_pkts_matched;   
-	uint32  num_pkts_forwarded; 
-	uint32  num_pkts_discarded; 
+	uint32  num_pkts_matched;
+	uint32  num_pkts_forwarded;
+	uint32  num_pkts_discarded;
 } wl_pkt_filter_stats_t;
 
 
 typedef struct wl_seq_cmd_ioctl {
-	uint32 cmd;     
-	uint32 len;     
+	uint32 cmd;
+	uint32 len;
 } wl_seq_cmd_ioctl_t;
 
 #define WL_SEQ_CMD_ALIGN_BYTES  4
@@ -2088,16 +2112,16 @@
 #define WL_PKTENG_PER_RX_STOP           0x08
 #define WL_PKTENG_PER_MASK          0xff
 
-#define WL_PKTENG_SYNCHRONOUS           0x100   
+#define WL_PKTENG_SYNCHRONOUS           0x100
 
 typedef struct wl_pkteng {
 	uint32 flags;
-	uint32 delay;           
-	uint32 nframes;         
-	uint32 length;          
-	uint8  seqno;           
-	struct ether_addr dest;     
-	struct ether_addr src;      
+	uint32 delay;
+	uint32 nframes;
+	uint32 length;
+	uint8  seqno;
+	struct ether_addr dest;
+	struct ether_addr src;
 } wl_pkteng_t;
 
 #define NUM_80211b_RATES    4
@@ -2105,34 +2129,34 @@
 #define NUM_80211n_RATES    32
 #define NUM_80211_RATES     (NUM_80211b_RATES+NUM_80211ag_RATES+NUM_80211n_RATES)
 typedef struct wl_pkteng_stats {
-	uint32 lostfrmcnt;      
-	int32 rssi;         
-	int32 snr;          
+	uint32 lostfrmcnt;
+	int32 rssi;
+	int32 snr;
 	uint16 rxpktcnt[NUM_80211_RATES+1];
 } wl_pkteng_stats_t;
 
 
-#define WL_WOWL_MAGIC   (1 << 0)    
-#define WL_WOWL_NET (1 << 1)    
-#define WL_WOWL_DIS (1 << 2)    
-#define WL_WOWL_RETR    (1 << 3)    
-#define WL_WOWL_BCN (1 << 4)    
-#define WL_WOWL_TST (1 << 5)    
-#define WL_WOWL_M1      (1 << 6)        
-#define WL_WOWL_EAPID   (1 << 7)        
-#define WL_WOWL_KEYROT  (1 << 14)       
-#define WL_WOWL_BCAST   (1 << 15)   
+#define WL_WOWL_MAGIC   (1 << 0)
+#define WL_WOWL_NET (1 << 1)
+#define WL_WOWL_DIS (1 << 2)
+#define WL_WOWL_RETR    (1 << 3)
+#define WL_WOWL_BCN (1 << 4)
+#define WL_WOWL_TST (1 << 5)
+#define WL_WOWL_M1      (1 << 6)
+#define WL_WOWL_EAPID   (1 << 7)
+#define WL_WOWL_KEYROT  (1 << 14)
+#define WL_WOWL_BCAST   (1 << 15)
 
-#define MAGIC_PKT_MINLEN 102    
+#define MAGIC_PKT_MINLEN 102
 
 typedef struct {
-	uint masksize;      
-	uint offset;        
-	uint patternoffset; 
-	uint patternsize;   
-	ulong id;       
-	
-	
+	uint masksize;
+	uint offset;
+	uint patternoffset;
+	uint patternsize;
+	ulong id;
+
+
 } wl_wowl_pattern_t;
 
 typedef struct {
@@ -2141,8 +2165,8 @@
 } wl_wowl_pattern_list_t;
 
 typedef struct {
-	uint8   pci_wakeind;    
-	uint16  ucode_wakeind;  
+	uint8   pci_wakeind;
+	uint16  ucode_wakeind;
 } wl_wowl_wakeind_t;
 
 
@@ -2155,27 +2179,27 @@
 
 
 
-#define WLC_OBSS_SCAN_PASSIVE_DWELL_DEFAULT     20  
-#define WLC_OBSS_SCAN_PASSIVE_DWELL_MIN         5   
-#define WLC_OBSS_SCAN_PASSIVE_DWELL_MAX         1000    
-#define WLC_OBSS_SCAN_ACTIVE_DWELL_DEFAULT      10  
-#define WLC_OBSS_SCAN_ACTIVE_DWELL_MIN          10  
-#define WLC_OBSS_SCAN_ACTIVE_DWELL_MAX          1000    
-#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_DEFAULT    300 
-#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_MIN        10  
-#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_MAX        900 
+#define WLC_OBSS_SCAN_PASSIVE_DWELL_DEFAULT     20
+#define WLC_OBSS_SCAN_PASSIVE_DWELL_MIN         5
+#define WLC_OBSS_SCAN_PASSIVE_DWELL_MAX         1000
+#define WLC_OBSS_SCAN_ACTIVE_DWELL_DEFAULT      10
+#define WLC_OBSS_SCAN_ACTIVE_DWELL_MIN          10
+#define WLC_OBSS_SCAN_ACTIVE_DWELL_MAX          1000
+#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_DEFAULT    300
+#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_MIN        10
+#define WLC_OBSS_SCAN_WIDTHSCAN_INTERVAL_MAX        900
 #define WLC_OBSS_SCAN_CHANWIDTH_TRANSITION_DLY_DEFAULT  5
 #define WLC_OBSS_SCAN_CHANWIDTH_TRANSITION_DLY_MIN  5
 #define WLC_OBSS_SCAN_CHANWIDTH_TRANSITION_DLY_MAX  100
-#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_DEFAULT 200 
-#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_MIN 200 
-#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_MAX 10000   
-#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_DEFAULT  20  
-#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_MIN  20  
-#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_MAX  10000   
-#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_DEFAULT    25  
-#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_MIN        0   
-#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_MAX        100 
+#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_DEFAULT 200
+#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_MIN 200
+#define WLC_OBSS_SCAN_PASSIVE_TOTAL_PER_CHANNEL_MAX 10000
+#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_DEFAULT  20
+#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_MIN  20
+#define WLC_OBSS_SCAN_ACTIVE_TOTAL_PER_CHANNEL_MAX  10000
+#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_DEFAULT    25
+#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_MIN        0
+#define WLC_OBSS_SCAN_ACTIVITY_THRESHOLD_MAX        100
 
 
 typedef struct wl_obss_scan_arg {
@@ -2189,22 +2213,22 @@
 } wl_obss_scan_arg_t;
 
 #define WL_OBSS_SCAN_PARAM_LEN  sizeof(wl_obss_scan_arg_t)
-#define WL_MIN_NUM_OBSS_SCAN_ARG 7  
+#define WL_MIN_NUM_OBSS_SCAN_ARG 7
 
 #define WL_COEX_INFO_MASK       0x07
 #define WL_COEX_INFO_REQ        0x01
 #define WL_COEX_40MHZ_INTOLERANT    0x02
 #define WL_COEX_WIDTH20         0x04
 
-#define WLC_RSSI_INVALID     0  
+#define WLC_RSSI_INVALID     0
 
 #define MAX_RSSI_LEVELS 8
 
 
 typedef struct wl_rssi_event {
-	uint32 rate_limit_msec;     
-	uint8 num_rssi_levels;      
-	int8 rssi_levels[MAX_RSSI_LEVELS];  
+	uint32 rate_limit_msec;
+	uint8 num_rssi_levels;
+	int8 rssi_levels[MAX_RSSI_LEVELS];
 } wl_rssi_event_t;
 
 typedef struct wl_action_obss_coex_req {
@@ -2216,34 +2240,34 @@
 
 #define EXTLOG_CUR_VER      0x0100
 
-#define MAX_ARGSTR_LEN      18 
+#define MAX_ARGSTR_LEN      18
 
 
 #define LOG_MODULE_COMMON   0x0001
 #define LOG_MODULE_ASSOC    0x0002
 #define LOG_MODULE_EVENT    0x0004
-#define LOG_MODULE_MAX      3           
+#define LOG_MODULE_MAX      3
 
 
 #define WL_LOG_LEVEL_DISABLE    0
 #define WL_LOG_LEVEL_ERR    1
 #define WL_LOG_LEVEL_WARN   2
 #define WL_LOG_LEVEL_INFO   3
-#define WL_LOG_LEVEL_MAX    WL_LOG_LEVEL_INFO   
+#define WL_LOG_LEVEL_MAX    WL_LOG_LEVEL_INFO
 
 
 #define LOG_FLAG_EVENT      1
 
 
 #define LOG_ARGTYPE_NULL    0
-#define LOG_ARGTYPE_STR     1   
-#define LOG_ARGTYPE_INT     2   
-#define LOG_ARGTYPE_INT_STR 3   
-#define LOG_ARGTYPE_STR_INT 4   
+#define LOG_ARGTYPE_STR     1
+#define LOG_ARGTYPE_INT     2
+#define LOG_ARGTYPE_INT_STR 3
+#define LOG_ARGTYPE_STR_INT 4
 
 typedef struct wlc_extlog_cfg {
 	int max_number;
-	uint16 module;  
+	uint16 module;
 	uint8 level;
 	uint8 flag;
 	uint16 version;
@@ -2318,10 +2342,10 @@
 
 #ifdef DONGLEOVERLAYS
 typedef struct {
-	uint32 flags_idx;	
-	uint32 offset;		
-	uint32 len;			
-	
+	uint32 flags_idx;
+	uint32 offset;
+	uint32 len;
+
 } wl_ioctl_overlay_t;
 
 #define OVERLAY_IDX_MASK		0x000000ff
@@ -2336,7 +2360,7 @@
 #define OVERLAY_FLAG_PRESLEEP	0x400
 
 #define OVERLAY_DOWNLOAD_CHUNKSIZE	1024
-#endif 
+#endif
 
 
 #include <packed_section_end.h>
@@ -2344,7 +2368,7 @@
 
 #include <packed_section_start.h>
 
-#define VNDR_IE_CMD_LEN     4   
+#define VNDR_IE_CMD_LEN     4
 
 
 #define VNDR_IE_BEACON_FLAG 0x1
@@ -2353,23 +2377,23 @@
 #define VNDR_IE_AUTHRSP_FLAG    0x8
 #define VNDR_IE_PRBREQ_FLAG 0x10
 #define VNDR_IE_ASSOCREQ_FLAG   0x20
-#define VNDR_IE_CUSTOM_FLAG 0x100 
+#define VNDR_IE_CUSTOM_FLAG 0x100
 
 #define VNDR_IE_INFO_HDR_LEN    (sizeof(uint32))
 
 typedef BWL_PRE_PACKED_STRUCT struct {
-	uint32 pktflag;         
-	vndr_ie_t vndr_ie_data;     
+	uint32 pktflag;
+	vndr_ie_t vndr_ie_data;
 } BWL_POST_PACKED_STRUCT vndr_ie_info_t;
 
 typedef BWL_PRE_PACKED_STRUCT struct {
-	int iecount;            
-	vndr_ie_info_t vndr_ie_list[1]; 
+	int iecount;
+	vndr_ie_info_t vndr_ie_list[1];
 } BWL_POST_PACKED_STRUCT vndr_ie_buf_t;
 
 typedef BWL_PRE_PACKED_STRUCT struct {
-	char cmd[VNDR_IE_CMD_LEN];  
-	vndr_ie_buf_t vndr_ie_buffer;   
+	char cmd[VNDR_IE_CMD_LEN];
+	vndr_ie_buf_t vndr_ie_buffer;
 } BWL_POST_PACKED_STRUCT vndr_ie_setbuf_t;
 
 
@@ -2392,15 +2416,15 @@
 
 #ifdef WLMEDIA_TXFAILEVENT
 typedef BWL_PRE_PACKED_STRUCT struct {
-	char   dest[ETHER_ADDR_LEN]; 
-	uint8  prio;            
-	uint8  flags;           
-	uint32 tsf_l;           
-	uint32 tsf_h;           
-	uint16 rates;           
-	uint16 txstatus;        
+	char   dest[ETHER_ADDR_LEN];
+	uint8  prio;
+	uint8  flags;
+	uint32 tsf_l;
+	uint32 tsf_h;
+	uint16 rates;
+	uint16 txstatus;
 } BWL_POST_PACKED_STRUCT txfailinfo_t;
-#endif 
+#endif
 
 #include <packed_section_end.h>
 
@@ -2424,13 +2448,24 @@
 #define LOGRRC_FIX_LEN  8
 #define IOBUF_ALLOWED_NUM_OF_LOGREC(type, len) ((len - LOGRRC_FIX_LEN)/sizeof(type))
 
+#ifdef WAPI
+#define IV_LEN 16 /* XXX, same as SMS4_WPI_PN_LEN */
+struct wapi_sta_msg_t
+{
+	uint16  msg_type;
+	uint16  datalen;
+	uint8   vap_mac[6];
+	uint8   reserve_data1[2];
+	uint8   sta_mac[6];
+	uint8   reserve_data2[2];
+	uint8   gsn[IV_LEN];
+	uint8   wie[256];
+};
+#endif /* WAPI */
 
-
-
-
-#define CHANIM_DISABLE  0   
-#define CHANIM_DETECT   1   
-#define CHANIM_ACT  2   
+#define CHANIM_DISABLE  0
+#define CHANIM_DETECT   1
+#define CHANIM_ACT  2
 #define CHANIM_MODE_MAX 2
 
 
@@ -2464,17 +2499,17 @@
 
 typedef struct wl_smfs_elem {
 	uint32 count;
-	uint16 code;  
+	uint16 code;
 } wl_smfs_elem_t;
 
 typedef struct wl_smf_stats {
 	uint32 version;
-	uint16 length;  
+	uint16 length;
 	uint8 type;
 	uint8 codetype;
 	uint32 ignored_cnt;
 	uint32 malformed_cnt;
-	uint32 count_total; 
+	uint32 count_total;
 	wl_smfs_elem_t elem[1];
 } wl_smf_stats_t;
 
@@ -2505,7 +2540,7 @@
 #define PHYMON_VERSION 1
 
 typedef struct wl_phycal_core_state {
-	
+
 	int16 tx_iqlocal_a;
 	int16 tx_iqlocal_b;
 	int8 tx_iqlocal_ci;
@@ -2517,19 +2552,19 @@
 	int8 tx_iqlocal_fi;
 	int8 tx_iqlocal_fq;
 
-	
+
 	int16 rx_iqcal_a;
 	int16 rx_iqcal_b;
 
-	uint8 tx_iqlocal_pwridx; 
-	uint32 papd_epsilon_table[64]; 
-	int16 papd_epsilon_offset; 
-	uint8 curr_tx_pwrindex; 
-	int8 idle_tssi; 
-	int8 est_tx_pwr; 
-	int8 est_rx_pwr; 
-	uint16 rx_gaininfo; 
-	uint16 init_gaincode; 
+	uint8 tx_iqlocal_pwridx;
+	uint32 papd_epsilon_table[64];
+	int16 papd_epsilon_offset;
+	uint8 curr_tx_pwrindex;
+	int8 idle_tssi;
+	int8 est_tx_pwr;
+	int8 est_rx_pwr;
+	uint16 rx_gaininfo;
+	uint16 init_gaincode;
 	int8 estirr_tx;
 	int8 estirr_rx;
 
@@ -2537,25 +2572,25 @@
 
 typedef struct wl_phycal_state {
 	int version;
-	int8 num_phy_cores; 
-	int8 curr_temperature; 
-	chanspec_t chspec; 
-	bool aci_state; 
-	uint16 crsminpower; 
-	uint16 crsminpowerl; 
-	uint16 crsminpoweru; 
+	int8 num_phy_cores;
+	int8 curr_temperature;
+	chanspec_t chspec;
+	bool aci_state;
+	uint16 crsminpower;
+	uint16 crsminpowerl;
+	uint16 crsminpoweru;
 	wl_phycal_core_state_t phycal_core[1];
 } wl_phycal_state_t;
 
 #define WL_PHYCAL_STAT_FIXED_LEN OFFSETOF(wl_phycal_state_t, phycal_core)
-#endif 
+#endif
 
 #ifdef WLP2P
 
 typedef struct wl_p2p_disc_st {
-	uint8 state;    
-	chanspec_t chspec;  
-	uint16 dwell;   
+	uint8 state;
+	chanspec_t chspec;
+	uint16 dwell;
 } wl_p2p_disc_st_t;
 
 
@@ -2565,16 +2600,16 @@
 
 
 typedef struct wl_p2p_scan {
-	uint8 type;     
+	uint8 type;
 	uint8 reserved[3];
-	
+
 } wl_p2p_scan_t;
 
 
 typedef struct wl_p2p_if {
 	struct ether_addr addr;
-	uint8 type; 
-	chanspec_t chspec;  
+	uint8 type;
+	chanspec_t chspec;
 } wl_p2p_if_t;
 
 
@@ -2591,8 +2626,8 @@
 
 
 typedef struct wl_p2p_ops {
-	uint8 ops;  
-	uint8 ctw;  
+	uint8 ops;
+	uint8 ctw;
 } wl_p2p_ops_t;
 
 
@@ -2600,44 +2635,44 @@
 	uint32 start;
 	uint32 interval;
 	uint32 duration;
-	uint32 count;   
+	uint32 count;
 } wl_p2p_sched_desc_t;
 
 
 #define WL_P2P_SCHED_RSVD   0
-#define WL_P2P_SCHED_REPEAT 255 
+#define WL_P2P_SCHED_REPEAT 255
 
 typedef struct wl_p2p_sched {
-	uint8 type; 
-	uint8 action;   
-	uint8 option;   
+	uint8 type;
+	uint8 action;
+	uint8 option;
 	wl_p2p_sched_desc_t desc[1];
 } wl_p2p_sched_t;
 #define WL_P2P_SCHED_FIXED_LEN      3
 
 
-#define WL_P2P_SCHED_TYPE_ABS       0   
-#define WL_P2P_SCHED_TYPE_REQ_ABS   1   
+#define WL_P2P_SCHED_TYPE_ABS       0
+#define WL_P2P_SCHED_TYPE_REQ_ABS   1
 
 
-#define WL_P2P_SCHED_ACTION_NONE    0   
-#define WL_P2P_SCHED_ACTION_DOZE    1   
+#define WL_P2P_SCHED_ACTION_NONE    0
+#define WL_P2P_SCHED_ACTION_DOZE    1
 
-#define WL_P2P_SCHED_ACTION_GOOFF   2   
+#define WL_P2P_SCHED_ACTION_GOOFF   2
 
-#define WL_P2P_SCHED_ACTION_RESET   255 
+#define WL_P2P_SCHED_ACTION_RESET   255
 
 
-#define WL_P2P_SCHED_OPTION_NORMAL  0   
-#define WL_P2P_SCHED_OPTION_BCNPCT  1   
+#define WL_P2P_SCHED_OPTION_NORMAL  0
+#define WL_P2P_SCHED_OPTION_BCNPCT  1
 
-#define WL_P2P_SCHED_OPTION_TSFOFS  2   
+#define WL_P2P_SCHED_OPTION_TSFOFS  2
 
 
-#define WL_P2P_FEAT_GO_CSA      (1 << 0)        
-#define WL_P2P_FEAT_GO_NOLEGACY (1 << 1)        
-#define WL_P2P_FEAT_RESTRICT_DEV_RESP (1 << 2)  
-#endif 
+#define WL_P2P_FEAT_GO_CSA      (1 << 0)
+#define WL_P2P_FEAT_GO_NOLEGACY (1 << 1)
+#define WL_P2P_FEAT_RESTRICT_DEV_RESP (1 << 2)
+#endif
 
 
 #define BCM_ACTION_RFAWARE      0x77
@@ -2675,29 +2710,29 @@
 
 struct  wl_lq {
 	int32 enable;
-	int32 rssi[LQ_IDX_LAST];    
+	int32 rssi[LQ_IDX_LAST];
 	int32 rssicnt;
-	int32 snr[LQ_IDX_LAST];     
-	uint32 nsamples;            
-	uint8 isvalid;              
+	int32 snr[LQ_IDX_LAST];
+	uint32 nsamples;
+	uint8 isvalid;
 	uint8 version;
-}; 
+};
 
 typedef struct wl_lq wl_lq_t;
 typedef struct wl_lq  wl_lq_stats_t;
 
 typedef struct {
-	struct  ether_addr ea;  
-	uint8   ac_cat; 
-	uint8   num_pkts;   
-} wl_mac_ratehisto_cmd_t;   
+	struct  ether_addr ea;
+	uint8   ac_cat;
+	uint8   num_pkts;
+} wl_mac_ratehisto_cmd_t;
 
 
 typedef struct {
-	uint32  rate[WLC_MAXRATE + 1];  
-	uint32  mcs_index[MCS_INDEX_SIZE];  
-	uint32  tsf_timer[2][2];    
-} wl_mac_ratehisto_res_t;   
+	uint32  rate[WLC_MAXRATE + 1];
+	uint32  mcs_index[MCS_INDEX_SIZE];
+	uint32  tsf_timer[2][2];
+} wl_mac_ratehisto_res_t;
 
 #ifdef PROP_TXSTATUS
 
@@ -2713,7 +2748,7 @@
 #define WLFC_FLAGS_HOST_PROPTXSTATUS_ACTIVE     8
 #define WLFC_FLAGS_PSQ_GENERATIONFSM_ENABLE     16
 #define WLFC_FLAGS_PSQ_ZERO_BUFFER_ENABLE	32
-#endif 
+#endif
 
 #define BTA_STATE_LOG_SZ    64
 
@@ -2740,10 +2775,10 @@
 	struct ether_addr ea;
 } flush_txfifo_t;
 
-#define CHANNEL_5G_LOW_START    36      
-#define CHANNEL_5G_MID_START    52      
-#define CHANNEL_5G_HIGH_START   100     
-#define CHANNEL_5G_UPPER_START  149     
+#define CHANNEL_5G_LOW_START    36
+#define CHANNEL_5G_MID_START    52
+#define CHANNEL_5G_HIGH_START   100
+#define CHANNEL_5G_UPPER_START  149
 
 enum {
 	SPATIAL_MODE_2G_IDX = 0,
@@ -2754,4 +2789,4 @@
 	SPATIAL_MODE_MAX_IDX
 };
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/linux_osl.c b/drivers/net/wireless/bcmdhd/linux_osl.c
index 1a54437..04c5487 100644
--- a/drivers/net/wireless/bcmdhd/linux_osl.c
+++ b/drivers/net/wireless/bcmdhd/linux_osl.c
@@ -2,13 +2,13 @@
  * Linux OS Independent Layer
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: linux_osl.c,v 1.168.2.7 2011-01-27 17:01:13 Exp $
+ * $Id: linux_osl.c 281175 2011-09-01 09:46:46Z $
  */
 
 
@@ -44,10 +44,10 @@
 
 #define PCI_CFG_RETRY 		10
 
-#define OS_HANDLE_MAGIC		0x1234abcd	
-#define BCM_MEM_FILENAME_LEN 	24		
+#define OS_HANDLE_MAGIC		0x1234abcd
+#define BCM_MEM_FILENAME_LEN 	24
 
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 #define STATIC_BUF_MAX_NUM	16
 #define STATIC_BUF_SIZE		(PAGE_SIZE * 2)
 #define STATIC_BUF_TOTAL_LEN	(STATIC_BUF_MAX_NUM * STATIC_BUF_SIZE)
@@ -70,7 +70,7 @@
 } bcm_static_pkt_t;
 
 static bcm_static_pkt_t *bcm_static_skb = 0;
-#endif 
+#endif
 
 typedef struct bcm_mem_link {
 	struct bcm_mem_link *prev;
@@ -84,7 +84,7 @@
 	osl_pubinfo_t pub;
 #ifdef CTFPOOL
 	ctfpool_t *ctfpool;
-#endif 
+#endif
 	uint magic;
 	void *pdev;
 	atomic_t malloced;
@@ -99,49 +99,49 @@
 uint32 g_assert_type = FALSE;
 
 static int16 linuxbcmerrormap[] =
-{	0, 			
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL,		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-E2BIG,			
-	-E2BIG,			
-	-EBUSY, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EFAULT, 		
-	-ENOMEM, 		
-	-EOPNOTSUPP,		
-	-EMSGSIZE,		
-	-EINVAL,		
-	-EPERM,			
-	-ENOMEM, 		
-	-EINVAL, 		
-	-ERANGE, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL, 		
-	-EINVAL,		
-	-EIO,			
-	-ENODEV,		
-	-EINVAL,		
-	-EIO,			
-	-EIO,			
-	-ENODEV,		
-	-EINVAL,		
-	-ENODATA,		
+{	0,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-E2BIG,
+	-E2BIG,
+	-EBUSY,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EFAULT,
+	-ENOMEM,
+	-EOPNOTSUPP,
+	-EMSGSIZE,
+	-EINVAL,
+	-EPERM,
+	-ENOMEM,
+	-EINVAL,
+	-ERANGE,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EINVAL,
+	-EIO,
+	-ENODEV,
+	-EINVAL,
+	-EIO,
+	-EIO,
+	-ENODEV,
+	-EINVAL,
+	-ENODATA,
 
 
 
@@ -160,7 +160,7 @@
 	else if (bcmerror < BCME_LAST)
 		bcmerror = BCME_ERROR;
 
-	
+
 	return linuxbcmerrormap[-bcmerror];
 }
 
@@ -177,12 +177,12 @@
 	osh = kmalloc(sizeof(osl_t), flags);
 #else
 	osh = kmalloc(sizeof(osl_t), GFP_ATOMIC);
-#endif 
+#endif
 	ASSERT(osh);
 
 	bzero(osh, sizeof(osl_t));
 
-	
+
 	ASSERT(ABS(BCME_LAST) == (ARRAYSIZE(linuxbcmerrormap) - 1));
 
 	osh->magic = OS_HANDLE_MAGIC;
@@ -211,7 +211,7 @@
 			break;
 	}
 
-#if defined(DHD_USE_STATIC_BUF)
+#if defined(CONFIG_DHD_USE_STATIC_BUF)
 	if (!bcm_static_buf) {
 		if (!(bcm_static_buf = (bcm_static_buf_t *)dhd_os_prealloc(osh, 3, STATIC_BUF_SIZE+
 			STATIC_BUF_TOTAL_LEN))) {
@@ -238,7 +238,7 @@
 
 		sema_init(&bcm_static_skb->osl_pkt_sem, 1);
 	}
-#endif 
+#endif
 
 	return osh;
 }
@@ -277,13 +277,13 @@
 	spin_lock_bh(&osh->ctfpool->lock);
 	ASSERT(osh->ctfpool->curr_obj <= osh->ctfpool->max_obj);
 
-	
+
 	if (osh->ctfpool->curr_obj == osh->ctfpool->max_obj) {
 		spin_unlock_bh(&osh->ctfpool->lock);
 		return NULL;
 	}
 
-	
+
 	skb = osl_alloc_skb(osh->ctfpool->obj_size);
 	if (skb == NULL) {
 		printf("%s: skb alloc of len %d failed\n", __FUNCTION__,
@@ -292,16 +292,16 @@
 		return NULL;
 	}
 
-	
+
 	skb->next = (struct sk_buff *)osh->ctfpool->head;
 	osh->ctfpool->head = skb;
 	osh->ctfpool->fast_frees++;
 	osh->ctfpool->curr_obj++;
 
-	
+
 	CTFPOOLPTR(osh, skb) = (void *)osh->ctfpool;
 
-	
+
 	PKTFAST(osh, skb) = FASTBUF;
 
 	spin_unlock_bh(&osh->ctfpool->lock);
@@ -316,7 +316,7 @@
 	if ((osh == NULL) || (osh->ctfpool == NULL))
 		return;
 
-	
+
 	while ((osh->ctfpool->refills > 0) && (thresh--)) {
 		osl_ctfpool_add(osh);
 		osh->ctfpool->refills--;
@@ -334,7 +334,7 @@
 	osh->ctfpool = kmalloc(sizeof(ctfpool_t), flags);
 #else
 	osh->ctfpool = kmalloc(sizeof(ctfpool_t), GFP_ATOMIC);
-#endif 
+#endif
 	ASSERT(osh->ctfpool);
 	bzero(osh->ctfpool, sizeof(ctfpool_t));
 
@@ -388,14 +388,14 @@
 	if ((osh == NULL) || (osh->ctfpool == NULL))
 		return;
 
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 	if (bcm_static_buf) {
 		bcm_static_buf = 0;
 	}
 	if (bcm_static_skb) {
 		bcm_static_skb = 0;
 	}
-#endif 
+#endif
 
 	bb = b;
 
@@ -414,7 +414,7 @@
 {
 	struct sk_buff *skb;
 
-	
+
 	if (osh->ctfpool == NULL)
 		return NULL;
 
@@ -428,7 +428,7 @@
 
 	ASSERT(len <= osh->ctfpool->obj_size);
 
-	
+
 	skb = (struct sk_buff *)osh->ctfpool->head;
 	osh->ctfpool->head = (void *)skb->next;
 
@@ -437,7 +437,7 @@
 	ASSERT(CTFPOOLHEAD(osh, skb) == (struct sock *)osh->ctfpool->head);
 	spin_unlock_bh(&osh->ctfpool->lock);
 
-	
+
 	skb->next = skb->prev = NULL;
 	skb->data = skb->head + 16;
 	skb->tail = skb->head + 16;
@@ -460,6 +460,7 @@
 	struct sk_buff *skb;
 
 #ifdef CTFPOOL
+
 	skb = osl_pktfastget(osh, len);
 	if ((skb != NULL) || ((skb = osl_alloc_skb(len)) != NULL)) {
 #else
@@ -468,6 +469,7 @@
 		skb_put(skb, len);
 		skb->priority = 0;
 
+
 		osh->pub.pktalloced++;
 	}
 
@@ -483,7 +485,7 @@
 	ctfpool = (ctfpool_t *)CTFPOOLPTR(osh, skb);
 	ASSERT(ctfpool != NULL);
 
-	
+
 	spin_lock_bh(&ctfpool->lock);
 	skb->next = (struct sk_buff *)ctfpool->head;
 	ctfpool->head = (void *)skb;
@@ -500,14 +502,14 @@
 	skb->stamp.tv_sec = 0;
 #endif
 
-	
+
 	skb->dev = NULL;
 	skb->dst = NULL;
 	memset(skb->cb, 0, sizeof(skb->cb));
 	skb->ip_summed = 0;
 	skb->destructor = NULL;
 }
-#endif 
+#endif
 
 
 void BCMFASTPATH
@@ -520,7 +522,7 @@
 	if (send && osh->pub.tx_fn)
 		osh->pub.tx_fn(osh->pub.tx_ctx, p, 0);
 
-	
+
 	while (skb) {
 		nskb = skb->next;
 		skb->next = NULL;
@@ -530,15 +532,15 @@
 		if (PKTISFAST(osh, skb))
 			osl_pktfastfree(osh, skb);
 		else {
-#else 
+#else
 		{
-#endif 
+#endif
 
 			if (skb->destructor)
-				
+
 				dev_kfree_skb_any(skb);
 			else
-				
+
 				dev_kfree_skb(skb);
 		}
 
@@ -548,14 +550,14 @@
 	}
 }
 
-#ifdef DHD_USE_STATIC_BUF
+#ifdef CONFIG_DHD_USE_STATIC_BUF
 void *
 osl_pktget_static(osl_t *osh, uint len)
 {
 	int i;
 	struct sk_buff *skb;
 
-	if (len > (PAGE_SIZE * 2)) {
+	if (!bcm_static_skb || (len > (PAGE_SIZE * 2))) {
 		printk("%s: attempt to allocate huge packet (0x%x)\n", __FUNCTION__, len);
 		return osl_pktget(osh, len);
 	}
@@ -570,10 +572,10 @@
 
 		if (i != STATIC_PKT_MAX_NUM) {
 			bcm_static_skb->pkt_use[i] = 1;
-			up(&bcm_static_skb->osl_pkt_sem);
 			skb = bcm_static_skb->skb_4k[i];
 			skb->tail = skb->data + len;
 			skb->len = len;
+			up(&bcm_static_skb->osl_pkt_sem);
 			return skb;
 		}
 	}
@@ -586,10 +588,10 @@
 
 	if (i != STATIC_PKT_MAX_NUM) {
 		bcm_static_skb->pkt_use[i+STATIC_PKT_MAX_NUM] = 1;
-		up(&bcm_static_skb->osl_pkt_sem);
 		skb = bcm_static_skb->skb_8k[i];
 		skb->tail = skb->data + len;
 		skb->len = len;
+		up(&bcm_static_skb->osl_pkt_sem);
 		return skb;
 	}
 
@@ -603,9 +605,14 @@
 {
 	int i;
 
+	if (!bcm_static_skb) {
+		osl_pktfree(osh, p, send);
+		return;
+	}
+
+	down(&bcm_static_skb->osl_pkt_sem);
 	for (i = 0; i < STATIC_PKT_MAX_NUM; i++) {
 		if (p == bcm_static_skb->skb_4k[i]) {
-			down(&bcm_static_skb->osl_pkt_sem);
 			bcm_static_skb->pkt_use[i] = 0;
 			up(&bcm_static_skb->osl_pkt_sem);
 			return;
@@ -614,16 +621,17 @@
 
 	for (i = 0; i < STATIC_PKT_MAX_NUM; i++) {
 		if (p == bcm_static_skb->skb_8k[i]) {
-			down(&bcm_static_skb->osl_pkt_sem);
 			bcm_static_skb->pkt_use[i + STATIC_PKT_MAX_NUM] = 0;
 			up(&bcm_static_skb->osl_pkt_sem);
 			return;
 		}
 	}
+	up(&bcm_static_skb->osl_pkt_sem);
 
-	return osl_pktfree(osh, p, send);
+	osl_pktfree(osh, p, send);
+	return;
 }
-#endif 
+#endif
 
 uint32
 osl_pci_read_config(osl_t *osh, uint offset, uint size)
@@ -633,7 +641,7 @@
 
 	ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
 
-	
+
 	ASSERT(size == 4);
 
 	do {
@@ -653,7 +661,7 @@
 
 	ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
 
-	
+
 	ASSERT(size == 4);
 
 	do {
@@ -708,7 +716,7 @@
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 	gfp_t flags;
 
-	
+
 	if (osh)
 		ASSERT(osh->magic == OS_HANDLE_MAGIC);
 
@@ -716,7 +724,7 @@
 	if ((addr = kmalloc(size, flags)) == NULL) {
 #else
 	if ((addr = kmalloc(size, GFP_ATOMIC)) == NULL) {
-#endif 
+#endif
 		if (osh)
 			osh->failed++;
 		return (NULL);
@@ -808,7 +816,7 @@
 	char *basename;
 
 	basename = strrchr(file, '/');
-	
+
 	if (basename)
 		basename++;
 
@@ -820,11 +828,11 @@
 		exp, basename, line);
 
 	bcm_assert_log(tempbuf);
-#endif 
+#endif
 
 
 }
-#endif 
+#endif
 
 void
 osl_delay(uint usec)
@@ -851,27 +859,27 @@
 	if ((p = skb_clone((struct sk_buff *)skb, flags)) == NULL)
 #else
 	if ((p = skb_clone((struct sk_buff*)skb, GFP_ATOMIC)) == NULL)
-#endif 
+#endif
 		return NULL;
 
 #ifdef CTFPOOL
 	if (PKTISFAST(osh, skb)) {
 		ctfpool_t *ctfpool;
 
-		
+
 		ctfpool = (ctfpool_t *)CTFPOOLPTR(osh, skb);
 		ASSERT(ctfpool != NULL);
 		PKTCLRFAST(osh, p);
 		PKTCLRFAST(osh, skb);
 		ctfpool->refills++;
 	}
-#endif 
+#endif
 
-	
+
 	if (osh->pub.pkttag)
 		bzero((void*)((struct sk_buff *)p)->cb, OSL_PKTTAG_SZ);
 
-	
+
 	osh->pub.pktalloced++;
 	return (p);
 }
@@ -888,7 +896,7 @@
 	struct file *fp;
 
 	fp = filp_open(filename, O_RDONLY, 0);
-	
+
 	 if (IS_ERR(fp))
 		 fp = NULL;
 
diff --git a/drivers/net/wireless/bcmdhd/sbutils.c b/drivers/net/wireless/bcmdhd/sbutils.c
index 02d1bc0..be79f62 100644
--- a/drivers/net/wireless/bcmdhd/sbutils.c
+++ b/drivers/net/wireless/bcmdhd/sbutils.c
@@ -3,13 +3,13 @@
  * of the SiliconBackplane-based Broadcom chips.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: sbutils.c,v 1.687.2.1 2010-11-29 20:21:56 Exp $
+ * $Id: sbutils.c 275693 2011-08-04 19:59:34Z $
  */
 
 #include <typedefs.h>
diff --git a/drivers/net/wireless/bcmdhd/siutils.c b/drivers/net/wireless/bcmdhd/siutils.c
index 22aa412..0ff33cb 100644
--- a/drivers/net/wireless/bcmdhd/siutils.c
+++ b/drivers/net/wireless/bcmdhd/siutils.c
@@ -3,13 +3,13 @@
  * of the SiliconBackplane-based Broadcom chips.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: siutils.c,v 1.813.2.36 2011-02-10 23:43:55 Exp $
+ * $Id: siutils.c 279502 2011-08-24 20:46:27Z $
  */
 
 #include <typedefs.h>
diff --git a/drivers/net/wireless/bcmdhd/siutils_priv.h b/drivers/net/wireless/bcmdhd/siutils_priv.h
index d80246e..1798f77 100644
--- a/drivers/net/wireless/bcmdhd/siutils_priv.h
+++ b/drivers/net/wireless/bcmdhd/siutils_priv.h
@@ -2,13 +2,13 @@
  * Include file private to the SOC Interconnect support files.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: siutils_priv.h,v 1.17.4.3 2010-10-25 16:56:56 Exp $
+ * $Id: siutils_priv.h 275693 2011-08-04 19:59:34Z $
  */
 
 #ifndef	_siutils_priv_h_
diff --git a/drivers/net/wireless/bcmdhd/uamp_api.h b/drivers/net/wireless/bcmdhd/uamp_api.h
deleted file mode 100644
index c51c68c..0000000
--- a/drivers/net/wireless/bcmdhd/uamp_api.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- *  Name:       uamp_api.h
- *
- *  Description: Universal AMP API
- *
- * Copyright (C) 1999-2011, Broadcom Corporation
- * 
- *         Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- * 
- *      As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module.  An independent module is a module which is not
- * derived from this software.  The special exception does not apply to any
- * modifications of the software.
- * 
- *      Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: uamp_api.h,v 1.2.8.1 2011-02-05 00:16:14 Exp $
- *
- */
-#ifndef UAMP_API_H
-#define UAMP_API_H
-
-
-#include "typedefs.h"
-
-
-/*****************************************************************************
-**  Constant and Type Definitions
-******************************************************************************
-*/
-
-#define BT_API
-
-/* Types. */
-typedef bool	BOOLEAN;
-typedef uint8	UINT8;
-typedef uint16	UINT16;
-
-
-/* UAMP identifiers */
-#define UAMP_ID_1   1
-#define UAMP_ID_2   2
-typedef UINT8 tUAMP_ID;
-
-/* UAMP event ids (used by UAMP_CBACK) */
-#define UAMP_EVT_RX_READY           0   /* Data from AMP controller is ready to be read */
-#define UAMP_EVT_CTLR_REMOVED       1   /* Controller removed */
-#define UAMP_EVT_CTLR_READY         2   /* Controller added/ready */
-typedef UINT8 tUAMP_EVT;
-
-
-/* UAMP Channels */
-#define UAMP_CH_HCI_CMD            0   /* HCI Command channel */
-#define UAMP_CH_HCI_EVT            1   /* HCI Event channel */
-#define UAMP_CH_HCI_DATA           2   /* HCI ACL Data channel */
-typedef UINT8 tUAMP_CH;
-
-/* tUAMP_EVT_DATA: union for event-specific data, used by UAMP_CBACK */
-typedef union {
-    tUAMP_CH channel;       /* UAMP_EVT_RX_READY: channel for which rx occured */
-} tUAMP_EVT_DATA;
-
-
-/*****************************************************************************
-**
-** Function:    UAMP_CBACK
-**
-** Description: Callback for events. Register callback using UAMP_Init.
-**
-** Parameters   amp_id:         AMP device identifier that generated the event
-**              amp_evt:        event id
-**              p_amp_evt_data: pointer to event-specific data
-**
-******************************************************************************
-*/
-typedef void (*tUAMP_CBACK)(tUAMP_ID amp_id, tUAMP_EVT amp_evt, tUAMP_EVT_DATA *p_amp_evt_data);
-
-/*****************************************************************************
-**  external function declarations
-******************************************************************************
-*/
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/*****************************************************************************
-**
-** Function:    UAMP_Init
-**
-** Description: Initialize UAMP driver
-**
-** Parameters   p_cback:    Callback function for UAMP event notification
-**
-******************************************************************************
-*/
-BT_API BOOLEAN UAMP_Init(tUAMP_CBACK p_cback);
-
-
-/*****************************************************************************
-**
-** Function:    UAMP_Open
-**
-** Description: Open connection to local AMP device.
-**
-** Parameters   app_id: Application specific AMP identifer. This value
-**                      will be included in AMP messages sent to the
-**                      BTU task, to identify source of the message
-**
-******************************************************************************
-*/
-BT_API BOOLEAN UAMP_Open(tUAMP_ID amp_id);
-
-/*****************************************************************************
-**
-** Function:    UAMP_Close
-**
-** Description: Close connection to local AMP device.
-**
-** Parameters   app_id: Application specific AMP identifer.
-**
-******************************************************************************
-*/
-BT_API void UAMP_Close(tUAMP_ID amp_id);
-
-
-/*****************************************************************************
-**
-** Function:    UAMP_Write
-**
-** Description: Send buffer to AMP device. Frees GKI buffer when done.
-**
-**
-** Parameters:  app_id:     AMP identifer.
-**              p_buf:      pointer to buffer to write
-**              num_bytes:  number of bytes to write
-**              channel:    UAMP_CH_HCI_ACL, or UAMP_CH_HCI_CMD
-**
-** Returns:     number of bytes written
-**
-******************************************************************************
-*/
-BT_API UINT16 UAMP_Write(tUAMP_ID amp_id, UINT8 *p_buf, UINT16 num_bytes, tUAMP_CH channel);
-
-/*****************************************************************************
-**
-** Function:    UAMP_Read
-**
-** Description: Read incoming data from AMP. Call after receiving a
-**              UAMP_EVT_RX_READY callback event.
-**
-** Parameters:  app_id:     AMP identifer.
-**              p_buf:      pointer to buffer for holding incoming AMP data
-**              buf_size:   size of p_buf
-**              channel:    UAMP_CH_HCI_ACL, or UAMP_CH_HCI_EVT
-**
-** Returns:     number of bytes read
-**
-******************************************************************************
-*/
-BT_API UINT16 UAMP_Read(tUAMP_ID amp_id, UINT8 *p_buf, UINT16 buf_size, tUAMP_CH channel);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* UAMP_API_H */
diff --git a/drivers/net/wireless/bcmdhd/wl_android.c b/drivers/net/wireless/bcmdhd/wl_android.c
index 9ca3d60..e83d292 100644
--- a/drivers/net/wireless/bcmdhd/wl_android.c
+++ b/drivers/net/wireless/bcmdhd/wl_android.c
@@ -53,29 +53,29 @@
  * so they can be updated easily in the future (if needed)
  */
 
-#define CMD_START				"START"
-#define CMD_STOP				"STOP"
+#define CMD_START			"START"
+#define CMD_STOP			"STOP"
 #define CMD_SCAN_ACTIVE			"SCAN-ACTIVE"
 #define CMD_SCAN_PASSIVE		"SCAN-PASSIVE"
-#define CMD_RSSI				"RSSI"
+#define CMD_RSSI			"RSSI"
 #define CMD_LINKSPEED			"LINKSPEED"
 #define CMD_RXFILTER_START		"RXFILTER-START"
 #define CMD_RXFILTER_STOP		"RXFILTER-STOP"
 #define CMD_RXFILTER_ADD		"RXFILTER-ADD"
 #define CMD_RXFILTER_REMOVE		"RXFILTER-REMOVE"
-#define CMD_BTCOEXSCAN_START	"BTCOEXSCAN-START"
+#define CMD_BTCOEXSCAN_START		"BTCOEXSCAN-START"
 #define CMD_BTCOEXSCAN_STOP		"BTCOEXSCAN-STOP"
 #define CMD_BTCOEXMODE			"BTCOEXMODE"
 #define CMD_SETSUSPENDOPT		"SETSUSPENDOPT"
 #define CMD_P2P_DEV_ADDR		"P2P_DEV_ADDR"
 #define CMD_SETFWPATH			"SETFWPATH"
-#define CMD_SETBAND				"SETBAND"
-#define CMD_GETBAND				"GETBAND"
-#define CMD_COUNTRY				"COUNTRY"
+#define CMD_SETBAND			"SETBAND"
+#define CMD_GETBAND			"GETBAND"
+#define CMD_COUNTRY			"COUNTRY"
 #define CMD_P2P_SET_NOA			"P2P_SET_NOA"
 #define CMD_P2P_GET_NOA			"P2P_GET_NOA"
 #define CMD_P2P_SET_PS			"P2P_SET_PS"
-#define CMD_SET_AP_WPS_P2P_IE	"SET_AP_WPS_P2P_IE"
+#define CMD_SET_AP_WPS_P2P_IE 		"SET_AP_WPS_P2P_IE"
 
 
 #ifdef PNO_SUPPORT
@@ -108,7 +108,7 @@
 } android_wifi_priv_cmd;
 
 /**
- * Extern function declarations (TODO: move them to dhd_linux.h)
+ * Extern function declarations
  */
 void dhd_customer_gpio_wlan_ctrl(int onoff);
 uint dhd_dev_reset(struct net_device *dev, uint8 flag);
@@ -130,7 +130,7 @@
 extern void *bcmsdh_get_drvdata(void);
 
 extern bool ap_fw_loaded;
-#ifdef CUSTOMER_HW2
+#ifdef CUSTOMER_HW
 extern char iface_name[IFNAMSIZ];
 #endif
 
@@ -265,11 +265,12 @@
 		goto exit_proc;
 	}
 
+
 #ifdef PNO_SET_DEBUG
 	memcpy(command, pno_in_example, sizeof(pno_in_example));
 	for (i = 0; i < sizeof(pno_in_example); i++)
-		printf("%02X ", command[i]);
-	printf("\n");
+		DHD_TRACE(("%02X ", command[i]));
+	DHD_TRACE(("\n"));
 	total_len = sizeof(pno_in_example);
 #endif
 
@@ -352,7 +353,6 @@
 {
 	int ret = 0;
 
-	printk("%s in\n", __FUNCTION__);
 	if (!dev) {
 		DHD_ERROR(("%s: dev is null\n", __FUNCTION__));
 		return -EINVAL;
@@ -364,8 +364,7 @@
 		sdioh_start(NULL, 0);
 		ret = dhd_dev_reset(dev, FALSE);
 		sdioh_start(NULL, 1);
-		if (!ret)
-			dhd_dev_init_ioctl(dev);
+		dhd_dev_init_ioctl(dev);
 		g_wifi_on = 1;
 	}
 	dhd_net_if_unlock(dev);
@@ -377,7 +376,6 @@
 {
 	int ret = 0;
 
-	printk("%s in\n", __FUNCTION__);
 	if (!dev) {
 		DHD_TRACE(("%s: dev is null\n", __FUNCTION__));
 		return -EINVAL;
@@ -385,7 +383,7 @@
 
 	dhd_net_if_lock(dev);
 	if (g_wifi_on) {
-		ret = dhd_dev_reset(dev, TRUE);
+		dhd_dev_reset(dev, 1);
 		sdioh_stop(NULL);
 		dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
 		g_wifi_on = 0;
@@ -558,8 +556,9 @@
 		snprintf(command, 3, "OK");
 		bytes_written = strlen("OK");
 	}
-
-	if (bytes_written > 0) {
+	if (bytes_written >= 0) {
+		if (bytes_written == 0)
+			command[0] = '\0';
 		if (bytes_written > priv_cmd.total_len) {
 			DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written));
 			bytes_written = priv_cmd.total_len;
@@ -571,7 +570,8 @@
 			DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__));
 			ret = -EFAULT;
 		}
-	} else {
+	}
+	else {
 		ret = bytes_written;
 	}
 
@@ -592,12 +592,12 @@
 #ifdef ENABLE_INSMOD_NO_FW_LOAD
 	dhd_download_fw_on_driverload = FALSE;
 #endif /* ENABLE_INSMOD_NO_FW_LOAD */
-#ifdef CUSTOMER_HW2
+#ifdef CUSTOMER_HW
 	if (!iface_name[0]) {
 		memset(iface_name, 0, IFNAMSIZ);
 		bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ);
 	}
-#endif /* CUSTOMER_HW2 */
+#endif /* CUSTOMER_HW */
 	return ret;
 }
 
@@ -608,30 +608,14 @@
 	return ret;
 }
 
-int wl_android_post_init(void)
+void wl_android_post_init(void)
 {
-	struct net_device *ndev;
-	int ret = 0;
-	char buf[IFNAMSIZ];
 	if (!dhd_download_fw_on_driverload) {
 		/* Call customer gpio to turn off power with WL_REG_ON signal */
 		dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
 		g_wifi_on = 0;
-	} else {
-		memset(buf, 0, IFNAMSIZ);
-#ifdef CUSTOMER_HW2
-		snprintf(buf, IFNAMSIZ, "%s%d", iface_name, 0);
-#else
-		snprintf(buf, IFNAMSIZ, "%s%d", "eth", 0);
-#endif
-		if ((ndev = dev_get_by_name (&init_net, buf)) != NULL) {
-			dhd_dev_init_ioctl(ndev);
-			dev_put(ndev);
-		}
 	}
-	return ret;
 }
-
 /**
  * Functions for Android WiFi card detection
  */
@@ -640,7 +624,6 @@
 static int g_wifidev_registered = 0;
 static struct semaphore wifi_control_sem;
 static struct wifi_platform_data *wifi_control_data = NULL;
-static struct resource *wifi_irqres = NULL;
 
 static int wifi_add_dev(void);
 static void wifi_del_dev(void);
@@ -691,44 +674,7 @@
 	return 0;
 }
 
-int wifi_get_irq_number(unsigned long *irq_flags_ptr)
-{
-	if (wifi_irqres) {
-		*irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
-		return (int)wifi_irqres->start;
-	}
-#ifdef CUSTOM_OOB_GPIO_NUM
-	return CUSTOM_OOB_GPIO_NUM;
-#else
-	return -1;
-#endif
-}
-
-int wifi_set_power(int on, unsigned long msec)
-{
-	DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
-	if (wifi_control_data && wifi_control_data->set_power) {
-		wifi_control_data->set_power(on);
-	}
-	if (msec)
-		msleep(msec);
-	return 0;
-}
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
-int wifi_get_mac_addr(unsigned char *buf)
-{
-	DHD_ERROR(("%s\n", __FUNCTION__));
-	if (!buf)
-		return -EINVAL;
-	if (wifi_control_data && wifi_control_data->get_mac_addr) {
-		return wifi_control_data->get_mac_addr(buf);
-	}
-	return -EOPNOTSUPP;
-}
-#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+#if !defined(CUSTOMER_HW) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
 void *wifi_get_country_code(char *ccode)
 {
 	DHD_TRACE(("%s\n", __FUNCTION__));
@@ -739,7 +685,7 @@
 	}
 	return NULL;
 }
-#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
+#endif /* !(CUSTOMER_HW) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
 
 static int wifi_set_carddetect(int on)
 {
@@ -756,13 +702,8 @@
 		(struct wifi_platform_data *)(pdev->dev.platform_data);
 
 	DHD_ERROR(("## %s\n", __FUNCTION__));
-	wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
-	if (wifi_irqres == NULL)
-		wifi_irqres = platform_get_resource_byname(pdev,
-			IORESOURCE_IRQ, "bcm4329_wlan_irq");
 	wifi_control_data = wifi_ctrl;
 
-	wifi_set_power(1, 0);	/* Power On */
 	wifi_set_carddetect(1);	/* CardDetect (0->1) */
 
 	up(&wifi_control_sem);
@@ -777,7 +718,6 @@
 	DHD_ERROR(("## %s\n", __FUNCTION__));
 	wifi_control_data = wifi_ctrl;
 
-	wifi_set_power(0, 0);	/* Power Off */
 	wifi_set_carddetect(0);	/* CardDetect (1->0) */
 
 	up(&wifi_control_sem);
@@ -787,19 +727,19 @@
 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
 {
 	DHD_TRACE(("##> %s\n", __FUNCTION__));
-#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
+#if defined(OOB_INTR_ONLY)
 	bcmsdh_oob_intr_set(0);
-#endif
+#endif /* (OOB_INTR_ONLY) */
 	return 0;
 }
 
 static int wifi_resume(struct platform_device *pdev)
 {
 	DHD_TRACE(("##> %s\n", __FUNCTION__));
-#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
+#if defined(OOB_INTR_ONLY)
 	if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
 		bcmsdh_oob_intr_set(1);
-#endif
+#endif /* (OOB_INTR_ONLY) */
 	return 0;
 }
 
@@ -809,17 +749,7 @@
 	.suspend        = wifi_suspend,
 	.resume         = wifi_resume,
 	.driver         = {
-	.name   = "bcmdhd_wlan",
-	}
-};
-
-static struct platform_driver wifi_device_legacy = {
-	.probe          = wifi_probe,
-	.remove         = wifi_remove,
-	.suspend        = wifi_suspend,
-	.resume         = wifi_resume,
-	.driver         = {
-	.name   = "bcm4329_wlan",
+	.name   = "bcm4330_wlan",
 	}
 };
 
@@ -827,7 +757,6 @@
 {
 	DHD_TRACE(("## Calling platform_driver_register\n"));
 	platform_driver_register(&wifi_device);
-	platform_driver_register(&wifi_device_legacy);
 	return 0;
 }
 
@@ -835,6 +764,5 @@
 {
 	DHD_TRACE(("## Unregister platform_driver_register\n"));
 	platform_driver_unregister(&wifi_device);
-	platform_driver_unregister(&wifi_device_legacy);
 }
 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
diff --git a/drivers/net/wireless/bcmdhd/wl_android.h b/drivers/net/wireless/bcmdhd/wl_android.h
index 17373b7..3983306 100644
--- a/drivers/net/wireless/bcmdhd/wl_android.h
+++ b/drivers/net/wireless/bcmdhd/wl_android.h
@@ -40,7 +40,7 @@
  */
 int wl_android_init(void);
 int wl_android_exit(void);
-int wl_android_post_init(void);
+void wl_android_post_init(void);
 int wl_android_wifi_on(struct net_device *dev);
 int wl_android_wifi_off(struct net_device *dev);
 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd);
diff --git a/drivers/net/wireless/bcmdhd/wl_cfg80211.c b/drivers/net/wireless/bcmdhd/wl_cfg80211.c
index daa7d26..87482c6 100644
--- a/drivers/net/wireless/bcmdhd/wl_cfg80211.c
+++ b/drivers/net/wireless/bcmdhd/wl_cfg80211.c
@@ -2,6 +2,7 @@
  * Linux cfg80211 driver
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
+ * Copyright (C) 2012 Sony Mobile Communications AB.
  *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
@@ -16,7 +17,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -41,10 +42,9 @@
 #include <dhd.h>
 #include <dhdioctl.h>
 #include <wlioctl.h>
+#include <dhd_cfg80211.h>
 
 #include <proto/ethernet.h>
-#include <dngl_stats.h>
-#include <dhd.h>
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/netdevice.h>
@@ -54,54 +54,67 @@
 #include <linux/ieee80211.h>
 #include <linux/wait.h>
 #include <net/cfg80211.h>
-
 #include <net/rtnetlink.h>
-#include <linux/mmc/sdio_func.h>
-#include <linux/firmware.h>
-#include <bcmsdbus.h>
 
 #include <wlioctl.h>
 #include <wldev_common.h>
 #include <wl_cfg80211.h>
 #include <wl_cfgp2p.h>
 
-static struct sdio_func *cfg80211_sdio_func;
-static struct wl_priv *wlcfg_drv_priv;
+#ifdef WAPI
+/* these items should evetually go into wireless.h of the linux system headfile dir */
+#ifndef IW_ENCODE_ALG_SM4
+#define IW_ENCODE_ALG_SM4 0x20
+#endif
+
+#ifndef IW_AUTH_WAPI_ENABLED
+#define IW_AUTH_WAPI_ENABLED 0x20
+#endif
+
+#ifndef IW_AUTH_WAPI_VERSION_1
+#define IW_AUTH_WAPI_VERSION_1  0x00000008
+#endif
+
+#ifndef IW_AUTH_CIPHER_SMS4
+#define IW_AUTH_CIPHER_SMS4     0x00000020
+#endif
+
+#ifndef IW_AUTH_KEY_MGMT_WAPI_PSK
+#define IW_AUTH_KEY_MGMT_WAPI_PSK 4
+#endif
+
+#ifndef IW_AUTH_KEY_MGMT_WAPI_CERT
+#define IW_AUTH_KEY_MGMT_WAPI_CERT 8
+#endif
+#endif /* WAPI */
+
+#ifdef WAPI
+#define IW_WSEC_ENABLED(wsec)   ((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED | SMS4_ENABLED))
+#else /* WAPI */
+#define IW_WSEC_ENABLED(wsec)   ((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))
+#endif /* WAPI */
+
+static struct device *cfg80211_parent_dev = NULL;
+struct wl_priv *wlcfg_drv_priv = NULL;
 
 u32 wl_dbg_level = WL_DBG_ERR;
 
-#define WL_4329_FW_FILE "brcm/bcm4329-fullmac-4-218-248-5.bin"
-#define WL_4329_NVRAM_FILE "brcm/bcm4329-fullmac-4-218-248-5.txt"
 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
 #define MAX_WAIT_TIME 1500
-static s8 ioctlbuf[WLC_IOCTL_MAXLEN];
+#define WL_SCAN_ACTIVE_TIME	 40
+#define WL_SCAN_PASSIVE_TIME	130
+#define WL_FRAME_LEN			300
 
+
+#define DNGL_FUNC(func, parameters) func parameters;
 #define COEX_DHCP
 
-#if defined(COEX_DHCP)
-#define BT_DHCP_eSCO_FIX		/* use New SCO/eSCO smart YG
-					 * suppression
-					 */
-#define BT_DHCP_USE_FLAGS		/* this flag boost wifi pkt priority
-					 * to max, caution: -not fair to sco
-					 */
-#define BT_DHCP_OPPR_WIN_TIME	2500	/* T1 start SCO/ESCo priority
-					 * suppression
-					 */
-#define BT_DHCP_FLAG_FORCE_TIME 5500	/* T2 turn off SCO/SCO supperesion
-					 * is (timeout)
-					 */
-enum wl_cfg80211_btcoex_status {
-	BT_DHCP_IDLE,
-	BT_DHCP_START,
-	BT_DHCP_OPPR_WIN,
-	BT_DHCP_FLAG_FORCE_TIMEOUT
-};
 
-static int wl_cfg80211_btcoex_init(struct wl_priv *wl);
-static void wl_cfg80211_btcoex_deinit(struct wl_priv *wl);
-#endif
+/* Set this to 1 to use a seperate interface (p2p0)
+ *  for p2p operations.
+ */
+#define ENABLE_P2P_INTERFACE	0
 
 /* This is to override regulatory domains defined in cfg80211 module (reg.c)
  * By default world regulatory domain defined in reg.c puts the flags NL80211_RRF_PASSIVE_SCAN
@@ -224,7 +237,7 @@
 	struct cfg80211_pmksa *pmksa);
 static s32 wl_cfg80211_flush_pmksa(struct wiphy *wiphy,
 	struct net_device *dev);
-static void wl_notify_escan_complete(struct wl_priv *wl, bool aborted);
+static void wl_notify_escan_complete(struct wl_priv *wl, struct net_device *ndev, bool aborted);
 /*
  * event & event Q handlers for cfg80211 interfaces
  */
@@ -257,21 +270,9 @@
 static s32 wl_notify_mic_status(struct wl_priv *wl, struct net_device *ndev,
 	const wl_event_msg_t *e, void *data);
 /*
- * register/deregister sdio function
+ * register/deregister parent device
  */
-struct sdio_func *wl_cfg80211_get_sdio_func(void);
-static void wl_clear_sdio_func(void);
-
-/*
- * ioctl utilites
- */
-static s32 wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
-	s32 buf_len);
-static __used s32 wl_dev_bufvar_set(struct net_device *dev, s8 *name,
-	s8 *buf, s32 len);
-static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val);
-static s32 wl_dev_intvar_get(struct net_device *dev, s8 *name,
-	s32 *retval);
+static void wl_cfg80211_clear_parent_dev(void);
 
 /*
  * cfg80211 set_wiphy_params utilities
@@ -283,10 +284,10 @@
 /*
  * wl profile utilities
  */
-static s32 wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e,
-	void *data, s32 item);
-static void *wl_read_prof(struct wl_priv *wl, s32 item);
-static void wl_init_prof(struct wl_priv *wl);
+static s32 wl_update_prof(struct wl_priv *wl, struct net_device *ndev,
+	const wl_event_msg_t *e, void *data, s32 item);
+static void *wl_read_prof(struct wl_priv *wl, struct net_device *ndev, s32 item);
+static void wl_init_prof(struct wl_priv *wl, struct net_device *ndev);
 
 /*
  * cfg80211 connect utilites
@@ -301,6 +302,10 @@
 	struct cfg80211_connect_params *sme);
 static s32 wl_set_set_sharedkey(struct net_device *dev,
 	struct cfg80211_connect_params *sme);
+#ifdef WAPI
+static s32 wl_set_set_wapi_ie(struct net_device *dev,
+        struct cfg80211_connect_params *sme);
+#endif
 static s32 wl_get_assoc_ies(struct wl_priv *wl, struct net_device *ndev);
 static void wl_ch_to_chanspec(int ch,
 	struct wl_join_params *join_params, size_t *join_params_size);
@@ -314,14 +319,14 @@
 static s32 wl_cp_ie(struct wl_priv *wl, u8 *dst, u16 dst_size);
 static u32 wl_get_ielen(struct wl_priv *wl);
 
-static s32 wl_mode_to_nl80211_iftype(s32 mode);
 
-static struct wireless_dev *wl_alloc_wdev(struct device *sdiofunc_dev);
+static struct wireless_dev *wl_alloc_wdev(struct device *dev);
 static void wl_free_wdev(struct wl_priv *wl);
 
 static s32 wl_inform_bss(struct wl_priv *wl);
 static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi);
 static s32 wl_update_bss_info(struct wl_priv *wl, struct net_device *ndev);
+static chanspec_t wl_cfg80211_get_shared_freq(struct wiphy *wiphy);
 
 static s32 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
 	u8 key_idx, const u8 *mac_addr,
@@ -347,42 +352,19 @@
 static __used bool wl_is_ibssstarter(struct wl_priv *wl);
 
 /*
- * dongle up/down , default configuration utilities
+ * link up/down , default configuration utilities
  */
+static s32 __wl_cfg80211_up(struct wl_priv *wl);
+static s32 __wl_cfg80211_down(struct wl_priv *wl);
+static s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
 static bool wl_is_linkdown(struct wl_priv *wl, const wl_event_msg_t *e);
 static bool wl_is_linkup(struct wl_priv *wl, const wl_event_msg_t *e, struct net_device *ndev);
 static bool wl_is_nonetwork(struct wl_priv *wl, const wl_event_msg_t *e);
 static void wl_link_up(struct wl_priv *wl);
 static void wl_link_down(struct wl_priv *wl);
-static s32 wl_dongle_mode(struct wl_priv *wl, struct net_device *ndev, s32 iftype);
-static s32 __wl_cfg80211_up(struct wl_priv *wl);
-static s32 __wl_cfg80211_down(struct wl_priv *wl);
-static s32 wl_dongle_probecap(struct wl_priv *wl);
+static s32 wl_config_ifmode(struct wl_priv *wl, struct net_device *ndev, s32 iftype);
 static void wl_init_conf(struct wl_conf *conf);
-static s32 wl_dongle_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
-
-/*
- * dongle configuration utilities
- */
-#ifndef EMBEDDED_PLATFORM
-static s32 wl_dongle_country(struct net_device *ndev, u8 ccode);
-static s32 wl_dongle_up(struct net_device *ndev, u32 up);
-static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode);
-static s32 wl_dongle_glom(struct net_device *ndev, u32 glom,
-	u32 dongle_align);
-static s32 wl_dongle_roam(struct net_device *ndev, u32 roamvar,
-	u32 bcn_timeout);
-static s32 wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
-	s32 scan_unassoc_time);
-static s32 wl_dongle_offload(struct net_device *ndev, s32 arpoe,
-	s32 arp_ol);
-static s32 wl_pattern_atoh(s8 *src, s8 *dst);
-static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode);
 static s32 wl_update_wiphybands(struct wl_priv *wl);
-#endif				/* !EMBEDDED_PLATFORM */
-static __used void wl_dongle_poweron(struct wl_priv *wl);
-static __used void wl_dongle_poweroff(struct wl_priv *wl);
-static s32 wl_config_dongle(struct wl_priv *wl, bool need_lock);
 
 /*
  * iscan handler
@@ -406,33 +388,20 @@
 static s32 wl_iscan_aborted(struct wl_priv *wl);
 
 /*
- * fw/nvram downloading handler
- */
-static void wl_init_fw(struct wl_fw_ctrl *fw);
-
-/*
  * find most significant bit set
  */
 static __used u32 wl_find_msb(u16 bit16);
 
 /*
- * update pmklist to dongle
- */
-static __used s32 wl_update_pmklist(struct net_device *dev,
-	struct wl_pmk_list *pmk_list, s32 err);
-
-/*
- * debufs support
- */
-static int wl_debugfs_add_netdev_params(struct wl_priv *wl);
-static void wl_debugfs_remove_netdev(struct wl_priv *wl);
-
-/*
  * rfkill support
  */
 static int wl_setup_rfkill(struct wl_priv *wl, bool setup);
 static int wl_rfkill_set(void *data, bool blocked);
 
+static wl_scan_params_t *wl_cfg80211_scan_alloc_params(int channel,
+	int nprobes, int *out_params_size);
+static void get_primary_mac(struct wl_priv *wl, struct ether_addr *mac);
+
 /*
  * Some external functions, TODO: move them to dhd_linux.h
  */
@@ -442,12 +411,13 @@
 int dhd_monitor_uninit(void);
 int dhd_start_xmit(struct sk_buff *skb, struct net_device *net);
 
+
 #define CHECK_SYS_UP(wlpriv)							\
 do {									\
-	if (unlikely(!wl_get_drv_status(wlpriv, READY))) {	\
-		WL_INFO(("device is not ready : status (%d)\n",		\
-			(int)wlpriv->status));			\
-		return -EIO;						\
+	struct net_device *ndev = wl_to_prmry_ndev(wlpriv);       \
+	if (unlikely(!wl_get_drv_status(wlpriv, READY, ndev))) {	\
+		WL_INFO(("device is not ready\n"));		\
+			return -EIO;					\
 	}								\
 } while (0)
 
@@ -573,7 +543,20 @@
 	.channels = __wl_2ghz_channels,
 	.n_channels = ARRAY_SIZE(__wl_2ghz_channels),
 	.bitrates = wl_g_rates,
-	.n_bitrates = wl_g_rates_size
+	.n_bitrates = wl_g_rates_size,
+	/* wpa_supplicant sets wmm_enabled based on whether ht_cap
+	 * is present or not. The wmm_enabled is inturn used to
+	 * set the replay counters in the RSN IE. Without this
+	 * the 4way handshake will fail complaining that IE in beacon
+	 * doesn't match with the IE present in the 3/4 EAPOL msg.
+	 */
+	.ht_cap = {
+				IEEE80211_HT_CAP_SGI_20 |
+				IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU,
+				.ht_supported = TRUE,
+				.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
+				.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16
+	}
 };
 
 static struct ieee80211_supported_band __wl_band_5ghz_a = {
@@ -590,6 +573,9 @@
 	WLAN_CIPHER_SUITE_TKIP,
 	WLAN_CIPHER_SUITE_CCMP,
 	WLAN_CIPHER_SUITE_AES_CMAC,
+#ifdef WAPI
+	WLAN_CIPHER_SUITE_SMS4
+#endif
 };
 
 /* There isn't a lot of sense in it, but you can transmit anything you like */
@@ -740,12 +726,45 @@
 	}
 }
 
+static chanspec_t wl_cfg80211_get_shared_freq(struct wiphy *wiphy)
+{
+	chanspec_t chspec;
+	int err = 0;
+	struct wl_priv *wl = wiphy_priv(wiphy);
+	struct net_device *dev = wl_to_prmry_ndev(wl);
+	struct ether_addr bssid;
+	struct wl_bss_info *bss = NULL;
+
+	if ((err = wldev_ioctl(dev, WLC_GET_BSSID, &bssid, sizeof(bssid), false))) {
+		/* STA interface is not associated. So start the new interface on a temp
+		 * channel . Later proper channel will be applied by the above framework
+		 * via set_channel (cfg80211 API).
+		 */
+		WL_DBG(("Not associated. Return a temp channel. \n"));
+		return wf_chspec_aton(WL_P2P_TEMP_CHAN);
+	}
+
+
+	*(u32 *) wl->extra_buf = htod32(WL_EXTRA_BUF_MAX);
+	if ((err = wldev_ioctl(dev, WLC_GET_BSS_INFO, wl->extra_buf,
+		sizeof(WL_EXTRA_BUF_MAX), false))) {
+			WL_ERR(("Failed to get associated bss info, use temp channel \n"));
+			chspec = wf_chspec_aton(WL_P2P_TEMP_CHAN);
+	}
+	else {
+			bss = (struct wl_bss_info *) (wl->extra_buf + 4);
+			chspec =  bss->chanspec;
+			WL_DBG(("Valid BSS Found. chanspec:%d \n", bss->chanspec));
+	}
+
+	return chspec;
+}
+
 static struct net_device* wl_cfg80211_add_monitor_if(char *name)
 {
-	int ret = 0;
 	struct net_device* ndev = NULL;
 
-	ret = dhd_add_monitor(name, &ndev);
+	dhd_add_monitor(name, &ndev);
 	WL_INFO(("wl_cfg80211_add_monitor_if net device returned: 0x%p\n", ndev));
 	return ndev;
 }
@@ -758,15 +777,17 @@
 	s32 err;
 	s32 timeout = -1;
 	s32 wlif_type = -1;
-	s32 index = 0;
 	s32 mode = 0;
 	chanspec_t chspec;
 	struct wl_priv *wl = wiphy_priv(wiphy);
 	struct net_device *_ndev;
-	dhd_pub_t *dhd = (dhd_pub_t *)(wl->pub);
-	int (*net_attach)(dhd_pub_t *dhdp, int ifidx);
+	struct ether_addr primary_mac;
+	int (*net_attach)(void *dhdp, int ifidx);
 	bool rollback_lock = false;
 
+	/* Use primary I/F for to send commands down */
+	_ndev = wl_to_prmry_ndev(wl);
+
 	WL_DBG(("if name: %s, type: %d\n", name, type));
 	switch (type) {
 	case NL80211_IFTYPE_ADHOC:
@@ -798,6 +819,8 @@
 		WL_ERR(("name is NULL\n"));
 		return NULL;
 	}
+	if (wl->iface_cnt == IFACE_MAX_CNT)
+		return ERR_PTR(-ENOMEM);
 	if (wl->p2p_supported && (wlif_type != -1)) {
 		if (wl_get_p2p_status(wl, IF_DELETING)) {
 			/* wait till IF_DEL is complete
@@ -809,7 +832,7 @@
 			}
 			WL_INFO(("%s: Released the lock and wait till IF_DEL is complete\n",
 				__func__));
-			timeout = wait_event_interruptible_timeout(wl->dongle_event_wait,
+			timeout = wait_event_interruptible_timeout(wl->netif_change_event,
 				(wl_get_p2p_status(wl, IF_DELETING) == false),
 				msecs_to_jiffies(MAX_WAIT_TIME));
 
@@ -826,17 +849,22 @@
 				return ERR_PTR(-EAGAIN);
 			}
 		}
-		if (!p2p_on(wl) && strstr(name, WL_P2P_INTERFACE_PREFIX)) {
+		if (!p2p_is_on(wl) && strstr(name, WL_P2P_INTERFACE_PREFIX)) {
 			p2p_on(wl) = true;
 			wl_cfgp2p_set_firm_p2p(wl);
 			wl_cfgp2p_init_discovery(wl);
 		}
+
 		memset(wl->p2p->vir_ifname, 0, IFNAMSIZ);
 		strncpy(wl->p2p->vir_ifname, name, IFNAMSIZ - 1);
-		wl_cfgp2p_generate_bss_mac(&dhd->mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
+		get_primary_mac(wl, &primary_mac);
+		wl_cfgp2p_generate_bss_mac(&primary_mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
 
-		/* Temporary use channel 11, in case GO will be changed with set_channel API  */
-		chspec = wf_chspec_aton(WL_P2P_TEMP_CHAN);
+		/* In concurrency case, STA may be already associated in a particular channel.
+		 * so retrieve the current channel of primary interface and then start the virtual
+		 * interface on that.
+		 */
+		 chspec = wl_cfg80211_get_shared_freq(wiphy);
 
 		/* For P2P mode, use P2P-specific driver features to create the
 		 * bss: "wl p2p_ifadd"
@@ -844,10 +872,12 @@
 		wl_set_p2p_status(wl, IF_ADD);
 		err = wl_cfgp2p_ifadd(wl, &wl->p2p->int_addr, htod32(wlif_type), chspec);
 
-		if (unlikely(err))
+		if (unlikely(err)) {
+			WL_ERR((" virtual iface add failed (%d) \n", err));
 			return ERR_PTR(-ENOMEM);
+		}
 
-		timeout = wait_event_interruptible_timeout(wl->dongle_event_wait,
+		timeout = wait_event_interruptible_timeout(wl->netif_change_event,
 			(wl_get_p2p_status(wl, IF_ADD) == false),
 			msecs_to_jiffies(MAX_WAIT_TIME));
 		if (timeout > 0 && (!wl_get_p2p_status(wl, IF_ADD))) {
@@ -861,24 +891,21 @@
 			vwdev->wiphy = wl->wdev->wiphy;
 			WL_INFO((" virtual interface(%s) is created memalloc done \n",
 			wl->p2p->vir_ifname));
-			index = alloc_idx_vwdev(wl);
-			wl->vwdev[index] = vwdev;
-			vwdev->iftype =
-				(wlif_type == WL_P2P_IF_CLIENT) ? NL80211_IFTYPE_STATION
-				: NL80211_IFTYPE_AP;
+			vwdev->iftype = type;
 			_ndev =  wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION);
 			_ndev->ieee80211_ptr = vwdev;
 			SET_NETDEV_DEV(_ndev, wiphy_dev(vwdev->wiphy));
 			vwdev->netdev = _ndev;
-			wl_set_drv_status(wl, READY);
+			wl_set_drv_status(wl, READY, _ndev);
 			wl->p2p->vif_created = true;
-			set_mode_by_netdev(wl, _ndev, mode);
+			wl_set_mode_by_netdev(wl, _ndev, mode);
 			net_attach =  wl_to_p2p_bss_private(wl, P2PAPI_BSSCFG_CONNECTION);
 			if (rtnl_is_locked()) {
 				rtnl_unlock();
 				rollback_lock = true;
 			}
-			if (net_attach && !net_attach(dhd, _ndev->ifindex)) {
+			if (net_attach && !net_attach(wl->pub, _ndev->ifindex)) {
+				wl_alloc_netinfo(wl, _ndev, vwdev, mode);
 				WL_DBG((" virtual interface(%s) is "
 					"created net attach done\n", wl->p2p->vir_ifname));
 			} else {
@@ -911,33 +938,42 @@
 	s32 timeout = -1;
 	s32 ret = 0;
 	WL_DBG(("Enter\n"));
+
+	if (wl->p2p_net == dev) {
+		/* Since there is no ifidx corresponding to p2p0,
+		 * all commands should be routed through primary I/F
+		 */
+		dev = wl_to_prmry_ndev(wl);
+	}
+
 	if (wl->p2p_supported) {
 		memcpy(p2p_mac.octet, wl->p2p->int_addr.octet, ETHER_ADDR_LEN);
 		if (wl->p2p->vif_created) {
-			if (wl_get_drv_status(wl, SCANNING)) {
+			if (wl_get_drv_status(wl, SCANNING, dev)) {
 				wl_cfg80211_scan_abort(wl, dev);
 			}
 			wldev_iovar_setint(dev, "mpc", 1);
 			wl_set_p2p_status(wl, IF_DELETING);
 			ret = wl_cfgp2p_ifdel(wl, &p2p_mac);
-			if (ret) {
 			/* Firmware could not delete the interface so we will not get WLC_E_IF
 			* event for cleaning the dhd virtual nw interace
 			* So lets do it here. Failures from fw will ensure the application to do
 			* ifconfig <inter> down and up sequnce, which will reload the fw
 			* however we should cleanup the linux network virtual interfaces
 			*/
-				dhd_pub_t *dhd = (dhd_pub_t *)(wl->pub);
-				WL_ERR(("Firmware returned an error from p2p_ifdel\n"));
-				WL_ERR(("try to remove linux virtual interface %s\n", dev->name));
-				dhd_del_if(dhd->info, dhd_net2idx(dhd->info, dev));
+			/* Request framework to RESET and clean up */
+			if (ret) {
+				struct net_device *ndev = wl_to_prmry_ndev(wl);
+				WL_ERR(("Firmware returned an error (%d) from p2p_ifdel"
+					"HANG Notification sent to %s\n", ret, ndev->name));
+				wl_cfg80211_hang(ndev, WLAN_REASON_UNSPECIFIED);
 			}
 
 			/* Wait for any pending scan req to get aborted from the sysioc context */
-			timeout = wait_event_interruptible_timeout(wl->dongle_event_wait,
-				(wl_get_p2p_status(wl, IF_DELETING) == false),
+			timeout = wait_event_interruptible_timeout(wl->netif_change_event,
+				(wl->p2p->vif_created == false),
 				msecs_to_jiffies(MAX_WAIT_TIME));
-			if (timeout > 0 && !wl_get_p2p_status(wl, IF_DELETING)) {
+			if (timeout > 0 && (wl->p2p->vif_created == false)) {
 				WL_DBG(("IFDEL operation done\n"));
 			} else {
 				WL_ERR(("IFDEL didn't complete properly\n"));
@@ -955,12 +991,11 @@
 {
 	s32 ap = 0;
 	s32 infra = 0;
-	s32 err = BCME_OK;
-	s32 timeout = -1;
 	s32 wlif_type;
 	s32 mode = 0;
 	chanspec_t chspec;
 	struct wl_priv *wl = wiphy_priv(wiphy);
+
 	WL_DBG(("Enter \n"));
 	switch (type) {
 	case NL80211_IFTYPE_MONITOR:
@@ -988,28 +1023,33 @@
 		return -EINVAL;
 	}
 
-
 	if (ap) {
-		set_mode_by_netdev(wl, ndev, mode);
+		wl_set_mode_by_netdev(wl, ndev, mode);
 		if (wl->p2p_supported && wl->p2p->vif_created) {
 			WL_DBG(("p2p_vif_created (%d) p2p_on (%d)\n", wl->p2p->vif_created,
 			p2p_on(wl)));
-			chspec = wf_chspec_aton(WL_P2P_TEMP_CHAN);
+			wldev_iovar_setint(ndev, "mpc", 0);
+			/* In concurrency case, STA may be already associated in a particular
+			 * channel. so retrieve the current channel of primary interface and
+			 * then start the virtual interface on that.
+			 */
+			chspec = wl_cfg80211_get_shared_freq(wiphy);
+
 			wlif_type = ap ? WL_P2P_IF_GO : WL_P2P_IF_CLIENT;
 			WL_ERR(("%s : ap (%d), infra (%d), iftype: (%d)\n",
 				ndev->name, ap, infra, type));
 			wl_set_p2p_status(wl, IF_CHANGING);
 			wl_clr_p2p_status(wl, IF_CHANGED);
-			err = wl_cfgp2p_ifchange(wl, &wl->p2p->int_addr, htod32(wlif_type), chspec);
-			timeout = wait_event_interruptible_timeout(wl->dongle_event_wait,
+			wl_cfgp2p_ifchange(wl, &wl->p2p->int_addr, htod32(wlif_type), chspec);
+			wait_event_interruptible_timeout(wl->netif_change_event,
 				(wl_get_p2p_status(wl, IF_CHANGED) == true),
 				msecs_to_jiffies(MAX_WAIT_TIME));
-			set_mode_by_netdev(wl, ndev, mode);
+			wl_set_mode_by_netdev(wl, ndev, mode);
 			wl_clr_p2p_status(wl, IF_CHANGING);
 			wl_clr_p2p_status(wl, IF_CHANGED);
 		} else if (ndev == wl_to_prmry_ndev(wl) &&
-			!wl_get_drv_status(wl, AP_CREATED)) {
-			wl_set_drv_status(wl, AP_CREATING);
+			!wl_get_drv_status(wl, AP_CREATED, ndev)) {
+			wl_set_drv_status(wl, AP_CREATING, ndev);
 			if (!wl->ap_info &&
 				!(wl->ap_info = kzalloc(sizeof(struct ap_info), GFP_KERNEL))) {
 				WL_ERR(("struct ap_saved_ie allocation failed\n"));
@@ -1026,8 +1066,7 @@
 }
 
 s32
-wl_cfg80211_notify_ifadd(struct net_device *ndev, s32 idx, s32 bssidx,
-int (*_net_attach)(dhd_pub_t *dhdp, int ifidx))
+wl_cfg80211_notify_ifadd(struct net_device *ndev, s32 idx, s32 bssidx, void* _net_attach)
 {
 	struct wl_priv *wl = wlcfg_drv_priv;
 	s32 ret = BCME_OK;
@@ -1035,8 +1074,8 @@
 		WL_ERR(("net is NULL\n"));
 		return 0;
 	}
-	if (wl->p2p_supported) {
-		WL_DBG(("IF_ADD event called from dongle, old interface name: %s,"
+	if (wl->p2p_supported && wl_get_p2p_status(wl, IF_ADD)) {
+		WL_DBG(("IF_ADD event received, old interface name: %s,"
 			"new name: %s\n", ndev->name, wl->p2p->vir_ifname));
 		/* Assign the net device to CONNECT BSSCFG */
 		strncpy(ndev->name, wl->p2p->vir_ifname, IFNAMSIZ - 1);
@@ -1046,25 +1085,39 @@
 		ndev->ifindex = idx;
 		wl_clr_p2p_status(wl, IF_ADD);
 
-		wake_up_interruptible(&wl->dongle_event_wait);
+		wake_up_interruptible(&wl->netif_change_event);
+	} else {
+		ret = BCME_NOTREADY;
 	}
 	return ret;
 }
 
 s32
-wl_cfg80211_notify_ifdel(struct net_device *ndev)
+wl_cfg80211_notify_ifdel(void)
+{
+	struct wl_priv *wl = wlcfg_drv_priv;
+
+	WL_DBG(("Enter \n"));
+	wl_clr_p2p_status(wl, IF_DELETING);
+
+	return 0;
+}
+
+s32
+wl_cfg80211_ifdel_ops(struct net_device *ndev)
 {
 	struct wl_priv *wl = wlcfg_drv_priv;
 	bool rollback_lock = false;
 	s32 index = 0;
-
 	if (!ndev || !ndev->name) {
 		WL_ERR(("net is NULL\n"));
 		return 0;
 	}
 
-	if (p2p_is_on(wl) && wl->p2p->vif_created) {
-		if (wl->scan_request) {
+	if (p2p_is_on(wl) && wl->p2p->vif_created &&
+		wl_get_p2p_status(wl, IF_DELETING)) {
+		if (wl->scan_request &&
+			(wl->escan_info.ndev == ndev)) {
 			/* Abort any pending scan requests */
 			wl->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
 			if (!rtnl_is_locked()) {
@@ -1072,7 +1125,7 @@
 				rollback_lock = true;
 			}
 			WL_DBG(("ESCAN COMPLETED\n"));
-			wl_notify_escan_complete(wl, true);
+			wl_notify_escan_complete(wl, ndev, true);
 			if (rollback_lock)
 				rtnl_unlock();
 		}
@@ -1086,12 +1139,12 @@
 		wl->p2p->vif_created = false;
 		wl_cfgp2p_clear_management_ie(wl,
 			index);
-		wl_clr_p2p_status(wl, IF_DELETING);
 		WL_DBG(("index : %d\n", index));
 
 	}
+
 	/* Wake up any waiting thread */
-	wake_up_interruptible(&wl->dongle_event_wait);
+	wake_up_interruptible(&wl->netif_change_event);
 
 	return 0;
 }
@@ -1123,15 +1176,84 @@
 	struct wl_priv *wl = wlcfg_drv_priv;
 	if (wl_get_p2p_status(wl, IF_CHANGING)) {
 		wl_set_p2p_status(wl, IF_CHANGED);
-		wake_up_interruptible(&wl->dongle_event_wait);
+		wake_up_interruptible(&wl->netif_change_event);
 	}
 	return 0;
 }
 
+#ifdef DHD_BCM_WIFI_HDMI
+/* Quietly check if a BSS is up without printing any errors.
+ * Based on wl_cfgp2p_bss_isup().
+ */
+bool
+wl_cfgp2p_bss_isup_quiet(struct net_device *ndev, int bsscfg_idx)
+{
+	s32 result, val;
+	bool isup = false;
+	s8 getbuf[64];
+
+	/* Check if the BSS is up */
+	*(int*)getbuf = -1;
+	result = wldev_iovar_getbuf_bsscfg(ndev, "bss", &bsscfg_idx,
+	                    sizeof(bsscfg_idx), getbuf, sizeof(getbuf), 0);
+	if (result == 0) {
+		val = *(int*)getbuf;
+		val = dtoh32(val);
+		isup = (val ? TRUE : FALSE);
+	}
+	return isup;
+}
+
+static bool
+wl_cfg80211_is_whdmi_active(struct wiphy *wiphy, struct net_device *dev)
+{
+	bool is_whdmi_on = false;
+	s32 err = 0;
+	struct wl_priv *wl;
+	struct ether_addr bssid;
+	struct station_info sinfo;
+
+	/* Check if WHDMI is enabled */
+	if (!dhd_bcm_whdmi_enable) {
+		WL_INFO(("%s: whdmi not enabled\n", __FUNCTION__));
+		goto done;
+	}
+
+	/* Check if we are associated as a STA */
+	wl = wiphy_priv(wiphy);
+	err = wldev_ioctl(dev, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN, false);
+	if (err) {
+		WL_INFO(("%s: not associated, no BSSID (%d)\n",
+			__FUNCTION__, err));
+		goto done;
+	}
+	WL_INFO(("%s: bssid=" MACSTR "\n", __FUNCTION__, MAC2STR(bssid.octet)));
+	err = wl_cfg80211_get_station(wiphy, dev, bssid.octet, &sinfo);
+	if (err) {
+		WL_INFO(("%s: not associated, get_station err %d\n",
+			__FUNCTION__, err));
+		goto done;
+	}
+
+	/* Check if we have a WHDMI softAP bsscfg up */
+	if (!wl_cfgp2p_bss_isup_quiet(dev, DHD_WHDMI_SOFTAP_IF_NUM)) {
+		WL_INFO(("%s: softAP bss not up\n", __FUNCTION__));
+		goto done;
+	}
+
+	is_whdmi_on = true;
+
+done:
+	return is_whdmi_on;
+}
+#else /* !DHD_BCM_WIFI_HDMI */
+#define wl_cfg80211_is_whdmi_active(wiphy, dev) (0)
+#endif /* DHD_BCM_WIFI_HDMI */
+
 static void wl_scan_prep(struct wl_scan_params *params, struct cfg80211_scan_request *request)
 {
-	u32 n_ssids = request->n_ssids;
-	u32 n_channels = request->n_channels;
+	u32 n_ssids;
+	u32 n_channels;
 	u16 channel;
 	chanspec_t chanspec;
 	s32 i, offset;
@@ -1160,6 +1282,13 @@
 	params->passive_time = htod32(params->passive_time);
 	params->home_time = htod32(params->home_time);
 
+	/* if request is null just exit so it will be all channel broadcast scan */
+	if (!request)
+		return;
+
+	n_ssids = request->n_ssids;
+	n_channels = request->n_channels;
+
 	/* Copy channel array if applicable */
 	WL_SCAN(("### List of channelspecs to scan ###\n"));
 	if (n_channels > 0) {
@@ -1248,8 +1377,7 @@
 		return -ENOMEM;
 	}
 
-	if (request != NULL)
-		wl_scan_prep(&params->params, request);
+	wl_scan_prep(&params->params, request);
 
 	params->version = htod32(ISCAN_REQ_VERSION);
 	params->action = htod16(action);
@@ -1261,7 +1389,7 @@
 		goto done;
 	}
 	err = wldev_iovar_setbuf(iscan->dev, "iscan", params, params_size,
-		iscan->ioctl_buf, WLC_IOCTL_MEDLEN);
+		iscan->ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
 	if (unlikely(err)) {
 		if (err == -EBUSY) {
 			WL_ERR(("system busy : iscan canceled\n"));
@@ -1340,8 +1468,7 @@
 			goto exit;
 		}
 
-		if (request != NULL)
-			wl_scan_prep(&params->params, request);
+		wl_scan_prep(&params->params, request);
 		params->version = htod32(ESCAN_REQ_VERSION);
 		params->action =  htod16(action);
 		params->sync_id = htod16(0x1234);
@@ -1352,12 +1479,12 @@
 			goto exit;
 		}
 		err = wldev_iovar_setbuf(ndev, "escan", params, params_size,
-			wl->escan_ioctl_buf, WLC_IOCTL_MEDLEN);
+			wl->escan_ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
 		if (unlikely(err))
 			WL_ERR((" Escan set error (%d)\n", err));
 		kfree(params);
 	}
-	else if (p2p_on(wl) && p2p_scan(wl)) {
+	else if (p2p_is_on(wl) && p2p_scan(wl)) {
 		/* P2P SCAN TRIGGER */
 		if (scan_request && scan_request->n_channels) {
 			num_chans = scan_request->n_channels;
@@ -1383,7 +1510,7 @@
 				search_state = WL_P2P_DISC_ST_SEARCH;
 				WL_INFO(("P2P SEARCH PHASE START \n"));
 			} else if ((dev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION)) &&
-				(get_mode_by_netdev(wl, dev) == WL_MODE_AP)) {
+				(wl_get_mode_by_netdev(wl, dev) == WL_MODE_AP)) {
 				/* If you are already a GO, then do SEARCH only */
 				WL_INFO(("Already a GO. Do SEARCH Only"));
 				search_state = WL_P2P_DISC_ST_SEARCH;
@@ -1413,7 +1540,7 @@
 	s32 passive_scan;
 	wl_scan_results_t *results;
 	WL_SCAN(("Enter \n"));
-
+	wl->escan_info.ndev = ndev;
 	wl->escan_info.wiphy = wiphy;
 	wl->escan_info.escan_state = WL_ESCAN_STATE_SCANING;
 	passive_scan = wl->active_scan ? 0 : 1;
@@ -1444,32 +1571,36 @@
 	s32 passive_scan;
 	bool iscan_req;
 	bool escan_req;
-	bool spec_scan;
 	bool p2p_ssid;
 	s32 err = 0;
 	s32 i;
 	u32 wpsie_len = 0;
 	u8 wpsie[IE_MAX_LEN];
 
+	/* If scan req comes for p2p0, send it over primary I/F
+	 * Scan results will be delivered corresponding to cfg80211_scan_request
+	 */
+	if (ndev == wl->p2p_net) {
+		ndev = wl_to_prmry_ndev(wl);
+	}
+
 	WL_DBG(("Enter wiphy (%p)\n", wiphy));
-	if (unlikely(wl_get_drv_status(wl, SCANNING))) {
-		WL_ERR(("Scanning already : status (%d)\n", (int)wl->status));
+	if (wl_get_drv_status_all(wl, SCANNING)) {
+		WL_ERR(("Scanning already\n"));
 		return -EAGAIN;
 	}
-	if (unlikely(wl_get_drv_status(wl, SCAN_ABORTING))) {
-		WL_ERR(("Scanning being aborted : status (%d)\n",
-			(int)wl->status));
+	if (wl_get_drv_status(wl, SCAN_ABORTING, ndev)) {
+		WL_ERR(("Scanning being aborted\n"));
 		return -EAGAIN;
 	}
-	if (request->n_ssids > WL_SCAN_PARAMS_SSID_MAX) {
-		WL_ERR(("n_ssids > WL_SCAN_PARAMS_SSID_MAX\n"));
+	if (request && request->n_ssids > WL_SCAN_PARAMS_SSID_MAX) {
+		WL_ERR(("request null or n_ssids > WL_SCAN_PARAMS_SSID_MAX\n"));
 		return -EOPNOTSUPP;
 	}
 
 	/* Arm scan timeout timer */
 	mod_timer(&wl->scan_timeout, jiffies + WL_SCAN_TIMER_INTERVAL_MS * HZ / 1000);
 	iscan_req = false;
-	spec_scan = false;
 	if (request) {		/* scan bss */
 		ssids = request->ssids;
 		if (wl->iscan_on && (!ssids || !ssids->ssid_len || request->n_ssids != 1)) {
@@ -1543,7 +1674,7 @@
 		ssids = this_ssid;
 	}
 	wl->scan_request = request;
-	wl_set_drv_status(wl, SCANNING);
+	wl_set_drv_status(wl, SCANNING, ndev);
 	if (iscan_req) {
 		err = wl_do_iscan(wl, request);
 		if (likely(!err))
@@ -1578,7 +1709,6 @@
 			sr->ssid.SSID_len = htod32(sr->ssid.SSID_len);
 			WL_SCAN(("Specific scan ssid=\"%s\" len=%d\n",
 				sr->ssid.SSID, sr->ssid.SSID_len));
-			spec_scan = true;
 		} else {
 			WL_SCAN(("Broadcast scan\n"));
 		}
@@ -1606,7 +1736,7 @@
 	return 0;
 
 scan_out:
-	wl_clr_drv_status(wl, SCANNING);
+	wl_clr_drv_status(wl, SCANNING, ndev);
 	wl->scan_request = NULL;
 	return err;
 }
@@ -1621,6 +1751,13 @@
 	WL_DBG(("Enter \n"));
 	CHECK_SYS_UP(wl);
 
+#ifdef DHD_BCM_WIFI_HDMI
+	if (wl_cfg80211_is_whdmi_active(wiphy, ndev)) {
+		WL_ERR(("%s: omitting scan because whdmi is on\n", __FUNCTION__));
+		return BCME_EPERM;
+	}
+#endif /* DHD_BCM_WIFI_HDMI */
+
 	err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
 	if (unlikely(err)) {
 		WL_ERR(("scan error (%d)\n", err));
@@ -1630,52 +1767,11 @@
 	return err;
 }
 
-static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val)
-{
-	s8 buf[WLC_IOCTL_SMLEN];
-	u32 len;
-	s32 err = 0;
-
-	val = htod32(val);
-	len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
-	BUG_ON(unlikely(!len));
-
-	err = wldev_ioctl(dev, WLC_SET_VAR, buf, len, false);
-	if (unlikely(err)) {
-		WL_ERR(("error (%d)\n", err));
-	}
-
-	return err;
-}
-
-static s32
-wl_dev_intvar_get(struct net_device *dev, s8 *name, s32 *retval)
-{
-	union {
-		s8 buf[WLC_IOCTL_SMLEN];
-		s32 val;
-	} var;
-	u32 len;
-	u32 data_null;
-	s32 err = 0;
-
-	len = bcm_mkiovar(name, (char *)(&data_null), 0,
-		(char *)(&var), sizeof(var.buf));
-	BUG_ON(unlikely(!len));
-	err = wldev_ioctl(dev, WLC_GET_VAR, &var, len, false);
-	if (unlikely(err)) {
-		WL_ERR(("error (%d)\n", err));
-	}
-	*retval = dtoh32(var.val);
-
-	return err;
-}
-
 static s32 wl_set_rts(struct net_device *dev, u32 rts_threshold)
 {
 	s32 err = 0;
 
-	err = wl_dev_intvar_set(dev, "rtsthresh", rts_threshold);
+	err = wldev_iovar_setint(dev, "rtsthresh", rts_threshold);
 	if (unlikely(err)) {
 		WL_ERR(("Error (%d)\n", err));
 		return err;
@@ -1687,7 +1783,7 @@
 {
 	s32 err = 0;
 
-	err = wl_dev_intvar_set(dev, "fragthresh", frag_threshold);
+	err = wldev_iovar_setint_bsscfg(dev, "fragthresh", frag_threshold, 0);
 	if (unlikely(err)) {
 		WL_ERR(("Error (%d)\n", err));
 		return err;
@@ -1856,17 +1952,47 @@
 	if (is_wps_conn(sme))
 		val = WPA_AUTH_DISABLED;
 
+#ifdef WAPI
+	if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1) {
+		WL_ERR((" * wl_set_wpa_version, set wpa_auth"
+			" to WPA_AUTH_WAPI 0x400"));
+		val = WAPI_AUTH_PSK; /* | WAPI_AUTH_UNSPECIFIED; */
+	}
+#endif
 	WL_DBG(("setting wpa_auth to 0x%0x\n", val));
 	err = wldev_iovar_setint_bsscfg(dev, "wpa_auth", val, bssidx);
 	if (unlikely(err)) {
 		WL_ERR(("set wpa_auth failed (%d)\n", err));
 		return err;
 	}
-	sec = wl_read_prof(wl, WL_PROF_SEC);
+	sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 	sec->wpa_versions = sme->crypto.wpa_versions;
 	return err;
 }
 
+#ifdef WAPI
+static s32
+wl_set_set_wapi_ie(struct net_device *dev, struct cfg80211_connect_params *sme)
+{
+	struct wl_priv *wl = wlcfg_drv_priv;
+	s32 err = 0;
+	s32 bssidx = wl_cfgp2p_find_idx(wl, dev);
+
+	WL_ERR((" %s \n", __FUNCTION__));
+
+	if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1) {
+		err = wldev_iovar_setbuf_bsscfg(dev, "wapiie", sme->ie,
+			sme->ie_len, wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
+
+		if (unlikely(err)) {
+			WL_ERR(("===> set_wapi_ie Error (%d)\n", err));
+			return err;
+		}
+	} else
+		WL_ERR((" * skip \n"));
+	return err;
+}
+#endif /* WAPI */
 static s32
 wl_set_auth_type(struct net_device *dev, struct cfg80211_connect_params *sme)
 {
@@ -1901,7 +2027,7 @@
 		WL_ERR(("set auth failed (%d)\n", err));
 		return err;
 	}
-	sec = wl_read_prof(wl, WL_PROF_SEC);
+	sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 	sec->auth_type = sme->auth_type;
 	return err;
 }
@@ -1914,6 +2040,9 @@
 	s32 pval = 0;
 	s32 gval = 0;
 	s32 err = 0;
+#ifdef WAPI
+	s32 val = 0;
+#endif
 	s32 bssidx = wl_cfgp2p_find_idx(wl, dev);
 
 	if (sme->crypto.n_ciphers_pairwise) {
@@ -1931,6 +2060,12 @@
 		case WLAN_CIPHER_SUITE_AES_CMAC:
 			pval = AES_ENABLED;
 			break;
+#ifdef WAPI
+		case WLAN_CIPHER_SUITE_SMS4:
+			val = SMS4_ENABLED;
+			pval = SMS4_ENABLED;
+			break;
+#endif
 		default:
 			WL_ERR(("invalid cipher pairwise (%d)\n",
 				sme->crypto.ciphers_pairwise[0]));
@@ -1952,6 +2087,12 @@
 		case WLAN_CIPHER_SUITE_AES_CMAC:
 			gval = AES_ENABLED;
 			break;
+#ifdef WAPI
+		case WLAN_CIPHER_SUITE_SMS4:
+			val = SMS4_ENABLED;
+			gval = SMS4_ENABLED;
+			break;
+#endif
 		default:
 			WL_ERR(("invalid cipher group (%d)\n",
 				sme->crypto.cipher_group));
@@ -1962,18 +2103,31 @@
 	WL_DBG(("pval (%d) gval (%d)\n", pval, gval));
 
 	if (is_wps_conn(sme)) {
-		err = wldev_iovar_setint_bsscfg(dev, "wsec", 4, bssidx);
+		if (sme->privacy) {
+			err = wldev_iovar_setint_bsscfg(dev, "wsec", 4, bssidx);
+		} else {
+			err = wldev_iovar_setint_bsscfg(dev, "wsec", 0, bssidx);
+		}
 	} else {
-		WL_DBG((" NO, is_wps_conn, Set pval | gval to WSEC"));
-		err = wldev_iovar_setint_bsscfg(dev, "wsec",
+#ifdef WAPI
+		if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_SMS4) {
+			WL_ERR((" NO, is_wps_conn, WAPI set to SMS4_ENABLED"));
+			err = wldev_iovar_setint_bsscfg(dev, "wsec", val, bssidx);
+		} else {
+#endif
+			WL_DBG((" NO, is_wps_conn, Set pval | gval to WSEC"));
+			err = wldev_iovar_setint_bsscfg(dev, "wsec",
 				pval | gval, bssidx);
+#ifdef WAPI
+		}
+#endif
 	}
 	if (unlikely(err)) {
 		WL_ERR(("error (%d)\n", err));
 		return err;
 	}
 
-	sec = wl_read_prof(wl, WL_PROF_SEC);
+	sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 	sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
 	sec->cipher_group = sme->crypto.cipher_group;
 
@@ -1990,7 +2144,7 @@
 	s32 bssidx = wl_cfgp2p_find_idx(wl, dev);
 
 	if (sme->crypto.n_akm_suites) {
-		err = wl_dev_intvar_get(dev, "wpa_auth", &val);
+		err = wldev_iovar_getint(dev, "wpa_auth", &val);
 		if (unlikely(err)) {
 			WL_ERR(("could not get wpa_auth (%d)\n", err));
 			return err;
@@ -2022,6 +2176,22 @@
 				return -EINVAL;
 			}
 		}
+#ifdef WAPI
+		else if (val & (WAPI_AUTH_PSK | WAPI_AUTH_UNSPECIFIED)) {
+			switch (sme->crypto.akm_suites[0]) {
+			case WLAN_AKM_SUITE_WAPI_CERT:
+				val = WAPI_AUTH_UNSPECIFIED;
+				break;
+			case WLAN_AKM_SUITE_WAPI_PSK:
+				val = WAPI_AUTH_PSK;
+				break;
+			default:
+				WL_ERR(("invalid cipher group (%d)\n",
+					sme->crypto.cipher_group));
+				return -EINVAL;
+			}
+		}
+#endif
 		WL_DBG(("setting wpa_auth to %d\n", val));
 
 		err = wldev_iovar_setint_bsscfg(dev, "wpa_auth", val, bssidx);
@@ -2030,7 +2200,7 @@
 			return err;
 		}
 	}
-	sec = wl_read_prof(wl, WL_PROF_SEC);
+	sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 	sec->wpa_auth = sme->crypto.akm_suites[0];
 
 	return err;
@@ -2049,13 +2219,22 @@
 
 	WL_DBG(("key len (%d)\n", sme->key_len));
 	if (sme->key_len) {
-		sec = wl_read_prof(wl, WL_PROF_SEC);
+		sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 		WL_DBG(("wpa_versions 0x%x cipher_pairwise 0x%x\n",
 			sec->wpa_versions, sec->cipher_pairwise));
 		if (!(sec->wpa_versions & (NL80211_WPA_VERSION_1 |
-			NL80211_WPA_VERSION_2)) &&
+			NL80211_WPA_VERSION_2
+#ifdef WAPI
+			| NL80211_WAPI_VERSION_1
+#endif
+		)) &&
 			(sec->cipher_pairwise & (WLAN_CIPHER_SUITE_WEP40 |
-			WLAN_CIPHER_SUITE_WEP104))) {
+			WLAN_CIPHER_SUITE_WEP104
+#ifdef WAPI
+		| WLAN_CIPHER_SUITE_SMS4
+#endif
+		)))
+		{
 			memset(&key, 0, sizeof(key));
 			key.len = (u32) sme->key_len;
 			key.index = (u32) sme->key_idx;
@@ -2072,6 +2251,11 @@
 			case WLAN_CIPHER_SUITE_WEP104:
 				key.algo = CRYPTO_ALGO_WEP128;
 				break;
+#ifdef WAPI
+			case WLAN_CIPHER_SUITE_SMS4:
+				key.algo = CRYPTO_ALGO_SMS4;
+				break;
+#endif
 			default:
 				WL_ERR(("Invalid algorithm (%d)\n",
 					sme->crypto.ciphers_pairwise[0]));
@@ -2083,7 +2267,7 @@
 			WL_DBG(("key \"%s\"\n", key.data));
 			swap_key_from_BE(&key);
 			err = wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key),
-				ioctlbuf, sizeof(ioctlbuf), bssidx);
+				wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 			if (unlikely(err)) {
 				WL_ERR(("WLC_SET_KEY error (%d)\n", err));
 				return err;
@@ -2121,7 +2305,6 @@
 	u32 chan_cnt = 0;
 	u8 wpsie[IE_MAX_LEN];
 	struct ether_addr bssid;
-
 	WL_DBG(("In\n"));
 	CHECK_SYS_UP(wl);
 
@@ -2133,11 +2316,11 @@
 	}
 	/* Clean BSSID */
 	bzero(&bssid, sizeof(bssid));
-	wl_update_prof(wl, NULL, (void *)&bssid, WL_PROF_BSSID);
+	wl_update_prof(wl, dev, NULL, (void *)&bssid, WL_PROF_BSSID);
 
 	if (IS_P2P_SSID(sme->ssid) && (dev != wl_to_prmry_ndev(wl))) {
 		/* we only allow to connect using virtual interface in case of P2P */
-		if (p2p_on(wl) && is_wps_conn(sme)) {
+		if (p2p_is_on(wl) && is_wps_conn(sme)) {
 			WL_DBG(("ASSOC1 p2p index : %d sme->ie_len %d\n",
 				wl_cfgp2p_find_idx(wl, dev), sme->ie_len));
 			/* Have to apply WPS IE + P2P IE in assoc req frame */
@@ -2148,7 +2331,7 @@
 				P2PAPI_BSSCFG_DEVICE).p2p_probe_req_ie_len);
 			wl_cfgp2p_set_management_ie(wl, dev, wl_cfgp2p_find_idx(wl, dev),
 				VNDR_IE_ASSOCREQ_FLAG, sme->ie, sme->ie_len);
-		} else if (p2p_on(wl) && (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
+		} else if (p2p_is_on(wl) && (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
 			/* This is the connect req after WPS is done [credentials exchanged]
 			 * currently identified with WPA_VERSION_2 .
 			 * Update the previously set IEs with
@@ -2177,10 +2360,10 @@
 				wpaie_len = (wpa_ie != NULL) ? wpa_ie->length : wpa2_ie->len;
 				wpaie_len += WPA_RSN_IE_TAG_FIXED_LEN;
 				wldev_iovar_setbuf(dev, "wpaie", wpaie, wpaie_len,
-				ioctlbuf, sizeof(ioctlbuf));
+					wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 			} else {
 				wldev_iovar_setbuf(dev, "wpaie", NULL, 0,
-				ioctlbuf, sizeof(ioctlbuf));
+					wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 			}
 
 			/* find the WPSIE */
@@ -2209,18 +2392,38 @@
 			chan->center_freq));
 	} else
 		wl->channel = 0;
+
+#ifdef WAPI
+	WL_ERR(("1. enable wapi auth\n"));
+	if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1) {
+		WL_ERR(("2. set wapi ie  \n"));
+		err = wl_set_set_wapi_ie(dev, sme);
+		if (unlikely(err))
+			return err;
+	} else
+		WL_ERR(("2. Not wapi ie  \n"));
+#endif
 	WL_DBG(("ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len));
+	WL_DBG(("3. set wapi version \n"));
 	err = wl_set_wpa_version(dev, sme);
 	if (unlikely(err)) {
 		WL_ERR(("Invalid wpa_version\n"));
 		return err;
 	}
-
-	err = wl_set_auth_type(dev, sme);
-	if (unlikely(err)) {
-		WL_ERR(("Invalid auth type\n"));
-		return err;
+#ifdef WAPI
+	if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1)
+		WL_ERR(("4. WAPI Dont Set wl_set_auth_type\n"));
+	else {
+		WL_ERR(("4. wl_set_auth_type\n"));
+#endif
+		err = wl_set_auth_type(dev, sme);
+		if (unlikely(err)) {
+			WL_ERR(("Invalid auth type\n"));
+			return err;
+		}
+#ifdef WAPI
 	}
+#endif
 
 	err = wl_set_set_cipher(dev, sme);
 	if (unlikely(err)) {
@@ -2249,7 +2452,7 @@
 	ext_join_params =  (wl_extjoin_params_t*)kzalloc(join_params_size, GFP_KERNEL);
 	if (ext_join_params == NULL) {
 		err = -ENOMEM;
-		wl_clr_drv_status(wl, CONNECTING);
+		wl_clr_drv_status(wl, CONNECTING, dev);
 		goto exit;
 	}
 	ext_join_params->ssid.SSID_len = min(sizeof(ext_join_params->ssid.SSID), sme->ssid_len);
@@ -2258,12 +2461,13 @@
 	/* Set up join scan parameters */
 	ext_join_params->scan.scan_type = -1;
 	ext_join_params->scan.nprobes = 2;
-	/* increate dwell time to receive probe response
-	* from target AP at a noisy air
+	/* increate dwell time to receive probe response or detect Beacon
+	* from target AP at a noisy air only during connect command
 	*/
-	ext_join_params->scan.active_time = 150;
-	ext_join_params->scan.passive_time = 300;
+	ext_join_params->scan.active_time = WL_SCAN_ACTIVE_TIME*3;
+	ext_join_params->scan.passive_time = WL_SCAN_PASSIVE_TIME*3;
 	ext_join_params->scan.home_time = -1;
+
 	if (sme->bssid)
 		memcpy(&ext_join_params->assoc.bssid, sme->bssid, ETH_ALEN);
 	else
@@ -2288,12 +2492,12 @@
 		WL_INFO(("ssid \"%s\", len (%d)\n", ext_join_params->ssid.SSID,
 			ext_join_params->ssid.SSID_len));
 	}
-	wl_set_drv_status(wl, CONNECTING);
-	err = wldev_iovar_setbuf_bsscfg(dev, "join", ext_join_params, join_params_size, ioctlbuf,
-		sizeof(ioctlbuf), wl_cfgp2p_find_idx(wl, dev));
+	wl_set_drv_status(wl, CONNECTING, dev);
+	err = wldev_iovar_setbuf_bsscfg(dev, "join", ext_join_params, join_params_size,
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, wl_cfgp2p_find_idx(wl, dev), &wl->ioctl_buf_sync);
 	kfree(ext_join_params);
 	if (err) {
-		wl_clr_drv_status(wl, CONNECTING);
+		wl_clr_drv_status(wl, CONNECTING, dev);
 		if (err == BCME_UNSUPPORTED) {
 			WL_DBG(("join iovar is not supported\n"));
 			goto set_ssid;
@@ -2309,7 +2513,7 @@
 	join_params.ssid.SSID_len = min(sizeof(join_params.ssid.SSID), sme->ssid_len);
 	memcpy(&join_params.ssid.SSID, sme->ssid, join_params.ssid.SSID_len);
 	join_params.ssid.SSID_len = htod32(join_params.ssid.SSID_len);
-	wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
+	wl_update_prof(wl, dev, NULL, &join_params.ssid, WL_PROF_SSID);
 	if (sme->bssid)
 		memcpy(&join_params.params.bssid, sme->bssid, ETH_ALEN);
 	else
@@ -2322,11 +2526,11 @@
 		WL_INFO(("ssid \"%s\", len (%d)\n", join_params.ssid.SSID,
 			join_params.ssid.SSID_len));
 	}
-	wl_set_drv_status(wl, CONNECTING);
+	wl_set_drv_status(wl, CONNECTING, dev);
 	err = wldev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size, true);
 	if (err) {
 		WL_ERR(("error (%d)\n", err));
-		wl_clr_drv_status(wl, CONNECTING);
+		wl_clr_drv_status(wl, CONNECTING, dev);
 	}
 exit:
 	return err;
@@ -2343,23 +2547,23 @@
 	u8 *curbssid;
 	WL_ERR(("Reason %d\n", reason_code));
 	CHECK_SYS_UP(wl);
-	act = *(bool *) wl_read_prof(wl, WL_PROF_ACT);
-	curbssid = wl_read_prof(wl, WL_PROF_BSSID);
-	if (likely(act)) {
+	act = *(bool *) wl_read_prof(wl, dev, WL_PROF_ACT);
+	curbssid = wl_read_prof(wl, dev, WL_PROF_BSSID);
+	if (act) {
 		/*
 		* Cancel ongoing scan to sync up with sme state machine of cfg80211.
 		*/
 		if (wl->scan_request) {
 			wl_cfg80211_scan_abort(wl, dev);
 		}
-		wl_set_drv_status(wl, DISCONNECTING);
+		wl_set_drv_status(wl, DISCONNECTING, dev);
 		scbval.val = reason_code;
 		memcpy(&scbval.ea, curbssid, ETHER_ADDR_LEN);
 		scbval.val = htod32(scbval.val);
 		err = wldev_ioctl(dev, WLC_DISASSOC, &scbval,
 			sizeof(scb_val_t), true);
 		if (unlikely(err)) {
-			wl_clr_drv_status(wl, DISCONNECTING);
+			wl_clr_drv_status(wl, DISCONNECTING, dev);
 			WL_ERR(("error (%d)\n", err));
 			return err;
 		}
@@ -2409,7 +2613,7 @@
 		txpwrmw = 0xffff;
 	else
 		txpwrmw = (u16) dbm;
-	err = wl_dev_intvar_set(ndev, "qtxpower",
+	err = wldev_iovar_setint(ndev, "qtxpower",
 		(s32) (bcm_mw_to_qdbm(txpwrmw)));
 	if (unlikely(err)) {
 		WL_ERR(("qtxpower error (%d)\n", err));
@@ -2429,7 +2633,7 @@
 	s32 err = 0;
 
 	CHECK_SYS_UP(wl);
-	err = wl_dev_intvar_get(ndev, "qtxpower", &txpwrdbm);
+	err = wldev_iovar_getint(ndev, "qtxpower", &txpwrdbm);
 	if (unlikely(err)) {
 		WL_ERR(("error (%d)\n", err));
 		return err;
@@ -2478,7 +2682,7 @@
 	struct wl_wsec_key key;
 	s32 err = 0;
 	s32 bssidx = wl_cfgp2p_find_idx(wl, dev);
-	s32 mode = get_mode_by_netdev(wl, dev);
+	s32 mode = wl_get_mode_by_netdev(wl, dev);
 	memset(&key, 0, sizeof(key));
 	key.index = (u32) key_idx;
 
@@ -2490,8 +2694,8 @@
 	if (key.len == 0) {
 		/* key delete */
 		swap_key_from_BE(&key);
-		wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), ioctlbuf,
-			sizeof(ioctlbuf), bssidx);
+		wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key),
+			wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 		if (unlikely(err)) {
 			WL_ERR(("key delete error (%d)\n", err));
 			return err;
@@ -2544,16 +2748,22 @@
 			key.algo = CRYPTO_ALGO_AES_CCM;
 			WL_DBG(("WLAN_CIPHER_SUITE_CCMP\n"));
 			break;
+#ifdef WAPI
+		case WLAN_CIPHER_SUITE_SMS4:
+			key.algo = CRYPTO_ALGO_SMS4;
+			WL_ERR(("WLAN_CIPHER_SUITE_SMS4\n"));
+			break;
+#endif
 		default:
 			WL_ERR(("Invalid cipher (0x%x)\n", params->cipher));
 			return -EINVAL;
 		}
 		swap_key_from_BE(&key);
-#ifdef CONFIG_WIRELESS_EXT
+#if defined(CONFIG_WIRELESS_EXT)
 		dhd_wait_pend8021x(dev);
 #endif
-		wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), ioctlbuf,
-			sizeof(ioctlbuf), bssidx);
+		wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key),
+			wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 		if (unlikely(err)) {
 			WL_ERR(("WLC_SET_KEY error (%d)\n", err));
 			return err;
@@ -2574,7 +2784,7 @@
 	u8 keybuf[8];
 	s32 bssidx = 0;
 	struct wl_priv *wl = wiphy_priv(wiphy);
-	s32 mode = get_mode_by_netdev(wl, dev);
+	s32 mode = wl_get_mode_by_netdev(wl, dev);
 	WL_DBG(("key index (%d)\n", key_idx));
 	CHECK_SYS_UP(wl);
 
@@ -2628,6 +2838,14 @@
 		val = AES_ENABLED;
 		WL_DBG(("WLAN_CIPHER_SUITE_CCMP\n"));
 		break;
+#ifdef WAPI
+	case WLAN_CIPHER_SUITE_SMS4:
+		key.algo = CRYPTO_ALGO_SMS4;
+		val = SMS4_ENABLED;
+		WL_ERR((" * wl_cfg80211_add_key, set key "
+			" to WLAN_CIPHER_SUITE_SMS4\n"));
+		break;
+#endif /* WAPI */
 	default:
 		WL_ERR(("Invalid cipher (0x%x)\n", params->cipher));
 		return -EINVAL;
@@ -2635,8 +2853,8 @@
 
 	/* Set the new key/index */
 	swap_key_from_BE(&key);
-	err = wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), ioctlbuf,
-		sizeof(ioctlbuf), bssidx);
+	err = wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), wl->ioctl_buf,
+		WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 	if (unlikely(err)) {
 		WL_ERR(("WLC_SET_KEY error (%d)\n", err));
 		return err;
@@ -2679,8 +2897,8 @@
 	WL_DBG(("key index (%d)\n", key_idx));
 	/* Set the new key/index */
 	swap_key_from_BE(&key);
-	wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), ioctlbuf,
-		sizeof(ioctlbuf), bssidx);
+	wldev_iovar_setbuf_bsscfg(dev, "wsec_key", &key, sizeof(key), wl->ioctl_buf,
+		WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 	if (unlikely(err)) {
 		if (err == -EINVAL) {
 			if (key.index >= DOT11_MAX_DEFAULT_KEYS) {
@@ -2724,7 +2942,7 @@
 	}
 	switch (wsec & ~SES_OW_ENABLED) {
 		case WEP_ENABLED:
-			sec = wl_read_prof(wl, WL_PROF_SEC);
+			sec = wl_read_prof(wl, dev, WL_PROF_SEC);
 			if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
 				params.cipher = WLAN_CIPHER_SUITE_WEP40;
 				WL_DBG(("WLAN_CIPHER_SUITE_WEP40\n"));
@@ -2741,6 +2959,13 @@
 			params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
 			WL_DBG(("WLAN_CIPHER_SUITE_AES_CMAC\n"));
 			break;
+#ifdef WAPI
+		case WLAN_CIPHER_SUITE_SMS4:
+			key.algo = CRYPTO_ALGO_SMS4;
+			WL_ERR((" * wl_cfg80211_add_key, set key"
+				"to WLAN_CIPHER_SUITE_SMS4\n"));
+			break;
+#endif
 		default:
 			WL_ERR(("Invalid algo (0x%x)\n", wsec));
 			return -EINVAL;
@@ -2772,17 +2997,16 @@
 	s8 eabuf[ETHER_ADDR_STR_LEN];
 #endif
 	dhd_pub_t *dhd =  (dhd_pub_t *)(wl->pub);
-
 	CHECK_SYS_UP(wl);
-	if (get_mode_by_netdev(wl, dev) == WL_MODE_AP) {
+	if (wl_get_mode_by_netdev(wl, dev) == WL_MODE_AP) {
 		err = wldev_iovar_getbuf(dev, "sta_info", (struct ether_addr *)mac,
-			ETHER_ADDR_LEN, ioctlbuf, sizeof(ioctlbuf));
+			ETHER_ADDR_LEN, wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 		if (err < 0) {
 			WL_ERR(("GET STA INFO failed, %d\n", err));
 			return err;
 		}
 		sinfo->filled = STATION_INFO_INACTIVE_TIME;
-		sta = (sta_info_t *)ioctlbuf;
+		sta = (sta_info_t *)wl->ioctl_buf;
 		sta->len = dtoh16(sta->len);
 		sta->cap = dtoh16(sta->cap);
 		sta->flags = dtoh32(sta->flags);
@@ -2798,11 +3022,11 @@
 			bcm_ether_ntoa((const struct ether_addr *)mac, eabuf), sinfo->inactive_time,
 			sta->idle * 1000));
 #endif
-	} else if (get_mode_by_netdev(wl, dev) == WL_MODE_BSS) {
-			u8 *curmacp = wl_read_prof(wl, WL_PROF_BSSID);
-
-			if (!wl_get_drv_status(wl, CONNECTED) ||
+	} else if (wl_get_mode_by_netdev(wl, dev) == WL_MODE_BSS) {
+			u8 *curmacp = wl_read_prof(wl, dev, WL_PROF_BSSID);
+			if (!wl_get_drv_status(wl, CONNECTED, dev) ||
 			    (dhd_is_associated(dhd, NULL) == FALSE)) {
+
 				WL_ERR(("NOT assoc\n"));
 				err = -ENODEV;
 				goto get_station_err;
@@ -2823,25 +3047,24 @@
 				WL_DBG(("Rate %d Mbps\n", (rate / 2)));
 			}
 
-			memset(&scb_val, 0, sizeof(scb_val));
-			scb_val.val = 0;
-			err = wldev_ioctl(dev, WLC_GET_RSSI, &scb_val,
+				memset(&scb_val, 0, sizeof(scb_val));
+				scb_val.val = 0;
+				err = wldev_ioctl(dev, WLC_GET_RSSI, &scb_val,
 					sizeof(scb_val_t), false);
-			if (err) {
-				WL_ERR(("Could not get rssi (%d)\n", err));
-				goto get_station_err;
-			}
-
-			rssi = dtoh32(scb_val.val);
-			sinfo->filled |= STATION_INFO_SIGNAL;
-			sinfo->signal = rssi;
-			WL_DBG(("RSSI %d dBm\n", rssi));
+				if (err) {
+					WL_ERR(("Could not get rssi (%d)\n", err));
+					goto get_station_err;
+				}
+				rssi = dtoh32(scb_val.val);
+				sinfo->filled |= STATION_INFO_SIGNAL;
+				sinfo->signal = rssi;
+				WL_DBG(("RSSI %d dBm\n", rssi));
 
 get_station_err:
 		if (err) {
 			/* Disconnect due to zero BSSID or error to get RSSI */
 			WL_ERR(("force cfg80211_disconnected\n"));
-			wl_clr_drv_status(wl, CONNECTED);
+			wl_clr_drv_status(wl, CONNECTED, dev);
 			cfg80211_disconnected(dev, 0, NULL, 0, GFP_KERNEL);
 			wl_link_down(wl);
 		}
@@ -2859,6 +3082,12 @@
 	struct wl_priv *wl = wiphy_priv(wiphy);
 
 	CHECK_SYS_UP(wl);
+
+	WL_DBG(("Enter : power save %s\n", (enabled ? "enable" : "disable")));
+	if (wl->p2p_net == dev) {
+		return err;
+	}
+
 	pm = enabled ? PM_FAST : PM_OFF;
 	/* Do not enable the power save after assoc if it is p2p interface */
 	if (wl->p2p && wl->p2p->vif_created) {
@@ -2866,7 +3095,6 @@
 		pm = PM_OFF;
 	}
 	pm = htod32(pm);
-	WL_DBG(("power save %s\n", (pm ? "enabled" : "disabled")));
 	err = wldev_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm), true);
 	if (unlikely(err)) {
 		if (err == -ENODEV)
@@ -2908,11 +3136,11 @@
 static s32 wl_cfg80211_resume(struct wiphy *wiphy)
 {
 	struct wl_priv *wl = wiphy_priv(wiphy);
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
 	s32 err = 0;
 
-	if (unlikely(!wl_get_drv_status(wl, READY))) {
-		WL_INFO(("device is not ready : status (%d)\n",
-			(int)wl->status));
+	if (unlikely(!wl_get_drv_status(wl, READY, ndev))) {
+		WL_INFO(("device is not ready\n"));
 		return 0;
 	}
 
@@ -2929,33 +3157,37 @@
 {
 #ifdef DHD_CLEAR_ON_SUSPEND
 	struct wl_priv *wl = wiphy_priv(wiphy);
+	struct net_info *iter, *next;
 	struct net_device *ndev = wl_to_prmry_ndev(wl);
 	unsigned long flags;
-
-	if (unlikely(!wl_get_drv_status(wl, READY))) {
+	if (unlikely(!wl_get_drv_status(wl, READY, ndev))) {
 		WL_INFO(("device is not ready : status (%d)\n",
 			(int)wl->status));
 		return 0;
 	}
-
-	wl_set_drv_status(wl, SCAN_ABORTING);
+	for_each_ndev(wl, iter, next)
+		wl_set_drv_status(wl, SCAN_ABORTING, iter->ndev);
 	wl_term_iscan(wl);
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	if (wl->scan_request) {
 		cfg80211_scan_done(wl->scan_request, true);
 		wl->scan_request = NULL;
 	}
-	wl_clr_drv_status(wl, SCANNING);
-	wl_clr_drv_status(wl, SCAN_ABORTING);
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
-	if (wl_get_drv_status(wl, CONNECTING)) {
-		wl_bss_connect_done(wl, ndev, NULL, NULL, false);
+	for_each_ndev(wl, iter, next) {
+		wl_clr_drv_status(wl, SCANNING, iter->ndev);
+		wl_clr_drv_status(wl, SCAN_ABORTING, iter->ndev);
 	}
-#endif
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
+	for_each_ndev(wl, iter, next) {
+		if (wl_get_drv_status(wl, CONNECTING, iter->ndev)) {
+			wl_bss_connect_done(wl, iter->ndev, NULL, NULL, false);
+		}
+	}
+#endif /* DHD_CLEAR_ON_SUSPEND */
 	return 0;
 }
 
-static __used s32
+static s32
 wl_update_pmklist(struct net_device *dev, struct wl_pmk_list *pmk_list,
 	s32 err)
 {
@@ -2963,9 +3195,12 @@
 	struct wl_priv *wl = wlcfg_drv_priv;
 	struct net_device *primary_dev = wl_to_prmry_ndev(wl);
 
-	/* Firmware is supporting pmk list only for STA interface i.e. primary interface
+	if (!pmk_list) {
+		printk("pmk_list is NULL\n");
+		return -EINVAL;
+	}
+	/* pmk list is supported only for STA interface i.e. primary interface
 	  * Refer code wlc_bsscfg.c->wlc_bsscfg_sta_init
-	  * Do we really need to support PMK cache in P2P in firmware?
 	*/
 	if (primary_dev != dev) {
 		WL_INFO(("Not supporting Flushing pmklist on virtual"
@@ -2982,8 +3217,8 @@
 		}
 	}
 	if (likely(!err)) {
-		err = wl_dev_bufvar_set(dev, "pmkid_info", (char *)pmk_list,
-			sizeof(*pmk_list));
+		err = wldev_iovar_setbuf(dev, "pmkid_info", (char *)pmk_list,
+			sizeof(*pmk_list), wl->ioctl_buf, WLC_IOCTL_MAXLEN, NULL);
 	}
 
 	return err;
@@ -3084,7 +3319,7 @@
 
 }
 
-wl_scan_params_t *
+static wl_scan_params_t *
 wl_cfg80211_scan_alloc_params(int channel, int nprobes, int *out_params_size)
 {
 	wl_scan_params_t *params;
@@ -3121,7 +3356,6 @@
 	*out_params_size = params_size;	/* rtn size to the caller */
 	return params;
 }
-
 s32
 wl_cfg80211_scan_abort(struct wl_priv *wl, struct net_device *ndev)
 {
@@ -3145,18 +3379,17 @@
 		}
 	}
 	del_timer_sync(&wl->scan_timeout);
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	if (wl->scan_request) {
 		cfg80211_scan_done(wl->scan_request, true);
 		wl->scan_request = NULL;
 	}
-	wl_clr_drv_status(wl, SCANNING);
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	wl_clr_drv_status(wl, SCANNING, ndev);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 	if (params)
 		kfree(params);
 	return err;
 }
-
 static s32
 wl_cfg80211_remain_on_channel(struct wiphy *wiphy, struct net_device *dev,
 	struct ieee80211_channel * channel,
@@ -3164,36 +3397,49 @@
 	unsigned int duration, u64 *cookie)
 {
 	s32 target_channel;
+	u32 id;
+	struct ether_addr primary_mac;
+	struct net_device *ndev = NULL;
 
 	s32 err = BCME_OK;
 	struct wl_priv *wl = wiphy_priv(wiphy);
-	dhd_pub_t *dhd = (dhd_pub_t *)(wl->pub);
 	WL_DBG(("Enter, netdev_ifidx: %d \n", dev->ifindex));
-	if (likely(wl_get_drv_status(wl, SCANNING))) {
-		wl_cfg80211_scan_abort(wl, dev);
+
+	if (wl->p2p_net == dev) {
+		ndev = wl_to_prmry_ndev(wl);
+	} else {
+		ndev = dev;
+	}
+
+	if (wl_get_drv_status(wl, SCANNING, ndev)) {
+		wl_cfg80211_scan_abort(wl, ndev);
 	}
 
 	target_channel = ieee80211_frequency_to_channel(channel->center_freq);
 	memcpy(&wl->remain_on_chan, channel, sizeof(struct ieee80211_channel));
 	wl->remain_on_chan_type = channel_type;
-	wl->cache_cookie = *cookie;
+	id = ++wl->last_roc_id;
+	if (id == 0)
+		id = ++wl->last_roc_id;
+	*cookie = id;
 	cfg80211_ready_on_channel(dev, *cookie, channel,
 		channel_type, duration, GFP_KERNEL);
-	if (!p2p_on(wl)) {
-		wl_cfgp2p_generate_bss_mac(&dhd->mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
+	if (!p2p_is_on(wl)) {
+		get_primary_mac(wl, &primary_mac);
+		wl_cfgp2p_generate_bss_mac(&primary_mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
 
 		/* In case of p2p_listen command, supplicant send remain_on_channel
 		 * without turning on P2P
 		 */
 
 		p2p_on(wl) = true;
-		err = wl_cfgp2p_enable_discovery(wl, dev, NULL, 0);
+		err = wl_cfgp2p_enable_discovery(wl, ndev, NULL, 0);
 
 		if (unlikely(err)) {
 			goto exit;
 		}
 	}
-	if (p2p_on(wl))
+	if (p2p_is_on(wl))
 		wl_cfgp2p_discover_listen(wl, target_channel, duration);
 
 
@@ -3209,41 +3455,139 @@
 	WL_DBG((" enter ) netdev_ifidx: %d \n", dev->ifindex));
 	return err;
 }
+static s32
+wl_cfg80211_send_pending_tx_act_frm(struct wl_priv *wl)
+{
+	wl_af_params_t *tx_act_frm;
+	struct net_device *dev = wl->afx_hdl->dev;
+	if (!p2p_is_on(wl))
+		return -1;
+
+	if (dev == wl->p2p_net) {
+		dev = wl_to_prmry_ndev(wl);
+	}
+
+	tx_act_frm = wl->afx_hdl->pending_tx_act_frm;
+	WL_DBG(("Sending the action frame\n"));
+	wl->afx_hdl->pending_tx_act_frm = NULL;
+	if (tx_act_frm != NULL) {
+		/* Suspend P2P discovery's search-listen to prevent it from
+		 * starting a scan or changing the channel.
+		 */
+		wl_clr_drv_status(wl, SENDING_ACT_FRM, wl->afx_hdl->dev);
+		wl_clr_drv_status(wl, SCANNING, wl->afx_hdl->dev);
+		wl_cfg80211_scan_abort(wl, dev);
+		wl_cfgp2p_discover_enable_search(wl, false);
+		tx_act_frm->channel = wl->afx_hdl->peer_chan;
+		wl->afx_hdl->ack_recv = (wl_cfgp2p_tx_action_frame(wl, dev,
+			tx_act_frm, wl->afx_hdl->bssidx)) ? false : true;
+	}
+	return 0;
+}
+static void
+wl_cfg80211_afx_handler(struct work_struct *work)
+{
+
+	struct afx_hdl *afx_instance;
+	struct wl_priv *wl = wlcfg_drv_priv;
+	afx_instance = container_of(work, struct afx_hdl, work);
+	if (afx_instance != NULL) {
+		wl_cfgp2p_act_frm_search(wl, wl->afx_hdl->dev,
+			wl->afx_hdl->bssidx, 0);
+	}
+}
+
+static bool
+wl_cfg80211_send_at_common_channel(struct wl_priv *wl,
+	struct net_device *dev,
+	wl_af_params_t *af_params)
+{
+	WL_DBG((" enter ) \n"));
+	/* initialize afx_hdl */
+	wl->afx_hdl->pending_tx_act_frm = af_params;
+	wl->afx_hdl->bssidx = wl_cfgp2p_find_idx(wl, dev);
+	wl->afx_hdl->dev = dev;
+	wl->afx_hdl->retry = 0;
+	wl->afx_hdl->peer_chan = WL_INVALID;
+	wl->afx_hdl->ack_recv = false;
+	memcpy(wl->afx_hdl->pending_tx_dst_addr.octet,
+		af_params->action_frame.da.octet,
+		sizeof(wl->afx_hdl->pending_tx_dst_addr.octet));
+	/* Loop to wait until we have sent the pending tx action frame or the
+	 * pending action frame tx is cancelled.
+	 */
+	while ((wl->afx_hdl->retry < WL_CHANNEL_SYNC_RETRY) &&
+		(wl->afx_hdl->peer_chan == WL_INVALID)) {
+		wl_set_drv_status(wl, SENDING_ACT_FRM, dev);
+		wl_set_drv_status(wl, SCANNING, dev);
+		WL_DBG(("Scheduling the action frame for sending.. retry %d\n",
+			wl->afx_hdl->retry));
+		/* Do find_peer_for_action */
+		schedule_work(&wl->afx_hdl->work);
+		wait_for_completion(&wl->act_frm_scan);
+		wl->afx_hdl->retry++;
+	}
+	if (wl->afx_hdl->peer_chan != WL_INVALID)
+		wl_cfg80211_send_pending_tx_act_frm(wl);
+	else {
+		WL_ERR(("Couldn't find the peer after %d retries\n",
+			wl->afx_hdl->retry));
+	}
+	wl->afx_hdl->dev = NULL;
+	wl->afx_hdl->bssidx = WL_INVALID;
+	wl_clr_drv_status(wl, SENDING_ACT_FRM, dev);
+	if (wl->afx_hdl->ack_recv)
+		return true; /* ACK */
+	else
+		return false; /* NO ACK */
+}
 
 static s32
-wl_cfg80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
+wl_cfg80211_mgmt_tx(struct wiphy *wiphy, struct net_device *ndev,
 	struct ieee80211_channel *channel, bool offchan,
 	enum nl80211_channel_type channel_type,
 	bool channel_type_valid, unsigned int wait,
 	const u8* buf, size_t len, u64 *cookie)
 {
+	struct ether_addr primary_mac;
 	wl_action_frame_t *action_frame;
 	wl_af_params_t *af_params;
 	wifi_p2p_ie_t *p2p_ie;
 	wpa_ie_fixed_t *wps_ie;
+	scb_val_t scb_val;
 	const struct ieee80211_mgmt *mgmt;
 	struct wl_priv *wl = wiphy_priv(wiphy);
-	dhd_pub_t *dhd = (dhd_pub_t *)(wl->pub);
+	struct net_device *dev = NULL;
 	s32 err = BCME_OK;
 	s32 bssidx = 0;
 	u32 p2pie_len = 0;
 	u32 wpsie_len = 0;
-	u16 fc;
+	u32 id;
+	u32 retry = 0;
 	bool ack = false;
 	wifi_p2p_pub_act_frame_t *act_frm;
+	wifi_p2psd_gas_pub_act_frame_t *sd_act_frm = NULL;
+	s8 eabuf[ETHER_ADDR_STR_LEN];
+
 	WL_DBG(("Enter \n"));
+
+	if (ndev == wl->p2p_net) {
+		dev = wl_to_prmry_ndev(wl);
+	} else {
+		/* If TX req is for any valid ifidx. Use as is */
+		dev = ndev;
+	}
+
 	/* find bssidx based on ndev */
 	bssidx = wl_cfgp2p_find_idx(wl, dev);
-	/* cookie generation */
-	*cookie = (unsigned long) buf;
-
 	if (bssidx == -1) {
 
 		WL_ERR(("Can not find the bssidx for dev( %p )\n", dev));
 		return -ENODEV;
 	}
-	if (wl->p2p_supported && p2p_on(wl)) {
-		wl_cfgp2p_generate_bss_mac(&dhd->mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
+	if (p2p_is_on(wl)) {
+		get_primary_mac(wl, &primary_mac);
+		wl_cfgp2p_generate_bss_mac(&primary_mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
 		/* Suspend P2P discovery search-listen to prevent it from changing the
 		 * channel.
 		 */
@@ -3252,31 +3596,27 @@
 			return -EFAULT;
 		}
 	}
-
-	mgmt = (const struct ieee80211_mgmt *) buf;
-	fc = mgmt->frame_control;
-	if (fc != IEEE80211_STYPE_ACTION) {
-		if (fc == IEEE80211_STYPE_PROBE_RESP) {
+	*cookie = 0;
+	id = wl->send_action_id++;
+	if (id == 0)
+		id = wl->send_action_id++;
+	*cookie = id;
+	mgmt = (const struct ieee80211_mgmt *)buf;
+	if (ieee80211_is_mgmt(mgmt->frame_control)) {
+		if (ieee80211_is_probe_resp(mgmt->frame_control)) {
 			s32 ie_offset =  DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
 			s32 ie_len = len - ie_offset;
 			if ((p2p_ie = wl_cfgp2p_find_p2pie((u8 *)(buf + ie_offset), ie_len))
 				!= NULL) {
 				/* Total length of P2P Information Element */
 				p2pie_len = p2p_ie->len + sizeof(p2p_ie->len) + sizeof(p2p_ie->id);
-				/* Have to change p2p device address in dev_info attribute
-				 * because Supplicant use primary eth0 address
-				 */
-			#ifdef ENABLE_DRIVER_CHANGE_IFADDR /* We are now doing this in supplicant */
-				wl_cfg80211_change_ifaddr((u8 *)p2p_ie,
-					&wl->p2p_dev_addr, P2P_SEID_DEV_INFO);
-			#endif
 			}
 			if ((wps_ie = wl_cfgp2p_find_wpsie((u8 *)(buf + ie_offset), ie_len))
 				!= NULL) {
 				/* Order of Vendor IE is 1) WPS IE +
 				 * 2) P2P IE created by supplicant
 				 *  So, it is ok to find start address of WPS IE
-				 *  to save IEs to firmware
+				 *  to save IEs
 				 */
 				wpsie_len = wps_ie->length + sizeof(wps_ie->length) +
 					sizeof(wps_ie->tag);
@@ -3284,18 +3624,35 @@
 					VNDR_IE_PRBRSP_FLAG,
 					(u8 *)wps_ie, wpsie_len + p2pie_len);
 			}
+			cfg80211_mgmt_tx_status(ndev, *cookie, buf, len, true, GFP_KERNEL);
+			goto exit;
+		} else if (ieee80211_is_disassoc(mgmt->frame_control) ||
+			ieee80211_is_deauth(mgmt->frame_control)) {
+			memcpy(scb_val.ea.octet, mgmt->da, ETH_ALEN);
+			scb_val.val = mgmt->u.disassoc.reason_code;
+			wldev_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scb_val,
+				sizeof(scb_val_t), true);
+			WL_DBG(("Disconnect STA : %s\n",
+				bcm_ether_ntoa((const struct ether_addr *)mgmt->da, eabuf)));
+			cfg80211_mgmt_tx_status(ndev, *cookie, buf, len, true, GFP_KERNEL);
+			goto exit;
+
+		} else if (ieee80211_is_action(mgmt->frame_control)) {
+			/* Abort the dwell time of any previous off-channel action frame that may
+			* be still in effect.  Sending off-channel action frames relies on the
+			* driver's scan engine.  If a previous off-channel action frame tx is
+			* still in progress (including the dwell time), then this new action
+			* frame will not be sent out.
+			*/
+			wl_cfg80211_scan_abort(wl, dev);
+
 		}
-		cfg80211_mgmt_tx_status(dev, *cookie, buf, len, true, GFP_KERNEL);
-		goto exit;
+
 	} else {
-	    /* Abort the dwell time of any previous off-channel action frame that may
-	     * be still in effect.  Sending off-channel action frames relies on the
-	     * driver's scan engine.  If a previous off-channel action frame tx is
-	     * still in progress (including the dwell time), then this new action
-	     * frame will not be sent out.
-	     */
-		wl_cfg80211_scan_abort(wl, dev);
+		WL_ERR(("Driver only allows MGMT packet type\n"));
+		goto exit;
 	}
+
 	af_params = (wl_af_params_t *) kzalloc(WL_WIFI_AF_PARAMS_SIZE, GFP_KERNEL);
 
 	if (af_params == NULL)
@@ -3307,7 +3664,7 @@
 	action_frame = &af_params->action_frame;
 
 	/* Add the packet Id */
-	action_frame->packetId = (u32) action_frame;
+	action_frame->packetId = *cookie;
 	WL_DBG(("action frame %d\n", action_frame->packetId));
 	/* Add BSSID */
 	memcpy(&action_frame->da, &mgmt->da[0], ETHER_ADDR_LEN);
@@ -3321,6 +3678,14 @@
 	af_params->channel =
 		ieee80211_frequency_to_channel(channel->center_freq);
 
+	if (channel->band == IEEE80211_BAND_5GHZ) {
+		err = wldev_ioctl(dev, WLC_SET_CHANNEL,
+			&af_params->channel, sizeof(af_params->channel), true);
+		if (err < 0) {
+			WL_ERR(("WLC_SET_CHANNEL error %d\n", err));
+		}
+	}
+
 	/* Add the dwell time
 	 * Dwell time to stay off-channel to wait for a response action frame
 	 * after transmitting an GO Negotiation action frame
@@ -3333,23 +3698,46 @@
 	WL_DBG(("action_frame->len: %d chan %d category %d subtype %d\n",
 		action_frame->len, af_params->channel,
 		act_frm->category, act_frm->subtype));
-	if (wl->p2p->vif_created) {
-		/*
-		 * To make sure to send successfully action frame, we have to turn off mpc
-		 */
-		if ((act_frm->subtype == P2P_PAF_GON_REQ)||
-		  (act_frm->subtype == P2P_PAF_GON_RSP)) {
-			wldev_iovar_setint(dev, "mpc", 0);
-		} else if (act_frm->subtype == P2P_PAF_GON_CONF) {
-			wldev_iovar_setint(dev, "mpc", 1);
-		} else if (act_frm->subtype == P2P_PAF_DEVDIS_REQ) {
-			af_params->dwell_time = WL_LONG_DWELL_TIME;
-		}
+	/*
+	 * To make sure to send successfully action frame, we have to turn off mpc
+	 */
+
+	if (act_frm && ((act_frm->subtype == P2P_PAF_GON_REQ) ||
+	  (act_frm->subtype == P2P_PAF_GON_RSP) ||
+	  (act_frm->subtype == P2P_PAF_GON_CONF) ||
+	  (act_frm->subtype == P2P_PAF_PROVDIS_REQ))) {
+		wldev_iovar_setint(dev, "mpc", 0);
 	}
 
-	ack = (wl_cfgp2p_tx_action_frame(wl, dev, af_params, bssidx)) ? false : true;
-	cfg80211_mgmt_tx_status(dev, *cookie, buf, len, ack, GFP_KERNEL);
+	if (act_frm && act_frm->subtype == P2P_PAF_DEVDIS_REQ) {
+		af_params->dwell_time = WL_LONG_DWELL_TIME;
+	} else if (act_frm &&
+		(act_frm->subtype == P2P_PAF_PROVDIS_REQ ||
+		act_frm->subtype == P2P_PAF_PROVDIS_RSP ||
+		act_frm->subtype == P2P_PAF_GON_RSP)) {
+		af_params->dwell_time = WL_MED_DWELL_TIME;
+	}
 
+	if (IS_P2P_SOCIAL(af_params->channel) &&
+		(IS_P2P_PUB_ACT_REQ(act_frm, action_frame->len) ||
+		IS_GAS_REQ(sd_act_frm, action_frame->len))) {
+		/* channel offload for action request frame */
+		ack = wl_cfg80211_send_at_common_channel(wl, dev, af_params);
+	} else {
+		ack = (wl_cfgp2p_tx_action_frame(wl, dev, af_params, bssidx)) ? false : true;
+		if (!ack) {
+			for (retry = 0; retry < WL_CHANNEL_SYNC_RETRY; retry++) {
+				ack = (wl_cfgp2p_tx_action_frame(wl, dev,
+					af_params, bssidx)) ? false : true;
+				if (ack)
+					break;
+			}
+		}
+	}
+	cfg80211_mgmt_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
+	if (act_frm && act_frm->subtype == P2P_PAF_GON_CONF) {
+		wldev_iovar_setint(dev, "mpc", 1);
+	}
 	kfree(af_params);
 exit:
 	return err;
@@ -3403,7 +3791,11 @@
 {
 	s32 channel;
 	s32 err = BCME_OK;
+	struct wl_priv *wl = wiphy_priv(wiphy);
 
+	if (wl->p2p_net == dev) {
+		dev = wl_to_prmry_ndev(wl);
+	}
 	channel = ieee80211_frequency_to_channel(chan->center_freq);
 	WL_DBG(("netdev_ifidx(%d), chan_type(%d) target channel(%d) \n",
 		dev->ifindex, channel_type, channel));
@@ -3420,7 +3812,6 @@
 	s32 len = 0;
 	s32 err = BCME_OK;
 	u16 auth = 0; /* d11 open authentication */
-	u16 count;
 	u32 wsec;
 	u32 pval = 0;
 	u32 gval = 0;
@@ -3451,6 +3842,11 @@
 		case WPA_CIPHER_AES_CCM:
 			gval = AES_ENABLED;
 			break;
+#ifdef WAPI
+		case WAPI_CIPHER_SMS4:
+			gval = SMS4_ENABLED;
+			break;
+#endif
 		default:
 			WL_ERR(("No Security Info\n"));
 			break;
@@ -3458,7 +3854,7 @@
 	len -= WPA_SUITE_LEN;
 	/* check the unicast cipher */
 	ucast = (wpa_suite_ucast_t *)&mcast[1];
-	count = ltoh16_ua(&ucast->count);
+	ltoh16_ua(&ucast->count);
 	tmp = ucast->list[0].oui;
 	switch (tmp[DOT11_OUI_LEN]) {
 		case WPA_CIPHER_NONE:
@@ -3474,6 +3870,11 @@
 		case WPA_CIPHER_AES_CCM:
 			pval = AES_ENABLED;
 			break;
+#ifdef WAPI
+		case WAPI_CIPHER_SMS4:
+			pval = SMS4_ENABLED;
+			break;
+#endif
 		default:
 			WL_ERR(("No Security Info\n"));
 	}
@@ -3481,7 +3882,7 @@
 	wsec = (pval | gval | SES_OW_ENABLED);
 	/* check the AKM */
 	mgmt = (wpa_suite_auth_key_mgmt_t *)&ucast->list[1];
-	count = ltoh16_ua(&mgmt->count);
+	ltoh16_ua(&mgmt->count);
 	tmp = (u8 *)&mgmt->list[0];
 	switch (tmp[DOT11_OUI_LEN]) {
 		case RSN_AKM_NONE:
@@ -3684,13 +4085,19 @@
 	u16 p2pie_len = 0;
 	u8 beacon_ie[IE_MAX_LEN];
 	s32 ie_offset = 0;
-	s32 bssidx = wl_cfgp2p_find_idx(wl, dev);
+	s32 bssidx = 0;
 	s32 infra = 1;
 	s32 join_params_size = 0;
 	s32 ap = 0;
 	WL_DBG(("interval (%d) dtim_period (%d) head_len (%d) tail_len (%d)\n",
 		info->interval, info->dtim_period, info->head_len, info->tail_len));
-	if (wl->p2p_supported && p2p_on(wl) &&
+
+	if (wl->p2p_net == dev) {
+		dev = wl_to_prmry_ndev(wl);
+	}
+
+	bssidx = wl_cfgp2p_find_idx(wl, dev);
+	if (p2p_is_on(wl) &&
 		(bssidx == wl_to_p2p_bss_bssidx(wl,
 		P2PAPI_BSSCFG_CONNECTION))) {
 		memset(beacon_ie, 0, sizeof(beacon_ie));
@@ -3728,19 +4135,13 @@
 		if ((p2p_ie = wl_cfgp2p_find_p2pie((u8 *)info->tail, info->tail_len)) != NULL) {
 			/* Total length of P2P Information Element */
 			p2pie_len = p2p_ie->len + sizeof(p2p_ie->len) + sizeof(p2p_ie->id);
-		#ifdef ENABLE_DRIVER_CHANGE_IFADDR /* We are now doing this in supplicant */
-			/* Have to change device address in dev_id attribute because Supplicant
-			 * use primary eth0 address
-			 */
-			wl_cfg80211_change_ifaddr((u8 *)p2p_ie, &wl->p2p_dev_addr, P2P_SEID_DEV_ID);
-		#endif
 			memcpy(&beacon_ie[wpsie_len], p2p_ie, p2pie_len);
 
 		} else {
 			WL_ERR(("No P2PIE in beacon \n"));
 		}
 		/* add WLC_E_PROBREQ_MSG event to respose probe_request from STA */
-		wl_dongle_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
+		wl_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
 		wl_cfgp2p_set_management_ie(wl, dev, bssidx, VNDR_IE_BEACON_FLAG,
 			beacon_ie, wpsie_len + p2pie_len);
 
@@ -3763,17 +4164,18 @@
 				goto exit;
 			}
 			err = wldev_iovar_setbuf_bsscfg(dev, "ssid", &wl->p2p->ssid,
-				sizeof(wl->p2p->ssid), ioctlbuf, sizeof(ioctlbuf), bssidx);
+				sizeof(wl->p2p->ssid), wl->ioctl_buf, WLC_IOCTL_MAXLEN,
+				bssidx, &wl->ioctl_buf_sync);
 			if (err < 0) {
 				WL_ERR(("GO SSID setting error %d\n", err));
 				goto exit;
 			}
-			if ((err = wl_cfgp2p_bss(dev, bssidx, 1)) < 0) {
+			if ((err = wl_cfgp2p_bss(wl, dev, bssidx, 1)) < 0) {
 				WL_ERR(("GO Bring up error %d\n", err));
 				goto exit;
 			}
 		}
-	} else if (wl_get_drv_status(wl, AP_CREATING)) {
+	} else if (wl_get_drv_status(wl, AP_CREATING, dev)) {
 		ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
 		ap = 1;
 		/* find the SSID */
@@ -3848,7 +4250,7 @@
 				beacon_ie, wpsie_len);
 				wl->ap_info->wps_ie = kmemdup(wps_ie, 	wpsie_len, GFP_KERNEL);
 				/* add WLC_E_PROBREQ_MSG event to respose probe_request from STA */
-				wl_dongle_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
+				wl_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
 			} else {
 				WL_DBG(("No WPSIE in beacon \n"));
 			}
@@ -3879,11 +4281,11 @@
 			/* create softap */
 			if ((err = wldev_ioctl(dev, WLC_SET_SSID, &join_params,
 				join_params_size, true)) == 0) {
-				wl_clr_drv_status(wl, AP_CREATING);
-				wl_set_drv_status(wl, AP_CREATED);
+				wl_clr_drv_status(wl, AP_CREATING, dev);
+				wl_set_drv_status(wl, AP_CREATED, dev);
 			}
 		}
-	} else if (wl_get_drv_status(wl, AP_CREATED)) {
+	} else if (wl_get_drv_status(wl, AP_CREATED, dev)) {
 		ap = 1;
 		/* find the WPSIE */
 		if ((wps_ie = wl_cfgp2p_find_wpsie((u8 *)info->tail, info->tail_len)) != NULL) {
@@ -3901,12 +4303,12 @@
 				kfree(wl->ap_info->wps_ie);
 				wl->ap_info->wps_ie = kmemdup(wps_ie, 	wpsie_len, GFP_KERNEL);
 				/* add WLC_E_PROBREQ_MSG event to respose probe_request from STA */
-				wl_dongle_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
+				wl_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
 			} else if (wl->ap_info->wps_ie == NULL) {
 				WL_DBG((" WPS IE is added\n"));
 				wl->ap_info->wps_ie = kmemdup(wps_ie, 	wpsie_len, GFP_KERNEL);
 				/* add WLC_E_PROBREQ_MSG event to respose probe_request from STA */
-				wl_dongle_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
+				wl_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, pbc);
 			}
 			/* find the RSN_IE */
 			if ((wpa2_ie = bcm_parse_tlvs((u8 *)info->tail, info->tail_len,
@@ -3972,12 +4374,12 @@
 				}
 				if (update_bss) {
 					wl->ap_info->security_mode = true;
-					wl_cfgp2p_bss(dev, bssidx, 0);
+					wl_cfgp2p_bss(wl, dev, bssidx, 0);
 					if (wl_validate_wpa2ie(dev, wpa2_ie, bssidx)  < 0 ||
 						wl_validate_wpaie(dev, wpa_ie, bssidx) < 0) {
 						return BCME_ERROR;
 					}
-					wl_cfgp2p_bss(dev, bssidx, 1);
+					wl_cfgp2p_bss(wl, dev, bssidx, 1);
 				}
 			}
 		} else {
@@ -4024,7 +4426,7 @@
 	.add_beacon = wl_cfg80211_add_set_beacon,
 };
 
-static s32 wl_mode_to_nl80211_iftype(s32 mode)
+s32 wl_mode_to_nl80211_iftype(s32 mode)
 {
 	s32 err = 0;
 
@@ -4042,7 +4444,7 @@
 	return err;
 }
 
-static struct wireless_dev *wl_alloc_wdev(struct device *sdiofunc_dev)
+static struct wireless_dev *wl_alloc_wdev(struct device *dev)
 {
 	struct wireless_dev *wdev;
 	s32 err = 0;
@@ -4058,7 +4460,7 @@
 		err = -ENOMEM;
 		goto wiphy_new_out;
 	}
-	set_wiphy_dev(wdev->wiphy, sdiofunc_dev);
+	set_wiphy_dev(wdev->wiphy, dev);
 	wdev->wiphy->max_scan_ie_len = WL_SCAN_IE_LEN_MAX;
 	/* Report  how many SSIDs Driver can support per Scan request */
 	wdev->wiphy->max_scan_ssids = WL_SCAN_PARAMS_SSID_MAX;
@@ -4108,24 +4510,21 @@
 
 static void wl_free_wdev(struct wl_priv *wl)
 {
-	int i;
 	struct wireless_dev *wdev = wl->wdev;
-
-	if (unlikely(!wdev)) {
+	struct wiphy *wiphy;
+	if (!wdev) {
 		WL_ERR(("wdev is invalid\n"));
 		return;
 	}
-
-	for (i = 0; i < VWDEV_CNT; i++) {
-		if ((wl->vwdev[i] != NULL)) {
-			kfree(wl->vwdev[i]);
-			wl->vwdev[i] = NULL;
-		}
-	}
+	wiphy = wdev->wiphy;
 	wiphy_unregister(wdev->wiphy);
 	wdev->wiphy->dev.parent = NULL;
-	wiphy_free(wdev->wiphy);
-	kfree(wdev);
+
+	wl_delete_all_netinfo(wl);
+	wiphy_free(wiphy);
+	/* PLEASE do NOT call any function after wiphy_free, the driver's private structure "wl",
+	 * which is the private part of wiphy, has been freed in wiphy_free !!!!!!!!!!!
+	 */
 }
 
 static s32 wl_inform_bss(struct wl_priv *wl)
@@ -4155,6 +4554,7 @@
 	struct wl_cfg80211_bss_info *notif_bss_info;
 	struct wl_scan_req *sr = wl_to_sr(wl);
 	struct beacon_proberesp *beacon_proberesp;
+	struct cfg80211_bss *cbss = NULL;
 	s32 mgmt_type;
 	s32 signal;
 	u32 freq;
@@ -4200,6 +4600,7 @@
 		u.beacon.variable) + wl_get_ielen(wl);
 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 38) && !defined(WL_COMPAT_WIRELESS)
 	freq = ieee80211_channel_to_frequency(notif_bss_info->channel);
+	(void)band->band;
 #else
 	freq = ieee80211_channel_to_frequency(notif_bss_info->channel, band->band);
 #endif
@@ -4213,13 +4614,30 @@
 
 	signal = notif_bss_info->rssi * 100;
 
-	if (unlikely(!cfg80211_inform_bss_frame(wiphy, channel, mgmt,
-		le16_to_cpu(notif_bss_info->frame_len),
-		signal, GFP_KERNEL))) {
+#if defined(WLP2P) && ENABLE_P2P_INTERFACE
+	if (wl->p2p_net && wl->scan_request && wl->scan_request->dev == wl->p2p_net) {
+#else
+	if (p2p_is_on(wl) && p2p_scan(wl)) {
+#endif
+		/* find the P2PIE, if we do not find it, we will discard this frame */
+		wifi_p2p_ie_t * p2p_ie;
+		if ((p2p_ie = wl_cfgp2p_find_p2pie((u8 *)beacon_proberesp->variable,
+			wl_get_ielen(wl))) == NULL) {
+			WL_ERR(("Couldn't find P2PIE in probe response/beacon\n"));
+			kfree(notif_bss_info);
+			return err;
+		}
+	}
+
+	cbss = cfg80211_inform_bss_frame(wiphy, channel, mgmt,
+		le16_to_cpu(notif_bss_info->frame_len), signal, GFP_KERNEL);
+	if (unlikely(!cbss)) {
 		WL_ERR(("cfg80211_inform_bss_frame error\n"));
 		kfree(notif_bss_info);
 		return -EINVAL;
 	}
+
+	cfg80211_put_bss(cbss);
 	kfree(notif_bss_info);
 
 	return err;
@@ -4286,10 +4704,11 @@
 	s32 err = 0;
 	s32 freq;
 	s32 channel;
-	u8 body[200];
+	u8 body[WL_FRAME_LEN];
 	u32 event = ntoh32(e->event_type);
 	u32 reason = ntoh32(e->reason);
 	u32 len = ntoh32(e->datalen);
+
 	u16 fc = 0;
 	u8 *mgmt_frame;
 	u8 bsscfgidx = e->bsscfgidx;
@@ -4302,12 +4721,19 @@
 	memset(body, 0, sizeof(body));
 	memset(&bssid, 0, ETHER_ADDR_LEN);
 	WL_DBG(("Enter \n"));
+	if (wl_get_mode_by_netdev(wl, ndev) == WL_INVALID)
+		return WL_INVALID;
+	if (len > WL_FRAME_LEN) {
+		WL_ERR(("Received frame length %d from dongle is greater than"
+			" allocated body buffer len %d", len, WL_FRAME_LEN));
+		goto exit;
+	}
 
-	if (get_mode_by_netdev(wl, ndev) == WL_MODE_AP) {
+	if (wl_get_mode_by_netdev(wl, ndev) == WL_MODE_AP) {
 		memcpy(body, data, len);
 		wldev_iovar_getbuf_bsscfg(ndev, "cur_etheraddr",
-		NULL, 0, ioctlbuf, sizeof(ioctlbuf), bsscfgidx);
-		memcpy(da.octet, ioctlbuf, ETHER_ADDR_LEN);
+			NULL, 0, wl->ioctl_buf, WLC_IOCTL_MAXLEN, bsscfgidx, &wl->ioctl_buf_sync);
+		memcpy(da.octet, wl->ioctl_buf, ETHER_ADDR_LEN);
 		err = wldev_ioctl(ndev, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN, false);
 		switch (event) {
 			case WLC_E_ASSOC_IND:
@@ -4340,6 +4766,7 @@
 
 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 38) && !defined(WL_COMPAT_WIRELESS)
 		freq = ieee80211_channel_to_frequency(channel);
+		(void)band->band;
 #else
 		freq = ieee80211_channel_to_frequency(channel, band->band);
 #endif
@@ -4364,21 +4791,20 @@
 		if (wl_is_linkup(wl, e, ndev)) {
 			wl_link_up(wl);
 			act = true;
-			wl_update_prof(wl, e, &act, WL_PROF_ACT);
-			wl_update_prof(wl, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
+			wl_update_prof(wl, ndev, e, &act, WL_PROF_ACT);
+			wl_update_prof(wl, ndev, NULL, (void *)&e->addr, WL_PROF_BSSID);
 			if (wl_is_ibssmode(wl, ndev)) {
 				printk("cfg80211_ibss_joined\n");
 				cfg80211_ibss_joined(ndev, (s8 *)&e->addr,
 					GFP_KERNEL);
 				WL_DBG(("joined in IBSS network\n"));
 			} else {
-				if (!wl_get_drv_status(wl, DISCONNECTING)) {
-					printk("wl_bss_connect_done succeeded status=(0x%x)\n",
-						(int)wl->status);
+				if (!wl_get_drv_status(wl, DISCONNECTING, ndev)) {
+					printk("wl_bss_connect_done succeeded\n");
 					wl_bss_connect_done(wl, ndev, e, data, true);
 					WL_DBG(("joined in BSS network \"%s\"\n",
 					((struct wlc_ssid *)
-					 wl_read_prof(wl, WL_PROF_SSID))->SSID));
+					 wl_read_prof(wl, ndev, WL_PROF_SSID))->SSID));
 				}
 			}
 
@@ -4386,15 +4812,15 @@
 			if (wl->scan_request) {
 				del_timer_sync(&wl->scan_timeout);
 				if (wl->escan_on) {
-					wl_notify_escan_complete(wl, true);
+					wl_notify_escan_complete(wl, ndev, true);
 				} else
 					wl_iscan_aborted(wl);
 			}
-			if (wl_get_drv_status(wl, CONNECTED)) {
+			if (wl_get_drv_status(wl, CONNECTED, ndev)) {
 				scb_val_t scbval;
-				u8 *curbssid = wl_read_prof(wl, WL_PROF_BSSID);
+				u8 *curbssid = wl_read_prof(wl, ndev, WL_PROF_BSSID);
 				printk("link down, call cfg80211_disconnected\n");
-				wl_clr_drv_status(wl, CONNECTED);
+				wl_clr_drv_status(wl, CONNECTED, ndev);
 				/* To make sure disconnect, explictly send dissassoc
 				*  for BSSID 00:00:00:00:00:00 issue
 				*/
@@ -4406,12 +4832,12 @@
 					sizeof(scb_val_t), true);
 				cfg80211_disconnected(ndev, 0, NULL, 0, GFP_KERNEL);
 				wl_link_down(wl);
-				wl_init_prof(wl);
-			} else if (wl_get_drv_status(wl, CONNECTING)) {
+				wl_init_prof(wl, ndev);
+			} else if (wl_get_drv_status(wl, CONNECTING, ndev)) {
 				printk("link down, during connecting\n");
 				wl_bss_connect_done(wl, ndev, e, data, false);
 			}
-			wl_clr_drv_status(wl, DISCONNECTING);
+			wl_clr_drv_status(wl, DISCONNECTING, ndev);
 
 		} else if (wl_is_nonetwork(wl, e)) {
 			printk("connect failed event=%d e->status 0x%x\n",
@@ -4420,11 +4846,11 @@
 			if (wl->scan_request) {
 				del_timer_sync(&wl->scan_timeout);
 				if (wl->escan_on) {
-					wl_notify_escan_complete(wl, true);
+					wl_notify_escan_complete(wl, ndev, true);
 				} else
 					wl_iscan_aborted(wl);
 			}
-			if (wl_get_drv_status(wl, CONNECTING))
+			if (wl_get_drv_status(wl, CONNECTING, ndev))
 				wl_bss_connect_done(wl, ndev, e, data, false);
 		} else {
 			printk("%s nothing\n", __FUNCTION__);
@@ -4446,50 +4872,17 @@
 	u32 status = be32_to_cpu(e->status);
 	WL_DBG(("Enter \n"));
 	if (event == WLC_E_ROAM && status == WLC_E_STATUS_SUCCESS) {
-		if (wl_get_drv_status(wl, CONNECTED))
+		if (wl_get_drv_status(wl, CONNECTED, ndev))
 			wl_bss_roaming_done(wl, ndev, e, data);
 		else
 			wl_bss_connect_done(wl, ndev, e, data, true);
 		act = true;
-		wl_update_prof(wl, e, &act, WL_PROF_ACT);
-		wl_update_prof(wl, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
+		wl_update_prof(wl, ndev, e, &act, WL_PROF_ACT);
+		wl_update_prof(wl, ndev, NULL, (void *)&e->addr, WL_PROF_BSSID);
 	}
 	return err;
 }
 
-static __used s32
-wl_dev_bufvar_set(struct net_device *dev, s8 *name, s8 *buf, s32 len)
-{
-	struct wl_priv *wl = wlcfg_drv_priv;
-	u32 buflen;
-
-	buflen = bcm_mkiovar(name, buf, len, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
-	BUG_ON(unlikely(!buflen));
-
-	return wldev_ioctl(dev, WLC_SET_VAR, wl->ioctl_buf, buflen, true);
-}
-
-static s32
-wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
-	s32 buf_len)
-{
-	struct wl_priv *wl = wlcfg_drv_priv;
-	u32 len;
-	s32 err = 0;
-
-	len = bcm_mkiovar(name, NULL, 0, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
-	BUG_ON(unlikely(!len));
-	err = wldev_ioctl(dev, WLC_GET_VAR, (void *)wl->ioctl_buf,
-		WL_IOCTL_LEN_MAX, false);
-	if (unlikely(err)) {
-		WL_ERR(("error (%d)\n", err));
-		return err;
-	}
-	memcpy(buf, wl->ioctl_buf, buf_len);
-
-	return err;
-}
-
 static s32 wl_get_assoc_ies(struct wl_priv *wl, struct net_device *ndev)
 {
 	wl_assoc_info_t assoc_info;
@@ -4497,8 +4890,8 @@
 	s32 err = 0;
 
 	WL_DBG(("Enter \n"));
-	err = wl_dev_bufvar_get(ndev, "assoc_info", wl->extra_buf,
-		WL_ASSOC_INFO_MAX);
+	err = wldev_iovar_getbuf(ndev, "assoc_info", NULL, 0, wl->extra_buf,
+		WL_ASSOC_INFO_MAX, NULL);
 	if (unlikely(err)) {
 		WL_ERR(("could not get assoc info (%d)\n", err));
 		return err;
@@ -4516,8 +4909,8 @@
 		bzero(conn_info->resp_ie, sizeof(conn_info->resp_ie));
 	}
 	if (assoc_info.req_len) {
-		err = wl_dev_bufvar_get(ndev, "assoc_req_ies", wl->extra_buf,
-			WL_ASSOC_INFO_MAX);
+		err = wldev_iovar_getbuf(ndev, "assoc_req_ies", NULL, 0, wl->extra_buf,
+			WL_ASSOC_INFO_MAX, NULL);
 		if (unlikely(err)) {
 			WL_ERR(("could not get assoc req (%d)\n", err));
 			return err;
@@ -4537,8 +4930,8 @@
 		conn_info->req_ie_len = 0;
 	}
 	if (assoc_info.resp_len) {
-		err = wl_dev_bufvar_get(ndev, "assoc_resp_ies", wl->extra_buf,
-			WL_ASSOC_INFO_MAX);
+		err = wldev_iovar_getbuf(ndev, "assoc_resp_ies", NULL, 0, wl->extra_buf,
+			WL_ASSOC_INFO_MAX, NULL);
 		if (unlikely(err)) {
 			WL_ERR(("could not get assoc resp (%d)\n", err));
 			return err;
@@ -4600,26 +4993,27 @@
 	struct wl_bss_info *bi;
 	struct wlc_ssid *ssid;
 	struct bcm_tlv *tim;
-	u16 beacon_interval;
-	u8 dtim_period;
+	s32 beacon_interval;
+	s32 dtim_period;
 	size_t ie_len;
 	u8 *ie;
 	u8 *curbssid;
 	s32 err = 0;
 	struct wiphy *wiphy;
+
 	wiphy = wl_to_wiphy(wl);
 
 	if (wl_is_ibssmode(wl, ndev))
 		return err;
 
-	ssid = (struct wlc_ssid *)wl_read_prof(wl, WL_PROF_SSID);
-	curbssid = wl_read_prof(wl, WL_PROF_BSSID);
+	ssid = (struct wlc_ssid *)wl_read_prof(wl, ndev, WL_PROF_SSID);
+	curbssid = wl_read_prof(wl, ndev, WL_PROF_BSSID);
 	bss = cfg80211_get_bss(wiphy, NULL, curbssid,
 		ssid->SSID, ssid->SSID_len, WLAN_CAPABILITY_ESS,
 		WLAN_CAPABILITY_ESS);
 
 	mutex_lock(&wl->usr_sync);
-	if (unlikely(!bss)) {
+	if (!bss) {
 		WL_DBG(("Could not find the AP\n"));
 		*(u32 *) wl->extra_buf = htod32(WL_EXTRA_BUF_MAX);
 		err = wldev_ioctl(ndev, WLC_GET_BSS_INFO,
@@ -4655,7 +5049,7 @@
 		/*
 		* active scan was done so we could not get dtim
 		* information out of probe response.
-		* so we speficially query dtim information to dongle.
+		* so we speficially query dtim information.
 		*/
 		err = wldev_ioctl(ndev, WLC_GET_DTIMPRD,
 			&dtim_period, sizeof(dtim_period), false);
@@ -4665,8 +5059,8 @@
 		}
 	}
 
-	wl_update_prof(wl, NULL, &beacon_interval, WL_PROF_BEACONINT);
-	wl_update_prof(wl, NULL, &dtim_period, WL_PROF_DTIMPERIOD);
+	wl_update_prof(wl, ndev, NULL, &beacon_interval, WL_PROF_BEACONINT);
+	wl_update_prof(wl, ndev, NULL, &dtim_period, WL_PROF_DTIMPERIOD);
 
 update_bss_info_out:
 	mutex_unlock(&wl->usr_sync);
@@ -4682,8 +5076,8 @@
 	u8 *curbssid;
 
 	wl_get_assoc_ies(wl, ndev);
-	wl_update_prof(wl, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
-	curbssid = wl_read_prof(wl, WL_PROF_BSSID);
+	wl_update_prof(wl, ndev, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
+	curbssid = wl_read_prof(wl, ndev, WL_PROF_BSSID);
 	wl_update_bss_info(wl, ndev);
 	wl_update_pmklist(ndev, wl->pmk_list, err);
 	cfg80211_roamed(ndev,
@@ -4695,7 +5089,7 @@
 		conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
 	WL_DBG(("Report roaming result\n"));
 
-	wl_set_drv_status(wl, CONNECTED);
+	wl_set_drv_status(wl, CONNECTED, ndev);
 
 	return err;
 }
@@ -4706,20 +5100,21 @@
 {
 	struct wl_connect_info *conn_info = wl_to_conn(wl);
 	s32 err = 0;
-	u8 *curbssid = wl_read_prof(wl, WL_PROF_BSSID);
+	u8 *curbssid = wl_read_prof(wl, ndev, WL_PROF_BSSID);
+
 	WL_DBG((" enter\n"));
 	if (wl->scan_request) {
 		wl_cfg80211_scan_abort(wl, ndev);
 	}
-	if (wl_get_drv_status(wl, CONNECTING)) {
-		wl_clr_drv_status(wl, CONNECTING);
+	if (wl_get_drv_status(wl, CONNECTING, ndev)) {
+		wl_clr_drv_status(wl, CONNECTING, ndev);
 		if (completed) {
 			wl_get_assoc_ies(wl, ndev);
-			wl_update_prof(wl, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
-			curbssid = wl_read_prof(wl, WL_PROF_BSSID);
+			wl_update_prof(wl, ndev, NULL, (void *)(e->addr.octet), WL_PROF_BSSID);
+			curbssid = wl_read_prof(wl, ndev, WL_PROF_BSSID);
 			wl_update_bss_info(wl, ndev);
 			wl_update_pmklist(ndev, wl->pmk_list, err);
-			wl_set_drv_status(wl, CONNECTED);
+			wl_set_drv_status(wl, CONNECTED, ndev);
 		}
 		cfg80211_connect_result(ndev,
 			curbssid,
@@ -4768,11 +5163,15 @@
 	unsigned long flags;
 
 	WL_DBG(("Enter \n"));
+	if (!wl_get_drv_status(wl, SCANNING, ndev)) {
+		WL_ERR(("scan is not ready \n"));
+		return err;
+	}
 	if (wl->iscan_on && wl->iscan_kickstart)
 		return wl_wakeup_iscan(wl_to_iscan(wl));
 
 	mutex_lock(&wl->usr_sync);
-	wl_clr_drv_status(wl, SCANNING);
+	wl_clr_drv_status(wl, SCANNING, ndev);
 	err = wldev_ioctl(ndev, WLC_GET_CHANNEL, &channel_inform,
 		sizeof(channel_inform), false);
 	if (unlikely(err)) {
@@ -4803,13 +5202,13 @@
 
 scan_done_out:
 	del_timer_sync(&wl->scan_timeout);
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	if (wl->scan_request) {
 		WL_DBG(("cfg80211_scan_done\n"));
 		cfg80211_scan_done(wl->scan_request, false);
 		wl->scan_request = NULL;
 	}
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 	mutex_unlock(&wl->usr_sync);
 	return err;
 }
@@ -4865,6 +5264,7 @@
 	bool isfree = false;
 	s32 err = 0;
 	s32 freq;
+	struct net_device *dev = NULL;
 	wifi_p2p_pub_act_frame_t *act_frm;
 	wl_event_rx_frame_data_t *rxframe =
 		(wl_event_rx_frame_data_t*)data;
@@ -4875,6 +5275,13 @@
 	u16 channel = ((ntoh16(rxframe->channel) & WL_CHANSPEC_CHAN_MASK));
 
 	memset(&bssid, 0, ETHER_ADDR_LEN);
+
+	if (wl->p2p_net == ndev) {
+		dev = wl_to_prmry_ndev(wl);
+	} else {
+		dev = ndev;
+	}
+
 	if (channel <= CH_MAX_2G_CHANNEL)
 		band = wiphy->bands[IEEE80211_BAND_2GHZ];
 	else
@@ -4882,15 +5289,16 @@
 
 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 38) && !defined(WL_COMPAT_WIRELESS)
 	freq = ieee80211_channel_to_frequency(channel);
+	(void)band->band;
 #else
 	freq = ieee80211_channel_to_frequency(channel, band->band);
 #endif
 	if (event == WLC_E_ACTION_FRAME_RX) {
-		wldev_iovar_getbuf_bsscfg(ndev, "cur_etheraddr",
-		NULL, 0, ioctlbuf, sizeof(ioctlbuf), bsscfgidx);
+		wldev_iovar_getbuf_bsscfg(dev, "cur_etheraddr",
+			NULL, 0, wl->ioctl_buf, WLC_IOCTL_MAXLEN, bsscfgidx, &wl->ioctl_buf_sync);
 
-		wldev_ioctl(ndev, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN, false);
-		memcpy(da.octet, ioctlbuf, ETHER_ADDR_LEN);
+		wldev_ioctl(dev, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN, false);
+		memcpy(da.octet, wl->ioctl_buf, ETHER_ADDR_LEN);
 		err = wl_frame_get_mgmt(FC_ACTION, &da, &e->addr, &bssid,
 			&mgmt_frame, &mgmt_frame_len,
 			(u8 *)((wl_event_rx_frame_data_t *)rxframe + 1));
@@ -4905,8 +5313,9 @@
 		/*
 		 * After complete GO Negotiation, roll back to mpc mode
 		 */
-		 if (act_frm->subtype == P2P_PAF_GON_CONF) {
-			wldev_iovar_setint(ndev, "mpc", 1);
+		if ((act_frm->subtype == P2P_PAF_GON_CONF)||
+		(act_frm->subtype == P2P_PAF_PROVDIS_RSP)) {
+			wldev_iovar_setint(dev, "mpc", 1);
 		}
 	} else {
 		mgmt_frame = (u8 *)((wl_event_rx_frame_data_t *)rxframe + 1);
@@ -4925,12 +5334,7 @@
 
 static void wl_init_conf(struct wl_conf *conf)
 {
-	s32 i = 0;
 	WL_DBG(("Enter \n"));
-	for (i = 0; i <= VWDEV_CNT; i++) {
-		conf->mode[i].type = -1;
-		conf->mode[i].ndev = NULL;
-	}
 	conf->frag_threshold = (u32)-1;
 	conf->rts_threshold = (u32)-1;
 	conf->retry_short = (u32)-1;
@@ -4938,13 +5342,14 @@
 	conf->tx_power = -1;
 }
 
-static void wl_init_prof(struct wl_priv *wl)
+static void wl_init_prof(struct wl_priv *wl, struct net_device *ndev)
 {
 	unsigned long flags;
+	struct wl_profile *profile = wl_get_profile_by_netdev(wl, ndev);
 
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
-	memset(wl->profile, 0, sizeof(struct wl_profile));
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
+	memset(profile, 0, sizeof(struct wl_profile));
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 }
 
 static void wl_init_event_handler(struct wl_priv *wl)
@@ -4983,23 +5388,13 @@
 		WL_ERR(("wl_conf alloc failed\n"));
 		goto init_priv_mem_out;
 	}
-	wl->profile = (void *)kzalloc(sizeof(*wl->profile), GFP_KERNEL);
-	if (unlikely(!wl->profile)) {
-		WL_ERR(("wl_profile alloc failed\n"));
-		goto init_priv_mem_out;
-	}
-	wl->bss_info = (void *)kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
-	if (unlikely(!wl->bss_info)) {
-		WL_ERR(("Bss information alloc failed\n"));
-		goto init_priv_mem_out;
-	}
 	wl->scan_req_int =
 	    (void *)kzalloc(sizeof(*wl->scan_req_int), GFP_KERNEL);
 	if (unlikely(!wl->scan_req_int)) {
 		WL_ERR(("Scan req alloc failed\n"));
 		goto init_priv_mem_out;
 	}
-	wl->ioctl_buf = (void *)kzalloc(WL_IOCTL_LEN_MAX, GFP_KERNEL);
+	wl->ioctl_buf = (void *)kzalloc(WLC_IOCTL_MAXLEN, GFP_KERNEL);
 	if (unlikely(!wl->ioctl_buf)) {
 		WL_ERR(("Ioctl buf alloc failed\n"));
 		goto init_priv_mem_out;
@@ -5019,11 +5414,6 @@
 		WL_ERR(("Iscan buf alloc failed\n"));
 		goto init_priv_mem_out;
 	}
-	wl->fw = (void *)kzalloc(sizeof(*wl->fw), GFP_KERNEL);
-	if (unlikely(!wl->fw)) {
-		WL_ERR(("fw object alloc failed\n"));
-		goto init_priv_mem_out;
-	}
 	wl->pmk_list = (void *)kzalloc(sizeof(*wl->pmk_list), GFP_KERNEL);
 	if (unlikely(!wl->pmk_list)) {
 		WL_ERR(("pmk list alloc failed\n"));
@@ -5034,6 +5424,14 @@
 		WL_ERR(("sta info  alloc failed\n"));
 		goto init_priv_mem_out;
 	}
+	wl->afx_hdl = (void *)kzalloc(sizeof(*wl->afx_hdl), GFP_KERNEL);
+	if (unlikely(!wl->afx_hdl)) {
+		WL_ERR(("afx hdl  alloc failed\n"));
+		goto init_priv_mem_out;
+	} else {
+		init_completion(&wl->act_frm_scan);
+		INIT_WORK(&wl->afx_hdl->work, wl_cfg80211_afx_handler);
+	}
 	return 0;
 
 init_priv_mem_out:
@@ -5046,12 +5444,8 @@
 {
 	kfree(wl->scan_results);
 	wl->scan_results = NULL;
-	kfree(wl->bss_info);
-	wl->bss_info = NULL;
 	kfree(wl->conf);
 	wl->conf = NULL;
-	kfree(wl->profile);
-	wl->profile = NULL;
 	kfree(wl->scan_req_int);
 	wl->scan_req_int = NULL;
 	kfree(wl->ioctl_buf);
@@ -5062,12 +5456,16 @@
 	wl->extra_buf = NULL;
 	kfree(wl->iscan);
 	wl->iscan = NULL;
-	kfree(wl->fw);
-	wl->fw = NULL;
 	kfree(wl->pmk_list);
 	wl->pmk_list = NULL;
 	kfree(wl->sta_info);
 	wl->sta_info = NULL;
+	if (wl->afx_hdl) {
+		cancel_work_sync(&wl->afx_hdl->work);
+		kfree(wl->afx_hdl);
+		wl->afx_hdl = NULL;
+	}
+
 	if (wl->ap_info) {
 		kfree(wl->ap_info->wpa_ie);
 		kfree(wl->ap_info->rsn_ie);
@@ -5082,7 +5480,8 @@
 	int ret = 0;
 	WL_DBG(("Enter \n"));
 
-	wl->event_tsk.thr_pid = DHD_PID_KT_INVALID;
+	/* Do not use DHD in cfg driver */
+	wl->event_tsk.thr_pid = -1;
 	PROC_START(wl_event_handler, wl, &wl->event_tsk, 0);
 	if (wl->event_tsk.thr_pid < 0)
 		ret = -ENOMEM;
@@ -5112,21 +5511,22 @@
 static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted)
 {
 	struct wl_priv *wl = iscan_to_wl(iscan);
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
 	unsigned long flags;
 
 	WL_DBG(("Enter \n"));
-	if (unlikely(!wl_get_drv_status(wl, SCANNING))) {
-		wl_clr_drv_status(wl, SCANNING);
+	if (!wl_get_drv_status(wl, SCANNING, ndev)) {
+		wl_clr_drv_status(wl, SCANNING, ndev);
 		WL_ERR(("Scan complete while device not scanning\n"));
 		return;
 	}
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
-	wl_clr_drv_status(wl, SCANNING);
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
+	wl_clr_drv_status(wl, SCANNING, ndev);
 	if (likely(wl->scan_request)) {
 		cfg80211_scan_done(wl->scan_request, aborted);
 		wl->scan_request = NULL;
 	}
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 	wl->iscan_kickstart = false;
 }
 
@@ -5162,7 +5562,7 @@
 	list.results.buflen = htod32(WL_ISCAN_BUF_MAX);
 	err = wldev_iovar_getbuf(iscan->dev, "iscanresults", &list,
 		WL_ISCAN_RESULTS_FIXED_SIZE, iscan->scan_buf,
-		WL_ISCAN_BUF_MAX);
+		WL_ISCAN_BUF_MAX, NULL);
 	if (unlikely(err)) {
 		WL_ERR(("error (%d)\n", err));
 		return err;
@@ -5235,13 +5635,11 @@
 
 static s32 wl_iscan_thread(void *data)
 {
-	struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1 };
 	struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
 	struct wl_priv *wl = iscan_to_wl(iscan);
 	u32 status;
 	int err = 0;
 
-	sched_setscheduler(current, SCHED_FIFO, &param);
 	allow_signal(SIGTERM);
 	status = WL_SCAN_RESULTS_PARTIAL;
 	while (likely(!down_interruptible(&iscan->sync))) {
@@ -5276,12 +5674,11 @@
 	if (wl->scan_request) {
 		WL_ERR(("timer expired\n"));
 		if (wl->escan_on)
-			wl_notify_escan_complete(wl, true);
+			wl_notify_escan_complete(wl, wl->escan_info.ndev, true);
 		else
 			wl_notify_iscan_complete(wl_to_iscan(wl), true);
 	}
 }
-
 static void wl_iscan_timer(unsigned long data)
 {
 	struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
@@ -5322,21 +5719,46 @@
 	iscan->iscan_handler[WL_SCAN_RESULTS_NO_MEM] = wl_iscan_aborted;
 }
 
-static void wl_notify_escan_complete(struct wl_priv *wl, bool aborted)
+static s32
+wl_cfg80211_netdev_notifier_call(struct notifier_block * nb,
+	unsigned long state,
+	void *ndev)
+{
+	struct net_device *dev = ndev;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wl_priv *wl = wlcfg_drv_priv;
+
+	WL_DBG(("Enter \n"));
+	if (!wdev || dev == wl_to_prmry_ndev(wl))
+		return NOTIFY_DONE;
+	switch (state) {
+		case NETDEV_UNREGISTER:
+				/* after calling list_del_rcu(&wdev->list) */
+				wl_dealloc_netinfo(wl, ndev);
+				break;
+	}
+	return NOTIFY_DONE;
+}
+static struct notifier_block wl_cfg80211_netdev_notifier = {
+	.notifier_call = wl_cfg80211_netdev_notifier_call,
+};
+static void wl_notify_escan_complete(struct wl_priv *wl,
+	struct net_device *ndev,
+	bool aborted)
 {
 	unsigned long flags;
 
 	WL_DBG(("Enter \n"));
-	wl_clr_drv_status(wl, SCANNING);
-	if (wl->p2p_supported && p2p_on(wl))
+	wl_clr_drv_status(wl, SCANNING, ndev);
+	if (p2p_is_on(wl))
 		wl_clr_p2p_status(wl, SCANNING);
 
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	if (likely(wl->scan_request)) {
 		cfg80211_scan_done(wl->scan_request, aborted);
 		wl->scan_request = NULL;
 	}
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 }
 
 static s32 wl_escan_handler(struct wl_priv *wl,
@@ -5351,11 +5773,22 @@
 	wl_scan_results_t *list;
 	u32 bi_length;
 	u32 i;
+	u8 *p2p_dev_addr = NULL;
+
 	WL_DBG((" enter event type : %d, status : %d \n",
 		ntoh32(e->event_type), ntoh32(e->status)));
-	if (!wl->escan_on &&
-		!wl_get_drv_status(wl, SCANNING)) {
-		WL_ERR(("escan is not ready \n"));
+	/* P2P SCAN is coming from primary interface */
+	if (wl_get_p2p_status(wl, SCANNING)) {
+		if (wl_get_drv_status_all(wl, SENDING_ACT_FRM))
+			ndev = wl->afx_hdl->dev;
+		else
+			ndev = wl->escan_info.ndev;
+
+	}
+	if (!ndev || !wl->escan_on ||
+		!wl_get_drv_status(wl, SCANNING, ndev)) {
+		WL_ERR(("escan is not ready ndev %p wl->escan_on %d drv_status 0x%x\n",
+			ndev, wl->escan_on, wl_get_drv_status(wl, SCANNING, ndev)));
 		return err;
 	}
 
@@ -5380,77 +5813,111 @@
 			WL_ERR(("Invalid bss_info length %d: ignoring\n", bi_length));
 			goto exit;
 		}
-		list = (wl_scan_results_t *)wl->escan_info.escan_buf;
-		if (bi_length > ESCAN_BUF_SIZE - list->buflen) {
-			WL_ERR(("Buffer is too small: ignoring\n"));
-			goto exit;
-		}
-#define WLC_BSS_RSSI_ON_CHANNEL 0x0002
-		for (i = 0; i < list->count; i++) {
-			bss = bss ? (wl_bss_info_t *)((uintptr)bss + dtoh32(bss->length))
-				: list->bss_info;
 
-			if (!bcmp(&bi->BSSID, &bss->BSSID, ETHER_ADDR_LEN) &&
-				CHSPEC_BAND(bi->chanspec) == CHSPEC_BAND(bss->chanspec) &&
-				bi->SSID_len == bss->SSID_len &&
-				!bcmp(bi->SSID, bss->SSID, bi->SSID_len)) {
-				if ((bss->flags & WLC_BSS_RSSI_ON_CHANNEL) ==
-					(bi->flags & WLC_BSS_RSSI_ON_CHANNEL)) {
-					/* preserve max RSSI if the measurements are
-					 * both on-channel or both off-channel
-					 */
-					bss->RSSI = MAX(bss->RSSI, bi->RSSI);
-				} else if ((bss->flags & WLC_BSS_RSSI_ON_CHANNEL) &&
-					(bi->flags & WLC_BSS_RSSI_ON_CHANNEL) == 0) {
-					/* preserve the on-channel rssi measurement
-					 * if the new measurement is off channel
-					 */
-					bss->RSSI = bi->RSSI;
-					bss->flags |= WLC_BSS_RSSI_ON_CHANNEL;
-				}
-
+		if (wl_get_drv_status_all(wl, SENDING_ACT_FRM)) {
+			p2p_dev_addr = wl_cfgp2p_retreive_p2p_dev_addr(bi, bi_length);
+			if (p2p_dev_addr && !memcmp(p2p_dev_addr,
+				wl->afx_hdl->pending_tx_dst_addr.octet, ETHER_ADDR_LEN)) {
+				s32 channel = CHSPEC_CHANNEL(dtohchanspec(bi->chanspec));
+				WL_DBG(("ACTION FRAME SCAN : Peer found, channel : %d\n", channel));
+				wl_clr_p2p_status(wl, SCANNING);
+				wl->afx_hdl->peer_chan = channel;
+				complete(&wl->act_frm_scan);
 				goto exit;
 			}
+
+		} else {
+			list = (wl_scan_results_t *)wl->escan_info.escan_buf;
+			if (bi_length > ESCAN_BUF_SIZE - list->buflen) {
+				WL_ERR(("Buffer is too small: ignoring\n"));
+				goto exit;
+			}
+#define WLC_BSS_RSSI_ON_CHANNEL 0x0002
+			for (i = 0; i < list->count; i++) {
+				bss = bss ? (wl_bss_info_t *)((uintptr)bss + dtoh32(bss->length))
+					: list->bss_info;
+
+				if (!bcmp(&bi->BSSID, &bss->BSSID, ETHER_ADDR_LEN) &&
+					CHSPEC_BAND(bi->chanspec) == CHSPEC_BAND(bss->chanspec) &&
+					bi->SSID_len == bss->SSID_len &&
+					!bcmp(bi->SSID, bss->SSID, bi->SSID_len)) {
+					if ((bss->flags & WLC_BSS_RSSI_ON_CHANNEL) ==
+						(bi->flags & WLC_BSS_RSSI_ON_CHANNEL)) {
+						/* preserve max RSSI if the measurements are
+						* both on-channel or both off-channel
+						*/
+						bss->RSSI = MAX(bss->RSSI, bi->RSSI);
+					} else if ((bss->flags & WLC_BSS_RSSI_ON_CHANNEL) &&
+						(bi->flags & WLC_BSS_RSSI_ON_CHANNEL) == 0) {
+						/* preserve the on-channel rssi measurement
+						* if the new measurement is off channel
+						*/
+						bss->RSSI = bi->RSSI;
+						bss->flags |= WLC_BSS_RSSI_ON_CHANNEL;
+					}
+
+					goto exit;
+				}
+			}
+			memcpy(&(wl->escan_info.escan_buf[list->buflen]), bi, bi_length);
+			list->version = dtoh32(bi->version);
+			list->buflen += bi_length;
+			list->count++;
+
 		}
-		memcpy(&(wl->escan_info.escan_buf[list->buflen]), bi, bi_length);
-		list->version = dtoh32(bi->version);
-		list->buflen += bi_length;
-		list->count++;
 
 	}
 	else if (status == WLC_E_STATUS_SUCCESS) {
 		wl->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
-		if (likely(wl->scan_request)) {
+		if (wl_get_drv_status_all(wl, SENDING_ACT_FRM)) {
+			WL_INFO(("ACTION FRAME SCAN DONE\n"));
+			wl_clr_p2p_status(wl, SCANNING);
+			wl_clr_drv_status(wl, SCANNING, wl->afx_hdl->dev);
+			if (wl->afx_hdl->peer_chan == WL_INVALID)
+				complete(&wl->act_frm_scan);
+		} else if (likely(wl->scan_request)) {
 			mutex_lock(&wl->usr_sync);
 			del_timer_sync(&wl->scan_timeout);
 			WL_INFO(("ESCAN COMPLETED\n"));
 			wl->bss_list = (wl_scan_results_t *)wl->escan_info.escan_buf;
 			wl_inform_bss(wl);
-			wl_notify_escan_complete(wl, false);
+			wl_notify_escan_complete(wl, ndev, false);
 			mutex_unlock(&wl->usr_sync);
 		}
 	}
 	else if (status == WLC_E_STATUS_ABORT) {
 		wl->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
-		if (likely(wl->scan_request)) {
+		if (wl_get_drv_status_all(wl, SENDING_ACT_FRM)) {
+			WL_INFO(("ACTION FRAME SCAN DONE\n"));
+			wl_clr_drv_status(wl, SCANNING, wl->afx_hdl->dev);
+			wl_clr_p2p_status(wl, SCANNING);
+			if (wl->afx_hdl->peer_chan == WL_INVALID)
+				complete(&wl->act_frm_scan);
+		} else if (likely(wl->scan_request)) {
 			mutex_lock(&wl->usr_sync);
 			del_timer_sync(&wl->scan_timeout);
 			WL_INFO(("ESCAN ABORTED\n"));
 			wl->bss_list = (wl_scan_results_t *)wl->escan_info.escan_buf;
 			wl_inform_bss(wl);
-			wl_notify_escan_complete(wl, true);
+			wl_notify_escan_complete(wl, ndev, true);
 			mutex_unlock(&wl->usr_sync);
 		}
 	}
 	else {
 		WL_ERR(("unexpected Escan Event %d : abort\n", status));
 		wl->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
-		if (likely(wl->scan_request)) {
+		if (wl_get_drv_status_all(wl, SENDING_ACT_FRM)) {
+			WL_INFO(("ACTION FRAME SCAN DONE\n"));
+			wl_clr_p2p_status(wl, SCANNING);
+			wl_clr_drv_status(wl, SCANNING, wl->afx_hdl->dev);
+			if (wl->afx_hdl->peer_chan == WL_INVALID)
+				complete(&wl->act_frm_scan);
+		} else if (likely(wl->scan_request)) {
 			mutex_lock(&wl->usr_sync);
 			del_timer_sync(&wl->scan_timeout);
 			wl->bss_list = (wl_scan_results_t *)wl->escan_info.escan_buf;
 			wl_inform_bss(wl);
-			wl_notify_escan_complete(wl, true);
+			wl_notify_escan_complete(wl, ndev, true);
 			mutex_unlock(&wl->usr_sync);
 		}
 	}
@@ -5491,16 +5958,11 @@
 	return err;
 }
 
-static void wl_init_fw(struct wl_fw_ctrl *fw)
-{
-	fw->status = 0;
-}
-
 static s32 wl_init_priv(struct wl_priv *wl)
 {
 	struct wiphy *wiphy = wl_to_wiphy(wl);
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
 	s32 err = 0;
-	s32 i = 0;
 
 	wl->scan_request = NULL;
 	wl->pwr_save = !!(wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT);
@@ -5509,60 +5971,77 @@
 	wl->roam_on = false;
 	wl->iscan_kickstart = false;
 	wl->active_scan = true;
-	wl->dongle_up = false;
 	wl->rf_blocked = false;
-
-	for (i = 0; i < VWDEV_CNT; i++)
-		wl->vwdev[i] = NULL;
-
-	init_waitqueue_head(&wl->dongle_event_wait);
+	spin_lock_init(&wl->cfgdrv_lock);
+	mutex_init(&wl->ioctl_buf_sync);
+	init_waitqueue_head(&wl->netif_change_event);
 	wl_init_eq(wl);
 	err = wl_init_priv_mem(wl);
-	if (unlikely(err))
+	if (err)
 		return err;
-	if (unlikely(wl_create_event_handler(wl)))
+	if (wl_create_event_handler(wl))
 		return -ENOMEM;
 	wl_init_event_handler(wl);
 	mutex_init(&wl->usr_sync);
 	err = wl_init_scan(wl);
-	if (unlikely(err))
+	if (err)
 		return err;
-	wl_init_fw(wl->fw);
 	wl_init_conf(wl->conf);
-	wl_init_prof(wl);
+	wl_init_prof(wl, ndev);
 	wl_link_down(wl);
+	DNGL_FUNC(dhd_cfg80211_init, (wl));
 
 	return err;
 }
 
 static void wl_deinit_priv(struct wl_priv *wl)
 {
+	DNGL_FUNC(dhd_cfg80211_deinit, (wl));
 	wl_destroy_event_handler(wl);
-	wl->dongle_up = false;	/* dongle down */
 	wl_flush_eq(wl);
 	wl_link_down(wl);
 	del_timer_sync(&wl->scan_timeout);
 	wl_term_iscan(wl);
 	wl_deinit_priv_mem(wl);
+	unregister_netdevice_notifier(&wl_cfg80211_netdev_notifier);
 }
 
-#if defined(DHD_P2P_DEV_ADDR_FROM_SYSFS) && defined(CONFIG_SYSCTL)
-s32 wl_cfg80211_sysctl_export_devaddr(void *data)
+#if defined(WLP2P) && ENABLE_P2P_INTERFACE
+static s32 wl_cfg80211_attach_p2p(void)
 {
-	/* Export the p2p_dev_addr via sysctl interface
-	 * so that wpa_supplicant can access it
-	 */
-	dhd_pub_t *dhd = (dhd_pub_t *)data;
 	struct wl_priv *wl = wlcfg_drv_priv;
 
-	wl_cfgp2p_generate_bss_mac(&dhd->mac, &wl->p2p->dev_addr, &wl->p2p->int_addr);
+	WL_TRACE(("Enter \n"));
 
-	sprintf((char *)&wl_sysctl_macstring[0], MACSTR, MAC2STR(wl->p2p->dev_addr.octet));
-	sprintf((char *)&wl_sysctl_macstring[1], MACSTR, MAC2STR(wl->p2p->int_addr.octet));
+	if (wl_cfgp2p_register_ndev(wl) < 0) {
+		WL_ERR(("%s: P2P attach failed. \n", __func__));
+		return -ENODEV;
+	}
 
 	return 0;
 }
-#endif /* CONFIG_SYSCTL */
+
+static s32  wl_cfg80211_detach_p2p(void)
+{
+	struct wl_priv *wl = wlcfg_drv_priv;
+	struct wireless_dev *wdev = wl->p2p_wdev;
+
+	WL_DBG(("Enter \n"));
+	if (!wdev || !wl) {
+		WL_ERR(("Invalid Ptr\n"));
+		return -EINVAL;
+	}
+
+	wl_cfgp2p_unregister_ndev(wl);
+
+	wl->p2p_wdev = NULL;
+	wl->p2p_net = NULL;
+	WL_DBG(("Freeing 0x%08x \n", (unsigned int)wdev));
+	kfree(wdev);
+
+	return 0;
+}
+#endif /* defined(WLP2P) && (ENABLE_P2P_INTERFACE) */
 
 s32 wl_cfg80211_attach_post(struct net_device *ndev)
 {
@@ -5574,7 +6053,7 @@
 		return -ENODEV;
 	}
 	wl = wlcfg_drv_priv;
-	if (wl && !wl_get_drv_status(wl, READY)) {
+	if (wl && !wl_get_drv_status(wl, READY, ndev)) {
 			if (wl->wdev &&
 				wl_cfgp2p_supported(wl, ndev)) {
 				wl->wdev->wiphy->interface_modes |=
@@ -5582,67 +6061,90 @@
 					BIT(NL80211_IFTYPE_P2P_GO));
 				if ((err = wl_cfgp2p_init_priv(wl)) != 0)
 					goto fail;
-#if defined(DHD_P2P_DEV_ADDR_FROM_SYSFS) && defined(CONFIG_SYSCTL)
-				wl_cfg80211_sysctl_export_devaddr(wl->pub);
-#endif
+
+#if defined(WLP2P) && ENABLE_P2P_INTERFACE
+				if (wl->p2p_net) {
+					/* Update MAC addr for p2p0 interface here. */
+					memcpy(wl->p2p_net->dev_addr, ndev->dev_addr, ETH_ALEN);
+					wl->p2p_net->dev_addr[0] |= 0x02;
+					printk("%s: p2p_dev_addr="MACSTR "\n",
+						wl->p2p_net->name, MAC2STR(wl->p2p_net->dev_addr));
+				} else {
+					WL_ERR(("p2p_net not yet populated."
+					" Couldn't update the MAC Address for p2p0 \n"));
+					return -ENODEV;
+				}
+#endif /* defined(WLP2P) && (ENABLE_P2P_INTERFACE) */
+
 				wl->p2p_supported = true;
 			}
 	} else
 		return -ENODEV;
-
-	wl_set_drv_status(wl, READY);
+	wl_set_drv_status(wl, READY, ndev);
 fail:
 	return err;
 }
+
 s32 wl_cfg80211_attach(struct net_device *ndev, void *data)
 {
 	struct wireless_dev *wdev;
 	struct wl_priv *wl;
 	s32 err = 0;
+	struct device *dev;
 
 	WL_TRACE(("In\n"));
-	if (unlikely(!ndev)) {
+	if (!ndev) {
 		WL_ERR(("ndev is invaild\n"));
 		return -ENODEV;
 	}
-	WL_DBG(("func %p\n", wl_cfg80211_get_sdio_func()));
-	wdev = wl_alloc_wdev(&wl_cfg80211_get_sdio_func()->dev);
-	if (unlikely(IS_ERR(wdev)))
+	WL_DBG(("func %p\n", wl_cfg80211_get_parent_dev()));
+	dev = wl_cfg80211_get_parent_dev();
+	wdev = wl_alloc_wdev(dev);
+	if (IS_ERR(wdev))
 		return -ENOMEM;
 
 	wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS);
 	wl = (struct wl_priv *)wiphy_priv(wdev->wiphy);
 	wl->wdev = wdev;
 	wl->pub = data;
-
+	INIT_LIST_HEAD(&wl->net_list);
 	ndev->ieee80211_ptr = wdev;
 	SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
 	wdev->netdev = ndev;
-
+	err = wl_alloc_netinfo(wl, ndev, wdev, WL_MODE_BSS);
+	if (err) {
+		WL_ERR(("Failed to alloc net_info (%d)\n", err));
+		goto cfg80211_attach_out;
+	}
 	err = wl_init_priv(wl);
-	if (unlikely(err)) {
+	if (err) {
 		WL_ERR(("Failed to init iwm_priv (%d)\n", err));
 		goto cfg80211_attach_out;
 	}
 
 	err = wl_setup_rfkill(wl, TRUE);
-	if (unlikely(err)) {
+	if (err) {
 		WL_ERR(("Failed to setup rfkill %d\n", err));
 		goto cfg80211_attach_out;
 	}
-
-#if defined(DHD_P2P_DEV_ADDR_FROM_SYSFS) && defined(CONFIG_SYSCTL)
-	if (!(wl_sysctl_hdr = register_sysctl_table(wl_sysctl_table))) {
-		WL_ERR(("%s: sysctl register failed!! \n", __func__));
+	err = register_netdevice_notifier(&wl_cfg80211_netdev_notifier);
+	if (err) {
+		WL_ERR(("Failed to register notifierl %d\n", err));
 		goto cfg80211_attach_out;
 	}
-#endif
 #if defined(COEX_DHCP)
 	if (wl_cfg80211_btcoex_init(wl))
 		goto cfg80211_attach_out;
-#endif /* COEX_DHCP */
+#endif
 
 	wlcfg_drv_priv = wl;
+
+#if defined(WLP2P) && ENABLE_P2P_INTERFACE
+	err = wl_cfg80211_attach_p2p();
+	if (err)
+		goto cfg80211_attach_out;
+#endif
+
 	return err;
 
 cfg80211_attach_out:
@@ -5651,29 +6153,32 @@
 	return err;
 }
 
-void wl_cfg80211_detach(void)
+void wl_cfg80211_detach(void *para)
 {
 	struct wl_priv *wl;
 
+	(void)para;
 	wl = wlcfg_drv_priv;
 
 	WL_TRACE(("In\n"));
 
 #if defined(COEX_DHCP)
 	wl_cfg80211_btcoex_deinit(wl);
-#endif /* COEX_DHCP */
+#endif
 
-#if defined(DHD_P2P_DEV_ADDR_FROM_SYSFS) && defined(CONFIG_SYSCTL)
-	if (wl_sysctl_hdr)
-		unregister_sysctl_table(wl_sysctl_hdr);
+#if defined(WLP2P) && ENABLE_P2P_INTERFACE
+	wl_cfg80211_detach_p2p();
 #endif
 	wl_setup_rfkill(wl, FALSE);
 	if (wl->p2p_supported)
 		wl_cfgp2p_deinit_priv(wl);
 	wl_deinit_priv(wl);
 	wlcfg_drv_priv = NULL;
-	wl_clear_sdio_func();
+	wl_cfg80211_clear_parent_dev();
 	wl_free_wdev(wl);
+	 /* PLEASE do NOT call any function after wl_free_wdev, the driver's private structure "wl",
+	  * which is the private part of wiphy, has been freed in wl_free_wdev !!!!!!!!!!!
+	  */
 }
 
 static void wl_wakeup_event(struct wl_priv *wl)
@@ -5684,6 +6189,42 @@
 	}
 }
 
+static int wl_is_p2p_event(struct wl_event_q *e)
+{
+	switch (e->etype) {
+	/* We have to seperate out the P2P events received
+	 * on primary interface so that it can be send up
+	 * via p2p0 interface.
+	*/
+	case WLC_E_P2P_PROBREQ_MSG:
+	case WLC_E_P2P_DISC_LISTEN_COMPLETE:
+	case WLC_E_ACTION_FRAME_RX:
+	case WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE:
+	case WLC_E_ACTION_FRAME_COMPLETE:
+
+		if (e->emsg.ifidx != 0) {
+			WL_TRACE(("P2P Event on Virtual I/F (ifidx:%d) \n",
+			e->emsg.ifidx));
+			/* We are only bothered about the P2P events received
+			 * on primary interface. For rest of them return false
+			 * so that it is sent over the interface corresponding
+			 * to the ifidx.
+			 */
+			return FALSE;
+		} else {
+			WL_TRACE(("P2P Event on Primary I/F (ifidx:%d)."
+				" Sent it to p2p0 \n", e->emsg.ifidx));
+			return TRUE;
+		}
+		break;
+
+	default:
+		WL_TRACE(("NON-P2P Event %d on ifidx (ifidx:%d) \n",
+			e->etype, e->emsg.ifidx));
+		return FALSE;
+	}
+}
+
 static s32 wl_event_handler(void *data)
 {
 	struct net_device *netdev;
@@ -5700,7 +6241,15 @@
 			break;
 		while ((e = wl_deq_event(wl))) {
 			WL_DBG(("event type (%d), if idx: %d\n", e->etype, e->emsg.ifidx));
-			netdev = dhd_idx2net((struct dhd_pub *)(wl->pub), e->emsg.ifidx);
+			/* All P2P device address related events comes on primary interface since
+			 * there is no corresponding bsscfg for P2P interface. Map it to p2p0
+			 * interface.
+			 */
+			if ((wl_is_p2p_event(e) == TRUE) && (wl->p2p_net)) {
+				netdev = wl->p2p_net;
+			} else {
+				netdev = dhd_idx2net((struct dhd_pub *)(wl->pub), e->emsg.ifidx);
+			}
 			if (!netdev)
 				netdev = wl_to_prmry_ndev(wl);
 			if (e->etype < WLC_E_LAST && wl->evt_handler[e->etype]) {
@@ -5816,22 +6365,7 @@
 	kfree(e);
 }
 
-void wl_cfg80211_set_sdio_func(void *func)
-{
-	cfg80211_sdio_func = (struct sdio_func *)func;
-}
-
-static void wl_clear_sdio_func(void)
-{
-	cfg80211_sdio_func = NULL;
-}
-
-struct sdio_func *wl_cfg80211_get_sdio_func(void)
-{
-	return cfg80211_sdio_func;
-}
-
-static s32 wl_dongle_mode(struct wl_priv *wl, struct net_device *ndev, s32 iftype)
+static s32 wl_config_ifmode(struct wl_priv *wl, struct net_device *ndev, s32 iftype)
 {
 	s32 infra = 0;
 	s32 err = 0;
@@ -5868,11 +6402,12 @@
 		return err;
 	}
 
-	set_mode_by_netdev(wl, ndev, mode);
+	wl_set_mode_by_netdev(wl, ndev, mode);
 
 	return 0;
 }
-static s32 wl_dongle_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add)
+
+static s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add)
 {
 	s8 iovbuf[WL_EVENTING_MASK_LEN + 12];
 
@@ -5885,7 +6420,7 @@
 	err = wldev_ioctl(ndev, WLC_GET_VAR, iovbuf, sizeof(iovbuf), false);
 	if (unlikely(err)) {
 		WL_ERR(("Get event_msgs error (%d)\n", err));
-		goto dongle_eventmsg_out;
+		goto eventmsg_out;
 	}
 	memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN);
 	if (add) {
@@ -5898,353 +6433,15 @@
 	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
 	if (unlikely(err)) {
 		WL_ERR(("Set event_msgs error (%d)\n", err));
-		goto dongle_eventmsg_out;
+		goto eventmsg_out;
 	}
 
-dongle_eventmsg_out:
+eventmsg_out:
 	return err;
 
 }
 
-
-#ifndef EMBEDDED_PLATFORM
-static s32 wl_dongle_country(struct net_device *ndev, u8 ccode)
-{
-
-	s32 err = 0;
-
-	return err;
-}
-
-static s32 wl_dongle_up(struct net_device *ndev, u32 up)
-{
-	s32 err = 0;
-
-	err = wldev_ioctl(ndev, WLC_UP, &up, sizeof(up), true);
-	if (unlikely(err)) {
-		WL_ERR(("WLC_UP error (%d)\n", err));
-	}
-	return err;
-}
-
-static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode)
-{
-	s32 err = 0;
-
-	WL_TRACE(("In\n"));
-	err = wldev_ioctl(ndev, WLC_SET_PM, &power_mode, sizeof(power_mode), true);
-	if (unlikely(err)) {
-		WL_ERR(("WLC_SET_PM error (%d)\n", err));
-	}
-	return err;
-}
-
-static s32
-wl_dongle_glom(struct net_device *ndev, u32 glom, u32 dongle_align)
-{
-	s8 iovbuf[WL_EVENTING_MASK_LEN + 12];
-
-	s32 err = 0;
-
-	/* Match Host and Dongle rx alignment */
-	bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
-		sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (unlikely(err)) {
-		WL_ERR(("txglomalign error (%d)\n", err));
-		goto dongle_glom_out;
-	}
-	/* disable glom option per default */
-	bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (unlikely(err)) {
-		WL_ERR(("txglom error (%d)\n", err));
-		goto dongle_glom_out;
-	}
-dongle_glom_out:
-	return err;
-}
-
-static s32
-wl_dongle_roam(struct net_device *ndev, u32 roamvar, u32 bcn_timeout)
-{
-	s8 iovbuf[WL_EVENTING_MASK_LEN + 12];
-
-	s32 err = 0;
-
-	/* Setup timeout if Beacons are lost and roam is off to report link down */
-	if (roamvar) {
-		bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
-			sizeof(iovbuf));
-		err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-		if (unlikely(err)) {
-			WL_ERR(("bcn_timeout error (%d)\n", err));
-			goto dongle_rom_out;
-		}
-	}
-	/* Enable/Disable built-in roaming to allow supplicant to take care of roaming */
-	bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (unlikely(err)) {
-		WL_ERR(("roam_off error (%d)\n", err));
-		goto dongle_rom_out;
-	}
-dongle_rom_out:
-	return err;
-}
-
-static s32
-wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
-	s32 scan_unassoc_time)
-{
-	s32 err = 0;
-
-	err = wldev_ioctl(ndev, WLC_SET_SCAN_CHANNEL_TIME, &scan_assoc_time,
-		sizeof(scan_assoc_time), true);
-	if (err) {
-		if (err == -EOPNOTSUPP) {
-			WL_INFO(("Scan assoc time is not supported\n"));
-		} else {
-			WL_ERR(("Scan assoc time error (%d)\n", err));
-		}
-		goto dongle_scantime_out;
-	}
-	err = wldev_ioctl(ndev, WLC_SET_SCAN_UNASSOC_TIME, &scan_unassoc_time,
-		sizeof(scan_unassoc_time), true);
-	if (err) {
-		if (err == -EOPNOTSUPP) {
-			WL_INFO(("Scan unassoc time is not supported\n"));
-		} else {
-			WL_ERR(("Scan unassoc time error (%d)\n", err));
-		}
-		goto dongle_scantime_out;
-	}
-
-dongle_scantime_out:
-	return err;
-}
-
-static s32
-wl_dongle_offload(struct net_device *ndev, s32 arpoe, s32 arp_ol)
-{
-	/* Room for "event_msgs" + '\0' + bitvec */
-	s8 iovbuf[WL_EVENTING_MASK_LEN + 12];
-
-	s32 err = 0;
-
-	/* Set ARP offload */
-	bcm_mkiovar("arpoe", (char *)&arpoe, 4, iovbuf, sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (err) {
-		if (err == -EOPNOTSUPP)
-			WL_INFO(("arpoe is not supported\n"));
-		else
-			WL_ERR(("arpoe error (%d)\n", err));
-
-		goto dongle_offload_out;
-	}
-	bcm_mkiovar("arp_ol", (char *)&arp_ol, 4, iovbuf, sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (err) {
-		if (err == -EOPNOTSUPP)
-			WL_INFO(("arp_ol is not supported\n"));
-		else
-			WL_ERR(("arp_ol error (%d)\n", err));
-
-		goto dongle_offload_out;
-	}
-
-dongle_offload_out:
-	return err;
-}
-
-static s32 wl_pattern_atoh(s8 *src, s8 *dst)
-{
-	int i;
-	if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
-		WL_ERR(("Mask invalid format. Needs to start with 0x\n"));
-		return -1;
-	}
-	src = src + 2;		/* Skip past 0x */
-	if (strlen(src) % 2 != 0) {
-		WL_ERR(("Mask invalid format. Needs to be of even length\n"));
-		return -1;
-	}
-	for (i = 0; *src != '\0'; i++) {
-		char num[3];
-		strncpy(num, src, 2);
-		num[2] = '\0';
-		dst[i] = (u8) simple_strtoul(num, NULL, 16);
-		src += 2;
-	}
-	return i;
-}
-
-static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
-{
-	/* Room for "event_msgs" + '\0' + bitvec */
-	s8 iovbuf[WL_EVENTING_MASK_LEN + 12];
-
-	const s8 *str;
-	struct wl_pkt_filter pkt_filter;
-	struct wl_pkt_filter *pkt_filterp;
-	s32 buf_len;
-	s32 str_len;
-	u32 mask_size;
-	u32 pattern_size;
-	s8 buf[256];
-	s32 err = 0;
-
-	/* add a default packet filter pattern */
-	str = "pkt_filter_add";
-	str_len = strlen(str);
-	strncpy(buf, str, str_len);
-	buf[str_len] = '\0';
-	buf_len = str_len + 1;
-
-	pkt_filterp = (struct wl_pkt_filter *)(buf + str_len + 1);
-
-	/* Parse packet filter id. */
-	pkt_filter.id = htod32(100);
-
-	/* Parse filter polarity. */
-	pkt_filter.negate_match = htod32(0);
-
-	/* Parse filter type. */
-	pkt_filter.type = htod32(0);
-
-	/* Parse pattern filter offset. */
-	pkt_filter.u.pattern.offset = htod32(0);
-
-	/* Parse pattern filter mask. */
-	mask_size = htod32(wl_pattern_atoh("0xff",
-		(char *)pkt_filterp->u.pattern.
-		    mask_and_pattern));
-
-	/* Parse pattern filter pattern. */
-	pattern_size = htod32(wl_pattern_atoh("0x00",
-		(char *)&pkt_filterp->u.pattern.mask_and_pattern[mask_size]));
-
-	if (mask_size != pattern_size) {
-		WL_ERR(("Mask and pattern not the same size\n"));
-		err = -EINVAL;
-		goto dongle_filter_out;
-	}
-
-	pkt_filter.u.pattern.size_bytes = mask_size;
-	buf_len += WL_PKT_FILTER_FIXED_LEN;
-	buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
-
-	/* Keep-alive attributes are set in local
-	 * variable (keep_alive_pkt), and
-	 * then memcpy'ed into buffer (keep_alive_pktp) since there is no
-	 * guarantee that the buffer is properly aligned.
-	 */
-	memcpy((char *)pkt_filterp, &pkt_filter,
-		WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
-
-	err = wldev_ioctl(ndev, WLC_SET_VAR, buf, buf_len, true);
-	if (err) {
-		if (err == -EOPNOTSUPP) {
-			WL_INFO(("filter not supported\n"));
-		} else {
-			WL_ERR(("filter (%d)\n", err));
-		}
-		goto dongle_filter_out;
-	}
-
-	/* set mode to allow pattern */
-	bcm_mkiovar("pkt_filter_mode", (char *)&filter_mode, 4, iovbuf,
-		sizeof(iovbuf));
-	err = wldev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf), true);
-	if (err) {
-		if (err == -EOPNOTSUPP) {
-			WL_INFO(("filter_mode not supported\n"));
-		} else {
-			WL_ERR(("filter_mode (%d)\n", err));
-		}
-		goto dongle_filter_out;
-	}
-
-dongle_filter_out:
-	return err;
-}
-#endif				/* !EMBEDDED_PLATFORM */
-
-s32 wl_config_dongle(struct wl_priv *wl, bool need_lock)
-{
-#ifndef DHD_SDALIGN
-#define DHD_SDALIGN	32
-#endif
-	struct net_device *ndev;
-	struct wireless_dev *wdev;
-	s32 err = 0;
-
-	WL_TRACE(("In\n"));
-	if (wl->dongle_up) {
-		WL_ERR(("Dongle is already up\n"));
-		return err;
-	}
-
-	ndev = wl_to_prmry_ndev(wl);
-	wdev = ndev->ieee80211_ptr;
-	if (need_lock)
-		rtnl_lock();
-#ifndef EMBEDDED_PLATFORM
-	err = wl_dongle_up(ndev, 0);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_up failed\n"));
-		goto default_conf_out;
-	}
-	err = wl_dongle_country(ndev, 0);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_country failed\n"));
-		goto default_conf_out;
-	}
-	err = wl_dongle_power(ndev, PM_FAST);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_power failed\n"));
-		goto default_conf_out;
-	}
-	err = wl_dongle_glom(ndev, 0, DHD_SDALIGN);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_glom failed\n"));
-		goto default_conf_out;
-	}
-	err = wl_dongle_roam(ndev, (wl->roam_on ? 0 : 1), 3);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_roam failed\n"));
-		goto default_conf_out;
-	}
-	wl_dongle_scantime(ndev, 40, 80);
-	wl_dongle_offload(ndev, 1, 0xf);
-	wl_dongle_filter(ndev, 1);
-#endif				/* !EMBEDDED_PLATFORM */
-
-	err = wl_dongle_mode(wl, ndev, wdev->iftype);
-	if (unlikely(err && err != -EINPROGRESS)) {
-		WL_ERR(("wl_dongle_mode failed\n"));
-		goto default_conf_out;
-	}
-	err = wl_dongle_probecap(wl);
-	if (unlikely(err)) {
-		WL_ERR(("wl_dongle_probecap failed\n"));
-		goto default_conf_out;
-	}
-
-	/* -EINPROGRESS: Call commit handler */
-
-default_conf_out:
-	if (need_lock)
-		rtnl_unlock();
-
-	wl->dongle_up = true;
-
-	return err;
-
-}
-
-static s32 wl_update_wiphybands(struct wl_priv *wl)
+s32 wl_update_wiphybands(struct wl_priv *wl)
 {
 	struct wiphy *wiphy;
 	s8 phylist_buf[128];
@@ -6271,16 +6468,27 @@
 static s32 __wl_cfg80211_up(struct wl_priv *wl)
 {
 	s32 err = 0;
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
+	struct wireless_dev *wdev = ndev->ieee80211_ptr;
 
 	WL_TRACE(("In\n"));
-	wl_debugfs_add_netdev_params(wl);
 
-	err = wl_config_dongle(wl, false);
+	err = dhd_config_dongle(wl, false);
 	if (unlikely(err))
 		return err;
-	dhd_monitor_init(wl->pub);
-	wl_invoke_iscan(wl);
-	wl_set_drv_status(wl, READY);
+
+	err = wl_config_ifmode(wl, ndev, wdev->iftype);
+	if (unlikely(err && err != -EINPROGRESS)) {
+		WL_ERR(("wl_config_ifmode failed\n"));
+	}
+	err = wl_update_wiphybands(wl);
+	if (unlikely(err)) {
+		WL_ERR(("wl_update_wiphybands failed\n"));
+	}
+
+	err = dhd_monitor_init(wl->pub);
+	err = wl_invoke_iscan(wl);
+	wl_set_drv_status(wl, READY, ndev);
 	return err;
 }
 
@@ -6288,51 +6496,52 @@
 {
 	s32 err = 0;
 	unsigned long flags;
+	struct net_info *iter, *next;
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
 
 	WL_TRACE(("In\n"));
 	/* Check if cfg80211 interface is already down */
-	if (!wl_get_drv_status(wl, READY))
+	if (!wl_get_drv_status(wl, READY, ndev))
 		return err;	/* it is even not ready */
-
-	wl_set_drv_status(wl, SCAN_ABORTING);
+	for_each_ndev(wl, iter, next)
+		wl_set_drv_status(wl, SCAN_ABORTING, iter->ndev);
 
 	wl_term_iscan(wl);
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	if (wl->scan_request) {
 		cfg80211_scan_done(wl->scan_request, true);
 		wl->scan_request = NULL;
 	}
-	wl_clr_drv_status(wl, READY);
-	wl_clr_drv_status(wl, SCANNING);
-	wl_clr_drv_status(wl, SCAN_ABORTING);
-	wl_clr_drv_status(wl, CONNECTING);
-	wl_clr_drv_status(wl, CONNECTED);
-	wl_clr_drv_status(wl, DISCONNECTING);
-	if (wl_get_drv_status(wl, AP_CREATED)) {
-		wl_clr_drv_status(wl, AP_CREATED);
-		wl_clr_drv_status(wl, AP_CREATING);
+	for_each_ndev(wl, iter, next) {
+		wl_clr_drv_status(wl, READY, iter->ndev);
+		wl_clr_drv_status(wl, SCANNING, iter->ndev);
+		wl_clr_drv_status(wl, SCAN_ABORTING, iter->ndev);
+		wl_clr_drv_status(wl, CONNECTING, iter->ndev);
+		wl_clr_drv_status(wl, CONNECTED, iter->ndev);
+		wl_clr_drv_status(wl, DISCONNECTING, iter->ndev);
+		wl_clr_drv_status(wl, AP_CREATED, iter->ndev);
+		wl_clr_drv_status(wl, AP_CREATING, iter->ndev);
 	}
 	wl_to_prmry_ndev(wl)->ieee80211_ptr->iftype =
 		NL80211_IFTYPE_STATION;
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 
-	wl->dongle_up = false;
+	DNGL_FUNC(dhd_cfg80211_down, (wl));
 	wl_flush_eq(wl);
 	wl_link_down(wl);
 	if (wl->p2p_supported)
 		wl_cfgp2p_down(wl);
 	dhd_monitor_uninit();
 
-	wl_debugfs_remove_netdev(wl);
-
 	return err;
 }
 
-s32 wl_cfg80211_up(void)
+s32 wl_cfg80211_up(void *para)
 {
 	struct wl_priv *wl;
 	s32 err = 0;
 
+	(void)para;
 	WL_TRACE(("In\n"));
 	wl = wlcfg_drv_priv;
 	mutex_lock(&wl->usr_sync);
@@ -6345,13 +6554,13 @@
 	return err;
 }
 
-/* Private Event  to Supplicant with indication that FW hangs */
+/* Private Event to Supplicant with indication that chip hangs */
 int wl_cfg80211_hang(struct net_device *dev, u16 reason)
 {
 	struct wl_priv *wl;
 	wl = wlcfg_drv_priv;
 
-	WL_ERR(("In : FW crash Eventing\n"));
+	WL_ERR(("In : chip crash eventing\n"));
 	cfg80211_disconnected(dev, reason, NULL, 0, GFP_KERNEL);
 	if (wl != NULL) {
 		wl_link_down(wl);
@@ -6359,11 +6568,12 @@
 	return 0;
 }
 
-s32 wl_cfg80211_down(void)
+s32 wl_cfg80211_down(void *para)
 {
 	struct wl_priv *wl;
 	s32 err = 0;
 
+	(void)para;
 	WL_TRACE(("In\n"));
 	wl = wlcfg_drv_priv;
 	mutex_lock(&wl->usr_sync);
@@ -6373,84 +6583,79 @@
 	return err;
 }
 
-static s32 wl_dongle_probecap(struct wl_priv *wl)
-{
-	s32 err = 0;
-
-	err = wl_update_wiphybands(wl);
-	if (unlikely(err))
-		return err;
-
-	return err;
-}
-
-static void *wl_read_prof(struct wl_priv *wl, s32 item)
+static void *wl_read_prof(struct wl_priv *wl, struct net_device *ndev, s32 item)
 {
 	unsigned long flags;
 	void *rptr = NULL;
+	struct wl_profile *profile = wl_get_profile_by_netdev(wl, ndev);
 
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	if (!profile)
+		return NULL;
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	switch (item) {
 	case WL_PROF_SEC:
-		rptr = &wl->profile->sec;
+		rptr = &profile->sec;
 		break;
 	case WL_PROF_ACT:
-		rptr = &wl->profile->active;
+		rptr = &profile->active;
 		break;
 	case WL_PROF_BSSID:
-		rptr = &wl->profile->bssid;
+		rptr = profile->bssid;
 		break;
 	case WL_PROF_SSID:
-		rptr = &wl->profile->ssid;
+		rptr = &profile->ssid;
 		break;
 	}
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 	if (!rptr)
 		WL_ERR(("invalid item (%d)\n", item));
 	return rptr;
 }
 
 static s32
-wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e, void *data,
-	s32 item)
+wl_update_prof(struct wl_priv *wl, struct net_device *ndev,
+	const wl_event_msg_t *e, void *data, s32 item)
 {
 	s32 err = 0;
 	struct wlc_ssid *ssid;
 	unsigned long flags;
+	struct wl_profile *profile = wl_get_profile_by_netdev(wl, ndev);
 
-	flags = dhd_os_spin_lock((dhd_pub_t *)(wl->pub));
+	if (!profile)
+		return WL_INVALID;
+	spin_lock_irqsave(&wl->cfgdrv_lock, flags);
 	switch (item) {
 	case WL_PROF_SSID:
 		ssid = (wlc_ssid_t *) data;
-		memset(wl->profile->ssid.SSID, 0,
-			sizeof(wl->profile->ssid.SSID));
-		memcpy(wl->profile->ssid.SSID, ssid->SSID, ssid->SSID_len);
-		wl->profile->ssid.SSID_len = ssid->SSID_len;
+		memset(profile->ssid.SSID, 0,
+			sizeof(profile->ssid.SSID));
+		memcpy(profile->ssid.SSID, ssid->SSID, ssid->SSID_len);
+		profile->ssid.SSID_len = ssid->SSID_len;
 		break;
 	case WL_PROF_BSSID:
 		if (data)
-			memcpy(wl->profile->bssid, data, ETHER_ADDR_LEN);
+			memcpy(profile->bssid, data, ETHER_ADDR_LEN);
 		else
-			memset(wl->profile->bssid, 0, ETHER_ADDR_LEN);
+			memset(profile->bssid, 0, ETHER_ADDR_LEN);
 		break;
 	case WL_PROF_SEC:
-		memcpy(&wl->profile->sec, data, sizeof(wl->profile->sec));
+		memcpy(&profile->sec, data, sizeof(profile->sec));
 		break;
 	case WL_PROF_ACT:
-		wl->profile->active = *(bool *)data;
+		profile->active = *(bool *)data;
 		break;
 	case WL_PROF_BEACONINT:
-		wl->profile->beacon_interval = *(u16 *)data;
+		profile->beacon_interval = *(u16 *)data;
 		break;
 	case WL_PROF_DTIMPERIOD:
-		wl->profile->dtim_period = *(u8 *)data;
+		profile->dtim_period = *(u8 *)data;
 		break;
 	default:
 		WL_ERR(("unsupported item (%d)\n", item));
 		err = -EOPNOTSUPP;
 		break;
 	}
-	dhd_os_spin_unlock((dhd_pub_t *)(wl->pub), flags);
+	spin_unlock_irqrestore(&wl->cfgdrv_lock, flags);
 	return err;
 }
 
@@ -6467,7 +6672,7 @@
 
 static bool wl_is_ibssmode(struct wl_priv *wl, struct net_device *ndev)
 {
-	return get_mode_by_netdev(wl, ndev) == WL_MODE_IBSS;
+	return wl_get_mode_by_netdev(wl, ndev) == WL_MODE_IBSS;
 }
 
 static __used bool wl_is_ibssstarter(struct wl_priv *wl)
@@ -6578,114 +6783,22 @@
 	}
 }
 
-s32 wl_cfg80211_read_fw(s8 *buf, u32 size)
-{
-	const struct firmware *fw_entry;
-	struct wl_priv *wl;
-
-	wl = wlcfg_drv_priv;
-
-	fw_entry = wl->fw->fw_entry;
-
-	if (fw_entry->size < wl->fw->ptr + size)
-		size = fw_entry->size - wl->fw->ptr;
-
-	memcpy(buf, &fw_entry->data[wl->fw->ptr], size);
-	wl->fw->ptr += size;
-	return size;
-}
-
-void wl_cfg80211_release_fw(void)
-{
-	struct wl_priv *wl;
-
-	wl = wlcfg_drv_priv;
-	release_firmware(wl->fw->fw_entry);
-	wl->fw->ptr = 0;
-}
-
-void *wl_cfg80211_request_fw(s8 *file_name)
-{
-	struct wl_priv *wl;
-	const struct firmware *fw_entry = NULL;
-	s32 err = 0;
-
-	WL_TRACE(("In\n"));
-	WL_DBG(("file name : \"%s\"\n", file_name));
-	wl = wlcfg_drv_priv;
-
-	if (!test_bit(WL_FW_LOADING_DONE, &wl->fw->status)) {
-		err = request_firmware(&wl->fw->fw_entry, file_name,
-			&wl_cfg80211_get_sdio_func()->dev);
-		if (unlikely(err)) {
-			WL_ERR(("Could not download fw (%d)\n", err));
-			goto req_fw_out;
-		}
-		set_bit(WL_FW_LOADING_DONE, &wl->fw->status);
-		fw_entry = wl->fw->fw_entry;
-		if (fw_entry) {
-			WL_DBG(("fw size (%zd), data (%p)\n", fw_entry->size,
-				fw_entry->data));
-		}
-	} else if (!test_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status)) {
-		err = request_firmware(&wl->fw->fw_entry, file_name,
-			&wl_cfg80211_get_sdio_func()->dev);
-		if (unlikely(err)) {
-			WL_ERR(("Could not download nvram (%d)\n", err));
-			goto req_fw_out;
-		}
-		set_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status);
-		fw_entry = wl->fw->fw_entry;
-		if (fw_entry) {
-			WL_DBG(("nvram size (%zd), data (%p)\n", fw_entry->size,
-				fw_entry->data));
-		}
-	} else {
-		WL_DBG(("Downloading already done. Nothing to do more\n"));
-		err = -EPERM;
-	}
-
-req_fw_out:
-	if (unlikely(err)) {
-		return NULL;
-	}
-	wl->fw->ptr = 0;
-	return (void *)fw_entry->data;
-}
-
-s8 *wl_cfg80211_get_fwname(void)
-{
-	struct wl_priv *wl;
-
-	wl = wlcfg_drv_priv;
-	strcpy(wl->fw->fw_name, WL_4329_FW_FILE);
-	return wl->fw->fw_name;
-}
-
-s8 *wl_cfg80211_get_nvramname(void)
-{
-	struct wl_priv *wl;
-
-	wl = wlcfg_drv_priv;
-	strcpy(wl->fw->nvram_name, WL_4329_NVRAM_FILE);
-	return wl->fw->nvram_name;
-}
-
 s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr)
 {
 	struct wl_priv *wl;
-	dhd_pub_t *dhd_pub;
 	struct ether_addr p2pif_addr;
+	struct ether_addr primary_mac;
 
 	wl = wlcfg_drv_priv;
-	dhd_pub = (dhd_pub_t *)wl->pub;
-	wl_cfgp2p_generate_bss_mac(&dhd_pub->mac, p2pdev_addr, &p2pif_addr);
+	get_primary_mac(wl, &primary_mac);
+	wl_cfgp2p_generate_bss_mac(&primary_mac, p2pdev_addr, &p2pif_addr);
 
 	return 0;
 }
 s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len)
 {
 	struct wl_priv *wl;
+
 	wl = wlcfg_drv_priv;
 
 	return wl_cfgp2p_set_p2p_noa(wl, net, buf, len);
@@ -6719,8 +6832,8 @@
 	if (wl->p2p && wl->p2p->vif_created) {
 		ndev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION);
 		bssidx = wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_CONNECTION);
-	} else if (wl_get_drv_status(wl, AP_CREATING) ||
-		wl_get_drv_status(wl, AP_CREATED)) {
+	} else if (wl_get_drv_status(wl, AP_CREATING, net) ||
+		wl_get_drv_status(wl, AP_CREATED, net)) {
 		ndev = net;
 		bssidx = 0;
 	}
@@ -6743,69 +6856,6 @@
 	return ret;
 }
 
-static __used void wl_dongle_poweron(struct wl_priv *wl)
-{
-	WL_DBG(("Enter \n"));
-	dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON);
-
-#if defined(BCMLXSDMMC)
-	sdioh_start(NULL, 0);
-#endif
-#if defined(BCMLXSDMMC)
-	sdioh_start(NULL, 1);
-#endif
-	wl_cfg80211_resume(wl_to_wiphy(wl));
-}
-
-static __used void wl_dongle_poweroff(struct wl_priv *wl)
-{
-	WL_DBG(("Enter \n"));
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)
-	wl_cfg80211_suspend(wl_to_wiphy(wl), NULL);
-#else
-	wl_cfg80211_suspend(wl_to_wiphy(wl));
-#endif
-
-#if defined(BCMLXSDMMC)
-	sdioh_stop(NULL);
-#endif
-	/* clean up dtim_skip setting */
-	dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
-}
-
-static int wl_debugfs_add_netdev_params(struct wl_priv *wl)
-{
-	char buf[10+IFNAMSIZ];
-	struct dentry *fd;
-	s32 err = 0;
-
-	WL_TRACE(("In\n"));
-	sprintf(buf, "netdev:%s", wl_to_prmry_ndev(wl)->name);
-	wl->debugfsdir = debugfs_create_dir(buf, wl_to_wiphy(wl)->debugfsdir);
-
-	fd = debugfs_create_u16("beacon_int", S_IRUGO, wl->debugfsdir,
-		(u16 *)&wl->profile->beacon_interval);
-	if (!fd) {
-		err = -ENOMEM;
-		goto err_out;
-	}
-
-	fd = debugfs_create_u8("dtim_period", S_IRUGO, wl->debugfsdir,
-		(u8 *)&wl->profile->dtim_period);
-	if (!fd) {
-		err = -ENOMEM;
-		goto err_out;
-	}
-
-err_out:
-	return err;
-}
-
-static void wl_debugfs_remove_netdev(struct wl_priv *wl)
-{
-	WL_DBG(("Enter \n"));
-}
-
 static const struct rfkill_ops wl_rfkill_ops = {
 	.set_block = wl_rfkill_set
 };
@@ -6834,7 +6884,7 @@
 		return -EINVAL;
 	if (setup) {
 		wl->rfkill = rfkill_alloc("brcmfmac-wifi",
-			&wl_cfg80211_get_sdio_func()->dev,
+			wl_cfg80211_get_parent_dev(),
 			RFKILL_TYPE_WLAN, &wl_rfkill_ops, (void *)wl);
 
 		if (!wl->rfkill) {
@@ -6860,471 +6910,28 @@
 	return err;
 }
 
-#if defined(COEX_DHCP)
-/*
- * get named driver variable to uint register value and return error indication
- * calling example: dev_wlc_intvar_get_reg(dev, "btc_params",66, &reg_value)
- */
-static int
-dev_wlc_intvar_get_reg(struct net_device *dev, char *name,
-	uint reg, int *retval)
+struct device *wl_cfg80211_get_parent_dev(void)
 {
-	union {
-		char buf[WLC_IOCTL_SMLEN];
-		int val;
-	} var;
-	int error;
-
-	bcm_mkiovar(name, (char *)(&reg), sizeof(reg),
-		(char *)(&var), sizeof(var.buf));
-	error = wldev_ioctl(dev, WLC_GET_VAR, (char *)(&var), sizeof(var.buf), false);
-
-	*retval = dtoh32(var.val);
-	return (error);
+	return cfg80211_parent_dev;
 }
 
-static int
-dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len)
+void wl_cfg80211_set_parent_dev(void *dev)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
-	char ioctlbuf[1024];
-#else
-	static char ioctlbuf[1024];
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
-
-	bcm_mkiovar(name, buf, len, ioctlbuf, sizeof(ioctlbuf));
-
-	return (wldev_ioctl(dev, WLC_SET_VAR, ioctlbuf, sizeof(ioctlbuf), true));
-}
-/*
-get named driver variable to uint register value and return error indication
-calling example: dev_wlc_intvar_set_reg(dev, "btc_params",66, value)
-*/
-static int
-dev_wlc_intvar_set_reg(struct net_device *dev, char *name, char *addr, char * val)
-{
-	char reg_addr[8];
-
-	memset(reg_addr, 0, sizeof(reg_addr));
-	memcpy((char *)&reg_addr[0], (char *)addr, 4);
-	memcpy((char *)&reg_addr[4], (char *)val, 4);
-
-	return (dev_wlc_bufvar_set(dev, name, (char *)&reg_addr[0], sizeof(reg_addr)));
+	cfg80211_parent_dev = dev;
 }
 
-static bool btcoex_is_sco_active(struct net_device *dev)
+static void wl_cfg80211_clear_parent_dev(void)
 {
-	int ioc_res = 0;
-	bool res = FALSE;
-	int sco_id_cnt = 0;
-	int param27;
-	int i;
-
-	for (i = 0; i < 12; i++) {
-
-		ioc_res = dev_wlc_intvar_get_reg(dev, "btc_params", 27, &param27);
-
-		WL_TRACE(("%s, sample[%d], btc params: 27:%x\n",
-			__FUNCTION__, i, param27));
-
-		if (ioc_res < 0) {
-			WL_ERR(("%s ioc read btc params error\n", __FUNCTION__));
-			break;
-		}
-
-		if ((param27 & 0x6) == 2) { /* count both sco & esco  */
-			sco_id_cnt++;
-		}
-
-		if (sco_id_cnt > 2) {
-			WL_TRACE(("%s, sco/esco detected, pkt id_cnt:%d  samples:%d\n",
-				__FUNCTION__, sco_id_cnt, i));
-			res = TRUE;
-			break;
-		}
-
-		msleep(5);
-	}
-
-	return res;
+	cfg80211_parent_dev = NULL;
 }
 
-#if defined(BT_DHCP_eSCO_FIX)
-/* Enhanced BT COEX settings for eSCO compatibility during DHCP window */
-static int set_btc_esco_params(struct net_device *dev, bool trump_sco)
+static void get_primary_mac(struct wl_priv *wl, struct ether_addr *mac)
 {
-	static bool saved_status = FALSE;
-
-	char buf_reg50va_dhcp_on[8] =
-		{ 50, 00, 00, 00, 0x22, 0x80, 0x00, 0x00 };
-	char buf_reg51va_dhcp_on[8] =
-		{ 51, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
-	char buf_reg64va_dhcp_on[8] =
-		{ 64, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
-	char buf_reg65va_dhcp_on[8] =
-		{ 65, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
-	char buf_reg71va_dhcp_on[8] =
-		{ 71, 00, 00, 00, 0x00, 0x00, 0x00, 0x00 };
-	uint32 regaddr;
-	static uint32 saved_reg50;
-	static uint32 saved_reg51;
-	static uint32 saved_reg64;
-	static uint32 saved_reg65;
-	static uint32 saved_reg71;
-
-	if (trump_sco) {
-		/* this should reduce eSCO agressive retransmit
-		 * w/o breaking it
-		 */
-
-		/* 1st save current */
-		WL_TRACE(("Do new SCO/eSCO coex algo {save &"
-			  "override}\n"));
-		if ((!dev_wlc_intvar_get_reg(dev, "btc_params", 50, &saved_reg50)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 51, &saved_reg51)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 64, &saved_reg64)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 65, &saved_reg65)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 71, &saved_reg71))) {
-			saved_status = TRUE;
-			WL_TRACE(("%s saved bt_params[50,51,64,65,71]:"
-				  "0x%x 0x%x 0x%x 0x%x 0x%x\n",
-				  __FUNCTION__, saved_reg50, saved_reg51,
-				  saved_reg64, saved_reg65, saved_reg71));
-		} else {
-			WL_ERR((":%s: save btc_params failed\n",
-				__FUNCTION__));
-			saved_status = FALSE;
-			return -1;
-		}
-
-		WL_TRACE(("override with [50,51,64,65,71]:"
-			  "0x%x 0x%x 0x%x 0x%x 0x%x\n",
-			  *(u32 *)(buf_reg50va_dhcp_on+4),
-			  *(u32 *)(buf_reg51va_dhcp_on+4),
-			  *(u32 *)(buf_reg64va_dhcp_on+4),
-			  *(u32 *)(buf_reg65va_dhcp_on+4),
-			  *(u32 *)(buf_reg71va_dhcp_on+4)));
-
-		dev_wlc_bufvar_set(dev, "btc_params",
-			(char *)&buf_reg50va_dhcp_on[0], 8);
-		dev_wlc_bufvar_set(dev, "btc_params",
-			(char *)&buf_reg51va_dhcp_on[0], 8);
-		dev_wlc_bufvar_set(dev, "btc_params",
-			(char *)&buf_reg64va_dhcp_on[0], 8);
-		dev_wlc_bufvar_set(dev, "btc_params",
-			(char *)&buf_reg65va_dhcp_on[0], 8);
-		dev_wlc_bufvar_set(dev, "btc_params",
-			(char *)&buf_reg71va_dhcp_on[0], 8);
-
-		saved_status = TRUE;
-	} else if (saved_status) {
-		/* restore previously saved bt params */
-		WL_TRACE(("Do new SCO/eSCO coex algo {save &"
-			  "override}\n"));
-
-		regaddr = 50;
-		dev_wlc_intvar_set_reg(dev, "btc_params",
-			(char *)&regaddr, (char *)&saved_reg50);
-		regaddr = 51;
-		dev_wlc_intvar_set_reg(dev, "btc_params",
-			(char *)&regaddr, (char *)&saved_reg51);
-		regaddr = 64;
-		dev_wlc_intvar_set_reg(dev, "btc_params",
-			(char *)&regaddr, (char *)&saved_reg64);
-		regaddr = 65;
-		dev_wlc_intvar_set_reg(dev, "btc_params",
-			(char *)&regaddr, (char *)&saved_reg65);
-		regaddr = 71;
-		dev_wlc_intvar_set_reg(dev, "btc_params",
-			(char *)&regaddr, (char *)&saved_reg71);
-
-		WL_TRACE(("restore bt_params[50,51,64,65,71]:"
-			"0x%x 0x%x 0x%x 0x%x 0x%x\n",
-			saved_reg50, saved_reg51, saved_reg64,
-			saved_reg65, saved_reg71));
-
-		saved_status = FALSE;
-	} else {
-		WL_ERR((":%s att to restore not saved BTCOEX params\n",
-			__FUNCTION__));
-		return -1;
-	}
-	return 0;
+	wldev_iovar_getbuf_bsscfg(wl_to_prmry_ndev(wl), "cur_etheraddr", NULL,
+		0, wl->ioctl_buf, WLC_IOCTL_MAXLEN, 0, &wl->ioctl_buf_sync);
+	memcpy(mac->octet, wl->ioctl_buf, ETHER_ADDR_LEN);
 }
-#endif /* BT_DHCP_eSCO_FIX */
-
-static void
-wl_cfg80211_bt_setflag(struct net_device *dev, bool set)
+void wl_cfg80211_enable_trace(int level)
 {
-#if defined(BT_DHCP_USE_FLAGS)
-	char buf_flag7_dhcp_on[8] = { 7, 00, 00, 00, 0x1, 0x0, 0x00, 0x00 };
-	char buf_flag7_default[8]   = { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
-#endif
-
-#if defined(BT_DHCP_eSCO_FIX)
-	/* set = 1, save & turn on  0 - off & restore prev settings */
-	set_btc_esco_params(dev, set);
-#endif
-
-#if defined(BT_DHCP_USE_FLAGS)
-	WL_TRACE(("WI-FI priority boost via bt flags, set:%d\n", set));
-	if (set == TRUE)
-		/* Forcing bt_flag7  */
-		dev_wlc_bufvar_set(dev, "btc_flags",
-			(char *)&buf_flag7_dhcp_on[0],
-			sizeof(buf_flag7_dhcp_on));
-	else
-		/* Restoring default bt flag7 */
-		dev_wlc_bufvar_set(dev, "btc_flags",
-			(char *)&buf_flag7_default[0],
-			sizeof(buf_flag7_default));
-#endif
-}
-
-static void wl_cfg80211_bt_timerfunc(ulong data)
-{
-	struct btcoex_info *bt_local = (struct btcoex_info *)data;
-	WL_TRACE(("%s\n", __FUNCTION__));
-	bt_local->timer_on = 0;
-	schedule_work(&bt_local->work);
-}
-
-static void wl_cfg80211_bt_handler(struct work_struct *work)
-{
-	struct btcoex_info *btcx_inf;
-
-	btcx_inf = container_of(work, struct btcoex_info, work);
-
-	if (btcx_inf->timer_on) {
-		btcx_inf->timer_on = 0;
-		del_timer_sync(&btcx_inf->timer);
-	}
-
-	switch (btcx_inf->bt_state) {
-		case BT_DHCP_START:
-			/* DHCP started
-			 * provide OPPORTUNITY window to get DHCP address
-			 */
-			WL_TRACE(("%s bt_dhcp stm: started \n",
-				__FUNCTION__));
-			btcx_inf->bt_state = BT_DHCP_OPPR_WIN;
-			mod_timer(&btcx_inf->timer,
-				jiffies + BT_DHCP_OPPR_WIN_TIME*HZ/1000);
-			btcx_inf->timer_on = 1;
-			break;
-
-		case BT_DHCP_OPPR_WIN:
-			if (btcx_inf->dhcp_done) {
-				WL_TRACE(("%s DHCP Done before T1 expiration\n",
-					__FUNCTION__));
-				goto btc_coex_idle;
-			}
-
-			/* DHCP is not over yet, start lowering BT priority
-			 * enforce btc_params + flags if necessary
-			 */
-			WL_TRACE(("%s DHCP T1:%d expired\n", __FUNCTION__,
-				BT_DHCP_OPPR_WIN_TIME));
-			if (btcx_inf->dev)
-				wl_cfg80211_bt_setflag(btcx_inf->dev, TRUE);
-			btcx_inf->bt_state = BT_DHCP_FLAG_FORCE_TIMEOUT;
-			mod_timer(&btcx_inf->timer,
-				jiffies + BT_DHCP_FLAG_FORCE_TIME*HZ/1000);
-			btcx_inf->timer_on = 1;
-			break;
-
-		case BT_DHCP_FLAG_FORCE_TIMEOUT:
-			if (btcx_inf->dhcp_done) {
-				WL_TRACE(("%s DHCP Done before T2 expiration\n",
-					__FUNCTION__));
-			} else {
-				/* Noo dhcp during T1+T2, restore BT priority */
-				WL_TRACE(("%s DHCP wait interval T2:%d"
-					  "msec expired\n", __FUNCTION__,
-					  BT_DHCP_FLAG_FORCE_TIME));
-			}
-
-			/* Restoring default bt priority */
-			if (btcx_inf->dev)
-				wl_cfg80211_bt_setflag(btcx_inf->dev, FALSE);
-btc_coex_idle:
-			btcx_inf->bt_state = BT_DHCP_IDLE;
-			btcx_inf->timer_on = 0;
-			break;
-
-		default:
-			WL_ERR(("%s error g_status=%d !!!\n", __FUNCTION__,
-				btcx_inf->bt_state));
-			if (btcx_inf->dev)
-				wl_cfg80211_bt_setflag(btcx_inf->dev, FALSE);
-			btcx_inf->bt_state = BT_DHCP_IDLE;
-			btcx_inf->timer_on = 0;
-			break;
-	}
-
-	net_os_wake_unlock(btcx_inf->dev);
-}
-
-static int wl_cfg80211_btcoex_init(struct wl_priv *wl)
-{
-	struct btcoex_info *btco_inf = NULL;
-
-	btco_inf = kmalloc(sizeof(struct btcoex_info), GFP_KERNEL);
-	if (!btco_inf)
-		return -ENOMEM;
-
-	btco_inf->bt_state = BT_DHCP_IDLE;
-	btco_inf->ts_dhcp_start = 0;
-	btco_inf->ts_dhcp_ok = 0;
-	/* Set up timer for BT  */
-	btco_inf->timer_ms = 10;
-	init_timer(&btco_inf->timer);
-	btco_inf->timer.data = (ulong)btco_inf;
-	btco_inf->timer.function = wl_cfg80211_bt_timerfunc;
-
-	btco_inf->dev = wl->wdev->netdev;
-
-	INIT_WORK(&btco_inf->work, wl_cfg80211_bt_handler);
-
-	wl->btcoex_info = btco_inf;
-	return 0;
-}
-
-static void
-wl_cfg80211_btcoex_deinit(struct wl_priv *wl)
-{
-	if (!wl->btcoex_info)
-		return;
-
-	if (!wl->btcoex_info->timer_on) {
-		wl->btcoex_info->timer_on = 0;
-		del_timer_sync(&wl->btcoex_info->timer);
-	}
-
-	cancel_work_sync(&wl->btcoex_info->work);
-
-	kfree(wl->btcoex_info);
-	wl->btcoex_info = NULL;
-}
-#endif		/* COEX_DHCP */
-
-int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, char *command)
-{
-	char powermode_val = 0;
-	char buf_reg66va_dhcp_on[8] = { 66, 00, 00, 00, 0x10, 0x27, 0x00, 0x00 };
-	char buf_reg41va_dhcp_on[8] = { 41, 00, 00, 00, 0x33, 0x00, 0x00, 0x00 };
-	char buf_reg68va_dhcp_on[8] = { 68, 00, 00, 00, 0x90, 0x01, 0x00, 0x00 };
-
-	uint32 regaddr;
-	static uint32 saved_reg66;
-	static uint32 saved_reg41;
-	static uint32 saved_reg68;
-	static bool saved_status = FALSE;
-
-#ifdef COEX_DHCP
-	char buf_flag7_default[8] =   { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
-	struct btcoex_info *btco_inf = wlcfg_drv_priv->btcoex_info;
-#endif /* COEX_DHCP */
-
-	/* Figure out powermode 1 or o command */
-	strncpy((char *)&powermode_val, command + strlen("BTCOEXMODE") +1, 1);
-
-	if (strnicmp((char *)&powermode_val, "1", strlen("1")) == 0) {
-
-		WL_TRACE(("%s: DHCP session starts\n", __FUNCTION__));
-
-		/* Retrieve and saved orig regs value */
-		if ((saved_status == FALSE) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 66,  &saved_reg66)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 41,  &saved_reg41)) &&
-			(!dev_wlc_intvar_get_reg(dev, "btc_params", 68,  &saved_reg68)))   {
-				saved_status = TRUE;
-				WL_TRACE(("Saved 0x%x 0x%x 0x%x\n",
-					saved_reg66, saved_reg41, saved_reg68));
-
-				/* Disable PM mode during dhpc session */
-
-				/* Disable PM mode during dhpc session */
-#ifdef COEX_DHCP
-				/* Start  BT timer only for SCO connection */
-				if (btcoex_is_sco_active(dev)) {
-					/* btc_params 66 */
-					dev_wlc_bufvar_set(dev, "btc_params",
-						(char *)&buf_reg66va_dhcp_on[0],
-						sizeof(buf_reg66va_dhcp_on));
-					/* btc_params 41 0x33 */
-					dev_wlc_bufvar_set(dev, "btc_params",
-						(char *)&buf_reg41va_dhcp_on[0],
-						sizeof(buf_reg41va_dhcp_on));
-					/* btc_params 68 0x190 */
-					dev_wlc_bufvar_set(dev, "btc_params",
-						(char *)&buf_reg68va_dhcp_on[0],
-						sizeof(buf_reg68va_dhcp_on));
-					saved_status = TRUE;
-
-					btco_inf->bt_state = BT_DHCP_START;
-					btco_inf->timer_on = 1;
-					mod_timer(&btco_inf->timer, btco_inf->timer.expires);
-					WL_TRACE(("%s enable BT DHCP Timer\n",
-					__FUNCTION__));
-				}
-#endif /* COEX_DHCP */
-		}
-		else if (saved_status == TRUE) {
-			WL_ERR(("%s was called w/o DHCP OFF. Continue\n", __FUNCTION__));
-		}
-	}
-	else if (strnicmp((char *)&powermode_val, "2", strlen("2")) == 0) {
-
-
-		/* Restoring PM mode */
-
-#ifdef COEX_DHCP
-		/* Stop any bt timer because DHCP session is done */
-		WL_TRACE(("%s disable BT DHCP Timer\n", __FUNCTION__));
-		if (btco_inf->timer_on) {
-			btco_inf->timer_on = 0;
-			del_timer_sync(&btco_inf->timer);
-
-			if (btco_inf->bt_state != BT_DHCP_IDLE) {
-			/* need to restore original btc flags & extra btc params */
-				WL_TRACE(("%s bt->bt_state:%d\n",
-					__FUNCTION__, btco_inf->bt_state));
-				/* wake up btcoex thread to restore btlags+params  */
-				schedule_work(&btco_inf->work);
-			}
-		}
-
-		/* Restoring btc_flag paramter anyway */
-		if (saved_status == TRUE)
-			dev_wlc_bufvar_set(dev, "btc_flags",
-				(char *)&buf_flag7_default[0], sizeof(buf_flag7_default));
-#endif /* COEX_DHCP */
-
-		/* Restore original values */
-		if (saved_status == TRUE) {
-			regaddr = 66;
-			dev_wlc_intvar_set_reg(dev, "btc_params",
-				(char *)&regaddr, (char *)&saved_reg66);
-			regaddr = 41;
-			dev_wlc_intvar_set_reg(dev, "btc_params",
-				(char *)&regaddr, (char *)&saved_reg41);
-			regaddr = 68;
-			dev_wlc_intvar_set_reg(dev, "btc_params",
-				(char *)&regaddr, (char *)&saved_reg68);
-
-			WL_TRACE(("restore regs {66,41,68} <- 0x%x 0x%x 0x%x\n",
-				saved_reg66, saved_reg41, saved_reg68));
-		}
-		saved_status = FALSE;
-
-	}
-	else {
-		WL_ERR(("%s Unkwown yet power setting, ignored\n",
-			__FUNCTION__));
-	}
-
-	snprintf(command, 3, "OK");
-
-	return (strlen("OK"));
+	wl_dbg_level |= WL_DBG_DBG;
 }
diff --git a/drivers/net/wireless/bcmdhd/wl_cfg80211.h b/drivers/net/wireless/bcmdhd/wl_cfg80211.h
index 262335e..dba675a 100644
--- a/drivers/net/wireless/bcmdhd/wl_cfg80211.h
+++ b/drivers/net/wireless/bcmdhd/wl_cfg80211.h
@@ -2,13 +2,13 @@
  * Linux cfg80211 driver
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -68,6 +68,9 @@
 			printk args;						\
 		} 								\
 } while (0)
+#ifdef WL_INFO
+#undef WL_INFO
+#endif
 #define	WL_INFO(args)									\
 do {										\
 	if (wl_dbg_level & WL_DBG_INFO) {				\
@@ -75,6 +78,9 @@
 			printk args;						\
 		}								\
 } while (0)
+#ifdef WL_SCAN
+#undef WL_SCAN
+#endif
 #define	WL_SCAN(args)								\
 do {									\
 	if (wl_dbg_level & WL_DBG_SCAN) {			\
@@ -82,6 +88,9 @@
 		printk args;							\
 	}									\
 } while (0)
+#ifdef WL_TRACE
+#undef WL_TRACE
+#endif
 #define	WL_TRACE(args)								\
 do {									\
 	if (wl_dbg_level & WL_DBG_TRACE) {			\
@@ -102,39 +111,30 @@
 #endif				/* (WL_DBG_LEVEL > 0) */
 
 
-#define WL_SCAN_RETRY_MAX	3	/* used for ibss scan */
-#define WL_NUM_PMKIDS_MAX	MAXPMKID	/* will be used
-						 * for 2.6.33 kernel
-						 * or later
-						 */
-#define WL_SCAN_BUF_MAX 		(1024 * 8)
-#define WL_TLV_INFO_MAX 		1024
+#define WL_SCAN_RETRY_MAX	3
+#define WL_NUM_PMKIDS_MAX	MAXPMKID
+#define WL_SCAN_BUF_MAX 	(1024 * 8)
+#define WL_TLV_INFO_MAX 	1024
 #define WL_SCAN_IE_LEN_MAX      2048
-#define WL_BSS_INFO_MAX			2048
-#define WL_ASSOC_INFO_MAX	512	/*
-				 * needs to grab assoc info from dongle to
-				 * report it to cfg80211 through "connect"
-				 * event
-				 */
+#define WL_BSS_INFO_MAX		2048
+#define WL_ASSOC_INFO_MAX	512
 #define WL_IOCTL_LEN_MAX	1024
 #define WL_EXTRA_BUF_MAX	2048
-#define WL_ISCAN_BUF_MAX	2048	/*
-				 * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
-				 * to reduce iteration
-				 */
+#define WL_ISCAN_BUF_MAX	2048
 #define WL_ISCAN_TIMER_INTERVAL_MS	3000
 #define WL_SCAN_ERSULTS_LAST 	(WL_SCAN_RESULTS_NO_MEM+1)
-#define WL_AP_MAX	256	/* virtually unlimitted as long
-				 * as kernel memory allows
-				 */
+#define WL_AP_MAX		256
 #define WL_FILE_NAME_MAX	256
-#define WL_DWELL_TIME		200
-#define WL_LONG_DWELL_TIME	1000
-#define VWDEV_CNT 3
+#define WL_DWELL_TIME 		200
+#define WL_MED_DWELL_TIME 		400
+#define WL_LONG_DWELL_TIME 	1000
+#define IFACE_MAX_CNT 		2
 
 #define WL_SCAN_TIMER_INTERVAL_MS	8000 /* Scan timeout */
+#define WL_CHANNEL_SYNC_RETRY 	5
+#define WL_INVALID 		-1
 
-/* dongle status */
+/* driver status */
 enum wl_status {
 	WL_STATUS_READY = 0,
 	WL_STATUS_SCANNING,
@@ -143,7 +143,8 @@
 	WL_STATUS_CONNECTED,
 	WL_STATUS_DISCONNECTING,
 	WL_STATUS_AP_CREATING,
-	WL_STATUS_AP_CREATED
+	WL_STATUS_AP_CREATED,
+	WL_STATUS_SENDING_ACT_FRM
 };
 
 /* wi-fi mode */
@@ -153,7 +154,7 @@
 	WL_MODE_AP
 };
 
-/* dongle profile list */
+/* driver profile list */
 enum wl_prof_list {
 	WL_PROF_MODE,
 	WL_PROF_SSID,
@@ -166,7 +167,7 @@
 	WL_PROF_DTIMPERIOD
 };
 
-/* dongle iscan state */
+/* driver iscan state */
 enum wl_iscan_state {
 	WL_ISCAN_STATE_IDLE,
 	WL_ISCAN_STATE_SCANING
@@ -196,12 +197,8 @@
 	u8 variable[0];
 } __attribute__ ((packed));
 
-/* dongle configuration */
+/* driver configuration */
 struct wl_conf {
-	struct net_mode {
-		struct net_device *ndev;
-		s32 type;
-	} mode [VWDEV_CNT + 1];		/* adhoc , infrastructure or ap */
 	u32 frag_threshold;
 	u32 rts_threshold;
 	u32 retry_short;
@@ -259,22 +256,30 @@
 	u8 channel;
 };
 
-/* dongle profile */
+/* wl driver profile */
 struct wl_profile {
 	u32 mode;
+	s32 band;
 	struct wlc_ssid ssid;
+	struct wl_security sec;
+	struct wl_ibss ibss;
 	u8 bssid[ETHER_ADDR_LEN];
 	u16 beacon_interval;
 	u8 dtim_period;
-	struct wl_security sec;
-	struct wl_ibss ibss;
-	s32 band;
 	bool active;
 };
 
+struct net_info {
+	struct net_device *ndev;
+	struct wireless_dev *wdev;
+	struct wl_profile profile;
+	s32 mode;
+	unsigned long sme_state;
+	struct list_head list; /* list of all net_info structure */
+};
 typedef s32(*ISCAN_HANDLER) (struct wl_priv *wl);
 
-/* dongle iscan controller */
+/* iscan controller */
 struct wl_iscan_ctrl {
 	struct net_device *dev;
 	struct timer_list timer;
@@ -323,9 +328,10 @@
 #define ESCAN_BUF_SIZE (64 * 1024)
 
 struct escan_info {
-    u32 escan_state;
-    u8 escan_buf[ESCAN_BUF_SIZE];
-    struct wiphy *wiphy;
+	u32 escan_state;
+	u8 escan_buf[ESCAN_BUF_SIZE];
+	struct wiphy *wiphy;
+	struct net_device *ndev;
 };
 
 struct ap_info {
@@ -341,14 +347,14 @@
 };
 struct btcoex_info {
 	struct timer_list timer;
-	uint32 timer_ms;
-	uint32 timer_on;
-	uint32 ts_dhcp_start;	/* ms ts ecord time stats */
-	uint32 ts_dhcp_ok;	/* ms ts ecord time stats */
-	bool dhcp_done;		/* flag, indicates that host done with
-				 * dhcp before t1/t2 expiration
-				 */
-	int bt_state;
+	u32 timer_ms;
+	u32 timer_on;
+	u32 ts_dhcp_start;	/* ms ts ecord time stats */
+	u32 ts_dhcp_ok;		/* ms ts ecord time stats */
+	bool dhcp_done;	/* flag, indicates that host done with
+					 * dhcp before t1/t2 expiration
+					 */
+	s32 bt_state;
 	struct work_struct work;
 	struct net_device *dev;
 };
@@ -360,40 +366,50 @@
 	u32 probe_req_ie_len;
 	u32 assoc_req_ie_len;
 };
-/* dongle private data of cfg80211 interface */
+
+struct afx_hdl {
+	wl_af_params_t *pending_tx_act_frm;
+	struct ether_addr	pending_tx_dst_addr;
+	struct net_device *dev;
+	struct work_struct work;
+	u32 bssidx;
+	u32 retry;
+	s32 peer_chan;
+	bool ack_recv;
+};
+
+/* private data of cfg80211 interface */
 struct wl_priv {
 	struct wireless_dev *wdev;	/* representing wl cfg80211 device */
-	struct wireless_dev *vwdev[VWDEV_CNT];
-	struct wl_conf *conf;	/* dongle configuration */
+
+	struct wireless_dev *p2p_wdev;	/* representing wl cfg80211 device for P2P */
+	struct net_device *p2p_net;    /* reference to p2p0 interface */
+
+	struct wl_conf *conf;
 	struct cfg80211_scan_request *scan_request;	/* scan request object */
 	EVENT_HANDLER evt_handler[WLC_E_LAST];
 	struct list_head eq_list;	/* used for event queue */
+	struct list_head net_list;     /* used for struct net_info */
 	spinlock_t eq_lock;	/* for event queue synchronization */
-	struct mutex usr_sync;	/* maily for dongle up/down synchronization */
+	spinlock_t cfgdrv_lock;	/* to protect scan status (and others if needed) */
+	struct completion act_frm_scan;
+	struct mutex usr_sync;	/* maily for up/down synchronization */
 	struct wl_scan_results *bss_list;
 	struct wl_scan_results *scan_results;
 
 	/* scan request object for internal purpose */
 	struct wl_scan_req *scan_req_int;
-
-	/* bss information for cfg80211 layer */
-	struct wl_cfg80211_bss_info *bss_info;
 	/* information element object for internal purpose */
 	struct wl_ie ie;
-
-	/* for synchronization of main event thread */
-	struct wl_profile *profile;	/* holding dongle profile */
 	struct wl_iscan_ctrl *iscan;	/* iscan controller */
 
 	/* association information container */
 	struct wl_connect_info conn_info;
 
-	/* control firwmare and nvram paramter downloading */
-	struct wl_fw_ctrl *fw;
 	struct wl_pmk_list *pmk_list;	/* wpa2 pmk list */
 	tsk_ctl_t event_tsk;  		/* task of main event handler thread */
-	unsigned long status;		/* current dongle status */
 	void *pub;
+	u32 iface_cnt;
 	u32 channel;		/* current channel */
 	bool iscan_on;		/* iscan on/off switch */
 	bool iscan_kickstart;	/* indicate iscan already started */
@@ -403,12 +419,12 @@
 	bool ibss_starter;	/* indicates this sta is ibss starter */
 	bool link_up;		/* link/connection up flag */
 
-	/* indicate whether dongle to support power save mode */
+	/* indicate whether chip to support power save mode */
 	bool pwr_save;
-	bool dongle_up;		/* indicate whether dongle up or not */
-	bool roam_on;		/* on/off switch for dongle self-roaming */
+	bool roam_on;		/* on/off switch for self-roaming */
 	bool scan_tried;	/* indicates if first scan attempted */
-	u8 *ioctl_buf;	/* ioctl buffer */
+	u8 *ioctl_buf;		/* ioctl buffer */
+	struct mutex ioctl_buf_sync;
 	u8 *escan_ioctl_buf;
 	u8 *extra_buf;	/* maily to grab assoc information */
 	struct dentry *debugfsdir;
@@ -416,8 +432,10 @@
 	bool rf_blocked;
 	struct ieee80211_channel remain_on_chan;
 	enum nl80211_channel_type remain_on_chan_type;
-	u64 cache_cookie;
-	wait_queue_head_t dongle_event_wait;
+	u64 send_action_id;
+	u64 last_roc_id;
+	wait_queue_head_t netif_change_event;
+	struct afx_hdl *afx_hdl;
 	struct ap_info *ap_info;
 	struct sta_info *sta_info;
 	struct p2p_info *p2p;
@@ -426,6 +444,150 @@
 	struct timer_list scan_timeout;   /* Timer for catch scan event timeout */
 };
 
+
+static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
+{
+	return bss = bss ?
+		(struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
+}
+static inline s32
+wl_alloc_netinfo(struct wl_priv *wl, struct net_device *ndev,
+	struct wireless_dev * wdev, s32 mode)
+{
+	struct net_info *_net_info;
+	s32 err = 0;
+	if (wl->iface_cnt == IFACE_MAX_CNT)
+		return -ENOMEM;
+	_net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL);
+	if (!_net_info)
+		err = -ENOMEM;
+	else {
+		_net_info->mode = mode;
+		_net_info->ndev = ndev;
+		_net_info->wdev = wdev;
+		wl->iface_cnt++;
+		list_add(&_net_info->list, &wl->net_list);
+	}
+	return err;
+}
+static inline void
+wl_dealloc_netinfo(struct wl_priv *wl, struct net_device *ndev)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+		if (ndev && (_net_info->ndev == ndev)) {
+			list_del(&_net_info->list);
+			wl->iface_cnt--;
+			if (_net_info->wdev) {
+				kfree(_net_info->wdev);
+				ndev->ieee80211_ptr = NULL;
+			}
+			kfree(_net_info);
+		}
+	}
+
+}
+static inline void
+wl_delete_all_netinfo(struct wl_priv *wl)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+		list_del(&_net_info->list);
+			if (_net_info->wdev)
+				kfree(_net_info->wdev);
+			kfree(_net_info);
+	}
+	wl->iface_cnt = 0;
+}
+static inline bool
+wl_get_status_all(struct wl_priv *wl, s32 status)
+
+{
+	struct net_info *_net_info, *next;
+	u32 cnt = 0;
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+		if (_net_info->ndev &&
+			test_bit(status, &_net_info->sme_state))
+			cnt++;
+	}
+	return cnt? true: false;
+}
+static inline void
+wl_set_status_by_netdev(struct wl_priv *wl, s32 status,
+	struct net_device *ndev, u32 op)
+{
+
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+		if (ndev && (_net_info->ndev == ndev)) {
+			switch (op) {
+				case 1:
+					set_bit(status, &_net_info->sme_state);
+					break;
+				case 2:
+					clear_bit(status, &_net_info->sme_state);
+					break;
+				case 4:
+					change_bit(status, &_net_info->sme_state);
+					break;
+			}
+		}
+
+	}
+
+}
+
+static inline u32
+wl_get_status_by_netdev(struct wl_priv *wl, s32 status,
+	struct net_device *ndev)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+				if (ndev && (_net_info->ndev == ndev))
+					return test_bit(status, &_net_info->sme_state);
+	}
+	return 0;
+}
+
+static inline s32
+wl_get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+				if (ndev && (_net_info->ndev == ndev))
+					return _net_info->mode;
+	}
+	return -1;
+}
+
+
+static inline void
+wl_set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev,
+	s32 mode)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+				if (ndev && (_net_info->ndev == ndev))
+					_net_info->mode = mode;
+	}
+}
+static inline struct wl_profile *
+wl_get_profile_by_netdev(struct wl_priv *wl, struct net_device *ndev)
+{
+	struct net_info *_net_info, *next;
+
+	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
+				if (ndev && (_net_info->ndev == ndev))
+					return &_net_info->profile;
+	}
+	return NULL;
+}
 #define wl_to_wiphy(w) (w->wdev->wiphy)
 #define wl_to_prmry_ndev(w) (w->wdev->netdev)
 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
@@ -435,112 +597,50 @@
 #define wl_to_iscan(w) (w->iscan)
 #define wl_to_conn(w) (&w->conn_info)
 #define wiphy_from_scan(w) (w->escan_info.wiphy)
-#define wl_get_drv_status(wl, stat)   (test_bit(WL_STATUS_ ## stat, &(wl)->status))
-#define wl_set_drv_status(wl, stat)   (set_bit(WL_STATUS_ ## stat, &(wl)->status))
-#define wl_clr_drv_status(wl, stat)   (clear_bit(WL_STATUS_ ## stat, &(wl)->status))
-#define wl_chg_drv_status(wl, stat)   (change_bit(WL_STATUS_ ## stat, &(wl)->status))
-
-static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
-{
-	return bss = bss ?
-		(struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
-}
-static inline s32 alloc_idx_vwdev(struct wl_priv *wl)
-{
-	s32 i = 0;
-	for (i = 0; i < VWDEV_CNT; i++) {
-		if (wl->vwdev[i] == NULL)
-				return i;
-	}
-	return -1;
-}
-
-static inline s32 get_idx_vwdev_by_netdev(struct wl_priv *wl, struct net_device *ndev)
-{
-	s32 i = 0;
-	for (i = 0; i < VWDEV_CNT; i++) {
-		if ((wl->vwdev[i] != NULL) && (wl->vwdev[i]->netdev == ndev))
-				return i;
-	}
-	return -1;
-}
-
-static inline s32 get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev)
-{
-	s32 i = 0;
-	for (i = 0; i <= VWDEV_CNT; i++) {
-		if (wl->conf->mode[i].ndev != NULL && (wl->conf->mode[i].ndev == ndev))
-			return wl->conf->mode[i].type;
-	}
-	return -1;
-}
-static inline void set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev, s32 type)
-{
-	s32 i = 0;
-	for (i = 0; i <= VWDEV_CNT; i++) {
-		if (type == -1) {
-			/* free the info of netdev */
-			if (wl->conf->mode[i].ndev == ndev) {
-				wl->conf->mode[i].ndev = NULL;
-				wl->conf->mode[i].type = -1;
-				break;
-			}
-
-		} else {
-			if ((wl->conf->mode[i].ndev != NULL)&&
-			(wl->conf->mode[i].ndev == ndev)) {
-				/* update type of ndev */
-				wl->conf->mode[i].type = type;
-				break;
-			}
-			else if ((wl->conf->mode[i].ndev == NULL)&&
-			(wl->conf->mode[i].type == -1)) {
-				wl->conf->mode[i].ndev = ndev;
-				wl->conf->mode[i].type = type;
-				break;
-			}
-		}
-	}
-}
-#define free_vwdev_by_index(wl, __i) do {      \
-						if (wl->vwdev[__i] != NULL) \
-							kfree(wl->vwdev[__i]); \
-						wl->vwdev[__i] = NULL; \
-					} while (0)
+#define wl_get_drv_status_all(wl, stat) \
+	(wl_get_status_all(wl, WL_STATUS_ ## stat))
+#define wl_get_drv_status(wl, stat, ndev)  \
+	(wl_get_status_by_netdev(wl, WL_STATUS_ ## stat, ndev))
+#define wl_set_drv_status(wl, stat, ndev)  \
+	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 1))
+#define wl_clr_drv_status(wl, stat, ndev)  \
+	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 2))
+#define wl_chg_drv_status(wl, stat, ndev)  \
+	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 4))
 
 #define for_each_bss(list, bss, __i)	\
 	for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
 
+#define for_each_ndev(wl, iter, next) \
+	list_for_each_entry_safe(iter, next, &wl->net_list, list)
+
+
 /* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
  * In addtion to that, wpa_version is WPA_VERSION_1
  */
 #define is_wps_conn(_sme) \
-	((_sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) && \
+	((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \
 	 (!_sme->crypto.n_ciphers_pairwise) && \
 	 (!_sme->crypto.cipher_group))
 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
 extern s32 wl_cfg80211_attach_post(struct net_device *ndev);
-extern void wl_cfg80211_detach(void);
-/* event handler from dongle */
+extern void wl_cfg80211_detach(void *para);
+
 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
             void *data);
-extern void wl_cfg80211_set_sdio_func(void *func);	/* set sdio function info */
-extern struct sdio_func *wl_cfg80211_get_sdio_func(void);	/* set sdio function info */
-extern s32 wl_cfg80211_up(void);	/* dongle up */
-extern s32 wl_cfg80211_down(void);	/* dongle down */
-extern s32 wl_cfg80211_notify_ifadd(struct net_device *net, s32 idx, s32 bssidx,
-int (*_net_attach)(dhd_pub_t *dhdp, int ifidx));
-extern s32 wl_cfg80211_notify_ifdel(struct net_device *ndev);
+void wl_cfg80211_set_parent_dev(void *dev);
+struct device *wl_cfg80211_get_parent_dev(void);
+
+extern s32 wl_cfg80211_up(void *para);
+extern s32 wl_cfg80211_down(void *para);
+extern s32 wl_cfg80211_notify_ifadd(struct net_device *net, s32 idx, s32 bssidx, void* _net_attach);
+extern s32 wl_cfg80211_ifdel_ops(struct net_device *net);
+extern s32 wl_cfg80211_notify_ifdel(void);
 extern s32 wl_cfg80211_is_progress_ifadd(void);
 extern s32 wl_cfg80211_is_progress_ifchange(void);
 extern s32 wl_cfg80211_is_progress_ifadd(void);
 extern s32 wl_cfg80211_notify_ifchange(void);
 extern void wl_cfg80211_dbg_level(u32 level);
-extern void *wl_cfg80211_request_fw(s8 *file_name);
-extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);
-extern void wl_cfg80211_release_fw(void);
-extern s8 *wl_cfg80211_get_fwname(void);
-extern s8 *wl_cfg80211_get_nvramname(void);
 extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
 extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len);
 extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len);
@@ -548,11 +648,11 @@
 	enum wl_management_type type);
 extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len);
 extern int wl_cfg80211_hang(struct net_device *dev, u16 reason);
+extern s32 wl_mode_to_nl80211_iftype(s32 mode);
 
 /* do scan abort */
-extern s32
-wl_cfg80211_scan_abort(struct wl_priv *wl, struct net_device *ndev);
+extern s32 wl_cfg80211_scan_abort(struct wl_priv *wl, struct net_device *ndev);
 
-extern s32
-wl_cfg80211_if_is_group_owner(void);
+extern s32 wl_cfg80211_if_is_group_owner(void);
+void wl_cfg80211_enable_trace(int level);
 #endif				/* _wl_cfg80211_h_ */
diff --git a/drivers/net/wireless/bcmdhd/wl_cfgp2p.c b/drivers/net/wireless/bcmdhd/wl_cfgp2p.c
index 4ee6557..e4cde58 100644
--- a/drivers/net/wireless/bcmdhd/wl_cfgp2p.c
+++ b/drivers/net/wireless/bcmdhd/wl_cfgp2p.c
@@ -2,13 +2,13 @@
  * Linux cfgp2p driver
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -30,6 +30,7 @@
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/timer.h>
@@ -39,26 +40,202 @@
 #include <bcmutils.h>
 #include <bcmendian.h>
 #include <proto/ethernet.h>
-#include <dngl_stats.h>
-#include <dhd.h>
-#include <dhdioctl.h>
-#include <wlioctl.h>
 
 #include <wl_cfg80211.h>
 #include <wl_cfgp2p.h>
 #include <wldev_common.h>
+#include <wl_android.h>
 
-
-static s8 ioctlbuf[WLC_IOCTL_MAXLEN];
 static s8 scanparambuf[WLC_IOCTL_SMLEN];
-static s8 *smbuf = ioctlbuf;
 
 static bool
 wl_cfgp2p_has_ie(u8 *ie, u8 **tlvs, u32 *tlvs_len, const u8 *oui, u32 oui_len, u8 type);
 
 static s32
-wl_cfgp2p_vndr_ie(struct net_device *ndev, s32 bssidx, s32 pktflag,
+wl_cfgp2p_vndr_ie(struct wl_priv *wl, struct net_device *ndev, s32 bssidx, s32 pktflag,
             s8 *oui, s32 ie_id, s8 *data, s32 data_len, s32 delete);
+
+static int wl_cfgp2p_start_xmit(struct sk_buff *skb, struct net_device *ndev);
+static int wl_cfgp2p_do_ioctl(struct net_device *net, struct ifreq *ifr, int cmd);
+static int wl_cfgp2p_if_open(struct net_device *net);
+static int wl_cfgp2p_if_stop(struct net_device *net);
+
+static const struct net_device_ops wl_cfgp2p_if_ops = {
+	.ndo_open		= wl_cfgp2p_if_open,
+	.ndo_stop		= wl_cfgp2p_if_stop,
+	.ndo_do_ioctl		= wl_cfgp2p_do_ioctl,
+	.ndo_start_xmit		= wl_cfgp2p_start_xmit,
+};
+
+bool wl_cfgp2p_is_pub_action(void *frame, u32 frame_len)
+{
+	wifi_p2p_pub_act_frame_t *pact_frm;
+
+	if (frame == NULL)
+		return false;
+	pact_frm = (wifi_p2p_pub_act_frame_t *)frame;
+	if (frame_len < sizeof(wifi_p2p_pub_act_frame_t) -1)
+		return false;
+
+	if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
+		pact_frm->action == P2P_PUB_AF_ACTION &&
+		pact_frm->oui_type == P2P_VER &&
+		memcmp(pact_frm->oui, P2P_OUI, sizeof(pact_frm->oui)) == 0) {
+		return true;
+	}
+
+	return false;
+}
+
+bool wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len)
+{
+	wifi_p2p_action_frame_t *act_frm;
+
+	if (frame == NULL)
+		return false;
+	act_frm = (wifi_p2p_action_frame_t *)frame;
+	if (frame_len < sizeof(wifi_p2p_action_frame_t) -1)
+		return false;
+
+	if (act_frm->category == P2P_AF_CATEGORY &&
+		act_frm->type  == P2P_VER &&
+		memcmp(act_frm->OUI, P2P_OUI, DOT11_OUI_LEN) == 0) {
+		return true;
+	}
+
+	return false;
+}
+
+bool wl_cfgp2p_is_gas_action(void *frame, u32 frame_len)
+{
+
+	wifi_p2psd_gas_pub_act_frame_t *sd_act_frm;
+
+	if (frame == NULL)
+		return false;
+
+	sd_act_frm = (wifi_p2psd_gas_pub_act_frame_t *)frame;
+	if (frame_len < sizeof(wifi_p2psd_gas_pub_act_frame_t) - 1)
+		return false;
+	if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
+		return false;
+
+	if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
+		sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
+		sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
+		sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
+		return true;
+	else
+		return false;
+
+}
+
+void wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len)
+{
+	wifi_p2p_pub_act_frame_t *pact_frm;
+	wifi_p2p_action_frame_t *act_frm;
+	wifi_p2psd_gas_pub_act_frame_t *sd_act_frm;
+	if (!frame || frame_len <= 2)
+		return;
+
+	if (wl_cfgp2p_is_pub_action(frame, frame_len)) {
+		pact_frm = (wifi_p2p_pub_act_frame_t *)frame;
+		switch (pact_frm->subtype) {
+			case P2P_PAF_GON_REQ:
+				CFGP2P_DBG(("%s P2P Group Owner Negotiation Req Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_GON_RSP:
+				CFGP2P_DBG(("%s P2P Group Owner Negotiation Rsp Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_GON_CONF:
+				CFGP2P_DBG(("%s P2P Group Owner Negotiation Confirm Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_INVITE_REQ:
+				CFGP2P_DBG(("%s P2P Invitation Request  Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_INVITE_RSP:
+				CFGP2P_DBG(("%s P2P Invitation Response Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_DEVDIS_REQ:
+				CFGP2P_DBG(("%s P2P Device Discoverability Request Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_DEVDIS_RSP:
+				CFGP2P_DBG(("%s P2P Device Discoverability Response Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_PROVDIS_REQ:
+				CFGP2P_DBG(("%s P2P Provision Discovery Request Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_PAF_PROVDIS_RSP:
+				CFGP2P_DBG(("%s P2P Provision Discovery Response Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			default:
+				CFGP2P_DBG(("%s Unknown P2P Public Action Frame\n",
+					(tx)? "TX": "RX"));
+
+		}
+
+	} else if (wl_cfgp2p_is_p2p_action(frame, frame_len)) {
+		act_frm = (wifi_p2p_action_frame_t *)frame;
+		switch (act_frm->subtype) {
+			case P2P_AF_NOTICE_OF_ABSENCE:
+				CFGP2P_DBG(("%s P2P Notice of Absence Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_AF_PRESENCE_REQ:
+				CFGP2P_DBG(("%s P2P Presence Request Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_AF_PRESENCE_RSP:
+				CFGP2P_DBG(("%s P2P Presence Response Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			case P2P_AF_GO_DISC_REQ:
+				CFGP2P_DBG(("%s P2P Discoverability Request Frame\n",
+					(tx)? "TX": "RX"));
+				break;
+			default:
+				CFGP2P_DBG(("%s Unknown P2P Action Frame\n",
+					(tx)? "TX": "RX"));
+		}
+
+	} else if (wl_cfgp2p_is_gas_action(frame, frame_len)) {
+		sd_act_frm = (wifi_p2psd_gas_pub_act_frame_t *)frame;
+		switch (sd_act_frm->action) {
+			case P2PSD_ACTION_ID_GAS_IREQ:
+				CFGP2P_DBG(("%s P2P GAS Initial Request\n",
+					(tx)? "TX" : "RX"));
+				break;
+			case P2PSD_ACTION_ID_GAS_IRESP:
+				CFGP2P_DBG(("%s P2P GAS Initial Response\n",
+					(tx)? "TX" : "RX"));
+				break;
+			case P2PSD_ACTION_ID_GAS_CREQ:
+				CFGP2P_DBG(("%s P2P GAS Comback Request\n",
+					(tx)? "TX" : "RX"));
+				break;
+			case P2PSD_ACTION_ID_GAS_CRESP:
+				CFGP2P_DBG(("%s P2P GAS Comback Response\n",
+					(tx)? "TX" : "RX"));
+				break;
+			default:
+				CFGP2P_DBG(("%s Unknown P2P GAS Frame\n",
+					(tx)? "TX" : "RX"));
+		}
+
+
+	}
+
+}
+
 /*
  *  Initialize variables related to P2P
  *
@@ -110,9 +287,10 @@
 void
 wl_cfgp2p_deinit_priv(struct wl_priv *wl)
 {
+	CFGP2P_DBG(("In\n"));
+
 	if (wl->p2p) {
 		kfree(wl->p2p);
-		wl->p2p = NULL;
 	}
 	wl->p2p_supported = 0;
 }
@@ -142,7 +320,7 @@
 	 * firmware for P2P device address
 	 */
 	ret = wldev_iovar_setbuf_bsscfg(ndev, "p2p_da_override", &null_eth_addr,
-	            sizeof(null_eth_addr), ioctlbuf, sizeof(ioctlbuf), 0);
+		sizeof(null_eth_addr), wl->ioctl_buf, WLC_IOCTL_MAXLEN, 0, &wl->ioctl_buf_sync);
 	if (ret && ret != BCME_UNSUPPORTED) {
 		CFGP2P_ERR(("failed to update device address\n"));
 	}
@@ -175,7 +353,7 @@
 	        (chspec & WL_CHANSPEC_CHAN_MASK) >> WL_CHANSPEC_CHAN_SHIFT));
 
 	err = wldev_iovar_setbuf(ndev, "p2p_ifadd", &ifreq, sizeof(ifreq),
-		ioctlbuf, sizeof(ioctlbuf));
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 	return err;
 }
 
@@ -194,7 +372,7 @@
 	    netdev->ifindex, mac->octet[0], mac->octet[1], mac->octet[2],
 	    mac->octet[3], mac->octet[4], mac->octet[5]));
 	ret = wldev_iovar_setbuf(netdev, "p2p_ifdel", mac, sizeof(*mac),
-		ioctlbuf, sizeof(ioctlbuf));
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 	if (unlikely(ret < 0)) {
 		printk("'wl p2p_ifdel' error %d\n", ret);
 	}
@@ -225,7 +403,7 @@
 		(chspec & WL_CHANSPEC_CHAN_MASK) >> WL_CHANSPEC_CHAN_SHIFT));
 
 	err = wldev_iovar_setbuf(netdev, "p2p_ifupd", &ifreq, sizeof(ifreq),
-		ioctlbuf, sizeof(ioctlbuf));
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 
 	if (unlikely(err < 0)) {
 		printk("'wl p2p_ifupd' error %d\n", err);
@@ -251,8 +429,8 @@
 	    mac->octet[0], mac->octet[1], mac->octet[2],
 	    mac->octet[3], mac->octet[4], mac->octet[5]));
 
-	ret = wldev_iovar_getbuf_bsscfg(dev, "p2p_if", mac, sizeof(*mac),
-	            getbuf, sizeof(getbuf), wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_PRIMARY));
+	ret = wldev_iovar_getbuf_bsscfg(dev, "p2p_if", mac, sizeof(*mac), getbuf,
+		sizeof(getbuf), wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_PRIMARY), NULL);
 
 	if (ret == 0) {
 		memcpy(index, getbuf, sizeof(index));
@@ -262,7 +440,7 @@
 	return ret;
 }
 
-s32
+static s32
 wl_cfgp2p_set_discovery(struct wl_priv *wl, s32 on)
 {
 	s32 ret = BCME_OK;
@@ -311,13 +489,14 @@
 	discovery_mode.chspec = CH20MHZ_CHSPEC(channel);
 	discovery_mode.dwell = listen_ms;
 	ret = wldev_iovar_setbuf_bsscfg(dev, "p2p_state", &discovery_mode,
-	            sizeof(discovery_mode), ioctlbuf, sizeof(ioctlbuf), bssidx);
+		sizeof(discovery_mode), wl->ioctl_buf, WLC_IOCTL_MAXLEN,
+		bssidx, &wl->ioctl_buf_sync);
 
 	return ret;
 }
 
 /* Get the index of the P2P Discovery BSS */
-s32
+static s32
 wl_cfgp2p_get_disc_idx(struct wl_priv *wl, s32 *index)
 {
 	s32 ret;
@@ -381,7 +560,7 @@
  * @wl        : wl_private data
  * Returns 0 if succes
  */
-s32
+static s32
 wl_cfgp2p_deinit_discovery(struct wl_priv *wl)
 {
 	s32 ret = BCME_OK;
@@ -419,7 +598,8 @@
  * Returns 0 if success.
  */
 s32
-wl_cfgp2p_enable_discovery(struct wl_priv *wl, struct net_device *dev, const u8 *ie, u32 ie_len)
+wl_cfgp2p_enable_discovery(struct wl_priv *wl, struct net_device *dev,
+	const u8 *ie, u32 ie_len)
 {
 	s32 ret = BCME_OK;
 	if (wl_get_p2p_status(wl, DISCOVERY_ON)) {
@@ -511,9 +691,9 @@
 	wl_escan_params_t *eparams;
 	wlc_ssid_t ssid;
 	/* Scan parameters */
-#define P2PAPI_SCAN_NPROBES 4
-#define P2PAPI_SCAN_DWELL_TIME_MS 80
-#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 100
+#define P2PAPI_SCAN_NPROBES 1
+#define P2PAPI_SCAN_DWELL_TIME_MS 50
+#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
 #define P2PAPI_SCAN_HOME_TIME_MS 10
 	struct net_device *pri_dev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_PRIMARY);
 	wl_set_p2p_status(wl, SCANNING);
@@ -530,7 +710,7 @@
 		return -1;
 	}
 	memset(memblk, 0, memsize);
-	memset(ioctlbuf, 0, sizeof(ioctlbuf));
+	memset(wl->ioctl_buf, 0, WLC_IOCTL_MAXLEN);
 	if (search_state == WL_P2P_DISC_ST_SEARCH) {
 		/*
 		 * If we in SEARCH STATE, we don't need to set SSID explictly
@@ -569,7 +749,7 @@
 
 	eparams->params.nprobes = htod32(P2PAPI_SCAN_NPROBES);
 	eparams->params.home_time = htod32(P2PAPI_SCAN_HOME_TIME_MS);
-	if (wl_get_drv_status(wl, CONNECTED))
+	if (wl_get_drv_status_all(wl, CONNECTED))
 		eparams->params.active_time = htod32(-1);
 	else if (num_chans == 3)
 		eparams->params.active_time = htod32(P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS);
@@ -595,9 +775,54 @@
 	CFGP2P_INFO(("\n"));
 
 	ret = wldev_iovar_setbuf_bsscfg(pri_dev, "p2p_scan",
-	            memblk, memsize, smbuf, sizeof(ioctlbuf), bssidx);
+		memblk, memsize, wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 	return ret;
 }
+
+/* search function to reach at common channel to send action frame
+ * Parameters:
+ * @wl       : wl_private data
+ * @ndev     : net device for bssidx
+ * @bssidx   : bssidx for BSS
+ * Returns 0 if success.
+ */
+s32
+wl_cfgp2p_act_frm_search(struct wl_priv *wl, struct net_device *ndev,
+	s32 bssidx, s32 channel)
+{
+	s32 ret = 0;
+	u32 chan_cnt = 0;
+	u16 *default_chan_list = NULL;
+	if (!p2p_is_on(wl))
+		return -BCME_ERROR;
+	CFGP2P_ERR((" Enter\n"));
+	if (bssidx == P2PAPI_BSSCFG_PRIMARY)
+		bssidx =  wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE);
+	if (channel)
+		chan_cnt = 1;
+	else
+		chan_cnt = SOCIAL_CHAN_CNT;
+	default_chan_list = kzalloc(chan_cnt * sizeof(*default_chan_list), GFP_KERNEL);
+	if (default_chan_list == NULL) {
+		CFGP2P_ERR(("channel list allocation failed \n"));
+		ret = -ENOMEM;
+		goto exit;
+	}
+	if (channel) {
+		default_chan_list[0] = channel;
+	} else {
+		default_chan_list[0] = SOCIAL_CHAN_1;
+		default_chan_list[1] = SOCIAL_CHAN_2;
+		default_chan_list[2] = SOCIAL_CHAN_3;
+	}
+	ret = wl_cfgp2p_escan(wl, ndev, true, SOCIAL_CHAN_CNT,
+		default_chan_list, WL_P2P_DISC_ST_SEARCH,
+		WL_SCAN_ACTION_START, bssidx);
+	kfree(default_chan_list);
+exit:
+	return ret;
+}
+
 /* Check whether pointed-to IE looks like WPA. */
 #define wl_cfgp2p_is_wpa_ie(ie, tlvs, len)	wl_cfgp2p_has_ie(ie, tlvs, len, \
 		(const uint8 *)WPS_OUI, WPS_OUI_LEN, WPA_OUI_TYPE)
@@ -635,7 +860,7 @@
 	u8 delete = 0;
 #define IE_TYPE(type, bsstype) (wl_to_p2p_bss_saved_ie(wl, bsstype).p2p_ ## type ## _ie)
 #define IE_TYPE_LEN(type, bsstype) (wl_to_p2p_bss_saved_ie(wl, bsstype).p2p_ ## type ## _ie_len)
-	if (wl->p2p_supported && p2p_on(wl) && bssidx != -1) {
+	if (p2p_is_on(wl) && bssidx != -1) {
 		if (bssidx == P2PAPI_BSSCFG_PRIMARY)
 			bssidx =  wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE);
 		switch (pktflag) {
@@ -670,7 +895,7 @@
 				CFGP2P_ERR(("not suitable type\n"));
 				return -1;
 		}
-	} else if (get_mode_by_netdev(wl, ndev) == WL_MODE_AP) {
+	} else if (wl_get_mode_by_netdev(wl, ndev) == WL_MODE_AP) {
 		switch (pktflag) {
 			case VNDR_IE_PRBRSP_FLAG :
 				mgmt_ie_buf = wl->ap_info->probe_res_ie;
@@ -689,7 +914,7 @@
 				return -1;
 		}
 		bssidx = 0;
-	} else if (bssidx == -1 && get_mode_by_netdev(wl, ndev) == WL_MODE_BSS) {
+	} else if (bssidx == -1 && wl_get_mode_by_netdev(wl, ndev) == WL_MODE_BSS) {
 		switch (pktflag) {
 			case VNDR_IE_PRBREQ_FLAG :
 				mgmt_ie_buf = wl->sta_info->probe_req_ie;
@@ -735,8 +960,9 @@
 					CFGP2P_INFO(("DELELED ID : %d, Len : %d , OUI :"
 						"%02x:%02x:%02x\n", ie_id, ie_len, ie_buf[pos],
 						ie_buf[pos+1], ie_buf[pos+2]));
-					ret = wl_cfgp2p_vndr_ie(ndev, bssidx, pktflag, ie_buf+pos,
-					    VNDR_SPEC_ELEMENT_ID, ie_buf+pos+3, ie_len-3, delete);
+					ret = wl_cfgp2p_vndr_ie(wl, ndev, bssidx, pktflag,
+						ie_buf+pos, VNDR_SPEC_ELEMENT_ID, ie_buf+pos+3,
+						ie_len-3, delete);
 				}
 				pos += ie_len;
 			}
@@ -760,8 +986,9 @@
 					CFGP2P_INFO(("ADDED ID : %d, Len : %d , OUI :"
 						"%02x:%02x:%02x\n", ie_id, ie_len, ie_buf[pos],
 						ie_buf[pos+1], ie_buf[pos+2]));
-					ret = wl_cfgp2p_vndr_ie(ndev, bssidx, pktflag, ie_buf+pos,
-					    VNDR_SPEC_ELEMENT_ID, ie_buf+pos+3, ie_len-3, delete);
+					ret = wl_cfgp2p_vndr_ie(wl, ndev, bssidx, pktflag,
+						ie_buf+pos, VNDR_SPEC_ELEMENT_ID, ie_buf+pos+3,
+						ie_len-3, delete);
 				}
 				pos += ie_len;
 			}
@@ -867,7 +1094,7 @@
 }
 
 static s32
-wl_cfgp2p_vndr_ie(struct net_device *ndev, s32 bssidx, s32 pktflag,
+wl_cfgp2p_vndr_ie(struct wl_priv *wl, struct net_device *ndev, s32 bssidx, s32 pktflag,
             s8 *oui, s32 ie_id, s8 *data, s32 data_len, s32 delete)
 {
 	s32 err = BCME_OK;
@@ -909,7 +1136,7 @@
 	memcpy(ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.oui, oui, 3);
 	memcpy(ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.data, data, data_len);
 	err = wldev_iovar_setbuf_bsscfg(ndev, "vndr_ie", ie_setbuf, buf_len,
-		ioctlbuf, sizeof(ioctlbuf), bssidx);
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 
 	CFGP2P_INFO(("vndr_ie iovar returns %d\n", err));
 	kfree(ie_setbuf);
@@ -964,7 +1191,7 @@
 			del_timer_sync(&wl->p2p->listen_timer);
 			spin_unlock_bh(&wl->p2p->timer_lock);
 		}
-		cfg80211_remain_on_channel_expired(ndev, wl->cache_cookie, &wl->remain_on_chan,
+		cfg80211_remain_on_channel_expired(ndev, wl->last_roc_id, &wl->remain_on_chan,
 		    wl->remain_on_chan_type, GFP_KERNEL);
 	} else
 		wl_clr_p2p_status(wl, LISTEN_EXPIRED);
@@ -1093,10 +1320,10 @@
 			wl_set_p2p_status(wl, ACTION_TX_NOACK);
 			CFGP2P_ERR(("WLC_E_ACTION_FRAME_COMPLETE : NO ACK\n"));
 		}
-		wake_up_interruptible(&wl->dongle_event_wait);
 	} else {
 		CFGP2P_INFO((" WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE is received,"
 					"status : %d\n", status));
+		wake_up_interruptible(&wl->netif_change_event);
 	}
 	return ret;
 }
@@ -1126,15 +1353,15 @@
 	if (bssidx == P2PAPI_BSSCFG_PRIMARY)
 		bssidx =  wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE);
 
-	ret = wldev_iovar_setbuf_bsscfg(dev, "actframe",
-	           af_params, sizeof(*af_params), ioctlbuf, sizeof(ioctlbuf), bssidx);
+	ret = wldev_iovar_setbuf_bsscfg(dev, "actframe", af_params, sizeof(*af_params),
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
 
 	if (ret < 0) {
 
 		CFGP2P_ERR((" sending action frame is failed\n"));
 		goto exit;
 	}
-	timeout = wait_event_interruptible_timeout(wl->dongle_event_wait,
+	timeout = wait_event_interruptible_timeout(wl->netif_change_event,
 	(wl_get_p2p_status(wl, ACTION_TX_COMPLETED) || wl_get_p2p_status(wl, ACTION_TX_NOACK)),
 	msecs_to_jiffies(MAX_WAIT_TIME));
 
@@ -1243,7 +1470,7 @@
 	/* Check if the BSS is up */
 	*(int*)getbuf = -1;
 	result = wldev_iovar_getbuf_bsscfg(ndev, "bss", &bsscfg_idx,
-	                    sizeof(bsscfg_idx), getbuf, sizeof(getbuf), 0);
+		sizeof(bsscfg_idx), getbuf, sizeof(getbuf), 0, NULL);
 	if (result != 0) {
 		CFGP2P_ERR(("'wl bss -C %d' failed: %d\n", bsscfg_idx, result));
 		CFGP2P_ERR(("NOTE: this ioctl error is normal "
@@ -1260,7 +1487,7 @@
 
 /* Bring up or down a BSS */
 s32
-wl_cfgp2p_bss(struct net_device *ndev, s32 bsscfg_idx, s32 up)
+wl_cfgp2p_bss(struct wl_priv *wl, struct net_device *ndev, s32 bsscfg_idx, s32 up)
 {
 	s32 ret = BCME_OK;
 	s32 val = up ? 1 : 0;
@@ -1274,7 +1501,7 @@
 	bss_setbuf.val = htod32(val);
 	CFGP2P_INFO(("---wl bss -C %d %s\n", bsscfg_idx, up ? "up" : "down"));
 	ret = wldev_iovar_setbuf(ndev, "bss", &bss_setbuf, sizeof(bss_setbuf),
-		ioctlbuf, sizeof(ioctlbuf));
+		wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 
 	if (ret != 0) {
 		CFGP2P_ERR(("'bss %d' failed with %d\n", up, ret));
@@ -1303,7 +1530,6 @@
 	}
 	return p2p_supported;
 }
-
 /* Cleanup P2P resources */
 s32
 wl_cfgp2p_down(struct wl_priv *wl)
@@ -1313,8 +1539,8 @@
 	wl_cfgp2p_deinit_priv(wl);
 	return 0;
 }
-
-s32 wl_cfgp2p_set_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len)
+s32
+wl_cfgp2p_set_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len)
 {
 	s32 ret = -1;
 	int count, start, duration;
@@ -1330,7 +1556,7 @@
 
 		sscanf(buf, "%d %d %d", &count, &start, &duration);
 		CFGP2P_DBG(("set_p2p_noa count %d start %d duration %d\n",
-				count, start, duration));
+			count, start, duration));
 		if (count != -1)
 			wl->p2p->noa.desc[0].count = count;
 
@@ -1374,7 +1600,8 @@
 		dongle_noa.desc[0].interval = htod32(wl->p2p->noa.desc[0].interval*1000);
 
 		ret = wldev_iovar_setbuf(wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION),
-			"p2p_noa", &dongle_noa, sizeof(dongle_noa), ioctlbuf, sizeof(ioctlbuf));
+			"p2p_noa", &dongle_noa, sizeof(dongle_noa), wl->ioctl_buf, WLC_IOCTL_MAXLEN,
+			&wl->ioctl_buf_sync);
 
 		if (ret < 0) {
 			CFGP2P_ERR(("fw set p2p_noa failed %d\n", ret));
@@ -1385,9 +1612,10 @@
 	}
 	return ret;
 }
-
-s32 wl_cfgp2p_get_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int buf_len)
+s32
+wl_cfgp2p_get_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int buf_len)
 {
+
 	wifi_p2p_noa_desc_t *noa_desc;
 	int len = 0, i;
 	char _buf[200];
@@ -1427,8 +1655,8 @@
 	}
 	return len * 2;
 }
-
-s32 wl_cfgp2p_set_p2p_ps(struct wl_priv *wl, struct net_device *ndev, char* buf, int len)
+s32
+wl_cfgp2p_set_p2p_ps(struct wl_priv *wl, struct net_device *ndev, char* buf, int len)
 {
 	int ps, ctw;
 	int ret = -1;
@@ -1446,20 +1674,21 @@
 			wl->p2p->ops.ops = ps;
 			ret = wldev_iovar_setbuf(wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION),
 				"p2p_ops", &wl->p2p->ops, sizeof(wl->p2p->ops),
-				ioctlbuf, sizeof(ioctlbuf));
+				wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
 			if (ret < 0) {
 				CFGP2P_ERR(("fw set p2p_ops failed %d\n", ret));
 			}
 		}
 
-		if (legacy_ps != -1) {
-			s32 pm = legacy_ps ? PM_MAX : PM_OFF;
+		if ((legacy_ps != -1) && ((legacy_ps == PM_MAX) || (legacy_ps == PM_OFF))) {
 			ret = wldev_ioctl(wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION),
-				WLC_SET_PM, &pm, sizeof(pm), true);
+				WLC_SET_PM, &legacy_ps, sizeof(legacy_ps), true);
 			if (unlikely(ret)) {
 				CFGP2P_ERR(("error (%d)\n", ret));
 			}
 		}
+		else
+			CFGP2P_ERR(("ilegal setting\n"));
 	}
 	else {
 		CFGP2P_ERR(("ERROR: set_p2p_ps in non-p2p mode\n"));
@@ -1467,3 +1696,238 @@
 	}
 	return ret;
 }
+
+u8 *
+wl_cfgp2p_retreive_p2pattrib(void *buf, u8 element_id)
+{
+	wifi_p2p_ie_t *ie = NULL;
+	u16 len = 0;
+	u8 *subel;
+	u8 subelt_id;
+	u16 subelt_len;
+
+	if (!buf) {
+		WL_ERR(("P2P IE not present"));
+		return 0;
+	}
+
+	ie = (wifi_p2p_ie_t*) buf;
+	len = ie->len;
+
+	/* Point subel to the P2P IE's subelt field.
+	 * Subtract the preceding fields (id, len, OUI, oui_type) from the length.
+	 */
+	subel = ie->subelts;
+	len -= 4;	/* exclude OUI + OUI_TYPE */
+
+	while (len >= 3) {
+	/* attribute id */
+		subelt_id = *subel;
+		subel += 1;
+		len -= 1;
+
+		/* 2-byte little endian */
+		subelt_len = *subel++;
+		subelt_len |= *subel++ << 8;
+
+		len -= 2;
+		len -= subelt_len;	/* for the remaining subelt fields */
+
+		if (subelt_id == element_id) {
+			/* This will point to start of subelement attrib after
+			 * attribute id & len
+			 */
+			return subel;
+		}
+
+		/* Go to next subelement */
+		subel += subelt_len;
+	}
+
+	/* Not Found */
+	return NULL;
+}
+
+#define P2P_GROUP_CAPAB_GO_BIT	0x01
+u8 *
+wl_cfgp2p_retreive_p2p_dev_addr(wl_bss_info_t *bi, u32 bi_length)
+{
+	wifi_p2p_ie_t * p2p_ie = NULL;
+	u8 *capability = NULL;
+	bool p2p_go	= 0;
+	u8 *ptr = NULL;
+
+	if (!(p2p_ie = wl_cfgp2p_find_p2pie(((u8 *) bi) + bi->ie_offset, bi->ie_length))) {
+		WL_ERR(("P2P IE not found"));
+		return NULL;
+	}
+
+	if (!(capability = wl_cfgp2p_retreive_p2pattrib(p2p_ie, P2P_SEID_P2P_INFO))) {
+		WL_ERR(("P2P Capability attribute not found"));
+		return NULL;
+	}
+
+	/* Check Group capability for Group Owner bit */
+	p2p_go = capability[1] & P2P_GROUP_CAPAB_GO_BIT;
+	if (!p2p_go) {
+		return bi->BSSID.octet;
+	}
+
+	/* In probe responses, DEVICE INFO attribute will be present */
+	if (!(ptr = wl_cfgp2p_retreive_p2pattrib(p2p_ie, P2P_SEID_DEV_INFO))) {
+		/* If DEVICE_INFO is not found, this might be a beacon frame.
+		 * check for DEVICE_ID in the beacon frame.
+		 */
+		ptr = wl_cfgp2p_retreive_p2pattrib(p2p_ie, P2P_SEID_DEV_ID);
+	}
+
+	if (!ptr)
+		WL_ERR((" Both DEVICE_ID & DEVICE_INFO attribute not present in P2P IE "));
+
+	return ptr;
+}
+
+s32
+wl_cfgp2p_register_ndev(struct wl_priv *wl)
+{
+	int ret = 0;
+	struct net_device* net = NULL;
+	struct wireless_dev *wdev;
+	uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x33, 0x22, 0x11 };
+
+	/* Allocate etherdev, including space for private structure */
+	if (!(net = alloc_etherdev(sizeof(wl)))) {
+		CFGP2P_ERR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
+		goto fail;
+	}
+
+	strcpy(net->name, "p2p%d");
+	net->name[IFNAMSIZ - 1] = '\0';
+
+	/* Copy the reference to wl_priv */
+	memcpy((void *)netdev_priv(net), &wl, sizeof(wl));
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
+	ASSERT(!net->open);
+	net->do_ioctl = wl_cfgp2p_do_ioctl;
+	net->hard_start_xmit = wl_cfgp2p_start_xmit;
+	net->open = wl_cfgp2p_if_open;
+	net->stop = wl_cfgp2p_if_stop;
+#else
+	ASSERT(!net->netdev_ops);
+	net->netdev_ops = &wl_cfgp2p_if_ops;
+#endif
+
+	/* Register with a dummy MAC addr */
+	memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
+
+	wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
+	if (unlikely(!wdev)) {
+		WL_ERR(("Could not allocate wireless device\n"));
+		return -ENOMEM;
+	}
+
+	wdev->wiphy = wl->wdev->wiphy;
+
+	wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS);
+
+	net->ieee80211_ptr = wdev;
+
+	SET_NETDEV_DEV(net, wiphy_dev(wdev->wiphy));
+
+	/* Associate p2p0 network interface with new wdev */
+	wdev->netdev = net;
+
+	/* store p2p net ptr for further reference. Note that iflist won't have this
+	 * entry as there corresponding firmware interface is a "Hidden" interface.
+	 */
+	if (wl->p2p_net) {
+		CFGP2P_ERR(("p2p_net defined already.\n"));
+		return -EINVAL;
+	} else {
+		wl->p2p_wdev = wdev;
+		wl->p2p_net = net;
+	}
+
+	ret = register_netdev(net);
+	if (ret) {
+		CFGP2P_ERR((" register_netdevice failed (%d)\n", ret));
+		goto fail;
+	}
+
+	printk("%s: P2P Interface Registered\n", net->name);
+
+	return ret;
+fail:
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
+	net->open = NULL;
+#else
+	net->netdev_ops = NULL;
+#endif
+
+	if (net) {
+		unregister_netdev(net);
+		free_netdev(net);
+	}
+
+	return -ENODEV;
+}
+
+s32
+wl_cfgp2p_unregister_ndev(struct wl_priv *wl)
+{
+
+	if (!wl || !wl->p2p_net) {
+		CFGP2P_ERR(("Invalid Ptr\n"));
+		return -EINVAL;
+	}
+
+	unregister_netdev(wl->p2p_net);
+	free_netdev(wl->p2p_net);
+
+	return 0;
+}
+static int wl_cfgp2p_start_xmit(struct sk_buff *skb, struct net_device *ndev)
+{
+	CFGP2P_DBG(("(%s) is not used for data operations. Droping the packet. \n", ndev->name));
+	return 0;
+}
+
+static int wl_cfgp2p_do_ioctl(struct net_device *net, struct ifreq *ifr, int cmd)
+{
+	int ret = 0;
+	struct wl_priv *wl = *(struct wl_priv **)netdev_priv(net);
+	struct net_device *ndev = wl_to_prmry_ndev(wl);
+
+	/* There is no ifidx corresponding to p2p0 in our firmware. So we should
+	 * not Handle any IOCTL cmds on p2p0 other than ANDROID PRIVATE CMDs.
+	 * For Android PRIV CMD handling map it to primary I/F
+	 */
+	if (cmd == SIOCDEVPRIVATE+1) {
+#if defined(OEM_ANROID)
+		ret = wl_android_priv_cmd(ndev, ifr, cmd);
+#else
+	(void)ndev;
+#endif
+
+	} else {
+		CFGP2P_ERR(("%s: IOCTL req 0x%x on p2p0 I/F. Ignoring. \n",
+		__FUNCTION__, cmd));
+		return -1;
+	}
+
+	return ret;
+}
+
+static int wl_cfgp2p_if_open(struct net_device *net)
+{
+	CFGP2P_DBG(("Do Nothing \n"));
+	return 0;
+}
+
+static int wl_cfgp2p_if_stop(struct net_device *net)
+{
+	CFGP2P_DBG(("Do Nothing \n"));
+	return 0;
+}
diff --git a/drivers/net/wireless/bcmdhd/wl_cfgp2p.h b/drivers/net/wireless/bcmdhd/wl_cfgp2p.h
index 5a69168..4d24ae5 100644
--- a/drivers/net/wireless/bcmdhd/wl_cfgp2p.h
+++ b/drivers/net/wireless/bcmdhd/wl_cfgp2p.h
@@ -2,13 +2,13 @@
  * Linux cfgp2p driver
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -103,11 +103,11 @@
 #define wl_to_p2p_bss(wl, type) ((wl)->p2p->bss_idx[type])
 #define wl_get_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : test_bit(WLP2P_STATUS_ ## stat, \
 									&(wl)->p2p->status))
-#define wl_set_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? : set_bit(WLP2P_STATUS_ ## stat, \
+#define wl_set_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : set_bit(WLP2P_STATUS_ ## stat, \
 									&(wl)->p2p->status))
-#define wl_clr_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? : clear_bit(WLP2P_STATUS_ ## stat, \
+#define wl_clr_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : clear_bit(WLP2P_STATUS_ ## stat, \
 									&(wl)->p2p->status))
-#define wl_chg_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? : change_bit(WLP2P_STATUS_ ## stat, \
+#define wl_chg_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0: change_bit(WLP2P_STATUS_ ## stat, \
 									&(wl)->p2p->status))
 #define p2p_on(wl) ((wl)->p2p->on)
 #define p2p_scan(wl) ((wl)->p2p->scan)
@@ -140,7 +140,14 @@
 		}									\
 	} while (0)
 
-
+extern bool
+wl_cfgp2p_is_pub_action(void *frame, u32 frame_len);
+extern bool
+wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len);
+extern bool
+wl_cfgp2p_is_gas_action(void *frame, u32 frame_len);
+extern void
+wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len);
 extern s32
 wl_cfgp2p_init_priv(struct wl_priv *wl);
 extern void
@@ -172,6 +179,10 @@
 	u16 *channels,
 	s32 search_state, u16 action, u32 bssidx);
 
+extern s32
+wl_cfgp2p_act_frm_search(struct wl_priv *wl, struct net_device *ndev,
+	s32 bssidx, s32 channel);
+
 extern wpa_ie_fixed_t *
 wl_cfgp2p_find_wpaie(u8 *parse, u32 len);
 
@@ -217,7 +228,7 @@
 wl_cfgp2p_bss_isup(struct net_device *ndev, int bsscfg_idx);
 
 extern s32
-wl_cfgp2p_bss(struct net_device *ndev, s32 bsscfg_idx, s32 up);
+wl_cfgp2p_bss(struct wl_priv *wl, struct net_device *ndev, s32 bsscfg_idx, s32 up);
 
 
 extern s32
@@ -235,13 +246,36 @@
 extern s32
 wl_cfgp2p_set_p2p_ps(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
 
+extern u8 *
+wl_cfgp2p_retreive_p2pattrib(void *buf, u8 element_id);
+
+extern u8 *
+wl_cfgp2p_retreive_p2p_dev_addr(wl_bss_info_t *bi, u32 bi_length);
+
+extern s32
+wl_cfgp2p_register_ndev(struct wl_priv *wl);
+
+extern s32
+wl_cfgp2p_unregister_ndev(struct wl_priv *wl);
+
 /* WiFi Direct */
 #define SOCIAL_CHAN_1 1
 #define SOCIAL_CHAN_2 6
 #define SOCIAL_CHAN_3 11
+#define SOCIAL_CHAN_CNT 3
 #define WL_P2P_WILDCARD_SSID "DIRECT-"
 #define WL_P2P_WILDCARD_SSID_LEN 7
 #define WL_P2P_INTERFACE_PREFIX "p2p"
 #define WL_P2P_TEMP_CHAN "11"
+
+
+#define IS_GAS_REQ(frame, len) (wl_cfgp2p_is_gas_action(frame, len) && \
+					((frame->action == P2PSD_ACTION_ID_GAS_IREQ) || \
+					(frame->action == P2PSD_ACTION_ID_GAS_CREQ)))
+#define IS_P2P_PUB_ACT_REQ(frame, len) (wl_cfgp2p_is_pub_action(frame, len) && \
+						((frame->subtype == P2P_PAF_GON_REQ) || \
+						(frame->subtype == P2P_PAF_INVITE_REQ) || \
+						(frame->subtype == P2P_PAF_PROVDIS_REQ)))
+#define IS_P2P_SOCIAL(ch) ((ch == SOCIAL_CHAN_1) || (ch == SOCIAL_CHAN_2) || (ch == SOCIAL_CHAN_3))
 #define IS_P2P_SSID(ssid) (memcmp(ssid, WL_P2P_WILDCARD_SSID, WL_P2P_WILDCARD_SSID_LEN) == 0)
 #endif				/* _wl_cfgp2p_h_ */
diff --git a/drivers/net/wireless/bcmdhd/wl_dbg.h b/drivers/net/wireless/bcmdhd/wl_dbg.h
index 0b99557..410f46f 100644
--- a/drivers/net/wireless/bcmdhd/wl_dbg.h
+++ b/drivers/net/wireless/bcmdhd/wl_dbg.h
@@ -3,13 +3,13 @@
  * Broadcom 802.11 Networking Adapter.
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,12 +17,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wl_dbg.h,v 1.115.6.3 2010-12-15 21:42:23 Exp $
+ * $Id: wl_dbg.h,v 1.115.6.3 2010-12-15 21:42:23 $
  */
 
 
@@ -46,4 +46,4 @@
 
 extern uint32 wl_msg_level;
 extern uint32 wl_msg_level2;
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/wl_iw.c b/drivers/net/wireless/bcmdhd/wl_iw.c
index ba3cc6c8..9cde2e0 100644
--- a/drivers/net/wireless/bcmdhd/wl_iw.c
+++ b/drivers/net/wireless/bcmdhd/wl_iw.c
@@ -2,13 +2,13 @@
  * Linux Wireless Extensions support
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wl_iw.c,v 1.132.2.18 2011-02-05 01:44:47 Exp $
+ * $Id: wl_iw.c,v 1.132.2.18 2011-02-05 01:44:47 $
  */
 
 #include <wlioctl.h>
@@ -36,6 +36,8 @@
 
 #include <linux/if_arp.h>
 #include <asm/uaccess.h>
+#include <linux/kernel.h>
+#include <linux/mmc/host.h>
 
 #include <dngl_stats.h>
 #include <dhd.h>
@@ -66,14 +68,16 @@
 
 #define JF2MS ((((jiffies / HZ) * 1000) + ((jiffies % HZ) * 1000) / HZ))
 
-#ifdef COEX_DBG       
+#define BTCOEX_FORCE_PM1
+
+#ifdef COEX_DBG
 #define WL_TRACE_COEX(x) printf("TS:%lu ", JF2MS); \
 							printf x
 #else
 #define WL_TRACE_COEX(x)
 #endif
 
-#ifdef SCAN_DBG        
+#ifdef SCAN_DBG
 #define WL_TRACE_SCAN(x) printf("TS:%lu ", JF2MS); \
 							printf x
 #else
@@ -84,9 +88,37 @@
 #include <wl_iw.h>
 
 
+#ifdef WAPI
+#ifndef IW_ENCODE_ALG_SM4
+#define IW_ENCODE_ALG_SM4 0x20
+#endif
 
+#ifndef IW_AUTH_WAPI_ENABLED
+#define IW_AUTH_WAPI_ENABLED 0x20
+#endif
 
+#ifndef IW_AUTH_WAPI_VERSION_1
+#define IW_AUTH_WAPI_VERSION_1	0x00000008
+#endif
+
+#ifndef IW_AUTH_CIPHER_SMS4
+#define IW_AUTH_CIPHER_SMS4	0x00000020
+#endif
+
+#ifndef IW_AUTH_KEY_MGMT_WAPI_PSK
+#define IW_AUTH_KEY_MGMT_WAPI_PSK 4
+#endif
+
+#ifndef IW_AUTH_KEY_MGMT_WAPI_CERT
+#define IW_AUTH_KEY_MGMT_WAPI_CERT 8
+#endif
+#endif /* WAPI */
+
+#ifndef WAPI
 #define IW_WSEC_ENABLED(wsec)	((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))
+#else
+#define IW_WSEC_ENABLED(wsec)	((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED | SMS4_ENABLED))
+#endif /* WAPI */
 
 #include <linux/rtnetlink.h>
 
@@ -97,9 +129,9 @@
 bool g_set_essid_before_scan = TRUE;
 #endif
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
-	struct mutex  g_wl_ss_scan_lock; 
-#endif 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
+	struct mutex  g_wl_ss_scan_lock;
+#endif
 
 #if defined(SOFTAP)
 #define WL_SOFTAP(x)
@@ -110,7 +142,7 @@
 tsk_ctl_t ap_eth_ctl;
 static int wl_iw_set_ap_security(struct net_device *dev, struct ap_profile *ap);
 static int wl_iw_softap_deassoc_stations(struct net_device *dev, u8 *mac);
-#endif 
+#endif
 
 
 #define WL_IW_IOCTL_CALL(func_call) \
@@ -128,10 +160,11 @@
 wl_iw_extra_params_t	g_wl_iw_params;
 
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
 
 static struct mutex	wl_cache_lock;
 static struct mutex	wl_softap_lock;
+static struct mutex	wl_wps_lock;
 
 #define DHD_OS_MUTEX_INIT(a) mutex_init(a)
 #define DHD_OS_MUTEX_LOCK(a) mutex_lock(a)
@@ -143,7 +176,7 @@
 #define DHD_OS_MUTEX_LOCK(a)
 #define DHD_OS_MUTEX_UNLOCK(a)
 
-#endif 
+#endif
 
 #include <bcmsdbus.h>
 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
@@ -166,53 +199,51 @@
 
 extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
 extern int dhd_wait_pend8021x(struct net_device *dev);
-#endif 
+#endif
 
 #if WIRELESS_EXT < 19
 #define IW_IOCTL_IDX(cmd)	((cmd) - SIOCIWFIRST)
 #define IW_EVENT_IDX(cmd)	((cmd) - IWEVFIRST)
-#endif 
+#endif
 
 static void *g_scan = NULL;
-static volatile uint g_scan_specified_ssid;	
-static wlc_ssid_t g_specific_ssid;		
+static volatile uint g_scan_specified_ssid;
+static wlc_ssid_t g_specific_ssid;
 
 static wlc_ssid_t g_ssid;
 
-#ifdef CONFIG_WPS2
-static char *g_wps_probe_req_ie;
-static int g_wps_probe_req_ie_len;
-#endif
+char *g_wps_probe_req_ie;
+int g_wps_probe_req_ie_len;
 
-bool btcoex_is_sco_active(struct net_device *dev);  
-static wl_iw_ss_cache_ctrl_t g_ss_cache_ctrl;	
+bool btcoex_is_sco_active(struct net_device *dev);
+static wl_iw_ss_cache_ctrl_t g_ss_cache_ctrl;
 #if defined(CONFIG_FIRST_SCAN)
-static volatile uint g_first_broadcast_scan;	
+static volatile uint g_first_broadcast_scan;
 static volatile uint g_first_counter_scans;
 #define MAX_ALLOWED_BLOCK_SCAN_FROM_FIRST_SCAN 3
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
 #define DAEMONIZE(a) daemonize(a); \
 	allow_signal(SIGKILL); \
 	allow_signal(SIGTERM);
-#else 
+#else
 #define RAISE_RX_SOFTIRQ() \
 	cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
 #define DAEMONIZE(a) daemonize(); \
 	do { if (a) \
 		strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
 	} while (0);
-#endif 
+#endif
 
 #if defined(WL_IW_USE_ISCAN)
 #if  !defined(CSCAN)
 static void wl_iw_free_ss_cache(void);
 static int   wl_iw_run_ss_cache_timer(int kick_off);
-#endif 
+#endif
 #if defined(CONFIG_FIRST_SCAN)
 int  wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
-#endif 
+#endif
 static int dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len);
 #define ISCAN_STATE_IDLE   0
 #define ISCAN_STATE_SCANING 1
@@ -233,29 +264,29 @@
 	iscan_buf_t * list_hdr;
 	iscan_buf_t * list_cur;
 
-	
+
 	tsk_ctl_t tsk_ctl;
 
-	uint32 scan_flag;	
+	uint32 scan_flag;
 #if defined CSCAN
 	char ioctlbuf[WLC_IOCTL_MEDLEN];
 #else
 	char ioctlbuf[WLC_IOCTL_SMLEN];
-#endif 
-	
+#endif
+
 	wl_iscan_params_t *iscan_ex_params_p;
 	int iscan_ex_param_size;
 } iscan_info_t;
 
 
 
-#define  COEX_DHCP 1	
+#define  COEX_DHCP 1
 #ifdef COEX_DHCP
 
-#define BT_DHCP_eSCO_FIX 
-#define BT_DHCP_USE_FLAGS  
-#define BT_DHCP_OPPORTUNITY_WINDOW_TIME	 2500 
-#define BT_DHCP_FLAG_FORCE_TIME 5500 
+#define BT_DHCP_eSCO_FIX
+#define BT_DHCP_USE_FLAGS
+#define BT_DHCP_OPPORTUNITY_WINDOW_TIME	 2500
+#define BT_DHCP_FLAG_FORCE_TIME 5500
 
 
 
@@ -282,26 +313,27 @@
 	struct timer_list timer;
 	uint32 timer_ms;
 	uint32 timer_on;
-	uint32 ts_dhcp_start; 
-	uint32 ts_dhcp_ok;    
-	bool	dhcp_done; 
+	uint32 ts_dhcp_start;
+	uint32 ts_dhcp_ok;
+	bool	dhcp_done;
+	bool    link_up;
 	int	bt_state;
 
-	
+
 	tsk_ctl_t tsk_ctl;
 
 } bt_info_t;
 
 bt_info_t *g_bt = NULL;
 static void wl_iw_bt_timerfunc(ulong data);
-#endif 
+#endif
 iscan_info_t *g_iscan = NULL;
 void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
 static void wl_iw_timerfunc(ulong data);
 static void wl_iw_set_event_mask(struct net_device *dev);
 static int
 wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action);
-#endif 
+#endif
 
 static int
 wl_iw_set_scan(
@@ -327,7 +359,7 @@
 	char *extra,
 	short max_size
 );
-#endif 
+#endif
 
 static void
 swap_key_from_BE(
@@ -389,7 +421,7 @@
 		strcpy(ifr.ifr_name, dev->name);
 		ifr.ifr_data = (caddr_t) &ioc;
 
-		
+
 		ret = dev_open(dev);
 		if (ret) {
 			WL_ERROR(("%s: Error dev_open: %d\n", __func__, ret));
@@ -403,7 +435,7 @@
 		ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
 #else
 		ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
-#endif 
+#endif
 		set_fs(fs);
 	}
 	else {
@@ -511,7 +543,7 @@
 
 	return (dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen));
 }
-#endif 
+#endif
 
 
 #if WIRELESS_EXT > 17
@@ -525,7 +557,7 @@
 	char ioctlbuf[MAX_WLIW_IOCTL_LEN];
 #else
 	static char ioctlbuf[MAX_WLIW_IOCTL_LEN];
-#endif 
+#endif
 	uint buflen;
 
 	buflen = bcm_mkiovar(name, buf, len, ioctlbuf, sizeof(ioctlbuf));
@@ -533,7 +565,7 @@
 
 	return (dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen));
 }
-#endif 
+#endif
 
 
 static int
@@ -546,7 +578,7 @@
 	char ioctlbuf[MAX_WLIW_IOCTL_LEN];
 #else
 	static char ioctlbuf[MAX_WLIW_IOCTL_LEN];
-#endif 
+#endif
 	int error;
 	uint len;
 
@@ -601,12 +633,12 @@
 
 #if defined(WL_IW_USE_ISCAN)
 	if (g_iscan->iscan_state == ISCAN_STATE_IDLE)
-#endif 
+#endif
 		error = dev_wlc_ioctl(dev, WLC_SET_PASSIVE_SCAN, &as, sizeof(as));
 #if defined(WL_IW_USE_ISCAN)
 	else
 		g_iscan->scan_flag = as;
-#endif 
+#endif
 	p += snprintf(p, MAX_WX_STRING, "OK");
 
 	wrqu->data.length = p - extra + 1;
@@ -627,9 +659,9 @@
 
 #if defined(WL_IW_USE_ISCAN)
 	if (g_iscan->iscan_state == ISCAN_STATE_IDLE) {
-#endif 
+#endif
 
-		 
+
 		if (g_scan_specified_ssid == 0) {
 			error = dev_wlc_ioctl(dev, WLC_SET_PASSIVE_SCAN, &ps, sizeof(ps));
 		}
@@ -637,7 +669,7 @@
 	}
 	else
 		g_iscan->scan_flag = ps;
-#endif 
+#endif
 
 	p += snprintf(p, MAX_WX_STRING, "OK");
 
@@ -689,7 +721,7 @@
 	struct ether_addr *id;
 	char *p = extra;
 
-	
+
 	strcpy(buf, "cur_etheraddr");
 	error = dev_wlc_ioctl(dev, WLC_GET_VAR, buf, sizeof(buf));
 	id = (struct ether_addr *) buf;
@@ -724,16 +756,16 @@
 	memset(country_code, 0, sizeof(country_code));
 	memset(smbuf, 0, sizeof(smbuf));
 
-	
+
 	country_offset = strcspn(extra, " ");
 	country_code_size = strlen(extra) - country_offset;
 
-	
+
 	if (country_offset != 0) {
 		strncpy(country_code, extra + country_offset +1,
 			MIN(country_code_size, sizeof(country_code)));
 
-		
+
 		bzero(&scbval, sizeof(scb_val_t));
 		if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
 			WL_ERROR(("%s: set country failed due to Disassoc error\n", __FUNCTION__));
@@ -745,7 +777,7 @@
 
 		get_customized_country_code((char *)&cspec.country_abbrev, &cspec);
 
-		
+
 		if ((error = dev_iw_iovar_setbuf(dev, "country", &cspec,
 			sizeof(cspec), smbuf, sizeof(smbuf))) >= 0) {
 			p += snprintf(p, MAX_WX_STRING, "OK");
@@ -792,22 +824,22 @@
 		dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm));
 		dev_wlc_ioctl(dev, WLC_SET_PM, &pm_local, sizeof(pm_local));
 
-		
+
 		net_os_set_packet_filter(dev, 0);
 
 #ifdef COEX_DHCP
 		g_bt->ts_dhcp_start = JF2MS;
 		g_bt->dhcp_done = FALSE;
-		WL_TRACE_COEX(("%s: DHCP start, pm:%d changed to pm:%d\n",
+		WL_TRACE_COEX(("%s: pm:%d changed to pm:%d\n",
 			__FUNCTION__, pm, pm_local));
 
-#endif 
+#endif
 	} else if (strnicmp((char *)&powermode_val, "0", strlen("0")) == 0) {
-		
+
 
 		dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
 
-		
+
 		net_os_set_packet_filter(dev, 1);
 
 #ifdef COEX_DHCP
@@ -815,7 +847,11 @@
 		g_bt->ts_dhcp_ok = JF2MS;
 		WL_TRACE_COEX(("%s: DHCP done for:%d ms, restored pm:%d\n",
 			__FUNCTION__, (g_bt->ts_dhcp_ok - g_bt->ts_dhcp_start), pm));
-#endif 
+#endif
+
+#ifdef BTCOEX_FORCE_PM1
+	up(&g_bt->tsk_ctl.sema);
+#endif
 
 	} else {
 		WL_ERROR(("%s Unkwown yet power setting, ignored\n",
@@ -836,32 +872,46 @@
 	bool res = FALSE;
 	int sco_id_cnt = 0;
 	int param27;
-	int i;
+	int i = 0;
+	int ts1,ts2, mpc;
 
-	for (i = 0; i < 12; i++) {
+	ts1 = JF2MS;
 
+	mpc = 0;
+
+	if ((ioc_res = dev_wlc_intvar_set(dev, "mpc", mpc))) {
+		WL_ERROR(("%s fail to set mpc\n", __FUNCTION__));
+	}
+
+	while (1) {
+
+		i++;
 		ioc_res = dev_wlc_intvar_get_reg(dev, "btc_params", 27, &param27);
 
-		WL_TRACE_COEX(("%s, sample[%d], btc params: 27:%x\n",
-			__FUNCTION__, i, param27));
-
 		if (ioc_res < 0) {
-			WL_ERROR(("%s ioc read btc params error\n", __FUNCTION__));
-			break;
+			WL_ERROR(("%s couldn't perform ioctl at this time\n", __FUNCTION__));
 		}
 
-		if ((param27 & 0x6) == 2) { 
+		if ((param27 & 0xE) == 2) {
 			sco_id_cnt++;
 		}
 
-		if (sco_id_cnt > 2) {
-			WL_TRACE_COEX(("%s, sco/esco detected, pkt id_cnt:%d  samples:%d\n",
-				__FUNCTION__, sco_id_cnt, i));
+		if (sco_id_cnt >= 1) {
 			res = TRUE;
 			break;
 		}
 
-		msleep(5);
+		if (JF2MS - ts1 > 50)
+			break;
+	}
+
+	ts2 = JF2MS;
+	WL_TRACE_COEX(("%s sco_id_cnt:%d, result: %d , samples:%d, rt:%d\n",
+		__FUNCTION__, sco_id_cnt, res, i, ts2-ts1));
+
+	mpc = 1;
+	if ((ioc_res = dev_wlc_intvar_set(dev, "mpc", mpc))) {
+		WL_ERROR(("%s fail to set mpc\n", __FUNCTION__));
 	}
 
 	return res;
@@ -886,9 +936,9 @@
 	static uint32 saved_reg65;
 	static uint32 saved_reg71;
 
-	if (trump_sco) { 
+	if (trump_sco) {
 
-		
+
 		WL_TRACE_COEX(("Do new SCO/eSCO coex algo {save & override} \n"));
 
 
@@ -928,7 +978,7 @@
 		saved_status = TRUE;
 
 	} else if (saved_status) {
-		
+
 		WL_TRACE_COEX(("Do new SCO/eSCO coex algo {save & override} \n"));
 
 		regaddr = 50;
@@ -959,7 +1009,7 @@
 	}
 	return 0;
 }
-#endif 
+#endif
 
 
 static int
@@ -978,9 +1028,9 @@
 	if (!error) {
 		WL_TRACE(("%s: Powermode = %d\n", __func__, pm_local));
 		if (pm_local == PM_OFF)
-			pm_local = 1; 
+			pm_local = 1;
 		else
-			pm_local = 0; 
+			pm_local = 0;
 		p += snprintf(p, MAX_WX_STRING, "powermode = %d", pm_local);
 	}
 	else {
@@ -1001,7 +1051,7 @@
 {
 	int error = 0;
 	char *p = extra;
-	char powermode_val = 0;
+	char coexmode_val = 0;
 	char buf_reg66va_dhcp_on[8] = { 66, 00, 00, 00, 0x10, 0x27, 0x00, 0x00 };
 	char buf_reg41va_dhcp_on[8] = { 41, 00, 00, 00, 0x33, 0x00, 0x00, 0x00 };
 	char buf_reg68va_dhcp_on[8] = { 68, 00, 00, 00, 0x90, 0x01, 0x00, 0x00 };
@@ -1014,39 +1064,41 @@
 
 #ifdef COEX_DHCP
 	char buf_flag7_default[8] =   { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
-#endif 
+#endif
 
-	
-	strncpy((char *)&powermode_val, extra + strlen("BTCOEXMODE") +1, 1);
 
-	if (strnicmp((char *)&powermode_val, "1", strlen("1")) == 0) {
+	strncpy((char *)&coexmode_val, extra + strlen("BTCOEXMODE") +1, 1);
 
-		WL_TRACE(("%s: DHCP session starts\n", __FUNCTION__));
+	WL_TRACE_COEX(("%s BTCOEXMODE %s \n",__FUNCTION__, extra + strlen("BTCOEXMODE") ));
 
-		
+	if (strnicmp((char *)&coexmode_val, "1", strlen("1")) == 0) {
+
+		WL_TRACE_COEX(("%s: BTCOEXMODE 1, dhcp starts \n", __FUNCTION__));
+
+
 		if ((saved_status == FALSE) &&
 			(!dev_wlc_intvar_get_reg(dev, "btc_params", 66,  &saved_reg66)) &&
 			(!dev_wlc_intvar_get_reg(dev, "btc_params", 41,  &saved_reg41)) &&
 			(!dev_wlc_intvar_get_reg(dev, "btc_params", 68,  &saved_reg68)))   {
 				saved_status = TRUE;
-				WL_TRACE(("Saved 0x%x 0x%x 0x%x\n",
+				WL_TRACE_COEX(("Saved regs {66,41,68} --> 0x%x 0x%x 0x%x\n",
 					saved_reg66, saved_reg41, saved_reg68));
 
-				
 
-				
+
+
 #ifdef COEX_DHCP
-				
+
 				if (btcoex_is_sco_active(dev)) {
-					
+
 					dev_wlc_bufvar_set(dev, "btc_params",
 						(char *)&buf_reg66va_dhcp_on[0],
 						sizeof(buf_reg66va_dhcp_on));
-					
+
 					dev_wlc_bufvar_set(dev, "btc_params",
 						(char *)&buf_reg41va_dhcp_on[0],
 						sizeof(buf_reg41va_dhcp_on));
-					
+
 					dev_wlc_bufvar_set(dev, "btc_params",
 						(char *)&buf_reg68va_dhcp_on[0],
 						sizeof(buf_reg68va_dhcp_on));
@@ -1058,40 +1110,40 @@
 					WL_TRACE_COEX(("%s enable BT DHCP Timer\n",
 					__FUNCTION__));
 				}
-#endif 
+#endif
 		}
 		else if (saved_status == TRUE) {
 			WL_ERROR(("%s was called w/o DHCP OFF. Continue\n", __FUNCTION__));
 		}
 	}
-	else if (strnicmp((char *)&powermode_val, "2", strlen("2")) == 0) {
+	else if (strnicmp((char *)&coexmode_val, "2", strlen("2")) == 0) {
 
 
-		
+
 
 #ifdef COEX_DHCP
-		
-		WL_TRACE(("%s disable BT DHCP Timer\n", __FUNCTION__));
+
+		WL_TRACE_COEX(("%s BTCOEXMODE 2, dhcp done \n", __FUNCTION__));
 		if (g_bt->timer_on) {
 			g_bt->timer_on = 0;
 			del_timer_sync(&g_bt->timer);
 
 			if (g_bt->bt_state != BT_DHCP_IDLE) {
-			
+
 				WL_TRACE_COEX(("%s bt->bt_state:%d\n",
 					__FUNCTION__, g_bt->bt_state));
-				
+
 				up(&g_bt->tsk_ctl.sema);
 			}
 		}
 
-		
+
 		if (saved_status == TRUE)
 			dev_wlc_bufvar_set(dev, "btc_flags",
 				(char *)&buf_flag7_default[0], sizeof(buf_flag7_default));
-#endif 
+#endif
 
-		
+
 		if (saved_status == TRUE) {
 			regaddr = 66;
 			dev_wlc_intvar_set_reg(dev, "btc_params",
@@ -1110,8 +1162,8 @@
 
 	}
 	else {
-		WL_ERROR(("%s Unkwown yet power setting, ignored\n",
-			__FUNCTION__));
+		WL_ERROR(("%s BTCOEXMODE %d: is unkwown argument, ignored\n",
+			__FUNCTION__, coexmode_val));
 	}
 
 	p += snprintf(p, MAX_WX_STRING, "OK");
@@ -1140,7 +1192,7 @@
 
 	ret_now = net_os_set_suspend_disable(dev, suspend_flag);
 
-	
+
 	if (ret_now != suspend_flag) {
 		if (!(ret = net_os_set_suspend(dev, ret_now)))
 			WL_ERROR(("%s: Suspend Flag %d -> %d\n",
@@ -1188,7 +1240,7 @@
 	char *p = extra;
 	static int link_speed;
 
-	
+
 	net_os_wake_lock(dev);
 	if (g_onoff == G_WLAN_SET_ON) {
 		error = dev_wlc_ioctl(dev, WLC_GET_RATE, &link_speed, sizeof(link_speed));
@@ -1266,7 +1318,7 @@
 				&iovbuf, sizeof(iovbuf))) >= 0) {
 				p += snprintf(p, MAX_WX_STRING, "OK");
 
-				
+
 				net_os_set_dtim_skip(dev, bcn_li_dtim);
 
 				WL_TRACE(("%s: set dtim_skip %d OK\n", __FUNCTION__,
@@ -1335,7 +1387,7 @@
 		band = htod32((uint)*(extra + strlen(BAND_SET_CMD) + 1) - '0');
 
 		if ((band == WLC_BAND_AUTO) || (band == WLC_BAND_5G) || (band == WLC_BAND_2G)) {
-			
+
 			if ((error = dev_wlc_ioctl(dev, WLC_SET_BAND,
 				&band, sizeof(band))) >= 0) {
 				p += snprintf(p, MAX_WX_STRING, "OK");
@@ -1463,7 +1515,7 @@
 		'2',
 		0x00
 		};
-#endif 
+#endif
 
 	net_os_wake_lock(dev);
 	WL_ERROR(("\n### %s: info->cmd:%x, info->flags:%x, u.data=0x%p, u.len=%d\n",
@@ -1491,7 +1543,7 @@
 	for (i = 0; i < wrqu->data.length; i++)
 		printf("%02X ", extra[i]);
 	printf("\n");
-#endif 
+#endif
 
 	str_ptr = extra;
 #ifdef PNO_SET_DEBUG
@@ -1505,7 +1557,7 @@
 	cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
 	memset(ssids_local, 0, sizeof(ssids_local));
 	pno_repeat = pno_freq_expo_max = 0;
-	
+
 	if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
 		(cmd_tlv_temp->version == PNO_TLV_VERSION) &&
 		(cmd_tlv_temp->subver == PNO_TLV_SUBVERSION))
@@ -1513,7 +1565,7 @@
 		str_ptr += sizeof(cmd_tlv_t);
 		tlv_size_left  -= sizeof(cmd_tlv_t);
 
-		
+
 		if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
 			MAX_PFN_LIST_COUNT,
 			&tlv_size_left)) <= 0) {
@@ -1530,7 +1582,7 @@
 			pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
 			WL_PNO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
 
-			
+
 			if (str_ptr[0] != 0) {
 				if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
 					WL_ERROR(("%s pno repeat : corrupted field\n",
@@ -1557,14 +1609,14 @@
 		goto exit_proc;
 	}
 
-	
+
 	res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
 
 exit_proc:
 	net_os_wake_unlock(dev);
 	return res;
 }
-#endif 
+#endif
 
 static int
 wl_iw_get_rssi(
@@ -1636,9 +1688,6 @@
 int
 wl_control_wl_start(struct net_device *dev)
 {
-	wl_iw_t *iw;
-	int ret = 0;
-
 	WL_TRACE(("Enter %s \n", __FUNCTION__));
 
 	if (!dev) {
@@ -1646,36 +1695,17 @@
 		return -1;
 	}
 
-	iw = *(wl_iw_t **)netdev_priv(dev);
-
-	if (!iw) {
-		WL_ERROR(("%s: wl is null\n", __FUNCTION__));
-		return -1;
-	}
-
 	dhd_net_if_lock(dev);
 
 	if (g_onoff == G_WLAN_SET_OFF) {
-		dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON);
-
-#if defined(BCMLXSDMMC)
-		sdioh_start(NULL, 0);
-#endif
-
-		ret = dhd_dev_reset(dev, 0);
-
-#if defined(BCMLXSDMMC)
-		sdioh_start(NULL, 1);
-#endif
-		if (!ret)
-			dhd_dev_init_ioctl(dev);
-
+		dhd_dev_init_ioctl(dev);
 		g_onoff = G_WLAN_SET_ON;
 	}
-	WL_TRACE(("Exited %s\n", __FUNCTION__));
 
 	dhd_net_if_unlock(dev);
-	return ret;
+
+	WL_TRACE(("Exited %s\n", __FUNCTION__));
+	return 0;
 }
 
 
@@ -1685,8 +1715,8 @@
 	struct iw_request_info *info
 )
 {
-	wl_iw_t *iw;
-	int ret = 0;
+	int error = 0;
+	scb_val_t scbval;
 
 	WL_TRACE(("Enter %s\n", __FUNCTION__));
 
@@ -1695,59 +1725,29 @@
 		return -1;
 	}
 
-	iw = *(wl_iw_t **)netdev_priv(dev);
-
-	if (!iw) {
-		WL_ERROR(("%s: wl is null\n", __FUNCTION__));
-		return -1;
-	}
-
 	dhd_net_if_lock(dev);
 
 #ifdef SOFTAP
 	ap_cfg_running = FALSE;
-#endif 
+#endif
 
 	if (g_onoff == G_WLAN_SET_ON) {
 		g_onoff = G_WLAN_SET_OFF;
 
-#if defined(WL_IW_USE_ISCAN)
-		g_iscan->iscan_state = ISCAN_STATE_IDLE;
-#endif 
-
-		ret = dhd_dev_reset(dev, 1);
-
-#if defined(WL_IW_USE_ISCAN)
-#if !defined(CSCAN)
-		
-		wl_iw_free_ss_cache();
-		wl_iw_run_ss_cache_timer(0);
-		
-		g_ss_cache_ctrl.m_link_down = 1;
-#endif 
-		memset(g_scan, 0, G_SCAN_RESULTS);
-		g_scan_specified_ssid = 0;
-#if defined(CONFIG_FIRST_SCAN)
-		
-		g_first_broadcast_scan = BROADCAST_SCAN_FIRST_IDLE;
-		g_first_counter_scans = 0;
-#endif 
-#endif 
-
-#if defined(BCMLXSDMMC)
-		sdioh_stop(NULL);
-#endif
-
-		dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
-
 		wl_iw_send_priv_event(dev, "STOP");
 	}
 
 	dhd_net_if_unlock(dev);
 
+	bzero(&scbval, sizeof(scb_val_t));
+	if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
+		WL_ERROR(("%s: Failed to disassociate \n", __FUNCTION__));
+	}
+
 	WL_TRACE(("Exited %s\n", __FUNCTION__));
 
-	return ret;
+	return 0;
+
 }
 
 static int
@@ -1779,14 +1779,14 @@
 
 #ifdef SOFTAP
 static struct ap_profile my_ap;
-static int set_ap_cfg(struct net_device *dev, struct ap_profile *ap); 
+static int set_ap_cfg(struct net_device *dev, struct ap_profile *ap);
 static int get_assoc_sta_list(struct net_device *dev, char *buf, int len);
 static int set_ap_mac_list(struct net_device *dev, void *buf);
 
 #define PTYPE_STRING 0
-#define PTYPE_INTDEC 1   
+#define PTYPE_INTDEC 1
 #define PTYPE_INTHEX 2
-#define PTYPE_STR_HEX 3  
+#define PTYPE_STR_HEX 3
 
 static int get_parameter_from_string(
 	char **str_ptr, const char *token, int param_type, void  *dst, int param_max_len);
@@ -1837,7 +1837,7 @@
 	memset(sub_cmd, 0, sizeof(sub_cmd));
 	memset(ap_cfg, 0, sizeof(struct ap_profile));
 
-	
+
 	if (get_parameter_from_string(&str_ptr, "ASCII_CMD=",
 		PTYPE_STRING, sub_cmd, SSID_LEN) != 0) {
 	 return -1;
@@ -1847,8 +1847,8 @@
 		return -1;
 	}
 
-	
-	
+
+
 	ret = get_parameter_from_string(&str_ptr, "SSID=", PTYPE_STRING, ap_cfg->ssid, SSID_LEN);
 
 	ret |= get_parameter_from_string(&str_ptr, "SEC=", PTYPE_STRING,  ap_cfg->sec, SEC_LEN);
@@ -1857,23 +1857,23 @@
 
 	ret |= get_parameter_from_string(&str_ptr, "CHANNEL=", PTYPE_INTDEC, &ap_cfg->channel, 5);
 
-	
+
 	get_parameter_from_string(&str_ptr, "PREAMBLE=", PTYPE_INTDEC, &ap_cfg->preamble, 5);
 
-	
+
 	get_parameter_from_string(&str_ptr, "MAX_SCB=", PTYPE_INTDEC,  &ap_cfg->max_scb, 5);
 
-	
+
 	get_parameter_from_string(&str_ptr, "HIDDEN=",
 		PTYPE_INTDEC,  &ap_cfg->closednet, 5);
 
-	
+
 	get_parameter_from_string(&str_ptr, "COUNTRY=",
 		PTYPE_STRING,  &ap_cfg->country_code, 3);
 
 	return ret;
 }
-#endif 
+#endif
 
 
 
@@ -1915,7 +1915,7 @@
 
 		memset(ap_cfg, 0, sizeof(struct ap_profile));
 
-		
+
 
 		str_ptr = extra;
 
@@ -1926,7 +1926,7 @@
 		}
 
 	} else {
-	 
+
 	  WL_ERROR(("IWPRIV argument len = 0 \n"));
 	  return -1;
 	}
@@ -1938,7 +1938,7 @@
 
 	return res;
 }
-#endif 
+#endif
 
 
 
@@ -1958,7 +1958,7 @@
 	wl_iw_t *iw;
 
 	if ((!dev) || (!extra)) {
-		
+
 		return -EINVAL;
 	}
 
@@ -1990,19 +1990,19 @@
 		sta_maclist->count));
 
 
-	
+
 	memset(mac_lst, 0, sizeof(mac_lst));
 	p_mac_str = mac_lst;
 	p_mac_str_end = &mac_lst[sizeof(mac_lst)-1];
 
-	for (i = 0; i < 8; i++) { 
+	for (i = 0; i < 8; i++) {
 		struct ether_addr * id = &sta_maclist->ea[i];
 		if (!ETHER_ISNULLADDR(id->octet)) {
 			scb_val_t scb_val;
 			int rssi = 0;
 			bzero(&scb_val, sizeof(scb_val_t));
 
-			
+
 			if ((p_mac_str_end - p_mac_str) <= 36) {
 				WL_ERROR(("%s: mac list buf is < 36 for item[%i] item\n",
 					__FUNCTION__, i));
@@ -2014,7 +2014,7 @@
 			id->octet[0], id->octet[1], id->octet[2],
 			id->octet[3], id->octet[4], id->octet[5]);
 
-			
+
 			bcopy(id->octet, &scb_val.ea, 6);
 			ret = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t));
 			if (ret  < 0) {
@@ -2030,7 +2030,7 @@
 		}
 	}
 
-	p_iwrq->data.length = strlen(mac_lst)+1; 
+	p_iwrq->data.length = strlen(mac_lst)+1;
 
 	WL_SOFTAP(("%s: data to user:\n%s\n usr_ptr:%p\n", __FUNCTION__,
 		mac_lst, p_iwrq->data.pointer));
@@ -2047,7 +2047,7 @@
 	WL_SOFTAP(("%s: Exited\n", __FUNCTION__));
 	return ret;
 }
-#endif 
+#endif
 
 
 #ifdef SOFTAP
@@ -2060,10 +2060,10 @@
 {
 	int i, ret = -1;
 	char  * extra = NULL;
-	int mac_cnt = 0; 
+	int mac_cnt = 0;
 	int mac_mode = 0;
 	struct ether_addr *p_ea;
-	struct mac_list_set mflist_set; 
+	struct mac_list_set mflist_set;
 
 	WL_SOFTAP((">>> Got IWPRIV SET_MAC_FILTER IOCTL:  info->cmd:%x,"
 			"info->flags:%x, u.data:%p, u.len:%d\n",
@@ -2087,11 +2087,11 @@
 
 		memset(&mflist_set, 0, sizeof(mflist_set));
 
-		
+
 		str_ptr = extra;
 
 
-		
+
 		if (get_parameter_from_string(&str_ptr, "MAC_MODE=",
 			PTYPE_INTDEC, &mac_mode, 4) != 0) {
 			WL_ERROR(("ERROR: 'MAC_MODE=' token is missing\n"));
@@ -2111,7 +2111,7 @@
 			goto exit_proc;
 		}
 
-		for (i=0; i< mac_cnt; i++)	
+		for (i=0; i< mac_cnt; i++)
 		if (get_parameter_from_string(&str_ptr, "MAC=",
 			PTYPE_STR_HEX, &p_ea[i], 12) != 0) {
 			WL_ERROR(("ERROR: MAC_filter[%d] is missing !\n", i));
@@ -2124,18 +2124,18 @@
 		   dhd_print_buf(&p_ea[i], 6, 0);
 		}
 
-		
+
 		mflist_set.mode = mac_mode;
 		mflist_set.mac_list.count = mac_cnt;
 		set_ap_mac_list(dev, &mflist_set);
 
-		
+
 		wrqu->data.pointer = NULL;
 		wrqu->data.length = 0;
 		ret = 0;
 
 	} else {
-	 
+
 	  WL_ERROR(("IWPRIV argument len is 0\n"));
 	  return -1;
 	}
@@ -2144,7 +2144,7 @@
 	kfree(extra);
 	return ret;
 }
-#endif 
+#endif
 
 
 #ifdef SOFTAP
@@ -2180,22 +2180,22 @@
 
 	return res;
 }
-#endif 
+#endif
 
-#endif 
+#endif
 
 #if WIRELESS_EXT < 13
 struct iw_request_info
 {
-	__u16		cmd;		
-	__u16		flags;		
+	__u16		cmd;
+	__u16		flags;
 };
 
 typedef int (*iw_handler)(struct net_device *dev,
                 struct iw_request_info *info,
                 void *wrqu,
                 char *extra);
-#endif 
+#endif
 
 static int
 wl_iw_config_commit(
@@ -2263,13 +2263,13 @@
 	}
 #endif
 
-	
+
 	if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
 		chan = fwrq->m;
 	}
-	
+
 	else {
-		
+
 		if (fwrq->e >= 6) {
 			fwrq->e -= 6;
 			while (fwrq->e--)
@@ -2278,9 +2278,9 @@
 			while (fwrq->e++ < 6)
 				fwrq->m /= 10;
 		}
-		
+
 		if (fwrq->m > 4000 && fwrq->m < 5000)
-			sf = WF_CHAN_FACTOR_4_G; 
+			sf = WF_CHAN_FACTOR_4_G;
 
 		chan = wf_mhz2channel(fwrq->m, sf);
 	}
@@ -2292,7 +2292,7 @@
 
 	g_wl_iw_params.target_channel = chan;
 
-	
+
 	return -EINPROGRESS;
 }
 
@@ -2312,7 +2312,7 @@
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
 		return error;
 
-	
+
 	fwrq->m = dtoh32(ci.hw_channel);
 	fwrq->e = dtoh32(0);
 	return 0;
@@ -2350,7 +2350,7 @@
 	    (error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap))))
 		return error;
 
-	
+
 	return -EINPROGRESS;
 }
 
@@ -2416,10 +2416,10 @@
 	dwrq->length = sizeof(struct iw_range);
 	memset(range, 0, sizeof(*range));
 
-	
+
 	range->min_nwid = range->max_nwid = 0;
 
-	
+
 	list->count = htod32(MAXCHANNEL);
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, (MAXCHANNEL+1)*4))) {
 		kfree(channels);
@@ -2439,25 +2439,25 @@
 	}
 	range->num_frequency = range->num_channels = i;
 
-	
+
 	range->max_qual.qual = 5;
-	
-	range->max_qual.level = 0x100 - 200;	
-	
-	range->max_qual.noise = 0x100 - 200;	
-	
+
+	range->max_qual.level = 0x100 - 200;
+
+	range->max_qual.noise = 0x100 - 200;
+
 	range->sensitivity = 65535;
 
 #if WIRELESS_EXT > 11
-	
-	range->avg_qual.qual = 3;
-	
-	range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
-	
-	range->avg_qual.noise = 0x100 - 75;	
-#endif 
 
-	
+	range->avg_qual.qual = 3;
+
+	range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
+
+	range->avg_qual.noise = 0x100 - 75;
+#endif
+
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset)))) {
 		kfree(channels);
 		return error;
@@ -2465,7 +2465,7 @@
 	rateset.count = dtoh32(rateset.count);
 	range->num_bitrates = rateset.count;
 	for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
-		range->bitrate[i] = (rateset.rates[i]& 0x7f) * 500000; 
+		range->bitrate[i] = (rateset.rates[i]& 0x7f) * 500000;
 	dev_wlc_intvar_get(dev, "nmode", &nmode);
 	dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype));
 
@@ -2491,23 +2491,23 @@
 		}
 		range->num_bitrates += 8;
 		for (k = 0; i < range->num_bitrates; k++, i++) {
-			
+
 			range->bitrate[i] = (nrate_list[nrate_list2copy][k]) * 500000;
 		}
 	}
 
-	
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i)))) {
 		kfree(channels);
 		return error;
 	}
 	i = dtoh32(i);
 	if (i == WLC_PHY_TYPE_A)
-		range->throughput = 24000000;	
+		range->throughput = 24000000;
 	else
-		range->throughput = 1500000;	
+		range->throughput = 1500000;
 
-	
+
 	range->min_rts = 0;
 	range->max_rts = 2347;
 	range->min_frag = 256;
@@ -2524,7 +2524,7 @@
 #endif
 	range->encoding_size[3] = AES_KEY_SIZE;
 
-	
+
 	range->min_pmp = 0;
 	range->max_pmp = 0;
 	range->min_pmt = 0;
@@ -2532,7 +2532,7 @@
 	range->pmp_flags = 0;
 	range->pm_capa = 0;
 
-	
+
 	range->num_txpower = 2;
 	range->txpower[0] = 1;
 	range->txpower[1] = 255;
@@ -2542,17 +2542,17 @@
 	range->we_version_compiled = WIRELESS_EXT;
 	range->we_version_source = 19;
 
-	
+
 	range->retry_capa = IW_RETRY_LIMIT;
 	range->retry_flags = IW_RETRY_LIMIT;
 	range->r_time_flags = 0;
-	
+
 	range->min_retry = 1;
 	range->max_retry = 255;
-	
+
 	range->min_r_time = 0;
 	range->max_r_time = 0;
-#endif 
+#endif
 
 #if WIRELESS_EXT > 17
 	range->enc_capa = IW_ENC_CAPA_WPA;
@@ -2560,15 +2560,15 @@
 	range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
 	range->enc_capa |= IW_ENC_CAPA_WPA2;
 
-	
+
 	IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
-	
+
 	IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
 	IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
 	IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
 	IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
 	IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
-#endif 
+#endif
 
 	kfree(channels);
 
@@ -2653,7 +2653,7 @@
 	chanspec_t chanspec = 0;
 
 	if (ch != 0) {
-		
+
 		join_params->params.chanspec_num = 1;
 		join_params->params.chanspec_list[0] = ch;
 
@@ -2665,11 +2665,11 @@
 		chanspec |= WL_CHANSPEC_BW_20;
 		chanspec |= WL_CHANSPEC_CTL_SB_NONE;
 
-		
+
 		*join_params_size += WL_ASSOC_PARAMS_FIXED_SIZE +
 			join_params->params.chanspec_num * sizeof(chanspec_t);
 
-		
+
 		join_params->params.chanspec_list[0]  &= WL_CHANSPEC_CHAN_MASK;
 		join_params->params.chanspec_list[0] |= chanspec;
 		join_params->params.chanspec_list[0] =
@@ -2702,18 +2702,18 @@
 		return -EINVAL;
 	}
 
-	
+
 	if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) {
 		scb_val_t scbval;
-		
+
 		bzero(&scbval, sizeof(scb_val_t));
-		
+
 		(void) dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t));
 		return 0;
 	}
 
 
-	
+
 	memset(&join_params, 0, sizeof(join_params));
 	join_params_size = sizeof(join_params.ssid);
 
@@ -2721,8 +2721,8 @@
 	join_params.ssid.SSID_len = htod32(g_ssid.SSID_len);
 	memcpy(&join_params.params.bssid, awrq->sa_data, ETHER_ADDR_LEN);
 
-	
-	
+
+
 	WL_TRACE(("%s  target_channel=%d\n", __FUNCTION__, g_wl_iw_params.target_channel));
 	wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params, &join_params_size);
 
@@ -2737,7 +2737,7 @@
 			g_wl_iw_params.target_channel));
 	}
 
-	
+
 	memset(&g_ssid, 0, sizeof(g_ssid));
 	return 0;
 }
@@ -2755,7 +2755,7 @@
 	awrq->sa_family = ARPHRD_ETHER;
 	memset(awrq->sa_data, 0, ETHER_ADDR_LEN);
 
-	
+
 	(void) dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN);
 
 	return 0;
@@ -2801,7 +2801,7 @@
 
 	return error;
 }
-#endif 
+#endif
 
 #ifndef WL_IW_USE_ISCAN
 static int
@@ -2824,7 +2824,7 @@
 	if (!extra)
 		return -EINVAL;
 
-	
+
 	list = kmalloc(buflen, GFP_KERNEL);
 	if (!list)
 		return -ENOMEM;
@@ -2850,23 +2850,23 @@
 		ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
 			buflen));
 
-		
+
 		if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
 			continue;
 
-		
+
 		memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
 		addr[dwrq->length].sa_family = ARPHRD_ETHER;
 		qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI));
 		qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI);
 		qual[dwrq->length].noise = 0x100 + bi->phy_noise;
 
-		
+
 #if WIRELESS_EXT > 18
 		qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
 #else
 		qual[dwrq->length].updated = 7;
-#endif 
+#endif
 
 		dwrq->length++;
 	}
@@ -2875,13 +2875,13 @@
 
 	if (dwrq->length) {
 		memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
-		
+
 		dwrq->flags = 1;
 	}
 
 	return 0;
 }
-#endif 
+#endif
 
 #ifdef WL_IW_USE_ISCAN
 static int
@@ -2912,7 +2912,7 @@
 	}
 
 	buf = iscan->list_hdr;
-	
+
 	while (buf) {
 		list = &((wl_iscan_results_t*)buf->iscan_buf)->results;
 		if (list->version != WL_BSS_INFO_VERSION) {
@@ -2928,23 +2928,23 @@
 			ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
 				WLC_IW_ISCAN_MAXLEN));
 
-			
+
 			if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
 				continue;
 
-			
+
 			memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
 			addr[dwrq->length].sa_family = ARPHRD_ETHER;
 			qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI));
 			qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI);
 			qual[dwrq->length].noise = 0x100 + bi->phy_noise;
 
-			
+
 #if WIRELESS_EXT > 18
 			qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
 #else
 			qual[dwrq->length].updated = 7;
-#endif 
+#endif
 
 			dwrq->length++;
 		}
@@ -2952,7 +2952,7 @@
 	}
 	if (dwrq->length) {
 		memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
-		
+
 		dwrq->flags = 1;
 	}
 
@@ -2974,10 +2974,10 @@
 	params->channel_num = 0;
 
 #if defined(CONFIG_FIRST_SCAN)
-	
+
 	if (g_first_broadcast_scan == BROADCAST_SCAN_FIRST_STARTED)
 		params->passive_time = 30;
-#endif 
+#endif
 	params->nprobes = htod32(params->nprobes);
 	params->active_time = htod32(params->active_time);
 	params->passive_time = htod32(params->passive_time);
@@ -3030,7 +3030,7 @@
 wl_iw_set_event_mask(struct net_device *dev)
 {
 	char eventmask[WL_EVENTING_MASK_LEN];
-	char iovbuf[WL_EVENTING_MASK_LEN + 12];	
+	char iovbuf[WL_EVENTING_MASK_LEN + 12];
 
 	dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
 	bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
@@ -3099,7 +3099,7 @@
 		status = dtoh32(list_buf->status);
 	} else {
 		WL_ERROR(("%s returns error %d\n", __FUNCTION__, res));
-		
+
 		status = WL_SCAN_RESULTS_NO_MEM;
 	}
 	DHD_OS_MUTEX_UNLOCK(&wl_cache_lock);
@@ -3128,12 +3128,12 @@
 
 	memset(&wrqu, 0, sizeof(wrqu));
 
-	
+
 	wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
 #if defined(CONFIG_FIRST_SCAN)
 		if (g_first_broadcast_scan == BROADCAST_SCAN_FIRST_STARTED)
 			g_first_broadcast_scan = BROADCAST_SCAN_FIRST_RESULT_READY;
-#endif 
+#endif
 		WL_TRACE(("Send Event ISCAN complete\n"));
 }
 
@@ -3152,7 +3152,7 @@
 
 	status = WL_SCAN_RESULTS_PARTIAL;
 
-	
+
 	complete(&tsk_ctl->completed);
 
 	while (down_interruptible(&tsk_ctl->sema) == 0) {
@@ -3162,16 +3162,16 @@
 			break;
 		}
 #if defined(SOFTAP)
-		
+
 		if (ap_cfg_running) {
 		 WL_TRACE(("%s skipping SCAN ops in AP mode !!!\n", __FUNCTION__));
 		 net_os_wake_unlock(iscan->dev);
 		 continue;
 		}
-#endif 
+#endif
 
 		if (iscan->timer_on) {
-			
+
 			iscan->timer_on = 0;
 			del_timer_sync(&iscan->timer);
 		}
@@ -3197,12 +3197,12 @@
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 				rtnl_lock();
 #endif
-				
+
 				wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 				rtnl_unlock();
 #endif
-				
+
 				mod_timer(&iscan->timer, jiffies + iscan->timer_ms*HZ/1000);
 				iscan->timer_on = 1;
 				break;
@@ -3213,7 +3213,7 @@
 				break;
 			case WL_SCAN_RESULTS_PENDING:
 				WL_TRACE(("iscanresults pending\n"));
-				
+
 				mod_timer(&iscan->timer, jiffies + iscan->timer_ms*HZ/1000);
 				iscan->timer_on = 1;
 				break;
@@ -3245,7 +3245,7 @@
 	}
 	complete_and_exit(&tsk_ctl->completed, 0);
 }
-#endif 
+#endif
 
 #if !defined(CSCAN)
 
@@ -3316,7 +3316,7 @@
 #ifdef CONFIG_PRESCANNED
 			(*timer)->expires = jiffies + 70000 * HZ / 1000;
 #else
-			(*timer)->expires = jiffies + 30000 * HZ / 1000;	
+			(*timer)->expires = jiffies + 30000 * HZ / 1000;
 #endif
 			add_timer(*timer);
 			WL_TRACE(("%s : timer starts \n", __FUNCTION__));
@@ -3389,7 +3389,7 @@
 	wl_bss_info_t *bi = NULL;
 	int i;
 
-	
+
 	if (!ss_list->count) {
 		return 0;
 	}
@@ -3407,7 +3407,7 @@
 		WL_TRACE(("%s : find %d with specific SSID %s\n", __FUNCTION__, i, bi->SSID));
 		for (;node;) {
 			if (!memcmp(&node->bss_info->BSSID, &bi->BSSID, ETHER_ADDR_LEN)) {
-				
+
 				WL_TRACE(("dirty marked : SSID %s\n", bi->SSID));
 				node->dirty = 1;
 				break;
@@ -3507,7 +3507,7 @@
 	return 0;
 }
 
-#endif	
+#endif
 
 static int
 wl_iw_set_scan(
@@ -3527,45 +3527,45 @@
 #if defined(CSCAN)
 		WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __FUNCTION__));
 		return -EINVAL;
-#endif 
+#endif
 
 #if defined(SOFTAP)
-	
+
 	if (ap_cfg_running) {
 		WL_TRACE(("\n>%s: Not executed, reason -'SOFTAP is active'\n", __FUNCTION__));
 		return 0;
 	}
-#endif 
+#endif
 
-	
+
 	if (g_onoff == G_WLAN_SET_OFF)
 		return 0;
 
-	
+
 	memset(&g_specific_ssid, 0, sizeof(g_specific_ssid));
 #ifndef WL_IW_USE_ISCAN
-	
+
 	g_scan_specified_ssid = 0;
-#endif 
+#endif
 
 #if WIRELESS_EXT > 17
-	
+
 	if (wrqu->data.length == sizeof(struct iw_scan_req)) {
 		if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
 			struct iw_scan_req *req = (struct iw_scan_req *)extra;
 #if defined(CONFIG_FIRST_SCAN)
 			if (g_first_broadcast_scan != BROADCAST_SCAN_FIRST_RESULT_CONSUMED) {
-				
+
 				WL_TRACE(("%s Ignoring SC %s first BC is not done = %d\n",
 				          __FUNCTION__, req->essid,
 				          g_first_broadcast_scan));
 				return -EBUSY;
 			}
-#endif	
+#endif
 			if (g_scan_specified_ssid) {
 				WL_TRACE(("%s Specific SCAN is not done ignore scan for = %s \n",
 					__FUNCTION__, req->essid));
-				
+
 				return -EBUSY;
 			}
 			else {
@@ -3579,11 +3579,11 @@
 			}
 		}
 	}
-#endif 
-	
+#endif
+
 	if ((error = dev_wlc_ioctl(dev, WLC_SCAN, &g_specific_ssid, sizeof(g_specific_ssid)))) {
 		WL_TRACE(("#### Set SCAN for %s failed with %d\n", g_specific_ssid.SSID, error));
-		
+
 		g_scan_specified_ssid = 0;
 		return -EBUSY;
 	}
@@ -3599,7 +3599,7 @@
 	iscan_info_t *iscan = g_iscan;
 
 #if defined(CONFIG_FIRST_SCAN)
-	
+
 	if (g_first_broadcast_scan == BROADCAST_SCAN_FIRST_IDLE) {
 		g_first_broadcast_scan = BROADCAST_SCAN_FIRST_STARTED;
 		WL_TRACE(("%s: First Brodcast scan was forced\n", __FUNCTION__));
@@ -3608,7 +3608,7 @@
 		WL_TRACE(("%s: ignore ISCAN request first BS is not done yet\n", __FUNCTION__));
 		return 0;
 	}
-#endif 
+#endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
 	if (flag)
@@ -3619,7 +3619,7 @@
 	wl_iw_set_event_mask(dev);
 
 	WL_TRACE(("+++: Set Broadcast ISCAN\n"));
-	
+
 	memset(&ssid, 0, sizeof(ssid));
 
 	iscan->list_cur = iscan->list_hdr;
@@ -3658,31 +3658,31 @@
 #if defined(CSCAN)
 		WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __FUNCTION__));
 		return -EINVAL;
-#endif 
+#endif
 
 	net_os_wake_lock(dev);
 
-	
+
 #if defined(SOFTAP)
 	if (ap_cfg_running) {
 		WL_TRACE(("\n>%s: Not executed, reason -'SOFTAP is active'\n", __FUNCTION__));
 		goto set_scan_end;
 	}
 #endif
-	
+
 	if (g_onoff == G_WLAN_SET_OFF) {
 		WL_TRACE(("%s: driver is not up yet after START\n", __FUNCTION__));
 		goto set_scan_end;
 	}
 
 #ifdef PNO_SUPPORT
-	
+
 	if  (dhd_dev_get_pno_status(dev)) {
 		WL_ERROR(("%s: Scan called when PNO is active\n", __FUNCTION__));
 	}
-#endif 
+#endif
 
-	
+
 	if ((!iscan) || (iscan->tsk_ctl.thr_pid < 0)) {
 		WL_ERROR(("%s error \n",  __FUNCTION__));
 		goto set_scan_end;
@@ -3695,16 +3695,16 @@
 		goto set_scan_end;
 	}
 
-	
+
 	memset(&ssid, 0, sizeof(ssid));
 
 #if WIRELESS_EXT > 17
-	
+
 	if (wrqu->data.length == sizeof(struct iw_scan_req)) {
 		if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
 			int as = 0;
 			struct iw_scan_req *req = (struct iw_scan_req *)extra;
-			
+
 			ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
 			memcpy(ssid.SSID, req->essid, ssid.SSID_len);
 			ssid.SSID_len = htod32(ssid.SSID_len);
@@ -3722,7 +3722,7 @@
 			}
 		}
 	}
-#endif 
+#endif
 
 #if defined(CONFIG_FIRST_SCAN) && !defined(CSCAN)
 	if (g_first_broadcast_scan < BROADCAST_SCAN_FIRST_RESULT_CONSUMED) {
@@ -3747,7 +3747,7 @@
 	net_os_wake_unlock(dev);
 	return ret;
 }
-#endif 
+#endif
 
 #if WIRELESS_EXT > 17
 static bool
@@ -3757,17 +3757,17 @@
 
 	uint8 *ie = *wpaie;
 
-	
+
 	if ((ie[1] >= 6) &&
 		!bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
 		return TRUE;
 	}
 
-	
+
 	ie += ie[1] + 2;
-	
+
 	*tlvs_len -= (int)(ie - *tlvs);
-	
+
 	*tlvs = ie;
 	return FALSE;
 }
@@ -3779,22 +3779,50 @@
 
 	uint8 *ie = *wpsie;
 
-	
+
 	if ((ie[1] >= 4) &&
 		!bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
 		return TRUE;
 	}
 
-	
+
 	ie += ie[1] + 2;
-	
+
 	*tlvs_len -= (int)(ie - *tlvs);
-	
+
 	*tlvs = ie;
 	return FALSE;
 }
-#endif 
+#endif
 
+#ifdef WAPI
+static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
+	size_t len, int uppercase)
+{
+	size_t i;
+	char *pos = buf, *end = buf + buf_size;
+	int ret;
+	if (buf_size == 0)
+		return 0;
+	for (i = 0; i < len; i++) {
+		ret = snprintf(pos, end - pos, uppercase ? "%02X" : "%02x",
+			data[i]);
+		if (ret < 0 || ret >= end - pos) {
+			end[-1] = '\0';
+			return pos - buf;
+		}
+		pos += ret;
+	}
+	end[-1] = '\0';
+	return pos - buf;
+}
+
+
+int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
+{
+	return _wpa_snprintf_hex(buf, buf_size, data, len, 0);
+}
+#endif /* WAPI */
 
 static int
 wl_iw_handle_scanresults_ies(char **event_p, char *end,
@@ -3803,10 +3831,14 @@
 #if WIRELESS_EXT > 17
 	struct iw_event	iwe;
 	char *event;
+#ifdef WAPI
+	char *buf;
+	int custom_event_len;
+#endif /* WAPI */
 
 	event = *event_p;
 	if (bi->ie_length) {
-		
+
 		bcm_tlv_t *ie;
 		uint8 *ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
 		int ptr_len = bi->ie_length;
@@ -3819,7 +3851,7 @@
 		ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
 
 		while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
-			
+
 			if (ie_is_wps_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
 				iwe.cmd = IWEVGENIE;
 				iwe.u.data.length = ie->len + 2;
@@ -3839,9 +3871,43 @@
 			}
 		}
 
+#ifdef WAPI
+		ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
+		ptr_len = bi->ie_length;
+
+		while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WAPI_ID))) {
+
+			WL_TRACE(("%s: found a WAPI IE...\n", __FUNCTION__));
+#ifdef WAPI_IE_USE_GENIE
+			iwe.cmd = IWEVGENIE;
+			iwe.u.data.length = ie->len + 2;
+			event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
+#else
+			iwe.cmd = IWEVCUSTOM;
+			custom_event_len = strlen("wapi_ie=") + 2*(ie->len + 2);
+			iwe.u.data.length = custom_event_len;
+
+			buf = kmalloc(custom_event_len+1, GFP_KERNEL);
+			if (buf == NULL)
+			{
+				WL_ERROR(("malloc(%d) returned NULL...\n", custom_event_len));
+				break;
+			}
+
+			memcpy(buf, "wapi_ie=", 8);
+			wpa_snprintf_hex(buf + 8, 2+1, &(ie->id), 1);
+			wpa_snprintf_hex(buf + 10, 2+1, &(ie->len), 1);
+			wpa_snprintf_hex(buf + 12, 2*ie->len+1, ie->data, ie->len);
+			event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, buf);
+			kfree(buf);
+#endif
+			break;
+		}
+#endif /* WAPI */
+
 	*event_p = event;
 	}
-#endif 
+#endif
 
 	return 0;
 }
@@ -3865,7 +3931,7 @@
 		return ret;
 	}
 
-	
+
 
 	for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
 		if (list->version != WL_BSS_INFO_VERSION) {
@@ -3878,18 +3944,18 @@
 
 		WL_TRACE(("%s : %s\n", __FUNCTION__, bi->SSID));
 
-		
+
 		iwe.cmd = SIOCGIWAP;
 		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
 		memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
 		event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
-		
+
 		iwe.u.data.length = dtoh32(bi->SSID_len);
 		iwe.cmd = SIOCGIWESSID;
 		iwe.u.data.flags = 1;
 		event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
 
-		
+
 		if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
 			iwe.cmd = SIOCGIWMODE;
 			if (dtoh16(bi->capability) & DOT11_CAP_ESS)
@@ -3899,7 +3965,7 @@
 			event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
 		}
 
-		
+
 		iwe.cmd = SIOCGIWFREQ;
 		iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
 			CHSPEC_CHANNEL(bi->chanspec) <= CH_MAX_2G_CHANNEL ?
@@ -3907,17 +3973,17 @@
 		iwe.u.freq.e = 6;
 		event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
 
-		
+
 		iwe.cmd = IWEVQUAL;
 		iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI));
 		iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI);
 		iwe.u.qual.noise = 0x100 + bi->phy_noise;
 		event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
 
-		
+
 		 wl_iw_handle_scanresults_ies(&event, end, info, bi);
 
-		
+
 		iwe.cmd = SIOCGIWENCODE;
 		if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
 			iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
@@ -3926,12 +3992,12 @@
 		iwe.u.data.length = 0;
 		event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
 
-		
+
 		if (bi->rateset.count) {
 			if (((event -extra) + IW_EV_LCP_LEN) <= (uintptr)end) {
 				value = event + IW_EV_LCP_LEN;
 				iwe.cmd = SIOCGIWRATE;
-				
+
 				iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
 				for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
 					iwe.u.bitrate.value =
@@ -3976,8 +4042,8 @@
 	iscan_buf_t * p_buf;
 #if  !defined(CSCAN)
 	uint32 counter = 0;
-#endif 
-#endif 
+#endif
+#endif
 
 	WL_TRACE(("%s: buflen_from_user %d: \n", dev->name, buflen_from_user));
 
@@ -3986,7 +4052,7 @@
 		return -EINVAL;
 	}
 
-	
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
 		return error;
 	ci.scan_channel = dtoh32(ci.scan_channel);
@@ -4001,7 +4067,7 @@
 	if ((!g_scan_specified_ssid && g_ss_cache_ctrl.m_prev_scan_mode) ||
 		g_ss_cache_ctrl.m_cons_br_scan_cnt > 4) {
 		g_ss_cache_ctrl.m_cons_br_scan_cnt = 0;
-		
+
 		wl_iw_reset_ss_cache();
 	}
 	g_ss_cache_ctrl.m_prev_scan_mode = g_scan_specified_ssid;
@@ -4011,12 +4077,12 @@
 	else {
 		g_ss_cache_ctrl.m_cons_br_scan_cnt++;
 	}
-#endif 
+#endif
 
 
-	
+
 	if (g_scan_specified_ssid) {
-		
+
 		list = kmalloc(len, GFP_KERNEL);
 		if (!list) {
 			WL_TRACE(("%s: wl_iw_get_scan return -ENOMEM\n", dev->name));
@@ -4040,7 +4106,7 @@
 	list->version = dtoh32(list->version);
 	list->count = dtoh32(list->count);
 
-	
+
 	if (list->version != WL_BSS_INFO_VERSION) {
 		WL_ERROR(("%s : list->version %d != WL_BSS_INFO_VERSION\n",
 		          __FUNCTION__, list->version));
@@ -4053,7 +4119,7 @@
 
 #if  !defined(CSCAN)
 	if (g_scan_specified_ssid) {
-		
+
 		wl_iw_add_bss_to_ss_cache(list);
 		kfree(list);
 	}
@@ -4065,7 +4131,7 @@
 	if (g_scan_specified_ssid)
 		WL_TRACE(("%s: Specified scan APs from scan=%d\n", __FUNCTION__, list->count));
 	p_buf = iscan->list_hdr;
-	
+
 	while (p_buf != iscan->list_cur) {
 		list_merge = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
 		WL_TRACE(("%s: Bcast APs list=%d\n", __FUNCTION__, list_merge->count));
@@ -4079,20 +4145,20 @@
 #else
 	list_merge = (wl_scan_results_t *) g_scan;
 	len_ret = (__u16) wl_iw_get_scan_prep(list_merge, info, extra, buflen_from_user);
-#endif 
+#endif
 	DHD_OS_MUTEX_UNLOCK(&wl_cache_lock);
 	if (g_ss_cache_ctrl.m_link_down) {
-		
+
 		wl_iw_delete_bss_from_ss_cache(g_ss_cache_ctrl.m_active_bssid);
 	}
-	
+
 	wl_iw_merge_scan_cache(info, extra+len_ret, buflen_from_user-len_ret, &merged_len);
 	len_ret += merged_len;
 	wl_iw_run_ss_cache_timer(0);
 	wl_iw_run_ss_cache_timer(1);
-#else	
+#else
 
-	
+
 	if (g_scan_specified_ssid) {
 		WL_TRACE(("%s: Specified scan APs in the list =%d\n", __FUNCTION__, list->count));
 		len_ret = (__u16) wl_iw_get_scan_prep(list, info, extra, buflen_from_user);
@@ -4100,7 +4166,7 @@
 
 #if defined(WL_IW_USE_ISCAN)
 		p_buf = iscan->list_hdr;
-		
+
 		while (p_buf != iscan->list_cur) {
 			list_merge = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
 			WL_TRACE(("%s: Bcast APs list=%d\n", __FUNCTION__, list_merge->count));
@@ -4115,29 +4181,29 @@
 		if (list_merge->count > 0)
 			len_ret += (__u16) wl_iw_get_scan_prep(list_merge, info, extra+len_ret,
 				buflen_from_user -len_ret);
-#endif 
+#endif
 	}
 	else {
 		list = (wl_scan_results_t *) g_scan;
 		len_ret = (__u16) wl_iw_get_scan_prep(list, info, extra, buflen_from_user);
 	}
-#endif	
+#endif
 
 #if defined(WL_IW_USE_ISCAN)
-	
+
 	g_scan_specified_ssid = 0;
-#endif 
-	
+#endif
+
 	if ((len_ret + WE_ADD_EVENT_FIX) < buflen_from_user)
 		len = len_ret;
 
 	dwrq->length = len;
-	dwrq->flags = 0;	
+	dwrq->flags = 0;
 
 	WL_TRACE(("%s return to WE %d bytes APs=%d\n", __FUNCTION__, dwrq->length, list->count));
 	return 0;
 }
-#endif 
+#endif
 
 #if defined(WL_IW_USE_ISCAN)
 static int
@@ -4183,14 +4249,14 @@
 		          dev->name, __FUNCTION__));
 		return -EAGAIN;
 	}
-#endif	
-	
+#endif
+
 	if ((!iscan) || (iscan->tsk_ctl.thr_pid < 0)) {
 		WL_ERROR(("%ssysioc_pid\n", __FUNCTION__));
 		return EAGAIN;
 	}
 
-	
+
 
 #if !defined(CSCAN)
 	if (g_ss_cache_ctrl.m_timer_expired) {
@@ -4202,23 +4268,23 @@
 	}
 	else {
 		if (g_ss_cache_ctrl.m_link_down) {
-			
+
 			wl_iw_delete_bss_from_ss_cache(g_ss_cache_ctrl.m_active_bssid);
 		}
 		if (g_ss_cache_ctrl.m_prev_scan_mode || g_ss_cache_ctrl.m_cons_br_scan_cnt > 4) {
 			g_ss_cache_ctrl.m_cons_br_scan_cnt = 0;
-			
+
 			wl_iw_reset_ss_cache();
 		}
 		g_ss_cache_ctrl.m_prev_scan_mode = g_scan_specified_ssid;
 		g_ss_cache_ctrl.m_cons_br_scan_cnt++;
 	}
-#endif 
+#endif
 
 	WL_TRACE(("%s: SIOCGIWSCAN GET broadcast results\n", dev->name));
 	apcnt = 0;
 	p_buf = iscan->list_hdr;
-	
+
 	while (p_buf != iscan->list_cur) {
 		list = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
 
@@ -4238,23 +4304,23 @@
 			ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
 			                                              WLC_IW_ISCAN_MAXLEN));
 
-			
+
 			if (event + ETHER_ADDR_LEN + bi->SSID_len +
 			    IW_EV_UINT_LEN + IW_EV_FREQ_LEN + IW_EV_QUAL_LEN >= end)
 				return -E2BIG;
-			
+
 			iwe.cmd = SIOCGIWAP;
 			iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
 			memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
 			event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
 
-			
+
 			iwe.u.data.length = dtoh32(bi->SSID_len);
 			iwe.cmd = SIOCGIWESSID;
 			iwe.u.data.flags = 1;
 			event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
 
-			
+
 			if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
 				iwe.cmd = SIOCGIWMODE;
 				if (dtoh16(bi->capability) & DOT11_CAP_ESS)
@@ -4265,7 +4331,7 @@
 				                             &iwe, IW_EV_UINT_LEN);
 			}
 
-			
+
 			iwe.cmd = SIOCGIWFREQ;
 			channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
 			iwe.u.freq.m = wf_channel2mhz(channel,
@@ -4274,17 +4340,17 @@
 			iwe.u.freq.e = 6;
 			event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
 
-			
+
 			iwe.cmd = IWEVQUAL;
 			iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI));
 			iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI);
 			iwe.u.qual.noise = 0x100 + bi->phy_noise;
 			event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
 
-			
+
 			wl_iw_handle_scanresults_ies(&event, end, info, bi);
 
-			
+
 			iwe.cmd = SIOCGIWENCODE;
 			if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
 				iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
@@ -4293,14 +4359,14 @@
 			iwe.u.data.length = 0;
 			event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
 
-			
+
 			if (bi->rateset.count) {
 				if (event + IW_MAX_BITRATES*IW_EV_PARAM_LEN >= end)
 					return -E2BIG;
 
 				value = event + IW_EV_LCP_LEN;
 				iwe.cmd = SIOCGIWRATE;
-				
+
 				iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
 				for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
 					iwe.u.bitrate.value =
@@ -4312,28 +4378,28 @@
 			}
 		}
 		p_buf = p_buf->next;
-	} 
+	}
 
 	dwrq->length = event - extra;
-	dwrq->flags = 0;	
+	dwrq->flags = 0;
 
 #if !defined(CSCAN)
-	
+
 	wl_iw_merge_scan_cache(info, event, buflen_from_user - dwrq->length, &merged_len);
 	dwrq->length += merged_len;
 	wl_iw_run_ss_cache_timer(0);
 	wl_iw_run_ss_cache_timer(1);
-#endif 
-	
+#endif
+
 #if defined(CONFIG_FIRST_SCAN)
 	g_first_broadcast_scan = BROADCAST_SCAN_FIRST_RESULT_CONSUMED;
-#endif 
+#endif
 
 	WL_TRACE(("%s return to WE %d bytes APs=%d\n", __FUNCTION__, dwrq->length, counter));
 
 	return 0;
 }
-#endif 
+#endif
 
 #define WL_JOIN_PARAMS_MAX 1600
 #ifdef CONFIG_PRESCANNED
@@ -4407,7 +4473,7 @@
 	WL_ERROR(("Passing %d channel/bssid pairs.\n", cnt));
 	return cnt;
 }
-#endif 
+#endif
 
 static int
 wl_iw_set_essid(
@@ -4436,7 +4502,7 @@
 
 	memset(join_params, 0, WL_JOIN_PARAMS_MAX);
 
-	
+
 	memset(&g_ssid, 0, sizeof(g_ssid));
 
 	if (dwrq->length && extra) {
@@ -4463,14 +4529,14 @@
 		} else {
 			WL_ERROR(("No matched found\n Trying to join to specific channel\n"));
 		}
-#endif 
+#endif
 	} else {
-		
+
 		g_ssid.SSID_len = 0;
 	}
 	g_ssid.SSID_len = htod32(g_ssid.SSID_len);
 
-	
+
 	memset(join_params, 0, sizeof(*join_params));
 	join_params_size = sizeof(join_params->ssid);
 
@@ -4478,8 +4544,8 @@
 	join_params->ssid.SSID_len = htod32(g_ssid.SSID_len);
 	memcpy(&(join_params->params.bssid), &ether_bcast, ETHER_ADDR_LEN);
 
-	
-	
+
+
 	wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, join_params, &join_params_size);
 
 	if ((error = dev_wlc_ioctl(dev, WLC_SET_SSID, join_params, join_params_size))) {
@@ -4518,12 +4584,12 @@
 
 	ssid.SSID_len = dtoh32(ssid.SSID_len);
 
-	
+
 	memcpy(extra, ssid.SSID, ssid.SSID_len);
 
 	dwrq->length = ssid.SSID_len;
 
-	dwrq->flags = 1; 
+	dwrq->flags = 1;
 
 	return 0;
 }
@@ -4543,7 +4609,7 @@
 	if (!extra)
 		return -EINVAL;
 
-	
+
 	if (dwrq->length > sizeof(iw->nickname))
 		return -E2BIG;
 
@@ -4587,47 +4653,47 @@
 
 	WL_TRACE(("%s: SIOCSIWRATE\n", dev->name));
 
-	
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
 		return error;
 
 	rateset.count = dtoh32(rateset.count);
 
 	if (vwrq->value < 0) {
-		
+
 		rate = rateset.rates[rateset.count - 1] & 0x7f;
 	} else if (vwrq->value < rateset.count) {
-		
+
 		rate = rateset.rates[vwrq->value] & 0x7f;
 	} else {
-		
+
 		rate = vwrq->value / 500000;
 	}
 
 	if (vwrq->fixed) {
-		
+
 		error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
 		error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
 
 		if (error_bg && error_a)
 			return (error_bg | error_a);
 	} else {
-		
-		
+
+
 		error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
-		
+
 		error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
 
 		if (error_bg && error_a)
 			return (error_bg | error_a);
 
-		
+
 		for (i = 0; i < rateset.count; i++)
 			if ((rateset.rates[i] & 0x7f) > rate)
 				break;
 		rateset.count = htod32(i);
 
-		
+
 		if ((error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, sizeof(rateset))))
 			return error;
 	}
@@ -4647,7 +4713,7 @@
 
 	WL_TRACE(("%s: SIOCGIWRATE\n", dev->name));
 
-	
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate))))
 		return error;
 	rate = dtoh32(rate);
@@ -4762,7 +4828,7 @@
 	uint16 txpwrmw;
 	WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name));
 
-	
+
 	disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
 	disable += WL_RADIO_SW_DISABLE << 16;
 
@@ -4770,15 +4836,15 @@
 	if ((error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable))))
 		return error;
 
-	
+
 	if (disable & WL_RADIO_SW_DISABLE)
 		return 0;
 
-	
+
 	if (!(vwrq->flags & IW_TXPOW_MWATT))
 		return -EINVAL;
 
-	
+
 	if (vwrq->value < 0)
 		return 0;
 
@@ -4830,32 +4896,32 @@
 
 	WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name));
 
-	
+
 	if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
 		return -EINVAL;
 
-	
+
 	if (vwrq->flags & IW_RETRY_LIMIT) {
 
-		
+
 #if WIRELESS_EXT > 20
 	if ((vwrq->flags & IW_RETRY_LONG) ||(vwrq->flags & IW_RETRY_MAX) ||
 		!((vwrq->flags & IW_RETRY_SHORT) || (vwrq->flags & IW_RETRY_MIN))) {
 #else
 	if ((vwrq->flags & IW_RETRY_MAX) || !(vwrq->flags & IW_RETRY_MIN)) {
-#endif 
+#endif
 			lrl = htod32(vwrq->value);
 			if ((error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(lrl))))
 				return error;
 		}
 
-		
+
 #if WIRELESS_EXT > 20
 	if ((vwrq->flags & IW_RETRY_SHORT) ||(vwrq->flags & IW_RETRY_MIN) ||
 		!((vwrq->flags & IW_RETRY_LONG) || (vwrq->flags & IW_RETRY_MAX))) {
 #else
 		if ((vwrq->flags & IW_RETRY_MIN) || !(vwrq->flags & IW_RETRY_MAX)) {
-#endif 
+#endif
 			srl = htod32(vwrq->value);
 			if ((error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, sizeof(srl))))
 				return error;
@@ -4876,13 +4942,13 @@
 
 	WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name));
 
-	vwrq->disabled = 0;      
+	vwrq->disabled = 0;
 
-	
+
 	if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
 		return -EINVAL;
 
-	
+
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl))) ||
 	    (error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl))))
 		return error;
@@ -4890,7 +4956,7 @@
 	lrl = dtoh32(lrl);
 	srl = dtoh32(srl);
 
-	
+
 	if (vwrq->flags & IW_RETRY_MAX) {
 		vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
 		vwrq->value = lrl;
@@ -4903,7 +4969,7 @@
 
 	return 0;
 }
-#endif 
+#endif
 
 static int
 wl_iw_set_encode(
@@ -4927,7 +4993,7 @@
 	memset(&key, 0, sizeof(key));
 
 	if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
-		
+
 		for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
 			val = htod32(key.index);
 			if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
@@ -4936,7 +5002,7 @@
 			if (val)
 				break;
 		}
-		
+
 		if (key.index == DOT11_MAX_DEFAULT_KEYS)
 			key.index = 0;
 	} else {
@@ -4945,9 +5011,9 @@
 			return -EINVAL;
 	}
 
-	
+
 	if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
-		
+
 		val = htod32(key.index);
 		if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, sizeof(val))))
 			return error;
@@ -4979,13 +5045,13 @@
 			return -EINVAL;
 		}
 
-		
+
 		swap_key_from_BE(&key);
 		if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key))))
 			return error;
 	}
 
-	
+
 	val = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
 
 	if ((error = dev_wlc_intvar_get(dev, "wsec", &wsec)))
@@ -4997,7 +5063,7 @@
 	if ((error = dev_wlc_intvar_set(dev, "wsec", wsec)))
 		return error;
 
-	
+
 	val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
 	val = htod32(val);
 	if ((error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val))))
@@ -5019,11 +5085,11 @@
 
 	WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name));
 
-	
+
 	bzero(&key, sizeof(wl_wsec_key_t));
 
 	if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
-		
+
 		for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
 			val = key.index;
 			if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
@@ -5038,7 +5104,7 @@
 	if (key.index >= DOT11_MAX_DEFAULT_KEYS)
 		key.index = 0;
 
-	
+
 
 	if ((error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec))) ||
 	    (error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth))))
@@ -5048,21 +5114,21 @@
 
 	wsec = dtoh32(wsec);
 	auth = dtoh32(auth);
-	
+
 	dwrq->length = MIN(DOT11_MAX_KEY_SIZE, key.len);
 
-	
+
 	dwrq->flags = key.index + 1;
 	if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) {
-		
+
 		dwrq->flags |= IW_ENCODE_DISABLED;
 	}
 	if (auth) {
-		
+
 		dwrq->flags |= IW_ENCODE_RESTRICTED;
 	}
 
-	
+
 	if (dwrq->length && extra)
 		memcpy(extra, key.data, dwrq->length);
 
@@ -5121,6 +5187,11 @@
 	char *extra
 )
 {
+#ifdef WAPI
+	uchar buf[WLC_IOCTL_SMLEN] = {0};
+	uchar *p = buf;
+	int wapi_ie_size;
+#endif /* WAPI */
 
 	WL_TRACE(("%s: SIOCSIWGENIE\n", dev->name));
 
@@ -5136,7 +5207,16 @@
 	}
 #endif
 
+#ifdef WAPI
+	if (extra[0] == DOT11_MNG_WAPI_ID)
+	{
+		wapi_ie_size = iwp->length;
+		memcpy(p, extra, iwp->length);
+		dev_wlc_bufvar_set(dev, "wapiie", buf, wapi_ie_size);
+	}
+	else
 		dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
+#endif /* WAPI */
 
 	return 0;
 }
@@ -5174,34 +5254,34 @@
 	memset(&key, 0, sizeof(key));
 	iwe = (struct iw_encode_ext *)extra;
 
-	
+
 	if (dwrq->flags & IW_ENCODE_DISABLED) {
 
 	}
 
-	
+
 	key.index = 0;
 	if (dwrq->flags & IW_ENCODE_INDEX)
 		key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
 
 	key.len = iwe->key_len;
 
-	
+
 	if (!ETHER_ISMULTI(iwe->addr.sa_data))
 		bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, ETHER_ADDR_LEN);
 
-	
+
 	if (key.len == 0) {
 		if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
 			WL_WSEC(("Changing the the primary Key to %d\n", key.index));
-			
+
 			key.index = htod32(key.index);
 			error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
 				&key.index, sizeof(key.index));
 			if (error)
 				return error;
 		}
-		
+
 		else {
 			swap_key_from_BE(&key);
 			dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
@@ -5226,7 +5306,7 @@
 			bcopy(keybuf, &key.data[16], sizeof(keybuf));
 		}
 
-		
+
 		if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
 			uchar *ivptr;
 			ivptr = (uchar *)iwe->rx_seq;
@@ -5252,6 +5332,14 @@
 			case IW_ENCODE_ALG_CCMP:
 				key.algo = CRYPTO_ALGO_AES_CCM;
 				break;
+#ifdef WAPI
+			case IW_ENCODE_ALG_SM4:
+				key.algo = CRYPTO_ALGO_SMS4;
+				if (iwe->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
+					key.flags &= ~WL_PRIMARY_KEY;
+				}
+				break;
+#endif /* WAPI */
 			default:
 				break;
 		}
@@ -5382,7 +5470,7 @@
 			sizeof(pmkid_list));
 	return ret;
 }
-#endif 
+#endif
 
 static int
 wl_iw_get_encodeext(
@@ -5403,25 +5491,33 @@
 	wl_iw_t *iw = NETDEV_PRIV(dev);
 	uint32 wsec;
 
-	
+
 	if (iw->pcipher & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
 		wsec = WEP_ENABLED;
 	else if (iw->pcipher & IW_AUTH_CIPHER_TKIP)
 		wsec = TKIP_ENABLED;
 	else if (iw->pcipher & IW_AUTH_CIPHER_CCMP)
 		wsec = AES_ENABLED;
+#ifdef WAPI
+	else if (iw->pcipher & IW_AUTH_CIPHER_SMS4)
+		wsec = SMS4_ENABLED;
+#endif /* WAPI */
 	else
 		wsec = 0;
 
-	
+
 	if (iw->gcipher & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
 		wsec |= WEP_ENABLED;
 	else if (iw->gcipher & IW_AUTH_CIPHER_TKIP)
 		wsec |= TKIP_ENABLED;
 	else if (iw->gcipher & IW_AUTH_CIPHER_CCMP)
 		wsec |= AES_ENABLED;
+#ifdef WAPI
+	else if (iw->gcipher & IW_AUTH_CIPHER_SMS4)
+		wsec |= SMS4_ENABLED;
+#endif /* WAPI */
 
-	
+
 	if (wsec == 0 && iw->privacy_invoked)
 		wsec = WEP_ENABLED;
 
@@ -5472,7 +5568,7 @@
 
 	switch (paramid) {
 	case IW_AUTH_WPA_VERSION:
-		
+
 		iw->wpaversion = paramval;
 		break;
 
@@ -5496,16 +5592,21 @@
 				val = WPA_AUTH_PSK;
 			else if (iw->wpaversion == IW_AUTH_WPA_VERSION_WPA2)
 				val = WPA2_AUTH_PSK;
-			else 
+			else
 				val = WPA_AUTH_DISABLED;
 		} else if (paramval & IW_AUTH_KEY_MGMT_802_1X) {
 			if (iw->wpaversion == IW_AUTH_WPA_VERSION_WPA)
 				val = WPA_AUTH_UNSPECIFIED;
 			else if (iw->wpaversion == IW_AUTH_WPA_VERSION_WPA2)
 				val = WPA2_AUTH_UNSPECIFIED;
-			else 
+			else
 				val = WPA_AUTH_DISABLED;
 		}
+#ifdef WAPI
+		else if (paramval & (IW_AUTH_KEY_MGMT_WAPI_PSK | IW_AUTH_KEY_MGMT_WAPI_CERT)) {
+			val = WPA_AUTH_WAPI;
+		}
+#endif /* WAPI */
 		else
 			val = WPA_AUTH_DISABLED;
 
@@ -5519,7 +5620,7 @@
 		break;
 
 	case IW_AUTH_80211_AUTH_ALG:
-		
+
 		WL_INFORM(("Setting the D11auth %d\n", paramval));
 		if (paramval == IW_AUTH_ALG_OPEN_SYSTEM)
 			val = 0;
@@ -5535,7 +5636,7 @@
 
 	case IW_AUTH_WPA_ENABLED:
 		if (paramval == 0) {
-			iw->privacy_invoked = 0; 
+			iw->privacy_invoked = 0;
 			iw->pcipher = 0;
 			iw->gcipher = 0;
 			val = wl_iw_create_wpaauth_wsec(dev);
@@ -5547,7 +5648,7 @@
 			return error;
 		}
 
-		
+
 		break;
 
 	case IW_AUTH_DROP_UNENCRYPTED:
@@ -5562,7 +5663,7 @@
 #if WIRELESS_EXT > 17
 	case IW_AUTH_ROAMING_CONTROL:
 		WL_INFORM(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
-		
+
 		break;
 
 	case IW_AUTH_PRIVACY_INVOKED:
@@ -5571,8 +5672,27 @@
 		if ((error = dev_wlc_intvar_set(dev, "wsec", val)))
 			return error;
 		break;
+#ifdef WAPI
+	case IW_AUTH_WAPI_ENABLED:
+		if ((error = dev_wlc_intvar_get(dev, "wsec", &val)))
+			return error;
+		if (paramval) {
+			val |= SMS4_ENABLED;
+			if ((error = dev_wlc_intvar_set(dev, "wsec", val))) {
+				WL_ERROR(("%s: setting wsec to 0x%0x returned error %d\n",
+					__FUNCTION__, val, error));
+				return error;
+			}
+			if ((error = dev_wlc_intvar_set(dev, "wpa_auth", WPA_AUTH_WAPI))) {
+				WL_ERROR(("%s: setting wpa_auth(WPA_AUTH_WAPI) returned %d\n",
+					__FUNCTION__, error));
+				return error;
+			}
+		}
 
-#endif 
+		break;
+#endif /* WAPI */
+#endif
 	default:
 		break;
 	}
@@ -5612,7 +5732,7 @@
 		break;
 
 	case IW_AUTH_KEY_MGMT:
-		
+
 		if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
 			return error;
 		if (VAL_PSK(val))
@@ -5635,7 +5755,7 @@
 		break;
 
 	case IW_AUTH_80211_AUTH_ALG:
-		
+
 		if ((error = dev_wlc_intvar_get(dev, "auth", &val)))
 			return error;
 		if (!val)
@@ -5654,18 +5774,18 @@
 #if WIRELESS_EXT > 17
 	case IW_AUTH_ROAMING_CONTROL:
 		WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
-		
+
 		break;
 	case IW_AUTH_PRIVACY_INVOKED:
 		paramval = iw->privacy_invoked;
 		break;
 
-#endif 
+#endif
 	}
 	vwrq->value = paramval;
 	return 0;
 }
-#endif 
+#endif
 
 
 #ifdef SOFTAP
@@ -5690,12 +5810,12 @@
 	case 28:
 	case 34:
 	case 66:
-		
+
 		if (!strnicmp(keystr, "0x", 2))
 			keystr += 2;
 		else
 			return -1;
-		
+
 	case 10:
 	case 26:
 	case 32:
@@ -5719,7 +5839,7 @@
 		key->algo = CRYPTO_ALGO_WEP128;
 		break;
 	case 16:
-		
+
 		key->algo = CRYPTO_ALGO_AES_CCM;
 		break;
 	case 32:
@@ -5729,7 +5849,7 @@
 		return -1;
 	}
 
-	
+
 	key->flags |= WL_PRIMARY_KEY;
 
 	return 0;
@@ -5751,7 +5871,7 @@
 	return -1;
 }
 
-#endif 
+#endif
 
 
 static int
@@ -5795,11 +5915,11 @@
 	uint namelen;
 	uint iolen;
 
-	prefixlen = strlen(prefix);	
-	namelen = strlen(iovar) + 1;	
+	prefixlen = strlen(prefix);
+	namelen = strlen(iovar) + 1;
 	iolen = prefixlen + namelen + sizeof(int) + paramlen;
 
-	
+
 	if (buflen < 0 || iolen > (uint)buflen) {
 		*perr = BCME_BUFTOOSHORT;
 		return 0;
@@ -5807,27 +5927,27 @@
 
 	p = (int8*)bufptr;
 
-	
+
 	memcpy(p, prefix, prefixlen);
 	p += prefixlen;
 
-	
+
 	memcpy(p, iovar, namelen);
 	p += namelen;
 
-	
+
 	bssidx = htod32(bssidx);
 	memcpy(p, &bssidx, sizeof(int32));
 	p += sizeof(int32);
 
-	
+
 	if (paramlen)
 		memcpy(p, param, paramlen);
 
 	*perr = 0;
 	return iolen;
 }
-#endif 
+#endif
 
 
 
@@ -5857,15 +5977,15 @@
 	}
 
 #ifdef PNO_SUPPORT
-	
+
 	if  (dhd_dev_get_pno_status(dev)) {
 		WL_ERROR(("%s: Scan called when PNO is active\n", __FUNCTION__));
 	}
-#endif 
+#endif
 
 	params_size += WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t);
 
-	
+
 	if (nssid > 0) {
 		i = OFFSETOF(wl_scan_params_t, channel_list) + nchan * sizeof(uint16);
 		i = ROUNDUP(i, sizeof(uint32));
@@ -5882,7 +6002,7 @@
 		p = (char*)iscan->iscan_ex_params_p->params.channel_list + nchan * sizeof(uint16);
 	}
 
-	
+
 	iscan->iscan_ex_params_p->params.channel_num =
 	        htod32((nssid << WL_SCAN_PARAMS_NSSID_SHIFT) |
 	               (nchan & WL_SCAN_PARAMS_COUNT_MASK));
@@ -5891,7 +6011,7 @@
 	        ((iscan->iscan_ex_params_p->params.channel_num >> WL_SCAN_PARAMS_NSSID_SHIFT) &
 	         WL_SCAN_PARAMS_COUNT_MASK);
 
-	
+
 	params_size = (int) (p - (char*)iscan->iscan_ex_params_p + nssid * sizeof(wlc_ssid_t));
 	iscan->iscan_ex_param_size = params_size;
 
@@ -5925,7 +6045,7 @@
 		WL_SCAN(("scan_type=%d\n", iscan->iscan_ex_params_p->params.scan_type));
 		WL_SCAN(("\n###################\n"));
 	}
-#endif 
+#endif
 
 	if (params_size > WLC_IOCTL_MEDLEN) {
 			WL_ERROR(("Set ISCAN for %s due to params_size=%d  \n",
@@ -5988,7 +6108,7 @@
 
 	str_ptr = extra;
 
-	
+
 	if (strncmp(str_ptr, GET_SSID, strlen(GET_SSID))) {
 		WL_ERROR(("%s Error: extracting SSID='' string\n", __FUNCTION__));
 		res = -EINVAL;
@@ -6007,13 +6127,13 @@
 	memset(iscan->iscan_ex_params_p, 0, iscan->iscan_ex_param_size);
 	ASSERT(iscan->iscan_ex_param_size < WLC_IOCTL_MAXLEN);
 
-	
+
 	wl_iw_iscan_prep(&iscan->iscan_ex_params_p->params, NULL);
 	iscan->iscan_ex_params_p->version = htod32(ISCAN_REQ_VERSION);
 	iscan->iscan_ex_params_p->action = htod16(WL_SCAN_ACTION_START);
 	iscan->iscan_ex_params_p->scan_duration = htod16(0);
 
-	
+
 	if ((nchan = wl_iw_parse_channel_list(&str_ptr,
 	                                      &iscan->iscan_ex_params_p->params.channel_list[0],
 	                                      WL_NUMCHANNELS)) == -1) {
@@ -6022,7 +6142,7 @@
 		goto exit_proc;
 	}
 
-	
+
 	get_parameter_from_string(&str_ptr,
 	                          GET_NPROBE, PTYPE_INTDEC,
 	                          &iscan->iscan_ex_params_p->params.nprobes, 2);
@@ -6039,7 +6159,7 @@
 	get_parameter_from_string(&str_ptr, GET_SCAN_TYPE, PTYPE_INTDEC,
 	                          &iscan->iscan_ex_params_p->params.scan_type, 1);
 
-	
+
 	res = wl_iw_combined_scan_set(dev, ssids_local, nssid, nchan);
 
 exit_proc:
@@ -6071,20 +6191,20 @@
 	char tlv_in_example[] = {
 		'C', 'S', 'C', 'A', 'N', ' ',
 		0x53, 0x01, 0x00, 0x00,
-		'S',	  
-		0x00, 
-		'S',    
-		0x04, 
+		'S',
+		0x00,
+		'S',
+		0x04,
 		'B', 'R', 'C', 'M',
 		'C',
-		0x06, 
-		'P', 
+		0x06,
+		'P',
 		0x94,
 		0x11,
-		'T',     
-		0x01  
+		'T',
+		0x01
 	};
-#endif 
+#endif
 
 	WL_TRACE(("\n### %s: info->cmd:%x, info->flags:%x, u.data=0x%p, u.len=%d\n",
 		__FUNCTION__, info->cmd, info->flags,
@@ -6109,7 +6229,7 @@
 	for (i = 0; i < wrqu->data.length; i++)
 		printf("%02X ", extra[i]);
 	printf("\n");
-#endif 
+#endif
 
 	str_ptr = extra;
 	str_ptr +=  strlen(CSCAN_COMMAND);
@@ -6117,7 +6237,7 @@
 
 	cscan_tlv_temp = (cscan_tlv_t *)str_ptr;
 	memset(ssids_local, 0, sizeof(ssids_local));
-	
+
 	if ((cscan_tlv_temp->prefix == CSCAN_TLV_PREFIX) &&
 		(cscan_tlv_temp->version == CSCAN_TLV_VERSION) &&
 		(cscan_tlv_temp->subver == CSCAN_TLV_SUBVERSION))
@@ -6125,29 +6245,29 @@
 		str_ptr += sizeof(cscan_tlv_t);
 		tlv_size_left  -= sizeof(cscan_tlv_t);
 
-		
+
 		if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
 			WL_SCAN_PARAMS_SSID_MAX, &tlv_size_left)) <= 0) {
 			WL_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid));
 			goto exit_proc;
 		}
 		else {
-			
+
 			memset(iscan->iscan_ex_params_p, 0, iscan->iscan_ex_param_size);
 
-			
+
 			wl_iw_iscan_prep(&iscan->iscan_ex_params_p->params, NULL);
 			iscan->iscan_ex_params_p->version = htod32(ISCAN_REQ_VERSION);
 			iscan->iscan_ex_params_p->action = htod16(WL_SCAN_ACTION_START);
 			iscan->iscan_ex_params_p->scan_duration = htod16(0);
 
-			
+
 			while (tlv_size_left > 0)
 			{
 			type = str_ptr[0];
 			switch (type) {
 				case CSCAN_TLV_TYPE_CHANNEL_IE:
-					
+
 					if ((nchan = wl_iw_parse_channel_list_tlv(&str_ptr,
 					&iscan->iscan_ex_params_p->params.channel_list[0],
 					WL_NUMCHANNELS, &tlv_size_left)) == -1) {
@@ -6213,7 +6333,7 @@
 					goto exit_proc;
 				break;
 				}
-			} 
+			}
 			}
 		}
 		else {
@@ -6224,7 +6344,7 @@
 #if defined(CONFIG_FIRST_SCAN)
 		if (g_first_broadcast_scan < BROADCAST_SCAN_FIRST_RESULT_CONSUMED) {
 			if (++g_first_counter_scans == MAX_ALLOWED_BLOCK_SCAN_FROM_FIRST_SCAN) {
-				
+
 				WL_ERROR(("%s Clean up First scan flag which is %d\n",
 					__FUNCTION__, g_first_broadcast_scan));
 				g_first_broadcast_scan = BROADCAST_SCAN_FIRST_RESULT_CONSUMED;
@@ -6235,9 +6355,9 @@
 				return -EBUSY;
 			}
 		}
-#endif 
+#endif
 
-		
+
 		res = wl_iw_combined_scan_set(dev, ssids_local, nssid, nchan);
 
 exit_proc:
@@ -6245,9 +6365,8 @@
 	return res;
 }
 
-#endif 
+#endif
 
-#ifdef CONFIG_WPS2
 static int
 wl_iw_del_wps_probe_req_ie(
 	struct net_device *dev,
@@ -6256,20 +6375,26 @@
 	char *extra
 )
 {
-	int ret;
+	int ret, req_ie_len;
+	char *req_ie;
 	vndr_ie_setbuf_t *ie_delbuf;
 
-	if (g_wps_probe_req_ie) {
-		ie_delbuf = (vndr_ie_setbuf_t *)(g_wps_probe_req_ie + strlen("vndr_ie "));
-		strncpy(ie_delbuf->cmd, "del", 3);
-		ie_delbuf->cmd[3] = '\0';
+	DHD_OS_MUTEX_LOCK(&wl_wps_lock);
+	req_ie = g_wps_probe_req_ie;
+	req_ie_len = g_wps_probe_req_ie_len;
+	DHD_OS_MUTEX_UNLOCK(&wl_wps_lock);
 
-		ret = dev_wlc_ioctl(dev, WLC_SET_VAR, g_wps_probe_req_ie, g_wps_probe_req_ie_len);
+	if (req_ie) {
+		ie_delbuf = (vndr_ie_setbuf_t *)(req_ie + strlen("vndr_ie "));
+		strcpy(ie_delbuf->cmd, "del");
+
+		ret = dev_wlc_ioctl(dev, WLC_SET_VAR, req_ie, req_ie_len);
 		if (ret) {
 			WL_ERROR(("ioctl failed %d \n", ret));
+			return ret;
 		}
 
-		kfree(g_wps_probe_req_ie);
+		kfree(req_ie);
 		g_wps_probe_req_ie = NULL;
 		g_wps_probe_req_ie_len = 0;
 	}
@@ -6291,38 +6416,38 @@
 	int ret = 0;
 	vndr_ie_setbuf_t *ie_setbuf = NULL;
 
+	DHD_OS_MUTEX_LOCK(&wl_wps_lock);
 	if (!g_wps_probe_req_ie) {
 		ret = -1;
 		str_ptr = extra;
 		str_ptr += WPS_PROBE_REQ_IE_CMD_LENGTH;
 		datalen = wrqu->data.length - WPS_PROBE_REQ_IE_CMD_LENGTH;
 
-		
-		
+
+
 		buflen = sizeof(vndr_ie_setbuf_t) + datalen - sizeof(vndr_ie_t);
-		ie_setbuf = (vndr_ie_setbuf_t *)kmalloc(buflen, GFP_KERNEL);
+		ie_setbuf = (vndr_ie_setbuf_t *) kzalloc(buflen, GFP_KERNEL);
 		if (!ie_setbuf) {
 			WL_ERROR(("memory alloc failure ie_setbuf\n"));
+			DHD_OS_MUTEX_UNLOCK(&wl_wps_lock);
 			return ret;
 		}
 
-		memset(ie_setbuf, 0x00, buflen);
+		/* Copy the vndr_ie SET command ("add"/"del") to the buffer */
+		strcpy(ie_setbuf->cmd, "add");
 
-		
-		strncpy(ie_setbuf->cmd, "add", VNDR_IE_CMD_LEN - 1);
-		ie_setbuf->cmd[VNDR_IE_CMD_LEN - 1] = '\0';
-
-		
+		/* Buffer contains only 1 IE */
 		iecount = htod32(1);
-		memcpy((void *)&ie_setbuf->vndr_ie_buffer.iecount, &iecount, sizeof(int));
+		ie_setbuf->vndr_ie_buffer.iecount = iecount;
 
-		
-		pktflag = 0x10;
-		memcpy((void *)&ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].pktflag,
-			&pktflag, sizeof(uint32));
+		/*
+		 * The packet flag bit field indicates the packets that will
+		 * contain this IE
+		 */
+		pktflag = htod32(VNDR_IE_PRBREQ_FLAG);
+		ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].pktflag = pktflag;
 
-		memcpy((void *)&ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data,
-			str_ptr, datalen);
+		memcpy((void *)&ie_setbuf->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data, str_ptr, datalen);
 
 		total_len = strlen("vndr_ie ") + buflen;
 		bufptr = (char *)kmalloc(total_len, GFP_KERNEL);
@@ -6363,9 +6488,10 @@
 		kfree(ie_setbuf);
 		ie_setbuf = NULL;
 	}
+	DHD_OS_MUTEX_UNLOCK(&wl_wps_lock);
+
 	return ret;
 }
-#endif
 
 
 #ifdef SOFTAP
@@ -6400,7 +6526,7 @@
 	if (down_timeout(&tsk_ctl->sema, msecs_to_jiffies(1000)) != 0) {
 #else
 	if (down_interruptible(&tsk_ctl->sema) != 0) {
-#endif 
+#endif
 		WL_ERROR(("\n%s: sap_eth_sema timeout \n", __FUNCTION__));
 		ret = -1;
 		goto fail;
@@ -6426,9 +6552,9 @@
 	ap_cfg_running = TRUE;
 
 	dhd_os_spin_unlock(iw->pub, flags);
-	bcm_mdelay(500); 
+	bcm_mdelay(500);
 
-	
+
 	wl_iw_send_priv_event(priv_dev, "AP_SET_CFG_OK");
 
 fail:
@@ -6440,7 +6566,7 @@
 	complete_and_exit(&tsk_ctl->completed, 0);
 	return ret;
 }
-#endif 
+#endif
 #ifndef AP_ONLY
 static int last_auto_channel = 6;
 #endif
@@ -6533,7 +6659,7 @@
 		return ret;
 	}
 	return res;
-} 
+}
 
 
 static int
@@ -6548,6 +6674,8 @@
 	int res = 0;
 	int apsta_var = 0;
 #ifndef AP_ONLY
+	int nmode = 0;
+	int wme = 0;
 	int mpc = 0;
 	int iolen = 0;
 	int mkvar_err = 0;
@@ -6573,17 +6701,17 @@
 
 #ifdef AP_ONLY
 	if (ap_cfg_running) {
-		wl_iw_softap_deassoc_stations(dev, NULL); 
+		wl_iw_softap_deassoc_stations(dev, NULL);
 		ap_cfg_running = FALSE;
 	}
-#endif	
+#endif
 
-	
+
 	if (ap_cfg_running == FALSE) {
 
 #ifndef AP_ONLY
 
-		
+
 		sema_init(&ap_eth_ctl.sema, 0);
 
 		mpc = 0;
@@ -6600,7 +6728,7 @@
 		}
 
 #ifdef AP_ONLY
-		
+
 		apsta_var = 0;
 		if ((res = dev_wlc_ioctl(dev, WLC_SET_AP, &apsta_var, sizeof(apsta_var)))) {
 			WL_ERROR(("%s fail to set apsta_var 0\n", __FUNCTION__));
@@ -6613,7 +6741,7 @@
 		}
 		res = dev_wlc_ioctl(dev, WLC_GET_AP, &apsta_var, sizeof(apsta_var));
 #else
-		
+
 		apsta_var = 1;
 		iolen = wl_bssiovar_mkbuf("apsta",
 			bsscfg_index,  &apsta_var, sizeof(apsta_var)+4,
@@ -6624,8 +6752,16 @@
 			goto fail;
 		}
 		WL_TRACE(("\n>in %s: apsta set result: %d \n", __FUNCTION__, res));
-
-
+		nmode = 0;
+		if ((res = dev_wlc_intvar_set(dev, "nmode", nmode))) {
+		    WL_ERROR(("%s fail to set nmode\n", __FUNCTION__));
+		    goto fail;
+		}
+		wme = 0;
+		if ((res = dev_wlc_intvar_set(dev, "wme", wme))) {
+		    WL_ERROR(("%s fail to set wme\n", __FUNCTION__));
+		    goto fail;
+		}
 		mpc = 0;
 		if ((res = dev_wlc_intvar_set(dev, "mpc", mpc))) {
 			WL_ERROR(("%s fail to set mpc\n", __FUNCTION__));
@@ -6633,7 +6769,7 @@
 		}
 
 
-#endif 
+#endif
 
 		updown = 1;
 		if ((res = dev_wlc_ioctl(dev, WLC_UP, &updown, sizeof(updown))) < 0) {
@@ -6642,7 +6778,7 @@
 		}
 
 	} else {
-		
+
 		if (!ap_net_dev) {
 			WL_ERROR(("%s: ap_net_dev is null\n", __FUNCTION__));
 			goto fail;
@@ -6650,7 +6786,7 @@
 
 		res = wl_iw_softap_deassoc_stations(ap_net_dev, NULL);
 
-		
+
 		if ((res = dev_iw_write_cfg1_bss_var(dev, 0)) < 0) {
 			WL_ERROR(("%s fail to set bss down\n", __FUNCTION__));
 			goto fail;
@@ -6676,7 +6812,7 @@
 		goto fail;
 	}
 
-	
+
 	if ((ap->channel == 0) && (get_softap_auto_channel(dev, ap) < 0)) {
 		ap->channel = 1;
 		WL_ERROR(("%s auto channel failed, use channel=%d\n",
@@ -6706,7 +6842,7 @@
 	ap_ssid.SSID_len = strlen(ap->ssid);
 	strncpy(ap_ssid.SSID, ap->ssid, ap_ssid.SSID_len);
 
-	
+
 #ifdef AP_ONLY
 	if ((res = wl_iw_set_ap_security(dev, &my_ap)) != 0) {
 		WL_ERROR(("ERROR:%d in:%s, wl_iw_set_ap_security is skipped\n",
@@ -6726,11 +6862,11 @@
 		goto fail;
 	}
 	if (ap_cfg_running == FALSE) {
-		
+
 		PROC_START(thr_wait_for_2nd_eth_dev, dev, &ap_eth_ctl, 0);
 	} else {
 		ap_eth_ctl.thr_pid = -1;
-		
+
 		if (ap_net_dev == NULL) {
 			WL_ERROR(("%s ERROR: ap_net_dev is NULL !!!\n", __FUNCTION__));
 			goto fail;
@@ -6739,19 +6875,19 @@
 		WL_ERROR(("%s: %s Configure security & restart AP bss \n",
 		          __FUNCTION__, ap_net_dev->name));
 
-		
+
 		if ((res = wl_iw_set_ap_security(ap_net_dev, &my_ap)) < 0) {
 			WL_ERROR(("%s fail to set security : %d\n", __FUNCTION__, res));
 			goto fail;
 		}
 
-		
+
 		if ((res = dev_iw_write_cfg1_bss_var(dev, 1)) < 0) {
 			WL_ERROR(("%s fail to set bss up\n", __FUNCTION__));
 			goto fail;
 		}
 	}
-#endif 
+#endif
 fail:
 	WL_SOFTAP(("%s exit with %d\n", __FUNCTION__, res));
 
@@ -6760,7 +6896,7 @@
 
 	return res;
 }
-#endif 
+#endif
 
 
 
@@ -6790,7 +6926,7 @@
 
 	if (strnicmp(ap->sec, "open", strlen("open")) == 0) {
 
-	   
+
 		wsec = 0;
 		res = dev_wlc_intvar_set(dev, "wsec", wsec);
 		wpa_auth = WPA_AUTH_DISABLED;
@@ -6802,7 +6938,7 @@
 
 	} else if (strnicmp(ap->sec, "wep", strlen("wep")) == 0) {
 
-	   
+
 		memset(&key, 0, sizeof(key));
 
 		wsec = WEP_ENABLED;
@@ -6830,7 +6966,7 @@
 
 	} else if (strnicmp(ap->sec, "wpa2-psk", strlen("wpa2-psk")) == 0) {
 
-	   
+
 
 		wsec_pmk_t psk;
 		size_t key_len;
@@ -6845,18 +6981,18 @@
 			return -1;
 		}
 
-		
+
 		if (key_len < WSEC_MAX_PSK_LEN) {
 			unsigned char output[2*SHA1HashSize];
 			char key_str_buf[WSEC_MAX_PSK_LEN+1];
 
-			
+
 			memset(output, 0, sizeof(output));
 			pbkdf2_sha1(ap->key, ap->ssid, strlen(ap->ssid), 4096, output, 32);
-			
+
 			ptr = key_str_buf;
 			for (i = 0; i < (WSEC_MAX_PSK_LEN/8); i++) {
-				
+
 				sprintf(ptr, "%02x%02x%02x%02x", (uint)output[i*4],
 				        (uint)output[i*4+1], (uint)output[i*4+2],
 				        (uint)output[i*4+3]);
@@ -6878,7 +7014,7 @@
 
 	} else if (strnicmp(ap->sec, "wpa-psk", strlen("wpa-psk")) == 0) {
 
-		
+
 		wsec_pmk_t psk;
 		size_t key_len;
 
@@ -6892,20 +7028,20 @@
 			return -1;
 		}
 
-		
+
 		if (key_len < WSEC_MAX_PSK_LEN) {
 			unsigned char output[2*SHA1HashSize];
 			char key_str_buf[WSEC_MAX_PSK_LEN+1];
 			bzero(output, 2*SHA1HashSize);
 
 			WL_SOFTAP(("%s: do passhash...\n", __FUNCTION__));
-			
+
 			pbkdf2_sha1(ap->key, ap->ssid, strlen(ap->ssid), 4096, output, 32);
-			
+
 			ptr = key_str_buf;
 			for (i = 0; i < (WSEC_MAX_PSK_LEN/8); i++) {
 				WL_SOFTAP(("[%02d]: %08x\n", i, *((unsigned int*)&output[i*4])));
-				
+
 				sprintf(ptr, "%02x%02x%02x%02x", (uint)output[i*4],
 					(uint)output[i*4+1], (uint)output[i*4+2],
 				        (uint)output[i*4+3]);
@@ -6957,15 +7093,15 @@
 
 	if ((*str_ptr) && !strncmp(*str_ptr, token, strlen(token))) {
 
-		strsep(str_ptr, "=,"); 
+		strsep(str_ptr, "=,");
 		param_str_begin = *str_ptr;
-		strsep(str_ptr, "=,"); 
+		strsep(str_ptr, "=,");
 
 		if (*str_ptr == NULL) {
-			
+
 			parm_str_len = strlen(param_str_begin);
 		} else {
-			param_str_end = *str_ptr-1;  
+			param_str_end = *str_ptr-1;
 			parm_str_len = param_str_end - param_str_begin;
 		}
 
@@ -6981,7 +7117,7 @@
 		switch (param_type) {
 
 			case PTYPE_INTDEC: {
-			
+
 				int *pdst_int = dst;
 				char *eptr;
 
@@ -6997,16 +7133,16 @@
 			break;
 			case PTYPE_STR_HEX: {
 				u8 *buf = dst;
-				
-				param_max_len = param_max_len >> 1;  
+
+				param_max_len = param_max_len >> 1;
 				hstr_2_buf(param_str_begin, buf, param_max_len);
 				dhd_print_buf(buf, param_max_len, 0);
 			}
 			break;
 			default:
-				
+
 				memcpy(dst, param_str_begin, parm_str_len);
-				*((char *)dst + parm_str_len) = 0; 
+				*((char *)dst + parm_str_len) = 0;
 				WL_ERROR((" written as a string:%s\n", (char *)dst));
 			break;
 
@@ -7031,16 +7167,16 @@
 	struct maclist *assoc_maclist = (struct maclist *) mac_buf;
 	bool deauth_all = FALSE;
 
-	
+
 	if (mac == NULL) {
 		deauth_all = TRUE;
-		sta_mac = z_mac;  
+		sta_mac = z_mac;
 	} else {
-		sta_mac = mac;  
+		sta_mac = mac;
 	}
 
 	memset(assoc_maclist, 0, sizeof(mac_buf));
-	assoc_maclist->count = 8; 
+	assoc_maclist->count = 8;
 
 	res = dev_wlc_ioctl(dev, WLC_GET_ASSOCLIST, assoc_maclist, 128);
 	if (res != 0) {
@@ -7052,11 +7188,11 @@
 		for (i = 0; i < assoc_maclist->count; i++) {
 		scb_val_t scbval;
 		scbval.val = htod32(1);
-		
+
 		bcopy(&assoc_maclist->ea[i], &scbval.ea, ETHER_ADDR_LEN);
 
 		if (deauth_all || (memcmp(&scbval.ea, sta_mac, ETHER_ADDR_LEN) == 0))  {
-			
+
 			WL_SOFTAP(("%s, deauth STA:%d \n", __FUNCTION__, i));
 			res |= dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON,
 				&scbval, sizeof(scb_val_t));
@@ -7066,7 +7202,7 @@
 	if (res != 0) {
 		WL_ERROR(("%s: Error:%d\n", __FUNCTION__, res));
 	} else if (assoc_maclist->count) {
-		
+
 		bcm_mdelay(200);
 	}
 	return res;
@@ -7101,7 +7237,7 @@
 			WL_ERROR(("%s failed to del BSS err = %d", __FUNCTION__, res));
 #endif
 
-		
+
 		bcm_mdelay(100);
 
 		wrqu->data.length = 0;
@@ -7126,7 +7262,7 @@
 {
 	int ret = -1;
 	char extra[256];
-	char *fwstr = fw_path ; 
+	char *fwstr = fw_path ;
 
 	WL_SOFTAP(("current firmware_path[]=%s\n", fwstr));
 
@@ -7144,7 +7280,7 @@
 			goto exit_proc;
 		}
 
-		
+
 		extra[wrqu->data.length] = 8;
 		str_ptr = extra;
 
@@ -7206,13 +7342,13 @@
 		return -EFAULT;
 	}
 
-	
+
 	res = wl_iw_send_priv_event(dev, params);
 	kfree(params);
 
 	return res;
 }
-#endif 
+#endif
 
 
 static int
@@ -7234,21 +7370,21 @@
 
 	WL_TRACE(("%s: rcvd IWPRIV IOCTL:  for dev:%s\n", __FUNCTION__, dev->name));
 
-	
+
 #ifndef AP_ONLY
 	if ((res = wl_iw_set_ap_security(dev, &my_ap)) != 0) {
 		WL_ERROR((" %s ERROR setting SOFTAP security in :%d\n", __FUNCTION__, res));
 	}
 	else {
-		
+
 		if ((res = dev_iw_write_cfg1_bss_var(dev, 1)) < 0)
 			WL_ERROR(("%s fail to set bss up err=%d\n", __FUNCTION__, res));
 		else
-			
+
 			bcm_mdelay(100);
 	}
 
-#endif 
+#endif
 	WL_SOFTAP(("%s done with res %d \n", __FUNCTION__, res));
 
 	DHD_OS_MUTEX_UNLOCK(&wl_softap_lock);
@@ -7260,7 +7396,7 @@
 static int
 get_assoc_sta_list(struct net_device *dev, char *buf, int len)
 {
-	
+
 	WL_TRACE(("%s: dev_wlc_ioctl(dev:%p, cmd:%d, buf:%p, len:%d)\n",
 		__FUNCTION__, dev, WLC_GET_ASSOCLIST, buf, len));
 
@@ -7284,30 +7420,30 @@
 	int i;
 	int mac_mode = mac_list_set->mode;
 	int ioc_res = 0;
-	ap_macmode = mac_list_set->mode;  
+	ap_macmode = mac_list_set->mode;
 
-	
+
 	bzero(&ap_black_list, sizeof(struct mflist));
 
 	if (mac_mode == MACLIST_MODE_DISABLED) {
-		
+
 		ioc_res = dev_wlc_ioctl(dev, WLC_SET_MACMODE, &mac_mode, sizeof(mac_mode));
 		check_error(ioc_res, "ioctl ERROR:", __FUNCTION__, __LINE__);
 		WL_SOFTAP(("%s: MAC filtering disabled\n", __FUNCTION__));
 	} else {
-		
+
 		scb_val_t scbval;
 		char mac_buf[256] = {0};
 		struct maclist *assoc_maclist = (struct maclist *) mac_buf;
 
-		
+
 		bcopy(maclist, &ap_black_list, sizeof(ap_black_list));
 
-		
+
 		ioc_res = dev_wlc_ioctl(dev, WLC_SET_MACMODE, &mac_mode, sizeof(mac_mode));
 		check_error(ioc_res, "ioctl ERROR:", __FUNCTION__, __LINE__);
 
-		
+
 		length = sizeof(maclist->count) + maclist->count*ETHER_ADDR_LEN;
 		dev_wlc_ioctl(dev, WLC_SET_MACLIST, maclist, length);
 
@@ -7321,18 +7457,18 @@
 				maclist->ea[i].octet[3], maclist->ea[i].octet[4],
 				maclist->ea[i].octet[5]));
 
-		
+
 		assoc_maclist->count = 8;
 		ioc_res = dev_wlc_ioctl(dev, WLC_GET_ASSOCLIST, assoc_maclist, 256);
 		check_error(ioc_res, "ioctl ERROR:", __FUNCTION__, __LINE__);
 		WL_SOFTAP((" Cur assoc clients:%d\n", assoc_maclist->count));
 
-		
+
 		if (assoc_maclist->count)
 			for (i = 0; i < assoc_maclist->count; i++) {
 				int j;
 				bool assoc_mac_matched = FALSE;
-				
+
 				WL_SOFTAP(("\n Cheking assoc STA: "));
 				dhd_print_buf(&assoc_maclist->ea[i], 6, 7);
 				WL_SOFTAP(("with the b/w list:"));
@@ -7340,12 +7476,12 @@
 				for (j = 0; j < maclist->count; j++)
 					if (!bcmp(&assoc_maclist->ea[i], &maclist->ea[j],
 						ETHER_ADDR_LEN)) {
-						
+
 						assoc_mac_matched = TRUE;
 						break;
 					}
 
-				
+
 				if (((mac_mode == MACLIST_MODE_ALLOW) && !assoc_mac_matched) ||
 					((mac_mode == MACLIST_MODE_DENY) && assoc_mac_matched)) {
 
@@ -7366,14 +7502,14 @@
 				}
 		} else {
 			WL_SOFTAP(("No ASSOC CLIENTS\n"));
-		} 
+		}
 
-	} 
+	}
 
 	WL_SOFTAP(("%s iocres:%d\n", __FUNCTION__, ioc_res));
 	return ioc_res;
 }
-#endif 
+#endif
 
 
 
@@ -7397,7 +7533,7 @@
 
 		WL_SOFTAP((" AP_CFG \n"));
 
-		
+
 		if (init_ap_profile_from_string(cmd_str+PROFILE_OFFSET, &my_ap) != 0) {
 				WL_ERROR(("ERROR: SoftAP CFG prams !\n"));
 				ret = -1;
@@ -7409,14 +7545,14 @@
 
 		WL_SOFTAP(("\n SOFTAP - ENABLE BSS \n"));
 
-		
+
 		WL_SOFTAP(("\n!!! got 'WL_AP_EN_BSS' from WPA supplicant, dev:%s\n", dev->name));
 
 #ifndef AP_ONLY
 		if (ap_net_dev == NULL) {
 				 printf("\n ERROR: SOFTAP net_dev* is NULL !!!\n");
 		} else {
-			  
+
 			if ((ret = iwpriv_en_ap_bss(ap_net_dev, info, dwrq, cmd_str)) < 0)
 				WL_ERROR(("%s line %d fail to set bss up\n",
 					__FUNCTION__, __LINE__));
@@ -7428,7 +7564,7 @@
 #endif
 	} else if (strnicmp(sub_cmd, "ASSOC_LST", strlen("ASSOC_LST")) == 0) {
 
-		
+
 
 	} else if (strnicmp(sub_cmd, "AP_BSS_STOP", strlen("AP_BSS_STOP")) == 0) {
 
@@ -7444,7 +7580,7 @@
 	return ret;
 
 }
-#endif 
+#endif
 
 
 static int
@@ -7469,7 +7605,7 @@
 	WL_TRACE(("%s: SIOCSIWPRIV request %s, info->cmd:%x, info->flags:%d\n dwrq->length:%d\n",
 		dev->name, extra, info->cmd, info->flags, dwrq->length));
 
-	
+
 
 	net_os_wake_lock(dev);
 
@@ -7491,14 +7627,14 @@
 			WL_TRACE(("%s: active scan setting suppressed\n", dev->name));
 #else
 			ret = wl_iw_set_active_scan(dev, info, (union iwreq_data *)dwrq, extra);
-#endif 
+#endif
 		}
 		else if (strnicmp(extra, "SCAN-PASSIVE", strlen("SCAN-PASSIVE")) == 0)
 #ifdef ENABLE_ACTIVE_PASSIVE_SCAN_SUPPRESS
 			WL_TRACE(("%s: passive scan setting suppressed\n", dev->name));
 #else
 			ret = wl_iw_set_passive_scan(dev, info, (union iwreq_data *)dwrq, extra);
-#endif 
+#endif
 		else if (strnicmp(extra, "RSSI", strlen("RSSI")) == 0)
 			ret = wl_iw_get_rssi(dev, info, (union iwreq_data *)dwrq, extra);
 		else if (strnicmp(extra, "LINKSPEED", strlen("LINKSPEED")) == 0)
@@ -7528,22 +7664,16 @@
 			ret = wl_iw_set_pno_set(dev, info, (union iwreq_data *)dwrq, extra);
 		else if (strnicmp(extra, PNOENABLE_SET_CMD, strlen(PNOENABLE_SET_CMD)) == 0)
 			ret = wl_iw_set_pno_enable(dev, info, (union iwreq_data *)dwrq, extra);
-#endif 
+#endif
 #if defined(CSCAN)
-	    
+
 		else if (strnicmp(extra, CSCAN_COMMAND, strlen(CSCAN_COMMAND)) == 0)
 			ret = wl_iw_set_cscan(dev, info, (union iwreq_data *)dwrq, extra);
-#endif 
-#ifdef CONFIG_WPS2
-		else if (strnicmp(extra, WPS_ADD_PROBE_REQ_IE_CMD,
-			strlen(WPS_ADD_PROBE_REQ_IE_CMD)) == 0)
-			ret = wl_iw_add_wps_probe_req_ie(dev, info,
-				(union iwreq_data *)dwrq, extra);
-		else if (strnicmp(extra, WPS_DEL_PROBE_REQ_IE_CMD,
-			strlen(WPS_DEL_PROBE_REQ_IE_CMD)) == 0)
-			ret = wl_iw_del_wps_probe_req_ie(dev, info,
-				(union iwreq_data *)dwrq, extra);
-#endif 
+#endif
+	    else if (strnicmp(extra, WPS_ADD_PROBE_REQ_IE_CMD, strlen(WPS_ADD_PROBE_REQ_IE_CMD)) == 0)
+			ret = wl_iw_add_wps_probe_req_ie(dev, info, (union iwreq_data *)dwrq, extra);
+	    else if (strnicmp(extra, WPS_DEL_PROBE_REQ_IE_CMD, strlen(WPS_DEL_PROBE_REQ_IE_CMD)) == 0)
+			ret = wl_iw_del_wps_probe_req_ie(dev, info, (union iwreq_data *)dwrq, extra);
 		else if (strnicmp(extra, "POWERMODE", strlen("POWERMODE")) == 0)
 			ret = wl_iw_set_power_mode(dev, info, (union iwreq_data *)dwrq, extra);
 		else if (strnicmp(extra, "BTCOEXMODE", strlen("BTCOEXMODE")) == 0)
@@ -7552,6 +7682,7 @@
 			ret = wl_iw_get_power_mode(dev, info, (union iwreq_data *)dwrq, extra);
 #ifdef SOFTAP
 		else if (strnicmp(extra, "ASCII_CMD", strlen("ASCII_CMD")) == 0) {
+
 			wl_iw_process_private_ascii_cmd(dev, info, (union iwreq_data *)dwrq, extra);
 		}
 		else if (strnicmp(extra, "AP_MAC_LIST_SET", strlen("AP_MAC_LIST_SET")) == 0) {
@@ -7582,83 +7713,83 @@
 
 static const iw_handler wl_iw_handler[] =
 {
-	(iw_handler) wl_iw_config_commit,	
-	(iw_handler) wl_iw_get_name,		
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_set_freq,		
-	(iw_handler) wl_iw_get_freq,		
-	(iw_handler) wl_iw_set_mode,		
-	(iw_handler) wl_iw_get_mode,		
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_get_range,		
-	(iw_handler) wl_iw_set_priv,		
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_set_spy,		
-	(iw_handler) wl_iw_get_spy,		
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_set_wap,		
-	(iw_handler) wl_iw_get_wap,		
+	(iw_handler) wl_iw_config_commit,
+	(iw_handler) wl_iw_get_name,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_set_freq,
+	(iw_handler) wl_iw_get_freq,
+	(iw_handler) wl_iw_set_mode,
+	(iw_handler) wl_iw_get_mode,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_get_range,
+	(iw_handler) wl_iw_set_priv,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_set_spy,
+	(iw_handler) wl_iw_get_spy,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_set_wap,
+	(iw_handler) wl_iw_get_wap,
 #if WIRELESS_EXT > 17
-	(iw_handler) wl_iw_mlme,		
+	(iw_handler) wl_iw_mlme,
 #else
-	(iw_handler) NULL,			
+	(iw_handler) NULL,
 #endif
 #if defined(WL_IW_USE_ISCAN)
-	(iw_handler) wl_iw_iscan_get_aplist,	
+	(iw_handler) wl_iw_iscan_get_aplist,
 #else
-	(iw_handler) wl_iw_get_aplist,		
-#endif 
+	(iw_handler) wl_iw_get_aplist,
+#endif
 #if WIRELESS_EXT > 13
 #if defined(WL_IW_USE_ISCAN)
-	(iw_handler) wl_iw_iscan_set_scan,	
-	(iw_handler) wl_iw_iscan_get_scan,	
+	(iw_handler) wl_iw_iscan_set_scan,
+	(iw_handler) wl_iw_iscan_get_scan,
 #else
-	(iw_handler) wl_iw_set_scan,		
-	(iw_handler) wl_iw_get_scan,		
+	(iw_handler) wl_iw_set_scan,
+	(iw_handler) wl_iw_get_scan,
 #endif
-#else	
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-#endif	
-	(iw_handler) wl_iw_set_essid,		
-	(iw_handler) wl_iw_get_essid,		
-	(iw_handler) wl_iw_set_nick,		
-	(iw_handler) wl_iw_get_nick,		
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_set_rate,		
-	(iw_handler) wl_iw_get_rate,		
-	(iw_handler) wl_iw_set_rts,		
-	(iw_handler) wl_iw_get_rts,		
-	(iw_handler) wl_iw_set_frag,		
-	(iw_handler) wl_iw_get_frag,		
-	(iw_handler) wl_iw_set_txpow,		
-	(iw_handler) wl_iw_get_txpow,		
+#else
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+#endif
+	(iw_handler) wl_iw_set_essid,
+	(iw_handler) wl_iw_get_essid,
+	(iw_handler) wl_iw_set_nick,
+	(iw_handler) wl_iw_get_nick,
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_set_rate,
+	(iw_handler) wl_iw_get_rate,
+	(iw_handler) wl_iw_set_rts,
+	(iw_handler) wl_iw_get_rts,
+	(iw_handler) wl_iw_set_frag,
+	(iw_handler) wl_iw_get_frag,
+	(iw_handler) wl_iw_set_txpow,
+	(iw_handler) wl_iw_get_txpow,
 #if WIRELESS_EXT > 10
-	(iw_handler) wl_iw_set_retry,		
-	(iw_handler) wl_iw_get_retry,		
-#endif 
-	(iw_handler) wl_iw_set_encode,		
-	(iw_handler) wl_iw_get_encode,		
-	(iw_handler) wl_iw_set_power,		
-	(iw_handler) wl_iw_get_power,		
+	(iw_handler) wl_iw_set_retry,
+	(iw_handler) wl_iw_get_retry,
+#endif
+	(iw_handler) wl_iw_set_encode,
+	(iw_handler) wl_iw_get_encode,
+	(iw_handler) wl_iw_set_power,
+	(iw_handler) wl_iw_get_power,
 #if WIRELESS_EXT > 17
-	(iw_handler) NULL,			
-	(iw_handler) NULL,			
-	(iw_handler) wl_iw_set_wpaie,		
-	(iw_handler) wl_iw_get_wpaie,		
-	(iw_handler) wl_iw_set_wpaauth,		
-	(iw_handler) wl_iw_get_wpaauth,		
-	(iw_handler) wl_iw_set_encodeext,	
-	(iw_handler) wl_iw_get_encodeext,	
-	(iw_handler) wl_iw_set_pmksa,			
-#endif 
+	(iw_handler) NULL,
+	(iw_handler) NULL,
+	(iw_handler) wl_iw_set_wpaie,
+	(iw_handler) wl_iw_get_wpaie,
+	(iw_handler) wl_iw_set_wpaauth,
+	(iw_handler) wl_iw_get_wpaauth,
+	(iw_handler) wl_iw_set_encodeext,
+	(iw_handler) wl_iw_get_encodeext,
+	(iw_handler) wl_iw_set_pmksa,
+#endif
 };
 
 #if WIRELESS_EXT > 12
@@ -7677,47 +7808,47 @@
 	(iw_handler)wl_iw_control_wl_off,
 	NULL,
 	(iw_handler)wl_iw_control_wl_on,
-#ifdef SOFTAP       
+#ifdef SOFTAP
 
-	
+
 	NULL,
 	(iw_handler)iwpriv_set_ap_config,
 
-	
-	
+
+
 	NULL,
 	(iw_handler)iwpriv_get_assoc_list,
 
-	
+
 	NULL,
 	(iw_handler)iwpriv_set_mac_filters,
 
-	
+
 	NULL,
 	(iw_handler)iwpriv_en_ap_bss,
 
-	
+
 	NULL,
 	(iw_handler)iwpriv_wpasupp_loop_tst,
-	
+
 	NULL,
 	(iw_handler)iwpriv_softap_stop,
-	
+
 	NULL,
 	(iw_handler)iwpriv_fw_reload,
-	NULL, 
+	NULL,
 	(iw_handler)iwpriv_set_ap_sta_disassoc,
-#endif 
+#endif
 #if defined(CSCAN)
-	
+
 	NULL,
 	(iw_handler)iwpriv_set_cscan
-#endif 	
+#endif
 };
 
 static const struct iw_priv_args wl_iw_priv_args[] =
 {
-	{	
+	{
 		WL_IW_SET_ACTIVE_SCAN,
 		0,
 		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
@@ -7761,30 +7892,30 @@
 	},
 
 #ifdef SOFTAP
-	
-	
+
+
 	{
 		WL_SET_AP_CFG,
-		IW_PRIV_TYPE_CHAR |  256,      
+		IW_PRIV_TYPE_CHAR |  256,
 		0,
 		"AP_SET_CFG"
 	},
 
 	{
 		WL_AP_STA_LIST,
-		IW_PRIV_TYPE_CHAR | 0,	
-		IW_PRIV_TYPE_CHAR | 1024,  
+		IW_PRIV_TYPE_CHAR | 0,
+		IW_PRIV_TYPE_CHAR | 1024,
 		"AP_GET_STA_LIST"
 	},
 
 	{
 		WL_AP_MAC_FLTR,
-		IW_PRIV_TYPE_CHAR | 256,                      
-		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,    
+		IW_PRIV_TYPE_CHAR | 256,
+		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,
 		"AP_SET_MAC_FLTR"
 	},
 
-	{ 
+	{
 		WL_AP_BSS_START,
 		0,
 		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
@@ -7793,32 +7924,32 @@
 
 	{
 		AP_LPB_CMD,
-		IW_PRIV_TYPE_CHAR | 256,   
-		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,    
+		IW_PRIV_TYPE_CHAR | 256,
+		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,
 		"AP_LPB_CMD"
 	},
 
-	{ 
+	{
 		WL_AP_STOP,
-		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,   
-		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,   
+		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,
+		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,
 		"AP_BSS_STOP"
 	},
-	{ 
+	{
 		WL_FW_RELOAD,
 		IW_PRIV_TYPE_CHAR | 256,
 		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 0,
 		"WL_FW_RELOAD"
 	},
-#endif 
+#endif
 #if defined(CSCAN)
-	{ 
+	{
 		WL_COMBO_SCAN,
-		IW_PRIV_TYPE_CHAR | 1024,  
+		IW_PRIV_TYPE_CHAR | 1024,
 		0,
 		"CSCAN"
 	},
-#endif 
+#endif
 	};
 
 const struct iw_handler_def wl_iw_handler_def =
@@ -7832,9 +7963,9 @@
 
 #if WIRELESS_EXT >= 19
 	get_wireless_stats: dhd_get_wireless_stats,
-#endif 
+#endif
 	};
-#endif 
+#endif
 
 
 
@@ -7882,7 +8013,7 @@
 		break;
 
 	case SIOCGIWRANGE:
-		
+
 		max_tokens = sizeof(struct iw_range) + 500;
 		break;
 
@@ -7900,7 +8031,7 @@
 #endif
 		max_tokens = IW_SCAN_MAX_DATA;
 		break;
-#endif 
+#endif
 
 	case SIOCSIWSPY:
 		token_size = sizeof(struct sockaddr);
@@ -7915,7 +8046,7 @@
 #if WIRELESS_EXT > 17
 	case SIOCSIWPMKSA:
 	case SIOCSIWGENIE:
-#endif 
+#endif
 	case SIOCSIWPRIV:
 		max_tokens = wrq->u.data.length;
 		break;
@@ -7968,18 +8099,18 @@
 	char* stringBuf, uint buflen)
 {
 	typedef struct conn_fail_event_map_t {
-		uint32 inEvent;			
-		uint32 inStatus;		
-		uint32 inReason;		
-		const char* outName;	
-		const char* outCause;	
+		uint32 inEvent;
+		uint32 inStatus;
+		uint32 inReason;
+		const char* outName;
+		const char* outCause;
 	} conn_fail_event_map_t;
 
-	
+
 #define WL_IW_DONT_CARE	9999
 	const conn_fail_event_map_t event_map [] = {
-		
-		
+
+
 		{WLC_E_SET_SSID,     WLC_E_STATUS_SUCCESS,   WL_IW_DONT_CARE,
 		"Conn", "Success"},
 		{WLC_E_SET_SSID,     WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
@@ -8018,7 +8149,7 @@
 	const char* cause = NULL;
 	int i;
 
-	
+
 	for (i = 0;  i < sizeof(event_map)/sizeof(event_map[0]);  i++) {
 		const conn_fail_event_map_t* row = &event_map[i];
 		if (row->inEvent == event_type &&
@@ -8030,7 +8161,7 @@
 		}
 	}
 
-	
+
 	if (cause) {
 		memset(stringBuf, 0, buflen);
 		snprintf(stringBuf, buflen, "%s %s %02d %02d",
@@ -8057,11 +8188,11 @@
 	else
 		return FALSE;
 }
-#endif 
+#endif
 
 #ifndef IW_CUSTOM_MAX
-#define IW_CUSTOM_MAX 256 
-#endif 
+#define IW_CUSTOM_MAX 256
+#endif
 
 void
 wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void* data)
@@ -8087,7 +8218,7 @@
 
 	WL_TRACE(("%s: dev=%s event=%d \n", __FUNCTION__, dev->name, event_type));
 
-	
+
 	switch (event_type) {
 #if defined(SOFTAP)
 	case WLC_E_PRUNE:
@@ -8097,7 +8228,7 @@
 				macaddr[0], macaddr[1], macaddr[2], macaddr[3],
 				macaddr[4], macaddr[5]));
 
-			
+
 			if (ap_macmode)
 			{
 				int i;
@@ -8110,7 +8241,7 @@
 				}
 
 				if (i == ap_black_list.count) {
-					
+
 					char mac_buf[32] = {0};
 					sprintf(mac_buf, "STA_BLOCK %02X:%02X:%02X:%02X:%02X:%02X",
 						macaddr[0], macaddr[1], macaddr[2],
@@ -8120,7 +8251,7 @@
 			}
 		}
 		break;
-#endif 
+#endif
 	case WLC_E_TXFAIL:
 		cmd = IWEVTXDROP;
 		memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
@@ -8136,7 +8267,7 @@
 			wl_iw_send_priv_event(priv_dev, "STA_JOIN");
 			goto wl_iw_event_end;
 		}
-#endif 
+#endif
 		memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
 		wrqu.addr.sa_family = ARPHRD_ETHER;
 		cmd = IWEVREGISTERED;
@@ -8156,7 +8287,7 @@
 			wl_iw_send_priv_event(priv_dev, "STA_LEAVE");
 			goto wl_iw_event_end;
 		}
-#endif 
+#endif
 		cmd = SIOCGIWAP;
 		bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
 		wrqu.addr.sa_family = ARPHRD_ETHER;
@@ -8166,34 +8297,36 @@
 	case WLC_E_NDIS_LINK:
 		cmd = SIOCGIWAP;
 		if (!(flags & WLC_EVENT_MSG_LINK)) {
-			
-			
+
+
 #ifdef SOFTAP
 #ifdef AP_ONLY
 		if (ap_cfg_running) {
 #else
 		if (ap_cfg_running && !strncmp(dev->name, "wl0.1", 5)) {
-#endif	
-			
+#endif
+
 			WL_SOFTAP(("AP DOWN %d\n", event_type));
 			wl_iw_send_priv_event(priv_dev, "AP_DOWN");
 		} else {
 			WL_TRACE(("STA_Link Down\n"));
 			g_ss_cache_ctrl.m_link_down = 1;
+			g_bt->link_up = FALSE;
+			smp_wmb();
 		}
-#else		
+#else
 		g_ss_cache_ctrl.m_link_down = 1;
-#endif 
+#endif
 			WL_TRACE(("Link Down\n"));
 
 			bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
 			bzero(&extra, ETHER_ADDR_LEN);
 		}
 		else {
-			
+
 			memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
 			g_ss_cache_ctrl.m_link_down = 0;
-			
+
 			memcpy(g_ss_cache_ctrl.m_active_bssid, &e->addr, ETHER_ADDR_LEN);
 #ifdef SOFTAP
 
@@ -8202,17 +8335,20 @@
 #else
 			if (ap_cfg_running && !strncmp(dev->name, "wl0.1", 5)) {
 #endif
-			
+
 				WL_SOFTAP(("AP UP %d\n", event_type));
 				wl_iw_send_priv_event(priv_dev, "AP_UP");
 			} else {
 				WL_TRACE(("STA_LINK_UP\n"));
+				g_bt->link_up = TRUE;
+				smp_wmb();
 			}
 #else
-#endif 
+#endif
 			WL_TRACE(("Link UP\n"));
 
 		}
+		net_os_wake_lock_timeout_enable(dev, DHD_EVENT_TIMEOUT);
 		wrqu.addr.sa_family = ARPHRD_ETHER;
 		break;
 	case WLC_E_ACTION_FRAME:
@@ -8236,7 +8372,7 @@
 			printf("WLC_E_ACTION_FRAME_COMPLETE len %d \n", wrqu.data.length);
 		}
 		break;
-#endif 
+#endif
 #if WIRELESS_EXT > 17
 	case WLC_E_MIC_ERROR: {
 		struct	iw_michaelmicfailure  *micerrevt = (struct  iw_michaelmicfailure  *)&extra;
@@ -8278,11 +8414,12 @@
 		}
 		goto wl_iw_event_end;
 	}
-#endif 
+#endif
 
 	case WLC_E_SCAN_COMPLETE:
 #if defined(WL_IW_USE_ISCAN)
 		if (!g_iscan) {
+
 			WL_ERROR(("Event WLC_E_SCAN_COMPLETE on g_iscan NULL!"));
 			goto wl_iw_event_end;
 		}
@@ -8301,10 +8438,10 @@
 		cmd = SIOCGIWSCAN;
 		wrqu.data.length = strlen(extra);
 		WL_TRACE(("Event WLC_E_SCAN_COMPLETE\n"));
-#endif 
+#endif
 	break;
 
-	
+
 	case WLC_E_PFN_NET_FOUND:
 	{
 		wl_pfn_net_info_t *netinfo;
@@ -8313,6 +8450,7 @@
 		WL_ERROR(("%s Event WLC_E_PFN_NET_FOUND, send %s up : find %s len=%d\n",
 		   __FUNCTION__, PNO_EVENT_UP, netinfo->pfnsubnet.SSID,
 		   netinfo->pfnsubnet.SSID_len));
+		net_os_wake_lock_timeout_enable(dev, DHD_EVENT_TIMEOUT);
 		cmd = IWEVCUSTOM;
 		memset(&wrqu, 0, sizeof(wrqu));
 		strcpy(extra, PNO_EVENT_UP);
@@ -8321,10 +8459,17 @@
 	break;
 
 	default:
-		
+
 		WL_TRACE(("Unknown Event %d: ignoring\n", event_type));
 		break;
 	}
+#ifdef DHD_BCM_WIFI_HDMI
+
+	if (cmd && dhd_bcm_whdmi_enable && strncmp(dev->name,
+		DHD_WHDMI_SOFTAP_IF_NAME, DHD_WHDMI_SOFTAP_IF_NAME_LEN) == 0) {
+
+	} else
+#endif
 		if (cmd) {
 			if (cmd == SIOCGIWSCAN)
 				wireless_send_event(dev, cmd, &wrqu, NULL);
@@ -8333,20 +8478,20 @@
 		}
 
 #if WIRELESS_EXT > 14
-	
+
 	memset(extra, 0, sizeof(extra));
 	if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
 		cmd = IWEVCUSTOM;
 		wrqu.data.length = strlen(extra);
 		wireless_send_event(dev, cmd, &wrqu, extra);
 	}
-#endif 
+#endif
 
-	goto wl_iw_event_end;	
+	goto wl_iw_event_end;
 wl_iw_event_end:
 
 	net_os_wake_unlock(dev);
-#endif 
+#endif
 }
 
 int
@@ -8384,14 +8529,14 @@
 	else
 		wstats->qual.qual = 5;
 
-	
+
 	wstats->qual.level = 0x100 + rssi;
 	wstats->qual.noise = 0x100 + phy_noise;
 #if WIRELESS_EXT > 18
 	wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM);
 #else
 	wstats->qual.updated |= 7;
-#endif 
+#endif
 
 #if WIRELESS_EXT > 11
 	WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n", (int)sizeof(wl_cnt_t)));
@@ -8428,7 +8573,7 @@
 	WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n", dtoh32(cnt.rxrunt)));
 	WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n", dtoh32(cnt.rxgiant)));
 
-#endif 
+#endif
 
 done:
 	return res;
@@ -8450,7 +8595,7 @@
 
 
 #if defined(BT_DHCP_eSCO_FIX)
-	
+
 	set_btc_esco_params(dev, set);
 #endif
 
@@ -8458,12 +8603,12 @@
 #if defined(BT_DHCP_USE_FLAGS)
 	WL_TRACE_COEX(("WI-FI priority boost via bt flags, set:%d\n", set));
 	if (set == TRUE) {
-		
+
 		dev_wlc_bufvar_set(dev, "btc_flags",
 			(char *)&buf_flag7_dhcp_on[0], sizeof(buf_flag7_dhcp_on));
 	}
 	else  {
-		
+
 		dev_wlc_bufvar_set(dev, "btc_flags",
 			(char *)&buf_flag7_default[0], sizeof(buf_flag7_default));
 	}
@@ -8474,13 +8619,96 @@
 #endif
 }
 
+#ifdef BTCOEX_FORCE_PM1
+#define SCO_ACTIVE_CHK_PERIOD 1000
+void btcoex_monitor_func(void)
+{
+	int pm;
+	static int saved_pm = -1;
+	static int is_sco_cnt = 0;
+	int ioctl_res = 0;
+
+	WL_TRACE_COEX(("%s enter is_sco_cnt:%d \n", __FUNCTION__, is_sco_cnt));
+
+	/* read current PM state */
+	if  (dev_wlc_ioctl(g_bt->dev, WLC_GET_PM, &pm, sizeof(pm)) == 0) {
+		if (pm == 0) {
+			WL_TRACE_COEX(("%s PM IS 0, link down? \n", __FUNCTION__));
+			WL_TRACE_COEX(("%s pm:%d, saved_pm:%d \n", __FUNCTION__, pm, saved_pm));
+		}
+	} else {
+		WL_ERROR(("%s: can't read PM at this time\n",__FUNCTION__));
+		goto rearm_tmr_ret;
+	}
+
+	/*  if we got disconnected from AP stop polling & restore PM  */
+	if (!g_bt->link_up || (pm == 0) ) {
+
+		WL_TRACE_COEX(("%s !!!!! Link went down !!!!!, stop monitoring, saved_pm:%d\n",
+		__FUNCTION__, saved_pm));
+
+		pm = 2;
+		ioctl_res = dev_wlc_ioctl(g_bt->dev, WLC_SET_PM, &pm, sizeof(pm));
+		if (ioctl_res)
+			WL_ERROR(("%s: ioctl PM restore error\n",__FUNCTION__));
+
+		saved_pm = -1;
+		return; /* don't reschedule the timer */
+	}
+
+
+	/*  filter out occasional false negative sco detection */
+	if (btcoex_is_sco_active(g_bt->dev)) {
+		is_sco_cnt = 5;
+	} else if (is_sco_cnt)  {
+		is_sco_cnt--;
+	}
+
+	/* we are still connected  keep watching sco/esco status */
+	if (is_sco_cnt) {
+
+		if ((saved_pm == -1) && (pm == 2)) {
+			saved_pm = pm;
+			WL_TRACE_COEX(("%s: switch to PM 1 MODE \n",__FUNCTION__));
+
+			pm = 1;
+			ioctl_res = dev_wlc_ioctl(g_bt->dev, WLC_SET_PM, &pm, sizeof(pm));
+			if (ioctl_res)
+				WL_ERROR(("%s: ioctl PM set error\n",__FUNCTION__));
+		} else {
+			/* do nothing: PM is either 0 or 1  */
+			WL_TRACE_COEX(("%s nothing to do: saved_pm:%d, pm:%d\n",
+					__FUNCTION__, saved_pm, pm));
+		}
+
+		/* check if we need to restore PM  no need if */
+	} else if ((saved_pm != -1) ) {
+		/* we may need to restor PM */
+		WL_TRACE_COEX(("%s  SCO/ESCO is gone , changing PM:%d -> to PM:%d\n",
+			__FUNCTION__, pm, saved_pm));
+
+		ioctl_res = dev_wlc_ioctl(g_bt->dev, WLC_SET_PM, &saved_pm, sizeof(pm));
+		if (ioctl_res)
+			WL_ERROR(("%s: ioctl PM restore error\n",__FUNCTION__));
+		saved_pm = -1;
+	}
+
+rearm_tmr_ret:
+	/*  reschedule the timer to keep poling  */
+	mod_timer(&g_bt->timer, jiffies + SCO_ACTIVE_CHK_PERIOD*HZ/1000);
+	g_bt->timer_on = 1;
+
+}
+#endif
+
+
 static void
 wl_iw_bt_timerfunc(ulong data)
 {
 	bt_info_t  *bt_local = (bt_info_t *)data;
 	bt_local->timer_on = 0;
 	WL_TRACE(("%s\n", __FUNCTION__));
-	
+
 	up(&bt_local->tsk_ctl.sema);
 }
 
@@ -8500,14 +8728,24 @@
 			break;
 		}
 
+		net_os_wake_lock(g_bt->dev);
+
 		if (g_bt->timer_on) {
 			g_bt->timer_on = 0;
 			del_timer_sync(&g_bt->timer);
 		}
 
 		switch (g_bt->bt_state) {
+
+			case BT_DHCP_IDLE:
+
+#ifdef BTCOEX_FORCE_PM1
+				btcoex_monitor_func();
+#endif
+				break;
+
 			case BT_DHCP_START:
-				
+
 				WL_TRACE_COEX(("%s bt_dhcp stm: started \n", __FUNCTION__));
 				g_bt->bt_state = BT_DHCP_OPPORTUNITY_WINDOW;
 				mod_timer(&g_bt->timer,
@@ -8522,10 +8760,10 @@
 					goto btc_coex_idle;
 				}
 
-				
+
 				WL_TRACE_COEX(("%s DHCP T1:%d expired\n",
 					__FUNCTION__, BT_DHCP_OPPORTUNITY_WINDOW_TIME));
-				
+
 				if (g_bt->dev) wl_iw_bt_flag_set(g_bt->dev, TRUE);
 				g_bt->bt_state = BT_DHCP_FLAG_FORCE_TIMEOUT;
 				mod_timer(&g_bt->timer, jiffies + BT_DHCP_FLAG_FORCE_TIME*HZ/1000);
@@ -8537,14 +8775,17 @@
 					WL_TRACE_COEX(("%s DHCP Done before T2 expiration\n",
 						__FUNCTION__));
 				} else  {
-					
+
 					WL_TRACE_COEX(("%s DHCP wait interval T2:%d msec expired\n",
 						__FUNCTION__, BT_DHCP_FLAG_FORCE_TIME));
 				}
 
-				
-				if (g_bt->dev)  wl_iw_bt_flag_set(g_bt->dev, FALSE);
+
+				if (g_bt->dev)
+					wl_iw_bt_flag_set(g_bt->dev, FALSE);
+
 			btc_coex_idle:
+				WL_TRACE_COEX(("%s @ btcoex  STM -> idle state \n", __FUNCTION__));
 				g_bt->bt_state = BT_DHCP_IDLE;
 				g_bt->timer_on = 0;
 				break;
@@ -8561,10 +8802,9 @@
 		net_os_wake_unlock(g_bt->dev);
 	}
 
-	if (g_bt->timer_on) {
-		g_bt->timer_on = 0;
-		del_timer_sync(&g_bt->timer);
-	}
+	g_bt->timer_on = 0;
+	del_timer_sync(&g_bt->timer);
+
 	complete_and_exit(&tsk_ctl->completed, 0);
 }
 
@@ -8599,7 +8839,7 @@
 	bt_dhcp->dev = dev;
 	bt_dhcp->bt_state = BT_DHCP_IDLE;
 
-	
+
 	bt_dhcp->timer_ms    = 10;
 	init_timer(&bt_dhcp->timer);
 	bt_dhcp->timer.data = (ulong)bt_dhcp;
@@ -8615,14 +8855,14 @@
 
 	return 0;
 }
-#endif 
+#endif
 
 int
 wl_iw_attach(struct net_device *dev, void * dhdp)
 {
 #if defined(WL_IW_USE_ISCAN)
 	int params_size = 0;
-#endif 
+#endif
 	wl_iw_t *iw;
 #if defined(WL_IW_USE_ISCAN)
 	iscan_info_t *iscan = NULL;
@@ -8630,27 +8870,28 @@
 
 	DHD_OS_MUTEX_INIT(&wl_cache_lock);
 	DHD_OS_MUTEX_INIT(&wl_softap_lock);
+	DHD_OS_MUTEX_INIT(&wl_wps_lock);
 
 #if defined(WL_IW_USE_ISCAN)
 	if (!dev)
 		return 0;
 
-	
+
 	memset(&g_wl_iw_params, 0, sizeof(wl_iw_extra_params_t));
 
-	
+
 #ifdef CSCAN
 	params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params)) +
 	    (WL_NUMCHANNELS * sizeof(uint16)) + WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t);
 #else
 	params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params));
-#endif 
+#endif
 	iscan = kmalloc(sizeof(iscan_info_t), GFP_KERNEL);
 	if (!iscan)
 		return -ENOMEM;
 	memset(iscan, 0, sizeof(iscan_info_t));
 
-	
+
 	iscan->iscan_ex_params_p = (wl_iscan_params_t*)kmalloc(params_size, GFP_KERNEL);
 	if (!iscan->iscan_ex_params_p) {
 		kfree(iscan);
@@ -8658,7 +8899,7 @@
 	}
 	iscan->iscan_ex_param_size = params_size;
 
-	
+
 	g_iscan = iscan;
 	iscan->dev = dev;
 	iscan->iscan_state = ISCAN_STATE_IDLE;
@@ -8667,13 +8908,11 @@
 	g_first_broadcast_scan = BROADCAST_SCAN_FIRST_IDLE;
 	g_first_counter_scans = 0;
 	g_iscan->scan_flag = 0;
-#endif 
+#endif
 
-#ifdef CONFIG_WPS2
 	g_wps_probe_req_ie = NULL;
 	g_wps_probe_req_ie_len = 0;
-#endif
-	
+
 	iscan->timer_ms    = 8000;
 	init_timer(&iscan->timer);
 	iscan->timer.data = (ulong)iscan;
@@ -8682,16 +8921,16 @@
 	PROC_START(_iscan_sysioc_thread, iscan, &iscan->tsk_ctl, 0);
 	if (iscan->tsk_ctl.thr_pid < 0)
 		return -ENOMEM;
-#endif 
+#endif
 
 	iw = *(wl_iw_t **)netdev_priv(dev);
 	iw->pub = (dhd_pub_t *)dhdp;
 #ifdef SOFTAP
 	priv_dev = dev;
-#endif 
+#endif
 	g_scan = NULL;
 
-	
+
 	g_scan = (void *)kmalloc(G_SCAN_RESULTS, GFP_KERNEL);
 	if (!g_scan)
 		return -ENOMEM;
@@ -8700,13 +8939,13 @@
 	g_scan_specified_ssid = 0;
 
 #if !defined(CSCAN)
-	
+
 	wl_iw_init_ss_cache_ctrl();
-#endif 
+#endif
 #ifdef COEX_DHCP
-	
+
 	wl_iw_bt_init(dev);
-#endif 
+#endif
 
 
 	return 0;
@@ -8734,31 +8973,32 @@
 	kfree(iscan);
 	g_iscan = NULL;
 	DHD_OS_MUTEX_UNLOCK(&wl_cache_lock);
-#endif 
+#endif
 
 	if (g_scan)
 		kfree(g_scan);
 
 	g_scan = NULL;
-#ifdef CONFIG_WPS2
 
+	DHD_OS_MUTEX_LOCK(&wl_wps_lock);
 	if (g_wps_probe_req_ie) {
 		kfree(g_wps_probe_req_ie);
 		g_wps_probe_req_ie = NULL;
 		g_wps_probe_req_ie_len = 0;
 	}
-#endif
+	DHD_OS_MUTEX_UNLOCK(&wl_wps_lock);
+
 #if !defined(CSCAN)
 	wl_iw_release_ss_cache_ctrl();
-#endif 
+#endif
 #ifdef COEX_DHCP
 	wl_iw_bt_release();
-#endif 
+#endif
 
 #ifdef SOFTAP
 	if (ap_cfg_running) {
 		WL_TRACE(("\n%s AP is going down\n", __FUNCTION__));
-		
+
 		wl_iw_send_priv_event(priv_dev, "AP_DOWN");
 	}
 #endif
diff --git a/drivers/net/wireless/bcmdhd/wl_iw.h b/drivers/net/wireless/bcmdhd/wl_iw.h
index c0cc14b..f3131f3 100644
--- a/drivers/net/wireless/bcmdhd/wl_iw.h
+++ b/drivers/net/wireless/bcmdhd/wl_iw.h
@@ -2,13 +2,13 @@
  * Linux Wireless Extensions support
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,12 +16,12 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wl_iw.h,v 1.15.80.6 2010-12-23 01:13:23 Exp $
+ * $Id: wl_iw.h,v 1.15.80.6 2010-12-23 01:13:23 $
  */
 
 
@@ -50,7 +50,7 @@
 #define SETSUSPEND_CMD				"SETSUSPENDOPT"
 #define PNOSSIDCLR_SET_CMD			"PNOSSIDCLR"
 
-#define PNOSETUP_SET_CMD			"PNOSETUP " 
+#define PNOSETUP_SET_CMD			"PNOSETUP "
 #define PNOENABLE_SET_CMD			"PNOFORCE"
 #define PNODEBUG_SET_CMD			"PNODEBUG"
 #define TXPOWER_SET_CMD			"TXPOWER"
@@ -60,24 +60,24 @@
 
 
 typedef struct wl_iw_extra_params {
-	int 	target_channel; 
+	int 	target_channel;
 } wl_iw_extra_params_t;
 
 struct cntry_locales_custom {
-	char iso_abbrev[WLC_CNTRY_BUF_SZ];	
-	char custom_locale[WLC_CNTRY_BUF_SZ];	
-	int32 custom_locale_rev;		
+	char iso_abbrev[WLC_CNTRY_BUF_SZ];
+	char custom_locale[WLC_CNTRY_BUF_SZ];
+	int32 custom_locale_rev;
 };
 
 
-#define	WL_IW_RSSI_MINVAL		-200	
-#define	WL_IW_RSSI_NO_SIGNAL	-91	
-#define	WL_IW_RSSI_VERY_LOW	-80	
-#define	WL_IW_RSSI_LOW		-70	
-#define	WL_IW_RSSI_GOOD		-68	
-#define	WL_IW_RSSI_VERY_GOOD	-58	
-#define	WL_IW_RSSI_EXCELLENT	-57	
-#define	WL_IW_RSSI_INVALID	 0	
+#define	WL_IW_RSSI_MINVAL		-200
+#define	WL_IW_RSSI_NO_SIGNAL	-91
+#define	WL_IW_RSSI_VERY_LOW	-80
+#define	WL_IW_RSSI_LOW		-70
+#define	WL_IW_RSSI_GOOD		-68
+#define	WL_IW_RSSI_VERY_GOOD	-58
+#define	WL_IW_RSSI_EXCELLENT	-57
+#define	WL_IW_RSSI_INVALID	 0
 #define MAX_WX_STRING 80
 #define isprint(c) bcm_isprint(c)
 #define WL_IW_SET_ACTIVE_SCAN	(SIOCIWFIRSTPRIV+1)
@@ -117,10 +117,10 @@
 	struct iw_statistics wstats;
 
 	int spy_num;
-	int wpaversion;			
-	int pcipher;			
-	int gcipher;			
-	int privacy_invoked; 		
+	int wpaversion;
+	int pcipher;
+	int gcipher;
+	int privacy_invoked;
 
 	struct ether_addr spy_addr[IW_MAX_SPY];
 	struct iw_quality spy_qual[IW_MAX_SPY];
@@ -144,13 +144,13 @@
 } wl_iw_ss_cache_t;
 
 typedef struct wl_iw_ss_cache_ctrl {
-	wl_iw_ss_cache_t *m_cache_head;	
-	int m_link_down;		
-	int m_timer_expired;		
-	char m_active_bssid[ETHER_ADDR_LEN];	
-	uint m_prev_scan_mode;	
-	uint m_cons_br_scan_cnt;	
-	struct timer_list *m_timer;	
+	wl_iw_ss_cache_t *m_cache_head;
+	int m_link_down;
+	int m_timer_expired;
+	char m_active_bssid[ETHER_ADDR_LEN];
+	uint m_prev_scan_mode;
+	uint m_cons_br_scan_cnt;
+	struct timer_list *m_timer;
 } wl_iw_ss_cache_ctrl_t;
 
 typedef enum broadcast_first_scan {
@@ -168,10 +168,10 @@
 	uint8	ssid[SSID_LEN];
 	uint8	sec[SEC_LEN];
 	uint8	key[KEY_LEN];
-	uint32	channel; 
+	uint32	channel;
 	uint32	preamble;
-	uint32	max_scb;	
-	uint32  closednet;  
+	uint32	max_scb;
+	uint32  closednet;
 	char country_code[WLC_CNTRY_BUF_SZ];
 };
 
@@ -187,12 +187,12 @@
 	uint32	mode;
 	struct mflist mac_list;
 };
-#endif   
+#endif
 
 #if WIRELESS_EXT > 12
 #include <net/iw_handler.h>
 extern const struct iw_handler_def wl_iw_handler_def;
-#endif 
+#endif
 
 extern int wl_iw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 extern void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void* data);
@@ -279,7 +279,7 @@
 #define TLV_TYPE_SECUR				'E'
 #define TLV_TYPE_KEY				'K'
 #define TLV_TYPE_CHANNEL			'C'
-#endif 
+#endif
 
 extern int wl_iw_parse_channel_list_tlv(char** list_str, uint16* channel_list,
 	int channel_num, int *bytes_left);
@@ -297,10 +297,8 @@
 
 #define NETDEV_PRIV(dev)	(*(wl_iw_t **)netdev_priv(dev))
 
-#ifdef CONFIG_WPS2
 #define WPS_ADD_PROBE_REQ_IE_CMD "ADD_WPS_PROBE_REQ_IE "
 #define WPS_DEL_PROBE_REQ_IE_CMD "DEL_WPS_PROBE_REQ_IE "
 #define WPS_PROBE_REQ_IE_CMD_LENGTH 21
-#endif
 
-#endif 
+#endif
diff --git a/drivers/net/wireless/bcmdhd/dhd_linux_mon.c b/drivers/net/wireless/bcmdhd/wl_linux_mon.c
similarity index 91%
rename from drivers/net/wireless/bcmdhd/dhd_linux_mon.c
rename to drivers/net/wireless/bcmdhd/wl_linux_mon.c
index dd9c71f..7022e72 100644
--- a/drivers/net/wireless/bcmdhd/dhd_linux_mon.c
+++ b/drivers/net/wireless/bcmdhd/wl_linux_mon.c
@@ -21,7 +21,7 @@
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: dhd_linux_mon.c,v 1.131.2.55 2011-02-09 05:31:56 Exp $
+ * $Id: wl_linux_mon.c 299401 2011-11-30 00:33:54Z $
  */
 
 #include <linux/string.h>
@@ -96,16 +96,30 @@
 static struct net_device* lookup_real_netdev(char *name)
 {
 	int i;
+	int len = 0;
 	int last_name_len = 0;
 	struct net_device *ndev;
 	struct net_device *ndev_found = NULL;
 
-	/* We want to find interface "p2p-eth0-0" for monitor interface "mon.p2p-eth0-0", so
-	 * we skip "eth0" even if "mon.p2p-eth0-0" contains "eth0"
+	/* We need to find interface "p2p-p2p-0" corresponding to monitor interface "mon-p2p-0",
+	 * Once mon iface name reaches IFNAMSIZ, it is reset to p2p0-0 and corresponding mon
+	 * iface would be mon-p2p0-0.
 	 */
 	for (i = 0; i < DHD_MAX_IFS; i++) {
 		ndev = dhd_idx2net(g_monitor.dhd_pub, i);
-		if (ndev && strstr(name, ndev->name)) {
+
+		/* Skip "p2p" and look for "-p2p0-x" in monitor interface name. If it
+		 * it matches, then this netdev is the corresponding real_netdev.
+		 */
+		if (ndev && strstr(ndev->name, "p2p-p2p0")) {
+			len = strlen("p2p");
+		} else {
+		/* if p2p- is not present, then the IFNAMSIZ have reached and name
+		 * would have got reset. In this casse,look for p2p0-x in mon-p2p0-x
+		 */
+			len = 0;
+		}
+		if (ndev && strstr(name, (ndev->name + len))) {
 			if (strlen(ndev->name) > last_name_len) {
 				ndev_found = ndev;
 				last_name_len = strlen(ndev->name);
@@ -225,9 +239,10 @@
 	mon_if = ndev_to_monif(ndev);
 	if (mon_if == NULL || mon_if->real_ndev == NULL) {
 		MON_PRINT(" cannot find matched net dev, skip the packet\n");
+	} else {
+		MON_PRINT("enter, if name: %s, matched if name %s\n",
+		ndev->name, mon_if->real_ndev->name);
 	}
-
-	MON_PRINT("enter, if name: %s, matched if name %s\n", ndev->name, mon_if->real_ndev->name);
 }
 
 static int dhd_mon_if_change_mac(struct net_device *ndev, void *addr)
@@ -238,9 +253,10 @@
 	mon_if = ndev_to_monif(ndev);
 	if (mon_if == NULL || mon_if->real_ndev == NULL) {
 		MON_PRINT(" cannot find matched net dev, skip the packet\n");
+	} else {
+		MON_PRINT("enter, if name: %s, matched if name %s\n",
+		ndev->name, mon_if->real_ndev->name);
 	}
-
-	MON_PRINT("enter, if name: %s, matched if name %s\n", ndev->name, mon_if->real_ndev->name);
 	return ret;
 }
 
diff --git a/drivers/net/wireless/bcmdhd/wldev_common.c b/drivers/net/wireless/bcmdhd/wldev_common.c
index bb3eaea..cba79a5 100644
--- a/drivers/net/wireless/bcmdhd/wldev_common.c
+++ b/drivers/net/wireless/bcmdhd/wldev_common.c
@@ -2,13 +2,13 @@
  * Common function shared by Linux WEXT, cfg80211 and p2p drivers
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,7 +16,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -24,12 +24,13 @@
  * $Id: wldev_common.c,v 1.1.4.1.2.14 2011-02-09 01:40:07 $
  */
 
-#include <linux/module.h>
+#include <osl.h>
+#include <linux/kernel.h>
+#include <linux/kthread.h>
 #include <linux/netdevice.h>
 
 #include <wldev_common.h>
 #include <bcmutils.h>
-#include <dhd_dbg.h>
 
 #define htod32(i) i
 #define htod16(i) i
@@ -37,6 +38,13 @@
 #define dtoh16(i) i
 #define htodchanspec(i) i
 #define dtohchanspec(i) i
+
+#define	WLDEV_ERROR(args)						\
+	do {										\
+		printk(KERN_ERR "WLDEV-ERROR) %s : ", __func__);	\
+		printk args;							\
+	} while (0)
+
 extern int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd);
 
 s32 wldev_ioctl(
@@ -71,26 +79,34 @@
 
 s32 wldev_iovar_getbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen)
+	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len = 0;
-
+	if (buf_sync) {
+		mutex_lock(buf_sync);
+	}
 	iovar_len = wldev_mkiovar(iovar_name, param, paramlen, buf, buflen);
 	ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE);
+	if (buf_sync)
+		mutex_unlock(buf_sync);
 	return ret;
 }
 
 
 s32 wldev_iovar_setbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen)
+	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len;
-
+	if (buf_sync) {
+		mutex_lock(buf_sync);
+	}
 	iovar_len = wldev_mkiovar(iovar_name, param, paramlen, buf, buflen);
 	ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE);
+	if (buf_sync)
+		mutex_unlock(buf_sync);
 	return ret;
 }
 
@@ -102,7 +118,7 @@
 	val = htod32(val);
 	memset(iovar_buf, 0, sizeof(iovar_buf));
 	return wldev_iovar_setbuf(dev, iovar, &val, sizeof(val), iovar_buf,
-		sizeof(iovar_buf));
+		sizeof(iovar_buf), NULL);
 }
 
 
@@ -114,7 +130,7 @@
 
 	memset(iovar_buf, 0, sizeof(iovar_buf));
 	err = wldev_iovar_getbuf(dev, iovar, pval, sizeof(*pval), iovar_buf,
-		sizeof(iovar_buf));
+		sizeof(iovar_buf), NULL);
 	if (err == 0)
 	{
 		memcpy(pval, iovar_buf, sizeof(*pval));
@@ -148,7 +164,7 @@
 
 	if (buflen < 0 || iolen > (u32)buflen)
 	{
-		DHD_ERROR(("%s: buffer is too short\n", __FUNCTION__));
+		WLDEV_ERROR(("%s: buffer is too short\n", __FUNCTION__));
 		return BCME_BUFTOOSHORT;
 	}
 
@@ -174,29 +190,39 @@
 	return iolen;
 
 }
-
 s32 wldev_iovar_getbuf_bsscfg(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx)
+	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len = 0;
-
+	if (buf_sync) {
+		mutex_lock(buf_sync);
+	}
 	iovar_len = wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx);
 	ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE);
+	if (buf_sync) {
+		mutex_unlock(buf_sync);
+	}
 	return ret;
 
 }
 
 s32 wldev_iovar_setbuf_bsscfg(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx)
+	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len;
-
+	if (buf_sync) {
+		mutex_lock(buf_sync);
+	}
 	iovar_len = wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx);
+
 	ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE);
+	if (buf_sync) {
+		mutex_unlock(buf_sync);
+	}
 	return ret;
 }
 
@@ -208,7 +234,7 @@
 	val = htod32(val);
 	memset(iovar_buf, 0, sizeof(iovar_buf));
 	return wldev_iovar_setbuf_bsscfg(dev, iovar, &val, sizeof(val), iovar_buf,
-		sizeof(iovar_buf), bssidx);
+		sizeof(iovar_buf), bssidx, NULL);
 }
 
 
@@ -220,7 +246,7 @@
 
 	memset(iovar_buf, 0, sizeof(iovar_buf));
 	err = wldev_iovar_getbuf_bsscfg(dev, iovar, pval, sizeof(*pval), iovar_buf,
-		sizeof(iovar_buf), bssidx);
+		sizeof(iovar_buf), bssidx, NULL);
 	if (err == 0)
 	{
 		memcpy(pval, iovar_buf, sizeof(*pval));
@@ -309,16 +335,16 @@
 		return error;
 
 	error = wldev_iovar_getbuf(dev, "country", &cspec, sizeof(cspec),
-		smbuf, sizeof(smbuf));
+		smbuf, sizeof(smbuf), NULL);
 	if (error < 0)
-		DHD_ERROR(("%s: get country failed = %d\n", __FUNCTION__, error));
+		WLDEV_ERROR(("%s: get country failed = %d\n", __FUNCTION__, error));
 
 	if ((error < 0) ||
 	    (strncmp(country_code, smbuf, WLC_CNTRY_BUF_SZ) != 0)) {
 		bzero(&scbval, sizeof(scb_val_t));
 		error = wldev_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t), 1);
 		if (error < 0) {
-			DHD_ERROR(("%s: set country failed due to Disassoc error %d\n",
+			WLDEV_ERROR(("%s: set country failed due to Disassoc error %d\n",
 				__FUNCTION__, error));
 			return error;
 		}
@@ -328,14 +354,14 @@
 	memcpy(cspec.ccode, country_code, WLC_CNTRY_BUF_SZ);
 	get_customized_country_code((char *)&cspec.country_abbrev, &cspec);
 	error = wldev_iovar_setbuf(dev, "country", &cspec, sizeof(cspec),
-		smbuf, sizeof(smbuf));
+		smbuf, sizeof(smbuf), NULL);
 	if (error < 0) {
-		DHD_ERROR(("%s: set country for %s as %s rev %d failed\n",
+		WLDEV_ERROR(("%s: set country for %s as %s rev %d failed\n",
 			__FUNCTION__, country_code, cspec.ccode, cspec.rev));
 		return error;
 	}
 	dhd_bus_country_set(dev, &cspec);
-	DHD_INFO(("%s: set country for %s as %s rev %d\n",
+	WLDEV_ERROR(("%s: set country for %s as %s rev %d\n",
 		__FUNCTION__, country_code, cspec.ccode, cspec.rev));
 	return 0;
 }
diff --git a/drivers/net/wireless/bcmdhd/wldev_common.h b/drivers/net/wireless/bcmdhd/wldev_common.h
index 4632680..ea6b075 100644
--- a/drivers/net/wireless/bcmdhd/wldev_common.h
+++ b/drivers/net/wireless/bcmdhd/wldev_common.h
@@ -2,13 +2,13 @@
  * Common function shared by Linux WEXT, cfg80211 and p2p drivers
  *
  * Copyright (C) 1999-2011, Broadcom Corporation
- * 
+ *
  *         Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -16,38 +16,38 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
  *
- * $Id: wldev_common.h,v 1.1.4.1.2.14 2011-02-09 01:40:07 Exp $
+ * $Id: wldev_common.h,v 1.1.4.1.2.14 2011-02-09 01:40:07 $
  */
 #ifndef __WLDEV_COMMON_H__
 #define __WLDEV_COMMON_H__
 
 #include <wlioctl.h>
 
-/** wl_dev_ioctl - get/set IOCTLs, will call net_device's do_ioctl (or 
+/* wl_dev_ioctl - get/set IOCTLs, will call net_device's do_ioctl (or
  *  netdev_ops->ndo_do_ioctl in new kernels)
  *  @dev: the net_device handle
  */
 s32 wldev_ioctl(
 	struct net_device *dev, u32 cmd, void *arg, u32 len, u32 set);
 
-/** Retrieve named IOVARs, this function calls wl_dev_ioctl with 
+/** Retrieve named IOVARs, this function calls wl_dev_ioctl with
  *  WLC_GET_VAR IOCTL code
  */
 s32 wldev_iovar_getbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen);
+	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync);
 
 /** Set named IOVARs, this function calls wl_dev_ioctl with
  *  WLC_SET_VAR IOCTL code
  */
 s32 wldev_iovar_setbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen);
+	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync);
 
 s32 wldev_iovar_setint(
 	struct net_device *dev, s8 *iovar, s32 val);
@@ -67,15 +67,15 @@
  *  WLC_GET_VAR IOCTL code
  */
 s32 wldev_iovar_getbuf_bsscfg(
-	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx);
+	struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen,
+	void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync);
 
 /** Set named and bsscfg indexed IOVARs, this function calls wl_dev_ioctl with
  *  WLC_SET_VAR IOCTL code
  */
 s32 wldev_iovar_setbuf_bsscfg(
-	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx);
+	struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen,
+	void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync);
 
 s32 wldev_iovar_getint_bsscfg(
 	struct net_device *dev, s8 *iovar, s32 *pval, s32 bssidx);
@@ -94,7 +94,7 @@
 extern int net_os_set_suspend_disable(struct net_device *dev, int val);
 extern int net_os_set_suspend(struct net_device *dev, int val);
 extern int wl_iw_parse_ssid_list_tlv(char** list_str, wlc_ssid_t* ssid,
-					int max, int *bytes_left);
+	int max, int *bytes_left);
 
 /* Get the link speed from dongle, speed is in kpbs */
 int wldev_get_link_speed(struct net_device *dev, int *plink_speed);