From: hwg Date: Tue, 29 Nov 2011 07:41:58 +0000 (+0800) Subject: add atheros ar6003 wifi driver X-Git-Tag: firefly_0821_release~9733^2~14 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b38c45814da8df98fe65ac26c867ad74ea6b1038;p=firefly-linux-kernel-4.4.55.git add atheros ar6003 wifi driver need to remove bt support in menuconfig: Networking support ---> Bluetooth subsystem support. --- diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig index 3027be6e850c..f221fec6806a 100644 --- a/drivers/net/wireless/Kconfig +++ b/drivers/net/wireless/Kconfig @@ -70,6 +70,7 @@ choice (4) Murata SP-8HEP-P source "drivers/net/wireless/rtl8192c/Kconfig" +source "drivers/net/wireless/ar6003/Kconfig" endchoice endif diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile index f463629aa9c2..8f04989765e0 100644 --- a/drivers/net/wireless/Makefile +++ b/drivers/net/wireless/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_BCM4329) += bcm4329/ obj-$(CONFIG_MV8686) += mv8686/ obj-$(CONFIG_BCM4319) += bcm4319/ obj-$(CONFIG_RTL8192CU) += rtl8192c/ +obj-$(CONFIG_AR6003) += ar6003/ #obj-m += wlan/ diff --git a/drivers/net/wireless/ar6003/Kconfig b/drivers/net/wireless/ar6003/Kconfig new file mode 100644 index 000000000000..09841df4af7f --- /dev/null +++ b/drivers/net/wireless/ar6003/Kconfig @@ -0,0 +1,9 @@ + config AR6003 + depends on WLAN_80211 && MMC + select WIRELESS_EXT + select IEEE80211 + select FW_LOADER + bool "Atheros AR6003/AR6302 SDIO" + ---help--- + Atheros ROC AR6003/AR6302. + diff --git a/drivers/net/wireless/ar6003/Makefile b/drivers/net/wireless/ar6003/Makefile new file mode 100644 index 000000000000..380ec1259a06 --- /dev/null +++ b/drivers/net/wireless/ar6003/Makefile @@ -0,0 +1,77 @@ +AR6003_SRC_PATH := drivers/net/wireless/ar6003 + +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/include +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/include +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/wlan/include +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/os/linux/include +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/os/ +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/bmi/include +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/include/AR6002 +EXTRA_CFLAGS += -I${AR6003_SRC_PATH}/host/hif/sdio/linux_sdio/include +EXTRA_CFLAGS += -Idrivers/net/wireless + +EXTRA_CFLAGS += -DLINUX -D__KERNEL__ -DTCMD -DSEND_EVENT_TO_APP -DUSER_KEYS -DNO_SYNC_FLUSH -DHTC_EP_STAT_PROFILING -DWLAN_HEADERS -DATH_AR6K_11N_SUPPORT -DATH_SUPPORT_DFS -DANDROID_ENV -D__linux__ -DINIT_MODE_DRV_ENABLED -DBMIENABLE_SET -DAR600x_SD31_XXX -DATH6KL_SKIP_ABI_VERSION_CHECK -DATH6KL_CONFIG_HIF_VIRTUAL_SCATTER -DCONFIG_HOST_TCMD_SUPPORT -DCONFIG_AP_VIRTUAL_ADAPTER_SUPPORT -DSOFTMAC_FILE_USED -DDEBUG -DATH_DEBUG_MODULE -DAR6002_HEADERS_DEF -DAR6003_HEADERS_DEF -DMCKINLEY_HEADERS_DEF -DKERNEL_2_6 + +ifeq ($(CONFIG_BT),y) +EXTRA_CFLAGS += -DATH_AR6K_ENABLE_GMBOX +EXTRA_CFLAGS += -DHCI_TRANSPORT_SDIO +EXTRA_CFLAGS += -DSETUPHCI_ENABLED +EXTRA_CFLAGS += -DSETUPBTDEV_ENABLED +endif + +EXTRA_CFLAGS += -DRK29 +EXTRA_CFLAGS += -DTCHIP + +olca3-objs := host/hif/sdio/linux_sdio/src/hif.o \ + host/hif/sdio/linux_sdio/src/hif_scatter.o \ + host/hif/common/hif_bmi_reg_access.o \ + host/hif/common/hif_diag_reg_access.o \ + host/wmi/wmi.o \ + host/reorder/rcv_aggr.o \ + host/htc2/AR6000/ar6k.o \ + host/htc2/AR6000/ar6k_events.o \ + host/htc2/htc_services.o \ + host/htc2/htc.o \ + host/htc2/htc_send.o \ + host/htc2/htc_recv.o \ + host/wlan/src/wlan_recv_beacon.o \ + host/wlan/src/wlan_utils.o \ + host/wlan/src/wlan_node.o \ + host/bmi/src/bmi.o \ + host/miscdrv/credit_dist.o \ + host/miscdrv/common_drv.o \ + host/os/linux/hci_bridge.o \ + host/os/linux/netbuf.o \ + host/os/linux/ar6000_android.o \ + host/os/linux/ioctl.o \ + host/os/linux/wireless_ext.o \ + host/os/linux/ar6000_pm.o \ + host/os/linux/ar6000_raw_if.o \ + host/os/linux/ar6000_drv.o \ + host/os/linux/ar6k_pal.o \ + host/regtable/regtable.o \ + host/regtable/AR6002def.o \ + host/regtable/MCKINLEYdef.o \ + host/regtable/AR6003def.o \ + host/dfs/dfs_debug.o \ + host/dfs/dfs_process_phyerr.o \ + host/dfs/dfs.o \ + host/dfs/dfs_misc.o \ + host/dfs/dfs_bindetects.o \ + host/dfs/dfs_init.o \ + host/dfs/dfs_host_project.o \ + host/dfs/dfs_staggered.o \ + host/dfs/dfs_ar.o \ + host/dfs/dfs_process_radarevent.o \ + host/dfs/dfs_fcc_bin5.o + +ifeq ($(CONFIG_BT),y) +olca3-objs += host/htc2/AR6000/ar6k_gmbox.o \ + host/htc2/AR6000/ar6k_gmbox_hciuart.o \ + host/miscdrv/ar3kconfig.o \ + host/miscdrv/ar3kps/ar3kpsconfig.o \ + host/miscdrv/ar3kps/ar3kpsparser.o +endif + +obj-$(CONFIG_AR6003) += olca3.o + diff --git a/drivers/net/wireless/ar6003/clean.sh b/drivers/net/wireless/ar6003/clean.sh new file mode 100644 index 000000000000..be346d1ea5f9 --- /dev/null +++ b/drivers/net/wireless/ar6003/clean.sh @@ -0,0 +1,5 @@ +#!/bin/bash +find . \( -not -path "*.output*" -a -name '*.[oas]' -o -name core -o -name '.*.flags' -o -name '.ko' -o -name '.*.cmd' -o -name 'Module.symvers' -o -name 'modules.order' \) -type f -print \ + | grep -v lxdialog/ | xargs rm -f +find . \( -name '.tmp_versions' \) -type d -print | grep -v lxdialog/ | xargs rm -rf + diff --git a/drivers/net/wireless/ar6003/host/Android.mk b/drivers/net/wireless/ar6003/host/Android.mk new file mode 100644 index 000000000000..cccadb6137bb --- /dev/null +++ b/drivers/net/wireless/ar6003/host/Android.mk @@ -0,0 +1,125 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +ifneq ($(TARGET_SIMULATOR),true) + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +ATH_ANDROID_SRC_BASE:= $(BOARD_WLAN_ATHEROS_SDK) +export ATH_BUILD_TYPE=ANDROID_ARM_NATIVEMMC +export ATH_BUS_TYPE=sdio +export ATH_OS_SUB_TYPE=linux_2_6 + +ATH_ANDROID_ROOT:= $(CURDIR) +export ATH_SRC_BASE:=$(ATH_ANDROID_ROOT)/$(BOARD_WLAN_ATHEROS_SDK)/host +#ATH_CROSS_COMPILE_TYPE:=$(ATH_ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi- +ATH_TARGET_OUTPUT:=$(ATH_ANDROID_ROOT) + +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),qsd8250_surf qsd8250_ffa msm7627_surf msm7627_ffa msm7627a msm7625_ffa msm7625_surf msm7630_surf)) +export ATH_LINUXPATH=$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ +ATH_CROSS_COMPILE_TYPE:=$(ATH_ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi- +endif + +ifndef ATH_LINUXPATH +#check for Nvidia-base platform +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),harmony ventana)) +export ATH_LINUXPATH=$(ATH_ANDROID_ROOT)/$(TARGET_OUT_INTERMEDIATES)/KERNEL +ATH_CROSS_COMPILE_TYPE:=$(CROSS_COMPILE) +endif +endif + +ifndef ATH_LINUXPATH +#check for IMX51 platform +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),imx51_bbg)) +export ATH_LINUXPATH=$(ATH_ANDROID_ROOT)/kernel_imx +ATH_CROSS_COMPILE_TYPE:=$(ATH_ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi- +endif +endif + + +ifndef ATH_LINUXPATH +# Comment out the following variable and $(error) for your platform +# Link your kernel into android SDK directory as 'kernel' directory +# export ATH_LINUXPATH= [Your android/kernel path ] +ATH_CROSS_COMPILE_TYPE:=$(ATH_ANDROID_ROOT)/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi- +$(error define your kernel path here for ATH_LINUXPATH) +endif + +export ATH_ARCH_CPU_TYPE=arm +export ATH_BUS_SUBTYPE=linux_sdio +export ATH_ANDROID_ENV=yes +export ATH_SOFTMAC_FILE_USED=no +export ATH_CFG80211_ENV=no +export ATH_DEBUG_DRIVER=yes +export ATH_HTC_RAW_INT_ENV=yes +export ATH_AR6K_OTA_TEST_MODE=no +export ATH_BUILD_P2P=yes + +ATH_HIF_TYPE:=sdio + +ifneq ($(PLATFORM_VERSION),$(filter $(PLATFORM_VERSION),1.5 1.6)) + +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),msm7627_surf msm7627_ffa GT-I5500)) +ATH_ANDROID_BUILD_FLAGS=-D__LINUX_ARM_ARCH__=6 -march=armv6 -DUSE_4BYTE_REGISTER_ACCESS +#-fstack-check="generic" +endif + +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),qsd8250_surf qsd8250_ffa msm7630_surf smdkc100)) +ATH_ANDROID_BUILD_FLAGS=-D__LINUX_ARM_ARCH__=7 -march=armv7-a -DUSE_4BYTE_REGISTER_ACCESS +#-fstack-check="generic" +endif + +endif # ECLAIR + +ifeq ($(TARGET_PRODUCT),$(filter $(TARGET_PRODUCT),smdk6410)) +ATH_ANDROID_BUILD_FLAGS += -DATH6KL_CONFIG_HIF_VIRTUAL_SCATTER +endif + +#Uncomment the following define in order to enable OTA mode +#ATH_ANDROID_BUILD_FLAGS += -DATH6K_CONFIG_OTA_MODE + +export ATH_ANDROID_BUILD_FLAGS + +mod_cleanup := $(ATH_TARGET_OUTPUT)/$(ATH_ANDROID_SRC_BASE)/dummy + +$(mod_cleanup) : + rm -f `find $(ATH_TARGET_OUTPUT)/$(ATH_ANDROID_SRC_BASE) -name "*.o"` + mkdir -p $(TARGET_OUT)/wifi/ath6k/AR6003/hw2.0/ + +mod_file := os/linux/ar6000.ko +$(ATH_ANDROID_SRC_BASE)/host/$(mod_file) : $(mod_cleanup) $(TARGET_PREBUILT_KERNEL) $(ACP) + $(MAKE) ARCH=arm CROSS_COMPILE=$(ATH_CROSS_COMPILE_TYPE) -C $(ATH_LINUXPATH) ATH_HIF_TYPE=$(ATH_HIF_TYPE) SUBDIRS=$(ATH_SRC_BASE)/os/linux modules + $(ATH_CROSS_COMPILE_TYPE)strip -g -S -d $(ATH_ANDROID_SRC_BASE)/host/$(mod_file) + $(ACP) -fpt $(ATH_ANDROID_SRC_BASE)/host/$(mod_file) $(TARGET_OUT)/wifi + +LOCAL_MODULE := ar6000.ko +LOCAL_MODULE_TAGS := debug eng optional +LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_PATH := $(TARGET_OUT)/wifi +LOCAL_SRC_FILES := $(mod_file) +include $(BUILD_PREBUILT) + +include $(LOCAL_PATH)/tools/Android.mk + +endif diff --git a/drivers/net/wireless/ar6003/host/Makefile b/drivers/net/wireless/ar6003/host/Makefile new file mode 100644 index 000000000000..ee62e661ab19 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/Makefile @@ -0,0 +1,174 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +# AR6K Host driver makefile +# +# Minimal build invocation: +# +# make (all | clean | clobber) +# +# Extended Make invocation: +# +# make ATH_BUILD_TYPE= ATH_SDIO_STACK_BASE= (all | clean | clobber) +# +# Notes: +# 1. This makefile must be invoked from the host/ directory +# 2. The must match an entry in localmake.linux.inc. +# 3. The localmake.linux.inc can be overridden using an include file outside the build tree. +# This file (name and path) can be set via the ATH_MAKE_INCLUDE_OVERRIDE variable. +# ** If ATH_MAKE_INCLUDE_OVERRIDE is used, you can define all build variables in that file +# instead of using command line arguments **. This feature is provided for developers +# that may want to customize the build using a single include file. +# +# For example : +# +# " make ATH_MAKE_INCLUDE_OVERRIDE=$HOME/mymake.inc " +# +# could be used, as long as "mymake.inc" defines all the required variables (see below) +# +# Required Variables: +# +# ATH_OS_SUB_TYPE - on linux, this must be "linux_2_4" for 2.4 kernels or left blank for 2.6 kernels. +# ATH_LINUXPATH - linux kernel source path +# ATH_CROSS_COMPILE_TYPE - optional cross compiler path , leave blank for local gcc compilation +# ATH_ARCH_CPU_TYPE - CPU architecture type, leave blank for local gcc compilation +# ATH_SDIO_STACK_BASE - SDIO Stack installation path to compile the SDIO HIF layer against an externally supplied +# SDIO stack source. +# +# Override variables: +# +# ATH_MAKE_INCLUDE_OVERRIDE - full path to include file which overrides the default (localmake.linux.inc) +# this file can contain other overrides specific to a developers +# workspace environment. +# ATH_BUILD_OUTPUT_OVERRIDE - output path override for compiled executable and +# database image +# + +# Include local variables +ifdef ATH_MAKE_INCLUDE_OVERRIDE +_LOCALMAKE_INCLUDE = $(ATH_MAKE_INCLUDE_OVERRIDE) +else +_LOCALMAKE_INCLUDE = localmake.linux.inc +endif + +-include $(_LOCALMAKE_INCLUDE) + +export ATH_SRC_BASE +export ATH_BUILD_TYPE +export ATH_OS_SUB_TYPE +export ATH_LINUXPATH +export ATH_CROSS_COMPILE_TYPE +export ATH_ARCH_CPU_TYPE +export ATH_SDIO_STACK_BASE +export ATH_BUS_TYPE +export ATH_BUS_SUBTYPE +export ATH_HC_DRIVERS +export ATH_HTC_RAW_INT_ENV +export ATH_ANDROID_ENV +export ATH_SOFTMAC_FILE_USED +export ATH_CFG80211_ENV +export ATH_DEBUG_DRIVER +export ATH_AR6K_HCI_PAL +export ATH_AR6K_DEBUG_ALLOC +#export ATH_BUILD_P2P + +ATH_SRC_BASE :=$(shell pwd) +MAKE :=make +CC :=$(ATH_CROSS_COMPILE_TYPE)gcc +LD :=$(ATH_CROSS_COMPILE_TYPE)ld +STRIP :=$(ATH_CROSS_COMPILE_TYPE)strip +ATH_HIF_TYPE :=`echo $(ATH_BUS_TYPE) | tr [:upper:] [:lower:]` + +export STRIP + +#export compiler variables for 3rd party applications (like the WPA supplicant) +export CC +export LD +export STRIP + +# Set cross compile type (if any) +ifdef ATH_CROSS_COMPILE_TYPE +_CROSS_COMPILE_LINE := ARCH=$(ATH_ARCH_CPU_TYPE) CROSS_COMPILE=$(ATH_CROSS_COMPILE_TYPE) +endif + +# Figure out module extension +ifneq ($(ATH_OS_SUB_TYPE),linux_2_4) +KMOD_EXTENSION :=ko +endif +ifeq ($(ATH_OS_SUB_TYPE),linux_2_4) +KMOD_EXTENSION :=o +endif + +# Set up object output areas +ifdef ATH_BUILD_OUTPUT_OVERRIDE +_COMPILED_OBJECTS_PATH :=$(ATH_BUILD_OUTPUT_OVERRIDE) +COMPILED_BIN_OBJECTS_PATH :=$(ATH_BUILD_OUTPUT_OVERRIDE) +COMPILED_IMAGE_OBJECTS_PATH :=$(ATH_BUILD_OUTPUT_OVERRIDE) +_MAKE_IMAGE_OUTPUT_DIR := +_MAKE_BIN_OUTPUT_DIR := +_CLEAN_IMAGE_OUTPUT_DIR := +_CLEAN_BIN_OUTPUT_DIR := +else +_COMPILED_OBJECTS_PATH := $(ATH_SRC_BASE)/.output/$(ATH_BUILD_TYPE)-$(ATH_BUS_TYPE) +COMPILED_BIN_OBJECTS_PATH := $(ATH_SRC_BASE)/.output/bin +COMPILED_IMAGE_OBJECTS_PATH :=$(_COMPILED_OBJECTS_PATH)/$(COMPILED_OBJECTS_PREFIX)image +_MAKE_IMAGE_OUTPUT_DIR := mkdir --parents $(COMPILED_IMAGE_OBJECTS_PATH) +_MAKE_BIN_OUTPUT_DIR := mkdir --parents $(COMPILED_BIN_OBJECTS_PATH) +_CLEAN_IMAGE_OUTPUT_DIR := rm -R -f $(COMPILED_IMAGE_OBJECTS_PATH) +_CLEAN_BIN_OUTPUT_DIR := rm -R -f $(COMPILED_BIN_OBJECTS_PATH) +endif + +# Export the required variables to other Makefiles in the system +export COMPILED_IMAGE_OBJECTS_PATH +export COMPILED_BIN_OBJECTS_PATH + +all: modules + +modules: +ifndef ATH_BUILD_TYPE + @echo "Please edit the $(_LOCALMAKE_INCLUDE) file" + exit 1 +endif + $(_MAKE_IMAGE_OUTPUT_DIR) + $(_MAKE_BIN_OUTPUT_DIR) + $(MAKE) $(_CROSS_COMPILE_LINE) -C $(ATH_LINUXPATH) ATH_HIF_TYPE=$(ATH_HIF_TYPE) SUBDIRS=$(ATH_SRC_BASE)/os/linux modules + $(MAKE) -C hif/$(ATH_HIF_TYPE) +# $(MAKE) -C tools/wmiconfig/ +# $(MAKE) -C tools/recEvent/ + cp -f $(ATH_SRC_BASE)/os/linux/ar6000.$(KMOD_EXTENSION) $(COMPILED_IMAGE_OBJECTS_PATH) + $(STRIP) -g -S -d $(COMPILED_IMAGE_OBJECTS_PATH)/ar6000.$(KMOD_EXTENSION) +# cp -f tools/wmiconfig/wmiconfig $(COMPILED_IMAGE_OBJECTS_PATH) +# cp -f tools/recEvent/recEvent $(COMPILED_IMAGE_OBJECTS_PATH) +# cp -f tools/recEvent/restore.sh $(COMPILED_IMAGE_OBJECTS_PATH) + +clean: + rm -f os/linux/ar6000.mod.c os/linux/*.o os/linux/*.ko wmi/*.o htc/AR6000/src/*.o htc/*.o \ + bmi/src/*.o wlan/src/*.o driver/* tools/wmiconfig/wmiconfig \ + tools/recEvent/recEvent + +# The kernel module build process leaves some intermediate files, this will clean up all these files + find $(ATH_SRC_BASE) \( -not -path "*.output*" -a -name '*.[oas]' -o -name core -o -name '.*.flags' -o -name '.ko' -o -name '.*.cmd' \) -type f -print \ + | grep -v lxdialog/ | xargs rm -f + $(MAKE) -C hif/$(ATH_HIF_TYPE) clean + +clobber:clean + rm -rf .output diff --git a/drivers/net/wireless/ar6003/host/bmi/include/bmi_internal.h b/drivers/net/wireless/ar6003/host/bmi/include/bmi_internal.h new file mode 100644 index 000000000000..bb155909e65b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/bmi/include/bmi_internal.h @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef BMI_INTERNAL_H +#define BMI_INTERNAL_H + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME bmi +#include "a_debug.h" +#include "bmi_msg.h" + +#define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0) + +/* ------ Global Variable Declarations ------- */ +A_BOOL bmiDone; + +#endif diff --git a/drivers/net/wireless/ar6003/host/bmi/src/bmi.c b/drivers/net/wireless/ar6003/host/bmi/src/bmi.c new file mode 100644 index 000000000000..59a8b92a9a44 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/bmi/src/bmi.c @@ -0,0 +1,774 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// +// Author(s): ="Atheros" +//============================================================================== + + +#include "hif.h" +#include "bmi.h" +#include "bmi_internal.h" + +#ifdef DEBUG +static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = { + { ATH_DEBUG_BMI , "BMI Tracing"}, +}; + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi, + "bmi", + "Boot Manager Interface", + ATH_DEBUG_MASK_DEFAULTS, + ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc), + bmi_debug_desc); + +#endif + +/* +Although we had envisioned BMI to run on top of HTC, this is not how the +final implementation ended up. On the Target side, BMI is a part of the BSP +and does not use the HTC protocol nor even DMA -- it is intentionally kept +very simple. +*/ + +static A_UCHAR *pBMICmdBuf; +#define MAX_BMI_CMDBUF_SZ (BMI_DATASZ_MAX + \ + sizeof(A_UINT32) /* cmd */ + \ + sizeof(A_UINT32) /* addr */ + \ + sizeof(A_UINT32))/* length */ +#define BMI_COMMAND_FITS(sz) ((sz) <= MAX_BMI_CMDBUF_SZ) +#define BMI_EXCHANGE_TIMEOUT_MS 1000 + +/* APIs visible to the driver */ +void +BMIInit(void) +{ + bmiDone = FALSE; + + + /* + * On some platforms, it's not possible to DMA to a static variable + * in a device driver (e.g. Linux loadable driver module). + * So we need to A_MALLOC space for "command credits" and for commands. + * + * Note: implicitly relies on A_MALLOC to provide a buffer that is + * suitable for DMA (or PIO). This buffer will be passed down the + * bus stack. + */ + + if (!pBMICmdBuf) { + pBMICmdBuf = (A_UCHAR *)A_MALLOC_NOWAIT(MAX_BMI_CMDBUF_SZ); + A_ASSERT(pBMICmdBuf); + } + + A_REGISTER_MODULE_DEBUG_INFO(bmi); +} + +void +BMICleanup(void) +{ +#if 0 + if (pBMICmdCredits) { + A_FREE(pBMICmdCredits); + pBMICmdCredits = NULL; + } +#endif + + if (pBMICmdBuf) { + A_FREE(pBMICmdBuf); + pBMICmdBuf = NULL; + } +} + +A_STATUS +BMIDone(HIF_DEVICE *device) +{ + A_STATUS status; + A_UINT32 cid; + + if (bmiDone) { + AR_DEBUG_PRINTF (ATH_DEBUG_BMI, ("BMIDone skipped\n")); + return A_OK; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Enter (device: 0x%p)\n", device)); + bmiDone = TRUE; + cid = BMI_DONE; + A_MEMCPY(pBMICmdBuf,&cid,sizeof(cid)); + + status = HIFExchangeBMIMsg(device, pBMICmdBuf, sizeof(cid), NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + if (pBMICmdBuf) { + A_FREE(pBMICmdBuf); + pBMICmdBuf = NULL; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Exit\n")); + + return A_OK; +} + +#ifndef HIF_MESSAGE_BASED +extern A_STATUS HIFRegBasedGetTargetInfo(HIF_DEVICE *device, struct bmi_target_info *targ_info); +#endif + +A_STATUS +BMIGetTargetInfo(HIF_DEVICE *device, struct bmi_target_info *targ_info) +{ + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI Get Target Info Command disallowed\n")); + return A_ERROR; + } + +#ifndef HIF_MESSAGE_BASED + /* getting the target ID requires special handling because of the variable length + * message */ + return HIFRegBasedGetTargetInfo(device,targ_info); +#else + /* TODO */ + return A_ERROR; +#endif +} + +A_STATUS +BMIReadMemory(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 remaining, rxlen; + + A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length))); + memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Read Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", + device, address, length)); + + cid = BMI_READ_MEMORY; + + remaining = length; + + while (remaining) + { + rxlen = (remaining < BMI_DATASZ_MAX) ? remaining : BMI_DATASZ_MAX; + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + A_MEMCPY(&(pBMICmdBuf[offset]), &rxlen, sizeof(rxlen)); + offset += sizeof(length); + + status = HIFExchangeBMIMsg(device, + pBMICmdBuf, + offset, + pBMICmdBuf, /* note we reuse the same buffer to receive on */ + &rxlen, + BMI_EXCHANGE_TIMEOUT_MS); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); + return A_ERROR; + } + A_MEMCPY(&buffer[length - remaining], pBMICmdBuf, rxlen); + remaining -= rxlen; address += rxlen; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read Memory: Exit\n")); + return A_OK; +} + +A_STATUS +BMIWriteMemory(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 remaining, txlen; + const A_UINT32 header = sizeof(cid) + sizeof(address) + sizeof(length); + A_UCHAR alignedBuffer[BMI_DATASZ_MAX]; + A_UCHAR *src; + + A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + header)); + memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + header); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Write Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", + device, address, length)); + + cid = BMI_WRITE_MEMORY; + + remaining = length; + while (remaining) + { + src = &buffer[length - remaining]; + if (remaining < (BMI_DATASZ_MAX - header)) { + if (remaining & 3) { + /* align it with 4 bytes */ + remaining = remaining + (4 - (remaining & 3)); + memcpy(alignedBuffer, src, remaining); + src = alignedBuffer; + } + txlen = remaining; + } else { + txlen = (BMI_DATASZ_MAX - header); + } + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); + offset += sizeof(txlen); + A_MEMCPY(&(pBMICmdBuf[offset]), src, txlen); + offset += txlen; + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, BMI_EXCHANGE_TIMEOUT_MS); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + remaining -= txlen; address += txlen; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write Memory: Exit\n")); + + return A_OK; +} + +A_STATUS +BMIExecute(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 *param) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 paramLen; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address) + sizeof(param))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address) + sizeof(param)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Execute: Enter (device: 0x%p, address: 0x%x, param: %d)\n", + device, address, *param)); + + cid = BMI_EXECUTE; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + A_MEMCPY(&(pBMICmdBuf[offset]), param, sizeof(*param)); + offset += sizeof(*param); + paramLen = sizeof(*param); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, ¶mLen, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); + return A_ERROR; + } + + A_MEMCPY(param, pBMICmdBuf, sizeof(*param)); + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Execute: Exit (param: %d)\n", *param)); + return A_OK; +} + +A_STATUS +BMISetAppStart(HIF_DEVICE *device, + A_UINT32 address) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Set App Start: Enter (device: 0x%p, address: 0x%x)\n", + device, address)); + + cid = BMI_SET_APP_START; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Set App Start: Exit\n")); + return A_OK; +} + +A_STATUS +BMIReadSOCRegister(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 *param) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset,paramLen; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Read SOC Register: Enter (device: 0x%p, address: 0x%x)\n", + device, address)); + + cid = BMI_READ_SOC_REGISTER; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + paramLen = sizeof(*param); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, ¶mLen, BMI_EXCHANGE_TIMEOUT_MS); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); + return A_ERROR; + } + A_MEMCPY(param, pBMICmdBuf, sizeof(*param)); + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read SOC Register: Exit (value: %d)\n", *param)); + return A_OK; +} + +A_STATUS +BMIWriteSOCRegister(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 param) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address) + sizeof(param))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address) + sizeof(param)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Write SOC Register: Enter (device: 0x%p, address: 0x%x, param: %d)\n", + device, address, param)); + + cid = BMI_WRITE_SOC_REGISTER; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + A_MEMCPY(&(pBMICmdBuf[offset]), ¶m, sizeof(param)); + offset += sizeof(param); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read SOC Register: Exit\n")); + return A_OK; +} + +A_STATUS +BMIrompatchInstall(HIF_DEVICE *device, + A_UINT32 ROM_addr, + A_UINT32 RAM_addr, + A_UINT32 nbytes, + A_UINT32 do_activate, + A_UINT32 *rompatch_id) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset,responseLen; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(ROM_addr) + sizeof(RAM_addr) + + sizeof(nbytes) + sizeof(do_activate))); + memset(pBMICmdBuf, 0, sizeof(cid) + sizeof(ROM_addr) + sizeof(RAM_addr) + + sizeof(nbytes) + sizeof(do_activate)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI rompatch Install: Enter (device: 0x%p, ROMaddr: 0x%x, RAMaddr: 0x%x length: %d activate: %d)\n", + device, ROM_addr, RAM_addr, nbytes, do_activate)); + + cid = BMI_ROMPATCH_INSTALL; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &ROM_addr, sizeof(ROM_addr)); + offset += sizeof(ROM_addr); + A_MEMCPY(&(pBMICmdBuf[offset]), &RAM_addr, sizeof(RAM_addr)); + offset += sizeof(RAM_addr); + A_MEMCPY(&(pBMICmdBuf[offset]), &nbytes, sizeof(nbytes)); + offset += sizeof(nbytes); + A_MEMCPY(&(pBMICmdBuf[offset]), &do_activate, sizeof(do_activate)); + offset += sizeof(do_activate); + responseLen = sizeof(*rompatch_id); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, &responseLen, BMI_EXCHANGE_TIMEOUT_MS); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to install ROM patch\n")); + return A_ERROR; + } + + A_MEMCPY(rompatch_id, pBMICmdBuf, sizeof(*rompatch_id)); + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch Install: (rompatch_id=%d)\n", *rompatch_id)); + return A_OK; +} + +A_STATUS +BMIrompatchUninstall(HIF_DEVICE *device, + A_UINT32 rompatch_id) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(rompatch_id))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(rompatch_id)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI rompatch Uninstall: Enter (device: 0x%p, rompatch_id: %d)\n", + device, rompatch_id)); + + cid = BMI_ROMPATCH_UNINSTALL; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &rompatch_id, sizeof(rompatch_id)); + offset += sizeof(rompatch_id); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch UNinstall: (rompatch_id=0x%x)\n", rompatch_id)); + return A_OK; +} + +static A_STATUS +_BMIrompatchChangeActivation(HIF_DEVICE *device, + A_UINT32 rompatch_count, + A_UINT32 *rompatch_list, + A_UINT32 do_activate) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 length; + + A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + sizeof(cid) + sizeof(rompatch_count))); + memset(pBMICmdBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(rompatch_count)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Change rompatch Activation: Enter (device: 0x%p, count: %d)\n", + device, rompatch_count)); + + cid = do_activate ? BMI_ROMPATCH_ACTIVATE : BMI_ROMPATCH_DEACTIVATE; + + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &rompatch_count, sizeof(rompatch_count)); + offset += sizeof(rompatch_count); + length = rompatch_count * sizeof(*rompatch_list); + A_MEMCPY(&(pBMICmdBuf[offset]), rompatch_list, length); + offset += length; + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Change rompatch Activation: Exit\n")); + + return A_OK; +} + +A_STATUS +BMIrompatchActivate(HIF_DEVICE *device, + A_UINT32 rompatch_count, + A_UINT32 *rompatch_list) +{ + return _BMIrompatchChangeActivation(device, rompatch_count, rompatch_list, 1); +} + +A_STATUS +BMIrompatchDeactivate(HIF_DEVICE *device, + A_UINT32 rompatch_count, + A_UINT32 *rompatch_list) +{ + return _BMIrompatchChangeActivation(device, rompatch_count, rompatch_list, 0); +} + +A_STATUS +BMILZData(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 remaining, txlen; + const A_UINT32 header = sizeof(cid) + sizeof(length); + + A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX+header)); + memset (pBMICmdBuf, 0, BMI_DATASZ_MAX+header); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI Send LZ Data: Enter (device: 0x%p, length: %d)\n", + device, length)); + + cid = BMI_LZ_DATA; + + remaining = length; + while (remaining) + { + txlen = (remaining < (BMI_DATASZ_MAX - header)) ? + remaining : (BMI_DATASZ_MAX - header); + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); + offset += sizeof(txlen); + A_MEMCPY(&(pBMICmdBuf[offset]), &buffer[length - remaining], txlen); + offset += txlen; + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + remaining -= txlen; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI LZ Data: Exit\n")); + + return A_OK; +} + +A_STATUS +BMILZStreamStart(HIF_DEVICE *device, + A_UINT32 address) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); + memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI LZ Stream Start: Enter (device: 0x%p, address: 0x%x)\n", + device, address)); + + cid = BMI_LZ_STREAM_START; + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); + offset += sizeof(address); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to Start LZ Stream to the device\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI LZ Stream Start: Exit\n")); + + return A_OK; +} + +A_STATUS +BMIFastDownload(HIF_DEVICE *device, A_UINT32 address, A_UCHAR *buffer, A_UINT32 length) +{ + A_STATUS status = A_ERROR; + A_UINT32 lastWord = 0; + A_UINT32 lastWordOffset = length & ~0x3; + A_UINT32 unalignedBytes = length & 0x3; + + status = BMILZStreamStart (device, address); + if (A_FAILED(status)) { + return A_ERROR; + } + + if (unalignedBytes) { + /* copy the last word into a zero padded buffer */ + A_MEMCPY(&lastWord, &buffer[lastWordOffset], unalignedBytes); + } + + status = BMILZData(device, buffer, lastWordOffset); + + if (A_FAILED(status)) { + return A_ERROR; + } + + if (unalignedBytes) { + status = BMILZData(device, (A_UINT8 *)&lastWord, 4); + } + + if (A_SUCCESS(status)) { + // + // Close compressed stream and open a new (fake) one. This serves mainly to flush Target caches. + // + status = BMILZStreamStart (device, 0x00); + if (A_FAILED(status)) { + return A_ERROR; + } + } + return status; +} + +A_STATUS +BMInvramProcess(HIF_DEVICE *device, A_UCHAR *seg_name, A_UINT32 *retval) +{ + A_UINT32 cid; + A_STATUS status; + A_UINT32 offset; + A_UINT32 retvalLen; + + A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + BMI_NVRAM_SEG_NAME_SZ)); + + if (bmiDone) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, + ("BMI NVRAM Process: Enter (device: 0x%p, name: %s)\n", + device, seg_name)); + + cid = BMI_NVRAM_PROCESS; + offset = 0; + A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); + offset += sizeof(cid); + A_MEMCPY(&(pBMICmdBuf[offset]), seg_name, BMI_NVRAM_SEG_NAME_SZ); + offset += BMI_NVRAM_SEG_NAME_SZ; + retvalLen = sizeof(*retval); + status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, &retvalLen, 0); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to access the device\n")); + return A_ERROR; + } + + A_MEMCPY(retval, pBMICmdBuf, sizeof(*retval)); + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI NVRAM Process: Exit\n")); + + return A_OK; +} + +#ifdef HIF_MESSAGE_BASED + +/* TODO.. stubs.. for message-based HIFs, the RAW access APIs need to be changed + */ + +A_STATUS +BMIRawWrite(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length) +{ + /* TODO */ + return A_ERROR; +} + +A_STATUS +BMIRawRead(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length, A_BOOL want_timeout) +{ + /* TODO */ + return A_ERROR; +} + +#endif + + diff --git a/drivers/net/wireless/ar6003/host/bmi/src/makefile b/drivers/net/wireless/ar6003/host/bmi/src/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/bmi/src/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs.c b/drivers/net/wireless/ar6003/host/dfs/dfs.c new file mode 100644 index 000000000000..0b87ab42d7c8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2002-2006, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" +#include "dfs_common.h" + +struct ath_dfs_host *dfs_attach_host(DEV_HDL dev, OS_HDL os, ATH_DFS_CAPINFO *cap_info) +{ + int i,n; + struct ath_dfs_host *dfs; + + dfs = (struct ath_dfs_host *)DFS_MALLOC(os, sizeof(struct ath_dfs_host)); + + if (dfs == NULL) { + A_PRINTF("%s: ath_dfs allocation failed\n", __func__); + return dfs; + } + + OS_MEMZERO(dfs, sizeof (struct ath_dfs_host)); + + dfs->dev_hdl = dev; + dfs->os_hdl = os; + + dfs->dfs_debug_level=ATH_DEBUG_DFS; + + ATH_DFSQ_LOCK_INIT(dfs); + STAILQ_INIT(&dfs->dfs_radarq); + ATH_ARQ_LOCK_INIT(dfs); + STAILQ_INIT(&dfs->dfs_arq); + STAILQ_INIT(&(dfs->dfs_eventq)); + ATH_DFSEVENTQ_LOCK_INIT(dfs); + + OS_INIT_TIMER(&dfs->dfs_radar_task_timer, dfs_radar_task, dfs); + + dfs->events = (struct dfs_event *)DFS_MALLOC(os, + sizeof(struct dfs_event)*DFS_MAX_EVENTS); + + if (dfs->events == NULL) { + OS_FREE(dfs); + dfs = NULL; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "%s: events allocation failed\n", __func__); + return dfs; + } + for (i=0; i< DFS_MAX_EVENTS; i++) { + STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), &dfs->events[i], re_list); + } + + dfs->pulses = (struct dfs_pulseline *)DFS_MALLOC(os, sizeof(struct dfs_pulseline)); + + if (dfs->pulses == NULL) { + OS_FREE(dfs->events); + dfs->events = NULL; + OS_FREE(dfs); + dfs = NULL; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "%s: pulse buffer allocation failed\n", __func__); + return dfs; + } + + dfs->pulses->pl_lastelem = DFS_MAX_PULSE_BUFFER_MASK; + +#ifdef ATH_ENABLE_AR + if(cap_info->enable_ar){ + dfs_reset_ar(dfs); + dfs_reset_arq(dfs); + dfs->dfs_proc_phyerr |= DFS_AR_EN; + } +#endif /* ATH_ENABLE_AR */ + + if(cap_info->enable_radar) { + /* Allocate memory for radar filters */ + for (n=0; ndfs_radarf[n] = (struct dfs_filtertype *)DFS_MALLOC(os, sizeof(struct dfs_filtertype)); + if (dfs->dfs_radarf[n] == NULL) { + DFS_DPRINTK(dfs,ATH_DEBUG_DFS, + "%s: cannot allocate memory for radar filter types\n", + __func__); + goto bad1; + } + } + /* Allocate memory for radar table */ + dfs->dfs_radartable = (int8_t **)DFS_MALLOC(os, 256*sizeof(int8_t *)); + if (dfs->dfs_radartable == NULL) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: cannot allocate memory for radar table\n", + __func__); + goto bad1; + } + for (n=0; n<256; n++) { + dfs->dfs_radartable[n] = DFS_MALLOC(os, DFS_MAX_RADAR_OVERLAP*sizeof(int8_t)); + if (dfs->dfs_radartable[n] == NULL) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "%s: cannot allocate memory for radar table entry\n", + __func__); + goto bad2; + } + } + + /* Init the Bin5 chirping related data */ + dfs->dfs_rinfo.dfs_bin5_chirp_ts = cap_info->ext_chan_busy_ts; + dfs->dfs_rinfo.dfs_last_bin5_dur = MAX_BIN5_DUR; + + dfs->dfs_b5radars = NULL; + } + + return dfs; + +bad2: + OS_FREE(dfs->dfs_radartable); + dfs->dfs_radartable = NULL; +bad1: + for (n=0; ndfs_radarf[n] != NULL) { + OS_FREE(dfs->dfs_radarf[n]); + dfs->dfs_radarf[n] = NULL; + } + } + if (dfs->pulses) { + OS_FREE(dfs->pulses); + dfs->pulses = NULL; + } + if (dfs->events) { + OS_FREE(dfs->events); + dfs->events = NULL; + } + + return dfs; + +} + +void +dfs_detach_host(struct ath_dfs_host *dfs) +{ + int n, empty; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + + OS_CANCEL_TIMER(&dfs->dfs_radar_task_timer); + + /* Return radar events to free q*/ + dfs_reset_radarq(dfs); + dfs_reset_alldelaylines(dfs); + + /* Free up pulse log*/ + if (dfs->pulses != NULL) { + OS_FREE(dfs->pulses); + dfs->pulses = NULL; + } + + for (n=0; ndfs_radarf[n] != NULL) { + OS_FREE(dfs->dfs_radarf[n]); + dfs->dfs_radarf[n] = NULL; + } + } + + + if (dfs->dfs_radartable != NULL) { + for (n=0; n<256; n++) { + if (dfs->dfs_radartable[n] != NULL) { + OS_FREE(dfs->dfs_radartable[n]); + dfs->dfs_radartable[n] = NULL; + } + } + OS_FREE(dfs->dfs_radartable); + dfs->dfs_radartable = NULL; + } + + if (dfs->dfs_b5radars != NULL) { + OS_FREE(dfs->dfs_b5radars); + dfs->dfs_b5radars=NULL; + } + + dfs_reset_ar(dfs); + + ATH_ARQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_arq)); + ATH_ARQ_UNLOCK(dfs); + if (!empty) { + dfs_reset_arq(dfs); + } + if (dfs->events != NULL) { + OS_FREE(dfs->events); + dfs->events = NULL; + } + OS_FREE(dfs); + dfs = NULL; +} + + +void dfs_bangradar_enable(struct ath_dfs_host *dfs, u_int8_t enable) +{ + dfs->dfs_bangradar = enable; +} + +void dfs_set_dur_multiplier(struct ath_dfs_host *dfs, u_int32_t dur_multiplier) +{ + dfs->dur_multiplier = dur_multiplier; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS3, + "%s: duration multiplier is %d\n", __func__, dfs->dur_multiplier); +} + +void dfs_set_debug_level_host(struct ath_dfs_host *dfs, u_int32_t level) +{ + dfs->dfs_debug_level = level; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS3, + "%s: debug level is %d\n", __func__, dfs->dfs_debug_level); + +} + +#endif /* ATH_UPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_ar.c b/drivers/net/wireless/ar6003/host/dfs/dfs_ar.c new file mode 100644 index 000000000000..143606519326 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_ar.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +#define UPDATE_TOP_THREE_PEAKS(_histo, _peakPtrList, _currWidth) { \ + if ((_histo)[(_peakPtrList)[0]] < (_histo)[(_currWidth)]) { \ + (_peakPtrList)[2] = (_currWidth != (_peakPtrList)[1]) ? \ + (_peakPtrList)[1] : (_peakPtrList)[2]; \ + (_peakPtrList)[1] = (_peakPtrList)[0]; \ + (_peakPtrList)[0] = (_currWidth); \ + } else if ((_currWidth != (_peakPtrList)[0]) \ + && ((_histo)[(_peakPtrList)[1]] < (_histo)[(_currWidth)])) { \ + (_peakPtrList)[2] = (_peakPtrList)[1]; \ + (_peakPtrList)[1] = (_currWidth); \ + } else if ((_currWidth != (_peakPtrList)[1]) \ + && (_currWidth != (_peakPtrList)[0]) \ + && ((_histo)[(_peakPtrList)[2]] < (_histo)[(_currWidth)])) { \ + (_peakPtrList)[2] = (_currWidth); \ + } \ +} + + + +u_int32_t dfs_process_ar_event(struct ath_dfs_host *dfs) +{ + struct dfs_ar_state *ar; + struct dfs_event *re=NULL; + u_int32_t sumpeak=0,numpeaks,rssi,width,origregionsum=0, i; + u_int16_t thistimestamp; + int empty; + u_int32_t result = 0; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return result; + } + ar = (struct dfs_ar_state *) &(dfs->dfs_ar_state); + ATH_ARQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_arq)); + ATH_ARQ_UNLOCK(dfs); + while (!empty) { + ATH_ARQ_LOCK(dfs); + re = STAILQ_FIRST(&(dfs->dfs_arq)); + if (re != NULL) + STAILQ_REMOVE_HEAD(&(dfs->dfs_arq), re_list); + ATH_ARQ_UNLOCK(dfs); + if (re == NULL) + return result; + + thistimestamp = re->re_ts; + rssi = re->re_rssi; + width = re->re_dur; + + /* Return the dfs event to the free event list */ + OS_MEMZERO(re, sizeof(struct dfs_event)); + ATH_DFSEVENTQ_LOCK(dfs); + STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), re, re_list); + ATH_DFSEVENTQ_UNLOCK(dfs); + + /* determine if current radar is an extension of previous radar */ + if (ar->ar_prevwidth == 255) { + /* tag on previous width for consideraion of low data rate ACKs */ + ar->ar_prevwidth += width; + width = (width == 255) ? 255 : ar->ar_prevwidth; + } else if ((width == 255) && + (ar->ar_prevwidth == 510 || + ar->ar_prevwidth == 765 || + ar->ar_prevwidth == 1020)) { + /* Aggregate up to 5 consecuate max radar widths + * to consider 11Mbps long preamble 1500-byte pkts + */ + ar->ar_prevwidth += width; + } else if (ar->ar_prevwidth == 1275 && width != 255) { + /* Found 5th consecute maxed out radar, reset history */ + width += ar->ar_prevwidth; + ar->ar_prevwidth = 0; + } else if (ar->ar_prevwidth > 255) { + /* Ignore if there are less than 5 consecutive maxed out radars */ + ar->ar_prevwidth = width; + width = 255; + } else { + ar->ar_prevwidth = width; + } + /* For ignoring noises with radar duration in ranges of 3-30: AP4x */ + if ((width >= 257 && width <= 278) || /* Region 7 - 5.5Mbps (long pre) ACK = 270 = 216 us */ + (width >= 295 && width <= 325) || /* Region 8 - 2Mbps (long pre) ACKC = 320 = 256us */ + (width >= 1280 && width <= 1300)) { + u_int16_t wraparoundadj=0; + u_int16_t base = (width >= 1280) ? 1275 : 255; + if (thistimestamp < ar->ar_prevtimestamp) { + wraparoundadj = 32768; + } + if ((thistimestamp + wraparoundadj - ar->ar_prevtimestamp) != + (width - base)) { + width = 1; + } + } + if (width <= 10) { + ATH_ARQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_arq)); + ATH_ARQ_UNLOCK(dfs); + continue; + } + /* + * Overloading the width=2 in: Store a count of radars w/max duration + * and high RSSI (not noise) + */ + if ((width == 255) && (rssi > DFS_AR_RSSI_THRESH_STRONG_PKTS)) + width = 2; + /* + * Overloading the width=3 bin: + * Double and store a count of rdars of durtaion that matches 11Mbps (long preamble) + * TCP ACKs or 1500-byte data packets + */ + if ((width >= 1280 && width <= 1300) || + (width >= 318 && width <= 325)) { + width = 3; + ar->ar_phyerrcount[3] += 2; + ar->ar_acksum += 2; + } + /* build histogram of radar duration */ + if (width > 0 && width <= 510) + ar->ar_phyerrcount[width]++; + else { + /* invalid radar width, throw it away */ + ATH_ARQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_arq)); + ATH_ARQ_UNLOCK(dfs); + continue; + } + /* Received radar of interest (i.e., signature match), proceed to check if + * there is enough neighboring traffic to drop out of Turbo + */ + if ((width >= 33 && width <= 38) || /* Region 0: 24Mbps ACK = 35 = 28us */ + (width >= 39 && width <= 44) || /* Region 1: 12Mbps ACK = 40 = 32us */ + (width >= 53 && width <= 58) || /* Region 2: 6Mbps ACK = 55 = 44us */ + (width >= 126 && width <= 140) || /* Region 3: 11Mbps ACK = 135 = 108us */ + (width >= 141 && width <= 160) || /* Region 4: 5.5Mbps ACK = 150 = 120us */ + (width >= 189 && width <= 210) || /* Region 5: 2Mbps ACK = 200 = 160us */ + (width >= 360 && width <= 380) || /* Region 6 1Mbps ACK = 400 = 320us */ + (width >= 257 && width <= 270) || /* Region 7 5.5Mbps (Long Pre) ACK = 270 = 216us */ + (width >= 295 && width <= 302) || /* Region 8 2Mbps (Long Pre) ACK = 320 = 256us */ + /* Ignoring Region 9 due to overlap with 255 which is same as board noise */ + /* Region 9 11Mbps (Long Pre) ACK = 255 = 204us */ + (width == 3)) { + ar->ar_acksum++; + /* double the count for strong radars that match one of the ACK signatures */ + if (rssi > DFS_AR_RSSI_DOUBLE_THRESHOLD) { + ar->ar_phyerrcount[width]++; + ar->ar_acksum++; + } + UPDATE_TOP_THREE_PEAKS(ar->ar_phyerrcount, + ar->ar_peaklist, width); + /* sum the counts of these peaks */ + numpeaks = DFS_AR_MAX_NUM_PEAKS; + origregionsum = ar->ar_acksum; + for (i=0; i<= DFS_AR_MAX_NUM_PEAKS; i++) { + if (ar->ar_peaklist[i] > 0) { + if ((i==0) && + (ar->ar_peaklist[i] == 3) && + (ar->ar_phyerrcount[3] < + ar->ar_phyerrcount[2]) && + (ar->ar_phyerrcount[3] > 6)) { + /* + * If the top peak is one that + * maches the 11Mbps long + * preamble TCP Ack/1500-byte + * data, include the count for + * radars that hav emax + * duration and high rssi + * (width = 2) to boost the + * sum for the PAR test that + * follows */ + sumpeak += (ar->ar_phyerrcount[2] + + ar->ar_phyerrcount[3]); + ar->ar_acksum += (ar->ar_phyerrcount[2] + + ar->ar_phyerrcount[3]); + } else { + sumpeak += ar->ar_phyerrcount[ar->ar_peaklist[i]]; + } + } else + numpeaks--; + } + /* + * If sum of patterns matches exceeds packet threshold, + * perform comparison between peak-to-avg ratio against parThreshold + */ + if ((ar->ar_acksum > ar->ar_packetthreshold) && + ((sumpeak * DFS_AR_REGION_WIDTH) > (ar->ar_parthreshold * numpeaks * + ar->ar_acksum))) { + /* neighboring traffic detected, get out of Turbo */ + result = TRAFFIC_DETECTED; + OS_MEMZERO(ar->ar_peaklist, sizeof(ar->ar_peaklist)); + ar->ar_acksum = 0; + OS_MEMZERO(ar->ar_phyerrcount, sizeof(ar->ar_phyerrcount)); + } else { + /* + * reset sum of matches to discount the count of + * strong radars with max duration + */ + ar->ar_acksum = origregionsum; + } + } + ar->ar_prevtimestamp = thistimestamp; + ATH_ARQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_arq)); + ATH_ARQ_UNLOCK(dfs); + } + return result; +} + +void dfs_reset_ar(struct ath_dfs_host *dfs) +{ + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + OS_MEMZERO(&dfs->dfs_ar_state, sizeof(dfs->dfs_ar_state)); + dfs->dfs_ar_state.ar_packetthreshold = DFS_AR_PKT_COUNT_THRESH; + dfs->dfs_ar_state.ar_parthreshold = DFS_AR_ACK_DETECT_PAR_THRESH; + dfs->dfs_ar_state.ar_radarrssi = DFS_AR_RADAR_RSSI_THR; + +} + +void dfs_reset_arq(struct ath_dfs_host *dfs) +{ + struct dfs_event *event; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + ATH_ARQ_LOCK(dfs); + ATH_DFSEVENTQ_LOCK(dfs); + while (!STAILQ_EMPTY(&(dfs->dfs_arq))) { + event = STAILQ_FIRST(&(dfs->dfs_arq)); + STAILQ_REMOVE_HEAD(&(dfs->dfs_arq), re_list); + OS_MEMZERO(event, sizeof(struct dfs_event)); + STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), event, re_list); + } + ATH_DFSEVENTQ_UNLOCK(dfs); + ATH_ARQ_UNLOCK(dfs); +} + + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_bindetects.c b/drivers/net/wireless/ar6003/host/dfs/dfs_bindetects.c new file mode 100644 index 000000000000..d2582f9c3efd --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_bindetects.c @@ -0,0 +1,340 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +int dfs_bin_fixedpattern_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, u_int32_t dur, int ext_chan_flag, u_int32_t ext_chan_busy) +{ + struct dfs_pulseline *pl = dfs->pulses; + int i, n, refpri, primargin, numpulses=0; + u_int64_t start_ts, end_ts, event_ts, prev_event_ts, next_event_ts, window_start, window_end; + u_int32_t index, next_index, deltadur; + + /* For fixed pattern types, rf->rf_patterntype=1*/ + primargin = dfs_get_pri_margin(ext_chan_flag, (rf->rf_patterntype==1),dfs->dfs_rinfo.rn_lastfull_ts, ext_chan_busy); + + refpri = (rf->rf_minpri + rf->rf_maxpri)/2; + index = pl->pl_lastelem; + end_ts = pl->pl_elems[index].p_time; + start_ts = end_ts - (refpri*rf->rf_numpulses); + + DFS_DPRINTK(dfs, ATH_DEBUG_DFS3, "lastelem ts=%llu start_ts=%llu, end_ts=%llu\n", (unsigned long long)pl->pl_elems[index].p_time, (unsigned long long)start_ts, (unsigned long long)end_ts); + /* find the index of first element in our window of interest */ + for(i=0;ipl_numelems;i++) { + index = (index-1) & DFS_MAX_PULSE_BUFFER_MASK; + if(pl->pl_elems[index].p_time >= start_ts ) + continue; + else { + index = (index) & DFS_MAX_PULSE_BUFFER_MASK; + break; + } + } + for (n=0;n<=rf->rf_numpulses; n++) { + window_start = (start_ts + (refpri*n))-(primargin+n); + window_end = window_start + 2*(primargin+n); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "window_start %u window_end %u \n", + (u_int32_t)window_start, (u_int32_t)window_end); + for(i=0;ipl_numelems;i++) { + prev_event_ts = pl->pl_elems[index].p_time; + index = (index+1) & DFS_MAX_PULSE_BUFFER_MASK; + event_ts = pl->pl_elems[index].p_time; + next_index = (index+1) & DFS_MAX_PULSE_BUFFER_MASK; + next_event_ts = pl->pl_elems[next_index].p_time; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "ts %u \n", (u_int32_t)event_ts); + if( (event_ts <= window_end) && (event_ts >= window_start)){ + deltadur = DFS_DIFF(pl->pl_elems[index].p_dur, dur); + if( (pl->pl_elems[index].p_dur == 1) || + ((dur != 1) && (deltadur <= 2))) { + numpulses++; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "numpulses %u \n", numpulses); + break; + } + } + else if( event_ts > window_end) { + index = (index-1) & DFS_MAX_PULSE_BUFFER_MASK; + break; + } + else if( event_ts == prev_event_ts) { + if( ((next_event_ts - event_ts) > refpri) || + ((next_event_ts - event_ts) == 0)) { + deltadur = DFS_DIFF(pl->pl_elems[index].p_dur, dur); + if( (pl->pl_elems[index].p_dur == 1) || + ((pl->pl_elems[index].p_dur != 1) && (deltadur <= 2))) { + numpulses++; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "zero PRI: numpulses %u \n", numpulses); + break; + } + } + } + } + } + if (numpulses >= dfs_get_filter_threshold(rf, ext_chan_flag, dfs->dfs_rinfo.rn_lastfull_ts, ext_chan_busy)) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "%s FOUND filterID=%u numpulses=%d unadj thresh=%d\n", __func__, rf->rf_pulseid, numpulses, rf->rf_threshold); + return 1; + } + else + return 0; +} + +void +dfs_add_pulse(struct ath_dfs_host *dfs, struct dfs_filter *rf, struct dfs_event *re, + u_int32_t deltaT) +{ + u_int32_t index,n, window, pri; + struct dfs_delayline *dl; + + dl = &rf->rf_dl; + /* Circular buffer of size 2^n */ + index = (dl->dl_lastelem + 1) & DFS_MAX_DL_MASK; + //if ((dl->dl_numelems+1) == DFS_MAX_DL_SIZE) + if ((dl->dl_numelems) == DFS_MAX_DL_SIZE) + dl->dl_firstelem = (dl->dl_firstelem + 1) & DFS_MAX_DL_MASK; + else + dl->dl_numelems++; + dl->dl_lastelem = index; + dl->dl_elems[index].de_time = deltaT; + window = deltaT; + dl->dl_elems[index].de_dur = re->re_dur; + dl->dl_elems[index].de_rssi = re->re_rssi; + + for (n=0;ndl_numelems-1; n++) { + index = (index-1) & DFS_MAX_DL_MASK; + pri = dl->dl_elems[index].de_time; + window += pri; + if (window > rf->rf_filterlen) { + dl->dl_firstelem = (index+1) & DFS_MAX_DL_MASK; + dl->dl_numelems = n+1; + } + } + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "dl firstElem = %d lastElem = %d\n",dl->dl_firstelem, + dl->dl_lastelem); +} + + +int dfs_bin_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + u_int32_t deltaT, u_int32_t width, int ext_chan_flag, u_int32_t ext_chan_busy) +{ + u_int32_t refpri, refdur, searchpri, deltapri, averagerefpri; + u_int32_t n, i, primargin, durmargin, highscore, highscoreindex; + int score[DFS_MAX_DL_SIZE], delayindex, dindex, found=0; + struct dfs_delayline *dl; + u_int32_t scoreindex, lowpriindex= 0, lowpri = 0xffff; + int numpulses=0; + + dl = &rf->rf_dl; + if( dl->dl_numelems < (rf->rf_threshold-1)) { + return 0; + } + if( deltaT > rf->rf_filterlen) + return 0; + + primargin = dfs_get_pri_margin(ext_chan_flag, (rf->rf_patterntype==1), + dfs->dfs_rinfo.rn_lastfull_ts, ext_chan_busy); + + + if(rf->rf_maxdur < 10) { + durmargin = 4; + } + else { + durmargin = 6; + } + + if( rf->rf_patterntype == 1 ){ + found = dfs_bin_fixedpattern_check(dfs, rf, width, ext_chan_flag, ext_chan_busy); + if(found) { + dl->dl_numelems = 0; + } + return found; + } + + OS_MEMZERO(score, sizeof(int)*DFS_MAX_DL_SIZE); + /* find out the lowest pri */ + for (n=0;ndl_numelems; n++) { + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refpri = dl->dl_elems[delayindex].de_time; + if( refpri == 0) + continue; + else if(refpri < lowpri) { + lowpri = dl->dl_elems[delayindex].de_time; + lowpriindex = n; + } + } + /* find out the each delay element's pri score */ + for (n=0;ndl_numelems; n++) { + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refpri = dl->dl_elems[delayindex].de_time; + if( refpri == 0) + continue; + for (i=0;idl_numelems; i++) { + dindex = (dl->dl_firstelem + i) & DFS_MAX_DL_MASK; + searchpri = dl->dl_elems[dindex].de_time; + deltapri = DFS_DIFF(searchpri, refpri); + if( deltapri < primargin) + score[n]++; + } + if( score[n] > rf->rf_threshold) { + /* we got the most possible candidate, + * no need to continue further */ + break; + } + } + /* find out the high scorer */ + highscore = 0; + highscoreindex = 0; + for (n=0;ndl_numelems; n++) { + if( score[n] > highscore) { + highscore = score[n]; + highscoreindex = n; + } + else if( score[n] == highscore ) { + /*more than one pri has highscore take the least pri */ + delayindex = (dl->dl_firstelem + highscoreindex) & DFS_MAX_DL_MASK; + dindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + if( dl->dl_elems[dindex].de_time <= + dl->dl_elems[delayindex].de_time ) { + highscoreindex = n; + } + } + } + /* find the average pri of pulses around the pri of highscore or + * the pulses around the lowest pri */ + if( highscore < 3) { + scoreindex = lowpriindex; + } + else { + scoreindex = highscoreindex; + } + /* We got the possible pri, save its parameters as reference */ + delayindex = (dl->dl_firstelem + scoreindex) & DFS_MAX_DL_MASK; + refdur = dl->dl_elems[delayindex].de_dur; + refpri = dl->dl_elems[delayindex].de_time; + averagerefpri = 0; + + numpulses = dfs_bin_pri_check(dfs, rf, dl, score[scoreindex], refpri, refdur, ext_chan_flag, ext_chan_busy); + if (numpulses >= dfs_get_filter_threshold(rf, ext_chan_flag, dfs->dfs_rinfo.rn_lastfull_ts, ext_chan_busy)) { + found = 1; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "ext_flag=%d MATCH filter=%u numpulses=%u thresh=%u refpri=%d primargin=%d\n", ext_chan_flag, rf->rf_pulseid, numpulses,rf->rf_threshold, refpri, primargin); + dfs_print_delayline(dfs, &rf->rf_dl); + dfs_print_filter(dfs, rf); + } + return found; +} + +int dfs_bin_pri_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + struct dfs_delayline *dl, u_int32_t score, + u_int32_t refpri, u_int32_t refdur, int ext_chan_flag, u_int32_t ext_chan_busy) +{ + u_int32_t searchpri, searchdur, searchrssi, deltapri, deltadur, averagerefpri=0; + int primultiples[6]; + int delayindex, dindex; + u_int32_t i, j, primargin, durmargin, highscore=score, highscoreindex=0; + int numpulses=1; //first pulse in the burst is most likely being filtered out based on maxfilterlen + + //Use the adjusted PRI margin to reduce false alarms + /* For non fixed pattern types, rf->rf_patterntype=0*/ + primargin = dfs_get_pri_margin(ext_chan_flag, (rf->rf_patterntype==1), + dfs->dfs_rinfo.rn_lastfull_ts, ext_chan_busy); + + + if(rf->rf_maxdur < 10) { + durmargin = 4; + } + else { + durmargin = 6; + } + if( score > 1) { + for (i=0;idl_numelems; i++) { + dindex = (dl->dl_firstelem + i) & DFS_MAX_DL_MASK; + searchpri = dl->dl_elems[dindex].de_time; + deltapri = DFS_DIFF(searchpri, refpri); + if( deltapri < primargin) + averagerefpri += searchpri; + } + refpri = (averagerefpri/score); //average + } + /* Note: Following primultiple calculation should be done once per filter + * during initialization stage (dfs_attach) and stored in its array + * atleast for fixed frequency types like FCC Bin1 to save some CPU cycles. + * multiplication, devide operators in the following code are left as it is + * for readability hoping the complier will use left/right shifts wherever possible + */ + if( refpri > rf->rf_maxpri) { + primultiples[0] = (refpri - refdur)/2; + primultiples[1] = refpri; + primultiples[2] = refpri + primultiples[0]; + primultiples[3] = (refpri - refdur)*2; + primultiples[4] = primultiples[3] + primultiples[0]; + primultiples[5] = primultiples[3] + refpri; + } + else { + primultiples[0] = refpri; + primultiples[1] = refpri + primultiples[0]; + primultiples[2] = refpri + primultiples[1]; + primultiples[3] = refpri + primultiples[2]; + primultiples[4] = refpri + primultiples[3]; + primultiples[5] = refpri + primultiples[4]; + } + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "pri0 = %d pri1 = %d pri2 = %d pri3 = %d pri4 = %d pri5 = %d\n", + primultiples[0], primultiples[1], primultiples[2], + primultiples[3], primultiples[4], primultiples[5]); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "refpri = %d high score = %d index = %d numpulses = %d\n", + refpri, highscore, highscoreindex, numpulses); + /* Count the other delay elements that have pri and dur with in the + * acceptable range from the reference one */ + for (i=0; idl_numelems; i++) { + delayindex = (dl->dl_firstelem + i) & DFS_MAX_DL_MASK; + searchpri = dl->dl_elems[delayindex].de_time; + if( searchpri == 0) { + /* This events PRI is zero, take it as a + * valid pulse but decrement next event's PRI by refpri + */ + dindex = (delayindex+1)& DFS_MAX_DL_MASK; + dl->dl_elems[dindex].de_time -= refpri; + searchpri = refpri; + } + searchdur = dl->dl_elems[delayindex].de_dur; + searchrssi = dl->dl_elems[delayindex].de_rssi; + deltadur = DFS_DIFF(searchdur, refdur); + for(j=0; j<6; j++) { + deltapri = DFS_DIFF(searchpri, primultiples[j]); + /* May need to revisit this as this increases the primargin by 5*/ + /* if( deltapri < (primargin+j)) { */ + if( deltapri < (primargin)) { + if( deltadur < durmargin) { + if( (refdur < 8) || ((refdur >=8)&& + (searchrssi < 250))) { + + numpulses++; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "rf->minpri=%d rf->maxpri=%d searchpri = %d index = %d numpulses = %d deltapri=%d j=%d\n", + rf->rf_minpri, rf->rf_maxpri, searchpri, i, numpulses, deltapri, j); + } + } + break; + } + } + } + return numpulses; +} +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_debug.c b/drivers/net/wireless/ar6003/host/dfs/dfs_debug.c new file mode 100644 index 000000000000..40eb11a53505 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_debug.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +void +dfs_print_delayline(struct ath_dfs_host *dfs, struct dfs_delayline *dl) +{ + int i=0,index; + struct dfs_delayelem *de; + + index = dl->dl_lastelem; + for (i=0; idl_numelems; i++) { + de = &dl->dl_elems[index]; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "Elem %d: ts = %u (0x%x) dur=%u\n",i, + de->de_time, de->de_time, de->de_dur); + index = (index - 1)& DFS_MAX_DL_MASK; + } +} + + +void +dfs_print_filter(struct ath_dfs_host *dfs, struct dfs_filter *rf) +{ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "filterID[%d] rf_numpulses=%u; rf->rf_minpri=%u; rf->rf_maxpri=%u; rf->rf_threshold=%u; rf->rf_filterlen=%u; rf->rf_mindur=%u; rf->rf_maxdur=%u\n", rf->rf_pulseid, rf->rf_numpulses, rf->rf_minpri, rf->rf_maxpri, rf->rf_threshold, rf->rf_filterlen, rf->rf_mindur, rf->rf_maxdur); +} + + +void +dfs_print_filters(struct ath_dfs_host *dfs) +{ + struct dfs_filtertype *ft = NULL; + struct dfs_filter *rf; + int i,j; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + for (i=0; idfs_radarf[i] != NULL) { + ft = dfs->dfs_radarf[i]; + if((ft->ft_numfilters > DFS_MAX_NUM_RADAR_FILTERS) || (!ft->ft_numfilters)) + continue; + printk("===========ft->ft_numfilters=%u===========\n", ft->ft_numfilters); + for (j=0; jft_numfilters; j++) { + rf = &(ft->ft_filters[j]); + printk("filter[%d] filterID = %d rf_numpulses=%u; rf->rf_minpri=%u; rf->rf_maxpri=%u; rf->rf_threshold=%u; rf->rf_filterlen=%u; rf->rf_mindur=%u; rf->rf_maxdur=%u\n",j, rf->rf_pulseid, + rf->rf_numpulses, rf->rf_minpri, rf->rf_maxpri, rf->rf_threshold, rf->rf_filterlen, rf->rf_mindur, rf->rf_maxdur); + } + } + } +} + + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_fcc_bin5.c b/drivers/net/wireless/ar6003/host/dfs/dfs_fcc_bin5.c new file mode 100644 index 000000000000..07d42367a6fc --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_fcc_bin5.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + + +int dfs_bin5_addpulse(struct ath_dfs_host *dfs, struct dfs_bin5radars *br, + struct dfs_event *re, u_int64_t thists) +{ + u_int32_t index,stop; + u_int64_t tsDelta; + + /* Check if this pulse is a valid pulse in terms of repetition, + * if not, return without adding it to the queue. + * PRI : Pulse Repitetion Interval + * BRI : Burst Repitetion Interval */ + if( br->br_numelems != 0){ + index = br->br_lastelem; + tsDelta = thists - br->br_elems[index].be_ts; + if( (tsDelta < DFS_BIN5_PRI_LOWER_LIMIT) || + ( (tsDelta > DFS_BIN5_PRI_HIGHER_LIMIT) && + (tsDelta < DFS_BIN5_BRI_LOWER_LIMIT))) { + return 0; + } + } + /* Circular buffer of size 2^n */ + index = (br->br_lastelem +1) & DFS_MAX_B5_MASK; + br->br_lastelem = index; + if (br->br_numelems == DFS_MAX_B5_SIZE) + br->br_firstelem = (br->br_firstelem+1)&DFS_MAX_B5_MASK; + else + br->br_numelems++; + br->br_elems[index].be_ts = thists; + br->br_elems[index].be_rssi = re->re_rssi; + br->br_elems[index].be_dur = re->re_dur; + stop = 0; + index = br->br_firstelem; + while ((!stop) && (br->br_numelems-1) > 0) { + if ((thists - br->br_elems[index].be_ts) > + ((u_int64_t) br->br_pulse.b5_timewindow)) { + br->br_numelems--; + br->br_firstelem = (br->br_firstelem +1) & DFS_MAX_B5_MASK; + index = br->br_firstelem; + } else + stop = 1; + } + return 1; +} + +/* + * If the dfs structure is NULL (which should be illegal if everyting is working + * properly, then signify that a bin5 radar was found + */ + +int dfs_bin5_check(struct ath_dfs_host *dfs) +{ + struct dfs_bin5radars *br; + int index[DFS_MAX_B5_SIZE]; + u_int32_t n, i, this, prev, rssi_diff, width_diff, bursts= 0; + u_int32_t total_diff=0, average_diff, total_width=0, average_width, numevents=0; + u_int64_t pri; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return 1; + } + for (n=0;ndfs_rinfo.rn_numbin5radars; n++) { + br = &(dfs->dfs_b5radars[n]); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, + "Num elems = %d\n", br->br_numelems); + prev = br->br_firstelem; + for(i=0;ibr_numelems;i++){ + this = ((br->br_firstelem +i) & DFS_MAX_B5_MASK); + /* Rule 1: 1000 <= PRI <= 2000 + some margin */ + if( br->br_elems[this].be_ts >= br->br_elems[prev].be_ts ) { + pri = br->br_elems[this].be_ts - br->br_elems[prev].be_ts; + } + else {//roll over case + //pri = (0xffffffffffffffff - br->br_elems[prev].be_ts) + br->br_elems[this].be_ts; + pri = br->br_elems[this].be_ts; + } + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2," pri=%llu this.ts=%llu prev.ts=%llu\n", pri, br->br_elems[this].be_ts, br->br_elems[prev].be_ts); + if(( (pri >= DFS_BIN5_PRI_LOWER_LIMIT) && (pri <= DFS_BIN5_PRI_HIGHER_LIMIT))) { //pri: pulse repitition interval in us + /* Rule 2: pulse width of the pulses in the burst should be same (+/- margin) */ + if( br->br_elems[this].be_dur >= br->br_elems[prev].be_dur) { + width_diff = br->br_elems[this].be_dur - br->br_elems[prev].be_dur; + } + else { + width_diff = br->br_elems[prev].be_dur - br->br_elems[this].be_dur; + } + if( width_diff <= DFS_BIN5_WIDTH_MARGIN ) { + /* Rule 3: RSSI of the pulses in the burst should be same (+/- margin) */ + if( br->br_elems[this].be_rssi >= br->br_elems[prev].be_rssi) { + rssi_diff = br->br_elems[this].be_rssi - br->br_elems[prev].be_rssi; + } + else { + rssi_diff = br->br_elems[prev].be_rssi - br->br_elems[this].be_rssi; + } + if( rssi_diff <= DFS_BIN5_RSSI_MARGIN ) { + bursts++; + /* Save the indexes of this pair for later width variance check */ + if( numevents >= 2 ) { + /* make sure the event is not duplicated, + * possible in a 3 pulse burst */ + if( index[numevents-1] != prev) { + index[numevents++] = prev; + } + } + else { + index[numevents++] = prev; } + index[numevents++] = this; + } else { + DFS_DPRINTK(dfs,ATH_DEBUG_DFS2,"%s %d Bin5 rssi_diff=%d\n", __func__, __LINE__, rssi_diff); + } + } else { + DFS_DPRINTK(dfs,ATH_DEBUG_DFS2,"%s %d Bin5 width_diff=%d\n", __func__, __LINE__, width_diff); + } + } else { + DFS_DPRINTK(dfs,ATH_DEBUG_DFS2,"%s %d Bin5 PRI check fail pri=%llu\n", __func__, __LINE__,pri); + } + prev = this; + } + + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "bursts=%u numevents=%u\n", bursts, numevents); + if ( bursts >= br->br_pulse.b5_threshold) { + if( (br->br_elems[br->br_lastelem].be_ts - br->br_elems[br->br_firstelem].be_ts) < 3000000 ) { + return 0; + } + else { + for (i=0; ibr_elems[index[i]].be_dur; + } + average_width = total_width/numevents; + for (i=0; ibr_elems[index[i]].be_dur, average_width); + } + average_diff = total_diff/numevents; + if( average_diff > DFS_BIN5_WIDTH_MARGIN ) { + return 1; + } else { + + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "bursts=%u numevents=%u total_width=%d average_width=%d total_diff=%d average_diff=%d\n", bursts, numevents, total_width, average_width, total_diff, average_diff); + + } + + } + } + } + + return 0; +} + + +u_int8_t dfs_retain_bin5_burst_pattern(struct ath_dfs_host *dfs, u_int32_t diff_ts, u_int8_t old_dur) +{ + + // Pulses may get split into 2 during chirping, this print is only to show that it happened, we do not handle this condition if we cannot detect the chirping + // SPLIT pulses will have a time stamp difference of < 50 + if (diff_ts < 50) { + DFS_DPRINTK(dfs,ATH_DEBUG_DFS1,"%s SPLIT pulse diffTs=%u dur=%d (old_dur=%d)\n", __func__, diff_ts, dfs->dfs_rinfo.dfs_last_bin5_dur, old_dur); + } + // Check if this is the 2nd or 3rd pulse in the same burst, PRI will be between 1000 and 2000 us + if(((diff_ts >= DFS_BIN5_PRI_LOWER_LIMIT) && (diff_ts <= DFS_BIN5_PRI_HIGHER_LIMIT))) { + + //This pulse belongs to the same burst as the pulse before, so return the same random duration for it + DFS_DPRINTK(dfs,ATH_DEBUG_DFS1,"%s this pulse belongs to the same burst as before, give it same dur=%d (old_dur=%d)\n", __func__, dfs->dfs_rinfo.dfs_last_bin5_dur, old_dur); + + return (dfs->dfs_rinfo.dfs_last_bin5_dur); + } + // This pulse does not belong to this burst, return unchanged duration + return old_dur; +} + + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_host_project.c b/drivers/net/wireless/ar6003/host/dfs/dfs_host_project.c new file mode 100644 index 000000000000..40dd5d31d337 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_host_project.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" +#include "dfs_target_api.h" + +void dfs_radar_task (unsigned long arg) +{ + struct ath_dfs_host *dfs = (struct ath_dfs_host *)arg; + A_INT16 chan_index; + A_UINT8 bangradar; + + //printk("\n%s\n",__func__); + + if(dfs_process_radarevent_host(dfs, &chan_index, &bangradar)){ + if(!bangradar){ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: Radar detected on channel idx %d\n", + __func__, chan_index); + } + + /* TODO: The radar detected event is sent from host in timer + * context which could potentially cause issues with sleepable + * WMI. Change this to process context later. */ + DFS_RADAR_DETECTED(dfs->dev_hdl, chan_index, bangradar); + } + +} + +#endif /* ATH_SUPPORT_DFS */ + + diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_init.c b/drivers/net/wireless/ar6003/host/dfs/dfs_init.c new file mode 100644 index 000000000000..bddae9fbfbd8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_init.c @@ -0,0 +1,375 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" +#include "dfs_target_api.h" + + +struct dfs_pulse ar6000_etsi_radars[] = { + /* TYPE 1 */ + {15, 2, 750, 750, 0, 24, 7, 0, 2, 21, 0, -10, 0}, + /* TYPE 2 */ + {10, 5, 200, 200, 0, 24, 5, 1, 9, 21, 0, 3, 1}, + {10, 5, 300, 300, 0, 24, 8, 1, 9, 21, 0, 3, 2}, + {10, 5, 500, 500, 0, 24, 8, 1, 9, 21, 1, 3, 3}, + {10, 5, 800, 800, 0, 24, 8, 1, 9, 21, 1, 3, 4}, + {10, 5, 1001, 1001, 0, 30, 8, 1, 9, 21, 0, 3, 5}, + /* TYPE 3 */ + {15, 16, 200, 200, 0, 24, 6, 10, 19, 22, 0, 3, 6}, + {15, 16, 300, 300, 0, 24, 6, 10, 19, 22, 0, 3, 7}, + {15, 16, 503, 503, 0, 24, 7, 10, 19, 22, 0, 3, 8}, + {15, 16, 809, 809, 0, 24, 7, 10, 19, 22, 0, 3, 9}, + {15, 16, 1014, 1014, 0, 30, 7, 10, 19, 22, 0, 3, 10}, + /* TYPE 4 */ + {15, 5, 1200, 1200, 0, 24, 7, 1, 9, 21, 0, 3, 11}, + {15, 5, 1500, 1500, 0, 30, 7, 1, 9, 21, 0, 3, 12}, + {15, 5, 1600, 1600, 0, 24, 7, 1, 9, 21, 0, 3, 13}, + {15, 16, 1200, 1200, 0, 30, 7, 10, 19, 22, 0, 3, 14}, + {15, 16, 1500, 1500, 0, 24, 7, 10, 19, 22, 0, 3, 15}, + {15, 16, 1600, 1600, 0, 24, 7, 10, 19, 22, 0, 3, 16}, + /* TYPE 5 */ + {25, 5, 2305, 2305, 0, 24, 12, 1, 9, 21, 0, 3, 17}, + {25, 5, 3009, 3009, 0, 24, 12, 1, 9, 21, 0, 3, 18}, + {25, 5, 3500, 3500, 0, 24, 12, 1, 9, 21, 0, 3, 19}, + {25, 5, 4000, 4000, 0, 24, 12, 1, 9, 21, 0, 3, 20}, + {25, 16, 2300, 2300, 0, 24, 12, 10, 20, 22, 0, 3, 21}, + {25, 16, 3000, 3000, 0, 24, 12, 10, 20, 22, 0, 3, 22}, + {25, 16, 3500, 3500, 0, 24, 12, 10, 20, 22, 0, 3, 23}, + {25, 16, 3850, 3850, 0, 24, 12, 10, 20, 22, 0, 3, 24}, + /* TYPE 6 */ + {20, 25, 2000, 2000, 0, 24, 10, 20, 26, 22, 0, 3, 25}, + {20, 25, 3000, 3000, 0, 24, 10, 20, 26, 22, 0, 3, 26}, + {20, 25, 4000, 4000, 0, 24, 10, 20, 26, 22, 0, 3, 27}, + {20, 37, 2000, 2000, 0, 24, 10, 30, 36, 22, 0, 3, 28}, + {20, 37, 3000, 3000, 0, 24, 10, 30, 36, 22, 0, 3, 29}, + {20, 37, 4000, 4000, 0, 24, 10, 30, 36, 22, 0, 3, 30}, + + /* TYPE staggered pulse */ + {20, 2, 300, 400, 2, 30, 10, 0, 2, 22, 0, 3, 31}, //0.8-2us, 2-3 bursts,300-400 PRF, 10 pulses each + {30, 2, 400, 1200, 2, 30, 15, 0, 2, 22, 0, 3, 32}, //0.8-2us, 2-3 bursts, 400-1200 PRF, 15 pulses each + + /* constant PRF based */ + {10, 5, 200, 1000, 0, 24, 6, 0, 8, 21, 0, -10, 33}, /*0.8-5us , 200-1000 PRF, 10 pulses */ + {15, 15, 200, 1600, 0, 24, 7, 0, 18, 21, 0, -10, 34}, /*0.8-15us , 200-1600 PRF, 15 pulses */ + {25, 15, 2300, 4000, 0, 24, 12, 0, 18, 21, 0, -10, 35}, /* 0.8-15 us, 2300-4000 PRF, 25 pulses*/ + {20, 30, 2000, 4000, 0, 24, 10, 19, 33, 21, 0, -10, 36}, /* 20-30us, 2000-4000 PRF, 20 pulses*/ + +}; + +/* The following are for FCC Bin 1-4 pulses */ +struct dfs_pulse ar6000_fcc_radars[] = { + /* following two filters are specific to Japan/MKK4 */ + {18, 1, 720, 720, 1, 6, 6, 0, 1, 18, 0, 3, 17}, // 1389 +/- 6 us + {18, 4, 250, 250, 1, 10, 5, 1, 6, 18, 0, 3, 18}, // 4000 +/- 6 us + {18, 5, 260, 260, 1, 10, 6, 1, 6, 18, 0, 3, 19}, // 3846 +/- 7 us + /* following filters are common to both FCC and JAPAN */ + {18, 1, 325, 1930, 0, 6, 7, 0, 1, 18, 0, 3, 0}, // 1428 +/- 7 us + {9, 1, 3003, 3003, 1, 7, 5, 0, 1, 18, 0, 0, 1}, // 333 +/- 7 us + + {23, 5, 6250, 6250, 0, 15, 11, 0, 7, 22, 0, 3, 2}, // 160 +/- 15 us + {23, 5, 5263, 5263, 0, 18, 11, 0, 7, 22, 0, 3, 3}, // 190 +/- 15 us + {23, 5, 4545, 4545, 0, 18, 11, 0, 7, 22, 0, 3, 4}, // 220 +/- 15 us + + {18, 10, 4444, 4444, 0, 35, 6, 7, 13, 22, 0, 3, 5}, // 225 +/- 30 us + {18, 10, 3636, 3636, 0, 25, 6, 7, 13, 22, 0, 3, 6}, // 275 +/- 25 us + {18, 10, 3076, 3076, 0, 25, 8, 7, 13, 22, 0, 3, 7}, // 325 +/- 25 us + {18, 10, 2666, 2666, 0, 25, 8, 7, 13, 22, 0, 3, 8}, // 375 +/- 25 us + {18, 10, 2352, 2352, 0, 25, 8, 7, 13, 22, 0, 3, 9}, // 425 +/- 25 us + {18, 10, 2105, 2105, 0, 30, 8, 7, 13, 22, 0, 3, 10}, // 475 +/- 30 us + + {14, 15, 4444, 4444, 0, 35, 5, 13, 21, 22, 0, 3, 11}, // 225 +/- 30 us + {14, 15, 3636, 3636, 0, 25, 5, 13, 24, 22, 0, 3, 12}, // 275 +/- 25 us + {14, 15, 3076, 3076, 0, 25, 7, 13, 23, 22, 0, 3, 13}, // 325 +/- 25 us + {14, 15, 2666, 2666, 0, 25, 7, 13, 23, 22, 0, 3, 14}, // 375 +/- 25 us + {14, 15, 2352, 2352, 0, 25, 7, 13, 21, 22, 0, 3, 15}, // 425 +/- 25 us + {12, 15, 2105, 2105, 0, 30, 7, 13, 21, 22, 0, 3, 16}, // 475 +/- 30 us +}; + +struct dfs_bin5pulse ar6000_bin5pulses[] = { + {4, 28, 105, 12, 22, 5}, +}; + +/* + * Clear all delay lines for all filter types + */ +void dfs_reset_alldelaylines(struct ath_dfs_host *dfs) +{ + struct dfs_filtertype *ft = NULL; + struct dfs_filter *rf; + struct dfs_delayline *dl; + struct dfs_pulseline *pl; + int i,j; + + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + + pl = dfs->pulses; + /* reset the pulse log */ + pl->pl_firstelem = pl->pl_numelems = 0; + pl->pl_lastelem = DFS_MAX_PULSE_BUFFER_MASK; + + for (i=0; idfs_radarf[i] != NULL) { + ft = dfs->dfs_radarf[i]; + for (j=0; jft_numfilters; j++) { + rf = &(ft->ft_filters[j]); + dl = &(rf->rf_dl); + if(dl != NULL) { + OS_MEMZERO(dl, sizeof(struct dfs_delayline)); + dl->dl_lastelem = (0xFFFFFFFF) & DFS_MAX_DL_MASK; + } + } + } + } + for (i=0; idfs_rinfo.rn_numbin5radars; i++) { + OS_MEMZERO(&(dfs->dfs_b5radars[i].br_elems[0]), sizeof(struct dfs_bin5elem)*DFS_MAX_B5_SIZE); + dfs->dfs_b5radars[i].br_firstelem = 0; + dfs->dfs_b5radars[i].br_numelems = 0; + dfs->dfs_b5radars[i].br_lastelem = (0xFFFFFFFF)&DFS_MAX_B5_MASK; + } +} +/* + * Clear only a single delay line + */ + +void dfs_reset_delayline(struct dfs_delayline *dl) +{ + OS_MEMZERO(&(dl->dl_elems[0]), sizeof(dl->dl_elems)); + dl->dl_lastelem = (0xFFFFFFFF)&DFS_MAX_DL_MASK; +} + +void dfs_reset_filter_delaylines(struct dfs_filtertype *dft) +{ + int i; + struct dfs_filter *df; + for (i=0; i< DFS_MAX_NUM_RADAR_FILTERS; i++) { + df = &dft->ft_filters[i]; + dfs_reset_delayline(&(df->rf_dl)); + } +} + +void +dfs_reset_radarq(struct ath_dfs_host *dfs) +{ + struct dfs_event *event; + if (dfs == NULL) { + A_PRINTF("%s: sc_dfs is NULL\n", __func__); + return; + } + ATH_DFSQ_LOCK(dfs); + ATH_DFSEVENTQ_LOCK(dfs); + while (!STAILQ_EMPTY(&(dfs->dfs_radarq))) { + event = STAILQ_FIRST(&(dfs->dfs_radarq)); + STAILQ_REMOVE_HEAD(&(dfs->dfs_radarq), re_list); + OS_MEMZERO(event, sizeof(struct dfs_event)); + STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), event, re_list); + } + ATH_DFSEVENTQ_UNLOCK(dfs); + ATH_DFSQ_UNLOCK(dfs); +} + +struct dfs_pulse *dfs_get_radars(u_int32_t dfsdomain, u_int32_t *numradars, struct dfs_bin5pulse **bin5pulses, u_int32_t *numb5radars) +{ +#define N(a) (sizeof(a)/sizeof(a[0])) + struct dfs_pulse *dfs_radars = NULL; + switch (dfsdomain) { + case DFS_FCC_DOMAIN: + dfs_radars = &ar6000_fcc_radars[3]; + *numradars= N(ar6000_fcc_radars)-3; + *bin5pulses = &ar6000_bin5pulses[0]; + *numb5radars = N(ar6000_bin5pulses); + break; + case DFS_ETSI_DOMAIN: + dfs_radars = &ar6000_etsi_radars[0]; + *numradars = N(ar6000_etsi_radars); + *bin5pulses = &ar6000_bin5pulses[0]; + *numb5radars = N(ar6000_bin5pulses); + break; + case DFS_MKK4_DOMAIN: + dfs_radars = &ar6000_fcc_radars[0]; + *numradars = N(ar6000_fcc_radars); + *bin5pulses = &ar6000_bin5pulses[0]; + *numb5radars = N(ar6000_bin5pulses); + break; + default: + return NULL; + } + + return dfs_radars; + +#undef N + +} + +int dfs_init_radar_filters_host( struct ath_dfs_host *dfs, struct ath_dfs_info *dfs_info) +{ + u_int32_t T, Tmax; + int numpulses,p,n, i; + struct dfs_filtertype *ft = NULL; + struct dfs_filter *rf=NULL; + struct dfs_pulse *dfs_radars; + struct dfs_bin5pulse *b5pulses; + int32_t min_rssithresh=DFS_MAX_RSSI_VALUE; + u_int32_t max_pulsedur=0; + u_int32_t numb5radars; + u_int32_t numradars; + + dfs_radars = dfs_get_radars(dfs_info->dfs_domain, &numradars, &b5pulses, &numb5radars); + /* If DFS not enabled return immediately.*/ + if (!dfs_radars) { + return 0; + } + + dfs->dfs_rinfo.rn_numradars = 0; + + /* Clear filter type table */ + for (n=0; n<256; n++) { + for (i=0;idfs_radartable[n])[i] = -1; + } + + /* Now, initialize the radar filters */ + for (p=0; p < numradars; p++) { + ft = NULL; + for (n=0; ndfs_rinfo.rn_numradars; n++) { + if ((dfs_radars[p].rp_pulsedur == dfs->dfs_radarf[n]->ft_filterdur) && + (dfs_radars[p].rp_numpulses == dfs->dfs_radarf[n]->ft_numpulses) && + (dfs_radars[p].rp_mindur == dfs->dfs_radarf[n]->ft_mindur) && + (dfs_radars[p].rp_maxdur == dfs->dfs_radarf[n]->ft_maxdur)) { + ft = dfs->dfs_radarf[n]; + break; + } + } + if (ft == NULL) { + /* No filter of the appropriate dur was found */ + if ((dfs->dfs_rinfo.rn_numradars+1) >DFS_MAX_RADAR_TYPES) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: Too many filter types\n", + __func__); + goto bad4; + } + + ft = dfs->dfs_radarf[dfs->dfs_rinfo.rn_numradars]; + ft->ft_numfilters = 0; + ft->ft_numpulses = dfs_radars[p].rp_numpulses; + ft->ft_patterntype = dfs_radars[p].rp_patterntype; + ft->ft_mindur = dfs_radars[p].rp_mindur; + ft->ft_maxdur = dfs_radars[p].rp_maxdur; + ft->ft_filterdur = dfs_radars[p].rp_pulsedur; + ft->ft_rssithresh = dfs_radars[p].rp_rssithresh; + ft->ft_rssimargin = dfs_radars[p].rp_rssimargin; + ft->ft_minpri = 1000000; + + if (ft->ft_rssithresh < min_rssithresh) + min_rssithresh = ft->ft_rssithresh; + if (ft->ft_maxdur > max_pulsedur) + max_pulsedur = ft->ft_maxdur; + for (i=ft->ft_mindur; i<=ft->ft_maxdur; i++) { + u_int32_t stop=0,tableindex=0; + while ((tableindex < DFS_MAX_RADAR_OVERLAP) && (!stop)) { + if ((dfs->dfs_radartable[i])[tableindex] == -1) + stop = 1; + else + tableindex++; + } + if (stop) { + (dfs->dfs_radartable[i])[tableindex] = + (int8_t) (dfs->dfs_rinfo.rn_numradars); + } else { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "%s: Too many overlapping radar filters\n", + __func__); + goto bad4; + } + } + dfs->dfs_rinfo.rn_numradars++; + } + rf = &(ft->ft_filters[ft->ft_numfilters++]); + dfs_reset_delayline(&rf->rf_dl); + numpulses = dfs_radars[p].rp_numpulses; + + rf->rf_numpulses = numpulses; + rf->rf_patterntype = dfs_radars[p].rp_patterntype; + rf->rf_pulseid = dfs_radars[p].rp_pulseid; + rf->rf_mindur = dfs_radars[p].rp_mindur; + rf->rf_maxdur = dfs_radars[p].rp_maxdur; + rf->rf_numpulses = dfs_radars[p].rp_numpulses; + + T = (100000000/dfs_radars[p].rp_max_pulsefreq) - + 100*(dfs_radars[p].rp_meanoffset); + rf->rf_minpri = + dfs_round((int32_t)T - (100*(dfs_radars[p].rp_pulsevar))); + Tmax = (100000000/dfs_radars[p].rp_pulsefreq) - + 100*(dfs_radars[p].rp_meanoffset); + rf->rf_maxpri = + dfs_round((int32_t)Tmax + (100*(dfs_radars[p].rp_pulsevar))); + + if( rf->rf_minpri < ft->ft_minpri ) + ft->ft_minpri = rf->rf_minpri; + + rf->rf_threshold = dfs_radars[p].rp_threshold; + rf->rf_filterlen = rf->rf_maxpri * rf->rf_numpulses; + + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "minprf = %d maxprf = %d pulsevar = %d thresh=%d\n", + dfs_radars[p].rp_pulsefreq, dfs_radars[p].rp_max_pulsefreq, dfs_radars[p].rp_pulsevar, rf->rf_threshold); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "minpri = %d maxpri = %d filterlen = %d filterID = %d\n", + rf->rf_minpri, rf->rf_maxpri, rf->rf_filterlen, rf->rf_pulseid); + } + +#ifdef DFS_DEBUG + dfs_print_filters(dfs); +#endif + + dfs->dfs_rinfo.rn_numbin5radars = numb5radars; + if ( dfs->dfs_b5radars == NULL ) { + dfs->dfs_b5radars = (struct dfs_bin5radars *)DFS_MALLOC(dfs->os_hdl, numb5radars * sizeof(struct dfs_bin5radars)); + if (dfs->dfs_b5radars == NULL) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "%s: cannot allocate memory for bin5 radars\n", + __func__); + goto bad4; + } + } + for (n=0; ndfs_b5radars[n].br_pulse = b5pulses[n]; + dfs->dfs_b5radars[n].br_pulse.b5_timewindow *= 1000000; + if (dfs->dfs_b5radars[n].br_pulse.b5_rssithresh < min_rssithresh) + min_rssithresh = dfs->dfs_b5radars[n].br_pulse.b5_rssithresh; + if (dfs->dfs_b5radars[n].br_pulse.b5_maxdur > max_pulsedur ) + max_pulsedur = dfs->dfs_b5radars[n].br_pulse.b5_maxdur; + } + dfs_reset_alldelaylines(dfs); + dfs_reset_radarq(dfs); + + DFS_SET_MINRSSITHRESH(dfs->dev_hdl, min_rssithresh); + DFS_SET_MAXPULSEDUR(dfs->dev_hdl, dfs_round((int32_t)((max_pulsedur*100/80)*100))); + + + return 0; + +bad4: + for (n=0; nft_numfilters; n++) { + rf = &(ft->ft_filters[n]); + } + return 1; +} + + + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_misc.c b/drivers/net/wireless/ar6003/host/dfs/dfs_misc.c new file mode 100644 index 000000000000..f0036c55dd7f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_misc.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +int adjust_pri_per_chan_busy(int ext_chan_busy, int pri_margin) +{ + int adjust_pri=0; + + if(ext_chan_busy > DFS_EXT_CHAN_LOADING_THRESH) { + + adjust_pri = (ext_chan_busy - DFS_EXT_CHAN_LOADING_THRESH) * (pri_margin); + adjust_pri /= 100; + + } + return adjust_pri; +} + +int adjust_thresh_per_chan_busy(int ext_chan_busy, int thresh) +{ + int adjust_thresh=0; + + if(ext_chan_busy > DFS_EXT_CHAN_LOADING_THRESH) { + + adjust_thresh = (ext_chan_busy - DFS_EXT_CHAN_LOADING_THRESH) * thresh; + adjust_thresh /= 100; + + } + return adjust_thresh; +} +/* For the extension channel, if legacy traffic is present, we see a lot of false alarms, +so make the PRI margin narrower depending on the busy % for the extension channel.*/ + +int dfs_get_pri_margin(int is_extchan_detect, int is_fixed_pattern, u_int64_t lastfull_ts, u_int32_t ext_chan_busy) +{ + + int adjust_pri=0; + int pri_margin; + // struct ath_dfs_target *dfs = sc->sc_dfs_tgt; + + if (is_fixed_pattern) + pri_margin = DFS_DEFAULT_FIXEDPATTERN_PRI_MARGIN; + else + pri_margin = DFS_DEFAULT_PRI_MARGIN; + + + /*XXX: Does cached value make sense here? */ +#if 0 + if(ext_chan_busy) { + dfs->dfs_rinfo.ext_chan_busy_ts = ath_hal_gettsf64(sc->sc_ah); + dfs->dfs_rinfo.dfs_ext_chan_busy = ext_chan_busy; + } else { + // Check to see if the cached value of ext_chan_busy can be used + if (dfs->dfs_rinfo.dfs_ext_chan_busy) { + if (lastfull_ts < dfs->dfs_rinfo.ext_chan_busy_ts) { + ext_chan_busy = dfs->dfs_rinfo.dfs_ext_chan_busy; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2," PRI Use cached copy of ext_chan_busy extchanbusy=%d \n", ext_chan_busy); + } + } + } +#endif + adjust_pri = adjust_pri_per_chan_busy(ext_chan_busy, pri_margin); + + pri_margin -= adjust_pri; + return pri_margin; +} + +/* For the extension channel, if legacy traffic is present, we see a lot of false alarms, +so make the thresholds higher depending on the busy % for the extension channel.*/ + +int dfs_get_filter_threshold(struct dfs_filter *rf, int is_extchan_detect, u_int64_t lastfull_ts, u_int32_t ext_chan_busy) +{ + int thresh, adjust_thresh=0; + // struct ath_dfs_target *dfs = sc->sc_dfs_tgt; + + thresh = rf->rf_threshold; + + /*XXX: Does cached value make sense here? */ +#if 0 + if(ext_chan_busy) { + dfs->dfs_rinfo.ext_chan_busy_ts = ath_hal_gettsf64(sc->sc_ah); + dfs->dfs_rinfo.dfs_ext_chan_busy = ext_chan_busy; + } else { + // Check to see if the cached value of ext_chan_busy can be used + if (dfs->dfs_rinfo.dfs_ext_chan_busy) { + if (lastfull_ts < dfs->dfs_rinfo.ext_chan_busy_ts) { + ext_chan_busy = dfs->dfs_rinfo.dfs_ext_chan_busy; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2," THRESH Use cached copy of ext_chan_busy extchanbusy=%d lastfull_ts=%llu ext_chan_busy_ts=%llu\n", ext_chan_busy ,lastfull_ts, dfs->dfs_rinfo.ext_chan_busy_ts); + } + } + } +#endif + adjust_thresh = adjust_thresh_per_chan_busy(ext_chan_busy, thresh); + + //DFS_DPRINTK(dfs, ATH_DEBUG_DFS2," filterID=%d extchanbusy=%d adjust_thresh=%d\n", rf->rf_pulseid, ext_chan_busy, adjust_thresh); + + thresh += adjust_thresh; + return thresh; +} + + + + + + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_process_phyerr.c b/drivers/net/wireless/ar6003/host/dfs/dfs_process_phyerr.c new file mode 100644 index 000000000000..1968731391be --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_process_phyerr.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" +void +dfs_queue_phyerr(struct ath_dfs_host *dfs, struct dfs_event_info *ev_info); + + +void +dfs_process_phyerr_host(struct ath_dfs_host *dfs, WMI_DFS_PHYERR_EVENT *ev) +{ + int i; + for(i=0; inum_events; i++) + dfs_queue_phyerr(dfs, &ev->ev_info[i]); +} + +void +dfs_queue_phyerr(struct ath_dfs_host *dfs, struct dfs_event_info *ev_info) +{ + struct dfs_event *event; + int empty; + + ATH_DFSEVENTQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_eventq)); + ATH_DFSEVENTQ_UNLOCK(dfs); + if (empty) { + return; + } + + /* XXX: Lot of common code. Optimize */ + + if((ev_info->flags & EVENT_TYPE_MASK) == AR_EVENT){ + ATH_DFSEVENTQ_LOCK(dfs); + event = STAILQ_FIRST(&(dfs->dfs_eventq)); + if (event == NULL) { + ATH_DFSEVENTQ_UNLOCK(dfs); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: no more events space left\n", + __func__); + return; + } + STAILQ_REMOVE_HEAD(&(dfs->dfs_eventq), re_list); + ATH_DFSEVENTQ_UNLOCK(dfs); + event->re_rssi = ev_info->rssi; + event->re_dur = ev_info->dur; + event->re_full_ts = ev_info->full_ts; + event->re_ts = ev_info->ts; + event->re_chanindex = ev_info->chanindex; + event->re_chanindextype = ev_info->flags & CH_TYPE_MASK; + ATH_ARQ_LOCK(dfs); + STAILQ_INSERT_TAIL(&(dfs->dfs_arq), event, re_list); + ATH_ARQ_UNLOCK(dfs); + } + else { /* DFS event */ + ATH_DFSEVENTQ_LOCK(dfs); + event = STAILQ_FIRST(&(dfs->dfs_eventq)); + if (event == NULL) { + ATH_DFSEVENTQ_UNLOCK(dfs); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: no more events space left\n", + __func__); + return; + } + STAILQ_REMOVE_HEAD(&(dfs->dfs_eventq), re_list); + ATH_DFSEVENTQ_UNLOCK(dfs); + event->re_rssi = ev_info->rssi; + event->re_dur = ev_info->dur; + event->re_full_ts = ev_info->full_ts; + event->re_ts = ev_info->ts; + event->re_chanindex = ev_info->chanindex; + event->re_chanindextype = ev_info->flags & CH_TYPE_MASK; + event->re_ext_chan_busy = ev_info->ext_chan_busy; + + ATH_DFSQ_LOCK(dfs); + STAILQ_INSERT_TAIL(&(dfs->dfs_radarq), event, re_list); + ATH_DFSQ_UNLOCK(dfs); + } + + /* TODO: The radar detected event is sent from host in timer + * context which could potentially cause issues with sleepable + * WMI. Change this to process context later. */ + + A_TIMEOUT_MS(&dfs->dfs_radar_task_timer, 0, 0); + +} + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_process_radarevent.c b/drivers/net/wireless/ar6003/host/dfs/dfs_process_radarevent.c new file mode 100644 index 000000000000..9ebe19bb33a1 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_process_radarevent.c @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +static char debug_dup[33]; +static int debug_dup_cnt; + +u_int32_t dfs_round(int32_t val) +{ + u_int32_t ival,rem; + + if (val < 0) + return 0; + ival = val/100; + rem = val-(ival*100); + if (rem <50) + return ival; + else + return(ival+1); +} + + +static inline u_int8_t +dfs_process_pulse_dur(struct ath_dfs_host *dfs, u_int8_t re_dur) +{ + if (re_dur == 0) { + return 1; + } else { + /* Convert 0.8us durations to TSF ticks (usecs) */ + return (u_int8_t)dfs_round((int32_t)((dfs->dur_multiplier)*re_dur)); + } +} + +int +dfs_process_radarevent_host(struct ath_dfs_host *dfs, int16_t *chan_index, u_int8_t *bangradar) +{ + struct dfs_event re,*event; + struct dfs_filtertype *ft; + struct dfs_filter *rf; + int found, retval=0,p, empty; + int events_processed=0; + u_int32_t tabledepth, index; + u_int64_t deltafull_ts = 0,this_ts, deltaT; + struct dfs_pulseline *pl; + static u_int32_t test_ts = 0; + static u_int32_t diff_ts = 0; + + int ext_chan_event_flag=0; + + if (dfs == NULL) { + A_PRINTF("%s: sc_sfs is NULL\n", __func__); + return 0; + } + pl = dfs->pulses; + /* TEST : Simulate radar bang, make sure we add the channel to NOL (bug 29968) */ + if (dfs->dfs_bangradar) { + /* bangradar will always simulate radar found on the primary channel */ + *bangradar = 1; + dfs->dfs_bangradar = 0; /* reset */ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: bangradar\n", __func__); + retval = 1; + } + else + *bangradar = 0; + + ATH_DFSQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_radarq)); + ATH_DFSQ_UNLOCK(dfs); + + while ((!empty) && (!retval) && (events_processed < MAX_EVENTS)) { + ATH_DFSQ_LOCK(dfs); + event = STAILQ_FIRST(&(dfs->dfs_radarq)); + if (event != NULL) + STAILQ_REMOVE_HEAD(&(dfs->dfs_radarq), re_list); + ATH_DFSQ_UNLOCK(dfs); + + if (event == NULL) { + empty = 1; + break; + } + events_processed++; + re = *event; + + OS_MEMZERO(event, sizeof(struct dfs_event)); + ATH_DFSEVENTQ_LOCK(dfs); + STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), event, re_list); + ATH_DFSEVENTQ_UNLOCK(dfs); + + found = 0; + if (re.re_chanindex < DFS_NUM_RADAR_STATES) + *chan_index = re.re_chanindex; + else { + ATH_DFSQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_radarq)); + ATH_DFSQ_UNLOCK(dfs); + continue; + } + + if (dfs->dfs_rinfo.rn_lastfull_ts == 0) { + /* + * Either not started, or 64-bit rollover exactly to zero + * Just prepend zeros to the 15-bit ts + */ + dfs->dfs_rinfo.rn_ts_prefix = 0; + this_ts = (u_int64_t) re.re_ts; + } else { + /* WAR 23031- patch duplicate ts on very short pulses */ + /* This pacth has two problems in linux environment. + * 1)The time stamp created and hence PRI depends entirely on the latency. + * If the latency is high, it possibly can split two consecutive + * pulses in the same burst so far away (the same amount of latency) + * that make them look like they are from differenct bursts. It is + * observed to happen too often. It sure makes the detection fail. + * 2)Even if the latency is not that bad, it simply shifts the duplicate + * timestamps to a new duplicate timestamp based on how they are processed. + * This is not worse but not good either. + * + * Take this pulse as a good one and create a probable PRI later + */ + if (re.re_dur == 0 && re.re_ts == dfs->dfs_rinfo.rn_last_unique_ts) { + debug_dup[debug_dup_cnt++] = '1'; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "\n %s deltaT is 0 \n", __func__); + } else { + dfs->dfs_rinfo.rn_last_unique_ts = re.re_ts; + debug_dup[debug_dup_cnt++] = '0'; + } + if (debug_dup_cnt >= 32){ + debug_dup_cnt = 0; + } + + + if (re.re_ts <= dfs->dfs_rinfo.rn_last_ts) { + dfs->dfs_rinfo.rn_ts_prefix += + (((u_int64_t) 1) << DFS_TSSHIFT); + /* Now, see if it's been more than 1 wrap */ + deltafull_ts = re.re_full_ts - dfs->dfs_rinfo.rn_lastfull_ts; + if (deltafull_ts > + ((u_int64_t)((DFS_TSMASK - dfs->dfs_rinfo.rn_last_ts) + 1 + re.re_ts))) + deltafull_ts -= (DFS_TSMASK - dfs->dfs_rinfo.rn_last_ts) + 1 + re.re_ts; + deltafull_ts = deltafull_ts >> DFS_TSSHIFT; + if (deltafull_ts > 1) { + dfs->dfs_rinfo.rn_ts_prefix += + ((deltafull_ts - 1) << DFS_TSSHIFT); + } + } else { + deltafull_ts = re.re_full_ts - dfs->dfs_rinfo.rn_lastfull_ts; + if (deltafull_ts > (u_int64_t) DFS_TSMASK) { + deltafull_ts = deltafull_ts >> DFS_TSSHIFT; + dfs->dfs_rinfo.rn_ts_prefix += + ((deltafull_ts - 1) << DFS_TSSHIFT); + } + } + this_ts = dfs->dfs_rinfo.rn_ts_prefix | ((u_int64_t) re.re_ts); + } + dfs->dfs_rinfo.rn_lastfull_ts = re.re_full_ts; + dfs->dfs_rinfo.rn_last_ts = re.re_ts; + + re.re_dur = dfs_process_pulse_dur(dfs, re.re_dur); + if (re.re_dur != 1) { + this_ts -= re.re_dur; + } + + /* Save the pulse parameters in the pulse buffer(pulse line) */ + index = (pl->pl_lastelem + 1) & DFS_MAX_PULSE_BUFFER_MASK; + if (pl->pl_numelems == DFS_MAX_PULSE_BUFFER_SIZE) + pl->pl_firstelem = (pl->pl_firstelem+1) & DFS_MAX_PULSE_BUFFER_MASK; + else + pl->pl_numelems++; + pl->pl_lastelem = index; + pl->pl_elems[index].p_time = this_ts; + pl->pl_elems[index].p_dur = re.re_dur; + pl->pl_elems[index].p_rssi = re.re_rssi; + diff_ts = (u_int32_t)this_ts - test_ts; + test_ts = (u_int32_t)this_ts; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1,"ts%u %u %u diff %u pl->pl_lastelem.p_time=%llu\n",(u_int32_t)this_ts, re.re_dur, re.re_rssi, diff_ts, (unsigned long long)pl->pl_elems[index].p_time); + + found = 0; + for (p=0; (pdfs_rinfo.rn_numbin5radars)&&(!found); p++) { + struct dfs_bin5radars *br; + u_int32_t b5_rssithresh; + br = &(dfs->dfs_b5radars[p]); + b5_rssithresh = br->br_pulse.b5_rssithresh; + + /* Adjust the filter threshold for rssi in non TURBO mode*/ + //XXX: If turbo mode, ar events would be used? + //if( ! (sc->sc_curchan.channelFlags & CHANNEL_TURBO) ) { + b5_rssithresh += br->br_pulse.b5_rssimargin; + //} + + if ((re.re_dur >= br->br_pulse.b5_mindur) && + (re.re_dur <= br->br_pulse.b5_maxdur) && + (re.re_rssi >= b5_rssithresh)) { + + // This is a valid Bin5 pulse, check if it belongs to a burst + re.re_dur = dfs_retain_bin5_burst_pattern(dfs, diff_ts, re.re_dur); + // Remember our computed duration for the next pulse in the burst (if needed) + dfs->dfs_rinfo.dfs_bin5_chirp_ts = this_ts; + dfs->dfs_rinfo.dfs_last_bin5_dur = re.re_dur; + + + if( dfs_bin5_addpulse(dfs, br, &re, this_ts) ) { + found |= dfs_bin5_check(dfs); + } + } else + DFS_DPRINTK(dfs, ATH_DEBUG_DFS3, "%s too low to be Bin5 pulse (%d)\n", __func__, re.re_dur); + } + if (found) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "%s: Found bin5 radar\n", __func__); + retval |= found; + goto dfsfound; + } + tabledepth = 0; + rf = NULL; + + while ((tabledepth < DFS_MAX_RADAR_OVERLAP) && + ((dfs->dfs_radartable[re.re_dur])[tabledepth] != -1) && + (!retval)) { + ft = dfs->dfs_radarf[((dfs->dfs_radartable[re.re_dur])[tabledepth])]; + + if (re.re_rssi < ft->ft_rssithresh && re.re_dur > 4) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2,"%s : Rejecting on rssi rssi=%u thresh=%u\n", __func__, re.re_rssi, ft->ft_rssithresh); + tabledepth++; + ATH_DFSQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_radarq)); + ATH_DFSQ_UNLOCK(dfs); + continue; + } + deltaT = this_ts - ft->ft_last_ts; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2,"deltaT = %lld (ts: 0x%llx) (last ts: 0x%llx)\n",(unsigned long long)deltaT, (unsigned long long)this_ts, (unsigned long long)ft->ft_last_ts); + if ((deltaT < ft->ft_minpri) && (deltaT !=0)){ + /* This check is for the whole filter type. Individual filters + will check this again. This is first line of filtering.*/ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "%s: Rejecting on pri pri=%lld minpri=%u\n", __func__, (unsigned long long)deltaT, ft->ft_minpri); + tabledepth++; + continue; + } + for (p=0, found = 0; (pft_numfilters) && (!found); p++) { + rf = &(ft->ft_filters[p]); + if ((re.re_dur >= rf->rf_mindur) && (re.re_dur <= rf->rf_maxdur)) { + /* The above check is probably not necessary */ + deltaT = this_ts - rf->rf_dl.dl_last_ts; + if (deltaT < 0) + deltaT = (int64_t) ((DFS_TSF_WRAP - rf->rf_dl.dl_last_ts) + this_ts +1); + if ((deltaT < rf->rf_minpri) && (deltaT != 0)) { + /* Second line of PRI filtering. */ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "filterID %d : Rejecting on individual filter min PRI deltaT=%lld rf->rf_minpri=%u\n", + rf->rf_pulseid, (unsigned long long)deltaT, rf->rf_minpri); + continue; + } + + if ((rf->rf_patterntype==2) && (deltaT > rf->rf_maxpri) ) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "filterID %d : Staggered - Rejecting on individual filter max PRI deltaT=%lld rf->rf_maxpri=%u\n", + rf->rf_pulseid, (unsigned long long)deltaT, rf->rf_maxpri); + /* But update the last time stamp */ + rf->rf_dl.dl_last_ts = this_ts; + continue; + } + + if ((rf->rf_patterntype!= 2) && (deltaT > rf->rf_maxpri) && (deltaT < (2*rf->rf_minpri))) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, + "filterID %d : Rejecting on individual filter max PRI deltaT=%lld rf->rf_minpri=%u\n", + rf->rf_pulseid, (unsigned long long)deltaT, rf->rf_minpri); + /* But update the last time stamp */ + rf->rf_dl.dl_last_ts = this_ts; + continue; + } + dfs_add_pulse(dfs, rf, &re, deltaT); + /* If this is an extension channel event, flag it for false alarm reduction */ + if (re.re_chanindextype == EXT_CH) + ext_chan_event_flag = 1; + + if (rf->rf_patterntype == 2) + found = dfs_staggered_check(dfs, rf, (u_int32_t) deltaT, re.re_dur, re.re_ext_chan_busy); + else + found = dfs_bin_check(dfs, rf, (u_int32_t) deltaT, re.re_dur, ext_chan_event_flag, re.re_ext_chan_busy); + + dfs_print_delayline(dfs, &rf->rf_dl); + rf->rf_dl.dl_last_ts = this_ts; + } + } + ft->ft_last_ts = this_ts; + retval |= found; + if (found) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, + "Found on channel minDur = %d, filterId = %d\n",ft->ft_mindur, + rf != NULL ? rf->rf_pulseid : -1); + } + tabledepth++; + } + ATH_DFSQ_LOCK(dfs); + empty = STAILQ_EMPTY(&(dfs->dfs_radarq)); + ATH_DFSQ_UNLOCK(dfs); + } +dfsfound: + + return retval; +} + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_staggered.c b/drivers/net/wireless/ar6003/host/dfs/dfs_staggered.c new file mode 100644 index 000000000000..44091c363876 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_staggered.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2002-2010, Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef ATH_SUPPORT_DFS +#include "dfs_host.h" + +int is_pri_multiple(u_int32_t sample_pri, u_int32_t refpri) +{ +#define MAX_ALLOWED_MISSED 3 + int i; + + if (sample_pri < refpri || (!refpri)) + return 0; + + for (i=1; i<= MAX_ALLOWED_MISSED; i++) { + if((sample_pri%(i*refpri) <= 5)) { + //printk("sample_pri=%d is a multiple of refpri=%d\n", sample_pri, refpri); + return 1; + } + } + return 0; +#undef MAX_ALLOWED_MISSED +} + +int is_unique_pri(u_int32_t highestpri , u_int32_t midpri, + u_int32_t lowestpri , u_int32_t refpri ) +{ +#define DFS_STAGGERED_PRI_MARGIN_MIN 20 +#define DFS_STAGGERED_PRI_MARGIN_MAX 400 + if ((DFS_DIFF(lowestpri, refpri) >= DFS_STAGGERED_PRI_MARGIN_MIN) && + (DFS_DIFF(midpri, refpri) >= DFS_STAGGERED_PRI_MARGIN_MIN) && + (DFS_DIFF(highestpri, refpri) >= DFS_STAGGERED_PRI_MARGIN_MIN)) { + return 1; + } else { + if ((is_pri_multiple(refpri, highestpri)) || (is_pri_multiple(refpri, lowestpri)) || + (is_pri_multiple(refpri, midpri))) + return 0; + } + return 0; +#undef DFS_STAGGERED_PRI_MARGIN_MIN +#undef DFS_STAGGERED_PRI_MARGIN_MAX +} + + +int dfs_staggered_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + u_int32_t deltaT, u_int32_t width, u_int32_t ext_chan_busy) +{ + + u_int32_t refpri, refdur, searchpri=0, deltapri;//, averagerefpri; + u_int32_t n, i, primargin, durmargin; + int score[DFS_MAX_DL_SIZE], delayindex, dindex, found=0; + struct dfs_delayline *dl; + u_int32_t scoreindex, lowpriindex= 0, lowpri = 0xffff; + int numpulses=0, higherthan, lowerthan, numscores; + u_int32_t lowestscore=0, lowestscoreindex=0, lowestpri=0; + u_int32_t midscore=0, midscoreindex=0, midpri=0; + u_int32_t highestscore=0, highestscoreindex=0, highestpri=0; + + dl = &rf->rf_dl; + if( dl->dl_numelems < (rf->rf_threshold-1)) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "numelems %d < threshold for filter %d\n", dl->dl_numelems, rf->rf_pulseid); + return 0; + } + if( deltaT > rf->rf_filterlen) { + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "numelems %d < threshold for filter %d\n", dl->dl_numelems, rf->rf_pulseid); + return 0; + } + primargin = 10; + if(rf->rf_maxdur < 10) { + durmargin = 4; + } + else { + durmargin = 6; + } + + OS_MEMZERO(score, sizeof(int)*DFS_MAX_DL_SIZE); + /* find out the lowest pri */ + for (n=0;ndl_numelems; n++) { + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refpri = dl->dl_elems[delayindex].de_time; + if( refpri == 0) + continue; + else if(refpri < lowpri) { + lowpri = dl->dl_elems[delayindex].de_time; + lowpriindex = n; + } + } + /* find out the each delay element's pri score */ + for (n=0;ndl_numelems; n++) { + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refpri = dl->dl_elems[delayindex].de_time; + if( refpri == 0) + continue; + for (i=0;idl_numelems; i++) { + dindex = (dl->dl_firstelem + i) & DFS_MAX_DL_MASK; + searchpri = dl->dl_elems[dindex].de_time; + deltapri = DFS_DIFF(searchpri, refpri); + if( deltapri < primargin) + score[n]++; + } + if( score[n] > rf->rf_threshold) { + /* we got the most possible candidate, + * no need to continue further */ + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "THRESH score[%d]=%d pri=%d\n", n, score[n], searchpri); + break; + } + } + for (n=0;ndl_numelems; n++) { + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refdur = dl->dl_elems[delayindex].de_time; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "score[%d]=%d pri=%d\n", n, score[n], refdur); + } + + /* find out the 2 or 3 highest scorers */ + scoreindex = 0; + highestscore=0; + highestscoreindex=0; + highestpri=0; numscores=0; lowestscore=0; + + for (n=0;ndl_numelems; n++) { + higherthan=0; + lowerthan=0; + delayindex = (dl->dl_firstelem + n) & DFS_MAX_DL_MASK; + refpri = dl->dl_elems[delayindex].de_time; + + if ((score[n] >= highestscore) && + (is_unique_pri(highestpri, midpri, lowestpri, refpri))) { + lowestscore = midscore; + lowestpri = midpri; + lowestscoreindex = midscoreindex; + midscore = highestscore; + midpri = highestpri; + midscoreindex = highestscoreindex; + highestscore = score[n]; + highestpri = refpri; + highestscoreindex = n; + } else { + if ((score[n] >= midscore) && + (is_unique_pri(highestpri, midpri, lowestpri, refpri))) { + lowestscore = midscore; + lowestpri = midpri; + lowestscoreindex = midscoreindex; + midscore = score[n]; + midpri = refpri; + midscoreindex = n; + } else if ((score[n] >= lowestscore) && + (is_unique_pri(highestpri, midpri, lowestpri, refpri))) { + lowestscore = score[n]; + lowestpri = refpri; + lowestscoreindex = n; + } + } + + } + + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "FINAL highestscore=%d highestscoreindex=%d highestpri=%d\n", highestscore, highestscoreindex, highestpri); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "FINAL lowestscore=%d lowestscoreindex=%d lowpri=%d\n", lowestscore, lowestscoreindex, lowestpri); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "FINAL midscore=%d midscoreindex=%d midpri=%d\n", midscore, midscoreindex, midpri); + + delayindex = (dl->dl_firstelem + highestscoreindex) & DFS_MAX_DL_MASK; + refdur = dl->dl_elems[delayindex].de_dur; + refpri = dl->dl_elems[delayindex].de_time; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "highscoreindex=%d refdur=%d refpri=%d\n", highestscoreindex, refdur, refpri); + + numpulses += dfs_bin_pri_check(dfs, rf, dl, highestscore, refpri, refdur, 0, ext_chan_busy); + + ; delayindex = (dl->dl_firstelem + midscoreindex) & DFS_MAX_DL_MASK; + refdur = dl->dl_elems[delayindex].de_dur; + refpri = dl->dl_elems[delayindex].de_time; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "midscoreindex=%d refdur=%d refpri=%d\n", midscoreindex, refdur, refpri); + + numpulses += dfs_bin_pri_check(dfs, rf, dl, midscore, refpri, refdur, 0, ext_chan_busy); + ; + delayindex = (dl->dl_firstelem + lowestscoreindex) & DFS_MAX_DL_MASK; + refdur = dl->dl_elems[delayindex].de_dur; + refpri = dl->dl_elems[delayindex].de_time; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS1, "lowestscoreindex=%d refdur=%d refpri=%d\n", lowestscoreindex, refdur, refpri); + + numpulses += dfs_bin_pri_check(dfs, rf, dl, lowestscore, refpri, refdur, 0, ext_chan_busy); + DFS_DPRINTK(dfs, ATH_DEBUG_DFS2, "numpulses=%d\n",numpulses); + + if (numpulses >= rf->rf_threshold) { + found = 1; + DFS_DPRINTK(dfs, ATH_DEBUG_DFS, "MATCH filter=%u numpulses=%u thresh=%u\n", rf->rf_pulseid, numpulses,rf->rf_threshold); + } + return found; +} + +#endif /* ATH_SUPPORT_DFS */ diff --git a/drivers/net/wireless/ar6003/host/dfs/dfs_target_api.h b/drivers/net/wireless/ar6003/host/dfs/dfs_target_api.h new file mode 100644 index 000000000000..1cc2bdc6b5fe --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/dfs_target_api.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2005-2006 Atheros Communications, Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#ifndef _DFS_TARGET_API_H_ +#define _DFS_TARGET_API_H_ + +#ifdef ATH_SUPPORT_DFS + +#include "ar6000_api.h" + +#define DFS_SET_MINRSSITHRESH(dev_hdl, value) ar6000_dfs_set_minrssithresh_cmd((dev_hdl),(value)) +#define DFS_SET_MAXPULSEDUR(dev_hdl, value) ar6000_dfs_set_maxpulsedur_cmd((dev_hdl),(value)) +#define DFS_RADAR_DETECTED(dev_hdl, ch_idx, bangradar) ar6000_dfs_radar_detected_cmd((dev_hdl),(ch_idx),(bangradar)) + +#endif /* ATH_SUPPORT_DFS */ + +#endif /* _DFS_TARGET_API_ */ diff --git a/drivers/net/wireless/ar6003/host/dfs/makefile b/drivers/net/wireless/ar6003/host/dfs/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/dfs/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/hif/common/hif_bmi_reg_access.c b/drivers/net/wireless/ar6003/host/hif/common/hif_bmi_reg_access.c new file mode 100644 index 000000000000..87af33cf811c --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/common/hif_bmi_reg_access.c @@ -0,0 +1,379 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// common BMI access handling for register-based HIFs +// This module implements BMI message exchanges on behalf of the BMI module for +// HIFs that are based on a register access model +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME bmi +#include "a_debug.h" +#define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0) +#include "hif.h" +#include "bmi.h" +#include "htc_api.h" +#include "target_reg_table.h" +#include "host_reg_table.h" + +#define BMI_COMMUNICATION_TIMEOUT 100000 + +static A_BOOL pendingEventsFuncCheck = FALSE; +static A_UINT32 commandCredits = 0; +static A_UINT32 *pBMICmdCredits = &commandCredits; + +/* BMI Access routines */ +static A_STATUS +bmiBufferSend(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length) +{ + A_STATUS status; + A_UINT32 timeout; + A_UINT32 address; + A_UINT32 mboxAddress[HTC_MAILBOX_NUM_MAX]; + + HIFConfigureDevice(device, HIF_DEVICE_GET_MBOX_ADDR, + &mboxAddress[0], sizeof(mboxAddress)); + + *pBMICmdCredits = 0; + timeout = BMI_COMMUNICATION_TIMEOUT; + + while(timeout-- && !(*pBMICmdCredits)) { + /* Read the counter register to get the command credits */ + address = COUNT_DEC_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 4; + /* hit the credit counter with a 4-byte access, the first byte read will hit the counter and cause + * a decrement, while the remaining 3 bytes has no effect. The rationale behind this is to + * make all HIF accesses 4-byte aligned */ + status = HIFReadWrite(device, address, (A_UINT8 *)pBMICmdCredits, 4, + HIF_RD_SYNC_BYTE_INC, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to decrement the command credit count register\n")); + return A_ERROR; + } + /* the counter is only 8=bits, ignore anything in the upper 3 bytes */ + (*pBMICmdCredits) &= 0xFF; + } + + if (*pBMICmdCredits) { + address = mboxAddress[ENDPOINT1]; + status = HIFReadWrite(device, address, buffer, length, + HIF_WR_SYNC_BYTE_INC, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to send the BMI data to the device\n")); + return A_ERROR; + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI Communication timeout - bmiBufferSend\n")); + return A_ERROR; + } + + return status; +} + +static A_STATUS +bmiBufferReceive(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length, + A_BOOL want_timeout) +{ + A_STATUS status; + A_UINT32 address; + A_UINT32 mboxAddress[HTC_MAILBOX_NUM_MAX]; + HIF_PENDING_EVENTS_INFO hifPendingEvents; + static HIF_PENDING_EVENTS_FUNC getPendingEventsFunc = NULL; + + if (!pendingEventsFuncCheck) { + /* see if the HIF layer implements an alternative function to get pending events + * do this only once! */ + HIFConfigureDevice(device, + HIF_DEVICE_GET_PENDING_EVENTS_FUNC, + &getPendingEventsFunc, + sizeof(HIF_PENDING_EVENTS_FUNC)); + pendingEventsFuncCheck = TRUE; + } + + HIFConfigureDevice(device, HIF_DEVICE_GET_MBOX_ADDR, + &mboxAddress[0], sizeof(mboxAddress)); + + /* + * During normal bootup, small reads may be required. + * Rather than issue an HIF Read and then wait as the Target + * adds successive bytes to the FIFO, we wait here until + * we know that response data is available. + * + * This allows us to cleanly timeout on an unexpected + * Target failure rather than risk problems at the HIF level. In + * particular, this avoids SDIO timeouts and possibly garbage + * data on some host controllers. And on an interconnect + * such as Compact Flash (as well as some SDIO masters) which + * does not provide any indication on data timeout, it avoids + * a potential hang or garbage response. + * + * Synchronization is more difficult for reads larger than the + * size of the MBOX FIFO (128B), because the Target is unable + * to push the 129th byte of data until AFTER the Host posts an + * HIF Read and removes some FIFO data. So for large reads the + * Host proceeds to post an HIF Read BEFORE all the data is + * actually available to read. Fortunately, large BMI reads do + * not occur in practice -- they're supported for debug/development. + * + * So Host/Target BMI synchronization is divided into these cases: + * CASE 1: length < 4 + * Should not happen + * + * CASE 2: 4 <= length <= 128 + * Wait for first 4 bytes to be in FIFO + * If CONSERVATIVE_BMI_READ is enabled, also wait for + * a BMI command credit, which indicates that the ENTIRE + * response is available in the the FIFO + * + * CASE 3: length > 128 + * Wait for the first 4 bytes to be in FIFO + * + * For most uses, a small timeout should be sufficient and we will + * usually see a response quickly; but there may be some unusual + * (debug) cases of BMI_EXECUTE where we want an larger timeout. + * For now, we use an unbounded busy loop while waiting for + * BMI_EXECUTE. + * + * If BMI_EXECUTE ever needs to support longer-latency execution, + * especially in production, this code needs to be enhanced to sleep + * and yield. Also note that BMI_COMMUNICATION_TIMEOUT is currently + * a function of Host processor speed. + */ + if (length >= 4) { /* NB: Currently, always true */ + /* + * NB: word_available is declared static for esoteric reasons + * having to do with protection on some OSes. + */ + static A_UINT32 word_available; + A_UINT32 timeout; + + word_available = 0; + timeout = BMI_COMMUNICATION_TIMEOUT; + while((!want_timeout || timeout--) && !word_available) { + + if (getPendingEventsFunc != NULL) { + status = getPendingEventsFunc(device, + &hifPendingEvents, + NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to get pending events \n")); + break; + } + + if (hifPendingEvents.AvailableRecvBytes >= sizeof(A_UINT32)) { + word_available = 1; + } + continue; + } + + status = HIFReadWrite(device, RX_LOOKAHEAD_VALID_ADDRESS, (A_UINT8 *)&word_available, + sizeof(word_available), HIF_RD_SYNC_BYTE_INC, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read RX_LOOKAHEAD_VALID register\n")); + return A_ERROR; + } + /* We did a 4-byte read to the same register; all we really want is one bit */ + word_available &= (1 << ENDPOINT1); + } + + if (!word_available) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI Communication timeout - bmiBufferReceive FIFO empty\n")); + return A_ERROR; + } + } + +#define CONSERVATIVE_BMI_READ 0 +#if CONSERVATIVE_BMI_READ + /* + * This is an extra-conservative CREDIT check. It guarantees + * that ALL data is available in the FIFO before we start to + * read from the interconnect. + * + * This credit check is useless when firmware chooses to + * allow multiple outstanding BMI Command Credits, since the next + * credit will already be present. To restrict the Target to one + * BMI Command Credit, see HI_OPTION_BMI_CRED_LIMIT. + * + * And for large reads (when HI_OPTION_BMI_CRED_LIMIT is set) + * we cannot wait for the next credit because the Target's FIFO + * will not hold the entire response. So we need the Host to + * start to empty the FIFO sooner. (And again, large reads are + * not used in practice; they are for debug/development only.) + * + * For a more conservative Host implementation (which would be + * safer for a Compact Flash interconnect): + * Set CONSERVATIVE_BMI_READ (above) to 1 + * Set HI_OPTION_BMI_CRED_LIMIT and + * reduce BMI_DATASZ_MAX to 32 or 64 + */ + if ((length > 4) && (length < 128)) { /* check against MBOX FIFO size */ + A_UINT32 timeout; + + *pBMICmdCredits = 0; + timeout = BMI_COMMUNICATION_TIMEOUT; + while((!want_timeout || timeout--) && !(*pBMICmdCredits) { + /* Read the counter register to get the command credits */ + address = COUNT_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 1; + /* read the counter using a 4-byte read. Since the counter is NOT auto-decrementing, + * we can read this counter multiple times using a non-incrementing address mode. + * The rationale here is to make all HIF accesses a multiple of 4 bytes */ + status = HIFReadWrite(device, address, (A_UINT8 *)pBMICmdCredits, sizeof(*pBMICmdCredits), + HIF_RD_SYNC_BYTE_FIX, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read the command credit count register\n")); + return A_ERROR; + } + /* we did a 4-byte read to the same count register so mask off upper bytes */ + (*pBMICmdCredits) &= 0xFF; + } + + if (!(*pBMICmdCredits)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI Communication timeout- bmiBufferReceive no credit\n")); + return A_ERROR; + } + } +#endif + + address = mboxAddress[ENDPOINT1]; + status = HIFReadWrite(device, address, buffer, length, HIF_RD_SYNC_BYTE_INC, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read the BMI data from the device\n")); + return A_ERROR; + } + + return A_OK; +} + + +A_STATUS HIFRegBasedGetTargetInfo(HIF_DEVICE *device, struct bmi_target_info *targ_info) +{ + A_STATUS status; + A_UINT32 cid; + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Get Target Info: Enter (device: 0x%p)\n", device)); + cid = BMI_GET_TARGET_INFO; + + status = bmiBufferSend(device, (A_UCHAR *)&cid, sizeof(cid)); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); + return A_ERROR; + } + + status = bmiBufferReceive(device, (A_UCHAR *)&targ_info->target_ver, + sizeof(targ_info->target_ver), TRUE); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read Target Version from the device\n")); + return A_ERROR; + } + + if (targ_info->target_ver == TARGET_VERSION_SENTINAL) { + /* Determine how many bytes are in the Target's targ_info */ + status = bmiBufferReceive(device, (A_UCHAR *)&targ_info->target_info_byte_count, + sizeof(targ_info->target_info_byte_count), TRUE); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read Target Info Byte Count from the device\n")); + return A_ERROR; + } + + /* + * The Target's targ_info doesn't match the Host's targ_info. + * We need to do some backwards compatibility work to make this OK. + */ + A_ASSERT(targ_info->target_info_byte_count == sizeof(*targ_info)); + + /* Read the remainder of the targ_info */ + status = bmiBufferReceive(device, + ((A_UCHAR *)targ_info)+sizeof(targ_info->target_info_byte_count), + sizeof(*targ_info)-sizeof(targ_info->target_info_byte_count), TRUE); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read Target Info (%d bytes) from the device\n", + targ_info->target_info_byte_count)); + return A_ERROR; + } + } else { + /* + * Target must be an AR6001 whose firmware does not + * support BMI_GET_TARGET_INFO. Construct the data + * that it would have sent. + */ + targ_info->target_info_byte_count=sizeof(*targ_info); + targ_info->target_type=TARGET_TYPE_AR6001; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Get Target Info: Exit (ver: 0x%x type: 0x%x)\n", + targ_info->target_ver, targ_info->target_type)); + + return A_OK; +} + +A_STATUS HIFExchangeBMIMsg(HIF_DEVICE *device, + A_UINT8 *pSendMessage, + A_UINT32 Length, + A_UINT8 *pResponseMessage, + A_UINT32 *pResponseLength, + A_UINT32 TimeoutMS) +{ + A_STATUS status = A_OK; + + do { + + status = bmiBufferSend(device, pSendMessage, Length); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI : Unable to Send Message to device \n")); + break; + } + + if (pResponseMessage != NULL) { + status = bmiBufferReceive(device, pResponseMessage, *pResponseLength, TimeoutMS ? TRUE : FALSE); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI : Unable to read response from device \n")); + break; + } + } + + } while (FALSE); + + return status; +} + +/* TODO .. the following APIs are a relic of the old register based interface */ + +A_STATUS +BMIRawWrite(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length) +{ + return bmiBufferSend(device, buffer, length); +} + +A_STATUS +BMIRawRead(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length, A_BOOL want_timeout) +{ + return bmiBufferReceive(device, buffer, length, want_timeout); +} + + + diff --git a/drivers/net/wireless/ar6003/host/hif/common/hif_diag_reg_access.c b/drivers/net/wireless/ar6003/host/hif/common/hif_diag_reg_access.c new file mode 100644 index 000000000000..559de163f766 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/common/hif_diag_reg_access.c @@ -0,0 +1,266 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// common Diagnostic access handling for register-based HIFs +// This module implements diagnostic accesses on behalf of the diagnostic window module for +// HIFs that are based on a register access model +// +// +// Author(s): ="Atheros" +//============================================================================== + + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME misc +#include "a_debug.h" + +#include "targaddrs.h" +#include "hif.h" +#include "host_reg_table.h" + +#define CPU_DBG_SEL_ADDRESS 0x00000483 +#define CPU_DBG_ADDRESS 0x00000484 + +#ifdef USE_4BYTE_REGISTER_ACCESS +/* set the window address register (using 4-byte register access ). + * This mitigates host interconnect issues with non-4byte aligned bus requests, some + * interconnects use bus adapters that impose strict limitations. + * Since diag window access is not intended for performance critical operations, the 4byte mode should + * be satisfactory even though it generates 4X the bus activity. */ +static A_STATUS ar6000_SetAddressWindowRegister(HIF_DEVICE *hifDevice, A_UINT32 RegisterAddr, A_UINT32 Address) +{ + A_STATUS status; + static A_UINT8 addrValue[4]; + A_INT32 i; + static A_UINT32 address; + + address = Address; + + + /* write bytes 1,2,3 of the register to set the upper address bytes, the LSB is written + * last to initiate the access cycle */ + + for (i = 1; i <= 3; i++) { + /* fill the buffer with the address byte value we want to hit 4 times*/ + addrValue[0] = ((A_UINT8 *)&Address)[i]; + addrValue[1] = addrValue[0]; + addrValue[2] = addrValue[0]; + addrValue[3] = addrValue[0]; + + /* hit each byte of the register address with a 4-byte write operation to the same address, + * this is a harmless operation */ + status = HIFReadWrite(hifDevice, + RegisterAddr+i, + addrValue, + 4, + HIF_WR_SYNC_BYTE_FIX, + NULL); + if (status != A_OK) { + break; + } + } + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write initial bytes of 0x%x to window reg: 0x%X \n", + Address, RegisterAddr)); + return status; + } + + /* write the address register again, this time write the whole 4-byte value. + * The effect here is that the LSB write causes the cycle to start, the extra + * 3 byte write to bytes 1,2,3 has no effect since we are writing the same values again */ + status = HIFReadWrite(hifDevice, + RegisterAddr, + (A_UCHAR *)(&address), + 4, + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to window reg: 0x%X \n", + Address, RegisterAddr)); + return status; + } + + return A_OK; +} +#else + +/* set the window address register */ +A_STATUS ar6000_SetAddressWindowRegister(HIF_DEVICE *hifDevice, A_UINT32 RegisterAddr, A_UINT32 Address) +{ + A_STATUS status; + + /* write bytes 1,2,3 of the register to set the upper address bytes, the LSB is written + * last to initiate the access cycle */ + status = HIFReadWrite(hifDevice, + RegisterAddr+1, /* write upper 3 bytes */ + ((A_UCHAR *)(&Address))+1, + sizeof(A_UINT32)-1, + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write initial bytes of 0x%x to window reg: 0x%X \n", + RegisterAddr, Address)); + return status; + } + + /* write the LSB of the register, this initiates the operation */ + status = HIFReadWrite(hifDevice, + RegisterAddr, + (A_UCHAR *)(&Address), + sizeof(A_UINT8), + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to window reg: 0x%X \n", + RegisterAddr, Address)); + return status; + } + + return A_OK; +} +#endif //USE_4BYTE_REGISTER_ACCESS + +/* + * Read from the AR6000 through its diagnostic window. + * No cooperation from the Target is required for this. + */ +A_STATUS +HIFDiagReadAccess(HIF_DEVICE *hifDevice, A_UINT32 address, A_UINT32 *data) +{ + A_STATUS status; + static A_UINT32 readvalue; + + /* set window register to start read cycle */ + status = ar6000_SetAddressWindowRegister(hifDevice, + WINDOW_READ_ADDR_ADDRESS, + address); + + if (status != A_OK) { + return status; + } + + /* read the data */ + status = HIFReadWrite(hifDevice, + WINDOW_DATA_ADDRESS, + (A_UCHAR *)&readvalue, + sizeof(A_UINT32), + HIF_RD_SYNC_BYTE_INC, + NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot read from WINDOW_DATA_ADDRESS\n")); + return status; + } + + *data = readvalue; + + return status; +} + + +/* + * Write to the AR6000 through its diagnostic window. + * No cooperation from the Target is required for this. + */ +A_STATUS HIFDiagWriteAccess(HIF_DEVICE *hifDevice, A_UINT32 address, A_UINT32 data) +{ + A_STATUS status; + static A_UINT32 writeValue; + + writeValue = data; + + /* set write data */ + status = HIFReadWrite(hifDevice, + WINDOW_DATA_ADDRESS, + (A_UCHAR *)&writeValue, + sizeof(A_UINT32), + HIF_WR_SYNC_BYTE_INC, + NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to WINDOW_DATA_ADDRESS\n", data)); + return status; + } + + /* set window register, which starts the write cycle */ + return ar6000_SetAddressWindowRegister(hifDevice, + WINDOW_WRITE_ADDR_ADDRESS, + address); +} + + +/* TODO .. the following APIs are only available on register-based HIFs where the CPU_DBG_SEL_ADDRESS + * register is available */ + +A_STATUS +ar6k_ReadTargetRegister(HIF_DEVICE *hifDevice, int regsel, A_UINT32 *regval) +{ + A_STATUS status; + A_UCHAR vals[4]; + A_UCHAR register_selection[4]; + + register_selection[0] = register_selection[1] = register_selection[2] = register_selection[3] = (regsel & 0xff); + status = HIFReadWrite(hifDevice, + CPU_DBG_SEL_ADDRESS, + register_selection, + 4, + HIF_WR_SYNC_BYTE_FIX, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write CPU_DBG_SEL (%d)\n", regsel)); + return status; + } + + status = HIFReadWrite(hifDevice, + CPU_DBG_ADDRESS, + (A_UCHAR *)vals, + sizeof(vals), + HIF_RD_SYNC_BYTE_INC, + NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot read from CPU_DBG_ADDRESS\n")); + return status; + } + + *regval = vals[0]<<0 | vals[1]<<8 | vals[2]<<16 | vals[3]<<24; + + return status; +} + +void +ar6k_FetchTargetRegs(HIF_DEVICE *hifDevice, A_UINT32 *targregs) +{ + int i; + A_UINT32 val; + + for (i=0; iMboxProp[0].ExtendedAddress = HIF_MBOX0_EXTENDED_BASE_ADDR; + //pInfo->MboxProp[0].ExtendedSize = HIF_MBOX0_EXTENDED_WIDTH_AR6002; + + pInfo->MboxProp[0].ExtendedAddress = HIF_MBOX0_EXTENDED_BASE_ADDR_AR6003_V1; + pInfo->MboxProp[0].ExtendedSize = HIF_MBOX0_EXTENDED_WIDTH_AR6003_V1; + + break; + case MANUFACTURER_ID_AR6003_BASE : + /* MBOX 0 has an extended range */ + pInfo->MboxProp[0].ExtendedAddress = HIF_MBOX0_EXTENDED_BASE_ADDR_AR6003_V1; + pInfo->MboxProp[0].ExtendedSize = HIF_MBOX0_EXTENDED_WIDTH_AR6003_V1; + pInfo->GMboxAddress = HIF_GMBOX_BASE_ADDR; + pInfo->GMboxSize = HIF_GMBOX_WIDTH; + break; + case MANUFACTURER_ID_MCKINLEY_BASE : + pInfo->MboxProp[0].ExtendedAddress = HIF_MBOX0_EXTENDED_BASE_ADDR_AR6003_V1; /* TBDXXX */ + pInfo->MboxProp[0].ExtendedSize = HIF_MBOX0_EXTENDED_WIDTH_AR6003_V1; + break; + default: + A_ASSERT(FALSE); + break; + } +} + +/* special CCCR (func 0) registers */ + +#define CCCR_SDIO_IRQ_MODE_REG 0xF0 /* interrupt mode register */ +#define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ (1 << 0) /* mode to enable special 4-bit interrupt assertion without clock*/ + +#endif /*HIF_SDIO_COMMON_H_*/ diff --git a/drivers/net/wireless/ar6003/host/hif/common/makefile b/drivers/net/wireless/ar6003/host/hif/common/makefile new file mode 100644 index 000000000000..4cab10f2397a --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/common/makefile @@ -0,0 +1,12 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + diff --git a/drivers/net/wireless/ar6003/host/hif/sdio/Makefile b/drivers/net/wireless/ar6003/host/hif/sdio/Makefile new file mode 100644 index 000000000000..17c3d8c594da --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/sdio/Makefile @@ -0,0 +1,90 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2008 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +# +#SDIO HIF makefile for atheros SDIO stack +# + +# Check for SDIO stack +ifdef ATH_SDIO_STACK_BASE +# Someone already set it on entry, the stack resides outside this tree, we will try to build it +_SDIO_STACK = YES +else +# Check for SDIO stack within this tree +_SDIO_STACK = $(shell if [ -f $(ATH_SRC_BASE)/sdiostack/src/Makefile ]; then echo "YES"; else echo "NO"; fi) + +ifeq ($(_SDIO_STACK), YES) + # SDIO stack is part of the kit and will need to be compiled +ATH_SDIO_STACK_BASE := $(ATH_SRC_BASE)/sdiostack +endif +endif + + +ifeq ($(ATH_BUS_SUBTYPE),linux_sdio) +_HIF_SUB_TYPE = linux_sdio +_SDIO_STACK = NO +else +_HIF_SUB_TYPE = linux_athsdio +endif + + +ifeq ($(_SDIO_STACK), YES) + # Pass and translate build variables to the SDIO stack makefile +_SDIO_STACK_MAKE_PARAMS := CT_BUILD_TYPE=$(ATH_BUILD_TYPE) \ + CT_OS_TYPE=linux \ + CT_OS_SUB_TYPE=$(ATH_OS_SUB_TYPE) \ + CT_LINUXPATH=$(ATH_LINUXPATH) \ + CT_BUILD_TYPE=$(ATH_BUILD_TYPE) \ + CT_CROSS_COMPILE_TYPE=$(ATH_CROSS_COMPILE_TYPE) \ + CT_ARCH_CPU_TYPE=$(ATH_ARCH_CPU_TYPE) \ + CT_HC_DRIVERS=$(ATH_HC_DRIVERS) \ + CT_MAKE_INCLUDE_OVERRIDE=$(_LOCALMAKE_INCLUDE) \ + CT_BUILD_OUTPUT_OVERRIDE=$(COMPILED_IMAGE_OBJECTS_PATH) \ + BUS_BUILD=1 +endif +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/hif/sdio/$(_HIF_SUB_TYPE)/include +EXTRA_CFLAGS += -DSDIO +EXTRA_CFLAGS += -I$(ATH_SDIO_STACK_BASE)/src/include + +ifeq ($(ATH_OS_SUB_TYPE),linux_2_4) +obj-y += ../../hif/sdio/linux_athsdio/src/hif.o +obj-y += ../../hif/sdio/linux_athsdio/src/hif_scatter.o +endif + +ifneq ($(ATH_OS_SUB_TYPE),linux_2_4) +ar6000-objs := ../../hif/sdio/$(_HIF_SUB_TYPE)/src/hif.o \ + ../../hif/sdio/$(_HIF_SUB_TYPE)/src/hif_scatter.o + + +endif + +all: +ifeq ($(_SDIO_STACK),YES) + $(MAKE) $(_SDIO_STACK_MAKE_PARAMS) -C $(ATH_SDIO_STACK_BASE)/src default + -cp -f $(ATH_SDIO_STACK_BASE)/src/Module.symvers $(COMPILED_IMAGE_OBJECTS_PATH) +endif + +clean: +ifeq ($(_SDIO_STACK),YES) + $(MAKE) $(_SDIO_STACK_MAKE_PARAMS) -C $(ATH_SDIO_STACK_BASE)/src clean +endif diff --git a/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/include/hif_internal.h b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/include/hif_internal.h new file mode 100644 index 000000000000..df6ab6aeb56c --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/include/hif_internal.h @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// internal header file for hif layer +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HIF_INTERNAL_H_ +#define _HIF_INTERNAL_H_ + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "hif.h" +#include "../../../common/hif_sdio_common.h" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) +#include +//#define HIF_LINUX_MMC_SCATTER_SUPPORT +#endif + +#define BUS_REQUEST_MAX_NUM 64 + +#define SDIO_CLOCK_FREQUENCY_DEFAULT 25000000 +#define SDWLAN_ENABLE_DISABLE_TIMEOUT 20 +#define FLAGS_CARD_ENAB 0x02 +#define FLAGS_CARD_IRQ_UNMSK 0x04 + +#define HIF_MBOX_BLOCK_SIZE HIF_DEFAULT_IO_BLOCK_SIZE +#define HIF_MBOX0_BLOCK_SIZE 1 +#define HIF_MBOX1_BLOCK_SIZE HIF_MBOX_BLOCK_SIZE +#define HIF_MBOX2_BLOCK_SIZE HIF_MBOX_BLOCK_SIZE +#define HIF_MBOX3_BLOCK_SIZE HIF_MBOX_BLOCK_SIZE + +struct _HIF_SCATTER_REQ_PRIV; + +typedef struct bus_request { + struct bus_request *next; /* link list of available requests */ + struct bus_request *inusenext; /* link list of in use requests */ + struct semaphore sem_req; + A_UINT32 address; /* request data */ + A_UCHAR *buffer; + A_UINT32 length; + A_UINT32 request; + void *context; + A_STATUS status; + struct _HIF_SCATTER_REQ_PRIV *pScatterReq; /* this request is a scatter request */ +} BUS_REQUEST; + +struct hif_device { + struct sdio_func *func; + spinlock_t asynclock; + struct task_struct* async_task; /* task to handle async commands */ + struct semaphore sem_async; /* wake up for async task */ + int async_shutdown; /* stop the async task */ + struct completion async_completion; /* thread completion */ + BUS_REQUEST *asyncreq; /* request for async tasklet */ + BUS_REQUEST *taskreq; /* async tasklet data */ + spinlock_t lock; + BUS_REQUEST *s_busRequestFreeQueue; /* free list */ + BUS_REQUEST busRequest[BUS_REQUEST_MAX_NUM]; /* available bus requests */ + void *claimedContext; + HTC_CALLBACKS htcCallbacks; + A_UINT8 *dma_buffer; + DL_LIST ScatterReqHead; /* scatter request list head */ + A_BOOL scatter_enabled; /* scatter enabled flag */ + A_BOOL is_suspend; + A_BOOL is_disabled; + atomic_t irqHandling; + HIF_DEVICE_POWER_CHANGE_TYPE powerConfig; + const struct sdio_device_id *id; + struct mmc_host *host; +}; + +#define HIF_DMA_BUFFER_SIZE (32 * 1024) +#define CMD53_FIXED_ADDRESS 1 +#define CMD53_INCR_ADDRESS 2 + +BUS_REQUEST *hifAllocateBusRequest(HIF_DEVICE *device); +void hifFreeBusRequest(HIF_DEVICE *device, BUS_REQUEST *busrequest); +void AddToAsyncList(HIF_DEVICE *device, BUS_REQUEST *busrequest); + +#ifdef HIF_LINUX_MMC_SCATTER_SUPPORT + +#define MAX_SCATTER_REQUESTS 4 +#define MAX_SCATTER_ENTRIES_PER_REQ 16 +#define MAX_SCATTER_REQ_TRANSFER_SIZE 32*1024 + +typedef struct _HIF_SCATTER_REQ_PRIV { + HIF_SCATTER_REQ *pHifScatterReq; /* HIF scatter request with allocated entries */ + HIF_DEVICE *device; /* this device */ + BUS_REQUEST *busrequest; /* request associated with request */ + /* scatter list for linux */ + struct scatterlist sgentries[MAX_SCATTER_ENTRIES_PER_REQ]; +} HIF_SCATTER_REQ_PRIV; + +#define ATH_DEBUG_SCATTER ATH_DEBUG_MAKE_MODULE_MASK(0) + +A_STATUS SetupHIFScatterSupport(HIF_DEVICE *device, HIF_DEVICE_SCATTER_SUPPORT_INFO *pInfo); +void CleanupHIFScatterResources(HIF_DEVICE *device); +A_STATUS DoHifReadWriteScatter(HIF_DEVICE *device, BUS_REQUEST *busrequest); + +#else // HIF_LINUX_MMC_SCATTER_SUPPORT + +static inline A_STATUS SetupHIFScatterSupport(HIF_DEVICE *device, HIF_DEVICE_SCATTER_SUPPORT_INFO *pInfo) +{ + return A_ENOTSUP; +} + +static inline A_STATUS DoHifReadWriteScatter(HIF_DEVICE *device, BUS_REQUEST *busrequest) +{ + return A_ENOTSUP; +} + +#define CleanupHIFScatterResources(d) { } + +#endif // HIF_LINUX_MMC_SCATTER_SUPPORT + +#endif // _HIF_INTERNAL_H_ + diff --git a/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif.c b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif.c new file mode 100644 index 000000000000..dfca63fd4f9e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif.c @@ -0,0 +1,1504 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HIF layer reference implementation for Linux Native MMC stack +// +// Author(s): ="Atheros" +//============================================================================== +#include +#include +#include +#include +#include +#include +#include +#include +#include "common_drv.h" +#include "host_reg_table.h" + +/* by default setup a bounce buffer for the data packets, if the underlying host controller driver + does not use DMA you may be able to skip this step and save the memory allocation and transfer time */ +#define HIF_USE_DMA_BOUNCE_BUFFER 1 +#include "hif_internal.h" +#define ATH_MODULE_NAME hif +#include "a_debug.h" + +#if HIF_USE_DMA_BOUNCE_BUFFER +/* macro to check if DMA buffer is WORD-aligned and DMA-able. Most host controllers assume the + * buffer is DMA'able and will bug-check otherwise (i.e. buffers on the stack). + * virt_addr_valid check fails on stack memory. + */ +#define BUFFER_NEEDS_BOUNCE(buffer) (((unsigned long)(buffer) & 0x3) || !virt_addr_valid((buffer))) +#else +#define BUFFER_NEEDS_BOUNCE(buffer) (FALSE) +#endif + +#define MAX_HIF_DEVICES 2 + +/* ATHENV */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) +#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev) +#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv) +static int hifDeviceSuspend(struct device *dev); +static int hifDeviceResume(struct device *dev); +#endif /* CONFIG_PM */ +static int hifDeviceInserted(struct sdio_func *func, const struct sdio_device_id *id); +static void hifDeviceRemoved(struct sdio_func *func); +static HIF_DEVICE *addHifDevice(struct sdio_func *func); +static HIF_DEVICE *getHifDevice(struct sdio_func *func); +static void delHifDevice(HIF_DEVICE * device); +static int Func0_CMD52WriteByte(struct mmc_card *card, unsigned int address, unsigned char byte); +static int Func0_CMD52ReadByte(struct mmc_card *card, unsigned int address, unsigned char *byte); +void hif_register_tbl_attach(A_UINT32 hif_type); + +int reset_sdio_on_unload = 0; +module_param(reset_sdio_on_unload, int, 0644); + +extern A_UINT32 nohifscattersupport; + + +/* ------ Static Variables ------ */ +static const struct sdio_device_id ar6k_id_table[] = { +#ifdef AR6003_HEADERS_DEF + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0)) }, + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1)) }, +#endif + { /* null */ }, +}; +MODULE_DEVICE_TABLE(sdio, ar6k_id_table); + +static struct sdio_driver ar6k_driver = { + .name = "ar6k_wlan", + .id_table = ar6k_id_table, + .probe = hifDeviceInserted, + .remove = hifDeviceRemoved, +}; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) +/* New suspend/resume based on linux-2.6.32 + * Need to patch linux-2.6.32 with mmc2.6.32_suspend.patch + * Need to patch with msmsdcc2.6.29_suspend.patch for msm_sdcc host + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) +static struct dev_pm_ops ar6k_device_pm_ops = { +#else +static struct pm_ops ar6k_device_pm_ops = { +#endif + .suspend = hifDeviceSuspend, + .resume = hifDeviceResume, +}; +#endif /* CONFIG_PM */ + +/* make sure we only unregister when registered. */ +static int registered = 0; + +OSDRV_CALLBACKS osdrvCallbacks; +extern A_UINT32 onebitmode; +extern A_UINT32 busspeedlow; +extern A_UINT32 debughif; + +static HIF_DEVICE *hif_devices[MAX_HIF_DEVICES]; + +static void ResetAllCards(void); +static A_STATUS hifDisableFunc(HIF_DEVICE *device, struct sdio_func *func); +static A_STATUS hifEnableFunc(HIF_DEVICE *device, struct sdio_func *func); + +#ifdef DEBUG + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(hif, + "hif", + "(Linux MMC) Host Interconnect Framework", + ATH_DEBUG_MASK_DEFAULTS, + 0, + NULL); + +#endif + + +/* ------ Functions ------ */ +A_STATUS HIFInit(OSDRV_CALLBACKS *callbacks) +{ + int status; + AR_DEBUG_ASSERT(callbacks != NULL); + + A_REGISTER_MODULE_DEBUG_INFO(hif); + + /* store the callback handlers */ + osdrvCallbacks = *callbacks; + + /* Register with bus driver core */ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: HIFInit registering\n")); + registered = 1; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) + if (callbacks->deviceSuspendHandler && callbacks->deviceResumeHandler) { + ar6k_driver.drv.pm = &ar6k_device_pm_ops; + } +#endif /* CONFIG_PM */ + status = sdio_register_driver(&ar6k_driver); + AR_DEBUG_ASSERT(status==0); + + if (status != 0) { + return A_ERROR; + } + + return A_OK; + +} + +static A_STATUS +__HIFReadWrite(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length, + A_UINT32 request, + void *context) +{ + A_UINT8 opcode; + A_STATUS status = A_OK; + int ret; + A_UINT8 *tbuffer; + A_BOOL bounced = FALSE; + + AR_DEBUG_ASSERT(device != NULL); + AR_DEBUG_ASSERT(device->func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Device: 0x%p, buffer:0x%p (addr:0x%X)\n", + device, buffer, address)); + + do { + if (request & HIF_EXTENDED_IO) { + //AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Command type: CMD53\n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Invalid command type: 0x%08x\n", request)); + status = A_EINVAL; + break; + } + + if (request & HIF_BLOCK_BASIS) { + /* round to whole block length size */ + length = (length / HIF_MBOX_BLOCK_SIZE) * HIF_MBOX_BLOCK_SIZE; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: Block mode (BlockLen: %d)\n", + length)); + } else if (request & HIF_BYTE_BASIS) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: Byte mode (BlockLen: %d)\n", + length)); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Invalid data mode: 0x%08x\n", request)); + status = A_EINVAL; + break; + } + +#if 0 + /* useful for checking register accesses */ + if (length & 0x3) { + A_PRINTF(KERN_ALERT"AR6000: HIF (%s) is not a multiple of 4 bytes, addr:0x%X, len:%d\n", + request & HIF_WRITE ? "write":"read", address, length); + } +#endif + + if (request & HIF_WRITE) { + if ((address >= HIF_MBOX_START_ADDR(0)) && + (address <= HIF_MBOX_END_ADDR(3))) + { + + AR_DEBUG_ASSERT(length <= HIF_MBOX_WIDTH); + + /* + * Mailbox write. Adjust the address so that the last byte + * falls on the EOM address. + */ + address += (HIF_MBOX_WIDTH - length); + } + } + + if (request & HIF_FIXED_ADDRESS) { + opcode = CMD53_FIXED_ADDRESS; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Address mode: Fixed 0x%X\n", address)); + } else if (request & HIF_INCREMENTAL_ADDRESS) { + opcode = CMD53_INCR_ADDRESS; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Address mode: Incremental 0x%X\n", address)); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Invalid address mode: 0x%08x\n", request)); + status = A_EINVAL; + break; + } + + if (request & HIF_WRITE) { +#if HIF_USE_DMA_BOUNCE_BUFFER + if (BUFFER_NEEDS_BOUNCE(buffer)) { + AR_DEBUG_ASSERT(device->dma_buffer != NULL); + tbuffer = device->dma_buffer; + /* copy the write data to the dma buffer */ + AR_DEBUG_ASSERT(length <= HIF_DMA_BUFFER_SIZE); + memcpy(tbuffer, buffer, length); + bounced = TRUE; + } else { + tbuffer = buffer; + } +#else + tbuffer = buffer; +#endif + if (opcode == CMD53_FIXED_ADDRESS) { + ret = sdio_writesb(device->func, address, tbuffer, length); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: writesb ret=%d address: 0x%X, len: %d, 0x%X\n", + ret, address, length, *(int *)tbuffer)); + } else { + ret = sdio_memcpy_toio(device->func, address, tbuffer, length); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: writeio ret=%d address: 0x%X, len: %d, 0x%X\n", + ret, address, length, *(int *)tbuffer)); + } + } else if (request & HIF_READ) { +#if HIF_USE_DMA_BOUNCE_BUFFER + if (BUFFER_NEEDS_BOUNCE(buffer)) { + AR_DEBUG_ASSERT(device->dma_buffer != NULL); + AR_DEBUG_ASSERT(length <= HIF_DMA_BUFFER_SIZE); + tbuffer = device->dma_buffer; + bounced = TRUE; + } else { + tbuffer = buffer; + } +#else + tbuffer = buffer; +#endif + if (opcode == CMD53_FIXED_ADDRESS) { + ret = sdio_readsb(device->func, tbuffer, address, length); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: readsb ret=%d address: 0x%X, len: %d, 0x%X\n", + ret, address, length, *(int *)tbuffer)); + } else { + ret = sdio_memcpy_fromio(device->func, tbuffer, address, length); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: readio ret=%d address: 0x%X, len: %d, 0x%X\n", + ret, address, length, *(int *)tbuffer)); + } +#if HIF_USE_DMA_BOUNCE_BUFFER + if (bounced) { + /* copy the read data from the dma buffer */ + memcpy(buffer, tbuffer, length); + } +#endif + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Invalid direction: 0x%08x\n", request)); + status = A_EINVAL; + break; + } + + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: SDIO bus operation failed! MMC stack returned : %d \n", ret)); + status = A_ERROR; + } + } while (FALSE); + + return status; +} + +void AddToAsyncList(HIF_DEVICE *device, BUS_REQUEST *busrequest) +{ + unsigned long flags; + BUS_REQUEST *async; + BUS_REQUEST *active; + + spin_lock_irqsave(&device->asynclock, flags); + active = device->asyncreq; + if (active == NULL) { + device->asyncreq = busrequest; + device->asyncreq->inusenext = NULL; + } else { + for (async = device->asyncreq; + async != NULL; + async = async->inusenext) { + active = async; + } + active->inusenext = busrequest; + busrequest->inusenext = NULL; + } + spin_unlock_irqrestore(&device->asynclock, flags); +} + + +/* queue a read/write request */ +A_STATUS +HIFReadWrite(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length, + A_UINT32 request, + void *context) +{ + A_STATUS status = A_OK; + BUS_REQUEST *busrequest; + + + AR_DEBUG_ASSERT(device != NULL); + AR_DEBUG_ASSERT(device->func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Device: %p addr:0x%X\n", device,address)); + + do { + if ((request & HIF_ASYNCHRONOUS) || (request & HIF_SYNCHRONOUS)){ + /* serialize all requests through the async thread */ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Execution mode: %s\n", + (request & HIF_ASYNCHRONOUS)?"Async":"Synch")); + busrequest = hifAllocateBusRequest(device); + if (busrequest == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: no async bus requests available (%s, addr:0x%X, len:%d) \n", + request & HIF_READ ? "READ":"WRITE", address, length)); + return A_ERROR; + } + busrequest->address = address; + busrequest->buffer = buffer; + busrequest->length = length; + busrequest->request = request; + busrequest->context = context; + + AddToAsyncList(device, busrequest); + + if (request & HIF_SYNCHRONOUS) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: queued sync req: 0x%lX\n", (unsigned long)busrequest)); + + /* wait for completion */ + up(&device->sem_async); + if (down_interruptible(&busrequest->sem_req) != 0) { + /* interrupted, exit */ + return A_ERROR; + } else { + A_STATUS status = busrequest->status; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: sync return freeing 0x%lX: 0x%X\n", + (unsigned long)busrequest, busrequest->status)); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: freeing req: 0x%X\n", (unsigned int)request)); + hifFreeBusRequest(device, busrequest); + return status; + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: queued async req: 0x%lX\n", (unsigned long)busrequest)); + up(&device->sem_async); + return A_PENDING; + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Invalid execution mode: 0x%08x\n", (unsigned int)request)); + status = A_EINVAL; + break; + } + } while(0); + + return status; +} +/* thread to serialize all requests, both sync and async */ +static int async_task(void *param) + { + HIF_DEVICE *device; + BUS_REQUEST *request; + A_STATUS status; + unsigned long flags; + + device = (HIF_DEVICE *)param; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async task\n")); + set_current_state(TASK_INTERRUPTIBLE); + while(!device->async_shutdown) { + /* wait for work */ + if (down_interruptible(&device->sem_async) != 0) { + /* interrupted, exit */ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async task interrupted\n")); + break; + } + if (device->async_shutdown) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async task stopping\n")); + break; + } + /* we want to hold the host over multiple cmds if possible, but holding the host blocks card interrupts */ + sdio_claim_host(device->func); + spin_lock_irqsave(&device->asynclock, flags); + /* pull the request to work on */ + while (device->asyncreq != NULL) { + request = device->asyncreq; + if (request->inusenext != NULL) { + device->asyncreq = request->inusenext; + } else { + device->asyncreq = NULL; + } + spin_unlock_irqrestore(&device->asynclock, flags); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async_task processing req: 0x%lX\n", (unsigned long)request)); + + if (request->pScatterReq != NULL) { + A_ASSERT(device->scatter_enabled); + /* this is a queued scatter request, pass the request to scatter routine which + * executes it synchronously, note, no need to free the request since scatter requests + * are maintained on a separate list */ + status = DoHifReadWriteScatter(device,request); + } else { + /* call HIFReadWrite in sync mode to do the work */ + status = __HIFReadWrite(device, request->address, request->buffer, + request->length, request->request & ~HIF_SYNCHRONOUS, NULL); + if (request->request & HIF_ASYNCHRONOUS) { + void *context = request->context; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async_task freeing req: 0x%lX\n", (unsigned long)request)); + hifFreeBusRequest(device, request); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async_task completion routine req: 0x%lX\n", (unsigned long)request)); + device->htcCallbacks.rwCompletionHandler(context, status); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: async_task upping req: 0x%lX\n", (unsigned long)request)); + request->status = status; + up(&request->sem_req); + } + } + spin_lock_irqsave(&device->asynclock, flags); + } + spin_unlock_irqrestore(&device->asynclock, flags); + sdio_release_host(device->func); + } + + complete_and_exit(&device->async_completion, 0); + return 0; +} + +static A_INT32 IssueSDCommand(HIF_DEVICE *device, A_UINT32 opcode, A_UINT32 arg, A_UINT32 flags, A_UINT32 *resp) +{ + struct mmc_command cmd; + A_INT32 err; + struct mmc_host *host; + struct sdio_func *func; + + func = device->func; + host = func->card->host; + + memset(&cmd, 0, sizeof(struct mmc_command)); + cmd.opcode = opcode; + cmd.arg = arg; + cmd.flags = flags; + err = mmc_wait_for_cmd(host, &cmd, 3); + + if ((!err) && (resp)) { + *resp = cmd.resp[0]; + } + + return err; +} +A_STATUS ReinitSDIO(HIF_DEVICE *device) +{ + A_INT32 err = 0; + struct mmc_host *host; + struct mmc_card *card; + struct sdio_func *func; + A_UINT8 cmd52_resp; + A_UINT32 clock; + + func = device->func; + card = func->card; + host = card->host; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +ReinitSDIO \n")); + sdio_claim_host(func); + + do { + /* 2.6.32 kernel does part of the SDIO initalization upon resume */ + A_BOOL lt_2_6_32 = (LINUX_VERSION_CODEocr_avail) - 1; + /* emulate the mmc_power_up(...) */ + host->ios.vdd = bit; + host->ios.chip_select = MMC_CS_DONTCARE; + host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; + host->ios.power_mode = MMC_POWER_UP; + host->ios.bus_width = MMC_BUS_WIDTH_1; + host->ios.timing = MMC_TIMING_LEGACY; + host->ops->set_ios(host, &host->ios); + /* + * This delay should be sufficient to allow the power supply + * to reach the minimum voltage. + */ + msleep(2); + + host->ios.clock = host->f_min; + host->ios.power_mode = MMC_POWER_ON; + host->ops->set_ios(host, &host->ios); + + /* + * This delay must be at least 74 clock sizes, or 1 ms, or the + * time required to reach a stable voltage. + */ + msleep(2); + + /* Issue CMD0. Goto idle state */ + host->ios.chip_select = MMC_CS_HIGH; + host->ops->set_ios(host, &host->ios); + msleep(1); + err = IssueSDCommand(device, MMC_GO_IDLE_STATE, 0, (MMC_RSP_NONE | MMC_CMD_BC), NULL); + host->ios.chip_select = MMC_CS_DONTCARE; + host->ops->set_ios(host, &host->ios); + msleep(1); + host->use_spi_crc = 0; + + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD0 failed : %d \n",err)); + break; + } + + if (!host->ocr) { + /* Issue CMD5, arg = 0 */ + err = IssueSDCommand(device, SD_IO_SEND_OP_COND, 0, (MMC_RSP_R4 | MMC_CMD_BCR), &resp); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD5 failed : %d \n",err)); + break; + } + host->ocr = resp; + } + + /* Issue CMD5, arg = ocr. Wait till card is ready */ + for (i=0;i<100;i++) { + err = IssueSDCommand(device, SD_IO_SEND_OP_COND, host->ocr, (MMC_RSP_R4 | MMC_CMD_BCR), &resp); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD5 failed : %d \n",err)); + break; + } + if (resp & MMC_CARD_BUSY) { + break; + } + msleep(10); + } + + if ((i == 100) || (err)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: card in not ready : %d %d \n",i,err)); + break; + } + + /* Issue CMD3, get RCA */ + err = IssueSDCommand(device, SD_SEND_RELATIVE_ADDR, 0, MMC_RSP_R6 | MMC_CMD_BCR, &resp); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD3 failed : %d \n",err)); + break; + } + rca = resp >> 16; + host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; + host->ops->set_ios(host, &host->ios); + + /* Issue CMD7, select card */ + err = IssueSDCommand(device, MMC_SELECT_CARD, (rca << 16), MMC_RSP_R1 | MMC_CMD_AC, NULL); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD7 failed : %d \n",err)); + break; + } + } + + /* Enable high speed */ + if (card->host->caps & MMC_CAP_SD_HIGHSPEED) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("ReinitSDIO: Set high speed mode\n")); + err = Func0_CMD52ReadByte(card, SDIO_CCCR_SPEED, &cmd52_resp); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD52 read to CCCR speed register failed : %d \n",err)); + card->state &= ~MMC_STATE_HIGHSPEED; + /* no need to break */ + } else { + err = Func0_CMD52WriteByte(card, SDIO_CCCR_SPEED, (cmd52_resp | SDIO_SPEED_EHS)); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD52 write to CCCR speed register failed : %d \n",err)); + break; + } + mmc_card_set_highspeed(card); + host->ios.timing = MMC_TIMING_SD_HS; + host->ops->set_ios(host, &host->ios); + } + } + + /* Set clock */ + if (mmc_card_highspeed(card)) { + clock = 50000000; + } else { + clock = card->cis.max_dtr; + } + + if (clock > host->f_max) { + clock = host->f_max; + } + host->ios.clock = clock; + host->ops->set_ios(host, &host->ios); + + + if (card->host->caps & MMC_CAP_4_BIT_DATA) { + /* CMD52: Set bus width & disable card detect resistor */ + err = Func0_CMD52WriteByte(card, SDIO_CCCR_IF, SDIO_BUS_CD_DISABLE | SDIO_BUS_WIDTH_4BIT); + if (err) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ReinitSDIO: CMD52 to set bus mode failed : %d \n",err)); + break; + } + host->ios.bus_width = MMC_BUS_WIDTH_4; + host->ops->set_ios(host, &host->ios); + } + } while (0); + + sdio_release_host(func); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -ReinitSDIO \n")); + + return (err) ? A_ERROR : A_OK; +} + +#if defined(CONFIG_PM) +/* + * Setup IRQ mode for deep sleep and WoW + * Switch back to 1 bits mode when we suspend for WoW in order to + * detect SDIO irq without clock. + * Re-enable async 4-bit irq mode for some host controllers after resume + */ +static int SdioEnable4bits(HIF_DEVICE *device, int enable) +{ + int ret = 0; + struct sdio_func *func = device->func; + struct mmc_card *card = func->card; + struct mmc_host *host = card->host; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) + unsigned char ctrl = 0; + unsigned int width; +#ifdef SDIO_BUS_WIDTH_8BIT + unsigned char wide_mask = (SDIO_BUS_WIDTH_4BIT|SDIO_BUS_WIDTH_8BIT); +#else + unsigned char wide_mask = (SDIO_BUS_WIDTH_4BIT); +#endif +#endif + + if (!(host->caps & (MMC_CAP_4_BIT_DATA))) + return 0; + + if (card->cccr.low_speed && !card->cccr.wide_bus) + return 0; + + sdio_claim_host(func); + do { + /* 2.6.34 will setup 1bits automatically. No need to setup */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) + ret = Func0_CMD52ReadByte(card, SDIO_CCCR_IF, &ctrl); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Fail to read CCCR_IF : %d \n", __func__, ret)); + break; + } + if (enable) { + width = MMC_BUS_WIDTH_4; + ctrl &= ~(SDIO_BUS_WIDTH_1BIT|wide_mask); + ctrl |= SDIO_BUS_WIDTH_4BIT; + } else { + width = MMC_BUS_WIDTH_1; + ctrl &= ~(wide_mask); + } + + ret = Func0_CMD52WriteByte(card, SDIO_CCCR_IF, ctrl); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Fail to write CCCR_IF : %d \n", __func__, ret)); + break; + } + host->ios.bus_width = width; + host->ops->set_ios(host, &host->ios); +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) */ + + if ((device->id->device & MANUFACTURER_ID_AR6K_BASE_MASK) >= MANUFACTURER_ID_AR6003_BASE) { + /* Re-enable 4-bit ASYNC interrupt on AR6003x after system resume for some host controller */ + ret = Func0_CMD52WriteByte(func->card, CCCR_SDIO_IRQ_MODE_REG, enable ? SDIO_IRQ_MODE_ASYNC_4BIT_IRQ : 0); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6000: failed to setup 4-bit ASYNC IRQ mode into %d err %d \n", enable, ret)); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("AR6000: Setup 4-bit ASYNC IRQ mode into %d successfully\n", enable)); + } + } + } while (0); + sdio_release_host(func); + return ret; +} +#endif +A_STATUS +PowerStateChangeNotify(HIF_DEVICE *device, HIF_DEVICE_POWER_CHANGE_TYPE config) +{ + A_STATUS status = A_OK; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) + struct sdio_func *func = device->func; + int old_reset_val; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +PowerStateChangeNotify %d\n", config)); + switch (config) { + case HIF_DEVICE_POWER_DOWN: + /* Disable 4bits in order to let SDIO bus detect DAT1 as interrupt source */ + SdioEnable4bits(device, 0); + break; + case HIF_DEVICE_POWER_CUT: + old_reset_val = reset_sdio_on_unload; + reset_sdio_on_unload = 1; + status = hifDisableFunc(device, func); + reset_sdio_on_unload = old_reset_val; + if (!device->is_suspend) { + device->powerConfig = config; + mmc_detect_change(device->host, HZ/3); + } + break; + case HIF_DEVICE_POWER_UP: + if (device->powerConfig == HIF_DEVICE_POWER_CUT) { + if (device->is_suspend) { + status = ReinitSDIO(device); + if (status == A_OK) { + status = hifEnableFunc(device, func); + } + } else { + /* device->func is bad pointer at this time */ + mmc_detect_change(device->host, 0); + return A_PENDING; /* Don't change powerConfig status */ + } + } else if (device->powerConfig == HIF_DEVICE_POWER_DOWN) { + int ret = SdioEnable4bits(device, 1); + status = (ret==0) ? A_OK : A_ERROR; + } + break; + } + device->powerConfig = config; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -PowerStateChangeNotify\n")); +#endif + return status; +} + +A_STATUS +HIFConfigureDevice(HIF_DEVICE *device, HIF_DEVICE_CONFIG_OPCODE opcode, + void *config, A_UINT32 configLen) +{ + A_UINT32 count; + A_STATUS status = A_OK; + + switch(opcode) { + case HIF_DEVICE_GET_MBOX_BLOCK_SIZE: + ((A_UINT32 *)config)[0] = HIF_MBOX0_BLOCK_SIZE; + ((A_UINT32 *)config)[1] = HIF_MBOX1_BLOCK_SIZE; + ((A_UINT32 *)config)[2] = HIF_MBOX2_BLOCK_SIZE; + ((A_UINT32 *)config)[3] = HIF_MBOX3_BLOCK_SIZE; + break; + + case HIF_DEVICE_GET_MBOX_ADDR: + for (count = 0; count < 4; count ++) { + ((A_UINT32 *)config)[count] = HIF_MBOX_START_ADDR(count); + } + + if (configLen >= sizeof(HIF_DEVICE_MBOX_INFO)) { + SetExtendedMboxWindowInfo((A_UINT16)device->func->device, + (HIF_DEVICE_MBOX_INFO *)config); + } + + break; + case HIF_DEVICE_GET_PENDING_EVENTS_FUNC: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR6000: configuration opcode %d is not used for Linux SDIO stack", opcode)); + status = A_ERROR; + break; + case HIF_DEVICE_GET_IRQ_PROC_MODE: + *((HIF_DEVICE_IRQ_PROCESSING_MODE *)config) = HIF_DEVICE_IRQ_SYNC_ONLY; + break; + case HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR6000: configuration opcode %d is not used for Linux SDIO stack", opcode)); + status = A_ERROR; + break; + case HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT: + if (!device->scatter_enabled) { + return A_ENOTSUP; + } + status = SetupHIFScatterSupport(device, (HIF_DEVICE_SCATTER_SUPPORT_INFO *)config); + if (A_FAILED(status)) { + device->scatter_enabled = FALSE; + } + break; + case HIF_DEVICE_GET_OS_DEVICE: + /* pass back a pointer to the SDIO function's "dev" struct */ + if (device->func) { + ((HIF_DEVICE_OS_DEVICE_INFO *)config)->pOSDevice = &device->func->dev; + } else { + ((HIF_DEVICE_OS_DEVICE_INFO *)config)->pOSDevice = NULL; + status = A_DEVICE_NOT_FOUND; + } + break; + case HIF_DEVICE_POWER_STATE_CHANGE: + status = PowerStateChangeNotify(device, *(HIF_DEVICE_POWER_CHANGE_TYPE *)config); + break; + case HIF_DEVICE_GET_IRQ_YIELD_PARAMS: + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("AR6000: configuration opcode %d is only used for RTOS systems, not Linux systems", opcode)); + status = A_ERROR; + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("AR6000: Unsupported configuration opcode: %d\n", opcode)); + status = A_ERROR; + } + + return status; +} + +void +HIFShutDownDevice(HIF_DEVICE *device) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +HIFShutDownDevice\n")); + if (device != NULL) { + AR_DEBUG_ASSERT(device->powerConfig==HIF_DEVICE_POWER_CUT || device->func != NULL); + } else { + int i; + /* since we are unloading the driver anyways, reset all cards in case the SDIO card + * is externally powered and we are unloading the SDIO stack. This avoids the problem when + * the SDIO stack is reloaded and attempts are made to re-enumerate a card that is already + * enumerated */ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: HIFShutDownDevice, resetting\n")); + ResetAllCards(); + + /* Unregister with bus driver core */ + if (registered) { + registered = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: Unregistering with the bus driver\n")); + sdio_unregister_driver(&ar6k_driver); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: Unregistered\n")); + } + + for (i=0; ifunc == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: Remove pending hif_device %p\n", hif_devices[i])); + delHifDevice(hif_devices[i]); + hif_devices[i] = NULL; + } + } + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -HIFShutDownDevice\n")); +} + +static void +hifIRQHandler(struct sdio_func *func) +{ + A_STATUS status; + HIF_DEVICE *device; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifIRQHandler\n")); + + device = getHifDevice(func); + atomic_set(&device->irqHandling, 1); + /* release the host during ints so we can pick it back up when we process cmds */ + sdio_release_host(device->func); + status = device->htcCallbacks.dsrHandler(device->htcCallbacks.context); + sdio_claim_host(device->func); + atomic_set(&device->irqHandling, 0); + AR_DEBUG_ASSERT(status == A_OK || status == A_ECANCELED); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifIRQHandler\n")); +} + +/* handle HTC startup via thread*/ +static int startup_task(void *param) +{ + HIF_DEVICE *device; + + device = (HIF_DEVICE *)param; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: call HTC from startup_task\n")); + /* start up inform DRV layer */ + if ((osdrvCallbacks.deviceInsertedHandler(osdrvCallbacks.context,device)) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Device rejected\n")); + } + return 0; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) +static int enable_task(void *param) +{ + HIF_DEVICE *device; + device = (HIF_DEVICE *)param; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: call from resume_task\n")); + + /* start up inform DRV layer */ + if (device && + device->claimedContext && + osdrvCallbacks.devicePowerChangeHandler && + osdrvCallbacks.devicePowerChangeHandler(device->claimedContext, HIF_DEVICE_POWER_UP) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Device rejected\n")); + } + + return 0; +} +#endif + +static void hifAssignTargetHeaders(A_UINT16 SDIO_ID) +{ + switch (SDIO_ID) { + case MANUFACTURER_ID_AR6003_BASE: + hif_register_tbl_attach(HIF_TYPE_AR6003); + break; + + case MANUFACTURER_ID_MCKINLEY_BASE: + hif_register_tbl_attach(HIF_TYPE_MCKINLEY); + break; + default: + hif_register_tbl_attach(HIF_TYPE_AR6003); + break; + } +} + +static int hifDeviceInserted(struct sdio_func *func, const struct sdio_device_id *id) +{ + int i; + int ret; + HIF_DEVICE * device = NULL; + int count; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: hifDeviceInserted, Function: 0x%X, Vendor ID: 0x%X, Device ID: 0x%X, block size: 0x%X/0x%X\n", + func->num, func->vendor, func->device, func->max_blksize, func->cur_blksize)); + + for (i=0; ipowerConfig == HIF_DEVICE_POWER_CUT && + hifdevice->host == func->card->host) { + hifdevice->func = func; + hifdevice->powerConfig = HIF_DEVICE_POWER_UP; + sdio_set_drvdata(func, hifdevice); + device = getHifDevice(func); + ret = 0; + break; + } + } + + if (device==NULL) { + addHifDevice(func); + device = getHifDevice(func); + hifAssignTargetHeaders(id->device); + + for (i=0; iid = id; + device->host = func->card->host; + device->is_disabled = TRUE; + + spin_lock_init(&device->lock); + + spin_lock_init(&device->asynclock); + + DL_LIST_INIT(&device->ScatterReqHead); + + if (!nohifscattersupport) { + /* try to allow scatter operation on all instances, + * unless globally overridden */ + device->scatter_enabled = TRUE; + } + + /* Initialize the bus requests to be used later */ + A_MEMZERO(device->busRequest, sizeof(device->busRequest)); + for (count = 0; count < BUS_REQUEST_MAX_NUM; count ++) { + sema_init(&device->busRequest[count].sem_req, 0); + hifFreeBusRequest(device, &device->busRequest[count]); + } + sema_init(&device->sem_async, 0); + } + + ret = hifEnableFunc(device, func); + return (ret == A_OK || ret == A_PENDING) ? 0 : -1; +} + + +void +HIFAckInterrupt(HIF_DEVICE *device) +{ + AR_DEBUG_ASSERT(device != NULL); + + /* Acknowledge our function IRQ */ +} + +void +HIFUnMaskInterrupt(HIF_DEVICE *device) +{ + int ret;; + + AR_DEBUG_ASSERT(device != NULL); + AR_DEBUG_ASSERT(device->func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: HIFUnMaskInterrupt\n")); + + /* Register the IRQ Handler */ + sdio_claim_host(device->func); + ret = sdio_claim_irq(device->func, hifIRQHandler); + sdio_release_host(device->func); + AR_DEBUG_ASSERT(ret == 0); +} + +void HIFMaskInterrupt(HIF_DEVICE *device) +{ + int ret; + AR_DEBUG_ASSERT(device != NULL); + AR_DEBUG_ASSERT(device->func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: HIFMaskInterrupt\n")); + + /* Mask our function IRQ */ + sdio_claim_host(device->func); + while (atomic_read(&device->irqHandling)) { + sdio_release_host(device->func); + schedule_timeout_interruptible(HZ/10); + sdio_claim_host(device->func); + } + ret = sdio_release_irq(device->func); + sdio_release_host(device->func); + if (ret) { + if (ret == -ETIMEDOUT) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("AR6000: Timeout to mask interrupt. Card removed?\n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: Unable to mask interrupt %d\n", ret)); + AR_DEBUG_ASSERT(ret == 0); + } + } +} + +BUS_REQUEST *hifAllocateBusRequest(HIF_DEVICE *device) +{ + BUS_REQUEST *busrequest; + unsigned long flag; + + /* Acquire lock */ + spin_lock_irqsave(&device->lock, flag); + + /* Remove first in list */ + if((busrequest = device->s_busRequestFreeQueue) != NULL) + { + device->s_busRequestFreeQueue = busrequest->next; + } + /* Release lock */ + spin_unlock_irqrestore(&device->lock, flag); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: hifAllocateBusRequest: 0x%p\n", busrequest)); + return busrequest; +} + +void +hifFreeBusRequest(HIF_DEVICE *device, BUS_REQUEST *busrequest) +{ + unsigned long flag; + + AR_DEBUG_ASSERT(busrequest != NULL); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: hifFreeBusRequest: 0x%p\n", busrequest)); + /* Acquire lock */ + spin_lock_irqsave(&device->lock, flag); + + + /* Insert first in list */ + busrequest->next = device->s_busRequestFreeQueue; + busrequest->inusenext = NULL; + device->s_busRequestFreeQueue = busrequest; + + /* Release lock */ + spin_unlock_irqrestore(&device->lock, flag); +} + +static A_STATUS hifDisableFunc(HIF_DEVICE *device, struct sdio_func *func) +{ + int ret; + A_STATUS status = A_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDisableFunc\n")); + device = getHifDevice(func); + if (!IS_ERR(device->async_task)) { + init_completion(&device->async_completion); + device->async_shutdown = 1; + up(&device->sem_async); + wait_for_completion(&device->async_completion); + device->async_task = NULL; + sema_init(&device->sem_async, 0); + } + /* Disable the card */ + sdio_claim_host(device->func); + ret = sdio_disable_func(device->func); + if (ret) { + status = A_ERROR; + } + + if (reset_sdio_on_unload && status == A_OK) { + /* reset the SDIO interface. This is useful in automated testing where the card + * does not need to be removed at the end of the test. It is expected that the user will + * also unload/reload the host controller driver to force the bus driver to re-enumerate the slot */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("AR6000: reseting SDIO card back to uninitialized state \n")); + + /* NOTE : sdio_f0_writeb() cannot be used here, that API only allows access + * to undefined registers in the range of: 0xF0-0xFF */ + + ret = Func0_CMD52WriteByte(device->func->card, SDIO_CCCR_ABORT, (1 << 3)); + if (ret) { + status = A_ERROR; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6000: reset failed : %d \n",ret)); + } + } + + sdio_release_host(device->func); + + if (status == A_OK) { + device->is_disabled = TRUE; + } + CleanupHIFScatterResources(device); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDisableFunc\n")); + + return status; +} + +static A_STATUS hifEnableFunc(HIF_DEVICE *device, struct sdio_func *func) +{ + struct task_struct* pTask; + const char *taskName = NULL; + int (*taskFunc)(void *) = NULL; + int ret = A_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifEnableFunc\n")); + device = getHifDevice(func); + + if (device->is_disabled) { + /* enable the SDIO function */ + sdio_claim_host(func); + + if ((device->id->device & MANUFACTURER_ID_AR6K_BASE_MASK) >= MANUFACTURER_ID_AR6003_BASE) { + /* enable 4-bit ASYNC interrupt on AR6003 or later devices */ + ret = Func0_CMD52WriteByte(func->card, CCCR_SDIO_IRQ_MODE_REG, SDIO_IRQ_MODE_ASYNC_4BIT_IRQ); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6000: failed to enable 4-bit ASYNC IRQ mode %d \n",ret)); + sdio_release_host(func); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: 4-bit ASYNC IRQ mode enabled\n")); + } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + /* give us some time to enable, in ms */ + func->enable_timeout = 100; +#endif + ret = sdio_enable_func(func); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), Unable to enable AR6K: 0x%X\n", + __FUNCTION__, ret)); + sdio_release_host(func); + return A_ERROR; + } + ret = sdio_set_block_size(func, HIF_MBOX_BLOCK_SIZE); + sdio_release_host(func); + if (ret) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), Unable to set block size 0x%x AR6K: 0x%X\n", + __FUNCTION__, HIF_MBOX_BLOCK_SIZE, ret)); + return A_ERROR; + } + device->is_disabled = FALSE; + /* create async I/O thread */ + if (!device->async_task) { + device->async_shutdown = 0; + device->async_task = kthread_create(async_task, + (void *)device, + "AR6K Async"); + if (IS_ERR(device->async_task)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), to create async task\n", __FUNCTION__)); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: start async task\n")); + wake_up_process(device->async_task ); + } + } + + if (!device->claimedContext) { + taskFunc = startup_task; + taskName = "AR6K startup"; + ret = A_OK; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) + } else { + taskFunc = enable_task; + taskName = "AR6K enable"; + ret = A_PENDING; +#endif /* CONFIG_PM */ + } + /* create resume thread */ + pTask = kthread_create(taskFunc, (void *)device, taskName); + if (IS_ERR(pTask)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), to create enabel task\n", __FUNCTION__)); + return A_ERROR; + } + wake_up_process(pTask); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifEnableFunc\n")); + + /* task will call the enable func, indicate pending */ + return ret; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && defined(CONFIG_PM) +static int hifDeviceSuspend(struct device *dev) +{ + struct sdio_func *func=dev_to_sdio_func(dev); + A_STATUS status = A_OK; + HIF_DEVICE *device = getHifDevice(func); + +#if defined(MMC_PM_KEEP_POWER) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) + struct mmc_host *host = NULL; + if (device && device->func) { + host = device->func->card->host; + } +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceSuspend\n")); + if (device && device->claimedContext && osdrvCallbacks.deviceSuspendHandler) { + device->is_suspend = TRUE; /* set true first for PowerStateChangeNotify(..) */ + status = osdrvCallbacks.deviceSuspendHandler(device->claimedContext); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceSuspend\n")); + + switch (status) { + case A_OK: +#if defined(MMC_PM_KEEP_POWER) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) + if (host) { + host->pm_flags &= ~(MMC_PM_KEEP_POWER|MMC_PM_WAKE_SDIO_IRQ); + } +#endif + return 0; + case A_EBUSY: +#if defined(MMC_PM_KEEP_POWER) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) + if (host) { + /* Some controller need to WAKE_SDIO_IRQ in order to wake up by DAT1 */ + host->pm_flags |= (MMC_PM_KEEP_POWER|MMC_PM_WAKE_SDIO_IRQ); + //host->pm_flags &= host->pm_caps; + } + return 0; +#else + return -EBUSY; /* Hack for kernel to support deep sleep and wow */ +#endif + default: + device->is_suspend = FALSE; + return -1; + } +} + +static int hifDeviceResume(struct device *dev) +{ + struct sdio_func *func=dev_to_sdio_func(dev); + A_STATUS status = A_OK; + HIF_DEVICE *device; + + device = getHifDevice(func); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceResume\n")); + if (device && device->claimedContext && osdrvCallbacks.deviceSuspendHandler) { + status = osdrvCallbacks.deviceResumeHandler(device->claimedContext); + device->is_suspend = FALSE; + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceResume\n")); + + return A_SUCCESS(status) ? 0 : status; +} +#endif /* CONFIG_PM */ + +static void hifDeviceRemoved(struct sdio_func *func) +{ + A_STATUS status = A_OK; + HIF_DEVICE *device; + AR_DEBUG_ASSERT(func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceRemoved\n")); + device = getHifDevice(func); + + if (device->powerConfig == HIF_DEVICE_POWER_CUT) { + device->func = NULL; /* func will be free by mmc stack */ + return; /* Just return for cut-off mode */ + } else { + int i; + for (i=0; iclaimedContext != NULL) { + status = osdrvCallbacks.deviceRemovedHandler(device->claimedContext, device); + } + + if (device->is_disabled) { + device->is_disabled = FALSE; + } else { + status = hifDisableFunc(device, func); + } + + delHifDevice(device); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("AR6000: Unable to disable sdio func. Card removed?\n")); + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceRemoved\n")); +} + +/* + * This should be moved to AR6K HTC layer. + */ +A_STATUS hifWaitForPendingRecv(HIF_DEVICE *device) +{ + A_INT32 cnt = 10; + A_UINT8 host_int_status; + A_STATUS status = A_OK; + + do { + while (atomic_read(&device->irqHandling)) { + /* wait until irq handler finished all the jobs */ + schedule_timeout(HZ/10); + } + /* check if there is any pending irq due to force done */ + host_int_status = 0; + status = HIFReadWrite(device, HOST_INT_STATUS_ADDRESS, + (A_UINT8 *)&host_int_status, sizeof(host_int_status), + HIF_RD_SYNC_BYTE_INC, NULL); + host_int_status = A_SUCCESS(status) ? (host_int_status & (1 << 0)) : 0; + if (host_int_status) { + schedule(); /* schedule for next dsrHandler */ + } + } while (host_int_status && --cnt > 0); + + if (host_int_status && cnt == 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("AR6000: %s(), Unable clear up pending IRQ before the system suspended\n", __FUNCTION__)); + } + + return A_OK; +} + + +static HIF_DEVICE * +addHifDevice(struct sdio_func *func) +{ + HIF_DEVICE *hifdevice; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice\n")); + AR_DEBUG_ASSERT(func != NULL); + hifdevice = (HIF_DEVICE *)A_MALLOC(sizeof(HIF_DEVICE)); + AR_DEBUG_ASSERT(hifdevice != NULL); + A_MEMZERO(hifdevice, sizeof(*hifdevice)); +#if HIF_USE_DMA_BOUNCE_BUFFER + hifdevice->dma_buffer = A_MALLOC(HIF_DMA_BUFFER_SIZE); + AR_DEBUG_ASSERT(hifdevice->dma_buffer != NULL); +#endif + hifdevice->func = func; + hifdevice->powerConfig = HIF_DEVICE_POWER_UP; + sdio_set_drvdata(func, hifdevice); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice; 0x%p\n", hifdevice)); + return hifdevice; +} + +static HIF_DEVICE * +getHifDevice(struct sdio_func *func) +{ + AR_DEBUG_ASSERT(func != NULL); + return (HIF_DEVICE *)sdio_get_drvdata(func); +} + +static void +delHifDevice(HIF_DEVICE * device) +{ + AR_DEBUG_ASSERT(device!= NULL); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: delHifDevice; 0x%p\n", device)); + if (device->dma_buffer != NULL) { + A_FREE(device->dma_buffer); + } + A_FREE(device); +} + +static void ResetAllCards(void) +{ +} + +void HIFClaimDevice(HIF_DEVICE *device, void *context) +{ + device->claimedContext = context; +} + +void HIFReleaseDevice(HIF_DEVICE *device) +{ + device->claimedContext = NULL; +} + +A_STATUS HIFAttachHTC(HIF_DEVICE *device, HTC_CALLBACKS *callbacks) +{ + if (device->htcCallbacks.context != NULL) { + /* already in use! */ + return A_ERROR; + } + device->htcCallbacks = *callbacks; + return A_OK; +} + +void HIFDetachHTC(HIF_DEVICE *device) +{ + A_MEMZERO(&device->htcCallbacks,sizeof(device->htcCallbacks)); +} + +#define SDIO_SET_CMD52_ARG(arg,rw,func,raw,address,writedata) \ + (arg) = (((rw) & 1) << 31) | \ + (((func) & 0x7) << 28) | \ + (((raw) & 1) << 27) | \ + (1 << 26) | \ + (((address) & 0x1FFFF) << 9) | \ + (1 << 8) | \ + ((writedata) & 0xFF) + +#define SDIO_SET_CMD52_READ_ARG(arg,func,address) \ + SDIO_SET_CMD52_ARG(arg,0,(func),0,address,0x00) +#define SDIO_SET_CMD52_WRITE_ARG(arg,func,address,value) \ + SDIO_SET_CMD52_ARG(arg,1,(func),0,address,value) + +static int Func0_CMD52WriteByte(struct mmc_card *card, unsigned int address, unsigned char byte) +{ + struct mmc_command ioCmd; + unsigned long arg; + + memset(&ioCmd,0,sizeof(ioCmd)); + SDIO_SET_CMD52_WRITE_ARG(arg,0,address,byte); + ioCmd.opcode = SD_IO_RW_DIRECT; + ioCmd.arg = arg; + ioCmd.flags = MMC_RSP_R5 | MMC_CMD_AC; + + return mmc_wait_for_cmd(card->host, &ioCmd, 0); +} + +static int Func0_CMD52ReadByte(struct mmc_card *card, unsigned int address, unsigned char *byte) +{ + struct mmc_command ioCmd; + unsigned long arg; + A_INT32 err; + + memset(&ioCmd,0,sizeof(ioCmd)); + SDIO_SET_CMD52_READ_ARG(arg,0,address); + ioCmd.opcode = SD_IO_RW_DIRECT; + ioCmd.arg = arg; + ioCmd.flags = MMC_RSP_R5 | MMC_CMD_AC; + + err = mmc_wait_for_cmd(card->host, &ioCmd, 0); + + if ((!err) && (byte)) { + *byte = ioCmd.resp[0] & 0xFF; + } + + return err; +} diff --git a/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif_scatter.c b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif_scatter.c new file mode 100644 index 000000000000..8e755231a35b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/hif/sdio/linux_sdio/src/hif_scatter.c @@ -0,0 +1,393 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HIF scatter implementation +// +// Author(s): ="Atheros" +//============================================================================== + +#include +#include +#include +#include +#include +#include +#include "hif_internal.h" +#define ATH_MODULE_NAME hif +#include "a_debug.h" + +#ifdef HIF_LINUX_MMC_SCATTER_SUPPORT + +#define _CMD53_ARG_READ 0 +#define _CMD53_ARG_WRITE 1 +#define _CMD53_ARG_BLOCK_BASIS 1 +#define _CMD53_ARG_FIXED_ADDRESS 0 +#define _CMD53_ARG_INCR_ADDRESS 1 + +#define SDIO_SET_CMD53_ARG(arg,rw,func,mode,opcode,address,bytes_blocks) \ + (arg) = (((rw) & 1) << 31) | \ + (((func) & 0x7) << 28) | \ + (((mode) & 1) << 27) | \ + (((opcode) & 1) << 26) | \ + (((address) & 0x1FFFF) << 9) | \ + ((bytes_blocks) & 0x1FF) + +static void FreeScatterReq(HIF_DEVICE *device, HIF_SCATTER_REQ *pReq) +{ + unsigned long flag; + + spin_lock_irqsave(&device->lock, flag); + + DL_ListInsertTail(&device->ScatterReqHead, &pReq->ListLink); + + spin_unlock_irqrestore(&device->lock, flag); + +} + +static HIF_SCATTER_REQ *AllocScatterReq(HIF_DEVICE *device) +{ + DL_LIST *pItem; + unsigned long flag; + + spin_lock_irqsave(&device->lock, flag); + + pItem = DL_ListRemoveItemFromHead(&device->ScatterReqHead); + + spin_unlock_irqrestore(&device->lock, flag); + + if (pItem != NULL) { + return A_CONTAINING_STRUCT(pItem, HIF_SCATTER_REQ, ListLink); + } + + return NULL; +} + + /* called by async task to perform the operation synchronously using direct MMC APIs */ +A_STATUS DoHifReadWriteScatter(HIF_DEVICE *device, BUS_REQUEST *busrequest) +{ + int i; + A_UINT8 rw; + A_UINT8 opcode; + struct mmc_request mmcreq; + struct mmc_command cmd; + struct mmc_data data; + HIF_SCATTER_REQ_PRIV *pReqPriv; + HIF_SCATTER_REQ *pReq; + A_STATUS status = A_OK; + struct scatterlist *pSg; + + pReqPriv = busrequest->pScatterReq; + + A_ASSERT(pReqPriv != NULL); + + pReq = pReqPriv->pHifScatterReq; + + memset(&mmcreq, 0, sizeof(struct mmc_request)); + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + data.blksz = HIF_MBOX_BLOCK_SIZE; + data.blocks = pReq->TotalLength / HIF_MBOX_BLOCK_SIZE; + + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER: (%s) Address: 0x%X, (BlockLen: %d, BlockCount: %d) , (tot:%d,sg:%d)\n", + (pReq->Request & HIF_WRITE) ? "WRITE":"READ", pReq->Address, data.blksz, data.blocks, + pReq->TotalLength,pReq->ValidScatterEntries)); + + if (pReq->Request & HIF_WRITE) { + rw = _CMD53_ARG_WRITE; + data.flags = MMC_DATA_WRITE; + } else { + rw = _CMD53_ARG_READ; + data.flags = MMC_DATA_READ; + } + + if (pReq->Request & HIF_FIXED_ADDRESS) { + opcode = _CMD53_ARG_FIXED_ADDRESS; + } else { + opcode = _CMD53_ARG_INCR_ADDRESS; + } + + /* fill SG entries */ + pSg = pReqPriv->sgentries; + sg_init_table(pSg, pReq->ValidScatterEntries); + + /* assemble SG list */ + for (i = 0 ; i < pReq->ValidScatterEntries ; i++, pSg++) { + /* setup each sg entry */ + if ((unsigned long)pReq->ScatterList[i].pBuffer & 0x3) { + /* note some scatter engines can handle unaligned buffers, print this + * as informational only */ + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, + ("HIF: (%s) Scatter Buffer is unaligned 0x%lx\n", + pReq->Request & HIF_WRITE ? "WRITE":"READ", + (unsigned long)pReq->ScatterList[i].pBuffer)); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, (" %d: Addr:0x%lX, Len:%d \n", + i,(unsigned long)pReq->ScatterList[i].pBuffer,pReq->ScatterList[i].Length)); + + sg_set_buf(pSg, pReq->ScatterList[i].pBuffer, pReq->ScatterList[i].Length); + } + /* set scatter-gather table for request */ + data.sg = pReqPriv->sgentries; + data.sg_len = pReq->ValidScatterEntries; + /* set command argument */ + SDIO_SET_CMD53_ARG(cmd.arg, + rw, + device->func->num, + _CMD53_ARG_BLOCK_BASIS, + opcode, + pReq->Address, + data.blocks); + + cmd.opcode = SD_IO_RW_EXTENDED; + cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; + + mmcreq.cmd = &cmd; + mmcreq.data = &data; + + mmc_set_data_timeout(&data, device->func->card); + /* synchronous call to process request */ + mmc_wait_for_req(device->func->card->host, &mmcreq); + + if (cmd.error) { + status = A_ERROR; + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("HIF-SCATTER: cmd error: %d \n",cmd.error)); + } + + if (data.error) { + status = A_ERROR; + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("HIF-SCATTER: data error: %d \n",data.error)); + } + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("HIF-SCATTER: FAILED!!! (%s) Address: 0x%X, Block mode (BlockLen: %d, BlockCount: %d)\n", + (pReq->Request & HIF_WRITE) ? "WRITE":"READ",pReq->Address, data.blksz, data.blocks)); + } + + /* set completion status, fail or success */ + pReq->CompletionStatus = status; + + if (pReq->Request & HIF_ASYNCHRONOUS) { + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER: async_task completion routine req: 0x%lX (%d)\n",(unsigned long)busrequest, status)); + /* complete the request */ + A_ASSERT(pReq->CompletionRoutine != NULL); + pReq->CompletionRoutine(pReq); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER async_task upping busrequest : 0x%lX (%d)\n", (unsigned long)busrequest,status)); + /* signal wait */ + up(&busrequest->sem_req); + } + + return status; +} + + /* callback to issue a read-write scatter request */ +static A_STATUS HifReadWriteScatter(HIF_DEVICE *device, HIF_SCATTER_REQ *pReq) +{ + A_STATUS status = A_EINVAL; + A_UINT32 request = pReq->Request; + HIF_SCATTER_REQ_PRIV *pReqPriv = (HIF_SCATTER_REQ_PRIV *)pReq->HIFPrivate[0]; + + do { + + A_ASSERT(pReqPriv != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER: total len: %d Scatter Entries: %d\n", + pReq->TotalLength, pReq->ValidScatterEntries)); + + if (!(request & HIF_EXTENDED_IO)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("HIF-SCATTER: Invalid command type: 0x%08x\n", request)); + break; + } + + if (!(request & (HIF_SYNCHRONOUS | HIF_ASYNCHRONOUS))) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("HIF-SCATTER: Invalid execution mode: 0x%08x\n", request)); + break; + } + + if (!(request & HIF_BLOCK_BASIS)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("HIF-SCATTER: Invalid data mode: 0x%08x\n", request)); + break; + } + + if (pReq->TotalLength > MAX_SCATTER_REQ_TRANSFER_SIZE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, + ("HIF-SCATTER: Invalid length: %d \n", pReq->TotalLength)); + break; + } + + if (pReq->TotalLength == 0) { + A_ASSERT(FALSE); + break; + } + + /* add bus request to the async list for the async I/O thread to process */ + AddToAsyncList(device, pReqPriv->busrequest); + + if (request & HIF_SYNCHRONOUS) { + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER: queued sync req: 0x%lX\n", (unsigned long)pReqPriv->busrequest)); + /* signal thread and wait */ + up(&device->sem_async); + if (down_interruptible(&pReqPriv->busrequest->sem_req) != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERROR,("HIF-SCATTER: interrupted! \n")); + /* interrupted, exit */ + status = A_ERROR; + break; + } else { + status = pReq->CompletionStatus; + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_SCATTER, ("HIF-SCATTER: queued async req: 0x%lX\n", (unsigned long)pReqPriv->busrequest)); + /* wake thread, it will process and then take care of the async callback */ + up(&device->sem_async); + status = A_OK; + } + + } while (FALSE); + + if (A_FAILED(status) && (request & HIF_ASYNCHRONOUS)) { + pReq->CompletionStatus = status; + pReq->CompletionRoutine(pReq); + status = A_OK; + } + + return status; +} + + /* setup of HIF scatter resources */ +A_STATUS SetupHIFScatterSupport(HIF_DEVICE *device, HIF_DEVICE_SCATTER_SUPPORT_INFO *pInfo) +{ + A_STATUS status = A_ERROR; + int i; + HIF_SCATTER_REQ_PRIV *pReqPriv; + BUS_REQUEST *busrequest; + + do { + + /* check if host supports scatter requests and it meets our requirements */ + if (device->func->card->host->max_hw_segs < MAX_SCATTER_ENTRIES_PER_REQ) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HIF-SCATTER : host only supports scatter of : %d entries, need: %d \n", + device->func->card->host->max_hw_segs, MAX_SCATTER_ENTRIES_PER_REQ)); + status = A_ENOTSUP; + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HIF-SCATTER Enabled: max scatter req : %d entries: %d \n", + MAX_SCATTER_REQUESTS, MAX_SCATTER_ENTRIES_PER_REQ)); + + for (i = 0; i < MAX_SCATTER_REQUESTS; i++) { + /* allocate the private request blob */ + pReqPriv = (HIF_SCATTER_REQ_PRIV *)A_MALLOC(sizeof(HIF_SCATTER_REQ_PRIV)); + if (NULL == pReqPriv) { + break; + } + A_MEMZERO(pReqPriv, sizeof(HIF_SCATTER_REQ_PRIV)); + /* save the device instance*/ + pReqPriv->device = device; + /* allocate the scatter request */ + pReqPriv->pHifScatterReq = (HIF_SCATTER_REQ *)A_MALLOC(sizeof(HIF_SCATTER_REQ) + + (MAX_SCATTER_ENTRIES_PER_REQ - 1) * (sizeof(HIF_SCATTER_ITEM))); + + if (NULL == pReqPriv->pHifScatterReq) { + A_FREE(pReqPriv); + break; + } + /* just zero the main part of the scatter request */ + A_MEMZERO(pReqPriv->pHifScatterReq, sizeof(HIF_SCATTER_REQ)); + /* back pointer to the private struct */ + pReqPriv->pHifScatterReq->HIFPrivate[0] = pReqPriv; + /* allocate a bus request for this scatter request */ + busrequest = hifAllocateBusRequest(device); + if (NULL == busrequest) { + A_FREE(pReqPriv->pHifScatterReq); + A_FREE(pReqPriv); + break; + } + /* assign the scatter request to this bus request */ + busrequest->pScatterReq = pReqPriv; + /* point back to the request */ + pReqPriv->busrequest = busrequest; + /* add it to the scatter pool */ + FreeScatterReq(device,pReqPriv->pHifScatterReq); + } + + if (i != MAX_SCATTER_REQUESTS) { + status = A_NO_MEMORY; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HIF-SCATTER : failed to alloc scatter resources !\n")); + break; + } + + /* set scatter function pointers */ + pInfo->pAllocateReqFunc = AllocScatterReq; + pInfo->pFreeReqFunc = FreeScatterReq; + pInfo->pReadWriteScatterFunc = HifReadWriteScatter; + pInfo->MaxScatterEntries = MAX_SCATTER_ENTRIES_PER_REQ; + pInfo->MaxTransferSizePerScatterReq = MAX_SCATTER_REQ_TRANSFER_SIZE; + + status = A_OK; + + } while (FALSE); + + if (A_FAILED(status)) { + CleanupHIFScatterResources(device); + } + + return status; +} + + /* clean up scatter support */ +void CleanupHIFScatterResources(HIF_DEVICE *device) +{ + HIF_SCATTER_REQ_PRIV *pReqPriv; + HIF_SCATTER_REQ *pReq; + + /* empty the free list */ + + while (1) { + + pReq = AllocScatterReq(device); + + if (NULL == pReq) { + break; + } + + pReqPriv = (HIF_SCATTER_REQ_PRIV *)pReq->HIFPrivate[0]; + A_ASSERT(pReqPriv != NULL); + + if (pReqPriv->busrequest != NULL) { + pReqPriv->busrequest->pScatterReq = NULL; + /* free bus request */ + hifFreeBusRequest(device, pReqPriv->busrequest); + pReqPriv->busrequest = NULL; + } + + if (pReqPriv->pHifScatterReq != NULL) { + A_FREE(pReqPriv->pHifScatterReq); + pReqPriv->pHifScatterReq = NULL; + } + + A_FREE(pReqPriv); + } +} + +#endif // HIF_LINUX_MMC_SCATTER_SUPPORT diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.c b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.c new file mode 100644 index 000000000000..bbddef7a3a53 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.c @@ -0,0 +1,1463 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// AR6K device layer that handles register level I/O +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "../htc_debug.h" +#include "hif.h" +#include "htc_packet.h" +#include "ar6k.h" +#include "target_reg_table.h" +#include "host_reg_table.h" + +#define MAILBOX_FOR_BLOCK_SIZE 1 + +A_STATUS DevEnableInterrupts(AR6K_DEVICE *pDev); +A_STATUS DevDisableInterrupts(AR6K_DEVICE *pDev); + +static void DevCleanupVirtualScatterSupport(AR6K_DEVICE *pDev); + +void AR6KFreeIOPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket) +{ + LOCK_AR6K(pDev); + HTC_PACKET_ENQUEUE(&pDev->RegisterIOList,pPacket); + UNLOCK_AR6K(pDev); +} + +HTC_PACKET *AR6KAllocIOPacket(AR6K_DEVICE *pDev) +{ + HTC_PACKET *pPacket; + + LOCK_AR6K(pDev); + pPacket = HTC_PACKET_DEQUEUE(&pDev->RegisterIOList); + UNLOCK_AR6K(pDev); + + return pPacket; +} + +void DevCleanup(AR6K_DEVICE *pDev) +{ + if (pDev->HifAttached) { + HIFDetachHTC(pDev->HIFDevice); + pDev->HifAttached = FALSE; + } + + DevCleanupVirtualScatterSupport(pDev); + + if (A_IS_MUTEX_VALID(&pDev->Lock)) { + A_MUTEX_DELETE(&pDev->Lock); + } +} + +A_STATUS DevSetup(AR6K_DEVICE *pDev) +{ + A_UINT32 blocksizes[AR6K_MAILBOXES]; + A_STATUS status = A_OK; + int i; + HTC_CALLBACKS htcCallbacks; + + do { + + DL_LIST_INIT(&pDev->ScatterReqHead); + /* initialize our free list of IO packets */ + INIT_HTC_PACKET_QUEUE(&pDev->RegisterIOList); + A_MUTEX_INIT(&pDev->Lock); + + A_MEMZERO(&htcCallbacks, sizeof(HTC_CALLBACKS)); + /* the device layer handles these */ + htcCallbacks.rwCompletionHandler = DevRWCompletionHandler; + htcCallbacks.dsrHandler = DevDsrHandler; + htcCallbacks.context = pDev; + + status = HIFAttachHTC(pDev->HIFDevice, &htcCallbacks); + + if (A_FAILED(status)) { + break; + } + + pDev->HifAttached = TRUE; + + /* get the addresses for all 4 mailboxes */ + status = HIFConfigureDevice(pDev->HIFDevice, HIF_DEVICE_GET_MBOX_ADDR, + &pDev->MailBoxInfo, sizeof(pDev->MailBoxInfo)); + + if (status != A_OK) { + A_ASSERT(FALSE); + break; + } + + /* carve up register I/O packets (these are for ASYNC register I/O ) */ + for (i = 0; i < AR6K_MAX_REG_IO_BUFFERS; i++) { + HTC_PACKET *pIOPacket; + pIOPacket = &pDev->RegIOBuffers[i].HtcPacket; + SET_HTC_PACKET_INFO_RX_REFILL(pIOPacket, + pDev, + pDev->RegIOBuffers[i].Buffer, + AR6K_REG_IO_BUFFER_SIZE, + 0); /* don't care */ + AR6KFreeIOPacket(pDev,pIOPacket); + } + + /* get the block sizes */ + status = HIFConfigureDevice(pDev->HIFDevice, HIF_DEVICE_GET_MBOX_BLOCK_SIZE, + blocksizes, sizeof(blocksizes)); + + if (status != A_OK) { + A_ASSERT(FALSE); + break; + } + + /* note: we actually get the block size of a mailbox other than 0, for SDIO the block + * size on mailbox 0 is artificially set to 1. So we use the block size that is set + * for the other 3 mailboxes */ + pDev->BlockSize = blocksizes[MAILBOX_FOR_BLOCK_SIZE]; + /* must be a power of 2 */ + A_ASSERT((pDev->BlockSize & (pDev->BlockSize - 1)) == 0); + + /* assemble mask, used for padding to a block */ + pDev->BlockMask = pDev->BlockSize - 1; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("BlockSize: %d, MailboxAddress:0x%X \n", + pDev->BlockSize, pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX])); + + pDev->GetPendingEventsFunc = NULL; + /* see if the HIF layer implements the get pending events function */ + HIFConfigureDevice(pDev->HIFDevice, + HIF_DEVICE_GET_PENDING_EVENTS_FUNC, + &pDev->GetPendingEventsFunc, + sizeof(pDev->GetPendingEventsFunc)); + + /* assume we can process HIF interrupt events asynchronously */ + pDev->HifIRQProcessingMode = HIF_DEVICE_IRQ_ASYNC_SYNC; + + /* see if the HIF layer overrides this assumption */ + HIFConfigureDevice(pDev->HIFDevice, + HIF_DEVICE_GET_IRQ_PROC_MODE, + &pDev->HifIRQProcessingMode, + sizeof(pDev->HifIRQProcessingMode)); + + switch (pDev->HifIRQProcessingMode) { + case HIF_DEVICE_IRQ_SYNC_ONLY: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HIF Interrupt processing is SYNC ONLY\n")); + /* see if HIF layer wants HTC to yield */ + HIFConfigureDevice(pDev->HIFDevice, + HIF_DEVICE_GET_IRQ_YIELD_PARAMS, + &pDev->HifIRQYieldParams, + sizeof(pDev->HifIRQYieldParams)); + + if (pDev->HifIRQYieldParams.RecvPacketYieldCount > 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("HIF requests that DSR yield per %d RECV packets \n", + pDev->HifIRQYieldParams.RecvPacketYieldCount)); + pDev->DSRCanYield = TRUE; + } + break; + case HIF_DEVICE_IRQ_ASYNC_SYNC: + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("HIF Interrupt processing is ASYNC and SYNC\n")); + break; + default: + A_ASSERT(FALSE); + } + + pDev->HifMaskUmaskRecvEvent = NULL; + + /* see if the HIF layer implements the mask/unmask recv events function */ + HIFConfigureDevice(pDev->HIFDevice, + HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC, + &pDev->HifMaskUmaskRecvEvent, + sizeof(pDev->HifMaskUmaskRecvEvent)); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("HIF special overrides : 0x%lX , 0x%lX\n", + (unsigned long)pDev->GetPendingEventsFunc, (unsigned long)pDev->HifMaskUmaskRecvEvent)); + + status = DevDisableInterrupts(pDev); + + if (A_FAILED(status)) { + break; + } + + } while (FALSE); + + if (A_FAILED(status)) { + if (pDev->HifAttached) { + HIFDetachHTC(pDev->HIFDevice); + pDev->HifAttached = FALSE; + } + } + + return status; + +} + +A_STATUS DevEnableInterrupts(AR6K_DEVICE *pDev) +{ + A_STATUS status; + AR6K_IRQ_ENABLE_REGISTERS regs; + + LOCK_AR6K(pDev); + + /* Enable all the interrupts except for the internal AR6000 CPU interrupt */ + pDev->IrqEnableRegisters.int_status_enable = INT_STATUS_ENABLE_ERROR_SET(0x01) | + INT_STATUS_ENABLE_CPU_SET(0x01) | + INT_STATUS_ENABLE_COUNTER_SET(0x01); + + if (NULL == pDev->GetPendingEventsFunc) { + pDev->IrqEnableRegisters.int_status_enable |= INT_STATUS_ENABLE_MBOX_DATA_SET(0x01); + } else { + /* The HIF layer provided us with a pending events function which means that + * the detection of pending mbox messages is handled in the HIF layer. + * This is the case for the SPI2 interface. + * In the normal case we enable MBOX interrupts, for the case + * with HIFs that offer this mechanism, we keep these interrupts + * masked */ + pDev->IrqEnableRegisters.int_status_enable &= ~INT_STATUS_ENABLE_MBOX_DATA_SET(0x01); + } + + + /* Set up the CPU Interrupt Status Register */ + pDev->IrqEnableRegisters.cpu_int_status_enable = CPU_INT_STATUS_ENABLE_BIT_SET(0x00); + + /* Set up the Error Interrupt Status Register */ + pDev->IrqEnableRegisters.error_status_enable = + ERROR_STATUS_ENABLE_RX_UNDERFLOW_SET(0x01) | + ERROR_STATUS_ENABLE_TX_OVERFLOW_SET(0x01); + + /* Set up the Counter Interrupt Status Register (only for debug interrupt to catch fatal errors) */ + pDev->IrqEnableRegisters.counter_int_status_enable = + COUNTER_INT_STATUS_ENABLE_BIT_SET(AR6K_TARGET_DEBUG_INTR_MASK); + + /* copy into our temp area */ + A_MEMCPY(®s,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + + UNLOCK_AR6K(pDev); + + /* always synchronous */ + status = HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + ®s.int_status_enable, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + /* Can't write it for some reason */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Failed to update interrupt control registers err: %d\n", status)); + + } + + return status; +} + +A_STATUS DevDisableInterrupts(AR6K_DEVICE *pDev) +{ + AR6K_IRQ_ENABLE_REGISTERS regs; + + LOCK_AR6K(pDev); + /* Disable all interrupts */ + pDev->IrqEnableRegisters.int_status_enable = 0; + pDev->IrqEnableRegisters.cpu_int_status_enable = 0; + pDev->IrqEnableRegisters.error_status_enable = 0; + pDev->IrqEnableRegisters.counter_int_status_enable = 0; + /* copy into our temp area */ + A_MEMCPY(®s,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + + UNLOCK_AR6K(pDev); + + /* always synchronous */ + return HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + ®s.int_status_enable, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_SYNC_BYTE_INC, + NULL); +} + +/* enable device interrupts */ +A_STATUS DevUnmaskInterrupts(AR6K_DEVICE *pDev) +{ + /* for good measure, make sure interrupt are disabled before unmasking at the HIF + * layer. + * The rationale here is that between device insertion (where we clear the interrupts the first time) + * and when HTC is finally ready to handle interrupts, other software can perform target "soft" resets. + * The AR6K interrupt enables reset back to an "enabled" state when this happens. + * */ + DevDisableInterrupts(pDev); + + /* Unmask the host controller interrupts */ + HIFUnMaskInterrupt(pDev->HIFDevice); + + return DevEnableInterrupts(pDev); +} + +/* disable all device interrupts */ +A_STATUS DevMaskInterrupts(AR6K_DEVICE *pDev) +{ + /* mask the interrupt at the HIF layer, we don't want a stray interrupt taken while + * we zero out our shadow registers in DevDisableInterrupts()*/ + HIFMaskInterrupt(pDev->HIFDevice); + + return DevDisableInterrupts(pDev); +} + +/* callback when our fetch to enable/disable completes */ +static void DevDoEnableDisableRecvAsyncHandler(void *Context, HTC_PACKET *pPacket) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevDoEnableDisableRecvAsyncHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" Failed to disable receiver, status:%d \n", pPacket->Status)); + } + /* free this IO packet */ + AR6KFreeIOPacket(pDev,pPacket); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevDoEnableDisableRecvAsyncHandler \n")); +} + +/* disable packet reception (used in case the host runs out of buffers) + * this is the "override" method when the HIF reports another methods to + * disable recv events */ +static A_STATUS DevDoEnableDisableRecvOverride(AR6K_DEVICE *pDev, A_BOOL EnableRecv, A_BOOL AsyncMode) +{ + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket = NULL; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("DevDoEnableDisableRecvOverride: Enable:%d Mode:%d\n", + EnableRecv,AsyncMode)); + + do { + + if (AsyncMode) { + + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevDoEnableDisableRecvAsyncHandler; + pIOPacket->pContext = pDev; + + /* call the HIF layer override and do this asynchronously */ + status = pDev->HifMaskUmaskRecvEvent(pDev->HIFDevice, + EnableRecv ? HIF_UNMASK_RECV : HIF_MASK_RECV, + pIOPacket); + break; + } + + /* if we get here we are doing it synchronously */ + status = pDev->HifMaskUmaskRecvEvent(pDev->HIFDevice, + EnableRecv ? HIF_UNMASK_RECV : HIF_MASK_RECV, + NULL); + + } while (FALSE); + + if (A_FAILED(status) && (pIOPacket != NULL)) { + AR6KFreeIOPacket(pDev,pIOPacket); + } + + return status; +} + +/* disable packet reception (used in case the host runs out of buffers) + * this is the "normal" method using the interrupt enable registers through + * the host I/F */ +static A_STATUS DevDoEnableDisableRecvNormal(AR6K_DEVICE *pDev, A_BOOL EnableRecv, A_BOOL AsyncMode) +{ + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket = NULL; + AR6K_IRQ_ENABLE_REGISTERS regs; + + /* take the lock to protect interrupt enable shadows */ + LOCK_AR6K(pDev); + + if (EnableRecv) { + pDev->IrqEnableRegisters.int_status_enable |= INT_STATUS_ENABLE_MBOX_DATA_SET(0x01); + } else { + pDev->IrqEnableRegisters.int_status_enable &= ~INT_STATUS_ENABLE_MBOX_DATA_SET(0x01); + } + + /* copy into our temp area */ + A_MEMCPY(®s,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + UNLOCK_AR6K(pDev); + + do { + + if (AsyncMode) { + + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + /* copy values to write to our async I/O buffer */ + A_MEMCPY(pIOPacket->pBuffer,®s,AR6K_IRQ_ENABLE_REGS_SIZE); + + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevDoEnableDisableRecvAsyncHandler; + pIOPacket->pContext = pDev; + + /* write it out asynchronously */ + status = HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + pIOPacket->pBuffer, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_ASYNC_BYTE_INC, + pIOPacket); + break; + } + + /* if we get here we are doing it synchronously */ + + status = HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + ®s.int_status_enable, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_SYNC_BYTE_INC, + NULL); + + } while (FALSE); + + if (A_FAILED(status) && (pIOPacket != NULL)) { + AR6KFreeIOPacket(pDev,pIOPacket); + } + + return status; +} + + +A_STATUS DevStopRecv(AR6K_DEVICE *pDev, A_BOOL AsyncMode) +{ + if (NULL == pDev->HifMaskUmaskRecvEvent) { + return DevDoEnableDisableRecvNormal(pDev,FALSE,AsyncMode); + } else { + return DevDoEnableDisableRecvOverride(pDev,FALSE,AsyncMode); + } +} + +A_STATUS DevEnableRecv(AR6K_DEVICE *pDev, A_BOOL AsyncMode) +{ + if (NULL == pDev->HifMaskUmaskRecvEvent) { + return DevDoEnableDisableRecvNormal(pDev,TRUE,AsyncMode); + } else { + return DevDoEnableDisableRecvOverride(pDev,TRUE,AsyncMode); + } +} + +A_STATUS DevWaitForPendingRecv(AR6K_DEVICE *pDev,A_UINT32 TimeoutInMs,A_BOOL *pbIsRecvPending) +{ + A_STATUS status = A_OK; + A_UCHAR host_int_status = 0x0; + A_UINT32 counter = 0x0; + + if(TimeoutInMs < 100) + { + TimeoutInMs = 100; + } + + counter = TimeoutInMs / 100; + + do + { + //Read the Host Interrupt Status Register + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + &host_int_status, + sizeof(A_UCHAR), + HIF_RD_SYNC_BYTE_INC, + NULL); + if(A_FAILED(status)) + { + AR_DEBUG_PRINTF(ATH_LOG_ERR,("DevWaitForPendingRecv:Read HOST_INT_STATUS_ADDRESS Failed 0x%X\n",status)); + break; + } + + host_int_status = A_SUCCESS(status) ? (host_int_status & (1 << 0)):0; + if(!host_int_status) + { + status = A_OK; + *pbIsRecvPending = FALSE; + break; + } + else + { + *pbIsRecvPending = TRUE; + } + + A_MDELAY(100); + + counter--; + + }while(counter); + return status; +} + +void DevDumpRegisters(AR6K_DEVICE *pDev, + AR6K_IRQ_PROC_REGISTERS *pIrqProcRegs, + AR6K_IRQ_ENABLE_REGISTERS *pIrqEnableRegs) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("\n<------- Register Table -------->\n")); + + if (pIrqProcRegs != NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Host Int Status: 0x%x\n",pIrqProcRegs->host_int_status)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("CPU Int Status: 0x%x\n",pIrqProcRegs->cpu_int_status)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Error Int Status: 0x%x\n",pIrqProcRegs->error_int_status)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Counter Int Status: 0x%x\n",pIrqProcRegs->counter_int_status)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Mbox Frame: 0x%x\n",pIrqProcRegs->mbox_frame)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Rx Lookahead Valid: 0x%x\n",pIrqProcRegs->rx_lookahead_valid)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Rx Lookahead 0: 0x%x\n",pIrqProcRegs->rx_lookahead[0])); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Rx Lookahead 1: 0x%x\n",pIrqProcRegs->rx_lookahead[1])); + + if (pDev->MailBoxInfo.GMboxAddress != 0) { + /* if the target supports GMBOX hardware, dump some additional state */ + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("GMBOX Host Int Status 2: 0x%x\n",pIrqProcRegs->host_int_status2)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("GMBOX RX Avail: 0x%x\n",pIrqProcRegs->gmbox_rx_avail)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("GMBOX lookahead alias 0: 0x%x\n",pIrqProcRegs->rx_gmbox_lookahead_alias[0])); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("GMBOX lookahead alias 1: 0x%x\n",pIrqProcRegs->rx_gmbox_lookahead_alias[1])); + } + + } + + if (pIrqEnableRegs != NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Int Status Enable: 0x%x\n",pIrqEnableRegs->int_status_enable)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("Counter Int Status Enable: 0x%x\n",pIrqEnableRegs->counter_int_status_enable)); + } + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("<------------------------------->\n")); +} + + +#define DEV_GET_VIRT_DMA_INFO(p) ((DEV_SCATTER_DMA_VIRTUAL_INFO *)((p)->HIFPrivate[0])) + +static HIF_SCATTER_REQ *DevAllocScatterReq(HIF_DEVICE *Context) +{ + DL_LIST *pItem; + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + LOCK_AR6K(pDev); + pItem = DL_ListRemoveItemFromHead(&pDev->ScatterReqHead); + UNLOCK_AR6K(pDev); + if (pItem != NULL) { + return A_CONTAINING_STRUCT(pItem, HIF_SCATTER_REQ, ListLink); + } + return NULL; +} + +static void DevFreeScatterReq(HIF_DEVICE *Context, HIF_SCATTER_REQ *pReq) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + LOCK_AR6K(pDev); + DL_ListInsertTail(&pDev->ScatterReqHead, &pReq->ListLink); + UNLOCK_AR6K(pDev); +} + +A_STATUS DevCopyScatterListToFromDMABuffer(HIF_SCATTER_REQ *pReq, A_BOOL FromDMA) +{ + A_UINT8 *pDMABuffer = NULL; + int i, remaining; + A_UINT32 length; + + pDMABuffer = pReq->pScatterBounceBuffer; + + if (pDMABuffer == NULL) { + A_ASSERT(FALSE); + return A_EINVAL; + } + + remaining = (int)pReq->TotalLength; + + for (i = 0; i < pReq->ValidScatterEntries; i++) { + + length = min((int)pReq->ScatterList[i].Length, remaining); + + if (length != (int)pReq->ScatterList[i].Length) { + A_ASSERT(FALSE); + /* there is a problem with the scatter list */ + return A_EINVAL; + } + + if (FromDMA) { + /* from DMA buffer */ + A_MEMCPY(pReq->ScatterList[i].pBuffer, pDMABuffer , length); + } else { + /* to DMA buffer */ + A_MEMCPY(pDMABuffer, pReq->ScatterList[i].pBuffer, length); + } + + pDMABuffer += length; + remaining -= length; + } + + return A_OK; +} + +static void DevReadWriteScatterAsyncHandler(void *Context, HTC_PACKET *pPacket) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + HIF_SCATTER_REQ *pReq = (HIF_SCATTER_REQ *)pPacket->pPktContext; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+DevReadWriteScatterAsyncHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + pReq->CompletionStatus = pPacket->Status; + + AR6KFreeIOPacket(pDev,pPacket); + + pReq->CompletionRoutine(pReq); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-DevReadWriteScatterAsyncHandler \n")); +} + +static A_STATUS DevReadWriteScatter(HIF_DEVICE *Context, HIF_SCATTER_REQ *pReq) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket = NULL; + A_UINT32 request = pReq->Request; + + do { + + if (pReq->TotalLength > AR6K_MAX_TRANSFER_SIZE_PER_SCATTER) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Invalid length: %d \n", pReq->TotalLength)); + break; + } + + if (pReq->TotalLength == 0) { + A_ASSERT(FALSE); + break; + } + + if (request & HIF_ASYNCHRONOUS) { + /* use an I/O packet to carry this request */ + pIOPacket = AR6KAllocIOPacket(pDev); + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + break; + } + + /* save the request */ + pIOPacket->pPktContext = pReq; + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevReadWriteScatterAsyncHandler; + pIOPacket->pContext = pDev; + } + + if (request & HIF_WRITE) { + /* in virtual DMA, we are issuing the requests through the legacy HIFReadWrite API + * this API will adjust the address automatically for the last byte to fall on the mailbox + * EOM. */ + + /* if the address is an extended address, we can adjust the address here since the extended + * address will bypass the normal checks in legacy HIF layers */ + if (pReq->Address == pDev->MailBoxInfo.MboxProp[HTC_MAILBOX].ExtendedAddress) { + pReq->Address += pDev->MailBoxInfo.MboxProp[HTC_MAILBOX].ExtendedSize - pReq->TotalLength; + } + } + + /* use legacy readwrite */ + status = HIFReadWrite(pDev->HIFDevice, + pReq->Address, + DEV_GET_VIRT_DMA_INFO(pReq)->pVirtDmaBuffer, + pReq->TotalLength, + request, + (request & HIF_ASYNCHRONOUS) ? pIOPacket : NULL); + + } while (FALSE); + + if ((status != A_PENDING) && A_FAILED(status) && (request & HIF_ASYNCHRONOUS)) { + if (pIOPacket != NULL) { + AR6KFreeIOPacket(pDev,pIOPacket); + } + pReq->CompletionStatus = status; + pReq->CompletionRoutine(pReq); + status = A_OK; + } + + return status; +} + + +static void DevCleanupVirtualScatterSupport(AR6K_DEVICE *pDev) +{ + HIF_SCATTER_REQ *pReq; + + while (1) { + pReq = DevAllocScatterReq((HIF_DEVICE *)pDev); + if (NULL == pReq) { + break; + } + A_FREE(pReq); + } + +} + + /* function to set up virtual scatter support if HIF layer has not implemented the interface */ +static A_STATUS DevSetupVirtualScatterSupport(AR6K_DEVICE *pDev) +{ + A_STATUS status = A_OK; + int bufferSize, sgreqSize; + int i; + DEV_SCATTER_DMA_VIRTUAL_INFO *pVirtualInfo; + HIF_SCATTER_REQ *pReq; + + bufferSize = sizeof(DEV_SCATTER_DMA_VIRTUAL_INFO) + + 2 * (A_GET_CACHE_LINE_BYTES()) + AR6K_MAX_TRANSFER_SIZE_PER_SCATTER; + + sgreqSize = sizeof(HIF_SCATTER_REQ) + + (AR6K_SCATTER_ENTRIES_PER_REQ - 1) * (sizeof(HIF_SCATTER_ITEM)); + + for (i = 0; i < AR6K_SCATTER_REQS; i++) { + /* allocate the scatter request, buffer info and the actual virtual buffer itself */ + pReq = (HIF_SCATTER_REQ *)A_MALLOC_NOWAIT(sgreqSize + bufferSize); + + if (NULL == pReq) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Alloc HIF_SCATTER_REQ fail with NOWAIT func. Try wait version\n", __FUNCTION__)); + pReq = (HIF_SCATTER_REQ *)A_MALLOC(sgreqSize + bufferSize); + } + if (NULL == pReq) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pReq, sgreqSize); + + /* the virtual DMA starts after the scatter request struct */ + pVirtualInfo = (DEV_SCATTER_DMA_VIRTUAL_INFO *)((A_UINT8 *)pReq + sgreqSize); + A_MEMZERO(pVirtualInfo, sizeof(DEV_SCATTER_DMA_VIRTUAL_INFO)); + + pVirtualInfo->pVirtDmaBuffer = &pVirtualInfo->DataArea[0]; + /* align buffer to cache line in case host controller can actually DMA this */ + pVirtualInfo->pVirtDmaBuffer = A_ALIGN_TO_CACHE_LINE(pVirtualInfo->pVirtDmaBuffer); + /* store the structure in the private area */ + pReq->HIFPrivate[0] = pVirtualInfo; + /* we emulate a DMA bounce interface */ + pReq->ScatterMethod = HIF_SCATTER_DMA_BOUNCE; + pReq->pScatterBounceBuffer = pVirtualInfo->pVirtDmaBuffer; + /* free request to the list */ + DevFreeScatterReq((HIF_DEVICE *)pDev,pReq); + } + + if (A_FAILED(status)) { + DevCleanupVirtualScatterSupport(pDev); + } else { + pDev->HifScatterInfo.pAllocateReqFunc = DevAllocScatterReq; + pDev->HifScatterInfo.pFreeReqFunc = DevFreeScatterReq; + pDev->HifScatterInfo.pReadWriteScatterFunc = DevReadWriteScatter; + pDev->HifScatterInfo.MaxScatterEntries = AR6K_SCATTER_ENTRIES_PER_REQ; + pDev->HifScatterInfo.MaxTransferSizePerScatterReq = AR6K_MAX_TRANSFER_SIZE_PER_SCATTER; + pDev->ScatterIsVirtual = TRUE; + } + + return status; +} + +A_STATUS DevCleanupMsgBundling(AR6K_DEVICE *pDev) +{ + A_STATUS status = A_OK; + + if(NULL != pDev) + { + DevCleanupVirtualScatterSupport(pDev); + } + + return status; +} + +A_STATUS DevSetupMsgBundling(AR6K_DEVICE *pDev, int MaxMsgsPerTransfer) +{ + A_STATUS status; + + if (pDev->MailBoxInfo.Flags & HIF_MBOX_FLAG_NO_BUNDLING) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("HIF requires bundling disabled\n")); + return A_ENOTSUP; + } + + status = HIFConfigureDevice(pDev->HIFDevice, + HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT, + &pDev->HifScatterInfo, + sizeof(pDev->HifScatterInfo)); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("AR6K: ** HIF layer does not support scatter requests (%d) \n",status)); + + /* we can try to use a virtual DMA scatter mechanism using legacy HIFReadWrite() */ + status = DevSetupVirtualScatterSupport(pDev); + + if (A_SUCCESS(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR6K: virtual scatter transfers enabled (max scatter items:%d: maxlen:%d) \n", + DEV_GET_MAX_MSG_PER_BUNDLE(pDev), DEV_GET_MAX_BUNDLE_LENGTH(pDev))); + } + + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR6K: HIF layer supports scatter requests (max scatter items:%d: maxlen:%d) \n", + DEV_GET_MAX_MSG_PER_BUNDLE(pDev), DEV_GET_MAX_BUNDLE_LENGTH(pDev))); + } + + if (A_SUCCESS(status)) { + /* for the recv path, the maximum number of bytes per recv bundle is just limited + * by the maximum transfer size at the HIF layer */ + pDev->MaxRecvBundleSize = pDev->HifScatterInfo.MaxTransferSizePerScatterReq; + + /* for the send path, the max transfer size is limited by the existence and size of + * the extended mailbox address range */ + if (pDev->MailBoxInfo.MboxProp[0].ExtendedAddress != 0) { + pDev->MaxSendBundleSize = pDev->MailBoxInfo.MboxProp[0].ExtendedSize; + } else { + /* legacy */ + pDev->MaxSendBundleSize = AR6K_LEGACY_MAX_WRITE_LENGTH; + } + + if (pDev->MaxSendBundleSize > pDev->HifScatterInfo.MaxTransferSizePerScatterReq) { + /* limit send bundle size to what the HIF can support for scatter requests */ + pDev->MaxSendBundleSize = pDev->HifScatterInfo.MaxTransferSizePerScatterReq; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR6K: max recv: %d max send: %d \n", + DEV_GET_MAX_BUNDLE_RECV_LENGTH(pDev), DEV_GET_MAX_BUNDLE_SEND_LENGTH(pDev))); + + } + return status; +} + +A_STATUS DevSubmitScatterRequest(AR6K_DEVICE *pDev, HIF_SCATTER_REQ *pScatterReq, A_BOOL Read, A_BOOL Async) +{ + A_STATUS status; + + if (Read) { + /* read operation */ + pScatterReq->Request = (Async) ? HIF_RD_ASYNC_BLOCK_FIX : HIF_RD_SYNC_BLOCK_FIX; + pScatterReq->Address = pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX]; + A_ASSERT(pScatterReq->TotalLength <= (A_UINT32)DEV_GET_MAX_BUNDLE_RECV_LENGTH(pDev)); + } else { + A_UINT32 mailboxWidth; + + /* write operation */ + pScatterReq->Request = (Async) ? HIF_WR_ASYNC_BLOCK_INC : HIF_WR_SYNC_BLOCK_INC; + A_ASSERT(pScatterReq->TotalLength <= (A_UINT32)DEV_GET_MAX_BUNDLE_SEND_LENGTH(pDev)); + if (pScatterReq->TotalLength > AR6K_LEGACY_MAX_WRITE_LENGTH) { + /* for large writes use the extended address */ + pScatterReq->Address = pDev->MailBoxInfo.MboxProp[HTC_MAILBOX].ExtendedAddress; + mailboxWidth = pDev->MailBoxInfo.MboxProp[HTC_MAILBOX].ExtendedSize; + } else { + pScatterReq->Address = pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX]; + mailboxWidth = AR6K_LEGACY_MAX_WRITE_LENGTH; + } + + if (!pDev->ScatterIsVirtual) { + /* we are passing this scatter list down to the HIF layer' scatter request handler, fixup the address + * so that the last byte falls on the EOM, we do this for those HIFs that support the + * scatter API */ + pScatterReq->Address += (mailboxWidth - pScatterReq->TotalLength); + } + + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV | ATH_DEBUG_SEND, + ("DevSubmitScatterRequest, Entries: %d, Total Length: %d Mbox:0x%X (mode: %s : %s)\n", + pScatterReq->ValidScatterEntries, + pScatterReq->TotalLength, + pScatterReq->Address, + Async ? "ASYNC" : "SYNC", + (Read) ? "RD" : "WR")); + + status = DEV_PREPARE_SCATTER_OPERATION(pScatterReq); + + if (A_FAILED(status)) { + if (Async) { + pScatterReq->CompletionStatus = status; + pScatterReq->CompletionRoutine(pScatterReq); + return A_OK; + } + return status; + } + + status = pDev->HifScatterInfo.pReadWriteScatterFunc(pDev->ScatterIsVirtual ? pDev : pDev->HIFDevice, + pScatterReq); + if (!Async) { + /* in sync mode, we can touch the scatter request */ + pScatterReq->CompletionStatus = status; + DEV_FINISH_SCATTER_OPERATION(pScatterReq); + } else { + if (status == A_PENDING) { + status = A_OK; + } + } + + return status; +} + + +#ifdef MBOXHW_UNIT_TEST + + +/* This is a mailbox hardware unit test that must be called in a schedulable context + * This test is very simple, it will send a list of buffers with a counting pattern + * and the target will invert the data and send the message back + * + * the unit test has the following constraints: + * + * The target has at least 8 buffers of 256 bytes each. The host will send + * the following pattern of buffers in rapid succession : + * + * 1 buffer - 128 bytes + * 1 buffer - 256 bytes + * 1 buffer - 512 bytes + * 1 buffer - 1024 bytes + * + * The host will send the buffers to one mailbox and wait for buffers to be reflected + * back from the same mailbox. The target sends the buffers FIFO order. + * Once the final buffer has been received for a mailbox, the next mailbox is tested. + * + * + * Note: To simplifythe test , we assume that the chosen buffer sizes + * will fall on a nice block pad + * + * It is expected that higher-order tests will be written to stress the mailboxes using + * a message-based protocol (with some performance timming) that can create more + * randomness in the packets sent over mailboxes. + * + * */ + +#define A_ROUND_UP_PWR2(x, align) (((int) (x) + ((align)-1)) & ~((align)-1)) + +#define BUFFER_BLOCK_PAD 128 + +#if 0 +#define BUFFER1 128 +#define BUFFER2 256 +#define BUFFER3 512 +#define BUFFER4 1024 +#endif + +#if 1 +#define BUFFER1 80 +#define BUFFER2 200 +#define BUFFER3 444 +#define BUFFER4 800 +#endif + +#define TOTAL_BYTES (A_ROUND_UP_PWR2(BUFFER1,BUFFER_BLOCK_PAD) + \ + A_ROUND_UP_PWR2(BUFFER2,BUFFER_BLOCK_PAD) + \ + A_ROUND_UP_PWR2(BUFFER3,BUFFER_BLOCK_PAD) + \ + A_ROUND_UP_PWR2(BUFFER4,BUFFER_BLOCK_PAD) ) + +#define TEST_BYTES (BUFFER1 + BUFFER2 + BUFFER3 + BUFFER4) + +#define TEST_CREDITS_RECV_TIMEOUT 100 + +static A_UINT8 g_Buffer[TOTAL_BYTES]; +static A_UINT32 g_MailboxAddrs[AR6K_MAILBOXES]; +static A_UINT32 g_BlockSizes[AR6K_MAILBOXES]; + +#define BUFFER_PROC_LIST_DEPTH 4 + +typedef struct _BUFFER_PROC_LIST{ + A_UINT8 *pBuffer; + A_UINT32 length; +}BUFFER_PROC_LIST; + + +#define PUSH_BUFF_PROC_ENTRY(pList,len,pCurrpos) \ +{ \ + (pList)->pBuffer = (pCurrpos); \ + (pList)->length = (len); \ + (pCurrpos) += (len); \ + (pList)++; \ +} + +/* a simple and crude way to send different "message" sizes */ +static void AssembleBufferList(BUFFER_PROC_LIST *pList) +{ + A_UINT8 *pBuffer = g_Buffer; + +#if BUFFER_PROC_LIST_DEPTH < 4 +#error "Buffer processing list depth is not deep enough!!" +#endif + + PUSH_BUFF_PROC_ENTRY(pList,BUFFER1,pBuffer); + PUSH_BUFF_PROC_ENTRY(pList,BUFFER2,pBuffer); + PUSH_BUFF_PROC_ENTRY(pList,BUFFER3,pBuffer); + PUSH_BUFF_PROC_ENTRY(pList,BUFFER4,pBuffer); + +} + +#define FILL_ZERO TRUE +#define FILL_COUNTING FALSE +static void InitBuffers(A_BOOL Zero) +{ + A_UINT16 *pBuffer16 = (A_UINT16 *)g_Buffer; + int i; + + /* fill buffer with 16 bit counting pattern or zeros */ + for (i = 0; i < (TOTAL_BYTES / 2) ; i++) { + if (!Zero) { + pBuffer16[i] = (A_UINT16)i; + } else { + pBuffer16[i] = 0; + } + } +} + + +static A_BOOL CheckOneBuffer(A_UINT16 *pBuffer16, int Length) +{ + int i; + A_UINT16 startCount; + A_BOOL success = TRUE; + + /* get the starting count */ + startCount = pBuffer16[0]; + /* invert it, this is the expected value */ + startCount = ~startCount; + /* scan the buffer and verify */ + for (i = 0; i < (Length / 2) ; i++,startCount++) { + /* target will invert all the data */ + if ((A_UINT16)pBuffer16[i] != (A_UINT16)~startCount) { + success = FALSE; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Invalid Data Got:0x%X, Expecting:0x%X (offset:%d, total:%d) \n", + pBuffer16[i], ((A_UINT16)~startCount), i, Length)); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("0x%X 0x%X 0x%X 0x%X \n", + pBuffer16[i], pBuffer16[i + 1], pBuffer16[i + 2],pBuffer16[i+3])); + break; + } + } + + return success; +} + +static A_BOOL CheckBuffers(void) +{ + int i; + A_BOOL success = TRUE; + BUFFER_PROC_LIST checkList[BUFFER_PROC_LIST_DEPTH]; + + /* assemble the list */ + AssembleBufferList(checkList); + + /* scan the buffers and verify */ + for (i = 0; i < BUFFER_PROC_LIST_DEPTH ; i++) { + success = CheckOneBuffer((A_UINT16 *)checkList[i].pBuffer, checkList[i].length); + if (!success) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Buffer : 0x%X, Length:%d failed verify \n", + (A_UINT32)checkList[i].pBuffer, checkList[i].length)); + break; + } + } + + return success; +} + + /* find the end marker for the last buffer we will be sending */ +static A_UINT16 GetEndMarker(void) +{ + A_UINT8 *pBuffer; + BUFFER_PROC_LIST checkList[BUFFER_PROC_LIST_DEPTH]; + + /* fill up buffers with the normal counting pattern */ + InitBuffers(FILL_COUNTING); + + /* assemble the list we will be sending down */ + AssembleBufferList(checkList); + /* point to the last 2 bytes of the last buffer */ + pBuffer = &(checkList[BUFFER_PROC_LIST_DEPTH - 1].pBuffer[(checkList[BUFFER_PROC_LIST_DEPTH - 1].length) - 2]); + + /* the last count in the last buffer is the marker */ + return (A_UINT16)pBuffer[0] | ((A_UINT16)pBuffer[1] << 8); +} + +#define ATH_PRINT_OUT_ZONE ATH_DEBUG_ERR + +/* send the ordered buffers to the target */ +static A_STATUS SendBuffers(AR6K_DEVICE *pDev, int mbox) +{ + A_STATUS status = A_OK; + A_UINT32 request = HIF_WR_SYNC_BLOCK_INC; + BUFFER_PROC_LIST sendList[BUFFER_PROC_LIST_DEPTH]; + int i; + int totalBytes = 0; + int paddedLength; + int totalwPadding = 0; + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Sending buffers on mailbox : %d \n",mbox)); + + /* fill buffer with counting pattern */ + InitBuffers(FILL_COUNTING); + + /* assemble the order in which we send */ + AssembleBufferList(sendList); + + for (i = 0; i < BUFFER_PROC_LIST_DEPTH; i++) { + + /* we are doing block transfers, so we need to pad everything to a block size */ + paddedLength = (sendList[i].length + (g_BlockSizes[mbox] - 1)) & + (~(g_BlockSizes[mbox] - 1)); + + /* send each buffer synchronously */ + status = HIFReadWrite(pDev->HIFDevice, + g_MailboxAddrs[mbox], + sendList[i].pBuffer, + paddedLength, + request, + NULL); + if (status != A_OK) { + break; + } + totalBytes += sendList[i].length; + totalwPadding += paddedLength; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Sent %d bytes (%d padded bytes) to mailbox : %d \n",totalBytes,totalwPadding,mbox)); + + return status; +} + +/* poll the mailbox credit counter until we get a credit or timeout */ +static A_STATUS GetCredits(AR6K_DEVICE *pDev, int mbox, int *pCredits) +{ + A_STATUS status = A_OK; + int timeout = TEST_CREDITS_RECV_TIMEOUT; + A_UINT8 credits = 0; + A_UINT32 address; + + while (TRUE) { + + /* Read the counter register to get credits, this auto-decrements */ + address = COUNT_DEC_ADDRESS + (AR6K_MAILBOXES + mbox) * 4; + status = HIFReadWrite(pDev->HIFDevice, address, &credits, sizeof(credits), + HIF_RD_SYNC_BYTE_FIX, NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Unable to decrement the command credit count register (mbox=%d)\n",mbox)); + status = A_ERROR; + break; + } + + if (credits) { + break; + } + + timeout--; + + if (timeout <= 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" Timeout reading credit registers (mbox=%d, address:0x%X) \n",mbox,address)); + status = A_ERROR; + break; + } + + /* delay a little, target may not be ready */ + A_MDELAY(1000); + + } + + if (status == A_OK) { + *pCredits = credits; + } + + return status; +} + + +/* wait for the buffers to come back */ +static A_STATUS RecvBuffers(AR6K_DEVICE *pDev, int mbox) +{ + A_STATUS status = A_OK; + A_UINT32 request = HIF_RD_SYNC_BLOCK_INC; + BUFFER_PROC_LIST recvList[BUFFER_PROC_LIST_DEPTH]; + int curBuffer; + int credits; + int i; + int totalBytes = 0; + int paddedLength; + int totalwPadding = 0; + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Waiting for buffers on mailbox : %d \n",mbox)); + + /* zero the buffers */ + InitBuffers(FILL_ZERO); + + /* assemble the order in which we should receive */ + AssembleBufferList(recvList); + + curBuffer = 0; + + while (curBuffer < BUFFER_PROC_LIST_DEPTH) { + + /* get number of buffers that have been completed, this blocks + * until we get at least 1 credit or it times out */ + status = GetCredits(pDev, mbox, &credits); + + if (status != A_OK) { + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Got %d messages on mailbox : %d \n",credits, mbox)); + + /* get all the buffers that are sitting on the queue */ + for (i = 0; i < credits; i++) { + A_ASSERT(curBuffer < BUFFER_PROC_LIST_DEPTH); + /* recv the current buffer synchronously, the buffers should come back in + * order... with padding applied by the target */ + paddedLength = (recvList[curBuffer].length + (g_BlockSizes[mbox] - 1)) & + (~(g_BlockSizes[mbox] - 1)); + + status = HIFReadWrite(pDev->HIFDevice, + g_MailboxAddrs[mbox], + recvList[curBuffer].pBuffer, + paddedLength, + request, + NULL); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to read %d bytes on mailbox:%d : address:0x%X \n", + recvList[curBuffer].length, mbox, g_MailboxAddrs[mbox])); + break; + } + + totalwPadding += paddedLength; + totalBytes += recvList[curBuffer].length; + curBuffer++; + } + + if (status != A_OK) { + break; + } + /* go back and get some more */ + credits = 0; + } + + if (totalBytes != TEST_BYTES) { + A_ASSERT(FALSE); + } else { + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Got all buffers on mbox:%d total recv :%d (w/Padding : %d) \n", + mbox, totalBytes, totalwPadding)); + } + + return status; + + +} + +static A_STATUS DoOneMboxHWTest(AR6K_DEVICE *pDev, int mbox) +{ + A_STATUS status; + + do { + /* send out buffers */ + status = SendBuffers(pDev,mbox); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Sending buffers Failed : %d mbox:%d\n",status,mbox)); + break; + } + + /* go get them, this will block */ + status = RecvBuffers(pDev, mbox); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Recv buffers Failed : %d mbox:%d\n",status,mbox)); + break; + } + + /* check the returned data patterns */ + if (!CheckBuffers()) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Buffer Verify Failed : mbox:%d\n",mbox)); + status = A_ERROR; + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, (" Send/Recv success! mailbox : %d \n",mbox)); + + } while (FALSE); + + return status; +} + +/* here is where the test starts */ +A_STATUS DoMboxHWTest(AR6K_DEVICE *pDev) +{ + int i; + A_STATUS status; + int credits = 0; + A_UINT8 params[4]; + int numBufs; + int bufferSize; + A_UINT16 temp; + + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, (" DoMboxHWTest START - \n")); + + do { + /* get the addresses for all 4 mailboxes */ + status = HIFConfigureDevice(pDev->HIFDevice, HIF_DEVICE_GET_MBOX_ADDR, + g_MailboxAddrs, sizeof(g_MailboxAddrs)); + + if (status != A_OK) { + A_ASSERT(FALSE); + break; + } + + /* get the block sizes */ + status = HIFConfigureDevice(pDev->HIFDevice, HIF_DEVICE_GET_MBOX_BLOCK_SIZE, + g_BlockSizes, sizeof(g_BlockSizes)); + + if (status != A_OK) { + A_ASSERT(FALSE); + break; + } + + /* note, the HIF layer usually reports mbox 0 to have a block size of + * 1, but our test wants to run in block-mode for all mailboxes, so we treat all mailboxes + * the same. */ + g_BlockSizes[0] = g_BlockSizes[1]; + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Block Size to use: %d \n",g_BlockSizes[0])); + + if (g_BlockSizes[1] > BUFFER_BLOCK_PAD) { + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("%d Block size is too large for buffer pad %d\n", + g_BlockSizes[1], BUFFER_BLOCK_PAD)); + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Waiting for target.... \n")); + + /* the target lets us know it is ready by giving us 1 credit on + * mailbox 0 */ + status = GetCredits(pDev, 0, &credits); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to wait for target ready \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Target is ready ...\n")); + + /* read the first 4 scratch registers */ + status = HIFReadWrite(pDev->HIFDevice, + SCRATCH_ADDRESS, + params, + 4, + HIF_RD_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to wait get parameters \n")); + break; + } + + numBufs = params[0]; + bufferSize = (int)(((A_UINT16)params[2] << 8) | (A_UINT16)params[1]); + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, + ("Target parameters: bufs per mailbox:%d, buffer size:%d bytes (total space: %d, minimum required space (w/padding): %d) \n", + numBufs, bufferSize, (numBufs * bufferSize), TOTAL_BYTES)); + + if ((numBufs * bufferSize) < TOTAL_BYTES) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Not Enough buffer space to run test! need:%d, got:%d \n", + TOTAL_BYTES, (numBufs*bufferSize))); + status = A_ERROR; + break; + } + + temp = GetEndMarker(); + + status = HIFReadWrite(pDev->HIFDevice, + SCRATCH_ADDRESS + 4, + (A_UINT8 *)&temp, + 2, + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to write end marker \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("End Marker: 0x%X \n",temp)); + + temp = (A_UINT16)g_BlockSizes[1]; + /* convert to a mask */ + temp = temp - 1; + status = HIFReadWrite(pDev->HIFDevice, + SCRATCH_ADDRESS + 6, + (A_UINT8 *)&temp, + 2, + HIF_WR_SYNC_BYTE_INC, + NULL); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to write block mask \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, ("Set Block Mask: 0x%X \n",temp)); + + /* execute the test on each mailbox */ + for (i = 0; i < AR6K_MAILBOXES; i++) { + status = DoOneMboxHWTest(pDev, i); + if (status != A_OK) { + break; + } + } + + } while (FALSE); + + if (status == A_OK) { + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, (" DoMboxHWTest DONE - SUCCESS! - \n")); + } else { + AR_DEBUG_PRINTF(ATH_PRINT_OUT_ZONE, (" DoMboxHWTest DONE - FAILED! - \n")); + } + /* don't let HTC_Start continue, the target is actually not running any HTC code */ + return A_ERROR; +} +#endif + + + diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.h b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.h new file mode 100644 index 000000000000..a5a3c984554e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k.h @@ -0,0 +1,399 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// AR6K device layer that handles register level I/O +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef AR6K_H_ +#define AR6K_H_ + +#include "hci_transport_api.h" +#include "../htc_debug.h" + +#define AR6K_MAILBOXES 4 + +/* HTC runs over mailbox 0 */ +#define HTC_MAILBOX 0 + +#define AR6K_TARGET_DEBUG_INTR_MASK 0x01 + +#define OTHER_INTS_ENABLED (INT_STATUS_ENABLE_ERROR_MASK | \ + INT_STATUS_ENABLE_CPU_MASK | \ + INT_STATUS_ENABLE_COUNTER_MASK) + + +//#define MBOXHW_UNIT_TEST 1 + +#include "athstartpack.h" +typedef PREPACK struct _AR6K_IRQ_PROC_REGISTERS { + A_UINT8 host_int_status; + A_UINT8 cpu_int_status; + A_UINT8 error_int_status; + A_UINT8 counter_int_status; + A_UINT8 mbox_frame; + A_UINT8 rx_lookahead_valid; + A_UINT8 host_int_status2; + A_UINT8 gmbox_rx_avail; + A_UINT32 rx_lookahead[2]; + A_UINT32 rx_gmbox_lookahead_alias[2]; +} POSTPACK AR6K_IRQ_PROC_REGISTERS; + +#define AR6K_IRQ_PROC_REGS_SIZE sizeof(AR6K_IRQ_PROC_REGISTERS) + +typedef PREPACK struct _AR6K_IRQ_ENABLE_REGISTERS { + A_UINT8 int_status_enable; + A_UINT8 cpu_int_status_enable; + A_UINT8 error_status_enable; + A_UINT8 counter_int_status_enable; +} POSTPACK AR6K_IRQ_ENABLE_REGISTERS; + +typedef PREPACK struct _AR6K_GMBOX_CTRL_REGISTERS { + A_UINT8 int_status_enable; +} POSTPACK AR6K_GMBOX_CTRL_REGISTERS; + +#include "athendpack.h" + +#define AR6K_IRQ_ENABLE_REGS_SIZE sizeof(AR6K_IRQ_ENABLE_REGISTERS) + +#define AR6K_REG_IO_BUFFER_SIZE 32 +#define AR6K_MAX_REG_IO_BUFFERS 8 +#define FROM_DMA_BUFFER TRUE +#define TO_DMA_BUFFER FALSE +#define AR6K_SCATTER_ENTRIES_PER_REQ 16 +#define AR6K_MAX_TRANSFER_SIZE_PER_SCATTER 16*1024 +#define AR6K_SCATTER_REQS 4 +#define AR6K_LEGACY_MAX_WRITE_LENGTH 2048 + +#ifndef A_CACHE_LINE_PAD +#define A_CACHE_LINE_PAD 128 +#endif + +/* buffers for ASYNC I/O */ +typedef struct AR6K_ASYNC_REG_IO_BUFFER { + HTC_PACKET HtcPacket; /* we use an HTC packet as a wrapper for our async register-based I/O */ + A_UINT8 _Pad1[A_CACHE_LINE_PAD]; + A_UINT8 Buffer[AR6K_REG_IO_BUFFER_SIZE]; /* cache-line safe with pads around */ + A_UINT8 _Pad2[A_CACHE_LINE_PAD]; +} AR6K_ASYNC_REG_IO_BUFFER; + +typedef struct _AR6K_GMBOX_INFO { + void *pProtocolContext; + A_STATUS (*pMessagePendingCallBack)(void *pContext, A_UINT8 LookAheadBytes[], int ValidBytes); + A_STATUS (*pCreditsPendingCallback)(void *pContext, int NumCredits, A_BOOL CreditIRQEnabled); + void (*pTargetFailureCallback)(void *pContext, A_STATUS Status); + void (*pStateDumpCallback)(void *pContext); + A_BOOL CreditCountIRQEnabled; +} AR6K_GMBOX_INFO; + +typedef struct _AR6K_DEVICE { + A_MUTEX_T Lock; + A_UINT8 _Pad1[A_CACHE_LINE_PAD]; + AR6K_IRQ_PROC_REGISTERS IrqProcRegisters; /* cache-line safe with pads around */ + A_UINT8 _Pad2[A_CACHE_LINE_PAD]; + AR6K_IRQ_ENABLE_REGISTERS IrqEnableRegisters; /* cache-line safe with pads around */ + A_UINT8 _Pad3[A_CACHE_LINE_PAD]; + void *HIFDevice; + A_UINT32 BlockSize; + A_UINT32 BlockMask; + HIF_DEVICE_MBOX_INFO MailBoxInfo; + HIF_PENDING_EVENTS_FUNC GetPendingEventsFunc; + void *HTCContext; + HTC_PACKET_QUEUE RegisterIOList; + AR6K_ASYNC_REG_IO_BUFFER RegIOBuffers[AR6K_MAX_REG_IO_BUFFERS]; + void (*TargetFailureCallback)(void *Context); + A_STATUS (*MessagePendingCallback)(void *Context, + A_UINT32 LookAheads[], + int NumLookAheads, + A_BOOL *pAsyncProc, + int *pNumPktsFetched); + HIF_DEVICE_IRQ_PROCESSING_MODE HifIRQProcessingMode; + HIF_MASK_UNMASK_RECV_EVENT HifMaskUmaskRecvEvent; + A_BOOL HifAttached; + HIF_DEVICE_IRQ_YIELD_PARAMS HifIRQYieldParams; + A_BOOL DSRCanYield; + int CurrentDSRRecvCount; + HIF_DEVICE_SCATTER_SUPPORT_INFO HifScatterInfo; + DL_LIST ScatterReqHead; + A_BOOL ScatterIsVirtual; + int MaxRecvBundleSize; + int MaxSendBundleSize; + AR6K_GMBOX_INFO GMboxInfo; + A_BOOL GMboxEnabled; + AR6K_GMBOX_CTRL_REGISTERS GMboxControlRegisters; + int RecheckIRQStatusCnt; +} AR6K_DEVICE; + +#define LOCK_AR6K(p) A_MUTEX_LOCK(&(p)->Lock); +#define UNLOCK_AR6K(p) A_MUTEX_UNLOCK(&(p)->Lock); +#define REF_IRQ_STATUS_RECHECK(p) (p)->RecheckIRQStatusCnt = 1 /* note: no need to lock this, it only gets set */ + +A_STATUS DevSetup(AR6K_DEVICE *pDev); +void DevCleanup(AR6K_DEVICE *pDev); +A_STATUS DevUnmaskInterrupts(AR6K_DEVICE *pDev); +A_STATUS DevMaskInterrupts(AR6K_DEVICE *pDev); +A_STATUS DevPollMboxMsgRecv(AR6K_DEVICE *pDev, + A_UINT32 *pLookAhead, + int TimeoutMS); +A_STATUS DevRWCompletionHandler(void *context, A_STATUS status); +A_STATUS DevDsrHandler(void *context); +A_STATUS DevCheckPendingRecvMsgsAsync(void *context); +void DevAsyncIrqProcessComplete(AR6K_DEVICE *pDev); +void DevDumpRegisters(AR6K_DEVICE *pDev, + AR6K_IRQ_PROC_REGISTERS *pIrqProcRegs, + AR6K_IRQ_ENABLE_REGISTERS *pIrqEnableRegs); + +#define DEV_STOP_RECV_ASYNC TRUE +#define DEV_STOP_RECV_SYNC FALSE +#define DEV_ENABLE_RECV_ASYNC TRUE +#define DEV_ENABLE_RECV_SYNC FALSE +A_STATUS DevStopRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode); +A_STATUS DevEnableRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode); +A_STATUS DevEnableInterrupts(AR6K_DEVICE *pDev); +A_STATUS DevDisableInterrupts(AR6K_DEVICE *pDev); +A_STATUS DevWaitForPendingRecv(AR6K_DEVICE *pDev,A_UINT32 TimeoutInMs,A_BOOL *pbIsRecvPending); + +#define DEV_CALC_RECV_PADDED_LEN(pDev, length) (((length) + (pDev)->BlockMask) & (~((pDev)->BlockMask))) +#define DEV_CALC_SEND_PADDED_LEN(pDev, length) DEV_CALC_RECV_PADDED_LEN(pDev,length) +#define DEV_IS_LEN_BLOCK_ALIGNED(pDev, length) (((length) % (pDev)->BlockSize) == 0) + +static INLINE A_STATUS DevSendPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 SendLength) { + A_UINT32 paddedLength; + A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE; + A_STATUS status; + + /* adjust the length to be a multiple of block size if appropriate */ + paddedLength = DEV_CALC_SEND_PADDED_LEN(pDev, SendLength); + +#if 0 + if (paddedLength > pPacket->BufferLength) { + A_ASSERT(FALSE); + if (pPacket->Completion != NULL) { + COMPLETE_HTC_PACKET(pPacket,A_EINVAL); + return A_OK; + } + return A_EINVAL; + } +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + ("DevSendPacket, Padded Length: %d Mbox:0x%X (mode:%s)\n", + paddedLength, + pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX], + sync ? "SYNC" : "ASYNC")); + + status = HIFReadWrite(pDev->HIFDevice, + pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX], + pPacket->pBuffer, + paddedLength, /* the padded length */ + sync ? HIF_WR_SYNC_BLOCK_INC : HIF_WR_ASYNC_BLOCK_INC, + sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */ + + if (sync) { + pPacket->Status = status; + } else { + if (status == A_PENDING) { + status = A_OK; + } + } + + return status; +} + +static INLINE A_STATUS DevRecvPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 RecvLength) { + A_UINT32 paddedLength; + A_STATUS status; + A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE; + + /* adjust the length to be a multiple of block size if appropriate */ + paddedLength = DEV_CALC_RECV_PADDED_LEN(pDev, RecvLength); + + if (paddedLength > pPacket->BufferLength) { + A_ASSERT(FALSE); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("DevRecvPacket, Not enough space for padlen:%d recvlen:%d bufferlen:%d \n", + paddedLength,RecvLength,pPacket->BufferLength)); + if (pPacket->Completion != NULL) { + COMPLETE_HTC_PACKET(pPacket,A_EINVAL); + return A_OK; + } + return A_EINVAL; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("DevRecvPacket (0x%lX : hdr:0x%X) Padded Length: %d Mbox:0x%X (mode:%s)\n", + (unsigned long)pPacket, pPacket->PktInfo.AsRx.ExpectedHdr, + paddedLength, + pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX], + sync ? "SYNC" : "ASYNC")); + + status = HIFReadWrite(pDev->HIFDevice, + pDev->MailBoxInfo.MboxAddresses[HTC_MAILBOX], + pPacket->pBuffer, + paddedLength, + sync ? HIF_RD_SYNC_BLOCK_FIX : HIF_RD_ASYNC_BLOCK_FIX, + sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */ + + if (sync) { + pPacket->Status = status; + } + + return status; +} + +#define DEV_CHECK_RECV_YIELD(pDev) \ + ((pDev)->CurrentDSRRecvCount >= (pDev)->HifIRQYieldParams.RecvPacketYieldCount) + +#define IS_DEV_IRQ_PROC_SYNC_MODE(pDev) (HIF_DEVICE_IRQ_SYNC_ONLY == (pDev)->HifIRQProcessingMode) +#define IS_DEV_IRQ_PROCESSING_ASYNC_ALLOWED(pDev) ((pDev)->HifIRQProcessingMode != HIF_DEVICE_IRQ_SYNC_ONLY) + +/**************************************************/ +/****** Scatter Function and Definitions + * + * + */ + +A_STATUS DevCopyScatterListToFromDMABuffer(HIF_SCATTER_REQ *pReq, A_BOOL FromDMA); + + /* copy any READ data back into scatter list */ +#define DEV_FINISH_SCATTER_OPERATION(pR) \ + if (A_SUCCESS((pR)->CompletionStatus) && \ + !((pR)->Request & HIF_WRITE) && \ + ((pR)->ScatterMethod == HIF_SCATTER_DMA_BOUNCE)) { \ + (pR)->CompletionStatus = DevCopyScatterListToFromDMABuffer((pR),FROM_DMA_BUFFER); \ + } + + /* copy any WRITE data to bounce buffer */ +static INLINE A_STATUS DEV_PREPARE_SCATTER_OPERATION(HIF_SCATTER_REQ *pReq) { + if ((pReq->Request & HIF_WRITE) && (pReq->ScatterMethod == HIF_SCATTER_DMA_BOUNCE)) { + return DevCopyScatterListToFromDMABuffer(pReq,TO_DMA_BUFFER); + } else { + return A_OK; + } +} + + +A_STATUS DevSetupMsgBundling(AR6K_DEVICE *pDev, int MaxMsgsPerTransfer); + +A_STATUS DevCleanupMsgBundling(AR6K_DEVICE *pDev); + + +#define DEV_GET_MAX_MSG_PER_BUNDLE(pDev) (pDev)->HifScatterInfo.MaxScatterEntries +#define DEV_GET_MAX_BUNDLE_LENGTH(pDev) (pDev)->HifScatterInfo.MaxTransferSizePerScatterReq +#define DEV_ALLOC_SCATTER_REQ(pDev) \ + (pDev)->HifScatterInfo.pAllocateReqFunc((pDev)->ScatterIsVirtual ? (pDev) : (pDev)->HIFDevice) + +#define DEV_FREE_SCATTER_REQ(pDev,pR) \ + (pDev)->HifScatterInfo.pFreeReqFunc((pDev)->ScatterIsVirtual ? (pDev) : (pDev)->HIFDevice,(pR)) + +#define DEV_GET_MAX_BUNDLE_RECV_LENGTH(pDev) (pDev)->MaxRecvBundleSize +#define DEV_GET_MAX_BUNDLE_SEND_LENGTH(pDev) (pDev)->MaxSendBundleSize + +#define DEV_SCATTER_READ TRUE +#define DEV_SCATTER_WRITE FALSE +#define DEV_SCATTER_ASYNC TRUE +#define DEV_SCATTER_SYNC FALSE +A_STATUS DevSubmitScatterRequest(AR6K_DEVICE *pDev, HIF_SCATTER_REQ *pScatterReq, A_BOOL Read, A_BOOL Async); + +#ifdef MBOXHW_UNIT_TEST +A_STATUS DoMboxHWTest(AR6K_DEVICE *pDev); +#endif + + /* completely virtual */ +typedef struct _DEV_SCATTER_DMA_VIRTUAL_INFO { + A_UINT8 *pVirtDmaBuffer; /* dma-able buffer - CPU accessible address */ + A_UINT8 DataArea[1]; /* start of data area */ +} DEV_SCATTER_DMA_VIRTUAL_INFO; + + + +void DumpAR6KDevState(AR6K_DEVICE *pDev); + +/**************************************************/ +/****** GMBOX functions and definitions + * + * + */ + +#ifdef ATH_AR6K_ENABLE_GMBOX + +void DevCleanupGMbox(AR6K_DEVICE *pDev); +A_STATUS DevSetupGMbox(AR6K_DEVICE *pDev); +A_STATUS DevCheckGMboxInterrupts(AR6K_DEVICE *pDev); +void DevNotifyGMboxTargetFailure(AR6K_DEVICE *pDev); + +#else + + /* compiled out */ +#define DevCleanupGMbox(p) +#define DevCheckGMboxInterrupts(p) A_OK +#define DevNotifyGMboxTargetFailure(p) + +static INLINE A_STATUS DevSetupGMbox(AR6K_DEVICE *pDev) { + pDev->GMboxEnabled = FALSE; + return A_OK; +} + +#endif + +#ifdef ATH_AR6K_ENABLE_GMBOX + + /* GMBOX protocol modules must expose each of these internal APIs */ +HCI_TRANSPORT_HANDLE GMboxAttachProtocol(AR6K_DEVICE *pDev, HCI_TRANSPORT_CONFIG_INFO *pInfo); +A_STATUS GMboxProtocolInstall(AR6K_DEVICE *pDev); +void GMboxProtocolUninstall(AR6K_DEVICE *pDev); + + /* API used by GMBOX protocol modules */ +AR6K_DEVICE *HTCGetAR6KDevice(void *HTCHandle); +#define DEV_GMBOX_SET_PROTOCOL(pDev,recv_callback,credits_pending,failure,statedump,context) \ +{ \ + (pDev)->GMboxInfo.pProtocolContext = (context); \ + (pDev)->GMboxInfo.pMessagePendingCallBack = (recv_callback); \ + (pDev)->GMboxInfo.pCreditsPendingCallback = (credits_pending); \ + (pDev)->GMboxInfo.pTargetFailureCallback = (failure); \ + (pDev)->GMboxInfo.pStateDumpCallback = (statedump); \ +} + +#define DEV_GMBOX_GET_PROTOCOL(pDev) (pDev)->GMboxInfo.pProtocolContext + +A_STATUS DevGMboxWrite(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 WriteLength); +A_STATUS DevGMboxRead(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 ReadLength); + +#define PROC_IO_ASYNC TRUE +#define PROC_IO_SYNC FALSE +typedef enum GMBOX_IRQ_ACTION_TYPE { + GMBOX_ACTION_NONE = 0, + GMBOX_DISABLE_ALL, + GMBOX_ERRORS_IRQ_ENABLE, + GMBOX_RECV_IRQ_ENABLE, + GMBOX_RECV_IRQ_DISABLE, + GMBOX_CREDIT_IRQ_ENABLE, + GMBOX_CREDIT_IRQ_DISABLE, +} GMBOX_IRQ_ACTION_TYPE; + +A_STATUS DevGMboxIRQAction(AR6K_DEVICE *pDev, GMBOX_IRQ_ACTION_TYPE, A_BOOL AsyncMode); +A_STATUS DevGMboxReadCreditCounter(AR6K_DEVICE *pDev, A_BOOL AsyncMode, int *pCredits); +A_STATUS DevGMboxReadCreditSize(AR6K_DEVICE *pDev, int *pCreditSize); +A_STATUS DevGMboxRecvLookAheadPeek(AR6K_DEVICE *pDev, A_UINT8 *pLookAheadBuffer, int *pLookAheadBytes); +A_STATUS DevGMboxSetTargetInterrupt(AR6K_DEVICE *pDev, int SignalNumber, int AckTimeoutMS); + +#endif + +#endif /*AR6K_H_*/ diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_events.c b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_events.c new file mode 100644 index 000000000000..18b733e9e9f2 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_events.c @@ -0,0 +1,767 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// AR6K Driver layer event handling (i.e. interrupts, message polling) +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "../htc_debug.h" +#include "hif.h" +#include "htc_packet.h" +#include "ar6k.h" +#include "target_reg_table.h" +#include "host_reg_table.h" + +extern void AR6KFreeIOPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket); +extern HTC_PACKET *AR6KAllocIOPacket(AR6K_DEVICE *pDev); + +static A_STATUS DevServiceDebugInterrupt(AR6K_DEVICE *pDev); + +#define DELAY_PER_INTERVAL_MS 10 /* 10 MS delay per polling interval */ + +/* completion routine for ALL HIF layer async I/O */ +A_STATUS DevRWCompletionHandler(void *context, A_STATUS status) +{ + HTC_PACKET *pPacket = (HTC_PACKET *)context; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("+DevRWCompletionHandler (Pkt:0x%lX) , Status: %d \n", + (unsigned long)pPacket, + status)); + + COMPLETE_HTC_PACKET(pPacket,status); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("-DevRWCompletionHandler\n")); + + return A_OK; +} + +/* mailbox recv message polling */ +A_STATUS DevPollMboxMsgRecv(AR6K_DEVICE *pDev, + A_UINT32 *pLookAhead, + int TimeoutMS) +{ + A_STATUS status = A_OK; + int timeout = TimeoutMS/DELAY_PER_INTERVAL_MS; + + A_ASSERT(timeout > 0); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+DevPollMboxMsgRecv \n")); + + while (TRUE) { + + if (pDev->GetPendingEventsFunc != NULL) { + + HIF_PENDING_EVENTS_INFO events; + + /* the HIF layer uses a special mechanism to get events, do this + * synchronously */ + status = pDev->GetPendingEventsFunc(pDev->HIFDevice, + &events, + NULL); + if (A_FAILED(status)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to get pending events \n")); + break; + } + + if (events.Events & HIF_RECV_MSG_AVAIL) + { + /* there is a message available, the lookahead should be valid now */ + *pLookAhead = events.LookAhead; + + break; + } + } else { + + /* this is the standard HIF way.... */ + /* load the register table */ + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + (A_UINT8 *)&pDev->IrqProcRegisters, + AR6K_IRQ_PROC_REGS_SIZE, + HIF_RD_SYNC_BYTE_INC, + NULL); + + if (A_FAILED(status)){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to read register table \n")); + break; + } + + /* check for MBOX data and valid lookahead */ + if (pDev->IrqProcRegisters.host_int_status & (1 << HTC_MAILBOX)) { + if (pDev->IrqProcRegisters.rx_lookahead_valid & (1 << HTC_MAILBOX)) + { + /* mailbox has a message and the look ahead is valid */ + *pLookAhead = pDev->IrqProcRegisters.rx_lookahead[HTC_MAILBOX]; + break; + } + } + + } + + timeout--; + + if (timeout <= 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, (" Timeout waiting for recv message \n")); + status = A_ERROR; + + /* check if the target asserted */ + if ( pDev->IrqProcRegisters.counter_int_status & AR6K_TARGET_DEBUG_INTR_MASK) { + /* target signaled an assert, process this pending interrupt + * this will call the target failure handler */ + DevServiceDebugInterrupt(pDev); + } + + break; + } + + /* delay a little */ + A_MDELAY(DELAY_PER_INTERVAL_MS); + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" Retry Mbox Poll : %d \n",timeout)); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-DevPollMboxMsgRecv \n")); + + return status; +} + +static A_STATUS DevServiceCPUInterrupt(AR6K_DEVICE *pDev) +{ + A_STATUS status; + A_UINT8 cpu_int_status; + A_UINT8 regBuffer[4]; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("CPU Interrupt\n")); + cpu_int_status = pDev->IrqProcRegisters.cpu_int_status & + pDev->IrqEnableRegisters.cpu_int_status_enable; + A_ASSERT(cpu_int_status); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + ("Valid interrupt source(s) in CPU_INT_STATUS: 0x%x\n", + cpu_int_status)); + + /* Clear the interrupt */ + pDev->IrqProcRegisters.cpu_int_status &= ~cpu_int_status; /* W1C */ + + /* set up the register transfer buffer to hit the register 4 times , this is done + * to make the access 4-byte aligned to mitigate issues with host bus interconnects that + * restrict bus transfer lengths to be a multiple of 4-bytes */ + + /* set W1C value to clear the interrupt, this hits the register first */ + regBuffer[0] = cpu_int_status; + /* the remaining 4 values are set to zero which have no-effect */ + regBuffer[1] = 0; + regBuffer[2] = 0; + regBuffer[3] = 0; + + status = HIFReadWrite(pDev->HIFDevice, + CPU_INT_STATUS_ADDRESS, + regBuffer, + 4, + HIF_WR_SYNC_BYTE_FIX, + NULL); + + A_ASSERT(status == A_OK); + return status; +} + + +static A_STATUS DevServiceErrorInterrupt(AR6K_DEVICE *pDev) +{ + A_STATUS status; + A_UINT8 error_int_status; + A_UINT8 regBuffer[4]; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("Error Interrupt\n")); + error_int_status = pDev->IrqProcRegisters.error_int_status & 0x0F; + A_ASSERT(error_int_status); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + ("Valid interrupt source(s) in ERROR_INT_STATUS: 0x%x\n", + error_int_status)); + + if (ERROR_INT_STATUS_WAKEUP_GET(error_int_status)) { + /* Wakeup */ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("Error : Wakeup\n")); + } + + if (ERROR_INT_STATUS_RX_UNDERFLOW_GET(error_int_status)) { + /* Rx Underflow */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Error : Rx Underflow\n")); + } + + if (ERROR_INT_STATUS_TX_OVERFLOW_GET(error_int_status)) { + /* Tx Overflow */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Error : Tx Overflow\n")); + } + + /* Clear the interrupt */ + pDev->IrqProcRegisters.error_int_status &= ~error_int_status; /* W1C */ + + /* set up the register transfer buffer to hit the register 4 times , this is done + * to make the access 4-byte aligned to mitigate issues with host bus interconnects that + * restrict bus transfer lengths to be a multiple of 4-bytes */ + + /* set W1C value to clear the interrupt, this hits the register first */ + regBuffer[0] = error_int_status; + /* the remaining 4 values are set to zero which have no-effect */ + regBuffer[1] = 0; + regBuffer[2] = 0; + regBuffer[3] = 0; + + status = HIFReadWrite(pDev->HIFDevice, + ERROR_INT_STATUS_ADDRESS, + regBuffer, + 4, + HIF_WR_SYNC_BYTE_FIX, + NULL); + + A_ASSERT(status == A_OK); + return status; +} + +static A_STATUS DevServiceDebugInterrupt(AR6K_DEVICE *pDev) +{ + A_UINT32 dummy; + A_STATUS status; + + /* Send a target failure event to the application */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Target debug interrupt\n")); + + if (pDev->TargetFailureCallback != NULL) { + pDev->TargetFailureCallback(pDev->HTCContext); + } + + if (pDev->GMboxEnabled) { + DevNotifyGMboxTargetFailure(pDev); + } + + /* clear the interrupt , the debug error interrupt is + * counter 0 */ + /* read counter to clear interrupt */ + status = HIFReadWrite(pDev->HIFDevice, + COUNT_DEC_ADDRESS, + (A_UINT8 *)&dummy, + 4, + HIF_RD_SYNC_BYTE_INC, + NULL); + + A_ASSERT(status == A_OK); + return status; +} + +static A_STATUS DevServiceCounterInterrupt(AR6K_DEVICE *pDev) +{ + A_UINT8 counter_int_status; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("Counter Interrupt\n")); + + counter_int_status = pDev->IrqProcRegisters.counter_int_status & + pDev->IrqEnableRegisters.counter_int_status_enable; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + ("Valid interrupt source(s) in COUNTER_INT_STATUS: 0x%x\n", + counter_int_status)); + + /* Check if the debug interrupt is pending + * NOTE: other modules like GMBOX may use the counter interrupt for + * credit flow control on other counters, we only need to check for the debug assertion + * counter interrupt */ + if (counter_int_status & AR6K_TARGET_DEBUG_INTR_MASK) { + return DevServiceDebugInterrupt(pDev); + } + + return A_OK; +} + +/* callback when our fetch to get interrupt status registers completes */ +static void DevGetEventAsyncHandler(void *Context, HTC_PACKET *pPacket) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + A_UINT32 lookAhead = 0; + A_BOOL otherInts = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevGetEventAsyncHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + do { + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" GetEvents I/O request failed, status:%d \n", pPacket->Status)); + /* bail out, don't unmask HIF interrupt */ + break; + } + + if (pDev->GetPendingEventsFunc != NULL) { + /* the HIF layer collected the information for us */ + HIF_PENDING_EVENTS_INFO *pEvents = (HIF_PENDING_EVENTS_INFO *)pPacket->pBuffer; + if (pEvents->Events & HIF_RECV_MSG_AVAIL) { + lookAhead = pEvents->LookAhead; + if (0 == lookAhead) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" DevGetEventAsyncHandler1, lookAhead is zero! \n")); + } + } + if (pEvents->Events & HIF_OTHER_EVENTS) { + otherInts = TRUE; + } + } else { + /* standard interrupt table handling.... */ + AR6K_IRQ_PROC_REGISTERS *pReg = (AR6K_IRQ_PROC_REGISTERS *)pPacket->pBuffer; + A_UINT8 host_int_status; + + host_int_status = pReg->host_int_status & pDev->IrqEnableRegisters.int_status_enable; + + if (host_int_status & (1 << HTC_MAILBOX)) { + host_int_status &= ~(1 << HTC_MAILBOX); + if (pReg->rx_lookahead_valid & (1 << HTC_MAILBOX)) { + /* mailbox has a message and the look ahead is valid */ + lookAhead = pReg->rx_lookahead[HTC_MAILBOX]; + if (0 == lookAhead) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" DevGetEventAsyncHandler2, lookAhead is zero! \n")); + } + } + } + + if (host_int_status) { + /* there are other interrupts to handle */ + otherInts = TRUE; + } + } + + if (otherInts || (lookAhead == 0)) { + /* if there are other interrupts to process, we cannot do this in the async handler so + * ack the interrupt which will cause our sync handler to run again + * if however there are no more messages, we can now ack the interrupt */ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + (" Acking interrupt from DevGetEventAsyncHandler (otherints:%d, lookahead:0x%X)\n", + otherInts, lookAhead)); + HIFAckInterrupt(pDev->HIFDevice); + } else { + int fetched = 0; + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + (" DevGetEventAsyncHandler : detected another message, lookahead :0x%X \n", + lookAhead)); + /* lookahead is non-zero and there are no other interrupts to service, + * go get the next message */ + status = pDev->MessagePendingCallback(pDev->HTCContext, &lookAhead, 1, NULL, &fetched); + + if (A_SUCCESS(status) && !fetched) { + /* HTC layer could not pull out messages due to lack of resources, stop IRQ processing */ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("MessagePendingCallback did not pull any messages, force-ack \n")); + DevAsyncIrqProcessComplete(pDev); + } + } + + } while (FALSE); + + /* free this IO packet */ + AR6KFreeIOPacket(pDev,pPacket); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevGetEventAsyncHandler \n")); +} + +/* called by the HTC layer when it wants us to check if the device has any more pending + * recv messages, this starts off a series of async requests to read interrupt registers */ +A_STATUS DevCheckPendingRecvMsgsAsync(void *context) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)context; + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket; + + /* this is called in an ASYNC only context, we may NOT block, sleep or call any apis that can + * cause us to switch contexts */ + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevCheckPendingRecvMsgsAsync: (dev: 0x%lX)\n", (unsigned long)pDev)); + + do { + + if (HIF_DEVICE_IRQ_SYNC_ONLY == pDev->HifIRQProcessingMode) { + /* break the async processing chain right here, no need to continue. + * The DevDsrHandler() will handle things in a loop when things are driven + * synchronously */ + break; + } + + /* an optimization to bypass reading the IRQ status registers unecessarily which can re-wake + * the target, if upper layers determine that we are in a low-throughput mode, we can + * rely on taking another interrupt rather than re-checking the status registers which can + * re-wake the target */ + if (pDev->RecheckIRQStatusCnt == 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("Bypassing IRQ Status re-check, re-acking HIF interrupts\n")); + /* ack interrupt */ + HIFAckInterrupt(pDev->HIFDevice); + break; + } + + /* first allocate one of our HTC packets we created for async I/O + * we reuse HTC packet definitions so that we can use the completion mechanism + * in DevRWCompletionHandler() */ + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + /* there should be only 1 asynchronous request out at a time to read these registers + * so this should actually never happen */ + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevGetEventAsyncHandler; + pIOPacket->pContext = pDev; + + if (pDev->GetPendingEventsFunc) { + /* HIF layer has it's own mechanism, pass the IO to it.. */ + status = pDev->GetPendingEventsFunc(pDev->HIFDevice, + (HIF_PENDING_EVENTS_INFO *)pIOPacket->pBuffer, + pIOPacket); + + } else { + /* standard way, read the interrupt register table asynchronously again */ + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + pIOPacket->pBuffer, + AR6K_IRQ_PROC_REGS_SIZE, + HIF_RD_ASYNC_BYTE_INC, + pIOPacket); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,(" Async IO issued to get interrupt status...\n")); + } while (FALSE); + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevCheckPendingRecvMsgsAsync \n")); + + return status; +} + +void DevAsyncIrqProcessComplete(AR6K_DEVICE *pDev) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("DevAsyncIrqProcessComplete - forcing HIF IRQ ACK \n")); + HIFAckInterrupt(pDev->HIFDevice); +} + +/* process pending interrupts synchronously */ +static A_STATUS ProcessPendingIRQs(AR6K_DEVICE *pDev, A_BOOL *pDone, A_BOOL *pASyncProcessing) +{ + A_STATUS status = A_OK; + A_UINT8 host_int_status = 0; + A_UINT32 lookAhead = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+ProcessPendingIRQs: (dev: 0x%lX)\n", (unsigned long)pDev)); + + /*** NOTE: the HIF implementation guarantees that the context of this call allows + * us to perform SYNCHRONOUS I/O, that is we can block, sleep or call any API that + * can block or switch thread/task ontexts. + * This is a fully schedulable context. + * */ + do { + + if (pDev->IrqEnableRegisters.int_status_enable == 0) { + /* interrupt enables have been cleared, do not try to process any pending interrupts that + * may result in more bus transactions. The target may be unresponsive at this + * point. */ + break; + } + + if (pDev->GetPendingEventsFunc != NULL) { + HIF_PENDING_EVENTS_INFO events; + + /* the HIF layer uses a special mechanism to get events + * get this synchronously */ + status = pDev->GetPendingEventsFunc(pDev->HIFDevice, + &events, + NULL); + + if (A_FAILED(status)) { + break; + } + + if (events.Events & HIF_RECV_MSG_AVAIL) { + lookAhead = events.LookAhead; + if (0 == lookAhead) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" ProcessPendingIRQs1 lookAhead is zero! \n")); + } + } + + if (!(events.Events & HIF_OTHER_EVENTS) || + !(pDev->IrqEnableRegisters.int_status_enable & OTHER_INTS_ENABLED)) { + /* no need to read the register table, no other interesting interrupts. + * Some interfaces (like SPI) can shadow interrupt sources without + * requiring the host to do a full table read */ + break; + } + + /* otherwise fall through and read the register table */ + } + + /* + * Read the first 28 bytes of the HTC register table. This will yield us + * the value of different int status registers and the lookahead + * registers. + * length = sizeof(int_status) + sizeof(cpu_int_status) + + * sizeof(error_int_status) + sizeof(counter_int_status) + + * sizeof(mbox_frame) + sizeof(rx_lookahead_valid) + + * sizeof(hole) + sizeof(rx_lookahead) + + * sizeof(int_status_enable) + sizeof(cpu_int_status_enable) + + * sizeof(error_status_enable) + + * sizeof(counter_int_status_enable); + * + */ + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + (A_UINT8 *)&pDev->IrqProcRegisters, + AR6K_IRQ_PROC_REGS_SIZE, + HIF_RD_SYNC_BYTE_INC, + NULL); + + if (A_FAILED(status)) { + break; + } + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_IRQ)) { + DevDumpRegisters(pDev, + &pDev->IrqProcRegisters, + &pDev->IrqEnableRegisters); + } + + /* Update only those registers that are enabled */ + host_int_status = pDev->IrqProcRegisters.host_int_status & + pDev->IrqEnableRegisters.int_status_enable; + + if (NULL == pDev->GetPendingEventsFunc) { + /* only look at mailbox status if the HIF layer did not provide this function, + * on some HIF interfaces reading the RX lookahead is not valid to do */ + if (host_int_status & (1 << HTC_MAILBOX)) { + /* mask out pending mailbox value, we use "lookAhead" as the real flag for + * mailbox processing below */ + host_int_status &= ~(1 << HTC_MAILBOX); + if (pDev->IrqProcRegisters.rx_lookahead_valid & (1 << HTC_MAILBOX)) { + /* mailbox has a message and the look ahead is valid */ + lookAhead = pDev->IrqProcRegisters.rx_lookahead[HTC_MAILBOX]; + if (0 == lookAhead) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" ProcessPendingIRQs2, lookAhead is zero! \n")); + } + } + } + } else { + /* not valid to check if the HIF has another mechanism for reading mailbox pending status*/ + host_int_status &= ~(1 << HTC_MAILBOX); + } + + if (pDev->GMboxEnabled) { + /*call GMBOX layer to process any interrupts of interest */ + status = DevCheckGMboxInterrupts(pDev); + } + + } while (FALSE); + + + do { + + /* did the interrupt status fetches succeed? */ + if (A_FAILED(status)) { + break; + } + + if ((0 == host_int_status) && (0 == lookAhead)) { + /* nothing to process, the caller can use this to break out of a loop */ + *pDone = TRUE; + break; + } + + if (lookAhead != 0) { + int fetched = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("Pending mailbox message, LookAhead: 0x%X\n",lookAhead)); + /* Mailbox Interrupt, the HTC layer may issue async requests to empty the + * mailbox... + * When emptying the recv mailbox we use the async handler above called from the + * completion routine of the callers read request. This can improve performance + * by reducing context switching when we rapidly pull packets */ + status = pDev->MessagePendingCallback(pDev->HTCContext, &lookAhead, 1, pASyncProcessing, &fetched); + if (A_FAILED(status)) { + break; + } + + if (!fetched) { + /* HTC could not pull any messages out due to lack of resources */ + /* force DSR handler to ack the interrupt */ + *pASyncProcessing = FALSE; + pDev->RecheckIRQStatusCnt = 0; + } + } + + /* now handle the rest of them */ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + (" Valid interrupt source(s) for OTHER interrupts: 0x%x\n", + host_int_status)); + + if (HOST_INT_STATUS_CPU_GET(host_int_status)) { + /* CPU Interrupt */ + status = DevServiceCPUInterrupt(pDev); + if (A_FAILED(status)){ + break; + } + } + + if (HOST_INT_STATUS_ERROR_GET(host_int_status)) { + /* Error Interrupt */ + status = DevServiceErrorInterrupt(pDev); + if (A_FAILED(status)){ + break; + } + } + + if (HOST_INT_STATUS_COUNTER_GET(host_int_status)) { + /* Counter Interrupt */ + status = DevServiceCounterInterrupt(pDev); + if (A_FAILED(status)){ + break; + } + } + + } while (FALSE); + + /* an optimization to bypass reading the IRQ status registers unecessarily which can re-wake + * the target, if upper layers determine that we are in a low-throughput mode, we can + * rely on taking another interrupt rather than re-checking the status registers which can + * re-wake the target. + * + * NOTE : for host interfaces that use the special GetPendingEventsFunc, this optimization cannot + * be used due to possible side-effects. For example, SPI requires the host to drain all + * messages from the mailbox before exiting the ISR routine. */ + if (!(*pASyncProcessing) && (pDev->RecheckIRQStatusCnt == 0) && (pDev->GetPendingEventsFunc == NULL)) { + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("Bypassing IRQ Status re-check, forcing done \n")); + *pDone = TRUE; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-ProcessPendingIRQs: (done:%d, async:%d) status=%d \n", + *pDone, *pASyncProcessing, status)); + + return status; +} + + +/* Synchronousinterrupt handler, this handler kicks off all interrupt processing.*/ +A_STATUS DevDsrHandler(void *context) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)context; + A_STATUS status = A_OK; + A_BOOL done = FALSE; + A_BOOL asyncProc = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevDsrHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + /* reset the recv counter that tracks when we need to yield from the DSR */ + pDev->CurrentDSRRecvCount = 0; + /* reset counter used to flag a re-scan of IRQ status registers on the target */ + pDev->RecheckIRQStatusCnt = 0; + + while (!done) { + status = ProcessPendingIRQs(pDev, &done, &asyncProc); + if (A_FAILED(status)) { + break; + } + + if (HIF_DEVICE_IRQ_SYNC_ONLY == pDev->HifIRQProcessingMode) { + /* the HIF layer does not allow async IRQ processing, override the asyncProc flag */ + asyncProc = FALSE; + /* this will cause us to re-enter ProcessPendingIRQ() and re-read interrupt status registers. + * this has a nice side effect of blocking us until all async read requests are completed. + * This behavior is required on some HIF implementations that do not allow ASYNC + * processing in interrupt handlers (like Windows CE) */ + + if (pDev->DSRCanYield && DEV_CHECK_RECV_YIELD(pDev)) { + /* ProcessPendingIRQs() pulled enough recv messages to satisfy the yield count, stop + * checking for more messages and return */ + break; + } + } + + if (asyncProc) { + /* the function performed some async I/O for performance, we + need to exit the ISR immediately, the check below will prevent the interrupt from being + Ack'd while we handle it asynchronously */ + break; + } + + } + + if (A_SUCCESS(status) && !asyncProc) { + /* Ack the interrupt only if : + * 1. we did not get any errors in processing interrupts + * 2. there are no outstanding async processing requests */ + if (pDev->DSRCanYield) { + /* if the DSR can yield do not ACK the interrupt, there could be more pending messages. + * The HIF layer must ACK the interrupt on behalf of HTC */ + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,(" Yield in effect (cur RX count: %d) \n", pDev->CurrentDSRRecvCount)); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,(" Acking interrupt from DevDsrHandler \n")); + HIFAckInterrupt(pDev->HIFDevice); + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevDsrHandler \n")); + return status; +} + +void DumpAR6KDevState(AR6K_DEVICE *pDev) +{ + A_STATUS status; + AR6K_IRQ_ENABLE_REGISTERS regs; + AR6K_IRQ_PROC_REGISTERS procRegs; + + LOCK_AR6K(pDev); + /* copy into our temp area */ + A_MEMCPY(®s,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + UNLOCK_AR6K(pDev); + + /* load the register table from the device */ + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + (A_UINT8 *)&procRegs, + AR6K_IRQ_PROC_REGS_SIZE, + HIF_RD_SYNC_BYTE_INC, + NULL); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("DumpAR6KDevState : Failed to read register table (%d) \n",status)); + return; + } + + DevDumpRegisters(pDev,&procRegs,®s); + + if (pDev->GMboxInfo.pStateDumpCallback != NULL) { + pDev->GMboxInfo.pStateDumpCallback(pDev->GMboxInfo.pProtocolContext); + } + + /* dump any bus state at the HIF layer */ + HIFConfigureDevice(pDev->HIFDevice,HIF_DEVICE_DEBUG_BUS_STATE,NULL,0); + +} + + diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox.c b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox.c new file mode 100644 index 000000000000..4aacbea60fb8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox.c @@ -0,0 +1,757 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Generic MBOX API implementation +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "../htc_debug.h" +#include "hif.h" +#include "htc_packet.h" +#include "ar6k.h" +#include "hw/mbox_host_reg.h" +#include "gmboxif.h" + +/* + * This file provides management functions and a toolbox for GMBOX protocol modules. + * Only one protocol module can be installed at a time. The determination of which protocol + * module is installed is determined at compile time. + * + */ +#ifdef ATH_AR6K_ENABLE_GMBOX + /* GMBOX definitions */ +#define GMBOX_INT_STATUS_ENABLE_REG 0x488 +#define GMBOX_INT_STATUS_RX_DATA (1 << 0) +#define GMBOX_INT_STATUS_TX_OVERFLOW (1 << 1) +#define GMBOX_INT_STATUS_RX_OVERFLOW (1 << 2) + +#define GMBOX_LOOKAHEAD_MUX_REG 0x498 +#define GMBOX_LA_MUX_OVERRIDE_2_3 (1 << 0) + +#define AR6K_GMBOX_CREDIT_DEC_ADDRESS (COUNT_DEC_ADDRESS + 4 * AR6K_GMBOX_CREDIT_COUNTER) +#define AR6K_GMBOX_CREDIT_SIZE_ADDRESS (COUNT_ADDRESS + AR6K_GMBOX_CREDIT_SIZE_COUNTER) + + + /* external APIs for allocating and freeing internal I/O packets to handle ASYNC I/O */ +extern void AR6KFreeIOPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket); +extern HTC_PACKET *AR6KAllocIOPacket(AR6K_DEVICE *pDev); + + +/* callback when our fetch to enable/disable completes */ +static void DevGMboxIRQActionAsyncHandler(void *Context, HTC_PACKET *pPacket) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevGMboxIRQActionAsyncHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("IRQAction Operation (%d) failed! status:%d \n", pPacket->PktInfo.AsRx.HTCRxFlags,pPacket->Status)); + } + /* free this IO packet */ + AR6KFreeIOPacket(pDev,pPacket); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevGMboxIRQActionAsyncHandler \n")); +} + +static A_STATUS DevGMboxCounterEnableDisable(AR6K_DEVICE *pDev, GMBOX_IRQ_ACTION_TYPE IrqAction, A_BOOL AsyncMode) +{ + A_STATUS status = A_OK; + AR6K_IRQ_ENABLE_REGISTERS regs; + HTC_PACKET *pIOPacket = NULL; + + LOCK_AR6K(pDev); + + if (GMBOX_CREDIT_IRQ_ENABLE == IrqAction) { + pDev->GMboxInfo.CreditCountIRQEnabled = TRUE; + pDev->IrqEnableRegisters.counter_int_status_enable |= + COUNTER_INT_STATUS_ENABLE_BIT_SET(1 << AR6K_GMBOX_CREDIT_COUNTER); + pDev->IrqEnableRegisters.int_status_enable |= INT_STATUS_ENABLE_COUNTER_SET(0x01); + } else { + pDev->GMboxInfo.CreditCountIRQEnabled = FALSE; + pDev->IrqEnableRegisters.counter_int_status_enable &= + ~(COUNTER_INT_STATUS_ENABLE_BIT_SET(1 << AR6K_GMBOX_CREDIT_COUNTER)); + } + /* copy into our temp area */ + A_MEMCPY(®s,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + + UNLOCK_AR6K(pDev); + + do { + + if (AsyncMode) { + + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + /* copy values to write to our async I/O buffer */ + A_MEMCPY(pIOPacket->pBuffer,&pDev->IrqEnableRegisters,AR6K_IRQ_ENABLE_REGS_SIZE); + + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevGMboxIRQActionAsyncHandler; + pIOPacket->pContext = pDev; + pIOPacket->PktInfo.AsRx.HTCRxFlags = IrqAction; + /* write it out asynchronously */ + HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + pIOPacket->pBuffer, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_ASYNC_BYTE_INC, + pIOPacket); + + pIOPacket = NULL; + break; + } + + /* if we get here we are doing it synchronously */ + status = HIFReadWrite(pDev->HIFDevice, + INT_STATUS_ENABLE_ADDRESS, + ®s.int_status_enable, + AR6K_IRQ_ENABLE_REGS_SIZE, + HIF_WR_SYNC_BYTE_INC, + NULL); + } while (FALSE); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" IRQAction Operation (%d) failed! status:%d \n", IrqAction, status)); + } else { + if (!AsyncMode) { + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + (" IRQAction Operation (%d) success \n", IrqAction)); + } + } + + if (pIOPacket != NULL) { + AR6KFreeIOPacket(pDev,pIOPacket); + } + + return status; +} + + +A_STATUS DevGMboxIRQAction(AR6K_DEVICE *pDev, GMBOX_IRQ_ACTION_TYPE IrqAction, A_BOOL AsyncMode) +{ + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket = NULL; + A_UINT8 GMboxIntControl[4]; + + if (GMBOX_CREDIT_IRQ_ENABLE == IrqAction) { + return DevGMboxCounterEnableDisable(pDev, GMBOX_CREDIT_IRQ_ENABLE, AsyncMode); + } else if(GMBOX_CREDIT_IRQ_DISABLE == IrqAction) { + return DevGMboxCounterEnableDisable(pDev, GMBOX_CREDIT_IRQ_DISABLE, AsyncMode); + } + + if (GMBOX_DISABLE_ALL == IrqAction) { + /* disable credit IRQ, those are on a different set of registers */ + DevGMboxCounterEnableDisable(pDev, GMBOX_CREDIT_IRQ_DISABLE, AsyncMode); + } + + /* take the lock to protect interrupt enable shadows */ + LOCK_AR6K(pDev); + + switch (IrqAction) { + + case GMBOX_DISABLE_ALL: + pDev->GMboxControlRegisters.int_status_enable = 0; + break; + case GMBOX_ERRORS_IRQ_ENABLE: + pDev->GMboxControlRegisters.int_status_enable |= GMBOX_INT_STATUS_TX_OVERFLOW | + GMBOX_INT_STATUS_RX_OVERFLOW; + break; + case GMBOX_RECV_IRQ_ENABLE: + pDev->GMboxControlRegisters.int_status_enable |= GMBOX_INT_STATUS_RX_DATA; + break; + case GMBOX_RECV_IRQ_DISABLE: + pDev->GMboxControlRegisters.int_status_enable &= ~GMBOX_INT_STATUS_RX_DATA; + break; + case GMBOX_ACTION_NONE: + default: + A_ASSERT(FALSE); + break; + } + + GMboxIntControl[0] = pDev->GMboxControlRegisters.int_status_enable; + GMboxIntControl[1] = GMboxIntControl[0]; + GMboxIntControl[2] = GMboxIntControl[0]; + GMboxIntControl[3] = GMboxIntControl[0]; + + UNLOCK_AR6K(pDev); + + do { + + if (AsyncMode) { + + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + /* copy values to write to our async I/O buffer */ + A_MEMCPY(pIOPacket->pBuffer,GMboxIntControl,sizeof(GMboxIntControl)); + + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevGMboxIRQActionAsyncHandler; + pIOPacket->pContext = pDev; + pIOPacket->PktInfo.AsRx.HTCRxFlags = IrqAction; + /* write it out asynchronously */ + HIFReadWrite(pDev->HIFDevice, + GMBOX_INT_STATUS_ENABLE_REG, + pIOPacket->pBuffer, + sizeof(GMboxIntControl), + HIF_WR_ASYNC_BYTE_FIX, + pIOPacket); + pIOPacket = NULL; + break; + } + + /* if we get here we are doing it synchronously */ + + status = HIFReadWrite(pDev->HIFDevice, + GMBOX_INT_STATUS_ENABLE_REG, + GMboxIntControl, + sizeof(GMboxIntControl), + HIF_WR_SYNC_BYTE_FIX, + NULL); + + } while (FALSE); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" IRQAction Operation (%d) failed! status:%d \n", IrqAction, status)); + } else { + if (!AsyncMode) { + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, + (" IRQAction Operation (%d) success \n", IrqAction)); + } + } + + if (pIOPacket != NULL) { + AR6KFreeIOPacket(pDev,pIOPacket); + } + + return status; +} + +void DevCleanupGMbox(AR6K_DEVICE *pDev) +{ + if (pDev->GMboxEnabled) { + pDev->GMboxEnabled = FALSE; + GMboxProtocolUninstall(pDev); + } +} + +A_STATUS DevSetupGMbox(AR6K_DEVICE *pDev) +{ + A_STATUS status = A_OK; + A_UINT8 muxControl[4]; + + do { + + if (0 == pDev->MailBoxInfo.GMboxAddress) { + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,(" GMBOX Advertised: Address:0x%X , size:%d \n", + pDev->MailBoxInfo.GMboxAddress, pDev->MailBoxInfo.GMboxSize)); + + status = DevGMboxIRQAction(pDev, GMBOX_DISABLE_ALL, PROC_IO_SYNC); + + if (A_FAILED(status)) { + break; + } + + /* write to mailbox look ahead mux control register, we want the + * GMBOX lookaheads to appear on lookaheads 2 and 3 + * the register is 1-byte wide so we need to hit it 4 times to align the operation + * to 4-bytes */ + muxControl[0] = GMBOX_LA_MUX_OVERRIDE_2_3; + muxControl[1] = GMBOX_LA_MUX_OVERRIDE_2_3; + muxControl[2] = GMBOX_LA_MUX_OVERRIDE_2_3; + muxControl[3] = GMBOX_LA_MUX_OVERRIDE_2_3; + + status = HIFReadWrite(pDev->HIFDevice, + GMBOX_LOOKAHEAD_MUX_REG, + muxControl, + sizeof(muxControl), + HIF_WR_SYNC_BYTE_FIX, /* hit this register 4 times */ + NULL); + + if (A_FAILED(status)) { + break; + } + + status = GMboxProtocolInstall(pDev); + + if (A_FAILED(status)) { + break; + } + + pDev->GMboxEnabled = TRUE; + + } while (FALSE); + + return status; +} + +A_STATUS DevCheckGMboxInterrupts(AR6K_DEVICE *pDev) +{ + A_STATUS status = A_OK; + A_UINT8 counter_int_status; + int credits; + A_UINT8 host_int_status2; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("+DevCheckGMboxInterrupts \n")); + + /* the caller guarantees that this is a context that allows for blocking I/O */ + + do { + + host_int_status2 = pDev->IrqProcRegisters.host_int_status2 & + pDev->GMboxControlRegisters.int_status_enable; + + if (host_int_status2 & GMBOX_INT_STATUS_TX_OVERFLOW) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("GMBOX : TX Overflow \n")); + status = A_ECOMM; + } + + if (host_int_status2 & GMBOX_INT_STATUS_RX_OVERFLOW) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("GMBOX : RX Overflow \n")); + status = A_ECOMM; + } + + if (A_FAILED(status)) { + if (pDev->GMboxInfo.pTargetFailureCallback != NULL) { + pDev->GMboxInfo.pTargetFailureCallback(pDev->GMboxInfo.pProtocolContext, status); + } + break; + } + + if (host_int_status2 & GMBOX_INT_STATUS_RX_DATA) { + if (pDev->IrqProcRegisters.gmbox_rx_avail > 0) { + A_ASSERT(pDev->GMboxInfo.pMessagePendingCallBack != NULL); + status = pDev->GMboxInfo.pMessagePendingCallBack( + pDev->GMboxInfo.pProtocolContext, + (A_UINT8 *)&pDev->IrqProcRegisters.rx_gmbox_lookahead_alias[0], + pDev->IrqProcRegisters.gmbox_rx_avail); + } + } + + if (A_FAILED(status)) { + break; + } + + counter_int_status = pDev->IrqProcRegisters.counter_int_status & + pDev->IrqEnableRegisters.counter_int_status_enable; + + /* check if credit interrupt is pending */ + if (counter_int_status & (COUNTER_INT_STATUS_ENABLE_BIT_SET(1 << AR6K_GMBOX_CREDIT_COUNTER))) { + + /* do synchronous read */ + status = DevGMboxReadCreditCounter(pDev, PROC_IO_SYNC, &credits); + + if (A_FAILED(status)) { + break; + } + + A_ASSERT(pDev->GMboxInfo.pCreditsPendingCallback != NULL); + status = pDev->GMboxInfo.pCreditsPendingCallback(pDev->GMboxInfo.pProtocolContext, + credits, + pDev->GMboxInfo.CreditCountIRQEnabled); + } + + } while (FALSE); + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ, ("-DevCheckGMboxInterrupts (%d) \n",status)); + + return status; +} + + +A_STATUS DevGMboxWrite(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 WriteLength) +{ + A_UINT32 paddedLength; + A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE; + A_STATUS status; + A_UINT32 address; + + /* adjust the length to be a multiple of block size if appropriate */ + paddedLength = DEV_CALC_SEND_PADDED_LEN(pDev, WriteLength); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + ("DevGMboxWrite, Padded Length: %d Mbox:0x%X (mode:%s)\n", + WriteLength, + pDev->MailBoxInfo.GMboxAddress, + sync ? "SYNC" : "ASYNC")); + + /* last byte of packet has to hit the EOM marker */ + address = pDev->MailBoxInfo.GMboxAddress + pDev->MailBoxInfo.GMboxSize - paddedLength; + + status = HIFReadWrite(pDev->HIFDevice, + address, + pPacket->pBuffer, + paddedLength, /* the padded length */ + sync ? HIF_WR_SYNC_BLOCK_INC : HIF_WR_ASYNC_BLOCK_INC, + sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */ + + if (sync) { + pPacket->Status = status; + } else { + if (status == A_PENDING) { + status = A_OK; + } + } + + return status; +} + +A_STATUS DevGMboxRead(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 ReadLength) +{ + + A_UINT32 paddedLength; + A_STATUS status; + A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE; + + /* adjust the length to be a multiple of block size if appropriate */ + paddedLength = DEV_CALC_RECV_PADDED_LEN(pDev, ReadLength); + + if (paddedLength > pPacket->BufferLength) { + A_ASSERT(FALSE); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("DevGMboxRead, Not enough space for padlen:%d recvlen:%d bufferlen:%d \n", + paddedLength,ReadLength,pPacket->BufferLength)); + if (pPacket->Completion != NULL) { + COMPLETE_HTC_PACKET(pPacket,A_EINVAL); + return A_OK; + } + return A_EINVAL; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("DevGMboxRead (0x%lX : hdr:0x%X) Padded Length: %d Mbox:0x%X (mode:%s)\n", + (unsigned long)pPacket, pPacket->PktInfo.AsRx.ExpectedHdr, + paddedLength, + pDev->MailBoxInfo.GMboxAddress, + sync ? "SYNC" : "ASYNC")); + + status = HIFReadWrite(pDev->HIFDevice, + pDev->MailBoxInfo.GMboxAddress, + pPacket->pBuffer, + paddedLength, + sync ? HIF_RD_SYNC_BLOCK_FIX : HIF_RD_ASYNC_BLOCK_FIX, + sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */ + + if (sync) { + pPacket->Status = status; + } + + return status; +} + + +static int ProcessCreditCounterReadBuffer(A_UINT8 *pBuffer, int Length) +{ + int credits = 0; + + /* theory of how this works: + * We read the credit decrement register multiple times on a byte-wide basis. + * The number of times (32) aligns the I/O operation to be a multiple of 4 bytes and provides a + * reasonable chance to acquire "all" pending credits in a single I/O operation. + * + * Once we obtain the filled buffer, we can walk through it looking for credit decrement transitions. + * Each non-zero byte represents a single credit decrement (which is a credit given back to the host) + * For example if the target provides 3 credits and added 4 more during the 32-byte read operation the following + * pattern "could" appear: + * + * 0x3 0x2 0x1 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x1 0x0 0x1 0x0 0x1 0x0 ......rest zeros + * <---------> <-----------------------------> + * \_ credits aleady there \_ target adding 4 more credits + * + * The total available credits would be 7, since there are 7 non-zero bytes in the buffer. + * + * */ + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + DebugDumpBytes(pBuffer, Length, "GMBOX Credit read buffer"); + } + + while (Length) { + if (*pBuffer != 0) { + credits++; + } + Length--; + pBuffer++; + } + + return credits; +} + + +/* callback when our fetch to enable/disable completes */ +static void DevGMboxReadCreditsAsyncHandler(void *Context, HTC_PACKET *pPacket) +{ + AR6K_DEVICE *pDev = (AR6K_DEVICE *)Context; + + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("+DevGMboxReadCreditsAsyncHandler: (dev: 0x%lX)\n", (unsigned long)pDev)); + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Read Credit Operation failed! status:%d \n", pPacket->Status)); + } else { + int credits = 0; + credits = ProcessCreditCounterReadBuffer(pPacket->pBuffer, AR6K_REG_IO_BUFFER_SIZE); + pDev->GMboxInfo.pCreditsPendingCallback(pDev->GMboxInfo.pProtocolContext, + credits, + pDev->GMboxInfo.CreditCountIRQEnabled); + + + } + /* free this IO packet */ + AR6KFreeIOPacket(pDev,pPacket); + AR_DEBUG_PRINTF(ATH_DEBUG_IRQ,("-DevGMboxReadCreditsAsyncHandler \n")); +} + +A_STATUS DevGMboxReadCreditCounter(AR6K_DEVICE *pDev, A_BOOL AsyncMode, int *pCredits) +{ + A_STATUS status = A_OK; + HTC_PACKET *pIOPacket = NULL; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+DevGMboxReadCreditCounter (%s) \n", AsyncMode ? "ASYNC" : "SYNC")); + + do { + + pIOPacket = AR6KAllocIOPacket(pDev); + + if (NULL == pIOPacket) { + status = A_NO_MEMORY; + A_ASSERT(FALSE); + break; + } + + A_MEMZERO(pIOPacket->pBuffer,AR6K_REG_IO_BUFFER_SIZE); + + if (AsyncMode) { + /* stick in our completion routine when the I/O operation completes */ + pIOPacket->Completion = DevGMboxReadCreditsAsyncHandler; + pIOPacket->pContext = pDev; + /* read registers asynchronously */ + HIFReadWrite(pDev->HIFDevice, + AR6K_GMBOX_CREDIT_DEC_ADDRESS, + pIOPacket->pBuffer, + AR6K_REG_IO_BUFFER_SIZE, /* hit the register multiple times */ + HIF_RD_ASYNC_BYTE_FIX, + pIOPacket); + pIOPacket = NULL; + break; + } + + pIOPacket->Completion = NULL; + /* if we get here we are doing it synchronously */ + status = HIFReadWrite(pDev->HIFDevice, + AR6K_GMBOX_CREDIT_DEC_ADDRESS, + pIOPacket->pBuffer, + AR6K_REG_IO_BUFFER_SIZE, + HIF_RD_SYNC_BYTE_FIX, + NULL); + } while (FALSE); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" DevGMboxReadCreditCounter failed! status:%d \n", status)); + } + + if (pIOPacket != NULL) { + if (A_SUCCESS(status)) { + /* sync mode processing */ + *pCredits = ProcessCreditCounterReadBuffer(pIOPacket->pBuffer, AR6K_REG_IO_BUFFER_SIZE); + } + AR6KFreeIOPacket(pDev,pIOPacket); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-DevGMboxReadCreditCounter (%s) (%d) \n", + AsyncMode ? "ASYNC" : "SYNC", status)); + + return status; +} + +A_STATUS DevGMboxReadCreditSize(AR6K_DEVICE *pDev, int *pCreditSize) +{ + A_STATUS status; + A_UINT8 buffer[4]; + + status = HIFReadWrite(pDev->HIFDevice, + AR6K_GMBOX_CREDIT_SIZE_ADDRESS, + buffer, + sizeof(buffer), + HIF_RD_SYNC_BYTE_FIX, /* hit the register 4 times to align the I/O */ + NULL); + + if (A_SUCCESS(status)) { + if (buffer[0] == 0) { + *pCreditSize = 256; + } else { + *pCreditSize = buffer[0]; + } + + } + + return status; +} + +void DevNotifyGMboxTargetFailure(AR6K_DEVICE *pDev) +{ + /* Target ASSERTED!!! */ + if (pDev->GMboxInfo.pTargetFailureCallback != NULL) { + pDev->GMboxInfo.pTargetFailureCallback(pDev->GMboxInfo.pProtocolContext, A_HARDWARE); + } +} + +A_STATUS DevGMboxRecvLookAheadPeek(AR6K_DEVICE *pDev, A_UINT8 *pLookAheadBuffer, int *pLookAheadBytes) +{ + + A_STATUS status = A_OK; + AR6K_IRQ_PROC_REGISTERS procRegs; + int maxCopy; + + do { + /* on entry the caller provides the length of the lookahead buffer */ + if (*pLookAheadBytes > sizeof(procRegs.rx_gmbox_lookahead_alias)) { + A_ASSERT(FALSE); + status = A_EINVAL; + break; + } + + maxCopy = *pLookAheadBytes; + *pLookAheadBytes = 0; + /* load the register table from the device */ + status = HIFReadWrite(pDev->HIFDevice, + HOST_INT_STATUS_ADDRESS, + (A_UINT8 *)&procRegs, + AR6K_IRQ_PROC_REGS_SIZE, + HIF_RD_SYNC_BYTE_INC, + NULL); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("DevGMboxRecvLookAheadPeek : Failed to read register table (%d) \n",status)); + break; + } + + if (procRegs.gmbox_rx_avail > 0) { + int bytes = procRegs.gmbox_rx_avail > maxCopy ? maxCopy : procRegs.gmbox_rx_avail; + A_MEMCPY(pLookAheadBuffer,&procRegs.rx_gmbox_lookahead_alias[0],bytes); + *pLookAheadBytes = bytes; + } + + } while (FALSE); + + return status; +} + +A_STATUS DevGMboxSetTargetInterrupt(AR6K_DEVICE *pDev, int Signal, int AckTimeoutMS) +{ + A_STATUS status = A_OK; + int i; + A_UINT8 buffer[4]; + + A_MEMZERO(buffer, sizeof(buffer)); + + do { + + if (Signal >= MBOX_SIG_HCI_BRIDGE_MAX) { + status = A_EINVAL; + break; + } + + /* set the last buffer to do the actual signal trigger */ + buffer[3] = (1 << Signal); + + status = HIFReadWrite(pDev->HIFDevice, + INT_WLAN_ADDRESS, + buffer, + sizeof(buffer), + HIF_WR_SYNC_BYTE_FIX, /* hit the register 4 times to align the I/O */ + NULL); + + if (A_FAILED(status)) { + break; + } + + } while (FALSE); + + + if (A_SUCCESS(status)) { + /* now read back the register to see if the bit cleared */ + while (AckTimeoutMS) { + status = HIFReadWrite(pDev->HIFDevice, + INT_WLAN_ADDRESS, + buffer, + sizeof(buffer), + HIF_RD_SYNC_BYTE_FIX, + NULL); + + if (A_FAILED(status)) { + break; + } + + for (i = 0; i < sizeof(buffer); i++) { + if (buffer[i] & (1 << Signal)) { + /* bit is still set */ + break; + } + } + + if (i >= sizeof(buffer)) { + /* done */ + break; + } + + AckTimeoutMS--; + A_MDELAY(1); + } + + if (0 == AckTimeoutMS) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("DevGMboxSetTargetInterrupt : Ack Timed-out (sig:%d) \n",Signal)); + status = A_ERROR; + } + } + + return status; + +} + +#endif //ATH_AR6K_ENABLE_GMBOX + + + + diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox_hciuart.c b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox_hciuart.c new file mode 100644 index 000000000000..c840fef07612 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/ar6k_gmbox_hciuart.c @@ -0,0 +1,1289 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Protocol module for use in bridging HCI-UART packets over the GMBOX interface +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "../htc_debug.h" +#include "hif.h" +#include "htc_packet.h" +#include "ar6k.h" +#include "hci_transport_api.h" +#include "gmboxif.h" +#include "ar6000_diag.h" +#include "hw/apb_map.h" +#include "hw/mbox_reg.h" + +#ifdef ATH_AR6K_ENABLE_GMBOX +#define HCI_UART_COMMAND_PKT 0x01 +#define HCI_UART_ACL_PKT 0x02 +#define HCI_UART_SCO_PKT 0x03 +#define HCI_UART_EVENT_PKT 0x04 + +#define HCI_RECV_WAIT_BUFFERS (1 << 0) + +#define HCI_SEND_WAIT_CREDITS (1 << 0) + +#define HCI_UART_BRIDGE_CREDIT_SIZE 128 + +#define CREDIT_POLL_COUNT 256 + +#define HCI_DELAY_PER_INTERVAL_MS 10 +#define BTON_TIMEOUT_MS 500 +#define BTOFF_TIMEOUT_MS 500 +#define BAUD_TIMEOUT_MS 1 +#define BTPWRSAV_TIMEOUT_MS 1 + +typedef struct { + HCI_TRANSPORT_CONFIG_INFO HCIConfig; + A_BOOL HCIAttached; + A_BOOL HCIStopped; + A_UINT32 RecvStateFlags; + A_UINT32 SendStateFlags; + HCI_TRANSPORT_PACKET_TYPE WaitBufferType; + HTC_PACKET_QUEUE SendQueue; /* write queue holding HCI Command and ACL packets */ + HTC_PACKET_QUEUE HCIACLRecvBuffers; /* recv queue holding buffers for incomming ACL packets */ + HTC_PACKET_QUEUE HCIEventBuffers; /* recv queue holding buffers for incomming event packets */ + AR6K_DEVICE *pDev; + A_MUTEX_T HCIRxLock; + A_MUTEX_T HCITxLock; + int CreditsMax; + int CreditsConsumed; + int CreditsAvailable; + int CreditSize; + int CreditsCurrentSeek; + int SendProcessCount; +} GMBOX_PROTO_HCI_UART; + +#define LOCK_HCI_RX(t) A_MUTEX_LOCK(&(t)->HCIRxLock); +#define UNLOCK_HCI_RX(t) A_MUTEX_UNLOCK(&(t)->HCIRxLock); +#define LOCK_HCI_TX(t) A_MUTEX_LOCK(&(t)->HCITxLock); +#define UNLOCK_HCI_TX(t) A_MUTEX_UNLOCK(&(t)->HCITxLock); + +#define DO_HCI_RECV_INDICATION(p,pt) \ +{ AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI: Indicate Recv on packet:0x%lX status:%d len:%d type:%d \n", \ + (unsigned long)(pt),(pt)->Status, A_SUCCESS((pt)->Status) ? (pt)->ActualLength : 0, HCI_GET_PACKET_TYPE(pt))); \ + (p)->HCIConfig.pHCIPktRecv((p)->HCIConfig.pContext, (pt)); \ +} + +#define DO_HCI_SEND_INDICATION(p,pt) \ +{ AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: Indicate Send on packet:0x%lX status:%d type:%d \n", \ + (unsigned long)(pt),(pt)->Status,HCI_GET_PACKET_TYPE(pt))); \ + (p)->HCIConfig.pHCISendComplete((p)->HCIConfig.pContext, (pt)); \ +} + +static A_STATUS HCITrySend(GMBOX_PROTO_HCI_UART *pProt, HTC_PACKET *pPacket, A_BOOL Synchronous); + +static void HCIUartCleanup(GMBOX_PROTO_HCI_UART *pProtocol) +{ + A_ASSERT(pProtocol != NULL); + + A_MUTEX_DELETE(&pProtocol->HCIRxLock); + A_MUTEX_DELETE(&pProtocol->HCITxLock); + + A_FREE(pProtocol); +} + +static A_STATUS InitTxCreditState(GMBOX_PROTO_HCI_UART *pProt) +{ + A_STATUS status; + int credits; + int creditPollCount = CREDIT_POLL_COUNT; + A_BOOL gotCredits = FALSE; + + pProt->CreditsConsumed = 0; + + do { + + if (pProt->CreditsMax != 0) { + /* we can only call this only once per target reset */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI: InitTxCreditState - already called! \n")); + A_ASSERT(FALSE); + status = A_EINVAL; + break; + } + + /* read the credit counter. At startup the target will set the credit counter + * to the max available, we read this in a loop because it may take + * multiple credit counter reads to get all credits */ + + while (creditPollCount) { + + credits = 0; + + status = DevGMboxReadCreditCounter(pProt->pDev, PROC_IO_SYNC, &credits); + + if (A_FAILED(status)) { + break; + } + + if (!gotCredits && (0 == credits)) { + creditPollCount--; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: credit is 0, retrying (%d) \n",creditPollCount)); + A_MDELAY(HCI_DELAY_PER_INTERVAL_MS); + continue; + } else { + gotCredits = TRUE; + } + + if (0 == credits) { + break; + } + + pProt->CreditsMax += credits; + } + + if (A_FAILED(status)) { + break; + } + + if (0 == creditPollCount) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("** HCI : Failed to get credits! GMBOX Target was not available \n")); + status = A_ERROR; + break; + } + + /* now get the size */ + status = DevGMboxReadCreditSize(pProt->pDev, &pProt->CreditSize); + + if (A_FAILED(status)) { + break; + } + + } while (FALSE); + + if (A_SUCCESS(status)) { + pProt->CreditsAvailable = pProt->CreditsMax; + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("HCI : InitTxCreditState - credits avail: %d, size: %d \n", + pProt->CreditsAvailable, pProt->CreditSize)); + } + + return status; +} + +static A_STATUS CreditsAvailableCallback(void *pContext, int Credits, A_BOOL CreditIRQEnabled) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)pContext; + A_BOOL enableCreditIrq = FALSE; + A_BOOL disableCreditIrq = FALSE; + A_BOOL doPendingSends = FALSE; + A_STATUS status = A_OK; + + /** this callback is called under 2 conditions: + * 1. The credit IRQ interrupt was enabled and signaled. + * 2. A credit counter read completed. + * + * The function must not assume that the calling context can block ! + */ + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+CreditsAvailableCallback (Credits:%d, IRQ:%s) \n", + Credits, CreditIRQEnabled ? "ON" : "OFF")); + + LOCK_HCI_TX(pProt); + + do { + + if (0 == Credits) { + if (!CreditIRQEnabled) { + /* enable credit IRQ */ + enableCreditIrq = TRUE; + } + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: current credit state, consumed:%d available:%d max:%d seek:%d\n", + pProt->CreditsConsumed, + pProt->CreditsAvailable, + pProt->CreditsMax, + pProt->CreditsCurrentSeek)); + + pProt->CreditsAvailable += Credits; + A_ASSERT(pProt->CreditsAvailable <= pProt->CreditsMax); + pProt->CreditsConsumed -= Credits; + A_ASSERT(pProt->CreditsConsumed >= 0); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: new credit state, consumed:%d available:%d max:%d seek:%d\n", + pProt->CreditsConsumed, + pProt->CreditsAvailable, + pProt->CreditsMax, + pProt->CreditsCurrentSeek)); + + if (pProt->CreditsAvailable >= pProt->CreditsCurrentSeek) { + /* we have enough credits to fullfill at least 1 packet waiting in the queue */ + pProt->CreditsCurrentSeek = 0; + pProt->SendStateFlags &= ~HCI_SEND_WAIT_CREDITS; + doPendingSends = TRUE; + if (CreditIRQEnabled) { + /* credit IRQ was enabled, we shouldn't need it anymore */ + disableCreditIrq = TRUE; + } + } else { + /* not enough credits yet, enable credit IRQ if we haven't already */ + if (!CreditIRQEnabled) { + enableCreditIrq = TRUE; + } + } + + } while (FALSE); + + UNLOCK_HCI_TX(pProt); + + if (enableCreditIrq) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" Enabling credit count IRQ...\n")); + /* must use async only */ + status = DevGMboxIRQAction(pProt->pDev, GMBOX_CREDIT_IRQ_ENABLE, PROC_IO_ASYNC); + } else if (disableCreditIrq) { + /* must use async only */ + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" Disabling credit count IRQ...\n")); + status = DevGMboxIRQAction(pProt->pDev, GMBOX_CREDIT_IRQ_DISABLE, PROC_IO_ASYNC); + } + + if (doPendingSends) { + HCITrySend(pProt, NULL, FALSE); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+CreditsAvailableCallback \n")); + return status; +} + +static INLINE void NotifyTransportFailure(GMBOX_PROTO_HCI_UART *pProt, A_STATUS status) +{ + if (pProt->HCIConfig.TransportFailure != NULL) { + pProt->HCIConfig.TransportFailure(pProt->HCIConfig.pContext, status); + } +} + +static void FailureCallback(void *pContext, A_STATUS Status) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)pContext; + + /* target assertion occured */ + NotifyTransportFailure(pProt, Status); +} + +static void StateDumpCallback(void *pContext) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)pContext; + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("============ HCIUart State ======================\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("RecvStateFlags : 0x%X \n",pProt->RecvStateFlags)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("SendStateFlags : 0x%X \n",pProt->SendStateFlags)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("WaitBufferType : %d \n",pProt->WaitBufferType)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("SendQueue Depth : %d \n",HTC_PACKET_QUEUE_DEPTH(&pProt->SendQueue))); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("CreditsMax : %d \n",pProt->CreditsMax)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("CreditsConsumed : %d \n",pProt->CreditsConsumed)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("CreditsAvailable : %d \n",pProt->CreditsAvailable)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("==================================================\n")); +} + +static A_STATUS HCIUartMessagePending(void *pContext, A_UINT8 LookAheadBytes[], int ValidBytes) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)pContext; + A_STATUS status = A_OK; + int totalRecvLength = 0; + HCI_TRANSPORT_PACKET_TYPE pktType = HCI_PACKET_INVALID; + A_BOOL recvRefillCalled = FALSE; + A_BOOL blockRecv = FALSE; + HTC_PACKET *pPacket = NULL; + + /** caller guarantees that this is a fully block-able context (synch I/O is allowed) */ + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HCIUartMessagePending Lookahead Bytes:%d \n",ValidBytes)); + + LOCK_HCI_RX(pProt); + + do { + + if (ValidBytes < 3) { + /* not enough for ACL or event header */ + break; + } + + if ((LookAheadBytes[0] == HCI_UART_ACL_PKT) && (ValidBytes < 5)) { + /* not enough for ACL data header */ + break; + } + + switch (LookAheadBytes[0]) { + case HCI_UART_EVENT_PKT: + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI Event: %d param length: %d \n", + LookAheadBytes[1], LookAheadBytes[2])); + totalRecvLength = LookAheadBytes[2]; + totalRecvLength += 3; /* add type + event code + length field */ + pktType = HCI_EVENT_TYPE; + break; + case HCI_UART_ACL_PKT: + totalRecvLength = (LookAheadBytes[4] << 8) | LookAheadBytes[3]; + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI ACL: conn:0x%X length: %d \n", + ((LookAheadBytes[2] & 0xF0) << 8) | LookAheadBytes[1], totalRecvLength)); + totalRecvLength += 5; /* add type + connection handle + length field */ + pktType = HCI_ACL_TYPE; + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("**Invalid HCI packet type: %d \n",LookAheadBytes[0])); + status = A_EPROTO; + break; + } + + if (A_FAILED(status)) { + break; + } + + if (pProt->HCIConfig.pHCIPktRecvAlloc != NULL) { + UNLOCK_HCI_RX(pProt); + /* user is using a per-packet allocation callback */ + pPacket = pProt->HCIConfig.pHCIPktRecvAlloc(pProt->HCIConfig.pContext, + pktType, + totalRecvLength); + LOCK_HCI_RX(pProt); + + } else { + HTC_PACKET_QUEUE *pQueue; + /* user is using a refill handler that can refill multiple HTC buffers */ + + /* select buffer queue */ + if (pktType == HCI_ACL_TYPE) { + pQueue = &pProt->HCIACLRecvBuffers; + } else { + pQueue = &pProt->HCIEventBuffers; + } + + if (HTC_QUEUE_EMPTY(pQueue)) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("** HCI pkt type: %d has no buffers available calling allocation handler \n", + pktType)); + /* check for refill handler */ + if (pProt->HCIConfig.pHCIPktRecvRefill != NULL) { + recvRefillCalled = TRUE; + UNLOCK_HCI_RX(pProt); + /* call the re-fill handler */ + pProt->HCIConfig.pHCIPktRecvRefill(pProt->HCIConfig.pContext, + pktType, + 0); + LOCK_HCI_RX(pProt); + /* check if we have more buffers */ + pPacket = HTC_PACKET_DEQUEUE(pQueue); + /* fall through */ + } + } else { + pPacket = HTC_PACKET_DEQUEUE(pQueue); + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("HCI pkt type: %d now has %d recv buffers left \n", + pktType, HTC_PACKET_QUEUE_DEPTH(pQueue))); + } + } + + if (NULL == pPacket) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("** HCI pkt type: %d has no buffers available stopping recv...\n", pktType)); + /* this is not an error, we simply need to mark that we are waiting for buffers.*/ + pProt->RecvStateFlags |= HCI_RECV_WAIT_BUFFERS; + pProt->WaitBufferType = pktType; + blockRecv = TRUE; + break; + } + + if (totalRecvLength > (int)pPacket->BufferLength) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** HCI-UART pkt: %d requires %d bytes (%d buffer bytes avail) ! \n", + LookAheadBytes[0], totalRecvLength, pPacket->BufferLength)); + status = A_EINVAL; + break; + } + + } while (FALSE); + + UNLOCK_HCI_RX(pProt); + + /* locks are released, we can go fetch the packet */ + + do { + + if (A_FAILED(status) || (NULL == pPacket)) { + break; + } + + /* do this synchronously, we don't need to be fast here */ + pPacket->Completion = NULL; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI : getting recv packet len:%d hci-uart-type: %s \n", + totalRecvLength, (LookAheadBytes[0] == HCI_UART_EVENT_PKT) ? "EVENT" : "ACL")); + + status = DevGMboxRead(pProt->pDev, pPacket, totalRecvLength); + + if (A_FAILED(status)) { + break; + } + + if (pPacket->pBuffer[0] != LookAheadBytes[0]) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** HCI buffer does not contain expected packet type: %d ! \n", + pPacket->pBuffer[0])); + status = A_EPROTO; + break; + } + + if (pPacket->pBuffer[0] == HCI_UART_EVENT_PKT) { + /* validate event header fields */ + if ((pPacket->pBuffer[1] != LookAheadBytes[1]) || + (pPacket->pBuffer[2] != LookAheadBytes[2])) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** HCI buffer does not match lookahead! \n")); + DebugDumpBytes(LookAheadBytes, 3, "Expected HCI-UART Header"); + DebugDumpBytes(pPacket->pBuffer, 3, "** Bad HCI-UART Header"); + status = A_EPROTO; + break; + } + } else if (pPacket->pBuffer[0] == HCI_UART_ACL_PKT) { + /* validate acl header fields */ + if ((pPacket->pBuffer[1] != LookAheadBytes[1]) || + (pPacket->pBuffer[2] != LookAheadBytes[2]) || + (pPacket->pBuffer[3] != LookAheadBytes[3]) || + (pPacket->pBuffer[4] != LookAheadBytes[4])) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** HCI buffer does not match lookahead! \n")); + DebugDumpBytes(LookAheadBytes, 5, "Expected HCI-UART Header"); + DebugDumpBytes(pPacket->pBuffer, 5, "** Bad HCI-UART Header"); + status = A_EPROTO; + break; + } + } + + /* adjust buffer to move past packet ID */ + pPacket->pBuffer++; + pPacket->ActualLength = totalRecvLength - 1; + pPacket->Status = A_OK; + /* indicate packet */ + DO_HCI_RECV_INDICATION(pProt,pPacket); + pPacket = NULL; + + /* check if we need to refill recv buffers */ + if ((pProt->HCIConfig.pHCIPktRecvRefill != NULL) && !recvRefillCalled) { + HTC_PACKET_QUEUE *pQueue; + int watermark; + + if (pktType == HCI_ACL_TYPE) { + watermark = pProt->HCIConfig.ACLRecvBufferWaterMark; + pQueue = &pProt->HCIACLRecvBuffers; + } else { + watermark = pProt->HCIConfig.EventRecvBufferWaterMark; + pQueue = &pProt->HCIEventBuffers; + } + + if (HTC_PACKET_QUEUE_DEPTH(pQueue) < watermark) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("** HCI pkt type: %d watermark hit (%d) current:%d \n", + pktType, watermark, HTC_PACKET_QUEUE_DEPTH(pQueue))); + /* call the re-fill handler */ + pProt->HCIConfig.pHCIPktRecvRefill(pProt->HCIConfig.pContext, + pktType, + HTC_PACKET_QUEUE_DEPTH(pQueue)); + } + } + + } while (FALSE); + + /* check if we need to disable the reciever */ + if (A_FAILED(status) || blockRecv) { + DevGMboxIRQAction(pProt->pDev, GMBOX_RECV_IRQ_DISABLE, PROC_IO_SYNC); + } + + /* see if we need to recycle the recv buffer */ + if (A_FAILED(status) && (pPacket != NULL)) { + HTC_PACKET_QUEUE queue = { {0} }; + + if (A_EPROTO == status) { + DebugDumpBytes(pPacket->pBuffer, totalRecvLength, "Bad HCI-UART Recv packet"); + } + /* recycle packet */ + HTC_PACKET_RESET_RX(pPacket); + INIT_HTC_PACKET_QUEUE_AND_ADD(&queue,pPacket); + HCI_TransportAddReceivePkts(pProt,&queue); + NotifyTransportFailure(pProt,status); + } + + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HCIUartMessagePending \n")); + + return status; +} + +static void HCISendPacketCompletion(void *Context, HTC_PACKET *pPacket) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)Context; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCISendPacketCompletion (pPacket:0x%lX) \n",(unsigned long)pPacket)); + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Send Packet (0x%lX) failed: %d , len:%d \n", + (unsigned long)pPacket, pPacket->Status, pPacket->ActualLength)); + } + + DO_HCI_SEND_INDICATION(pProt,pPacket); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCISendPacketCompletion \n")); +} + +static A_STATUS SeekCreditsSynch(GMBOX_PROTO_HCI_UART *pProt) +{ + A_STATUS status = A_OK; + int credits; + int retry = 100; + + while (TRUE) { + credits = 0; + status = DevGMboxReadCreditCounter(pProt->pDev, PROC_IO_SYNC, &credits); + if (A_FAILED(status)) { + break; + } + LOCK_HCI_TX(pProt); + pProt->CreditsAvailable += credits; + pProt->CreditsConsumed -= credits; + if (pProt->CreditsAvailable >= pProt->CreditsCurrentSeek) { + pProt->CreditsCurrentSeek = 0; + UNLOCK_HCI_TX(pProt); + break; + } + UNLOCK_HCI_TX(pProt); + retry--; + if (0 == retry) { + status = A_EBUSY; + break; + } + A_MDELAY(20); + } + + return status; +} + +static A_STATUS HCITrySend(GMBOX_PROTO_HCI_UART *pProt, HTC_PACKET *pPacket, A_BOOL Synchronous) +{ + A_STATUS status = A_OK; + int transferLength; + int creditsRequired, remainder; + A_UINT8 hciUartType; + A_BOOL synchSendComplete = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCITrySend (pPacket:0x%lX) %s \n",(unsigned long)pPacket, + Synchronous ? "SYNC" :"ASYNC")); + + LOCK_HCI_TX(pProt); + + /* increment write processing count on entry */ + pProt->SendProcessCount++; + + do { + + if (pProt->HCIStopped) { + status = A_ECANCELED; + break; + } + + if (pPacket != NULL) { + /* packet was supplied */ + if (Synchronous) { + /* in synchronous mode, the send queue can only hold 1 packet */ + if (!HTC_QUEUE_EMPTY(&pProt->SendQueue)) { + status = A_EBUSY; + A_ASSERT(FALSE); + break; + } + + if (pProt->SendProcessCount > 1) { + /* another thread or task is draining the TX queues */ + status = A_EBUSY; + A_ASSERT(FALSE); + break; + } + + HTC_PACKET_ENQUEUE(&pProt->SendQueue,pPacket); + + } else { + /* see if adding this packet hits the max depth (asynchronous mode only) */ + if ((pProt->HCIConfig.MaxSendQueueDepth > 0) && + ((HTC_PACKET_QUEUE_DEPTH(&pProt->SendQueue) + 1) >= pProt->HCIConfig.MaxSendQueueDepth)) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("HCI Send queue is full, Depth:%d, Max:%d \n", + HTC_PACKET_QUEUE_DEPTH(&pProt->SendQueue), + pProt->HCIConfig.MaxSendQueueDepth)); + /* queue will be full, invoke any callbacks to determine what action to take */ + if (pProt->HCIConfig.pHCISendFull != NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + ("HCI : Calling driver's send full callback.... \n")); + if (pProt->HCIConfig.pHCISendFull(pProt->HCIConfig.pContext, + pPacket) == HCI_SEND_FULL_DROP) { + /* drop it */ + status = A_NO_RESOURCE; + break; + } + } + } + + HTC_PACKET_ENQUEUE(&pProt->SendQueue,pPacket); + } + + } + + if (pProt->SendStateFlags & HCI_SEND_WAIT_CREDITS) { + break; + } + + if (pProt->SendProcessCount > 1) { + /* another thread or task is draining the TX queues */ + break; + } + + /***** beyond this point only 1 thread may enter ******/ + + /* now drain the send queue for transmission as long as we have enough + * credits */ + while (!HTC_QUEUE_EMPTY(&pProt->SendQueue)) { + + pPacket = HTC_PACKET_DEQUEUE(&pProt->SendQueue); + + switch (HCI_GET_PACKET_TYPE(pPacket)) { + case HCI_COMMAND_TYPE: + hciUartType = HCI_UART_COMMAND_PKT; + break; + case HCI_ACL_TYPE: + hciUartType = HCI_UART_ACL_PKT; + break; + default: + status = A_EINVAL; + A_ASSERT(FALSE); + break; + } + + if (A_FAILED(status)) { + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: Got head packet:0x%lX , Type:%d Length: %d Remaining Queue Depth: %d\n", + (unsigned long)pPacket, HCI_GET_PACKET_TYPE(pPacket), pPacket->ActualLength, + HTC_PACKET_QUEUE_DEPTH(&pProt->SendQueue))); + + transferLength = 1; /* UART type header is 1 byte */ + transferLength += pPacket->ActualLength; + transferLength = DEV_CALC_SEND_PADDED_LEN(pProt->pDev, transferLength); + + /* figure out how many credits this message requires */ + creditsRequired = transferLength / pProt->CreditSize; + remainder = transferLength % pProt->CreditSize; + + if (remainder) { + creditsRequired++; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: Creds Required:%d Got:%d\n", + creditsRequired, pProt->CreditsAvailable)); + + if (creditsRequired > pProt->CreditsAvailable) { + if (Synchronous) { + /* in synchronous mode we need to seek credits in synchronously */ + pProt->CreditsCurrentSeek = creditsRequired; + UNLOCK_HCI_TX(pProt); + status = SeekCreditsSynch(pProt); + LOCK_HCI_TX(pProt); + if (A_FAILED(status)) { + break; + } + /* fall through and continue processing this send op */ + } else { + /* not enough credits, queue back to the head */ + HTC_PACKET_ENQUEUE_TO_HEAD(&pProt->SendQueue,pPacket); + /* waiting for credits */ + pProt->SendStateFlags |= HCI_SEND_WAIT_CREDITS; + /* provide a hint to reduce attempts to re-send if credits are dribbling back + * this hint is the short fall of credits */ + pProt->CreditsCurrentSeek = creditsRequired; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: packet:0x%lX placed back in queue. head packet needs: %d credits \n", + (unsigned long)pPacket, pProt->CreditsCurrentSeek)); + pPacket = NULL; + UNLOCK_HCI_TX(pProt); + + /* schedule a credit counter read, our CreditsAvailableCallback callback will be called + * with the result */ + DevGMboxReadCreditCounter(pProt->pDev, PROC_IO_ASYNC, NULL); + + LOCK_HCI_TX(pProt); + break; + } + } + + /* caller guarantees some head room */ + pPacket->pBuffer--; + pPacket->pBuffer[0] = hciUartType; + + pProt->CreditsAvailable -= creditsRequired; + pProt->CreditsConsumed += creditsRequired; + A_ASSERT(pProt->CreditsConsumed <= pProt->CreditsMax); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: new credit state: consumed:%d available:%d max:%d\n", + pProt->CreditsConsumed, pProt->CreditsAvailable, pProt->CreditsMax)); + + UNLOCK_HCI_TX(pProt); + + /* write it out */ + if (Synchronous) { + pPacket->Completion = NULL; + pPacket->pContext = NULL; + } else { + pPacket->Completion = HCISendPacketCompletion; + pPacket->pContext = pProt; + } + + status = DevGMboxWrite(pProt->pDev,pPacket,transferLength); + if (Synchronous) { + synchSendComplete = TRUE; + } else { + pPacket = NULL; + } + + LOCK_HCI_TX(pProt); + + } + + } while (FALSE); + + pProt->SendProcessCount--; + A_ASSERT(pProt->SendProcessCount >= 0); + UNLOCK_HCI_TX(pProt); + + if (Synchronous) { + A_ASSERT(pPacket != NULL); + if (A_SUCCESS(status) && (!synchSendComplete)) { + status = A_EBUSY; + A_ASSERT(FALSE); + LOCK_HCI_TX(pProt); + + if (pPacket) + { + if (pPacket->ListLink.pNext != NULL) { + /* remove from the queue */ + HTC_PACKET_REMOVE(&pProt->SendQueue,pPacket); + } + } + UNLOCK_HCI_TX(pProt); + } + } else { + if (A_FAILED(status) && (pPacket != NULL)) { + pPacket->Status = status; + DO_HCI_SEND_INDICATION(pProt,pPacket); + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HCITrySend: \n")); + return status; +} + +static void FlushSendQueue(GMBOX_PROTO_HCI_UART *pProt) +{ + HTC_PACKET *pPacket; + HTC_PACKET_QUEUE discardQueue = { {0} }; + + INIT_HTC_PACKET_QUEUE(&discardQueue); + + LOCK_HCI_TX(pProt); + + if (!HTC_QUEUE_EMPTY(&pProt->SendQueue)) { + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&discardQueue,&pProt->SendQueue); + } + + UNLOCK_HCI_TX(pProt); + + /* discard packets */ + while (!HTC_QUEUE_EMPTY(&discardQueue)) { + pPacket = HTC_PACKET_DEQUEUE(&discardQueue); + pPacket->Status = A_ECANCELED; + DO_HCI_SEND_INDICATION(pProt,pPacket); + } + +} + +static void FlushRecvBuffers(GMBOX_PROTO_HCI_UART *pProt) +{ + HTC_PACKET_QUEUE discardQueue = { {0} }; + HTC_PACKET *pPacket; + + INIT_HTC_PACKET_QUEUE(&discardQueue); + + LOCK_HCI_RX(pProt); + /*transfer list items from ACL and event buffer queues to the discard queue */ + if (!HTC_QUEUE_EMPTY(&pProt->HCIACLRecvBuffers)) { + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&discardQueue,&pProt->HCIACLRecvBuffers); + } + if (!HTC_QUEUE_EMPTY(&pProt->HCIEventBuffers)) { + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&discardQueue,&pProt->HCIEventBuffers); + } + UNLOCK_HCI_RX(pProt); + + /* now empty the discard queue */ + while (!HTC_QUEUE_EMPTY(&discardQueue)) { + pPacket = HTC_PACKET_DEQUEUE(&discardQueue); + pPacket->Status = A_ECANCELED; + DO_HCI_RECV_INDICATION(pProt,pPacket); + } + +} + +/*** protocol module install entry point ***/ + +A_STATUS GMboxProtocolInstall(AR6K_DEVICE *pDev) +{ + A_STATUS status = A_OK; + GMBOX_PROTO_HCI_UART *pProtocol = NULL; + + do { + + pProtocol = A_MALLOC(sizeof(GMBOX_PROTO_HCI_UART)); + + if (NULL == pProtocol) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pProtocol, sizeof(*pProtocol)); + pProtocol->pDev = pDev; + INIT_HTC_PACKET_QUEUE(&pProtocol->SendQueue); + INIT_HTC_PACKET_QUEUE(&pProtocol->HCIACLRecvBuffers); + INIT_HTC_PACKET_QUEUE(&pProtocol->HCIEventBuffers); + A_MUTEX_INIT(&pProtocol->HCIRxLock); + A_MUTEX_INIT(&pProtocol->HCITxLock); + + } while (FALSE); + + if (A_SUCCESS(status)) { + LOCK_AR6K(pDev); + DEV_GMBOX_SET_PROTOCOL(pDev, + HCIUartMessagePending, + CreditsAvailableCallback, + FailureCallback, + StateDumpCallback, + pProtocol); + UNLOCK_AR6K(pDev); + } else { + if (pProtocol != NULL) { + HCIUartCleanup(pProtocol); + } + } + + return status; +} + +/*** protocol module uninstall entry point ***/ +void GMboxProtocolUninstall(AR6K_DEVICE *pDev) +{ + GMBOX_PROTO_HCI_UART *pProtocol = (GMBOX_PROTO_HCI_UART *)DEV_GMBOX_GET_PROTOCOL(pDev); + + if (pProtocol != NULL) { + + /* notify anyone attached */ + if (pProtocol->HCIAttached) { + A_ASSERT(pProtocol->HCIConfig.TransportRemoved != NULL); + pProtocol->HCIConfig.TransportRemoved(pProtocol->HCIConfig.pContext); + pProtocol->HCIAttached = FALSE; + } + + HCIUartCleanup(pProtocol); + DEV_GMBOX_SET_PROTOCOL(pDev,NULL,NULL,NULL,NULL,NULL); + } + +} + +static A_STATUS NotifyTransportReady(GMBOX_PROTO_HCI_UART *pProt) +{ + HCI_TRANSPORT_PROPERTIES props; + A_STATUS status = A_OK; + + do { + + A_MEMZERO(&props,sizeof(props)); + + /* HCI UART only needs one extra byte at the head to indicate the packet TYPE */ + props.HeadRoom = 1; + props.TailRoom = 0; + props.IOBlockPad = pProt->pDev->BlockSize; + if (pProt->HCIAttached) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("HCI: notifying attached client to transport... \n")); + A_ASSERT(pProt->HCIConfig.TransportReady != NULL); + status = pProt->HCIConfig.TransportReady(pProt, + &props, + pProt->HCIConfig.pContext); + } + + } while (FALSE); + + return status; +} + +/*********** HCI UART protocol implementation ************************************************/ + +HCI_TRANSPORT_HANDLE HCI_TransportAttach(void *HTCHandle, HCI_TRANSPORT_CONFIG_INFO *pInfo) +{ + GMBOX_PROTO_HCI_UART *pProtocol = NULL; + AR6K_DEVICE *pDev; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportAttach \n")); + + pDev = HTCGetAR6KDevice(HTCHandle); + + LOCK_AR6K(pDev); + + do { + + pProtocol = (GMBOX_PROTO_HCI_UART *)DEV_GMBOX_GET_PROTOCOL(pDev); + + if (NULL == pProtocol) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("GMBOX protocol not installed! \n")); + break; + } + + if (pProtocol->HCIAttached) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("GMBOX protocol already attached! \n")); + break; + } + + A_MEMCPY(&pProtocol->HCIConfig, pInfo, sizeof(HCI_TRANSPORT_CONFIG_INFO)); + + A_ASSERT(pProtocol->HCIConfig.pHCIPktRecv != NULL); + A_ASSERT(pProtocol->HCIConfig.pHCISendComplete != NULL); + + pProtocol->HCIAttached = TRUE; + + } while (FALSE); + + UNLOCK_AR6K(pDev); + + if (pProtocol != NULL) { + /* TODO ... should we use a worker? */ + NotifyTransportReady(pProtocol); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportAttach (0x%lX) \n",(unsigned long)pProtocol)); + return (HCI_TRANSPORT_HANDLE)pProtocol; +} + +void HCI_TransportDetach(HCI_TRANSPORT_HANDLE HciTrans) +{ + GMBOX_PROTO_HCI_UART *pProtocol = (GMBOX_PROTO_HCI_UART *)HciTrans; + AR6K_DEVICE *pDev = pProtocol->pDev; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportDetach \n")); + + LOCK_AR6K(pDev); + if (!pProtocol->HCIAttached) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("GMBOX protocol not attached! \n")); + UNLOCK_AR6K(pDev); + return; + } + pProtocol->HCIAttached = FALSE; + UNLOCK_AR6K(pDev); + + HCI_TransportStop(HciTrans); + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportAttach \n")); +} + +A_STATUS HCI_TransportAddReceivePkts(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET_QUEUE *pQueue) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + A_STATUS status = A_OK; + A_BOOL unblockRecv = FALSE; + HTC_PACKET *pPacket; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HCI_TransportAddReceivePkt \n")); + + LOCK_HCI_RX(pProt); + + do { + + if (pProt->HCIStopped) { + status = A_ECANCELED; + break; + } + + pPacket = HTC_GET_PKT_AT_HEAD(pQueue); + + if (NULL == pPacket) { + status = A_EINVAL; + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" HCI recv packet added, type :%d, len:%d num:%d \n", + HCI_GET_PACKET_TYPE(pPacket), pPacket->BufferLength, HTC_PACKET_QUEUE_DEPTH(pQueue))); + + if (HCI_GET_PACKET_TYPE(pPacket) == HCI_EVENT_TYPE) { + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pProt->HCIEventBuffers, pQueue); + } else if (HCI_GET_PACKET_TYPE(pPacket) == HCI_ACL_TYPE) { + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pProt->HCIACLRecvBuffers, pQueue); + } else { + status = A_EINVAL; + break; + } + + if (pProt->RecvStateFlags & HCI_RECV_WAIT_BUFFERS) { + if (pProt->WaitBufferType == HCI_GET_PACKET_TYPE(pPacket)) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" HCI recv was blocked on packet type :%d, unblocking.. \n", + pProt->WaitBufferType)); + pProt->RecvStateFlags &= ~HCI_RECV_WAIT_BUFFERS; + pProt->WaitBufferType = HCI_PACKET_INVALID; + unblockRecv = TRUE; + } + } + + } while (FALSE); + + UNLOCK_HCI_RX(pProt); + + if (A_FAILED(status)) { + while (!HTC_QUEUE_EMPTY(pQueue)) { + pPacket = HTC_PACKET_DEQUEUE(pQueue); + pPacket->Status = A_ECANCELED; + DO_HCI_RECV_INDICATION(pProt,pPacket); + } + } + + if (unblockRecv) { + DevGMboxIRQAction(pProt->pDev, GMBOX_RECV_IRQ_ENABLE, PROC_IO_ASYNC); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HCI_TransportAddReceivePkt \n")); + + return A_OK; +} + +A_STATUS HCI_TransportSendPkt(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET *pPacket, A_BOOL Synchronous) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + + return HCITrySend(pProt,pPacket,Synchronous); +} + +void HCI_TransportStop(HCI_TRANSPORT_HANDLE HciTrans) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportStop \n")); + + LOCK_AR6K(pProt->pDev); + if (pProt->HCIStopped) { + UNLOCK_AR6K(pProt->pDev); + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStop \n")); + return; + } + pProt->CreditsAvailable = 0; + pProt->CreditsMax = 0; + pProt->HCIStopped = TRUE; + UNLOCK_AR6K(pProt->pDev); + + /* disable interrupts */ + DevGMboxIRQAction(pProt->pDev, GMBOX_DISABLE_ALL, PROC_IO_SYNC); + FlushSendQueue(pProt); + FlushRecvBuffers(pProt); + + /* signal bridge side to power down BT */ + DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_BT_OFF, BTOFF_TIMEOUT_MS); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStop \n")); +} + +A_STATUS HCI_TransportStart(HCI_TRANSPORT_HANDLE HciTrans) +{ + A_STATUS status; + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportStart \n")); + + /* set stopped in case we have a problem in starting */ + pProt->HCIStopped = TRUE; + + do { + + status = InitTxCreditState(pProt); + + if (A_FAILED(status)) { + break; + } + + status = DevGMboxIRQAction(pProt->pDev, GMBOX_ERRORS_IRQ_ENABLE, PROC_IO_SYNC); + + if (A_FAILED(status)) { + break; + } + /* enable recv */ + status = DevGMboxIRQAction(pProt->pDev, GMBOX_RECV_IRQ_ENABLE, PROC_IO_SYNC); + + if (A_FAILED(status)) { + break; + } + /* signal bridge side to power up BT */ + status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_BT_ON, BTON_TIMEOUT_MS); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI_TransportStart : Failed to trigger BT ON \n")); + break; + } + + /* we made it */ + pProt->HCIStopped = FALSE; + + } while (FALSE); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStart \n")); + + return status; +} + +A_STATUS HCI_TransportEnableDisableAsyncRecv(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + return DevGMboxIRQAction(pProt->pDev, + Enable ? GMBOX_RECV_IRQ_ENABLE : GMBOX_RECV_IRQ_DISABLE, + PROC_IO_SYNC); + +} + +A_STATUS HCI_TransportRecvHCIEventSync(HCI_TRANSPORT_HANDLE HciTrans, + HTC_PACKET *pPacket, + int MaxPollMS) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + A_STATUS status = A_OK; + A_UINT8 lookAhead[8]; + int bytes; + int totalRecvLength; + + MaxPollMS = MaxPollMS / 16; + + if (MaxPollMS < 2) { + MaxPollMS = 2; + } + + while (MaxPollMS) { + + bytes = sizeof(lookAhead); + status = DevGMboxRecvLookAheadPeek(pProt->pDev,lookAhead,&bytes); + if (A_FAILED(status)) { + break; + } + + if (bytes < 3) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI recv poll got bytes: %d, retry : %d \n", + bytes, MaxPollMS)); + A_MDELAY(16); + MaxPollMS--; + continue; + } + + totalRecvLength = 0; + switch (lookAhead[0]) { + case HCI_UART_EVENT_PKT: + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI Event: %d param length: %d \n", + lookAhead[1], lookAhead[2])); + totalRecvLength = lookAhead[2]; + totalRecvLength += 3; /* add type + event code + length field */ + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("**Invalid HCI packet type: %d \n",lookAhead[0])); + status = A_EPROTO; + break; + } + + if (A_FAILED(status)) { + break; + } + + pPacket->Completion = NULL; + status = DevGMboxRead(pProt->pDev,pPacket,totalRecvLength); + if (A_FAILED(status)) { + break; + } + + pPacket->pBuffer++; + pPacket->ActualLength = totalRecvLength - 1; + pPacket->Status = A_OK; + break; + } + + if (MaxPollMS == 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI recv poll timeout! \n")); + status = A_ERROR; + } + + return status; +} + +A_STATUS HCI_TransportSetBaudRate(HCI_TRANSPORT_HANDLE HciTrans, A_UINT32 Baud) +{ + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + HIF_DEVICE *pHIFDevice = (HIF_DEVICE *)(pProt->pDev->HIFDevice); + A_UINT32 scaledBaud, scratchAddr; + A_STATUS status = A_OK; + + /* Divide the desired baud rate by 100 + * Store the LSB in the local scratch register 4 and the MSB in the local + * scratch register 5 for the target to read + */ + scratchAddr = MBOX_BASE_ADDRESS | (LOCAL_SCRATCH_ADDRESS + 4 * LSB_SCRATCH_IDX); + scaledBaud = (Baud / 100) & LOCAL_SCRATCH_VALUE_MASK; + status = ar6000_WriteRegDiag(pHIFDevice, &scratchAddr, &scaledBaud); + scratchAddr = MBOX_BASE_ADDRESS | (LOCAL_SCRATCH_ADDRESS + 4 * MSB_SCRATCH_IDX); + scaledBaud = ((Baud / 100) >> (LOCAL_SCRATCH_VALUE_MSB+1)) & LOCAL_SCRATCH_VALUE_MASK; + status |= ar6000_WriteRegDiag(pHIFDevice, &scratchAddr, &scaledBaud); + if (A_OK != status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to set up baud rate in scratch register!")); + return status; + } + + /* Now interrupt the target to tell it about the baud rate */ + status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_BAUD_SET, BAUD_TIMEOUT_MS); + if (A_OK != status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to tell target to change baud rate!")); + } + + return status; +} + +A_STATUS HCI_TransportEnablePowerMgmt(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable) +{ + A_STATUS status; + GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; + + if (Enable) { + status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_PWR_SAV_ON, BTPWRSAV_TIMEOUT_MS); + } else { + status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_PWR_SAV_OFF, BTPWRSAV_TIMEOUT_MS); + } + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to enable/disable HCI power management!\n")); + } else { + if (Enable) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI power management ENABLED!\n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI power management DISABLED!\n")); + } + } + + return status; +} + +#endif //ATH_AR6K_ENABLE_GMBOX + diff --git a/drivers/net/wireless/ar6003/host/htc2/AR6000/makefile b/drivers/net/wireless/ar6003/host/htc2/AR6000/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/AR6000/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/htc2/htc.c b/drivers/net/wireless/ar6003/host/htc2/htc.c new file mode 100644 index 000000000000..813b4ccbdad1 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc.c @@ -0,0 +1,578 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#include "htc_internal.h" + +#ifdef DEBUG +static ATH_DEBUG_MASK_DESCRIPTION g_HTCDebugDescription[] = { + { ATH_DEBUG_SEND , "Send"}, + { ATH_DEBUG_RECV , "Recv"}, + { ATH_DEBUG_SYNC , "Sync"}, + { ATH_DEBUG_DUMP , "Dump Data (RX or TX)"}, + { ATH_DEBUG_IRQ , "Interrupt Processing"} +}; + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(htc, + "htc", + "Host Target Communications", + ATH_DEBUG_MASK_DEFAULTS, + ATH_DEBUG_DESCRIPTION_COUNT(g_HTCDebugDescription), + g_HTCDebugDescription); + +#endif + +static void HTCReportFailure(void *Context); +static void ResetEndpointStates(HTC_TARGET *target); + +void HTCFreeControlBuffer(HTC_TARGET *target, HTC_PACKET *pPacket, HTC_PACKET_QUEUE *pList) +{ + LOCK_HTC(target); + HTC_PACKET_ENQUEUE(pList,pPacket); + UNLOCK_HTC(target); +} + +HTC_PACKET *HTCAllocControlBuffer(HTC_TARGET *target, HTC_PACKET_QUEUE *pList) +{ + HTC_PACKET *pPacket; + + LOCK_HTC(target); + pPacket = HTC_PACKET_DEQUEUE(pList); + UNLOCK_HTC(target); + + return pPacket; +} + +/* cleanup the HTC instance */ +static void HTCCleanup(HTC_TARGET *target) +{ + A_INT32 i; + + DevCleanup(&target->Device); + + for (i = 0;i < NUM_CONTROL_BUFFERS;i++) { + if (target->HTCControlBuffers[i].Buffer) { + A_FREE(target->HTCControlBuffers[i].Buffer); + } + } + + if (A_IS_MUTEX_VALID(&target->HTCLock)) { + A_MUTEX_DELETE(&target->HTCLock); + } + + if (A_IS_MUTEX_VALID(&target->HTCRxLock)) { + A_MUTEX_DELETE(&target->HTCRxLock); + } + + if (A_IS_MUTEX_VALID(&target->HTCTxLock)) { + A_MUTEX_DELETE(&target->HTCTxLock); + } + /* free our instance */ + A_FREE(target); +} + +/* registered target arrival callback from the HIF layer */ +HTC_HANDLE HTCCreate(void *hif_handle, HTC_INIT_INFO *pInfo) +{ + HTC_TARGET *target = NULL; + A_STATUS status = A_OK; + int i; + A_UINT32 ctrl_bufsz; + A_UINT32 blocksizes[HTC_MAILBOX_NUM_MAX]; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCCreate - Enter\n")); + + A_REGISTER_MODULE_DEBUG_INFO(htc); + + do { + + /* allocate target memory */ + if ((target = (HTC_TARGET *)A_MALLOC(sizeof(HTC_TARGET))) == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to allocate memory\n")); + status = A_ERROR; + break; + } + + A_MEMZERO(target, sizeof(HTC_TARGET)); + A_MUTEX_INIT(&target->HTCLock); + A_MUTEX_INIT(&target->HTCRxLock); + A_MUTEX_INIT(&target->HTCTxLock); + INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList); + INIT_HTC_PACKET_QUEUE(&target->ControlBufferRXFreeList); + + /* give device layer the hif device handle */ + target->Device.HIFDevice = hif_handle; + /* give the device layer our context (for event processing) + * the device layer will register it's own context with HIF + * so we need to set this so we can fetch it in the target remove handler */ + target->Device.HTCContext = target; + /* set device layer target failure callback */ + target->Device.TargetFailureCallback = HTCReportFailure; + /* set device layer recv message pending callback */ + target->Device.MessagePendingCallback = HTCRecvMessagePendingHandler; + target->EpWaitingForBuffers = ENDPOINT_MAX; + + A_MEMCPY(&target->HTCInitInfo,pInfo,sizeof(HTC_INIT_INFO)); + + ResetEndpointStates(target); + + /* setup device layer */ + status = DevSetup(&target->Device); + + if (A_FAILED(status)) { + break; + } + + + /* get the block sizes */ + status = HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_MBOX_BLOCK_SIZE, + blocksizes, sizeof(blocksizes)); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to get block size info from HIF layer...\n")); + break; + } + + /* Set the control buffer size based on the block size */ + if (blocksizes[1] > HTC_MAX_CONTROL_MESSAGE_LENGTH) { + ctrl_bufsz = blocksizes[1] + HTC_HDR_LENGTH; + } else { + ctrl_bufsz = HTC_MAX_CONTROL_MESSAGE_LENGTH + HTC_HDR_LENGTH; + } + for (i = 0;i < NUM_CONTROL_BUFFERS;i++) { + target->HTCControlBuffers[i].Buffer = A_MALLOC(ctrl_bufsz); + if (target->HTCControlBuffers[i].Buffer == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to allocate memory\n")); + status = A_ERROR; + break; + } + } + + if (A_FAILED(status)) { + break; + } + + /* carve up buffers/packets for control messages */ + for (i = 0; i < NUM_CONTROL_RX_BUFFERS; i++) { + HTC_PACKET *pControlPacket; + pControlPacket = &target->HTCControlBuffers[i].HtcPacket; + SET_HTC_PACKET_INFO_RX_REFILL(pControlPacket, + target, + target->HTCControlBuffers[i].Buffer, + ctrl_bufsz, + ENDPOINT_0); + HTC_FREE_CONTROL_RX(target,pControlPacket); + } + + for (;i < NUM_CONTROL_BUFFERS;i++) { + HTC_PACKET *pControlPacket; + pControlPacket = &target->HTCControlBuffers[i].HtcPacket; + INIT_HTC_PACKET_INFO(pControlPacket, + target->HTCControlBuffers[i].Buffer, + ctrl_bufsz); + HTC_FREE_CONTROL_TX(target,pControlPacket); + } + + } while (FALSE); + + if (A_FAILED(status)) { + if (target != NULL) { + HTCCleanup(target); + target = NULL; + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCCreate - Exit\n")); + + return target; +} + +void HTCDestroy(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCDestroy .. Destroying :0x%lX \n",(unsigned long)target)); + HTCCleanup(target); + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCDestroy \n")); +} + +/* get the low level HIF device for the caller , the caller may wish to do low level + * HIF requests */ +void *HTCGetHifDevice(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + return target->Device.HIFDevice; +} + +/* wait for the target to arrive (sends HTC Ready message) + * this operation is fully synchronous and the message is polled for */ +A_STATUS HTCWaitTarget(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + A_STATUS status; + HTC_PACKET *pPacket = NULL; + HTC_READY_EX_MSG *pRdyMsg; + HTC_SERVICE_CONNECT_REQ connect; + HTC_SERVICE_CONNECT_RESP resp; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCWaitTarget - Enter (target:0x%lX) \n", (unsigned long)target)); + + do { + +#ifdef MBOXHW_UNIT_TEST + + status = DoMboxHWTest(&target->Device); + + if (status != A_OK) { + break; + } + +#endif + + /* we should be getting 1 control message that the target is ready */ + status = HTCWaitforControlMessage(target, &pPacket); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, (" Target Not Available!!\n")); + break; + } + + /* we controlled the buffer creation so it has to be properly aligned */ + pRdyMsg = (HTC_READY_EX_MSG *)pPacket->pBuffer; + + if ((pRdyMsg->Version2_0_Info.MessageID != HTC_MSG_READY_ID) || + (pPacket->ActualLength < sizeof(HTC_READY_MSG))) { + /* this message is not valid */ + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + + if (pRdyMsg->Version2_0_Info.CreditCount == 0 || pRdyMsg->Version2_0_Info.CreditSize == 0) { + /* this message is not valid */ + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + target->TargetCredits = pRdyMsg->Version2_0_Info.CreditCount; + target->TargetCreditSize = pRdyMsg->Version2_0_Info.CreditSize; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (" Target Ready: credits: %d credit size: %d\n", + target->TargetCredits, target->TargetCreditSize)); + + /* check if this is an extended ready message */ + if (pPacket->ActualLength >= sizeof(HTC_READY_EX_MSG)) { + /* this is an extended message */ + target->HTCTargetVersion = pRdyMsg->HTCVersion; + target->MaxMsgPerBundle = pRdyMsg->MaxMsgsPerHTCBundle; + } else { + /* legacy */ + target->HTCTargetVersion = HTC_VERSION_2P0; + target->MaxMsgPerBundle = 0; + } + +#ifdef HTC_FORCE_LEGACY_2P0 + /* for testing and comparison...*/ + target->HTCTargetVersion = HTC_VERSION_2P0; + target->MaxMsgPerBundle = 0; +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, + ("Using HTC Protocol Version : %s (%d)\n ", + (target->HTCTargetVersion == HTC_VERSION_2P0) ? "2.0" : ">= 2.1", + target->HTCTargetVersion)); + + if (target->MaxMsgPerBundle > 0) { + /* limit what HTC can handle */ + target->MaxMsgPerBundle = min(HTC_HOST_MAX_MSG_PER_BUNDLE, target->MaxMsgPerBundle); + /* target supports message bundling, setup device layer */ + if (A_FAILED(DevSetupMsgBundling(&target->Device,target->MaxMsgPerBundle))) { + /* device layer can't handle bundling */ + target->MaxMsgPerBundle = 0; + } else { + /* limit bundle what the device layer can handle */ + target->MaxMsgPerBundle = min(DEV_GET_MAX_MSG_PER_BUNDLE(&target->Device), + target->MaxMsgPerBundle); + } + } + + if (target->MaxMsgPerBundle > 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, + (" HTC bundling allowed. Max Msg Per HTC Bundle: %d\n", target->MaxMsgPerBundle)); + target->SendBundlingEnabled = TRUE; + target->RecvBundlingEnabled = TRUE; + if (!DEV_IS_LEN_BLOCK_ALIGNED(&target->Device,target->TargetCreditSize)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("*** Credit size: %d is not block aligned! Disabling send bundling \n", + target->TargetCreditSize)); + /* disallow send bundling since the credit size is not aligned to a block size + * the I/O block padding will spill into the next credit buffer which is fatal */ + target->SendBundlingEnabled = FALSE; + } + } + + status = DevSetupGMbox(&target->Device); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, (" GMbox set up Failed!!\n")); + break; + } + + /* setup our pseudo HTC control endpoint connection */ + A_MEMZERO(&connect,sizeof(connect)); + A_MEMZERO(&resp,sizeof(resp)); + connect.EpCallbacks.pContext = target; + connect.EpCallbacks.EpTxComplete = HTCControlTxComplete; + connect.EpCallbacks.EpRecv = HTCControlRecv; + connect.EpCallbacks.EpRecvRefill = NULL; /* not needed */ + connect.EpCallbacks.EpSendFull = NULL; /* not nedded */ + connect.MaxSendQueueDepth = NUM_CONTROL_BUFFERS; + connect.ServiceID = HTC_CTRL_RSVD_SVC; + + /* connect fake service */ + status = HTCConnectService((HTC_HANDLE)target, + &connect, + &resp); + + if (!A_FAILED(status)) { + break; + } + + } while (FALSE); + + if (pPacket != NULL) { + HTC_FREE_CONTROL_RX(target,pPacket); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCWaitTarget - Exit\n")); + + return status; +} + + + +/* Start HTC, enable interrupts and let the target know host has finished setup */ +A_STATUS HTCStart(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_PACKET *pPacket; + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCStart Enter\n")); + + /* make sure interrupts are disabled at the chip level, + * this function can be called again from a reboot of the target without shutting down HTC */ + DevDisableInterrupts(&target->Device); + /* make sure state is cleared again */ + target->OpStateFlags = 0; + target->RecvStateFlags = 0; + + /* now that we are starting, push control receive buffers into the + * HTC control endpoint */ + + while (1) { + pPacket = HTC_ALLOC_CONTROL_RX(target); + if (NULL == pPacket) { + break; + } + HTCAddReceivePkt((HTC_HANDLE)target,pPacket); + } + + do { + + AR_DEBUG_ASSERT(target->InitCredits != NULL); + AR_DEBUG_ASSERT(target->EpCreditDistributionListHead != NULL); + AR_DEBUG_ASSERT(target->EpCreditDistributionListHead->pNext != NULL); + + /* call init credits callback to do the distribution , + * NOTE: the first entry in the distribution list is ENDPOINT_0, so + * we pass the start of the list after this one. */ + target->InitCredits(target->pCredDistContext, + target->EpCreditDistributionListHead->pNext, + target->TargetCredits); + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_TRC)) { + DumpCreditDistStates(target); + } + + /* the caller is done connecting to services, so we can indicate to the + * target that the setup phase is complete */ + status = HTCSendSetupComplete(target); + + if (A_FAILED(status)) { + break; + } + + /* unmask interrupts */ + status = DevUnmaskInterrupts(&target->Device); + + if (A_FAILED(status)) { + HTCStop(target); + } + + } while (FALSE); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCStart Exit\n")); + return status; +} + +static void ResetEndpointStates(HTC_TARGET *target) +{ + HTC_ENDPOINT *pEndpoint; + int i; + + for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) { + pEndpoint = &target->EndPoint[i]; + + A_MEMZERO(&pEndpoint->CreditDist, sizeof(pEndpoint->CreditDist)); + pEndpoint->ServiceID = 0; + pEndpoint->MaxMsgLength = 0; + pEndpoint->MaxTxQueueDepth = 0; +#ifdef HTC_EP_STAT_PROFILING + A_MEMZERO(&pEndpoint->EndPointStats,sizeof(pEndpoint->EndPointStats)); +#endif + INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBuffers); + INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue); + INIT_HTC_PACKET_QUEUE(&pEndpoint->RecvIndicationQueue); + pEndpoint->target = target; + } + /* reset distribution list */ + target->EpCreditDistributionListHead = NULL; +} + +/* stop HTC communications, i.e. stop interrupt reception, and flush all queued buffers */ +void HTCStop(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCStop \n")); + + LOCK_HTC(target); + + /* mark that we are shutting down .. */ + target->OpStateFlags |= HTC_OP_STATE_STOPPING; + UNLOCK_HTC(target); + + /* Masking interrupts is a synchronous operation, when this function returns + * all pending HIF I/O has completed, we can safely flush the queues */ + DevMaskInterrupts (&target->Device); + + + /* flush all send packets */ + HTCFlushSendPkts(target); + /* flush all recv buffers */ + HTCFlushRecvBuffers(target); + + DevCleanupMsgBundling(&target->Device); + + DevCleanupGMbox(&target->Device); + + ResetEndpointStates(target); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCStop \n")); +} + +void HTCDumpCreditStates(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + + LOCK_HTC_TX(target); + + DumpCreditDistStates(target); + + UNLOCK_HTC_TX(target); + + DumpAR6KDevState(&target->Device); +} + +/* report a target failure from the device, this is a callback from the device layer + * which uses a mechanism to report errors from the target (i.e. special interrupts) */ +static void HTCReportFailure(void *Context) +{ + HTC_TARGET *target = (HTC_TARGET *)Context; + + target->TargetFailure = TRUE; + + if (target->HTCInitInfo.TargetFailure != NULL) { + /* let upper layer know, it needs to call HTCStop() */ + target->HTCInitInfo.TargetFailure(target->HTCInitInfo.pContext, A_ERROR); + } +} + +A_BOOL HTCGetEndpointStatistics(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint, + HTC_ENDPOINT_STAT_ACTION Action, + HTC_ENDPOINT_STATS *pStats) +{ + +#ifdef HTC_EP_STAT_PROFILING + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + A_BOOL clearStats = FALSE; + A_BOOL sample = FALSE; + + switch (Action) { + case HTC_EP_STAT_SAMPLE : + sample = TRUE; + break; + case HTC_EP_STAT_SAMPLE_AND_CLEAR : + sample = TRUE; + clearStats = TRUE; + break; + case HTC_EP_STAT_CLEAR : + clearStats = TRUE; + break; + default: + break; + } + + A_ASSERT(Endpoint < ENDPOINT_MAX); + if (!(Endpoint < ENDPOINT_MAX)) { + return FALSE; /* in case panic_on_assert==0 */ + } + /* lock out TX and RX while we sample and/or clear */ + LOCK_HTC_TX(target); + LOCK_HTC_RX(target); + + if (sample) { + A_ASSERT(pStats != NULL); + /* return the stats to the caller */ + A_MEMCPY(pStats, &target->EndPoint[Endpoint].EndPointStats, sizeof(HTC_ENDPOINT_STATS)); + } + + if (clearStats) { + /* reset stats */ + A_MEMZERO(&target->EndPoint[Endpoint].EndPointStats, sizeof(HTC_ENDPOINT_STATS)); + } + + UNLOCK_HTC_RX(target); + UNLOCK_HTC_TX(target); + + return TRUE; +#else + return FALSE; +#endif +} + +AR6K_DEVICE *HTCGetAR6KDevice(void *HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + return &target->Device; +} + diff --git a/drivers/net/wireless/ar6003/host/htc2/htc_debug.h b/drivers/net/wireless/ar6003/host/htc2/htc_debug.h new file mode 100644 index 000000000000..8455703e221c --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc_debug.h @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef HTC_DEBUG_H_ +#define HTC_DEBUG_H_ + +#define ATH_MODULE_NAME htc +#include "a_debug.h" + +/* ------- Debug related stuff ------- */ + +#define ATH_DEBUG_SEND ATH_DEBUG_MAKE_MODULE_MASK(0) +#define ATH_DEBUG_RECV ATH_DEBUG_MAKE_MODULE_MASK(1) +#define ATH_DEBUG_SYNC ATH_DEBUG_MAKE_MODULE_MASK(2) +#define ATH_DEBUG_DUMP ATH_DEBUG_MAKE_MODULE_MASK(3) +#define ATH_DEBUG_IRQ ATH_DEBUG_MAKE_MODULE_MASK(4) + + +#endif /*HTC_DEBUG_H_*/ diff --git a/drivers/net/wireless/ar6003/host/htc2/htc_internal.h b/drivers/net/wireless/ar6003/host/htc2/htc_internal.h new file mode 100644 index 000000000000..ca0ba3825fa6 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc_internal.h @@ -0,0 +1,217 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HTC_INTERNAL_H_ +#define _HTC_INTERNAL_H_ + +/* for debugging, uncomment this to capture the last frame header, on frame header + * processing errors, the last frame header is dump for comparison */ +//#define HTC_CAPTURE_LAST_FRAME + +//#define HTC_EP_STAT_PROFILING + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Header files */ + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "htc_debug.h" +#include "htc.h" +#include "htc_api.h" +#include "bmi_msg.h" +#include "hif.h" +#include "AR6000/ar6k.h" + +/* HTC operational parameters */ +#define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */ +#define HTC_TARGET_DEBUG_INTR_MASK 0x01 +#define HTC_TARGET_CREDIT_INTR_MASK 0xF0 + +#define HTC_HOST_MAX_MSG_PER_BUNDLE 8 +#define HTC_MIN_HTC_MSGS_TO_BUNDLE 2 + +/* packet flags */ + +#define HTC_RX_PKT_IGNORE_LOOKAHEAD (1 << 0) +#define HTC_RX_PKT_REFRESH_HDR (1 << 1) +#define HTC_RX_PKT_PART_OF_BUNDLE (1 << 2) +#define HTC_RX_PKT_NO_RECYCLE (1 << 3) + +/* scatter request flags */ + +#define HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE (1 << 0) + +typedef struct _HTC_ENDPOINT { + HTC_ENDPOINT_ID Id; + HTC_SERVICE_ID ServiceID; /* service ID this endpoint is bound to + non-zero value means this endpoint is in use */ + HTC_PACKET_QUEUE TxQueue; /* HTC frame buffer TX queue */ + HTC_PACKET_QUEUE RxBuffers; /* HTC frame buffer RX list */ + HTC_ENDPOINT_CREDIT_DIST CreditDist; /* credit distribution structure (exposed to driver layer) */ + HTC_EP_CALLBACKS EpCallBacks; /* callbacks associated with this endpoint */ + int MaxTxQueueDepth; /* max depth of the TX queue before we need to + call driver's full handler */ + int MaxMsgLength; /* max length of endpoint message */ + int TxProcessCount; /* reference count to continue tx processing */ + HTC_PACKET_QUEUE RecvIndicationQueue; /* recv packets ready to be indicated */ + int RxProcessCount; /* reference count to allow single processing context */ + struct _HTC_TARGET *target; /* back pointer to target */ + A_UINT8 SeqNo; /* TX seq no (helpful) for debugging */ + A_UINT32 LocalConnectionFlags; /* local connection flags */ +#ifdef HTC_EP_STAT_PROFILING + HTC_ENDPOINT_STATS EndPointStats; /* endpoint statistics */ +#endif +} HTC_ENDPOINT; + +#ifdef HTC_EP_STAT_PROFILING +#define INC_HTC_EP_STAT(p,stat,count) (p)->EndPointStats.stat += (count); +#else +#define INC_HTC_EP_STAT(p,stat,count) +#endif + +#define HTC_SERVICE_TX_PACKET_TAG HTC_TX_PACKET_TAG_INTERNAL + +#define NUM_CONTROL_BUFFERS 8 +#define NUM_CONTROL_TX_BUFFERS 2 +#define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS) + +typedef struct HTC_CONTROL_BUFFER { + HTC_PACKET HtcPacket; + A_UINT8 *Buffer; +} HTC_CONTROL_BUFFER; + +#define HTC_RECV_WAIT_BUFFERS (1 << 0) +#define HTC_OP_STATE_STOPPING (1 << 0) + +/* our HTC target state */ +typedef struct _HTC_TARGET { + HTC_ENDPOINT EndPoint[ENDPOINT_MAX]; + HTC_CONTROL_BUFFER HTCControlBuffers[NUM_CONTROL_BUFFERS]; + HTC_ENDPOINT_CREDIT_DIST *EpCreditDistributionListHead; + HTC_PACKET_QUEUE ControlBufferTXFreeList; + HTC_PACKET_QUEUE ControlBufferRXFreeList; + HTC_CREDIT_DIST_CALLBACK DistributeCredits; + HTC_CREDIT_INIT_CALLBACK InitCredits; + void *pCredDistContext; + int TargetCredits; + unsigned int TargetCreditSize; + A_MUTEX_T HTCLock; + A_MUTEX_T HTCRxLock; + A_MUTEX_T HTCTxLock; + AR6K_DEVICE Device; /* AR6K - specific state */ + A_UINT32 OpStateFlags; + A_UINT32 RecvStateFlags; + HTC_ENDPOINT_ID EpWaitingForBuffers; + A_BOOL TargetFailure; +#ifdef HTC_CAPTURE_LAST_FRAME + HTC_FRAME_HDR LastFrameHdr; /* useful for debugging */ + A_UINT8 LastTrailer[256]; + A_UINT8 LastTrailerLength; +#endif + HTC_INIT_INFO HTCInitInfo; + A_UINT8 HTCTargetVersion; + int MaxMsgPerBundle; /* max messages per bundle for HTC */ + A_BOOL SendBundlingEnabled; /* run time enable for send bundling (dynamic) */ + int RecvBundlingEnabled; /* run time enable for recv bundling (dynamic) */ +} HTC_TARGET; + +#define HTC_STOPPING(t) ((t)->OpStateFlags & HTC_OP_STATE_STOPPING) +#define LOCK_HTC(t) A_MUTEX_LOCK(&(t)->HTCLock); +#define UNLOCK_HTC(t) A_MUTEX_UNLOCK(&(t)->HTCLock); +#define LOCK_HTC_RX(t) A_MUTEX_LOCK(&(t)->HTCRxLock); +#define UNLOCK_HTC_RX(t) A_MUTEX_UNLOCK(&(t)->HTCRxLock); +#define LOCK_HTC_TX(t) A_MUTEX_LOCK(&(t)->HTCTxLock); +#define UNLOCK_HTC_TX(t) A_MUTEX_UNLOCK(&(t)->HTCTxLock); + +#define GET_HTC_TARGET_FROM_HANDLE(hnd) ((HTC_TARGET *)(hnd)) +#define HTC_RECYCLE_RX_PKT(target,p,e) \ +{ \ + if ((p)->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_NO_RECYCLE) { \ + HTC_PACKET_RESET_RX(pPacket); \ + pPacket->Status = A_ECANCELED; \ + (e)->EpCallBacks.EpRecv((e)->EpCallBacks.pContext, \ + (p)); \ + } else { \ + HTC_PACKET_RESET_RX(pPacket); \ + HTCAddReceivePkt((HTC_HANDLE)(target),(p)); \ + } \ +} + +/* internal HTC functions */ +void HTCControlTxComplete(void *Context, HTC_PACKET *pPacket); +void HTCControlRecv(void *Context, HTC_PACKET *pPacket); +A_STATUS HTCWaitforControlMessage(HTC_TARGET *target, HTC_PACKET **ppControlPacket); +HTC_PACKET *HTCAllocControlBuffer(HTC_TARGET *target, HTC_PACKET_QUEUE *pList); +void HTCFreeControlBuffer(HTC_TARGET *target, HTC_PACKET *pPacket, HTC_PACKET_QUEUE *pList); +A_STATUS HTCIssueSend(HTC_TARGET *target, HTC_PACKET *pPacket); +void HTCRecvCompleteHandler(void *Context, HTC_PACKET *pPacket); +A_STATUS HTCRecvMessagePendingHandler(void *Context, A_UINT32 MsgLookAheads[], int NumLookAheads, A_BOOL *pAsyncProc, int *pNumPktsFetched); +void HTCProcessCreditRpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt, int NumEntries, HTC_ENDPOINT_ID FromEndpoint); +A_STATUS HTCSendSetupComplete(HTC_TARGET *target); +void HTCFlushRecvBuffers(HTC_TARGET *target); +void HTCFlushSendPkts(HTC_TARGET *target); +void DumpCreditDist(HTC_ENDPOINT_CREDIT_DIST *pEPDist); +void DumpCreditDistStates(HTC_TARGET *target); +void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription); + +static INLINE HTC_PACKET *HTC_ALLOC_CONTROL_TX(HTC_TARGET *target) { + HTC_PACKET *pPacket = HTCAllocControlBuffer(target,&target->ControlBufferTXFreeList); + if (pPacket != NULL) { + /* set payload pointer area with some headroom */ + pPacket->pBuffer = pPacket->pBufferStart + HTC_HDR_LENGTH; + } + return pPacket; +} + +#define HTC_FREE_CONTROL_TX(t,p) HTCFreeControlBuffer((t),(p),&(t)->ControlBufferTXFreeList) +#define HTC_ALLOC_CONTROL_RX(t) HTCAllocControlBuffer((t),&(t)->ControlBufferRXFreeList) +#define HTC_FREE_CONTROL_RX(t,p) \ +{ \ + HTC_PACKET_RESET_RX(p); \ + HTCFreeControlBuffer((t),(p),&(t)->ControlBufferRXFreeList); \ +} + +#define HTC_PREPARE_SEND_PKT(pP,sendflags,ctrl0,ctrl1) \ +{ \ + A_UINT8 *pHdrBuf; \ + (pP)->pBuffer -= HTC_HDR_LENGTH; \ + pHdrBuf = (pP)->pBuffer; \ + A_SET_UINT16_FIELD(pHdrBuf,HTC_FRAME_HDR,PayloadLen,(A_UINT16)(pP)->ActualLength); \ + A_SET_UINT8_FIELD(pHdrBuf,HTC_FRAME_HDR,Flags,(sendflags)); \ + A_SET_UINT8_FIELD(pHdrBuf,HTC_FRAME_HDR,EndpointID, (A_UINT8)(pP)->Endpoint); \ + A_SET_UINT8_FIELD(pHdrBuf,HTC_FRAME_HDR,ControlBytes[0], (A_UINT8)(ctrl0)); \ + A_SET_UINT8_FIELD(pHdrBuf,HTC_FRAME_HDR,ControlBytes[1], (A_UINT8)(ctrl1)); \ +} + +#define HTC_UNPREPARE_SEND_PKT(pP) \ + (pP)->pBuffer += HTC_HDR_LENGTH; \ + +#ifdef __cplusplus +} +#endif + +#endif /* _HTC_INTERNAL_H_ */ diff --git a/drivers/net/wireless/ar6003/host/htc2/htc_recv.c b/drivers/net/wireless/ar6003/host/htc2/htc_recv.c new file mode 100644 index 000000000000..d483f701713e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc_recv.c @@ -0,0 +1,1572 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#include "htc_internal.h" + +#define HTCIssueRecv(t, p) \ + DevRecvPacket(&(t)->Device, \ + (p), \ + (p)->ActualLength) + +#define DO_RCV_COMPLETION(e,q) DoRecvCompletion(e,q) + +#define DUMP_RECV_PKT_INFO(pP) \ + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, (" HTC RECV packet 0x%lX (%d bytes) (hdr:0x%X) on ep : %d \n", \ + (unsigned long)(pP), \ + (pP)->ActualLength, \ + (pP)->PktInfo.AsRx.ExpectedHdr, \ + (pP)->Endpoint)) + +#ifdef HTC_EP_STAT_PROFILING +#define HTC_RX_STAT_PROFILE(t,ep,numLookAheads) \ +{ \ + INC_HTC_EP_STAT((ep), RxReceived, 1); \ + if ((numLookAheads) == 1) { \ + INC_HTC_EP_STAT((ep), RxLookAheads, 1); \ + } else if ((numLookAheads) > 1) { \ + INC_HTC_EP_STAT((ep), RxBundleLookAheads, 1); \ + } \ +} +#else +#define HTC_RX_STAT_PROFILE(t,ep,lookAhead) +#endif + +static void DoRecvCompletion(HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pQueueToIndicate) +{ + + do { + + if (HTC_QUEUE_EMPTY(pQueueToIndicate)) { + /* nothing to indicate */ + break; + } + + if (pEndpoint->EpCallBacks.EpRecvPktMultiple != NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, (" HTC calling ep %d, recv multiple callback (%d pkts) \n", + pEndpoint->Id, HTC_PACKET_QUEUE_DEPTH(pQueueToIndicate))); + /* a recv multiple handler is being used, pass the queue to the handler */ + pEndpoint->EpCallBacks.EpRecvPktMultiple(pEndpoint->EpCallBacks.pContext, + pQueueToIndicate); + INIT_HTC_PACKET_QUEUE(pQueueToIndicate); + } else { + HTC_PACKET *pPacket; + /* using legacy EpRecv */ + do { + pPacket = HTC_PACKET_DEQUEUE(pQueueToIndicate); + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, (" HTC calling ep %d recv callback on packet 0x%lX \n", \ + pEndpoint->Id, (unsigned long)(pPacket))); + pEndpoint->EpCallBacks.EpRecv(pEndpoint->EpCallBacks.pContext, pPacket); + } while (!HTC_QUEUE_EMPTY(pQueueToIndicate)); + } + + } while (FALSE); + +} + +static INLINE A_STATUS HTCProcessTrailer(HTC_TARGET *target, + A_UINT8 *pBuffer, + int Length, + A_UINT32 *pNextLookAheads, + int *pNumLookAheads, + HTC_ENDPOINT_ID FromEndpoint) +{ + HTC_RECORD_HDR *pRecord; + A_UINT8 *pRecordBuf; + HTC_LOOKAHEAD_REPORT *pLookAhead; + A_UINT8 *pOrigBuffer; + int origLength; + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCProcessTrailer (length:%d) \n", Length)); + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + AR_DEBUG_PRINTBUF(pBuffer,Length,"Recv Trailer"); + } + + pOrigBuffer = pBuffer; + origLength = Length; + status = A_OK; + + while (Length > 0) { + + if (Length < sizeof(HTC_RECORD_HDR)) { + status = A_EPROTO; + break; + } + /* these are byte aligned structs */ + pRecord = (HTC_RECORD_HDR *)pBuffer; + Length -= sizeof(HTC_RECORD_HDR); + pBuffer += sizeof(HTC_RECORD_HDR); + + if (pRecord->Length > Length) { + /* no room left in buffer for record */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" invalid record length: %d (id:%d) buffer has: %d bytes left \n", + pRecord->Length, pRecord->RecordID, Length)); + status = A_EPROTO; + break; + } + /* start of record follows the header */ + pRecordBuf = pBuffer; + + switch (pRecord->RecordID) { + case HTC_RECORD_CREDITS: + AR_DEBUG_ASSERT(pRecord->Length >= sizeof(HTC_CREDIT_REPORT)); + HTCProcessCreditRpt(target, + (HTC_CREDIT_REPORT *)pRecordBuf, + pRecord->Length / (sizeof(HTC_CREDIT_REPORT)), + FromEndpoint); + break; + case HTC_RECORD_LOOKAHEAD: + AR_DEBUG_ASSERT(pRecord->Length >= sizeof(HTC_LOOKAHEAD_REPORT)); + pLookAhead = (HTC_LOOKAHEAD_REPORT *)pRecordBuf; + if ((pLookAhead->PreValid == ((~pLookAhead->PostValid) & 0xFF)) && + (pNextLookAheads != NULL)) { + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + (" LookAhead Report Found (pre valid:0x%X, post valid:0x%X) \n", + pLookAhead->PreValid, + pLookAhead->PostValid)); + + /* look ahead bytes are valid, copy them over */ + ((A_UINT8 *)(&pNextLookAheads[0]))[0] = pLookAhead->LookAhead[0]; + ((A_UINT8 *)(&pNextLookAheads[0]))[1] = pLookAhead->LookAhead[1]; + ((A_UINT8 *)(&pNextLookAheads[0]))[2] = pLookAhead->LookAhead[2]; + ((A_UINT8 *)(&pNextLookAheads[0]))[3] = pLookAhead->LookAhead[3]; + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + DebugDumpBytes((A_UINT8 *)pNextLookAheads,4,"Next Look Ahead"); + } + /* just one normal lookahead */ + if (pNumLookAheads != NULL) { + *pNumLookAheads = 1; + } + } + break; + case HTC_RECORD_LOOKAHEAD_BUNDLE: + AR_DEBUG_ASSERT(pRecord->Length >= sizeof(HTC_BUNDLED_LOOKAHEAD_REPORT)); + if (pRecord->Length >= sizeof(HTC_BUNDLED_LOOKAHEAD_REPORT) && + (pNextLookAheads != NULL)) { + HTC_BUNDLED_LOOKAHEAD_REPORT *pBundledLookAheadRpt; + int i; + + pBundledLookAheadRpt = (HTC_BUNDLED_LOOKAHEAD_REPORT *)pRecordBuf; + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + DebugDumpBytes(pRecordBuf,pRecord->Length,"Bundle LookAhead"); + } + + if ((pRecord->Length / (sizeof(HTC_BUNDLED_LOOKAHEAD_REPORT))) > + HTC_HOST_MAX_MSG_PER_BUNDLE) { + /* this should never happen, the target restricts the number + * of messages per bundle configured by the host */ + A_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + for (i = 0; i < (int)(pRecord->Length / (sizeof(HTC_BUNDLED_LOOKAHEAD_REPORT))); i++) { + ((A_UINT8 *)(&pNextLookAheads[i]))[0] = pBundledLookAheadRpt->LookAhead[0]; + ((A_UINT8 *)(&pNextLookAheads[i]))[1] = pBundledLookAheadRpt->LookAhead[1]; + ((A_UINT8 *)(&pNextLookAheads[i]))[2] = pBundledLookAheadRpt->LookAhead[2]; + ((A_UINT8 *)(&pNextLookAheads[i]))[3] = pBundledLookAheadRpt->LookAhead[3]; + pBundledLookAheadRpt++; + } + + *pNumLookAheads = i; + } + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, (" unhandled record: id:%d length:%d \n", + pRecord->RecordID, pRecord->Length)); + break; + } + + if (A_FAILED(status)) { + break; + } + + /* advance buffer past this record for next time around */ + pBuffer += pRecord->Length; + Length -= pRecord->Length; + } + + if (A_FAILED(status)) { + DebugDumpBytes(pOrigBuffer,origLength,"BAD Recv Trailer"); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-HTCProcessTrailer \n")); + return status; + +} + +/* process a received message (i.e. strip off header, process any trailer data) + * note : locks must be released when this function is called */ +static A_STATUS HTCProcessRecvHeader(HTC_TARGET *target, + HTC_PACKET *pPacket, + A_UINT32 *pNextLookAheads, + int *pNumLookAheads) +{ + A_UINT8 temp; + A_UINT8 *pBuf; + A_STATUS status = A_OK; + A_UINT16 payloadLen; + A_UINT32 lookAhead; + + pBuf = pPacket->pBuffer; + + if (pNumLookAheads != NULL) { + *pNumLookAheads = 0; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCProcessRecvHeader \n")); + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + AR_DEBUG_PRINTBUF(pBuf,pPacket->ActualLength,"HTC Recv PKT"); + } + + do { + /* note, we cannot assume the alignment of pBuffer, so we use the safe macros to + * retrieve 16 bit fields */ + payloadLen = A_GET_UINT16_FIELD(pBuf, HTC_FRAME_HDR, PayloadLen); + + ((A_UINT8 *)&lookAhead)[0] = pBuf[0]; + ((A_UINT8 *)&lookAhead)[1] = pBuf[1]; + ((A_UINT8 *)&lookAhead)[2] = pBuf[2]; + ((A_UINT8 *)&lookAhead)[3] = pBuf[3]; + + if (pPacket->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_REFRESH_HDR) { + /* refresh expected hdr, since this was unknown at the time we grabbed the packets + * as part of a bundle */ + pPacket->PktInfo.AsRx.ExpectedHdr = lookAhead; + /* refresh actual length since we now have the real header */ + pPacket->ActualLength = payloadLen + HTC_HDR_LENGTH; + + /* validate the actual header that was refreshed */ + if (pPacket->ActualLength > pPacket->BufferLength) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Refreshed HDR payload length (%d) in bundled RECV is invalid (hdr: 0x%X) \n", + payloadLen, lookAhead)); + /* limit this to max buffer just to print out some of the buffer */ + pPacket->ActualLength = min(pPacket->ActualLength, pPacket->BufferLength); + status = A_EPROTO; + break; + } + + if (pPacket->Endpoint != A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, EndpointID)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Refreshed HDR endpoint (%d) does not match expected endpoint (%d) \n", + A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, EndpointID), pPacket->Endpoint)); + status = A_EPROTO; + break; + } + } + + if (lookAhead != pPacket->PktInfo.AsRx.ExpectedHdr) { + /* somehow the lookahead that gave us the full read length did not + * reflect the actual header in the pending message */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("HTCProcessRecvHeader, lookahead mismatch! (pPkt:0x%lX flags:0x%X) \n", + (unsigned long)pPacket, pPacket->PktInfo.AsRx.HTCRxFlags)); +#ifdef ATH_DEBUG_MODULE + DebugDumpBytes((A_UINT8 *)&pPacket->PktInfo.AsRx.ExpectedHdr,4,"Expected Message LookAhead"); + DebugDumpBytes(pBuf,sizeof(HTC_FRAME_HDR),"Current Frame Header"); +#ifdef HTC_CAPTURE_LAST_FRAME + DebugDumpBytes((A_UINT8 *)&target->LastFrameHdr,sizeof(HTC_FRAME_HDR),"Last Frame Header"); + if (target->LastTrailerLength != 0) { + DebugDumpBytes(target->LastTrailer, + target->LastTrailerLength, + "Last trailer"); + } +#endif +#endif + status = A_EPROTO; + break; + } + + /* get flags */ + temp = A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, Flags); + + if (temp & HTC_FLAGS_RECV_TRAILER) { + /* this packet has a trailer */ + + /* extract the trailer length in control byte 0 */ + temp = A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, ControlBytes[0]); + + if ((temp < sizeof(HTC_RECORD_HDR)) || (temp > payloadLen)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("HTCProcessRecvHeader, invalid header (payloadlength should be :%d, CB[0] is:%d) \n", + payloadLen, temp)); + status = A_EPROTO; + break; + } + + if (pPacket->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_IGNORE_LOOKAHEAD) { + /* this packet was fetched as part of an HTC bundle, the embedded lookahead is + * not valid since the next packet may have already been fetched as part of the + * bundle */ + pNextLookAheads = NULL; + pNumLookAheads = NULL; + } + + /* process trailer data that follows HDR + application payload */ + status = HTCProcessTrailer(target, + (pBuf + HTC_HDR_LENGTH + payloadLen - temp), + temp, + pNextLookAheads, + pNumLookAheads, + pPacket->Endpoint); + + if (A_FAILED(status)) { + break; + } + +#ifdef HTC_CAPTURE_LAST_FRAME + A_MEMCPY(target->LastTrailer, (pBuf + HTC_HDR_LENGTH + payloadLen - temp), temp); + target->LastTrailerLength = temp; +#endif + /* trim length by trailer bytes */ + pPacket->ActualLength -= temp; + } +#ifdef HTC_CAPTURE_LAST_FRAME + else { + target->LastTrailerLength = 0; + } +#endif + + /* if we get to this point, the packet is good */ + /* remove header and adjust length */ + pPacket->pBuffer += HTC_HDR_LENGTH; + pPacket->ActualLength -= HTC_HDR_LENGTH; + + } while (FALSE); + + if (A_FAILED(status)) { + /* dump the whole packet */ + DebugDumpBytes(pBuf,pPacket->ActualLength < 256 ? pPacket->ActualLength : 256 ,"BAD HTC Recv PKT"); + } else { +#ifdef HTC_CAPTURE_LAST_FRAME + A_MEMCPY(&target->LastFrameHdr,pBuf,sizeof(HTC_FRAME_HDR)); +#endif + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) { + if (pPacket->ActualLength > 0) { + AR_DEBUG_PRINTBUF(pPacket->pBuffer,pPacket->ActualLength,"HTC - Application Msg"); + } + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-HTCProcessRecvHeader \n")); + return status; +} + +static INLINE void HTCAsyncRecvCheckMorePackets(HTC_TARGET *target, + A_UINT32 NextLookAheads[], + int NumLookAheads, + A_BOOL CheckMoreMsgs) +{ + /* was there a lookahead for the next packet? */ + if (NumLookAheads > 0) { + A_STATUS nextStatus; + int fetched = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("HTCAsyncRecvCheckMorePackets - num lookaheads were non-zero : %d \n", + NumLookAheads)); + /* force status re-check */ + REF_IRQ_STATUS_RECHECK(&target->Device); + /* we have more packets, get the next packet fetch started */ + nextStatus = HTCRecvMessagePendingHandler(target, NextLookAheads, NumLookAheads, NULL, &fetched); + if (A_EPROTO == nextStatus) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Next look ahead from recv header was INVALID\n")); + DebugDumpBytes((A_UINT8 *)NextLookAheads, + NumLookAheads * (sizeof(A_UINT32)), + "BAD lookaheads from lookahead report"); + } + if (A_SUCCESS(nextStatus) && !fetched) { + /* we could not fetch any more packets due to resources */ + DevAsyncIrqProcessComplete(&target->Device); + } + } else { + if (CheckMoreMsgs) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("HTCAsyncRecvCheckMorePackets - rechecking for more messages...\n")); + /* if we did not get anything on the look-ahead, + * call device layer to asynchronously re-check for messages. If we can keep the async + * processing going we get better performance. If there is a pending message we will keep processing + * messages asynchronously which should pipeline things nicely */ + DevCheckPendingRecvMsgsAsync(&target->Device); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("HTCAsyncRecvCheckMorePackets - no check \n")); + } + } + + +} + + /* unload the recv completion queue */ +static INLINE void DrainRecvIndicationQueue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint) +{ + HTC_PACKET_QUEUE recvCompletions = { {0} }; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+DrainRecvIndicationQueue \n")); + + INIT_HTC_PACKET_QUEUE(&recvCompletions); + + LOCK_HTC_RX(target); + + /* increment rx processing count on entry */ + pEndpoint->RxProcessCount++; + if (pEndpoint->RxProcessCount > 1) { + pEndpoint->RxProcessCount--; + /* another thread or task is draining the RX completion queue on this endpoint + * that thread will reset the rx processing count when the queue is drained */ + UNLOCK_HTC_RX(target); + return; + } + + /******* at this point only 1 thread may enter ******/ + + while (TRUE) { + + /* transfer items from main recv queue to the local one so we can release the lock */ + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&recvCompletions, &pEndpoint->RecvIndicationQueue); + + if (HTC_QUEUE_EMPTY(&recvCompletions)) { + /* all drained */ + break; + } + + /* release lock while we do the recv completions + * other threads can now queue more recv completions */ + UNLOCK_HTC_RX(target); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("DrainRecvIndicationQueue : completing %d RECV packets \n", + HTC_PACKET_QUEUE_DEPTH(&recvCompletions))); + /* do completion */ + DO_RCV_COMPLETION(pEndpoint,&recvCompletions); + + /* re-acquire lock to grab some more completions */ + LOCK_HTC_RX(target); + } + + /* reset count */ + pEndpoint->RxProcessCount = 0; + UNLOCK_HTC_RX(target); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-DrainRecvIndicationQueue \n")); + +} + + /* optimization for recv packets, we can indicate a "hint" that there are more + * single-packets to fetch on this endpoint */ +#define SET_MORE_RX_PACKET_INDICATION_FLAG(L,N,E,P) \ + if ((N) > 0) { SetRxPacketIndicationFlags((L)[0],(E),(P)); } + + /* for bundled frames, we can force the flag to indicate there are more packets */ +#define FORCE_MORE_RX_PACKET_INDICATION_FLAG(P) \ + (P)->PktInfo.AsRx.IndicationFlags |= HTC_RX_FLAGS_INDICATE_MORE_PKTS; + + /* note: this function can be called with the RX lock held */ +static INLINE void SetRxPacketIndicationFlags(A_UINT32 LookAhead, + HTC_ENDPOINT *pEndpoint, + HTC_PACKET *pPacket) +{ + HTC_FRAME_HDR *pHdr = (HTC_FRAME_HDR *)&LookAhead; + /* check to see if the "next" packet is from the same endpoint of the + completing packet */ + if (pHdr->EndpointID == pPacket->Endpoint) { + /* check that there is a buffer available to actually fetch it */ + if (!HTC_QUEUE_EMPTY(&pEndpoint->RxBuffers)) { + /* provide a hint that there are more RX packets to fetch */ + FORCE_MORE_RX_PACKET_INDICATION_FLAG(pPacket); + } + } +} + + +/* asynchronous completion handler for recv packet fetching, when the device layer + * completes a read request, it will call this completion handler */ +void HTCRecvCompleteHandler(void *Context, HTC_PACKET *pPacket) +{ + HTC_TARGET *target = (HTC_TARGET *)Context; + HTC_ENDPOINT *pEndpoint; + A_UINT32 nextLookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE]; + int numLookAheads = 0; + A_STATUS status; + A_BOOL checkMorePkts = TRUE; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCRecvCompleteHandler (pkt:0x%lX, status:%d, ep:%d) \n", + (unsigned long)pPacket, pPacket->Status, pPacket->Endpoint)); + + A_ASSERT(!IS_DEV_IRQ_PROC_SYNC_MODE(&target->Device)); + AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX); + pEndpoint = &target->EndPoint[pPacket->Endpoint]; + pPacket->Completion = NULL; + + /* get completion status */ + status = pPacket->Status; + + do { + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HTCRecvCompleteHandler: request failed (status:%d, ep:%d) \n", + pPacket->Status, pPacket->Endpoint)); + break; + } + /* process the header for any trailer data */ + status = HTCProcessRecvHeader(target,pPacket,nextLookAheads,&numLookAheads); + + if (A_FAILED(status)) { + break; + } + + if (pPacket->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_IGNORE_LOOKAHEAD) { + /* this packet was part of a bundle that had to be broken up. + * It was fetched one message at a time. There may be other asynchronous reads queued behind this one. + * Do no issue another check for more packets since the last one in the series of requests + * will handle it */ + checkMorePkts = FALSE; + } + + DUMP_RECV_PKT_INFO(pPacket); + LOCK_HTC_RX(target); + SET_MORE_RX_PACKET_INDICATION_FLAG(nextLookAheads,numLookAheads,pEndpoint,pPacket); + /* we have a good packet, queue it to the completion queue */ + HTC_PACKET_ENQUEUE(&pEndpoint->RecvIndicationQueue,pPacket); + HTC_RX_STAT_PROFILE(target,pEndpoint,numLookAheads); + UNLOCK_HTC_RX(target); + + /* check for more recv packets before indicating */ + HTCAsyncRecvCheckMorePackets(target,nextLookAheads,numLookAheads,checkMorePkts); + + } while (FALSE); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("HTCRecvCompleteHandler , message fetch failed (status = %d) \n", + status)); + /* recycle this packet */ + HTC_RECYCLE_RX_PKT(target, pPacket, pEndpoint); + } else { + /* a good packet was queued, drain the queue */ + DrainRecvIndicationQueue(target,pEndpoint); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-HTCRecvCompleteHandler\n")); +} + +/* synchronously wait for a control message from the target, + * This function is used at initialization time ONLY. At init messages + * on ENDPOINT 0 are expected. */ +A_STATUS HTCWaitforControlMessage(HTC_TARGET *target, HTC_PACKET **ppControlPacket) +{ + A_STATUS status; + A_UINT32 lookAhead; + HTC_PACKET *pPacket = NULL; + HTC_FRAME_HDR *pHdr; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCWaitforControlMessage \n")); + + do { + + *ppControlPacket = NULL; + + /* call the polling function to see if we have a message */ + status = DevPollMboxMsgRecv(&target->Device, + &lookAhead, + HTC_TARGET_RESPONSE_TIMEOUT); + + if (A_FAILED(status)) { + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("HTCWaitforControlMessage : lookAhead : 0x%X \n", lookAhead)); + + /* check the lookahead */ + pHdr = (HTC_FRAME_HDR *)&lookAhead; + + if (pHdr->EndpointID != ENDPOINT_0) { + /* unexpected endpoint number, should be zero */ + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + if (A_FAILED(status)) { + /* bad message */ + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + pPacket = HTC_ALLOC_CONTROL_RX(target); + + if (pPacket == NULL) { + AR_DEBUG_ASSERT(FALSE); + status = A_NO_MEMORY; + break; + } + + pPacket->PktInfo.AsRx.HTCRxFlags = 0; + pPacket->PktInfo.AsRx.ExpectedHdr = lookAhead; + pPacket->ActualLength = pHdr->PayloadLen + HTC_HDR_LENGTH; + + if (pPacket->ActualLength > pPacket->BufferLength) { + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + /* we want synchronous operation */ + pPacket->Completion = NULL; + + /* get the message from the device, this will block */ + status = HTCIssueRecv(target, pPacket); + + if (A_FAILED(status)) { + break; + } + + /* process receive header */ + status = HTCProcessRecvHeader(target,pPacket,NULL,NULL); + + pPacket->Status = status; + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("HTCWaitforControlMessage, HTCProcessRecvHeader failed (status = %d) \n", + status)); + break; + } + + /* give the caller this control message packet, they are responsible to free */ + *ppControlPacket = pPacket; + + } while (FALSE); + + if (A_FAILED(status)) { + if (pPacket != NULL) { + /* cleanup buffer on error */ + HTC_FREE_CONTROL_RX(target,pPacket); + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCWaitforControlMessage \n")); + + return status; +} + +static A_STATUS AllocAndPrepareRxPackets(HTC_TARGET *target, + A_UINT32 LookAheads[], + int Messages, + HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pQueue) +{ + A_STATUS status = A_OK; + HTC_PACKET *pPacket; + HTC_FRAME_HDR *pHdr; + int i,j; + int numMessages; + int fullLength; + A_BOOL noRecycle; + + /* lock RX while we assemble the packet buffers */ + LOCK_HTC_RX(target); + + for (i = 0; i < Messages; i++) { + + pHdr = (HTC_FRAME_HDR *)&LookAheads[i]; + + if (pHdr->EndpointID >= ENDPOINT_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Endpoint in look-ahead: %d \n",pHdr->EndpointID)); + /* invalid endpoint */ + status = A_EPROTO; + break; + } + + if (pHdr->EndpointID != pEndpoint->Id) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Endpoint in look-ahead: %d should be : %d (index:%d)\n", + pHdr->EndpointID, pEndpoint->Id, i)); + /* invalid endpoint */ + status = A_EPROTO; + break; + } + + if (pHdr->PayloadLen > HTC_MAX_PAYLOAD_LENGTH) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Payload length %d exceeds max HTC : %d !\n", + pHdr->PayloadLen, (A_UINT32)HTC_MAX_PAYLOAD_LENGTH)); + status = A_EPROTO; + break; + } + + if (0 == pEndpoint->ServiceID) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Endpoint %d is not connected !\n",pHdr->EndpointID)); + /* endpoint isn't even connected */ + status = A_EPROTO; + break; + } + + if ((pHdr->Flags & HTC_FLAGS_RECV_BUNDLE_CNT_MASK) == 0) { + /* HTC header only indicates 1 message to fetch */ + numMessages = 1; + } else { + /* HTC header indicates that every packet to follow has the same padded length so that it can + * be optimally fetched as a full bundle */ + numMessages = (pHdr->Flags & HTC_FLAGS_RECV_BUNDLE_CNT_MASK) >> HTC_FLAGS_RECV_BUNDLE_CNT_SHIFT; + /* the count doesn't include the starter frame, just a count of frames to follow */ + numMessages++; + A_ASSERT(numMessages <= target->MaxMsgPerBundle); + INC_HTC_EP_STAT(pEndpoint, RxBundleIndFromHdr, 1); + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("HTC header indicates :%d messages can be fetched as a bundle \n",numMessages)); + } + + fullLength = DEV_CALC_RECV_PADDED_LEN(&target->Device,pHdr->PayloadLen + sizeof(HTC_FRAME_HDR)); + + /* get packet buffers for each message, if there was a bundle detected in the header, + * use pHdr as a template to fetch all packets in the bundle */ + for (j = 0; j < numMessages; j++) { + + /* reset flag, any packets allocated using the RecvAlloc() API cannot be recycled on cleanup, + * they must be explicitly returned */ + noRecycle = FALSE; + + if (pEndpoint->EpCallBacks.EpRecvAlloc != NULL) { + UNLOCK_HTC_RX(target); + noRecycle = TRUE; + /* user is using a per-packet allocation callback */ + pPacket = pEndpoint->EpCallBacks.EpRecvAlloc(pEndpoint->EpCallBacks.pContext, + pEndpoint->Id, + fullLength); + LOCK_HTC_RX(target); + + } else if ((pEndpoint->EpCallBacks.EpRecvAllocThresh != NULL) && + (fullLength > pEndpoint->EpCallBacks.RecvAllocThreshold)) { + INC_HTC_EP_STAT(pEndpoint,RxAllocThreshHit,1); + INC_HTC_EP_STAT(pEndpoint,RxAllocThreshBytes,pHdr->PayloadLen); + /* threshold was hit, call the special recv allocation callback */ + UNLOCK_HTC_RX(target); + noRecycle = TRUE; + /* user wants to allocate packets above a certain threshold */ + pPacket = pEndpoint->EpCallBacks.EpRecvAllocThresh(pEndpoint->EpCallBacks.pContext, + pEndpoint->Id, + fullLength); + LOCK_HTC_RX(target); + + } else { + /* user is using a refill handler that can refill multiple HTC buffers */ + + /* get a packet from the endpoint recv queue */ + pPacket = HTC_PACKET_DEQUEUE(&pEndpoint->RxBuffers); + + if (NULL == pPacket) { + /* check for refill handler */ + if (pEndpoint->EpCallBacks.EpRecvRefill != NULL) { + UNLOCK_HTC_RX(target); + /* call the re-fill handler */ + pEndpoint->EpCallBacks.EpRecvRefill(pEndpoint->EpCallBacks.pContext, + pEndpoint->Id); + LOCK_HTC_RX(target); + /* check if we have more buffers */ + pPacket = HTC_PACKET_DEQUEUE(&pEndpoint->RxBuffers); + /* fall through */ + } + } + } + + if (NULL == pPacket) { + /* this is not an error, we simply need to mark that we are waiting for buffers.*/ + target->RecvStateFlags |= HTC_RECV_WAIT_BUFFERS; + target->EpWaitingForBuffers = pEndpoint->Id; + status = A_NO_RESOURCE; + break; + } + + AR_DEBUG_ASSERT(pPacket->Endpoint == pEndpoint->Id); + /* clear flags */ + pPacket->PktInfo.AsRx.HTCRxFlags = 0; + pPacket->PktInfo.AsRx.IndicationFlags = 0; + pPacket->Status = A_OK; + + if (noRecycle) { + /* flag that these packets cannot be recycled, they have to be returned to the + * user */ + pPacket->PktInfo.AsRx.HTCRxFlags |= HTC_RX_PKT_NO_RECYCLE; + } + /* add packet to queue (also incase we need to cleanup down below) */ + HTC_PACKET_ENQUEUE(pQueue,pPacket); + + if (HTC_STOPPING(target)) { + status = A_ECANCELED; + break; + } + + /* make sure this message can fit in the endpoint buffer */ + if ((A_UINT32)fullLength > pPacket->BufferLength) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Payload Length Error : header reports payload of: %d (%d) endpoint buffer size: %d \n", + pHdr->PayloadLen, fullLength, pPacket->BufferLength)); + status = A_EPROTO; + break; + } + + if (j > 0) { + /* for messages fetched in a bundle the expected lookahead is unknown since we + * are only using the lookahead of the first packet as a template of what to + * expect for lengths */ + /* flag that once we get the real HTC header we need to refesh the information */ + pPacket->PktInfo.AsRx.HTCRxFlags |= HTC_RX_PKT_REFRESH_HDR; + /* set it to something invalid */ + pPacket->PktInfo.AsRx.ExpectedHdr = 0xFFFFFFFF; + } else { + + pPacket->PktInfo.AsRx.ExpectedHdr = LookAheads[i]; /* set expected look ahead */ + } + /* set the amount of data to fetch */ + pPacket->ActualLength = pHdr->PayloadLen + HTC_HDR_LENGTH; + } + + if (A_FAILED(status)) { + if (A_NO_RESOURCE == status) { + /* this is actually okay */ + status = A_OK; + } + break; + } + + } + + UNLOCK_HTC_RX(target); + + if (A_FAILED(status)) { + while (!HTC_QUEUE_EMPTY(pQueue)) { + pPacket = HTC_PACKET_DEQUEUE(pQueue); + /* recycle all allocated packets */ + HTC_RECYCLE_RX_PKT(target,pPacket,&target->EndPoint[pPacket->Endpoint]); + } + } + + return status; +} + +static void HTCAsyncRecvScatterCompletion(HIF_SCATTER_REQ *pScatterReq) +{ + int i; + HTC_PACKET *pPacket; + HTC_ENDPOINT *pEndpoint; + A_UINT32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE]; + int numLookAheads = 0; + HTC_TARGET *target = (HTC_TARGET *)pScatterReq->Context; + A_STATUS status; + A_BOOL partialBundle = FALSE; + HTC_PACKET_QUEUE localRecvQueue = { {0} }; + A_BOOL procError = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCAsyncRecvScatterCompletion TotLen: %d Entries: %d\n", + pScatterReq->TotalLength, pScatterReq->ValidScatterEntries)); + + A_ASSERT(!IS_DEV_IRQ_PROC_SYNC_MODE(&target->Device)); + + if (A_FAILED(pScatterReq->CompletionStatus)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** Recv Scatter Request Failed: %d \n",pScatterReq->CompletionStatus)); + } + + if (pScatterReq->CallerFlags & HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE) { + partialBundle = TRUE; + } + + DEV_FINISH_SCATTER_OPERATION(pScatterReq); + + INIT_HTC_PACKET_QUEUE(&localRecvQueue); + + pPacket = (HTC_PACKET *)pScatterReq->ScatterList[0].pCallerContexts[0]; + /* note: all packets in a scatter req are for the same endpoint ! */ + pEndpoint = &target->EndPoint[pPacket->Endpoint]; + + /* walk through the scatter list and process */ + /* **** NOTE: DO NOT HOLD ANY LOCKS here, HTCProcessRecvHeader can take the TX lock + * as it processes credit reports */ + for (i = 0; i < pScatterReq->ValidScatterEntries; i++) { + pPacket = (HTC_PACKET *)pScatterReq->ScatterList[i].pCallerContexts[0]; + A_ASSERT(pPacket != NULL); + /* reset count, we are only interested in the look ahead in the last packet when we + * break out of this loop */ + numLookAheads = 0; + + if (A_SUCCESS(pScatterReq->CompletionStatus)) { + /* process header for each of the recv packets */ + status = HTCProcessRecvHeader(target,pPacket,lookAheads,&numLookAheads); + } else { + status = A_ERROR; + } + + if (A_SUCCESS(status)) { +#ifdef HTC_EP_STAT_PROFILING + LOCK_HTC_RX(target); + HTC_RX_STAT_PROFILE(target,pEndpoint,numLookAheads); + INC_HTC_EP_STAT(pEndpoint, RxPacketsBundled, 1); + UNLOCK_HTC_RX(target); +#endif + if (i == (pScatterReq->ValidScatterEntries - 1)) { + /* last packet's more packets flag is set based on the lookahead */ + SET_MORE_RX_PACKET_INDICATION_FLAG(lookAheads,numLookAheads,pEndpoint,pPacket); + } else { + /* packets in a bundle automatically have this flag set */ + FORCE_MORE_RX_PACKET_INDICATION_FLAG(pPacket); + } + + DUMP_RECV_PKT_INFO(pPacket); + /* since we can't hold a lock in this loop, we insert into our local recv queue for + * storage until we can transfer them to the recv completion queue */ + HTC_PACKET_ENQUEUE(&localRecvQueue,pPacket); + + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Recv packet scatter entry %d failed (out of %d) \n", + i, pScatterReq->ValidScatterEntries)); + /* recycle failed recv */ + HTC_RECYCLE_RX_PKT(target, pPacket, pEndpoint); + /* set flag and continue processing the remaining scatter entries */ + procError = TRUE; + } + + } + + /* free scatter request */ + DEV_FREE_SCATTER_REQ(&target->Device,pScatterReq); + + LOCK_HTC_RX(target); + /* transfer the packets in the local recv queue to the recv completion queue */ + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->RecvIndicationQueue, &localRecvQueue); + + UNLOCK_HTC_RX(target); + + if (!procError) { + /* pipeline the next check (asynchronously) for more packets */ + HTCAsyncRecvCheckMorePackets(target, + lookAheads, + numLookAheads, + partialBundle ? FALSE : TRUE); + } + + /* now drain the indication queue */ + DrainRecvIndicationQueue(target,pEndpoint); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCAsyncRecvScatterCompletion \n")); +} + +static A_STATUS HTCIssueRecvPacketBundle(HTC_TARGET *target, + HTC_PACKET_QUEUE *pRecvPktQueue, + HTC_PACKET_QUEUE *pSyncCompletionQueue, + int *pNumPacketsFetched, + A_BOOL PartialBundle) +{ + A_STATUS status = A_OK; + HIF_SCATTER_REQ *pScatterReq; + int i, totalLength; + int pktsToScatter; + HTC_PACKET *pPacket; + A_BOOL asyncMode = (pSyncCompletionQueue == NULL) ? TRUE : FALSE; + int scatterSpaceRemaining = DEV_GET_MAX_BUNDLE_RECV_LENGTH(&target->Device); + + pktsToScatter = HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue); + pktsToScatter = min(pktsToScatter, target->MaxMsgPerBundle); + + if ((HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue) - pktsToScatter) > 0) { + /* we were forced to split this bundle receive operation + * all packets in this partial bundle must have their lookaheads ignored */ + PartialBundle = TRUE; + /* this would only happen if the target ignored our max bundle limit */ + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("HTCIssueRecvPacketBundle : partial bundle detected num:%d , %d \n", + HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue), pktsToScatter)); + } + + totalLength = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCIssueRecvPacketBundle (Numpackets: %d , actual : %d) \n", + HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue), pktsToScatter)); + + do { + + pScatterReq = DEV_ALLOC_SCATTER_REQ(&target->Device); + + if (pScatterReq == NULL) { + /* no scatter resources left, just let caller handle it the legacy way */ + break; + } + + pScatterReq->CallerFlags = 0; + + if (PartialBundle) { + /* mark that this is a partial bundle, this has special ramifications to the + * scatter completion routine */ + pScatterReq->CallerFlags |= HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE; + } + + /* convert HTC packets to scatter list */ + for (i = 0; i < pktsToScatter; i++) { + int paddedLength; + + pPacket = HTC_PACKET_DEQUEUE(pRecvPktQueue); + A_ASSERT(pPacket != NULL); + + paddedLength = DEV_CALC_RECV_PADDED_LEN(&target->Device, pPacket->ActualLength); + + if ((scatterSpaceRemaining - paddedLength) < 0) { + /* exceeds what we can transfer, put the packet back */ + HTC_PACKET_ENQUEUE_TO_HEAD(pRecvPktQueue,pPacket); + break; + } + + scatterSpaceRemaining -= paddedLength; + + if (PartialBundle || (i < (pktsToScatter - 1))) { + /* packet 0..n-1 cannot be checked for look-aheads since we are fetching a bundle + * the last packet however can have it's lookahead used */ + pPacket->PktInfo.AsRx.HTCRxFlags |= HTC_RX_PKT_IGNORE_LOOKAHEAD; + } + + /* note: 1 HTC packet per scatter entry */ + /* setup packet into */ + pScatterReq->ScatterList[i].pBuffer = pPacket->pBuffer; + pScatterReq->ScatterList[i].Length = paddedLength; + + pPacket->PktInfo.AsRx.HTCRxFlags |= HTC_RX_PKT_PART_OF_BUNDLE; + + if (asyncMode) { + /* save HTC packet for async completion routine */ + pScatterReq->ScatterList[i].pCallerContexts[0] = pPacket; + } else { + /* queue to caller's sync completion queue, caller will unload this when we return */ + HTC_PACKET_ENQUEUE(pSyncCompletionQueue,pPacket); + } + + A_ASSERT(pScatterReq->ScatterList[i].Length); + totalLength += pScatterReq->ScatterList[i].Length; + } + + pScatterReq->TotalLength = totalLength; + pScatterReq->ValidScatterEntries = i; + + if (asyncMode) { + pScatterReq->CompletionRoutine = HTCAsyncRecvScatterCompletion; + pScatterReq->Context = target; + } + + status = DevSubmitScatterRequest(&target->Device, pScatterReq, DEV_SCATTER_READ, asyncMode); + + if (A_SUCCESS(status)) { + *pNumPacketsFetched = i; + } + + if (!asyncMode) { + /* free scatter request */ + DEV_FREE_SCATTER_REQ(&target->Device, pScatterReq); + } + + } while (FALSE); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCIssueRecvPacketBundle (status:%d) (fetched:%d) \n", + status,*pNumPacketsFetched)); + + return status; +} + +static INLINE void CheckRecvWaterMark(HTC_ENDPOINT *pEndpoint) +{ + /* see if endpoint is using a refill watermark + * ** no need to use a lock here, since we are only inspecting... + * caller may must not hold locks when calling this function */ + if (pEndpoint->EpCallBacks.RecvRefillWaterMark > 0) { + if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->RxBuffers) < pEndpoint->EpCallBacks.RecvRefillWaterMark) { + /* call the re-fill handler before we continue */ + pEndpoint->EpCallBacks.EpRecvRefill(pEndpoint->EpCallBacks.pContext, + pEndpoint->Id); + } + } +} + +/* callback when device layer or lookahead report parsing detects a pending message */ +A_STATUS HTCRecvMessagePendingHandler(void *Context, A_UINT32 MsgLookAheads[], int NumLookAheads, A_BOOL *pAsyncProc, int *pNumPktsFetched) +{ + HTC_TARGET *target = (HTC_TARGET *)Context; + A_STATUS status = A_OK; + HTC_PACKET *pPacket; + HTC_ENDPOINT *pEndpoint; + A_BOOL asyncProc = FALSE; + A_UINT32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE]; + int pktsFetched; + HTC_PACKET_QUEUE recvPktQueue = { {0} }; + HTC_PACKET_QUEUE syncCompletedPktsQueue = { {0} }; + A_BOOL partialBundle; + HTC_ENDPOINT_ID id; + int totalFetched = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCRecvMessagePendingHandler NumLookAheads: %d \n",NumLookAheads)); + + if (pNumPktsFetched != NULL) { + *pNumPktsFetched = 0; + } + + if (IS_DEV_IRQ_PROCESSING_ASYNC_ALLOWED(&target->Device)) { + /* We use async mode to get the packets if the device layer supports it. + * The device layer interfaces with HIF in which HIF may have restrictions on + * how interrupts are processed */ + asyncProc = TRUE; + } + + if (pAsyncProc != NULL) { + /* indicate to caller how we decided to process this */ + *pAsyncProc = asyncProc; + } + + if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) { + A_ASSERT(FALSE); + return A_EPROTO; + } + + /* on first entry copy the lookaheads into our temp array for processing */ + A_MEMCPY(lookAheads, MsgLookAheads, (sizeof(A_UINT32)) * NumLookAheads); + + while (TRUE) { + + /* reset packets queues */ + INIT_HTC_PACKET_QUEUE(&recvPktQueue); + INIT_HTC_PACKET_QUEUE(&syncCompletedPktsQueue); + + if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) { + status = A_EPROTO; + A_ASSERT(FALSE); + break; + } + + /* first lookahead sets the expected endpoint IDs for all packets in a bundle */ + id = ((HTC_FRAME_HDR *)&lookAheads[0])->EndpointID; + pEndpoint = &target->EndPoint[id]; + + if (id >= ENDPOINT_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MsgPend, Invalid Endpoint in look-ahead: %d \n",id)); + status = A_EPROTO; + break; + } + + /* try to allocate as many HTC RX packets indicated by the lookaheads + * these packets are stored in the recvPkt queue */ + status = AllocAndPrepareRxPackets(target, + lookAheads, + NumLookAheads, + pEndpoint, + &recvPktQueue); + if (A_FAILED(status)) { + break; + } + + if (HTC_PACKET_QUEUE_DEPTH(&recvPktQueue) >= 2) { + /* a recv bundle was detected, force IRQ status re-check again */ + REF_IRQ_STATUS_RECHECK(&target->Device); + } + + totalFetched += HTC_PACKET_QUEUE_DEPTH(&recvPktQueue); + + /* we've got packet buffers for all we can currently fetch, + * this count is not valid anymore */ + NumLookAheads = 0; + partialBundle = FALSE; + + /* now go fetch the list of HTC packets */ + while (!HTC_QUEUE_EMPTY(&recvPktQueue)) { + + pktsFetched = 0; + + if (target->RecvBundlingEnabled && (HTC_PACKET_QUEUE_DEPTH(&recvPktQueue) > 1)) { + /* there are enough packets to attempt a bundle transfer and recv bundling is allowed */ + status = HTCIssueRecvPacketBundle(target, + &recvPktQueue, + asyncProc ? NULL : &syncCompletedPktsQueue, + &pktsFetched, + partialBundle); + if (A_FAILED(status)) { + break; + } + + if (HTC_PACKET_QUEUE_DEPTH(&recvPktQueue) != 0) { + /* we couldn't fetch all packets at one time, this creates a broken + * bundle */ + partialBundle = TRUE; + } + } + + /* see if the previous operation fetched any packets using bundling */ + if (0 == pktsFetched) { + /* dequeue one packet */ + pPacket = HTC_PACKET_DEQUEUE(&recvPktQueue); + A_ASSERT(pPacket != NULL); + + if (asyncProc) { + /* we use async mode to get the packet if the device layer supports it + * set our callback and context */ + pPacket->Completion = HTCRecvCompleteHandler; + pPacket->pContext = target; + } else { + /* fully synchronous */ + pPacket->Completion = NULL; + } + + if (HTC_PACKET_QUEUE_DEPTH(&recvPktQueue) > 0) { + /* lookaheads in all packets except the last one in the bundle must be ignored */ + pPacket->PktInfo.AsRx.HTCRxFlags |= HTC_RX_PKT_IGNORE_LOOKAHEAD; + } + + /* go fetch the packet */ + status = HTCIssueRecv(target, pPacket); + if (A_FAILED(status)) { + break; + } + + if (!asyncProc) { + /* sent synchronously, queue this packet for synchronous completion */ + HTC_PACKET_ENQUEUE(&syncCompletedPktsQueue,pPacket); + } + + } + + } + + if (A_SUCCESS(status)) { + CheckRecvWaterMark(pEndpoint); + } + + if (asyncProc) { + /* we did this asynchronously so we can get out of the loop, the asynch processing + * creates a chain of requests to continue processing pending messages in the + * context of callbacks */ + break; + } + + /* synchronous handling */ + if (target->Device.DSRCanYield) { + /* for the SYNC case, increment count that tracks when the DSR should yield */ + target->Device.CurrentDSRRecvCount++; + } + + /* in the sync case, all packet buffers are now filled, + * we can process each packet, check lookaheads and then repeat */ + + /* unload sync completion queue */ + while (!HTC_QUEUE_EMPTY(&syncCompletedPktsQueue)) { + HTC_PACKET_QUEUE container; + + pPacket = HTC_PACKET_DEQUEUE(&syncCompletedPktsQueue); + A_ASSERT(pPacket != NULL); + + pEndpoint = &target->EndPoint[pPacket->Endpoint]; + /* reset count on each iteration, we are only interested in the last packet's lookahead + * information when we break out of this loop */ + NumLookAheads = 0; + /* process header for each of the recv packets + * note: the lookahead of the last packet is useful for us to continue in this loop */ + status = HTCProcessRecvHeader(target,pPacket,lookAheads,&NumLookAheads); + if (A_FAILED(status)) { + break; + } + + if (HTC_QUEUE_EMPTY(&syncCompletedPktsQueue)) { + /* last packet's more packets flag is set based on the lookahead */ + SET_MORE_RX_PACKET_INDICATION_FLAG(lookAheads,NumLookAheads,pEndpoint,pPacket); + } else { + /* packets in a bundle automatically have this flag set */ + FORCE_MORE_RX_PACKET_INDICATION_FLAG(pPacket); + } + /* good packet, indicate it */ + HTC_RX_STAT_PROFILE(target,pEndpoint,NumLookAheads); + + if (pPacket->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_PART_OF_BUNDLE) { + INC_HTC_EP_STAT(pEndpoint, RxPacketsBundled, 1); + } + + INIT_HTC_PACKET_QUEUE_AND_ADD(&container,pPacket); + DO_RCV_COMPLETION(pEndpoint,&container); + } + + if (A_FAILED(status)) { + break; + } + + if (NumLookAheads == 0) { + /* no more look aheads */ + break; + } + + /* when we process recv synchronously we need to check if we should yield and stop + * fetching more packets indicated by the embedded lookaheads */ + if (target->Device.DSRCanYield) { + if (DEV_CHECK_RECV_YIELD(&target->Device)) { + /* break out, don't fetch any more packets */ + break; + } + } + + + /* check whether other OS contexts have queued any WMI command/data for WLAN. + * This check is needed only if WLAN Tx and Rx happens in same thread context */ + A_CHECK_DRV_TX(); + + /* for SYNCH processing, if we get here, we are running through the loop again due to a detected lookahead. + * Set flag that we should re-check IRQ status registers again before leaving IRQ processing, + * this can net better performance in high throughput situations */ + REF_IRQ_STATUS_RECHECK(&target->Device); + } + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Failed to get pending recv messages (%d) \n",status)); + /* cleanup any packets we allocated but didn't use to actually fetch any packets */ + while (!HTC_QUEUE_EMPTY(&recvPktQueue)) { + pPacket = HTC_PACKET_DEQUEUE(&recvPktQueue); + /* clean up packets */ + HTC_RECYCLE_RX_PKT(target, pPacket, &target->EndPoint[pPacket->Endpoint]); + } + /* cleanup any packets in sync completion queue */ + while (!HTC_QUEUE_EMPTY(&syncCompletedPktsQueue)) { + pPacket = HTC_PACKET_DEQUEUE(&syncCompletedPktsQueue); + /* clean up packets */ + HTC_RECYCLE_RX_PKT(target, pPacket, &target->EndPoint[pPacket->Endpoint]); + } + if (HTC_STOPPING(target)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + (" Host is going to stop. blocking receiver for HTCStop.. \n")); + DevStopRecv(&target->Device, asyncProc ? DEV_STOP_RECV_ASYNC : DEV_STOP_RECV_SYNC); + } + } + /* before leaving, check to see if host ran out of buffers and needs to stop the + * receiver */ + if (target->RecvStateFlags & HTC_RECV_WAIT_BUFFERS) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + (" Host has no RX buffers, blocking receiver to prevent overrun.. \n")); + /* try to stop receive at the device layer */ + DevStopRecv(&target->Device, asyncProc ? DEV_STOP_RECV_ASYNC : DEV_STOP_RECV_SYNC); + } + + if (pNumPktsFetched != NULL) { + *pNumPktsFetched = totalFetched; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCRecvMessagePendingHandler \n")); + + return status; +} + +A_STATUS HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_ENDPOINT *pEndpoint; + A_BOOL unblockRecv = FALSE; + A_STATUS status = A_OK; + HTC_PACKET *pFirstPacket; + + pFirstPacket = HTC_GET_PKT_AT_HEAD(pPktQueue); + + if (NULL == pFirstPacket) { + A_ASSERT(FALSE); + return A_EINVAL; + } + + AR_DEBUG_ASSERT(pFirstPacket->Endpoint < ENDPOINT_MAX); + + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, + ("+- HTCAddReceivePktMultiple : endPointId: %d, cnt:%d, length: %d\n", + pFirstPacket->Endpoint, + HTC_PACKET_QUEUE_DEPTH(pPktQueue), + pFirstPacket->BufferLength)); + + do { + + pEndpoint = &target->EndPoint[pFirstPacket->Endpoint]; + + LOCK_HTC_RX(target); + + if (HTC_STOPPING(target)) { + HTC_PACKET *pPacket; + + UNLOCK_HTC_RX(target); + + /* walk through queue and mark each one canceled */ + HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue,pPacket) { + pPacket->Status = A_ECANCELED; + } HTC_PACKET_QUEUE_ITERATE_END; + + DO_RCV_COMPLETION(pEndpoint,pPktQueue); + break; + } + + /* store receive packets */ + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->RxBuffers, pPktQueue); + + /* check if we are blocked waiting for a new buffer */ + if (target->RecvStateFlags & HTC_RECV_WAIT_BUFFERS) { + if (target->EpWaitingForBuffers == pFirstPacket->Endpoint) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" receiver was blocked on ep:%d, unblocking.. \n", + target->EpWaitingForBuffers)); + target->RecvStateFlags &= ~HTC_RECV_WAIT_BUFFERS; + target->EpWaitingForBuffers = ENDPOINT_MAX; + unblockRecv = TRUE; + } + } + + UNLOCK_HTC_RX(target); + + if (unblockRecv && !HTC_STOPPING(target)) { + /* TODO : implement a buffer threshold count? */ + DevEnableRecv(&target->Device,DEV_ENABLE_RECV_SYNC); + } + + } while (FALSE); + + return status; +} + +/* Makes a buffer available to the HTC module */ +A_STATUS HTCAddReceivePkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket) +{ + HTC_PACKET_QUEUE queue = { {0} }; + INIT_HTC_PACKET_QUEUE_AND_ADD(&queue,pPacket); + return HTCAddReceivePktMultiple(HTCHandle, &queue); +} + +void HTCUnblockRecv(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + A_BOOL unblockRecv = FALSE; + + LOCK_HTC_RX(target); + + /* check if we are blocked waiting for a new buffer */ + if (target->RecvStateFlags & HTC_RECV_WAIT_BUFFERS) { + AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HTCUnblockRx : receiver was blocked on ep:%d, unblocking.. \n", + target->EpWaitingForBuffers)); + target->RecvStateFlags &= ~HTC_RECV_WAIT_BUFFERS; + target->EpWaitingForBuffers = ENDPOINT_MAX; + unblockRecv = TRUE; + } + + UNLOCK_HTC_RX(target); + + if (unblockRecv && !HTC_STOPPING(target)) { + /* re-enable */ + DevEnableRecv(&target->Device,DEV_ENABLE_RECV_ASYNC); + } +} + +static void HTCFlushRxQueue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint, HTC_PACKET_QUEUE *pQueue) +{ + HTC_PACKET *pPacket; + HTC_PACKET_QUEUE container = { {0} }; + + LOCK_HTC_RX(target); + + while (1) { + pPacket = HTC_PACKET_DEQUEUE(pQueue); + if (NULL == pPacket) { + break; + } + UNLOCK_HTC_RX(target); + pPacket->Status = A_ECANCELED; + pPacket->ActualLength = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_RECV, (" Flushing RX packet:0x%lX, length:%d, ep:%d \n", + (unsigned long)pPacket, pPacket->BufferLength, pPacket->Endpoint)); + INIT_HTC_PACKET_QUEUE_AND_ADD(&container,pPacket); + /* give the packet back */ + DO_RCV_COMPLETION(pEndpoint,&container); + LOCK_HTC_RX(target); + } + + UNLOCK_HTC_RX(target); +} + +static void HTCFlushEndpointRX(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint) +{ + /* flush any recv indications not already made */ + HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RecvIndicationQueue); + /* flush any rx buffers */ + HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RxBuffers); +} + +void HTCFlushRecvBuffers(HTC_TARGET *target) +{ + HTC_ENDPOINT *pEndpoint; + int i; + + for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) { + pEndpoint = &target->EndPoint[i]; + if (pEndpoint->ServiceID == 0) { + /* not in use.. */ + continue; + } + HTCFlushEndpointRX(target,pEndpoint); + } +} + + +void HTCEnableRecv(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + + if (!HTC_STOPPING(target)) { + /* re-enable */ + DevEnableRecv(&target->Device,DEV_ENABLE_RECV_SYNC); + } +} + +void HTCDisableRecv(HTC_HANDLE HTCHandle) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + + if (!HTC_STOPPING(target)) { + /* disable */ + DevStopRecv(&target->Device,DEV_ENABLE_RECV_SYNC); + } +} + +int HTCGetNumRecvBuffers(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + return HTC_PACKET_QUEUE_DEPTH(&(target->EndPoint[Endpoint].RxBuffers)); +} + +A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle, + A_UINT32 TimeoutInMs, + A_BOOL *pbIsRecvPending) +{ + A_STATUS status = A_OK; + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + + status = DevWaitForPendingRecv(&target->Device, + TimeoutInMs, + pbIsRecvPending); + + return status; +} diff --git a/drivers/net/wireless/ar6003/host/htc2/htc_send.c b/drivers/net/wireless/ar6003/host/htc2/htc_send.c new file mode 100644 index 000000000000..cdc393485a56 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc_send.c @@ -0,0 +1,1024 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#include "htc_internal.h" + +typedef enum _HTC_SEND_QUEUE_RESULT { + HTC_SEND_QUEUE_OK = 0, /* packet was queued */ + HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */ +} HTC_SEND_QUEUE_RESULT; + +#define DO_EP_TX_COMPLETION(ep,q) DoSendCompletion(ep,q) + +/* call the distribute credits callback with the distribution */ +#define DO_DISTRIBUTION(t,reason,description,pList) \ +{ \ + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, \ + (" calling distribute function (%s) (dfn:0x%lX, ctxt:0x%lX, dist:0x%lX) \n", \ + (description), \ + (unsigned long)(t)->DistributeCredits, \ + (unsigned long)(t)->pCredDistContext, \ + (unsigned long)pList)); \ + (t)->DistributeCredits((t)->pCredDistContext, \ + (pList), \ + (reason)); \ +} + +static void DoSendCompletion(HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pQueueToIndicate) +{ + do { + + if (HTC_QUEUE_EMPTY(pQueueToIndicate)) { + /* nothing to indicate */ + break; + } + + if (pEndpoint->EpCallBacks.EpTxCompleteMultiple != NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" HTC calling ep %d, send complete multiple callback (%d pkts) \n", + pEndpoint->Id, HTC_PACKET_QUEUE_DEPTH(pQueueToIndicate))); + /* a multiple send complete handler is being used, pass the queue to the handler */ + pEndpoint->EpCallBacks.EpTxCompleteMultiple(pEndpoint->EpCallBacks.pContext, + pQueueToIndicate); + /* all packets are now owned by the callback, reset queue to be safe */ + INIT_HTC_PACKET_QUEUE(pQueueToIndicate); + } else { + HTC_PACKET *pPacket; + /* using legacy EpTxComplete */ + do { + pPacket = HTC_PACKET_DEQUEUE(pQueueToIndicate); + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" HTC calling ep %d send complete callback on packet 0x%lX \n", \ + pEndpoint->Id, (unsigned long)(pPacket))); + pEndpoint->EpCallBacks.EpTxComplete(pEndpoint->EpCallBacks.pContext, pPacket); + } while (!HTC_QUEUE_EMPTY(pQueueToIndicate)); + } + + } while (FALSE); + +} + +/* do final completion on sent packet */ +static INLINE void CompleteSentPacket(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint, HTC_PACKET *pPacket) +{ + pPacket->Completion = NULL; + + if (A_FAILED(pPacket->Status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("CompleteSentPacket: request failed (status:%d, ep:%d, length:%d creds:%d) \n", + pPacket->Status, pPacket->Endpoint, pPacket->ActualLength, pPacket->PktInfo.AsTx.CreditsUsed)); + /* on failure to submit, reclaim credits for this packet */ + LOCK_HTC_TX(target); + pEndpoint->CreditDist.TxCreditsToDist += pPacket->PktInfo.AsTx.CreditsUsed; + pEndpoint->CreditDist.TxQueueDepth = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); + DO_DISTRIBUTION(target, + HTC_CREDIT_DIST_SEND_COMPLETE, + "Send Complete", + target->EpCreditDistributionListHead->pNext); + UNLOCK_HTC_TX(target); + } + /* first, fixup the head room we allocated */ + pPacket->pBuffer += HTC_HDR_LENGTH; +} + +/* our internal send packet completion handler when packets are submited to the AR6K device + * layer */ +static void HTCSendPktCompletionHandler(void *Context, HTC_PACKET *pPacket) +{ + HTC_TARGET *target = (HTC_TARGET *)Context; + HTC_ENDPOINT *pEndpoint = &target->EndPoint[pPacket->Endpoint]; + HTC_PACKET_QUEUE container = { {0} }; + + CompleteSentPacket(target,pEndpoint,pPacket); + INIT_HTC_PACKET_QUEUE_AND_ADD(&container,pPacket); + /* do completion */ + DO_EP_TX_COMPLETION(pEndpoint,&container); +} + +A_STATUS HTCIssueSend(HTC_TARGET *target, HTC_PACKET *pPacket) +{ + A_STATUS status; + A_BOOL sync = FALSE; + + if (pPacket->Completion == NULL) { + /* mark that this request was synchronously issued */ + sync = TRUE; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + ("+-HTCIssueSend: transmit length : %d (%s) \n", + pPacket->ActualLength + (A_UINT32)HTC_HDR_LENGTH, + sync ? "SYNC" : "ASYNC" )); + + /* send message to device */ + status = DevSendPacket(&target->Device, + pPacket, + pPacket->ActualLength + HTC_HDR_LENGTH); + + if (sync) { + /* use local sync variable. If this was issued asynchronously, pPacket is no longer + * safe to access. */ + pPacket->pBuffer += HTC_HDR_LENGTH; + } + + /* if this request was asynchronous, the packet completion routine will be invoked by + * the device layer when the HIF layer completes the request */ + + return status; +} + + /* get HTC send packets from the TX queue on an endpoint */ +static INLINE void GetHTCSendPackets(HTC_TARGET *target, + HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pQueue) +{ + int creditsRequired; + int remainder; + A_UINT8 sendFlags; + HTC_PACKET *pPacket; + unsigned int transferLength; + + /****** NOTE : the TX lock is held when this function is called *****************/ + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+GetHTCSendPackets \n")); + + /* loop until we can grab as many packets out of the queue as we can */ + while (TRUE) { + + sendFlags = 0; + /* get packet at head, but don't remove it */ + pPacket = HTC_GET_PKT_AT_HEAD(&pEndpoint->TxQueue); + if (pPacket == NULL) { + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" Got head packet:0x%lX , Queue Depth: %d\n", + (unsigned long)pPacket, HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue))); + + transferLength = DEV_CALC_SEND_PADDED_LEN(&target->Device, pPacket->ActualLength + HTC_HDR_LENGTH); + + if (transferLength <= target->TargetCreditSize) { + creditsRequired = 1; + } else { + /* figure out how many credits this message requires */ + creditsRequired = transferLength / target->TargetCreditSize; + remainder = transferLength % target->TargetCreditSize; + + if (remainder) { + creditsRequired++; + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" Creds Required:%d Got:%d\n", + creditsRequired, pEndpoint->CreditDist.TxCredits)); + + if (pEndpoint->CreditDist.TxCredits < creditsRequired) { + + /* not enough credits */ + if (pPacket->Endpoint == ENDPOINT_0) { + /* leave it in the queue */ + break; + } + /* invoke the registered distribution function only if this is not + * endpoint 0, we let the driver layer provide more credits if it can. + * We pass the credit distribution list starting at the endpoint in question + * */ + + /* set how many credits we need */ + pEndpoint->CreditDist.TxCreditsSeek = + creditsRequired - pEndpoint->CreditDist.TxCredits; + DO_DISTRIBUTION(target, + HTC_CREDIT_DIST_SEEK_CREDITS, + "Seek Credits", + &pEndpoint->CreditDist); + pEndpoint->CreditDist.TxCreditsSeek = 0; + + if (pEndpoint->CreditDist.TxCredits < creditsRequired) { + /* still not enough credits to send, leave packet in the queue */ + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + (" Not enough credits for ep %d leaving packet in queue..\n", + pPacket->Endpoint)); + break; + } + + } + + pEndpoint->CreditDist.TxCredits -= creditsRequired; + INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed, creditsRequired); + + /* check if we need credits back from the target */ + if (pEndpoint->CreditDist.TxCredits < pEndpoint->CreditDist.TxCreditsPerMaxMsg) { + /* we are getting low on credits, see if we can ask for more from the distribution function */ + pEndpoint->CreditDist.TxCreditsSeek = + pEndpoint->CreditDist.TxCreditsPerMaxMsg - pEndpoint->CreditDist.TxCredits; + + DO_DISTRIBUTION(target, + HTC_CREDIT_DIST_SEEK_CREDITS, + "Seek Credits", + &pEndpoint->CreditDist); + + pEndpoint->CreditDist.TxCreditsSeek = 0; + /* see if we were successful in getting more */ + if (pEndpoint->CreditDist.TxCredits < pEndpoint->CreditDist.TxCreditsPerMaxMsg) { + /* tell the target we need credits ASAP! */ + sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE; + INC_HTC_EP_STAT(pEndpoint, TxCreditLowIndications, 1); + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" Host Needs Credits \n")); + } + } + + /* now we can fully dequeue */ + pPacket = HTC_PACKET_DEQUEUE(&pEndpoint->TxQueue); + /* save the number of credits this packet consumed */ + pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired; + /* all TX packets are handled asynchronously */ + pPacket->Completion = HTCSendPktCompletionHandler; + pPacket->pContext = target; + INC_HTC_EP_STAT(pEndpoint, TxIssued, 1); + /* save send flags */ + pPacket->PktInfo.AsTx.SendFlags = sendFlags; + pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo; + pEndpoint->SeqNo++; + /* queue this packet into the caller's queue */ + HTC_PACKET_ENQUEUE(pQueue,pPacket); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-GetHTCSendPackets \n")); + +} + +static void HTCAsyncSendScatterCompletion(HIF_SCATTER_REQ *pScatterReq) +{ + int i; + HTC_PACKET *pPacket; + HTC_ENDPOINT *pEndpoint = (HTC_ENDPOINT *)pScatterReq->Context; + HTC_TARGET *target = (HTC_TARGET *)pEndpoint->target; + A_STATUS status = A_OK; + HTC_PACKET_QUEUE sendCompletes = { {0} }; + + INIT_HTC_PACKET_QUEUE(&sendCompletes); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HTCAsyncSendScatterCompletion TotLen: %d Entries: %d\n", + pScatterReq->TotalLength, pScatterReq->ValidScatterEntries)); + + DEV_FINISH_SCATTER_OPERATION(pScatterReq); + + if (A_FAILED(pScatterReq->CompletionStatus)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** Send Scatter Request Failed: %d \n",pScatterReq->CompletionStatus)); + status = A_ERROR; + } + + /* walk through the scatter list and process */ + for (i = 0; i < pScatterReq->ValidScatterEntries; i++) { + pPacket = (HTC_PACKET *)(pScatterReq->ScatterList[i].pCallerContexts[0]); + A_ASSERT(pPacket != NULL); + pPacket->Status = status; + CompleteSentPacket(target,pEndpoint,pPacket); + /* add it to the completion queue */ + HTC_PACKET_ENQUEUE(&sendCompletes, pPacket); + } + + /* free scatter request */ + DEV_FREE_SCATTER_REQ(&target->Device,pScatterReq); + /* complete all packets */ + DO_EP_TX_COMPLETION(pEndpoint,&sendCompletes); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HTCAsyncSendScatterCompletion \n")); +} + + /* drain a queue and send as bundles + * this function may return without fully draining the queue under the following conditions : + * - scatter resources are exhausted + * - a message that will consume a partial credit will stop the bundling process early + * - we drop below the minimum number of messages for a bundle + * */ +static void HTCIssueSendBundle(HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pQueue, + int *pBundlesSent, + int *pTotalBundlesPkts) +{ + int pktsToScatter; + unsigned int scatterSpaceRemaining; + HIF_SCATTER_REQ *pScatterReq = NULL; + int i, packetsInScatterReq; + unsigned int transferLength; + HTC_PACKET *pPacket; + A_BOOL done = FALSE; + int bundlesSent = 0; + int totalPktsInBundle = 0; + HTC_TARGET *target = pEndpoint->target; + int creditRemainder = 0; + int creditPad; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HTCIssueSendBundle \n")); + + while (!done) { + + pktsToScatter = HTC_PACKET_QUEUE_DEPTH(pQueue); + pktsToScatter = min(pktsToScatter, target->MaxMsgPerBundle); + + if (pktsToScatter < HTC_MIN_HTC_MSGS_TO_BUNDLE) { + /* not enough to bundle */ + break; + } + + pScatterReq = DEV_ALLOC_SCATTER_REQ(&target->Device); + + if (pScatterReq == NULL) { + /* no scatter resources */ + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" No more scatter resources \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" pkts to scatter: %d \n", pktsToScatter)); + + pScatterReq->TotalLength = 0; + pScatterReq->ValidScatterEntries = 0; + + packetsInScatterReq = 0; + scatterSpaceRemaining = DEV_GET_MAX_BUNDLE_SEND_LENGTH(&target->Device); + + for (i = 0; i < pktsToScatter; i++) { + + pScatterReq->ScatterList[i].pCallerContexts[0] = NULL; + + pPacket = HTC_GET_PKT_AT_HEAD(pQueue); + if (pPacket == NULL) { + A_ASSERT(FALSE); + break; + } + + creditPad = 0; + transferLength = DEV_CALC_SEND_PADDED_LEN(&target->Device, + pPacket->ActualLength + HTC_HDR_LENGTH); + /* see if the padded transfer length falls on a credit boundary */ + creditRemainder = transferLength % target->TargetCreditSize; + + if (creditRemainder != 0) { + /* the transfer consumes a "partial" credit, this packet cannot be bundled unless + * we add additional "dummy" padding (max 255 bytes) to consume the entire credit + *** NOTE: only allow the send padding if the endpoint is allowed to */ + if (pEndpoint->LocalConnectionFlags & HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING) { + if (transferLength < target->TargetCreditSize) { + /* special case where the transfer is less than a credit */ + creditPad = target->TargetCreditSize - transferLength; + } else { + creditPad = creditRemainder; + } + + /* now check to see if we can indicate padding in the HTC header */ + if ((creditPad > 0) && (creditPad <= 255)) { + /* adjust the transferlength of this packet with the new credit padding */ + transferLength += creditPad; + } else { + /* the amount to pad is too large, bail on this packet, we have to + * send it using the non-bundled method */ + pPacket = NULL; + } + } else { + /* bail on this packet, user does not want padding applied */ + pPacket = NULL; + } + } + + if (NULL == pPacket) { + /* can't bundle */ + done = TRUE; + break; + } + + if (scatterSpaceRemaining < transferLength) { + /* exceeds what we can transfer */ + break; + } + + scatterSpaceRemaining -= transferLength; + /* now remove it from the queue */ + pPacket = HTC_PACKET_DEQUEUE(pQueue); + /* save it in the scatter list */ + pScatterReq->ScatterList[i].pCallerContexts[0] = pPacket; + /* prepare packet and flag message as part of a send bundle */ + HTC_PREPARE_SEND_PKT(pPacket, + pPacket->PktInfo.AsTx.SendFlags | HTC_FLAGS_SEND_BUNDLE, + creditPad, + pPacket->PktInfo.AsTx.SeqNo); + pScatterReq->ScatterList[i].pBuffer = pPacket->pBuffer; + pScatterReq->ScatterList[i].Length = transferLength; + A_ASSERT(transferLength); + pScatterReq->TotalLength += transferLength; + pScatterReq->ValidScatterEntries++; + packetsInScatterReq++; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" %d, Adding packet : 0x%lX, len:%d (remaining space:%d) \n", + i, (unsigned long)pPacket,transferLength,scatterSpaceRemaining)); + } + + if (packetsInScatterReq >= HTC_MIN_HTC_MSGS_TO_BUNDLE) { + /* send path is always asynchronous */ + pScatterReq->CompletionRoutine = HTCAsyncSendScatterCompletion; + pScatterReq->Context = pEndpoint; + bundlesSent++; + totalPktsInBundle += packetsInScatterReq; + packetsInScatterReq = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,(" Send Scatter total bytes: %d , entries: %d\n", + pScatterReq->TotalLength,pScatterReq->ValidScatterEntries)); + DevSubmitScatterRequest(&target->Device, pScatterReq, DEV_SCATTER_WRITE, DEV_SCATTER_ASYNC); + /* we don't own this anymore */ + pScatterReq = NULL; + /* try to send some more */ + continue; + } + + /* not enough packets to use the scatter request, cleanup */ + if (pScatterReq != NULL) { + if (packetsInScatterReq > 0) { + /* work backwards to requeue requests */ + for (i = (packetsInScatterReq - 1); i >= 0; i--) { + pPacket = (HTC_PACKET *)(pScatterReq->ScatterList[i].pCallerContexts[0]); + if (pPacket != NULL) { + /* undo any prep */ + HTC_UNPREPARE_SEND_PKT(pPacket); + /* queue back to the head */ + HTC_PACKET_ENQUEUE_TO_HEAD(pQueue,pPacket); + } + } + } + DEV_FREE_SCATTER_REQ(&target->Device,pScatterReq); + } + + /* if we get here, we sent all that we could, get out */ + break; + + } + + *pBundlesSent = bundlesSent; + *pTotalBundlesPkts = totalPktsInBundle; + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HTCIssueSendBundle (sent:%d) \n",bundlesSent)); + + return; +} + +/* + * if there are no credits, the packet(s) remains in the queue. + * this function returns the result of the attempt to send a queue of HTC packets */ +static HTC_SEND_QUEUE_RESULT HTCTrySend(HTC_TARGET *target, + HTC_ENDPOINT *pEndpoint, + HTC_PACKET_QUEUE *pCallersSendQueue) +{ + HTC_PACKET_QUEUE sendQueue = { {0} }; /* temp queue to hold packets at various stages */ + HTC_PACKET *pPacket; + int bundlesSent; + int pktsInBundles; + int overflow; + HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HTCTrySend (Queue:0x%lX Depth:%d)\n", + (unsigned long)pCallersSendQueue, + (pCallersSendQueue == NULL) ? 0 : HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue))); + + /* init the local send queue */ + INIT_HTC_PACKET_QUEUE(&sendQueue); + + do { + + if (NULL == pCallersSendQueue) { + /* caller didn't provide a queue, just wants us to check queues and send */ + break; + } + + if (HTC_QUEUE_EMPTY(pCallersSendQueue)) { + /* empty queue */ + result = HTC_SEND_QUEUE_DROP; + break; + } + + if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >= pEndpoint->MaxTxQueueDepth) { + /* we've already overflowed */ + overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue); + } else { + /* figure out how much we will overflow by */ + overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); + overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue); + /* figure out how much we will overflow the TX queue by */ + overflow -= pEndpoint->MaxTxQueueDepth; + } + + /* if overflow is negative or zero, we are okay */ + if (overflow > 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + (" Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d \n", + pEndpoint->Id, overflow, HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue), pEndpoint->MaxTxQueueDepth)); + } + if ((overflow <= 0) || (pEndpoint->EpCallBacks.EpSendFull == NULL)) { + /* all packets will fit or caller did not provide send full indication handler + * -- just move all of them to the local sendQueue object */ + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue, pCallersSendQueue); + } else { + int i; + int goodPkts = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) - overflow; + + A_ASSERT(goodPkts >= 0); + /* we have overflowed, and a callback is provided */ + /* dequeue all non-overflow packets into the sendqueue */ + for (i = 0; i < goodPkts; i++) { + /* pop off caller's queue*/ + pPacket = HTC_PACKET_DEQUEUE(pCallersSendQueue); + A_ASSERT(pPacket != NULL); + /* insert into local queue */ + HTC_PACKET_ENQUEUE(&sendQueue,pPacket); + } + + /* the caller's queue has all the packets that won't fit*/ + /* walk through the caller's queue and indicate each one to the send full handler */ + ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->QueueHead, pPacket, HTC_PACKET, ListLink) { + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" Indicating overflowed TX packet: 0x%lX \n", + (unsigned long)pPacket)); + if (pEndpoint->EpCallBacks.EpSendFull(pEndpoint->EpCallBacks.pContext, + pPacket) == HTC_SEND_FULL_DROP) { + /* callback wants the packet dropped */ + INC_HTC_EP_STAT(pEndpoint, TxDropped, 1); + /* leave this one in the caller's queue for cleanup */ + } else { + /* callback wants to keep this packet, remove from caller's queue */ + HTC_PACKET_REMOVE(pCallersSendQueue, pPacket); + /* put it in the send queue */ + HTC_PACKET_ENQUEUE(&sendQueue,pPacket); + } + + } ITERATE_END; + + if (HTC_QUEUE_EMPTY(&sendQueue)) { + /* no packets made it in, caller will cleanup */ + result = HTC_SEND_QUEUE_DROP; + break; + } + } + + } while (FALSE); + + if (result != HTC_SEND_QUEUE_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HTCTrySend: \n")); + return result; + } + + LOCK_HTC_TX(target); + + if (!HTC_QUEUE_EMPTY(&sendQueue)) { + /* transfer packets */ + HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,&sendQueue); + A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue)); + INIT_HTC_PACKET_QUEUE(&sendQueue); + } + + /* increment tx processing count on entry */ + pEndpoint->TxProcessCount++; + if (pEndpoint->TxProcessCount > 1) { + /* another thread or task is draining the TX queues on this endpoint + * that thread will reset the tx processing count when the queue is drained */ + pEndpoint->TxProcessCount--; + UNLOCK_HTC_TX(target); + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HTCTrySend (busy) \n")); + return HTC_SEND_QUEUE_OK; + } + + /***** beyond this point only 1 thread may enter ******/ + + /* now drain the endpoint TX queue for transmission as long as we have enough + * credits */ + while (TRUE) { + + if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0) { + break; + } + + /* get all the packets for this endpoint that we can for this pass */ + GetHTCSendPackets(target, pEndpoint, &sendQueue); + + if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) { + /* didn't get any packets due to a lack of credits */ + break; + } + + UNLOCK_HTC_TX(target); + + /* any packets to send are now in our local send queue */ + + bundlesSent = 0; + pktsInBundles = 0; + + while (TRUE) { + + /* try to send a bundle on each pass */ + if ((target->SendBundlingEnabled) && + (HTC_PACKET_QUEUE_DEPTH(&sendQueue) >= HTC_MIN_HTC_MSGS_TO_BUNDLE)) { + int temp1,temp2; + /* bundling is enabled and there is at least a minimum number of packets in the send queue + * send what we can in this pass */ + HTCIssueSendBundle(pEndpoint, &sendQueue, &temp1, &temp2); + bundlesSent += temp1; + pktsInBundles += temp2; + } + + /* if not bundling or there was a packet that could not be placed in a bundle, pull it out + * and send it the normal way */ + pPacket = HTC_PACKET_DEQUEUE(&sendQueue); + if (NULL == pPacket) { + /* local queue is fully drained */ + break; + } + HTC_PREPARE_SEND_PKT(pPacket, + pPacket->PktInfo.AsTx.SendFlags, + 0, + pPacket->PktInfo.AsTx.SeqNo); + HTCIssueSend(target, pPacket); + + /* go back and see if we can bundle some more */ + } + + LOCK_HTC_TX(target); + + INC_HTC_EP_STAT(pEndpoint, TxBundles, bundlesSent); + INC_HTC_EP_STAT(pEndpoint, TxPacketsBundled, pktsInBundles); + + } + + /* done with this endpoint, we can clear the count */ + pEndpoint->TxProcessCount = 0; + UNLOCK_HTC_TX(target); + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("-HTCTrySend: \n")); + + return HTC_SEND_QUEUE_OK; +} + +A_STATUS HTCSendPktsMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_ENDPOINT *pEndpoint; + HTC_PACKET *pPacket; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+HTCSendPktsMultiple: Queue: 0x%lX, Pkts %d \n", + (unsigned long)pPktQueue, HTC_PACKET_QUEUE_DEPTH(pPktQueue))); + + /* get packet at head to figure out which endpoint these packets will go into */ + pPacket = HTC_GET_PKT_AT_HEAD(pPktQueue); + if (NULL == pPacket) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-HTCSendPktsMultiple \n")); + return A_EINVAL; + } + + AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX); + pEndpoint = &target->EndPoint[pPacket->Endpoint]; + + HTCTrySend(target, pEndpoint, pPktQueue); + + /* do completion on any packets that couldn't get in */ + if (!HTC_QUEUE_EMPTY(pPktQueue)) { + + HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue,pPacket) { + if (HTC_STOPPING(target)) { + pPacket->Status = A_ECANCELED; + } else { + pPacket->Status = A_NO_RESOURCE; + } + } HTC_PACKET_QUEUE_ITERATE_END; + + DO_EP_TX_COMPLETION(pEndpoint,pPktQueue); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-HTCSendPktsMultiple \n")); + + return A_OK; +} + +/* HTC API - HTCSendPkt */ +A_STATUS HTCSendPkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket) +{ + HTC_PACKET_QUEUE queue = { {0} }; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, + ("+-HTCSendPkt: Enter endPointId: %d, buffer: 0x%lX, length: %d \n", + pPacket->Endpoint, (unsigned long)pPacket->pBuffer, pPacket->ActualLength)); + INIT_HTC_PACKET_QUEUE_AND_ADD(&queue,pPacket); + return HTCSendPktsMultiple(HTCHandle, &queue); +} + +/* check TX queues to drain because of credit distribution update */ +static INLINE void HTCCheckEndpointTxQueues(HTC_TARGET *target) +{ + HTC_ENDPOINT *pEndpoint; + HTC_ENDPOINT_CREDIT_DIST *pDistItem; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+HTCCheckEndpointTxQueues \n")); + pDistItem = target->EpCreditDistributionListHead; + + /* run through the credit distribution list to see + * if there are packets queued + * NOTE: no locks need to be taken since the distribution list + * is not dynamic (cannot be re-ordered) and we are not modifying any state */ + while (pDistItem != NULL) { + pEndpoint = (HTC_ENDPOINT *)pDistItem->pHTCReserved; + + if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) > 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" Ep %d has %d credits and %d Packets in TX Queue \n", + pDistItem->Endpoint, pEndpoint->CreditDist.TxCredits, HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue))); + /* try to start the stalled queue, this list is ordered by priority. + * Highest priority queue get's processed first, if there are credits available the + * highest priority queue will get a chance to reclaim credits from lower priority + * ones */ + HTCTrySend(target, pEndpoint, NULL); + } + + pDistItem = pDistItem->pNext; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-HTCCheckEndpointTxQueues \n")); +} + +/* process credit reports and call distribution function */ +void HTCProcessCreditRpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt, int NumEntries, HTC_ENDPOINT_ID FromEndpoint) +{ + int i; + HTC_ENDPOINT *pEndpoint; + int totalCredits = 0; + A_BOOL doDist = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+HTCProcessCreditRpt, Credit Report Entries:%d \n", NumEntries)); + + /* lock out TX while we update credits */ + LOCK_HTC_TX(target); + + for (i = 0; i < NumEntries; i++, pRpt++) { + if (pRpt->EndpointID >= ENDPOINT_MAX) { + AR_DEBUG_ASSERT(FALSE); + break; + } + + pEndpoint = &target->EndPoint[pRpt->EndpointID]; + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" Endpoint %d got %d credits \n", + pRpt->EndpointID, pRpt->Credits)); + + +#ifdef HTC_EP_STAT_PROFILING + + INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1); + INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, pRpt->Credits); + + if (FromEndpoint == pRpt->EndpointID) { + /* this credit report arrived on the same endpoint indicating it arrived in an RX + * packet */ + INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx, pRpt->Credits); + INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1); + } else if (FromEndpoint == ENDPOINT_0) { + /* this credit arrived on endpoint 0 as a NULL message */ + INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0, pRpt->Credits); + INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1); + } else { + /* arrived on another endpoint */ + INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther, pRpt->Credits); + INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1); + } + +#endif + + if (ENDPOINT_0 == pRpt->EndpointID) { + /* always give endpoint 0 credits back */ + pEndpoint->CreditDist.TxCredits += pRpt->Credits; + } else { + /* for all other endpoints, update credits to distribute, the distribution function + * will handle giving out credits back to the endpoints */ + pEndpoint->CreditDist.TxCreditsToDist += pRpt->Credits; + /* flag that we have to do the distribution */ + doDist = TRUE; + } + + /* refresh tx depth for distribution function that will recover these credits + * NOTE: this is only valid when there are credits to recover! */ + pEndpoint->CreditDist.TxQueueDepth = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); + + totalCredits += pRpt->Credits; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" Report indicated %d credits to distribute \n", totalCredits)); + + if (doDist) { + /* this was a credit return based on a completed send operations + * note, this is done with the lock held */ + DO_DISTRIBUTION(target, + HTC_CREDIT_DIST_SEND_COMPLETE, + "Send Complete", + target->EpCreditDistributionListHead->pNext); + } + + UNLOCK_HTC_TX(target); + + if (totalCredits) { + HTCCheckEndpointTxQueues(target); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-HTCProcessCreditRpt \n")); +} + +/* flush endpoint TX queue */ +static void HTCFlushEndpointTX(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint, HTC_TX_TAG Tag) +{ + HTC_PACKET *pPacket; + HTC_PACKET_QUEUE discardQueue = { {0} }; + HTC_PACKET_QUEUE container = { {0} }; + + /* initialize the discard queue */ + INIT_HTC_PACKET_QUEUE(&discardQueue); + + LOCK_HTC_TX(target); + + /* interate from the front of the TX queue and flush out packets */ + ITERATE_OVER_LIST_ALLOW_REMOVE(&pEndpoint->TxQueue.QueueHead, pPacket, HTC_PACKET, ListLink) { + + /* check for removal */ + if ((HTC_TX_PACKET_TAG_ALL == Tag) || (Tag == pPacket->PktInfo.AsTx.Tag)) { + /* remove from queue */ + HTC_PACKET_REMOVE(&pEndpoint->TxQueue, pPacket); + /* add it to the discard pile */ + HTC_PACKET_ENQUEUE(&discardQueue, pPacket); + } + + } ITERATE_END; + + UNLOCK_HTC_TX(target); + + /* empty the discard queue */ + while (1) { + pPacket = HTC_PACKET_DEQUEUE(&discardQueue); + if (NULL == pPacket) { + break; + } + pPacket->Status = A_ECANCELED; + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, (" Flushing TX packet:0x%lX, length:%d, ep:%d tag:0x%X \n", + (unsigned long)pPacket, pPacket->ActualLength, pPacket->Endpoint, pPacket->PktInfo.AsTx.Tag)); + INIT_HTC_PACKET_QUEUE_AND_ADD(&container,pPacket); + DO_EP_TX_COMPLETION(pEndpoint,&container); + } + +} + +void DumpCreditDist(HTC_ENDPOINT_CREDIT_DIST *pEPDist) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("--- EP : %d ServiceID: 0x%X --------------\n", + pEPDist->Endpoint, pEPDist->ServiceID)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" this:0x%lX next:0x%lX prev:0x%lX\n", + (unsigned long)pEPDist, (unsigned long)pEPDist->pNext, (unsigned long)pEPDist->pPrev)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" DistFlags : 0x%X \n", pEPDist->DistFlags)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsNorm : %d \n", pEPDist->TxCreditsNorm)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsMin : %d \n", pEPDist->TxCreditsMin)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCredits : %d \n", pEPDist->TxCredits)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsAssigned : %d \n", pEPDist->TxCreditsAssigned)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsSeek : %d \n", pEPDist->TxCreditsSeek)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditSize : %d \n", pEPDist->TxCreditSize)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsPerMaxMsg : %d \n", pEPDist->TxCreditsPerMaxMsg)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxCreditsToDist : %d \n", pEPDist->TxCreditsToDist)); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, (" TxQueueDepth : %d \n", + HTC_PACKET_QUEUE_DEPTH(&((HTC_ENDPOINT *)pEPDist->pHTCReserved)->TxQueue))); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("----------------------------------------------------\n")); +} + +void DumpCreditDistStates(HTC_TARGET *target) +{ + HTC_ENDPOINT_CREDIT_DIST *pEPList = target->EpCreditDistributionListHead; + + while (pEPList != NULL) { + DumpCreditDist(pEPList); + pEPList = pEPList->pNext; + } + + if (target->DistributeCredits != NULL) { + DO_DISTRIBUTION(target, + HTC_DUMP_CREDIT_STATE, + "Dump State", + NULL); + } +} + +/* flush all send packets from all endpoint queues */ +void HTCFlushSendPkts(HTC_TARGET *target) +{ + HTC_ENDPOINT *pEndpoint; + int i; + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_TRC)) { + DumpCreditDistStates(target); + } + + for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) { + pEndpoint = &target->EndPoint[i]; + if (pEndpoint->ServiceID == 0) { + /* not in use.. */ + continue; + } + HTCFlushEndpointTX(target,pEndpoint,HTC_TX_PACKET_TAG_ALL); + } + + +} + +/* HTC API to flush an endpoint's TX queue*/ +void HTCFlushEndpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint, HTC_TX_TAG Tag) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_ENDPOINT *pEndpoint = &target->EndPoint[Endpoint]; + + if (pEndpoint->ServiceID == 0) { + AR_DEBUG_ASSERT(FALSE); + /* not in use.. */ + return; + } + + HTCFlushEndpointTX(target, pEndpoint, Tag); +} + +/* HTC API to indicate activity to the credit distribution function */ +void HTCIndicateActivityChange(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint, + A_BOOL Active) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_ENDPOINT *pEndpoint = &target->EndPoint[Endpoint]; + A_BOOL doDist = FALSE; + + if (pEndpoint->ServiceID == 0) { + AR_DEBUG_ASSERT(FALSE); + /* not in use.. */ + return; + } + + LOCK_HTC_TX(target); + + if (Active) { + if (!(pEndpoint->CreditDist.DistFlags & HTC_EP_ACTIVE)) { + /* mark active now */ + pEndpoint->CreditDist.DistFlags |= HTC_EP_ACTIVE; + doDist = TRUE; + } + } else { + if (pEndpoint->CreditDist.DistFlags & HTC_EP_ACTIVE) { + /* mark inactive now */ + pEndpoint->CreditDist.DistFlags &= ~HTC_EP_ACTIVE; + doDist = TRUE; + } + } + + if (doDist) { + /* indicate current Tx Queue depth to the credit distribution function */ + pEndpoint->CreditDist.TxQueueDepth = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); + /* do distribution again based on activity change + * note, this is done with the lock held */ + DO_DISTRIBUTION(target, + HTC_CREDIT_DIST_ACTIVITY_CHANGE, + "Activity Change", + target->EpCreditDistributionListHead->pNext); + } + + UNLOCK_HTC_TX(target); + + if (doDist && !Active) { + /* if a stream went inactive and this resulted in a credit distribution change, + * some credits may now be available for HTC packets that are stuck in + * HTC queues */ + HTCCheckEndpointTxQueues(target); + } +} + +A_BOOL HTCIsEndpointActive(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + HTC_ENDPOINT *pEndpoint = &target->EndPoint[Endpoint]; + + if (pEndpoint->ServiceID == 0) { + return FALSE; + } + + if (pEndpoint->CreditDist.DistFlags & HTC_EP_ACTIVE) { + return TRUE; + } + + return FALSE; +} diff --git a/drivers/net/wireless/ar6003/host/htc2/htc_services.c b/drivers/net/wireless/ar6003/host/htc2/htc_services.c new file mode 100644 index 000000000000..3488208cd4cf --- /dev/null +++ b/drivers/net/wireless/ar6003/host/htc2/htc_services.c @@ -0,0 +1,449 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#include "htc_internal.h" + +void HTCControlTxComplete(void *Context, HTC_PACKET *pPacket) +{ + /* not implemented + * we do not send control TX frames during normal runtime, only during setup */ + AR_DEBUG_ASSERT(FALSE); +} + + /* callback when a control message arrives on this endpoint */ +void HTCControlRecv(void *Context, HTC_PACKET *pPacket) +{ + AR_DEBUG_ASSERT(pPacket->Endpoint == ENDPOINT_0); + + if (pPacket->Status == A_ECANCELED) { + /* this is a flush operation, return the control packet back to the pool */ + HTC_FREE_CONTROL_RX((HTC_TARGET*)Context,pPacket); + return; + } + + /* the only control messages we are expecting are NULL messages (credit resports) */ + if (pPacket->ActualLength > 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("HTCControlRecv, got message with length:%d \n", + pPacket->ActualLength + (A_UINT32)HTC_HDR_LENGTH)); + + /* dump header and message */ + DebugDumpBytes(pPacket->pBuffer - HTC_HDR_LENGTH, + pPacket->ActualLength + HTC_HDR_LENGTH, + "Unexpected ENDPOINT 0 Message"); + } + + HTC_RECYCLE_RX_PKT((HTC_TARGET*)Context,pPacket,&((HTC_TARGET*)Context)->EndPoint[0]); +} + +A_STATUS HTCSendSetupComplete(HTC_TARGET *target) +{ + HTC_PACKET *pSendPacket = NULL; + A_STATUS status; + + do { + /* allocate a packet to send to the target */ + pSendPacket = HTC_ALLOC_CONTROL_TX(target); + + if (NULL == pSendPacket) { + status = A_NO_MEMORY; + break; + } + + if (target->HTCTargetVersion >= HTC_VERSION_2P1) { + HTC_SETUP_COMPLETE_EX_MSG *pSetupCompleteEx; + A_UINT32 setupFlags = 0; + + pSetupCompleteEx = (HTC_SETUP_COMPLETE_EX_MSG *)pSendPacket->pBuffer; + A_MEMZERO(pSetupCompleteEx, sizeof(HTC_SETUP_COMPLETE_EX_MSG)); + pSetupCompleteEx->MessageID = HTC_MSG_SETUP_COMPLETE_EX_ID; + if (target->MaxMsgPerBundle > 0) { + /* host can do HTC bundling, indicate this to the target */ + setupFlags |= HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV; + pSetupCompleteEx->MaxMsgsPerBundledRecv = target->MaxMsgPerBundle; + } + A_MEMCPY(&pSetupCompleteEx->SetupFlags, &setupFlags, sizeof(pSetupCompleteEx->SetupFlags)); + SET_HTC_PACKET_INFO_TX(pSendPacket, + NULL, + (A_UINT8 *)pSetupCompleteEx, + sizeof(HTC_SETUP_COMPLETE_EX_MSG), + ENDPOINT_0, + HTC_SERVICE_TX_PACKET_TAG); + + } else { + HTC_SETUP_COMPLETE_MSG *pSetupComplete; + /* assemble setup complete message */ + pSetupComplete = (HTC_SETUP_COMPLETE_MSG *)pSendPacket->pBuffer; + A_MEMZERO(pSetupComplete, sizeof(HTC_SETUP_COMPLETE_MSG)); + pSetupComplete->MessageID = HTC_MSG_SETUP_COMPLETE_ID; + SET_HTC_PACKET_INFO_TX(pSendPacket, + NULL, + (A_UINT8 *)pSetupComplete, + sizeof(HTC_SETUP_COMPLETE_MSG), + ENDPOINT_0, + HTC_SERVICE_TX_PACKET_TAG); + } + + /* we want synchronous operation */ + pSendPacket->Completion = NULL; + HTC_PREPARE_SEND_PKT(pSendPacket,0,0,0); + /* send the message */ + status = HTCIssueSend(target,pSendPacket); + + } while (FALSE); + + if (pSendPacket != NULL) { + HTC_FREE_CONTROL_TX(target,pSendPacket); + } + + return status; +} + + +A_STATUS HTCConnectService(HTC_HANDLE HTCHandle, + HTC_SERVICE_CONNECT_REQ *pConnectReq, + HTC_SERVICE_CONNECT_RESP *pConnectResp) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + A_STATUS status = A_OK; + HTC_PACKET *pRecvPacket = NULL; + HTC_PACKET *pSendPacket = NULL; + HTC_CONNECT_SERVICE_RESPONSE_MSG *pResponseMsg; + HTC_CONNECT_SERVICE_MSG *pConnectMsg; + HTC_ENDPOINT_ID assignedEndpoint = ENDPOINT_MAX; + HTC_ENDPOINT *pEndpoint; + unsigned int maxMsgSize = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCConnectService, target:0x%lX SvcID:0x%X \n", + (unsigned long)target, pConnectReq->ServiceID)); + + do { + + AR_DEBUG_ASSERT(pConnectReq->ServiceID != 0); + + if (HTC_CTRL_RSVD_SVC == pConnectReq->ServiceID) { + /* special case for pseudo control service */ + assignedEndpoint = ENDPOINT_0; + maxMsgSize = HTC_MAX_CONTROL_MESSAGE_LENGTH; + } else { + /* allocate a packet to send to the target */ + pSendPacket = HTC_ALLOC_CONTROL_TX(target); + + if (NULL == pSendPacket) { + AR_DEBUG_ASSERT(FALSE); + status = A_NO_MEMORY; + break; + } + /* assemble connect service message */ + pConnectMsg = (HTC_CONNECT_SERVICE_MSG *)pSendPacket->pBuffer; + AR_DEBUG_ASSERT(pConnectMsg != NULL); + A_MEMZERO(pConnectMsg,sizeof(HTC_CONNECT_SERVICE_MSG)); + pConnectMsg->MessageID = HTC_MSG_CONNECT_SERVICE_ID; + pConnectMsg->ServiceID = pConnectReq->ServiceID; + pConnectMsg->ConnectionFlags = pConnectReq->ConnectionFlags; + /* check caller if it wants to transfer meta data */ + if ((pConnectReq->pMetaData != NULL) && + (pConnectReq->MetaDataLength <= HTC_SERVICE_META_DATA_MAX_LENGTH)) { + /* copy meta data into message buffer (after header ) */ + A_MEMCPY((A_UINT8 *)pConnectMsg + sizeof(HTC_CONNECT_SERVICE_MSG), + pConnectReq->pMetaData, + pConnectReq->MetaDataLength); + pConnectMsg->ServiceMetaLength = pConnectReq->MetaDataLength; + } + + SET_HTC_PACKET_INFO_TX(pSendPacket, + NULL, + (A_UINT8 *)pConnectMsg, + sizeof(HTC_CONNECT_SERVICE_MSG) + pConnectMsg->ServiceMetaLength, + ENDPOINT_0, + HTC_SERVICE_TX_PACKET_TAG); + + /* we want synchronous operation */ + pSendPacket->Completion = NULL; + HTC_PREPARE_SEND_PKT(pSendPacket,0,0,0); + status = HTCIssueSend(target,pSendPacket); + + if (A_FAILED(status)) { + break; + } + + /* wait for response */ + status = HTCWaitforControlMessage(target, &pRecvPacket); + + if (A_FAILED(status)) { + break; + } + /* we controlled the buffer creation so it has to be properly aligned */ + pResponseMsg = (HTC_CONNECT_SERVICE_RESPONSE_MSG *)pRecvPacket->pBuffer; + + if ((pResponseMsg->MessageID != HTC_MSG_CONNECT_SERVICE_RESPONSE_ID) || + (pRecvPacket->ActualLength < sizeof(HTC_CONNECT_SERVICE_RESPONSE_MSG))) { + /* this message is not valid */ + AR_DEBUG_ASSERT(FALSE); + status = A_EPROTO; + break; + } + + pConnectResp->ConnectRespCode = pResponseMsg->Status; + /* check response status */ + if (pResponseMsg->Status != HTC_SERVICE_SUCCESS) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + (" Target failed service 0x%X connect request (status:%d)\n", + pResponseMsg->ServiceID, pResponseMsg->Status)); + status = A_EPROTO; + break; + } + + assignedEndpoint = (HTC_ENDPOINT_ID) pResponseMsg->EndpointID; + maxMsgSize = pResponseMsg->MaxMsgSize; + + if ((pConnectResp->pMetaData != NULL) && + (pResponseMsg->ServiceMetaLength > 0) && + (pResponseMsg->ServiceMetaLength <= HTC_SERVICE_META_DATA_MAX_LENGTH)) { + /* caller supplied a buffer and the target responded with data */ + int copyLength = min((int)pConnectResp->BufferLength, (int)pResponseMsg->ServiceMetaLength); + /* copy the meta data */ + A_MEMCPY(pConnectResp->pMetaData, + ((A_UINT8 *)pResponseMsg) + sizeof(HTC_CONNECT_SERVICE_RESPONSE_MSG), + copyLength); + pConnectResp->ActualLength = copyLength; + } + + } + + /* the rest of these are parameter checks so set the error status */ + status = A_EPROTO; + + if (assignedEndpoint >= ENDPOINT_MAX) { + AR_DEBUG_ASSERT(FALSE); + break; + } + + if (0 == maxMsgSize) { + AR_DEBUG_ASSERT(FALSE); + break; + } + + pEndpoint = &target->EndPoint[assignedEndpoint]; + pEndpoint->Id = assignedEndpoint; + if (pEndpoint->ServiceID != 0) { + /* endpoint already in use! */ + AR_DEBUG_ASSERT(FALSE); + break; + } + + /* return assigned endpoint to caller */ + pConnectResp->Endpoint = assignedEndpoint; + pConnectResp->MaxMsgLength = maxMsgSize; + + /* setup the endpoint */ + pEndpoint->ServiceID = pConnectReq->ServiceID; /* this marks the endpoint in use */ + pEndpoint->MaxTxQueueDepth = pConnectReq->MaxSendQueueDepth; + pEndpoint->MaxMsgLength = maxMsgSize; + /* copy all the callbacks */ + pEndpoint->EpCallBacks = pConnectReq->EpCallbacks; + /* set the credit distribution info for this endpoint, this information is + * passed back to the credit distribution callback function */ + pEndpoint->CreditDist.ServiceID = pConnectReq->ServiceID; + pEndpoint->CreditDist.pHTCReserved = pEndpoint; + pEndpoint->CreditDist.Endpoint = assignedEndpoint; + pEndpoint->CreditDist.TxCreditSize = target->TargetCreditSize; + + if (pConnectReq->MaxSendMsgSize != 0) { + /* override TxCreditsPerMaxMsg calculation, this optimizes the credit-low indications + * since the host will actually issue smaller messages in the Send path */ + if (pConnectReq->MaxSendMsgSize > maxMsgSize) { + /* can't be larger than the maximum the target can support */ + AR_DEBUG_ASSERT(FALSE); + break; + } + pEndpoint->CreditDist.TxCreditsPerMaxMsg = pConnectReq->MaxSendMsgSize / target->TargetCreditSize; + } else { + pEndpoint->CreditDist.TxCreditsPerMaxMsg = maxMsgSize / target->TargetCreditSize; + } + + if (0 == pEndpoint->CreditDist.TxCreditsPerMaxMsg) { + pEndpoint->CreditDist.TxCreditsPerMaxMsg = 1; + } + + /* save local connection flags */ + pEndpoint->LocalConnectionFlags = pConnectReq->LocalConnectionFlags; + + status = A_OK; + + } while (FALSE); + + if (pSendPacket != NULL) { + HTC_FREE_CONTROL_TX(target,pSendPacket); + } + + if (pRecvPacket != NULL) { + HTC_FREE_CONTROL_RX(target,pRecvPacket); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCConnectService \n")); + + return status; +} + +static void AddToEndpointDistList(HTC_TARGET *target, HTC_ENDPOINT_CREDIT_DIST *pEpDist) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEntry = NULL; + HTC_ENDPOINT_CREDIT_DIST *pLastEntry = NULL; + + if (NULL == target->EpCreditDistributionListHead) { + target->EpCreditDistributionListHead = pEpDist; + pEpDist->pNext = NULL; + pEpDist->pPrev = NULL; + return; + } + + /* queue to the end of the list, this does not have to be very + * fast since this list is built at startup time */ + pCurEntry = target->EpCreditDistributionListHead; + + while (pCurEntry) { + pLastEntry = pCurEntry; + pCurEntry = pCurEntry->pNext; + } + + pLastEntry->pNext = pEpDist; + pEpDist->pPrev = pLastEntry; + pEpDist->pNext = NULL; +} + + + +/* default credit init callback */ +static void HTCDefaultCreditInit(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPList, + int TotalCredits) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist; + int totalEps = 0; + int creditsPerEndpoint; + + pCurEpDist = pEPList; + /* first run through the list and figure out how many endpoints we are dealing with */ + while (pCurEpDist != NULL) { + pCurEpDist = pCurEpDist->pNext; + totalEps++; + } + + /* even distribution */ + creditsPerEndpoint = TotalCredits/totalEps; + + pCurEpDist = pEPList; + /* run through the list and set minimum and normal credits and + * provide the endpoint with some credits to start */ + while (pCurEpDist != NULL) { + + if (creditsPerEndpoint < pCurEpDist->TxCreditsPerMaxMsg) { + /* too many endpoints and not enough credits */ + AR_DEBUG_ASSERT(FALSE); + break; + } + /* our minimum is set for at least 1 max message */ + pCurEpDist->TxCreditsMin = pCurEpDist->TxCreditsPerMaxMsg; + /* this value is ignored by our credit alg, since we do + * not dynamically adjust credits, this is the policy of + * the "default" credit distribution, something simple and easy */ + pCurEpDist->TxCreditsNorm = 0xFFFF; + /* give the endpoint minimum credits */ + pCurEpDist->TxCredits = creditsPerEndpoint; + pCurEpDist->TxCreditsAssigned = creditsPerEndpoint; + pCurEpDist = pCurEpDist->pNext; + } + +} + +/* default credit distribution callback, NOTE, this callback holds the TX lock */ +void HTCDefaultCreditDist(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPDistList, + HTC_CREDIT_DIST_REASON Reason) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist; + + if (Reason == HTC_CREDIT_DIST_SEND_COMPLETE) { + pCurEpDist = pEPDistList; + /* simple distribution */ + while (pCurEpDist != NULL) { + if (pCurEpDist->TxCreditsToDist > 0) { + /* just give the endpoint back the credits */ + pCurEpDist->TxCredits += pCurEpDist->TxCreditsToDist; + pCurEpDist->TxCreditsToDist = 0; + } + pCurEpDist = pCurEpDist->pNext; + } + } + + /* note we do not need to handle the other reason codes as this is a very + * simple distribution scheme, no need to seek for more credits or handle inactivity */ +} + +void HTCSetCreditDistribution(HTC_HANDLE HTCHandle, + void *pCreditDistContext, + HTC_CREDIT_DIST_CALLBACK CreditDistFunc, + HTC_CREDIT_INIT_CALLBACK CreditInitFunc, + HTC_SERVICE_ID ServicePriorityOrder[], + int ListLength) +{ + HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); + int i; + int ep; + + if (CreditInitFunc != NULL) { + /* caller has supplied their own distribution functions */ + target->InitCredits = CreditInitFunc; + AR_DEBUG_ASSERT(CreditDistFunc != NULL); + target->DistributeCredits = CreditDistFunc; + target->pCredDistContext = pCreditDistContext; + } else { + /* caller wants HTC to do distribution */ + /* if caller wants service to handle distributions then + * it must set both of these to NULL! */ + AR_DEBUG_ASSERT(CreditDistFunc == NULL); + target->InitCredits = HTCDefaultCreditInit; + target->DistributeCredits = HTCDefaultCreditDist; + target->pCredDistContext = target; + } + + /* always add HTC control endpoint first, we only expose the list after the + * first one, this is added for TX queue checking */ + AddToEndpointDistList(target, &target->EndPoint[ENDPOINT_0].CreditDist); + + /* build the list of credit distribution structures in priority order + * supplied by the caller, these will follow endpoint 0 */ + for (i = 0; i < ListLength; i++) { + /* match services with endpoints and add the endpoints to the distribution list + * in FIFO order */ + for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) { + if (target->EndPoint[ep].ServiceID == ServicePriorityOrder[i]) { + /* queue this one to the list */ + AddToEndpointDistList(target, &target->EndPoint[ep].CreditDist); + break; + } + } + AR_DEBUG_ASSERT(ep < ENDPOINT_MAX); + } + +} diff --git a/drivers/net/wireless/ar6003/host/include/a_config.h b/drivers/net/wireless/ar6003/host/include/a_config.h new file mode 100644 index 000000000000..5f789917b39b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_config.h @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains software configuration options that enables +// specific software "features" +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_CONFIG_H_ +#define _A_CONFIG_H_ + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/config.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/config.h" +#endif + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/config_linux.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/config_rexos.h" +#endif + +#ifdef ATHR_WIN_NWF +#include "../os/windows/include/config.h" +#pragma warning( disable:4242) +#pragma warning( disable:4100) +#pragma warning( disable:4189) +#pragma warning( disable:4244) +#pragma warning( disable:4701) +#pragma warning( disable:4389) +#pragma warning( disable:4057) +#pragma warning( disable:28193) +#endif + +#endif diff --git a/drivers/net/wireless/ar6003/host/include/a_debug.h b/drivers/net/wireless/ar6003/host/include/a_debug.h new file mode 100644 index 000000000000..bde27e6bea3e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_debug.h @@ -0,0 +1,219 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_DEBUG_H_ +#define _A_DEBUG_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include + + /* standard debug print masks bits 0..7 */ +#define ATH_DEBUG_ERR (1 << 0) /* errors */ +#define ATH_DEBUG_WARN (1 << 1) /* warnings */ +#define ATH_DEBUG_INFO (1 << 2) /* informational (module startup info) */ +#define ATH_DEBUG_TRC (1 << 3) /* generic function call tracing */ +#define ATH_DEBUG_RSVD1 (1 << 4) +#define ATH_DEBUG_RSVD2 (1 << 5) +#define ATH_DEBUG_RSVD3 (1 << 6) +#define ATH_DEBUG_RSVD4 (1 << 7) + +#define ATH_DEBUG_MASK_DEFAULTS (ATH_DEBUG_ERR | ATH_DEBUG_WARN) +#define ATH_DEBUG_ANY 0xFFFF + + /* other aliases used throughout */ +#define ATH_DEBUG_ERROR ATH_DEBUG_ERR +#define ATH_LOG_ERR ATH_DEBUG_ERR +#define ATH_LOG_INF ATH_DEBUG_INFO +#define ATH_LOG_TRC ATH_DEBUG_TRC +#define ATH_DEBUG_TRACE ATH_DEBUG_TRC +#define ATH_DEBUG_INIT ATH_DEBUG_INFO + + /* bits 8..31 are module-specific masks */ +#define ATH_DEBUG_MODULE_MASK_SHIFT 8 + + /* macro to make a module-specific masks */ +#define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index))) + +void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription); + +/* Debug support on a per-module basis + * + * Usage: + * + * Each module can utilize it's own debug mask variable. A set of commonly used + * masks are provided (ERRORS, WARNINGS, TRACE etc..). It is up to each module + * to define module-specific masks using the macros above. + * + * Each module defines a single debug mask variable debug_XXX where the "name" of the module is + * common to all C-files within that module. This requires every C-file that includes a_debug.h + * to define the module name in that file. + * + * Example: + * + * #define ATH_MODULE_NAME htc + * #include "a_debug.h" + * + * This will define a debug mask structure called debug_htc and all debug macros will reference this + * variable. + * + * A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro: + * + * #define ATH_DEBUG_MY_MASK1 ATH_DEBUG_MAKE_MODULE_MASK(0) + * #define ATH_DEBUG_MY_MASK2 ATH_DEBUG_MAKE_MODULE_MASK(1) + * + * The instantiation of the debug structure should be made by the module. When a module is + * instantiated, the module can set a description string, a default mask and an array of description + * entries containing information on each module-defined debug mask. + * NOTE: The instantiation is statically allocated, only one instance can exist per module. + * + * Example: + * + * + * #define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0) + * + * #ifdef DEBUG + * static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = { + * { ATH_DEBUG_BMI , "BMI Tracing"}, <== description of the module specific mask + * }; + * + * ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi, + * "bmi" <== module name + * "Boot Manager Interface", <== description of module + * ATH_DEBUG_MASK_DEFAULTS, <== defaults + * ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc), + * bmi_debug_desc); + * + * #endif + * + * A module can optionally register it's debug module information in order for other tools to change the + * bit mask at runtime. A module can call A_REGISTER_MODULE_DEBUG_INFO() in it's module + * init code. This macro can be called multiple times without consequence. The debug info maintains + * state to indicate whether the information was previously registered. + * + * */ + +#define ATH_DEBUG_MAX_MASK_DESC_LENGTH 32 +#define ATH_DEBUG_MAX_MOD_DESC_LENGTH 64 + +typedef struct { + A_UINT32 Mask; + A_CHAR Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH]; +} ATH_DEBUG_MASK_DESCRIPTION; + +#define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0) + +typedef struct _ATH_DEBUG_MODULE_DBG_INFO{ + struct _ATH_DEBUG_MODULE_DBG_INFO *pNext; + A_CHAR ModuleName[16]; + A_CHAR ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH]; + A_UINT32 Flags; + A_UINT32 CurrentMask; + int MaxDescriptions; + ATH_DEBUG_MASK_DESCRIPTION *pMaskDescriptions; /* pointer to array of descriptions */ +} ATH_DEBUG_MODULE_DBG_INFO; + +#define ATH_DEBUG_DESCRIPTION_COUNT(d) (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION))) + +#define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s) +#define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask +#define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s + +#ifdef DEBUG + + /* for source files that will instantiate the debug variables */ +#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \ +ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \ + {NULL,(name),(moddesc),0,(initmask),count,(descriptions)} + +#ifdef ATH_MODULE_NAME +extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME); +#define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl)) +#endif /* ATH_MODULE_NAME */ + +#define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl) + +#define ATH_DEBUG_DECLARE_EXTERN(s) \ + extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) + +#define AR_DEBUG_PRINTBUF(buffer, length, desc) DebugDumpBytes(buffer,length,desc) + + +#define AR_DEBUG_ASSERT A_ASSERT + +void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo); +void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo); +#define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s))) +#define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s))) + +#else /* !DEBUG */ + /* NON DEBUG */ +#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) +#define AR_DEBUG_LVL_CHECK(lvl) 0 +#define AR_DEBUG_PRINTBUF(buffer, length, desc) +#define AR_DEBUG_ASSERT(test) +#define ATH_DEBUG_DECLARE_EXTERN(s) +#define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) +#define A_DUMP_MODULE_DEBUG_INFO(s) +#define A_REGISTER_MODULE_DEBUG_INFO(s) + +#endif + +A_STATUS a_get_module_mask(A_CHAR *module_name, A_UINT32 *pMask); +A_STATUS a_set_module_mask(A_CHAR *module_name, A_UINT32 Mask); +void a_dump_module_debug_info_by_name(A_CHAR *module_name); +void a_module_debug_support_init(void); +void a_module_debug_support_cleanup(void); + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/debug.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/debug.h" +#endif + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/debug_linux.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/debug_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/debug_win.h" +#endif + +#ifdef ATHR_WIN_NWF +#include "../os/windows/include/win/debug_win.h" +#endif + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/drivers/net/wireless/ar6003/host/include/a_drv.h b/drivers/net/wireless/ar6003/host/include/a_drv.h new file mode 100644 index 000000000000..e86f2e584ff1 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_drv.h @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the definitions of the basic atheros data types. +// It is used to map the data types in atheros files to a platform specific +// type. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_DRV_H_ +#define _A_DRV_H_ + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/athdrv_linux.h" +#endif + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/athdrv.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athdrv.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/athdrv_rexos.h" +#endif + +#ifdef ATHR_WIN_NWF +#include "../os/windows/include/athdrv.h" +#endif + +#endif /* _ADRV_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/a_drv_api.h b/drivers/net/wireless/ar6003/host/include/a_drv_api.h new file mode 100644 index 000000000000..71bc3fd20032 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_drv_api.h @@ -0,0 +1,333 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_DRV_API_H_ +#define _A_DRV_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************/ +/****************************************************************************/ +/** **/ +/** WMI related hooks **/ +/** **/ +/****************************************************************************/ +/****************************************************************************/ + +#include + +#define A_WMI_CHANNELLIST_RX(devt, numChan, chanList) \ + ar6000_channelList_rx((devt), (numChan), (chanList)) + +#define A_WMI_SET_NUMDATAENDPTS(devt, num) \ + ar6000_set_numdataendpts((devt), (num)) + +#define A_WMI_CONTROL_TX(devt, osbuf, streamID) \ + ar6000_control_tx((devt), (osbuf), (streamID)) + +#define A_WMI_TARGETSTATS_EVENT(devt, pStats, len) \ + ar6000_targetStats_event((devt), (pStats), (len)) + +#define A_WMI_SCANCOMPLETE_EVENT(devt, status) \ + ar6000_scanComplete_event((devt), (status)) + +#ifdef CONFIG_HOST_DSET_SUPPORT + +#define A_WMI_DSET_DATA_REQ(devt, access_cookie, offset, length, targ_buf, targ_reply_fn, targ_reply_arg) \ + ar6000_dset_data_req((devt), (access_cookie), (offset), (length), (targ_buf), (targ_reply_fn), (targ_reply_arg)) + +#define A_WMI_DSET_CLOSE(devt, access_cookie) \ + ar6000_dset_close((devt), (access_cookie)) + +#endif + +#define A_WMI_DSET_OPEN_REQ(devt, id, targ_handle, targ_reply_fn, targ_reply_arg) \ + ar6000_dset_open_req((devt), (id), (targ_handle), (targ_reply_fn), (targ_reply_arg)) + +#define A_WMI_CONNECT_EVENT(devt, pEvt) \ + ar6000_connect_event((devt), (pEvt)) + +#define A_WMI_PSPOLL_EVENT(devt, aid)\ + ar6000_pspoll_event((devt),(aid)) + +#define A_WMI_DTIMEXPIRY_EVENT(devt)\ + ar6000_dtimexpiry_event((devt)) + +#ifdef WAPI_ENABLE +#define A_WMI_WAPI_REKEY_EVENT(devt, type, mac)\ + ap_wapi_rekey_event((devt),(type),(mac)) +#endif + +#ifdef P2P +#define A_WMI_P2PGONEG_EVENT(devt, res, len)\ + p2p_go_neg_event((devt),(res), (len)) + +#define A_WMI_P2PGONEG_REQ_EVENT(devt, sa, dev_passwd_id)\ + p2p_go_neg_req_event((devt), (sa), (dev_passwd_id)) + +#define A_WMI_P2P_INVITE_SENT_RESULT_EVENT(devt, res, len)\ + p2p_invite_sent_result_event((devt), (res), (len)) + +#define A_WMI_P2P_INVITE_RCVD_RESULT_EVENT(devt, res, len)\ + p2p_invite_rcvd_result_event((devt), (res), (len)) + +#define A_WMI_P2PDEV_EVENT(devt, addr, dev_addr, \ + pri_dev_type, dev_name, dev_name_len, config_methods,\ + dev_capab, grp_capab)\ + ar6000_p2pdev_event((devt), (addr), (dev_addr),\ + (pri_dev_type), (dev_name), (dev_name_len), (config_methods),\ + (dev_capab), (grp_capab)) + +#define A_WMI_P2P_PROV_DISC_REQ_EVENT(devt, peer, config_methods, dev_addr, \ + pri_dev_type, dev_name, dev_name_len, supp_config_methods,\ + dev_capab, group_capab) \ + ar6000_p2p_prov_disc_req_event((devt), (peer), (config_methods), \ + (dev_addr), (pri_dev_type), (dev_name), (dev_name_len),\ + (supp_config_methods), (dev_capab), (group_capab)) + +#define A_WMI_P2P_PROV_DISC_RESP_EVENT(devt, peer, config_methods) \ + ar6000_p2p_prov_disc_resp_event((devt), (peer), (config_methods)) + +#define A_WMI_GET_P2P_CTX(devt) \ + get_p2p_ctx((devt)) + +#define A_WMI_GET_WMI_CTX(devt) \ + get_wmi_ctx((devt)) + +#define A_WMI_GET_DEV_NETWORK_SUBTYPE(devt) \ + get_network_subtype((devt)) + +#define A_WMI_P2P_SD_RX_EVENT(devt, ev) \ + ar6000_p2p_sd_rx_event((devt), (ev)) +#endif /* P2P */ + +#ifdef CONFIG_WLAN_RFKILL +#define A_WMI_RFKILL_STATE_CHANGE_EVENT(devt,radiostate) \ + ar6000_rfkill_state_change_event((devt),(radiostate)) + +#define A_WMI_RFKILL_GET_MODE_CMD_EVENT(devt,datap,len) \ + ar6000_rfkill_get_mode_cmd_event_rx((devt),(datap)); + +#endif + +#define A_WMI_REGDOMAIN_EVENT(devt, regCode) \ + ar6000_regDomain_event((devt), (regCode)) + +#define A_WMI_NEIGHBORREPORT_EVENT(devt, numAps, info) \ + ar6000_neighborReport_event((devt), (numAps), (info)) + +#define A_WMI_DISCONNECT_EVENT(devt, reason, bssid, assocRespLen, assocInfo, protocolReasonStatus) \ + ar6000_disconnect_event((devt), (reason), (bssid), (assocRespLen), (assocInfo), (protocolReasonStatus)) + +#ifdef ATH_SUPPORT_DFS + +#define A_WMI_DFS_ATTACH_EVENT(devt, capinfo) \ + ar6000_dfs_attach_event((devt),(capinfo)) + +#define A_WMI_DFS_INIT_EVENT(devt, capinfo) \ + ar6000_dfs_init_event((devt),(capinfo)) + +#define A_WMI_DFS_PHYERR_EVENT(devt, info) \ + ar6000_dfs_phyerr_event((devt),(info)) + +#define A_WMI_DFS_RESET_DELAYLINES_EVENT(devt) \ + ar6000_dfs_reset_delaylines_event((devt)) + +#define A_WMI_DFS_RESET_RADARQ_EVENT(devt) \ + ar6000_dfs_reset_radarq_event((devt)) + +#define A_WMI_DFS_RESET_AR_EVENT(devt) \ + ar6000_dfs_reset_ar_event((devt)) + +#define A_WMI_DFS_RESET_ARQ_EVENT(devt) \ + ar6000_dfs_reset_arq_event((devt)) + +#define A_WMI_DFS_SET_DUR_MULTIPLIER_EVENT(devt, value) \ + ar6000_dfs_set_dur_multiplier_event((devt), (value)) + +#define A_WMI_DFS_SET_BANGRADAR_EVENT(devt, value) \ + ar6000_dfs_set_bangradar_event((devt), (value)) + +#define A_WMI_DFS_SET_DEBUGLEVEL_EVENT(devt, value) \ + ar6000_dfs_set_debuglevel_event((devt), (value)) + +#endif /* ATH_SUPPORT_DFS */ + +#define A_WMI_TKIP_MICERR_EVENT(devt, keyid, ismcast) \ + ar6000_tkip_micerr_event((devt), (keyid), (ismcast)) + +#define A_WMI_BITRATE_RX(devt, rateKbps) \ + ar6000_bitrate_rx((devt), (rateKbps)) + +#define A_WMI_TXPWR_RX(devt, txPwr) \ + ar6000_txPwr_rx((devt), (txPwr)) + +#define A_WMI_READY_EVENT(devt, datap, phyCap, sw_ver, abi_ver) \ + ar6000_ready_event((devt), (datap), (phyCap), (sw_ver), (abi_ver)) + +#define A_WMI_DBGLOG_INIT_DONE(devt) \ + ar6000_dbglog_init_done(devt); + +#define A_WMI_RSSI_THRESHOLD_EVENT(devt, newThreshold, rssi) \ + ar6000_rssiThreshold_event((devt), (newThreshold), (rssi)) + +#define A_WMI_REPORT_ERROR_EVENT(devt, errorVal) \ + ar6000_reportError_event((devt), (errorVal)) + +#define A_WMI_ROAM_TABLE_EVENT(devt, pTbl) \ + ar6000_roam_tbl_event((devt), (pTbl)) + +#define A_WMI_ROAM_DATA_EVENT(devt, p) \ + ar6000_roam_data_event((devt), (p)) + +#define A_WMI_WOW_LIST_EVENT(devt, num_filters, wow_filters) \ + ar6000_wow_list_event((devt), (num_filters), (wow_filters)) + +#define A_WMI_CAC_EVENT(devt, ac, cac_indication, statusCode, tspecSuggestion) \ + ar6000_cac_event((devt), (ac), (cac_indication), (statusCode), (tspecSuggestion)) + +#define A_WMI_CHANNEL_CHANGE_EVENT(devt, oldChannel, newChannel) \ + ar6000_channel_change_event((devt), (oldChannel), (newChannel)) + +#define A_WMI_PMKID_LIST_EVENT(devt, num_pmkid, pmkid_list, bssid_list) \ + ar6000_pmkid_list_event((devt), (num_pmkid), (pmkid_list), (bssid_list)) + +#define A_WMI_PEER_EVENT(devt, eventCode, bssid) \ + ar6000_peer_event ((devt), (eventCode), (bssid)) + +#define A_WMI_WACINFO_EVENT(devt, pStats, len) \ + ar6000_wacinfo_event((devt), (pStats), (len)) + +#ifdef CONFIG_HOST_GPIO_SUPPORT + +#define A_WMI_GPIO_INTR_RX(devt, intr_mask, input_values) \ + ar6000_gpio_intr_rx((devt), (intr_mask), (input_values)) + +#define A_WMI_GPIO_DATA_RX(devt, reg_id, value) \ + ar6000_gpio_data_rx((devt), (reg_id), (value)) + +#define A_WMI_GPIO_ACK_RX(devt) \ + ar6000_gpio_ack_rx((devt)) + +#endif + +#ifdef SEND_EVENT_TO_APP + +#define A_WMI_SEND_EVENT_TO_APP(ar, eventId, datap, len) \ + ar6000_send_event_to_app((ar), (eventId), (datap), (len)) + +#define A_WMI_SEND_GENERIC_EVENT_TO_APP(ar, eventId, datap, len) \ + ar6000_send_generic_event_to_app((ar), (eventId), (datap), (len)) + +#else + +#define A_WMI_SEND_EVENT_TO_APP(ar, eventId, datap, len) +#define A_WMI_SEND_GENERIC_EVENT_TO_APP(ar, eventId, datap, len) + +#endif + +#ifdef CONFIG_HOST_TCMD_SUPPORT +#define A_WMI_TCMD_RX_REPORT_EVENT(devt, results, len) \ + ar6000_tcmd_rx_report_event((devt), (results), (len)) +#endif + +#define A_WMI_HBCHALLENGERESP_EVENT(devt, cookie, source) \ + ar6000_hbChallengeResp_event((devt), (cookie), (source)) + +#define A_WMI_TX_RETRY_ERR_EVENT(devt) \ + ar6000_tx_retry_err_event((devt)) + +#define A_WMI_SNR_THRESHOLD_EVENT_RX(devt, newThreshold, snr) \ + ar6000_snrThresholdEvent_rx((devt), (newThreshold), (snr)) + +#define A_WMI_LQ_THRESHOLD_EVENT_RX(devt, range, lqVal) \ + ar6000_lqThresholdEvent_rx((devt), (range), (lqVal)) + +#define A_WMI_RATEMASK_RX(devt, ratemask) \ + ar6000_ratemask_rx((devt), (ratemask)) + +#define A_WMI_KEEPALIVE_RX(devt, configured) \ + ar6000_keepalive_rx((devt), (configured)) + +#define A_WMI_BSSINFO_EVENT_RX(ar, datp, len) \ + ar6000_bssInfo_event_rx((ar), (datap), (len)) + +#define A_WMI_DBGLOG_EVENT(ar, dropped, buffer, length) \ + ar6000_dbglog_event((ar), (dropped), (buffer), (length)); + +#define A_WMI_STREAM_TX_ACTIVE(devt,trafficClass) \ + ar6000_indicate_tx_activity((devt),(trafficClass), TRUE) + +#define A_WMI_STREAM_TX_INACTIVE(devt,trafficClass) \ + ar6000_indicate_tx_activity((devt),(trafficClass), FALSE) +#define A_WMI_Ac2EndpointID(devht, ac)\ + ar6000_ac2_endpoint_id((devht), (ac)) + +#define A_WMI_AGGR_RECV_ADDBA_REQ_EVT(devt, cmd)\ + ar6000_aggr_rcv_addba_req_evt((devt), (cmd)) +#define A_WMI_AGGR_RECV_ADDBA_RESP_EVT(devt, cmd)\ + ar6000_aggr_rcv_addba_resp_evt((devt), (cmd)) +#define A_WMI_AGGR_RECV_DELBA_REQ_EVT(devt, cmd)\ + ar6000_aggr_rcv_delba_req_evt((devt), (cmd)) +#define A_WMI_HCI_EVENT_EVT(devt, cmd)\ + ar6000_hci_event_rcv_evt((devt), (cmd)) + +#define A_WMI_Endpoint2Ac(devt, ep) \ + ar6000_endpoint_id2_ac((devt), (ep)) + +#define A_WMI_BTCOEX_CONFIG_EVENT(devt, evt, len)\ + ar6000_btcoex_config_event((devt), (evt), (len)) + +#define A_WMI_BTCOEX_STATS_EVENT(devt, datap, len)\ + ar6000_btcoex_stats_event((devt), (datap), (len)) + +#define A_WMI_PROBERESP_RECV_EVENT(devt, datap, len, bssid)\ + ar6000_indicate_proberesp((devt), (datap), (len), (bssid)) + +#define A_WMI_BEACON_RECV_EVENT(devt, datap, len, bssid)\ + ar6000_indicate_beacon((devt), (datap), (len), (bssid)) + +#define A_WMI_ASSOC_REQ_REPORT_EVENT(devt, status, rspType, datap, len)\ + ar6000_assoc_req_report_event((devt),(status),(rspType),(datap),(len)) + +#define A_WMI_GET_DEVICE_ADDR(devt, addr) \ + ar6000_get_device_addr((devt), (addr)) + +/****************************************************************************/ +/****************************************************************************/ +/** **/ +/** HTC related hooks **/ +/** **/ +/****************************************************************************/ +/****************************************************************************/ + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +#define A_WMI_PROF_COUNT_RX(addr, count) prof_count_rx((addr), (count)) +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/drivers/net/wireless/ar6003/host/include/a_osapi.h b/drivers/net/wireless/ar6003/host/include/a_osapi.h new file mode 100644 index 000000000000..47b088a33c2d --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_osapi.h @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the definitions of the basic atheros data types. +// It is used to map the data types in atheros files to a platform specific +// type. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_OSAPI_H_ +#define _A_OSAPI_H_ + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/osapi_linux.h" +#endif + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/osapi.h" +#include "../os/windows/include/netbuf.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/osapi.h" +#include "../os/windows/include/netbuf.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/osapi_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/osapi_win.h" +#include "../os/win_art/include/netbuf.h" +#endif + +#ifdef ATHR_WIN_NWF +#include "../os/windows/include/win/osapi_win.h" +#include "../os/windows/include/netbuf.h" +#endif + +#endif /* _OSAPI_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/a_types.h b/drivers/net/wireless/ar6003/host/include/a_types.h new file mode 100644 index 000000000000..d80a78264342 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/a_types.h @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the definitions of the basic atheros data types. +// It is used to map the data types in atheros files to a platform specific +// type. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _A_TYPES_H_ +#define _A_TYPES_H_ + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/athtypes_linux.h" +#endif + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/athtypes.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athtypes.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/athtypes_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/athtypes_win.h" +#endif + +#ifdef ATHR_WIN_NWF +#include +#endif + +#endif /* _ATHTYPES_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/aggr_recv_api.h b/drivers/net/wireless/ar6003/host/include/aggr_recv_api.h new file mode 100644 index 000000000000..e61ec6767b18 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/aggr_recv_api.h @@ -0,0 +1,156 @@ +/* + * + * Copyright (c) 2004-2010 Atheros Communications Inc. + * All rights reserved. + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#ifndef __AGGR_RECV_API_H__ +#define __AGGR_RECV_API_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (* RX_CALLBACK)(void * dev, void *osbuf); + +typedef void (* ALLOC_NETBUFS)(A_NETBUF_QUEUE_T *q, A_UINT16 num); + +/* + * aggr_init: + * Initialises the data structures, allocates data queues and + * os buffers. Netbuf allocator is the input param, used by the + * aggr module for allocation of NETBUFs from driver context. + * These NETBUFs are used for AMSDU processing. + * + * Also registers OS call back function to deliver the + * frames to OS. This is generally the topmost layer of + * the driver context, after which the frames go to + * IP stack via the call back function. + * This dispatcher is active only when aggregation is ON. + * Returns A_OK if init success, else returns A_ERROR + */ +A_UINT8 +aggr_init(ALLOC_NETBUFS netbuf_allocator, RX_CALLBACK fn); + +/* + * aggr_init_conn: + * Initialises the data structures, allocates data queues and + * os buffers. Returns the context for a single conn aggr. + * For each supported conn, this API should be called. + */ +void * +aggr_init_conn(void); + +/* + * aggr_process_bar: + * When target receives BAR, it communicates to host driver + * for modifying window parameters. Target indicates this via the + * event: WMI_ADDBA_REQ_EVENTID. Host will dequeue all frames + * up to the indicated sequence number. + */ +void +aggr_process_bar(void *cntxt, A_UINT8 tid, A_UINT16 seq_no); + + +/* + * aggr_recv_addba_req_evt: + * This event is to initiate/modify the receive side window. + * Target will send WMI_ADDBA_REQ_EVENTID event to host - to setup + * recv re-ordering queues. Target will negotiate ADDBA with peer, + * and indicate via this event after succesfully completing the + * negotiation. This happens in two situations: + * 1. Initial setup of aggregation + * 2. Renegotiation of current recv window. + * Window size for re-ordering is limited by target buffer + * space, which is reflected in win_sz. + * (Re)Start the periodic timer to deliver long standing frames, + * in hold_q to OS. + */ +void +aggr_recv_addba_req_evt(void * cntxt, A_UINT8 tid, A_UINT16 seq_no, A_UINT8 win_sz); + + +/* + * aggr_recv_delba_req_evt: + * Target indicates deletion of a BA window for a tid via the + * WMI_DELBA_EVENTID. Host would deliver all the frames in the + * hold_q, reset tid config and disable the periodic timer, if + * aggr is not enabled on any tid. + */ +void +aggr_recv_delba_req_evt(void * cntxt, A_UINT8 tid); + + + +/* + * aggr_process_recv_frm: + * Called only for data frames. When aggr is ON for a tid, the buffer + * is always consumed, and osbuf would be NULL. For a non-aggr case, + * osbuf is not modified. + * AMSDU frames are consumed and are later freed. They are sliced and + * diced to individual frames and dispatched to stack. + * After consuming a osbuf(when aggr is ON), a previously registered + * callback may be called to deliver frames in order. + */ +void +aggr_process_recv_frm(void *cntxt, A_UINT8 tid, A_UINT16 seq_no, A_BOOL is_amsdu, void **osbuf); + + +/* + * aggr_module_destroy: + * Frees up all the queues and frames in them. + */ +void +aggr_module_destroy(void); + +/* + * * aggr_module_destroy_timers: + * * Disarm the timers. + * */ +void +aggr_module_destroy_timers(void *cntxt); + +/* + * aggr_module_destroy_conn: + * Frees up all the queues and frames in them. Releases the cntxt to OS. + */ +void +aggr_module_destroy_conn(void *cntxt); + +/* + * Dumps the aggregation stats + */ +void +aggr_dump_stats(void *cntxt, PACKET_LOG **log_buf); + +/* + * aggr_reset_state -- Called when it is deemed necessary to clear the aggregate + * hold Q state. Examples include when a Connect event or disconnect event is + * received. + */ +void +aggr_reset_state(void *cntxt, void *dev); + + +#ifdef __cplusplus +} +#endif + +#endif /*__AGGR_RECV_API_H__ */ diff --git a/drivers/net/wireless/ar6003/host/include/ar3kconfig.h b/drivers/net/wireless/ar6003/host/include/ar3kconfig.h new file mode 100644 index 000000000000..3a5584e4bf02 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/ar3kconfig.h @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +/* AR3K module configuration APIs for HCI-bridge operation */ + +#ifndef AR3KCONFIG_H_ +#define AR3KCONFIG_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define AR3K_CONFIG_FLAG_FORCE_MINBOOT_EXIT (1 << 0) +#define AR3K_CONFIG_FLAG_SET_AR3K_BAUD (1 << 1) +#define AR3K_CONFIG_FLAG_AR3K_BAUD_CHANGE_DELAY (1 << 2) +#define AR3K_CONFIG_FLAG_SET_AR6K_SCALE_STEP (1 << 3) + + +typedef struct { + A_UINT32 Flags; /* config flags */ + void *pHCIDev; /* HCI bridge device */ + HCI_TRANSPORT_PROPERTIES *pHCIProps; /* HCI bridge props */ + HIF_DEVICE *pHIFDevice; /* HIF layer device */ + + A_UINT32 AR3KBaudRate; /* AR3K operational baud rate */ + A_UINT16 AR6KScale; /* AR6K UART scale value */ + A_UINT16 AR6KStep; /* AR6K UART step value */ + struct hci_dev *pBtStackHCIDev; /* BT Stack HCI dev */ + A_UINT32 PwrMgmtEnabled; /* TLPM enabled? */ + A_UINT32 IdleTimeout; /* TLPM idle timeout */ + A_UINT16 WakeupTimeout; /* TLPM wakeup timeout */ + A_UINT8 bdaddr[6]; /* Bluetooth device address */ +} AR3K_CONFIG_INFO; + +A_STATUS AR3KConfigure(AR3K_CONFIG_INFO *pConfigInfo); + +A_STATUS AR3KConfigureExit(void *config); + +#ifdef __cplusplus +} +#endif + +#endif /*AR3KCONFIG_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/ar6000_api.h b/drivers/net/wireless/ar6003/host/include/ar6000_api.h new file mode 100644 index 000000000000..62f7766aedf3 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/ar6000_api.h @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the API to access the OS dependent atheros host driver +// by the WMI or WLAN generic modules. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _AR6000_API_H_ +#define _AR6000_API_H_ + +#if defined(__linux__) && !defined(LINUX_EMULATION) +#include "../os/linux/include/ar6xapi_linux.h" +#endif + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/ar6xapi.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/ar6xapi.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/ar6xapi_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/ar6xapi_win.h" +#endif + +#ifdef ATHR_WIN_NWF +#include "../os/windows/include/ar6xapi.h" +#endif + +#endif /* _AR6000_API_H */ + diff --git a/drivers/net/wireless/ar6003/host/include/ar6000_diag.h b/drivers/net/wireless/ar6003/host/include/ar6000_diag.h new file mode 100644 index 000000000000..b53512e23d32 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/ar6000_diag.h @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#ifndef AR6000_DIAG_H_ +#define AR6000_DIAG_H_ + + +A_STATUS +ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); + +A_STATUS +ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); + +A_STATUS +ar6000_ReadDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address, + A_UCHAR *data, A_UINT32 length); + +A_STATUS +ar6000_WriteDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address, + A_UCHAR *data, A_UINT32 length); + +A_STATUS +ar6k_ReadTargetRegister(HIF_DEVICE *hifDevice, int regsel, A_UINT32 *regval); + +void +ar6k_FetchTargetRegs(HIF_DEVICE *hifDevice, A_UINT32 *targregs); + +#endif /*AR6000_DIAG_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/ar6kap_common.h b/drivers/net/wireless/ar6003/host/include/ar6kap_common.h new file mode 100644 index 000000000000..9ab85314741d --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/ar6kap_common.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ + +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ + +//============================================================================== + +// This file contains the definitions of common AP mode data structures. +// +// Author(s): ="Atheros" +//============================================================================== + +#ifndef _AR6KAP_COMMON_H_ +#define _AR6KAP_COMMON_H_ +/* + * Used with AR6000_XIOCTL_AP_GET_STA_LIST + */ +typedef struct { + A_UINT8 mac[ATH_MAC_LEN]; + A_UINT8 aid; + A_UINT8 keymgmt; + A_UINT8 ucipher; + A_UINT8 auth; + A_UINT8 wmode; +} station_t; + +typedef struct { + station_t sta[AP_MAX_NUM_STA]; +} ap_get_sta_t; +#endif /* _AR6KAP_COMMON_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/athbtfilter.h b/drivers/net/wireless/ar6003/host/include/athbtfilter.h new file mode 100644 index 000000000000..b7ba661f03d6 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/athbtfilter.h @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Public Bluetooth filter APIs +// Author(s): ="Atheros" +//============================================================================== +#ifndef ATHBTFILTER_H_ +#define ATHBTFILTER_H_ + +#define ATH_DEBUG_INFO (1 << 2) +#define ATH_DEBUG_INF ATH_DEBUG_INFO + +typedef enum _ATHBT_HCI_CTRL_TYPE { + ATHBT_HCI_COMMAND = 0, + ATHBT_HCI_EVENT = 1, +} ATHBT_HCI_CTRL_TYPE; + +typedef enum _ATHBT_STATE_INDICATION { + ATH_BT_NOOP = 0, + ATH_BT_INQUIRY = 1, + ATH_BT_CONNECT = 2, + ATH_BT_SCO = 3, + ATH_BT_ACL = 4, + ATH_BT_A2DP = 5, + ATH_BT_ESCO = 6, + /* new states go here.. */ + + ATH_BT_MAX_STATE_INDICATION +} ATHBT_STATE_INDICATION; + + /* filter function for OUTGOING commands and INCOMMING events */ +typedef void (*ATHBT_FILTER_CMD_EVENTS_FN)(void *pContext, ATHBT_HCI_CTRL_TYPE Type, unsigned char *pBuffer, int Length); + + /* filter function for OUTGOING data HCI packets */ +typedef void (*ATHBT_FILTER_DATA_FN)(void *pContext, unsigned char *pBuffer, int Length); + +typedef enum _ATHBT_STATE { + STATE_OFF = 0, + STATE_ON = 1, + STATE_MAX +} ATHBT_STATE; + + /* BT state indication (when filter functions are not used) */ + +typedef void (*ATHBT_INDICATE_STATE_FN)(void *pContext, ATHBT_STATE_INDICATION Indication, ATHBT_STATE State, unsigned char LMPVersion); + +typedef struct _ATHBT_FILTER_INSTANCE { +#ifdef UNDER_CE + WCHAR *pWlanAdapterName; /* filled in by user */ +#else + A_CHAR *pWlanAdapterName; /* filled in by user */ +#endif /* UNDER_CE */ + int FilterEnabled; /* filtering is enabled */ + int Attached; /* filter library is attached */ + void *pContext; /* private context for filter library */ + ATHBT_FILTER_CMD_EVENTS_FN pFilterCmdEvents; /* function ptr to filter a command or event */ + ATHBT_FILTER_DATA_FN pFilterAclDataOut; /* function ptr to filter ACL data out (to radio) */ + ATHBT_FILTER_DATA_FN pFilterAclDataIn; /* function ptr to filter ACL data in (from radio) */ + ATHBT_INDICATE_STATE_FN pIndicateState; /* function ptr to indicate a state */ +} ATH_BT_FILTER_INSTANCE; + + +/* API MACROS */ + +#define AthBtFilterHciCommand(instance,packet,length) \ + if ((instance)->FilterEnabled) { \ + (instance)->pFilterCmdEvents((instance)->pContext, \ + ATHBT_HCI_COMMAND, \ + (unsigned char *)(packet), \ + (length)); \ + } + +#define AthBtFilterHciEvent(instance,packet,length) \ + if ((instance)->FilterEnabled) { \ + (instance)->pFilterCmdEvents((instance)->pContext, \ + ATHBT_HCI_EVENT, \ + (unsigned char *)(packet), \ + (length)); \ + } + +#define AthBtFilterHciAclDataOut(instance,packet,length) \ + if ((instance)->FilterEnabled) { \ + (instance)->pFilterAclDataOut((instance)->pContext, \ + (unsigned char *)(packet), \ + (length)); \ + } + +#define AthBtFilterHciAclDataIn(instance,packet,length) \ + if ((instance)->FilterEnabled) { \ + (instance)->pFilterAclDataIn((instance)->pContext, \ + (unsigned char *)(packet), \ + (length)); \ + } + +/* if filtering is not desired, the application can indicate the state directly using this + * macro: + */ +#define AthBtIndicateState(instance,indication,state) \ + if ((instance)->FilterEnabled) { \ + (instance)->pIndicateState((instance)->pContext, \ + (indication), \ + (state), \ + 0); \ + } + +#ifdef __cplusplus +extern "C" { +#endif + +/* API prototypes */ +int AthBtFilter_Attach(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 flags); +void AthBtFilter_Detach(ATH_BT_FILTER_INSTANCE *pInstance); + +#ifdef __cplusplus +} +#endif + +#endif /*ATHBTFILTER_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/athendpack.h b/drivers/net/wireless/ar6003/host/include/athendpack.h new file mode 100644 index 000000000000..96445d790752 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/athendpack.h @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// end compiler-specific structure packing +// +// Author(s): ="Atheros" +//============================================================================== +#ifdef VXWORKS +#endif /* VXWORKS */ + +#if defined(LINUX) || defined(__linux__) +#endif /* LINUX */ + +#ifdef QNX +#endif /* QNX */ + +#ifdef INTEGRITY +#include "integrity/athendpack_integrity.h" +#endif /* INTEGRITY */ + +#ifdef NUCLEUS +#endif /* NUCLEUS */ + + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/athendpack.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athendpack.h" +#endif /* WINCE */ + +#ifdef ATHR_WIN_NWF +#include +#endif diff --git a/drivers/net/wireless/ar6003/host/include/athstartpack.h b/drivers/net/wireless/ar6003/host/include/athstartpack.h new file mode 100644 index 000000000000..c81435b2405c --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/athstartpack.h @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// start compiler-specific structure packing +// +// Author(s): ="Atheros" +//============================================================================== +#ifdef VXWORKS +#endif /* VXWORKS */ + +#if defined(LINUX) || defined(__linux__) +#endif /* LINUX */ + +#ifdef QNX +#endif /* QNX */ + +#ifdef INTEGRITY +#include "integrity/athstartpack_integrity.h" +#endif /* INTEGRITY */ + +#ifdef NUCLEUS +#endif /* NUCLEUS */ + +#ifdef ATHR_WM_NWF +#include "../os/windows/include/athstartpack.h" +#define PREPACK +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athstartpack.h" +#endif /* WINCE */ + +#ifdef ATHR_WIN_NWF + +#ifndef PREPACK +#define PREPACK __declspec(align(1)) +#endif + +#include +#define __ATTRIB_PACK POSTPACK + +#endif + +#if __LONG_MAX__ == __INT_MAX__ +/* 32-bit compilation */ +#define PREPACK64 +#define POSTPACK64 +#else +/* 64-bit compilation */ +#define PREPACK64 PREPACK +#define POSTPACK64 POSTPACK +#endif diff --git a/drivers/net/wireless/ar6003/host/include/bmi.h b/drivers/net/wireless/ar6003/host/include/bmi.h new file mode 100644 index 000000000000..960294e228a8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/bmi.h @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// BMI declarations and prototypes +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _BMI_H_ +#define _BMI_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Header files */ +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "hif.h" +#include "a_osapi.h" +#include "bmi_msg.h" + +void +BMIInit(void); + +void +BMICleanup(void); + +A_STATUS +BMIDone(HIF_DEVICE *device); + +A_STATUS +BMIGetTargetInfo(HIF_DEVICE *device, struct bmi_target_info *targ_info); + +A_STATUS +BMIReadMemory(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length); + +A_STATUS +BMIWriteMemory(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length); + +A_STATUS +BMIExecute(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 *param); + +A_STATUS +BMISetAppStart(HIF_DEVICE *device, + A_UINT32 address); + +A_STATUS +BMIReadSOCRegister(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 *param); + +A_STATUS +BMIWriteSOCRegister(HIF_DEVICE *device, + A_UINT32 address, + A_UINT32 param); + +A_STATUS +BMIrompatchInstall(HIF_DEVICE *device, + A_UINT32 ROM_addr, + A_UINT32 RAM_addr, + A_UINT32 nbytes, + A_UINT32 do_activate, + A_UINT32 *patch_id); + +A_STATUS +BMIrompatchUninstall(HIF_DEVICE *device, + A_UINT32 rompatch_id); + +A_STATUS +BMIrompatchActivate(HIF_DEVICE *device, + A_UINT32 rompatch_count, + A_UINT32 *rompatch_list); + +A_STATUS +BMIrompatchDeactivate(HIF_DEVICE *device, + A_UINT32 rompatch_count, + A_UINT32 *rompatch_list); + +A_STATUS +BMILZStreamStart(HIF_DEVICE *device, + A_UINT32 address); + +A_STATUS +BMILZData(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length); + +A_STATUS +BMIFastDownload(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length); + +A_STATUS +BMInvramProcess(HIF_DEVICE *device, + A_UCHAR *seg_name, + A_UINT32 *retval); + +A_STATUS +BMIRawWrite(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length); + +A_STATUS +BMIRawRead(HIF_DEVICE *device, + A_UCHAR *buffer, + A_UINT32 length, + A_BOOL want_timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* _BMI_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/common_drv.h b/drivers/net/wireless/ar6003/host/include/common_drv.h new file mode 100644 index 000000000000..43dc19954078 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/common_drv.h @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef COMMON_DRV_H_ +#define COMMON_DRV_H_ + +#include "hif.h" +#include "htc_packet.h" +#include "htc_api.h" + +/* structure that is the state information for the default credit distribution callback + * drivers should instantiate (zero-init as well) this structure in their driver instance + * and pass it as a context to the HTC credit distribution functions */ +typedef struct _COMMON_CREDIT_STATE_INFO { + int TotalAvailableCredits; /* total credits in the system at startup */ + int CurrentFreeCredits; /* credits available in the pool that have not been + given out to endpoints */ + HTC_ENDPOINT_CREDIT_DIST *pLowestPriEpDist; /* pointer to the lowest priority endpoint dist struct */ +} COMMON_CREDIT_STATE_INFO; + +typedef struct { + A_INT32 (*setupTransport)(void *ar); + void (*cleanupTransport)(void *ar); +} HCI_TRANSPORT_CALLBACKS; + +typedef struct { + void *netDevice; + void *hifDevice; + void *htcHandle; +} HCI_TRANSPORT_MISC_HANDLES; + +/* HTC TX packet tagging definitions */ +#define AR6K_CONTROL_PKT_TAG HTC_TX_PACKET_TAG_USER_DEFINED +#define AR6K_DATA_PKT_TAG (AR6K_CONTROL_PKT_TAG + 1) + +#define AR6002_VERSION_REV2 0x20000188 +#define AR6003_VERSION_REV2 0x30000384 + +#define AR6002_CUST_DATA_SIZE 112 +#define AR6003_CUST_DATA_SIZE 16 +#define MCKINLEY_CUST_DATA_SIZE 16 + +#ifdef __cplusplus +extern "C" { +#endif + +/* OS-independent APIs */ +A_STATUS ar6000_setup_credit_dist(HTC_HANDLE HTCHandle, COMMON_CREDIT_STATE_INFO *pCredInfo); + +A_STATUS ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); + +A_STATUS ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); + +A_STATUS ar6000_ReadDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address, A_UCHAR *data, A_UINT32 length); + +A_STATUS ar6000_reset_device(HIF_DEVICE *hifDevice, A_UINT32 TargetType, A_BOOL waitForCompletion, A_BOOL coldReset); + +void ar6000_dump_target_assert_info(HIF_DEVICE *hifDevice, A_UINT32 TargetType); + +A_STATUS ar6000_set_htc_params(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 MboxIsrYieldValue, + A_UINT8 HtcControlBuffers); + +A_STATUS ar6000_prepare_target(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 TargetVersion); + +A_STATUS ar6000_set_hci_bridge_flags(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 Flags); + +void ar6000_copy_cust_data_from_target(HIF_DEVICE *hifDevice, A_UINT32 TargetType); + +A_UINT8 *ar6000_get_cust_data_buffer(A_UINT32 TargetType); + +A_STATUS ar6000_setBTState(void *context, A_UINT8 *pInBuf, A_UINT32 InBufSize); + +A_STATUS ar6000_setDevicePowerState(void *context, A_UINT8 *pInBuf, A_UINT32 InBufSize); + +A_STATUS ar6000_setWowMode(void *context, A_UINT8 *pInBuf, A_UINT32 InBufSize); + +A_STATUS ar6000_setHostMode(void *context, A_UINT8 *pInBuf, A_UINT32 InBufSize); + +#ifdef __cplusplus +} +#endif + +#endif /*COMMON_DRV_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/dbglog_api.h b/drivers/net/wireless/ar6003/host/include/dbglog_api.h new file mode 100644 index 000000000000..7aba883c8888 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/dbglog_api.h @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains host side debug primitives. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _DBGLOG_API_H_ +#define _DBGLOG_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "dbglog.h" + +#define DBGLOG_HOST_LOG_BUFFER_SIZE DBGLOG_LOG_BUFFER_SIZE + +#define DBGLOG_GET_DBGID(arg) \ + ((arg & DBGLOG_DBGID_MASK) >> DBGLOG_DBGID_OFFSET) + +#define DBGLOG_GET_MODULEID(arg) \ + ((arg & DBGLOG_MODULEID_MASK) >> DBGLOG_MODULEID_OFFSET) + +#define DBGLOG_GET_NUMARGS(arg) \ + ((arg & DBGLOG_NUM_ARGS_MASK) >> DBGLOG_NUM_ARGS_OFFSET) + +#define DBGLOG_GET_TIMESTAMP(arg) \ + ((arg & DBGLOG_TIMESTAMP_MASK) >> DBGLOG_TIMESTAMP_OFFSET) + +/** + @param lv 0->RAW info, 1->Breif translated info, 2->Full info + @param logbuf dbglog buffer + */ +int dbg_formater(int lv, char *output, size_t len, A_UINT32 ts, A_INT32 *logbuf); + +#ifdef __cplusplus +} +#endif + +#endif /* _DBGLOG_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/dfs_host.h b/drivers/net/wireless/ar6003/host/include/dfs_host.h new file mode 100644 index 000000000000..fc54ec5cbd07 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/dfs_host.h @@ -0,0 +1,387 @@ +/* + * Copyright (c) 2005-2006 Atheros Communications, Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#ifndef _DFS_HOST_H_ +#define _DFS_HOST_H_ + +#ifdef ATH_SUPPORT_DFS + +#include "dfs_host_project.h" + +#define DFS_MIN(a,b) ((a)<(b)?(a):(b)) +#define DFS_MAX(a,b) ((a)>(b)?(a):(b)) +#define DFS_DIFF(a,b) (DFS_MAX(a,b) - DFS_MIN(a,b)) +/* + * Maximum number of radar events to be processed in a single iteration. + * Allows soft watchdog to run. + */ +#define MAX_EVENTS 100 + + +#define DFS_MARGIN_EQUAL(a, b, margin) ((DFS_DIFF(a,b)) <= margin) +#define DFS_MAX_STAGGERED_BURSTS 3 + +/* All filter thresholds in the radar filter tables are effective at a 50% channel loading */ +#define DFS_CHAN_LOADING_THRESH 50 +#define DFS_EXT_CHAN_LOADING_THRESH 30 +#define DFS_DEFAULT_PRI_MARGIN 10 +#define DFS_DEFAULT_FIXEDPATTERN_PRI_MARGIN 6 + + +#define ATH_DFSQ_LOCK(_dfs) spin_lock(&(_dfs)->dfs_radarqlock) +#define ATH_DFSQ_UNLOCK(_dfs) spin_unlock(&(_dfs)->dfs_radarqlock) +#define ATH_DFSQ_LOCK_INIT(_dfs) spin_lock_init(&(_dfs)->dfs_radarqlock) + +#define ATH_ARQ_LOCK(_dfs) spin_lock(&(_dfs)->dfs_arqlock) +#define ATH_ARQ_UNLOCK(_dfs) spin_unlock(&(_dfs)->dfs_arqlock) +#define ATH_ARQ_LOCK_INIT(_dfs) spin_lock_init(&(_dfs)->dfs_arqlock) + +#define ATH_DFSEVENTQ_LOCK(_dfs) spin_lock(&(_dfs)->dfs_eventqlock) +#define ATH_DFSEVENTQ_UNLOCK(_dfs) spin_unlock(&(_dfs)->dfs_eventqlock) +#define ATH_DFSEVENTQ_LOCK_INIT(_dfs) spin_lock_init(&(_dfs)->dfs_eventqlock) + + +#define DFS_TSMASK 0xFFFFFFFF /* Mask for time stamp from descriptor */ +#define DFS_TSSHIFT 32 /* Shift for time stamp from descriptor */ +#define DFS_TSF_WRAP 0xFFFFFFFFFFFFFFFFULL /* 64 bit TSF wrap value */ +#define DFS_64BIT_TSFMASK 0x0000000000007FFFULL /* TS mask for 64 bit value */ + + +#define DFS_AR_RADAR_RSSI_THR 5 /* in dB */ +#define DFS_AR_RADAR_RESET_INT 1 /* in secs */ +#define DFS_AR_RADAR_MAX_HISTORY 500 +#define DFS_AR_REGION_WIDTH 128 +#define DFS_AR_RSSI_THRESH_STRONG_PKTS 17 /* in dB */ +#define DFS_AR_RSSI_DOUBLE_THRESHOLD 15 /* in dB */ +#define DFS_AR_MAX_NUM_ACK_REGIONS 9 +#define DFS_AR_ACK_DETECT_PAR_THRESH 20 +#define DFS_AR_PKT_COUNT_THRESH 20 + +#define DFS_MAX_DL_MASK 0x3F + +#define DFS_NOL_TIME 30*60*1000000 /* 30 minutes in usecs */ + +#define DFS_WAIT_TIME 60*1000000 /* 1 minute in usecs */ + +#define DFS_DISABLE_TIME 3*60*1000000 /* 3 minutes in usecs */ + +#define DFS_MAX_B5_SIZE 128 +#define DFS_MAX_B5_MASK 0x0000007F /* 128 */ + +#define DFS_MAX_RADAR_OVERLAP 16 /* Max number of overlapping filters */ + +#define DFS_MAX_EVENTS 1024 /* Max number of dfs events which can be q'd */ + +#define DFS_RADAR_EN 0x80000000 /* Radar detect is capable */ +#define DFS_AR_EN 0x40000000 /* AR detect is capable */ +#define DFS_MAX_RSSI_VALUE 0x7fffffff /* Max rssi value */ + +#define DFS_BIN_MAX_PULSES 60 /* max num of pulses in a burst */ +#define DFS_BIN5_PRI_LOWER_LIMIT 990 /* us */ +#define DFS_BIN5_PRI_HIGHER_LIMIT 2010 /* us */ +#define DFS_BIN5_WIDTH_MARGIN 4 /* us */ +#define DFS_BIN5_RSSI_MARGIN 5 /* dBm */ +/*Following threshold is not specified but should be okay statistically*/ +#define DFS_BIN5_BRI_LOWER_LIMIT 300000 /* us */ + +#define DFS_MAX_PULSE_BUFFER_SIZE 1024 /* Max number of pulses kept in buffer */ +#define DFS_MAX_PULSE_BUFFER_MASK 0x3ff + +#define DFS_FAST_CLOCK_MULTIPLIER (800/11) +#define DFS_NO_FAST_CLOCK_MULTIPLIER (80) + +typedef spinlock_t dfsq_lock_t; + +struct dfs_pulse { + A_UINT32 rp_numpulses; /* Num of pulses in radar burst */ + A_UINT32 rp_pulsedur; /* Duration of each pulse in usecs */ + A_UINT32 rp_pulsefreq; /* Frequency of pulses in burst */ + A_UINT32 rp_max_pulsefreq; /* Frequency of pulses in burst */ + A_UINT32 rp_patterntype; /*fixed or variable pattern type*/ + A_UINT32 rp_pulsevar; /* Time variation of pulse duration for + matched filter (single-sided) in usecs */ + A_UINT32 rp_threshold; /* Thershold for MF output to indicate + radar match */ + A_UINT32 rp_mindur; /* Min pulse duration to be considered for + this pulse type */ + A_UINT32 rp_maxdur; /* Max pusle duration to be considered for + this pulse type */ + A_UINT32 rp_rssithresh; /* Minimum rssi to be considered a radar pulse */ + A_UINT32 rp_meanoffset; /* Offset for timing adjustment */ + A_INT32 rp_rssimargin; /* rssi threshold margin. In Turbo Mode HW reports rssi 3dBm + * lower than in non TURBO mode. This will be used to offset + * that diff.*/ + A_UINT32 rp_pulseid; /* Unique ID for identifying filter */ + +}; + +struct dfs_bin5pulse { + A_UINT32 b5_threshold; /* Number of bin5 pulses to indicate detection */ + A_UINT32 b5_mindur; /* Min duration for a bin5 pulse */ + A_UINT32 b5_maxdur; /* Max duration for a bin5 pulse */ + A_UINT32 b5_timewindow; /* Window over which to count bin5 pulses */ + A_UINT32 b5_rssithresh; /* Min rssi to be considered a pulse */ + A_UINT32 b5_rssimargin; /* rssi threshold margin. In Turbo Mode HW reports rssi 3dB */ +}; + + +#define DFS_MAX_DL_SIZE 64 +#include "athstartpack.h" +PREPACK struct dfs_delayelem { + u_int32_t de_time; /* Current "filter" time for start of pulse in usecs*/ + u_int8_t de_dur; /* Duration of pulse in usecs*/ + u_int8_t de_rssi; /* rssi of pulse in dB*/ +} POSTPACK adf_os_packed; + +/* NB: The first element in the circular buffer is the oldest element */ + +PREPACK struct dfs_delayline { + struct dfs_delayelem dl_elems[DFS_MAX_DL_SIZE]; /* Array of pulses in delay line */ + u_int64_t dl_last_ts; /* Last timestamp the delay line was used (in usecs) */ + u_int32_t dl_firstelem; /* Index of the first element */ + u_int32_t dl_lastelem; /* Index of the last element */ + u_int32_t dl_numelems; /* Number of elements in the delay line */ +} POSTPACK adf_os_packed; + + +PREPACK struct dfs_filter { + struct dfs_delayline rf_dl; /* Delay line of pulses for this filter */ + u_int32_t rf_numpulses; /* Number of pulses in the filter */ + u_int32_t rf_minpri; /* min pri to be considered for this filter*/ + u_int32_t rf_maxpri; /* max pri to be considered for this filter*/ + u_int32_t rf_threshold; /* match filter output threshold for radar detect */ + u_int32_t rf_filterlen; /* Length (in usecs) of the filter */ + u_int32_t rf_patterntype; /* fixed or variable pattern type */ + u_int32_t rf_mindur; /* Min duration for this radar filter */ + u_int32_t rf_maxdur; /* Max duration for this radar filter */ + u_int32_t rf_pulseid; /* Unique ID corresponding to the original filter ID */ +} POSTPACK adf_os_packed; + + + +PREPACK struct dfs_pulseparams { + u_int64_t p_time; /* time for start of pulse in usecs*/ + u_int8_t p_dur; /* Duration of pulse in usecs*/ + u_int8_t p_rssi; /* Duration of pulse in usecs*/ +} POSTPACK adf_os_packed; + +PREPACK struct dfs_pulseline { + /* pl_elems - array of pulses in delay line */ + struct dfs_pulseparams pl_elems[DFS_MAX_PULSE_BUFFER_SIZE]; + u_int32_t pl_firstelem; /* Index of the first element */ + u_int32_t pl_lastelem; /* Index of the last element */ + u_int32_t pl_numelems; /* Number of elements in the delay line */ +} POSTPACK adf_os_packed; + +PREPACK struct dfs_event { + u_int64_t re_full_ts; /* 64-bit full timestamp from interrupt time */ + u_int32_t re_ts; /* Original 15 bit recv timestamp */ + u_int32_t re_ext_chan_busy; /* Ext channel busy % */ + u_int8_t re_rssi; /* rssi of radar event */ + u_int8_t re_dur; /* duration of radar pulse */ + u_int8_t re_chanindex; /* Channel of event */ + u_int8_t re_chanindextype; /* Primary channel or extension channel */ + STAILQ_ENTRY(dfs_event) re_list; /* List of radar events */ +} POSTPACK adf_os_packed; +#include "athendpack.h" + +#define DFS_AR_MAX_ACK_RADAR_DUR 511 +#define DFS_AR_MAX_NUM_PEAKS 3 +#define DFS_AR_ARQ_SIZE 2048 /* 8K AR events for buffer size */ +#define DFS_AR_ARQ_SEQSIZE 2049 /* Sequence counter wrap for AR */ + +#define DFS_RADARQ_SIZE 512 /* 1K radar events for buffer size */ +#define DFS_RADARQ_SEQSIZE 513 /* Sequence counter wrap for radar */ +#define DFS_NUM_RADAR_STATES 64 /* Number of radar channels we keep state for */ +#define DFS_MAX_NUM_RADAR_FILTERS 10 /* Max number radar filters for each type */ +#define DFS_MAX_RADAR_TYPES 32 /* Number of different radar types */ + +struct dfs_ar_state { + u_int32_t ar_prevwidth; + u_int32_t ar_phyerrcount[DFS_AR_MAX_ACK_RADAR_DUR]; + u_int32_t ar_acksum; + u_int32_t ar_packetthreshold; /* Thresh to determine traffic load */ + u_int32_t ar_parthreshold; /* Thresh to determine peak */ + u_int32_t ar_radarrssi; /* Rssi threshold for AR event */ + u_int16_t ar_prevtimestamp; + u_int16_t ar_peaklist[DFS_AR_MAX_NUM_PEAKS]; +}; + +struct dfs_filtertype { + struct dfs_filter ft_filters[DFS_MAX_NUM_RADAR_FILTERS]; + u_int32_t ft_filterdur; /* Duration of pulse which specifies filter type*/ + u_int32_t ft_numfilters; /* Num filters of this type */ + u_int64_t ft_last_ts; /* Last timestamp this filtertype was used + * (in usecs) */ + u_int32_t ft_mindur; /* min pulse duration to be considered + * for this filter type */ + u_int32_t ft_maxdur; /* max pulse duration to be considered + * for this filter type */ + u_int32_t ft_rssithresh; /* min rssi to be considered + * for this filter type */ + u_int32_t ft_numpulses; /* Num pulses in each filter of this type */ + u_int32_t ft_patterntype; /* fixed or variable pattern type */ + u_int32_t ft_minpri; /* min pri to be considered for this type */ + u_int32_t ft_rssimargin; /* rssi threshold margin. In Turbo Mode HW + * reports rssi 3dB lower than in non TURBO + * mode. This will offset that diff. */ +}; + + +#define DFS_NOL_TIMEOUT_S (30*60) /* 30 minutes in seconds */ +#define DFS_NOL_TIMEOUT_MS (DFS_NOL_TIMEOUT_S * 1000) +#define DFS_NOL_TIMEOUT_US (DFS_NOL_TIMEOUT_MS * 1000) + +#include "athstartpack.h" +PREPACK struct dfs_info_host { + u_int32_t rn_numradars; /* Number of different types of radars */ + u_int64_t rn_lastfull_ts; /* Last 64 bit timstamp from recv interrupt */ + u_int16_t rn_last_ts; /* last 15 bit ts from recv descriptor */ + u_int32_t rn_last_unique_ts; /* last unique 32 bit ts from recv descriptor */ + u_int64_t rn_ts_prefix; /* Prefix to prepend to 15 bit recv ts */ + u_int32_t rn_numbin5radars; /* Number of bin5 radar pulses to search for */ + u_int64_t dfs_bin5_chirp_ts; + u_int8_t dfs_last_bin5_dur; +} POSTPACK adf_os_packed; +#include "athendpack.h" + +struct dfs_bin5elem { + u_int64_t be_ts; /* Timestamp for the bin5 element */ + u_int32_t be_rssi; /* Rssi for the bin5 element */ + u_int32_t be_dur; /* Duration of bin5 element */ +}; + +struct dfs_bin5radars { + struct dfs_bin5elem br_elems[DFS_MAX_B5_SIZE]; /* List of bin5 elems that fall + * within the time window */ + u_int32_t br_firstelem; /* Index of the first element */ + u_int32_t br_lastelem; /* Index of the last element */ + u_int32_t br_numelems; /* Number of elements in the delay line */ + struct dfs_bin5pulse br_pulse; /* Original info about bin5 pulse */ +}; + + +#define ATH_DFS_RESET_TIME_S 7 +#define ATH_DFS_WAIT (60 + ATH_DFS_RESET_TIME_S) /* 60 seconds */ +#define ATH_DFS_WAIT_MS ((ATH_DFS_WAIT) * 1000) /*in MS*/ + +#define ATH_DFS_WEATHER_CHANNEL_WAIT_MIN 10 /*10 minutes*/ +#define ATH_DFS_WEATHER_CHANNEL_WAIT_S (ATH_DFS_WEATHER_CHANNEL_WAIT_MIN * 60) +#define ATH_DFS_WEATHER_CHANNEL_WAIT_MS ((ATH_DFS_WEATHER_CHANNEL_WAIT_S) * 1000) /*in MS*/ + +#define ATH_DFS_WAIT_POLL_PERIOD 2 /* 2 seconds */ +#define ATH_DFS_WAIT_POLL_PERIOD_MS ((ATH_DFS_WAIT_POLL_PERIOD) * 1000) /*in MS*/ +#define ATH_DFS_TEST_RETURN_PERIOD 2 /* 2 seconds */ +#define ATH_DFS_TEST_RETURN_PERIOD_MS ((ATH_DFS_TEST_RETURN_PERIOD) * 1000)/* n MS*/ + +#define IS_CHANNEL_WEATHER_RADAR(chan) ((chan->channel >= 5600) && (chan->channel <= 5650)) + +#define DFS_DEBUG_TIMEOUT_S 30 // debug timeout is 30 seconds +#define DFS_DEBUG_TIMEOUT_MS (DFS_DEBUG_TIMEOUT_S * 1000) +struct ath_dfs_host { + DEV_HDL dev_hdl; + u_int32_t dfs_debug_level; + OS_HDL os_hdl; + STAILQ_HEAD(,dfs_event) dfs_eventq; /* Q of free dfs event objects */ + dfsq_lock_t dfs_eventqlock; /* Lock for free dfs event list */ + STAILQ_HEAD(,dfs_event) dfs_radarq; /* Q of radar events */ + dfsq_lock_t dfs_radarqlock; /* Lock for dfs q */ + STAILQ_HEAD(,dfs_event) dfs_arq; /* Q of AR events */ + dfsq_lock_t dfs_arqlock; /* Lock for AR q */ + + struct dfs_pulseline *pulses; /* pulse history */ + struct dfs_event *events; /* Events structure */ + /* dfs_radarf - One filter for each radar pulse type */ + struct dfs_filtertype *dfs_radarf[DFS_MAX_RADAR_TYPES]; + + int8_t **dfs_radartable; /* map of radar durs to filter types */ + struct dfs_bin5radars *dfs_b5radars;/* array of bin5 radar events */ + struct dfs_ar_state dfs_ar_state; /* AR state */ + struct dfs_info_host dfs_rinfo; /* State vars for radar processing */ + u_int8_t dfs_bangradar; + u_int32_t dur_multiplier; + A_TIMER dfs_radar_task_timer; +}; + + +#define HAL_CAP_RADAR 0 +#define HAL_CAP_AR 1 +#define HAL_CAP_STRONG_DIV 2 + + +/* Attach, detach, handle ioctl prototypes */ +struct ath_dfs_host *dfs_attach_host(DEV_HDL dev, OS_HDL os, ATH_DFS_CAPINFO *cap_info); +void dfs_detach_host(struct ath_dfs_host *sc); + + +/* PHY error and radar event handling */ +void dfs_process_phyerr_host(struct ath_dfs_host *dfs, WMI_DFS_PHYERR_EVENT *ev); +int dfs_process_radarevent_host(struct ath_dfs_host *dfs, int16_t *chan_index, u_int8_t *bangradar); + + +/* FCC Bin5 detection prototypes */ +int dfs_bin5_addpulse(struct ath_dfs_host *sc, struct dfs_bin5radars *br, + struct dfs_event *re, u_int64_t thists); +int dfs_bin5_check(struct ath_dfs_host *dfs); +u_int8_t dfs_retain_bin5_burst_pattern(struct ath_dfs_host *dfs, u_int32_t diff_ts, u_int8_t old_dur); + +/* Debug prototypes */ +void dfs_print_delayline(struct ath_dfs_host *dfs, struct dfs_delayline *dl); +void dfs_print_filters(struct ath_dfs_host *dfs); +void dfs_print_filter(struct ath_dfs_host *dfs, struct dfs_filter *rf); + +/* Misc prototypes */ +u_int32_t dfs_round(int32_t val); + +/* Reset and init data structures */ + +int dfs_init_radar_filters_host(struct ath_dfs_host *dfs, struct ath_dfs_info *dfs_info); +void dfs_reset_alldelaylines(struct ath_dfs_host *dfs); +void dfs_reset_delayline(struct dfs_delayline *dl); +void dfs_reset_filter_delaylines(struct dfs_filtertype *dft); +void dfs_reset_radarq(struct ath_dfs_host *dfs); + +/* Detection algorithm prototypes */ +void dfs_add_pulse(struct ath_dfs_host *dfs, struct dfs_filter *rf, + struct dfs_event *re, u_int32_t deltaT); + +int dfs_bin_fixedpattern_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, u_int32_t dur, int ext_chan_flag, u_int32_t ext_chan_busy); +int dfs_bin_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + u_int32_t deltaT, u_int32_t dur, int ext_chan_flag, u_int32_t ext_chan_busy); + + +int dfs_bin_pri_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + struct dfs_delayline *dl, u_int32_t score, + u_int32_t refpri, u_int32_t refdur, int ext_chan_flag, u_int32_t ext_chan_busy); +int dfs_staggered_check(struct ath_dfs_host *dfs, struct dfs_filter *rf, + u_int32_t deltaT, u_int32_t width, u_int32_t ext_chan_busy); + +/* AR related prototypes */ +u_int32_t dfs_process_ar_event(struct ath_dfs_host *dfs); +void dfs_reset_ar(struct ath_dfs_host *dfs); +void dfs_reset_arq(struct ath_dfs_host *dfs); + +void dfs_bangradar_enable(struct ath_dfs_host *dfs, u_int8_t enable); +void dfs_set_dur_multiplier(struct ath_dfs_host *dfs, u_int32_t dur_multiplier); +void dfs_set_debug_level_host(struct ath_dfs_host *dfs, u_int32_t level); + +/* False detection reduction */ +int dfs_get_pri_margin(int is_extchan_detect, int is_fixed_pattern, u_int64_t lastfull_ts, u_int32_t ext_chan_busy); +int dfs_get_filter_threshold(struct dfs_filter *rf, int is_extchan_detect, u_int64_t lastfull_ts, u_int32_t ext_chan_busy); + +#endif /* ATH_SUPPORT_DFS */ +#endif /* _DFS_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/dfs_host_project.h b/drivers/net/wireless/ar6003/host/include/dfs_host_project.h new file mode 100644 index 000000000000..9f1ce2f2d717 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/dfs_host_project.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2005-2006 Atheros Communications, Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#ifndef _DFS_PROJECT_H_ +#define _DFS_PROJECT_H_ + +#ifdef ATH_SUPPORT_DFS + +#include +#include +#include +#include +#include +#include /* XXX: This is in target dir */ +#include "dfs_common.h" +#include "ar6000_drv.h" +#include "project.h" + +#define ATH_DFS_CAPINFO WMI_DFS_HOST_ATTACH_EVENT + +#define OS_HDL void * +#define DEV_HDL void * + +#define DFS_MALLOC(os_hdl, nbytes) A_MALLOC(nbytes) + +#define DFS_DPRINTK(pDfs, _m, _fmt, ...) do { \ + if ((_m) <= pDfs->dfs_debug_level) { \ + A_PRINTF(_fmt, __VA_ARGS__); \ + } \ +} while (0) + + +void dfs_radar_task (unsigned long arg); + +#define adf_os_packed + +typedef enum { + AH_FALSE = 0, /* NB: lots of code assumes false is zero */ + AH_TRUE = 1, +} HAL_BOOL; +#endif /* ATH_SUPPORT_DFS */ + +#endif /* _DFS_PROJECT_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/dl_list.h b/drivers/net/wireless/ar6003/host/include/dl_list.h new file mode 100644 index 000000000000..662ee1a0708f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/dl_list.h @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Double-link list definitions (adapted from Atheros SDIO stack) +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef __DL_LIST_H___ +#define __DL_LIST_H___ + +#include "a_osapi.h" + +#define A_CONTAINING_STRUCT(address, struct_type, field_name)\ + ((struct_type *)((unsigned long)(address) - (unsigned long)(&((struct_type *)0)->field_name))) + +/* list functions */ +/* pointers for the list */ +typedef struct _DL_LIST { + struct _DL_LIST *pPrev; + struct _DL_LIST *pNext; +}DL_LIST, *PDL_LIST; +/* + * DL_LIST_INIT , initialize doubly linked list +*/ +#define DL_LIST_INIT(pList)\ + {(pList)->pPrev = pList; (pList)->pNext = pList;} + +/* faster macro to init list and add a single item */ +#define DL_LIST_INIT_AND_ADD(pList,pItem) \ +{ (pList)->pPrev = (pItem); \ + (pList)->pNext = (pItem); \ + (pItem)->pNext = (pList); \ + (pItem)->pPrev = (pList); \ +} + +#define DL_LIST_IS_EMPTY(pList) (((pList)->pPrev == (pList)) && ((pList)->pNext == (pList))) +#define DL_LIST_GET_ITEM_AT_HEAD(pList) (pList)->pNext +#define DL_LIST_GET_ITEM_AT_TAIL(pList) (pList)->pPrev +/* + * ITERATE_OVER_LIST pStart is the list, pTemp is a temp list member + * NOT: do not use this function if the items in the list are deleted inside the + * iteration loop +*/ +#define ITERATE_OVER_LIST(pStart, pTemp) \ + for((pTemp) =(pStart)->pNext; pTemp != (pStart); (pTemp) = (pTemp)->pNext) + + +/* safe iterate macro that allows the item to be removed from the list + * the iteration continues to the next item in the list + */ +#define ITERATE_OVER_LIST_ALLOW_REMOVE(pStart,pItem,st,offset) \ +{ \ + PDL_LIST pTemp; \ + pTemp = (pStart)->pNext; \ + while (pTemp != (pStart)) { \ + (pItem) = A_CONTAINING_STRUCT(pTemp,st,offset); \ + pTemp = pTemp->pNext; \ + +#define ITERATE_END }} + +/* + * DL_ListInsertTail - insert pAdd to the end of the list +*/ +static INLINE PDL_LIST DL_ListInsertTail(PDL_LIST pList, PDL_LIST pAdd) { + /* insert at tail */ + pAdd->pPrev = pList->pPrev; + pAdd->pNext = pList; + pList->pPrev->pNext = pAdd; + pList->pPrev = pAdd; + return pAdd; +} + +/* + * DL_ListInsertHead - insert pAdd into the head of the list +*/ +static INLINE PDL_LIST DL_ListInsertHead(PDL_LIST pList, PDL_LIST pAdd) { + /* insert at head */ + pAdd->pPrev = pList; + pAdd->pNext = pList->pNext; + pList->pNext->pPrev = pAdd; + pList->pNext = pAdd; + return pAdd; +} + +#define DL_ListAdd(pList,pItem) DL_ListInsertHead((pList),(pItem)) +/* + * DL_ListRemove - remove pDel from list +*/ +static INLINE PDL_LIST DL_ListRemove(PDL_LIST pDel) { + pDel->pNext->pPrev = pDel->pPrev; + pDel->pPrev->pNext = pDel->pNext; + /* point back to itself just to be safe, incase remove is called again */ + pDel->pNext = pDel; + pDel->pPrev = pDel; + return pDel; +} + +/* + * DL_ListRemoveItemFromHead - get a list item from the head +*/ +static INLINE PDL_LIST DL_ListRemoveItemFromHead(PDL_LIST pList) { + PDL_LIST pItem = NULL; + if (pList->pNext != pList) { + pItem = pList->pNext; + /* remove the first item from head */ + DL_ListRemove(pItem); + } + return pItem; +} + +static INLINE PDL_LIST DL_ListRemoveItemFromTail(PDL_LIST pList) { + PDL_LIST pItem = NULL; + if (pList->pPrev != pList) { + pItem = pList->pPrev; + /* remove the item from tail */ + DL_ListRemove(pItem); + } + return pItem; +} + +/* transfer src list items to the tail of the destination list */ +static INLINE void DL_ListTransferItemsToTail(PDL_LIST pDest, PDL_LIST pSrc) { + /* only concatenate if src is not empty */ + if (!DL_LIST_IS_EMPTY(pSrc)) { + /* cut out circular list in src and re-attach to end of dest */ + pSrc->pPrev->pNext = pDest; + pSrc->pNext->pPrev = pDest->pPrev; + pDest->pPrev->pNext = pSrc->pNext; + pDest->pPrev = pSrc->pPrev; + /* terminate src list, it is now empty */ + pSrc->pPrev = pSrc; + pSrc->pNext = pSrc; + } +} + +#endif /* __DL_LIST_H___ */ diff --git a/drivers/net/wireless/ar6003/host/include/dset_api.h b/drivers/net/wireless/ar6003/host/include/dset_api.h new file mode 100644 index 000000000000..0cc121fd25a0 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/dset_api.h @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Host-side DataSet API. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _DSET_API_H_ +#define _DSET_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Host-side DataSet support is optional, and is not + * currently required for correct operation. To disable + * Host-side DataSet support, set this to 0. + */ +#ifndef CONFIG_HOST_DSET_SUPPORT +#define CONFIG_HOST_DSET_SUPPORT 1 +#endif + +/* Called to send a DataSet Open Reply back to the Target. */ +A_STATUS wmi_dset_open_reply(struct wmi_t *wmip, + A_UINT32 status, + A_UINT32 access_cookie, + A_UINT32 size, + A_UINT32 version, + A_UINT32 targ_handle, + A_UINT32 targ_reply_fn, + A_UINT32 targ_reply_arg); + +/* Called to send a DataSet Data Reply back to the Target. */ +A_STATUS wmi_dset_data_reply(struct wmi_t *wmip, + A_UINT32 status, + A_UINT8 *host_buf, + A_UINT32 length, + A_UINT32 targ_buf, + A_UINT32 targ_reply_fn, + A_UINT32 targ_reply_arg); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* _DSET_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/gpio_api.h b/drivers/net/wireless/ar6003/host/include/gpio_api.h new file mode 100644 index 000000000000..96a150383358 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/gpio_api.h @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Host-side General Purpose I/O API. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _GPIO_API_H_ +#define _GPIO_API_H_ + +/* + * Send a command to the Target in order to change output on GPIO pins. + */ +A_STATUS wmi_gpio_output_set(struct wmi_t *wmip, + A_UINT32 set_mask, + A_UINT32 clear_mask, + A_UINT32 enable_mask, + A_UINT32 disable_mask); + +/* + * Send a command to the Target requesting input state of GPIO pins. + */ +A_STATUS wmi_gpio_input_get(struct wmi_t *wmip); + +/* + * Send a command to the Target to change the value of a GPIO register. + */ +A_STATUS wmi_gpio_register_set(struct wmi_t *wmip, + A_UINT32 gpioreg_id, + A_UINT32 value); + +/* + * Send a command to the Target to fetch the value of a GPIO register. + */ +A_STATUS wmi_gpio_register_get(struct wmi_t *wmip, A_UINT32 gpioreg_id); + +/* + * Send a command to the Target, acknowledging some GPIO interrupts. + */ +A_STATUS wmi_gpio_intr_ack(struct wmi_t *wmip, A_UINT32 ack_mask); + +#endif /* _GPIO_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/hci_transport_api.h b/drivers/net/wireless/ar6003/host/include/hci_transport_api.h new file mode 100644 index 000000000000..b5157ea5d9e9 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/hci_transport_api.h @@ -0,0 +1,259 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HCI_TRANSPORT_API_H_ +#define _HCI_TRANSPORT_API_H_ + + /* Bluetooth HCI packets are stored in HTC packet containers */ +#include "htc_packet.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef void *HCI_TRANSPORT_HANDLE; + +typedef HTC_ENDPOINT_ID HCI_TRANSPORT_PACKET_TYPE; + + /* we map each HCI packet class to a static Endpoint ID */ +#define HCI_COMMAND_TYPE ENDPOINT_1 +#define HCI_EVENT_TYPE ENDPOINT_2 +#define HCI_ACL_TYPE ENDPOINT_3 +#define HCI_PACKET_INVALID ENDPOINT_MAX + +#define HCI_GET_PACKET_TYPE(pP) (pP)->Endpoint +#define HCI_SET_PACKET_TYPE(pP,s) (pP)->Endpoint = (s) + +/* callback when an HCI packet was completely sent */ +typedef void (*HCI_TRANSPORT_SEND_PKT_COMPLETE)(void *, HTC_PACKET *); +/* callback when an HCI packet is received */ +typedef void (*HCI_TRANSPORT_RECV_PKT)(void *, HTC_PACKET *); +/* Optional receive buffer re-fill callback, + * On some OSes (like Linux) packets are allocated from a global pool and indicated up + * to the network stack. The driver never gets the packets back from the OS. For these OSes + * a refill callback can be used to allocate and re-queue buffers into HTC. + * A refill callback is used for the reception of ACL and EVENT packets. The caller must + * set the watermark trigger point to cause a refill. + */ +typedef void (*HCI_TRANSPORT_RECV_REFILL)(void *, HCI_TRANSPORT_PACKET_TYPE Type, int BuffersAvailable); +/* Optional receive packet refill + * On some systems packet buffers are an extremely limited resource. Rather than + * queue largest-possible-sized buffers to the HCI bridge, some systems would rather + * allocate a specific size as the packet is received. The trade off is + * slightly more processing (callback invoked for each RX packet) + * for the benefit of committing fewer buffer resources into the bridge. + * + * The callback is provided the length of the pending packet to fetch. This includes the + * full transport header, HCI header, plus the length of payload. The callback can return a pointer to + * the allocated HTC packet for immediate use. + * + * NOTE*** This callback is mutually exclusive with the the refill callback above. + * + * */ +typedef HTC_PACKET *(*HCI_TRANSPORT_RECV_ALLOC)(void *, HCI_TRANSPORT_PACKET_TYPE Type, int Length); + +typedef enum _HCI_SEND_FULL_ACTION { + HCI_SEND_FULL_KEEP = 0, /* packet that overflowed should be kept in the queue */ + HCI_SEND_FULL_DROP = 1, /* packet that overflowed should be dropped */ +} HCI_SEND_FULL_ACTION; + +/* callback when an HCI send queue exceeds the caller's MaxSendQueueDepth threshold, + * the callback must return the send full action to take (either DROP or KEEP) */ +typedef HCI_SEND_FULL_ACTION (*HCI_TRANSPORT_SEND_FULL)(void *, HTC_PACKET *); + +typedef struct { + int HeadRoom; /* number of bytes in front of HCI packet for header space */ + int TailRoom; /* number of bytes at the end of the HCI packet for tail space */ + int IOBlockPad; /* I/O block padding required (always a power of 2) */ +} HCI_TRANSPORT_PROPERTIES; + +typedef struct _HCI_TRANSPORT_CONFIG_INFO { + int ACLRecvBufferWaterMark; /* low watermark to trigger recv refill */ + int EventRecvBufferWaterMark; /* low watermark to trigger recv refill */ + int MaxSendQueueDepth; /* max number of packets in the single send queue */ + void *pContext; /* context for all callbacks */ + void (*TransportFailure)(void *pContext, A_STATUS Status); /* transport failure callback */ + A_STATUS (*TransportReady)(HCI_TRANSPORT_HANDLE, HCI_TRANSPORT_PROPERTIES *,void *pContext); /* transport is ready */ + void (*TransportRemoved)(void *pContext); /* transport was removed */ + /* packet processing callbacks */ + HCI_TRANSPORT_SEND_PKT_COMPLETE pHCISendComplete; + HCI_TRANSPORT_RECV_PKT pHCIPktRecv; + HCI_TRANSPORT_RECV_REFILL pHCIPktRecvRefill; + HCI_TRANSPORT_RECV_ALLOC pHCIPktRecvAlloc; + HCI_TRANSPORT_SEND_FULL pHCISendFull; +} HCI_TRANSPORT_CONFIG_INFO; + +/* ------ Function Prototypes ------ */ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Attach to the HCI transport module + @function name: HCI_TransportAttach + @input: HTCHandle - HTC handle (see HTC apis) + pInfo - initialization information + @output: + @return: HCI_TRANSPORT_HANDLE on success, NULL on failure + @notes: The HTC module provides HCI transport services. + @example: + @see also: HCI_TransportDetach ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +HCI_TRANSPORT_HANDLE HCI_TransportAttach(void *HTCHandle, HCI_TRANSPORT_CONFIG_INFO *pInfo); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Detach from the HCI transport module + @function name: HCI_TransportDetach + @input: HciTrans - HCI transport handle + pInfo - initialization information + @output: + @return: + @notes: + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HCI_TransportDetach(HCI_TRANSPORT_HANDLE HciTrans); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Add receive packets to the HCI transport + @function name: HCI_TransportAddReceivePkts + @input: HciTrans - HCI transport handle + pQueue - a queue holding one or more packets + @output: + @return: A_OK on success + @notes: user must supply HTC packets for capturing incomming HCI packets. The caller + must initialize each HTC packet using the SET_HTC_PACKET_INFO_RX_REFILL() + macro. Each packet in the queue must be of the same type and length + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportAddReceivePkts(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET_QUEUE *pQueue); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Send an HCI packet packet + @function name: HCI_TransportSendPkt + @input: HciTrans - HCI transport handle + pPacket - packet to send + Synchronous - send the packet synchronously (blocking) + @output: + @return: A_OK + @notes: Caller must initialize packet using SET_HTC_PACKET_INFO_TX() and + HCI_SET_PACKET_TYPE() macros to prepare the packet. + If Synchronous is set to FALSE the call is fully asynchronous. On error or completion, + the registered send complete callback will be called. + If Synchronous is set to TRUE, the call will block until the packet is sent, if the + interface cannot send the packet within a 2 second timeout, the function will return + the failure code : A_EBUSY. + + Synchronous Mode should only be used at start-up to initialize the HCI device using + custom HCI commands. It should NOT be mixed with Asynchronous operations. Mixed synchronous + and asynchronous operation behavior is undefined. + + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportSendPkt(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET *pPacket, A_BOOL Synchronous); + + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Stop HCI transport + @function name: HCI_TransportStop + @input: HciTrans - hci transport handle + @output: + @return: + @notes: HCI transport communication will be halted. All receive and pending TX packets will + be flushed. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HCI_TransportStop(HCI_TRANSPORT_HANDLE HciTrans); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Start the HCI transport + @function name: HCI_TransportStart + @input: HciTrans - hci transport handle + @output: + @return: A_OK on success + @notes: HCI transport communication will begin, the caller can expect the arrival + of HCI recv packets as soon as this call returns. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportStart(HCI_TRANSPORT_HANDLE HciTrans); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Enable or Disable Asynchronous Recv + @function name: HCI_TransportEnableDisableAsyncRecv + @input: HciTrans - hci transport handle + Enable - enable or disable asynchronous recv + @output: + @return: A_OK on success + @notes: This API must be called when HCI recv is handled synchronously + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportEnableDisableAsyncRecv(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Receive an event packet from the HCI transport synchronously using polling + @function name: HCI_TransportRecvHCIEventSync + @input: HciTrans - hci transport handle + pPacket - HTC packet to hold the recv data + MaxPollMS - maximum polling duration in Milliseconds; + @output: + @return: A_OK on success + @notes: This API should be used only during HCI device initialization, the caller must call + HCI_TransportEnableDisableAsyncRecv with Enable=FALSE prior to using this API. + This API will only capture HCI Event packets. + @example: + @see also: HCI_TransportEnableDisableAsyncRecv ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportRecvHCIEventSync(HCI_TRANSPORT_HANDLE HciTrans, + HTC_PACKET *pPacket, + int MaxPollMS); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Set the desired baud rate for the underlying transport layer + @function name: HCI_TransportSetBaudRate + @input: HciTrans - hci transport handle + Baud - baud rate in bps + @output: + @return: A_OK on success + @notes: This API should be used only after HCI device initialization + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportSetBaudRate(HCI_TRANSPORT_HANDLE HciTrans, A_UINT32 Baud); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Enable/Disable HCI Transport Power Management + @function name: HCI_TransportEnablePowerMgmt + @input: HciTrans - hci transport handle + Enable - 1 = Enable, 0 = Disable + @output: + @return: A_OK on success + @notes: + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HCI_TransportEnablePowerMgmt(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); + +#ifdef __cplusplus +} +#endif + +#endif /* _HCI_TRANSPORT_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/hif.h b/drivers/net/wireless/ar6003/host/include/hif.h new file mode 100644 index 000000000000..df0d28f12ecb --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/hif.h @@ -0,0 +1,517 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HIF specific declarations and prototypes +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HIF_H_ +#define _HIF_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Header files */ +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "dl_list.h" + + +typedef struct htc_callbacks HTC_CALLBACKS; +typedef struct hif_device HIF_DEVICE; + +#define HIF_TYPE_AR6002 2 +#define HIF_TYPE_AR6003 3 +#define HIF_TYPE_MCKINLEY 5 + +/* + * direction - Direction of transfer (HIF_READ/HIF_WRITE). + */ +#define HIF_READ 0x00000001 +#define HIF_WRITE 0x00000002 +#define HIF_DIR_MASK (HIF_READ | HIF_WRITE) + +/* + * type - An interface may support different kind of read/write commands. + * For example: SDIO supports CMD52/CMD53s. In case of MSIO it + * translates to using different kinds of TPCs. The command type + * is thus divided into a basic and an extended command and can + * be specified using HIF_BASIC_IO/HIF_EXTENDED_IO. + */ +#define HIF_BASIC_IO 0x00000004 +#define HIF_EXTENDED_IO 0x00000008 +#define HIF_TYPE_MASK (HIF_BASIC_IO | HIF_EXTENDED_IO) + +/* + * emode - This indicates the whether the command is to be executed in a + * blocking or non-blocking fashion (HIF_SYNCHRONOUS/ + * HIF_ASYNCHRONOUS). The read/write data paths in HTC have been + * implemented using the asynchronous mode allowing the the bus + * driver to indicate the completion of operation through the + * registered callback routine. The requirement primarily comes + * from the contexts these operations get called from (a driver's + * transmit context or the ISR context in case of receive). + * Support for both of these modes is essential. + */ +#define HIF_SYNCHRONOUS 0x00000010 +#define HIF_ASYNCHRONOUS 0x00000020 +#define HIF_EMODE_MASK (HIF_SYNCHRONOUS | HIF_ASYNCHRONOUS) + +/* + * dmode - An interface may support different kinds of commands based on + * the tradeoff between the amount of data it can carry and the + * setup time. Byte and Block modes are supported (HIF_BYTE_BASIS/ + * HIF_BLOCK_BASIS). In case of latter, the data is rounded off + * to the nearest block size by padding. The size of the block is + * configurable at compile time using the HIF_BLOCK_SIZE and is + * negotiated with the target during initialization after the + * AR6000 interrupts are enabled. + */ +#define HIF_BYTE_BASIS 0x00000040 +#define HIF_BLOCK_BASIS 0x00000080 +#define HIF_DMODE_MASK (HIF_BYTE_BASIS | HIF_BLOCK_BASIS) + +/* + * amode - This indicates if the address has to be incremented on AR6000 + * after every read/write operation (HIF?FIXED_ADDRESS/ + * HIF_INCREMENTAL_ADDRESS). + */ +#define HIF_FIXED_ADDRESS 0x00000100 +#define HIF_INCREMENTAL_ADDRESS 0x00000200 +#define HIF_AMODE_MASK (HIF_FIXED_ADDRESS | HIF_INCREMENTAL_ADDRESS) + +#define HIF_WR_ASYNC_BYTE_FIX \ + (HIF_WRITE | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) +#define HIF_WR_ASYNC_BYTE_INC \ + (HIF_WRITE | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_WR_ASYNC_BLOCK_INC \ + (HIF_WRITE | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_WR_SYNC_BYTE_FIX \ + (HIF_WRITE | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) +#define HIF_WR_SYNC_BYTE_INC \ + (HIF_WRITE | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_WR_SYNC_BLOCK_INC \ + (HIF_WRITE | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_WR_ASYNC_BLOCK_FIX \ + (HIF_WRITE | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) +#define HIF_WR_SYNC_BLOCK_FIX \ + (HIF_WRITE | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) +#define HIF_RD_SYNC_BYTE_INC \ + (HIF_READ | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_RD_SYNC_BYTE_FIX \ + (HIF_READ | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) +#define HIF_RD_ASYNC_BYTE_FIX \ + (HIF_READ | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) +#define HIF_RD_ASYNC_BLOCK_FIX \ + (HIF_READ | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) +#define HIF_RD_ASYNC_BYTE_INC \ + (HIF_READ | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_RD_ASYNC_BLOCK_INC \ + (HIF_READ | HIF_ASYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_RD_SYNC_BLOCK_INC \ + (HIF_READ | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) +#define HIF_RD_SYNC_BLOCK_FIX \ + (HIF_READ | HIF_SYNCHRONOUS | HIF_EXTENDED_IO | HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) + +typedef enum { + HIF_DEVICE_POWER_STATE = 0, + HIF_DEVICE_GET_MBOX_BLOCK_SIZE, + HIF_DEVICE_GET_MBOX_ADDR, + HIF_DEVICE_GET_PENDING_EVENTS_FUNC, + HIF_DEVICE_GET_IRQ_PROC_MODE, + HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC, + HIF_DEVICE_POWER_STATE_CHANGE, + HIF_DEVICE_GET_IRQ_YIELD_PARAMS, + HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT, + HIF_DEVICE_GET_OS_DEVICE, + HIF_DEVICE_DEBUG_BUS_STATE, +} HIF_DEVICE_CONFIG_OPCODE; + +/* + * HIF CONFIGURE definitions: + * + * HIF_DEVICE_GET_MBOX_BLOCK_SIZE + * input : none + * output : array of 4 A_UINT32s + * notes: block size is returned for each mailbox (4) + * + * HIF_DEVICE_GET_MBOX_ADDR + * input : none + * output : HIF_DEVICE_MBOX_INFO + * notes: + * + * HIF_DEVICE_GET_PENDING_EVENTS_FUNC + * input : none + * output: HIF_PENDING_EVENTS_FUNC function pointer + * notes: this is optional for the HIF layer, if the request is + * not handled then it indicates that the upper layer can use + * the standard device methods to get pending events (IRQs, mailbox messages etc..) + * otherwise it can call the function pointer to check pending events. + * + * HIF_DEVICE_GET_IRQ_PROC_MODE + * input : none + * output : HIF_DEVICE_IRQ_PROCESSING_MODE (interrupt processing mode) + * note: the hif layer interfaces with the underlying OS-specific bus driver. The HIF + * layer can report whether IRQ processing is requires synchronous behavior or + * can be processed using asynchronous bus requests (typically faster). + * + * HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC + * input : + * output : HIF_MASK_UNMASK_RECV_EVENT function pointer + * notes: this is optional for the HIF layer. The HIF layer may require a special mechanism + * to mask receive message events. The upper layer can call this pointer when it needs + * to mask/unmask receive events (in case it runs out of buffers). + * + * HIF_DEVICE_POWER_STATE_CHANGE + * + * input : HIF_DEVICE_POWER_CHANGE_TYPE + * output : none + * note: this is optional for the HIF layer. The HIF layer can handle power on/off state change + * requests in an interconnect specific way. This is highly OS and bus driver dependent. + * The caller must guarantee that no HIF read/write requests will be made after the device + * is powered down. + * + * HIF_DEVICE_GET_IRQ_YIELD_PARAMS + * + * input : none + * output : HIF_DEVICE_IRQ_YIELD_PARAMS + * note: This query checks if the HIF layer wishes to impose a processing yield count for the DSR handler. + * The DSR callback handler will exit after a fixed number of RX packets or events are processed. + * This query is only made if the device reports an IRQ processing mode of HIF_DEVICE_IRQ_SYNC_ONLY. + * The HIF implementation can ignore this command if it does not desire the DSR callback to yield. + * The HIF layer can indicate the maximum number of IRQ processing units (RX packets) before the + * DSR handler callback must yield and return control back to the HIF layer. When a yield limit is + * used the DSR callback will not call HIFAckInterrupts() as it would normally do before returning. + * The HIF implementation that requires a yield count must call HIFAckInterrupt() when it is prepared + * to process interrupts again. + * + * HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT + * input : none + * output : HIF_DEVICE_SCATTER_SUPPORT_INFO + * note: This query checks if the HIF layer implements the SCATTER request interface. Scatter requests + * allows upper layers to submit mailbox I/O operations using a list of buffers. This is useful for + * multi-message transfers that can better utilize the bus interconnect. + * + * + * HIF_DEVICE_GET_OS_DEVICE + * intput : none + * output : HIF_DEVICE_OS_DEVICE_INFO; + * note: On some operating systems, the HIF layer has a parent device object for the bus. This object + * may be required to register certain types of logical devices. + * + * HIF_DEVICE_DEBUG_BUS_STATE + * input : none + * output : none + * note: This configure option triggers the HIF interface to dump as much bus interface state. This + * configuration request is optional (No-OP on some HIF implementations) + * + */ + +typedef struct { + A_UINT32 ExtendedAddress; /* extended address for larger writes */ + A_UINT32 ExtendedSize; +} HIF_MBOX_PROPERTIES; + +#define HIF_MBOX_FLAG_NO_BUNDLING (1 << 0) /* do not allow bundling over the mailbox */ + +typedef struct { + A_UINT32 MboxAddresses[4]; /* must be first element for legacy HIFs that return the address in + and ARRAY of 32-bit words */ + + /* the following describe extended mailbox properties */ + HIF_MBOX_PROPERTIES MboxProp[4]; + /* if the HIF supports the GMbox extended address region it can report it + * here, some interfaces cannot support the GMBOX address range and not set this */ + A_UINT32 GMboxAddress; + A_UINT32 GMboxSize; + A_UINT32 Flags; /* flags to describe mbox behavior or usage */ +} HIF_DEVICE_MBOX_INFO; + +typedef enum { + HIF_DEVICE_IRQ_SYNC_ONLY, /* for HIF implementations that require the DSR to process all + interrupts before returning */ + HIF_DEVICE_IRQ_ASYNC_SYNC, /* for HIF implementations that allow DSR to process interrupts + using ASYNC I/O (that is HIFAckInterrupt can be called at a + later time */ +} HIF_DEVICE_IRQ_PROCESSING_MODE; + +typedef enum { + HIF_DEVICE_POWER_UP, /* HIF layer should power up interface and/or module */ + HIF_DEVICE_POWER_DOWN, /* HIF layer should initiate bus-specific measures to minimize power */ + HIF_DEVICE_POWER_CUT /* HIF layer should initiate bus-specific AND/OR platform-specific measures + to completely power-off the module and associated hardware (i.e. cut power supplies) + */ +} HIF_DEVICE_POWER_CHANGE_TYPE; + +typedef struct { + int RecvPacketYieldCount; /* max number of packets to force DSR to return */ +} HIF_DEVICE_IRQ_YIELD_PARAMS; + + +typedef struct _HIF_SCATTER_ITEM { + A_UINT8 *pBuffer; /* CPU accessible address of buffer */ + int Length; /* length of transfer to/from this buffer */ + void *pCallerContexts[2]; /* space for caller to insert a context associated with this item */ +} HIF_SCATTER_ITEM; + +struct _HIF_SCATTER_REQ; + +typedef void ( *HIF_SCATTER_COMP_CB)(struct _HIF_SCATTER_REQ *); + +typedef enum _HIF_SCATTER_METHOD { + HIF_SCATTER_NONE = 0, + HIF_SCATTER_DMA_REAL, /* Real SG support no restrictions */ + HIF_SCATTER_DMA_BOUNCE, /* Uses SG DMA but HIF layer uses an internal bounce buffer */ +} HIF_SCATTER_METHOD; + +typedef struct _HIF_SCATTER_REQ { + DL_LIST ListLink; /* link management */ + A_UINT32 Address; /* address for the read/write operation */ + A_UINT32 Request; /* request flags */ + A_UINT32 TotalLength; /* total length of entire transfer */ + A_UINT32 CallerFlags; /* caller specific flags can be stored here */ + HIF_SCATTER_COMP_CB CompletionRoutine; /* completion routine set by caller */ + A_STATUS CompletionStatus; /* status of completion */ + void *Context; /* caller context for this request */ + int ValidScatterEntries; /* number of valid entries set by caller */ + HIF_SCATTER_METHOD ScatterMethod; /* scatter method handled by HIF */ + void *HIFPrivate[4]; /* HIF private area */ + A_UINT8 *pScatterBounceBuffer; /* bounce buffer for upper layers to copy to/from */ + HIF_SCATTER_ITEM ScatterList[1]; /* start of scatter list */ +} HIF_SCATTER_REQ; + +typedef HIF_SCATTER_REQ * ( *HIF_ALLOCATE_SCATTER_REQUEST)(HIF_DEVICE *device); +typedef void ( *HIF_FREE_SCATTER_REQUEST)(HIF_DEVICE *device, HIF_SCATTER_REQ *request); +typedef A_STATUS ( *HIF_READWRITE_SCATTER)(HIF_DEVICE *device, HIF_SCATTER_REQ *request); + +typedef struct _HIF_DEVICE_SCATTER_SUPPORT_INFO { + /* information returned from HIF layer */ + HIF_ALLOCATE_SCATTER_REQUEST pAllocateReqFunc; + HIF_FREE_SCATTER_REQUEST pFreeReqFunc; + HIF_READWRITE_SCATTER pReadWriteScatterFunc; + int MaxScatterEntries; + int MaxTransferSizePerScatterReq; +} HIF_DEVICE_SCATTER_SUPPORT_INFO; + +typedef struct { + void *pOSDevice; +} HIF_DEVICE_OS_DEVICE_INFO; + +#define HIF_MAX_DEVICES 1 + +struct htc_callbacks { + void *context; /* context to pass to the dsrhandler + note : rwCompletionHandler is provided the context passed to HIFReadWrite */ + A_STATUS (* rwCompletionHandler)(void *rwContext, A_STATUS status); + A_STATUS (* dsrHandler)(void *context); +}; + +typedef struct osdrv_callbacks { + void *context; /* context to pass for all callbacks except deviceRemovedHandler + the deviceRemovedHandler is only called if the device is claimed */ + A_STATUS (* deviceInsertedHandler)(void *context, void *hif_handle); + A_STATUS (* deviceRemovedHandler)(void *claimedContext, void *hif_handle); + A_STATUS (* deviceSuspendHandler)(void *context); + A_STATUS (* deviceResumeHandler)(void *context); + A_STATUS (* deviceWakeupHandler)(void *context); + A_STATUS (* devicePowerChangeHandler)(void *context, HIF_DEVICE_POWER_CHANGE_TYPE config); +} OSDRV_CALLBACKS; + +#define HIF_OTHER_EVENTS (1 << 0) /* other interrupts (non-Recv) are pending, host + needs to read the register table to figure out what */ +#define HIF_RECV_MSG_AVAIL (1 << 1) /* pending recv packet */ + +typedef struct _HIF_PENDING_EVENTS_INFO { + A_UINT32 Events; + A_UINT32 LookAhead; + A_UINT32 AvailableRecvBytes; +} HIF_PENDING_EVENTS_INFO; + + /* function to get pending events , some HIF modules use special mechanisms + * to detect packet available and other interrupts */ +typedef A_STATUS ( *HIF_PENDING_EVENTS_FUNC)(HIF_DEVICE *device, + HIF_PENDING_EVENTS_INFO *pEvents, + void *AsyncContext); + +#define HIF_MASK_RECV TRUE +#define HIF_UNMASK_RECV FALSE + /* function to mask recv events */ +typedef A_STATUS ( *HIF_MASK_UNMASK_RECV_EVENT)(HIF_DEVICE *device, + A_BOOL Mask, + void *AsyncContext); + + +/* + * This API is used to perform any global initialization of the HIF layer + * and to set OS driver callbacks (i.e. insertion/removal) to the HIF layer + * + */ +A_STATUS HIFInit(OSDRV_CALLBACKS *callbacks); + +/* This API claims the HIF device and provides a context for handling removal. + * The device removal callback is only called when the OSDRV layer claims + * a device. The claimed context must be non-NULL */ +void HIFClaimDevice(HIF_DEVICE *device, void *claimedContext); +/* release the claimed device */ +void HIFReleaseDevice(HIF_DEVICE *device); + +/* This API allows the HTC layer to attach to the HIF device */ +A_STATUS HIFAttachHTC(HIF_DEVICE *device, HTC_CALLBACKS *callbacks); +/* This API detaches the HTC layer from the HIF device */ +void HIFDetachHTC(HIF_DEVICE *device); + +/* + * This API is used to provide the read/write interface over the specific bus + * interface. + * address - Starting address in the AR6000's address space. For mailbox + * writes, it refers to the start of the mbox boundary. It should + * be ensured that the last byte falls on the mailbox's EOM. For + * mailbox reads, it refers to the end of the mbox boundary. + * buffer - Pointer to the buffer containg the data to be transmitted or + * received. + * length - Amount of data to be transmitted or received. + * request - Characterizes the attributes of the command. + */ +A_STATUS +HIFReadWrite(HIF_DEVICE *device, + A_UINT32 address, + A_UCHAR *buffer, + A_UINT32 length, + A_UINT32 request, + void *context); + +/* + * This can be initiated from the unload driver context when the OSDRV layer has no more use for + * the device. + */ +void HIFShutDownDevice(HIF_DEVICE *device); + +/* + * This should translate to an acknowledgment to the bus driver indicating that + * the previous interrupt request has been serviced and the all the relevant + * sources have been cleared. HTC is ready to process more interrupts. + * This should prevent the bus driver from raising an interrupt unless the + * previous one has been serviced and acknowledged using the previous API. + */ +void HIFAckInterrupt(HIF_DEVICE *device); + +void HIFMaskInterrupt(HIF_DEVICE *device); + +void HIFUnMaskInterrupt(HIF_DEVICE *device); + +A_STATUS +HIFConfigureDevice(HIF_DEVICE *device, HIF_DEVICE_CONFIG_OPCODE opcode, + void *config, A_UINT32 configLen); + +/* + * This API wait for the remaining MBOX messages to be drained + * This should be moved to HTC AR6K layer + */ +A_STATUS hifWaitForPendingRecv(HIF_DEVICE *device); + +/****************************************************************/ +/* message based HIF interfaces */ +/****************************************************************/ + +#define HIF_BMI_EXCHANGE_NO_TIMEOUT ((A_UINT32)(0)) + +struct _HIF_MSG_OBJ; + +typedef void (* HIF_MSG_RECV_CALLBACK)(void *, struct _HIF_MSG_OBJ *); +typedef void (* HIF_MSG_REQ_COMPLETION)(void *,struct _HIF_MSG_OBJ *); + +typedef enum { + HIF_MSG_SIMPLE_BUFFER = 0, /* a simple buffer ptr and length */ + HIF_MSG_NET_BUFFER = 1 /* advanced OS-specific network buffer */ +} HIF_MSG_BUFFER_TYPE; + + /* object to pass HIF message requests from upper layers */ +typedef struct _HIF_MSG_OBJ { + DL_LIST ListLink; /* for list management */ + A_INT32 PipeId; /* pipe number to send on or recv'd from*/ + HIF_MSG_BUFFER_TYPE BufferType; + union { + struct HIF_MSG_NET_BUFFER { + void *pAppNetBuf; /* OS-specific net buf */ + } AsNetBuffer; + struct HIF_MSG_SIMPLE_BUFFER { + void *pBuffer; /* for future use.... */ + A_UINT32 Length; + } AsSimpleBuffer; + } BufferInfo; + void *pContext; /* caller context of message */ + HIF_MSG_REQ_COMPLETION CompletionRoutine; /* completion routine */ + A_STATUS Status; /* completion status */ + A_UINT32 Flags; /* request flags */ + void *HIFPriv[4]; /* private contexts for HIF layer to use */ + +} HIF_MSG_OBJ; + + /* API to handle HIF-specific BMI message exchanges, this API is synchronous + * and only allowed to be called from a context that can block (sleep) */ +A_STATUS HIFExchangeBMIMsg(HIF_DEVICE *device, + A_UINT8 *pSendMessage, + A_UINT32 Length, + A_UINT8 *pResponseMessage, + A_UINT32 *pResponseLength, + A_UINT32 TimeoutMS); + + /* API to handle HIF specific diagnostic window read accesses, this API is synchronous + * and only allowed to be called from a context that can block (sleep) */ +A_STATUS HIFDiagReadAccess(HIF_DEVICE *hifDevice, A_UINT32 address, A_UINT32 *data); + + /* API to handle HIF specific diagnostic window write accesses, this API is synchronous + * and only allowed to be called from a context that can block (sleep) */ +A_STATUS HIFDiagWriteAccess(HIF_DEVICE *hifDevice, A_UINT32 address, A_UINT32 data); + + /* get the Pipe ID associated with the service ID */ +A_STATUS HIFGetPipeId(HIF_DEVICE *hifDevice, A_UINT16 ServiceId, A_INT32 *pId); + + /* API to let HIF layer know that pipe communications should be enabled + * caller will start to exchange messages on service pipes */ +A_STATUS HIFEnablePipes(HIF_DEVICE *hifDevice); + + /* set the message recv handler for all incomming messages */ +void HIFSetMsgRecvHandler(HIF_DEVICE *hifDevice, + HIF_MSG_RECV_CALLBACK Callback, + void *pContext); + + /* upper layers should return the HIF_MSG_OBJ back to HIF as it may be associated + * with some recv resource. The objects could be returned in a chain (batch mode) + * Note, upper layers can take ownership of the buffer (free it) if it is of the type + * HIF_MSG_NET_BUFFER, in this case upper layers will set + * BufferInfo.AsNetBuffer.pAppNetBuf to NULL */ +void HIFReturnRecvMsgObjects(HIF_DEVICE *hifDevice, HIF_MSG_OBJ *pMessageObj); + + /* API for upper layers to send one or more messages. Note, HIF may + * take ownership of the buffer (it will free it) if it is of the type + * HIF_MSG_NET_BUFFER, in this case the HIF layer will set + * BufferInfo.AsNetBuffer.pAppNetBuf to NULL */ +A_STATUS HIFSendMessages(HIF_DEVICE *hifDevice, HIF_MSG_OBJ *pMessages); + + +#ifdef __cplusplus +} +#endif + +#endif /* _HIF_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/host_reg_table.h b/drivers/net/wireless/ar6003/host/include/host_reg_table.h new file mode 100644 index 000000000000..a664cd826f31 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/host_reg_table.h @@ -0,0 +1,226 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Target register table macros and structure definitions +// +// Author(s): ="Atheros" +//============================================================================== + +#ifndef HOST_REG_TABLE_H_ +#define HOST_REG_TABLE_H_ + +#include "targaddrs.h" +/*** WARNING : Add to the end of the TABLE! do not change the order ****/ +typedef struct hostdef_s { + A_UINT32 d_INT_STATUS_ENABLE_ERROR_LSB; + A_UINT32 d_INT_STATUS_ENABLE_ERROR_MASK; + A_UINT32 d_INT_STATUS_ENABLE_CPU_LSB; + A_UINT32 d_INT_STATUS_ENABLE_CPU_MASK; + A_UINT32 d_INT_STATUS_ENABLE_COUNTER_LSB; + A_UINT32 d_INT_STATUS_ENABLE_COUNTER_MASK; + A_UINT32 d_INT_STATUS_ENABLE_MBOX_DATA_LSB; + A_UINT32 d_INT_STATUS_ENABLE_MBOX_DATA_MASK; + A_UINT32 d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB; + A_UINT32 d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK; + A_UINT32 d_ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB; + A_UINT32 d_ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK; + A_UINT32 d_COUNTER_INT_STATUS_ENABLE_BIT_LSB; + A_UINT32 d_COUNTER_INT_STATUS_ENABLE_BIT_MASK; + A_UINT32 d_INT_STATUS_ENABLE_ADDRESS; + A_UINT32 d_CPU_INT_STATUS_ENABLE_BIT_LSB; + A_UINT32 d_CPU_INT_STATUS_ENABLE_BIT_MASK; + A_UINT32 d_HOST_INT_STATUS_ADDRESS; + A_UINT32 d_CPU_INT_STATUS_ADDRESS; + A_UINT32 d_ERROR_INT_STATUS_ADDRESS; + A_UINT32 d_ERROR_INT_STATUS_WAKEUP_MASK; + A_UINT32 d_ERROR_INT_STATUS_WAKEUP_LSB; + A_UINT32 d_ERROR_INT_STATUS_RX_UNDERFLOW_MASK; + A_UINT32 d_ERROR_INT_STATUS_RX_UNDERFLOW_LSB; + A_UINT32 d_ERROR_INT_STATUS_TX_OVERFLOW_MASK; + A_UINT32 d_ERROR_INT_STATUS_TX_OVERFLOW_LSB; + A_UINT32 d_COUNT_DEC_ADDRESS; + A_UINT32 d_HOST_INT_STATUS_CPU_MASK; + A_UINT32 d_HOST_INT_STATUS_CPU_LSB; + A_UINT32 d_HOST_INT_STATUS_ERROR_MASK; + A_UINT32 d_HOST_INT_STATUS_ERROR_LSB; + A_UINT32 d_HOST_INT_STATUS_COUNTER_MASK; + A_UINT32 d_HOST_INT_STATUS_COUNTER_LSB; + A_UINT32 d_RX_LOOKAHEAD_VALID_ADDRESS; + A_UINT32 d_WINDOW_DATA_ADDRESS; + A_UINT32 d_WINDOW_READ_ADDR_ADDRESS; + A_UINT32 d_WINDOW_WRITE_ADDR_ADDRESS; +} HOST_REGISTER_TABLE; + +#if defined(MY_HOST_DEF) /* { */ +#if defined(ATHR_WIN_DEF) +#define ATH_REG_TABLE_DIRECT_ASSIGN +#endif +#ifdef ATH_REG_TABLE_DIRECT_ASSIGN + +static struct hostdef_s my_host_def = { + INT_STATUS_ENABLE_ERROR_LSB, + INT_STATUS_ENABLE_ERROR_MASK, + INT_STATUS_ENABLE_CPU_LSB, + INT_STATUS_ENABLE_CPU_MASK, + INT_STATUS_ENABLE_COUNTER_LSB, + INT_STATUS_ENABLE_COUNTER_MASK, + INT_STATUS_ENABLE_MBOX_DATA_LSB, + INT_STATUS_ENABLE_MBOX_DATA_MASK, + ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB, + ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK, + ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB, + ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK, + COUNTER_INT_STATUS_ENABLE_BIT_LSB, + COUNTER_INT_STATUS_ENABLE_BIT_MASK, + INT_STATUS_ENABLE_ADDRESS, + CPU_INT_STATUS_ENABLE_BIT_LSB, + CPU_INT_STATUS_ENABLE_BIT_MASK, + HOST_INT_STATUS_ADDRESS, + CPU_INT_STATUS_ADDRESS, + ERROR_INT_STATUS_ADDRESS, + ERROR_INT_STATUS_WAKEUP_MASK, + ERROR_INT_STATUS_WAKEUP_LSB, + ERROR_INT_STATUS_RX_UNDERFLOW_MASK, + ERROR_INT_STATUS_RX_UNDERFLOW_LSB, + ERROR_INT_STATUS_TX_OVERFLOW_MASK, + ERROR_INT_STATUS_TX_OVERFLOW_LSB, + COUNT_DEC_ADDRESS, + HOST_INT_STATUS_CPU_MASK, + HOST_INT_STATUS_CPU_LSB, + HOST_INT_STATUS_ERROR_MASK, + HOST_INT_STATUS_ERROR_LSB, + HOST_INT_STATUS_COUNTER_MASK, + HOST_INT_STATUS_COUNTER_LSB, + RX_LOOKAHEAD_VALID_ADDRESS, + WINDOW_DATA_ADDRESS, + WINDOW_READ_ADDR_ADDRESS, + WINDOW_WRITE_ADDR_ADDRESS, +}; + +#else + +static struct hostdef_s my_host_def = { + .d_INT_STATUS_ENABLE_ERROR_LSB = INT_STATUS_ENABLE_ERROR_LSB, + .d_INT_STATUS_ENABLE_ERROR_MASK = INT_STATUS_ENABLE_ERROR_MASK, + .d_INT_STATUS_ENABLE_CPU_LSB = INT_STATUS_ENABLE_CPU_LSB, + .d_INT_STATUS_ENABLE_CPU_MASK = INT_STATUS_ENABLE_CPU_MASK, + .d_INT_STATUS_ENABLE_COUNTER_LSB = INT_STATUS_ENABLE_COUNTER_LSB, + .d_INT_STATUS_ENABLE_COUNTER_MASK = INT_STATUS_ENABLE_COUNTER_MASK, + .d_INT_STATUS_ENABLE_MBOX_DATA_LSB = INT_STATUS_ENABLE_MBOX_DATA_LSB, + .d_INT_STATUS_ENABLE_MBOX_DATA_MASK = INT_STATUS_ENABLE_MBOX_DATA_MASK, + .d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB = ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB, + .d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK = ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK, + .d_ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB = ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB, + .d_ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK = ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK, + .d_COUNTER_INT_STATUS_ENABLE_BIT_LSB = COUNTER_INT_STATUS_ENABLE_BIT_LSB, + .d_COUNTER_INT_STATUS_ENABLE_BIT_MASK = COUNTER_INT_STATUS_ENABLE_BIT_MASK, + .d_INT_STATUS_ENABLE_ADDRESS = INT_STATUS_ENABLE_ADDRESS, + .d_CPU_INT_STATUS_ENABLE_BIT_LSB = CPU_INT_STATUS_ENABLE_BIT_LSB, + .d_CPU_INT_STATUS_ENABLE_BIT_MASK = CPU_INT_STATUS_ENABLE_BIT_MASK, + .d_HOST_INT_STATUS_ADDRESS = HOST_INT_STATUS_ADDRESS, + .d_CPU_INT_STATUS_ADDRESS = CPU_INT_STATUS_ADDRESS, + .d_ERROR_INT_STATUS_ADDRESS = ERROR_INT_STATUS_ADDRESS, + .d_ERROR_INT_STATUS_WAKEUP_MASK = ERROR_INT_STATUS_WAKEUP_MASK, + .d_ERROR_INT_STATUS_WAKEUP_LSB = ERROR_INT_STATUS_WAKEUP_LSB, + .d_ERROR_INT_STATUS_RX_UNDERFLOW_MASK = ERROR_INT_STATUS_RX_UNDERFLOW_MASK, + .d_ERROR_INT_STATUS_RX_UNDERFLOW_LSB = ERROR_INT_STATUS_RX_UNDERFLOW_LSB, + .d_ERROR_INT_STATUS_TX_OVERFLOW_MASK = ERROR_INT_STATUS_TX_OVERFLOW_MASK, + .d_ERROR_INT_STATUS_TX_OVERFLOW_LSB = ERROR_INT_STATUS_TX_OVERFLOW_LSB, + .d_COUNT_DEC_ADDRESS = COUNT_DEC_ADDRESS, + .d_HOST_INT_STATUS_CPU_MASK = HOST_INT_STATUS_CPU_MASK, + .d_HOST_INT_STATUS_CPU_LSB = HOST_INT_STATUS_CPU_LSB, + .d_HOST_INT_STATUS_ERROR_MASK = HOST_INT_STATUS_ERROR_MASK, + .d_HOST_INT_STATUS_ERROR_LSB = HOST_INT_STATUS_ERROR_LSB, + .d_HOST_INT_STATUS_COUNTER_MASK = HOST_INT_STATUS_COUNTER_MASK, + .d_HOST_INT_STATUS_COUNTER_LSB = HOST_INT_STATUS_COUNTER_LSB, + .d_RX_LOOKAHEAD_VALID_ADDRESS = RX_LOOKAHEAD_VALID_ADDRESS, + .d_WINDOW_DATA_ADDRESS = WINDOW_DATA_ADDRESS, + .d_WINDOW_READ_ADDR_ADDRESS = WINDOW_READ_ADDR_ADDRESS, + .d_WINDOW_WRITE_ADDR_ADDRESS = WINDOW_WRITE_ADDR_ADDRESS, +}; + +#endif + +struct hostdef_s *MY_HOST_DEF = &my_host_def; + +#else /* } { */ + +#define INT_STATUS_ENABLE_ERROR_LSB (hostdef->d_INT_STATUS_ENABLE_ERROR_LSB) +#define INT_STATUS_ENABLE_ERROR_MASK (hostdef->d_INT_STATUS_ENABLE_ERROR_MASK) +#define INT_STATUS_ENABLE_CPU_LSB (hostdef->d_INT_STATUS_ENABLE_CPU_LSB) +#define INT_STATUS_ENABLE_CPU_MASK (hostdef->d_INT_STATUS_ENABLE_CPU_MASK) +#define INT_STATUS_ENABLE_COUNTER_LSB (hostdef->d_INT_STATUS_ENABLE_COUNTER_LSB) +#define INT_STATUS_ENABLE_COUNTER_MASK (hostdef->d_INT_STATUS_ENABLE_COUNTER_MASK) +#define INT_STATUS_ENABLE_MBOX_DATA_LSB (hostdef->d_INT_STATUS_ENABLE_MBOX_DATA_LSB) +#define INT_STATUS_ENABLE_MBOX_DATA_MASK (hostdef->d_INT_STATUS_ENABLE_MBOX_DATA_MASK) +#define ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB (hostdef->d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB) +#define ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK (hostdef->d_ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK) +#define ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB (hostdef->d_ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB) +#define ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK (hostdef->d_ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK) +#define COUNTER_INT_STATUS_ENABLE_BIT_LSB (hostdef->d_COUNTER_INT_STATUS_ENABLE_BIT_LSB) +#define COUNTER_INT_STATUS_ENABLE_BIT_MASK (hostdef->d_COUNTER_INT_STATUS_ENABLE_BIT_MASK) +#define INT_STATUS_ENABLE_ADDRESS (hostdef->d_INT_STATUS_ENABLE_ADDRESS) +#define CPU_INT_STATUS_ENABLE_BIT_LSB (hostdef->d_CPU_INT_STATUS_ENABLE_BIT_LSB) +#define CPU_INT_STATUS_ENABLE_BIT_MASK (hostdef->d_CPU_INT_STATUS_ENABLE_BIT_MASK) +#define HOST_INT_STATUS_ADDRESS (hostdef->d_HOST_INT_STATUS_ADDRESS) +#define CPU_INT_STATUS_ADDRESS (hostdef->d_CPU_INT_STATUS_ADDRESS) +#define ERROR_INT_STATUS_ADDRESS (hostdef->d_ERROR_INT_STATUS_ADDRESS) +#define ERROR_INT_STATUS_WAKEUP_MASK (hostdef->d_ERROR_INT_STATUS_WAKEUP_MASK) +#define ERROR_INT_STATUS_WAKEUP_LSB (hostdef->d_ERROR_INT_STATUS_WAKEUP_LSB) +#define ERROR_INT_STATUS_RX_UNDERFLOW_MASK (hostdef->d_ERROR_INT_STATUS_RX_UNDERFLOW_MASK) +#define ERROR_INT_STATUS_RX_UNDERFLOW_LSB (hostdef->d_ERROR_INT_STATUS_RX_UNDERFLOW_LSB) +#define ERROR_INT_STATUS_TX_OVERFLOW_MASK (hostdef->d_ERROR_INT_STATUS_TX_OVERFLOW_MASK) +#define ERROR_INT_STATUS_TX_OVERFLOW_LSB (hostdef->d_ERROR_INT_STATUS_TX_OVERFLOW_LSB) +#define COUNT_DEC_ADDRESS (hostdef->d_COUNT_DEC_ADDRESS) +#define HOST_INT_STATUS_CPU_MASK (hostdef->d_HOST_INT_STATUS_CPU_MASK) +#define HOST_INT_STATUS_CPU_LSB (hostdef->d_HOST_INT_STATUS_CPU_LSB) +#define HOST_INT_STATUS_ERROR_MASK (hostdef->d_HOST_INT_STATUS_ERROR_MASK) +#define HOST_INT_STATUS_ERROR_LSB (hostdef->d_HOST_INT_STATUS_ERROR_LSB) +#define HOST_INT_STATUS_COUNTER_MASK (hostdef->d_HOST_INT_STATUS_COUNTER_MASK) +#define HOST_INT_STATUS_COUNTER_LSB (hostdef->d_HOST_INT_STATUS_COUNTER_LSB) +#define RX_LOOKAHEAD_VALID_ADDRESS (hostdef->d_RX_LOOKAHEAD_VALID_ADDRESS) +#define WINDOW_DATA_ADDRESS (hostdef->d_WINDOW_DATA_ADDRESS) +#define WINDOW_READ_ADDR_ADDRESS (hostdef->d_WINDOW_READ_ADDR_ADDRESS) +#define WINDOW_WRITE_ADDR_ADDRESS (hostdef->d_WINDOW_WRITE_ADDR_ADDRESS) + +/* SET macros */ +#define INT_STATUS_ENABLE_ERROR_SET(x) (((x) << INT_STATUS_ENABLE_ERROR_LSB) & INT_STATUS_ENABLE_ERROR_MASK) +#define INT_STATUS_ENABLE_CPU_SET(x) (((x) << INT_STATUS_ENABLE_CPU_LSB) & INT_STATUS_ENABLE_CPU_MASK) +#define INT_STATUS_ENABLE_COUNTER_SET(x) (((x) << INT_STATUS_ENABLE_COUNTER_LSB) & INT_STATUS_ENABLE_COUNTER_MASK) +#define INT_STATUS_ENABLE_MBOX_DATA_SET(x) (((x) << INT_STATUS_ENABLE_MBOX_DATA_LSB) & INT_STATUS_ENABLE_MBOX_DATA_MASK) +#define CPU_INT_STATUS_ENABLE_BIT_SET(x) (((x) << CPU_INT_STATUS_ENABLE_BIT_LSB) & CPU_INT_STATUS_ENABLE_BIT_MASK) +#define ERROR_STATUS_ENABLE_RX_UNDERFLOW_SET(x) (((x) << ERROR_STATUS_ENABLE_RX_UNDERFLOW_LSB) & ERROR_STATUS_ENABLE_RX_UNDERFLOW_MASK) +#define ERROR_STATUS_ENABLE_TX_OVERFLOW_SET(x) (((x) << ERROR_STATUS_ENABLE_TX_OVERFLOW_LSB) & ERROR_STATUS_ENABLE_TX_OVERFLOW_MASK) +#define COUNTER_INT_STATUS_ENABLE_BIT_SET(x) (((x) << COUNTER_INT_STATUS_ENABLE_BIT_LSB) & COUNTER_INT_STATUS_ENABLE_BIT_MASK) +#define ERROR_INT_STATUS_WAKEUP_GET(x) (((x) & ERROR_INT_STATUS_WAKEUP_MASK) >> ERROR_INT_STATUS_WAKEUP_LSB) +#define ERROR_INT_STATUS_RX_UNDERFLOW_GET(x) (((x) & ERROR_INT_STATUS_RX_UNDERFLOW_MASK) >> ERROR_INT_STATUS_RX_UNDERFLOW_LSB) +#define ERROR_INT_STATUS_TX_OVERFLOW_GET(x) (((x) & ERROR_INT_STATUS_TX_OVERFLOW_MASK) >> ERROR_INT_STATUS_TX_OVERFLOW_LSB) +#define HOST_INT_STATUS_CPU_GET(x) (((x) & HOST_INT_STATUS_CPU_MASK) >> HOST_INT_STATUS_CPU_LSB) +#define HOST_INT_STATUS_ERROR_GET(x) (((x) & HOST_INT_STATUS_ERROR_MASK) >> HOST_INT_STATUS_ERROR_LSB) +#define HOST_INT_STATUS_COUNTER_GET(x) (((x) & HOST_INT_STATUS_COUNTER_MASK) >> HOST_INT_STATUS_COUNTER_LSB) + + +extern struct hostdef_s *hostdef; + +#endif /* } */ + +#endif /*HOST_REG_TABLE_H_*/ + + diff --git a/drivers/net/wireless/ar6003/host/include/host_version.h b/drivers/net/wireless/ar6003/host/include/host_version.h new file mode 100644 index 000000000000..74f1982c681b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/host_version.h @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains version information for the sample host driver for the +// AR6000 chip +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HOST_VERSION_H_ +#define _HOST_VERSION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * The version number is made up of major, minor, patch and build + * numbers. These are 16 bit numbers. The build and release script will + * set the build number using a Perforce counter. Here the build number is + * set to 9999 so that builds done without the build-release script are easily + * identifiable. + */ + +#define ATH_SW_VER_MAJOR __VER_MAJOR_ +#define ATH_SW_VER_MINOR __VER_MINOR_ +#define ATH_SW_VER_PATCH __VER_PATCH_ +#define ATH_SW_VER_BUILD __BUILD_NUMBER_ + +#ifdef __cplusplus +} +#endif + +#endif /* _HOST_VERSION_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/htc_api.h b/drivers/net/wireless/ar6003/host/include/htc_api.h new file mode 100644 index 000000000000..b007051e0551 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/htc_api.h @@ -0,0 +1,575 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HTC_API_H_ +#define _HTC_API_H_ + +#include "htc_packet.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* TODO.. for BMI */ +#define ENDPOINT1 0 +// TODO -remove me, but we have to fix BMI first +#define HTC_MAILBOX_NUM_MAX 4 + +/* this is the amount of header room required by users of HTC */ +#define HTC_HEADER_LEN HTC_HDR_LENGTH + +typedef void *HTC_HANDLE; + +typedef A_UINT16 HTC_SERVICE_ID; + +typedef struct _HTC_INIT_INFO { + void *pContext; /* context for target failure notification */ + void (*TargetFailure)(void *Instance, A_STATUS Status); +} HTC_INIT_INFO; + +/* per service connection send completion */ +typedef void (*HTC_EP_SEND_PKT_COMPLETE)(void *,HTC_PACKET *); +/* per service connection callback when a plurality of packets have been sent + * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from the callback) + * to hold a list of completed send packets. + * If the handler cannot fully traverse the packet queue before returning, it should + * transfer the items of the queue into the caller's private queue using: + * HTC_PACKET_ENQUEUE() */ +typedef void (*HTC_EP_SEND_PKT_COMP_MULTIPLE)(void *,HTC_PACKET_QUEUE *); +/* per service connection pkt received */ +typedef void (*HTC_EP_RECV_PKT)(void *,HTC_PACKET *); +/* per service connection callback when a plurality of packets are received + * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from the callback) + * to hold a list of recv packets. + * If the handler cannot fully traverse the packet queue before returning, it should + * transfer the items of the queue into the caller's private queue using: + * HTC_PACKET_ENQUEUE() */ +typedef void (*HTC_EP_RECV_PKT_MULTIPLE)(void *,HTC_PACKET_QUEUE *); + +/* Optional per service connection receive buffer re-fill callback, + * On some OSes (like Linux) packets are allocated from a global pool and indicated up + * to the network stack. The driver never gets the packets back from the OS. For these OSes + * a refill callback can be used to allocate and re-queue buffers into HTC. + * + * On other OSes, the network stack can call into the driver's OS-specifc "return_packet" handler and + * the driver can re-queue these buffers into HTC. In this regard a refill callback is + * unnecessary */ +typedef void (*HTC_EP_RECV_REFILL)(void *, HTC_ENDPOINT_ID Endpoint); + +/* Optional per service connection receive buffer allocation callback. + * On some systems packet buffers are an extremely limited resource. Rather than + * queue largest-possible-sized buffers to HTC, some systems would rather + * allocate a specific size as the packet is received. The trade off is + * slightly more processing (callback invoked for each RX packet) + * for the benefit of committing fewer buffer resources into HTC. + * + * The callback is provided the length of the pending packet to fetch. This includes the + * HTC header length plus the length of payload. The callback can return a pointer to + * the allocated HTC packet for immediate use. + * + * Alternatively a variant of this handler can be used to allocate large receive packets as needed. + * For example an application can use the refill mechanism for normal packets and the recv-alloc mechanism to + * handle the case where a large packet buffer is required. This can significantly reduce the + * amount of "committed" memory used to receive packets. + * + * */ +typedef HTC_PACKET *(*HTC_EP_RECV_ALLOC)(void *, HTC_ENDPOINT_ID Endpoint, int Length); + +typedef enum _HTC_SEND_FULL_ACTION { + HTC_SEND_FULL_KEEP = 0, /* packet that overflowed should be kept in the queue */ + HTC_SEND_FULL_DROP = 1, /* packet that overflowed should be dropped */ +} HTC_SEND_FULL_ACTION; + +/* Optional per service connection callback when a send queue is full. This can occur if the + * host continues queueing up TX packets faster than credits can arrive + * To prevent the host (on some Oses like Linux) from continuously queueing packets + * and consuming resources, this callback is provided so that that the host + * can disable TX in the subsystem (i.e. network stack). + * This callback is invoked for each packet that "overflows" the HTC queue. The callback can + * determine whether the new packet that overflowed the queue can be kept (HTC_SEND_FULL_KEEP) or + * dropped (HTC_SEND_FULL_DROP). If a packet is dropped, the EpTxComplete handler will be called + * and the packet's status field will be set to A_NO_RESOURCE. + * Other OSes require a "per-packet" indication for each completed TX packet, this + * closed loop mechanism will prevent the network stack from overunning the NIC + * The packet to keep or drop is passed for inspection to the registered handler the handler + * must ONLY inspect the packet, it may not free or reclaim the packet. */ +typedef HTC_SEND_FULL_ACTION (*HTC_EP_SEND_QUEUE_FULL)(void *, HTC_PACKET *pPacket); + +typedef struct _HTC_EP_CALLBACKS { + void *pContext; /* context for each callback */ + HTC_EP_SEND_PKT_COMPLETE EpTxComplete; /* tx completion callback for connected endpoint */ + HTC_EP_RECV_PKT EpRecv; /* receive callback for connected endpoint */ + HTC_EP_RECV_REFILL EpRecvRefill; /* OPTIONAL receive re-fill callback for connected endpoint */ + HTC_EP_SEND_QUEUE_FULL EpSendFull; /* OPTIONAL send full callback */ + HTC_EP_RECV_ALLOC EpRecvAlloc; /* OPTIONAL recv allocation callback */ + HTC_EP_RECV_ALLOC EpRecvAllocThresh; /* OPTIONAL recv allocation callback based on a threshold */ + HTC_EP_SEND_PKT_COMP_MULTIPLE EpTxCompleteMultiple; /* OPTIONAL completion handler for multiple complete + indications (EpTxComplete must be NULL) */ + HTC_EP_RECV_PKT_MULTIPLE EpRecvPktMultiple; /* OPTIONAL completion handler for multiple + recv packet indications (EpRecv must be NULL) */ + int RecvAllocThreshold; /* if EpRecvAllocThresh is non-NULL, HTC will compare the + threshold value to the current recv packet length and invoke + the EpRecvAllocThresh callback to acquire a packet buffer */ + int RecvRefillWaterMark; /* if a EpRecvRefill handler is provided, this value + can be used to set a trigger refill callback + when the recv queue drops below this value + if set to 0, the refill is only called when packets + are empty */ +} HTC_EP_CALLBACKS; + +/* service connection information */ +typedef struct _HTC_SERVICE_CONNECT_REQ { + HTC_SERVICE_ID ServiceID; /* service ID to connect to */ + A_UINT16 ConnectionFlags; /* connection flags, see htc protocol definition */ + A_UINT8 *pMetaData; /* ptr to optional service-specific meta-data */ + A_UINT8 MetaDataLength; /* optional meta data length */ + HTC_EP_CALLBACKS EpCallbacks; /* endpoint callbacks */ + int MaxSendQueueDepth; /* maximum depth of any send queue */ + A_UINT32 LocalConnectionFlags; /* HTC flags for the host-side (local) connection */ + unsigned int MaxSendMsgSize; /* override max message size in send direction */ +} HTC_SERVICE_CONNECT_REQ; + +#define HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING (1 << 0) /* enable send bundle padding for this endpoint */ + +/* service connection response information */ +typedef struct _HTC_SERVICE_CONNECT_RESP { + A_UINT8 *pMetaData; /* caller supplied buffer to optional meta-data */ + A_UINT8 BufferLength; /* length of caller supplied buffer */ + A_UINT8 ActualLength; /* actual length of meta data */ + HTC_ENDPOINT_ID Endpoint; /* endpoint to communicate over */ + unsigned int MaxMsgLength; /* max length of all messages over this endpoint */ + A_UINT8 ConnectRespCode; /* connect response code from target */ +} HTC_SERVICE_CONNECT_RESP; + +/* endpoint distribution structure */ +typedef struct _HTC_ENDPOINT_CREDIT_DIST { + struct _HTC_ENDPOINT_CREDIT_DIST *pNext; + struct _HTC_ENDPOINT_CREDIT_DIST *pPrev; + HTC_SERVICE_ID ServiceID; /* Service ID (set by HTC) */ + HTC_ENDPOINT_ID Endpoint; /* endpoint for this distribution struct (set by HTC) */ + A_UINT32 DistFlags; /* distribution flags, distribution function can + set default activity using SET_EP_ACTIVE() macro */ + int TxCreditsNorm; /* credits for normal operation, anything above this + indicates the endpoint is over-subscribed, this field + is only relevant to the credit distribution function */ + int TxCreditsMin; /* floor for credit distribution, this field is + only relevant to the credit distribution function */ + int TxCreditsAssigned; /* number of credits assigned to this EP, this field + is only relevant to the credit dist function */ + int TxCredits; /* current credits available, this field is used by + HTC to determine whether a message can be sent or + must be queued */ + int TxCreditsToDist; /* pending credits to distribute on this endpoint, this + is set by HTC when credit reports arrive. + The credit distribution functions sets this to zero + when it distributes the credits */ + int TxCreditsSeek; /* this is the number of credits that the current pending TX + packet needs to transmit. This is set by HTC when + and endpoint needs credits in order to transmit */ + int TxCreditSize; /* size in bytes of each credit (set by HTC) */ + int TxCreditsPerMaxMsg; /* credits required for a maximum sized messages (set by HTC) */ + void *pHTCReserved; /* reserved for HTC use */ + int TxQueueDepth; /* current depth of TX queue , i.e. messages waiting for credits + This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE + or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint + that has non-zero credits to recover + */ +} HTC_ENDPOINT_CREDIT_DIST; + +#define HTC_EP_ACTIVE ((A_UINT32) (1u << 31)) + +/* macro to check if an endpoint has gone active, useful for credit + * distributions */ +#define IS_EP_ACTIVE(epDist) ((epDist)->DistFlags & HTC_EP_ACTIVE) +#define SET_EP_ACTIVE(epDist) (epDist)->DistFlags |= HTC_EP_ACTIVE + + /* credit distibution code that is passed into the distrbution function, + * there are mandatory and optional codes that must be handled */ +typedef enum _HTC_CREDIT_DIST_REASON { + HTC_CREDIT_DIST_SEND_COMPLETE = 0, /* credits available as a result of completed + send operations (MANDATORY) resulting in credit reports */ + HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1, /* a change in endpoint activity occured (OPTIONAL) */ + HTC_CREDIT_DIST_SEEK_CREDITS, /* an endpoint needs to "seek" credits (OPTIONAL) */ + HTC_DUMP_CREDIT_STATE /* for debugging, dump any state information that is kept by + the distribution function */ +} HTC_CREDIT_DIST_REASON; + +typedef void (*HTC_CREDIT_DIST_CALLBACK)(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPList, + HTC_CREDIT_DIST_REASON Reason); + +typedef void (*HTC_CREDIT_INIT_CALLBACK)(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPList, + int TotalCredits); + + /* endpoint statistics action */ +typedef enum _HTC_ENDPOINT_STAT_ACTION { + HTC_EP_STAT_SAMPLE = 0, /* only read statistics */ + HTC_EP_STAT_SAMPLE_AND_CLEAR = 1, /* sample and immediately clear statistics */ + HTC_EP_STAT_CLEAR /* clear only */ +} HTC_ENDPOINT_STAT_ACTION; + + /* endpoint statistics */ +typedef struct _HTC_ENDPOINT_STATS { + A_UINT32 TxCreditLowIndications; /* number of times the host set the credit-low flag in a send message on + this endpoint */ + A_UINT32 TxIssued; /* running count of total TX packets issued */ + A_UINT32 TxPacketsBundled; /* running count of TX packets that were issued in bundles */ + A_UINT32 TxBundles; /* running count of TX bundles that were issued */ + A_UINT32 TxDropped; /* tx packets that were dropped */ + A_UINT32 TxCreditRpts; /* running count of total credit reports received for this endpoint */ + A_UINT32 TxCreditRptsFromRx; /* credit reports received from this endpoint's RX packets */ + A_UINT32 TxCreditRptsFromOther; /* credit reports received from RX packets of other endpoints */ + A_UINT32 TxCreditRptsFromEp0; /* credit reports received from endpoint 0 RX packets */ + A_UINT32 TxCreditsFromRx; /* count of credits received via Rx packets on this endpoint */ + A_UINT32 TxCreditsFromOther; /* count of credits received via another endpoint */ + A_UINT32 TxCreditsFromEp0; /* count of credits received via another endpoint */ + A_UINT32 TxCreditsConsummed; /* count of consummed credits */ + A_UINT32 TxCreditsReturned; /* count of credits returned */ + A_UINT32 RxReceived; /* count of RX packets received */ + A_UINT32 RxLookAheads; /* count of lookahead records + found in messages received on this endpoint */ + A_UINT32 RxPacketsBundled; /* count of recv packets received in a bundle */ + A_UINT32 RxBundleLookAheads; /* count of number of bundled lookaheads */ + A_UINT32 RxBundleIndFromHdr; /* count of the number of bundle indications from the HTC header */ + A_UINT32 RxAllocThreshHit; /* count of the number of times the recv allocation threshhold was hit */ + A_UINT32 RxAllocThreshBytes; /* total number of bytes */ +} HTC_ENDPOINT_STATS; + +/* ------ Function Prototypes ------ */ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Create an instance of HTC over the underlying HIF device + @function name: HTCCreate + @input: HifDevice - hif device handle, + pInfo - initialization information + @output: + @return: HTC_HANDLE on success, NULL on failure + @notes: + @example: + @see also: HTCDestroy ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +HTC_HANDLE HTCCreate(void *HifDevice, HTC_INIT_INFO *pInfo); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Get the underlying HIF device handle + @function name: HTCGetHifDevice + @input: HTCHandle - handle passed into the AddInstance callback + @output: + @return: opaque HIF device handle usable in HIF API calls. + @notes: + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void *HTCGetHifDevice(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Set credit distribution parameters + @function name: HTCSetCreditDistribution + @input: HTCHandle - HTC handle + pCreditDistCont - caller supplied context to pass into distribution functions + CreditDistFunc - Distribution function callback + CreditDistInit - Credit Distribution initialization callback + ServicePriorityOrder - Array containing list of service IDs, lowest index is highest + priority + ListLength - number of elements in ServicePriorityOrder + @output: + @return: + @notes: The user can set a custom credit distribution function to handle special requirements + for each endpoint. A default credit distribution routine can be used by setting + CreditInitFunc to NULL. The default credit distribution is only provided for simple + "fair" credit distribution without regard to any prioritization. + + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCSetCreditDistribution(HTC_HANDLE HTCHandle, + void *pCreditDistContext, + HTC_CREDIT_DIST_CALLBACK CreditDistFunc, + HTC_CREDIT_INIT_CALLBACK CreditInitFunc, + HTC_SERVICE_ID ServicePriorityOrder[], + int ListLength); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Wait for the target to indicate the HTC layer is ready + @function name: HTCWaitTarget + @input: HTCHandle - HTC handle + @output: + @return: + @notes: This API blocks until the target responds with an HTC ready message. + The caller should not connect services until the target has indicated it is + ready. + @example: + @see also: HTCConnectService ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCWaitTarget(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Start target service communications + @function name: HTCStart + @input: HTCHandle - HTC handle + @output: + @return: + @notes: This API indicates to the target that the service connection phase is complete + and the target can freely start all connected services. This API should only be + called AFTER all service connections have been made. TCStart will issue a + SETUP_COMPLETE message to the target to indicate that all service connections + have been made and the target can start communicating over the endpoints. + @example: + @see also: HTCConnectService ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCStart(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Add receive packet to HTC + @function name: HTCAddReceivePkt + @input: HTCHandle - HTC handle + pPacket - HTC receive packet to add + @output: + @return: A_OK on success + @notes: user must supply HTC packets for capturing incomming HTC frames. The caller + must initialize each HTC packet using the SET_HTC_PACKET_INFO_RX_REFILL() + macro. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCAddReceivePkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Connect to an HTC service + @function name: HTCConnectService + @input: HTCHandle - HTC handle + pReq - connection details + @output: pResp - connection response + @return: + @notes: Service connections must be performed before HTCStart. User provides callback handlers + for various endpoint events. + @example: + @see also: HTCStart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCConnectService(HTC_HANDLE HTCHandle, + HTC_SERVICE_CONNECT_REQ *pReq, + HTC_SERVICE_CONNECT_RESP *pResp); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Send an HTC packet + @function name: HTCSendPkt + @input: HTCHandle - HTC handle + pPacket - packet to send + @output: + @return: A_OK + @notes: Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro. + This interface is fully asynchronous. On error, HTC SendPkt will + call the registered Endpoint callback to cleanup the packet. + @example: + @see also: HTCFlushEndpoint ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCSendPkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Stop HTC service communications + @function name: HTCStop + @input: HTCHandle - HTC handle + @output: + @return: + @notes: HTC communications is halted. All receive and pending TX packets will + be flushed. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCStop(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Destory HTC service + @function name: HTCDestroy + @input: HTCHandle + @output: + @return: + @notes: This cleans up all resources allocated by HTCCreate(). + @example: + @see also: HTCCreate ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCDestroy(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Flush pending TX packets + @function name: HTCFlushEndpoint + @input: HTCHandle - HTC handle + Endpoint - Endpoint to flush + Tag - flush tag + @output: + @return: + @notes: The Tag parameter is used to selectively flush packets with matching tags. + The value of 0 forces all packets to be flush regardless of tag. + @example: + @see also: HTCSendPkt ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCFlushEndpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint, HTC_TX_TAG Tag); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Dump credit distribution state + @function name: HTCDumpCreditStates + @input: HTCHandle - HTC handle + @output: + @return: + @notes: This dumps all credit distribution information to the debugger + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCDumpCreditStates(HTC_HANDLE HTCHandle); +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Indicate a traffic activity change on an endpoint + @function name: HTCIndicateActivityChange + @input: HTCHandle - HTC handle + Endpoint - endpoint in which activity has changed + Active - TRUE if active, FALSE if it has become inactive + @output: + @return: + @notes: This triggers the registered credit distribution function to + re-adjust credits for active/inactive endpoints. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCIndicateActivityChange(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint, + A_BOOL Active); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Get endpoint statistics + @function name: HTCGetEndpointStatistics + @input: HTCHandle - HTC handle + Endpoint - Endpoint identifier + Action - action to take with statistics + @output: + pStats - statistics that were sampled (can be NULL if Action is HTC_EP_STAT_CLEAR) + + @return: TRUE if statistics profiling is enabled, otherwise FALSE. + + @notes: Statistics is a compile-time option and this function may return FALSE + if HTC is not compiled with profiling. + + The caller can specify the statistic "action" to take when sampling + the statistics. This includes: + + HTC_EP_STAT_SAMPLE: The pStats structure is filled with the current values. + HTC_EP_STAT_SAMPLE_AND_CLEAR: The structure is filled and the current statistics + are cleared. + HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass a NULL value for + pStats + + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_BOOL HTCGetEndpointStatistics(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint, + HTC_ENDPOINT_STAT_ACTION Action, + HTC_ENDPOINT_STATS *pStats); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Unblock HTC message reception + @function name: HTCUnblockRecv + @input: HTCHandle - HTC handle + @output: + @return: + @notes: + HTC will block the receiver if the EpRecvAlloc callback fails to provide a packet. + The caller can use this API to indicate to HTC when resources (buffers) are available + such that the receiver can be unblocked and HTC may re-attempt fetching the pending message. + + This API is not required if the user uses the EpRecvRefill callback or uses the HTCAddReceivePacket() + API to recycle or provide receive packets to HTC. + + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +void HTCUnblockRecv(HTC_HANDLE HTCHandle); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: send a series of HTC packets + @function name: HTCSendPktsMultiple + @input: HTCHandle - HTC handle + pPktQueue - local queue holding packets to send + @output: + @return: A_OK + @notes: Caller must initialize each packet using SET_HTC_PACKET_INFO_TX() macro. + The queue must only contain packets directed at the same endpoint. + Caller supplies a pointer to an HTC_PACKET_QUEUE structure holding the TX packets in FIFO order. + This API will remove the packets from the pkt queue and place them into the HTC Tx Queue + and bundle messages where possible. + The caller may allocate the pkt queue on the stack to hold the packets. + This interface is fully asynchronous. On error, HTCSendPkts will + call the registered Endpoint callback to cleanup the packet. + @example: + @see also: HTCFlushEndpoint ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCSendPktsMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Add multiple receive packets to HTC + @function name: HTCAddReceivePktMultiple + @input: HTCHandle - HTC handle + pPktQueue - HTC receive packet queue holding packets to add + @output: + @return: A_OK on success + @notes: user must supply HTC packets for capturing incomming HTC frames. The caller + must initialize each HTC packet using the SET_HTC_PACKET_INFO_RX_REFILL() + macro. The queue must only contain recv packets for the same endpoint. + Caller supplies a pointer to an HTC_PACKET_QUEUE structure holding the recv packet. + This API will remove the packets from the pkt queue and place them into internal + recv packet list. + The caller may allocate the pkt queue on the stack to hold the packets. + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_STATUS HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue); + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Check if an endpoint is marked active + @function name: HTCIsEndpointActive + @input: HTCHandle - HTC handle + Endpoint - endpoint to check for active state + @output: + @return: returns TRUE if Endpoint is Active + @notes: + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +A_BOOL HTCIsEndpointActive(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint); + + +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @desc: Get the number of recv buffers currently queued into an HTC endpoint + @function name: HTCGetNumRecvBuffers + @input: HTCHandle - HTC handle + Endpoint - endpoint to check + @output: + @return: returns number of buffers in queue + @notes: + @example: + @see also: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +int HTCGetNumRecvBuffers(HTC_HANDLE HTCHandle, + HTC_ENDPOINT_ID Endpoint); + +/* internally used functions for testing... */ +void HTCEnableRecv(HTC_HANDLE HTCHandle); +void HTCDisableRecv(HTC_HANDLE HTCHandle); +A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle, + A_UINT32 TimeoutInMs, + A_BOOL *pbIsRecvPending); + +#ifdef __cplusplus +} +#endif + +#endif /* _HTC_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/htc_packet.h b/drivers/net/wireless/ar6003/host/include/htc_packet.h new file mode 100644 index 000000000000..15175cff2f28 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/htc_packet.h @@ -0,0 +1,227 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef HTC_PACKET_H_ +#define HTC_PACKET_H_ + + +#include "dl_list.h" + +/* ------ Endpoint IDS ------ */ +typedef enum +{ + ENDPOINT_UNUSED = -1, + ENDPOINT_0 = 0, + ENDPOINT_1 = 1, + ENDPOINT_2 = 2, + ENDPOINT_3, + ENDPOINT_4, + ENDPOINT_5, + ENDPOINT_6, + ENDPOINT_7, + ENDPOINT_8, + ENDPOINT_MAX, +} HTC_ENDPOINT_ID; + +struct _HTC_PACKET; + +typedef void (* HTC_PACKET_COMPLETION)(void *,struct _HTC_PACKET *); + +typedef A_UINT16 HTC_TX_TAG; + +typedef struct _HTC_TX_PACKET_INFO { + HTC_TX_TAG Tag; /* tag used to selective flush packets */ + int CreditsUsed; /* number of credits used for this TX packet (HTC internal) */ + A_UINT8 SendFlags; /* send flags (HTC internal) */ + int SeqNo; /* internal seq no for debugging (HTC internal) */ +} HTC_TX_PACKET_INFO; + +#define HTC_TX_PACKET_TAG_ALL 0 /* a tag of zero is reserved and used to flush ALL packets */ +#define HTC_TX_PACKET_TAG_INTERNAL 1 /* internal tags start here */ +#define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9) /* user-defined tags start here */ + +typedef struct _HTC_RX_PACKET_INFO { + A_UINT32 ExpectedHdr; /* HTC internal use */ + A_UINT32 HTCRxFlags; /* HTC internal use */ + A_UINT32 IndicationFlags; /* indication flags set on each RX packet indication */ +} HTC_RX_PACKET_INFO; + +#define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0) /* more packets on this endpoint are being fetched */ + +/* wrapper around endpoint-specific packets */ +typedef struct _HTC_PACKET { + DL_LIST ListLink; /* double link */ + void *pPktContext; /* caller's per packet specific context */ + + A_UINT8 *pBufferStart; /* the true buffer start , the caller can + store the real buffer start here. In + receive callbacks, the HTC layer sets pBuffer + to the start of the payload past the header. This + field allows the caller to reset pBuffer when it + recycles receive packets back to HTC */ + /* + * Pointer to the start of the buffer. In the transmit + * direction this points to the start of the payload. In the + * receive direction, however, the buffer when queued up + * points to the start of the HTC header but when returned + * to the caller points to the start of the payload + */ + A_UINT8 *pBuffer; /* payload start (RX/TX) */ + A_UINT32 BufferLength; /* length of buffer */ + A_UINT32 ActualLength; /* actual length of payload */ + HTC_ENDPOINT_ID Endpoint; /* endpoint that this packet was sent/recv'd from */ + A_STATUS Status; /* completion status */ + union { + HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */ + HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */ + } PktInfo; + + /* the following fields are for internal HTC use */ + HTC_PACKET_COMPLETION Completion; /* completion */ + void *pContext; /* HTC private completion context */ +} HTC_PACKET; + + + +#define COMPLETE_HTC_PACKET(p,status) \ +{ \ + (p)->Status = (status); \ + (p)->Completion((p)->pContext,(p)); \ +} + +#define INIT_HTC_PACKET_INFO(p,b,len) \ +{ \ + (p)->pBufferStart = (b); \ + (p)->BufferLength = (len); \ +} + +/* macro to set an initial RX packet for refilling HTC */ +#define SET_HTC_PACKET_INFO_RX_REFILL(p,c,b,len,ep) \ +{ \ + (p)->pPktContext = (c); \ + (p)->pBuffer = (b); \ + (p)->pBufferStart = (b); \ + (p)->BufferLength = (len); \ + (p)->Endpoint = (ep); \ +} + +/* fast macro to recycle an RX packet that will be re-queued to HTC */ +#define HTC_PACKET_RESET_RX(p) \ + { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; } + +/* macro to set packet parameters for TX */ +#define SET_HTC_PACKET_INFO_TX(p,c,b,len,ep,tag) \ +{ \ + (p)->pPktContext = (c); \ + (p)->pBuffer = (b); \ + (p)->ActualLength = (len); \ + (p)->Endpoint = (ep); \ + (p)->PktInfo.AsTx.Tag = (tag); \ +} + +/* HTC Packet Queueing Macros */ +typedef struct _HTC_PACKET_QUEUE { + DL_LIST QueueHead; + int Depth; +} HTC_PACKET_QUEUE; + +/* initialize queue */ +#define INIT_HTC_PACKET_QUEUE(pQ) \ +{ \ + DL_LIST_INIT(&(pQ)->QueueHead); \ + (pQ)->Depth = 0; \ +} + +/* enqueue HTC packet to the tail of the queue */ +#define HTC_PACKET_ENQUEUE(pQ,p) \ +{ DL_ListInsertTail(&(pQ)->QueueHead,&(p)->ListLink); \ + (pQ)->Depth++; \ +} + +/* enqueue HTC packet to the tail of the queue */ +#define HTC_PACKET_ENQUEUE_TO_HEAD(pQ,p) \ +{ DL_ListInsertHead(&(pQ)->QueueHead,&(p)->ListLink); \ + (pQ)->Depth++; \ +} +/* test if a queue is empty */ +#define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0) +/* get packet at head without removing it */ +static INLINE HTC_PACKET *HTC_GET_PKT_AT_HEAD(HTC_PACKET_QUEUE *queue) { + if (queue->Depth == 0) { + return NULL; + } + return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)),HTC_PACKET,ListLink); +} +/* remove a packet from a queue, where-ever it is in the queue */ +#define HTC_PACKET_REMOVE(pQ,p) \ +{ \ + DL_ListRemove(&(p)->ListLink); \ + (pQ)->Depth--; \ +} + +/* dequeue an HTC packet from the head of the queue */ +static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE(HTC_PACKET_QUEUE *queue) { + DL_LIST *pItem = DL_ListRemoveItemFromHead(&queue->QueueHead); + if (pItem != NULL) { + queue->Depth--; + return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); + } + return NULL; +} + +/* dequeue an HTC packet from the tail of the queue */ +static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE_TAIL(HTC_PACKET_QUEUE *queue) { + DL_LIST *pItem = DL_ListRemoveItemFromTail(&queue->QueueHead); + if (pItem != NULL) { + queue->Depth--; + return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); + } + return NULL; +} + +#define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth + + +#define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint +#define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag + + /* transfer the packets from one queue to the tail of another queue */ +#define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest,pQSrc) \ +{ \ + DL_ListTransferItemsToTail(&(pQDest)->QueueHead,&(pQSrc)->QueueHead); \ + (pQDest)->Depth += (pQSrc)->Depth; \ + (pQSrc)->Depth = 0; \ +} + + /* fast version to init and add a single packet to a queue */ +#define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ,pP) \ +{ \ + DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead,&(pP)->ListLink) \ + (pQ)->Depth = 1; \ +} + +#define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \ + ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead,(pPTemp), HTC_PACKET, ListLink) + +#define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END + +#endif /*HTC_PACKET_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/p2p_api.h b/drivers/net/wireless/ar6003/host/include/p2p_api.h new file mode 100644 index 000000000000..5b8837023d71 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/p2p_api.h @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains definitions exported by the P2P host module. +// +// Author(s): ="Atheros" +//============================================================================== + +#ifndef _HOST_P2P_API_H_ +#define _HOST_P2P_API_H_ + +#include "utils_api.h" +#include "wmi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define P2P_OUI 0x99a6f50 + +static int __inline +isp2poui(const A_UINT8 *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == (P2P_OUI); +} + +/* API function declarations */ + +void *p2p_init(void *dev); + +struct host_p2p_dev *p2p_get_device(void *p2p_dev_ctx, const A_UINT8 *addr); + +void *p2p_bssinfo_rx(void *p2p_dev_ctx, WMI_BI_FTYPE fType, A_UINT8 *addr, A_UINT16 channel, const A_UINT8 *data, A_UINT32 len); + +void p2p_go_neg_req_rx(void *p2p_dev_ctx, const A_UINT8 *datap, A_UINT8 len); + +void p2p_invite_req_rx(void *p2p_dev_ctx, const A_UINT8 *datap, A_UINT8 len); + +void p2p_prov_disc_req_rx(void *p2p_dev_ctx, const A_UINT8 *datap, A_UINT8 len); +void p2p_prov_disc_resp_rx(void *p2p_dev_ctx, + const A_UINT8 *datap, A_UINT8 len); +void p2p_start_sdpd_event_rx(void *p2p_dev_ctx); +void p2p_sdpd_rx_event_rx(void *p2p_dev_ctx, + const A_UINT8 *datap, A_UINT8 len); +void p2p_free_all_devices(void *ctx); +void p2p_device_free(void *peer_dev); + +A_STATUS p2p_auth_go_neg(void *ctx, + WMI_P2P_GO_NEG_START_CMD *auth_go_neg_param); + +A_STATUS p2p_auth_invite(void *ctx, A_UINT8 *auth_peer); + +A_STATUS p2p_peer_reject(void *ctx, A_UINT8 *peer_addr); + +A_STATUS p2p_go_neg_start(void *ctx, WMI_P2P_GO_NEG_START_CMD *go_neg_param); + +A_STATUS p2p_invite_cmd(void *ctx, WMI_P2P_INVITE_CMD *invite_param); + +A_STATUS p2p_prov_disc_req(void *ctx, A_UINT8 *peer, A_UINT16 wps_method); + +A_STATUS p2p_peer(void *ctx, A_UINT8 *peer, A_UINT8 next); + +A_STATUS p2p_get_device_p2p_buf(void *ctx, A_UINT8 *peer, A_UINT8 **p2p_buf, A_UINT8 *p2p_buf_len); + +A_STATUS wmi_p2p_get_go_params(void *ctx, A_UINT8 *go_dev_addr, + A_UINT16 *oper_freq, A_UINT8 *ssid, A_UINT8 *ssid_len); + +A_STATUS p2p_get_devaddr (void *ctx, A_UINT8 *intf_addr); + +A_STATUS p2p_get_ifaddr (void *ctx, A_UINT8 *dev_addr); + +struct host_p2p_dev *p2p_get_device_intf_addrs(void *ctx, const A_UINT8 *intfaddr); + +void p2p_increment_dev_ref_count(struct host_p2p_dev *dev); + +void p2p_free_all_sd_queries(void *ctx); + +A_STATUS p2p_sd_request(void *ctx, A_UINT8 *peer_addr, A_UINT8 *tlvbuf, + A_UINT8 tlv_buflen, A_UINT32 *qid); + +A_STATUS p2p_sdpd_tx_cmd(void *ctx, WMI_P2P_SDPD_TX_CMD *sdpd_tx_cmd, A_UINT32 *qid); + +A_STATUS p2p_sd_cancel_request(void *ctx, A_UINT32 qid); + +void p2p_go_neg_complete_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len); + +int p2p_get_peer_info(void *ctx, A_UINT8 *peer_addr, A_UINT8 *buf, A_UINT32 buflen); + +int p2p_get_next_addr(void *ctx, A_UINT8 *addr, A_UINT8 *buf, A_UINT32 buflen, int first_element); + +void p2p_clear_peers_reported_flag(void *ctx); + +void p2p_clear_peers_authorized_flag(void *ctx, const A_UINT8 *addr); + +#ifdef __cplusplus +} +#endif + +#endif /* _HOST_P2P_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/project.h b/drivers/net/wireless/ar6003/host/include/project.h new file mode 100644 index 000000000000..43378ded9e53 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/project.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008 Atheros Communications Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef _PROJECT_H_ +#define _PROJECT_H_ +#include "queue.h" + +#define OS_TIMER_FUNC(fn) void fn(A_HANDLE hdl, void *context) +#define OS_TIMER_FUNC_PTR(fn) void (* fn)(A_HANDLE hdl, void *context) +#define OS_CANCEL_TIMER(timer_hdl) A_UNTIMEOUT(timer_hdl) +#define OS_SET_TIMER(timer_hdl, period, repeat) A_TIMEOUT_MS(timer_hdl, period, repeat) +#define OS_INIT_TIMER(timer_hdl, fn, arg) A_INIT_TIMER(timer_hdl, fn, arg) + +typedef A_TIMER os_timer_t; + +/* Memory related */ +#define OS_MEMZERO(ptr, size) A_MEMZERO(ptr, size) +#define OS_MEMCPY(dst, src, len) A_MEMCPY(dst, src, len) +#define OS_MALLOC(nbytes) A_MALLOC(nbytes) +#define OS_FREE(ptr) A_FREE(ptr) + +#endif + + diff --git a/drivers/net/wireless/ar6003/host/include/target_reg_table.h b/drivers/net/wireless/ar6003/host/include/target_reg_table.h new file mode 100644 index 000000000000..55caa43b84f4 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/target_reg_table.h @@ -0,0 +1,349 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Target register table macros and structure definitions +// +// Author(s): ="Atheros" +//============================================================================== + +#ifndef TARGET_REG_TABLE_H_ +#define TARGET_REG_TABLE_H_ + +#include "targaddrs.h" +/*** WARNING : Add to the end of the TABLE! do not change the order ****/ +typedef struct targetdef_s { + A_UINT32 d_RTC_SOC_BASE_ADDRESS; + A_UINT32 d_RTC_WMAC_BASE_ADDRESS; + A_UINT32 d_SYSTEM_SLEEP_OFFSET; + A_UINT32 d_WLAN_SYSTEM_SLEEP_OFFSET; + A_UINT32 d_WLAN_SYSTEM_SLEEP_DISABLE_LSB; + A_UINT32 d_WLAN_SYSTEM_SLEEP_DISABLE_MASK; + A_UINT32 d_CLOCK_CONTROL_OFFSET; + A_UINT32 d_CLOCK_CONTROL_SI0_CLK_MASK; + A_UINT32 d_RESET_CONTROL_OFFSET; + A_UINT32 d_RESET_CONTROL_MBOX_RST_MASK; + A_UINT32 d_RESET_CONTROL_SI0_RST_MASK; + A_UINT32 d_WLAN_RESET_CONTROL_OFFSET; + A_UINT32 d_WLAN_RESET_CONTROL_COLD_RST_MASK; + A_UINT32 d_WLAN_RESET_CONTROL_WARM_RST_MASK; + A_UINT32 d_GPIO_BASE_ADDRESS; + A_UINT32 d_GPIO_PIN0_OFFSET; + A_UINT32 d_GPIO_PIN1_OFFSET; + A_UINT32 d_GPIO_PIN0_CONFIG_MASK; + A_UINT32 d_GPIO_PIN1_CONFIG_MASK; + A_UINT32 d_SI_CONFIG_BIDIR_OD_DATA_LSB; + A_UINT32 d_SI_CONFIG_BIDIR_OD_DATA_MASK; + A_UINT32 d_SI_CONFIG_I2C_LSB; + A_UINT32 d_SI_CONFIG_I2C_MASK; + A_UINT32 d_SI_CONFIG_POS_SAMPLE_LSB; + A_UINT32 d_SI_CONFIG_POS_SAMPLE_MASK; + A_UINT32 d_SI_CONFIG_INACTIVE_CLK_LSB; + A_UINT32 d_SI_CONFIG_INACTIVE_CLK_MASK; + A_UINT32 d_SI_CONFIG_INACTIVE_DATA_LSB; + A_UINT32 d_SI_CONFIG_INACTIVE_DATA_MASK; + A_UINT32 d_SI_CONFIG_DIVIDER_LSB; + A_UINT32 d_SI_CONFIG_DIVIDER_MASK; + A_UINT32 d_SI_BASE_ADDRESS; + A_UINT32 d_SI_CONFIG_OFFSET; + A_UINT32 d_SI_TX_DATA0_OFFSET; + A_UINT32 d_SI_TX_DATA1_OFFSET; + A_UINT32 d_SI_RX_DATA0_OFFSET; + A_UINT32 d_SI_RX_DATA1_OFFSET; + A_UINT32 d_SI_CS_OFFSET; + A_UINT32 d_SI_CS_DONE_ERR_MASK; + A_UINT32 d_SI_CS_DONE_INT_MASK; + A_UINT32 d_SI_CS_START_LSB; + A_UINT32 d_SI_CS_START_MASK; + A_UINT32 d_SI_CS_RX_CNT_LSB; + A_UINT32 d_SI_CS_RX_CNT_MASK; + A_UINT32 d_SI_CS_TX_CNT_LSB; + A_UINT32 d_SI_CS_TX_CNT_MASK; + A_UINT32 d_BOARD_DATA_SZ; + A_UINT32 d_BOARD_EXT_DATA_SZ; + A_UINT32 d_MBOX_BASE_ADDRESS; + A_UINT32 d_LOCAL_SCRATCH_OFFSET; + A_UINT32 d_CPU_CLOCK_OFFSET; + A_UINT32 d_LPO_CAL_OFFSET; + A_UINT32 d_GPIO_PIN10_OFFSET; + A_UINT32 d_GPIO_PIN11_OFFSET; + A_UINT32 d_GPIO_PIN12_OFFSET; + A_UINT32 d_GPIO_PIN13_OFFSET; + A_UINT32 d_CLOCK_GPIO_OFFSET; + A_UINT32 d_CPU_CLOCK_STANDARD_LSB; + A_UINT32 d_CPU_CLOCK_STANDARD_MASK; + A_UINT32 d_LPO_CAL_ENABLE_LSB; + A_UINT32 d_LPO_CAL_ENABLE_MASK; + A_UINT32 d_CLOCK_GPIO_BT_CLK_OUT_EN_LSB; + A_UINT32 d_CLOCK_GPIO_BT_CLK_OUT_EN_MASK; + A_UINT32 d_ANALOG_INTF_BASE_ADDRESS; +} TARGET_REGISTER_TABLE; + +#define ATH_UNSUPPORTED_REG_OFFSET 0xffffffff +#define ATH_SUPPORTED_BY_TARGET(reg_offset) ((reg_offset) != ATH_UNSUPPORTED_REG_OFFSET) + +#define BOARD_DATA_SZ_MAX 2048 + +#if defined(MY_TARGET_DEF) /* { */ +#if defined(ATHR_WIN_DEF) +#define ATH_REG_TABLE_DIRECT_ASSIGN +#endif + +/* Cross-platform compatibility */ +#if !defined(SOC_RESET_CONTROL_OFFSET) && defined(RESET_CONTROL_OFFSET) +#define SOC_RESET_CONTROL_OFFSET RESET_CONTROL_OFFSET +#endif +#if !defined(CLOCK_GPIO_OFFSET) +#define CLOCK_GPIO_OFFSET ATH_UNSUPPORTED_REG_OFFSET +#define CLOCK_GPIO_BT_CLK_OUT_EN_LSB 0 +#define CLOCK_GPIO_BT_CLK_OUT_EN_MASK 0 +#endif + +#ifdef ATH_REG_TABLE_DIRECT_ASSIGN + +static struct targetdef_s my_target_def = { + RTC_SOC_BASE_ADDRESS, + RTC_WMAC_BASE_ADDRESS, + SYSTEM_SLEEP_OFFSET, + WLAN_SYSTEM_SLEEP_OFFSET, + WLAN_SYSTEM_SLEEP_DISABLE_LSB, + WLAN_SYSTEM_SLEEP_DISABLE_MASK, + CLOCK_CONTROL_OFFSET, + CLOCK_CONTROL_SI0_CLK_MASK, + SOC_RESET_CONTROL_OFFSET, + RESET_CONTROL_MBOX_RST_MASK, + RESET_CONTROL_SI0_RST_MASK, + WLAN_RESET_CONTROL_OFFSET, + WLAN_RESET_CONTROL_COLD_RST_MASK, + WLAN_RESET_CONTROL_WARM_RST_MASK, + GPIO_BASE_ADDRESS, + GPIO_PIN0_OFFSET, + GPIO_PIN1_OFFSET, + GPIO_PIN0_CONFIG_MASK, + GPIO_PIN1_CONFIG_MASK, + SI_CONFIG_BIDIR_OD_DATA_LSB, + SI_CONFIG_BIDIR_OD_DATA_MASK, + SI_CONFIG_I2C_LSB, + SI_CONFIG_I2C_MASK, + SI_CONFIG_POS_SAMPLE_LSB, + SI_CONFIG_POS_SAMPLE_MASK, + SI_CONFIG_INACTIVE_CLK_LSB, + SI_CONFIG_INACTIVE_CLK_MASK, + SI_CONFIG_INACTIVE_DATA_LSB, + SI_CONFIG_INACTIVE_DATA_MASK, + SI_CONFIG_DIVIDER_LSB, + SI_CONFIG_DIVIDER_MASK, + SI_BASE_ADDRESS, + SI_CONFIG_OFFSET, + SI_TX_DATA0_OFFSET, + SI_TX_DATA1_OFFSET, + SI_RX_DATA0_OFFSET, + SI_RX_DATA1_OFFSET, + SI_CS_OFFSET, + SI_CS_DONE_ERR_MASK, + SI_CS_DONE_INT_MASK, + SI_CS_START_LSB, + SI_CS_START_MASK, + SI_CS_RX_CNT_LSB, + SI_CS_RX_CNT_MASK, + SI_CS_TX_CNT_LSB, + SI_CS_TX_CNT_MASK, + MY_TARGET_BOARD_DATA_SZ, + MY_TARGET_BOARD_EXT_DATA_SZ, + MBOX_BASE_ADDRESS, + LOCAL_SCRATCH_OFFSET, + CPU_CLOCK_OFFSET, + LPO_CAL_OFFSET, + GPIO_PIN10_OFFSET, + GPIO_PIN11_OFFSET, + GPIO_PIN12_OFFSET, + GPIO_PIN13_OFFSET, + CLOCK_GPIO_OFFSET, + CPU_CLOCK_STANDARD_LSB, + CPU_CLOCK_STANDARD_MASK, + LPO_CAL_ENABLE_LSB, + LPO_CAL_ENABLE_MASK, + CLOCK_GPIO_BT_CLK_OUT_EN_LSB, + CLOCK_GPIO_BT_CLK_OUT_EN_MASK, + ANALOG_INTF_BASE_ADDRESS, +}; + +#else + +static struct targetdef_s my_target_def = { + .d_RTC_SOC_BASE_ADDRESS = RTC_SOC_BASE_ADDRESS, + .d_RTC_WMAC_BASE_ADDRESS = RTC_WMAC_BASE_ADDRESS, + .d_SYSTEM_SLEEP_OFFSET = WLAN_SYSTEM_SLEEP_OFFSET, + .d_WLAN_SYSTEM_SLEEP_OFFSET = WLAN_SYSTEM_SLEEP_OFFSET, + .d_WLAN_SYSTEM_SLEEP_DISABLE_LSB = WLAN_SYSTEM_SLEEP_DISABLE_LSB, + .d_WLAN_SYSTEM_SLEEP_DISABLE_MASK = WLAN_SYSTEM_SLEEP_DISABLE_MASK, + .d_CLOCK_CONTROL_OFFSET = CLOCK_CONTROL_OFFSET, + .d_CLOCK_CONTROL_SI0_CLK_MASK = CLOCK_CONTROL_SI0_CLK_MASK, + .d_RESET_CONTROL_OFFSET = SOC_RESET_CONTROL_OFFSET, + .d_RESET_CONTROL_MBOX_RST_MASK = RESET_CONTROL_MBOX_RST_MASK, + .d_RESET_CONTROL_SI0_RST_MASK = RESET_CONTROL_SI0_RST_MASK, + .d_WLAN_RESET_CONTROL_OFFSET = WLAN_RESET_CONTROL_OFFSET, + .d_WLAN_RESET_CONTROL_COLD_RST_MASK = WLAN_RESET_CONTROL_COLD_RST_MASK, + .d_WLAN_RESET_CONTROL_WARM_RST_MASK = WLAN_RESET_CONTROL_WARM_RST_MASK, + .d_GPIO_BASE_ADDRESS = GPIO_BASE_ADDRESS, + .d_GPIO_PIN0_OFFSET = GPIO_PIN0_OFFSET, + .d_GPIO_PIN1_OFFSET = GPIO_PIN1_OFFSET, + .d_GPIO_PIN0_CONFIG_MASK = GPIO_PIN0_CONFIG_MASK, + .d_GPIO_PIN1_CONFIG_MASK = GPIO_PIN1_CONFIG_MASK, + .d_SI_CONFIG_BIDIR_OD_DATA_LSB = SI_CONFIG_BIDIR_OD_DATA_LSB, + .d_SI_CONFIG_BIDIR_OD_DATA_MASK = SI_CONFIG_BIDIR_OD_DATA_MASK, + .d_SI_CONFIG_I2C_LSB = SI_CONFIG_I2C_LSB, + .d_SI_CONFIG_I2C_MASK = SI_CONFIG_I2C_MASK, + .d_SI_CONFIG_POS_SAMPLE_LSB = SI_CONFIG_POS_SAMPLE_LSB, + .d_SI_CONFIG_POS_SAMPLE_MASK = SI_CONFIG_POS_SAMPLE_MASK, + .d_SI_CONFIG_INACTIVE_CLK_LSB = SI_CONFIG_INACTIVE_CLK_LSB, + .d_SI_CONFIG_INACTIVE_CLK_MASK = SI_CONFIG_INACTIVE_CLK_MASK, + .d_SI_CONFIG_INACTIVE_DATA_LSB = SI_CONFIG_INACTIVE_DATA_LSB, + .d_SI_CONFIG_INACTIVE_DATA_MASK = SI_CONFIG_INACTIVE_DATA_MASK, + .d_SI_CONFIG_DIVIDER_LSB = SI_CONFIG_DIVIDER_LSB, + .d_SI_CONFIG_DIVIDER_MASK = SI_CONFIG_DIVIDER_MASK, + .d_SI_BASE_ADDRESS = SI_BASE_ADDRESS, + .d_SI_CONFIG_OFFSET = SI_CONFIG_OFFSET, + .d_SI_TX_DATA0_OFFSET = SI_TX_DATA0_OFFSET, + .d_SI_TX_DATA1_OFFSET = SI_TX_DATA1_OFFSET, + .d_SI_RX_DATA0_OFFSET = SI_RX_DATA0_OFFSET, + .d_SI_RX_DATA1_OFFSET = SI_RX_DATA1_OFFSET, + .d_SI_CS_OFFSET = SI_CS_OFFSET, + .d_SI_CS_DONE_ERR_MASK = SI_CS_DONE_ERR_MASK, + .d_SI_CS_DONE_INT_MASK = SI_CS_DONE_INT_MASK, + .d_SI_CS_START_LSB = SI_CS_START_LSB, + .d_SI_CS_START_MASK = SI_CS_START_MASK, + .d_SI_CS_RX_CNT_LSB = SI_CS_RX_CNT_LSB, + .d_SI_CS_RX_CNT_MASK = SI_CS_RX_CNT_MASK, + .d_SI_CS_TX_CNT_LSB = SI_CS_TX_CNT_LSB, + .d_SI_CS_TX_CNT_MASK = SI_CS_TX_CNT_MASK, + .d_BOARD_DATA_SZ = MY_TARGET_BOARD_DATA_SZ, + .d_BOARD_EXT_DATA_SZ = MY_TARGET_BOARD_EXT_DATA_SZ, + .d_MBOX_BASE_ADDRESS = MBOX_BASE_ADDRESS, + .d_LOCAL_SCRATCH_OFFSET = LOCAL_SCRATCH_OFFSET, + .d_CPU_CLOCK_OFFSET = CPU_CLOCK_OFFSET, + .d_LPO_CAL_OFFSET = LPO_CAL_OFFSET, + .d_GPIO_PIN10_OFFSET = GPIO_PIN10_OFFSET, + .d_GPIO_PIN11_OFFSET = GPIO_PIN11_OFFSET, + .d_GPIO_PIN12_OFFSET = GPIO_PIN12_OFFSET, + .d_GPIO_PIN13_OFFSET = GPIO_PIN13_OFFSET, + .d_CLOCK_GPIO_OFFSET = CLOCK_GPIO_OFFSET, + .d_CPU_CLOCK_STANDARD_LSB = CPU_CLOCK_STANDARD_LSB, + .d_CPU_CLOCK_STANDARD_MASK = CPU_CLOCK_STANDARD_MASK, + .d_LPO_CAL_ENABLE_LSB = LPO_CAL_ENABLE_LSB, + .d_LPO_CAL_ENABLE_MASK = LPO_CAL_ENABLE_MASK, + .d_CLOCK_GPIO_BT_CLK_OUT_EN_LSB = CLOCK_GPIO_BT_CLK_OUT_EN_LSB, + .d_CLOCK_GPIO_BT_CLK_OUT_EN_MASK = CLOCK_GPIO_BT_CLK_OUT_EN_MASK, + .d_ANALOG_INTF_BASE_ADDRESS = ANALOG_INTF_BASE_ADDRESS, +}; + +#endif + +#if MY_TARGET_BOARD_DATA_SZ > BOARD_DATA_SZ_MAX +#error "BOARD_DATA_SZ_MAX is too small" +#endif + +struct targetdef_s *MY_TARGET_DEF = &my_target_def; + +#else /* } { */ + +#define RTC_SOC_BASE_ADDRESS (targetdef->d_RTC_SOC_BASE_ADDRESS) +#define RTC_WMAC_BASE_ADDRESS (targetdef->d_RTC_WMAC_BASE_ADDRESS) +#define SYSTEM_SLEEP_OFFSET (targetdef->d_SYSTEM_SLEEP_OFFSET) +#define WLAN_SYSTEM_SLEEP_OFFSET (targetdef->d_WLAN_SYSTEM_SLEEP_OFFSET) +#define WLAN_SYSTEM_SLEEP_DISABLE_LSB (targetdef->d_WLAN_SYSTEM_SLEEP_DISABLE_LSB) +#define WLAN_SYSTEM_SLEEP_DISABLE_MASK (targetdef->d_WLAN_SYSTEM_SLEEP_DISABLE_MASK) +#define CLOCK_CONTROL_OFFSET (targetdef->d_CLOCK_CONTROL_OFFSET) +#define CLOCK_CONTROL_SI0_CLK_MASK (targetdef->d_CLOCK_CONTROL_SI0_CLK_MASK) +#define RESET_CONTROL_OFFSET (targetdef->d_RESET_CONTROL_OFFSET) +#define RESET_CONTROL_MBOX_RST_MASK (targetdef->d_RESET_CONTROL_MBOX_RST_MASK) +#define RESET_CONTROL_SI0_RST_MASK (targetdef->d_RESET_CONTROL_SI0_RST_MASK) +#define WLAN_RESET_CONTROL_OFFSET (targetdef->d_WLAN_RESET_CONTROL_OFFSET) +#define WLAN_RESET_CONTROL_COLD_RST_MASK (targetdef->d_WLAN_RESET_CONTROL_COLD_RST_MASK) +#define WLAN_RESET_CONTROL_WARM_RST_MASK (targetdef->d_WLAN_RESET_CONTROL_WARM_RST_MASK) +#define GPIO_BASE_ADDRESS (targetdef->d_GPIO_BASE_ADDRESS) +#define GPIO_PIN0_OFFSET (targetdef->d_GPIO_PIN0_OFFSET) +#define GPIO_PIN1_OFFSET (targetdef->d_GPIO_PIN1_OFFSET) +#define GPIO_PIN0_CONFIG_MASK (targetdef->d_GPIO_PIN0_CONFIG_MASK) +#define GPIO_PIN1_CONFIG_MASK (targetdef->d_GPIO_PIN1_CONFIG_MASK) +#define SI_CONFIG_BIDIR_OD_DATA_LSB (targetdef->d_SI_CONFIG_BIDIR_OD_DATA_LSB) +#define SI_CONFIG_BIDIR_OD_DATA_MASK (targetdef->d_SI_CONFIG_BIDIR_OD_DATA_MASK) +#define SI_CONFIG_I2C_LSB (targetdef->d_SI_CONFIG_I2C_LSB) +#define SI_CONFIG_I2C_MASK (targetdef->d_SI_CONFIG_I2C_MASK) +#define SI_CONFIG_POS_SAMPLE_LSB (targetdef->d_SI_CONFIG_POS_SAMPLE_LSB) +#define SI_CONFIG_POS_SAMPLE_MASK (targetdef->d_SI_CONFIG_POS_SAMPLE_MASK) +#define SI_CONFIG_INACTIVE_CLK_LSB (targetdef->d_SI_CONFIG_INACTIVE_CLK_LSB) +#define SI_CONFIG_INACTIVE_CLK_MASK (targetdef->d_SI_CONFIG_INACTIVE_CLK_MASK) +#define SI_CONFIG_INACTIVE_DATA_LSB (targetdef->d_SI_CONFIG_INACTIVE_DATA_LSB) +#define SI_CONFIG_INACTIVE_DATA_MASK (targetdef->d_SI_CONFIG_INACTIVE_DATA_MASK) +#define SI_CONFIG_DIVIDER_LSB (targetdef->d_SI_CONFIG_DIVIDER_LSB) +#define SI_CONFIG_DIVIDER_MASK (targetdef->d_SI_CONFIG_DIVIDER_MASK) +#define SI_BASE_ADDRESS (targetdef->d_SI_BASE_ADDRESS) +#define SI_CONFIG_OFFSET (targetdef->d_SI_CONFIG_OFFSET) +#define SI_TX_DATA0_OFFSET (targetdef->d_SI_TX_DATA0_OFFSET) +#define SI_TX_DATA1_OFFSET (targetdef->d_SI_TX_DATA1_OFFSET) +#define SI_RX_DATA0_OFFSET (targetdef->d_SI_RX_DATA0_OFFSET) +#define SI_RX_DATA1_OFFSET (targetdef->d_SI_RX_DATA1_OFFSET) +#define SI_CS_OFFSET (targetdef->d_SI_CS_OFFSET) +#define SI_CS_DONE_ERR_MASK (targetdef->d_SI_CS_DONE_ERR_MASK) +#define SI_CS_DONE_INT_MASK (targetdef->d_SI_CS_DONE_INT_MASK) +#define SI_CS_START_LSB (targetdef->d_SI_CS_START_LSB) +#define SI_CS_START_MASK (targetdef->d_SI_CS_START_MASK) +#define SI_CS_RX_CNT_LSB (targetdef->d_SI_CS_RX_CNT_LSB) +#define SI_CS_RX_CNT_MASK (targetdef->d_SI_CS_RX_CNT_MASK) +#define SI_CS_TX_CNT_LSB (targetdef->d_SI_CS_TX_CNT_LSB) +#define SI_CS_TX_CNT_MASK (targetdef->d_SI_CS_TX_CNT_MASK) +#define EEPROM_SZ (targetdef->d_BOARD_DATA_SZ) +#define EEPROM_EXT_SZ (targetdef->d_BOARD_EXT_DATA_SZ) +#define MBOX_BASE_ADDRESS (targetdef->d_MBOX_BASE_ADDRESS) +#define LOCAL_SCRATCH_OFFSET (targetdef->d_LOCAL_SCRATCH_OFFSET) +#define CPU_CLOCK_OFFSET (targetdef->d_CPU_CLOCK_OFFSET) +#define LPO_CAL_OFFSET (targetdef->d_LPO_CAL_OFFSET) +#define GPIO_PIN10_OFFSET (targetdef->d_GPIO_PIN10_OFFSET) +#define GPIO_PIN11_OFFSET (targetdef->d_GPIO_PIN11_OFFSET) +#define GPIO_PIN12_OFFSET (targetdef->d_GPIO_PIN12_OFFSET) +#define GPIO_PIN13_OFFSET (targetdef->d_GPIO_PIN13_OFFSET) +#define CLOCK_GPIO_OFFSET (targetdef->d_CLOCK_GPIO_OFFSET) +#define CPU_CLOCK_STANDARD_LSB (targetdef->d_CPU_CLOCK_STANDARD_LSB) +#define CPU_CLOCK_STANDARD_MASK (targetdef->d_CPU_CLOCK_STANDARD_MASK) +#define LPO_CAL_ENABLE_LSB (targetdef->d_LPO_CAL_ENABLE_LSB) +#define LPO_CAL_ENABLE_MASK (targetdef->d_LPO_CAL_ENABLE_MASK) +#define CLOCK_GPIO_BT_CLK_OUT_EN_LSB (targetdef->d_CLOCK_GPIO_BT_CLK_OUT_EN_LSB) +#define CLOCK_GPIO_BT_CLK_OUT_EN_MASK (targetdef->d_CLOCK_GPIO_BT_CLK_OUT_EN_MASK) +#define ANALOG_INTF_BASE_ADDRESS (targetdef->d_ANALOG_INTF_BASE_ADDRESS) + +/* SET macros */ +#define WLAN_SYSTEM_SLEEP_DISABLE_SET(x) (((x) << WLAN_SYSTEM_SLEEP_DISABLE_LSB) & WLAN_SYSTEM_SLEEP_DISABLE_MASK) +#define SI_CONFIG_BIDIR_OD_DATA_SET(x) (((x) << SI_CONFIG_BIDIR_OD_DATA_LSB) & SI_CONFIG_BIDIR_OD_DATA_MASK) +#define SI_CONFIG_I2C_SET(x) (((x) << SI_CONFIG_I2C_LSB) & SI_CONFIG_I2C_MASK) +#define SI_CONFIG_POS_SAMPLE_SET(x) (((x) << SI_CONFIG_POS_SAMPLE_LSB) & SI_CONFIG_POS_SAMPLE_MASK) +#define SI_CONFIG_INACTIVE_CLK_SET(x) (((x) << SI_CONFIG_INACTIVE_CLK_LSB) & SI_CONFIG_INACTIVE_CLK_MASK) +#define SI_CONFIG_INACTIVE_DATA_SET(x) (((x) << SI_CONFIG_INACTIVE_DATA_LSB) & SI_CONFIG_INACTIVE_DATA_MASK) +#define SI_CONFIG_DIVIDER_SET(x) (((x) << SI_CONFIG_DIVIDER_LSB) & SI_CONFIG_DIVIDER_MASK) +#define SI_CS_START_SET(x) (((x) << SI_CS_START_LSB) & SI_CS_START_MASK) +#define SI_CS_RX_CNT_SET(x) (((x) << SI_CS_RX_CNT_LSB) & SI_CS_RX_CNT_MASK) +#define SI_CS_TX_CNT_SET(x) (((x) << SI_CS_TX_CNT_LSB) & SI_CS_TX_CNT_MASK) +#define LPO_CAL_ENABLE_SET(x) (((x) << LPO_CAL_ENABLE_LSB) & LPO_CAL_ENABLE_MASK) +#define CPU_CLOCK_STANDARD_SET(x) (((x) << CPU_CLOCK_STANDARD_LSB) & CPU_CLOCK_STANDARD_MASK) +#define CLOCK_GPIO_BT_CLK_OUT_EN_SET(x) (((x) << CLOCK_GPIO_BT_CLK_OUT_EN_LSB) & CLOCK_GPIO_BT_CLK_OUT_EN_MASK) +extern struct targetdef_s *targetdef; + +#endif /* } */ + +#endif /*TARGET_REG_TABLE_H_*/ diff --git a/drivers/net/wireless/ar6003/host/include/utils_api.h b/drivers/net/wireless/ar6003/host/include/utils_api.h new file mode 100644 index 000000000000..d3aad4ea9e64 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/utils_api.h @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Utility Macros & Functions common across OS. +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HOST_UTILS_API_H_ +#define _HOST_UTILS_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* unaligned little endian access */ +#define LE_READ_2(p) \ + ((A_UINT16) \ + ((((A_UINT8 *)(p))[0] ) | (((A_UINT8 *)(p))[1] << 8))) + +#define LE_READ_4(p) \ + ((A_UINT32) \ + ((((A_UINT8 *)(p))[0] ) | (((A_UINT8 *)(p))[1] << 8) | \ + (((A_UINT8 *)(p))[2] << 16) | (((A_UINT8 *)(p))[3] << 24))) + +#define WPA_GET_BE16(a) ((A_UINT16) (((a)[0] << 8) | (a)[1])) +#define WPA_PUT_BE16(a, val) \ + do { \ + (a)[0] = ((A_UINT16) (val)) >> 8; \ + (a)[1] = ((A_UINT16) (val)) & 0xff; \ + } while (0) + +#define WPA_GET_LE16(a) ((A_UINT16) (((a)[1] << 8) | (a)[0])) +#define WPA_PUT_LE16(a, val) \ + do { \ + (a)[1] = ((A_UINT16) (val)) >> 8; \ + (a)[0] = ((A_UINT16) (val)) & 0xff; \ + } while (0) + +#define WPA_GET_BE24(a) ((((A_UINT32) (a)[0]) << 16) | (((A_UINT32) (a)[1]) << 8) | \ + ((A_UINT32) (a)[2])) +#define WPA_PUT_BE24(a, val) \ + do { \ + (a)[0] = (A_UINT8) ((((A_UINT32) (val)) >> 16) & 0xff); \ + (a)[1] = (A_UINT8) ((((A_UINT32) (val)) >> 8) & 0xff); \ + (a)[2] = (A_UINT8) (((A_UINT32) (val)) & 0xff); \ + } while (0) + +#define WPA_GET_BE32(a) ((((A_UINT32) (a)[0]) << 24) | (((A_UINT32) (a)[1]) << 16) | \ + (((A_UINT32) (a)[2]) << 8) | ((A_UINT32) (a)[3])) +#define WPA_PUT_BE32(a, val) \ + do { \ + (a)[0] = (A_UINT8) ((((A_UINT32) (val)) >> 24) & 0xff); \ + (a)[1] = (A_UINT8) ((((A_UINT32) (val)) >> 16) & 0xff); \ + (a)[2] = (A_UINT8) ((((A_UINT32) (val)) >> 8) & 0xff); \ + (a)[3] = (A_UINT8) (((A_UINT32) (val)) & 0xff); \ + } while (0) + +#define WPA_GET_LE32(a) ((((A_UINT32) (a)[3]) << 24) | (((A_UINT32) (a)[2]) << 16) | \ + (((A_UINT32) (a)[1]) << 8) | ((A_UINT32) (a)[0])) +#define WPA_PUT_LE32(a, val) \ + do { \ + (a)[3] = (A_UINT8) ((((A_UINT32) (val)) >> 24) & 0xff); \ + (a)[2] = (A_UINT8) ((((A_UINT32) (val)) >> 16) & 0xff); \ + (a)[1] = (A_UINT8) ((((A_UINT32) (val)) >> 8) & 0xff); \ + (a)[0] = (A_UINT8) (((A_UINT32) (val)) & 0xff); \ + } while (0) + + +#define WPA_OUI 0xf25000 + +static int __inline +iswscoui(const A_UINT8 *frm) +{ + return frm[1] > 3 && LE_READ_4(frm+2) == ((0x04<<24)|WPA_OUI); +} + +static inline int is_zero_mac_addr(const A_UINT8 *addr) +{ + return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); +} + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _HOST_UTILS_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/wlan_api.h b/drivers/net/wireless/ar6003/host/include/wlan_api.h new file mode 100644 index 000000000000..5a53d18da5ff --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/wlan_api.h @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the API for the host wlan module +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HOST_WLAN_API_H_ +#define _HOST_WLAN_API_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct ieee80211_node_table; +struct ieee80211_frame; + +struct ieee80211_common_ie { + A_UINT16 ie_chan; + A_UINT8 *ie_tstamp; + A_UINT8 *ie_ssid; + A_UINT8 *ie_rates; + A_UINT8 *ie_xrates; + A_UINT8 *ie_country; + A_UINT8 *ie_wpa; + A_UINT8 *ie_rsn; + A_UINT8 *ie_wmm; + A_UINT8 *ie_ath; + A_UINT16 ie_capInfo; + A_UINT16 ie_beaconInt; + A_UINT8 *ie_tim; + A_UINT8 *ie_chswitch; + A_UINT8 ie_erp; + A_UINT8 *ie_wsc; + A_UINT8 *ie_htcap; + A_UINT8 *ie_htop; +#ifdef WAPI_ENABLE + A_UINT8 *ie_wapi; +#endif + + +}; + +typedef struct bss { + A_UINT8 ni_macaddr[6]; + A_UINT8 ni_snr; + A_INT16 ni_rssi; + struct bss *ni_list_next; + struct bss *ni_list_prev; + struct bss *ni_hash_next; + struct bss *ni_hash_prev; + struct ieee80211_common_ie ni_cie; +#ifdef P2P + void *p2p_dev; +#endif /* P2P */ + A_UINT8 *ni_buf; + A_UINT16 ni_framelen; + A_UINT8 ni_frametype; /* frame type in ni_buf */ + struct ieee80211_node_table *ni_table; + A_UINT32 ni_refcnt; + int ni_scangen; + + A_UINT32 ni_tstamp; + A_UINT32 ni_actcnt; +#ifdef OS_ROAM_MANAGEMENT + A_UINT32 ni_si_gen; +#endif +} bss_t; + +typedef void wlan_node_iter_func(void *arg, bss_t *); + +bss_t *wlan_node_alloc(struct ieee80211_node_table *nt, int wh_size); +void wlan_node_free(bss_t *ni); +void wlan_setup_node(struct ieee80211_node_table *nt, bss_t *ni, + const A_UINT8 *macaddr); +bss_t *wlan_find_node(struct ieee80211_node_table *nt, const A_UINT8 *macaddr); +void wlan_node_reclaim(struct ieee80211_node_table *nt, bss_t *ni); +A_STATUS wlan_node_buf_update(struct ieee80211_node_table *nt, bss_t *ni, A_UINT32 len); +void wlan_free_allnodes(struct ieee80211_node_table *nt); +void wlan_iterate_nodes(struct ieee80211_node_table *nt, wlan_node_iter_func *f, + void *arg); + +void wlan_node_table_init(void *wmip, struct ieee80211_node_table *nt); +void wlan_node_table_reset(struct ieee80211_node_table *nt); +void wlan_node_table_cleanup(struct ieee80211_node_table *nt); + +A_STATUS wlan_parse_beacon(A_UINT8 *buf, int framelen, + struct ieee80211_common_ie *cie); + +A_UINT16 wlan_ieee2freq(int chan); +A_UINT32 wlan_freq2ieee(A_UINT16 freq); + +void wlan_set_nodeage(struct ieee80211_node_table *nt, A_UINT32 nodeAge); + +void +wlan_refresh_inactive_nodes (struct ieee80211_node_table *nt); + +bss_t * +wlan_find_Ssidnode (struct ieee80211_node_table *nt, A_UCHAR *pSsid, + A_UINT32 ssidLength, A_BOOL bIsWPA2, A_BOOL bMatchSSID); + +void +wlan_node_return (struct ieee80211_node_table *nt, bss_t *ni); + +bss_t *wlan_node_remove(struct ieee80211_node_table *nt, A_UINT8 *bssid); + +bss_t * +wlan_find_matching_Ssidnode (struct ieee80211_node_table *nt, A_UCHAR *pSsid, + A_UINT32 ssidLength, A_UINT32 dot11AuthMode, A_UINT32 authMode, + A_UINT32 pairwiseCryptoType, A_UINT32 grpwiseCryptoTyp); + +void wlan_node_update_timestamp(struct ieee80211_node_table *nt, bss_t *ni); + +#ifdef __cplusplus +} +#endif + +#endif /* _HOST_WLAN_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/include/wmi_api.h b/drivers/net/wireless/ar6003/host/include/wmi_api.h new file mode 100644 index 000000000000..c992fd4fa1b7 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/include/wmi_api.h @@ -0,0 +1,565 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the definitions for the Wireless Module Interface (WMI). +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _WMI_API_H_ +#define _WMI_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + /* WMI converts a dix frame with an ethernet payload (up to 1500 bytes) + * to an 802.3 frame (adds SNAP header) and adds on a WMI data header */ +#define WMI_MAX_TX_DATA_FRAME_LENGTH (1500 + sizeof(WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) + sizeof(ATH_LLC_SNAP_HDR)) + + /* A normal WMI data frame */ +#define WMI_MAX_NORMAL_RX_DATA_FRAME_LENGTH (1500 + sizeof(WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) + sizeof(ATH_LLC_SNAP_HDR)) + + /* An AMSDU frame */ /* The MAX AMSDU length of AR6003 is 3839 */ +#define WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH (3840 + sizeof(WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) + sizeof(ATH_LLC_SNAP_HDR)) + +/* + * IP QoS Field definitions according to 802.1p + */ +#define BEST_EFFORT_PRI 0 +#define BACKGROUND_PRI 1 +#define EXCELLENT_EFFORT_PRI 3 +#define CONTROLLED_LOAD_PRI 4 +#define VIDEO_PRI 5 +#define VOICE_PRI 6 +#define NETWORK_CONTROL_PRI 7 +#define MAX_NUM_PRI 8 + +#define UNDEFINED_PRI (0xff) + +#define WMI_IMPLICIT_PSTREAM_INACTIVITY_INT 5000 /* 5 seconds */ + +#define A_ROUND_UP(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) + +typedef enum { + ATHEROS_COMPLIANCE = 0x1, +}TSPEC_PARAM_COMPLIANCE; + +struct wmi_t; + +void *wmi_init(void *devt, int devid); + +void wmi_qos_state_init(struct wmi_t *wmip); +void wmi_shutdown(struct wmi_t *wmip); +HTC_ENDPOINT_ID wmi_get_control_ep(struct wmi_t * wmip); +void wmi_set_control_ep(struct wmi_t * wmip, HTC_ENDPOINT_ID eid); +A_UINT16 wmi_get_mapped_qos_queue(struct wmi_t *, A_UINT8); +A_STATUS wmi_dix_2_dot3(struct wmi_t *wmip, void *osbuf); +A_STATUS wmi_data_hdr_add(struct wmi_t *wmip, void *osbuf, A_UINT8 msgType, A_UINT32 flags , WMI_DATA_HDR_DATA_TYPE data_type,A_UINT8 metaVersion, void *pTxMetaS); +A_STATUS wmi_dot3_2_dix(void *osbuf); + +A_STATUS wmi_dot11_hdr_remove (struct wmi_t *wmip, void *osbuf); +A_STATUS wmi_dot11_hdr_add(struct wmi_t *wmip, void *osbuf, NETWORK_TYPE mode); + +A_STATUS wmi_data_hdr_remove(struct wmi_t *wmip, void *osbuf); +A_STATUS wmi_syncpoint(struct wmi_t *wmip); +A_STATUS wmi_syncpoint_reset(struct wmi_t *wmip); +A_UINT8 wmi_implicit_create_pstream(struct wmi_t *wmip, void *osbuf, A_UINT32 layer2Priority, A_BOOL wmmEnabled); + +A_UINT8 wmi_determine_userPriority (A_UINT8 *pkt, A_UINT32 layer2Pri); + +A_STATUS wmi_control_rx(struct wmi_t *wmip, void *osbuf); +void wmi_iterate_nodes(struct wmi_t *wmip, wlan_node_iter_func *f, void *arg); +void wmi_free_allnodes(struct wmi_t *wmip); +bss_t *wmi_find_node(struct wmi_t *wmip, const A_UINT8 *macaddr); +void wmi_free_node(struct wmi_t *wmip, const A_UINT8 *macaddr); + + +typedef enum { + NO_SYNC_WMIFLAG = 0, + SYNC_BEFORE_WMIFLAG, /* transmit all queued data before cmd */ + SYNC_AFTER_WMIFLAG, /* any new data waits until cmd execs */ + SYNC_BOTH_WMIFLAG, + END_WMIFLAG /* end marker */ +} WMI_SYNC_FLAG; + +A_STATUS wmi_cmd_send(struct wmi_t *wmip, void *osbuf, WMI_COMMAND_ID cmdId, + WMI_SYNC_FLAG flag); + +A_STATUS wmi_connect_cmd(struct wmi_t *wmip, + NETWORK_TYPE netType, + DOT11_AUTH_MODE dot11AuthMode, + AUTH_MODE authMode, + CRYPTO_TYPE pairwiseCrypto, + A_UINT8 pairwiseCryptoLen, + CRYPTO_TYPE groupCrypto, + A_UINT8 groupCryptoLen, + int ssidLength, + A_UCHAR *ssid, + A_UINT8 *bssid, + A_UINT16 channel, + A_UINT32 ctrl_flags); + +A_STATUS wmi_set_div_param_cmd(struct wmi_t *wmip, A_UINT32 divIdleTime, + A_UINT8 antRssiThresh, A_UINT8 divEnable, A_UINT16 active_treshold_rate); + + +A_STATUS wmi_reconnect_cmd(struct wmi_t *wmip, + A_UINT8 *bssid, + A_UINT16 channel); +A_STATUS wmi_disconnect_cmd(struct wmi_t *wmip); +A_STATUS wmi_getrev_cmd(struct wmi_t *wmip); +A_STATUS wmi_startscan_cmd(struct wmi_t *wmip, WMI_SCAN_TYPE scanType, + A_BOOL forceFgScan, A_BOOL isLegacy, + A_UINT32 homeDwellTime, A_UINT32 forceScanInterval, + A_INT8 numChan, A_UINT16 *channelList); +A_STATUS wmi_scanparams_cmd(struct wmi_t *wmip, A_UINT16 fg_start_sec, + A_UINT16 fg_end_sec, A_UINT16 bg_sec, + A_UINT16 minact_chdw_msec, + A_UINT16 maxact_chdw_msec, A_UINT16 pas_chdw_msec, + A_UINT8 shScanRatio, A_UINT8 scanCtrlFlags, + A_UINT32 max_dfsch_act_time, + A_UINT16 maxact_scan_per_ssid); +A_STATUS wmi_bssfilter_cmd(struct wmi_t *wmip, A_UINT8 filter, A_UINT32 ieMask); +A_STATUS wmi_probedSsid_cmd(struct wmi_t *wmip, A_UINT8 index, A_UINT8 flag, + A_UINT8 ssidLength, A_UCHAR *ssid); +A_STATUS wmi_listeninterval_cmd(struct wmi_t *wmip, A_UINT16 listenInterval, A_UINT16 listenBeacons); +A_STATUS wmi_bmisstime_cmd(struct wmi_t *wmip, A_UINT16 bmisstime, A_UINT16 bmissbeacons); +A_STATUS wmi_associnfo_cmd(struct wmi_t *wmip, A_UINT8 ieType, + A_UINT8 ieLen, A_UINT8 *ieInfo); +A_STATUS wmi_powermode_cmd(struct wmi_t *wmip, A_UINT8 powerMode); +A_STATUS wmi_ibsspmcaps_cmd(struct wmi_t *wmip, A_UINT8 pmEnable, A_UINT8 ttl, + A_UINT16 atim_windows, A_UINT16 timeout_value); +A_STATUS wmi_apps_cmd(struct wmi_t *wmip, A_UINT8 psType, A_UINT32 idle_time, + A_UINT32 ps_period, A_UINT8 sleep_period); +A_STATUS wmi_pmparams_cmd(struct wmi_t *wmip, A_UINT16 idlePeriod, + A_UINT16 psPollNum, A_UINT16 dtimPolicy, + A_UINT16 wakup_tx_policy, A_UINT16 num_tx_to_wakeup, + A_UINT16 ps_fail_event_policy); +A_STATUS wmi_disctimeout_cmd(struct wmi_t *wmip, A_UINT8 timeout); +A_STATUS wmi_sync_cmd(struct wmi_t *wmip, A_UINT8 syncNumber); +A_STATUS wmi_create_pstream_cmd(struct wmi_t *wmip, WMI_CREATE_PSTREAM_CMD *pstream); +A_STATUS wmi_delete_pstream_cmd(struct wmi_t *wmip, A_UINT8 trafficClass, A_UINT8 streamID); +A_STATUS wmi_set_framerate_cmd(struct wmi_t *wmip, A_UINT8 bEnable, A_UINT8 type, A_UINT8 subType, A_UINT16 rateMask); +A_STATUS wmi_set_bitrate_cmd(struct wmi_t *wmip, A_INT32 dataRate, A_INT32 mgmtRate, A_INT32 ctlRate); +A_STATUS wmi_get_bitrate_cmd(struct wmi_t *wmip); +A_INT8 wmi_validate_bitrate(struct wmi_t *wmip, A_INT32 rate, A_INT8 *rate_idx); +A_STATUS wmi_get_regDomain_cmd(struct wmi_t *wmip); +A_STATUS wmi_get_channelList_cmd(struct wmi_t *wmip); +A_STATUS wmi_set_channelParams_cmd(struct wmi_t *wmip, A_UINT8 scanParam, + WMI_PHY_MODE mode, A_INT8 numChan, + A_UINT16 *channelList); + +A_STATUS wmi_set_snr_threshold_params(struct wmi_t *wmip, + WMI_SNR_THRESHOLD_PARAMS_CMD *snrCmd); +A_STATUS wmi_set_rssi_threshold_params(struct wmi_t *wmip, + WMI_RSSI_THRESHOLD_PARAMS_CMD *rssiCmd); +A_STATUS wmi_clr_rssi_snr(struct wmi_t *wmip); +A_STATUS wmi_set_lq_threshold_params(struct wmi_t *wmip, + WMI_LQ_THRESHOLD_PARAMS_CMD *lqCmd); +A_STATUS wmi_set_rts_cmd(struct wmi_t *wmip, A_UINT16 threshold); +A_STATUS wmi_set_lpreamble_cmd(struct wmi_t *wmip, A_UINT8 status, A_UINT8 preamblePolicy); + +A_STATUS wmi_set_error_report_bitmask(struct wmi_t *wmip, A_UINT32 bitmask); + +A_STATUS wmi_get_challenge_resp_cmd(struct wmi_t *wmip, A_UINT32 cookie, + A_UINT32 source); + +A_STATUS wmi_config_debug_module_cmd(struct wmi_t *wmip, A_UINT16 mmask, + A_UINT16 tsr, A_BOOL rep, A_UINT16 size, + A_UINT32 valid); + +A_STATUS wmi_get_stats_cmd(struct wmi_t *wmip); + +A_STATUS wmi_addKey_cmd(struct wmi_t *wmip, A_UINT8 keyIndex, + CRYPTO_TYPE keyType, A_UINT8 keyUsage, + A_UINT8 keyLength,A_UINT8 *keyRSC, + A_UINT8 *keyMaterial, A_UINT8 key_op_ctrl, A_UINT8 *mac, + WMI_SYNC_FLAG sync_flag); +A_STATUS wmi_add_krk_cmd(struct wmi_t *wmip, A_UINT8 *krk); +A_STATUS wmi_delete_krk_cmd(struct wmi_t *wmip); +A_STATUS wmi_deleteKey_cmd(struct wmi_t *wmip, A_UINT8 keyIndex); +A_STATUS wmi_set_akmp_params_cmd(struct wmi_t *wmip, + WMI_SET_AKMP_PARAMS_CMD *akmpParams); +A_STATUS wmi_get_pmkid_list_cmd(struct wmi_t *wmip); +A_STATUS wmi_set_pmkid_list_cmd(struct wmi_t *wmip, + WMI_SET_PMKID_LIST_CMD *pmkInfo); +A_STATUS wmi_abort_scan_cmd(struct wmi_t *wmip); +A_STATUS wmi_set_txPwr_cmd(struct wmi_t *wmip, A_UINT8 dbM); +A_STATUS wmi_get_txPwr_cmd(struct wmi_t *wmip); +A_STATUS wmi_addBadAp_cmd(struct wmi_t *wmip, A_UINT8 apIndex, A_UINT8 *bssid); +A_STATUS wmi_deleteBadAp_cmd(struct wmi_t *wmip, A_UINT8 apIndex); +A_STATUS wmi_set_tkip_countermeasures_cmd(struct wmi_t *wmip, A_BOOL en); +A_STATUS wmi_setPmkid_cmd(struct wmi_t *wmip, A_UINT8 *bssid, A_UINT8 *pmkId, + A_BOOL set); +A_STATUS wmi_set_access_params_cmd(struct wmi_t *wmip, A_UINT8 ac, A_UINT16 txop, + A_UINT8 eCWmin, A_UINT8 eCWmax, + A_UINT8 aifsn); +A_STATUS wmi_set_retry_limits_cmd(struct wmi_t *wmip, A_UINT8 frameType, + A_UINT8 trafficClass, A_UINT8 maxRetries, + A_UINT8 enableNotify); + +void wmi_get_current_bssid(struct wmi_t *wmip, A_UINT8 *bssid); + +A_STATUS wmi_get_roam_tbl_cmd(struct wmi_t *wmip); +A_STATUS wmi_get_roam_data_cmd(struct wmi_t *wmip, A_UINT8 roamDataType); +A_STATUS wmi_set_roam_ctrl_cmd(struct wmi_t *wmip, WMI_SET_ROAM_CTRL_CMD *p, + A_UINT8 size); +A_STATUS wmi_set_powersave_timers_cmd(struct wmi_t *wmip, + WMI_POWERSAVE_TIMERS_POLICY_CMD *pCmd, + A_UINT8 size); + +A_STATUS wmi_set_opt_mode_cmd(struct wmi_t *wmip, A_UINT8 optMode); +A_STATUS wmi_opt_tx_frame_cmd(struct wmi_t *wmip, + A_UINT8 frmType, + A_UINT8 *dstMacAddr, + A_UINT8 *bssid, + A_UINT16 optIEDataLen, + A_UINT8 *optIEData); + +A_STATUS wmi_set_adhoc_bconIntvl_cmd(struct wmi_t *wmip, A_UINT16 intvl); +A_STATUS wmi_set_voice_pkt_size_cmd(struct wmi_t *wmip, A_UINT16 voicePktSize); +A_STATUS wmi_set_max_sp_len_cmd(struct wmi_t *wmip, A_UINT8 maxSpLen); +A_UINT8 convert_userPriority_to_trafficClass(A_UINT8 userPriority); +A_UINT8 wmi_get_power_mode_cmd(struct wmi_t *wmip); +A_STATUS wmi_verify_tspec_params(WMI_CREATE_PSTREAM_CMD *pCmd, A_BOOL tspecCompliance); + +#ifdef CONFIG_HOST_TCMD_SUPPORT +A_STATUS wmi_test_cmd(struct wmi_t *wmip, A_UINT8 *buf, A_UINT32 len); +#endif + +A_STATUS wmi_set_bt_status_cmd(struct wmi_t *wmip, A_UINT8 streamType, A_UINT8 status); +A_STATUS wmi_set_bt_params_cmd(struct wmi_t *wmip, WMI_SET_BT_PARAMS_CMD* cmd); + +A_STATUS wmi_set_btcoex_fe_ant_cmd(struct wmi_t *wmip, WMI_SET_BTCOEX_FE_ANT_CMD * cmd); + +A_STATUS wmi_set_btcoex_colocated_bt_dev_cmd(struct wmi_t *wmip, + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD * cmd); + +A_STATUS wmi_set_btcoex_btinquiry_page_config_cmd(struct wmi_t *wmip, + WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD *cmd); + +A_STATUS wmi_set_btcoex_sco_config_cmd(struct wmi_t *wmip, + WMI_SET_BTCOEX_SCO_CONFIG_CMD * cmd); + +A_STATUS wmi_set_btcoex_a2dp_config_cmd(struct wmi_t *wmip, + WMI_SET_BTCOEX_A2DP_CONFIG_CMD* cmd); + + +A_STATUS wmi_set_btcoex_aclcoex_config_cmd(struct wmi_t *wmip, WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD* cmd); + +A_STATUS wmi_set_btcoex_debug_cmd(struct wmi_t *wmip, WMI_SET_BTCOEX_DEBUG_CMD * cmd); + +A_STATUS wmi_set_btcoex_bt_operating_status_cmd(struct wmi_t * wmip, + WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD * cmd); + +A_STATUS wmi_get_btcoex_config_cmd(struct wmi_t * wmip, WMI_GET_BTCOEX_CONFIG_CMD * cmd); + +A_STATUS wmi_get_btcoex_stats_cmd(struct wmi_t * wmip); + +A_STATUS wmi_SGI_cmd(struct wmi_t *wmip, A_UINT32 *sgiMask, A_UINT8 sgiPERThreshold); + +/* + * This function is used to configure the fix rates mask to the target. + */ +A_STATUS wmi_set_fixrates_cmd(struct wmi_t *wmip, A_UINT32 *fixRatesMask); +A_STATUS wmi_get_ratemask_cmd(struct wmi_t *wmip); + +A_STATUS wmi_set_authmode_cmd(struct wmi_t *wmip, A_UINT8 mode); + +A_STATUS wmi_set_reassocmode_cmd(struct wmi_t *wmip, A_UINT8 mode); + +A_STATUS wmi_set_qos_supp_cmd(struct wmi_t *wmip,A_UINT8 status); +A_STATUS wmi_set_wmm_cmd(struct wmi_t *wmip, WMI_WMM_STATUS status); +A_STATUS wmi_set_wmm_txop(struct wmi_t *wmip, WMI_TXOP_CFG txEnable); +A_STATUS wmi_set_country(struct wmi_t *wmip, A_UCHAR *countryCode); + +A_STATUS wmi_get_keepalive_configured(struct wmi_t *wmip); +A_UINT8 wmi_get_keepalive_cmd(struct wmi_t *wmip); +A_STATUS wmi_set_keepalive_cmd(struct wmi_t *wmip, A_UINT8 keepaliveInterval); + +A_STATUS wmi_set_appie_cmd(struct wmi_t *wmip, A_UINT8 mgmtFrmType, + A_UINT8 ieLen,A_UINT8 *ieInfo); + +A_STATUS wmi_set_halparam_cmd(struct wmi_t *wmip, A_UINT8 *cmd, A_UINT16 dataLen); + +A_INT32 wmi_get_rate(A_INT8 rateindex); + +A_STATUS wmi_set_ip_cmd(struct wmi_t *wmip, WMI_SET_IP_CMD *cmd); + +/*Wake on Wireless WMI commands*/ +A_STATUS wmi_set_host_sleep_mode_cmd(struct wmi_t *wmip, WMI_SET_HOST_SLEEP_MODE_CMD *cmd); +A_STATUS wmi_set_wow_mode_cmd(struct wmi_t *wmip, WMI_SET_WOW_MODE_CMD *cmd); +A_STATUS wmi_get_wow_list_cmd(struct wmi_t *wmip, WMI_GET_WOW_LIST_CMD *cmd); +A_STATUS wmi_add_wow_pattern_cmd(struct wmi_t *wmip, + WMI_ADD_WOW_PATTERN_CMD *cmd, A_UINT8* pattern, A_UINT8* mask, A_UINT8 pattern_size); +A_STATUS wmi_del_wow_pattern_cmd(struct wmi_t *wmip, + WMI_DEL_WOW_PATTERN_CMD *cmd); +A_STATUS wmi_set_wsc_status_cmd(struct wmi_t *wmip, A_UINT32 status); + +A_STATUS +wmi_set_params_cmd(struct wmi_t *wmip, A_UINT32 opcode, A_UINT32 length, A_CHAR* buffer); + +A_STATUS +wmi_set_mcast_filter_cmd(struct wmi_t *wmip, A_UINT8 *filter); + +A_STATUS +wmi_del_mcast_filter_cmd(struct wmi_t *wmip, A_UINT8 *filter); + +A_STATUS +wmi_mcast_filter_cmd(struct wmi_t *wmip, A_UINT8 enable); + +bss_t * +wmi_find_Ssidnode (struct wmi_t *wmip, A_UCHAR *pSsid, + A_UINT32 ssidLength, A_BOOL bIsWPA2, A_BOOL bMatchSSID); + + +void +wmi_node_return (struct wmi_t *wmip, bss_t *bss); + +void +wmi_node_update_timestamp(struct wmi_t *wmip, bss_t *bss); + +void wmi_setup_node(struct wmi_t *wmip, bss_t *bss, const A_UINT8 *bssid); + +bss_t *wmi_node_alloc(struct wmi_t *wmip, A_UINT8 len); + +void +wmi_set_nodeage(struct wmi_t *wmip, A_UINT32 nodeAge); + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +A_STATUS wmi_prof_cfg_cmd(struct wmi_t *wmip, A_UINT32 period, A_UINT32 nbins); +A_STATUS wmi_prof_addr_set_cmd(struct wmi_t *wmip, A_UINT32 addr); +A_STATUS wmi_prof_start_cmd(struct wmi_t *wmip); +A_STATUS wmi_prof_stop_cmd(struct wmi_t *wmip); +A_STATUS wmi_prof_count_get_cmd(struct wmi_t *wmip); +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ +#ifdef OS_ROAM_MANAGEMENT +void wmi_scan_indication (struct wmi_t *wmip); +#endif + +A_STATUS +wmi_set_target_event_report_cmd(struct wmi_t *wmip, WMI_SET_TARGET_EVENT_REPORT_CMD* cmd); + +bss_t *wmi_rm_current_bss (struct wmi_t *wmip, A_UINT8 *id); +A_STATUS wmi_add_current_bss (struct wmi_t *wmip, A_UINT8 *id, bss_t *bss); + + +/* + * AP mode + */ +A_STATUS +wmi_ap_profile_commit(struct wmi_t *wmip, WMI_CONNECT_CMD *p); + +A_STATUS +wmi_ap_set_hidden_ssid(struct wmi_t *wmip, A_UINT8 hidden_ssid); + +A_STATUS +wmi_ap_set_num_sta(struct wmi_t *wmip, A_UINT8 num_sta); + +A_STATUS +wmi_ap_set_dfs(struct wmi_t *wmip, A_UINT8 enable); + +A_STATUS +wmi_ap_set_acl_policy(struct wmi_t *wmip, A_UINT8 policy); + +A_STATUS +wmi_ap_acl_mac_list(struct wmi_t *wmip, WMI_AP_ACL_MAC_CMD *a); + +A_UINT8 +acl_add_del_mac(WMI_AP_ACL *a, WMI_AP_ACL_MAC_CMD *acl); + +A_STATUS +wmi_ap_set_mlme(struct wmi_t *wmip, A_UINT8 cmd, A_UINT8 *mac, A_UINT16 reason); + +A_STATUS +wmi_set_pvb_cmd(struct wmi_t *wmip, A_UINT16 aid, A_BOOL flag); + +A_STATUS +wmi_ap_conn_inact_time(struct wmi_t *wmip, A_UINT32 period); + +A_STATUS +wmi_ap_bgscan_time(struct wmi_t *wmip, A_UINT32 period, A_UINT32 dwell); + +A_STATUS +wmi_ap_set_dtim(struct wmi_t *wmip, A_UINT8 dtim); + +A_STATUS +wmi_ap_set_rateset(struct wmi_t *wmip, A_UINT8 rateset); + +A_STATUS +wmi_set_ht_cap_cmd(struct wmi_t *wmip, WMI_SET_HT_CAP_CMD *cmd); + +A_STATUS +wmi_get_ht_cap_cmd(struct wmi_t *wmip, WMI_SET_HT_CAP_CMD *cmd); + +A_STATUS +wmi_set_ht_op_cmd(struct wmi_t *wmip, A_UINT8 sta_chan_width); + +A_STATUS +wmi_send_hci_cmd(struct wmi_t *wmip, A_UINT8 *buf, A_UINT16 sz); + +A_STATUS +wmi_set_tx_select_rates_cmd(struct wmi_t *wmip, A_UINT32 *pMaskArray); + +A_STATUS +wmi_setup_aggr_cmd(struct wmi_t *wmip, A_UINT8 tid); + +A_STATUS +wmi_delete_aggr_cmd(struct wmi_t *wmip, A_UINT8 tid, A_BOOL uplink); + +A_STATUS +wmi_allow_aggr_cmd(struct wmi_t *wmip, A_UINT16 tx_tidmask, A_UINT16 rx_tidmask); + +A_STATUS +wmi_set_rx_frame_format_cmd(struct wmi_t *wmip, A_UINT8 rxMetaVersion, A_BOOL rxDot11Hdr, A_BOOL defragOnHost); + +A_STATUS +wmi_set_thin_mode_cmd(struct wmi_t *wmip, A_BOOL bThinMode); + +A_STATUS +wmi_set_wlan_conn_precedence_cmd(struct wmi_t *wmip, BT_WLAN_CONN_PRECEDENCE precedence); + +A_STATUS +wmi_set_pmk_cmd(struct wmi_t *wmip, A_UINT8 *pmk); + +A_STATUS +wmi_set_passphrase_cmd(struct wmi_t *wmip, WMI_SET_PASSPHRASE_CMD *cmd); + +A_STATUS +wmi_set_excess_tx_retry_thres_cmd(struct wmi_t *wmip, WMI_SET_EXCESS_TX_RETRY_THRES_CMD *cmd); + +A_STATUS +wmi_assoc_req_enable_cmd(struct wmi_t *wmip, A_UINT8 enable); + +A_STATUS +wmi_assoc_req_report_cmd (struct wmi_t *wmip, A_UINT8 host_accept, A_UINT8 host_reaspncode, A_UINT8 target_status, A_UINT8 *sta_mac_addr, A_UINT8 rspType); + +#ifdef P2P +A_STATUS +wmi_p2p_discover(struct wmi_t *wmip, WMI_P2P_FIND_CMD *find_param); + +A_STATUS +wmi_p2p_stop_find(struct wmi_t *wmip); + +A_STATUS +wmi_p2p_cancel(struct wmi_t *wmip); + +A_STATUS +wmi_p2p_listen(struct wmi_t *wmip, A_UINT32 timeout); + +A_STATUS +wmi_p2p_go_neg_start(struct wmi_t *wmip, WMI_P2P_GO_NEG_START_CMD *go_param); + +A_STATUS wmi_p2p_sdpd_tx_cmd(struct wmi_t *wmip, WMI_P2P_SDPD_TX_CMD *buf); + +A_STATUS wmi_p2p_stop_sdpd(struct wmi_t *wmip); + +A_STATUS wmi_p2p_go_neg_rsp_cmd(struct wmi_t *wmip, A_UINT8 status, + A_UINT8 go_intent, A_UINT32 wps_method, A_UINT16 listen_freq, + A_UINT8 *wpsbuf, A_UINT32 wpslen, A_UINT8 *p2pbuf, A_UINT32 p2plen, + A_UINT8 dialog_token, A_UINT8 persistent_grp); + +A_STATUS +wmi_p2p_set_config(struct wmi_t *wmip, WMI_P2P_SET_CONFIG_CMD *config); + +A_STATUS +wmi_wps_set_config(struct wmi_t *wmip, WMI_WPS_SET_CONFIG_CMD *wps_config); + +A_STATUS wmi_p2p_grp_init_cmd(struct wmi_t *wmip, WMI_P2P_GRP_INIT_CMD *buf); + +A_STATUS wmi_p2p_grp_done_cmd(struct wmi_t *wmip, + WMI_P2P_GRP_FORMATION_DONE_CMD *buf); + +A_STATUS wmi_p2p_invite_cmd(struct wmi_t *wmip, WMI_P2P_INVITE_CMD *buf); + +A_STATUS wmi_p2p_invite_req_rsp_cmd(struct wmi_t *wmip, A_UINT8 status, + A_INT8 is_go, A_UINT8 *grp_bssid, A_UINT8 *p2pbuf, + A_UINT8 p2plen, A_UINT8 dialog_token); + +A_STATUS wmi_p2p_prov_disc_cmd(struct wmi_t *wmip, + WMI_P2P_PROV_DISC_REQ_CMD *buf); + +A_STATUS wmi_p2p_set_cmd(struct wmi_t *wmip, WMI_P2P_SET_CMD *buf); + +#endif /* P2P */ + +A_UINT16 +wmi_ieee2freq (int chan); + +A_UINT32 +wmi_freq2ieee (A_UINT16 freq); + +bss_t * +wmi_find_matching_Ssidnode (struct wmi_t *wmip, A_UCHAR *pSsid, + A_UINT32 ssidLength, + A_UINT32 dot11AuthMode, A_UINT32 authMode, + A_UINT32 pairwiseCryptoType, A_UINT32 grpwiseCryptoTyp); + +A_STATUS +wmi_radarDetected_cmd(struct wmi_t *wmip, A_INT16 chan_index, A_INT8 bang_radar); + +A_STATUS +wmi_set_dfs_maxpulsedur_cmd(struct wmi_t *wmip, A_UINT32 value); + +A_STATUS +wmi_set_dfs_minrssithresh_cmd(struct wmi_t *wmip, A_INT32 rssi); + +A_STATUS +wmi_beacon2bssnode (struct wmi_t *wmip, A_UINT8 *datap, int len, A_UINT8 *bssid, A_UINT16 channel); + +A_STATUS +wmi_set_tx_mac_rules_cmd (struct wmi_t *wmip, A_UINT32 rules); + +A_STATUS +wmi_set_promiscuous_mode_cmd (struct wmi_t *wmip, A_BOOL bMode); + +//WAC +A_STATUS wmi_wac_enable_cmd(struct wmi_t *wmip, WMI_WAC_ENABLE_CMD *param); + +A_STATUS +wmi_wac_scan_reply_cmd(struct wmi_t *wmip, WAC_SUBCMD param); + +A_STATUS +wmi_wac_ctrl_req_cmd(struct wmi_t *wmip, WMI_WAC_CTRL_REQ_CMD *param); + +#ifdef CONFIG_WLAN_RFKILL +A_STATUS +wmi_get_rfkill_mode_cmd(struct wmi_t *wmip); + +A_STATUS +wmi_set_rfkill_mode_cmd(struct wmi_t *wmip,WMI_RFKILL_MODE_CMD *pCmd); + +#endif + +A_STATUS +wmi_force_target_assert(struct wmi_t *wmip); + +A_STATUS +wmi_ap_set_apsd(struct wmi_t *wmip, A_UINT8 enable); + +A_STATUS +wmi_set_apsd_buffered_traffic_cmd(struct wmi_t *wmip, A_UINT16 aid, A_UINT16 bitmap, A_UINT32 flags); + + +#ifdef __cplusplus +} +#endif + +#endif /* _WMI_API_H_ */ diff --git a/drivers/net/wireless/ar6003/host/lib/wac/Makefile b/drivers/net/wireless/ar6003/host/lib/wac/Makefile new file mode 100644 index 000000000000..22979973c956 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/lib/wac/Makefile @@ -0,0 +1,46 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +CC := $(ATH_CROSS_COMPILE_TYPE)gcc +KERNEL_SRC :=$(ATH_LINUXPATH) + +ifndef CFLAGS +#CFLAGS = -MMD -O2 -Wall -g +CFLAGS = -Wall +endif + +CFLAGS += -DCONFIG_CTRL_IFACE_UNIX -DCONFIG_CTRL_IFACE -DWAPI_ENABLE + +all: + $(CC) $(CFLAGS) -I./ -I$(KERNEL_SRC)/include -I../../include -I../../../include -I../../wlan/include \ + -I../../os/linux/include -I../../3rdparty/supplicant/opensrc_0_6_9/src/common \ + -I../../os/linux/include -I../../3rdparty/supplicant/opensrc_0_6_9/src/utils wac.c -o wac + +#wpa_ctrl.o: os_internal.o +# $(CC) $(CFLAGS) -I./ -I$(KERNEL_SRC)/include -I../../include -I../../../include -I../../wlan/include \ +# -I../../os/linux/include -I../../3rdparty/supplicant/opensrc_0_6_9/src/utils \ +# -c ../../3rdparty/supplicant/opensrc_0_6_9/src/common/wpa_ctrl.c +# +#os_internal.o: +# $(CC) $(CFLAGS) -I./ -I$(KERNEL_SRC)/include -I../../include -I../../../include -I../../wlan/include \ +# -I../../os/linux/include -I../../3rdparty/supplicant/opensrc_0_6_9/src/utils \ +# -c ../../3rdparty/supplicant/opensrc_0_6_9/src/utils/os_internal.c diff --git a/drivers/net/wireless/ar6003/host/lib/wac/wac.c b/drivers/net/wireless/ar6003/host/lib/wac/wac.c new file mode 100644 index 000000000000..f39e63ceb4c9 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/lib/wac/wac.c @@ -0,0 +1,1446 @@ +/* + * Copyright (c) 2006 Atheros Communications Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef ANDROID +#include "wireless_copy.h" +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "wac_defs.h" +//#include "wpa_ctrl.h" +//#include "os.h" + +#undef DEBUG +#undef DBGLOG_DEBUG + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) +/* ---------- CONSTANTS --------------- */ +#define ATH_WE_HEADER_TYPE_NULL 0 /* Not available */ +#define ATH_WE_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */ +#define ATH_WE_HEADER_TYPE_UINT 4 /* __u32 */ +#define ATH_WE_HEADER_TYPE_FREQ 5 /* struct iw_freq */ +#define ATH_WE_HEADER_TYPE_ADDR 6 /* struct sockaddr */ +#define ATH_WE_HEADER_TYPE_POINT 8 /* struct iw_point */ +#define ATH_WE_HEADER_TYPE_PARAM 9 /* struct iw_param */ +#define ATH_WE_HEADER_TYPE_QUAL 10 /* struct iw_quality */ + +#define ATH_WE_DESCR_FLAG_DUMP 0x0001 /* Not part of the dump command */ +#define ATH_WE_DESCR_FLAG_EVENT 0x0002 /* Generate an event on SET */ +#define ATH_WE_DESCR_FLAG_RESTRICT 0x0004 /* GET : request is ROOT only */ +#define ATH_WE_DESCR_FLAG_NOMAX 0x0008 /* GET : no limit on request size */ + +#define ATH_SIOCSIWMODUL 0x8b2f +#define ATH_SIOCGIWMODUL 0x8b2f +#define ATH_WE_VERSION (A_INT16)22 +/* ---------------------------- TYPES ---------------------------- */ + +/* + * standard IOCTL looks like. + */ +struct ath_ioctl_description +{ + A_UINT8 header_type; /* NULL, iw_point or other */ + A_UINT8 token_type; /* Future */ + A_UINT16 token_size; /* Granularity of payload */ + A_UINT16 min_tokens; /* Min acceptable token number */ + A_UINT16 max_tokens; /* Max acceptable token number */ + A_UINT32 flags; /* Special handling of the request */ +}; + + +/* -------------------------- VARIABLES -------------------------- */ + +/* + * Meta-data about all the standard Wireless Extension request we + * know about. + */ +static const struct ath_ioctl_description standard_ioctl_descr[] = { + [SIOCSIWCOMMIT - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_NULL, + }, + [SIOCGIWNAME - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_CHAR, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWNWID - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + .flags = ATH_WE_DESCR_FLAG_EVENT, + }, + [SIOCGIWNWID - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWFREQ - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_FREQ, + .flags = ATH_WE_DESCR_FLAG_EVENT, + }, + [SIOCGIWFREQ - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_FREQ, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWMODE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_UINT, + .flags = ATH_WE_DESCR_FLAG_EVENT, + }, + [SIOCGIWMODE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_UINT, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWSENS - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWSENS - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWRANGE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_NULL, + }, + [SIOCGIWRANGE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = sizeof(struct iw_range), + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWPRIV - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_NULL, + }, + [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */ + .header_type = ATH_WE_HEADER_TYPE_NULL, + }, + [SIOCSIWSTATS - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_NULL, + }, + [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */ + .header_type = ATH_WE_HEADER_TYPE_NULL, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWSPY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = sizeof(struct sockaddr), + .max_tokens = IW_MAX_SPY, + }, + [SIOCGIWSPY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = sizeof(struct sockaddr) + + sizeof(struct iw_quality), + .max_tokens = IW_MAX_SPY, + }, + [SIOCSIWTHRSPY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = sizeof(struct iw_thrspy), + .min_tokens = 1, + .max_tokens = 1, + }, + [SIOCGIWTHRSPY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = sizeof(struct iw_thrspy), + .min_tokens = 1, + .max_tokens = 1, + }, + [SIOCSIWAP - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_ADDR, + }, + [SIOCGIWAP - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_ADDR, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWMLME - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .min_tokens = sizeof(struct iw_mlme), + .max_tokens = sizeof(struct iw_mlme), + }, + [SIOCGIWAPLIST - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = sizeof(struct sockaddr) + + sizeof(struct iw_quality), + .max_tokens = IW_MAX_AP, + .flags = ATH_WE_DESCR_FLAG_NOMAX, + }, + [SIOCSIWSCAN - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .min_tokens = 0, + .max_tokens = sizeof(struct iw_scan_req), + }, + [SIOCGIWSCAN - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_SCAN_MAX_DATA, + .flags = ATH_WE_DESCR_FLAG_NOMAX, + }, + [SIOCSIWESSID - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ESSID_MAX_SIZE + 1, + .flags = ATH_WE_DESCR_FLAG_EVENT, + }, + [SIOCGIWESSID - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ESSID_MAX_SIZE + 1, + .flags = ATH_WE_DESCR_FLAG_DUMP, + }, + [SIOCSIWNICKN - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ESSID_MAX_SIZE + 1, + }, + [SIOCGIWNICKN - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ESSID_MAX_SIZE + 1, + }, + [SIOCSIWRATE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWRATE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWRTS - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWRTS - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWFRAG - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWFRAG - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWTXPOW - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWTXPOW - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWRETRY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWRETRY - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWENCODE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ENCODING_TOKEN_MAX, + .flags = ATH_WE_DESCR_FLAG_EVENT | ATH_WE_DESCR_FLAG_RESTRICT, + }, + [SIOCGIWENCODE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_ENCODING_TOKEN_MAX, + .flags = ATH_WE_DESCR_FLAG_DUMP | ATH_WE_DESCR_FLAG_RESTRICT, + }, + [SIOCSIWPOWER - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWPOWER - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [ATH_SIOCSIWMODUL - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [ATH_SIOCGIWMODUL - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWGENIE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_GENERIC_IE_MAX, + }, + [SIOCGIWGENIE - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_GENERIC_IE_MAX, + }, + [SIOCSIWAUTH - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCGIWAUTH - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_PARAM, + }, + [SIOCSIWENCODEEXT - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .min_tokens = sizeof(struct iw_encode_ext), + .max_tokens = sizeof(struct iw_encode_ext) + + IW_ENCODING_TOKEN_MAX, + }, + [SIOCGIWENCODEEXT - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .min_tokens = sizeof(struct iw_encode_ext), + .max_tokens = sizeof(struct iw_encode_ext) + + IW_ENCODING_TOKEN_MAX, + }, + [SIOCSIWPMKSA - SIOCIWFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .min_tokens = sizeof(struct iw_pmksa), + .max_tokens = sizeof(struct iw_pmksa), + }, +}; +static const unsigned int standard_ioctl_num = (sizeof(standard_ioctl_descr) / + sizeof(struct ath_ioctl_description)); + +/* + * Meta-data about all the additional standard Wireless Extension events + */ +static const struct ath_ioctl_description standard_event_descr[] = { + [IWEVTXDROP - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_ADDR, + }, + [IWEVQUAL - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_QUAL, + }, + [IWEVCUSTOM - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_CUSTOM_MAX, + }, + [IWEVREGISTERED - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_ADDR, + }, + [IWEVEXPIRED - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_ADDR, + }, + [IWEVGENIE - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_GENERIC_IE_MAX, + }, + [IWEVMICHAELMICFAILURE - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = sizeof(struct iw_michaelmicfailure), + }, + [IWEVASSOCREQIE - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_GENERIC_IE_MAX, + }, + [IWEVASSOCRESPIE - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = IW_GENERIC_IE_MAX, + }, + [IWEVPMKIDCAND - IWEVFIRST] = { + .header_type = ATH_WE_HEADER_TYPE_POINT, + .token_size = 1, + .max_tokens = sizeof(struct iw_pmkid_cand), + }, +}; +static const unsigned int standard_event_num = (sizeof(standard_event_descr) / + sizeof(struct ath_ioctl_description)); + +/* Size (in bytes) of various events */ +static const int event_type_size[] = { + IW_EV_LCP_PK_LEN, /* ATH_WE_HEADER_TYPE_NULL */ + 0, + IW_EV_CHAR_PK_LEN, /* ATH_WE_HEADER_TYPE_CHAR */ + 0, + IW_EV_UINT_PK_LEN, /* ATH_WE_HEADER_TYPE_UINT */ + IW_EV_FREQ_PK_LEN, /* ATH_WE_HEADER_TYPE_FREQ */ + IW_EV_ADDR_PK_LEN, /* ATH_WE_HEADER_TYPE_ADDR */ + 0, + IW_EV_POINT_PK_LEN, /* Without variable payload */ + IW_EV_PARAM_PK_LEN, /* ATH_WE_HEADER_TYPE_PARAM */ + IW_EV_QUAL_PK_LEN, /* ATH_WE_HEADER_TYPE_QUAL */ +}; + +//static const char *ctrl_iface_dir = "/var/run/wpa_supplicant"; +//static struct wpa_ctrl *ctrl_conn; +//static char *ctrl_ifname = NULL; + +/* Structure used for parsing event list, such as Wireless Events + * and scan results */ +typedef struct event_list +{ + A_INT8 * end; /* End of the list */ + A_INT8 * current; /* Current event in list of events */ + A_INT8 * value; /* Current value in event */ +} event_list; + +#endif /*#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) */ + + + + +#define MAX_WAC_BSS 10 +WMI_BSS_INFO_HDR2 myBssInfo[MAX_WAC_BSS]; +int myBssCnt = 0; +int wps_pending = 0; +char exec_path[128]; +char wps_pin[9]; + +//DBG +int fakeId = 0; + +// utilities functions +typedef long os_time_t; + +struct os_time { + os_time_t sec; + os_time_t usec; +}; + +static int os_get_random(unsigned char *buf, size_t len) +{ + FILE *f; + size_t rc; + + f = fopen("/dev/urandom", "rb"); + if (f == NULL) { + printf("Could not open /dev/urandom.\n"); + return -1; + } + + rc = fread(buf, 1, len, f); + fclose(f); + + return rc != len ? -1 : 0; +} + +static int os_get_time(struct os_time *t) +{ + int res; + struct timeval tv; + res = gettimeofday(&tv, NULL); + t->sec = tv.tv_sec; + t->usec = tv.tv_usec; + return res; +} + +static unsigned long os_random(void) +{ + return random(); +} + +/** + * wps_pin_checksum - Compute PIN checksum + * @pin: Seven digit PIN (i.e., eight digit PIN without the checksum digit) + * Returns: Checksum digit + */ +unsigned int wps_pin_checksum(unsigned int pin) +{ + unsigned int accum = 0; + while (pin) { + accum += 3 * (pin % 10); + pin /= 10; + accum += pin % 10; + pin /= 10; + } + + return (10 - accum % 10) % 10; +} + +/** + * wps_generate_pin - Generate a random PIN + * Returns: Eight digit PIN (i.e., including the checksum digit) + */ +unsigned int wps_generate_pin(void) +{ + unsigned int val; + + /* Generate seven random digits for the PIN */ + if (os_get_random((unsigned char *) &val, sizeof(val)) < 0) { + struct os_time now; + os_get_time(&now); + val = os_random() ^ now.sec ^ now.usec; + } + val %= 10000000; + + /* Append checksum digit */ + return val * 10 + wps_pin_checksum(val); +} + +static void str2hex(A_UINT8 *hex, char *str); +// +//////////////////////////////////////////////////////////////////////////////// +// Library APIs +int wac_enable(int s, int enable, unsigned int period, unsigned int scan_thres, int rssi_thres) +{ + char ifname[IFNAMSIZ]; + struct ifreq ifr; + char *ethIf; + char *cmd_buf = malloc(256); + WMI_WAC_ENABLE_CMD *cmd = (WMI_WAC_ENABLE_CMD *)(cmd_buf+4); + unsigned int pin = wps_generate_pin(); + + memset(cmd_buf, 0, sizeof(cmd_buf)); + memset(ifname, '\0', IFNAMSIZ); + cmd->enable = enable; + cmd->period = period; + cmd->threshold = scan_thres; + cmd->rssi = rssi_thres; + snprintf(wps_pin, 9, "%d", pin); + memcpy(cmd->wps_pin, wps_pin, 8); + + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = "eth1"; + } + strcpy(ifname, ethIf); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + ((int *)cmd_buf)[0] = AR6000_XIOCTL_WMI_ENABLE_WAC_PARAM; + ifr.ifr_data = cmd_buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + free(cmd_buf); + return -1; + } + printf("cmd = Wac Enable: %x, %x %x, %x\n", enable, period, scan_thres, rssi_thres); + printf("random PIN = %s\n", wps_pin); + free(cmd_buf); + + return 0; +} + +void wac_control_request( int s, + WAC_REQUEST_TYPE req, + WAC_COMMAND cmd, + WAC_FRAME_TYPE frm, + char *ie, + int *ret_val, + WAC_STATUS *status ) +{ + char ifname[IFNAMSIZ]; + struct ifreq ifr; + char *ethIf; + char *cmd_buf = malloc(256); + WMI_WAC_CTRL_REQ_CMD *ctrl_cmd = (WMI_WAC_CTRL_REQ_CMD *)(cmd_buf+4); + + memset(cmd_buf, 0, 256); + memset(ifname, '\0', IFNAMSIZ); + + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = "eth1"; + } + strcpy(ifname, ethIf); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + *ret_val = 0; + + if ( WAC_SET == req ) { + if ( PRBREQ == frm ) { + switch (cmd) { + case WAC_ADD: + { + if (0 != strncmp(ie, "0x", 2)) { + printf("expect \'ie\' in hex format with 0x\n"); + *ret_val = -1; + goto done_ctrl_req; + } + + if (0 != (strlen(ie) % 2)) { + printf("expect \'ie\' to be even length\n"); + *ret_val = -1; + goto done_ctrl_req; + } + + ctrl_cmd->req = WAC_SET; + ctrl_cmd->cmd = WAC_ADD; + ctrl_cmd->frame = PRBREQ; + str2hex(ctrl_cmd->ie, ie); + + ((int *)cmd_buf)[0] = AR6000_XIOCTL_WMI_WAC_CTRL_REQ; + ifr.ifr_data = cmd_buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + *ret_val = -1; + } + break; + } + + case WAC_DEL: + { + ctrl_cmd->req = WAC_SET; + ctrl_cmd->cmd = WAC_DEL; + ctrl_cmd->frame = PRBREQ; + + ((int *)cmd_buf)[0] = AR6000_XIOCTL_WMI_WAC_CTRL_REQ; + ifr.ifr_data = cmd_buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + *ret_val = -1; + } + break; + } + + default: + printf("unknown command %d\n", cmd); + *ret_val = -1; + break; + } + } + else { + printf("unknown set frame type %d\n", frm); + *ret_val = -1; + } + } + else if ( WAC_GET == req ) { + if ( WAC_GET_STATUS == cmd ) { // GET STATUS + ctrl_cmd->req = WAC_GET; + ctrl_cmd->cmd = WAC_GET_STATUS; + + ((int *)cmd_buf)[0] = AR6000_XIOCTL_WMI_WAC_CTRL_REQ; + ifr.ifr_data = cmd_buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + *ret_val = -1; + goto done_ctrl_req; + } + A_MEMCPY(status, ifr.ifr_data, sizeof(WAC_STATUS)); + } + else if ( PRBREQ == frm ) { // GET IE + ctrl_cmd->req = WAC_GET; + ctrl_cmd->cmd = WAC_GET_IE; + + ((int *)cmd_buf)[0] = AR6000_XIOCTL_WMI_WAC_CTRL_REQ; + ifr.ifr_data = cmd_buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + *ret_val = -1; + goto done_ctrl_req; + } + A_MEMCPY(ie, ifr.ifr_data, sizeof(WMI_GET_WAC_INFO)); + } + else { + printf("unknown get request\n"); + *ret_val = -1; + } + } + else + { + printf("unkown request type %d\n", req); + *ret_val = -1; + } + +done_ctrl_req: + free(cmd_buf); +} + +//////////////////////////////////////////////////////////////////////////////// + +static int htoi(char c) +{ + if (c >= 'a' && c <= 'f') { + return (c - 'a' + 10); + } + + if (c >= 'A' && c <= 'F') { + return (c - 'A' + 10); + } + + if (c >= '0' && c <= '9') { + return (c - '0'); + } + + return 0; +} + +static void str2hex(A_UINT8 *hex, char *str) +{ + int i; + int len = strlen(str); + + for (i = 2; i < len; i+=2) { + hex[(i-2)/2] = htoi(str[i]) * 16 + htoi(str[i+1]); + } +} + +static void getBssid(char *bssid) +{ + WMI_BSS_INFO_HDR2 *p = &myBssInfo[0]; + char tmp[3]; + + if (fakeId == (MAX_WAC_BSS+1)) { + strcpy(bssid, "1c:af:f7:1b:81:82"); + return; + } + + sprintf(tmp, "%02x", p->bssid[0]); + strcpy(bssid, tmp); + strcat(bssid, ":"); + sprintf(tmp, "%02x", p->bssid[1]); + strcat(bssid, tmp); + strcat(bssid, ":"); + sprintf(tmp, "%02x", p->bssid[2]); + strcat(bssid, tmp); + strcat(bssid, ":"); + sprintf(tmp, "%02x", p->bssid[3]); + strcat(bssid, tmp); + strcat(bssid, ":"); + sprintf(tmp, "%02x", p->bssid[4]); + strcat(bssid, tmp); + strcat(bssid, ":"); + sprintf(tmp, "%02x", p->bssid[5]); + strcat(bssid, tmp); + + printf("bssid = %s\n", bssid); +} + +static int check_stored_profile(A_UINT8 *bssid) +{ + FILE *fp; + char buffer[128]; + char full_cmd[256]; +// char *cmd = "../../.output/LOCAL_i686-SDIO/image/wpa_cli list_networks | grep -o \'\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w\'"; + + memset(full_cmd, '\0', 256); + strcpy(full_cmd, exec_path); + strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli list_networks | grep -o \'\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w\'"); + + memset(buffer, '\0', 128); + fp = popen(full_cmd, "r"); + fgets(buffer, 128, fp); + pclose(fp); + + if (buffer[0] == '\0') { + printf("no stored profile\n"); + return 1; + } + + printf("profile bssid = %s\n", buffer); + + bssid[0] = htoi(buffer[0]) * 16 + htoi(buffer[1]); + bssid[1] = htoi(buffer[3]) * 16 + htoi(buffer[4]); + bssid[2] = htoi(buffer[6]) * 16 + htoi(buffer[7]); + bssid[3] = htoi(buffer[9]) * 16 + htoi(buffer[10]); + bssid[4] = htoi(buffer[12]) * 16 + htoi(buffer[13]); + bssid[5] = htoi(buffer[15]) * 16 + htoi(buffer[16]); + + printf("bssid in decimal: %d:%d:%d:%d:%d:%d\n", + bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); + + return 0; +} + +static int match_stored_profile(A_UINT8 *myBssid) +{ + int i; + + for (i = 0; i < MAX_WAC_BSS; i++) { + if (0 == A_MEMCMP(myBssInfo[i].bssid, myBssid, 6)) { + break; + } + } + + if (i < MAX_WAC_BSS) { + printf("matched profile: %d\n", i); + return i; + } + else { + printf("no matched profile: %d\n", i); + return -1; + } +} + +static int select_best_bss() +{ + return 0; +} + +static void wpa_profile_reconnect(void) +{ + char full_cmd[128]; + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli ap_scan 1")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli save_config")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli reconfigure")); + + // wpa_cli ap_scan 1 + // wpa_cli save_config + // wpa_cli reconfigure + // wpa_cli ap_scan 0 + // wpa_cli save_config +} + +static int wps_start(void) +{ + char full_cmd[128]; + char which_bssid[32]; + int ret = 0; + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli ap_scan 1")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli save_config")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli reconfigure")); + + memset(which_bssid, '\0', 32); + getBssid(which_bssid); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli wps_pin "); + strcat(full_cmd, which_bssid); + strcat(full_cmd, " "); + strcat(full_cmd, wps_pin); + + wps_pending = 1; + printf("wps_start: %s\n", full_cmd); + + ret = system(full_cmd); + + return ret; +} + + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) +int app_extract_events(struct event_list* list, + struct iw_event * iwe); +#endif +static void +event_rtm_newlink(struct nlmsghdr *h, int len); + +static void +event_wireless(A_INT8 *data, int len); + +int +string_search(FILE *fp, char *string) +{ + char str[DBGLOG_DBGID_DEFINITION_LEN_MAX]; + + rewind(fp); + memset(str, 0, DBGLOG_DBGID_DEFINITION_LEN_MAX); + while (!feof(fp)) { + fscanf(fp, "%s", str); + if (strstr(str, string)) return 1; + } + + return 0; +} + +#define RECEVENT_DEBUG_PRINTF(args...) + +int s; //socket +int main(int argc, char** argv) +{ +// int s, c, ret; +// int s; + struct sockaddr_nl local; + struct sockaddr_nl from; + socklen_t fromlen; + struct nlmsghdr *h; + char buf[16384]; + int left; + FILE *fp; + char *cmd = "pwd"; + int len; + + //DBG + if (argc == 2) { + fakeId = atoi(argv[1]); + } + + // determine execution path + memset(exec_path, '\0', 128); + fp = popen(cmd, "r"); + fgets(exec_path, 128, fp); + pclose(fp); + + len = strlen(exec_path); + if ( '\n' == exec_path[len-1] ) { + exec_path[len-1] = '/'; + } + else { + exec_path[len] = '/'; + } + + printf("exec_path = %s\n", exec_path); + + s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (s < 0) { + perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)"); + return -1; + } + + memset(&local, 0, sizeof(local)); + local.nl_family = AF_NETLINK; + local.nl_groups = RTMGRP_LINK; + if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) { + perror("bind(netlink)"); + close(s); + return -1; + } + + while (1) { + fromlen = sizeof(from); + left = recvfrom(s, buf, sizeof(buf), 0, + (struct sockaddr *) &from, &fromlen); + if (left < 0) { + if (errno != EINTR && errno != EAGAIN) + perror("recvfrom(netlink)"); + break; + } + + h = (struct nlmsghdr *) buf; + + while (left >= sizeof(*h)) { + int len, plen; + + len = h->nlmsg_len; + plen = len - sizeof(*h); + if (len > left || plen < 0) { + perror("Malformed netlink message: "); + break; + } + + switch (h->nlmsg_type) { + case RTM_NEWLINK: + event_rtm_newlink(h, plen); + break; + case RTM_DELLINK: + RECEVENT_DEBUG_PRINTF("DELLINK\n"); + break; + default: + RECEVENT_DEBUG_PRINTF("OTHERS\n"); + } + + len = NLMSG_ALIGN(len); + left -= len; + h = (struct nlmsghdr *) ((char *) h + len); + } + } + + close(s); + return 0; +} + +static void +event_rtm_newlink(struct nlmsghdr *h, int len) +{ + struct ifinfomsg *ifi; + int attrlen, nlmsg_len, rta_len; + struct rtattr * attr; + + if (len < sizeof(*ifi)) { + perror("too short\n"); + return; + } + + ifi = NLMSG_DATA(h); + + nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg)); + + attrlen = h->nlmsg_len - nlmsg_len; + if (attrlen < 0) { + perror("bad attren\n"); + return; + } + + attr = (struct rtattr *) (((char *) ifi) + nlmsg_len); + + rta_len = RTA_ALIGN(sizeof(struct rtattr)); + while (RTA_OK(attr, attrlen)) { + if (attr->rta_type == IFLA_WIRELESS) { + event_wireless( ((A_INT8*)attr) + rta_len, attr->rta_len - rta_len); + } else if (attr->rta_type == IFLA_IFNAME) { + + } + attr = RTA_NEXT(attr, attrlen); + } +} + +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) +/*------------------------------------------------------------------*/ +/* + * Extract the next event from the event list. + */ +int +app_extract_events(struct event_list* list, /* list of events */ + struct iw_event * iwe /* Extracted event */ + ) +{ + const struct ath_ioctl_description * descr = NULL; + int event_type = 0; + unsigned int event_len = 1; /* Invalid */ + A_INT8 * pointer; + A_INT16 we_version = ATH_WE_VERSION; + unsigned cmd_index; + + /* Check for end of list */ + if((list->current + IW_EV_LCP_PK_LEN) > list->end) + return(0); + + /* Extract the event header (to get the event id). + * Note : the event may be unaligned, therefore copy... */ + memcpy((char *) iwe, list->current, IW_EV_LCP_PK_LEN); + + /* Check invalid events */ + if(iwe->len <= IW_EV_LCP_PK_LEN) + return(-1); + + /* Get the type and length of that event */ + if(iwe->cmd <= SIOCIWLAST) + { + cmd_index = iwe->cmd - SIOCIWFIRST; + if(cmd_index < standard_ioctl_num) + descr = &(standard_ioctl_descr[cmd_index]); + } + else + { + cmd_index = iwe->cmd - IWEVFIRST; + if(cmd_index < standard_event_num) + descr = &(standard_event_descr[cmd_index]); + } + if(descr != NULL) + event_type = descr->header_type; + /* Unknown events -> event_type=0 => IW_EV_LCP_PK_LEN */ + event_len = event_type_size[event_type]; + /* Fixup for earlier version of WE */ + if((we_version <= 18) && (event_type == ATH_WE_HEADER_TYPE_POINT)) + event_len += IW_EV_POINT_OFF; + + /* Check if we know about this event */ + if(event_len <= IW_EV_LCP_PK_LEN) + { + /* Skip to next event */ + list->current += iwe->len; + return(2); + } + event_len -= IW_EV_LCP_PK_LEN; + + /* Set pointer on data */ + if(list->value != NULL) + pointer = list->value; /* Next value in event */ + else + pointer = list->current + IW_EV_LCP_PK_LEN; /* First value in event */ + + /* Copy the rest of the event (at least, fixed part) */ + if((pointer + event_len) > list->end) + { + /* Go to next event */ + list->current += iwe->len; + return(-2); + } + /* Fixup for WE-19 and later : pointer no longer in the list */ + /* Beware of alignement. Dest has local alignement, not packed */ + if((we_version > 18) && (event_type == ATH_WE_HEADER_TYPE_POINT)) + memcpy((char *) iwe + IW_EV_LCP_LEN + IW_EV_POINT_OFF, + pointer, event_len); + else + memcpy((char *) iwe + IW_EV_LCP_LEN, pointer, event_len); + + /* Skip event in the stream */ + pointer += event_len; + + /* Special processing for iw_point events */ + if(event_type == ATH_WE_HEADER_TYPE_POINT) + { + /* Check the length of the payload */ + unsigned int extra_len = iwe->len - (event_len + IW_EV_LCP_PK_LEN); + if(extra_len > 0) + { + /* Set pointer on variable part (warning : non aligned) */ + iwe->u.data.pointer = pointer; + + /* Check that we have a descriptor for the command */ + if(descr == NULL) + /* Can't check payload -> unsafe... */ + iwe->u.data.pointer = NULL; /* Discard paylod */ + else + { + /* Those checks are actually pretty hard to trigger, + * because of the checks done in the kernel... */ + + unsigned int token_len = iwe->u.data.length * descr->token_size; + + /* Ugly fixup for alignement issues. + * If the kernel is 64 bits and userspace 32 bits, + * we have an extra 4+4 bytes. + * Fixing that in the kernel would break 64 bits userspace. */ + if((token_len != extra_len) && (extra_len >= 4)) + { + A_UINT16 alt_dlen = *((A_UINT16 *) pointer); + unsigned int alt_token_len = alt_dlen * descr->token_size; + if((alt_token_len + 8) == extra_len) + { + /* Ok, let's redo everything */ + pointer -= event_len; + pointer += 4; + /* Dest has local alignement, not packed */ + memcpy((char*) iwe + IW_EV_LCP_LEN + IW_EV_POINT_OFF, + pointer, event_len); + pointer += event_len + 4; + iwe->u.data.pointer = pointer; + token_len = alt_token_len; + } + } + + /* Discard bogus events which advertise more tokens than + * what they carry... */ + if(token_len > extra_len) + iwe->u.data.pointer = NULL; /* Discard paylod */ + /* Check that the advertised token size is not going to + * produce buffer overflow to our caller... */ + if((iwe->u.data.length > descr->max_tokens) + && !(descr->flags & ATH_WE_DESCR_FLAG_NOMAX)) + iwe->u.data.pointer = NULL; /* Discard paylod */ + /* Same for underflows... */ + if(iwe->u.data.length < descr->min_tokens) + iwe->u.data.pointer = NULL; /* Discard paylod */ + } + } + else + /* No data */ + iwe->u.data.pointer = NULL; + + /* Go to next event */ + list->current += iwe->len; + } + else + { + /* Ugly fixup for alignement issues. + * If the kernel is 64 bits and userspace 32 bits, + * we have an extra 4 bytes. + * Fixing that in the kernel would break 64 bits userspace. */ + if((list->value == NULL) + && ((((iwe->len - IW_EV_LCP_PK_LEN) % event_len) == 4) + || ((iwe->len == 12) && ((event_type == ATH_WE_HEADER_TYPE_UINT) || + (event_type == ATH_WE_HEADER_TYPE_QUAL))) )) + { + pointer -= event_len; + pointer += 4; + /* Beware of alignement. Dest has local alignement, not packed */ + memcpy((char *) iwe + IW_EV_LCP_LEN, pointer, event_len); + pointer += event_len; + } + + /* Is there more value in the event ? */ + if((pointer + event_len) <= (list->current + iwe->len)) + /* Go to next value */ + list->value = pointer; + else + { + /* Go to next event */ + list->value = NULL; + list->current += iwe->len; + } + } + return(1); +} +#endif /*#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) */ + +static void +event_wireless(A_INT8 *data, int len) +{ + A_INT8 *pos, *end, *custom, *buf; + A_UINT16 eventid; +// int status; +// static int wps = 0; +// A_STATUS status; + + pos = data; + end = data + len; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + struct iw_event iwe; + struct event_list list; + int ret; + + /* Cleanup */ + memset((char *) &list, '\0', sizeof(struct event_list)); + + /* Set things up */ + list.current = data; + list.end = data + len; + + do + { + /* Extract an event and print it */ + ret = app_extract_events(&list, &iwe); + if(ret != 0) + { + RECEVENT_DEBUG_PRINTF("\n cmd = %x, length = %d, ",iwe.cmd,iwe.u.data.length); + + switch (iwe.cmd) { + case IWEVCUSTOM: + custom = pos + IW_EV_POINT_LEN; + if (custom + iwe.u.data.length > end) + return; + buf = malloc(iwe.u.data.length + 1); + if (buf == NULL) return; + memcpy(buf, custom, iwe.u.data.length); + eventid = *((A_UINT16*)buf); + RECEVENT_DEBUG_PRINTF("\n eventid = %x",eventid); + + switch (eventid) { + case (WMI_READY_EVENTID): + printf("event = Wmi Ready, len = %d\n", iwe.u.data.length); +// status = app_wmiready_event_rx((A_UINT8 *)(buf + ID_LEN), iwe.u.data.length - ID_LEN); + break; + case (WMI_DISCONNECT_EVENTID): + printf("event = Wmi Disconnect, len = %d\n", iwe.u.data.length); + if (wps_pending) { + char full_cmd[128]; + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli ap_scan 1")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli save_config")); + + wps_pending = 0; + } +// status = app_disconnect_event_rx((A_UINT8 *)(buf + ID_LEN), iwe.u.data.length - ID_LEN); + break; + case (WMI_SCAN_COMPLETE_EVENTID): + printf("event = Wmi Scan Complete, len = %d\n", iwe.u.data.length); +// status = app_scan_complete_event_rx((A_UINT8 *)(buf + ID_LEN), iwe.u.data.length - ID_LEN); + break; + case (WMI_WAC_SCAN_DONE_EVENTID): + { + char ifname[IFNAMSIZ]; + struct ifreq ifr; + char *ethIf; + char *buf = malloc(256); + WMI_WAC_SCAN_REPLY_CMD *cmd = (WMI_WAC_SCAN_REPLY_CMD *)(buf+4); + int matched = 0, has_profile = 0; + + memset(buf, 0, sizeof(buf)); + memset(ifname, '\0', IFNAMSIZ); + + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = "eth1"; + } + strcpy(ifname, ethIf); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + printf("event = WAC scan done, len = %d\n", iwe.u.data.length); + + if (myBssCnt == 0) { + cmd->cmdid = -1; //no BSS, continue WAC scan + } + else { + A_UINT8 myBssid[6]; + // TODO: choose best BSS to connect + // OR match stored profile + if (check_stored_profile(myBssid)) { + // no stored profile, select best BSS to connect + has_profile = 0; + } + else { + has_profile = 1; + // has stored profile, match BSS with stored profile + if ( match_stored_profile(myBssid) >= 0 ) { + matched = 1; + } + } + + if (!matched || !has_profile) { + cmd->cmdid = select_best_bss(); + } + else { + // either has profile or found matched profile + // stop WAC scan + cmd->cmdid = -2; + } + } + + //DBG + if (fakeId != 0) { + cmd->cmdid = fakeId; //fake BSS info + } + printf("Sending WAC scan reply %d\n", cmd->cmdid); + + ((int *)buf)[0] = AR6000_XIOCTL_WAC_SCAN_REPLY; + ifr.ifr_data = buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + } + + if ( -2 == cmd->cmdid ) { + // stop WAC scan -> reconnect + wpa_profile_reconnect(); + } + + break; + } + case WMI_WAC_REPORT_BSS_EVENTID: + { + A_INT8 *rxB = buf+2; + WMI_BSS_INFO_HDR2 *p; + if (myBssCnt >= MAX_WAC_BSS) { + printf("Too many bss reported, quitting\n"); + break; + } + +// printf("event = WAC report bss, len = %d\n", iwe.u.data.length); + + p = &myBssInfo[myBssCnt++]; + memcpy((A_UINT8 *)p, rxB, sizeof(WMI_BSS_INFO_HDR2)); + + p = (WMI_BSS_INFO_HDR2 *) rxB; + printf("event = WAC report bss: %x:%x:%x:%x:%x:%x\n", + p->bssid[0], + p->bssid[1], + p->bssid[2], + p->bssid[3], + p->bssid[4], + p->bssid[5]); + break; + } + case WMI_WAC_START_WPS_EVENTID: +// printf("wps start\n"); + if (wps_start()) { + printf("wps start failed\n"); + } + break; + + default: + RECEVENT_DEBUG_PRINTF("Host received other event with id 0x%x\n", + eventid); + break; + } + free(buf); + break; + case IWEVGENIE: + custom = pos + IW_EV_POINT_LEN; + if (custom + iwe.u.data.length > end) + return; + buf = malloc(iwe.u.data.length + 1); + if (buf == NULL) return; + memcpy(buf, custom, iwe.u.data.length); + eventid = *((A_UINT16*)buf); + + switch (eventid) { + case (WMI_CONNECT_EVENTID): + { + char ifname[IFNAMSIZ]; + struct ifreq ifr; + char *ethIf; + char *buf = malloc(256); + WMI_WAC_ENABLE_CMD *cmd = (WMI_WAC_ENABLE_CMD *)(buf+4); + + memset(buf, 0, sizeof(buf)); + memset(ifname, '\0', IFNAMSIZ); + + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = "eth1"; + } + strcpy(ifname, ethIf); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + ((int *)buf)[0] = AR6000_XIOCTL_WMI_ENABLE_WAC_PARAM; + cmd->enable = 0; + ifr.ifr_data = buf; + if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) + { + err(1, "%s", ifr.ifr_name); + } + printf("event = Wmi Connect, len = %d\n", iwe.u.data.length); + printf("disabling WAC\n"); + if (!wps_pending) { + char full_cmd[128]; + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli ap_scan 0")); + + memset(full_cmd, '\0', 128); + strcpy(full_cmd, exec_path); + system(strcat(full_cmd, "../../.output/LOCAL_i686-SDIO/image/wpa_cli save_config")); + } + +// status = app_connect_event_rx((A_UINT8 *)(buf + ID_LEN), iwe.u.data.length - ID_LEN); + break; + } + case WMI_ENABLE_WAC_CMDID: + { + WMI_WAC_ENABLE_CMD *cmd = (WMI_WAC_ENABLE_CMD *)(buf+2); + + wac_enable(s, cmd->enable, cmd->period, cmd->threshold, cmd->rssi); + break; + } + default: + break; + } + free(buf); + break; + + default: + RECEVENT_DEBUG_PRINTF("event = Others\n"); + break; + } + } + } + while(ret > 0); + +#endif +} + diff --git a/drivers/net/wireless/ar6003/host/lib/wac/wac_lib_api.h b/drivers/net/wireless/ar6003/host/lib/wac/wac_lib_api.h new file mode 100644 index 000000000000..72b1a22adb04 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/lib/wac/wac_lib_api.h @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#ifndef __WAC_LIB_API_H__ +#define __WAC_LIB_API_H__ + +#include "wac_defs.h" + +/* + * Function to enable or disable the WAC feature. This is the entry point to WAC when the + * user pushed a button on the remote + * Input arguments: + * s - open file descriptor of socket + * enable - flag to enable/disable WAC. 1 = enable; 0 = disable + * for disablethe remaining arguments are don't cares + * period - time in milliseconds between consecutive scans when WAC is enabled + * scan_thres - number of scan retries before the STA gave up on looking for WAC AP + * rssi_thres - RSSI threshold the STA will check in beacon or probe response frames + * to qualify a WAC AP. This is absolute value of the signal strength in dBm + * Return value: + * 0 = success; -1 = failure + * + * Examples: + * To enable WAC: wac_enable(s, 1, 2000, 3, 25) + * - WAC enabled with 2-second interval between scans for up to 3 tries. RSSI threshold is -25dBm + * To disable WAC: wac_enable(s, 0, 0, 0, 0) + * - When the flag is disable, the rest of arguments are don't cares + */ +int wac_enable(int s, int enable, unsigned int period, unsigned int scan_thres, int rssi_thres); + +/* + * Function for I/O Control Request for Samsung IE as specified version 1.2 protocol + * Input arguments: + * s - open file descriptor for socket + * req - request type takes the possible values: + * WAC_SET + * WAC_GET + * cmd - command takes the possible values: + * WAC_ADD + * WAC_DEL + * WAC_GET_STATUS + * frm - frame type takes the possible values: + * PRBREQ (for STA) + * PRBRSP (for AP) + * BEACON (for AP) + * ie - pointer to char string that contains the IE to set or get + * ret_val - indicates whether the control request is successful + * 0 = success; -1 = failure + * status - status code returned by STA that takes possible values: + * WAC_FAILED_NO_WAC_AP + * WAC_FAILED_LOW_RSSI + * WAC_FAILED_INVALID_PARAM + * WAC_FAILED_REJECTED + * WAC_SUCCESS + * WAC_PROCEED_FIRST_PHASE + * WAC_PROCEED_SECOND_PHASE + * WAC_DISABLED + * Examples: + * To insert an IE into the probe request frame: + * wac_control_request(WAC_SET, WAC_ADD, PRBREQ, + * "0x0012fb0100010101083132333435363730" val, status) + * To query the WAC status from STA: + * wac_control_request(WAC_GET, WAC_GET_STATUS, NULL, NULL, val, status) + */ +void wac_control_request( int s, + WAC_REQUEST_TYPE req, + WAC_COMMAND cmd, + WAC_FRAME_TYPE frm, + char *ie, + int *ret_val, + WAC_STATUS *status ); + +#endif diff --git a/drivers/net/wireless/ar6003/host/localmake.linux.inc b/drivers/net/wireless/ar6003/host/localmake.linux.inc new file mode 100644 index 000000000000..9b48f3fc1010 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/localmake.linux.inc @@ -0,0 +1,40 @@ +# +# Local Makefile includes for tool and kernel source paths +# +# Copyright 2004-2010 Atheros Communications, Inc. +# +# When creating a new build type, use the following template: +# ifeq ($(ATH_BUILD_TYPE),) +# ATH_ARCH_CPU_TYPE := < cpu architecture > +# ATH_CROSS_COMPILE_TYPE := < cross compiler path > +# ATH_LINUXPATH := < kernel source path > + +ATH_BUILD_TYPE := LOCAL_ARM_RK29 +ATH_BUS_TYPE := SDIO +ATH_LINUXPATH := /home/ko/work/customer/yifang/trunk_exp +ATH_CROSS_COMPILE_TYPE := /home/ko/work/customer/yifang/kernel_rk29_v0.1/toolchain/arm-eabi-4.4.0/bin/arm-eabi- +ATH_ARCH_CPU_TYPE := arm + + + $(info *************************) + $(info PLATFORM: $(ATH_BUILD_TYPE)) + $(info BSP: $(ATH_BSP_TYPE)) + $(info *************************) + # Some environment settings + ATH_BUILD_TYPE=$(ATH_BSP_TYPE)_ARM_NATIVEMMC + ATH_ANDROID_ENV := yes + ATH_SOFTMAC_FILE_USED := no + ATH_DEBUG_DRIVER := yes + ATH_HTC_RAW_INT_ENV :=yes + ATH_AR6K_OTA_TEST_MODE := no + + # Some common variable + ATH_BUS_TYPE := SDIO + ATH_OS_SUB_TYPE := linux_2_6 + ATH_BUS_SUBTYPE := linux_sdio + ATH_BUILD_3RDPARTY := no + ATH_CFG80211_ENV := no + ATH_BUILD_SYSTEM_TOOLS := no + ATH_AR6K_HCI_PAL := no + ATH_AR6K_DEBUG_ALLOC := no + ATH_BUILD_P2P :=no diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/PS_ASIC.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/PS_ASIC.pst new file mode 100644 index 000000000000..c9c7539bd273 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/PS_ASIC.pst @@ -0,0 +1,59 @@ +// based on 1, change DVDD=0.85V, LPO measure time to 8ms, 1300ms reCal interval +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 02 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]009C +[H:A]C1 C1 17 02 02 00 01 30 48 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//# +//[H:S]0021 +//[H:S]0004 +//[H:A]09 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/RamPatch.txt b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/RamPatch.txt new file mode 100644 index 000000000000..badcc110d8e2 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000/RamPatch.txt @@ -0,0 +1,2 @@ +0569 +000000000e20000050800000000158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d0915300d4915300d8915300dc91530098b0530064ce5300f8d2530008e7530008d253000cd2530098d95300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff051001010101ffffff50500101010180019800c8019800f4029800d0039800380498001404980024059800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000366100ad0581c206bd01e00800bd0a17641c0c0abd05815d080c0ce00800bd02dd03ed05815c080c0ce00800c60400ad05c1f802922b11819903c09920926b11e008000c021df0003681001c0e516d030c0720d074d241107911d0cd90b805a0cc11cabbb90160e6030c2a609034972a026062003801e2c1102203068d07cc8260e613102000fd061df072631122011072434fc805204290a044114acc882c0c1980a00407e805820c4b07e8079c7aa20c4b07ea12a2c3340c0b0cfc0c198191029911e008000c1972434ec805e8114acca82cd20c4ba0a00416aa0590fd20f24c4bcc4e820349f65878a1b1039805a20a034a9992990980aa01a0a831909821809901909831a7294a0c5a81bc04bd02e00800cd0aad0281be04e805c0b0744ace920c4b0c4dd09920924c4be008009c7a72434a860400ad020c4b81bf0492a0fe909d10924c4be0080060e613102000ad061df00c1a81bd04bd02e00800cd0a46ecff0c5a81bd04bd02e00800cd0a86e8ff0000368100305074bd0120407481c206ad04e00800922a11216d0390920516890ba18804b16e03c0200040349091f204a03311822992c02000b08810a08820a8028269923aaab20a49d2ca48579b08c20a4bc0c204161c08b24a4ae1d104524d01eae5f20e7fe20e803c29f7be4a1c0b424110d9111c0c1c0f1c0552c110fd05cd0580e6030c2e80d034d72e02806200bd05b20500c20500a802c0bb90a0bb11baaa924a3480e613102000420500d811403490520d01a03311ad04b20d0081c204cd05e00800a802b2a0fb3aaa920a4b0c12b09910924a4b1df00c021df0364100811e0621c0098808921207ece8ecc9e1b103b21206a21ef1b73a210c0a817c03d21ef0c1d603f16c03c80ce20f44a0bd11e0bd93d1d209e00800a252071df00000364100817f04916c03880892092880801466180acc79810d04a2a064e008001df0000000364100c02000c16c03e1940391d9032178030c0dd2628bf20902c02000f0ed83e2628cc02000d2628dc02000d2628e820c43b20c28d19d0210bb01d0bb10cc580cba0c53c600000c0a0c83c020000c1dd2628fc02000a2628ac02000b26289a209020c088cfa661a040c1ac60300662a05a2190026ca040c0a8607000c0af0ba01e1da03a2090ce0bb100c1ea0ae93e1f40230aa11e0aa10b0aa20b1fd03c02000a26bc1f209020c18f62f040c098604009209070c1a909a930c2af09911a09910d09920c02000d17f04926bc6d80de20c28d0d014661d0acc7e810d04a2a064e00800c020003262881df00036410081c305c1900920b074e19605d16e09e80ec02000d22d82b94ed92ec02000b90c30e6030c2a309034972a02306200e00800c02000fd0391250382a10082698000710030e6131020001df0 \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC.pst new file mode 100644 index 000000000000..dbfb680e6883 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC.pst @@ -0,0 +1,68 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 01 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 06 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//# +//[H:S]0021 +//[H:S]0004 +//[H:A]09 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclHighPri.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclHighPri.pst new file mode 100644 index 000000000000..dbfb680e6883 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclHighPri.pst @@ -0,0 +1,68 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 01 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 06 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//# +//[H:S]0021 +//[H:S]0004 +//[H:A]09 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclLowPri.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclLowPri.pst new file mode 100644 index 000000000000..b2b9e3bc4b5b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/PS_ASIC_aclLowPri.pst @@ -0,0 +1,68 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 00 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 06 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//# +//[H:S]0021 +//[H:S]0004 +//[H:A]09 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/RamPatch.txt b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/RamPatch.txt new file mode 100644 index 000000000000..badcc110d8e2 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30000coex/RamPatch.txt @@ -0,0 +1,2 @@ +0569 +000000000e20000050800000000158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d0915300d4915300d8915300dc91530098b0530064ce5300f8d2530008e7530008d253000cd2530098d95300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff051001010101ffffff50500101010180019800c8019800f4029800d0039800380498001404980024059800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000366100ad0581c206bd01e00800bd0a17641c0c0abd05815d080c0ce00800bd02dd03ed05815c080c0ce00800c60400ad05c1f802922b11819903c09920926b11e008000c021df0003681001c0e516d030c0720d074d241107911d0cd90b805a0cc11cabbb90160e6030c2a609034972a026062003801e2c1102203068d07cc8260e613102000fd061df072631122011072434fc805204290a044114acc882c0c1980a00407e805820c4b07e8079c7aa20c4b07ea12a2c3340c0b0cfc0c198191029911e008000c1972434ec805e8114acca82cd20c4ba0a00416aa0590fd20f24c4bcc4e820349f65878a1b1039805a20a034a9992990980aa01a0a831909821809901909831a7294a0c5a81bc04bd02e00800cd0aad0281be04e805c0b0744ace920c4b0c4dd09920924c4be008009c7a72434a860400ad020c4b81bf0492a0fe909d10924c4be0080060e613102000ad061df00c1a81bd04bd02e00800cd0a46ecff0c5a81bd04bd02e00800cd0a86e8ff0000368100305074bd0120407481c206ad04e00800922a11216d0390920516890ba18804b16e03c0200040349091f204a03311822992c02000b08810a08820a8028269923aaab20a49d2ca48579b08c20a4bc0c204161c08b24a4ae1d104524d01eae5f20e7fe20e803c29f7be4a1c0b424110d9111c0c1c0f1c0552c110fd05cd0580e6030c2e80d034d72e02806200bd05b20500c20500a802c0bb90a0bb11baaa924a3480e613102000420500d811403490520d01a03311ad04b20d0081c204cd05e00800a802b2a0fb3aaa920a4b0c12b09910924a4b1df00c021df0364100811e0621c0098808921207ece8ecc9e1b103b21206a21ef1b73a210c0a817c03d21ef0c1d603f16c03c80ce20f44a0bd11e0bd93d1d209e00800a252071df00000364100817f04916c03880892092880801466180acc79810d04a2a064e008001df0000000364100c02000c16c03e1940391d9032178030c0dd2628bf20902c02000f0ed83e2628cc02000d2628dc02000d2628e820c43b20c28d19d0210bb01d0bb10cc580cba0c53c600000c0a0c83c020000c1dd2628fc02000a2628ac02000b26289a209020c088cfa661a040c1ac60300662a05a2190026ca040c0a8607000c0af0ba01e1da03a2090ce0bb100c1ea0ae93e1f40230aa11e0aa10b0aa20b1fd03c02000a26bc1f209020c18f62f040c098604009209070c1a909a930c2af09911a09910d09920c02000d17f04926bc6d80de20c28d0d014661d0acc7e810d04a2a064e00800c020003262881df00036410081c305c1900920b074e19605d16e09e80ec02000d22d82b94ed92ec02000b90c30e6030c2a309034972a02306200e00800c02000fd0391250382a10082698000710030e6131020001df0 \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/PS_ASIC.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/PS_ASIC.pst new file mode 100644 index 000000000000..812e6505df26 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/PS_ASIC.pst @@ -0,0 +1,65 @@ + +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 08 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]009C +[H:A]C1 C1 17 02 08 00 01 30 48 00 0E CC 33 26 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//# +//[H:S]0021 +//[H:S]0004 +//[H:A]09 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 +//Sniff Recovery +# +[H:S]003D +[H:S]0018 +[H:A]A0 0F 00 00 00 08 00 00 0F 00 7D 04 E8 03 01 00 + 01 00 01 05 00 02 1F 01 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/RamPatch.txt b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/RamPatch.txt new file mode 100644 index 000000000000..107fd0ff80c5 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/RamPatch.txt @@ -0,0 +1,2 @@ +21c7 +000000000e20000050800000000158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d8d5530024e7530030e1530060e15300ece1530070e353008ce4530054e1530088e1530040af530088e353008ce35300d4e25300d8e25300fce253003ce3530024e3530054e3530030dd530024b0530078d553000000000000000000000000000000000030d553002ca05300000000000000000000000000000000000000000080019800d80198006c029800ec049800fc0698005c0898009c08980020099800cc099800340a9800340b9800b00b9800700c9800e40c9800580d9800c40d9800300e9800600e9800380f9800d00f9800541198000000000000000000000000000000000084189800501b98000000000000000000000000000000000000000000364100813a03416f0382085148041618040c13bc040c07613b030c02680676942252a1085052821b225a564205062020742654052634026644079205bf1769011b773df04600000c077048c00c024023831df00c021df000364100569208c0200021ce0991f3020c04426992c0200042699398128d04ed0916c9063d09a802c859b809b912a90999028c9ca21e06b82ee00c00860300a21e088bce5c0b81d6020c8de0080098120c4bbcb9c1f302d819c02000ed0cd26c90dd0cc02000426c93c02000a812b26c92a81ac02000b22c910c0cb0bac0a61b04e813a79e0ac0200081f3020c1ff268931df0000036a100a2a0dcbd01810c030c1ce00800a2a0d24bb10c4c421202521201612d0782010092a0d49088827202008a26220280810c030c16e00800313d030c09a203005981076a1690b9a030bba0b21b0407eb0c1b9990907416b9fe4600000c196619040c09c600006d090c19cc290c121df00c2c7951810c03513b03b2a108b0b282b961a8050c02225104baaaa20a1db2a0cdbaaa8bb1e00800721104810c032931a80560d6a0303da0b2030ec2a108c0bb820c4cbaaaa20a1db2a0c8baaacbb1e008008bb10c2c810c03225104a805f831d2030ee2a108e0dd82f971daaaa20a1dd2a0cddaaae00800621104cbb10c4c810c03d861a8052931daaaa20a1dd2a0c8daaae00800e851c831e0e104161e12bd04a13c0381ef02a0ac10e00800d20315b871e881a0f4c0a811faeee040f4b0aac0b20310a020f4d09bc0c2c9feac7df13a03168c0f662c1ff20f539c9f52030e82a108805582813b0388085a88820879513b030b8816880da0f0f4e0a0f4f79a2f0c121df00c0277b60c6097c097bb062bbab794010c12d805e2030ef2a108f0ee82eaddd20d79cc4d82ccfe16d8081df0b941f991d9a1c9b1ba9af7a91a40a2c081b503b841e00800c8b1b841d8a1b08a82f8918a444040f4b941d9a1c9b1ba9f47a91820a4c081b503b841e00800b841c8b1b08a82d8a18a222020f447b204ba222020f4b7b209ba22ba444040f42020f4b092c09084c01658f620a4c016faf59aada0b4c0167bf5b66c404bcac7b40206d3ffd2c2fc47bd02c6d0ff0c021df0ad0c81ef02bd04e0080086b7fff20f53cd09d2cdfed0d07416bff1f66d0246c5ff2bc9d2cdfed0d07486c2ff1c4b673702c6c3ff70e6c0e73b0286c1fff2c2fef0f4c056dfef0c1286beff000000368100815308324114e008003d0a815208ad02e00800d1540837aa070c0aa25202860000a21202c20114daccc20c00921203a0cc827ce4b2cc1fc0bcb3b0b5211bbb40bb10b252019c69815308e008008ceab21203a21201baaa1baa40aa10a25201a13d03720114c20a000c09076c169089a0a088a082180407e80c1b9990907416b9fe4600000c19313b03513a03d2a0c86619070c0b9201004600000c1b9069a0a066a0bcfb0c4c81e905b803d2060ee2a108e0dd82a2a0c8dabbb20b1dd911aaab50bba0e008000c2cd811b80381e905dabbb20b1da2a0cdaaab50bb90b2cb10e00800d2a0c8812d0792a0d4907782b8037a7872078082a1088077820c4c7abbb20b1d81e905daab50bba0e008000c2cb80381e9057abbb20b1da2a0cdaaab50bb90b2cb10e008004bb6a2a0d281e9050c4ce00800a2a0dc0c1c81e905b2c114e00800312e03815508ad02e00800309ac056a909c21201a21202e20114b154080b9e1bdeba8e820800e0d993d0d074a08882dabbf20b00e2c81fa0ff8280e8b3e0e5211beed2cf1ff0dfb340ee10e0e0f4d0d5211bdd40dd10d0d0f4e7bd2582ccfe8080f4825201920b00a09982f2c91f90f9b3f0f5211bff40ff10f0f0f4873f830609002b9c9090f4925201e20b00a0ee82d2ce1fe0deb3d0d5211bdd40dd10d0d0f4d7b902c6d6ff0c0aa25202815308e00800dc1a91b706920907809901909831cc390c0aa252011df00000366100814d08ad02e008000c0541a50862a0d4606382a212016a44b2048a6d0a8cdb261b0b262b52212e031df02d0b1df0b21202821484921483b73837973b34c2cbfea72c1b81ef02e008009c2a815308e00800ccaa81ac07e00800cc2a0c021df0bd03815808ad02e00800b2120292120156bb0d52448a06ebffa13d0352448a920a0072a0cd0769189d0590b9a0a0bba0b21b0407eb0c1b9990907416b9fe4600000c19313b03d2a0c8513a036619070c0b9201004600000c1b9069a0a066a0bceb0c4cb80372060e82a108807782a2a0c87abbb20b1d81e905aaab50bba0e008000c2cb80381e9057abbb20b1da2a0cdaaab50bb90b2cb10e00800d2a0c872a0cdb80342047482a1088044820c4c4abbb20b1d81e905daab50bba0e00800b8030c2c4abbb20b1d81e9057aab50bb90b2cb10e008004bb6a2a0d281e9050c4ce00800815508ad02e00800a020f41df06099c05659ed52448a06c0ff00000036c1002241003241014911592169317941a2a0de0c1cb2c12022412081e90592211ad20164e22118e951d241189971e00800810609ad01e008002d0a1df00000366100a2a0debd01810c030c1ce008004202030c0761590782a0d48087828a66a2067f920100664a1ef6791b817e03c2166aa21669b20202caaab0aac0bd04e00800cc2a1cb21df0520206820202ac45b6352292166962166a0c239a668066c030a6c0817e03bd04e00800165afd2b333030745733e91b777070746697960c021df000003661000c03ad02a901b15907c2a0d4c0c382cabbc20b7f664c22c801d801721b6ab21b69d21d02c21c015d0dd7b7015d077795392d0b6d0c7d0d060d001b333030746693c30c0351cf0642a0ff30b3a050bba0820b00471809814c08a801e00800fc1a1b333030741613fec60d002d0c6d0b0c14bd0540a78281ef02aaa620aac0e00800dc3aa2a06481b503bd04e008001ce9a7b904212e031df01b444040746694d086e5ff0c021df00000364100ad03bd048159080c0ce00800ad058105070c29d21314f10905e8d30c4c0c0bb24316c24301f0ee10e9d3d25501c2132bc25503b24500924504e00800d22311877d17e203c4076e11bd04a2a4300c2cd2030081e3060c3ee00800815008ad03e008001df0003661004081040c0aa25100165808d172085c5ec20301b2030080cc11cabbb0b0f4a0ca90d0cca0f21c021baab79f5bd21c01d25100e2a410e0ebc0166e09f2a411f0fbc016df0882a42c808bc016480892a42d909bc016b907a2a3fda0abc0162a07c2a418c0cbc0166c050c1abd058175080c1ce00800a0a074bd02ed050c1c817408dd01e00800860c00a0a074e79a8f06e8ffad0581da062bb1e00800167a04c20a11b20300376c413c99979b3c81a50592a0f7909c10924a11e008000c021df0bd02ed050c0a0c1c817408dd01e0080006faff60a074bd02ed050c1c817408dd01e0080006f5ffb20300ad02cd03dd05ed06818908fd04e0080086efff00366100612d0782a0d48082828a66f6721481bd05a206a8e00800816108e00800a24301a2440c81a3080c19f20300f24100e20301e24101d203020be5e0e993d24102d20680c20303c241030c2cb20307b24104bd01a20304a24105a2a410e00800b1b70291b302822631a2262d908820b0aa20a2662d8266311df000368100612d0782a0d48082828a66f6722281bd05a206a8e00800816108e00800bd0aa24301921402a13503b2440ca09920925402220300224100f20305f24101e20301e24102d20302d24103d1b702c20303c24104c2262db20306b24105b1b302a20307d0cc20dd01a24106a226319203089241070c19b0aa20821305824108721305b2a42c70784172410942130642410a22130681740820284122410bf20304f2410ce2030ea26631c2662de2410de206801c0c0ba5a0a993e008001df0003661002060f481a408ad06e008002d0a26e61192a06d97160ba2a081a71605b2a06eb7960262a410624100424102bd010c2c0c190be582a0d460a841a24101808382e0e993312d07a2a3eb8a33811b07d20380e00800c1c203b2232dd223317cfee0e230e0dd10d26331c0bb10b2632d1df000003661002060f481a408ad06e008002d0a26e61192a06d97160ba2a081a71605b2a06eb7960262a42c624100424102bd010c2c0c190be582a0d460a841a24101808382e0e993312d07a2a4288a33816e07d20380e00800c1c203b2232dd223317cfee0e230e0dd10d26331c0bb10b2632d1df000003661002060f481a408ad06e0080082a0d480838231a5082d0a8a3326e60592a06d97960262a4108c959203850c1aa09920924385625100a2a3eabd010c2cd203740c190be4811d07e0e993e00800b1c203a2232ac2232e7cfdd0d230d0cc10c2632eb0aa10a2632a1df000003661002060f481a408ad06e0080082a0d480838231a5082d0a8a3326e60592a06d97960262a42c8c959203850c1aa09920924385625100a2a427bd010c2cd203740c190be4811d07e0e993e00800b1c203a2232ac2232e7cfdd0d230d0cc10c2632eb0aa10a2632a1df0000036410081610341b70691b40852a0d45052825a4451c2036224893224859066105033108066106264893264851df0000036410081a408ad02e0080091b706b2a0d4b0b382ba99922989a70909f6733756d5060c021df0f6734b5655ffc21402c0d014c0c20416dc08ad02bd0381b5082c3ce00800c60200ad02bd0381b6082c3ce008000c121df05675fc92140290d014909204160905ad02bd0381b5082c3ce0080006ebff1695fa92140290d014276926ad02bd0381b5082c3ce0080086f0ff92140290d0142769adad02bd0381b5082c3ce0080086eaffad02bd0381b6082c3ce00800c6e6ffad02bd0381b6082c3ce00800c6d6ffad02bd0381b6082c3ce0080046dfff0000003661000c0351a707cd02c91181c606e00800b2a0d4b0b3825a4b921450a099c016590672048581a80721b70662a1e02a2b6a62ad06e00800ad06b2145181aa072901e008009204852d0a771916a2a412d204780c3e81a907b801c2a1edcabb0c2ce00800d811e20484d7161c271e19224484d20478a2a4130c3e81ab07b801c2a1eccabb0c2ce008001b33303074d2c3f6567df71df0000036a100ad05bd0181da06225108e008007d0ac8da21bc03d19b02f13704e1c103176431b21108d70c02c63500922a11d0ac20a9d7f099209267118201000c1fb678028626000c0f20c920e0da20d9d7c26711862200d78c28922a11d0ac20a9d7f09920926711820100cd0af67802062900e0ca2020b920b267110c02c9d7460200e0fc100c1d0c02f02d838207014109056638420c7a812507bd07e00800bc3a8126070c7ae00800ac9aa21301b21302512e03a7bb6481ef02e00800817b08a25301b20100ad03e0080050aac00c19a09583861400c8d71ca240bc10b9d71df0ad0fdd03ed058174080c1ce00800860300bd07cd03dd02817d08a20100e008000c021df060a074dd03ed058174080c1ce0080046faff0c12c6dbffad03817b08b20100e008009d0afcf9ed02a2a3ea0c2cd20700b2c110811d07f207110c2990ff20f24711e00800cd03bd07817c08a21302a2572b92130192572aa20100e00800b8d740bb10b9d706e5ff50c9c056fcf7ad0798d781500840991099d7e008002c021df0364100c16d044c49a2a108813b03a0a2828808718403aa88820824a13d038088a0a088a08208137827908882b1c1048a778817216c039858a848904b457054a058656838ac4560d4b0d81d576d1de2050620d9105a5e8b55270910b0f510f71d0a204510c039104033203958a04b457054a058656084b0ac558818576821881762050678485a568b55206710270710b0951097160a20b510c0a710b0aa20a9481df0000036610056720e0c0b5c8c213a0381ad02ad02e0080082a0faa2a0f092a1e02c8b0c1c4c6d2c0e0caff24254e24243d24244c24224c24226c24242c24245c24246c2424ab25217b24248b2424b925219a2521882521a81e905a2a1040c099901a252265c0a1c4bb24249bd010c2cc242470c4ce00800813e03a2a0ffe00800818c0320e6030c2a209034972a02206200e00800818d03e00800818e03e00800818f03e00800819003e00800819103e00800819203e00800819303e00800819403e00800819503e00800819603e00800819703e00800819803e0080020e6131020008199039d02e00800819a03e008001df0364100cc3322a0641df00c0c0c0a769306a752011bcc1baabd03a2a06481ee02a0ac82e00800a020741df000368100c1a502613b0342a108404282680632a0a84a663a369206bf52262c67e913a21c2582a0808089201baaa25c258246bfc60400921660b206c20c1a001b4000aaa1a09920925660a2130c0cab92031a8178051b9992431ae00800a2431ba2031a0c07b69a0572431a72530c724316724338817905ad02e00800ad02817a05bd03e00800a2165482263bd13c03913b03c16c039809e13a034a99b2091d92292ce0bba0b80b780eb099c0c099109a77707141d077108077c0d07710f07711a7b7017d0aad02bd07cd010c0d81b8035941e00800d13a03b13b035d0ae80bc135034aee920e79f18103ec090c09b62a0582cafd56d80ea21d1ae20d29aacaa2ca14e0ac83a0a0f4a25100463600262a05264a02665a46ad02b21100817b05c13a03920e1dd22e2cc0e9a0e80ef2263be0ddc0e16c03c80ce0dd10daccd13c03c0c141d0cc10f0ccc0d0cc10f0cc11e00800b13b03c13503d13a03f18103880b1c0e4a888208bfa81f27e825f1a502921f261b99925f26c78a32a20d2c47ea2ce09a20817903924d2ce00800b13b03860600c78a17a20d2c476a1181790392a0ef909a10924d2ce00800b13b038841e80bf1c1024aeec20ebfd2a0fbd0cc10d82ec24ebfc2a0bfa80bf0dd204aaa920abfd92ec09910924abf28230c1a8022c0202a931df0a21100881f9911f7e80fc2165477bc09e20d29cc3ef2a4e2f911bd074bc18bd181d703cbe1e0080066550b8ba1cbb181d6034bc1e00800a8214c4cd831b81181c703dabbe00800b13b03c13503d13a03f18103a24316c6c7ff00000036a1000c067cf849612971dd03d981213b0342a0ff8991890191b703a802520904b2a10840e5c016ee0bb0b58272a0a8baaaf20a797a7a661f19c20ae09c3c818405ad05e0080098a70ba9167a1cb2c9fe161b1c817c03ad05e008004bc1dd01bd0a3d0a817d03ad05e008006d0a0b9a169907166a07a2cafd16ba1fb2c6fe163b19264602665654818505ad05e00800461200a2970a817e03b20712e00800cc3a0c0aa2570ac802d2a108d0d5821c0edaccd20cbfb62602c69a00e0dd200c9a0c0bd24cbf714d0381ae0352474be00800a1b7030c19924a050c0bb991c2c6fc165cf3d2c6fb16fdf228911df0b20716d802c2a108c0c582e13a03caddd20d1da827e0dda0d80df16c03d0eac0f0ee10e73b02c63f00c931b09ac056a617e20738e0e9c0ad050cbbd0cec0d16c03815705d0cc10e00800ed0ae951167a0db14d03a20b5a818605b0aab0a941a20a03e00800c2cafed851c901d73c02862d00913a03e871d831524e00c8028851daccf20c1da088c090ffa0f80f2ba88aff816c032bff80ff108881e13d03f908fd0ae20e00f991e0e004562e06f841f20f01661f5af65a57814d0382087c56e804d20cbfb2a080b0bd10f63a10c2a080c78d55d2071bed09e20e44e73d4aa9a1accb5c0a8bb1810c030c4ce00800b2010892071ba8a1b7b916d831c802daccc82c677c0bf13a03e21700f20f43f7be18b63a0246b6ff984192090126590a26390756b9ec4600000c36a861c871b881524c00390b564aebd8a7d2cdfe561d07e802f2a108f0f582faeef13a03e20e1df0eea0e80e0c2ff991f16c032beef0ee10f881e90f06a2ff817c03ad05e008000c0cdd01bd0a3d0a817d03a2073be008006d0a261a11262a0e263a0b92073b471995663692c6f3ff82a10852073b78028085828a7782a0a88a7786f7ffed0946a1ff920713a2970a16e9dfe61a02067effb20712e802b79a2df2a108f0f582faeed20ebf57ed1f0c2ab2a20e0c1c817f032c09909d20924ebfe008008c7a818003524a08e00800921708a837b16c03a0a3c0b0aa10a7b917c802d2a108d0d582daccd20cbf0c8e576d05e0ed20e24cbf816905ad05e0080056bad7818505ad05e008000c49a06993466cffb2a0efb0dd104663ff368100513a03713b0362a0ff41a803bd03a204050c13671a41820401d13c0380e00407e8109824c215179092c0d09910f09911c72924c807f2a108f0fa82faccc20c17b94180cc01c0c831e61c02066f00817b030c4be00800b8412204040c0d6092c01629219807e2a108e0e2820012409aeec20e79a2ce10ec4cf20e1780ff01f0f831e61f0b820e16808801808831a6180df805e22a37f0f141f0eec0169e21661c05821a741608210c0c00f3a1e21407a2a108a0a282a901f0ee20e254079aaa920a17e805809901909831a6195d9911821a80e0e1e480eec0e0e0e497eb3582054697282fb20551f63b29820a79661823b20545921a7cb7391ae921822a3fc93166981081b003ad02e00800c8310c0de82106140092040c3cba168904e73a45b21408f0bb20b25408460e00820545e21a7c873e2eb21408f0bb20b25408920a7966191fe20a1680ee01e0e831e61e13f22a3fc931669f0b81b003ad02e00800c8310c0d0c0e567c05a2040d9c3a92054797ba0eb801a807baaaa22a3f269a02668a38a805f20548a0a1e4f73e0ee2140ab20549e0eac0e0e0e4e7bb6122040467120f82a10880828228078a222202f5224404a2540ad2440c4611000ce9971ac1a2040c56bafba2040d2204048c3a1baaa2440d60b2c0ed0ac0ec93e2440d164b091c9c6712220caa0c0b914d0381ae03224953c24952e008003244001df02204040c0aa2440d86f0ff1df0b20407679b04a24407bd0adcee81af03e00800b20407c20401a09014a13c039092c030cc20c24401a0991099242d0b671bcb81ae03a14d035c09924a52b24a530c0b0caae00800b807c2a108c0c282cabbb20bf5324400b24407679ba0d20401e2a0fee0dd10d244011df0d2440cd2440df21407821408a805220402224404a0a1e4a2540af08810879f0ad25408a254095c0c060400c21409b2a078c0cac0c0c0e4c73be81c9cd2540786caffcc6ce20af31beee24af398070c1cc677ff366101a2a0dfb2c1100c4c42513c81e9050c1dd941d951e00800a2a0dfb2c11481e9050c4ce00800a2a0dfb2c110810c030c4ce00800a2a0dfb2c114810c030c4ce008000c0ad1b706f2c178c2a3f242113c816007e851984190ee01a099019941e951b2231190ee2080ee20e0bb10b26311c7247747ac02464600ad0381610720b074e00800d22311a1b706d0910416a93da21a04a0a004561a3dbd05a2c1201c0c91be0281d402909d10926311e00800811107e00800b2c120d2c140cd0a811207a2c36ce00800a2c37cb2c14481d4020ccce00800d20300ed07a2a3f3b2c1408113070c2ce008000c021df092a0d297a402063300d2a0d247ad02065800b0e00416be08bd040c02811a06ad02e00800224306ad030c1b810f072c0ce0080046f1ff92a08f9094c0564906a906920507e67205168947a672040ba9160a470c14c1c106b21d4c0c1dc2dcff40bb20b25c4ca672010c0dad03bd020c1c8124077cfee00800dcba0c5a812507bd03e00800166a438126070c5ae0080016ba420c1956f93ab2113c1c1a811a06a906e0080028061df0c2a3fac72471b2611947ac02062300cd05dd040cce0c1fa1b702816207a09b20926311ad03bd02e008002d0a1df0c2a076c7a40286420047ac0206d4ff076bbb42a0a4ad0391b902816307909b20926311e00800bd024ae30c2a1c6c810007d1db05e008000c0a811a061c6cc24303b2113ce00800c6b6ffa2a3f8a7a402c6410047aa02065100ad02bd03cd04dd05ed06816407fd07e00800c6adffb2a433b7a402463f0047ab020652000c1420b074816107ad03e00800424306ad03c20303810f070c0be0080006a2ffc2a3efc7a402865e0047ac02067100ad0381610720b074e008000c2abd03c1e202922311811007c09920926311e00800bd0581d4021c0ce008000c2abd020c8cd1db05e2a0a4810007eae3e008001c6a0c89815c06924303e00800d2a088dad316ca2dad02bd03ed06fd07816507c2a072e008004684ffb2a075b7a40246470047ab0286aaff42a400920305b20503b24306b099c0569918b2113c0c0a811a06a906e00800bd03c203060c0a922311810b07409920926311e008008672ffa2a3f6a0a4c0569ae6ad02bd03cd04816607dd05e00800066cff92a4329094c056f9e420b074816107ad03e00800ad03c203030c0b0c09810f07924306e00800c661ffa2a3f9a0a4c0566ae2bd0fed07a2a3ea0c2c811d07d20300e00800ad03816707bd06e00800c657ff92a43490a4c056eadfb21d04b0b004164b163c3a812507bd03e00800167a158126073c3ae0080016ca143c4a812507bd03e0080016fa138126073c4ae00800164a13ad0320b074ed070c0cdd06f2113c8168075901e00800066bff82a3ee8084c05638da0c0acd02dd0381f4061c3be00800863aff92c48c56c9d80c0a811a06bd04e00800815c061c7ae0080042a0884a43160a1aad02bd03dd04ed06fd07816907c2a070e00800062dff92a3f09094c05639d5d16a07c13704d0bb20c0bb20b26311a67208e1bc03e0eb20e26311ad02bd03cd04dd05ed06816b07fd07e00800c61effad05bd03cd02dd06ed078114070c4fe008008619ff0c2a812507bd03e00800164a098126070c2ae00800169a08b2113c0c0a0c0c811a06c906e00800ad03816c07b20306e008000b9a16f9c2ad030c4b922311812807409920926311e00800a2a3f66bb30c2cd20300816d070c3ee00800e2a0a4920306eae316290abd020c2a3c1c810007d1db05e008003c1992430306fafeed07a2a428b2c1600c2c816e0792a4343c72225131925130d20300e0080029063c721df0b2113c2c5a811a06a906e008000617ff811a06a1bb029223110c0cc24313b2113ca09920926311a806e00800ad038128070c2be008009203051699102caa812507bd03e0080016ba0b8126072caae00800160a0bad030c1b0cac0c09810f07924306e008000601ffbd020c2a1cac810007d1db05e008001ca946d6ff816f07ad0de0080046cffe0c0906f4febd042c1a811a06a906e0080046f4feb11f070c6c814e03922311a2a200a09920926311ad04e00800ecaab1b706b21b0407eb227ba5b1200781d4021c0ce00800ad02bd03dd05ed06fd07816907c2a06fe0080086b8fead04812107bd03e00800bd020c2a1c4cd1db05e2a0a4810007eae3e008001c4906b4ffad03812807b2a104e00800424313ed07a2a3f66bb30c2cd203000c09816d07924306e00800bd020c2a1cbcd1db05e2a0a4810007eae3e008001cbff2430386c9fead0320b074cd05d2113c8170070caee0080046c4fe \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/Readme.txt b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/Readme.txt new file mode 100644 index 000000000000..9adbc9fa07b7 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101/Readme.txt @@ -0,0 +1,22 @@ +-"PS_ASIC.pst" + This file contains radio, system, and firwmare configurabilities. + Details on how the ".pst" format and definitions can be found in the documents folder. + +-"RamPatch.txt" + This file contains firmware fixes for known defects. Atheros will release patch files as needed. + +Both files are required for the system to be operational. + +- "ar3kbdaddr.pst" +This file contains the user configurable Bluetooth Address + +Linux: + +The files have to be copied to "\lib\firmware\" folder. + + +Windows CE. + +The files have to be copied to "platform\\Files" folder. + +Please refer the corresponding documents for the exacts steps to be followed. diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC.pst new file mode 100644 index 000000000000..87d25d40b923 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC.pst @@ -0,0 +1,93 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 01 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 08 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//bit 7: sleep disable/enable, default to enable +//e.g. to disable sleep, clear bit 7: +//[H:A]08 00 00 00 +# +[H:S]0021 +[H:S]0004 +[H:A]88 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 +//Sniff Recovery +# +[H:S]003D +[H:S]0018 +[H:A]A0 0F 00 00 00 08 00 00 0F 00 7D 04 E8 03 01 00 + 01 00 01 05 00 02 1F 01 +//BRM Config +# +[H:S]0026 +[H:S]000C +[H:A]01 20 46 01 0F 02 28 14 01 28 68 01 +//TLPM +//[79:64] - TLPM wakeup timeout in ms, default 10 +//[127:96] - TLPM idle timeout in ms, default 1000 +//e.g. to change the wakeup timeout to 5 and idle timeout to 2000 +//[H:A]03 00 03 00 00 00 00 00 05 00 0A 00 D0 07 00 00 +// E8 03 00 00 E8 03 00 00 +# +[H:S]0023 +[H:S]0018 +[H:A]03 00 03 00 00 00 00 00 0A 00 0A 00 E8 03 00 00 + E8 03 00 00 E8 03 00 00 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclHighPri.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclHighPri.pst new file mode 100644 index 000000000000..87d25d40b923 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclHighPri.pst @@ -0,0 +1,93 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 01 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 08 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//bit 7: sleep disable/enable, default to enable +//e.g. to disable sleep, clear bit 7: +//[H:A]08 00 00 00 +# +[H:S]0021 +[H:S]0004 +[H:A]88 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 +//Sniff Recovery +# +[H:S]003D +[H:S]0018 +[H:A]A0 0F 00 00 00 08 00 00 0F 00 7D 04 E8 03 01 00 + 01 00 01 05 00 02 1F 01 +//BRM Config +# +[H:S]0026 +[H:S]000C +[H:A]01 20 46 01 0F 02 28 14 01 28 68 01 +//TLPM +//[79:64] - TLPM wakeup timeout in ms, default 10 +//[127:96] - TLPM idle timeout in ms, default 1000 +//e.g. to change the wakeup timeout to 5 and idle timeout to 2000 +//[H:A]03 00 03 00 00 00 00 00 05 00 0A 00 D0 07 00 00 +// E8 03 00 00 E8 03 00 00 +# +[H:S]0023 +[H:S]0018 +[H:A]03 00 03 00 00 00 00 00 0A 00 0A 00 E8 03 00 00 + E8 03 00 00 E8 03 00 00 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclLowPri.pst b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclLowPri.pst new file mode 100644 index 000000000000..8f5f8992c2ff --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/PS_ASIC_aclLowPri.pst @@ -0,0 +1,93 @@ + +// Coex Configuration +# +[H:S]0017 +[H:S]0022 +[H:A]d1 d1 20 00 02 01 02 09 0c 00 24 0f 04 00 00 01 + 00 01 00 00 01 01 01 01 01 00 00 00 01 00 00 00 + d2 d2 +// Radio table TAG +# +[H:S]012C +[H:S]0042 +[H:A]B1 B1 12 00 08 00 01 30 06 00 02 00 00 20 02 00 + 04 00 0C 40 01 00 48 00 00 48 54 9A 02 00 00 08 + 02 00 48 00 89 EE 70 E6 38 00 D8 70 EF 52 02 00 + 00 40 00 00 08 00 31 00 00 00 04 00 10 00 00 00 + B2 B2 +// System config TAG +# +[H:S]0013 +[H:S]00B6 +[H:A]C1 C1 17 02 06 00 01 30 55 00 0E CC 33 06 01 08 + 64 96 14 05 FF FF 05 80 00 00 FF CC 00 CC 01 00 + 20 80 FF CC 02 CC 04 00 DF EC 43 F8 00 21 00 E0 + FF CC 03 CC 06 00 80 F0 08 28 80 F4 0C 20 80 F8 + 0E 18 80 FC 14 10 80 00 18 08 80 04 16 00 FF CC + 04 CC 01 00 1A 12 40 96 01 C0 28 00 00 00 C0 01 + 40 06 00 01 00 00 C8 00 00 F0 00 00 FF CC 0C CC + 08 00 01 03 00 7E 08 08 00 7E 01 01 00 7E 01 03 + 00 7E 03 03 00 7E 61 63 00 7E 63 65 00 7E 6A 6C + 00 7E FF CC 09 CC 00 C9 FF CC 0B CC 0A 17 07 B2 + 5E 01 52 0A 60 09 05 06 14 4B 00 00 58 02 D0 07 + 00 41 FF CC C2 C2 +//Extern 32k + 24Mhz CPU +//bit 7: sleep disable/enable, default to enable +//e.g. to disable sleep, clear bit 7: +//[H:A]08 00 00 00 +# +[H:S]0021 +[H:S]0004 +[H:A]88 00 00 00 +//Bdaddr +//# +//[H:S]0001 +//[H:S]0006 +//[H:A]89 60 41 7f 03 00 +//Audio +# +[H:S]0002 +[H:S]0004 +[H:A]23 08 01 33 +//Audio +# +[H:S]0003 +[H:S]0004 +[H:A]dd e5 2e 00 +//Audio +# +[H:S]0015 +[H:S]0004 +[H:A]12 00 00 00 +//Audio +# +[H:S]0016 +[H:S]0004 +[H:A]00 00 a7 02 +# +//PLC +[H:S]001F +[H:S]0008 +[H:A]01 1A 06 14 50 B4 32 96 +//Sniff Recovery +# +[H:S]003D +[H:S]0018 +[H:A]A0 0F 00 00 00 08 00 00 0F 00 7D 04 E8 03 01 00 + 01 00 01 05 00 02 1F 01 +//BRM Config +# +[H:S]0026 +[H:S]000C +[H:A]01 20 46 01 0F 02 28 14 01 28 68 01 +//TLPM +//[79:64] - TLPM wakeup timeout in ms, default 10 +//[127:96] - TLPM idle timeout in ms, default 1000 +//e.g. to change the wakeup timeout to 5 and idle timeout to 2000 +//[H:A]03 00 03 00 00 00 00 00 05 00 0A 00 D0 07 00 00 +// E8 03 00 00 E8 03 00 00 +# +[H:S]0023 +[H:S]0018 +[H:A]03 00 03 00 00 00 00 00 0A 00 0A 00 E8 03 00 00 + E8 03 00 00 E8 03 00 00 diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/RamPatch.txt b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/RamPatch.txt new file mode 100644 index 000000000000..107fd0ff80c5 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3k/30101coex/RamPatch.txt @@ -0,0 +1,2 @@ +21c7 +000000000e20000050800000000158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d8d5530024e7530030e1530060e15300ece1530070e353008ce4530054e1530088e1530040af530088e353008ce35300d4e25300d8e25300fce253003ce3530024e3530054e3530030dd530024b0530078d553000000000000000000000000000000000030d553002ca05300000000000000000000000000000000000000000080019800d80198006c029800ec049800fc0698005c0898009c08980020099800cc099800340a9800340b9800b00b9800700c9800e40c9800580d9800c40d9800300e9800600e9800380f9800d00f9800541198000000000000000000000000000000000084189800501b98000000000000000000000000000000000000000000364100813a03416f0382085148041618040c13bc040c07613b030c02680676942252a1085052821b225a564205062020742654052634026644079205bf1769011b773df04600000c077048c00c024023831df00c021df000364100569208c0200021ce0991f3020c04426992c0200042699398128d04ed0916c9063d09a802c859b809b912a90999028c9ca21e06b82ee00c00860300a21e088bce5c0b81d6020c8de0080098120c4bbcb9c1f302d819c02000ed0cd26c90dd0cc02000426c93c02000a812b26c92a81ac02000b22c910c0cb0bac0a61b04e813a79e0ac0200081f3020c1ff268931df0000036a100a2a0dcbd01810c030c1ce00800a2a0d24bb10c4c421202521201612d0782010092a0d49088827202008a26220280810c030c16e00800313d030c09a203005981076a1690b9a030bba0b21b0407eb0c1b9990907416b9fe4600000c196619040c09c600006d090c19cc290c121df00c2c7951810c03513b03b2a108b0b282b961a8050c02225104baaaa20a1db2a0cdbaaa8bb1e00800721104810c032931a80560d6a0303da0b2030ec2a108c0bb820c4cbaaaa20a1db2a0c8baaacbb1e008008bb10c2c810c03225104a805f831d2030ee2a108e0dd82f971daaaa20a1dd2a0cddaaae00800621104cbb10c4c810c03d861a8052931daaaa20a1dd2a0c8daaae00800e851c831e0e104161e12bd04a13c0381ef02a0ac10e00800d20315b871e881a0f4c0a811faeee040f4b0aac0b20310a020f4d09bc0c2c9feac7df13a03168c0f662c1ff20f539c9f52030e82a108805582813b0388085a88820879513b030b8816880da0f0f4e0a0f4f79a2f0c121df00c0277b60c6097c097bb062bbab794010c12d805e2030ef2a108f0ee82eaddd20d79cc4d82ccfe16d8081df0b941f991d9a1c9b1ba9af7a91a40a2c081b503b841e00800c8b1b841d8a1b08a82f8918a444040f4b941d9a1c9b1ba9f47a91820a4c081b503b841e00800b841c8b1b08a82d8a18a222020f447b204ba222020f4b7b209ba22ba444040f42020f4b092c09084c01658f620a4c016faf59aada0b4c0167bf5b66c404bcac7b40206d3ffd2c2fc47bd02c6d0ff0c021df0ad0c81ef02bd04e0080086b7fff20f53cd09d2cdfed0d07416bff1f66d0246c5ff2bc9d2cdfed0d07486c2ff1c4b673702c6c3ff70e6c0e73b0286c1fff2c2fef0f4c056dfef0c1286beff000000368100815308324114e008003d0a815208ad02e00800d1540837aa070c0aa25202860000a21202c20114daccc20c00921203a0cc827ce4b2cc1fc0bcb3b0b5211bbb40bb10b252019c69815308e008008ceab21203a21201baaa1baa40aa10a25201a13d03720114c20a000c09076c169089a0a088a082180407e80c1b9990907416b9fe4600000c19313b03513a03d2a0c86619070c0b9201004600000c1b9069a0a066a0bcfb0c4c81e905b803d2060ee2a108e0dd82a2a0c8dabbb20b1dd911aaab50bba0e008000c2cd811b80381e905dabbb20b1da2a0cdaaab50bb90b2cb10e00800d2a0c8812d0792a0d4907782b8037a7872078082a1088077820c4c7abbb20b1d81e905daab50bba0e008000c2cb80381e9057abbb20b1da2a0cdaaab50bb90b2cb10e008004bb6a2a0d281e9050c4ce00800a2a0dc0c1c81e905b2c114e00800312e03815508ad02e00800309ac056a909c21201a21202e20114b154080b9e1bdeba8e820800e0d993d0d074a08882dabbf20b00e2c81fa0ff8280e8b3e0e5211beed2cf1ff0dfb340ee10e0e0f4d0d5211bdd40dd10d0d0f4e7bd2582ccfe8080f4825201920b00a09982f2c91f90f9b3f0f5211bff40ff10f0f0f4873f830609002b9c9090f4925201e20b00a0ee82d2ce1fe0deb3d0d5211bdd40dd10d0d0f4d7b902c6d6ff0c0aa25202815308e00800dc1a91b706920907809901909831cc390c0aa252011df00000366100814d08ad02e008000c0541a50862a0d4606382a212016a44b2048a6d0a8cdb261b0b262b52212e031df02d0b1df0b21202821484921483b73837973b34c2cbfea72c1b81ef02e008009c2a815308e00800ccaa81ac07e00800cc2a0c021df0bd03815808ad02e00800b2120292120156bb0d52448a06ebffa13d0352448a920a0072a0cd0769189d0590b9a0a0bba0b21b0407eb0c1b9990907416b9fe4600000c19313b03d2a0c8513a036619070c0b9201004600000c1b9069a0a066a0bceb0c4cb80372060e82a108807782a2a0c87abbb20b1d81e905aaab50bba0e008000c2cb80381e9057abbb20b1da2a0cdaaab50bb90b2cb10e00800d2a0c872a0cdb80342047482a1088044820c4c4abbb20b1d81e905daab50bba0e00800b8030c2c4abbb20b1d81e9057aab50bb90b2cb10e008004bb6a2a0d281e9050c4ce00800815508ad02e00800a020f41df06099c05659ed52448a06c0ff00000036c1002241003241014911592169317941a2a0de0c1cb2c12022412081e90592211ad20164e22118e951d241189971e00800810609ad01e008002d0a1df00000366100a2a0debd01810c030c1ce008004202030c0761590782a0d48087828a66a2067f920100664a1ef6791b817e03c2166aa21669b20202caaab0aac0bd04e00800cc2a1cb21df0520206820202ac45b6352292166962166a0c239a668066c030a6c0817e03bd04e00800165afd2b333030745733e91b777070746697960c021df000003661000c03ad02a901b15907c2a0d4c0c382cabbc20b7f664c22c801d801721b6ab21b69d21d02c21c015d0dd7b7015d077795392d0b6d0c7d0d060d001b333030746693c30c0351cf0642a0ff30b3a050bba0820b00471809814c08a801e00800fc1a1b333030741613fec60d002d0c6d0b0c14bd0540a78281ef02aaa620aac0e00800dc3aa2a06481b503bd04e008001ce9a7b904212e031df01b444040746694d086e5ff0c021df00000364100ad03bd048159080c0ce00800ad058105070c29d21314f10905e8d30c4c0c0bb24316c24301f0ee10e9d3d25501c2132bc25503b24500924504e00800d22311877d17e203c4076e11bd04a2a4300c2cd2030081e3060c3ee00800815008ad03e008001df0003661004081040c0aa25100165808d172085c5ec20301b2030080cc11cabbb0b0f4a0ca90d0cca0f21c021baab79f5bd21c01d25100e2a410e0ebc0166e09f2a411f0fbc016df0882a42c808bc016480892a42d909bc016b907a2a3fda0abc0162a07c2a418c0cbc0166c050c1abd058175080c1ce00800a0a074bd02ed050c1c817408dd01e00800860c00a0a074e79a8f06e8ffad0581da062bb1e00800167a04c20a11b20300376c413c99979b3c81a50592a0f7909c10924a11e008000c021df0bd02ed050c0a0c1c817408dd01e0080006faff60a074bd02ed050c1c817408dd01e0080006f5ffb20300ad02cd03dd05ed06818908fd04e0080086efff00366100612d0782a0d48082828a66f6721481bd05a206a8e00800816108e00800a24301a2440c81a3080c19f20300f24100e20301e24101d203020be5e0e993d24102d20680c20303c241030c2cb20307b24104bd01a20304a24105a2a410e00800b1b70291b302822631a2262d908820b0aa20a2662d8266311df000368100612d0782a0d48082828a66f6722281bd05a206a8e00800816108e00800bd0aa24301921402a13503b2440ca09920925402220300224100f20305f24101e20301e24102d20302d24103d1b702c20303c24104c2262db20306b24105b1b302a20307d0cc20dd01a24106a226319203089241070c19b0aa20821305824108721305b2a42c70784172410942130642410a22130681740820284122410bf20304f2410ce2030ea26631c2662de2410de206801c0c0ba5a0a993e008001df0003661002060f481a408ad06e008002d0a26e61192a06d97160ba2a081a71605b2a06eb7960262a410624100424102bd010c2c0c190be582a0d460a841a24101808382e0e993312d07a2a3eb8a33811b07d20380e00800c1c203b2232dd223317cfee0e230e0dd10d26331c0bb10b2632d1df000003661002060f481a408ad06e008002d0a26e61192a06d97160ba2a081a71605b2a06eb7960262a42c624100424102bd010c2c0c190be582a0d460a841a24101808382e0e993312d07a2a4288a33816e07d20380e00800c1c203b2232dd223317cfee0e230e0dd10d26331c0bb10b2632d1df000003661002060f481a408ad06e0080082a0d480838231a5082d0a8a3326e60592a06d97960262a4108c959203850c1aa09920924385625100a2a3eabd010c2cd203740c190be4811d07e0e993e00800b1c203a2232ac2232e7cfdd0d230d0cc10c2632eb0aa10a2632a1df000003661002060f481a408ad06e0080082a0d480838231a5082d0a8a3326e60592a06d97960262a42c8c959203850c1aa09920924385625100a2a427bd010c2cd203740c190be4811d07e0e993e00800b1c203a2232ac2232e7cfdd0d230d0cc10c2632eb0aa10a2632a1df0000036410081610341b70691b40852a0d45052825a4451c2036224893224859066105033108066106264893264851df0000036410081a408ad02e0080091b706b2a0d4b0b382ba99922989a70909f6733756d5060c021df0f6734b5655ffc21402c0d014c0c20416dc08ad02bd0381b5082c3ce00800c60200ad02bd0381b6082c3ce008000c121df05675fc92140290d014909204160905ad02bd0381b5082c3ce0080006ebff1695fa92140290d014276926ad02bd0381b5082c3ce0080086f0ff92140290d0142769adad02bd0381b5082c3ce0080086eaffad02bd0381b6082c3ce00800c6e6ffad02bd0381b6082c3ce00800c6d6ffad02bd0381b6082c3ce0080046dfff0000003661000c0351a707cd02c91181c606e00800b2a0d4b0b3825a4b921450a099c016590672048581a80721b70662a1e02a2b6a62ad06e00800ad06b2145181aa072901e008009204852d0a771916a2a412d204780c3e81a907b801c2a1edcabb0c2ce00800d811e20484d7161c271e19224484d20478a2a4130c3e81ab07b801c2a1eccabb0c2ce008001b33303074d2c3f6567df71df0000036a100ad05bd0181da06225108e008007d0ac8da21bc03d19b02f13704e1c103176431b21108d70c02c63500922a11d0ac20a9d7f099209267118201000c1fb678028626000c0f20c920e0da20d9d7c26711862200d78c28922a11d0ac20a9d7f09920926711820100cd0af67802062900e0ca2020b920b267110c02c9d7460200e0fc100c1d0c02f02d838207014109056638420c7a812507bd07e00800bc3a8126070c7ae00800ac9aa21301b21302512e03a7bb6481ef02e00800817b08a25301b20100ad03e0080050aac00c19a09583861400c8d71ca240bc10b9d71df0ad0fdd03ed058174080c1ce00800860300bd07cd03dd02817d08a20100e008000c021df060a074dd03ed058174080c1ce0080046faff0c12c6dbffad03817b08b20100e008009d0afcf9ed02a2a3ea0c2cd20700b2c110811d07f207110c2990ff20f24711e00800cd03bd07817c08a21302a2572b92130192572aa20100e00800b8d740bb10b9d706e5ff50c9c056fcf7ad0798d781500840991099d7e008002c021df0364100c16d044c49a2a108813b03a0a2828808718403aa88820824a13d038088a0a088a08208137827908882b1c1048a778817216c039858a848904b457054a058656838ac4560d4b0d81d576d1de2050620d9105a5e8b55270910b0f510f71d0a204510c039104033203958a04b457054a058656084b0ac558818576821881762050678485a568b55206710270710b0951097160a20b510c0a710b0aa20a9481df0000036610056720e0c0b5c8c213a0381ad02ad02e0080082a0faa2a0f092a1e02c8b0c1c4c6d2c0e0caff24254e24243d24244c24224c24226c24242c24245c24246c2424ab25217b24248b2424b925219a2521882521a81e905a2a1040c099901a252265c0a1c4bb24249bd010c2cc242470c4ce00800813e03a2a0ffe00800818c0320e6030c2a209034972a02206200e00800818d03e00800818e03e00800818f03e00800819003e00800819103e00800819203e00800819303e00800819403e00800819503e00800819603e00800819703e00800819803e0080020e6131020008199039d02e00800819a03e008001df0364100cc3322a0641df00c0c0c0a769306a752011bcc1baabd03a2a06481ee02a0ac82e00800a020741df000368100c1a502613b0342a108404282680632a0a84a663a369206bf52262c67e913a21c2582a0808089201baaa25c258246bfc60400921660b206c20c1a001b4000aaa1a09920925660a2130c0cab92031a8178051b9992431ae00800a2431ba2031a0c07b69a0572431a72530c724316724338817905ad02e00800ad02817a05bd03e00800a2165482263bd13c03913b03c16c039809e13a034a99b2091d92292ce0bba0b80b780eb099c0c099109a77707141d077108077c0d07710f07711a7b7017d0aad02bd07cd010c0d81b8035941e00800d13a03b13b035d0ae80bc135034aee920e79f18103ec090c09b62a0582cafd56d80ea21d1ae20d29aacaa2ca14e0ac83a0a0f4a25100463600262a05264a02665a46ad02b21100817b05c13a03920e1dd22e2cc0e9a0e80ef2263be0ddc0e16c03c80ce0dd10daccd13c03c0c141d0cc10f0ccc0d0cc10f0cc11e00800b13b03c13503d13a03f18103880b1c0e4a888208bfa81f27e825f1a502921f261b99925f26c78a32a20d2c47ea2ce09a20817903924d2ce00800b13b03860600c78a17a20d2c476a1181790392a0ef909a10924d2ce00800b13b038841e80bf1c1024aeec20ebfd2a0fbd0cc10d82ec24ebfc2a0bfa80bf0dd204aaa920abfd92ec09910924abf28230c1a8022c0202a931df0a21100881f9911f7e80fc2165477bc09e20d29cc3ef2a4e2f911bd074bc18bd181d703cbe1e0080066550b8ba1cbb181d6034bc1e00800a8214c4cd831b81181c703dabbe00800b13b03c13503d13a03f18103a24316c6c7ff00000036a1000c067cf849612971dd03d981213b0342a0ff8991890191b703a802520904b2a10840e5c016ee0bb0b58272a0a8baaaf20a797a7a661f19c20ae09c3c818405ad05e0080098a70ba9167a1cb2c9fe161b1c817c03ad05e008004bc1dd01bd0a3d0a817d03ad05e008006d0a0b9a169907166a07a2cafd16ba1fb2c6fe163b19264602665654818505ad05e00800461200a2970a817e03b20712e00800cc3a0c0aa2570ac802d2a108d0d5821c0edaccd20cbfb62602c69a00e0dd200c9a0c0bd24cbf714d0381ae0352474be00800a1b7030c19924a050c0bb991c2c6fc165cf3d2c6fb16fdf228911df0b20716d802c2a108c0c582e13a03caddd20d1da827e0dda0d80df16c03d0eac0f0ee10e73b02c63f00c931b09ac056a617e20738e0e9c0ad050cbbd0cec0d16c03815705d0cc10e00800ed0ae951167a0db14d03a20b5a818605b0aab0a941a20a03e00800c2cafed851c901d73c02862d00913a03e871d831524e00c8028851daccf20c1da088c090ffa0f80f2ba88aff816c032bff80ff108881e13d03f908fd0ae20e00f991e0e004562e06f841f20f01661f5af65a57814d0382087c56e804d20cbfb2a080b0bd10f63a10c2a080c78d55d2071bed09e20e44e73d4aa9a1accb5c0a8bb1810c030c4ce00800b2010892071ba8a1b7b916d831c802daccc82c677c0bf13a03e21700f20f43f7be18b63a0246b6ff984192090126590a26390756b9ec4600000c36a861c871b881524c00390b564aebd8a7d2cdfe561d07e802f2a108f0f582faeef13a03e20e1df0eea0e80e0c2ff991f16c032beef0ee10f881e90f06a2ff817c03ad05e008000c0cdd01bd0a3d0a817d03a2073be008006d0a261a11262a0e263a0b92073b471995663692c6f3ff82a10852073b78028085828a7782a0a88a7786f7ffed0946a1ff920713a2970a16e9dfe61a02067effb20712e802b79a2df2a108f0f582faeed20ebf57ed1f0c2ab2a20e0c1c817f032c09909d20924ebfe008008c7a818003524a08e00800921708a837b16c03a0a3c0b0aa10a7b917c802d2a108d0d582daccd20cbf0c8e576d05e0ed20e24cbf816905ad05e0080056bad7818505ad05e008000c49a06993466cffb2a0efb0dd104663ff368100513a03713b0362a0ff41a803bd03a204050c13671a41820401d13c0380e00407e8109824c215179092c0d09910f09911c72924c807f2a108f0fa82faccc20c17b94180cc01c0c831e61c02066f00817b030c4be00800b8412204040c0d6092c01629219807e2a108e0e2820012409aeec20e79a2ce10ec4cf20e1780ff01f0f831e61f0b820e16808801808831a6180df805e22a37f0f141f0eec0169e21661c05821a741608210c0c00f3a1e21407a2a108a0a282a901f0ee20e254079aaa920a17e805809901909831a6195d9911821a80e0e1e480eec0e0e0e497eb3582054697282fb20551f63b29820a79661823b20545921a7cb7391ae921822a3fc93166981081b003ad02e00800c8310c0de82106140092040c3cba168904e73a45b21408f0bb20b25408460e00820545e21a7c873e2eb21408f0bb20b25408920a7966191fe20a1680ee01e0e831e61e13f22a3fc931669f0b81b003ad02e00800c8310c0d0c0e567c05a2040d9c3a92054797ba0eb801a807baaaa22a3f269a02668a38a805f20548a0a1e4f73e0ee2140ab20549e0eac0e0e0e4e7bb6122040467120f82a10880828228078a222202f5224404a2540ad2440c4611000ce9971ac1a2040c56bafba2040d2204048c3a1baaa2440d60b2c0ed0ac0ec93e2440d164b091c9c6712220caa0c0b914d0381ae03224953c24952e008003244001df02204040c0aa2440d86f0ff1df0b20407679b04a24407bd0adcee81af03e00800b20407c20401a09014a13c039092c030cc20c24401a0991099242d0b671bcb81ae03a14d035c09924a52b24a530c0b0caae00800b807c2a108c0c282cabbb20bf5324400b24407679ba0d20401e2a0fee0dd10d244011df0d2440cd2440df21407821408a805220402224404a0a1e4a2540af08810879f0ad25408a254095c0c060400c21409b2a078c0cac0c0c0e4c73be81c9cd2540786caffcc6ce20af31beee24af398070c1cc677ff366101a2a0dfb2c1100c4c42513c81e9050c1dd941d951e00800a2a0dfb2c11481e9050c4ce00800a2a0dfb2c110810c030c4ce00800a2a0dfb2c114810c030c4ce008000c0ad1b706f2c178c2a3f242113c816007e851984190ee01a099019941e951b2231190ee2080ee20e0bb10b26311c7247747ac02464600ad0381610720b074e00800d22311a1b706d0910416a93da21a04a0a004561a3dbd05a2c1201c0c91be0281d402909d10926311e00800811107e00800b2c120d2c140cd0a811207a2c36ce00800a2c37cb2c14481d4020ccce00800d20300ed07a2a3f3b2c1408113070c2ce008000c021df092a0d297a402063300d2a0d247ad02065800b0e00416be08bd040c02811a06ad02e00800224306ad030c1b810f072c0ce0080046f1ff92a08f9094c0564906a906920507e67205168947a672040ba9160a470c14c1c106b21d4c0c1dc2dcff40bb20b25c4ca672010c0dad03bd020c1c8124077cfee00800dcba0c5a812507bd03e00800166a438126070c5ae0080016ba420c1956f93ab2113c1c1a811a06a906e0080028061df0c2a3fac72471b2611947ac02062300cd05dd040cce0c1fa1b702816207a09b20926311ad03bd02e008002d0a1df0c2a076c7a40286420047ac0206d4ff076bbb42a0a4ad0391b902816307909b20926311e00800bd024ae30c2a1c6c810007d1db05e008000c0a811a061c6cc24303b2113ce00800c6b6ffa2a3f8a7a402c6410047aa02065100ad02bd03cd04dd05ed06816407fd07e00800c6adffb2a433b7a402463f0047ab020652000c1420b074816107ad03e00800424306ad03c20303810f070c0be0080006a2ffc2a3efc7a402865e0047ac02067100ad0381610720b074e008000c2abd03c1e202922311811007c09920926311e00800bd0581d4021c0ce008000c2abd020c8cd1db05e2a0a4810007eae3e008001c6a0c89815c06924303e00800d2a088dad316ca2dad02bd03ed06fd07816507c2a072e008004684ffb2a075b7a40246470047ab0286aaff42a400920305b20503b24306b099c0569918b2113c0c0a811a06a906e00800bd03c203060c0a922311810b07409920926311e008008672ffa2a3f6a0a4c0569ae6ad02bd03cd04816607dd05e00800066cff92a4329094c056f9e420b074816107ad03e00800ad03c203030c0b0c09810f07924306e00800c661ffa2a3f9a0a4c0566ae2bd0fed07a2a3ea0c2c811d07d20300e00800ad03816707bd06e00800c657ff92a43490a4c056eadfb21d04b0b004164b163c3a812507bd03e00800167a158126073c3ae0080016ca143c4a812507bd03e0080016fa138126073c4ae00800164a13ad0320b074ed070c0cdd06f2113c8168075901e00800066bff82a3ee8084c05638da0c0acd02dd0381f4061c3be00800863aff92c48c56c9d80c0a811a06bd04e00800815c061c7ae0080042a0884a43160a1aad02bd03dd04ed06fd07816907c2a070e00800062dff92a3f09094c05639d5d16a07c13704d0bb20c0bb20b26311a67208e1bc03e0eb20e26311ad02bd03cd04dd05ed06816b07fd07e00800c61effad05bd03cd02dd06ed078114070c4fe008008619ff0c2a812507bd03e00800164a098126070c2ae00800169a08b2113c0c0a0c0c811a06c906e00800ad03816c07b20306e008000b9a16f9c2ad030c4b922311812807409920926311e00800a2a3f66bb30c2cd20300816d070c3ee00800e2a0a4920306eae316290abd020c2a3c1c810007d1db05e008003c1992430306fafeed07a2a428b2c1600c2c816e0792a4343c72225131925130d20300e0080029063c721df0b2113c2c5a811a06a906e008000617ff811a06a1bb029223110c0cc24313b2113ca09920926311a806e00800ad038128070c2be008009203051699102caa812507bd03e0080016ba0b8126072caae00800160a0bad030c1b0cac0c09810f07924306e008000601ffbd020c2a1cac810007d1db05e008001ca946d6ff816f07ad0de0080046cffe0c0906f4febd042c1a811a06a906e0080046f4feb11f070c6c814e03922311a2a200a09920926311ad04e00800ecaab1b706b21b0407eb227ba5b1200781d4021c0ce00800ad02bd03dd05ed06fd07816907c2a06fe0080086b8fead04812107bd03e00800bd020c2a1c4cd1db05e2a0a4810007eae3e008001c4906b4ffad03812807b2a104e00800424313ed07a2a3f66bb30c2cd203000c09816d07924306e00800bd020c2a1cbcd1db05e2a0a4810007eae3e008001cbff2430386c9fead0320b074cd05d2113c8170070caee0080046c4fe \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3kconfig.c b/drivers/net/wireless/ar6003/host/miscdrv/ar3kconfig.c new file mode 100644 index 000000000000..5965b3fcc517 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3kconfig.c @@ -0,0 +1,569 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// AR3K configuration implementation +// +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME misc +#include "a_debug.h" +#include "common_drv.h" +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +#include "export_hci_transport.h" +#else +#include "hci_transport_api.h" +#endif +#include "ar3kconfig.h" +#include "tlpm.h" + +#define BAUD_CHANGE_COMMAND_STATUS_OFFSET 5 +#define HCI_EVENT_RESP_TIMEOUTMS 3000 +#define HCI_CMD_OPCODE_BYTE_LOW_OFFSET 0 +#define HCI_CMD_OPCODE_BYTE_HI_OFFSET 1 +#define HCI_EVENT_OPCODE_BYTE_LOW 3 +#define HCI_EVENT_OPCODE_BYTE_HI 4 +#define HCI_CMD_COMPLETE_EVENT_CODE 0xE +#define HCI_MAX_EVT_RECV_LENGTH 257 +#define EXIT_MIN_BOOT_COMMAND_STATUS_OFFSET 5 + +A_STATUS AthPSInitialize(AR3K_CONFIG_INFO *hdev); + +static A_STATUS SendHCICommand(AR3K_CONFIG_INFO *pConfig, + A_UINT8 *pBuffer, + int Length) +{ + HTC_PACKET *pPacket = NULL; + A_STATUS status = A_OK; + + do { + + pPacket = (HTC_PACKET *)A_MALLOC(sizeof(HTC_PACKET)); + if (NULL == pPacket) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pPacket,sizeof(HTC_PACKET)); + SET_HTC_PACKET_INFO_TX(pPacket, + NULL, + pBuffer, + Length, + HCI_COMMAND_TYPE, + AR6K_CONTROL_PKT_TAG); + + /* issue synchronously */ + status = HCI_TransportSendPkt(pConfig->pHCIDev,pPacket,TRUE); + + } while (FALSE); + + if (pPacket != NULL) { + A_FREE(pPacket); + } + + return status; +} + +static A_STATUS RecvHCIEvent(AR3K_CONFIG_INFO *pConfig, + A_UINT8 *pBuffer, + int *pLength) +{ + A_STATUS status = A_OK; + HTC_PACKET *pRecvPacket = NULL; + + do { + + pRecvPacket = (HTC_PACKET *)A_MALLOC(sizeof(HTC_PACKET)); + if (NULL == pRecvPacket) { + status = A_NO_MEMORY; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to alloc HTC struct \n")); + break; + } + + A_MEMZERO(pRecvPacket,sizeof(HTC_PACKET)); + + SET_HTC_PACKET_INFO_RX_REFILL(pRecvPacket,NULL,pBuffer,*pLength,HCI_EVENT_TYPE); + + status = HCI_TransportRecvHCIEventSync(pConfig->pHCIDev, + pRecvPacket, + HCI_EVENT_RESP_TIMEOUTMS); + if (A_FAILED(status)) { + break; + } + + *pLength = pRecvPacket->ActualLength; + + } while (FALSE); + + if (pRecvPacket != NULL) { + A_FREE(pRecvPacket); + } + + return status; +} + +A_STATUS SendHCICommandWaitCommandComplete(AR3K_CONFIG_INFO *pConfig, + A_UINT8 *pHCICommand, + int CmdLength, + A_UINT8 **ppEventBuffer, + A_UINT8 **ppBufferToFree) +{ + A_STATUS status = A_OK; + A_UINT8 *pBuffer = NULL; + A_UINT8 *pTemp; + int length; + A_BOOL commandComplete = FALSE; + A_UINT8 opCodeBytes[2]; + + do { + + length = max(HCI_MAX_EVT_RECV_LENGTH,CmdLength); + length += pConfig->pHCIProps->HeadRoom + pConfig->pHCIProps->TailRoom; + length += pConfig->pHCIProps->IOBlockPad; + + pBuffer = (A_UINT8 *)A_MALLOC(length); + if (NULL == pBuffer) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: Failed to allocate bt buffer \n")); + status = A_NO_MEMORY; + break; + } + + /* get the opcodes to check the command complete event */ + opCodeBytes[0] = pHCICommand[HCI_CMD_OPCODE_BYTE_LOW_OFFSET]; + opCodeBytes[1] = pHCICommand[HCI_CMD_OPCODE_BYTE_HI_OFFSET]; + + /* copy HCI command */ + A_MEMCPY(pBuffer + pConfig->pHCIProps->HeadRoom,pHCICommand,CmdLength); + /* send command */ + status = SendHCICommand(pConfig, + pBuffer + pConfig->pHCIProps->HeadRoom, + CmdLength); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: Failed to send HCI Command (%d) \n", status)); + AR_DEBUG_PRINTBUF(pHCICommand,CmdLength,"HCI Bridge Failed HCI Command"); + break; + } + + /* reuse buffer to capture command complete event */ + A_MEMZERO(pBuffer,length); + status = RecvHCIEvent(pConfig,pBuffer,&length); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: HCI event recv failed \n")); + AR_DEBUG_PRINTBUF(pHCICommand,CmdLength,"HCI Bridge Failed HCI Command"); + break; + } + + pTemp = pBuffer + pConfig->pHCIProps->HeadRoom; + if (pTemp[0] == HCI_CMD_COMPLETE_EVENT_CODE) { + if ((pTemp[HCI_EVENT_OPCODE_BYTE_LOW] == opCodeBytes[0]) && + (pTemp[HCI_EVENT_OPCODE_BYTE_HI] == opCodeBytes[1])) { + commandComplete = TRUE; + } + } + + if (!commandComplete) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: Unexpected HCI event : %d \n",pTemp[0])); + AR_DEBUG_PRINTBUF(pTemp,pTemp[1],"Unexpected HCI event"); + status = A_ECOMM; + break; + } + + if (ppEventBuffer != NULL) { + /* caller wants to look at the event */ + *ppEventBuffer = pTemp; + if (ppBufferToFree == NULL) { + status = A_EINVAL; + break; + } + /* caller must free the buffer */ + *ppBufferToFree = pBuffer; + pBuffer = NULL; + } + + } while (FALSE); + + if (pBuffer != NULL) { + A_FREE(pBuffer); + } + + return status; +} + +static A_STATUS AR3KConfigureHCIBaud(AR3K_CONFIG_INFO *pConfig) +{ + A_STATUS status = A_OK; + A_UINT8 hciBaudChangeCommand[] = {0x0c,0xfc,0x2,0,0}; + A_UINT16 baudVal; + A_UINT8 *pEvent = NULL; + A_UINT8 *pBufferToFree = NULL; + + do { + + if (pConfig->Flags & AR3K_CONFIG_FLAG_SET_AR3K_BAUD) { + baudVal = (A_UINT16)(pConfig->AR3KBaudRate / 100); + hciBaudChangeCommand[3] = (A_UINT8)baudVal; + hciBaudChangeCommand[4] = (A_UINT8)(baudVal >> 8); + + status = SendHCICommandWaitCommandComplete(pConfig, + hciBaudChangeCommand, + sizeof(hciBaudChangeCommand), + &pEvent, + &pBufferToFree); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: Baud rate change failed! \n")); + break; + } + + if (pEvent[BAUD_CHANGE_COMMAND_STATUS_OFFSET] != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("AR3K Config: Baud change command event status failed: %d \n", + pEvent[BAUD_CHANGE_COMMAND_STATUS_OFFSET])); + status = A_ECOMM; + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("AR3K Config: Baud Changed to %d \n",pConfig->AR3KBaudRate)); + } + + if (pConfig->Flags & AR3K_CONFIG_FLAG_AR3K_BAUD_CHANGE_DELAY) { + /* some versions of AR3K do not switch baud immediately, up to 300MS */ + A_MDELAY(325); + } + + if (pConfig->Flags & AR3K_CONFIG_FLAG_SET_AR6K_SCALE_STEP) { + /* Tell target to change UART baud rate for AR6K */ + status = HCI_TransportSetBaudRate(pConfig->pHCIDev, pConfig->AR3KBaudRate); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("AR3K Config: failed to set scale and step values: %d \n", status)); + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY, + ("AR3K Config: Baud changed to %d for AR6K\n", pConfig->AR3KBaudRate)); + } + + } while (FALSE); + + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + + return status; +} + +static A_STATUS AR3KExitMinBoot(AR3K_CONFIG_INFO *pConfig) +{ + A_STATUS status; + A_CHAR exitMinBootCmd[] = {0x25,0xFC,0x0c,0x03,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00}; + A_UINT8 *pEvent = NULL; + A_UINT8 *pBufferToFree = NULL; + + status = SendHCICommandWaitCommandComplete(pConfig, + exitMinBootCmd, + sizeof(exitMinBootCmd), + &pEvent, + &pBufferToFree); + + if (A_SUCCESS(status)) { + if (pEvent[EXIT_MIN_BOOT_COMMAND_STATUS_OFFSET] != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("AR3K Config: MinBoot exit command event status failed: %d \n", + pEvent[EXIT_MIN_BOOT_COMMAND_STATUS_OFFSET])); + status = A_ECOMM; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("AR3K Config: MinBoot Exit Command Complete (Success) \n")); + A_MDELAY(1); + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: MinBoot Exit Failed! \n")); + } + + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + + return status; +} + +static A_STATUS AR3KConfigureSendHCIReset(AR3K_CONFIG_INFO *pConfig) +{ + A_STATUS status = A_OK; + A_UINT8 hciResetCommand[] = {0x03,0x0c,0x0}; + A_UINT8 *pEvent = NULL; + A_UINT8 *pBufferToFree = NULL; + + status = SendHCICommandWaitCommandComplete( pConfig, + hciResetCommand, + sizeof(hciResetCommand), + &pEvent, + &pBufferToFree ); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: HCI reset failed! \n")); + } + + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + + return status; +} + +static A_STATUS AR3KEnableTLPM(AR3K_CONFIG_INFO *pConfig) +{ + A_STATUS status; + /* AR3K vendor specific command for Host Wakeup Config */ + A_CHAR hostWakeupConfig[] = {0x31,0xFC,0x18, + 0x02,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00, + TLPM_DEFAULT_IDLE_TIMEOUT_LSB,TLPM_DEFAULT_IDLE_TIMEOUT_MSB,0x00,0x00, //idle timeout in ms + 0x00,0x00,0x00,0x00, + TLPM_DEFAULT_WAKEUP_TIMEOUT_MS,0x00,0x00,0x00, //wakeup timeout in ms + 0x00,0x00,0x00,0x00}; + /* AR3K vendor specific command for Target Wakeup Config */ + A_CHAR targetWakeupConfig[] = {0x31,0xFC,0x18, + 0x04,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00, + TLPM_DEFAULT_IDLE_TIMEOUT_LSB,TLPM_DEFAULT_IDLE_TIMEOUT_MSB,0x00,0x00, //idle timeout in ms + 0x00,0x00,0x00,0x00, + TLPM_DEFAULT_WAKEUP_TIMEOUT_MS,0x00,0x00,0x00, //wakeup timeout in ms + 0x00,0x00,0x00,0x00}; + /* AR3K vendor specific command for Host Wakeup Enable */ + A_CHAR hostWakeupEnable[] = {0x31,0xFC,0x4, + 0x01,0x00,0x00,0x00}; + /* AR3K vendor specific command for Target Wakeup Enable */ + A_CHAR targetWakeupEnable[] = {0x31,0xFC,0x4, + 0x06,0x00,0x00,0x00}; + /* AR3K vendor specific command for Sleep Enable */ + A_CHAR sleepEnable[] = {0x4,0xFC,0x1, + 0x1}; + A_UINT8 *pEvent = NULL; + A_UINT8 *pBufferToFree = NULL; + + if (0 != pConfig->IdleTimeout) { + A_UINT8 idle_lsb = pConfig->IdleTimeout & 0xFF; + A_UINT8 idle_msb = (pConfig->IdleTimeout & 0xFF00) >> 8; + hostWakeupConfig[11] = targetWakeupConfig[11] = idle_lsb; + hostWakeupConfig[12] = targetWakeupConfig[12] = idle_msb; + } + + if (0 != pConfig->WakeupTimeout) { + hostWakeupConfig[19] = targetWakeupConfig[19] = (pConfig->WakeupTimeout & 0xFF); + } + + status = SendHCICommandWaitCommandComplete(pConfig, + hostWakeupConfig, + sizeof(hostWakeupConfig), + &pEvent, + &pBufferToFree); + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HostWakeup Config Failed! \n")); + return status; + } + + pEvent = NULL; + pBufferToFree = NULL; + status = SendHCICommandWaitCommandComplete(pConfig, + targetWakeupConfig, + sizeof(targetWakeupConfig), + &pEvent, + &pBufferToFree); + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Target Wakeup Config Failed! \n")); + return status; + } + + pEvent = NULL; + pBufferToFree = NULL; + status = SendHCICommandWaitCommandComplete(pConfig, + hostWakeupEnable, + sizeof(hostWakeupEnable), + &pEvent, + &pBufferToFree); + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HostWakeup Enable Failed! \n")); + return status; + } + + pEvent = NULL; + pBufferToFree = NULL; + status = SendHCICommandWaitCommandComplete(pConfig, + targetWakeupEnable, + sizeof(targetWakeupEnable), + &pEvent, + &pBufferToFree); + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Target Wakeup Enable Failed! \n")); + return status; + } + + pEvent = NULL; + pBufferToFree = NULL; + status = SendHCICommandWaitCommandComplete(pConfig, + sleepEnable, + sizeof(sleepEnable), + &pEvent, + &pBufferToFree); + if (pBufferToFree != NULL) { + A_FREE(pBufferToFree); + } + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Sleep Enable Failed! \n")); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR3K Config: Enable TLPM Completed (status = %d) \n",status)); + + return status; +} + +A_STATUS AR3KConfigure(AR3K_CONFIG_INFO *pConfig) +{ + A_STATUS status = A_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR3K Config: Configuring AR3K ...\n")); + + do { + + if ((pConfig->pHCIDev == NULL) || (pConfig->pHCIProps == NULL) || (pConfig->pHIFDevice == NULL)) { + status = A_EINVAL; + break; + } + + /* disable asynchronous recv while we issue commands and receive events synchronously */ + status = HCI_TransportEnableDisableAsyncRecv(pConfig->pHCIDev,FALSE); + if (A_FAILED(status)) { + break; + } + + if (pConfig->Flags & AR3K_CONFIG_FLAG_FORCE_MINBOOT_EXIT) { + status = AR3KExitMinBoot(pConfig); + if (A_FAILED(status)) { + break; + } + } + + + /* Load patching and PST file if available*/ + if (A_OK != AthPSInitialize(pConfig)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Patch Download Failed!\n")); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("TLPM - PwrMgmtEnabled=%d, IdleTimeout=%d, WakeupTimeout=%d\n", + pConfig->PwrMgmtEnabled, + pConfig->IdleTimeout, + pConfig->WakeupTimeout)); + + /* Send HCI reset to make PS tags take effect*/ + AR3KConfigureSendHCIReset(pConfig); + + if (pConfig->PwrMgmtEnabled) { + /* the delay is required after the previous HCI reset before further + * HCI commands can be issued + */ + A_MDELAY(200); + AR3KEnableTLPM(pConfig); + } + + if (pConfig->Flags & + (AR3K_CONFIG_FLAG_SET_AR3K_BAUD | AR3K_CONFIG_FLAG_SET_AR6K_SCALE_STEP)) { + status = AR3KConfigureHCIBaud(pConfig); + if (A_FAILED(status)) { + break; + } + } + + /* re-enable asynchronous recv */ + status = HCI_TransportEnableDisableAsyncRecv(pConfig->pHCIDev,TRUE); + if (A_FAILED(status)) { + break; + } + + + } while (FALSE); + + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR3K Config: Configuration Complete (status = %d) \n",status)); + + return status; +} + +A_STATUS AR3KConfigureExit(void *config) +{ + A_STATUS status = A_OK; + AR3K_CONFIG_INFO *pConfig = (AR3K_CONFIG_INFO *)config; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR3K Config: Cleaning up AR3K ...\n")); + + do { + + if ((pConfig->pHCIDev == NULL) || (pConfig->pHCIProps == NULL) || (pConfig->pHIFDevice == NULL)) { + status = A_EINVAL; + break; + } + + /* disable asynchronous recv while we issue commands and receive events synchronously */ + status = HCI_TransportEnableDisableAsyncRecv(pConfig->pHCIDev,FALSE); + if (A_FAILED(status)) { + break; + } + + if (pConfig->Flags & + (AR3K_CONFIG_FLAG_SET_AR3K_BAUD | AR3K_CONFIG_FLAG_SET_AR6K_SCALE_STEP)) { + status = AR3KConfigureHCIBaud(pConfig); + if (A_FAILED(status)) { + break; + } + } + + /* re-enable asynchronous recv */ + status = HCI_TransportEnableDisableAsyncRecv(pConfig->pHCIDev,TRUE); + if (A_FAILED(status)) { + break; + } + + + } while (FALSE); + + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR3K Config: Cleanup Complete (status = %d) \n",status)); + + return status; +} + diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.c b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.c new file mode 100644 index 000000000000..df4cf8c16b97 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.c @@ -0,0 +1,694 @@ +/* + * Copyright (c) 2004-2010 Atheros Communications Inc. + * All rights reserved. + * + * This file implements the Atheros PS and patch downloaded for HCI UART Transport driver. + * This file can be used for HCI SDIO transport implementation for AR6002 with HCI_TRANSPORT_SDIO + * defined. + * + * + * ar3kcpsconfig.c + * + * + * + * The software source and binaries included in this development package are + * licensed, not sold. You, or your company, received the package under one + * or more license agreements. The rights granted to you are specifically + * listed in these license agreement(s). All other rights remain with Atheros + * Communications, Inc., its subsidiaries, or the respective owner including + * those listed on the included copyright notices.. Distribution of any + * portion of this package must be in strict compliance with the license + * agreement(s) terms. + * + * + * + */ + + + +#include "ar3kpsconfig.h" +#ifndef HCI_TRANSPORT_SDIO +#include "hci_ath.h" +#include "hci_uart.h" +#endif /* #ifndef HCI_TRANSPORT_SDIO */ + +#define MAX_FW_PATH_LEN 50 +#define MAX_BDADDR_FORMAT_LENGTH 30 + +/* + * Structure used to send HCI packet, hci packet length and device info + * together as parameter to PSThread. + */ +typedef struct { + + PSCmdPacket *HciCmdList; + A_UINT32 num_packets; + AR3K_CONFIG_INFO *dev; +}HciCommandListParam; + +A_STATUS SendHCICommandWaitCommandComplete(AR3K_CONFIG_INFO *pConfig, + A_UINT8 *pHCICommand, + int CmdLength, + A_UINT8 **ppEventBuffer, + A_UINT8 **ppBufferToFree); + +void LoadHeader(A_UCHAR *HCI_PS_Command,A_UCHAR opcode,int length,int index); +A_UINT32 Rom_Version; +A_UINT32 Build_Version; +extern A_BOOL BDADDR; +extern A_UINT32 Patch_Count; + +A_STATUS getDeviceType(AR3K_CONFIG_INFO *pConfig, A_UINT32 * code); +A_STATUS ReadVersionInfo(AR3K_CONFIG_INFO *pConfig); +A_STATUS set_patch_ram(AR3K_CONFIG_INFO *pConfig,A_UCHAR *patch_loc,A_UINT8 len); +#ifndef HCI_TRANSPORT_SDIO + +DECLARE_WAIT_QUEUE_HEAD(PsCompleteEvent); +DECLARE_WAIT_QUEUE_HEAD(HciEvent); +A_UCHAR *HciEventpacket; +rwlock_t syncLock; +wait_queue_t Eventwait; + +int PSHciWritepacket(struct hci_dev*,A_UCHAR* Data, A_UINT32 len); +extern char *bdaddr; +#endif /* HCI_TRANSPORT_SDIO */ + +A_STATUS write_bdaddr(AR3K_CONFIG_INFO *pConfig,A_UCHAR *bdaddr,int type); + +int PSSendOps(void *arg); + +#ifdef BT_PS_DEBUG +void Hci_log(A_UCHAR * log_string,A_UCHAR *data,A_UINT32 len) +{ + int i; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s : ",log_string)); + for (i = 0; i < len; i++) { + printk("0x%02x ", data[i]); + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("\n...................................\n")); +} +#else +#define Hci_log(string,data,len) +#endif /* BT_PS_DEBUG */ + + + + +A_STATUS AthPSInitialize(AR3K_CONFIG_INFO *hdev) +{ + A_STATUS status = A_OK; + if(hdev == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Device handle received\n")); + return A_ERROR; + } + +#ifndef HCI_TRANSPORT_SDIO + DECLARE_WAITQUEUE(wait, current); +#endif /* HCI_TRANSPORT_SDIO */ + + +#ifdef HCI_TRANSPORT_SDIO + status = PSSendOps((void*)hdev); +#else + if(InitPSState(hdev) == -1) { + return A_ERROR; + } + allow_signal(SIGKILL); + add_wait_queue(&PsCompleteEvent,&wait); + set_current_state(TASK_INTERRUPTIBLE); + if(!kernel_thread(PSSendOps,(void*)hdev,CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Kthread Failed\n")); + remove_wait_queue(&PsCompleteEvent,&wait); + return A_ERROR; + } + wait_event_interruptible(PsCompleteEvent,(PSTagMode == FALSE)); + set_current_state(TASK_RUNNING); + remove_wait_queue(&PsCompleteEvent,&wait); + +#endif /* HCI_TRANSPORT_SDIO */ + + + return status; + +} + +int PSSendOps(void *arg) +{ + int i; + int ps_index; + int status = 0; + PSCmdPacket *HciCmdList; /* List storing the commands */ + const struct firmware* firmware; + A_UINT32 numCmds; + A_UINT8 *event; + A_UINT8 *bufferToFree; + struct hci_dev *device; + A_UCHAR *buffer; + A_UINT32 len; + A_UINT32 DevType; + A_UCHAR *PsFileName; + A_UCHAR *patchFileName; + A_UCHAR patch_loc[40]; + A_UCHAR *path = NULL; + A_UCHAR *config_path = NULL; + A_UCHAR config_bdaddr[MAX_BDADDR_FORMAT_LENGTH]; + AR3K_CONFIG_INFO *hdev = (AR3K_CONFIG_INFO*)arg; + struct device *firmwareDev = NULL; + A_UINT8 cFlags = 0; + A_UINT8 bit7 = 0; + + status = 0; + HciCmdList = NULL; +#ifdef HCI_TRANSPORT_SDIO + device = hdev->pBtStackHCIDev; + firmwareDev = device->parent; +#else + device = hdev; + firmwareDev = &device->dev; + AthEnableSyncCommandOp(TRUE); +#endif /* HCI_TRANSPORT_SDIO */ + /* First verify if the controller is an FPGA or ASIC, so depending on the device type the PS file to be written will be different. + */ + + path =(A_UCHAR *)A_MALLOC(MAX_FW_PATH_LEN); + if(path == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Malloc failed to allocate %d bytes for path\n", MAX_FW_PATH_LEN)); + goto complete; + } + config_path = (A_UCHAR *) A_MALLOC(MAX_FW_PATH_LEN); + if(config_path == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Malloc failed to allocate %d bytes for config_path\n", MAX_FW_PATH_LEN)); + goto complete; + } + + if(A_ERROR == getDeviceType(hdev,&DevType)) { + status = 1; + goto complete; + } + if(A_ERROR == ReadVersionInfo(hdev)) { + status = 1; + goto complete; + } + + patchFileName = PATCH_FILE; + snprintf(path, MAX_FW_PATH_LEN, "%s/%xcoex/",CONFIG_PATH,Rom_Version); + if(DevType){ + if(DevType == 0xdeadc0de){ + PsFileName = PS_ASIC_FILE; + } else{ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" FPGA Test Image : %x %x \n",Rom_Version,Build_Version)); + if((Rom_Version == 0x99999999) && (Build_Version == 1)){ + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("FPGA Test Image : Skipping Patch File load\n")); + patchFileName = NULL; + } + PsFileName = PS_FPGA_FILE; + } + } + else{ + PsFileName = PS_ASIC_FILE; + } + + snprintf(config_path, MAX_FW_PATH_LEN, "%s%s",path,PsFileName); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%x: FPGA/ASIC PS File Name %s\n", DevType,config_path)); + /* Read the PS file to a dynamically allocated buffer */ + if(A_REQUEST_FIRMWARE(&firmware,config_path,firmwareDev) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: firmware file open error\n", __FUNCTION__ )); + status = 1; + goto complete; + + } + if(NULL == firmware || firmware->size == 0) { + status = 1; + goto complete; + } + buffer = (A_UCHAR *)A_MALLOC(firmware->size); + if(buffer != NULL) { + /* Copy the read file to a local Dynamic buffer */ + memcpy(buffer,firmware->data,firmware->size); + len = firmware->size; + A_RELEASE_FIRMWARE(firmware); + /* Parse the PS buffer to a global variable */ + status = AthDoParsePS(buffer,len); + A_FREE(buffer); + } else { + A_RELEASE_FIRMWARE(firmware); + } + + + /* Read the patch file to a dynamically allocated buffer */ + if(patchFileName != NULL) + snprintf(config_path, + MAX_FW_PATH_LEN, "%s%s",path,patchFileName); + else { + status = 0; + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Patch File Name %s\n", config_path)); + if((patchFileName == NULL) || (A_REQUEST_FIRMWARE(&firmware,config_path,firmwareDev) < 0)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: firmware file open error\n", __FUNCTION__ )); + /* + * It is not necessary that Patch file be available, continue with PS Operations if. + * failed. + */ + status = 0; + + } else { + if(NULL == firmware || firmware->size == 0) { + status = 0; + } else { + buffer = (A_UCHAR *)A_MALLOC(firmware->size); + if(buffer != NULL) { + /* Copy the read file to a local Dynamic buffer */ + memcpy(buffer,firmware->data,firmware->size); + len = firmware->size; + A_RELEASE_FIRMWARE(firmware); + /* parse and store the Patch file contents to a global variables */ + patch_loc[0] = '\0'; + status = AthDoParsePatch(buffer,len, patch_loc); + + A_FREE(buffer); + } else { + A_RELEASE_FIRMWARE(firmware); + } + } + } + + /* Create an HCI command list from the parsed PS and patch information */ + AthCreateCommandList(&HciCmdList,&numCmds); +#define CONFIG_PLATFORM 0x21 +#define CONFIG_TLPM 0x23 +#define PLATFORM_CONFIG_BIT 0x01 +#define TLPM_CONFIG_BIT 0x02 +#define IDLE_TIMEOUT_OFFSET 12 +#define WAKEUP_TIMEOUT_OFFSET 8 +#define IDLE_TIMEOUT_DEFAULT_VAL 1000 +#define WAKEUP_TIMEOUT_DEFAULT_VAL 10 + + hdev->IdleTimeout = IDLE_TIMEOUT_DEFAULT_VAL; + hdev->WakeupTimeout = WAKEUP_TIMEOUT_DEFAULT_VAL; + hdev->PwrMgmtEnabled = 0; + + ps_index = 2; /* CRC + PS Reset */ + if (Patch_Count) + ps_index += Patch_Count + 1; /* Patches + Enable patch Cmd */ + + for(i = ps_index; i PwrMgmtEnabled = 1; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("CONFIG PLATFORM present and Pwr Manage %x\n", hdev->PwrMgmtEnabled)); + } + } + else if((HciCmdList[i].Hcipacket[4] == CONFIG_TLPM) && + (HciCmdList[i].Hcipacket[5] == 0)) { + cFlags |= TLPM_CONFIG_BIT; + hdev->IdleTimeout = *((A_UINT32 *)&HciCmdList[i].Hcipacket[IDLE_TIMEOUT_OFFSET + 7]); + hdev->WakeupTimeout = *((A_UINT16 *)&HciCmdList[i].Hcipacket[WAKEUP_TIMEOUT_OFFSET + 7]); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("hdev->idletimeout %d hdev->WakeupTimeout %d",hdev->IdleTimeout, hdev->WakeupTimeout)); + } + } + + + /* Form the parameter for PSSendOps() API */ + + + /* + * First Send the CRC packet, + * We have to continue with the PS operations only if the CRC packet has been replied with + * a Command complete event with status Error. + */ + + if(SendHCICommandWaitCommandComplete + (hdev, + HciCmdList[0].Hcipacket, + HciCmdList[0].packetLen, + &event, + &bufferToFree) == A_OK) { + if(ReadPSEvent(event) == A_OK) { /* Exit if the status is success */ + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } +#ifndef HCI_TRANSPORT_SDIO + if(bdaddr && bdaddr[0] !='\0') { + write_bdaddr(hdev,bdaddr,BDADDR_TYPE_STRING); + } +#endif + status = 1; + goto complete; + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + } else { + status = 0; + goto complete; + } + /* Set Patch location */ + if(patch_loc[0] != '\0') { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Setting Patch Location %s\n", patch_loc)); + set_patch_ram(hdev,patch_loc,sizeof(patch_loc)); + } + for(i = 1; i ",HciCmdList[i].Hcipacket,HciCmdList[i].packetLen); + if(SendHCICommandWaitCommandComplete + (hdev, + HciCmdList[i].Hcipacket, + HciCmdList[i].packetLen, + &event, + &bufferToFree) == A_OK) { + if(ReadPSEvent(event) != A_OK) { /* Exit if the status is success */ + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + status = 1; + goto complete; + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + } else { + status = 0; + goto complete; + } + } +#ifdef HCI_TRANSPORT_SDIO + if(BDADDR == FALSE) + if(hdev->bdaddr[0] !=0x00 || + hdev->bdaddr[1] !=0x00 || + hdev->bdaddr[2] !=0x00 || + hdev->bdaddr[3] !=0x00 || + hdev->bdaddr[4] !=0x00 || + hdev->bdaddr[5] !=0x00) + write_bdaddr(hdev,hdev->bdaddr,BDADDR_TYPE_HEX); + + + /* if Platform config is present and TLPM is not available + * write HCI command for TLPM with default timeout values */ + if(bit7 && !(cFlags & TLPM_CONFIG_BIT)) { + A_UCHAR TLPMHciCmd[] = {0x0b, 0xfc, 0x1c, 0x01, 0x23, 0x00, 0x18, + 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0a, 0x00, 0x0a, 0x00, 0xe8, 0x03, + 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0xe8, + 0x03, 0x00, 0x00 }; + int CmdLen = sizeof(TLPMHciCmd); + + *((A_UINT32 *)&TLPMHciCmd[IDLE_TIMEOUT_OFFSET + 7]) = hdev->IdleTimeout; + *((A_UINT16 *)&TLPMHciCmd[WAKEUP_TIMEOUT_OFFSET + 7]) = hdev->WakeupTimeout; + + if(SendHCICommandWaitCommandComplete + (hdev, + TLPMHciCmd, + CmdLen, + &event, + &bufferToFree) == A_OK) { + if(ReadPSEvent(event) != A_OK) { /* Exit if the status is success */ + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + status = 1; + goto complete; + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + } else { + status = 0; + goto complete; + } + } + +#ifndef HCI_TRANSPORT_SDIO + + if(bdaddr && bdaddr[0] != '\0') { + write_bdaddr(hdev,bdaddr,BDADDR_TYPE_STRING); + } else +#endif /* HCI_TRANSPORT_SDIO */ + /* Write BDADDR Read from OTP here */ + + + +#endif + + { + /* Read Contents of BDADDR file if user has not provided any option */ + snprintf(config_path,MAX_FW_PATH_LEN, "%s%s",path,BDADDR_FILE); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR File Name %s\n", config_path)); + if(A_REQUEST_FIRMWARE(&firmware,config_path,firmwareDev) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: firmware file open error\n", __FUNCTION__ )); + goto complete; + } + if(NULL == firmware || firmware->size == 0) { + goto complete; + } + len = (firmware->size > MAX_BDADDR_FORMAT_LENGTH)? MAX_BDADDR_FORMAT_LENGTH: firmware->size; + memcpy(config_bdaddr, firmware->data,len); + config_bdaddr[len] = '\0'; + write_bdaddr(hdev,config_bdaddr,BDADDR_TYPE_STRING); + A_RELEASE_FIRMWARE(firmware); + } +complete: +#ifndef HCI_TRANSPORT_SDIO + AthEnableSyncCommandOp(FALSE); + PSTagMode = FALSE; + wake_up_interruptible(&PsCompleteEvent); +#endif /* HCI_TRANSPORT_SDIO */ + if(NULL != HciCmdList) { + AthFreeCommandList(&HciCmdList,numCmds); + } + if(path) { + A_FREE(path); + } + if(config_path) { + A_FREE(config_path); + } + return status; +} +#ifndef HCI_TRANSPORT_SDIO +/* + * This API is used to send the HCI command to controller and return + * with a HCI Command Complete event. + * For HCI SDIO transport, this will be internally defined. + */ +A_STATUS SendHCICommandWaitCommandComplete(AR3K_CONFIG_INFO *pConfig, + A_UINT8 *pHCICommand, + int CmdLength, + A_UINT8 **ppEventBuffer, + A_UINT8 **ppBufferToFree) +{ + if(CmdLength == 0) { + return A_ERROR; + } + Hci_log("COM Write -->",pHCICommand,CmdLength); + PSAcked = FALSE; + if(PSHciWritepacket(pConfig,pHCICommand,CmdLength) == 0) { + /* If the controller is not available, return Error */ + return A_ERROR; + } + //add_timer(&psCmdTimer); + wait_event_interruptible(HciEvent,(PSAcked == TRUE)); + if(NULL != HciEventpacket) { + *ppEventBuffer = HciEventpacket; + *ppBufferToFree = HciEventpacket; + } else { + /* Did not get an event from controller. return error */ + *ppBufferToFree = NULL; + return A_ERROR; + } + + return A_OK; +} +#endif /* HCI_TRANSPORT_SDIO */ + +A_STATUS ReadPSEvent(A_UCHAR* Data){ + + if(Data[4] == 0xFC && Data[5] == 0x00) + { + switch(Data[3]){ + case 0x0B: + return A_OK; + break; + case 0x0C: + /* Change Baudrate */ + return A_OK; + break; + case 0x04: + return A_OK; + break; + case 0x1E: + Rom_Version = Data[9]; + Rom_Version = ((Rom_Version << 8) |Data[8]); + Rom_Version = ((Rom_Version << 8) |Data[7]); + Rom_Version = ((Rom_Version << 8) |Data[6]); + + Build_Version = Data[13]; + Build_Version = ((Build_Version << 8) |Data[12]); + Build_Version = ((Build_Version << 8) |Data[11]); + Build_Version = ((Build_Version << 8) |Data[10]); + return A_OK; + break; + + + } + } + + return A_ERROR; +} +int str2ba(unsigned char *str_bdaddr,unsigned char *bdaddr) +{ + unsigned char bdbyte[3]; + unsigned char *str_byte = str_bdaddr; + int i,j; + unsigned char colon_present = 0; + + if(NULL != strstr(str_bdaddr,":")) { + colon_present = 1; + } + + + bdbyte[2] = '\0'; + + for( i = 0,j = 5; i < 6; i++, j--) { + bdbyte[0] = str_byte[0]; + bdbyte[1] = str_byte[1]; + bdaddr[j] = A_STRTOL(bdbyte,NULL,16); + if(colon_present == 1) { + str_byte+=3; + } else { + str_byte+=2; + } + } + return 0; +} +A_STATUS set_patch_ram(AR3K_CONFIG_INFO *pConfig,A_UCHAR *patch_loc,A_UINT8 len) +{ + A_UCHAR cmd[] = { 0x0B, 0xFC, 0x07, 0x0D, 0x00, 0x00, 0x00, /* Loc */0x00, 0x00, 0x00, 0x00 }; + A_UCHAR i,j; + unsigned char loc_byte[3]; + A_UINT8 *event; + A_UINT8 *bufferToFree = NULL; + A_STATUS result = A_ERROR; + A_UCHAR *loc_ptr = &cmd[7]; + + if(!patch_loc) + return result; + + loc_byte[2] = '\0'; + + LoadHeader(cmd, 0x0D, 4, 0); + for( i = 0,j = 3; i < 4; i++, j--) { + loc_byte[0] = patch_loc[0]; + loc_byte[1] = patch_loc[1]; + loc_ptr[j] = A_STRTOL(loc_byte,NULL,16); + patch_loc+=2; + } + Hci_log("Patch Ram Write -->",cmd, sizeof(cmd)); + if(A_OK == SendHCICommandWaitCommandComplete(pConfig,cmd, + sizeof(cmd), + &event,&bufferToFree)) { + + result = ReadPSEvent(event); + + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + return result; + +} +A_STATUS write_bdaddr(AR3K_CONFIG_INFO *pConfig,A_UCHAR *bdaddr,int type) +{ + A_UCHAR bdaddr_cmd[] = { 0x0B, 0xFC, 0x0A, 0x01, 0x01, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + A_UINT8 *event; + A_UINT8 *bufferToFree = NULL; + A_STATUS result = A_ERROR; + int inc,outc; + + if (type == BDADDR_TYPE_STRING) + str2ba(bdaddr,&bdaddr_cmd[7]); + else { + /* Bdaddr has to be sent as LAP first */ + for(inc = 5 ,outc = 7; inc >=0; inc--, outc++) + bdaddr_cmd[outc] = bdaddr[inc]; + } + + Hci_log("BDADDR Write -->",bdaddr_cmd,sizeof(bdaddr_cmd)); + if(A_OK == SendHCICommandWaitCommandComplete(pConfig,bdaddr_cmd, + sizeof(bdaddr_cmd), + &event,&bufferToFree)) { + + if(event[4] == 0xFC && event[5] == 0x00){ + if(event[3] == 0x0B){ + result = A_OK; + } + } + + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + return result; + +} +A_STATUS ReadVersionInfo(AR3K_CONFIG_INFO *pConfig) +{ + A_UINT8 hciCommand[] = {0x1E,0xfc,0x00}; + A_UINT8 *event; + A_UINT8 *bufferToFree = NULL; + A_STATUS result = A_ERROR; + Hci_log("Read Version -->",hciCommand,sizeof(hciCommand)); + if(A_OK == SendHCICommandWaitCommandComplete(pConfig,hciCommand,sizeof(hciCommand),&event,&bufferToFree)) { + result = ReadPSEvent(event); + + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + return result; +} +A_STATUS getDeviceType(AR3K_CONFIG_INFO *pConfig, A_UINT32 * code) +{ + A_UINT8 hciCommand[] = {0x05,0xfc,0x05,0x00,0x00,0x00,0x00,0x04}; + A_UINT8 *event; + A_UINT8 *bufferToFree = NULL; + A_UINT32 reg; + A_STATUS result = A_ERROR; + *code = 0; + hciCommand[3] = (A_UINT8)(FPGA_REGISTER & 0xFF); + hciCommand[4] = (A_UINT8)((FPGA_REGISTER >> 8) & 0xFF); + hciCommand[5] = (A_UINT8)((FPGA_REGISTER >> 16) & 0xFF); + hciCommand[6] = (A_UINT8)((FPGA_REGISTER >> 24) & 0xFF); + if(A_OK == SendHCICommandWaitCommandComplete(pConfig,hciCommand,sizeof(hciCommand),&event,&bufferToFree)) { + + if(event[4] == 0xFC && event[5] == 0x00){ + switch(event[3]){ + case 0x05: + reg = event[9]; + reg = ((reg << 8) |event[8]); + reg = ((reg << 8) |event[7]); + reg = ((reg << 8) |event[6]); + *code = reg; + result = A_OK; + + break; + case 0x06: + //Sleep(500); + break; + } + } + + } + if(bufferToFree != NULL) { + A_FREE(bufferToFree); + } + return result; +} + + diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.h b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.h new file mode 100644 index 000000000000..4358834f6d71 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsconfig.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2004-2010 Atheros Communications Inc. + * All rights reserved. + * + * This file defines the symbols exported by Atheros PS and patch download module. + * define the constant HCI_TRANSPORT_SDIO if the module is being used for HCI SDIO transport. + * defined. + * + * + * ar3kcpsconfig.h + * + * + * + * The software source and binaries included in this development package are + * licensed, not sold. You, or your company, received the package under one + * or more license agreements. The rights granted to you are specifically + * listed in these license agreement(s). All other rights remain with Atheros + * Communications, Inc., its subsidiaries, or the respective owner including + * those listed on the included copyright notices.. Distribution of any + * portion of this package must be in strict compliance with the license + * agreement(s) terms. + * + * + * + */ + + + +#ifndef __AR3KPSCONFIG_H +#define __AR3KPSCONFIG_H + +/* + * Define the flag HCI_TRANSPORT_SDIO and undefine HCI_TRANSPORT_UART if the transport being used is SDIO. + */ +#undef HCI_TRANSPORT_UART + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + + +#include +#include + +#include "ar3kpsparser.h" + +#define FPGA_REGISTER 0x4FFC +#define BDADDR_TYPE_STRING 0 +#define BDADDR_TYPE_HEX 1 +#define CONFIG_PATH "ar3k" + +#define PS_ASIC_FILE "PS_ASIC.pst" +#define PS_FPGA_FILE "PS_FPGA.pst" + +#define PATCH_FILE "RamPatch.txt" +#define BDADDR_FILE "ar3kbdaddr.pst" + +#define ROM_VER_AR3001_3_1_0 30000 +#define ROM_VER_AR3001_3_1_1 30101 + + +#ifndef HCI_TRANSPORT_SDIO +#define AR3K_CONFIG_INFO struct hci_dev +extern wait_queue_head_t HciEvent; +extern wait_queue_t Eventwait; +extern A_UCHAR *HciEventpacket; +#endif /* #ifndef HCI_TRANSPORT_SDIO */ + +A_STATUS AthPSInitialize(AR3K_CONFIG_INFO *hdev); +A_STATUS ReadPSEvent(A_UCHAR* Data); +#endif /* __AR3KPSCONFIG_H */ diff --git a/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsparser.c b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsparser.c new file mode 100644 index 000000000000..d59ba438a428 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/ar3kps/ar3kpsparser.c @@ -0,0 +1,989 @@ +/* + * Copyright (c) 2004-2010 Atheros Communications Inc. + * All rights reserved. + * + * This file implements the Atheros PS and patch parser. + * It implements APIs to parse data buffer with patch and PS information and convert it to HCI commands. + * + * + * + * ar3kpsparser.c + * + * + * + * The software source and binaries included in this development package are + * licensed, not sold. You, or your company, received the package under one + * or more license agreements. The rights granted to you are specifically + * listed in these license agreement(s). All other rights remain with Atheros + * Communications, Inc., its subsidiaries, or the respective owner including + * those listed on the included copyright notices.. Distribution of any + * portion of this package must be in strict compliance with the license + * agreement(s) terms. + * + * + * + */ + + +#include "ar3kpsparser.h" + +#define BD_ADDR_SIZE 6 +#define WRITE_PATCH 8 +#define ENABLE_PATCH 11 +#define PS_RESET 2 +#define PS_WRITE 1 +#define PS_VERIFY_CRC 9 +#define CHANGE_BDADDR 15 + +#define HCI_COMMAND_HEADER 7 + +#define HCI_EVENT_SIZE 7 + +#define WRITE_PATCH_COMMAND_STATUS_OFFSET 5 + +#define PS_RAM_SIZE 2048 + +#define RAM_PS_REGION (1<<0) +#define RAM_PATCH_REGION (1<<1) +#define RAMPS_MAX_PS_DATA_PER_TAG 20000 +#define MAX_RADIO_CFG_TABLE_SIZE 244 +#define RAMPS_MAX_PS_TAGS_PER_FILE 50 + +#define PS_MAX_LEN 500 +#define LINE_SIZE_MAX (PS_MAX_LEN *2) + +/* Constant values used by parser */ +#define BYTES_OF_PS_DATA_PER_LINE 16 +#define RAMPS_MAX_PS_DATA_PER_TAG 20000 + + +/* Number pf PS/Patch entries in an HCI packet */ +#define MAX_BYTE_LENGTH 244 + +#define SKIP_BLANKS(str) while (*str == ' ') str++ +#define MIN(x, y) (((x) <= (y))? (x):(y)) +#define MAX(x, y) (((x) >= (y))? (x):(y)) + +#define UNUSED(x) (x=x) + +#define IS_BETWEEN(x, lower, upper) (((lower) <= (x)) && ((x) <= (upper))) +#define IS_DIGIT(c) (IS_BETWEEN((c), '0', '9')) +#define IS_HEX(c) (IS_BETWEEN((c), '0', '9') || IS_BETWEEN((c), 'a', 'f') || IS_BETWEEN((c), 'A', 'F')) +#define TO_LOWER(c) (IS_BETWEEN((c), 'A', 'Z') ? ((c) - 'A' + 'a') : (c)) +#define IS_BLANK(c) ((c) == ' ') +#define CONV_DEC_DIGIT_TO_VALUE(c) ((c) - '0') +#define CONV_HEX_DIGIT_TO_VALUE(c) (IS_DIGIT(c) ? ((c) - '0') : (IS_BETWEEN((c), 'A', 'Z') ? ((c) - 'A' + 10) : ((c) - 'a' + 10))) +#define CONV_VALUE_TO_HEX(v) ((A_UINT8)( ((v & 0x0F) <= 9) ? ((v & 0x0F) + '0') : ((v & 0x0F) - 10 + 'A') ) ) + + +enum MinBootFileFormatE +{ + MB_FILEFORMAT_RADIOTBL, + MB_FILEFORMAT_PATCH, + MB_FILEFORMAT_COEXCONFIG +}; + +enum RamPsSection +{ + RAM_PS_SECTION, + RAM_PATCH_SECTION, + RAM_DYN_MEM_SECTION +}; + +enum eType { + eHex, + edecimal +}; + + +typedef struct tPsTagEntry +{ + A_UINT32 TagId; + A_UINT32 TagLen; + A_UINT8 *TagData; +} tPsTagEntry, *tpPsTagEntry; + +typedef struct tRamPatch +{ + A_UINT16 Len; + A_UINT8 * Data; +} tRamPatch, *ptRamPatch; + + + +typedef struct ST_PS_DATA_FORMAT { + enum eType eDataType; + A_BOOL bIsArray; +}ST_PS_DATA_FORMAT; + +typedef struct ST_READ_STATUS { + unsigned uTagID; + unsigned uSection; + unsigned uLineCount; + unsigned uCharCount; + unsigned uByteCount; +}ST_READ_STATUS; + + +/* Stores the number of PS Tags */ +static A_UINT32 Tag_Count = 0; + +/* Stores the number of patch commands */ +A_UINT32 Patch_Count = 0; +static A_UINT32 Total_tag_lenght = 0; +A_BOOL BDADDR = FALSE; +A_UINT32 StartTagId; + +tPsTagEntry PsTagEntry[RAMPS_MAX_PS_TAGS_PER_FILE]; +tRamPatch RamPatch[MAX_NUM_PATCH_ENTRY]; + + +A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat); +char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos); +char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_UINT32 *pos); +static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacket *PSPatchPacket,A_UINT32 *index); + +/* Function to reads the next character from the input buffer */ +char AthReadChar(A_UCHAR *buffer, A_UINT32 len,A_UINT32 *pos) +{ + char Ch; + if(buffer == NULL || *pos >=len ) + { + return '\0'; + } else { + Ch = buffer[*pos]; + (*pos)++; + return Ch; + } +} +/* PS parser helper function */ +unsigned int uGetInputDataFormat(char* pCharLine, ST_PS_DATA_FORMAT *pstFormat) +{ + if(pCharLine[0] != '[') { + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + return 0; + } + switch(pCharLine[1]) { + case 'H': + case 'h': + if(pCharLine[2]==':') { + if((pCharLine[3]== 'a') || (pCharLine[3]== 'A')) { + if(pCharLine[4] == ']') { + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 5; + return 0; + } + else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); //[H:A + return 1; + } + } + if((pCharLine[3]== 'S') || (pCharLine[3]== 's')) { + if(pCharLine[4] == ']') { + pstFormat->eDataType = eHex; + pstFormat->bIsArray = false; + pCharLine += 5; + return 0; + } + else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); //[H:A + return 1; + } + } + else if(pCharLine[3] == ']') { //[H:] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 4; + return 0; + } + else { //[H: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); + return 1; + } + } + else if(pCharLine[2]==']') { //[H] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 3; + return 0; + } + else { //[H + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format\n")); + return 1; + } + break; + + case 'A': + case 'a': + if(pCharLine[2]==':') { + if((pCharLine[3]== 'h') || (pCharLine[3]== 'H')) { + if(pCharLine[4] == ']') { + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 5; + return 0; + } + else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 1\n")); //[A:H + return 1; + } + } + else if(pCharLine[3]== ']') { //[A:] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 4; + return 0; + } + else { //[A: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 2\n")); + return 1; + } + } + else if(pCharLine[2]==']') { //[H] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 3; + return 0; + } + else { //[H + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 3\n")); + return 1; + } + break; + + case 'S': + case 's': + if(pCharLine[2]==':') { + if((pCharLine[3]== 'h') || (pCharLine[3]== 'H')) { + if(pCharLine[4] == ']') { + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 5; + return 0; + } + else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 5\n")); //[A:H + return 1; + } + } + else if(pCharLine[3]== ']') { //[A:] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 4; + return 0; + } + else { //[A: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 6\n")); + return 1; + } + } + else if(pCharLine[2]==']') { //[H] + pstFormat->eDataType = eHex; + pstFormat->bIsArray = true; + pCharLine += 3; + return 0; + } + else { //[H + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 7\n")); + return 1; + } + break; + + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Illegal Data format 8\n")); + return 1; + } +} + +unsigned int uReadDataInSection(char *pCharLine, ST_PS_DATA_FORMAT stPS_DataFormat) +{ + char *pTokenPtr = pCharLine; + + if(pTokenPtr[0] == '[') { + while(pTokenPtr[0] != ']' && pTokenPtr[0] != '\0') { + pTokenPtr++; + } + if(pTokenPtr[0] == '\0') { + return (0x0FFF); + } + pTokenPtr++; + + + } + if(stPS_DataFormat.eDataType == eHex) { + if(stPS_DataFormat.bIsArray == true) { + //Not implemented + return (0x0FFF); + } + else { + return (A_STRTOL(pTokenPtr, NULL, 16)); + } + } + else { + //Not implemented + return (0x0FFF); + } +} +A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat) +{ + char *Buffer; + char *pCharLine; + A_UINT8 TagCount; + A_UINT16 ByteCount; + A_UINT8 ParseSection=RAM_PS_SECTION; + A_UINT32 pos; + + + + int uReadCount; + ST_PS_DATA_FORMAT stPS_DataFormat; + ST_READ_STATUS stReadStatus = {0, 0, 0,0}; + pos = 0; + Buffer = NULL; + + if (srcbuffer == NULL || srclen == 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Could not open .\n")); + return A_ERROR; + } + TagCount = 0; + ByteCount = 0; + Buffer = A_MALLOC(LINE_SIZE_MAX + 1); + if(NULL == Buffer) { + return A_ERROR; + } + if (FileFormat == MB_FILEFORMAT_PATCH) + { + int LineRead = 0; + while((pCharLine = AthGetLine(Buffer, LINE_SIZE_MAX, srcbuffer,srclen,&pos)) != NULL) + { + + SKIP_BLANKS(pCharLine); + + // Comment line or empty line + if ((pCharLine[0] == '/') && (pCharLine[1] == '/')) + { + continue; + } + + if ((pCharLine[0] == '#')) { + if (stReadStatus.uSection != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("error\n")); + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + else { + stReadStatus.uSection = 1; + continue; + } + } + if ((pCharLine[0] == '/') && (pCharLine[1] == '*')) + { + pCharLine+=2; + SKIP_BLANKS(pCharLine); + + if(!strncmp(pCharLine,"PA",2)||!strncmp(pCharLine,"Pa",2)||!strncmp(pCharLine,"pa",2)) + ParseSection=RAM_PATCH_SECTION; + + if(!strncmp(pCharLine,"DY",2)||!strncmp(pCharLine,"Dy",2)||!strncmp(pCharLine,"dy",2)) + ParseSection=RAM_DYN_MEM_SECTION; + + if(!strncmp(pCharLine,"PS",2)||!strncmp(pCharLine,"Ps",2)||!strncmp(pCharLine,"ps",2)) + ParseSection=RAM_PS_SECTION; + + LineRead = 0; + stReadStatus.uSection = 0; + + continue; + } + + switch(ParseSection) + { + case RAM_PS_SECTION: + { + if (stReadStatus.uSection == 1) //TagID + { + SKIP_BLANKS(pCharLine); + if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail\n")); + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + //pCharLine +=5; + PsTagEntry[TagCount].TagId = uReadDataInSection(pCharLine, stPS_DataFormat); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" TAG ID %d \n",PsTagEntry[TagCount].TagId)); + + //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("tag # %x\n", PsTagEntry[TagCount].TagId); + if (TagCount == 0) + { + StartTagId = PsTagEntry[TagCount].TagId; + } + stReadStatus.uSection = 2; + } + else if (stReadStatus.uSection == 2) //TagLength + { + + if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail \n")); + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + //pCharLine +=5; + ByteCount = uReadDataInSection(pCharLine, stPS_DataFormat); + + //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("tag length %x\n", ByteCount)); + if (ByteCount > LINE_SIZE_MAX/2) + { + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + PsTagEntry[TagCount].TagLen = ByteCount; + PsTagEntry[TagCount].TagData = (A_UINT8*)A_MALLOC(ByteCount); + stReadStatus.uSection = 3; + stReadStatus.uLineCount = 0; + } + else if( stReadStatus.uSection == 3) { //Data + + if(stReadStatus.uLineCount == 0) { + if(uGetInputDataFormat(pCharLine,&stPS_DataFormat)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat Fail\n")); + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + //pCharLine +=5; + } + SKIP_BLANKS(pCharLine); + stReadStatus.uCharCount = 0; + if(pCharLine[stReadStatus.uCharCount] == '[') { + while(pCharLine[stReadStatus.uCharCount] != ']' && pCharLine[stReadStatus.uCharCount] != '\0' ) { + stReadStatus.uCharCount++; + } + if(pCharLine[stReadStatus.uCharCount] == ']' ) { + stReadStatus.uCharCount++; + } else { + stReadStatus.uCharCount = 0; + } + } + uReadCount = (ByteCount > BYTES_OF_PS_DATA_PER_LINE)? BYTES_OF_PS_DATA_PER_LINE: ByteCount; + //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" ")); + if((stPS_DataFormat.eDataType == eHex) && stPS_DataFormat.bIsArray == true) { + while(uReadCount > 0) { + PsTagEntry[TagCount].TagData[stReadStatus.uByteCount] = + (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount]) << 4) + | (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 1])); + + PsTagEntry[TagCount].TagData[stReadStatus.uByteCount+1] = + (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 3]) << 4) + | (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 4])); + + stReadStatus.uCharCount += 6; // read two bytes, plus a space; + stReadStatus.uByteCount += 2; + uReadCount -= 2; + } + if(ByteCount > BYTES_OF_PS_DATA_PER_LINE) { + ByteCount -= BYTES_OF_PS_DATA_PER_LINE; + } + else { + ByteCount = 0; + } + } + else { + //to be implemented + } + + stReadStatus.uLineCount++; + + if(ByteCount == 0) { + stReadStatus.uSection = 0; + stReadStatus.uCharCount = 0; + stReadStatus.uLineCount = 0; + stReadStatus.uByteCount = 0; + } + else { + stReadStatus.uCharCount = 0; + } + + if((stReadStatus.uSection == 0)&&(++TagCount == RAMPS_MAX_PS_TAGS_PER_FILE)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("\n Buffer over flow PS File too big!!!")); + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + //Sleep (3000); + //exit(1); + } + + } + } + + break; + default: + { + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + break; + } + LineRead++; + } + Tag_Count = TagCount; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Number of Tags %d\n", Tag_Count)); + } + + + if (TagCount > RAMPS_MAX_PS_TAGS_PER_FILE) + { + + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_ERROR; + } + + if(Buffer != NULL) { + A_FREE(Buffer); + } + return A_OK; + +} + + + +/********************/ + + +A_STATUS GetNextTwoChar(A_UCHAR *srcbuffer,A_UINT32 len, A_UINT32 *pos, char * buffer) +{ + unsigned char ch; + + ch = AthReadChar(srcbuffer,len,pos); + if(ch != '\0' && IS_HEX(ch)) { + buffer[0] = ch; + } else + { + return A_ERROR; + } + ch = AthReadChar(srcbuffer,len,pos); + if(ch != '\0' && IS_HEX(ch)) { + buffer[1] = ch; + } else + { + return A_ERROR; + } + return A_OK; +} +#define PATCH_LOC_KEY "DA:" +#define PATCH_LOC_STRING_LEN 8 +A_STATUS AthDoParsePatch(A_UCHAR *patchbuffer, A_UINT32 patchlen, A_UCHAR *patch_loc) +{ + + char Byte[3]; + char Line[MAX_BYTE_LENGTH + 1]; + int ByteCount,ByteCount_Org; + int count; + int i,j,k; + int data; + A_UINT32 filepos; + Byte[2] = '\0'; + j = 0; + filepos = 0; + Patch_Count = 0; + + if(!patch_loc) + return A_ERROR; + + while(NULL != AthGetLine(Line,MAX_BYTE_LENGTH,patchbuffer,patchlen,&filepos)) { + if(strlen(Line) <= 1) { + continue; + } else if (strstr(Line, PATCH_LOC_KEY) == Line) { + strncpy(patch_loc, &Line[sizeof(PATCH_LOC_KEY) -1],PATCH_LOC_STRING_LEN); + patch_loc[PATCH_LOC_STRING_LEN] = '\0'; + continue; + } else if(IS_HEX(Line[0])){ + break; + } else { + return A_ERROR; + } + } + ByteCount = A_STRTOL(Line, NULL, 16); + ByteCount_Org = ByteCount; + + if(!ByteCount) + return A_ERROR; + + while(ByteCount > MAX_BYTE_LENGTH){ + + /* Handle case when the number of patch buffer is more than the 20K */ + if(MAX_NUM_PATCH_ENTRY == Patch_Count) { + for(i = 0; i < Patch_Count; i++) { + A_FREE(RamPatch[i].Data); + } + return A_ERROR; + } + RamPatch[Patch_Count].Len= MAX_BYTE_LENGTH; + RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(MAX_BYTE_LENGTH); + Patch_Count ++; + + + ByteCount= ByteCount - MAX_BYTE_LENGTH; + } + + RamPatch[Patch_Count].Len= (ByteCount & 0xFF); + if(ByteCount != 0) { + RamPatch[Patch_Count].Data = (A_UINT8*)A_MALLOC(ByteCount); + Patch_Count ++; + } + count = 0; + while(ByteCount_Org > MAX_BYTE_LENGTH){ + for (i = 0,k=0; i < MAX_BYTE_LENGTH*2; i += 2,k++,count +=2) { + if(GetNextTwoChar(patchbuffer,patchlen,&filepos,Byte) == A_ERROR) { + return A_ERROR; + } + data = A_STRTOUL(&Byte[0], NULL, 16); + RamPatch[j].Data[k] = (data & 0xFF); + + + } + j++; + ByteCount_Org = ByteCount_Org - MAX_BYTE_LENGTH; + } + if(j == 0){ + j++; + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Index [%d]\n",j)); + for (k=0; k < ByteCount_Org; i += 2,k++,count+=2) { + if(GetNextTwoChar(patchbuffer,patchlen,&filepos,Byte) == A_ERROR) { + return A_ERROR; + } + data = A_STRTOUL(Byte, NULL, 16); + RamPatch[j].Data[k] = (data & 0xFF); + + + } + return A_OK; +} + + +/********************/ +A_STATUS AthDoParsePS(A_UCHAR *srcbuffer, A_UINT32 srclen) +{ + A_STATUS status; + int i; + A_BOOL BDADDR_Present = A_ERROR; + + Tag_Count = 0; + + Total_tag_lenght = 0; + BDADDR = FALSE; + + + status = A_ERROR; + + if(NULL != srcbuffer && srclen != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("File Open Operation Successful\n")); + + status = AthParseFilesUnified(srcbuffer,srclen,MB_FILEFORMAT_PATCH); + } + + + + if(Tag_Count == 0){ + Total_tag_lenght = 10; + + } + else{ + for(i=0; i 0 && !BDADDR_Present){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR is not present adding 10 extra bytes \r\n")); + Total_tag_lenght=Total_tag_lenght + 10; + } + Total_tag_lenght = Total_tag_lenght+ 10 + (Tag_Count*4); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** Total Length %d\n",Total_tag_lenght)); + + + return status; +} +char * AthGetLine(char * buffer, int maxlen, A_UCHAR *srcbuffer,A_UINT32 len,A_UINT32 *pos) +{ + + int count; + static short flag; + char CharRead; + count = 0; + flag = A_ERROR; + + do + { + CharRead = AthReadChar(srcbuffer,len,pos); + if( CharRead == '\0' ) { + buffer[count+1] = '\0'; + if(count == 0) { + return NULL; + } + else { + return buffer; + } + } + + if(CharRead == 13) { + } else if(CharRead == 10) { + buffer[count] ='\0'; + flag = A_ERROR; + return buffer; + }else { + buffer[count++] = CharRead; + } + + } + while(count < maxlen-1 && CharRead != '\0'); + buffer[count] = '\0'; + + return buffer; +} + +void LoadHeader(A_UCHAR *HCI_PS_Command,A_UCHAR opcode,int length,int index){ + + HCI_PS_Command[0]= 0x0B; + HCI_PS_Command[1]= 0xFC; + HCI_PS_Command[2]= length + 4; + HCI_PS_Command[3]= opcode; + HCI_PS_Command[4]= (index & 0xFF); + HCI_PS_Command[5]= ((index>>8) & 0xFF); + HCI_PS_Command[6]= length; +} + +///////////////////////// +// +int AthCreateCommandList(PSCmdPacket **HciPacketList, A_UINT32 *numPackets) +{ + + A_UINT8 count; + A_UINT32 NumcmdEntry = 0; + + A_UINT32 Crc = 0; + *numPackets = 0; + + + if(Patch_Count > 0) + Crc |= RAM_PATCH_REGION; + if(Tag_Count > 0) + Crc |= RAM_PS_REGION; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("PS Thread Started CRC %x Patch Count %d Tag Count %d \n",Crc,Patch_Count,Tag_Count)); + + if(Patch_Count || Tag_Count ){ + NumcmdEntry+=(2 + Patch_Count + Tag_Count); /* CRC Packet + PS Reset Packet + Patch List + PS List*/ + if(Patch_Count > 0) { + NumcmdEntry++; /* Patch Enable Command */ + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Num Cmd Entries %d Size %d \r\n",NumcmdEntry,(A_UINT32)sizeof(PSCmdPacket) * NumcmdEntry)); + (*HciPacketList) = A_MALLOC(sizeof(PSCmdPacket) * NumcmdEntry); + if(NULL == *HciPacketList) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("memory allocation failed \r\n")); + } + AthPSCreateHCICommand(PS_VERIFY_CRC,Crc,*HciPacketList,numPackets); + if(Patch_Count > 0){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** Write Patch**** \r\n")); + AthPSCreateHCICommand(WRITE_PATCH,Patch_Count,*HciPacketList,numPackets); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** Enable Patch**** \r\n")); + AthPSCreateHCICommand(ENABLE_PATCH,0,*HciPacketList,numPackets); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** PS Reset**** %d[0x%x] \r\n",PS_RAM_SIZE,PS_RAM_SIZE)); + AthPSCreateHCICommand(PS_RESET,PS_RAM_SIZE,*HciPacketList,numPackets); + if(Tag_Count > 0){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("*** PS Write**** \r\n")); + AthPSCreateHCICommand(PS_WRITE,Tag_Count,*HciPacketList,numPackets); + } + } + if(!BDADDR){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BD ADDR not present \r\n")); + + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("PS Count %d Patch Count %d",Tag_Count, Patch_Count)); + for(count = 0; count < Patch_Count; count++) { + + A_FREE(RamPatch[Patch_Count].Data); + } + + for(count = 0; count < Tag_Count; count++) { + + A_FREE(PsTagEntry[count].TagData); + } + +/* + * SDIO Transport uses synchronous mode of data transfer + * So, AthPSOperations() call returns only after receiving the + * command complete event. + */ + return *numPackets; +} + + +//////////////////////// + +///////////// +static A_STATUS AthPSCreateHCICommand(A_UCHAR Opcode, A_UINT32 Param1,PSCmdPacket *PSPatchPacket,A_UINT32 *index) +{ + A_UCHAR *HCI_PS_Command; + A_UINT32 Length; + int i,j; + + switch(Opcode) + { + case WRITE_PATCH: + + + for(i=0;i< Param1;i++){ + + HCI_PS_Command = (A_UCHAR *) A_MALLOC(RamPatch[i].Len+HCI_COMMAND_HEADER); + if(HCI_PS_Command == NULL){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n")); + return A_ERROR; + } + memset (HCI_PS_Command, 0, RamPatch[i].Len+HCI_COMMAND_HEADER); + LoadHeader(HCI_PS_Command,Opcode,RamPatch[i].Len,i); + for(j=0;j> 8) & 0xFF); + PSPatchPacket[*index].Hcipacket = HCI_PS_Command; + PSPatchPacket[*index].packetLen = Length+HCI_COMMAND_HEADER; + (*index)++; + + break; + + case PS_WRITE: + for(i=0;i< Param1;i++){ + if(PsTagEntry[i].TagId ==1) + BDADDR = TRUE; + + HCI_PS_Command = (A_UCHAR *) A_MALLOC(PsTagEntry[i].TagLen+HCI_COMMAND_HEADER); + if(HCI_PS_Command == NULL){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("MALLOC Failed\r\n")); + return A_ERROR; + } + + memset (HCI_PS_Command, 0, PsTagEntry[i].TagLen+HCI_COMMAND_HEADER); + LoadHeader(HCI_PS_Command,Opcode,PsTagEntry[i].TagLen,PsTagEntry[i].TagId); + + for(j=0;j +#include +#include "athdefs.h" +#ifdef HCI_TRANSPORT_SDIO +#include "a_config.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME misc +#include "a_debug.h" +#include "common_drv.h" +#include "hci_transport_api.h" +#include "ar3kconfig.h" +#else +#ifndef A_PRINTF +#define A_PRINTF(args...) printk(KERN_ALERT args) +#endif /* A_PRINTF */ +#include "debug_linux.h" + +/* Helper data type declaration */ + +#ifndef A_UINT32 +#define A_UCHAR unsigned char +#define A_UINT32 unsigned long +#define A_UINT16 unsigned short +#define A_UINT8 unsigned char +#define A_BOOL unsigned char +#endif /* A_UINT32 */ + +#define ATH_DEBUG_ERR (1 << 0) +#define ATH_DEBUG_WARN (1 << 1) +#define ATH_DEBUG_INFO (1 << 2) + + + +#define FALSE 0 +#define TRUE 1 + +#ifndef A_MALLOC +#define A_MALLOC(size) kmalloc((size),GFP_KERNEL) +#endif /* A_MALLOC */ + + +#ifndef A_FREE +#define A_FREE(addr) kfree((addr)) +#endif /* A_MALLOC */ +#endif /* HCI_TRANSPORT_UART */ + +/* String manipulation APIs */ +#ifndef A_STRTOUL +#define A_STRTOUL simple_strtoul +#endif /* A_STRTOL */ + +#ifndef A_STRTOL +#define A_STRTOL simple_strtol +#endif /* A_STRTOL */ + + +/* The maximum number of bytes possible in a patch entry */ +#define MAX_PATCH_SIZE 30000 + +/* Maximum HCI packets that will be formed from the Patch file */ +#define MAX_NUM_PATCH_ENTRY (MAX_PATCH_SIZE/MAX_BYTE_LENGTH) + 1 + + + + + + + +typedef struct PSCmdPacket +{ + A_UCHAR *Hcipacket; + int packetLen; +} PSCmdPacket; + +/* Parses a Patch information buffer and store it in global structure */ +A_STATUS AthDoParsePatch(A_UCHAR *, A_UINT32, A_UCHAR*); + +/* parses a PS information buffer and stores it in a global structure */ +A_STATUS AthDoParsePS(A_UCHAR *, A_UINT32); + +/* + * Uses the output of Both AthDoParsePS and AthDoParsePatch APIs to form HCI command array with + * all the PS and patch commands. + * The list will have the below mentioned commands in order. + * CRC command packet + * Download patch command(s) + * Enable patch Command + * PS Reset Command + * PS Tag Command(s) + * + */ +int AthCreateCommandList(PSCmdPacket **, A_UINT32 *); + +/* Cleanup the dynamically allicated HCI command list */ +A_STATUS AthFreeCommandList(PSCmdPacket **HciPacketList, A_UINT32 numPackets); +#endif /* __AR3KPSPARSER_H */ diff --git a/drivers/net/wireless/ar6003/host/miscdrv/common_drv.c b/drivers/net/wireless/ar6003/host/miscdrv/common_drv.c new file mode 100644 index 000000000000..d3039178a177 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/common_drv.c @@ -0,0 +1,882 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" + +#include "a_osapi.h" +#include "targaddrs.h" +#include "hif.h" +#include "htc_api.h" +#include "wmi.h" +#include "bmi.h" +#include "bmi_msg.h" +#include "common_drv.h" +#define ATH_MODULE_NAME misc +#include "a_debug.h" +#include "ar6000_diag.h" +#include "target_reg_table.h" +#include "host_reg_table.h" + +static ATH_DEBUG_MODULE_DBG_INFO *g_pModuleInfoHead = NULL; +static A_MUTEX_T g_ModuleListLock; +static A_BOOL g_ModuleDebugInit = FALSE; + +#ifdef DEBUG + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(misc, + "misc", + "Common and misc APIs", + ATH_DEBUG_MASK_DEFAULTS, + 0, + NULL); + +#endif + +#define AR6001_LOCAL_COUNT_ADDRESS 0x0c014080 +#define AR6002_LOCAL_COUNT_ADDRESS 0x00018080 +#define AR6003_LOCAL_COUNT_ADDRESS 0x00018080 + +static A_UINT8 custDataAR6002[AR6002_CUST_DATA_SIZE]; +static A_UINT8 custDataAR6003[AR6003_CUST_DATA_SIZE]; +static A_UINT8 custDataMCKINLEY[MCKINLEY_CUST_DATA_SIZE]; + + +/* + * Read from the AR6000 through its diagnostic window. + * No cooperation from the Target is required for this. + */ +A_STATUS +ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data) +{ + return HIFDiagReadAccess(hifDevice, *address, data); +} + + +/* + * Write to the AR6000 through its diagnostic window. + * No cooperation from the Target is required for this. + */ +A_STATUS +ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data) +{ + return HIFDiagWriteAccess(hifDevice, *address, *data); +} + +A_STATUS +ar6000_ReadDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address, + A_UCHAR *data, A_UINT32 length) +{ + A_UINT32 count; + A_STATUS status = A_OK; + + for (count = 0; count < length; count += 4, address += 4) { + if ((status = HIFDiagReadAccess(hifDevice, address, + (A_UINT32 *)&data[count])) != A_OK) + { + break; + } + } + + return status; +} + +A_STATUS +ar6000_WriteDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address, + A_UCHAR *data, A_UINT32 length) +{ + A_UINT32 count; + A_STATUS status = A_OK; + + for (count = 0; count < length; count += 4, address += 4) { + if ((status = HIFDiagWriteAccess(hifDevice, address, + *((A_UINT32 *)&data[count]))) != A_OK) + { + break; + } + } + + return status; +} + +#ifdef HIF_MESSAGE_BASED + +/* TODO : for message based interfaces there are no HOST registers. These are just + * stub functions for now */ + +A_STATUS +ar6k_ReadTargetRegister(HIF_DEVICE *hifDevice, int regsel, A_UINT32 *regval) +{ + + /* TODO */ + return A_ERROR; +} + +void +ar6k_FetchTargetRegs(HIF_DEVICE *hifDevice, A_UINT32 *targregs) +{ + int i; + for (i=0; i REGISTER_DUMP_LEN_MAX +#error "REG_DUMP_COUNT_AR6001 too large" +#endif +#if REG_DUMP_COUNT_AR6002 > REGISTER_DUMP_LEN_MAX +#error "REG_DUMP_COUNT_AR6002 too large" +#endif +#if REG_DUMP_COUNT_AR6003 > REGISTER_DUMP_LEN_MAX +#error "REG_DUMP_COUNT_AR6003 too large" +#endif +#if REG_DUMP_COUNT_MCKINLEY > REGISTER_DUMP_LEN_MAX +#error "REG_DUMP_COUNT_MCKINLEY too large" +#endif + + +void ar6000_dump_target_assert_info(HIF_DEVICE *hifDevice, A_UINT32 TargetType) +{ + A_UINT32 address; + A_UINT32 regDumpArea = 0; + A_STATUS status; + A_UINT32 regDumpValues[REGISTER_DUMP_LEN_MAX]; + A_UINT32 regDumpCount = 0; + A_UINT32 i; + + do { + + /* the reg dump pointer is copied to the host interest area */ + address = HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_failure_state); + address = TARG_VTOP(TargetType, address); + + if (TargetType == TARGET_TYPE_AR6002) { + regDumpCount = REG_DUMP_COUNT_AR6002; + } else if (TargetType == TARGET_TYPE_AR6003) { + regDumpCount = REG_DUMP_COUNT_AR6003; + } else if (TargetType == TARGET_TYPE_MCKINLEY) { + regDumpCount = REG_DUMP_COUNT_MCKINLEY; + } else { + A_ASSERT(0); + } + + /* read RAM location through diagnostic window */ + status = ar6000_ReadRegDiag(hifDevice, &address, ®DumpArea); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Failed to get ptr to register dump area \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Location of register dump data: 0x%X \n",regDumpArea)); + + if (regDumpArea == 0) { + /* no reg dump */ + break; + } + + regDumpArea = TARG_VTOP(TargetType, regDumpArea); + + /* fetch register dump data */ + status = ar6000_ReadDataDiag(hifDevice, + regDumpArea, + (A_UCHAR *)®DumpValues[0], + regDumpCount * (sizeof(A_UINT32))); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Failed to get register dump \n")); + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Register Dump: \n")); + + for (i = 0; i < regDumpCount; i++) + { + AR_DEBUG_PRINTF (ATH_DEBUG_ERR,(" %d : 0x%8.8X \n",i, regDumpValues[i])); +#ifdef UNDER_CE + /* + * For Every logPrintf() Open the File so that in case of Crashes + * We will have until the Last Message Flushed on to the File + * So use logPrintf Sparingly..!! + */ + tgtassertPrintf (ATH_DEBUG_TRC," %d: 0x%8.8X \n",i, regDumpValues[i]); +#endif + } + + } while (FALSE); + +} + +/* set HTC/Mbox operational parameters, this can only be called when the target is in the + * BMI phase */ +A_STATUS ar6000_set_htc_params(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 MboxIsrYieldValue, + A_UINT8 HtcControlBuffers) +{ + A_STATUS status; + A_UINT32 blocksizes[HTC_MAILBOX_NUM_MAX]; + + do { + /* get the block sizes */ + status = HIFConfigureDevice(hifDevice, HIF_DEVICE_GET_MBOX_BLOCK_SIZE, + blocksizes, sizeof(blocksizes)); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_LOG_ERR,("Failed to get block size info from HIF layer...\n")); + break; + } + /* note: we actually get the block size for mailbox 1, for SDIO the block + * size on mailbox 0 is artificially set to 1 */ + /* must be a power of 2 */ + A_ASSERT((blocksizes[1] & (blocksizes[1] - 1)) == 0); + + if (HtcControlBuffers != 0) { + /* set override for number of control buffers to use */ + blocksizes[1] |= ((A_UINT32)HtcControlBuffers) << 16; + } + + /* set the host interest area for the block size */ + status = BMIWriteMemory(hifDevice, + HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_io_block_sz), + (A_UCHAR *)&blocksizes[1], + 4); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_LOG_ERR,("BMIWriteMemory for IO block size failed \n")); + break; + } + + AR_DEBUG_PRINTF(ATH_LOG_INF,("Block Size Set: %d (target address:0x%X)\n", + blocksizes[1], HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_io_block_sz))); + + if (MboxIsrYieldValue != 0) { + /* set the host interest area for the mbox ISR yield limit */ + status = BMIWriteMemory(hifDevice, + HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_isr_yield_limit), + (A_UCHAR *)&MboxIsrYieldValue, + 4); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_LOG_ERR,("BMIWriteMemory for yield limit failed \n")); + break; + } + } + + } while (FALSE); + + return status; +} + + +static A_STATUS prepare_ar6002(HIF_DEVICE *hifDevice, A_UINT32 TargetVersion) +{ + A_STATUS status = A_OK; + + /* placeholder */ + + return status; +} + +static A_STATUS prepare_ar6003(HIF_DEVICE *hifDevice, A_UINT32 TargetVersion) +{ + A_STATUS status = A_OK; + + /* placeholder */ + + return status; +} + +static A_STATUS prepare_MCKINLEY(HIF_DEVICE *hifDevice, A_UINT32 TargetVersion) +{ + A_STATUS status = A_OK; + A_UINT32 value = 0; + + /* force the setting to disable sleep for Bringup FIXME_MK */ + value |= WLAN_SYSTEM_SLEEP_DISABLE_MASK; + + status = BMIWriteMemory(hifDevice, + HOST_INTEREST_ITEM_ADDRESS(TARGET_TYPE_AR6002, hi_system_sleep_setting), + (A_UCHAR *)&value, + 4); + + return status; +} + +/* this function assumes the caller has already initialized the BMI APIs */ +A_STATUS ar6000_prepare_target(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 TargetVersion) +{ + if (TargetType == TARGET_TYPE_AR6002) { + /* do any preparations for AR6002 devices */ + return prepare_ar6002(hifDevice,TargetVersion); + } else if (TargetType == TARGET_TYPE_AR6003) { + return prepare_ar6003(hifDevice,TargetVersion); + } else if (TargetType == TARGET_TYPE_MCKINLEY) { + return prepare_MCKINLEY(hifDevice,TargetVersion); + } + + return A_OK; +} + +#if defined(CONFIG_AR6002_REV1_FORCE_HOST) +/* + * Call this function just before the call to BMIInit + * in order to force* AR6002 rev 1.x firmware to detect a Host. + * THIS IS FOR USE ONLY WITH AR6002 REV 1.x. + * TBDXXX: Remove this function when REV 1.x is desupported. + */ +A_STATUS +ar6002_REV1_reset_force_host (HIF_DEVICE *hifDevice) +{ + A_INT32 i; + struct forceROM_s { + A_UINT32 addr; + A_UINT32 data; + }; + struct forceROM_s *ForceROM; + A_INT32 szForceROM; + A_STATUS status = A_OK; + A_UINT32 address; + A_UINT32 data; + + /* Force AR6002 REV1.x to recognize Host presence. + * + * Note: Use RAM at 0x52df80..0x52dfa0 with ROM Remap entry 0 + * so that this workaround functions with AR6002.war1.sh. We + * could fold that entire workaround into this one, but it's not + * worth the effort at this point. This workaround cannot be + * merged into the other workaround because this must be done + * before BMI. + */ + + static struct forceROM_s ForceROM_NEW[] = { + {0x52df80, 0x20f31c07}, + {0x52df84, 0x92374420}, + {0x52df88, 0x1d120c03}, + {0x52df8c, 0xff8216f0}, + {0x52df90, 0xf01d120c}, + {0x52df94, 0x81004136}, + {0x52df98, 0xbc9100bd}, + {0x52df9c, 0x00bba100}, + + {0x00008000|MC_TCAM_TARGET_ADDRESS, 0x0012dfe0}, /* Use remap entry 0 */ + {0x00008000|MC_TCAM_COMPARE_ADDRESS, 0x000e2380}, + {0x00008000|MC_TCAM_MASK_ADDRESS, 0x00000000}, + {0x00008000|MC_TCAM_VALID_ADDRESS, 0x00000001}, + + {0x00018000|(LOCAL_COUNT_ADDRESS+0x10), 0}, /* clear BMI credit counter */ + + {0x00004000|AR6002_RESET_CONTROL_ADDRESS, RESET_CONTROL_WARM_RST_MASK}, + }; + + address = 0x004ed4b0; /* REV1 target software ID is stored here */ + status = ar6000_ReadRegDiag(hifDevice, &address, &data); + if (A_FAILED(status) || (data != AR6002_VERSION_REV1)) { + return A_ERROR; /* Not AR6002 REV1 */ + } + + ForceROM = ForceROM_NEW; + szForceROM = sizeof(ForceROM_NEW)/sizeof(*ForceROM); + + ATH_DEBUG_PRINTF (DBG_MISC_DRV, ATH_DEBUG_TRC, ("Force Target to recognize Host....\n")); + for (i = 0; i < szForceROM; i++) + { + if (ar6000_WriteRegDiag(hifDevice, + &ForceROM[i].addr, + &ForceROM[i].data) != A_OK) + { + ATH_DEBUG_PRINTF (DBG_MISC_DRV, ATH_DEBUG_TRC, ("Cannot force Target to recognize Host!\n")); + return A_ERROR; + } + } + + A_MDELAY(1000); + + return A_OK; +} + +#endif /* CONFIG_AR6002_REV1_FORCE_HOST */ + +void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription) +{ + A_CHAR stream[60]; + A_CHAR byteOffsetStr[10]; + A_UINT32 i; + A_UINT16 offset, count, byteOffset; + + A_PRINTF("<---------Dumping %d Bytes : %s ------>\n", length, pDescription); + + count = 0; + offset = 0; + byteOffset = 0; + for(i = 0; i < length; i++) { + A_SPRINTF(stream + offset, "%2.2X ", buffer[i]); + count ++; + offset += 3; + + if(count == 16) { + count = 0; + offset = 0; + A_SPRINTF(byteOffsetStr,"%4.4X",byteOffset); + A_PRINTF("[%s]: %s\n", byteOffsetStr, stream); + A_MEMZERO(stream, 60); + byteOffset += 16; + } + } + + if(offset != 0) { + A_SPRINTF(byteOffsetStr,"%4.4X",byteOffset); + A_PRINTF("[%s]: %s\n", byteOffsetStr, stream); + } + + A_PRINTF("<------------------------------------------------->\n"); +} + +void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo) +{ + int i; + ATH_DEBUG_MASK_DESCRIPTION *pDesc; + + if (pInfo == NULL) { + return; + } + + pDesc = pInfo->pMaskDescriptions; + + A_PRINTF("========================================================\n\n"); + A_PRINTF("Module Debug Info => Name : %s \n", pInfo->ModuleName); + A_PRINTF(" => Descr. : %s \n", pInfo->ModuleDescription); + A_PRINTF("\n Current mask => 0x%8.8X \n", pInfo->CurrentMask); + A_PRINTF("\n Avail. Debug Masks :\n\n"); + + for (i = 0; i < pInfo->MaxDescriptions; i++,pDesc++) { + A_PRINTF(" => 0x%8.8X -- %s \n", pDesc->Mask, pDesc->Description); + } + + if (0 == i) { + A_PRINTF(" => * none defined * \n"); + } + + A_PRINTF("\n Standard Debug Masks :\n\n"); + /* print standard masks */ + A_PRINTF(" => 0x%8.8X -- Errors \n", ATH_DEBUG_ERR); + A_PRINTF(" => 0x%8.8X -- Warnings \n", ATH_DEBUG_WARN); + A_PRINTF(" => 0x%8.8X -- Informational \n", ATH_DEBUG_INFO); + A_PRINTF(" => 0x%8.8X -- Tracing \n", ATH_DEBUG_TRC); + A_PRINTF("\n========================================================\n"); + +} + + +static ATH_DEBUG_MODULE_DBG_INFO *FindModule(A_CHAR *module_name) +{ + ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead; + + if (!g_ModuleDebugInit) { + return NULL; + } + + while (pInfo != NULL) { + /* TODO: need to use something other than strlen */ + if (A_MEMCMP(pInfo->ModuleName,module_name,strlen(module_name)) == 0) { + break; + } + pInfo = pInfo->pNext; + } + + return pInfo; +} + + +void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo) +{ + if (!g_ModuleDebugInit) { + return; + } + + A_MUTEX_LOCK(&g_ModuleListLock); + + if (!(pInfo->Flags & ATH_DEBUG_INFO_FLAGS_REGISTERED)) { + if (g_pModuleInfoHead == NULL) { + g_pModuleInfoHead = pInfo; + } else { + pInfo->pNext = g_pModuleInfoHead; + g_pModuleInfoHead = pInfo; + } + pInfo->Flags |= ATH_DEBUG_INFO_FLAGS_REGISTERED; + } + + A_MUTEX_UNLOCK(&g_ModuleListLock); +} + +void a_dump_module_debug_info_by_name(A_CHAR *module_name) +{ + ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead; + + if (!g_ModuleDebugInit) { + return; + } + + if (A_MEMCMP(module_name,"all",3) == 0) { + /* dump all */ + while (pInfo != NULL) { + a_dump_module_debug_info(pInfo); + pInfo = pInfo->pNext; + } + return; + } + + pInfo = FindModule(module_name); + + if (pInfo != NULL) { + a_dump_module_debug_info(pInfo); + } + +} + +A_STATUS a_get_module_mask(A_CHAR *module_name, A_UINT32 *pMask) +{ + ATH_DEBUG_MODULE_DBG_INFO *pInfo = FindModule(module_name); + + if (NULL == pInfo) { + return A_ERROR; + } + + *pMask = pInfo->CurrentMask; + return A_OK; +} + +A_STATUS a_set_module_mask(A_CHAR *module_name, A_UINT32 Mask) +{ + ATH_DEBUG_MODULE_DBG_INFO *pInfo = FindModule(module_name); + + if (NULL == pInfo) { + return A_ERROR; + } + + pInfo->CurrentMask = Mask; + A_PRINTF("Module %s, new mask: 0x%8.8X \n",module_name,pInfo->CurrentMask); + return A_OK; +} + + +void a_module_debug_support_init(void) +{ + if (g_ModuleDebugInit) { + return; + } + A_MUTEX_INIT(&g_ModuleListLock); + g_pModuleInfoHead = NULL; + g_ModuleDebugInit = TRUE; + A_REGISTER_MODULE_DEBUG_INFO(misc); +} + +void a_module_debug_support_cleanup(void) +{ + ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead; + ATH_DEBUG_MODULE_DBG_INFO *pCur; + + if (!g_ModuleDebugInit) { + return; + } + + g_ModuleDebugInit = FALSE; + + A_MUTEX_LOCK(&g_ModuleListLock); + + while (pInfo != NULL) { + pCur = pInfo; + pInfo = pInfo->pNext; + pCur->pNext = NULL; + /* clear registered flag */ + pCur->Flags &= ~ATH_DEBUG_INFO_FLAGS_REGISTERED; + } + + A_MUTEX_UNLOCK(&g_ModuleListLock); + + A_MUTEX_DELETE(&g_ModuleListLock); + g_pModuleInfoHead = NULL; +} + + /* can only be called during bmi init stage */ +A_STATUS ar6000_set_hci_bridge_flags(HIF_DEVICE *hifDevice, + A_UINT32 TargetType, + A_UINT32 Flags) +{ + A_STATUS status = A_OK; + + do { + + if ((TargetType != TARGET_TYPE_AR6003) && (TargetType != TARGET_TYPE_MCKINLEY)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("Target Type:%d, does not support HCI bridging! \n", + TargetType)); + break; + } + + /* set hci bridge flags */ + status = BMIWriteMemory(hifDevice, + HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_hci_bridge_flags), + (A_UCHAR *)&Flags, + 4); + + + } while (FALSE); + + return status; +} + diff --git a/drivers/net/wireless/ar6003/host/miscdrv/credit_dist.c b/drivers/net/wireless/ar6003/host/miscdrv/credit_dist.c new file mode 100644 index 000000000000..f2f76d31d5fd --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/credit_dist.c @@ -0,0 +1,417 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +#include "a_config.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#define ATH_MODULE_NAME misc +#include "a_debug.h" +#include "htc_api.h" +#include "common_drv.h" + +/********* CREDIT DISTRIBUTION FUNCTIONS ******************************************/ + +#define NO_VO_SERVICE 1 /* currently WMI only uses 3 data streams, so we leave VO service inactive */ +#define CONFIG_GIVE_LOW_PRIORITY_STREAMS_MIN_CREDITS 1 + +#ifdef NO_VO_SERVICE +#define DATA_SVCS_USED 3 +#else +#define DATA_SVCS_USED 4 +#endif + +static void RedistributeCredits(COMMON_CREDIT_STATE_INFO *pCredInfo, + HTC_ENDPOINT_CREDIT_DIST *pEPDistList); + +static void SeekCredits(COMMON_CREDIT_STATE_INFO *pCredInfo, + HTC_ENDPOINT_CREDIT_DIST *pEPDistList); + +/* reduce an ep's credits back to a set limit */ +static INLINE void ReduceCredits(COMMON_CREDIT_STATE_INFO *pCredInfo, + HTC_ENDPOINT_CREDIT_DIST *pEpDist, + int Limit) +{ + int credits; + + /* set the new limit */ + pEpDist->TxCreditsAssigned = Limit; + + if (pEpDist->TxCredits <= Limit) { + return; + } + + /* figure out how much to take away */ + credits = pEpDist->TxCredits - Limit; + /* take them away */ + pEpDist->TxCredits -= credits; + pCredInfo->CurrentFreeCredits += credits; +} + +/* give an endpoint some credits from the free credit pool */ +#define GiveCredits(pCredInfo,pEpDist,credits) \ +{ \ + (pEpDist)->TxCredits += (credits); \ + (pEpDist)->TxCreditsAssigned += (credits); \ + (pCredInfo)->CurrentFreeCredits -= (credits); \ +} + + +/* default credit init callback. + * This function is called in the context of HTCStart() to setup initial (application-specific) + * credit distributions */ +static void ar6000_credit_init(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPList, + int TotalCredits) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist; + int count; + COMMON_CREDIT_STATE_INFO *pCredInfo = (COMMON_CREDIT_STATE_INFO *)Context; + + pCredInfo->CurrentFreeCredits = TotalCredits; + pCredInfo->TotalAvailableCredits = TotalCredits; + + pCurEpDist = pEPList; + + /* run through the list and initialize */ + while (pCurEpDist != NULL) { + + /* set minimums for each endpoint */ + pCurEpDist->TxCreditsMin = pCurEpDist->TxCreditsPerMaxMsg; + +#ifdef CONFIG_GIVE_LOW_PRIORITY_STREAMS_MIN_CREDITS + if (TotalCredits > 4) + { + if ((pCurEpDist->ServiceID == WMI_DATA_BK_SVC) || (pCurEpDist->ServiceID == WMI_DATA_BE_SVC)){ + /* assign at least min credits to lower than VO priority services */ + GiveCredits(pCredInfo,pCurEpDist,pCurEpDist->TxCreditsMin); + /* force active */ + SET_EP_ACTIVE(pCurEpDist); + } + } + +#endif + + if (pCurEpDist->ServiceID == WMI_CONTROL_SVC) { + /* give control service some credits */ + GiveCredits(pCredInfo,pCurEpDist,pCurEpDist->TxCreditsMin); + /* control service is always marked active, it never goes inactive EVER */ + SET_EP_ACTIVE(pCurEpDist); + } else if (pCurEpDist->ServiceID == WMI_DATA_BK_SVC) { + /* this is the lowest priority data endpoint, save this off for easy access */ + pCredInfo->pLowestPriEpDist = pCurEpDist; + } + + /* Streams have to be created (explicit | implicit)for all kinds + * of traffic. BE endpoints are also inactive in the beginning. + * When BE traffic starts it creates implicit streams that + * redistributes credits. + */ + + /* note, all other endpoints have minimums set but are initially given NO credits. + * Credits will be distributed as traffic activity demands */ + pCurEpDist = pCurEpDist->pNext; + } + + if (pCredInfo->CurrentFreeCredits <= 0) { + AR_DEBUG_PRINTF(ATH_LOG_INF, ("Not enough credits (%d) to do credit distributions \n", TotalCredits)); + A_ASSERT(FALSE); + return; + } + + /* reset list */ + pCurEpDist = pEPList; + /* now run through the list and set max operating credit limits for everyone */ + while (pCurEpDist != NULL) { + if (pCurEpDist->ServiceID == WMI_CONTROL_SVC) { + /* control service max is just 1 max message */ + pCurEpDist->TxCreditsNorm = pCurEpDist->TxCreditsPerMaxMsg; + } else { + /* for the remaining data endpoints, we assume that each TxCreditsPerMaxMsg are + * the same. + * We use a simple calculation here, we take the remaining credits and + * determine how many max messages this can cover and then set each endpoint's + * normal value equal to 3/4 this amount. + * */ + count = (pCredInfo->CurrentFreeCredits/pCurEpDist->TxCreditsPerMaxMsg) * pCurEpDist->TxCreditsPerMaxMsg; + count = (count * 3) >> 2; + count = max(count,pCurEpDist->TxCreditsPerMaxMsg); + /* set normal */ + pCurEpDist->TxCreditsNorm = count; + + } + pCurEpDist = pCurEpDist->pNext; + } + +} + + +/* default credit distribution callback + * This callback is invoked whenever endpoints require credit distributions. + * A lock is held while this function is invoked, this function shall NOT block. + * The pEPDistList is a list of distribution structures in prioritized order as + * defined by the call to the HTCSetCreditDistribution() api. + * + */ +static void ar6000_credit_distribute(void *Context, + HTC_ENDPOINT_CREDIT_DIST *pEPDistList, + HTC_CREDIT_DIST_REASON Reason) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist; + COMMON_CREDIT_STATE_INFO *pCredInfo = (COMMON_CREDIT_STATE_INFO *)Context; + + switch (Reason) { + case HTC_CREDIT_DIST_SEND_COMPLETE : + pCurEpDist = pEPDistList; + /* we are given the start of the endpoint distribution list. + * There may be one or more endpoints to service. + * Run through the list and distribute credits */ + while (pCurEpDist != NULL) { + + if (pCurEpDist->TxCreditsToDist > 0) { + /* return the credits back to the endpoint */ + pCurEpDist->TxCredits += pCurEpDist->TxCreditsToDist; + /* always zero out when we are done */ + pCurEpDist->TxCreditsToDist = 0; + + if (pCurEpDist->TxCredits > pCurEpDist->TxCreditsAssigned) { + /* reduce to the assigned limit, previous credit reductions + * could have caused the limit to change */ + ReduceCredits(pCredInfo, pCurEpDist, pCurEpDist->TxCreditsAssigned); + } + + if (pCurEpDist->TxCredits > pCurEpDist->TxCreditsNorm) { + /* oversubscribed endpoints need to reduce back to normal */ + ReduceCredits(pCredInfo, pCurEpDist, pCurEpDist->TxCreditsNorm); + } + + if (!IS_EP_ACTIVE(pCurEpDist)) { + /* endpoint is inactive, now check for messages waiting for credits */ + if (pCurEpDist->TxQueueDepth == 0) { + /* EP is inactive and there are no pending messages, + * reduce credits back to zero to recover credits */ + ReduceCredits(pCredInfo, pCurEpDist, 0); + } + } + } + + pCurEpDist = pCurEpDist->pNext; + } + + break; + + case HTC_CREDIT_DIST_ACTIVITY_CHANGE : + RedistributeCredits(pCredInfo,pEPDistList); + break; + case HTC_CREDIT_DIST_SEEK_CREDITS : + SeekCredits(pCredInfo,pEPDistList); + break; + case HTC_DUMP_CREDIT_STATE : + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Credit Distribution, total : %d, free : %d\n", + pCredInfo->TotalAvailableCredits, pCredInfo->CurrentFreeCredits)); + break; + default: + break; + + } + + /* sanity checks done after each distribution action */ + A_ASSERT(pCredInfo->CurrentFreeCredits <= pCredInfo->TotalAvailableCredits); + A_ASSERT(pCredInfo->CurrentFreeCredits >= 0); + +} + +/* redistribute credits based on activity change */ +static void RedistributeCredits(COMMON_CREDIT_STATE_INFO *pCredInfo, + HTC_ENDPOINT_CREDIT_DIST *pEPDistList) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist = pEPDistList; + + /* walk through the list and remove credits from inactive endpoints */ + while (pCurEpDist != NULL) { + +#ifdef CONFIG_GIVE_LOW_PRIORITY_STREAMS_MIN_CREDITS + + if ((pCurEpDist->ServiceID == WMI_DATA_BK_SVC) || (pCurEpDist->ServiceID == WMI_DATA_BE_SVC)) { + /* force low priority streams to always be active to retain their minimum credit distribution */ + SET_EP_ACTIVE(pCurEpDist); + } +#endif + + if (pCurEpDist->ServiceID != WMI_CONTROL_SVC) { + if (!IS_EP_ACTIVE(pCurEpDist)) { + if (pCurEpDist->TxQueueDepth == 0) { + /* EP is inactive and there are no pending messages, reduce credits back to zero */ + ReduceCredits(pCredInfo, pCurEpDist, 0); + } else { + /* we cannot zero the credits assigned to this EP, but to keep + * the credits available for these leftover packets, reduce to + * a minimum */ + ReduceCredits(pCredInfo, pCurEpDist, pCurEpDist->TxCreditsMin); + } + } + } + + /* NOTE in the active case, we do not need to do anything further, + * when an EP goes active and needs credits, HTC will call into + * our distribution function using a reason code of HTC_CREDIT_DIST_SEEK_CREDITS */ + + pCurEpDist = pCurEpDist->pNext; + } + +} + +/* HTC has an endpoint that needs credits, pEPDist is the endpoint in question */ +static void SeekCredits(COMMON_CREDIT_STATE_INFO *pCredInfo, + HTC_ENDPOINT_CREDIT_DIST *pEPDist) +{ + HTC_ENDPOINT_CREDIT_DIST *pCurEpDist; + int credits = 0; + int need; + + do { + + if (pEPDist->ServiceID == WMI_CONTROL_SVC) { + /* we never oversubscribe on the control service, this is not + * a high performance path and the target never holds onto control + * credits for too long */ + break; + } + +#ifdef CONFIG_GIVE_LOW_PRIORITY_STREAMS_MIN_CREDITS + if (pEPDist->ServiceID == WMI_DATA_VI_SVC) { + if ((pEPDist->TxCreditsAssigned >= pEPDist->TxCreditsNorm)) { + /* limit VI service from oversubscribing */ + break; + } + } + + if (pEPDist->ServiceID == WMI_DATA_VO_SVC) { + if ((pEPDist->TxCreditsAssigned >= pEPDist->TxCreditsNorm)) { + /* limit VO service from oversubscribing */ + break; + } + } +#else + if (pEPDist->ServiceID == WMI_DATA_VI_SVC) { + if ((pEPDist->TxCreditsAssigned >= pEPDist->TxCreditsNorm) || + (pCredInfo->CurrentFreeCredits <= pEPDist->TxCreditsPerMaxMsg)) { + /* limit VI service from oversubscribing */ + /* at least one free credit will not be used by VI */ + break; + } + } + + if (pEPDist->ServiceID == WMI_DATA_VO_SVC) { + if ((pEPDist->TxCreditsAssigned >= pEPDist->TxCreditsNorm) || + (pCredInfo->CurrentFreeCredits <= pEPDist->TxCreditsPerMaxMsg)) { + /* limit VO service from oversubscribing */ + /* at least one free credit will not be used by VO */ + break; + } + } +#endif + + /* for all other services, we follow a simple algorithm of + * 1. checking the free pool for credits + * 2. checking lower priority endpoints for credits to take */ + + /* give what we can */ + credits = min(pCredInfo->CurrentFreeCredits,pEPDist->TxCreditsSeek); + + if (credits >= pEPDist->TxCreditsSeek) { + /* we found some to fullfill the seek request */ + break; + } + + /* we don't have enough in the free pool, try taking away from lower priority services + * + * The rule for taking away credits: + * 1. Only take from lower priority endpoints + * 2. Only take what is allocated above the minimum (never starve an endpoint completely) + * 3. Only take what you need. + * + * */ + + /* starting at the lowest priority */ + pCurEpDist = pCredInfo->pLowestPriEpDist; + + /* work backwards until we hit the endpoint again */ + while (pCurEpDist != pEPDist) { + /* calculate how many we need so far */ + need = pEPDist->TxCreditsSeek - pCredInfo->CurrentFreeCredits; + + if ((pCurEpDist->TxCreditsAssigned - need) >= pCurEpDist->TxCreditsMin) { + /* the current one has been allocated more than it's minimum and it + * has enough credits assigned above it's minimum to fullfill our need + * try to take away just enough to fullfill our need */ + ReduceCredits(pCredInfo, + pCurEpDist, + pCurEpDist->TxCreditsAssigned - need); + + if (pCredInfo->CurrentFreeCredits >= pEPDist->TxCreditsSeek) { + /* we have enough */ + break; + } + } + + pCurEpDist = pCurEpDist->pPrev; + } + + /* return what we can get */ + credits = min(pCredInfo->CurrentFreeCredits,pEPDist->TxCreditsSeek); + + } while (FALSE); + + /* did we find some credits? */ + if (credits) { + /* give what we can */ + GiveCredits(pCredInfo, pEPDist, credits); + } + +} + +/* initialize and setup credit distribution */ +A_STATUS ar6000_setup_credit_dist(HTC_HANDLE HTCHandle, COMMON_CREDIT_STATE_INFO *pCredInfo) +{ + HTC_SERVICE_ID servicepriority[5]; + + A_MEMZERO(pCredInfo,sizeof(COMMON_CREDIT_STATE_INFO)); + + servicepriority[0] = WMI_CONTROL_SVC; /* highest */ + servicepriority[1] = WMI_DATA_VO_SVC; + servicepriority[2] = WMI_DATA_VI_SVC; + servicepriority[3] = WMI_DATA_BE_SVC; + servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */ + + /* set callbacks and priority list */ + HTCSetCreditDistribution(HTCHandle, + pCredInfo, + ar6000_credit_distribute, + ar6000_credit_init, + servicepriority, + 5); + + return A_OK; +} + diff --git a/drivers/net/wireless/ar6003/host/miscdrv/makefile b/drivers/net/wireless/ar6003/host/miscdrv/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/miscdrv/miscdrv.h b/drivers/net/wireless/ar6003/host/miscdrv/miscdrv.h new file mode 100644 index 000000000000..5defe9c636f4 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/miscdrv/miscdrv.h @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _MISCDRV_H +#define _MISCDRV_H + +A_UINT32 ar6kRev2Array[][128] = { + {0xFFFF, 0xFFFF}, // No Patches + }; + +#define CFG_REV2_ITEMS 0 // no patches so far +#define AR6K_RESET_ADDR 0x4000 +#define AR6K_RESET_VAL 0x100 + +#define EEPROM_SZ 768 +#define EEPROM_WAIT_LIMIT 4 + +#endif + diff --git a/drivers/net/wireless/ar6003/host/os/linux/Makefile b/drivers/net/wireless/ar6003/host/os/linux/Makefile new file mode 100644 index 000000000000..e4df8b1ef04d --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/Makefile @@ -0,0 +1,338 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +####################################################################################### +# AR6K Kernel Module makefile. +# +# This makefile is invoked by the master makefile in the linux kernel, the linux kernel +# source must be initially compiled. The top level make will invoke the main linux kernel +# makefile which will subsequently pick up this makefile. +# +####################################################################################### + + +REV ?= 2 + +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/include +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/../include +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/wlan/include +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/os/linux/include +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/os/ +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/bmi/include +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/../include/AR6002 + +EXTRA_CFLAGS += -DLINUX -D__KERNEL__ \ + -DTCMD -DSEND_EVENT_TO_APP -DUSER_KEYS \ + -DNO_SYNC_FLUSH -DHTC_EP_STAT_PROFILING -DWLAN_HEADERS\ + -DATH_AR6K_11N_SUPPORT \ + -DATH_SUPPORT_DFS \ + -DWAPI_ENABLE #\ + -DMULTIPLE_FRAMES_PER_INTERRUPT -DAR6000REV$(REV) \ + -DBLOCK_TX_PATH_FLAG -DCHECKSUM_OFFLOAD \ + + +ifeq ($(ATH_CFG80211_ENV),yes) + EXTRA_CFLAGS += -DATH6K_CONFIG_CFG80211 + # EXTRA_CFLAGS += -DCFG80211_WAPI_ENABLE +endif + +ifeq ($(ATH_INIT_MODE_DRV_ENABLED), yes) +ifeq ($(ATH_AR600x_WB31_XXX),yes) +EXTRA_CFLAGS += -DAR600x_WB31_XXX +else +ifeq ($(ATH_AR600x_SD32_XXX),yes) +EXTRA_CFLAGS += -DAR600x_SD32_XXX +else +EXTRA_CFLAGS += -DAR600x_SD31_XXX +endif +endif +EXTRA_CFLAGS += -DINIT_MODE_DRV_ENABLED -DBMIENABLE_SET +endif + +ifeq ($(ATH_ANDROID_ENV),yes) + EXTRA_CFLAGS += -DANDROID_ENV -D__linux__ $(ATH_ANDROID_BUILD_FLAGS) + EXTRA_CFLAGS += -DINIT_MODE_DRV_ENABLED -DBMIENABLE_SET -DAR600x_SD31_XXX \ + -DATH6KL_CONFIG_HIF_VIRTUAL_SCATTER \ + -DCONFIG_AP_VIRTUAL_ADAPTER_SUPPORT +ifeq ($(ATH_AR6K_HCI_BRIDGE),yes) + EXTRA_CFLAGS += -DSETUPHCI_ENABLED -DSETUPBTDEV_ENABLED \ + -DATH6KL_CONFIG_GPIO_BT_RESET -DAR600x_BT_AR3001 +endif +endif + +EXTRA_CFLAGS += -DCONFIG_BT +ifeq ($(ATH_AR6K_HCI_PAL),yes) + EXTRA_CFLAGS += -DSETUPHCIPAL_ENABLED +ifeq ($(ATH_AR6K_DEBUG_HCI_PAL),yes) + EXTRA_CFLAGS += -DHCIPAL_DEBUG +endif +endif + +ifeq ($(ATH_SOFTMAC_FILE_USED),yes) + EXTRA_CFLAGS += -DSOFTMAC_FILE_USED +endif + +ifeq ($(ATH_AR6K_OTA_TEST_MODE),yes) + EXTRA_CFLAGS += -DATH6K_CONFIG_OTA_MODE +endif + +ifeq ($(ATH_AR6K_HCI_BRIDGE),yes) +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/miscdrv/ar3kps +EXTRA_CFLAGS += -I$(ATH_SRC_BASE)/../include/AR6002/hw4.0 + +EXTRA_CFLAGS += -DATH_AR6K_ENABLE_GMBOX \ + -DHCI_TRANSPORT_SDIO + +ifeq ($(ATH_AR6K_BUILTIN_HCI_TRANSPORT),no) +EXTRA_CFLAGS += -DEXPORT_HCI_BRIDGE_INTERFACE +endif +endif + + +ifeq ($(ATH_HTC_RAW_INT_ENV),yes) + EXTRA_CFLAGS += -DHTC_RAW_INTERFACE +endif + +ifeq ($(ATH_DEBUG_DRIVER),yes) + EXTRA_CFLAGS += -DDEBUG -DATH_DEBUG_MODULE +endif + +ifeq ($(ATH_BUILD_P2P),yes) + EXTRA_CFLAGS += -DP2P +endif + +ifeq ($(AR6002_REV),4) + EXTRA_CFLAGS += -DAR6002_REV4 +endif + +ifneq ("$(wildcard $(ATH_SRC_BASE)/../include/AR6002/hw2.0)","") + EXTRA_CFLAGS += -DAR6002_HEADERS_DEF +endif + +ifneq ("$(wildcard $(ATH_SRC_BASE)/../include/AR6002/hw4.0)","") + EXTRA_CFLAGS += -DAR6003_HEADERS_DEF +endif + +ifneq ("$(wildcard $(ATH_SRC_BASE)/../include/AR6002/hw6.0)","") + EXTRA_CFLAGS += -DMCKINLEY_HEADERS_DEF +endif + +ifneq ($(ATH_OS_SUB_TYPE),linux_2_4) +# linux 2.6 and higher kernel module build settings +EXTRA_CFLAGS += -DKERNEL_2_6 +obj-m += ar6000.o +ifeq ($(ATH_AR6K_BUILTIN_HCI_TRANSPORT),no) +obj-m += bt_hci_sdio.o +endif +-include $(ATH_SRC_BASE)/hif/$(ATH_HIF_TYPE)/Makefile + +ifneq ($(ATH_HIF_MESSAGE_BASED),yes) +ar6000-objs += ../../htc2/AR6000/ar6k.o \ + ../../htc2/AR6000/ar6k_events.o \ + ../../htc2/htc_send.o \ + ../../htc2/htc_recv.o \ + ../../htc2/htc_services.o \ + ../../htc2/htc.o +endif + +ifeq ($(ATH_HIF_MESSAGE_BASED),yes) +ar6000-objs += ../../htc_thin/htc_send.o \ + ../../htc_thin/htc_recv.o \ + ../../htc_thin/htc_services.o \ + ../../htc_thin/htc.o +endif + + +ar6000-objs += ../../bmi/src/bmi.o \ + ar6000_drv.o \ + ar6000_pm.o \ + ar6000_raw_if.o \ + netbuf.o \ + wireless_ext.o \ + ioctl.o \ + ../../miscdrv/common_drv.o \ + ../../miscdrv/credit_dist.o \ + ../../wmi/wmi.o \ + ../../reorder/rcv_aggr.o \ + ../../dfs/dfs_ar.o \ + ../../dfs/dfs_bindetects.o \ + ../../dfs/dfs.o \ + ../../dfs/dfs_debug.o \ + ../../dfs/dfs_fcc_bin5.o \ + ../../dfs/dfs_init.o \ + ../../dfs/dfs_misc.o \ + ../../dfs/dfs_process_phyerr.o \ + ../../dfs/dfs_process_radarevent.o \ + ../../dfs/dfs_staggered.o \ + ../../dfs/dfs_host_project.o \ + ../../wlan/src/wlan_node.o \ + ../../wlan/src/wlan_recv_beacon.o \ + ../../wlan/src/wlan_utils.o \ + ../../regtable/regtable.o \ + ../../regtable/AR6002def.o \ + ../../regtable/AR6003def.o \ + ../../regtable/MCKINLEYdef.o + +ifeq ($(ATH_BUILD_P2P),yes) +ar6000-objs += ../../p2p/p2p_main.o +endif + +ifeq ($(ATH_HIF_TYPE),sdio) +ar6000-objs += ../../hif/common/hif_bmi_reg_access.o \ + ../../hif/common/hif_diag_reg_access.o + +endif + +ifeq ($(ATH_CFG80211_ENV),yes) +ar6000-objs += cfg80211.o +endif + +ifneq ($(ATH_AR6K_BUILTIN_HCI_TRANSPORT),no) +ar6000-objs += hci_bridge.o +endif + +ifneq ($(ATH_AR6K_BUILTIN_HCI_PAL),no) +ar6000-objs += ar6k_pal.o +else +obj-m += ar6k_pal.o +endif + +ifeq ($(ATH_AR6K_HCI_BRIDGE),yes) +ar6000-objs += ../../htc2/AR6000/ar6k_gmbox.o \ + ../../htc2/AR6000/ar6k_gmbox_hciuart.o +ifneq ($(ATH_AR6K_BUILTIN_HCI_TRANSPORT),no) +ar6000-objs += ../../miscdrv/ar3kconfig.o \ + ../../miscdrv/ar3kps/ar3kpsconfig.o \ + ../../miscdrv/ar3kps/ar3kpsparser.o +else +ar6000-objs += export_hci_transport.o +endif + +ifeq ($(ATH_AR6K_BUILTIN_HCI_TRANSPORT),no) +bt_hci_sdio-objs += hci_bridge.o \ + ../../miscdrv/ar3kconfig.o \ + ../../miscdrv/ar3kps/ar3kpsconfig.o \ + ../../miscdrv/ar3kps/ar3kpsparser.o +endif +endif + +ifeq ($(ATH_ANDROID_ENV),yes) + ar6000-objs += ar6000_android.o +endif + +ifeq ($(ATH_AR6K_DEBUG_ALLOC),yes) + EXTRA_CFLAGS += -DAR6K_ALLOC_DEBUG + ar6000-objs += ar6k_mem_debug.o +endif + +endif + +ifeq ($(ATH_OS_SUB_TYPE),linux_2_4) +# linux 2.4 kernel module build settings +EXTRA_CFLAGS += -DKERNEL_2_4 + +O_TARGET := ar6000.o +# need export line for module export +export-objs := ar6000_drv.o +-include $(ATH_SRC_BASE)/hif/$(ATH_HIF_TYPE)/Makefile +obj-y += $(ATH_SRC_BASE)/htc2/htc.o \ + $(ATH_SRC_BASE)/htc2/htc_send.o \ + $(ATH_SRC_BASE)/htc2/htc_recv.o \ + $(ATH_SRC_BASE)/htc2/htc_services.o \ + $(ATH_SRC_BASE)/htc2/AR6000/ar6k.o \ + $(ATH_SRC_BASE)/htc2/AR6000/ar6k_events.o \ + $(ATH_SRC_BASE)/bmi/src/bmi.o \ + $(ATH_SRC_BASE)/wmi/wmi.o \ + $(ATH_SRC_BASE)/reorder/rcv_aggr.o \ + $(ATH_SRC_BASE)/dfs/dfs_ar.o \ + $(ATH_SRC_BASE)/dfs/dfs_bindetects.o \ + $(ATH_SRC_BASE)/dfs/dfs.o \ + $(ATH_SRC_BASE)/dfs/dfs_debug.o \ + $(ATH_SRC_BASE)/dfs/dfs_fcc_bin5.o \ + $(ATH_SRC_BASE)/dfs/dfs_init.o \ + $(ATH_SRC_BASE)/dfs/dfs_misc.o \ + $(ATH_SRC_BASE)/dfs/dfs_process_phyerr.o \ + $(ATH_SRC_BASE)/dfs/dfs_process_radarevent.o \ + $(ATH_SRC_BASE)/dfs/dfs_staggered.o \ + $(ATH_SRC_BASE)/dfs/dfs_host_project.o \ + $(ATH_SRC_BASE)/wlan/src/wlan_node.o \ + $(ATH_SRC_BASE)/wlan/src/wlan_recv_beacon.o \ + $(ATH_SRC_BASE)/wlan/src/wlan_utils.o \ + $(ATH_SRC_BASE)/os/linux/ar6000_drv.o \ + $(ATH_SRC_BASE)/os/linux/ar6000_raw_if.o \ + $(ATH_SRC_BASE)/os/linux/wireless_ext.o \ + $(ATH_SRC_BASE)/os/linux/ioctl.o \ + $(ATH_SRC_BASE)/os/linux/netbuf.o \ + $(ATH_SRC_BASE)/os/linux/hci_bridge.o \ + $(ATH_SRC_BASE)/miscdrv/common_drv.o \ + $(ATH_SRC_BASE)/miscdrv/credit_dist.o + +ifeq ($(ATH_HIF_TYPE),SPI2) +obj-y += $(ATH_SRC_BASE)/hif/common/hif_bmi_reg_access.o \ + $(ATH_SRC_BASE)/hif/common/hif_diag_reg_access.o + +endif + +obj-m += htc.o \ + htc_send.o \ + htc_recv.o \ + htc_services.o \ + ar6k_events.o \ + ar6k.o \ + ar6k_gmbox.o \ + ar6k_gmbox_hciuart.o \ + hif.o \ + bmi.o \ + wmi.o \ + dfs_ar.o \ + dfs_bindetects.o \ + dfs.o \ + dfs_debug.o \ + dfs_fcc_bin5.o \ + dfs_init.o \ + dfs_misc.o \ + dfs_process_phyerr.o \ + dfs_process_radarevent.o \ + dfs_staggered.o \ + dfs_host_project.o \ + wlan_node.o \ + wlan_recv_beacon.o \ + wlan_utils.o \ + ar6000_drv.o \ + ar6000_raw_if.o \ + common_drv.o \ + credit_dist.o \ + netbuf.o \ + wireless_ext.o \ + rcv_aggr.o \ + ioctl.o \ + hci_bridge.o \ + ar6000.o + +ifeq ($(ATH_HIF_TYPE),SPI2) +obj-m += hif_bmi_reg_access.o \ + hif_diag_reg_access.o + +endif + +include $(ATH_LINUXPATH)/Rules.make +endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6000_android.c b/drivers/net/wireless/ar6003/host/os/linux/ar6000_android.c new file mode 100644 index 000000000000..3100618e3ef7 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6000_android.c @@ -0,0 +1,965 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ +#include "ar6000_drv.h" +#include "htc.h" +#include +#include + +#ifdef CONFIG_HAS_WAKELOCK +#include +#endif +#ifdef CONFIG_HAS_EARLYSUSPEND +#include +#endif + +#ifdef CONFIG_MMC_MSM +A_BOOL enable_mmc_host_detect_change = 1; +#else +A_BOOL enable_mmc_host_detect_change = 0; +#endif +static void ar6000_enable_mmchost_detect_change(int enable); + + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#ifdef RK29 +#ifdef TCHIP +char softmac_path[256] = "/data/misc/wifi/ar6302"; +#endif +char fwpath[256] = "/system/etc/firmware"; +//char fwpath[256] = "/data/ar6302"; +#else +char fwpath[256] = "/system/wifi"; +#endif +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ +int wowledon; +unsigned int enablelogcat; + +extern int bmienable; +extern struct net_device *ar6000_devices[]; +extern char ifname[]; + +#ifdef CONFIG_HAS_WAKELOCK +extern struct wake_lock ar6k_wow_wake_lock; +struct wake_lock ar6k_init_wake_lock; +#endif +extern int num_device; + +const char def_ifname[] = "wlan0"; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param_string(fwpath, fwpath, sizeof(fwpath), 0644); +module_param(enablelogcat, uint, 0644); +module_param(wowledon, int, 0644); +#else +#define __user +/* for linux 2.4 and lower */ +MODULE_PARAM(wowledon,"i"); +#endif + +#ifdef CONFIG_HAS_EARLYSUSPEND +static int screen_is_off; +static struct early_suspend ar6k_early_suspend; +#endif + +static A_STATUS (*ar6000_avail_ev_p)(void *, void *); + +#if defined(CONFIG_ANDROID_LOGGER) && (!defined(CONFIG_MMC_MSM) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) +int logger_write(const enum logidx index, + const unsigned char prio, + const char __kernel * const tag, + const char __kernel * const fmt, + ...) +{ + int ret = 0; + va_list vargs; + struct file *filp = (struct file *)-ENOENT; + mm_segment_t oldfs; + struct iovec vec[3]; + int tag_bytes = strlen(tag) + 1, msg_bytes; + char *msg; + va_start(vargs, fmt); + msg = kvasprintf(GFP_ATOMIC, fmt, vargs); + va_end(vargs); + if (!msg) + return -ENOMEM; + if (in_interrupt()) { + /* we have no choice since aio_write may be blocked */ + printk(KERN_ALERT "%s", msg); + goto out_free_message; + } + msg_bytes = strlen(msg) + 1; + if (msg_bytes <= 1) /* empty message? */ + goto out_free_message; /* don't bother, then */ + if ((msg_bytes + tag_bytes + 1) > 2048) { + ret = -E2BIG; + goto out_free_message; + } + + vec[0].iov_base = (unsigned char *) &prio; + vec[0].iov_len = 1; + vec[1].iov_base = (void *) tag; + vec[1].iov_len = strlen(tag) + 1; + vec[2].iov_base = (void *) msg; + vec[2].iov_len = strlen(msg) + 1; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + do { + filp = filp_open("/dev/log/main", O_WRONLY, S_IRUSR); + if (IS_ERR(filp) || !filp->f_op) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: filp_open /dev/log/main error\n", __FUNCTION__)); + ret = -ENOENT; + break; + } + + if (filp->f_op->aio_write) { + int nr_segs = sizeof(vec) / sizeof(vec[0]); + int len = vec[0].iov_len + vec[1].iov_len + vec[2].iov_len; + struct kiocb kiocb; + init_sync_kiocb(&kiocb, filp); + kiocb.ki_pos = 0; + kiocb.ki_left = len; + kiocb.ki_nbytes = len; + ret = filp->f_op->aio_write(&kiocb, vec, nr_segs, kiocb.ki_pos); + } + + } while (0); + + if (!IS_ERR(filp)) { + filp_close(filp, NULL); + } + set_fs(oldfs); +out_free_message: + if (msg) { + kfree(msg); + } + return ret; +} +#endif + +int android_logger_lv(void *module, int mask) +{ + switch (mask) { + case ATH_DEBUG_ERR: + return 6; + case ATH_DEBUG_INFO: + return 4; + case ATH_DEBUG_WARN: + return 5; + case ATH_DEBUG_TRC: + return 3; + default: +#ifdef DEBUG + if (!module) { + return 3; + } else if (module == &GET_ATH_MODULE_DEBUG_VAR_NAME(driver)) { + return (mask <=ATH_DEBUG_MAKE_MODULE_MASK(3)) ? 3 : 2; + } else if (module == &GET_ATH_MODULE_DEBUG_VAR_NAME(htc)) { + return 2; + } else { + return 3; + } +#else + return 3; /* DEBUG */ +#endif + } +} + +#ifdef RK29 +int +#else +static int +#endif +android_readwrite_file(const A_CHAR *filename, A_CHAR *rbuf, const A_CHAR *wbuf, size_t length) +{ + int ret = 0; + struct file *filp = (struct file *)-ENOENT; + mm_segment_t oldfs; + oldfs = get_fs(); + set_fs(KERNEL_DS); + do { + int mode = (wbuf) ? O_RDWR : O_RDONLY; +#ifdef TCHIP + if (strstr(filename, "softmac") && wbuf) { + mode = O_CREAT | O_RDWR; + } +#endif + filp = filp_open(filename, mode, S_IRUSR); + if (IS_ERR(filp) || !filp->f_op) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: file %s filp_open error\n", __FUNCTION__, filename)); + ret = -ENOENT; + break; + } + + if (length==0) { + /* Read the length of the file only */ + struct inode *inode; + + inode = GET_INODE_FROM_FILEP(filp); + if (!inode) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Get inode from %s failed\n", __FUNCTION__, filename)); + ret = -ENOENT; + break; + } + ret = i_size_read(inode->i_mapping->host); + break; + } + + if (wbuf) { + if ( (ret=filp->f_op->write(filp, wbuf, length, &filp->f_pos)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Write %u bytes to file %s error %d\n", __FUNCTION__, + length, filename, ret)); + break; + } + } else { + if ( (ret=filp->f_op->read(filp, rbuf, length, &filp->f_pos)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Read %u bytes from file %s error %d\n", __FUNCTION__, + length, filename, ret)); + break; + } + } + } while (0); + + if (!IS_ERR(filp)) { + filp_close(filp, NULL); + } + set_fs(oldfs); + + return ret; +} + +#ifdef TCHIP +void android_wifi_softmac_update(char *mac_buff, int len) +{ + char filename[256]; + sprintf(filename, "%s/%s", softmac_path, "softmac"); + + android_readwrite_file(filename, NULL, mac_buff, len); +} +#endif + +int android_request_firmware(const struct firmware **firmware_p, const char *name, + struct device *device) +{ + int ret = 0; + struct firmware *firmware; + char filename[256]; + const char *raw_filename = name; +#ifdef TCHIP + int sm = 0; + char mac[] = "00:00:00:00:00:00"; +#endif + + *firmware_p = firmware = A_MALLOC(sizeof(*firmware)); + if (!firmware) + return -ENOMEM; + A_MEMZERO(firmware, sizeof(*firmware)); + +#ifdef TCHIP + if(!strcmp(name,"softmac")) { + sprintf(filename, "%s/%s", softmac_path, raw_filename); + sm = 1; + } + else +#endif + sprintf(filename, "%s/%s", fwpath, raw_filename); + do { + size_t length, bufsize, bmisize; + + if ( (ret=android_readwrite_file(filename, NULL, NULL, 0)) < 0) { +#ifdef TCHIP + if (sm) { + android_wifi_softmac_update(mac, sizeof(mac)); + length = sizeof(mac); + } + else +#endif + break; + } else { + length = ret; + } + + bufsize = ALIGN(length, PAGE_SIZE); + bmisize = A_ROUND_UP(length, 4); + bufsize = max(bmisize, bufsize); + firmware->data = vmalloc(bufsize); + firmware->size = length; + if (!firmware->data) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Cannot allocate buffer for firmware\n", __FUNCTION__)); + ret = -ENOMEM; + break; + } + + if ( (ret=android_readwrite_file(filename, (char*)firmware->data, NULL, length)) != length) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: file read error, ret %d request %d\n", __FUNCTION__, ret, length)); + ret = -1; + break; + } + + } while (0); + + if (ret<0) { + if (firmware) { + if (firmware->data) + vfree(firmware->data); + A_FREE(firmware); + } + *firmware_p = NULL; + } else { + ret = 0; + } + return ret; +} + +void android_release_firmware(const struct firmware *firmware) +{ + if (firmware) { + if (firmware->data) + vfree(firmware->data); + A_FREE((struct firmware *)firmware); + } +} + +static A_STATUS ar6000_android_avail_ev(void *context, void *hif_handle) +{ + A_STATUS ret; +#ifdef CONFIG_HAS_WAKELOCK + wake_lock(&ar6k_init_wake_lock); +#endif + ar6000_enable_mmchost_detect_change(0); + ret = ar6000_avail_ev_p(context, hif_handle); +#ifdef CONFIG_HAS_WAKELOCK + wake_unlock(&ar6k_init_wake_lock); +#endif + return ret; +} + +static int android_do_ioctl_direct(struct net_device *dev, int cmd, struct ifreq *ifr, void *data) +{ + int ret = -EIO; + int (*do_ioctl)(struct net_device *, struct ifreq *, int); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) + do_ioctl = dev->do_ioctl; +#else + do_ioctl = dev->netdev_ops->ndo_do_ioctl; +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ + + ifr->ifr_ifru.ifru_data = (__force void __user *)data; + + if (do_ioctl) { + mm_segment_t oldfs = get_fs(); + set_fs(KERNEL_DS); + ret = do_ioctl(dev, ifr, cmd); + set_fs(oldfs); + } + return ret; +} + +int android_ioctl_siwpriv(struct net_device *dev, + struct iw_request_info *__info, + struct iw_point *data, char *__extra) +{ + char cmd[384]; /* assume that android command will not excess 384 */ + char buf[512]; + int len = sizeof(cmd)-1; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + + if (!data->pointer) { + return -EOPNOTSUPP; + } + if (data->length < len) { + len = data->length; + } + if (copy_from_user(cmd, data->pointer, len)) { + return -EIO; + } + cmd[len] = 0; + + if (strcasecmp(cmd, "RSSI")==0 || strcasecmp(cmd, "RSSI-APPROX") == 0) { + int rssi = -200; + struct iw_statistics *iwStats; + struct iw_statistics* (*get_iwstats)(struct net_device *); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) + get_iwstats = dev->get_wireless_stats; +#else + get_iwstats = dev->wireless_handlers->get_wireless_stats; +#endif + if (get_iwstats && arPriv->arConnected) { + iwStats = get_iwstats(dev); + if (iwStats) { + rssi = iwStats->qual.qual; + if (rssi == 255) + rssi = -200; + else + rssi += (161 - 256); + } + } + len = snprintf(buf, data->length, "SSID rssi %d\n", rssi) + 1; + return (copy_to_user(data->pointer, buf, len)==0) ? len : -1; + } else if (strcasecmp(cmd, "LINKSPEED")==0) { + /* We skip to use SIOCGIWRATE since Android always asked LINKSPEED just after RSSI*/ + unsigned int speed_mbps; + if (arPriv->arConnected) { + speed_mbps = arPriv->arTargetStats.tx_unicast_rate / 1000; + } else { + speed_mbps = 1; + } + len = snprintf(buf, data->length, "LinkSpeed %u\n", speed_mbps) + 1; + return (copy_to_user(data->pointer, buf, len)==0) ? len : -1; + } else if (memcmp(cmd, "CSCAN S\x01\x00\x00S\x00", 12)==0) { + int iocmd = SIOCSIWSCAN - SIOCSIWCOMMIT; + const iw_handler setScan = dev->wireless_handlers->standard[iocmd]; + A_INT32 home_dwell=0, pas_dwell=0, act_dwell=0; + A_UCHAR ssid[IW_ESSID_MAX_SIZE+1] = { 0 }; + A_INT32 ssid_len = 0, ie_len; + A_UINT8 index = 1; /* reserve index 0 for wext */ + A_INT32 ch = 0; + A_CHAR nprobe, scantype; + struct iw_freq chList[IW_MAX_FREQUENCIES]; + A_UCHAR *scanBuf = (A_UCHAR*)(cmd + 12); + A_UCHAR *scanEnd = (A_UCHAR*)(cmd + len); + A_BOOL broadcastSsid = FALSE; + + while ( scanBuf < scanEnd ) { + A_UCHAR *sp = scanBuf; + switch (*scanBuf) { + case 'S': /* SSID section */ + if (ssid_len > 0 && index < MAX_PROBED_SSID_INDEX) { + /* setup the last parsed ssid, reserve index 0 for wext */ + if (wmi_probedSsid_cmd(arPriv->arWmi, index, + SPECIFIC_SSID_FLAG, ssid_len, ssid) == A_OK) { + ++index; + if (arSta->scanSpecificSsidscanSpecificSsid = index; + } + } + } + ie_len = ((scanBuf + 1) < scanEnd) ? ((A_INT32)*(scanBuf+1) + 1) : 0; + if ((scanBuf+ie_len) < scanEnd ) { + ssid_len = *(scanBuf+1); + if (ssid_len == 0) { + broadcastSsid = TRUE; + } else { + A_MEMCPY(ssid, scanBuf+2, ssid_len); + ssid[ssid_len] = '\0'; + } + } + scanBuf += 1 + ie_len; + break; + case 'C': /* Channel section */ + if (scanBuf+1 < scanEnd) { + int value = *(scanBuf+1); + if (value == 0) { + ch = 0; /* scan for all channels */ + } else if (ch < IW_MAX_FREQUENCIES) { + if (value>1000) { + chList[ch].e = 1; + chList[ch].m = value * 100000; + } else { + chList[ch].e = 0; + chList[ch].m = value; + } + ++ch; + } + } + scanBuf += 2; + break; + case 'P': /* Passive dwell section */ + if (scanBuf+2 < scanEnd) { + pas_dwell = *(scanBuf+1) + (*(scanBuf+2) << 8); + } + scanBuf += 3; + break; + case 'H': /* Home dwell section */ + if (scanBuf+2 < scanEnd) { + home_dwell = *(scanBuf+1) + (*(scanBuf+2) << 8); + } + scanBuf += 3; + break; + case 'N': /* Number of probe section */ + if (scanBuf+1 < scanEnd) { + nprobe = *(scanBuf+1); + } + scanBuf += 2; + break; + case 'A': /* Active dwell section */ + if (scanBuf+2 < scanEnd) { + act_dwell = *(scanBuf+1) + (*(scanBuf+2) << 8); + } + scanBuf += 3; + break; + case 'T': /* Scan active type section */ + if (scanBuf+1 < scanEnd) { + scantype = *(scanBuf+1); + } + scanBuf += 2; + break; + default: + break; + } + if (sp == scanBuf) { + return -1; /* parsing error */ + } + } + + if (ssid_len>0) { + A_UINT8 idx; /* Clean up the last specific scan items */ + for (idx=index; idxscanSpecificSsid; ++idx) { + wmi_probedSsid_cmd(arPriv->arWmi, idx, DISABLE_SSID_FLAG, 0, NULL); + } + arSta->scanSpecificSsid = index; + /* + * There is no way to know when we need to send broadcast probe in current Android wpa_supplicant_6 + * combo scan implemenation. Always force to sent it here uniti future Android version will set + * the broadcast flags for combo scan. + */ +#if 0 + if (broadcastSsid) +#endif + { + /* setup the last index as broadcast SSID for combo scan */ + ++arSta->scanSpecificSsid; + wmi_probedSsid_cmd(arPriv->arWmi, index, ANY_SSID_FLAG, 0, NULL); + } + } + + if (pas_dwell>0) { + /* TODO: Should we change our passive dwell? There may be some impact for bt-coex */ + } + + if (home_dwell>0) { + /* TODO: Should we adjust home_dwell? How to pass it to wext handler? */ + } + + if (setScan) { + union iwreq_data miwr; + struct iw_request_info minfo; + struct iw_scan_req scanreq, *pScanReq = NULL; + A_MEMZERO(&minfo, sizeof(minfo)); + A_MEMZERO(&miwr, sizeof(miwr)); + A_MEMZERO(&scanreq, sizeof(scanreq)); + if (ssid_len > 0) { + pScanReq = &scanreq; + memcpy(scanreq.essid, ssid, ssid_len); + scanreq.essid_len = ssid_len; + miwr.data.flags |= IW_SCAN_THIS_ESSID; + } + if (ch > 0) { + pScanReq = &scanreq; + scanreq.num_channels = ch; + memcpy(scanreq.channel_list, chList, ch * sizeof(chList[0])); + miwr.data.flags |= IW_SCAN_THIS_FREQ; + } + if (pScanReq) { + miwr.data.pointer = (__force void __user *)&scanreq; + miwr.data.length = sizeof(scanreq); + } + minfo.cmd = SIOCSIWSCAN; + return setScan(dev, &minfo, &miwr, (char*)pScanReq); + } + return -1; + } else if (strcasecmp(cmd, "MACADDR")==0) { + /* reply comes back in the form "Macaddr = XX:XX:XX:XX:XX:XX" where XX */ + A_UCHAR *mac = dev->dev_addr; + len = snprintf(buf, data->length, "Macaddr = %02X:%02X:%02X:%02X:%02X:%02X\n", + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]) + 1; + return (copy_to_user(data->pointer, buf, len)==0) ? len : -1; + } else if (strcasecmp(cmd, "SCAN-ACTIVE")==0) { + return 0; /* unsupport function. Suppress the error */ + } else if (strcasecmp(cmd, "SCAN-PASSIVE")==0) { + return 0; /* unsupport function. Suppress the error */ + } else if (strcasecmp(cmd, "START")==0 || strcasecmp(cmd, "STOP")==0) { + struct ifreq ifr; + char userBuf[16]; + int ex_arg = (strcasecmp(cmd, "START")==0) ? WLAN_ENABLED : WLAN_DISABLED; + int ret; + A_MEMZERO(userBuf, sizeof(userBuf)); + ((int *)userBuf)[0] = AR6000_XIOCTRL_WMI_SET_WLAN_STATE; + ((int *)userBuf)[1] = ex_arg; + ret = android_do_ioctl_direct(dev, AR6000_IOCTL_EXTENDED, &ifr, userBuf); + if (ret==0) { + /* Send wireless event which need by android supplicant */ + union iwreq_data wrqu; + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(cmd); + wireless_send_event(dev, IWEVCUSTOM, &wrqu, cmd); + } + return ret; + } else if (strncasecmp(cmd, "POWERMODE ", 10)==0) { + int mode; + if (sscanf(cmd, "%*s %d", &mode) == 1) { + int iocmd = SIOCSIWPOWER - SIOCSIWCOMMIT; + iw_handler setPower = dev->wireless_handlers->standard[iocmd]; + if (setPower) { + union iwreq_data miwr; + struct iw_request_info minfo; + A_MEMZERO(&minfo, sizeof(minfo)); + A_MEMZERO(&miwr, sizeof(miwr)); + minfo.cmd = SIOCSIWPOWER; + if (mode == 0 /* auto */) + miwr.power.disabled = 0; + else if (mode == 1 /* active */) + miwr.power.disabled = 1; + else + return -1; + return setPower(dev, &minfo, &miwr, NULL); + } + } + return -1; + } else if (strcasecmp(cmd, "GETPOWER")==0) { + struct ifreq ifr; + int userBuf[2]; + A_MEMZERO(userBuf, sizeof(userBuf)); + ((int *)userBuf)[0] = AR6000_XIOCTRL_WMI_GET_POWER_MODE; + if (android_do_ioctl_direct(dev, AR6000_IOCTL_EXTENDED, &ifr, userBuf)>=0) { + WMI_POWER_MODE_CMD *getPowerMode = (WMI_POWER_MODE_CMD *)userBuf; + len = snprintf(buf, data->length, "powermode = %u\n", + (getPowerMode->powerMode==MAX_PERF_POWER) ? 1/*active*/ : 0/*auto*/) + 1; + return (copy_to_user(data->pointer, buf, len)==0) ? len : -1; + } + return -1; + } else if (strncasecmp(cmd, "SETSUSPENDOPT ", 14)==0) { + int enable; + if (sscanf(cmd, "%*s %d", &enable)==1) { + /* + * We set our suspend mode by wlan_config.h now. + * Should we follow Android command?? TODO + */ + return 0; + } + return -1; + } else if (strcasecmp(cmd, "SCAN-CHANNELS")==0) { + // reply comes back in the form "Scan-Channels = X" where X is the number of channels + int iocmd = SIOCGIWRANGE - SIOCSIWCOMMIT; + iw_handler getRange = dev->wireless_handlers->standard[iocmd]; + if (getRange) { + union iwreq_data miwr; + struct iw_request_info minfo; + struct iw_range range; + A_MEMZERO(&minfo, sizeof(minfo)); + A_MEMZERO(&miwr, sizeof(miwr)); + A_MEMZERO(&range, sizeof(range)); + minfo.cmd = SIOCGIWRANGE; + miwr.data.pointer = (__force void __user *) ⦥ + miwr.data.length = sizeof(range); + getRange(dev, &minfo, &miwr, (char*)&range); + } + if (arSta->arNumChannels!=-1) { + len = snprintf(buf, data->length, "Scan-Channels = %d\n", arSta->arNumChannels) + 1; + return (copy_to_user(data->pointer, buf, len)==0) ? len : -1; + } + return -1; + } else if (strncasecmp(cmd, "SCAN-CHANNELS ", 14)==0 || + strncasecmp(cmd, "COUNTRY ", 8)==0) { + /* + * Set the available channels with WMI_SET_CHANNELPARAMS cmd + * However, the channels will be limited by the eeprom regulator domain + * Try to use a regulator domain which will not limited the channels range. + */ + int i; + int chan = 0; + A_UINT16 *clist; + struct ifreq ifr; + char ioBuf[256]; + WMI_CHANNEL_PARAMS_CMD *chParamCmd = (WMI_CHANNEL_PARAMS_CMD *)ioBuf; + if (strncasecmp(cmd, "COUNTRY ", 8)==0) { + char *country = cmd + 8; + if (strcasecmp(country, "US")==0) { + chan = 11; + } else if (strcasecmp(country, "JP")==0) { + chan = 14; + } else if (strcasecmp(country, "EU")==0) { + chan = 13; + } + } else if (sscanf(cmd, "%*s %d", &chan) != 1) { + return -1; + } + if ( (chan != 11) && (chan != 13) && (chan != 14)) { + return -1; + } + if (arPriv->arNextMode == AP_NETWORK) { + return -1; + } + A_MEMZERO(&ifr, sizeof(ifr)); + A_MEMZERO(ioBuf, sizeof(ioBuf)); + + chParamCmd->phyMode = WMI_11G_MODE; + clist = chParamCmd->channelList; + chParamCmd->numChannels = chan; + chParamCmd->scanParam = 1; + for (i = 0; i < chan; i++) { + clist[i] = wlan_ieee2freq(i + 1); + } + + return android_do_ioctl_direct(dev, AR6000_IOCTL_WMI_SET_CHANNELPARAMS, &ifr, ioBuf); + } else if (strncasecmp(cmd, "BTCOEXMODE ", 11)==0) { + int mode; + if (sscanf(cmd, "%*s %d", &mode)==1) { + /* + * Android disable BT-COEX when obtaining dhcp packet except there is headset is connected + * It enable the BT-COEX after dhcp process is finished + * We ignore since we have our way to do bt-coex during dhcp obtaining. + */ + switch (mode) { + case 1: /* Disable*/ + break; + case 0: /* Enable */ + /* fall through */ + case 2: /* Sense*/ + /* fall through */ + default: + break; + } + return 0; /* ignore it */ + } + return -1; + } else if (strcasecmp(cmd, "BTCOEXSCAN-START")==0) { + /* Android enable or disable Bluetooth coexistence scan mode. When this mode is on, + * some of the low-level scan parameters used by the driver are changed to + * reduce interference with A2DP streaming. + */ + return 0; /* ignore it since we have btfilter */ + } else if (strcasecmp(cmd, "BTCOEXSCAN-STOP")==0) { + return 0; /* ignore it since we have btfilter */ + } else if (strncasecmp(cmd, "RXFILTER-ADD ", 13)==0) { + return 0; /* ignore it */ + } else if (strncasecmp(cmd, "RXFILTER-REMOVE ", 16)==0) { + return 0; /* ignoret it */ + } else if (strcasecmp(cmd, "RXFILTER-START")==0 || strcasecmp(cmd, "RXFILTER-STOP")==0) { + unsigned int flags = dev->flags; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + int mc_count = dev->mc_count; +#else + int mc_count = netdev_mc_count(dev); +#endif + if (strcasecmp(cmd, "RXFILTER-START")==0) { + if (mc_count > 0 || (flags & IFF_MULTICAST) ) { + flags &= ~IFF_MULTICAST; + } + } else { + flags |= IFF_MULTICAST; + } + if (flags != dev->flags) { + dev_change_flags(dev, flags); + } + return 0; + } + + return -EOPNOTSUPP; +} + +/* Useful for qualcom platform to detect our wlan card for mmc stack */ +static void ar6000_enable_mmchost_detect_change(int enable) +{ +#ifdef CONFIG_MMC_MSM +#define MMC_MSM_DEV "msm_sdcc.1" + char buf[3]; + int length; + + if (!enable_mmc_host_detect_change) { + return; + } + length = snprintf(buf, sizeof(buf), "%d\n", enable ? 1 : 0); + if (android_readwrite_file("/sys/devices/platform/" MMC_MSM_DEV "/detect_change", + NULL, buf, length) < 0) { + /* fall back to polling */ + android_readwrite_file("/sys/devices/platform/" MMC_MSM_DEV "/polling", NULL, buf, length); + A_MDELAY(50); + } +#endif +} + +#ifdef CONFIG_HAS_EARLYSUSPEND +static void android_early_suspend(struct early_suspend *h) +{ + screen_is_off = 1; +} + +static void android_late_resume(struct early_suspend *h) +{ + screen_is_off = 0; +} +#endif + +void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks) +{ + bmienable = 1; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + if (ifname[0] == '\0') + strcpy(ifname, def_ifname); +#endif +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_init(&ar6k_init_wake_lock, WAKE_LOCK_SUSPEND, "ar6k_init"); +#endif +#ifdef CONFIG_HAS_EARLYSUSPEND + ar6k_early_suspend.suspend = android_early_suspend; + ar6k_early_suspend.resume = android_late_resume; + ar6k_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN; + register_early_suspend(&ar6k_early_suspend); +#endif + + ar6000_avail_ev_p = osdrvCallbacks->deviceInsertedHandler; + osdrvCallbacks->deviceInsertedHandler = ar6000_android_avail_ev; + + ar6000_enable_mmchost_detect_change(1); +} + +void android_module_exit(void) +{ +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&ar6k_early_suspend); +#endif +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_destroy(&ar6k_init_wake_lock); +#endif + ar6000_enable_mmchost_detect_change(1); + /* disable polling again after we remove our wlan card */ + ar6000_enable_mmchost_detect_change(0); +} + +#ifdef CONFIG_PM +void android_ar6k_check_wow_status(AR_SOFTC_T *ar, struct sk_buff *skb, A_BOOL isEvent) +{ +#ifdef CONFIG_HAS_WAKELOCK + unsigned long wake_timeout = HZ; /* 1 second for normal window's ping test */ +#endif + AR_SOFTC_DEV_T *arPriv; + A_UINT8 i; + A_BOOL needWake = FALSE; + for(i = 0; i < num_device; i++) + { + arPriv = ar->arDev[i]; + if ( +#ifdef CONFIG_HAS_EARLYSUSPEND + screen_is_off && +#endif + skb && arPriv->arConnected) { + if (isEvent) { + if (A_NETBUF_LEN(skb) >= sizeof(A_UINT16)) { + A_UINT16 cmd = *(const A_UINT16 *)A_NETBUF_DATA(skb); + switch (cmd) { + case WMI_CONNECT_EVENTID: +#ifdef CONFIG_HAS_WAKELOCK + wake_timeout = 3*HZ; +#endif + needWake = TRUE; + break; + default: + /* dont wake lock the system for other event */ + break; + } + } + } else if (A_NETBUF_LEN(skb) >= sizeof(ATH_MAC_HDR)) { + ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); + if (!IEEE80211_IS_MULTICAST(datap->dstMac)) { + switch (A_BE2CPU16(datap->typeOrLen)) { + case 0x0800: /* IP */ + if (A_NETBUF_LEN(skb)>=24 && + *((A_UCHAR*)A_NETBUF_DATA(skb)+23)==0x11) { + A_UCHAR *udpPkt = (A_UCHAR*)A_NETBUF_DATA(skb)+14; + A_UINT8 ihl = (*udpPkt & 0x0f) * sizeof(A_UINT32); + const A_UCHAR ipsec_keepalive[] = { + 0x11, 0x94, 0x11, 0x94, 0x00, 0x09, 0x00, 0x00, 0xff + }; + udpPkt += ihl; + if (A_NETBUF_LEN(skb)>=14+ihl+sizeof(ipsec_keepalive) && + !memcmp(udpPkt, ipsec_keepalive, sizeof(ipsec_keepalive)-3) && + udpPkt[8]==0xff) { + /* + * RFC 3948 UDP Encapsulation of IPsec ESP Packets + * Source and Destination port must be 4500 + * Receivers MUST NOT depend upon the UDP checksum being zero + * Sender must use 1 byte payload with 0xff + * Receiver SHOULD ignore a received NAT-keepalive packet + * + * IPSec over UDP NAT keepalive packet. Just ignore + */ + break; + } + } + case 0x888e: /* EAPOL */ + case 0x88c7: /* RSN_PREAUTH */ + case 0x88b4: /* WAPI */ + needWake = TRUE; + break; + case 0x0806: /* ARP is not important to hold wake lock */ + needWake = (arPriv->arNetworkType==AP_NETWORK); + break; + default: + break; + } + } else if ( !IEEE80211_IS_BROADCAST(datap->dstMac) ) { + if (A_NETBUF_LEN(skb)>=14+20 ) { + /* check if it is mDNS packets */ + A_UINT8 *dstIpAddr = (A_UINT8*)(A_NETBUF_DATA(skb)+14+20-4); + struct net_device *ndev = arPriv->arNetDev; + needWake = ((dstIpAddr[3] & 0xf8) == 0xf8) && + (arPriv->arNetworkType==AP_NETWORK || + (ndev->flags & IFF_ALLMULTI || ndev->flags & IFF_MULTICAST)); + } + }else if (arPriv->arNetworkType==AP_NETWORK) { + switch (A_BE2CPU16(datap->typeOrLen)) { + case 0x0800: /* IP */ + if (A_NETBUF_LEN(skb)>=14+20+2) { + A_UINT16 dstPort = *(A_UINT16*)(A_NETBUF_DATA(skb)+14+20); + dstPort = A_BE2CPU16(dstPort); + needWake = (dstPort == 0x43); /* dhcp request */ + } + break; + case 0x0806: + needWake = TRUE; + default: + break; + } + } + } + } + } + if (needWake) { +#ifdef CONFIG_HAS_WAKELOCK + /* keep host wake up if there is any event and packate comming in*/ + wake_lock_timeout(&ar6k_wow_wake_lock, wake_timeout); +#endif + if (wowledon) { + char buf[32]; + int len = sprintf(buf, "on"); + android_readwrite_file("/sys/power/state", NULL, buf, len); + + len = sprintf(buf, "%d", 127); + android_readwrite_file("/sys/class/leds/lcd-backlight/brightness", + NULL, buf,len); + } + } +} +#endif /* CONFIG_PM */ + +void android_send_reload_event(AR_SOFTC_DEV_T *arPriv) +{ + struct net_device *ndev = arPriv->arNetDev; + union iwreq_data wrqu; + const char reloadEvt[] = "HANG"; + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(reloadEvt); + wireless_send_event(ndev, IWEVCUSTOM, &wrqu, reloadEvt); +} diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6000_drv.c b/drivers/net/wireless/ar6003/host/os/linux/ar6000_drv.c new file mode 100644 index 000000000000..e5d7952376ce --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6000_drv.c @@ -0,0 +1,8934 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +/* + * This driver is a pseudo ethernet driver to access the Atheros AR6000 + * WLAN Device + */ + +#ifdef ATH_AR6K_11N_SUPPORT +#define SUPPORT_11N +#include "wlan_defs.h" +#endif + +#include "ar6000_drv.h" +#ifdef ATH6K_CONFIG_CFG80211 +#include "cfg80211.h" +#endif /* ATH6K_CONFIG_CFG80211 */ +#include "htc.h" +#include "wmi_filter_linux.h" +#include "epping_test.h" +#include "wlan_config.h" +#include "ar3kconfig.h" +#include "dfs_host.h" +#include "ar6k_pal.h" +#include "AR6002/addrs.h" +#include "target_reg_table.h" +#include "p2p_api.h" + +/* LINUX_HACK_FUDGE_FACTOR -- this is used to provide a workaround for linux behavior. When + * the meta data was added to the header it was found that linux did not correctly provide + * enough headroom. However when more headroom was requested beyond what was truly needed + * Linux gave the requested headroom. Therefore to get the necessary headroom from Linux + * the driver requests more than is needed by the amount = LINUX_HACK_FUDGE_FACTOR */ +#define LINUX_HACK_FUDGE_FACTOR 16 +#define BDATA_BDADDR_OFFSET 28 + +A_UINT8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; +A_UINT8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + +#ifdef DEBUG + +#define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0) +#define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1) +#define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2) +#define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3) +#define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4) +#define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5) +#define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6) + +static ATH_DEBUG_MASK_DESCRIPTION driver_debug_desc[] = { + { ATH_DEBUG_DBG_LOG , "Target Debug Logs"}, + { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"}, + { ATH_DEBUG_WLAN_SCAN , "WLAN scan"}, + { ATH_DEBUG_WLAN_TX , "WLAN Tx"}, + { ATH_DEBUG_WLAN_RX , "WLAN Rx"}, + { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"}, + { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"}, + { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"}, + { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"}, +}; + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver, + "driver", + "Linux Driver Interface", + ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN | + ATH_DEBUG_HCI_BRIDGE, + ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc), + driver_debug_desc); + +#endif + + +#define IS_MAC_NULL(mac) (mac[0]==0 && mac[1]==0 && mac[2]==0 && mac[3]==0 && mac[4]==0 && mac[5]==0) +#define IS_MAC_BCAST(mac) (*mac==0xff) + +#define DESCRIPTION "Driver to access the Atheros AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_) + +MODULE_AUTHOR("Atheros Communications, Inc."); +MODULE_DESCRIPTION(DESCRIPTION); +MODULE_LICENSE("GPL and additional rights"); + +#ifndef REORG_APTC_HEURISTICS +#undef ADAPTIVE_POWER_THROUGHPUT_CONTROL +#endif /* REORG_APTC_HEURISTICS */ + +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +A_TIMER aptcTimer[NUM_DEV]; +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +// callbacks registered by HCI transport driver +HCI_TRANSPORT_CALLBACKS ar6kHciTransCallbacks = { NULL }; +#endif + +unsigned int processDot11Hdr = 0; +char targetconf[10]={0,}; +int bmienable = BMIENABLE_DEFAULT; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +char ifname[IFNAMSIZ] = {0,}; +char devmode[32] ={0,}; +char submode[32] ={0,}; +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ + +int regcode = 0x60; +int wlaninitmode = WLAN_INIT_MODE_DEFAULT; +unsigned int bypasswmi = 0; +unsigned int debuglevel = 0; +int tspecCompliance = ATHEROS_COMPLIANCE; +unsigned int busspeedlow = 0; +unsigned int onebitmode = 0; +unsigned int skipflash = 0; +unsigned int wmitimeout = 2; +unsigned int wlanNodeCaching = 1; +unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT; +unsigned int logWmiRawMsgs = 0; +unsigned int enabletimerwar = 0; +unsigned int fwmode = 1; +unsigned int fwsubmode = 0; +unsigned int mbox_yield_limit = 99; +unsigned int enablerssicompensation = 0; +int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF; +int allow_trace_signal = 0; +#ifdef CONFIG_HOST_TCMD_SUPPORT +unsigned int testmode =0; +#endif +unsigned int firmware_bridge = 0; + +unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC; +unsigned int panic_on_assert = 1; +unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT; + +unsigned int setuphci = SETUPHCI_DEFAULT; +unsigned int setuphcipal = SETUPHCIPAL_DEFAULT; +unsigned int loghci = 0; +unsigned int setupbtdev = SETUPBTDEV_DEFAULT; +#ifndef EXPORT_HCI_BRIDGE_INTERFACE +unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT; +unsigned int hciuartscale = HCIUARTSCALE_DEFAULT; +unsigned int hciuartstep = HCIUARTSTEP_DEFAULT; +#endif +#ifdef CONFIG_CHECKSUM_OFFLOAD +unsigned int csumOffload=0; +unsigned int csumOffloadTest=0; +#endif +unsigned int eppingtest=0; +unsigned int regscanmode=0; +unsigned int num_device=1; +unsigned char ar6k_init=FALSE; +unsigned int rtc_reset_only_on_exit=0; +unsigned int mac_addr_method=0; +A_BOOL avail_ev_called=FALSE; + + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param_string(ifname, ifname, sizeof(ifname), 0644); +module_param(regcode, int, 0644); +module_param(wlaninitmode, int, 0644); +module_param(bmienable, int, 0644); +module_param(bypasswmi, uint, 0644); +module_param(debuglevel, uint, 0644); +module_param(tspecCompliance, int, 0644); +module_param(onebitmode, uint, 0644); +module_param(busspeedlow, uint, 0644); +module_param(skipflash, uint, 0644); +module_param(wmitimeout, uint, 0644); +module_param(wlanNodeCaching, uint, 0644); +module_param(logWmiRawMsgs, uint, 0644); +module_param(enableuartprint, uint, 0644); +module_param(enabletimerwar, uint, 0644); +module_param(mbox_yield_limit, uint, 0644); +module_param(reduce_credit_dribble, int, 0644); +module_param(allow_trace_signal, int, 0644); +module_param(enablerssicompensation, uint, 0644); +module_param(processDot11Hdr, uint, 0644); +#ifdef CONFIG_CHECKSUM_OFFLOAD +module_param(csumOffload, uint, 0644); +#endif +#ifdef CONFIG_HOST_TCMD_SUPPORT +module_param(testmode, uint, 0644); +#endif +module_param(firmware_bridge, uint, 0644); +module_param(irqprocmode, uint, 0644); +module_param(nohifscattersupport, uint, 0644); +module_param(panic_on_assert, uint, 0644); +module_param(setuphci, uint, 0644); +module_param(setuphcipal, uint, 0644); +module_param(loghci, uint, 0644); +module_param(setupbtdev, uint, 0644); +#ifndef EXPORT_HCI_BRIDGE_INTERFACE +module_param(ar3khcibaud, uint, 0644); +module_param(hciuartscale, uint, 0644); +module_param(hciuartstep, uint, 0644); +#endif +module_param(eppingtest, uint, 0644); +module_param(regscanmode, uint, 0644); +module_param_string(devmode, devmode, sizeof(devmode), 0644); +module_param_string(submode, submode, sizeof(submode), 0644); +module_param_string(targetconf, targetconf, sizeof(targetconf), 0644); +module_param(rtc_reset_only_on_exit, uint, 0644); +module_param(mac_addr_method, uint, 0644); +#else + +#define __user +/* for linux 2.4 and lower */ +MODULE_PARM(bmienable,"i"); +MODULE_PARM(wlaninitmode,"i"); +MODULE_PARM(bypasswmi,"i"); +MODULE_PARM(debuglevel, "i"); +MODULE_PARM(onebitmode,"i"); +MODULE_PARM(busspeedlow, "i"); +MODULE_PARM(skipflash, "i"); +MODULE_PARM(wmitimeout, "i"); +MODULE_PARM(wlanNodeCaching, "i"); +MODULE_PARM(enableuartprint,"i"); +MODULE_PARM(logWmiRawMsgs, "i"); +MODULE_PARM(enabletimerwar,"i"); +MODULE_PARM(mbox_yield_limit,"i"); +MODULE_PARM(reduce_credit_dribble,"i"); +MODULE_PARM(allow_trace_signal,"i"); +MODULE_PARM(enablerssicompensation,"i"); +MODULE_PARM(processDot11Hdr,"i"); +#ifdef CONFIG_CHECKSUM_OFFLOAD +MODULE_PARM(csumOffload,"i"); +#endif +#ifdef CONFIG_HOST_TCMD_SUPPORT +MODULE_PARM(testmode, "i"); +#endif +MODULE_PARM(irqprocmode, "i"); +MODULE_PARM(nohifscattersupport, "i"); +MODULE_PARM(panic_on_assert, "i"); +MODULE_PARM(setuphci, "i"); +MODULE_PARM(setuphcipal, "i"); +MODULE_PARM(loghci, "i"); +MODULE_PARM(regscanmode, "i"); +MODULE_PARM(rtc_reset_only_on_exit, "i"); +MODULE_PARM(mac_addr_method, "i"); +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10) +/* in 2.6.10 and later this is now a pointer to a uint */ +unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX; +#define mboxnum &_mboxnum +#else +unsigned int mboxnum = HTC_MAILBOX_NUM_MAX; +#endif + +#ifdef DEBUG +A_UINT32 g_dbg_flags = DBG_DEFAULTS; +unsigned int debugflags = 0; +int debugdriver = 0; +unsigned int debughtc = 0; +unsigned int debugbmi = 0; +unsigned int debughif = 0; +unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0}; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param(debugflags, uint, 0644); +module_param(debugdriver, int, 0644); +module_param(debughtc, uint, 0644); +module_param(debugbmi, uint, 0644); +module_param(debughif, uint, 0644); +module_param_array(txcreditsavailable, uint, mboxnum, 0644); +module_param_array(txcreditsconsumed, uint, mboxnum, 0644); +module_param_array(txcreditintrenable, uint, mboxnum, 0644); +module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644); +#else +/* linux 2.4 and lower */ +MODULE_PARM(debugflags,"i"); +MODULE_PARM(debugdriver, "i"); +MODULE_PARM(debughtc, "i"); +MODULE_PARM(debugbmi, "i"); +MODULE_PARM(debughif, "i"); +MODULE_PARM(txcreditsavailable, "0-3i"); +MODULE_PARM(txcreditsconsumed, "0-3i"); +MODULE_PARM(txcreditintrenable, "0-3i"); +MODULE_PARM(txcreditintrenableaggregate, "0-3i"); +#endif + +#endif /* DEBUG */ + +#ifdef RK29 +unsigned int resetok = 0; +#else +unsigned int resetok = 1; +#endif +unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0}; +unsigned int hifBusRequestNumMax = 40; +unsigned int war23838_disabled = 0; +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +unsigned int enableAPTCHeuristics = 1; +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param_array(tx_attempt, uint, mboxnum, 0644); +module_param_array(tx_post, uint, mboxnum, 0644); +module_param_array(tx_complete, uint, mboxnum, 0644); +module_param(hifBusRequestNumMax, uint, 0644); +module_param(war23838_disabled, uint, 0644); +module_param(resetok, uint, 0644); +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +module_param(enableAPTCHeuristics, uint, 0644); +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ +#else +MODULE_PARM(tx_attempt, "0-3i"); +MODULE_PARM(tx_post, "0-3i"); +MODULE_PARM(tx_complete, "0-3i"); +MODULE_PARM(hifBusRequestNumMax, "i"); +MODULE_PARM(war23838_disabled, "i"); +MODULE_PARM(resetok, "i"); +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +MODULE_PARM(enableAPTCHeuristics, "i"); +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ +#endif + +#ifdef BLOCK_TX_PATH_FLAG +int blocktx = 0; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param(blocktx, int, 0644); +#else +MODULE_PARM(blocktx, "i"); +#endif +#endif /* BLOCK_TX_PATH_FLAG */ + +static A_INT16 rssi_compensation_table[NUM_DEV][96]; + +int reconnect_flag = 0; +static ar6k_pal_config_t ar6k_pal_config_g; + +/* Function declarations */ +static int ar6000_init_module(void); +static void ar6000_cleanup_module(void); + +int ar6000_init(struct net_device *dev); +static int ar6000_open(struct net_device *dev); +static int ar6000_close(struct net_device *dev); +static int ar6000_init_control_info(AR_SOFTC_DEV_T *arPriv); +static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev); + +void ar6000_destroy(struct net_device *dev, unsigned int unregister); +void ar6000_cleanup(AR_SOFTC_T *ar); +static void ar6000_detect_error(unsigned long ptr); +static void ar6000_set_multicast_list(struct net_device *dev); +static struct net_device_stats *ar6000_get_stats(struct net_device *dev); +static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev); + +static void disconnect_timer_handler(unsigned long ptr); +static void ap_acs_handler(unsigned long ptr); + +void read_rssi_compensation_param(AR_SOFTC_T *ar); +void target_register_tbl_attach(A_UINT32 target_type); +static void ar6000_uapsd_trigger_frame_rx(AR_SOFTC_DEV_T *arPriv, conn_t *conn); + + /* for android builds we call external APIs that handle firmware download and configuration */ +#ifdef ANDROID_ENV +/* !!!! Interim android support to make it easier to patch the default driver for + * android use. You must define an external source file ar6000_android.c that handles the following + * APIs */ +extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks); +extern void android_module_exit(void); +extern void android_send_reload_event(AR_SOFTC_DEV_T *arPriv); +#define ANDROID_RELOAD_THRESHOLD_FOR_EP_FULL 5 +static int android_epfull_cnt; +#endif +/* + * HTC service connection handlers + */ +static A_STATUS ar6000_avail_ev(void *context, void *hif_handle); + +static A_STATUS ar6000_unavail_ev(void *context, void *hif_handle); + +A_STATUS ar6000_configure_target(AR_SOFTC_T *ar); + +static void ar6000_target_failure(void *Instance, A_STATUS Status); + +static void ar6000_rx(void *Context, HTC_PACKET *pPacket); + +static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint); + +static void ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPackets); + +static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket); + +#ifdef ATH_AR6K_11N_SUPPORT +static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num); +#endif +static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf); +//static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf); + +static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length); + +static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count); + +static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +static ssize_t +ar6000_sysfs_bmi_read(struct kobject *kobj, struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count); + +static ssize_t +ar6000_sysfs_bmi_write(struct kobject *kobj, struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count); +#else +static ssize_t +ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count); + +static ssize_t +ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count); +#endif + +static A_STATUS +ar6000_sysfs_bmi_init(AR_SOFTC_T *ar); + +/* HCI PAL callback function declarations */ +A_STATUS ar6k_setup_hci_pal(AR_SOFTC_DEV_T *ar); +void ar6k_cleanup_hci_pal(AR_SOFTC_DEV_T *ar); + +static void +ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar); + +A_STATUS +ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode); + +/* + * Static variables + */ + +struct net_device *ar6000_devices[NUM_DEV]; +extern struct iw_handler_def ath_iw_handler_def; +static void ar6000_cookie_init(AR_SOFTC_T *ar); +static void ar6000_cookie_cleanup(AR_SOFTC_T *ar); +static void ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie); +static struct ar_cookie *ar6000_alloc_cookie(AR_SOFTC_T *ar); + +#ifdef USER_KEYS +static A_STATUS ar6000_reinstall_keys(AR_SOFTC_DEV_T *arPriv,A_UINT8 key_op_ctrl); +#endif + + +static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM]; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) +static struct net_device_ops ar6000_netdev_ops = { + .ndo_init = NULL, + .ndo_open = ar6000_open, + .ndo_stop = ar6000_close, + .ndo_get_stats = ar6000_get_stats, + .ndo_do_ioctl = ar6000_ioctl, + .ndo_start_xmit = ar6000_data_tx, + .ndo_set_multicast_list = ar6000_set_multicast_list, + .ndo_change_mtu = eth_change_mtu, +}; +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) */ + +/* Debug log support */ + +/* + * Flag to govern whether the debug logs should be parsed in the kernel + * or reported to the application. + */ +#define REPORT_DEBUG_LOGS_TO_APP + +A_STATUS +ar6000_set_host_app_area(AR_SOFTC_T *ar) +{ + A_UINT32 address, data; + struct host_app_area_s host_app_area; + + /* Fetch the address of the host_app_area_s instance in the host interest area */ + address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_app_host_interest)); + if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != A_OK) { + return A_ERROR; + } + address = TARG_VTOP(ar->arTargetType, data); + host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION; + if (ar6000_WriteDataDiag(ar->arHifDevice, address, + (A_UCHAR *)&host_app_area, + sizeof(struct host_app_area_s)) != A_OK) + { + return A_ERROR; + } + + return A_OK; +} + +A_UINT32 +dbglog_get_debug_hdr_ptr(AR_SOFTC_T *ar) +{ + A_UINT32 param; + A_UINT32 address; + A_STATUS status; + + address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dbglog_hdr)); + if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address, + (A_UCHAR *)¶m, 4)) != A_OK) + { + param = 0; + } + + return param; +} + +/* + * The dbglog module has been initialized. Its ok to access the relevant + * data stuctures over the diagnostic window. + */ +void +ar6000_dbglog_init_done(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + ar->dbglog_init_done = TRUE; +} + +A_UINT32 +dbglog_get_debug_fragment(A_INT8 *datap, A_UINT32 len, A_UINT32 limit) +{ + A_INT32 *buffer; + A_UINT32 count; + A_UINT32 numargs; + A_UINT32 length; + A_UINT32 fraglen; + + count = fraglen = 0; + buffer = (A_INT32 *)datap; + length = (limit >> 2); + + if (len <= limit) { + fraglen = len; + } else { + while (count < length) { + numargs = DBGLOG_GET_NUMARGS(buffer[count]); + fraglen = (count << 2); + count += numargs + 1; + } + } + + return fraglen; +} + +void +dbglog_parse_debug_logs(A_INT8 *datap, A_UINT32 len) +{ + A_INT32 *buffer; + A_UINT32 count; + A_UINT32 timestamp; + A_UINT32 debugid; + A_UINT32 moduleid; + A_UINT32 numargs; + A_UINT32 length; + + count = 0; + buffer = (A_INT32 *)datap; + length = (len >> 2); + while (count < length) { + debugid = DBGLOG_GET_DBGID(buffer[count]); + moduleid = DBGLOG_GET_MODULEID(buffer[count]); + numargs = DBGLOG_GET_NUMARGS(buffer[count]); + timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]); + switch (numargs) { + case 0: + AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp)); + break; + + case 1: + AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid, + timestamp, buffer[count+1])); + break; + + case 2: + AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid, + timestamp, buffer[count+1], buffer[count+2])); + break; + + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs)); + } + count += numargs + 1; + } +} + +int +ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar) +{ + struct dbglog_hdr_s debug_hdr; + struct dbglog_buf_s debug_buf; + A_UINT32 address; + A_UINT32 length; + A_UINT32 dropped; + A_UINT32 firstbuf; + A_UINT32 debug_hdr_ptr; + + if (!ar->dbglog_init_done) return A_ERROR; + + + AR6000_SPIN_LOCK(&ar->arLock, 0); + + if (ar->dbgLogFetchInProgress) { + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + return A_EBUSY; + } + + /* block out others */ + ar->dbgLogFetchInProgress = TRUE; + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar); + printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr); + + /* Get the contents of the ring buffer */ + if (debug_hdr_ptr) { + address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr); + length = sizeof(struct dbglog_hdr_s); + ar6000_ReadDataDiag(ar->arHifDevice, address, + (A_UCHAR *)&debug_hdr, length); + address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_hdr.dbuf); + firstbuf = address; + dropped = debug_hdr.dropped; + length = sizeof(struct dbglog_buf_s); + ar6000_ReadDataDiag(ar->arHifDevice, address, + (A_UCHAR *)&debug_buf, length); + + do { + address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_buf.buffer); + length = debug_buf.length; + if ((length) && (debug_buf.length <= debug_buf.bufsize)) { + /* Rewind the index if it is about to overrun the buffer */ + if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) { + ar->log_cnt = 0; + } + if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, + (A_UCHAR *)&ar->log_buffer[ar->log_cnt], length)) + { + break; + } + ar6000_dbglog_event(ar->arDev[0], dropped, (A_INT8*)&ar->log_buffer[ar->log_cnt], length); + ar->log_cnt += length; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n", + debug_buf.length, debug_buf.bufsize)); + } + + address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_buf.next); + length = sizeof(struct dbglog_buf_s); + if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, + (A_UCHAR *)&debug_buf, length)) + { + break; + } + + } while (address != firstbuf); + } + + ar->dbgLogFetchInProgress = FALSE; + + return A_OK; +} + +void +ar6000_dbglog_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 dropped, + A_INT8 *buffer, A_UINT32 length) +{ +#ifdef REPORT_DEBUG_LOGS_TO_APP + #define MAX_WIRELESS_EVENT_SIZE 252 + /* + * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages. + * There seems to be a limitation on the length of message that could be + * transmitted to the user app via this mechanism. + */ + A_UINT32 send, sent; + + sent = 0; + send = dbglog_get_debug_fragment(&buffer[sent], length - sent, + MAX_WIRELESS_EVENT_SIZE); + while (send) { + ar6000_send_event_to_app(arPriv, WMIX_DBGLOG_EVENTID, (A_UINT8*)&buffer[sent], send); + sent += send; + send = dbglog_get_debug_fragment(&buffer[sent], length - sent, + MAX_WIRELESS_EVENT_SIZE); + } +#else + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n", + dropped, length)); + + /* Interpret the debug logs */ + dbglog_parse_debug_logs((A_INT8*)buffer, length); +#endif /* REPORT_DEBUG_LOGS_TO_APP */ +} + +void +ar6000_parse_dev_mode(A_CHAR *mode) +{ + A_UINT8 i, match = FALSE, mode_len; + A_UINT8 val_mode, val_submode; + A_UINT8 num_submode; + + char *valid_modes[] = { "sta", + "ap", + "ibss", + "bt30amp", + "sta,ap", + "ap,sta", + "ap,ap", + "sta,sta", + "sta,bt30amp", + "sta,ap,ap" + }; + char *valid_submodes[] = { "none", + "p2pdev", + /*"p2pclient",*/ //persistent p2p support + /*"p2pgo", */ // persistent p2p support + "none,none", + "none,none,none", + "none,p2pdev", + "p2pdev,none", + /*"none,p2pclient",*/ //persistent p2p support + /*"none,p2pgo"*/ // persistent p2p support + }; + + A_CHAR *dev_mode; + A_CHAR *str; + A_UINT32 host_int = 0; + + dev_mode = mode; + str = mode; + num_device = 0; + fwmode = 0; + + mode_len = strlen(dev_mode); + for (i=0; i <= 9; i++) { + if ((mode_len == strlen(valid_modes[i])) && (strcmp(dev_mode,valid_modes[i]))==0) { + match = TRUE; + break; + } + } + + if(!match) { + num_device = fwmode = 1; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ERROR: Wrong mode. using default (single device STA mode).\n")); + return; + } + + do + { + str++; + if(*str == ',' || *str == '\0') { + num_device++; + if(strncmp(dev_mode,"ap",2) == 0) { + host_int = HI_OPTION_FW_MODE_AP; + } + else if(strncmp(dev_mode,"sta",3) == 0) { + host_int = HI_OPTION_FW_MODE_BSS_STA; + } + else if(strncmp(dev_mode,"ibss",4) == 0 ) { + host_int = HI_OPTION_FW_MODE_IBSS; + } else if(strncmp(dev_mode,"bt30amp",7) == 0) { + host_int = HI_OPTION_FW_MODE_BT30AMP; + } + + fwmode |= (host_int << ((num_device -1) * HI_OPTION_FW_MODE_BITS)); + dev_mode = ++str; + } + }while(*dev_mode != '\0'); + + /* Validate submode if present */ + if (!submode[0]) { + /* default "none" submode for all devices */ + fwsubmode = 0; + return; + } + + dev_mode = submode; + str = submode; + num_submode = 0; + fwsubmode = 0; + match = FALSE; + + mode_len = strlen(dev_mode); + for (i=0; i<6; i++) { + if ((mode_len == strlen(valid_submodes[i])) && (strcmp(dev_mode,valid_submodes[i]))==0) { + match = TRUE; + break; + } + } + + if (!match) { + fwsubmode = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ERROR: Wrong submode. using default (none for all devs).\n")); + return; + } + + do + { + str++; + if(*str == ',' || *str == '\0') { + num_submode++; + if(strncmp(dev_mode,"none",4) == 0) { + host_int = HI_OPTION_FW_SUBMODE_NONE; + } + else if(strncmp(dev_mode,"p2pdev",6) == 0) { + host_int = HI_OPTION_FW_SUBMODE_P2PDEV; + } + else if(strncmp(dev_mode,"p2pclient",9) == 0 ) { + host_int = HI_OPTION_FW_SUBMODE_P2PCLIENT; + } else if(strncmp(dev_mode,"p2pgo",5) == 0 ) { + host_int = HI_OPTION_FW_SUBMODE_P2PGO; + } + fwsubmode |= (host_int << ((num_submode -1) * HI_OPTION_FW_SUBMODE_BITS)); + dev_mode = ++str; + } + }while(*dev_mode != '\0'); + + /* Validate if the subopmode is specified for all the devs. + */ + if (num_device != num_submode) { + /* default to "none" submode for all devices */ + fwsubmode = 0; + return; + } + + /* Validate if the submode specified is appropriate for the device modes + * specified for each device. The following is the validation recipe. + * fwmode fwsubmode + * ----------------------- + * IBSS none + * STA none,p2pdev,p2pclient + * AP none,p2pgo + */ + for (i=0; i> (i * HI_OPTION_FW_MODE_BITS)) & + HI_OPTION_FW_MODE_MASK; + val_submode = (fwsubmode >> (i * HI_OPTION_FW_SUBMODE_BITS)) & + HI_OPTION_FW_SUBMODE_MASK; + switch (val_mode) { + case HI_OPTION_FW_MODE_IBSS: + if (val_submode != HI_OPTION_FW_SUBMODE_NONE) { + /* set submode to none */ + fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); + fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); + } + break; + + case HI_OPTION_FW_MODE_BSS_STA: + if (val_submode == HI_OPTION_FW_SUBMODE_P2PGO) { + /* set submode to none */ + fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); + fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); + } + + break; + case HI_OPTION_FW_MODE_AP: + if (val_submode == HI_OPTION_FW_SUBMODE_P2PDEV || + val_submode == HI_OPTION_FW_SUBMODE_P2PCLIENT) { + /* set submode to none */ + fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); + fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); + } + break; + + default: + break; + } + } + + return; +} + +#ifdef RK29 +static int +#else +static int __init +#endif +ar6000_init_module(void) +{ +#ifndef RK29 + static int probed = 0; +#endif + A_STATUS status; + OSDRV_CALLBACKS osdrvCallbacks; + + a_module_debug_support_init(); + +#ifdef DEBUG + /* check for debug mask overrides */ + if (debughtc != 0) { + ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc); + } + if (debugbmi != 0) { + ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi); + } + if (debughif != 0) { + ATH_DEBUG_SET_DEBUG_MASK(hif,debughif); + } + if (debugdriver != 0) { + ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver); + } + +#endif + + A_REGISTER_MODULE_DEBUG_INFO(driver); + ar6k_init = FALSE; + A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks)); + osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev; + osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev; + +#ifdef CONFIG_PM + osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev; + osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev; + osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev; +#endif + +#ifndef RK29 + ar6000_pm_init(); +#endif + + if(devmode[0]) + ar6000_parse_dev_mode(devmode); + +#ifdef ANDROID_ENV + android_module_init(&osdrvCallbacks); +#endif + +#ifdef DEBUG + /* Set the debug flags if specified at load time */ + if(debugflags != 0) + { + g_dbg_flags = debugflags; + } +#endif + +#ifndef RK29 + if (probed) { + return -ENODEV; + } + probed++; +#endif + +#ifdef CONFIG_HOST_GPIO_SUPPORT + ar6000_gpio_init(); +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + + status = HIFInit(&osdrvCallbacks); + if(status != A_OK) + return -ENODEV; + + return 0; +} + +#ifdef RK29 +static void +#else +static void __exit +#endif +ar6000_cleanup_module(void) +{ + int i = 0; + struct net_device *ar6000_netdev; + AR_SOFTC_T *ar; + AR_SOFTC_DEV_T *arPriv = NULL; + + if(ar6000_devices[0] != NULL) { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[0]); + ar = arPriv->arSoftc; + ar6000_cleanup(ar); + } + for (i=0; i < num_device; i++) { +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + /* Delete the Adaptive Power Control timer */ + if (timer_pending(&aptcTimer[i])) { + del_timer_sync(&aptcTimer[i]); + } +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + if (ar6000_devices[i] != NULL) { + ar6000_netdev = ar6000_devices[i]; + ar6000_devices[i] = NULL; + ar6000_destroy(ar6000_netdev, 1); + if (arPriv) + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + } + } + + HIFShutDownDevice(NULL); + + a_module_debug_support_cleanup(); + +#ifndef RK29 + ar6000_pm_exit(); +#endif + +#ifdef ANDROID_ENV + android_module_exit(); +#endif + a_meminfo_report(TRUE); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n")); +} + +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +void +aptcTimerHandler(unsigned long arg) +{ + A_UINT32 numbytes; + A_UINT32 throughput; + AR_SOFTC_T *ar; + A_STATUS status; + APTC_TRAFFIC_RECORD *aptcTR; + A_UNIT8 i; + + ar = (AR_SOFTC_T *)arg; + A_ASSERT(ar != NULL); + + for(i = 0; i < num_device; i++) { + aptcTR = ar->arDev[i].aptcTR; + A_ASSERT(!timer_pending(&aptcTimer[i])); + AR6000_SPIN_LOCK(&ar->arLock, 0); + + /* Get the number of bytes transferred */ + numbytes = aptcTR->bytesTransmitted + aptcTR->bytesReceived; + aptcTR->bytesTransmitted = aptcTR->bytesReceived = 0; + + /* Calculate and decide based on throughput thresholds */ + throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */ + if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) { + /* Enable Sleep and delete the timer */ + A_ASSERT(ar->arWmiReady == TRUE); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + status = wmi_powermode_cmd(ar->arWmi, REC_POWER); + AR6000_SPIN_LOCK(&ar->arLock, 0); + A_ASSERT(status == A_OK); + aptcTR->timerScheduled = FALSE; + } else { + A_TIMEOUT_MS(&aptcTimer[i], APTC_TRAFFIC_SAMPLING_INTERVAL, 0); + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } +} +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + +#ifdef ATH_AR6K_11N_SUPPORT +static void +ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num) +{ + void * osbuf; + + while(num) { + if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) { + A_NETBUF_ENQUEUE(q, osbuf); + } else { + break; + } + num--; + } + + if(num) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(), allocation of netbuf failed", __func__)); + } +} +#endif + +static struct bin_attribute bmi_attr = { + .attr = {.name = "bmi", .mode = 0600}, + .read = ar6000_sysfs_bmi_read, + .write = ar6000_sysfs_bmi_write, +}; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +static ssize_t +ar6000_sysfs_bmi_read(struct kobject *kobj, struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +#else +static ssize_t +ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +#endif +{ + int index; + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_T *ar = NULL; + HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", count)); + for (index=0; index < num_device; index++) { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[index]); + ar = arPriv->arSoftc; + osDevInfo = &ar->osDevInfo; + if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { + break; + } + } + + if (ar == NULL) return 0; + if (index == num_device) return 0; + + if ((BMIRawRead(ar->arHifDevice, (A_UCHAR*)buf, count, TRUE)) != A_OK) { + return 0; + } + + return count; +} + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +static ssize_t +ar6000_sysfs_bmi_write(struct kobject *kobj, struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +#else +static ssize_t +ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +#endif +{ + int index; + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_T *ar = NULL; + HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", count)); + for (index=0; index < num_device; index++) { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[index]); + ar = arPriv->arSoftc; + osDevInfo = &ar->osDevInfo; + if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { + break; + } + } + + if (ar == NULL) return 0; + if (index == num_device) return 0; + + if ((BMIRawWrite(ar->arHifDevice, (A_UCHAR*)buf, count)) != A_OK) { + return 0; + } + + return count; +} + +static A_STATUS +ar6000_sysfs_bmi_init(AR_SOFTC_T *ar) +{ + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n")); + A_MEMZERO(&ar->osDevInfo, sizeof(HIF_DEVICE_OS_DEVICE_INFO)); + + /* Get the underlying OS device */ + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_GET_OS_DEVICE, + &ar->osDevInfo, + sizeof(HIF_DEVICE_OS_DEVICE_INFO)); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n")); + return A_ERROR; + } + + /* Create a bmi entry in the sysfs filesystem */ + if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n")); + return A_ERROR; + } + + return A_OK; +} + +static void +ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar) +{ + if (ar->osDevInfo.pOSDevice) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n")); + sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr); + ar->osDevInfo.pOSDevice = NULL; + } +} + +#define bmifn(fn) do { \ + if ((fn) < A_OK) { \ + A_PRINTF("BMI operation failed: %d\n", __LINE__); \ + return A_ERROR; \ + } \ +} while(0) + +#ifdef INIT_MODE_DRV_ENABLED + +#define MCKINLEY_MAC_ADDRESS_OFFSET 0x16 +static +void calculate_crc(A_UINT32 TargetType, A_UCHAR *eeprom_data, size_t eeprom_size) +{ + A_UINT16 *ptr_crc; + A_UINT16 *ptr16_eeprom; + A_UINT16 checksum; + A_UINT32 i; + + if (TargetType == TARGET_TYPE_AR6001) + { + ptr_crc = (A_UINT16 *)eeprom_data; + } + else if (TargetType == TARGET_TYPE_AR6003) + { + ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); + } + else if (TargetType == TARGET_TYPE_MCKINLEY) + { + eeprom_size = 1024; + ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); + } + else + { + ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); + } + + + // Clear the crc + *ptr_crc = 0; + + // Recalculate new CRC + checksum = 0; + ptr16_eeprom = (A_UINT16 *)eeprom_data; + for (i = 0;i < eeprom_size; i += 2) + { + checksum = checksum ^ (*ptr16_eeprom); + ptr16_eeprom++; + } + checksum = 0xFFFF ^ checksum; + *ptr_crc = checksum; +} + +#ifdef SOFTMAC_FILE_USED +#define AR6002_MAC_ADDRESS_OFFSET 0x0A +#define AR6003_MAC_ADDRESS_OFFSET 0x16 +static void +ar6000_softmac_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t eeprom_size) +{ + /* We need to store the MAC, which comes either from the softmac file or is + * randomly generated, because we do not want to load a new MAC address + * if the chip goes into suspend and then is resumed later on. We ONLY + * want to load a new MAC if the driver is unloaded and then reloaded + */ + static A_UCHAR random_mac[6]; + const char *source = "random generated"; + const struct firmware *softmac_entry; + A_UCHAR *ptr_mac; + switch (ar->arTargetType) { + case TARGET_TYPE_AR6002: + ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET); + break; + case TARGET_TYPE_AR6003: + ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET); + break; + case TARGET_TYPE_MCKINLEY: + ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + MCKINLEY_MAC_ADDRESS_OFFSET); + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); + return; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("MAC from EEPROM %02X:%02X:%02X:%02X:%02X:%02X\n", + ptr_mac[0], ptr_mac[1], ptr_mac[2], + ptr_mac[3], ptr_mac[4], ptr_mac[5])); + + if (memcmp(random_mac, "\0\0\0\0\0\0", 6)!=0) { + memcpy(ptr_mac, random_mac, 6); + } else { + /* create a random MAC in case we cannot read file from system */ + ptr_mac[0] = random_mac[0] = 2; /* locally administered */ + ptr_mac[1] = random_mac[1] = 0x03; + ptr_mac[2] = random_mac[2] = 0x7F; + ptr_mac[3] = random_mac[3] = random32() & 0xff; + ptr_mac[4] = random_mac[4] = random32() & 0xff; + ptr_mac[5] = random_mac[5] = random32() & 0xff; + } + + if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0) + { + A_CHAR *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1); + if (macbuf) { + unsigned int softmac[6]; + memcpy(macbuf, softmac_entry->data, softmac_entry->size); + macbuf[softmac_entry->size] = '\0'; + if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x", + &softmac[0], &softmac[1], &softmac[2], + &softmac[3], &softmac[4], &softmac[5])==6) { + int i; + +#ifdef TCHIP + if(IS_MAC_NULL(softmac)) { + softmac[0]= 0x20; + softmac[1]= 0x59; + softmac[2]= 0xa0; + softmac[3]= (random32() & 0x0f) + 0x30; + softmac[4]= random32() & 0xff; + softmac[5]= random32() & 0xff; + + //write to the file. + sprintf(macbuf, + "%02x:%02x:%02x:%02x:%02x:%02x", + softmac[0], softmac[1], softmac[2], + softmac[3], softmac[4], softmac[5]); + { + extern void android_wifi_softmac_update(char *mac_buff, int len); + android_wifi_softmac_update(macbuf, softmac_entry->size); + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("MAC random %02X:%02X:%02X:%02X:%02X:%02X\n", + softmac[0], softmac[1], softmac[2], + softmac[3], softmac[4], softmac[5])); + + } +#endif + + for (i=0; i<6; ++i) { + ptr_mac[i] = softmac[i] & 0xff; + } + source = "softmac file"; + A_MEMZERO(random_mac, sizeof(random_mac)); + } + A_FREE(macbuf); + } + A_RELEASE_FIRMWARE(softmac_entry); + } + + if (memcmp(random_mac, "\0\0\0\0\0\0", 6)!=0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Warning! Random MAC address is just for testing purpose\n")); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, + ("MAC from %s %02X:%02X:%02X:%02X:%02X:%02X\n", source, + ptr_mac[0], ptr_mac[1], ptr_mac[2], + ptr_mac[3], ptr_mac[4], ptr_mac[5])); + calculate_crc(ar->arTargetType, eeprom_data, eeprom_size); +} +#endif /* SOFTMAC_FILE_USED */ + +static void +ar6000_reg_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t eeprom_size, int regCode) +{ + A_UCHAR *ptr_reg; + switch (ar->arTargetType) { + case TARGET_TYPE_AR6002: + ptr_reg = (A_UINT8 *)((A_UCHAR *)eeprom_data + 8); + break; + case TARGET_TYPE_AR6003: + ptr_reg = (A_UINT8 *)((A_UCHAR *)eeprom_data + 12); + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); + return; + } + + ptr_reg[0] = (A_UCHAR)(regCode&0xFF); + ptr_reg[1] = (A_UCHAR)((regCode>>8)&0xFF); + calculate_crc(ar->arTargetType, eeprom_data, eeprom_size); +} + +static A_STATUS +ar6000_transfer_bin_file(AR_SOFTC_T *ar, AR6K_BIN_FILE file, A_UINT32 address, A_BOOL compressed) +{ + A_STATUS status; + const char *filename; + const struct firmware *fw_entry; + A_UINT32 fw_entry_size; + A_UCHAR *tempEeprom; + A_UINT32 board_data_size; + + switch (file) { + case AR6K_OTP_FILE: + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_OTP_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_OTP_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + break; + + case AR6K_FIRMWARE_FILE: + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_FIRMWARE_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + if(ar->arVersion.targetconf_ver == AR6003_SUBVER_ROUTER) + filename = AR6003_REV3_ROUTER_FIRMWARE_FILE; + else if (ar->arVersion.targetconf_ver == AR6003_SUBVER_MOBILE) + filename = AR6003_REV3_MOBILE_FIRMWARE_FILE; + else if (ar->arVersion.targetconf_ver == AR6003_SUBVER_TABLET) + filename = AR6003_REV3_TABLET_FIRMWARE_FILE; + else + filename = AR6003_REV3_DEFAULT_FIRMWARE_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + + if (eppingtest) { + bypasswmi = TRUE; + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_EPPING_FIRMWARE_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_EPPING_FIRMWARE_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n", + ar->arVersion.target_ver)); + return A_ERROR; + } + compressed = 0; + } + +#ifdef CONFIG_HOST_TCMD_SUPPORT + if(testmode == 1) { + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_TCMD_FIRMWARE_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_TCMD_FIRMWARE_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + compressed = 0; + } +#endif +#ifdef HTC_RAW_INTERFACE + if (!eppingtest && bypasswmi) { + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_ART_FIRMWARE_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_ART_FIRMWARE_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + compressed = 0; + } +#endif + break; + + case AR6K_PATCH_FILE: + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_PATCH_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_PATCH_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + break; + + case AR6K_BOARD_DATA_FILE: + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_BOARD_DATA_FILE; + } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_BOARD_DATA_FILE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); + return A_ERROR; + } + break; + + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file)); + return A_ERROR; + } + if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); + return A_ENOENT; + } + + fw_entry_size = fw_entry->size; + tempEeprom = NULL; + + /* Load extended board data for AR6003 */ + if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) { + A_UINT32 board_ext_address; + A_INT32 board_ext_data_size; + + tempEeprom = A_MALLOC_NOWAIT(fw_entry->size); + if (!tempEeprom) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Memory allocation failed\n")); + A_RELEASE_FIRMWARE(fw_entry); + return A_ERROR; + } + + board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \ + (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0)); + + board_ext_data_size = 0; + if (ar->arTargetType == TARGET_TYPE_AR6002) { + board_ext_data_size = AR6002_BOARD_EXT_DATA_SZ; + } else if (ar->arTargetType == TARGET_TYPE_AR6003) { + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + board_ext_data_size = AR6003_VER2_BOARD_EXT_DATA_SZ; + } else { + board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ; + } + } + + /* AR6003 2.1.1 support 1792 bytes and 2048 bytes board file */ + if ((board_ext_data_size) && + (fw_entry->size < (board_data_size + board_ext_data_size))) + { + board_ext_data_size = fw_entry->size - board_data_size; + if (board_ext_data_size < 0) { + board_ext_data_size = 0; + } + } + + A_MEMCPY(tempEeprom, (A_UCHAR *)fw_entry->data, fw_entry->size); + +#ifdef SOFTMAC_FILE_USED + ar6000_softmac_update(ar, tempEeprom, board_data_size); +#endif + if (regcode!=0) { + ar6000_reg_update(ar, tempEeprom, board_data_size, regcode); + } + + /* Determine where in Target RAM to write Board Data */ + bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data), (A_UCHAR *)&board_ext_address, 4)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address)); + + /* check whether the target has allocated memory for extended board data and file contains extended board data */ + if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) { + A_UINT32 param; + + status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(((A_UINT32)tempEeprom) + board_data_size), board_ext_data_size); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); + A_RELEASE_FIRMWARE(fw_entry); + return A_ERROR; + } + + /* Record the fact that extended board Data IS initialized */ + param = (board_ext_data_size << 16) | 1; + bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data_config), (A_UCHAR *)¶m, 4)); + } + fw_entry_size = board_data_size; + } + + if (compressed) { + status = BMIFastDownload(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); + } else { + if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) + { + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)tempEeprom, fw_entry_size); + } + else + { + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); + } + } + + if (tempEeprom) { + A_FREE(tempEeprom); + } + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); + A_RELEASE_FIRMWARE(fw_entry); + return A_ERROR; + } + A_RELEASE_FIRMWARE(fw_entry); + return A_OK; +} +#endif /* INIT_MODE_DRV_ENABLED */ + +A_STATUS +ar6000_update_bdaddr(AR_SOFTC_T *ar) +{ + + if (setupbtdev != 0) { + A_UINT32 address; + + if (BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data), (A_UCHAR *)&address, 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n")); + return A_ERROR; + } + + if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (A_UCHAR *)ar->bdaddr, 6) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0], + ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3], + ar->bdaddr[4], ar->bdaddr[5])); + } + +return A_OK; +} + +A_STATUS +ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode) +{ +#if defined(INIT_MODE_DRV_ENABLED) && defined(CONFIG_HOST_TCMD_SUPPORT) + const char *filename; + const struct firmware *fw_entry; +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n")); + + if (mode == WLAN_INIT_MODE_UDEV) { + A_CHAR version[16]; + const struct firmware *fw_entry; + + /* Get config using udev through a script in user space */ + sprintf(version, "%2.2x", ar->arVersion.target_ver); + if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version)); + return A_ERROR; + } + + A_RELEASE_FIRMWARE(fw_entry); +#ifdef INIT_MODE_DRV_ENABLED + } else { + /* The config is contained within the driver itself */ + A_STATUS status; + A_UINT32 param, options, sleep, address; + + /* Temporarily disable system sleep */ + address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_OFFSET; + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + options = param; + param |= AR6K_OPTION_SLEEP_DISABLE; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = RTC_WMAC_BASE_ADDRESS + WLAN_SYSTEM_SLEEP_OFFSET; + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + sleep = param; + param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1); + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep)); + + if (ar->arTargetType == TARGET_TYPE_MCKINLEY) { + /* Run at 40/44MHz by default */ + param = CPU_CLOCK_STANDARD_SET(0); + } else if (ar->arTargetType == TARGET_TYPE_AR6003) { + /* Program analog PLL register */ + bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001)); + /* Run at 80/88MHz by default */ + param = CPU_CLOCK_STANDARD_SET(1); + } else { + /* Run at 40/44MHz by default */ + param = CPU_CLOCK_STANDARD_SET(0); + } + address = RTC_SOC_BASE_ADDRESS + CPU_CLOCK_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + param = 0; + if (ar->arTargetType == TARGET_TYPE_AR6002) { + bmifn(BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ext_clk_detected), + (A_UCHAR *)¶m, 4)); + } + + /* LPO_CAL.ENABLE = 1 if no external clk is detected */ + if (param != 1) { + address = RTC_SOC_BASE_ADDRESS + LPO_CAL_OFFSET; + param = LPO_CAL_ENABLE_SET(1); + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + } + + /* Venus2.0: Lower SDIO pad drive strength */ + if ((ar->arVersion.target_ver == AR6003_REV2_VERSION) || + (ar->arVersion.target_ver == AR6003_REV3_VERSION)) + { + param = 0x20; + address = GPIO_BASE_ADDRESS + GPIO_PIN10_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = GPIO_BASE_ADDRESS + GPIO_PIN11_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = GPIO_BASE_ADDRESS + GPIO_PIN12_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = GPIO_BASE_ADDRESS + GPIO_PIN13_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + } + +#ifdef FORCE_INTERNAL_CLOCK + /* Ignore external clock, if any, and force use of internal clock */ + if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { + /* hi_ext_clk_detected = 0 */ + param = 0; + bmifn(BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ext_clk_detected), + (A_UCHAR *)¶m, 4)); + + /* CLOCK_CONTROL &= ~LF_CLK32 */ + address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS; + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + param &= (~CLOCK_CONTROL_LF_CLK32_SET(1)); + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + } +#endif /* FORCE_INTERNAL_CLOCK */ + + /* Transfer Board Data from Target EEPROM to Target RAM */ + if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { + /* Determine where in Target RAM to write Board Data */ + bmifn(BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data), + (A_UCHAR *)&address, 4)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address)); + + /* Write EEPROM data to Target RAM */ + if ((status=ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, FALSE)) != A_OK) { + return A_ERROR; + } + + /* Record the fact that Board Data IS initialized */ + param = 1; + bmifn(BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data_initialized), + (A_UCHAR *)¶m, 4)); + + /* Transfer One time Programmable data */ + AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); + if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + address = BMI_SEGMENTED_WRITE_ADDR; + } + status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, TRUE); + if (status == A_OK) { + /* Execute the OTP code */ +#ifdef SOFTMAC_FILE_USED + param = 1; +#else + param = 0; +#endif + if (regcode != 0) + param |= 0x2; + AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); + bmifn(BMIExecute(ar->arHifDevice, address, ¶m)); + } else if (status != A_ENOENT) { + return A_ERROR; + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType)); + return A_ERROR; + } + + /* Download Target firmware */ + AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); + if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + address = BMI_SEGMENTED_WRITE_ADDR; + } + if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, TRUE)) != A_OK) { + return A_ERROR; + } + + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) + { + /* Set starting address for firmware */ + AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); + bmifn(BMISetAppStart(ar->arHifDevice, address)); + } + + /* Apply the patches */ + if (ar->arTargetType == TARGET_TYPE_AR6003) { + AR6K_DATASET_PATCH_ADDRESS(address, ar->arVersion.target_ver); + if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, FALSE)) != A_OK) { + return A_ERROR; + } + param = address; + bmifn(BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dset_list_head), + (A_UCHAR *)¶m, 4)); + } + + /* Restore system sleep */ + address = RTC_WMAC_BASE_ADDRESS + WLAN_SYSTEM_SLEEP_OFFSET; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep)); + + address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_OFFSET; + param = options | 0x20; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { + /* Configure GPIO AR6003 UART */ +#ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN +#define CONFIG_AR600x_DEBUG_UART_TX_PIN 8 +#endif + param = CONFIG_AR600x_DEBUG_UART_TX_PIN; + bmifn(BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dbg_uart_txpin), + (A_UCHAR *)¶m, 4)); + +#if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23) + if (ATH_REGISTER_SUPPORTED_BY_TARGET(CLOCK_GPIO_OFFSET)) { + address = GPIO_BASE_ADDRESS + CLOCK_GPIO_OFFSET; + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1); + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + } else { + /* AR6004 has no need for a CLOCK_GPIO register */ + } +#endif + + /* Configure GPIO for BT Reset */ +#ifdef ATH6KL_CONFIG_GPIO_BT_RESET +#define CONFIG_AR600x_BT_RESET_PIN 0x16 + param = CONFIG_AR600x_BT_RESET_PIN; + bmifn(BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_hci_uart_support_pins), + (A_UCHAR *)¶m, 4)); +#endif /* ATH6KL_CONFIG_GPIO_BT_RESET */ + + /* Configure UART flow control polarity */ +#ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY +#define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0 +#endif + +#if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1) + if ((ar->arVersion.target_ver == AR6003_REV2_VERSION) || + (ar->arVersion.target_ver == AR6003_REV3_VERSION)) + { + param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2); + bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (A_UCHAR *)¶m, 4)); + } +#endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */ + } +#ifdef HTC_RAW_INTERFACE + if (!eppingtest && bypasswmi) { + /* Don't run BMIDone for ART mode and force resetok=0 */ + resetok = 0; + msleep(1000); + param = 1; + status = BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data_initialized), + (A_UCHAR *)¶m, 4); + } +#endif /* HTC_RAW_INTERFACE */ + +#ifdef CONFIG_HOST_TCMD_SUPPORT + if (testmode == 2) { + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + filename = AR6003_REV2_UTF_FIRMWARE_FILE; + if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); + return A_ENOENT; + } + /* Download Target firmware */ + AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); + + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz); + param = 11008; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = 0x57D884; + filename = AR6003_REV2_TESTSCRIPT_FILE; + if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); + return A_ENOENT; + } + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); + + param = 0x57D884; + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ota_testscript); + bmifn(BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)¶m, 4)); + + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_test_apps_related); + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + param |= 1; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + A_RELEASE_FIRMWARE(fw_entry); + } + else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { + filename = AR6003_REV3_UTF_FIRMWARE_FILE; + if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); + return A_ENOENT; + } + /* Download Target firmware */ + address = BMI_SEGMENTED_WRITE_ADDR; + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); + + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz); + param = 4096; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + address = 0x57EF74; + filename = AR6003_REV3_TESTSCRIPT_FILE; + if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); + return A_ENOENT; + } + status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); + + param = 0x57EF74; + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ota_testscript); + bmifn(BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)¶m, 4)); + + address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_test_apps_related); + bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); + param |= 1; + bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); + + A_RELEASE_FIRMWARE(fw_entry); + } + } +#endif +#endif /* INIT_MODE_DRV_ENABLED */ + } + + return A_OK; +} + +A_STATUS +ar6000_configure_target(AR_SOFTC_T *ar) +{ + A_UINT32 param; + if (enableuartprint) { + param = 1; + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_serial_enable), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n")); + } + + /* Tell target which HTC version it is used*/ + param = HTC_PROTOCOL_VERSION; + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_app_host_interest), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n")); + return A_ERROR; + } + + if (enabletimerwar) { + A_UINT32 param; + + if (BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n")); + return A_ERROR; + } + + param |= HI_OPTION_TIMER_WAR; + + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n")); + } + + /* set the firmware mode to STA/IBSS/AP */ + { + A_UINT32 param; + + if (BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n")); + return A_ERROR; + } + + param |= (num_device << HI_OPTION_NUM_DEV_SHIFT); + param |= (fwmode << HI_OPTION_FW_MODE_SHIFT); + param |= (mac_addr_method << HI_OPTION_MAC_ADDR_METHOD_SHIFT); + param |= (firmware_bridge << HI_OPTION_FW_BRIDGE_SHIFT); + param |= (fwsubmode << HI_OPTION_FW_SUBMODE_SHIFT); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("NUM_DEV=%d FWMODE=0x%x FWSUBMODE=0x%x FWBR_BUF %d\n", + num_device, fwmode, fwsubmode, firmware_bridge)); + + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); + } +#ifdef ATH6KL_DISABLE_TARGET_DBGLOGS + { + A_UINT32 param; + + if (BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n")); + return A_ERROR; + } + + param |= HI_OPTION_DISABLE_DBGLOG; + + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); + } +#endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */ + + if (regscanmode) { + A_UINT32 param; + + if (BMIReadMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4)!= A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting regscanmode failed\n")); + return A_ERROR; + } + + if (regscanmode == 1) { + param |= HI_OPTION_SKIP_REG_SCAN; + } else if (regscanmode == 2) { + param |= HI_OPTION_INIT_REG_SCAN; + } + + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), + (A_UCHAR *)¶m, + 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting regscanmode failed\n")); + return A_ERROR; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Regulatory scan mode set\n")); + } + + /* + * Hardcode the address use for the extended board data + * Ideally this should be pre-allocate by the OS at boot time + * But since it is a new feature and board data is loaded + * at init time, we have to workaround this from host. + * It is difficult to patch the firmware boot code, + * but possible in theory. + */ + if (ar->arTargetType == TARGET_TYPE_AR6003) { + A_UINT32 ramReservedSz; + if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { + param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS; + ramReservedSz = AR6003_REV2_RAM_RESERVE_SIZE; + } else { + param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS; + ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE; + } + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data), + (A_UCHAR *)¶m, + 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n")); + return A_ERROR; + } + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz), + (A_UCHAR *)&ramReservedSz, 4) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_end_RAM_reserve_sz failed \n")); + return A_ERROR; + } + } + + + /* since BMIInit is called in the driver layer, we have to set the block + * size here for the target */ + + if (A_FAILED(ar6000_set_htc_params(ar->arHifDevice, + ar->arTargetType, + mbox_yield_limit, + 0 /* use default number of control buffers */ + ))) { + return A_ERROR; + } + + if (setupbtdev != 0) { + if (A_FAILED(ar6000_set_hci_bridge_flags(ar->arHifDevice, + ar->arTargetType, + setupbtdev))) { + return A_ERROR; + } + } + + return A_OK; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) +static void ar6000_ethtool_get_drvinfo(struct net_device *dev, + struct ethtool_drvinfo *info) +{ + A_STATUS status; + HIF_DEVICE_OS_DEVICE_INFO osDevInfo; + AR_SOFTC_T *ar; + AR_SOFTC_DEV_T *arPriv; + struct ar6000_version *revinfo; + if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { + return; + } + ar = arPriv->arSoftc; + revinfo = &ar->arVersion; + strcpy(info->driver, "AR6000"); + snprintf(info->version, sizeof(info->version), "%u.%u.%u.%u", + ((revinfo->host_ver)&0xf0000000)>>28, + ((revinfo->host_ver)&0x0f000000)>>24, + ((revinfo->host_ver)&0x00ff0000)>>16, + ((revinfo->host_ver)&0x0000ffff)); + snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u.%u", + ((revinfo->wlan_ver)&0xf0000000)>>28, + ((revinfo->wlan_ver)&0x0f000000)>>24, + ((revinfo->wlan_ver)&0x00ff0000)>>16, + ((revinfo->wlan_ver)&0x0000ffff)); + + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_GET_OS_DEVICE, + &osDevInfo, + sizeof(HIF_DEVICE_OS_DEVICE_INFO)); + if (A_SUCCESS(status) && osDevInfo.pOSDevice) { + struct device *dev = (struct device*)osDevInfo.pOSDevice; + if (dev->bus && dev->bus->name) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) + const char *dinfo = dev_name(dev); +#else + const char *dinfo = kobject_name(&dev->kobj); +#endif + snprintf(info->bus_info, sizeof(info->bus_info), dinfo); + } + } +} + +static u32 ar6000_ethtool_get_link(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv; + return ((arPriv = ar6k_priv(dev))!=NULL) ? arPriv->arConnected : 0; +} + +#ifdef CONFIG_CHECKSUM_OFFLOAD +static u32 ar6000_ethtool_get_rx_csum(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv; + if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { + return 0; + } + return (arPriv->arSoftc->rxMetaVersion==WMI_META_VERSION_2); +} + +static int ar6000_ethtool_set_rx_csum(struct net_device *dev, u32 enable) +{ + AR_SOFTC_T *ar; + AR_SOFTC_DEV_T *arPriv; + A_UINT8 metaVersion; + if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { + return -EIO; + } + ar = arPriv->arSoftc; + if (ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + metaVersion = (enable) ? WMI_META_VERSION_2 : 0; + if ((wmi_set_rx_frame_format_cmd(arPriv->arWmi, metaVersion, processDot11Hdr, processDot11Hdr)) != A_OK) { + return -EFAULT; + } + ar->rxMetaVersion = metaVersion; + return 0; +} + +static u32 ar6000_ethtool_get_tx_csum(struct net_device *dev) +{ + return csumOffload; +} + +static int ar6000_ethtool_set_tx_csum(struct net_device *dev, u32 enable) +{ + csumOffload = enable; + if(enable){ + dev->features |= NETIF_F_IP_CSUM; + } else { + dev->features &= ~NETIF_F_IP_CSUM; + } + return 0; +} +#endif /* CONFIG_CHECKSUM_OFFLOAD */ + +static const struct ethtool_ops ar6000_ethtool_ops = { + .get_drvinfo = ar6000_ethtool_get_drvinfo, + .get_link = ar6000_ethtool_get_link, +#ifdef CONFIG_CHECKSUM_OFFLOAD + .get_rx_csum = ar6000_ethtool_get_rx_csum, + .set_rx_csum = ar6000_ethtool_set_rx_csum, + .get_tx_csum = ar6000_ethtool_get_tx_csum, + .set_tx_csum = ar6000_ethtool_set_tx_csum, +#endif /* CONFIG_CHECKSUM_OFFLOAD */ +}; +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */ + +/* + * HTC Event handlers + */ +static A_STATUS +ar6000_avail_ev(void *context, void *hif_handle) +{ + int i; + struct net_device *dev; + void *ar_netif; + AR_SOFTC_T *ar=NULL; + AR_SOFTC_DEV_T *arPriv; + int device_index = 0; + HTC_INIT_INFO htcInfo; +#ifdef ATH6K_CONFIG_CFG80211 + struct wireless_dev *wdev; +#endif /* ATH6K_CONFIG_CFG80211 */ + A_STATUS init_status = A_OK; + unsigned char devnum = 0; + unsigned char cnt = 0; + + /* + * If ar6000_avail_ev is called more than once, this means that + * multiple AR600x devices have been inserted into the system. + * We do not support more than one AR600x device at this time. + */ +#ifndef RK29 + if (avail_ev_called) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ERROR: More than one AR600x device not supported by driver\n")); + return A_ERROR; + } + + avail_ev_called = TRUE; +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n")); + + + + ar = A_MALLOC(sizeof(AR_SOFTC_T)); + + if (ar == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR_SOFTC: can not allocate\n")); + return A_ERROR; + } + A_MEMZERO(ar, sizeof(AR_SOFTC_T)); + +#ifdef ATH_AR6K_11N_SUPPORT + if(aggr_init(ar6000_alloc_netbufs, ar6000_deliver_frames_to_nw_stack) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__)); + init_status = A_ERROR; + goto avail_ev_failed; + } +#endif + + A_MEMZERO((A_UINT8 *)ar->connTbl, NUM_CONN * sizeof(conn_t)); + /* Init the PS queues */ + for (i=0; i < NUM_CONN ; i++) { +#ifdef ATH_AR6K_11N_SUPPORT + if((ar->connTbl[i].conn_aggr = aggr_init_conn()) == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s() Failed to initialize aggr.\n", __func__)); + A_FREE(ar); + return A_ERROR; + } +#endif + A_MUTEX_INIT(&ar->connTbl[i].psqLock); + A_NETBUF_QUEUE_INIT(&ar->connTbl[i].psq); + A_NETBUF_QUEUE_INIT(&ar->connTbl[i].apsdq); + } + +#if 0//LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + if(ifname[0]) { + for(i = 0; i < strlen(ifname); i++) { + if(ifname[i] >= '0' && ifname[i] <= '9' ) { + devnum = (devnum * 10) + (ifname[i] - '0'); + } + else { + cnt++; + } + } + ifname[cnt]='\0'; + } +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ + ar->arConfNumDev = num_device; + for (i=0; i < num_device; i++) { + + if (ar6000_devices[i] != NULL) { + break; + } + + /* Save this. It gives a bit better readability especially since */ + /* we use another local "i" variable below. */ + device_index = i; +#ifdef ATH6K_CONFIG_CFG80211 + wdev = ar6k_cfg80211_init(NULL); + if (IS_ERR(wdev)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__)); + return A_ERROR; + } + ar_netif = wdev_priv(wdev); +#else + dev = alloc_etherdev(sizeof(AR_SOFTC_DEV_T)); + if (dev == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n")); + A_FREE(ar); + return A_ERROR; + } + ether_setup(dev); + ar_netif = ar6k_priv(dev); +#endif /* ATH6K_CONFIG_CFG80211 */ + + if (ar_netif == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__)); + A_FREE(ar); + return A_ERROR; + } + + A_MEMZERO(ar_netif, sizeof(AR_SOFTC_DEV_T)); + arPriv = (AR_SOFTC_DEV_T *)ar_netif; + +#ifdef ATH6K_CONFIG_CFG80211 + arPriv->wdev = wdev; + wdev->iftype = NL80211_IFTYPE_STATION; + + dev = alloc_netdev_mq(0, "wlan%d", ether_setup, NUM_SUBQUEUE); + if (!dev) { + printk(KERN_CRIT "AR6K: no memory for network device instance\n"); + ar6k_cfg80211_deinit(arPriv); + A_FREE(ar); + return A_ERROR; + } + + dev->ieee80211_ptr = wdev; + SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy)); + wdev->netdev = dev; + arPriv->arNetworkType = INFRA_NETWORK; +#endif /* ATH6K_CONFIG_CFG80211 */ + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + if (ifname[0]) + { + //sprintf(dev->name, "%s%d", ifname,(devnum + device_index)); + sprintf(dev->name, "%s", ifname); + } +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ + +#ifdef SET_MODULE_OWNER + SET_MODULE_OWNER(dev); +#endif + +#ifdef SET_NETDEV_DEV +#if 0 + if (ar_netif) { + HIF_DEVICE_OS_DEVICE_INFO osDevInfo; + A_MEMZERO(&osDevInfo, sizeof(osDevInfo)); + if ( A_SUCCESS( HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE, + &osDevInfo, sizeof(osDevInfo))) ) { + SET_NETDEV_DEV(dev, osDevInfo.pOSDevice); + } + } +#endif +#endif + + arPriv->arNetDev = dev; + ar6000_devices[device_index] = dev; + arPriv->arSoftc = ar; + ar->arDev[device_index] = arPriv; + ar->arWlanState = WLAN_ENABLED; + arPriv->arDeviceIndex = device_index; + + ar->arWlanPowerState = WLAN_POWER_STATE_ON; + + if(ar6000_init_control_info(arPriv) != A_OK) { + init_status = A_ERROR; + goto avail_ev_failed; + } + init_waitqueue_head(&arPriv->arEvent); + +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + A_INIT_TIMER(&aptcTimer[i], aptcTimerHandler, ar); +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + + spin_lock_init(&arPriv->arPrivLock); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) + dev->open = &ar6000_open; + dev->stop = &ar6000_close; + dev->hard_start_xmit = &ar6000_data_tx; + dev->get_stats = &ar6000_get_stats; + + /* dev->tx_timeout = ar6000_tx_timeout; */ + dev->do_ioctl = &ar6000_ioctl; + dev->set_multicast_list = &ar6000_set_multicast_list; +#else + dev->netdev_ops = &ar6000_netdev_ops; +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) + dev->ethtool_ops = &ar6000_ethtool_ops; +#endif + dev->watchdog_timeo = AR6000_TX_TIMEOUT; + dev->wireless_handlers = &ath_iw_handler_def; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) + dev->get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ +#else + ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ +#endif +#ifdef CONFIG_CHECKSUM_OFFLOAD + if(csumOffload){ + + dev->features |= NETIF_F_IP_CSUM;/*advertise kernel capability + to do TCP/UDP CSUM offload for IPV4*/ + } +#endif + if (processDot11Hdr) { + dev->hard_header_len = sizeof(struct ieee80211_qosframe) + sizeof(ATH_LLC_SNAP_HDR) + sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR; + } else { + /* + * We need the OS to provide us with more headroom in order to + * perform dix to 802.3, WMI header encap, and the HTC header + */ + dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) + + sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR; + } + + if (!bypasswmi) + { + /* Indicate that WMI is enabled (although not ready yet) */ + arPriv->arWmiEnabled = TRUE; + if ((arPriv->arWmi = wmi_init((void *) arPriv,arPriv->arDeviceIndex)) == NULL) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__)); + init_status = A_ERROR; + goto avail_ev_failed; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s() Got WMI @ 0x%08x.\n", __func__, + (unsigned int) arPriv->arWmi)); + } +#ifdef P2P + /* Allocate P2P module context if this dev is in any of the P2P modes. + * For non-P2P devices, this may be allocated just in time when the + * device assumes a P2P submode. This may be needed when we do + * mode switch between none and P2P submodes. For later enhancement. + */ + if (arPriv->arNetworkSubType == SUBTYPE_P2PDEV || + arPriv->arNetworkSubType == SUBTYPE_P2PCLIENT || + arPriv->arNetworkSubType == SUBTYPE_P2PGO) { + arPriv->p2p_ctx = p2p_init(arPriv); + } +#endif /* P2P */ + } + +#ifdef CONFIG_HOST_TCMD_SUPPORT + if(testmode) { + ar->arTargetMode = AR6000_TCMD_MODE; + }else { + ar->arTargetMode = AR6000_WLAN_MODE; + } +#endif + ar->arWlanOff = FALSE; /* We are in ON state */ +#ifdef CONFIG_PM + ar->arWowState = WLAN_WOW_STATE_NONE; + ar->arBTOff = TRUE; /* BT chip assumed to be OFF */ + ar->arBTSharing = WLAN_CONFIG_BT_SHARING; + ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF; + ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND; + ar->arWow2Config = WLAN_CONFIG_PM_WOW2; +#endif /* CONFIG_PM */ + + A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, ar); + ar->arHBChallengeResp.seqNum = 0; + ar->arHBChallengeResp.outstanding = FALSE; + ar->arHBChallengeResp.missCnt = 0; + ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT; + ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT; + ar->arHifDevice = hif_handle; + sema_init(&ar->arSem, 1); + ar->bIsDestroyProgress = FALSE; + + INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue); + /* + * If requested, perform some magic which requires no cooperation from + * the Target. It causes the Target to ignore flash and execute to the + * OS from ROM. + * + * This is intended to support recovery from a corrupted flash on Targets + * that support flash. + */ + if (skipflash) + { + //ar6000_reset_device_skipflash(ar->arHifDevice); + } + + BMIInit(); + + if (bmienable) { + ar6000_sysfs_bmi_init(ar); + } + + { + struct bmi_target_info targ_info; + A_MEMZERO(&targ_info, sizeof(targ_info)); + if (BMIGetTargetInfo(ar->arHifDevice, &targ_info) != A_OK) { + init_status = A_ERROR; + goto avail_ev_failed; + } + + ar->arVersion.target_ver = targ_info.target_ver; + ar->arTargetType = targ_info.target_type; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s() TARGET TYPE: %d\n", __func__,ar->arTargetType)); + target_register_tbl_attach(ar->arTargetType); + + /* do any target-specific preparation that can be done through BMI */ + if (ar6000_prepare_target(ar->arHifDevice, + targ_info.target_type, + targ_info.target_ver) != A_OK) { + init_status = A_ERROR; + goto avail_ev_failed; + } + + } + if (ar6000_configure_target(ar) != A_OK) { + init_status = A_ERROR; + goto avail_ev_failed; + } + + A_MEMZERO(&htcInfo,sizeof(htcInfo)); + htcInfo.pContext = ar; + htcInfo.TargetFailure = ar6000_target_failure; + + ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo); + + if (ar->arHtcTarget == NULL) { + init_status = A_ERROR; + goto avail_ev_failed; + } + + spin_lock_init(&ar->arLock); + +#ifdef CONFIG_CHECKSUM_OFFLOAD + if(csumOffload){ + + ar->rxMetaVersion=WMI_META_VERSION_2;/*if external frame work is also needed, change and use an extended rxMetaVerion*/ + } +#endif + + HIFClaimDevice(ar->arHifDevice, ar); + + if (bmienable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); + if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || + (wlaninitmode == WLAN_INIT_MODE_DRV)) + { + A_STATUS status = A_OK; + do { + if ((status = ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); + break; + } + }while (FALSE); + } + } + + if(bmienable) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); + if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || + (wlaninitmode == WLAN_INIT_MODE_DRV)) + { + A_STATUS status = A_OK; + dev = ar6000_devices[0]; + do { +#ifdef HTC_RAW_INTERFACE + if (!eppingtest && bypasswmi) { + break; /* Don't call ar6000_init for ART */ + } +#endif + rtnl_lock(); + status = (ar6000_init(dev)==0) ? A_OK : A_ERROR; + rtnl_unlock(); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n")); + } + } while (FALSE); + + if (status != A_OK) { + init_status = status; + goto avail_ev_failed; + } + } + } + + for (i=0; i < num_device; i++) + { + dev = ar6000_devices[i]; + arPriv = ar6k_priv(dev); + ar = arPriv->arSoftc; + /* Don't install the init function if BMI is requested */ + if (!bmienable) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) + dev->init = ar6000_init; +#else + ar6000_netdev_ops.ndo_init = ar6000_init; +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ + } + + /* This runs the init function if registered */ + if (register_netdev(dev)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n")); + ar6000_cleanup(ar); + ar6000_devices[i]=NULL; + ar6000_destroy(dev, 0); + return A_ERROR; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n", + dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index, + (unsigned long)ar)); + + } + +avail_ev_failed : + if (A_FAILED(init_status)) { + if (bmienable) { + ar6000_sysfs_bmi_deinit(ar); + } + for (i=0; i < num_device; i++) + { + dev = ar6000_devices[i]; + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + if(arPriv->arWmiEnabled == TRUE) + { + wmi_shutdown(arPriv->arWmi); + arPriv->arWmiEnabled = FALSE; + } + ar6000_devices[i] = NULL; + } + A_FREE(ar); + } + + return init_status; +} + +static void ar6000_target_failure(void *Instance, A_STATUS Status) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Instance; + WMI_TARGET_ERROR_REPORT_EVENT errEvent; + static A_BOOL sip = FALSE; + A_UINT8 i; + + if (Status != A_OK) { + + printk(KERN_ERR "ar6000_target_failure: target asserted \n"); + + if (timer_pending(&ar->arHBChallengeResp.timer)) { + A_UNTIMEOUT(&ar->arHBChallengeResp.timer); + } + + /* try dumping target assertion information (if any) */ + ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType); + + /* + * Fetch the logs from the target via the diagnostic + * window. + */ + ar6000_dbglog_get_debug_logs(ar); + + /* Report the error only once */ + if (!sip) { + sip = TRUE; + errEvent.errorVal = WMI_TARGET_COM_ERR | + WMI_TARGET_FATAL_ERR; + for(i = 0; i < num_device; i++) + { + + ar6000_send_event_to_app(ar->arDev[i], WMI_ERROR_REPORT_EVENTID, + (A_UINT8 *)&errEvent, + sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); + + } + } + } +} + +static A_STATUS +ar6000_unavail_ev(void *context, void *hif_handle) +{ + unsigned int old_reset_ok = resetok; + A_UINT8 i; + struct net_device *ar6000_netdev; + AR_SOFTC_T *ar = (AR_SOFTC_T*)context; + resetok = 0; /* card is remove, don't reset */ + ar6000_cleanup(ar); + resetok = old_reset_ok; + /* NULL out it's entry in the global list */ + for(i = 0; i < num_device; i++) { + ar6000_netdev = ar6000_devices[i]; + ar6000_devices[i] = NULL; + ar6000_destroy(ar6000_netdev, 1); + } + + return A_OK; +} + + +void +ar6000_restart_endpoint(AR_SOFTC_T *ar) +{ + + A_STATUS status = A_OK; + AR_SOFTC_DEV_T *arPriv; + struct net_device *dev; + A_UINT8 i = 0; + + /* + * Call wmi_init for each device. This must be done BEFORE ar6000_init() is + * called, or we will get a null pointer exception in the wmi code. We must + * also set the arWmiEnabled flag for each device. + */ + for(i = 0; i < num_device; i++) { + arPriv = ar->arDev[i]; + arPriv->arWmiEnabled = TRUE; + if ((arPriv->arWmi = wmi_init((void *) arPriv,arPriv->arDeviceIndex)) == NULL) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__)); + status = A_ERROR; + goto exit; + } + } + + + BMIInit(); + if (bmienable) { + ar6000_sysfs_bmi_init(ar); + } + do { + if ( (status=ar6000_configure_target(ar))!=A_OK) + break; + if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); + break; + } + } while(0); + + dev = ar6000_devices[0]; + rtnl_lock(); + status = (ar6000_init(dev)==0) ? A_OK : A_ERROR; + rtnl_unlock(); + + if (status!=A_OK) { + goto exit; + } + + + for(i = 0; i < num_device; i++) { + arPriv = ar->arDev[i]; + if (arPriv->arDoConnectOnResume && + arPriv->arSsidLen && + ar->arWlanState == WLAN_ENABLED) + { + ar6000_connect_to_ap(arPriv); + } + } + + if (status==A_OK) { + return; + } + +exit: + for(i = 0; i < num_device; i++) { + arPriv = ar->arDev[i]; + ar6000_devices[i] = NULL; + ar6000_destroy(arPriv->arNetDev, 1); + } + +} + +void +ar6000_stop_endpoint(AR_SOFTC_T *ar, A_BOOL keepprofile, A_BOOL getdbglogs) +{ + + AR_SOFTC_DEV_T *arPriv ; + A_UINT8 i; + A_UINT8 ctr; + AR_SOFTC_STA_T *arSta; + + for(i = 0; i < num_device; i++) + { + arPriv = ar->arDev[i]; + arSta = &arPriv->arSta; + /* Stop the transmit queues */ + netif_stop_queue(arPriv->arNetDev); + + /* Disable the target and the interrupts associated with it */ + if (ar->arWmiReady == TRUE) + { + if (!bypasswmi) { + A_BOOL disconnectIssued; + + arPriv->arDoConnectOnResume = arPriv->arConnected; + + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + A_UNTIMEOUT(&ar->ap_reconnect_timer); + A_UNTIMEOUT(&arPriv->ap_acs_timer); +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + /* Delete the Adaptive Power Control timer */ + if (timer_pending(&aptcTimer[i])) { + del_timer_sync(&aptcTimer[i]); + } +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ +#ifdef ATH_AR6K_11N_SUPPORT + for (ctr=0; ctr < NUM_CONN ; ctr++) { + aggr_module_destroy_timers(ar->connTbl[ctr].conn_aggr); + } +#endif + + disconnectIssued = (arPriv->arConnected) || (arPriv->arSta.arConnectPending); + ar6000_disconnect(arPriv); + if (!keepprofile) { + ar6000_init_profile_info(arPriv); + } + if (getdbglogs) { + ar6000_dbglog_get_debug_logs(ar); + } + ar->arWmiReady = FALSE; + arPriv->arWmiEnabled = FALSE; + wmi_shutdown(arPriv->arWmi); + arPriv->arWmi = NULL; + /* + * After wmi_shudown all WMI events will be dropped. + * We need to cleanup the buffers allocated in AP mode + * and give disconnect notification to stack, which usually + * happens in the disconnect_event. + * Simulate the disconnect_event by calling the function directly. + * Sometimes disconnect_event will be received when the debug logs + * are collected. + */ + if (disconnectIssued) { + if(arPriv->arNetworkType & AP_NETWORK) { + ar6000_disconnect_event(arPriv, DISCONNECT_CMD, bcast_mac, 0, NULL, 0); + } else { + ar6000_disconnect_event(arPriv, DISCONNECT_CMD, arPriv->arBssid, 0, NULL, 0); + } + } +#ifdef USER_KEYS + arPriv->arSta.user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; + arPriv->arSta.user_key_ctrl = 0; +#endif + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__)); + } + else + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n", + __func__, (unsigned long) ar, (unsigned long) arPriv->arWmi)); + /* Shut down WMI if we have started it */ + if(arPriv->arWmiEnabled == TRUE) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__)); + arPriv->arWmiEnabled = FALSE; + wmi_shutdown(arPriv->arWmi); + arPriv->arWmi = NULL; + } + } + /* cleanup hci pal driver data structures */ + if (setuphcipal && (arPriv->isBt30amp == TRUE)) { + ar6k_cleanup_hci_pal(arPriv); + } + } + + if (ar->arHtcTarget != NULL) { +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + if (NULL != ar6kHciTransCallbacks.cleanupTransport) { + ar6kHciTransCallbacks.cleanupTransport(NULL); + } +#else + // FIXME: workaround to reset BT's UART baud rate to default + if (NULL != ar->exitCallback) { + AR3K_CONFIG_INFO ar3kconfig; + A_STATUS status; + + A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig)); + ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig); + status = ar->exitCallback(&ar3kconfig); + if (A_OK != status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n")); + } + } + // END workaround + if (setuphci) + ar6000_cleanup_hci(ar); +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n")); + /* stop HTC */ + HTCStop(ar->arHtcTarget); + ar6k_init = FALSE; + } + + if (resetok) { + /* try to reset the device if we can + * The driver may have been configure NOT to reset the target during + * a debug session */ + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,(" Attempting to reset target on instance destroy.... \n")); + if (ar->arHifDevice != NULL) { +#if defined(CONFIG_MMC_MSM) || defined(CONFIG_MMC_SDHCI_S3C) + A_BOOL coldReset = ((ar->arTargetType == TARGET_TYPE_AR6003)|| (ar->arTargetType == TARGET_TYPE_MCKINLEY)) ? TRUE: FALSE; +#else + A_BOOL coldReset = (ar->arTargetType == TARGET_TYPE_MCKINLEY) ? TRUE: FALSE; +#endif + ar6000_reset_device(ar->arHifDevice, ar->arTargetType, TRUE, coldReset); + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n")); + } + /* Done with cookies */ + ar6000_cookie_cleanup(ar); + + /* cleanup any allocated AMSDU buffers */ + ar6000_cleanup_amsdu_rxbufs(ar); + + if (bmienable) { + ar6000_sysfs_bmi_deinit(ar); + } +} + +void ar6000_cleanup(AR_SOFTC_T *ar) +{ + A_UINT8 ctr; + ar->bIsDestroyProgress = TRUE; + + if (down_interruptible(&ar->arSem)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__)); + return; + } + + if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) { + /* only stop endpoint if we are not stop it in suspend_ev */ + ar6000_stop_endpoint(ar, FALSE, TRUE); + } else { + /* clear up the platform power state before rmmod */ + plat_setup_power(ar, 1, 0); + ar->arPlatPowerOff = FALSE; + } + +#ifdef ATH_AR6K_11N_SUPPORT + for (ctr=0; ctr < NUM_CONN ; ctr++) { + aggr_module_destroy_conn(ar->connTbl[ctr].conn_aggr); + } + aggr_module_destroy(); +#endif + + ar->arWlanState = WLAN_DISABLED; + if (ar->arHtcTarget != NULL) { + /* destroy HTC */ + HTCDestroy(ar->arHtcTarget); + } + if (ar->arHifDevice != NULL) { + /*release the device so we do not get called back on remove incase we + * we're explicity destroyed by module unload */ + HIFReleaseDevice(ar->arHifDevice); + HIFShutDownDevice(ar->arHifDevice); + } + /* Done with cookies */ + ar6000_cookie_cleanup(ar); + + /* cleanup any allocated AMSDU buffers */ + ar6000_cleanup_amsdu_rxbufs(ar); + + if (bmienable) { + ar6000_sysfs_bmi_deinit(ar); + } + + /* Cleanup BMI */ + BMICleanup(); + + /* Clear the tx counters */ + memset(tx_attempt, 0, sizeof(tx_attempt)); + memset(tx_post, 0, sizeof(tx_post)); + memset(tx_complete, 0, sizeof(tx_complete)); + +#ifdef HTC_RAW_INTERFACE + if (ar->arRawHtc) { + A_FREE(ar->arRawHtc); + ar->arRawHtc = NULL; + } +#endif + A_UNTIMEOUT(&ar->ap_reconnect_timer); + A_UNTIMEOUT(&ar->arHBChallengeResp.timer); + A_FREE(ar); + +} +/* + * We need to differentiate between the surprise and planned removal of the + * device because of the following consideration: + * - In case of surprise removal, the hcd already frees up the pending + * for the device and hence there is no need to unregister the function + * driver inorder to get these requests. For planned removal, the function + * driver has to explictly unregister itself to have the hcd return all the + * pending requests before the data structures for the devices are freed up. + * Note that as per the current implementation, the function driver will + * end up releasing all the devices since there is no API to selectively + * release a particular device. + * - Certain commands issued to the target can be skipped for surprise + * removal since they will anyway not go through. + */ +void +ar6000_destroy(struct net_device *dev, unsigned int unregister) +{ + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_AP_T *arAp; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n")); + + if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__)); + return; + } + + A_UNTIMEOUT(&arPriv->ap_acs_timer); + aggr_module_destroy_conn(arPriv->conn_aggr); + + if(arPriv->arNetworkType == AP_NETWORK) + { + arAp = &arPriv->arAp; + +#ifdef ATH_SUPPORT_DFS + dfs_detach_host(arAp->pDfs); +#endif + } + ar6k_init = FALSE; + /* Free up the device data structure */ + if (unregister) { + unregister_netdev(dev); + } +#define free_netdev_support +#ifndef free_netdev_support + kfree(dev); +#else + free_netdev(dev); +#endif + +#ifdef ATH6K_CONFIG_CFG80211 + ar6k_cfg80211_deinit(arPriv); +#endif /* ATH6K_CONFIG_CFG80211 */ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n")); +} + +static void ap_reconnect_timer_handler(unsigned long ptr) +{ + AR_SOFTC_T *ar= (AR_SOFTC_T *)ptr; + AR_SOFTC_DEV_T *arTempPriv = NULL; + A_UINT8 i=0; + A_UNTIMEOUT(&ar->ap_reconnect_timer); + + if(ar->arHoldConnection){ + ar->arHoldConnection = FALSE; + for(i=0;iarConfNumDev;i++){ + arTempPriv = ar->arDev[i]; + if((AP_NETWORK == arTempPriv->arNetworkType) && + (arTempPriv->arHoldConnection)){ + arTempPriv->arHoldConnection = FALSE; + ar6000_ap_mode_profile_commit(arTempPriv); + } + } + } +} +static void disconnect_timer_handler(unsigned long ptr) +{ + struct net_device *dev = (struct net_device *)ptr; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + + ar6000_init_profile_info(arPriv); + ar6000_disconnect(arPriv); +} + +static void ar6000_detect_error(unsigned long ptr) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)ptr; + A_UINT8 i; + WMI_TARGET_ERROR_REPORT_EVENT errEvent; + + AR6000_SPIN_LOCK(&ar->arLock, 0); + + if (ar->arHBChallengeResp.outstanding) { + ar->arHBChallengeResp.missCnt++; + } else { + ar->arHBChallengeResp.missCnt = 0; + } + + if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) { + /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */ + ar->arHBChallengeResp.missCnt = 0; + ar->arHBChallengeResp.seqNum = 0; + errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + for(i = 0; i < num_device; i++) + { + ar6000_send_event_to_app(ar->arDev[i], WMI_ERROR_REPORT_EVENTID, + (A_UINT8 *)&errEvent, + sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); + } + return; + } + + /* Generate the sequence number for the next challenge */ + ar->arHBChallengeResp.seqNum++; + ar->arHBChallengeResp.outstanding = TRUE; + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + /* Send the challenge on the control channel */ + if (wmi_get_challenge_resp_cmd(ar->arDev[0]->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n")); + } + + + /* Reschedule the timer for the next challenge */ + A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0); +} + +void ar6000_init_profile_info(AR_SOFTC_DEV_T *arPriv) +{ + A_UINT8 mode = 0; + A_UINT8 submode = 0; + mode = ((fwmode >> (arPriv->arDeviceIndex * HI_OPTION_FW_MODE_BITS)) & (HI_OPTION_FW_MODE_MASK )); + + switch(mode) { + case HI_OPTION_FW_MODE_IBSS: + arPriv->arNetworkType = arPriv->arNextMode = ADHOC_NETWORK; + break; + case HI_OPTION_FW_MODE_BSS_STA: + arPriv->arNetworkType = arPriv->arNextMode = INFRA_NETWORK; + break; + case HI_OPTION_FW_MODE_AP: + arPriv->arNetworkType = arPriv->arNextMode = AP_NETWORK; + break; + case HI_OPTION_FW_MODE_BT30AMP: + arPriv->arNetworkType = arPriv->arNextMode = INFRA_NETWORK; + arPriv->isBt30amp = TRUE; + break; + } + /* Initialize firware sub mode + */ + submode = ((fwsubmode>>(arPriv->arDeviceIndex * HI_OPTION_FW_SUBMODE_BITS)) + & (HI_OPTION_FW_SUBMODE_MASK)); + + switch(submode) { + case HI_OPTION_FW_SUBMODE_NONE: + arPriv->arNetworkSubType = SUBTYPE_NONE; + break; + case HI_OPTION_FW_SUBMODE_P2PDEV: + arPriv->arNetworkSubType = SUBTYPE_P2PDEV; + break; + case HI_OPTION_FW_SUBMODE_P2PCLIENT: + arPriv->arNetworkSubType = SUBTYPE_P2PCLIENT; + break; + case HI_OPTION_FW_SUBMODE_P2PGO: + arPriv->arNetworkSubType = SUBTYPE_P2PGO; + break; + } + + ar6000_init_mode_info(arPriv); +} + +static int +ar6000_init_control_info(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + + arPriv->arWmiEnabled = FALSE; + ar->arVersion.host_ver = AR6K_SW_VERSION; + + if(!(strcmp(targetconf,"mobile"))) + ar->arVersion.targetconf_ver = AR6003_SUBVER_MOBILE; + else if(!(strcmp(targetconf,"tablet"))) + ar->arVersion.targetconf_ver = AR6003_SUBVER_TABLET; + else if(!(strcmp(targetconf,"router"))) + ar->arVersion.targetconf_ver = AR6003_SUBVER_ROUTER; + else if(!(strcmp(targetconf,"default"))) + ar->arVersion.targetconf_ver = AR6003_SUBVER_DEFAULT; + else + ar->arVersion.targetconf_ver = AR6003_SUBVER_MOBILE; + + + ar6000_init_profile_info(arPriv); + + if((arPriv->conn_aggr = aggr_init_conn()) == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s() Failed to initialize aggr.\n", __func__)); + return A_ERROR; + } + return A_OK; +} + +static int +ar6000_open(struct net_device *dev) +{ + unsigned long flags; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + spin_lock_irqsave(&arPriv->arPrivLock, flags); + +#ifdef ATH6K_CONFIG_CFG80211 + if(arPriv->arSoftc->arWlanState == WLAN_DISABLED) { + arPriv->arSoftc->arWlanState = WLAN_ENABLED; + } +#endif /* ATH6K_CONFIG_CFG80211 */ + + if( arPriv->arConnected || bypasswmi) { + netif_carrier_on(dev); + /* Wake up the queues */ + netif_wake_queue(dev); + } + else + netif_carrier_off(dev); + + spin_unlock_irqrestore(&arPriv->arPrivLock, flags); + return 0; +} + +static int +ar6000_close(struct net_device *dev) +{ +#ifdef ATH6K_CONFIG_CFG80211 + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); +#endif /* ATH6K_CONFIG_CFG80211 */ + netif_stop_queue(dev); + +#ifdef ATH6K_CONFIG_CFG80211 + ar6000_disconnect(arPriv); + + if(arPriv->arSoftc->arWmiReady == TRUE) { + if (wmi_scanparams_cmd(arPriv->arWmi, 0xFFFF, 0, + 0, 0, 0, 0, 0, 0, 0, 0) != A_OK) { + return -EIO; + } + arPriv->arSoftc->arWlanState = WLAN_DISABLED; + } +#endif /* ATH6K_CONFIG_CFG80211 */ + + return 0; +} + +/* connect to a service */ +static A_STATUS ar6000_connectservice(AR_SOFTC_DEV_T *arPriv, + HTC_SERVICE_CONNECT_REQ *pConnect, + char *pDesc) +{ + A_STATUS status; + HTC_SERVICE_CONNECT_RESP response; + AR_SOFTC_T *ar = arPriv->arSoftc; + + do { + + A_MEMZERO(&response,sizeof(response)); + + status = HTCConnectService(ar->arHtcTarget, + pConnect, + &response); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n", + pDesc, status)); + break; + } + switch (pConnect->ServiceID) { + case WMI_CONTROL_SVC : + if(!bypasswmi) + { + /* set control endpoint for WMI use */ + wmi_set_control_ep(arPriv->arWmi, response.Endpoint); + /* save EP for fast lookup */ + ar->arControlEp = response.Endpoint; + } + break; + case WMI_DATA_BE_SVC : + arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint); + break; + case WMI_DATA_BK_SVC : + arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint); + break; + case WMI_DATA_VI_SVC : + arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint); + break; + case WMI_DATA_VO_SVC : + arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint); + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID)); + status = A_EINVAL; + break; + } + + } while (FALSE); + + return status; +} + +void ar6000_TxDataCleanup(AR_SOFTC_T *ar) +{ + /* flush all the data (non-control) streams + * we only flush packets that are tagged as data, we leave any control packets that + * were in the TX queues alone */ + HTCFlushEndpoint(ar->arHtcTarget, + arAc2EndpointID(ar, WMM_AC_BE), + AR6K_DATA_PKT_TAG); + HTCFlushEndpoint(ar->arHtcTarget, + arAc2EndpointID(ar, WMM_AC_BK), + AR6K_DATA_PKT_TAG); + HTCFlushEndpoint(ar->arHtcTarget, + arAc2EndpointID(ar, WMM_AC_VI), + AR6K_DATA_PKT_TAG); + HTCFlushEndpoint(ar->arHtcTarget, + arAc2EndpointID(ar, WMM_AC_VO), + AR6K_DATA_PKT_TAG); +} + +HTC_ENDPOINT_ID +ar6000_ac2_endpoint_id ( void * devt, A_UINT8 ac) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *) devt; + AR_SOFTC_T *ar = arPriv->arSoftc; + return(arAc2EndpointID(ar, ac)); +} + +A_UINT8 +ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep ) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *) devt; + AR_SOFTC_T *ar = arPriv->arSoftc; + return(arEndpoint2Ac(ar, ep )); +} + + +/* This function does one time initialization for the lifetime of the device */ +int ar6000_init(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_T *ar; + int ret = 0; + int i = 0; + int j = 0; + A_STATUS status; + A_INT32 timeleft; +#if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd; + WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd; +#endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ + + dev_hold(dev); + rtnl_unlock(); + + if(ar6k_init) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6000 Initialised\n")); + goto ar6000_init_done; + } + + ar6k_init = TRUE; + if((arPriv = ar6k_priv(dev)) == NULL) + { + ret = -EIO; + goto ar6000_init_done; + } + + ar = arPriv->arSoftc; + + if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) { + + ar6000_update_bdaddr(ar); + } + + if (enablerssicompensation) { + ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType); + read_rssi_compensation_param(ar); + for(j=0; jarDev[j],i); + } + } + } + + /* Do we need to finish the BMI phase */ + + if ((wlaninitmode==WLAN_INIT_MODE_USR || wlaninitmode==WLAN_INIT_MODE_DRV) && + (BMIDone(ar->arHifDevice) != A_OK)) + { + ret = -EIO; + goto ar6000_init_done; + } + + do { + HTC_SERVICE_CONNECT_REQ connect; + + /* the reason we have to wait for the target here is that the driver layer + * has to init BMI in order to set the host block size, + */ + status = HTCWaitTarget(ar->arHtcTarget); + + if (A_FAILED(status)) { + break; + } + + A_MEMZERO(&connect,sizeof(connect)); + /* meta data is unused for now */ + connect.pMetaData = NULL; + connect.MetaDataLength = 0; + /* these fields are the same for all service endpoints */ + connect.EpCallbacks.pContext = ar; + connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete; + connect.EpCallbacks.EpRecv = ar6000_rx; + connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill; + connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full; + /* set the max queue depth so that our ar6000_tx_queue_full handler gets called. + * Linux has the peculiarity of not providing flow control between the + * NIC and the network stack. There is no API to indicate that a TX packet + * was sent which could provide some back pressure to the network stack. + * Under linux you would have to wait till the network stack consumed all sk_buffs + * before any back-flow kicked in. Which isn't very friendly. + * So we have to manage this ourselves */ + connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH; + connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */ + if (0 == connect.EpCallbacks.RecvRefillWaterMark) { + connect.EpCallbacks.RecvRefillWaterMark++; + } + /* connect to control service */ + connect.ServiceID = WMI_CONTROL_SVC; + status = ar6000_connectservice(arPriv, + &connect, + "WMI CONTROL"); + if (A_FAILED(status)) { + break; + } + + connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING; + /* limit the HTC message size on the send path, although we can receive A-MSDU frames of + * 4K, we will only send ethernet-sized (802.3) frames on the send path. */ + connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH; + + /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold + * mechanism for larger packets */ + connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE; + connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf; + + /* for the remaining data services set the connection flag to reduce dribbling, + * if configured to do so */ + if (reduce_credit_dribble) { + connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE; + /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value + * of 0-3 */ + connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK; + connect.ConnectionFlags |= + ((A_UINT16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK; + } + /* connect to best-effort service */ + connect.ServiceID = WMI_DATA_BE_SVC; + + status = ar6000_connectservice(arPriv, + &connect, + "WMI DATA BE"); + if (A_FAILED(status)) { + break; + } + + /* connect to back-ground + * map this to WMI LOW_PRI */ + connect.ServiceID = WMI_DATA_BK_SVC; + status = ar6000_connectservice(arPriv, + &connect, + "WMI DATA BK"); + if (A_FAILED(status)) { + break; + } + + /* connect to Video service, map this to + * to HI PRI */ + connect.ServiceID = WMI_DATA_VI_SVC; + status = ar6000_connectservice(arPriv, + &connect, + "WMI DATA VI"); + if (A_FAILED(status)) { + break; + } + + /* connect to VO service, this is currently not + * mapped to a WMI priority stream due to historical reasons. + * WMI originally defined 3 priorities over 3 mailboxes + * We can change this when WMI is reworked so that priorities are not + * dependent on mailboxes */ + connect.ServiceID = WMI_DATA_VO_SVC; + status = ar6000_connectservice(arPriv, + &connect, + "WMI DATA VO"); + if (A_FAILED(status)) { + break; + } + + A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0); + A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0); + A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0); + A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0); + + /* setup access class priority mappings */ + ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */ + ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */ + ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */ + ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */ + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) { + HCI_TRANSPORT_MISC_HANDLES hciHandles; + + hciHandles.netDevice = ar->arNetDev; + hciHandles.hifDevice = ar->arHifDevice; + hciHandles.htcHandle = ar->arHtcTarget; + status = (A_STATUS)(ar6kHciTransCallbacks.setupTransport(&hciHandles)); + } +#else + if (setuphci) { + /* setup HCI */ + status = ar6000_setup_hci(ar); + } +#endif + + } while (FALSE); + + if (A_FAILED(status)) { + ret = -EIO; + goto ar6000_init_done; + } + + /* + * give our connected endpoints some buffers + */ + + ar6000_rx_refill(ar, ar->arControlEp); + ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE)); + + /* + * We will post the receive buffers only for SPE or endpoint ping testing so we are + * making it conditional on the 'bypasswmi' flag. + */ + if (bypasswmi) { + ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK)); + ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI)); + ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO)); + } + + /* allocate some buffers that handle larger AMSDU frames */ + ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS); + + /* setup credit distribution */ + ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo); + + /* Since cookies are used for HTC transports, they should be */ + /* initialized prior to enabling HTC. */ + ar6000_cookie_init(ar); + + /* start HTC */ + status = HTCStart(ar->arHtcTarget); + if (status != A_OK) { + for(i = 0; i < num_device; i++) + { + if (ar->arDev[i]->arWmiEnabled == TRUE) { + wmi_shutdown(ar->arDev[i]->arWmi); + ar->arDev[i]->arWmiEnabled = FALSE; + ar->arDev[i]->arWmi = NULL; + } + } + ar6000_cookie_cleanup(ar); + ret = -EIO; + goto ar6000_init_done; + } + + if (!bypasswmi) { + /* Wait for Wmi event to be ready */ + timeleft = wait_event_interruptible_timeout(ar->arDev[0]->arEvent, + (ar->arWmiReady == TRUE), wmitimeout * HZ); + + if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver)); +#ifndef ATH6KL_SKIP_ABI_VERSION_CHECK + ret = -EIO; + goto ar6000_init_done; +#endif /* ATH6KL_SKIP_ABI_VERSION_CHECK */ + } + + if(!timeleft || signal_pending(current)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n")); + ret = -EIO; + goto ar6000_init_done; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s() WMI is ready\n", __func__)); + + /* init PAL driver after WMI is ready */ + + if(setuphcipal) { + A_BOOL bt30ampDevFound = FALSE; + for (i=0; i < num_device; i++) { + if ( ar->arDev[i]->isBt30amp == TRUE ) { + status = ar6k_setup_hci_pal(ar->arDev[i]); + bt30ampDevFound = TRUE; + } + + } + } + + /* Communicate the wmi protocol verision to the target */ + if ((ar6000_set_host_app_area(ar)) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n")); + } + + /* configure the device for rx dot11 header rules 0,0 are the default values + * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required + if checksum offload is needed. Set RxMetaVersion to 2*/ + if ((wmi_set_rx_frame_format_cmd(arPriv->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n")); + } + +#if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) + /* Configure the type of BT collocated with WLAN */ + A_MEMZERO(&sbcb_cmd, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)); +#ifdef CONFIG_AR600x_BT_QCOM + sbcb_cmd.btcoexCoLocatedBTdev = 1; +#elif defined(CONFIG_AR600x_BT_CSR) + sbcb_cmd.btcoexCoLocatedBTdev = 2; +#elif defined(CONFIG_AR600x_BT_AR3001) + sbcb_cmd.btcoexCoLocatedBTdev = 3; +#else +#error Unsupported Bluetooth Type +#endif /* Collocated Bluetooth Type */ + + if ((wmi_set_btcoex_colocated_bt_dev_cmd(arPriv->arWmi, &sbcb_cmd)) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n")); + } + + /* Configure the type of BT collocated with WLAN */ + A_MEMZERO(&sbfa_cmd, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)); +#ifdef CONFIG_AR600x_DUAL_ANTENNA + sbfa_cmd.btcoexFeAntType = 2; +#elif defined(CONFIG_AR600x_SINGLE_ANTENNA) + sbfa_cmd.btcoexFeAntType = 1; +#else +#error Unsupported Front-End Antenna Configuration +#endif /* AR600x Front-End Antenna Configuration */ + + if ((wmi_set_btcoex_fe_ant_cmd(arPriv->arWmi, &sbfa_cmd)) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n")); + } +#endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ + } + + ar->arNumDataEndPts = 1; + + if (bypasswmi) { + /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise + * the data path through a raw socket is disabled */ + dev->dev_addr[0] = 0x00; + dev->dev_addr[1] = 0x01; + dev->dev_addr[2] = 0x02; + dev->dev_addr[3] = 0xAA; + dev->dev_addr[4] = 0xBB; + dev->dev_addr[5] = 0xCC; + } + + +ar6000_init_done: + rtnl_lock(); + dev_put(dev); + + return ret; + +} + + +void +ar6000_bitrate_rx(void *devt, A_INT32 rateKbps) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + arPriv->arBitRate = rateKbps; + wake_up(&arPriv->arEvent); +} + +void +ar6000_ratemask_rx(void *devt, A_UINT32 *ratemask) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + arPriv->arRateMask[0] = ratemask[0]; + arPriv->arRateMask[1] = ratemask[1]; + wake_up(&arPriv->arEvent); +} + +void +ar6000_txPwr_rx(void *devt, A_UINT8 txPwr) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + arPriv->arTxPwr = txPwr; + wake_up(&arPriv->arEvent); +} + + +void +ar6000_channelList_rx(void *devt, A_INT8 numChan, A_UINT16 *chanList) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + A_MEMCPY(arPriv->arSta.arChannelList, chanList, numChan * sizeof (A_UINT16)); + arPriv->arSta.arNumChannels = numChan; + + wake_up(&arPriv->arEvent); +} + +A_UINT8 +ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, A_UINT32 * mapNo) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UINT8 *datap; + ATH_MAC_HDR *macHdr; + A_UINT32 i, eptMap; + + (*mapNo) = 0; + datap = A_NETBUF_DATA(skb); + macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR)); + if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) { + return ENDPOINT_2; + } + + eptMap = -1; + for (i = 0; i < arSta->arNodeNum; i ++) { + if (IEEE80211_ADDR_EQ(macHdr->dstMac, arSta->arNodeMap[i].macAddress)) { + (*mapNo) = i + 1; + arSta->arNodeMap[i].txPending ++; + return arSta->arNodeMap[i].epId; + } + + if ((eptMap == -1) && !arSta->arNodeMap[i].txPending) { + eptMap = i; + } + } + + if (eptMap == -1) { + eptMap = arSta->arNodeNum; + arSta->arNodeNum ++; + A_ASSERT(arSta->arNodeNum <= MAX_NODE_NUM); + } + + A_MEMCPY(arSta->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN); + + for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) { + if (!ar->arTxPending[i]) { + arSta->arNodeMap[eptMap].epId = i; + break; + } + // No free endpoint is available, start redistribution on the inuse endpoints. + if (i == ENDPOINT_5) { + arSta->arNodeMap[eptMap].epId = arSta->arNexEpId; + arSta->arNexEpId ++; + if (arSta->arNexEpId > ENDPOINT_5) { + arSta->arNexEpId = ENDPOINT_2; + } + } + } + + (*mapNo) = eptMap + 1; + arSta->arNodeMap[eptMap].txPending ++; + + return arSta->arNodeMap[eptMap].epId; +} + +#ifdef DEBUG +static void ar6000_dump_skb(struct sk_buff *skb) +{ + u_char *ch; + for (ch = A_NETBUF_DATA(skb); + (A_UINT32)ch < ((A_UINT32)A_NETBUF_DATA(skb) + + A_NETBUF_LEN(skb)); ch++) + { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch)); + } + AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n")); +} +#endif + +#ifdef HTC_TEST_SEND_PKTS +static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb); +#endif + +void +check_addba_state(AR_SOFTC_DEV_T *arPriv, struct sk_buff *skb, conn_t *conn) +{ + A_UINT8 *datap; + A_UINT8 tid = 0; + WMI_DATA_HDR *dtHdr; + + /* Perform ADDBA if required */ + if(conn && (conn->wmode == MODE_11NG_HT20)) { + datap = A_NETBUF_DATA(skb); + dtHdr = (WMI_DATA_HDR *)datap; + tid = WMI_DATA_HDR_GET_UP(dtHdr); + + if(conn->ba_state[tid] < 3) { + wmi_setup_aggr_cmd(arPriv->arWmi, tid | (conn->aid << 4)); + conn->ba_state[tid]++; + } + } +} + +static int +ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) +{ +#define AC_NOT_MAPPED 99 + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + A_UINT8 ac = AC_NOT_MAPPED; + HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED; + A_UINT32 mapNo = 0; + int len; + struct ar_cookie *cookie; + A_BOOL checkAdHocPsMapping = FALSE; + HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG; + A_UINT8 dot11Hdr = processDot11Hdr; + A_UINT8 check_addba = 0; + conn_t *conn = NULL; + A_UINT32 wmiDataFlags = 0; + +#ifdef AR6K_ALLOC_DEBUG + A_NETBUF_CHECK(skb); +#endif + +#ifdef CONFIG_PM + if ((ar->arWowState != WLAN_WOW_STATE_NONE) || (ar->arWlanState == WLAN_DISABLED)) { + A_NETBUF_FREE(skb); + return 0; + } +#endif /* CONFIG_PM */ +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13) + skb->list = NULL; +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%x, data=0x%x, len=0x%x\n", + (A_UINT32)skb, (A_UINT32)A_NETBUF_DATA(skb), + A_NETBUF_LEN(skb))); + + /* If target is not associated */ + if( (!arPriv->arConnected && !bypasswmi) +#ifdef CONFIG_HOST_TCMD_SUPPORT + /* TCMD doesnt support any data, free the buf and return */ + || (ar->arTargetMode == AR6000_TCMD_MODE) +#endif + ) { + A_NETBUF_FREE(skb); + return 0; + } + + do { + + if (ar->arWmiReady == FALSE && bypasswmi == 0) { + break; + } + +#ifdef BLOCK_TX_PATH_FLAG + if (blocktx) { + break; + } +#endif /* BLOCK_TX_PATH_FLAG */ + + /* AP mode Power save processing */ + /* If the dst STA is in sleep state, queue the pkt in its PS queue */ + + if (arPriv->arNetworkType == AP_NETWORK) { + ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); + + /* If the dstMac is a Multicast address & atleast one of the + * associated STA is in PS mode, then queue the pkt to the + * mcastq + */ + if (IEEE80211_IS_MULTICAST(datap->dstMac)) { + A_UINT8 ctr=0; + A_BOOL qMcast=FALSE; + + for (ctr=0; ctrconnTbl[ctr].arPriv == arPriv) { + if (STA_IS_PWR_SLEEP((&ar->connTbl[ctr]))) { + qMcast = TRUE; + } + } + } + if(qMcast) { + /* If this transmit is not because of a Dtim Expiry q it */ + if (arAp->DTIMExpired == FALSE) { + A_BOOL isMcastqEmpty = FALSE; + + A_MUTEX_LOCK(&arAp->mcastpsqLock); + isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&arAp->mcastpsq); + A_NETBUF_ENQUEUE(&arAp->mcastpsq, skb); + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + + /* If this is the first Mcast pkt getting queued + * indicate to the target to set the BitmapControl LSB + * of the TIM IE. + */ + if (isMcastqEmpty) { + wmi_set_pvb_cmd(arPriv->arWmi, MCAST_AID, 1); + } + return 0; + } else { + /* This transmit is because of Dtim expiry. Determine if + * MoreData bit has to be set. + */ + A_MUTEX_LOCK(&arAp->mcastpsqLock); + if(!A_NETBUF_QUEUE_EMPTY(&arAp->mcastpsq)) { + wmiDataFlags |= WMI_DATA_HDR_FLAGS_MORE; + } + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + } + } + } else { + conn = ieee80211_find_conn(arPriv, datap->dstMac); + if (conn) { + if (STA_IS_PWR_SLEEP(conn)) { + /* If this transmit is not because of a PsPoll q it*/ + if (!(STA_IS_PS_POLLED(conn) || STA_IS_APSD_TRIGGER(conn))) { + A_BOOL trigger = FALSE; + + if (conn->apsd_info) { + A_UINT8 up = 0; + A_UINT8 trafficClass; + + if (arPriv->arWmmEnabled) { + A_UINT16 ipType = IP_ETHERTYPE; + A_UINT16 etherType; + A_UINT8 *ipHdr; + + etherType = datap->typeOrLen; + if (IS_ETHERTYPE(A_BE2CPU16(etherType))) { + /* packet is in DIX format */ + ipHdr = (A_UINT8 *)(datap + 1); + } else { + /* packet is in 802.3 format */ + ATH_LLC_SNAP_HDR *llcHdr; + + llcHdr = (ATH_LLC_SNAP_HDR *)(datap + 1); + etherType = llcHdr->etherType; + ipHdr = (A_UINT8 *)(llcHdr + 1); + } + + if (etherType == A_CPU2BE16(ipType)) { + up = wmi_determine_userPriority (ipHdr, 0); + } + } + trafficClass = convert_userPriority_to_trafficClass(up); + if (conn->apsd_info & (1 << trafficClass)) { + trigger = TRUE; + } + } + + if (trigger) { + A_BOOL isApsdqEmpty; + /* Queue the frames if the STA is sleeping */ + A_MUTEX_LOCK(&conn->psqLock); + isApsdqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->apsdq); + A_NETBUF_ENQUEUE(&conn->apsdq, skb); + A_MUTEX_UNLOCK(&conn->psqLock); + + /* If this is the first pkt getting queued + * for this STA, update the PVB for this STA + */ + if (isApsdqEmpty) { + wmi_set_apsd_buffered_traffic_cmd(arPriv->arWmi, conn->aid, 1, 0); + } + } else { + A_BOOL isPsqEmpty = FALSE; + /* Queue the frames if the STA is sleeping */ + A_MUTEX_LOCK(&conn->psqLock); + isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); + A_NETBUF_ENQUEUE(&conn->psq, skb); + A_MUTEX_UNLOCK(&conn->psqLock); + + /* If this is the first pkt getting queued + * for this STA, update the PVB for this STA + */ + if (isPsqEmpty) { + wmi_set_pvb_cmd(arPriv->arWmi, conn->aid, 1); + } + } + + return 0; + } else { + /* + * This tx is because of a PsPoll or trigger. Determine if + * MoreData bit has to be set + */ + A_MUTEX_LOCK(&conn->psqLock); + if (STA_IS_PS_POLLED(conn)) { + if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) { + wmiDataFlags |= WMI_DATA_HDR_FLAGS_MORE; + } + } else { + /* + * This tx is because of a uAPSD trigger, determine + * more and EOSP bit. Set EOSP is queue is empty + * or sufficient frames is delivered for this trigger + */ + if (!A_NETBUF_QUEUE_EMPTY(&conn->apsdq)) { + wmiDataFlags |= WMI_DATA_HDR_FLAGS_MORE; + } + if (STA_IS_APSD_EOSP(conn)) { + wmiDataFlags |= WMI_DATA_HDR_FLAGS_EOSP; + } + } + A_MUTEX_UNLOCK(&conn->psqLock); + } + } + check_addba = 1; + } else { + + /* non existent STA. drop the frame */ + A_NETBUF_FREE(skb); + return 0; + } + } + } + + if (arPriv->arWmiEnabled) { +#ifdef CONFIG_CHECKSUM_OFFLOAD + A_UINT8 csumStart=0; + A_UINT8 csumDest=0; + A_UINT8 csum=skb->ip_summed; + if(csumOffload && (csum==CHECKSUM_PARTIAL)){ + csumStart=skb->csum_start-(skb->network_header-skb->head)+sizeof(ATH_LLC_SNAP_HDR); + csumDest=skb->csum_offset+csumStart; + } +#endif + if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) { + struct sk_buff *newbuf; + + /* + * We really should have gotten enough headroom but sometimes + * we still get packets with not enough headroom. Copy the packet. + */ + len = A_NETBUF_LEN(skb); + newbuf = A_NETBUF_ALLOC(len); + if (newbuf == NULL) { + break; + } + A_NETBUF_PUT(newbuf, len); + A_MEMCPY(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len); + A_NETBUF_FREE(skb); + skb = newbuf; + /* fall through and assemble header */ + } + + if (dot11Hdr) { + if (wmi_dot11_hdr_add(arPriv->arWmi,skb,arPriv->arNetworkType) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n")); + break; + } + } else { + if (wmi_dix_2_dot3(arPriv->arWmi, skb) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n")); + break; + } + } +#ifdef CONFIG_CHECKSUM_OFFLOAD + if(csumOffload && (csum ==CHECKSUM_PARTIAL)){ + WMI_TX_META_V2 metaV2; + metaV2.csumStart =csumStart; + metaV2.csumDest = csumDest; + metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/ + if (wmi_data_hdr_add(arPriv->arWmi, skb, DATA_MSGTYPE, wmiDataFlags, dot11Hdr, + WMI_META_VERSION_2,&metaV2) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n")); + break; + } + + } + else +#endif + { + if (wmi_data_hdr_add(arPriv->arWmi, skb, DATA_MSGTYPE, wmiDataFlags, dot11Hdr,0,NULL) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n")); + break; + } + } + + + if ((arPriv->arNetworkType == ADHOC_NETWORK) && + arSta->arIbssPsEnable && arPriv->arConnected) { + /* flag to check adhoc mapping once we take the lock below: */ + checkAdHocPsMapping = TRUE; + + } else { + /* get the stream mapping */ + ac = wmi_implicit_create_pstream(arPriv->arWmi, skb, 0, arPriv->arWmmEnabled); + if(check_addba && conn) { + check_addba_state(arPriv, skb, conn); + } + } + + } else { + EPPING_HEADER *eppingHdr; + + eppingHdr = A_NETBUF_DATA(skb); + + if (IS_EPPING_PACKET(eppingHdr)) { + /* the stream ID is mapped to an access class */ + ac = eppingHdr->StreamNo_h; + /* some EPPING packets cannot be dropped no matter what access class it was + * sent on. We can change the packet tag to guarantee it will not get dropped */ + if (IS_EPING_PACKET_NO_DROP(eppingHdr)) { + htc_tag = AR6K_CONTROL_PKT_TAG; + } + + if (ac == HCI_TRANSPORT_STREAM_NUM) { + /* pass this to HCI */ +#ifndef EXPORT_HCI_BRIDGE_INTERFACE + if (A_SUCCESS(hci_test_send(ar,skb))) { + return 0; + } +#endif + /* set AC to discard this skb */ + ac = AC_NOT_MAPPED; + } else { + /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition + * of the HTC header will mis-align the start of the HTC frame, so we add some + * padding which will be stripped off in the target */ + if (EPPING_ALIGNMENT_PAD > 0) { + A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD); + } + } + + } else { + /* not a ping packet, drop it */ + ac = AC_NOT_MAPPED; + } + } + + } while (FALSE); + + /* did we succeed ? */ + if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) { + /* cleanup and exit */ + A_NETBUF_FREE(skb); + AR6000_STAT_INC(arPriv, tx_dropped); + AR6000_STAT_INC(arPriv, tx_aborted_errors); + return 0; + } + + cookie = NULL; + + /* take the lock to protect driver data */ + AR6000_SPIN_LOCK(&ar->arLock, 0); + + do { + + if (checkAdHocPsMapping) { + eid = ar6000_ibss_map_epid(skb, dev, &mapNo); + }else { + eid = arAc2EndpointID (ar, ac); + } + /* validate that the endpoint is connected */ + if (eid == 0 || eid == ENDPOINT_UNUSED ) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid)); + break; + } + /* allocate resource for this packet */ + cookie = ar6000_alloc_cookie(ar); + + if (cookie != NULL) { + /* update counts while the lock is held */ + ar->arTxPending[eid]++; + ar->arTotalTxDataPending++; + } + + } while (FALSE); + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (cookie != NULL) { + cookie->arc_bp[0] = (A_UINT32)skb; + cookie->arc_bp[1] = mapNo; + SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, + cookie, + A_NETBUF_DATA(skb), + A_NETBUF_LEN(skb), + eid, + htc_tag); + +#ifdef DEBUG + if (debugdriver >= 3) { + ar6000_dump_skb(skb); + } +#endif +#ifdef HTC_TEST_SEND_PKTS + DoHTCSendPktsTest(ar,mapNo,eid,skb); +#endif + /* HTC interface is asynchronous, if this fails, cleanup will happen in + * the ar6000_tx_complete callback */ + HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); + } else { + /* no packet to send, cleanup */ + A_NETBUF_FREE(skb); + AR6000_STAT_INC(arPriv, tx_dropped); + AR6000_STAT_INC(arPriv, tx_aborted_errors); + } + + return 0; +} + +int +ar6000_acl_data_tx(struct sk_buff *skb, AR_SOFTC_DEV_T *arPriv) +{ + struct ar_cookie *cookie; + AR_SOFTC_T *ar = arPriv->arSoftc; + HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED; + + cookie = NULL; + AR6000_SPIN_LOCK(&ar->arLock, 0); + + /* For now we send ACL on BE endpoint: We can also have a dedicated EP */ + eid = arAc2EndpointID (ar, 0); + /* allocate resource for this packet */ + cookie = ar6000_alloc_cookie(ar); + + if (cookie != NULL) { + /* update counts while the lock is held */ + ar->arTxPending[eid]++; + ar->arTotalTxDataPending++; + } + + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (cookie != NULL) { + cookie->arc_bp[0] = (A_UINT32)skb; + cookie->arc_bp[1] = 0; + SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, + cookie, + A_NETBUF_DATA(skb), + A_NETBUF_LEN(skb), + eid, + AR6K_DATA_PKT_TAG); + + /* HTC interface is asynchronous, if this fails, cleanup will happen in + * the ar6000_tx_complete callback */ + HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); + } else { + /* no packet to send, cleanup */ + A_NETBUF_FREE(skb); + AR6000_STAT_INC(arPriv, tx_dropped); + AR6000_STAT_INC(arPriv, tx_aborted_errors); + } + return 0; +} + + +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +static void +tvsub(register struct timeval *out, register struct timeval *in) +{ + if((out->tv_usec -= in->tv_usec) < 0) { + out->tv_sec--; + out->tv_usec += 1000000; + } + out->tv_sec -= in->tv_sec; +} + +void +applyAPTCHeuristics(AR_SOFTC_DEV_T *arPriv) +{ + A_UINT32 duration; + A_UINT32 numbytes; + A_UINT32 throughput; + struct timeval ts; + A_STATUS status; + APTC_TRAFFIC_RECORD *aptcTR; + AR_SOFTC_T *ar = arPriv->arSoftc; + + aptcTR = arPriv->aptcTR; + + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + + if ((enableAPTCHeuristics) && (!aptcTR->timerScheduled)) { + do_gettimeofday(&ts); + tvsub(&ts, &aptcTR->samplingTS); + duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */ + numbytes = aptcTR->bytesTransmitted + aptcTR->bytesReceived; + + if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) { + /* Initialize the time stamp and byte count */ + aptcTR->bytesTransmitted = aptcTR->bytesReceived = 0; + do_gettimeofday(&aptcTR->samplingTS); + + /* Calculate and decide based on throughput thresholds */ + throughput = ((numbytes * 8) / duration); + if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) { + /* Disable Sleep and schedule a timer */ + A_ASSERT(ar->arWmiReady == TRUE); + AR6000_SPIN_UNLOCK(&arPriv->ariPrivLock, 0); + status = wmi_powermode_cmd(arPriv->arWmi, MAX_PERF_POWER); + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + A_TIMEOUT_MS(&aptcTimer[arPriv->arDeviceIndex], APTC_TRAFFIC_SAMPLING_INTERVAL, 0); + aptcTR->timerScheduled = TRUE; + } + } + } + + AR6000_SPIN_UNLOCK(&arPriv->arLock, 0); +} +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + +static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP; + A_BOOL stopNet = FALSE; + HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket); + A_UINT8 i; + AR_SOFTC_DEV_T *arPriv; + + do { + + if (bypasswmi) { + int accessClass; + + if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) { + /* don't drop special control packets */ + break; + } + + accessClass = arEndpoint2Ac(ar,Endpoint); + /* for endpoint ping testing drop Best Effort and Background */ + if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) { + action = HTC_SEND_FULL_DROP; + stopNet = FALSE; + } else { + /* keep but stop the netqueues */ + stopNet = TRUE; + } + break; + } + + if (Endpoint == ar->arControlEp) { + /* under normal WMI if this is getting full, then something is running rampant + * the host should not be exhausting the WMI queue with too many commands + * the only exception to this is during testing using endpointping */ + AR6000_SPIN_LOCK(&ar->arLock, 0); + /* set flag to handle subsequent messages */ + ar->arWMIControlEpFull = TRUE; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n")); + /* no need to stop the network */ + stopNet = FALSE; + break; + } + + /* if we get here, we are dealing with data endpoints getting full */ + + if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) { + /* don't drop control packets issued on ANY data endpoint */ + break; + } + + /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest + * active stream */ + if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri && + ar->arCookieCount <= MAX_HI_COOKIE_NUM) { + /* this stream's priority is less than the highest active priority, we + * give preference to the highest priority stream by directing + * HTC to drop the packet that overflowed */ + action = HTC_SEND_FULL_DROP; + /* since we are dropping packets, no need to stop the network */ + stopNet = FALSE; + break; + } + + } while (FALSE); + + if (stopNet) { + for(i = 0; i < num_device; i++) + { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[i]); + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arPriv->arNetQueueStopped = TRUE; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + /* one of the data endpoints queues is getting full..need to stop network stack + * the queue will resume in ar6000_tx_complete() */ + netif_stop_queue(ar6000_devices[i]); + } + } + else + { + /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to + * continue, however we should stop the network */ + for(i = 0; i < num_device; i++) + { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[i]); + if(arPriv->arNetworkType == ADHOC_NETWORK) { + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arPriv->arNetQueueStopped = TRUE; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + /* one of the data endpoints queues is getting full..need to stop network stack + * the queue will resume in ar6000_tx_complete() */ + netif_stop_queue(ar6000_devices[i]); + } + } + } + return action; +} + + +static void +ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPacketQueue) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + A_UINT32 mapNo = 0; + A_STATUS status; + struct ar_cookie * ar_cookie; + HTC_ENDPOINT_ID eid; + A_BOOL wakeEvent = FALSE; + struct sk_buff_head skb_queue; + HTC_PACKET *pPacket; + struct sk_buff *pktSkb; + A_BOOL flushing[NUM_DEV]; + A_INT8 devid = -1; + AR_SOFTC_DEV_T *arPriv = NULL; + AR_SOFTC_STA_T *arSta; + A_UINT8 i; + + skb_queue_head_init(&skb_queue); + + /* lock the driver as we update internal state */ + AR6000_SPIN_LOCK(&ar->arLock, 0); + + /* reap completed packets */ + while (!HTC_QUEUE_EMPTY(pPacketQueue)) { + + pPacket = HTC_PACKET_DEQUEUE(pPacketQueue); + + ar_cookie = (struct ar_cookie *)pPacket->pPktContext; + A_ASSERT(ar_cookie); + + status = pPacket->Status; + pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0]; + eid = pPacket->Endpoint; + mapNo = ar_cookie->arc_bp[1]; + + A_ASSERT(pktSkb); + A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb)); + + /* add this to the list, use faster non-lock API */ + __skb_queue_tail(&skb_queue,pktSkb); + + if (A_SUCCESS(status)) { + A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb)); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%x data=0x%x len=0x%x eid=%d ", + (A_UINT32)pktSkb, (A_UINT32)pPacket->pBuffer, + pPacket->ActualLength, + eid)); + + ar->arTxPending[eid]--; + + if(!bypasswmi) + { + + if (eid != ar->arControlEp) { + WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(pktSkb); + ar->arTotalTxDataPending--; + devid = WMI_DATA_HDR_GET_DEVID(dhdr); + arPriv = ar->arDev[devid]; + } + + if (eid == ar->arControlEp) + { + WMI_CMD_HDR *cmhdr = (WMI_CMD_HDR*)A_NETBUF_DATA(pktSkb); + if (ar->arWMIControlEpFull) { + /* since this packet completed, the WMI EP is no longer full */ + ar->arWMIControlEpFull = FALSE; +#ifdef ANDROID_ENV + android_epfull_cnt = 0; +#endif + } + + if (ar->arTxPending[eid] == 0) { + wakeEvent = TRUE; + } + devid = WMI_CMD_HDR_GET_DEVID(cmhdr); + arPriv = ar->arDev[devid]; + } + } + else + { + devid = 0; + arPriv = ar->arDev[devid]; + } + + + if (A_FAILED(status)) { + if (status == A_ECANCELED) { + /* a packet was flushed */ + flushing[devid] = TRUE; + } + AR6000_STAT_INC(arPriv, tx_errors); + if (status != A_NO_RESOURCE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__, + status)); + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n")); + flushing[devid] = FALSE; + AR6000_STAT_INC(arPriv, tx_packets); + arPriv->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb); +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + arPriv->aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb); + applyAPTCHeuristics(arPriv); +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + } + + // TODO this needs to be looked at + if (arPriv->arNetworkType == ADHOC_NETWORK) + { + arSta = &arPriv->arSta; + if((arSta->arIbssPsEnable && (eid != ar->arControlEp) && mapNo)) + { + mapNo --; + arSta->arNodeMap[mapNo].txPending --; + + if (!arSta->arNodeMap[mapNo].txPending && (mapNo == (arSta->arNodeNum - 1))) { + A_UINT32 i; + for (i = arSta->arNodeNum; i > 0; i --) { + if (!arSta->arNodeMap[i - 1].txPending) { + A_MEMZERO(&arSta->arNodeMap[i - 1], sizeof(struct ar_node_mapping)); + arSta->arNodeNum --; + } else { + break; + } + } + } + } + } + + ar6000_free_cookie(ar, ar_cookie); + + if (arPriv->arNetQueueStopped) { + arPriv->arNetQueueStopped = FALSE; + } + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + /* lock is released, we can freely call other kernel APIs */ + + /* free all skbs in our local list */ + while (!skb_queue_empty(&skb_queue)) { + /* use non-lock version */ + pktSkb = __skb_dequeue(&skb_queue); + A_NETBUF_FREE(pktSkb); + } + for(i = 0; i < num_device; i++) { + arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[i]); + if (((arPriv->arNetworkType == INFRA_NETWORK ) && (arPriv->arConnected == TRUE)) + || (bypasswmi)) { + if (!flushing[i]) { + /* don't wake the queue if we are flushing, other wise it will just + * keep queueing packets, which will keep failing */ + + netif_wake_queue(arPriv->arNetDev); + } + } + + if (wakeEvent) { + wake_up(&arPriv->arEvent); + } + } + +} + +conn_t * +ieee80211_find_conn(AR_SOFTC_DEV_T *arPriv, A_UINT8 *node_addr) +{ + conn_t *conn = NULL; + A_UINT8 i; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (IS_MAC_NULL(node_addr)) { + return NULL; + } + + for (i = 0; i < NUM_CONN; i++) { + if (IEEE80211_ADDR_EQ(node_addr, ar->connTbl[i].mac)) { + conn = &ar->connTbl[i]; + break; + } + } + + return conn; +} + +conn_t *ieee80211_find_conn_for_aid(AR_SOFTC_DEV_T *arPriv, A_UINT8 aid) +{ + conn_t *conn = NULL; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (arPriv->arNetworkType != AP_NETWORK) { + conn = NULL; + } else if( (aid > 0) && (aid < NUM_CONN) ) { + if (ar->connTbl[aid-1].aid == aid) { + conn = &ar->connTbl[aid-1]; + } + } + return conn; +} + +void *get_aggr_ctx(AR_SOFTC_DEV_T *arPriv, conn_t *conn) +{ + if (arPriv->arNetworkType != AP_NETWORK) { + return (arPriv->conn_aggr); + } else { + return (conn->conn_aggr); + } +} + +/* + * Receive event handler. This is called by HTC when a packet is received + */ +int pktcount; +static void +ar6000_rx(void *Context, HTC_PACKET *pPacket) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext; + int minHdrLen; + A_UINT8 containsDot11Hdr = 0; + A_STATUS status = pPacket->Status; + HTC_ENDPOINT_ID ept = pPacket->Endpoint; + conn_t *conn = NULL; + AR_SOFTC_DEV_T *arPriv = NULL; + A_UINT8 devid ; + ATH_MAC_HDR *multicastcheck_datap = NULL; + + A_ASSERT((status != A_OK) || + (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN))); + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx ar=0x%x eid=%d, skb=0x%x, data=0x%x, len=0x%x status:%d", + (A_UINT32)ar, ept, (A_UINT32)skb, (A_UINT32)pPacket->pBuffer, + pPacket->ActualLength, status)); + + if (status != A_OK) { + if (status != A_ECANCELED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status)); + } + A_NETBUF_FREE(skb); + goto rx_done; + } + + /* take lock to protect buffer counts + * and adaptive power throughput state */ + AR6000_SPIN_LOCK(&ar->arLock, 0); + A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN); + A_NETBUF_PULL(skb, HTC_HEADER_LEN); + + if(!bypasswmi) + { + if(ept == ar->arControlEp) { + WMI_CMD_HDR *cmhdr = (WMI_CMD_HDR*)A_NETBUF_DATA(skb); + devid = WMI_CMD_HDR_GET_DEVID(cmhdr); + arPriv = ar->arDev[devid]; + } + else { + WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb); + devid = WMI_DATA_HDR_GET_DEVID(dhdr); + arPriv = ar->arDev[devid]; + } + } + else + { + devid = 0; + arPriv = ar->arDev[devid]; + } + + if (A_SUCCESS(status)) { + AR6000_STAT_INC(arPriv, rx_packets); + arPriv->arNetStats.rx_bytes += pPacket->ActualLength; +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + arPriv->aptcTR.bytesReceived += pPacket->ActualLength; + applyAPTCHeuristics(arPriv); +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + + +#ifdef DEBUG + if (debugdriver >= 2) { + ar6000_dump_skb(skb); + } +#endif /* DEBUG */ + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + skb->dev = arPriv->arNetDev; + if (status != A_OK) { + AR6000_STAT_INC(arPriv, rx_errors); + A_NETBUF_FREE(skb); + } else if (arPriv->arWmiEnabled == TRUE) { + if (ept == ar->arControlEp) { + /* + * this is a wmi control msg + */ +#ifdef CONFIG_PM + ar6000_check_wow_status(ar, skb, TRUE); +#endif /* CONFIG_PM */ + wmi_control_rx(arPriv->arWmi, skb); + } else { + WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb); + A_UINT8 is_amsdu, tid, is_acl_data_frame; + is_acl_data_frame = WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == WMI_DATA_HDR_DATA_TYPE_ACL; +#ifdef CONFIG_PM + ar6000_check_wow_status(ar, NULL, FALSE); +#endif /* CONFIG_PM */ + /* + * this is a wmi data packet + */ + // NWF + + if (processDot11Hdr) { + minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR); + } else { + minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) + + sizeof(ATH_LLC_SNAP_HDR); + } + + /* In the case of AP mode we may receive NULL data frames + * that do not have LLC hdr. They are 16 bytes in size. + * Allow these frames in the AP mode. + * ACL data frames don't follow ethernet frame bounds for + * min length + */ + if (arPriv->arNetworkType != AP_NETWORK && !is_acl_data_frame && + ((pPacket->ActualLength < minHdrLen) || + (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE))) + { + /* + * packet is too short or too long + */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n")); + AR6000_STAT_INC(arPriv, rx_errors); + AR6000_STAT_INC(arPriv, rx_length_errors); + A_NETBUF_FREE(skb); + } else { + A_UINT16 seq_no; + A_UINT8 meta_type; + +#if 0 + /* Access RSSI values here */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n", + ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi)); +#endif + /* Get the Power save state of the STA */ + if (arPriv->arNetworkType == AP_NETWORK) { + A_UINT8 psState=0,prevPsState; + ATH_MAC_HDR *datap=NULL; + A_UINT16 offset; + A_UINT8 triggerState; + + meta_type = WMI_DATA_HDR_GET_META(dhdr); + + psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info + >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK; + triggerState = WMI_DATA_HDR_IS_TRIGGER(dhdr); + + + offset = sizeof(WMI_DATA_HDR); + + switch (meta_type) { + case 0: + break; + case WMI_META_VERSION_1: + offset += sizeof(WMI_RX_META_V1); + break; +#ifdef CONFIG_CHECKSUM_OFFLOAD + case WMI_META_VERSION_2: + offset += sizeof(WMI_RX_META_V2); + break; +#endif + default: + break; + } +#ifdef DIX_RX_OFFLOAD +#define SKIP_LLC_LEN 8 + /*DIX to ETHERNET hdr conversion is offloaded to firmware */ + /*Empty LLC header is moved to get ethernet header*/ + A_UINT32 datalen = (A_UINT32)A_NETBUF_LEN(skb)-offset; + + is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr); + containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr); + if(!containsDot11Hdr && !is_amsdu && !is_acl_data_frame + && datalen >= (sizeof(ATH_MAC_HDR) + sizeof(ATH_LLC_SNAP_HDR))) { + datap = (ATH_MAC_HDR *)((A_INT8*)A_NETBUF_DATA(skb)+offset+SKIP_LLC_LEN); + } + else { + datap = (ATH_MAC_HDR *)((A_INT8*)A_NETBUF_DATA(skb)+offset); + } + +#else + datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset); +#endif + conn = ieee80211_find_conn(arPriv, datap->srcMac); + + if (conn) { + /* if there is a change in PS state of the STA, + * take appropriate steps. + * 1. If Sleep-->Awake, flush the psq for the STA + * Clear the PVB for the STA. + * 2. If Awake-->Sleep, Starting queueing frames + * the STA. + */ + prevPsState = STA_IS_PWR_SLEEP(conn); + if (psState) { + STA_SET_PWR_SLEEP(conn); + } else { + STA_CLR_PWR_SLEEP(conn); + } + + if (STA_IS_PWR_SLEEP(conn)) { + /* Accept trigger only when the station is in sleep */ + if (triggerState) { + ar6000_uapsd_trigger_frame_rx(arPriv, conn); + } + } + + if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) { + A_BOOL isApsdqEmptyAtStart; + + if (!STA_IS_PWR_SLEEP(conn)) { + + A_MUTEX_LOCK(&conn->psqLock); + + while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) { + struct sk_buff *skb=NULL; + + skb = A_NETBUF_DEQUEUE(&conn->psq); + A_MUTEX_UNLOCK(&conn->psqLock); + ar6000_data_tx(skb,arPriv->arNetDev); + A_MUTEX_LOCK(&conn->psqLock); + } + + isApsdqEmptyAtStart = A_NETBUF_QUEUE_EMPTY(&conn->apsdq); + + while (!A_NETBUF_QUEUE_EMPTY(&conn->apsdq)) { + struct sk_buff *skb=NULL; + + skb = A_NETBUF_DEQUEUE(&conn->apsdq); + A_MUTEX_UNLOCK(&conn->psqLock); + ar6000_data_tx(skb,arPriv->arNetDev); + A_MUTEX_LOCK(&conn->psqLock); + } + + A_MUTEX_UNLOCK(&conn->psqLock); + + /* Clear the APSD buffered bitmap for this STA */ + if (!isApsdqEmptyAtStart) { + wmi_set_apsd_buffered_traffic_cmd(arPriv->arWmi, conn->aid, 0, 0); + } + + /* Clear the PVB for this STA */ + wmi_set_pvb_cmd(arPriv->arWmi, conn->aid, 0); + } + } + + } else { + /* This frame is from a STA that is not associated*/ + A_NETBUF_FREE(skb); + goto rx_done; + } + + /* Drop NULL data frames here */ + if((pPacket->ActualLength < minHdrLen) || + (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) { + A_NETBUF_FREE(skb); + goto rx_done; + } + } + + is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr); + tid = WMI_DATA_HDR_GET_UP(dhdr); + seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr); + meta_type = WMI_DATA_HDR_GET_META(dhdr); + containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr); + + wmi_data_hdr_remove(arPriv->arWmi, skb); + + switch (meta_type) { + case WMI_META_VERSION_1: + { + WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags)); + A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1)); + break; + } +#ifdef CONFIG_CHECKSUM_OFFLOAD + case WMI_META_VERSION_2: + { + WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb); + if(pMeta->csumFlags & 0x1){ + skb->ip_summed=CHECKSUM_COMPLETE; + skb->csum=(pMeta->csum); + } + A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2)); + break; + } +#endif + default: + break; + } + + A_ASSERT(status == A_OK); + + /* NWF: print the 802.11 hdr bytes */ + if(containsDot11Hdr) { + status = wmi_dot11_hdr_remove(arPriv->arWmi,skb); + } else if(!is_amsdu && !is_acl_data_frame) { +#ifdef DIX_RX_OFFLOAD + /*Skip the conversion its offloaded to firmware*/ + if(A_NETBUF_PULL(skb, sizeof(ATH_LLC_SNAP_HDR)) != A_OK) { + status = A_NO_MEMORY; + } + else { + status = A_OK; + } +#else + status = wmi_dot3_2_dix(skb); +#endif + } + + if (status != A_OK) { + /* Drop frames that could not be processed (lack of memory, etc.) */ + A_NETBUF_FREE(skb); + goto rx_done; + } + + if (is_acl_data_frame) { + A_NETBUF_PUSH(skb, sizeof(int)); + *((short *)A_NETBUF_DATA(skb)) = WMI_ACL_DATA_EVENTID; + /* send the data packet to PAL driver */ + if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) { + if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(arPriv->hcipal_info, skb) == TRUE) + goto rx_done; + } + } +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + /* + * extra push and memcpy, for eth_type_trans() of 2.4 kernel + * will pull out hard_header_len bytes of the skb. + */ + A_NETBUF_PUSH(skb, sizeof(WMI_DATA_HDR) + sizeof(ATH_LLC_SNAP_HDR) + HTC_HEADER_LEN); + A_MEMCPY(A_NETBUF_DATA(skb), A_NETBUF_DATA(skb) + sizeof(WMI_DATA_HDR) + + sizeof(ATH_LLC_SNAP_HDR) + HTC_HEADER_LEN, sizeof(ATH_MAC_HDR)); +#endif + +#ifdef ATH_AR6K_11N_SUPPORT + multicastcheck_datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); + + if ((!(IEEE80211_IS_MULTICAST(multicastcheck_datap->dstMac))) && (arPriv->arNetworkType != AP_NETWORK)){ + aggr_process_recv_frm(get_aggr_ctx(arPriv, conn), tid, seq_no, is_amsdu, (void **)&skb); + } +#endif + ar6000_deliver_frames_to_nw_stack((void *) arPriv->arNetDev, (void *)skb); + } + } + } else { + if (EPPING_ALIGNMENT_PAD > 0) { + A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD); + } + ar6000_deliver_frames_to_nw_stack((void *)arPriv->arNetDev, (void *)skb); + } + +rx_done: + + return; +} + +static void +ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf) +{ + struct sk_buff *skb = (struct sk_buff *)osbuf; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if(skb) { + skb->dev = dev; + if ((skb->dev->flags & IFF_UP) == IFF_UP) { + + if (arPriv->arNetworkType == AP_NETWORK) { + + struct sk_buff *skb1 = NULL; + ATH_MAC_HDR *datap; + struct net_device *net_dev = arPriv->arNetDev; + +#ifdef CONFIG_PM + ar6000_check_wow_status(ar, skb, FALSE); +#endif /* CONFIG_PM */ + + + datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); + + if (IEEE80211_IS_MULTICAST(datap->dstMac)) { + + /* Bcast/Mcast frames should be sent to the OS + * stack as well as on the air. + */ + skb1 = skb_copy(skb,GFP_ATOMIC); + } else { + + /* Search for a connected STA with dstMac as + * the Mac address. If found send the frame to + * it on the air else send the frame up the stack + */ + + AR_SOFTC_DEV_T *to_arPriv = NULL; + A_UINT8 is_forward = 0; + conn_t *to_conn = NULL; + + to_conn = ieee80211_find_conn(arPriv, datap->dstMac); + + if (to_conn) { + to_arPriv = (AR_SOFTC_DEV_T *)to_conn->arPriv; + /* Forward data within BSS */ + if(arPriv == to_arPriv) { + is_forward = arPriv->arAp.intra_bss; + } else { + /* Forward data within mBSS */ + is_forward = ar->inter_bss; + net_dev = to_arPriv->arNetDev; + } + if(is_forward && net_dev) { + skb1 = skb; + skb = NULL; + } else { + A_NETBUF_FREE(skb); + skb = NULL; + return; + } + } + + } + + if (skb1) { + ar6000_data_tx(skb1, net_dev); + if (!skb) + return; + } + } + +#ifdef CONFIG_PM + ar6000_check_wow_status(ar, skb, FALSE); +#endif /* CONFIG_PM */ + skb->protocol = eth_type_trans(skb, skb->dev); + /* + * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ) + * or tasklet use the netif_rx to deliver the packet to the stack + * netif_rx will queue the packet onto the receive queue and mark + * the softirq thread has a pending action to complete. Kernel will + * schedule the softIrq kernel thread after processing the DSR. + * + * If this routine is called on a process context, use netif_rx_ni + * which will schedle the softIrq kernel thread after queuing the packet. + */ + if (in_interrupt()) { + A_NETIF_RX(skb); + } else { + A_NETIF_RX_NI(skb); + } + } else { + A_NETBUF_FREE(skb); + } + } +} + +#if 0 +static void +ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf) +{ + struct sk_buff *skb = (struct sk_buff *)osbuf; + + if(skb) { + skb->dev = dev; + if ((skb->dev->flags & IFF_UP) == IFF_UP) { + skb->protocol = htons(ETH_P_CONTROL); + netif_rx(skb); + } else { + A_NETBUF_FREE(skb); + } + } +} +#endif + +static void +ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + void *osBuf; + int RxBuffers; + int buffersToRefill; + HTC_PACKET *pPacket; + HTC_PACKET_QUEUE queue; + + buffersToRefill = (int)AR6000_MAX_RX_BUFFERS - + HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint); + + if (buffersToRefill <= 0) { + /* fast return, nothing to fill */ + return; + } + + INIT_HTC_PACKET_QUEUE(&queue); + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n", + buffersToRefill, Endpoint)); + + for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) { + osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE); + if (NULL == osBuf) { + break; + } + /* the HTC packet wrapper is at the head of the reserved area + * in the skb */ + pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf)); + /* set re-fill info */ + SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint); + /* add to queue */ + HTC_PACKET_ENQUEUE(&queue,pPacket); + } + + if (!HTC_QUEUE_EMPTY(&queue)) { + /* add packets */ + HTCAddReceivePktMultiple(ar->arHtcTarget, &queue); + } + +} + + /* clean up our amsdu buffer list */ +static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar) +{ + HTC_PACKET *pPacket; + void *osBuf; + + /* empty AMSDU buffer queue and free OS bufs */ + while (TRUE) { + + AR6000_SPIN_LOCK(&ar->arLock, 0); + pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (NULL == pPacket) { + break; + } + + osBuf = pPacket->pPktContext; + if (NULL == osBuf) { + A_ASSERT(FALSE); + break; + } + + A_NETBUF_FREE(osBuf); + } + +} + + + /* refill the amsdu buffer list */ +static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count) +{ + HTC_PACKET *pPacket; + void *osBuf; + + while (Count > 0) { + osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE); + if (NULL == osBuf) { + break; + } + /* the HTC packet wrapper is at the head of the reserved area + * in the skb */ + pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf)); + /* set re-fill info */ + SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0); + + AR6000_SPIN_LOCK(&ar->arLock, 0); + /* put it in the list */ + HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + Count--; + } + +} + + /* callback to allocate a large receive buffer for a pending packet. This function is called when + * an HTC packet arrives whose length exceeds a threshold value + * + * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to + * keep the allocation size the same to optimize cached-slab allocations. + * + * */ +static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length) +{ + HTC_PACKET *pPacket = NULL; + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + int refillCount = 0; + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length)); + + do { + + if (Length <= AR6000_BUFFER_SIZE) { + /* shouldn't be getting called on normal sized packets */ + A_ASSERT(FALSE); + break; + } + + if (Length > AR6000_AMSDU_BUFFER_SIZE) { + A_ASSERT(FALSE); + break; + } + + AR6000_SPIN_LOCK(&ar->arLock, 0); + /* allocate a packet from the list */ + pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue); + /* see if we need to refill again */ + refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (NULL == pPacket) { + break; + } + /* set actual endpoint ID */ + pPacket->Endpoint = Endpoint; + + } while (FALSE); + + if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) { + ar6000_refill_amsdu_rxbufs(ar,refillCount); + } + + return pPacket; +} + +static void +ar6000_set_multicast_list(struct net_device *dev) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) + int mc_count = dev->mc_count; + struct dev_mc_list *mc; + int j; +#else + int mc_count = netdev_mc_count(dev); + struct netdev_hw_addr *ha; +#endif + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + int i; + A_BOOL enableAll, disableAll; + enum { + IGNORE = 0, + MATCH = 1, + ADD = 2, + DELETE = 3 + } action[MAC_MAX_FILTERS_PER_LIST]; + A_BOOL mcValid; + A_UINT8 *mac; + A_UINT8 *filter; + A_BOOL filterValid; + + if (ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED) + return; + + enableAll = FALSE; + disableAll = FALSE; + + /* + * Enable receive all multicast, if + * 1. promiscous mode, + * 2. Allow all multicast + * 3. H/W supported filters is less than application requested filter + */ + if ((dev->flags & IFF_PROMISC) || + (dev->flags & IFF_ALLMULTI) || + (mc_count > MAC_MAX_FILTERS_PER_LIST)) + { + enableAll = TRUE; + } else { + /* Disable all multicast if interface has multicast disable or list is empty */ + if ((!(dev->flags & IFF_MULTICAST)) || (!mc_count)) { + disableAll = TRUE; + } + } + + /* + * Firmware behaviour + * enableAll - set filter to enable and delete valid filters + * disableAll - set filter to disable and delete valid filers + * filter - set valid filters + */ + + /* + * Pass 1: Mark all the valid filters to delete + */ + for (i=0; imcast_filters[i]; + filterValid = (filter[1] || filter[2]); + if (filterValid) { + action[i] = DELETE; + } else { + action[i] = IGNORE; + } + } + + if ((!enableAll) && (!disableAll)) { + /* + * Pass 2: Mark all filters which match the previous ones + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + for (j = 0, mc = dev->mc_list; mc && (j < dev->mc_count); + j++, mc = mc->next) { + mac = mc->dmi_addr; +#else + netdev_for_each_mc_addr(ha, dev) { + mac = ha->addr; +#endif + + mcValid = (mac[2] || mac[3] || mac[4] || mac[5]); + if (mcValid) { + for (i=0; imcast_filters[i]; + if ((A_MEMCMP(filter, &mac[0], AR_MCAST_FILTER_MAC_ADDR_SIZE)) == 0) { + action[i] = MATCH; + break; + } + } + } + } + + /* + * Delete old entries and free-up space for new additions + */ + for (i = 0; i < MAC_MAX_FILTERS_PER_LIST; i++) { + filter = arPriv->mcast_filters[i]; + if (action[i] == DELETE) { + A_PRINTF ("Delete Filter %d = %02x:%02x:%02x:%02x:%02x:%02x\n", + i, filter[0], filter[1], filter[2], filter[3], filter[4], filter[5]); + wmi_del_mcast_filter_cmd(arPriv->arWmi, filter); + A_MEMZERO(filter, AR_MCAST_FILTER_MAC_ADDR_SIZE); + /* Make this available for further additions */ + action[i] = IGNORE; + } + } + + /* + * Pass 3: Add new filters to empty slots + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + for (j = 0, mc = dev->mc_list; mc && (j < dev->mc_count); + j++, mc = mc->next) { +#else + netdev_for_each_mc_addr(ha, dev) { + +#endif + A_BOOL match; + A_INT32 free; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + mac = mc->dmi_addr; +#else + mac = ha->addr; +#endif + mcValid = (mac[2] || mac[3] || mac[4] || mac[5]); + if (mcValid) { + match = FALSE; + free = -1; + for (i=0; imcast_filters[i]; + if ((A_MEMCMP(filter, &mac[0], AR_MCAST_FILTER_MAC_ADDR_SIZE)) == 0) { + match = TRUE; + break; + } else if (action[i] != MATCH && action[i] != ADD) { + if (free == -1) { + free = i; // Mark the first free index + } + } + } + if ((!match) && (free != -1)) { + filter = arPriv->mcast_filters[free]; + A_MEMCPY(filter, &mac[0], AR_MCAST_FILTER_MAC_ADDR_SIZE); + action[free] = ADD; + } + } + } + } + + + for (i=0; imcast_filters[i]; + if (action[i] == DELETE) { + A_PRINTF ("Delete Filter %d = %02x:%02x:%02x:%02x:%02x:%02x\n", + i, filter[0], filter[1], filter[2], filter[3], filter[4], filter[5]); + wmi_del_mcast_filter_cmd(arPriv->arWmi, filter); + A_MEMZERO(filter, AR_MCAST_FILTER_MAC_ADDR_SIZE); + } else if (action[i] == ADD) { + A_PRINTF ("Add Filter %d = %02x:%02x:%02x:%02x:%02x:%02x\n", + i, filter[0], filter[1], filter[2], filter[3],filter[4],filter[5]); + wmi_set_mcast_filter_cmd(arPriv->arWmi, filter); + } else if (action[i] == MATCH) { + A_PRINTF ("Keep Filter %d = %02x:%02x:%02x:%02x:%02x:%02x\n", + i, filter[0], filter[1], filter[2], filter[3],filter[4],filter[5]); + } + } + + if (enableAll) { + /* target allow all multicast packets if fitler enable and fitler list is zero */ + wmi_mcast_filter_cmd(arPriv->arWmi, TRUE); + } else if (disableAll) { + /* target drop multicast packets if fitler disable and fitler list is zero */ + wmi_mcast_filter_cmd(arPriv->arWmi, FALSE); + } +} + +static struct net_device_stats * +ar6000_get_stats(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + return &arPriv->arNetStats; +} + +static struct iw_statistics * +ar6000_get_iwstats(struct net_device * dev) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + TARGET_STATS *pStats = &arPriv->arTargetStats; + struct iw_statistics * pIwStats = &arPriv->arIwStats; + int rtnllocked; + +#ifdef CONFIG_HOST_TCMD_SUPPORT + if (ar->bIsDestroyProgress || ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED || testmode) +#else + if (ar->bIsDestroyProgress || ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED) +#endif + { + pIwStats->status = 0; + pIwStats->qual.qual = 0; + pIwStats->qual.level =0; + pIwStats->qual.noise = 0; + pIwStats->discard.code =0; + pIwStats->discard.retries=0; + pIwStats->miss.beacon =0; + return pIwStats; + } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + /* + * The in_atomic function is used to determine if the scheduling is + * allowed in the current context or not. This was introduced in 2.6 + * From what I have read on the differences between 2.4 and 2.6, the + * 2.4 kernel did not support preemption and so this check might not + * be required for 2.4 kernels. + */ + if (in_atomic()) + { + if (wmi_get_stats_cmd(arPriv->arWmi) == A_OK) { + } + + pIwStats->status = 1 ; + pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; + pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ + pIwStats->qual.noise = pStats->noise_floor_calibation; + pIwStats->discard.code = pStats->rx_decrypt_err; + pIwStats->discard.retries = pStats->tx_retry_cnt; + pIwStats->miss.beacon = pStats->cs_bmiss_cnt; + return pIwStats; + } +#endif /* LINUX_VERSION_CODE */ + dev_hold(dev); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + rtnllocked = rtnl_is_locked(); +#else + rtnllocked = TRUE; +#endif + if (rtnllocked) { + rtnl_unlock(); + } + pIwStats->status = 0; + + if (down_interruptible(&ar->arSem)) { + goto err_exit; + } + + do { + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + break; + } + + arPriv->statsUpdatePending = TRUE; + + if(wmi_get_stats_cmd(arPriv->arWmi) != A_OK) { + break; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + if (signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : WMI get stats timeout \n")); + break; + } + pIwStats->status = 1 ; + pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; + pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ + pIwStats->qual.noise = pStats->noise_floor_calibation; + pIwStats->discard.code = pStats->rx_decrypt_err; + pIwStats->discard.retries = pStats->tx_retry_cnt; + pIwStats->miss.beacon = pStats->cs_bmiss_cnt; + } while (0); + up(&ar->arSem); + +err_exit: + if (rtnllocked) { + rtnl_lock(); + } + dev_put(dev); + return pIwStats; +} + +void +ar6000_ready_event(void *devt, A_UINT8 *datap, A_UINT8 phyCap, A_UINT32 sw_ver, A_UINT32 abi_ver) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + struct net_device *dev; + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UINT8 i, j, k; + + ar->arWmiReady = TRUE; + ar->arVersion.wlan_ver = sw_ver; + ar->arVersion.abi_ver = abi_ver; + wake_up(&arPriv->arEvent); + + for(i = 0; i < num_device ; i++) { + dev = ar6000_devices[i]; + arPriv = ar->arDev[i]; + arPriv->arPhyCapability = phyCap; + if (arPriv->arPhyCapability == WMI_11NAG_CAPABILITY){ + arPriv->phymode = DEF_AP_WMODE_AG; + } else { + arPriv->phymode = DEF_AP_WMODE_G; + } + A_MEMCPY(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN); + + if (i > 0) { + if(mac_addr_method) { + k = dev->dev_addr[5]; + dev->dev_addr[5] += i; + for(j=5; j>3; j--) { + if(dev->dev_addr[j] > k) { + break; + } + k = dev->dev_addr[j-1]; + dev->dev_addr[j-1]++; + } + } else { + dev->dev_addr[0] = (((dev->dev_addr[0]) ^ (1 << i))) | 0x02; + } + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("DEV%d mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", + i, dev->dev_addr[0], dev->dev_addr[1], + dev->dev_addr[2], dev->dev_addr[3], + dev->dev_addr[4], dev->dev_addr[5])); + +#ifdef AR6K_ENABLE_HCI_PAL + ar6k_hci_pal_info_t *pHciPalInfo = (ar6k_hci_pal_info_t *)ar->hcipal_info; + pHciPalInfo->hdev->bdaddr.b[0]=dev->dev_addr[5]; + pHciPalInfo->hdev->bdaddr.b[1]=dev->dev_addr[4]; + pHciPalInfo->hdev->bdaddr.b[2]=dev->dev_addr[3]; + pHciPalInfo->hdev->bdaddr.b[3]=dev->dev_addr[2]; + pHciPalInfo->hdev->bdaddr.b[4]=dev->dev_addr[1]; + pHciPalInfo->hdev->bdaddr.b[5]=dev->dev_addr[0]; + +#endif + +#if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN + wmi_pmparams_cmd(arPriv->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN); +#endif +#if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP + wmi_set_lpreamble_cmd(arPriv->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP); +#endif + + wmi_set_keepalive_cmd(arPriv->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL); + +#if WLAN_CONFIG_DISABLE_11N + { + WMI_SET_HT_CAP_CMD htCap; + + A_MEMZERO(&htCap, sizeof(WMI_SET_HT_CAP_CMD)); + htCap.band = 0; + wmi_set_ht_cap_cmd(arPriv->arWmi, &htCap); + + htCap.band = 1; + wmi_set_ht_cap_cmd(arPriv->arWmi, &htCap); + } +#endif /* WLAN_CONFIG_DISABLE_11N */ + +#ifdef ATH6K_CONFIG_OTA_MODE + wmi_powermode_cmd(arPriv->arWmi, MAX_PERF_POWER); +#endif + wmi_disctimeout_cmd(arPriv->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT); + } +} + +void +add_new_sta(AR_SOFTC_DEV_T *arPriv, A_UINT8 *mac, A_UINT16 aid, A_UINT8 *wpaie, + A_UINT8 ielen, A_UINT8 keymgmt, A_UINT8 ucipher, A_UINT8 auth, A_UINT8 wmode, A_UINT8 apsd_info) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + A_UINT8 free_slot=aid-1; + + A_MEMCPY(ar->connTbl[free_slot].mac, mac, ATH_MAC_LEN); + A_MEMCPY(ar->connTbl[free_slot].wpa_ie, wpaie, ielen); + ar->connTbl[free_slot].arPriv = arPriv; + ar->connTbl[free_slot].aid = aid; + ar->connTbl[free_slot].keymgmt = keymgmt; + ar->connTbl[free_slot].ucipher = ucipher; + ar->connTbl[free_slot].auth = auth; + ar->connTbl[free_slot].wmode = wmode; + ar->connTbl[free_slot].apsd_info= apsd_info; + ar->arAPStats[free_slot].aid = aid; + A_MEMZERO(ar->connTbl[free_slot].ba_state, 8); + arAp->sta_list_index = arAp->sta_list_index | (1 << free_slot); + aggr_reset_state(ar->connTbl[free_slot].conn_aggr, (void *) arPriv->arNetDev); +} + +void +ar6000_connect_event(AR_SOFTC_DEV_T *arPriv, WMI_CONNECT_EVENT *pEvt) +{ + union iwreq_data wrqu; + int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos; + static const char *tag1 = "ASSOCINFO(ReqIEs="; + static const char *tag2 = "ASSOCRESPIE="; + static const char *beaconIetag = "BEACONIE="; + char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1]; + char *pos; + A_UINT8 key_op_ctrl; + unsigned long flags; + struct ieee80211req_key *ik; + CRYPTO_TYPE keyType = NONE_CRYPT; + AR_SOFTC_STA_T *arSta; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_DEV_T *arTempPriv = NULL; + struct ieee80211_frame *wh; + A_UINT8 *frm, *efrm, *ssid, *rates, *xrates, *wpaie, wpaLen=0; + A_UINT16 subtype; + A_UINT8 beaconIeLen; + A_UINT8 assocReqLen; + A_UINT8 assocRespLen; + A_UINT8 *assocInfo; + A_UINT8 *bssid; + + beaconIeLen = pEvt->beaconIeLen; + assocReqLen = pEvt->assocReqLen; + assocRespLen = pEvt->assocRespLen; + assocInfo = pEvt->assocInfo; + + /* BSSID and MAC_ADDR is in the same location for all modes */ + bssid = pEvt->u.infra_ibss_bss.bssid; + + if(arPriv->arNetworkType & AP_NETWORK) { + struct net_device *dev = arPriv->arNetDev; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + A_UINT8 aid, wmode, keymgmt, auth_alg; + + if(A_MEMCMP(dev->dev_addr, bssid, ATH_MAC_LEN)==0) { + arPriv->arBssChannel = pEvt->u.ap_bss.channel; + ik = &arAp->ap_mode_bkey; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AP%d: [UP] SSID %s MAC %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", + arPriv->arDeviceIndex, arPriv->arSsid, + bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5])); +#ifdef P2P + if(arPriv->arNetworkSubType == SUBTYPE_P2PDEV) + arPriv->arNetworkSubType = SUBTYPE_P2PGO; +#endif + + switch(arPriv->arAuthMode) { + case WMI_NONE_AUTH: +#ifdef WAPI_ENABLE + if(arPriv->arPairwiseCrypto == WAPI_CRYPT) { + ap_set_wapi_key(arPriv, ik); + } +#endif + break; + case WMI_WPA_PSK_AUTH: + case WMI_WPA2_PSK_AUTH: + case (WMI_WPA_PSK_AUTH|WMI_WPA2_PSK_AUTH): + switch (ik->ik_type) { + case IEEE80211_CIPHER_TKIP: + keyType = TKIP_CRYPT; + break; + case IEEE80211_CIPHER_AES_CCM: + keyType = AES_CRYPT; + break; + default: + goto skip_key; + } + + wmi_addKey_cmd(arPriv->arWmi, ik->ik_keyix, keyType, GROUP_USAGE, + ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc, + ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, + SYNC_BOTH_WMIFLAG); + + break; + } +skip_key: + wmi_bssfilter_cmd(arPriv->arWmi, NONE_BSS_FILTER, 0); + + arPriv->arConnected = TRUE; + return; + } + + wh = (struct ieee80211_frame *) (assocInfo + beaconIeLen); + subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; + frm = (A_UINT8 *)&wh[1]; + efrm = assocInfo + beaconIeLen + assocReqLen; + + /* capability information */ + frm += 2; + + /* listen int */ + frm += 2; + + /* Reassoc will have current AP addr field */ + if(subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { + frm += 6; + } + + ssid = rates = xrates = wpaie = NULL; + while (frm < efrm) { + switch (*frm) { +/* currently unused */ +/* + case IEEE80211_ELEMID_SSID: + ssid = frm; + break; + case IEEE80211_ELEMID_RATES: + rates = frm; + break; + case IEEE80211_ELEMID_XRATES: + xrates = frm; + break; +*/ + case IEEE80211_ELEMID_VENDOR: + if( (frm[1] > 3) && (frm[2] == 0x00) && (frm[3] == 0x50) && + (frm[4] == 0xF2) && ((frm[5] == 0x01) || (frm[5] == 0x04)) ) + { + wpaie = frm; + wpaLen = wpaie[1]+2; + } + break; + case IEEE80211_ELEMID_RSN: + wpaie = frm; + wpaLen = wpaie[1]+2; + break; + } + frm += frm[1] + 2; + } + + aid = pEvt->u.ap_sta.aid; + wmode = pEvt->u.ap_sta.phymode; + keymgmt = pEvt->u.ap_sta.keymgmt; + auth_alg = pEvt->u.ap_sta.auth; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n " + " AID=%d AUTH=%d WMODE=%d KEYMGMT=%d CIPHER=%d APSD=%x\n", + pEvt->u.ap_sta.mac_addr[0], pEvt->u.ap_sta.mac_addr[1], pEvt->u.ap_sta.mac_addr[2], + pEvt->u.ap_sta.mac_addr[3], pEvt->u.ap_sta.mac_addr[4], pEvt->u.ap_sta.mac_addr[5], + aid, auth_alg, wmode, keymgmt, pEvt->u.ap_sta.cipher, pEvt->u.ap_sta.apsd_info)); + + add_new_sta(arPriv, pEvt->u.ap_sta.mac_addr, aid, wpaie, wpaLen, keymgmt, + pEvt->u.ap_sta.cipher, auth_alg, wmode, pEvt->u.ap_sta.apsd_info); + + /* Send event to application */ + A_MEMZERO(&wrqu, sizeof(wrqu)); + A_MEMCPY(wrqu.addr.sa_data, pEvt->u.ap_sta.mac_addr, ATH_MAC_LEN); + wireless_send_event(arPriv->arNetDev, IWEVREGISTERED, &wrqu, NULL); + /* In case the queue is stopped when we switch modes, this will + * wake it up + */ + netif_wake_queue(arPriv->arNetDev); + return; + } + arSta = &arPriv->arSta; +#ifdef ATH6K_CONFIG_CFG80211 + ar6k_cfg80211_connect_event(arPriv, pEvt->u.infra_ibss_bss.channel, bssid, + pEvt->u.infra_ibss_bss.listenInterval, pEvt->u.infra_ibss_bss.beaconInterval, + pEvt->u.infra_ibss_bss.networkType, beaconIeLen, + assocReqLen, assocRespLen, + assocInfo); +#endif /* ATH6K_CONFIG_CFG80211 */ + + A_MEMCPY(arPriv->arBssid, bssid, sizeof(arPriv->arBssid)); + arPriv->arBssChannel = pEvt->u.infra_ibss_bss.channel; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 connected event on freq %d ", pEvt->u.infra_ibss_bss.channel)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " + " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d" + " assocRespLen =%d\n", + bssid[0], bssid[1], bssid[2], + bssid[3], bssid[4], bssid[5], + pEvt->u.infra_ibss_bss.listenInterval, pEvt->u.infra_ibss_bss.beaconInterval, + beaconIeLen, assocReqLen, assocRespLen)); + if (pEvt->u.infra_ibss_bss.networkType & ADHOC_NETWORK) { + /* Disable BG Scan for ADHOC NETWORK */ + wmi_scanparams_cmd(arPriv->arWmi, 0, 0, + 0xFFFF, 0, 0, 0, WMI_SHORTSCANRATIO_DEFAULT,DEFAULT_SCAN_CTRL_FLAGS, 0, 0); + if (pEvt->u.infra_ibss_bss.networkType & ADHOC_CREATOR) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Network: Adhoc (Creator)\n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Network: Adhoc (Joiner)\n")); + } + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Network: Infrastructure\n")); + } + + if ((arPriv->arNetworkType == INFRA_NETWORK)) { + if (arSta->arConnectPending) { + wmi_listeninterval_cmd(arPriv->arWmi, arSta->arListenIntervalT, arSta->arListenIntervalB); + } + } +#ifdef P2P + if(arPriv->arNetworkSubType == SUBTYPE_P2PDEV) + arPriv->arNetworkSubType = SUBTYPE_P2PCLIENT; +#endif + + if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= ")); + + beacon_ie_pos = 0; + A_MEMZERO(buf, sizeof(buf)); + sprintf(buf, "%s", beaconIetag); + pos = buf + 9; + for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); + sprintf(pos, "%2.2x", assocInfo[i]); + pos += 2; + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(buf); + if (wrqu.data.length <= IW_CUSTOM_MAX) { + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Fail to send BeaconIEs to upper layer\n")); + } + } + + if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2)))) + { + assoc_resp_ie_pos = beaconIeLen + assocReqLen + + sizeof(A_UINT16) + /* capinfo*/ + sizeof(A_UINT16) + /* status Code */ + sizeof(A_UINT16) ; /* associd */ + A_MEMZERO(buf, sizeof(buf)); + sprintf(buf, "%s", tag2); + pos = buf + 12; + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= ")); + /* + * The Association Response Frame w.o. the WLAN header is delivered to + * the host, so skip over to the IEs + */ + for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++) + { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); + sprintf(pos, "%2.2x", assocInfo[i]); + pos += 2; + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(buf); + if (wrqu.data.length <= IW_CUSTOM_MAX) { + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + } else { +#if (WIRELESS_EXT >= 18) + wrqu.data.length = (assocRespLen - 6); + wireless_send_event(arPriv->arNetDev, IWEVASSOCRESPIE, &wrqu, &assocInfo[assoc_resp_ie_pos]); +#else + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Fail to send Association Response to upper layer\n")); +#endif + } + } + + if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) { + /* + * assoc Request includes capability and listen interval. Skip these. + */ + assoc_req_ie_pos = beaconIeLen + + sizeof(A_UINT16) + /* capinfo*/ + sizeof(A_UINT16); /* listen interval */ + + A_MEMZERO(buf, sizeof(buf)); + sprintf(buf, "%s", tag1); + pos = buf + 17; + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= ")); + for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); + sprintf(pos, "%2.2x", assocInfo[i]); + pos += 2;; + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(buf); + if (wrqu.data.length <= IW_CUSTOM_MAX) { + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + } else { +#if (WIRELESS_EXT >= 18) + wrqu.data.length = (assocReqLen - 4); + wireless_send_event(arPriv->arNetDev, IWEVASSOCREQIE, &wrqu, &assocInfo[assoc_req_ie_pos]); +#else + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Fail to send Association Request to upper layer\n")); +#endif + } + } + +#ifdef USER_KEYS + if (arSta->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN && + arSta->user_saved_keys.keyOk == TRUE) + { + key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC; + + if (arSta->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) { + key_op_ctrl &= ~KEY_OP_INIT_RSC; + } else { + key_op_ctrl |= KEY_OP_INIT_RSC; + } + ar6000_reinstall_keys(arPriv, key_op_ctrl); + } +#endif /* USER_KEYS */ + + netif_wake_queue(arPriv->arNetDev); + + /* For CFG80211 the key configuration and the default key comes in after connect so no point in plumbing invalid keys */ +#ifndef ATH6K_CONFIG_CFG80211 + if ((pEvt->u.infra_ibss_bss.networkType & ADHOC_NETWORK) && + (OPEN_AUTH == arPriv->arDot11AuthMode) && + (WMI_NONE_AUTH == arPriv->arAuthMode) && + (WEP_CRYPT == arPriv->arPairwiseCrypto)) + { + if (!arPriv->arConnected) { + wmi_addKey_cmd(arPriv->arWmi, + arPriv->arDefTxKeyIndex, + WEP_CRYPT, + GROUP_USAGE | TX_USAGE, + arPriv->arWepKeyList[arPriv->arDefTxKeyIndex].arKeyLen, + NULL, + arPriv->arWepKeyList[arPriv->arDefTxKeyIndex].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + } +#endif /* ATH6K_CONFIG_CFG80211 */ + + /* Update connect & link status atomically */ + spin_lock_irqsave(&arPriv->arPrivLock, flags); + arPriv->arConnected = TRUE; + arSta->arConnectPending = FALSE; + netif_carrier_on(arPriv->arNetDev); + spin_unlock_irqrestore(&arPriv->arPrivLock, flags); + /* reset the rx aggr state */ + aggr_reset_state(arPriv->conn_aggr, (void *) arPriv->arNetDev); + reconnect_flag = 0; + + A_MEMZERO(&wrqu, sizeof(wrqu)); + A_MEMCPY(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN); + wrqu.addr.sa_family = ARPHRD_ETHER; + wireless_send_event(arPriv->arNetDev, SIOCGIWAP, &wrqu, NULL); + if ((arPriv->arNetworkType == ADHOC_NETWORK) && arSta->arIbssPsEnable) { + A_MEMZERO(arSta->arNodeMap, sizeof(arSta->arNodeMap)); + arSta->arNodeNum = 0; + arSta->arNexEpId = ENDPOINT_2; + } + if (!arSta->arUserBssFilter) { + wmi_bssfilter_cmd(arPriv->arWmi, NONE_BSS_FILTER, 0); + } + /* AP-STA Concurrency */ + if(ar->arHoldConnection){ + for(i=0;i < ar->arConfNumDev;i++) { + arTempPriv = ar->arDev[i]; + if((AP_NETWORK == arTempPriv->arNetworkType)){ + arTempPriv->arBssChannel = arTempPriv->arChannelHint = 0; + } + } + A_TIMEOUT_MS(&ar->ap_reconnect_timer, 1*1000, 0); + } +} + +void ar6000_set_numdataendpts(AR_SOFTC_DEV_T *arPriv, A_UINT32 num) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1)); + ar->arNumDataEndPts = num; +} + +void +sta_cleanup(AR_SOFTC_DEV_T *arPriv, A_UINT8 i) +{ + struct sk_buff *skb; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + + /* empty the queued pkts in the PS queue if any */ + A_MUTEX_LOCK(&ar->connTbl[i].psqLock); + while (!A_NETBUF_QUEUE_EMPTY(&ar->connTbl[i].psq)) { + skb = A_NETBUF_DEQUEUE(&ar->connTbl[i].psq); + A_NETBUF_FREE(skb); + } + while (!A_NETBUF_QUEUE_EMPTY(&ar->connTbl[i].apsdq)) { + skb = A_NETBUF_DEQUEUE(&ar->connTbl[i].apsdq); + A_NETBUF_FREE(skb); + } + A_MUTEX_UNLOCK(&ar->connTbl[i].psqLock); + + /* Zero out the state fields */ + A_MEMZERO(&ar->arAPStats[i], sizeof(WMI_PER_STA_STAT)); + A_MEMZERO(&ar->connTbl[i].mac, ATH_MAC_LEN); + A_MEMZERO(&ar->connTbl[i].wpa_ie, IEEE80211_MAX_IE); + ar->connTbl[i].aid = 0; + ar->connTbl[i].flags = 0; + ar->connTbl[i].arPriv = NULL; + + arAp->sta_list_index =arAp->sta_list_index & ~(1 << i); + aggr_reset_state(ar->connTbl[i].conn_aggr, NULL); +} + +void +ar6000_ap_cleanup(AR_SOFTC_DEV_T *arPriv) +{ + A_UINT8 ctr; + struct sk_buff *skb; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("DEL ALL STA\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AP%d: [DOWN] SSID %s\n", arPriv->arDeviceIndex, arPriv->arSsid)); + + for (ctr=0; ctr < NUM_CONN; ctr++) { + if(ar->connTbl[ctr].arPriv == arPriv) { + remove_sta(arPriv, ar->connTbl[ctr].mac, 0); + } + } + A_MUTEX_LOCK(&arAp->mcastpsqLock); + while (!A_NETBUF_QUEUE_EMPTY(&arAp->mcastpsq)) { + skb = A_NETBUF_DEQUEUE(&arAp->mcastpsq); + A_NETBUF_FREE(skb); + } + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + arPriv->arConnected = FALSE; +} + +A_UINT8 +remove_sta(AR_SOFTC_DEV_T *arPriv, A_UINT8 *mac, A_UINT16 reason) +{ + A_UINT8 i, removed=0; + AR_SOFTC_T *ar = arPriv->arSoftc; + union iwreq_data wrqu; + struct sk_buff *skb; + + if(IS_MAC_NULL(mac)) { + return removed; + } + + if(reason == AP_DISCONNECT_MAX_STA) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("MAX STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", mac[0], + mac[1], mac[2], mac[3], mac[4], mac[5])); + return removed; + } else if(reason == AP_DISCONNECT_ACL) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ACL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", mac[0], + mac[1], mac[2], mac[3], mac[4], mac[5])); + return removed; + } + + for(i=0; i < NUM_CONN; i++) { + if(A_MEMCMP(ar->connTbl[i].mac, mac, ATH_MAC_LEN)==0) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " + " aid=%d REASON=%d\n", mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5], ar->connTbl[i].aid, reason)); + + sta_cleanup(arPriv, i); + removed = 1; + + /* Send event to application */ + A_MEMZERO(&wrqu, sizeof(wrqu)); + A_MEMCPY(wrqu.addr.sa_data, mac, ATH_MAC_LEN); + wireless_send_event(arPriv->arNetDev, IWEVEXPIRED, &wrqu, NULL); + + break; + } + } + + /* If there are no more associated STAs, empty the mcast PS q */ + if (arPriv->arAp.sta_list_index == 0) { + A_MUTEX_LOCK(&arPriv->arAp.mcastpsqLock); + while (!A_NETBUF_QUEUE_EMPTY(&arPriv->arAp.mcastpsq)) { + skb = A_NETBUF_DEQUEUE(&arPriv->arAp.mcastpsq); + A_NETBUF_FREE(skb); + } + A_MUTEX_UNLOCK(&arPriv->arAp.mcastpsqLock); + + /* Clear the LSB of the BitMapCtl field of the TIM IE */ + if (ar->arWmiReady) { + wmi_set_pvb_cmd(arPriv->arWmi, MCAST_AID, 0); + } + } + + return removed; +} + +void +ar6000_disconnect_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 reason, A_UINT8 *bssid, + A_UINT8 assocRespLen, A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus) +{ + A_UINT8 i; + unsigned long flags; + union iwreq_data wrqu; + AR_SOFTC_T *ar = arPriv->arSoftc; + A_BOOL bt30Devfound = FALSE; +#ifdef P2P + if((arPriv->arNetworkSubType == SUBTYPE_P2PCLIENT) || (arPriv->arNetworkSubType == SUBTYPE_P2PGO) + || (arPriv->arNetworkSubType == SUBTYPE_P2PDEV)){ + if(!(IS_MAC_BCAST(bssid))) + p2p_clear_peers_authorized_flag(arPriv->p2p_ctx, bssid); + } +#endif + + if(arPriv->arNetworkType & AP_NETWORK) { + if(IS_MAC_BCAST(bssid)) { + ar6000_ap_cleanup(arPriv); +#ifdef P2P + if(arPriv->arNetworkSubType == SUBTYPE_P2PGO) { + arPriv->arNextMode = INFRA_NETWORK; + ar6000_init_mode_info(arPriv); + arPriv->arNetworkType = INFRA_NETWORK; + arPriv->arNetworkSubType = SUBTYPE_P2PDEV; + } +#endif + } else { + remove_sta(arPriv, bssid, protocolReasonStatus); + } + return; + } + +#ifdef ATH6K_CONFIG_CFG80211 + ar6k_cfg80211_disconnect_event(arPriv, reason, bssid, + assocRespLen, assocInfo, + protocolReasonStatus); +#endif /* ATH6K_CONFIG_CFG80211 */ + + /* Send disconnect event to supplicant */ + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.addr.sa_family = ARPHRD_ETHER; + wireless_send_event(arPriv->arNetDev, SIOCGIWAP, &wrqu, NULL); + + /* it is necessary to clear the host-side rx aggregation state */ + aggr_reset_state(arPriv->conn_aggr, NULL); + + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 disconnected")); + if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", + bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5])); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Disconnect Reason is %d, Status Code is %d", reason, protocolReasonStatus)); + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason)); + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus)); + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s", + assocRespLen ? " " : "NULL")); + for (i = 0; i < assocRespLen; i++) { + if (!(i % 0x10)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); + /* + * If the event is due to disconnect cmd from the host, only they the target + * would stop trying to connect. Under any other condition, target would + * keep trying to connect. + * + */ + if( reason == DISCONNECT_CMD) + { + if ((!arPriv->arSta.arUserBssFilter) && (ar->arWmiReady)) { + wmi_bssfilter_cmd(arPriv->arWmi, NONE_BSS_FILTER, 0); + } + } else { + arPriv->arSta.arConnectPending = TRUE; + if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) || + ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) { + arPriv->arConnected = TRUE; + return; + } + } + + if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady)) + { + bss_t *pWmiSsidnode = NULL; + + /* remove the current associated bssid node */ + wmi_free_node (arPriv->arWmi, bssid); + + /* + * In case any other same SSID nodes are present + * remove it, since those nodes also not available now + */ + do + { + /* + * Find the nodes based on SSID and remove it + * NOTE :: This case will not work out for Hidden-SSID + */ + pWmiSsidnode = wmi_find_Ssidnode (arPriv->arWmi, arPriv->arSsid, arPriv->arSsidLen, FALSE, TRUE); + + if (pWmiSsidnode) + { + wmi_free_node (arPriv->arWmi, pWmiSsidnode->ni_macaddr); + } + + }while (pWmiSsidnode); + } + + /* Update connect & link status atomically */ + spin_lock_irqsave(&arPriv->arPrivLock, flags); + + arPriv->arConnected = FALSE; + netif_carrier_off(arPriv->arNetDev); + spin_unlock_irqrestore(&arPriv->arPrivLock, flags); +#ifdef P2P + if(arPriv->arNetworkSubType == SUBTYPE_P2PCLIENT) { + arPriv->arNextMode = INFRA_NETWORK; + ar6000_init_mode_info(arPriv); + arPriv->arNetworkType = INFRA_NETWORK; + arPriv->arNetworkSubType = SUBTYPE_P2PDEV; + } +#endif + + if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) { + reconnect_flag = 0; + } + +#ifdef USER_KEYS + if (reason != CSERV_DISCONNECT) + { + arPriv->arSta.user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; + arPriv->arSta.user_key_ctrl = 0; + } +#endif /* USER_KEYS */ + + netif_stop_queue(arPriv->arNetDev); + A_MEMZERO(arPriv->arBssid, sizeof(arPriv->arBssid)); + arPriv->arBssChannel = 0; + arPriv->arSta.arBeaconInterval = 0; + + for (i=0; i < num_device; i++) { + AR_SOFTC_DEV_T *temparPriv; + temparPriv = ar->arDev[i]; + if (temparPriv->isBt30amp == TRUE) { + bt30Devfound = TRUE; + } + } + if (bt30Devfound == FALSE) { + ar6000_TxDataCleanup(ar); + } + /* AP-STA Concurrency */ + if(ar->arHoldConnection){ + A_TIMEOUT_MS(&ar->ap_reconnect_timer, 2*1000, 0); + } + + if (arPriv->arNetworkType == ADHOC_NETWORK){ + /* Reset Scan params to default */ + wmi_scanparams_cmd(arPriv->arWmi, 0, 0, + 60, 0, 0, 0, WMI_SHORTSCANRATIO_DEFAULT,DEFAULT_SCAN_CTRL_FLAGS, 0, 0); + } +} + +void +ar6000_regDomain_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 regCode) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 Reg Code = 0x%x\n", regCode)); + arPriv->arRegCode = regCode; +} + +#ifdef ATH_AR6K_11N_SUPPORT +#define BA_EVT_GET_CONNID(a) ((a)>>4) +#define BA_EVT_GET_TID(b) ((b)&0xF) + +void +ar6000_aggr_rcv_addba_req_evt(AR_SOFTC_DEV_T *arPriv, WMI_ADDBA_REQ_EVENT *evt) +{ + A_UINT8 connid = BA_EVT_GET_CONNID(evt->tid); + A_UINT8 tid = BA_EVT_GET_TID(evt->tid); + conn_t *conn = ieee80211_find_conn_for_aid(arPriv, connid); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ADDBA REQ: tid=%d, connid=%d, status=%d, win_sz=%d\n", tid, connid, evt->status, evt->win_sz)); + if(((arPriv->arNetworkType == INFRA_NETWORK) || (conn != NULL)) && evt->status == 0) { + aggr_recv_addba_req_evt(get_aggr_ctx(arPriv, conn), tid, evt->st_seq_no, evt->win_sz); + } +} + +void +ar6000_aggr_rcv_addba_resp_evt(AR_SOFTC_DEV_T *arPriv, WMI_ADDBA_RESP_EVENT *evt) +{ + A_UINT8 connid = BA_EVT_GET_CONNID(evt->tid); + A_UINT8 tid = BA_EVT_GET_TID(evt->tid); + conn_t *conn = ieee80211_find_conn_for_aid(arPriv, connid); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ADDBA RSP: tid=%d, connid=%d, status=%d, sz=%d\n", tid, connid, evt->status, evt->amsdu_sz)); + if(conn) { + conn->ba_state[tid] = 0x80; + } + if(evt->status == 0) { + } +} + +void +ar6000_aggr_rcv_delba_req_evt(AR_SOFTC_DEV_T *arPriv, WMI_DELBA_EVENT *evt) +{ + A_UINT8 connid = BA_EVT_GET_CONNID(evt->tid); + A_UINT8 tid = BA_EVT_GET_TID(evt->tid); + conn_t *conn = ieee80211_find_conn_for_aid(arPriv, connid); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("DELBA REQ: tid=%d, connid=%d\n", tid, connid)); + if((arPriv->arNetworkType == INFRA_NETWORK) || (conn != NULL)) { + aggr_recv_delba_req_evt(get_aggr_ctx(arPriv, conn), tid); + } +} +#endif + +void register_pal_cb(ar6k_pal_config_t *palConfig_p) +{ + ar6k_pal_config_g = *palConfig_p; +} + +void +ar6000_hci_event_rcv_evt(AR_SOFTC_DEV_T *arPriv, WMI_HCI_EVENT *cmd) +{ + void *osbuf = NULL; + A_INT8 i; + A_UINT8 size, *buf; + A_STATUS ret = A_OK; + + size = cmd->evt_buf_sz + 4; + osbuf = A_NETBUF_ALLOC(size); + if (osbuf == NULL) { + ret = A_NO_MEMORY; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error in allocating netbuf \n")); + return; + } + + A_NETBUF_PUT(osbuf, size); + buf = (A_UINT8 *)A_NETBUF_DATA(osbuf); + /* First 2-bytes carry HCI event/ACL data type + * the next 2 are free + */ + *((short *)buf) = WMI_HCI_EVENT_EVENTID; + buf += sizeof(int); + A_MEMCPY(buf, cmd->buf, cmd->evt_buf_sz); + + if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) + { + /* pass the cmd packet to PAL driver */ + if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(arPriv->hcipal_info, osbuf) == TRUE) + return; + } + ar6000_deliver_frames_to_nw_stack(arPriv->arNetDev, osbuf); + if(loghci) { + A_PRINTF_LOG("HCI Event From PAL <-- \n"); + for(i = 0; i < cmd->evt_buf_sz; i++) { + A_PRINTF_LOG("0x%02x ", cmd->buf[i]); + if((i % 10) == 0) { + A_PRINTF_LOG("\n"); + } + } + A_PRINTF_LOG("\n"); + A_PRINTF_LOG("==================================\n"); + } +} + +void +ar6000_neighborReport_event(AR_SOFTC_DEV_T *arPriv, int numAps, WMI_NEIGHBOR_INFO *info) +{ +#if WIRELESS_EXT >= 18 + struct iw_pmkid_cand *pmkcand; +#else /* WIRELESS_EXT >= 18 */ + static const char *tag = "PRE-AUTH"; + char buf[128]; +#endif /* WIRELESS_EXT >= 18 */ + + union iwreq_data wrqu; + int i; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 Neighbor Report Event\n")); + for (i=0; i < numAps; info++, i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", + info->bssid[0], info->bssid[1], info->bssid[2], + info->bssid[3], info->bssid[4], info->bssid[5])); + if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("preauth-cap")); + } + if (info->bssFlags & WMI_PMKID_VALID_BSS) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" pmkid-valid\n")); + continue; /* we skip bss if the pmkid is already valid */ + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\n")); + A_MEMZERO(&wrqu, sizeof(wrqu)); +#if WIRELESS_EXT >= 18 + pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand)); + A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand)); + pmkcand->index = i; + pmkcand->flags = info->bssFlags; + A_MEMCPY(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN); + wrqu.data.length = sizeof(struct iw_pmkid_cand); + wireless_send_event(arPriv->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand); + A_FREE(pmkcand); +#else /* WIRELESS_EXT >= 18 */ + snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", + tag, + info->bssid[0], info->bssid[1], info->bssid[2], + info->bssid[3], info->bssid[4], info->bssid[5], + i, info->bssFlags); + wrqu.data.length = strlen(buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +#endif /* WIRELESS_EXT >= 18 */ + } +} + +void +ar6000_indicate_proberesp(AR_SOFTC_DEV_T *arPriv , A_UINT8* pData , A_UINT16 len ,A_UINT8* bssid) +{ +} + +void +ar6000_indicate_beacon(AR_SOFTC_DEV_T *arPriv, A_UINT8* pData , A_UINT16 len ,A_UINT8* bssid) +{ +} + +void +ar6000_assoc_req_report_event (void *context, A_UINT8 status, A_UINT8 rspType, A_UINT8* pData, int len) +{ +} + +#ifdef ATH_SUPPORT_DFS + +void ar6000_dfs_attach_event(AR_SOFTC_DEV_T *arPriv, WMI_DFS_HOST_ATTACH_EVENT *capinfo) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + arAp->pDfs = dfs_attach_host(arPriv, NULL, capinfo); + if(arAp->pDfs) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\nDFS host attached\n")); + } + else + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\nDFS host ptr NULL\n")); + } +} + +void ar6000_dfs_init_event(AR_SOFTC_DEV_T *arPriv, WMI_DFS_HOST_INIT_EVENT *info) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_init_radar_filters_host(arAp->pDfs, info); +} + +void ar6000_dfs_phyerr_event(AR_SOFTC_DEV_T *arPriv, WMI_DFS_PHYERR_EVENT *info) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_process_phyerr_host(arAp->pDfs, info); +} + +void ar6000_dfs_reset_delaylines_event(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_reset_alldelaylines(arAp->pDfs); +} + +void ar6000_dfs_reset_radarq_event(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_reset_radarq(arAp->pDfs); +} + +void ar6000_dfs_reset_ar_event(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_reset_ar(arAp->pDfs); +} + +void ar6000_dfs_reset_arq_event(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_reset_arq(arAp->pDfs); +} + +void ar6000_dfs_set_dur_multiplier_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 value) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_set_dur_multiplier(arAp->pDfs, value); +} + +void ar6000_dfs_set_bangradar_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 value) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_bangradar_enable(arAp->pDfs, value); +} + +void ar6000_dfs_set_debuglevel_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 value) +{ + AR_SOFTC_AP_T *arAp=&arPriv->arAp; + dfs_set_debug_level_host(arAp->pDfs, value); +} + +A_STATUS ar6000_dfs_set_maxpulsedur_cmd(AR_SOFTC_DEV_T *arPriv, A_UINT32 value) +{ + return wmi_set_dfs_maxpulsedur_cmd(arPriv->arWmi, value); +} + +A_STATUS ar6000_dfs_radar_detected_cmd(AR_SOFTC_DEV_T *arPriv, A_INT16 chan_index, A_INT8 bang_radar) +{ + return wmi_radarDetected_cmd(arPriv->arWmi, chan_index, bang_radar); +} + +A_STATUS ar6000_dfs_set_minrssithresh_cmd(AR_SOFTC_DEV_T *arPriv, A_INT32 rssi) +{ + return wmi_set_dfs_minrssithresh_cmd(arPriv->arWmi, rssi); +} + +#endif /* ATH_SUPPORT_DFS */ + +void +ar6000_tkip_micerr_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 keyid, A_BOOL ismcast) +{ + static const char *tag = "MLME-MICHAELMICFAILURE.indication"; + char buf[128]; + union iwreq_data wrqu; + + /* + * For AP case, keyid will have aid of STA which sent pkt with + * MIC error. Use this aid to get MAC & send it to hostapd. + */ + if (arPriv->arNetworkType == AP_NETWORK) { + conn_t *s = ieee80211_find_conn_for_aid(arPriv, (keyid >> 2)); + if(!s){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid)); + return; + } + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AP TKIP MIC error received from aid=%d\n", keyid)); + snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", + tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]); + } else { + +#ifdef ATH6K_CONFIG_CFG80211 + ar6k_cfg80211_tkip_micerr_event(arPriv, keyid, ismcast); +#endif /* ATH6K_CONFIG_CFG80211 */ + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6000 TKIP MIC error received for keyid %d %scast\n", + keyid & 0x3, ismcast ? "multi": "uni")); + snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3, + ismcast ? "mult" : "un"); + } + + memset(&wrqu, 0, sizeof(wrqu)); + wrqu.data.length = strlen(buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +void +ar6000_scanComplete_event(AR_SOFTC_DEV_T *arPriv, A_STATUS status) +{ + +#ifdef ATH6K_CONFIG_CFG80211 + ar6k_cfg80211_scanComplete_event(arPriv, status); +#endif /* ATH6K_CONFIG_CFG80211 */ + + if (arPriv->arSoftc->arWmiReady && arPriv->arSoftc->arWlanState==WLAN_ENABLED) { + if (!arPriv->arSta.arUserBssFilter) { + wmi_bssfilter_cmd(arPriv->arWmi, NONE_BSS_FILTER, 0); + } + } + if (arPriv->arSta.scan_triggered) { + union iwreq_data wrqu; + A_MEMZERO(&wrqu, sizeof(wrqu)); + wireless_send_event(arPriv->arNetDev, SIOCGIWSCAN, &wrqu, NULL); + arPriv->arSta.scan_triggered = 0; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,( "AR6000 scan complete: %d\n", status)); +} + +void +ar6000_targetStats_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *ptr, A_UINT32 len) +{ + A_UINT8 ac, i; + + if(arPriv->arNetworkType == AP_NETWORK) { + WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr; + WMI_PER_STA_STAT *ap = arPriv->arSoftc->arAPStats; + + if (len < sizeof(*p)) { + return; + } + + for(ac=0;acsta[ac].aid == 0) { + continue; + } + i = p->sta[ac].aid-1; + + ap[i].tx_bytes += p->sta[ac].tx_bytes; + ap[i].tx_pkts += p->sta[ac].tx_pkts; + ap[i].tx_error += p->sta[ac].tx_error; + ap[i].tx_discard += p->sta[ac].tx_discard; + ap[i].rx_bytes += p->sta[ac].rx_bytes; + ap[i].rx_pkts += p->sta[ac].rx_pkts; + ap[i].rx_error += p->sta[ac].rx_error; + ap[i].rx_discard += p->sta[ac].rx_discard; + } + } else { + WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr; + TARGET_STATS *pStats = &arPriv->arTargetStats; + + if (len < sizeof(*pTarget)) { + return; + } + + // Update the RSSI of the connected bss. + if (arPriv->arConnected) { + bss_t *pConnBss = NULL; + + pConnBss = wmi_find_node(arPriv->arWmi,arPriv->arBssid); + if (pConnBss) + { + pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi; + pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr; + wmi_node_return(arPriv->arWmi, pConnBss); + } + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n")); + pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets; + pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes; + pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts; + pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes; + pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts; + pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes; + pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts; + pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes; + pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt; + for(ac = 0; ac < WMM_NUM_AC; ac++) + pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac]; + pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors; + pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt; + pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt; + pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt; + pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt; + pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate); + + pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets; + pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes; + pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts; + pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes; + pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts; + pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes; + pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts; + pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes; + pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt; + pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors; + pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr; + pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss; + pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err; + pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames; + pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate); + + + pStats->tkip_local_mic_failure + += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure; + pStats->tkip_counter_measures_invoked + += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked; + pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays; + pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors; + pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors; + pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays; + + pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt; + pStats->noise_floor_calibation = pTarget->noise_floor_calibation; + + pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt; + pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt; + pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt; + pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt; + pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr; + pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi; + + if (enablerssicompensation) { + pStats->cs_aveBeacon_rssi = + rssi_compensation_calc(arPriv, pStats->cs_aveBeacon_rssi); + } + pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec; + pStats->cs_snr = pTarget->cservStats.cs_snr; + pStats->cs_rssi = pTarget->cservStats.cs_rssi; + + pStats->lq_val = pTarget->lqVal; + + pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped; + pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups; + pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups; + pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded; + pStats->arp_received += pTarget->arpStats.arp_received; + pStats->arp_matched += pTarget->arpStats.arp_matched; + pStats->arp_replied += pTarget->arpStats.arp_replied; + + if (arPriv->statsUpdatePending) { + arPriv->statsUpdatePending = FALSE; + wake_up(&arPriv->arEvent); + } + } +} + +void +ar6000_rssiThreshold_event(AR_SOFTC_DEV_T *arPriv, WMI_RSSI_THRESHOLD_VAL newThreshold, A_INT16 rssi) +{ + USER_RSSI_THOLD userRssiThold; + + rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR; + + if (enablerssicompensation) { + rssi = rssi_compensation_calc(arPriv, rssi); + } + + /* Send an event to the app */ + userRssiThold.tag = arPriv->arSta.rssi_map[newThreshold].tag; + userRssiThold.rssi = rssi; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold, + userRssiThold.tag, userRssiThold.rssi)); + + ar6000_send_event_to_app(arPriv, WMI_RSSI_THRESHOLD_EVENTID,(A_UINT8 *)&userRssiThold, sizeof(USER_RSSI_THOLD)); +} + + +void +ar6000_hbChallengeResp_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 cookie, A_UINT32 source) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + if (source == APP_HB_CHALLENGE) { + /* Report it to the app in case it wants a positive acknowledgement */ + ar6000_send_event_to_app(arPriv, WMIX_HB_CHALLENGE_RESP_EVENTID, + (A_UINT8 *)&cookie, sizeof(cookie)); + } else { + /* This would ignore the replys that come in after their due time */ + if (cookie == ar->arHBChallengeResp.seqNum) { + ar->arHBChallengeResp.outstanding = FALSE; + } + } +} + + +void +ar6000_reportError_event(AR_SOFTC_DEV_T *arPriv, WMI_TARGET_ERROR_VAL errorVal) +{ + char *errString[] = { + [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL", + [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND", + [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR", + [WMI_TARGET_BMISS] "WMI_TARGET_BMISS", + [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN" + }; + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6000 Error on Target. Error = 0x%x\n", errorVal)); + + /* One error is reported at a time, and errorval is a bitmask */ + if(errorVal & (errorVal - 1)) + return; + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6000 Error type = ")); + switch(errorVal) + { + case WMI_TARGET_PM_ERR_FAIL: + case WMI_TARGET_KEY_NOT_FOUND: + case WMI_TARGET_DECRYPTION_ERR: + case WMI_TARGET_BMISS: + case WMI_PSDISABLE_NODE_JOIN: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s\n", errString[errorVal])); + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("INVALID\n")); + break; + } + +} + + +void +ar6000_cac_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 ac, A_UINT8 cacIndication, + A_UINT8 statusCode, A_UINT8 *tspecSuggestion) +{ + WMM_TSPEC_IE *tspecIe; + + /* + * This is the TSPEC IE suggestion from AP. + * Suggestion provided by AP under some error + * cases, could be helpful for the host app. + * Check documentation. + */ + tspecIe = (WMM_TSPEC_IE *)tspecSuggestion; + + /* + * What do we do, if we get TSPEC rejection? One thought + * that comes to mind is implictly delete the pstream... + */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 CAC notification. " + "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n", + ac, cacIndication, statusCode)); +} + +void +ar6000_channel_change_event(AR_SOFTC_DEV_T *arPriv, A_UINT16 oldChannel, + A_UINT16 newChannel) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Channel Change notification\nOld Channel: %d, New Channel: %d\n", + oldChannel, newChannel)); +} + +#define AR6000_PRINT_BSSID(_pBss) do { \ + A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\ + (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\ + (_pBss)[4],(_pBss)[5]); \ +} while(0) + +void +ar6000_roam_tbl_event(AR_SOFTC_DEV_T *arPriv, WMI_TARGET_ROAM_TBL *pTbl) +{ + A_UINT8 i; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n", + pTbl->numEntries, pTbl->roamMode)); + for (i= 0; i < pTbl->numEntries; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i, + pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1], + pTbl->bssRoamInfo[i].bssid[2], + pTbl->bssRoamInfo[i].bssid[3], + pTbl->bssRoamInfo[i].bssid[4], + pTbl->bssRoamInfo[i].bssid[5])); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d" + " BIAS %d\n", + pTbl->bssRoamInfo[i].rssi, + pTbl->bssRoamInfo[i].rssidt, + pTbl->bssRoamInfo[i].last_rssi, + pTbl->bssRoamInfo[i].util, + pTbl->bssRoamInfo[i].roam_util, + pTbl->bssRoamInfo[i].bias)); + } +} + +void +ar6000_wow_list_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply) +{ + A_UINT8 i,j; + + /*Each event now contains exactly one filter, see bug 26613*/ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("wow mode = %s host mode = %s\n", + (wow_reply->wow_mode == 0? "disabled":"enabled"), + (wow_reply->host_mode == 1 ? "awake":"asleep"))); + + + /*If there are no patterns, the reply will only contain generic + WoW information. Pattern information will exist only if there are + patterns present. Bug 26716*/ + + /* If this event contains pattern information, display it*/ + if (wow_reply->this_filter_num) { + i=0; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("id=%d size=%d offset=%d\n", + wow_reply->wow_filters[i].wow_filter_id, + wow_reply->wow_filters[i].wow_filter_size, + wow_reply->wow_filters[i].wow_filter_offset)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("wow pattern = ")); + for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j])); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\nwow mask = ")); + for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j])); + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\n")); + } +} + +/* + * Report the Roaming related data collected on the target + */ +void +ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Disconnect Data : BSSID: ")); + AR6000_PRINT_BSSID(p->disassoc_bssid); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n", + p->disassoc_bss_rssi,p->disassoc_time, + p->no_txrx_time)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Connect Data: BSSID: ")); + AR6000_PRINT_BSSID(p->assoc_bssid); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" RSSI %d ASSOC Time %d TXRX_TIME %d\n", + p->assoc_bss_rssi,p->assoc_time, + p->allow_txrx_time)); +} + +void +ar6000_roam_data_event(AR_SOFTC_DEV_T *arPriv, WMI_TARGET_ROAM_DATA *p) +{ + switch (p->roamDataType) { + case ROAM_DATA_TIME: + ar6000_display_roam_time(&p->u.roamTime); + break; + default: + break; + } +} + +void +ar6000_bssInfo_event_rx(AR_SOFTC_DEV_T *arPriv, A_UINT8 *datap, int len) +{ + struct sk_buff *skb; + WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap; + + + if (!arPriv->arSta.arMgmtFilter) { + return; + } + if (((arPriv->arSta.arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) && + (bih->frameType != BEACON_FTYPE)) || + ((arPriv->arSta.arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) && + (bih->frameType != PROBERESP_FTYPE))) + { + return; + } + + if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) { + + A_NETBUF_PUT(skb, len); + A_MEMCPY(A_NETBUF_DATA(skb), datap, len); + skb->dev = arPriv->arNetDev; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) + A_MEMCPY(skb_mac_header(skb), A_NETBUF_DATA(skb), 6); +#else + skb->mac.raw = A_NETBUF_DATA(skb); +#endif + skb->ip_summed = CHECKSUM_NONE; + skb->pkt_type = PACKET_OTHERHOST; + skb->protocol = __constant_htons(0x0019); + A_NETIF_RX(skb); + } +} + +A_UINT32 wmiSendCmdNum; + +A_STATUS +ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + AR_SOFTC_T *ar = arPriv->arSoftc; + A_STATUS status = A_OK; + struct ar_cookie *cookie = NULL; + int i; + +#ifdef CONFIG_PM + if (ar->arWowState == WLAN_WOW_STATE_SUSPENDED) { + return A_EACCES; + } +#endif /* CONFIG_PM */ + /* take lock to protect ar6000_alloc_cookie() */ + AR6000_SPIN_LOCK(&ar->arLock, 0); + + do { + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%x, len=0x%x eid =%d\n", + (A_UINT32)osbuf, A_NETBUF_LEN(osbuf), eid)); + + if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) { + /* control endpoint is full, don't allocate resources, we + * are just going to drop this packet */ + cookie = NULL; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%X, len:%d \n", + (A_UINT32)osbuf, A_NETBUF_LEN(osbuf))); +#ifdef ANDROID_ENV + if (++android_epfull_cnt > ANDROID_RELOAD_THRESHOLD_FOR_EP_FULL) { + android_send_reload_event(arPriv); + android_epfull_cnt = 0; + } +#endif + } else { + cookie = ar6000_alloc_cookie(ar); + } + + if (cookie == NULL) { + status = A_NO_MEMORY; + break; + } + + if(logWmiRawMsgs) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WMI cmd send, msgNo %d :", wmiSendCmdNum)); + for(i = 0; i < a_netbuf_to_len(osbuf); i++) + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%x ", ((A_UINT8 *)a_netbuf_to_data(osbuf))[i])); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("\n")); + } + + wmiSendCmdNum++; + + } while (FALSE); + + if (cookie != NULL) { + /* got a structure to send it out on */ + ar->arTxPending[eid]++; + + if (eid != ar->arControlEp) { + ar->arTotalTxDataPending++; + } + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (cookie != NULL) { + cookie->arc_bp[0] = (A_UINT32)osbuf; + cookie->arc_bp[1] = 0; + SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, + cookie, + A_NETBUF_DATA(osbuf), + A_NETBUF_LEN(osbuf), + eid, + AR6K_CONTROL_PKT_TAG); + /* this interface is asynchronous, if there is an error, cleanup will happen in the + * TX completion callback */ + HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); + status = A_OK; + } + + return status; +} + +/* indicate tx activity or inactivity on a WMI stream */ +void ar6000_indicate_tx_activity(void *devt, A_UINT8 TrafficClass, A_BOOL Active) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + AR_SOFTC_T *ar = arPriv->arSoftc; + HTC_ENDPOINT_ID eid ; + int i; + + if (ar->arWmiReady) { + eid = arAc2EndpointID(ar, TrafficClass); + + AR6000_SPIN_LOCK(&ar->arLock, 0); + + ar->arAcStreamActive[TrafficClass] = Active; + + if (Active) { + /* when a stream goes active, keep track of the active stream with the highest priority */ + + if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) { + /* set the new highest active priority */ + ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass]; + } + + } else { + /* when a stream goes inactive, we may have to search for the next active stream + * that is the highest priority */ + + if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) { + + /* the highest priority stream just went inactive */ + + /* reset and search for the "next" highest "active" priority stream */ + ar->arHiAcStreamActivePri = 0; + for (i = 0; i < WMM_NUM_AC; i++) { + if (ar->arAcStreamActive[i]) { + if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) { + /* set the new highest active priority */ + ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i]; + } + } + } + } + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + } else { + /* for mbox ping testing, the traffic class is mapped directly as a stream ID, + * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c + * convert the stream ID to a endpoint */ + eid = arAc2EndpointID(ar, TrafficClass); + } + + /* notify HTC, this may cause credit distribution changes */ + + HTCIndicateActivityChange(ar->arHtcTarget, + eid, + Active); + +} + +void +ar6000_btcoex_config_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *ptr, A_UINT32 len) +{ + + WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr; + WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&arPriv->arBtcoexConfig; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n")); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("received config event\n")); + pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType; + pArbtcoexConfig->linkId = pBtcoexConfig->linkId; + + switch (pBtcoexConfig->btProfileType) { + case WMI_BTCOEX_BT_PROFILE_SCO: + A_MEMCPY(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd, + sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD)); + break; + case WMI_BTCOEX_BT_PROFILE_A2DP: + A_MEMCPY(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd, + sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD)); + break; + case WMI_BTCOEX_BT_PROFILE_ACLCOEX: + A_MEMCPY(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig, + sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD)); + break; + case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE: + A_MEMCPY(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd, + sizeof(WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD)); + break; + } + if (arPriv->statsUpdatePending) { + arPriv->statsUpdatePending = FALSE; + wake_up(&arPriv->arEvent); + } +} + +void +ar6000_btcoex_stats_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *ptr, A_UINT32 len) +{ + WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n")); + + A_MEMCPY(&arPriv->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT)); + + if (arPriv->statsUpdatePending) { + arPriv->statsUpdatePending = FALSE; + wake_up(&arPriv->arEvent); + } + +} + +void +ar6000_wacinfo_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *ptr, A_UINT32 len) +{ + WMI_GET_WAC_INFO *pWacInfo = (WMI_GET_WAC_INFO *)ptr; + + A_MEMCPY(&arPriv->wacInfo, pWacInfo, sizeof(WMI_GET_WAC_INFO)); + + if (arPriv->statsUpdatePending) { + arPriv->statsUpdatePending = FALSE; + wake_up(&arPriv->arEvent); + } +} + +#ifndef RK29 +module_init(ar6000_init_module); +module_exit(ar6000_cleanup_module); +#endif + +/* Init cookie queue */ +static void +ar6000_cookie_init(AR_SOFTC_T *ar) +{ + A_UINT32 i; + + ar->arCookieList = NULL; + ar->arCookieCount = 0; + + A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem)); + + for (i = 0; i < MAX_COOKIE_NUM; i++) { + ar6000_free_cookie(ar, &s_ar_cookie_mem[i]); + } +} + +/* cleanup cookie queue */ +static void +ar6000_cookie_cleanup(AR_SOFTC_T *ar) +{ + /* It is gone .... */ + ar->arCookieList = NULL; + ar->arCookieCount = 0; +} + +/* Init cookie queue */ +static void +ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie) +{ + /* Insert first */ + A_ASSERT(ar != NULL); + A_ASSERT(cookie != NULL); + + cookie->arc_list_next = ar->arCookieList; + ar->arCookieList = cookie; + ar->arCookieCount++; +} + +/* cleanup cookie queue */ +static struct ar_cookie * +ar6000_alloc_cookie(AR_SOFTC_T *ar) +{ + struct ar_cookie *cookie; + + cookie = ar->arCookieList; + if(cookie != NULL) + { + ar->arCookieList = cookie->arc_list_next; + ar->arCookieCount--; + } + + return cookie; +} + +#ifdef SEND_EVENT_TO_APP +/* + * This function is used to send event which come from taget to + * the application. The buf which send to application is include + * the event ID and event content. + */ +#define EVENT_ID_LEN 2 +void ar6000_send_event_to_app(AR_SOFTC_DEV_T *arPriv, A_UINT16 eventId, + A_UINT8 *datap, int len) +{ + +#if (WIRELESS_EXT >= 15) + +/* note: IWEVCUSTOM only exists in wireless extensions after version 15 */ + + char *buf; + A_UINT16 size; + union iwreq_data wrqu; + + size = len + EVENT_ID_LEN; + + if (size > IW_CUSTOM_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVCUSTOM (max=%d) \n", + eventId, size, IW_CUSTOM_MAX)); + return; + } + + buf = A_MALLOC_NOWAIT(size); + if (NULL == buf){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); + return; + } + + A_MEMZERO(buf, size); + A_MEMCPY(buf, &eventId, EVENT_ID_LEN); + A_MEMCPY(buf+EVENT_ID_LEN, datap, len); + + //AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("event ID = %d,len = %d\n",*(A_UINT16*)buf, size)); + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = size; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + A_FREE(buf); + +#ifdef ANDROID_ENV + if (eventId == WMI_ERROR_REPORT_EVENTID) { + android_send_reload_event(arPriv); + } +#endif /* ANDROID_ENV */ + +#endif + + +} + +/* + * This function is used to send events larger than 256 bytes + * to the application. The buf which is sent to application + * includes the event ID and event content. + */ +void ar6000_send_generic_event_to_app(AR_SOFTC_DEV_T *arPriv, A_UINT16 eventId, + A_UINT8 *datap, int len) +{ + +#if (WIRELESS_EXT >= 18) + +/* IWEVGENIE exists in wireless extensions version 18 onwards */ + + char *buf; + A_UINT16 size; + union iwreq_data wrqu; + + size = len + EVENT_ID_LEN; + + if (size > IW_GENERIC_IE_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVGENIE (max=%d) \n", + eventId, size, IW_GENERIC_IE_MAX)); + return; + } + + buf = A_MALLOC_NOWAIT(size); + if (NULL == buf){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); + return; + } + + A_MEMZERO(buf, size); + A_MEMCPY(buf, &eventId, EVENT_ID_LEN); + A_MEMCPY(buf+EVENT_ID_LEN, datap, len); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = size; + wireless_send_event(arPriv->arNetDev, IWEVGENIE, &wrqu, buf); + + A_FREE(buf); + +#endif /* (WIRELESS_EXT >= 18) */ + +} +#endif /* SEND_EVENT_TO_APP */ + + +void +ar6000_tx_retry_err_event(void *devt) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n")); +} + +void +ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, A_UINT8 snr) +{ + WMI_SNR_THRESHOLD_EVENT event; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + event.range = newThreshold; + event.snr = snr; + + ar6000_send_event_to_app(arPriv, WMI_SNR_THRESHOLD_EVENTID, (A_UINT8 *)&event, + sizeof(WMI_SNR_THRESHOLD_EVENT)); +} + +void +ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, A_UINT8 lq) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq)); +} + + + +A_UINT32 +a_copy_to_user(void *to, const void *from, A_UINT32 n) +{ + return(copy_to_user(to, from, n)); +} + +A_UINT32 +a_copy_from_user(void *to, const void *from, A_UINT32 n) +{ + return(copy_from_user(to, from, n)); +} + + +A_STATUS +ar6000_get_driver_cfg(struct net_device *dev, + A_UINT16 cfgParam, + void *result) +{ + A_STATUS ret = A_OK; + + switch(cfgParam) + { + case AR6000_DRIVER_CFG_GET_WLANNODECACHING: + *((A_UINT32 *)result) = wlanNodeCaching; + break; + case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS: + *((A_UINT32 *)result) = logWmiRawMsgs; + break; + default: + ret = A_EINVAL; + break; + } + + return ret; +} + +void +ar6000_keepalive_rx(void *devt, A_UINT8 configured) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)devt; + + arPriv->arSta.arKeepaliveConfigured = configured; + wake_up(&arPriv->arEvent); +} + +void +ar6000_pmkid_list_event(void *devt, A_UINT8 numPMKID, WMI_PMKID *pmkidList, + A_UINT8 *bssidList) +{ + A_UINT8 i, j; + + A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID); + + for (i = 0; i < numPMKID; i++) { + A_PRINTF("\nBSSID %d ", i); + for (j = 0; j < ATH_MAC_LEN; j++) { + A_PRINTF("%2.2x", bssidList[j]); + } + bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN); + A_PRINTF("\nPMKID %d ", i); + for (j = 0; j < WMI_PMKID_LEN; j++) { + A_PRINTF("%2.2x", pmkidList->pmkid[j]); + } + pmkidList = (WMI_PMKID *)((A_UINT8 *)pmkidList + ATH_MAC_LEN + + WMI_PMKID_LEN); + } +} + +void ar6000_pspoll_event(AR_SOFTC_DEV_T *arPriv,A_UINT8 aid) +{ + conn_t *conn=NULL; + A_BOOL isPsqEmpty = FALSE; + + conn = ieee80211_find_conn_for_aid(arPriv, aid); + + if(!conn) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("PS-POLL from invalid STA\n")); + return; + } + + /* If the PS q for this STA is not empty, dequeue and send a pkt from + * the head of the q. Also update the More data bit in the WMI_DATA_HDR + * if there are more pkts for this STA in the PS q. If there are no more + * pkts for this STA, update the PVB for this STA. + */ + A_MUTEX_LOCK(&conn->psqLock); + isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); + A_MUTEX_UNLOCK(&conn->psqLock); + + if (isPsqEmpty) { + /* TODO:No buffered pkts for this STA. Send out a NULL data frame */ + } else { + struct sk_buff *skb = NULL; + + A_MUTEX_LOCK(&conn->psqLock); + skb = A_NETBUF_DEQUEUE(&conn->psq); + A_MUTEX_UNLOCK(&conn->psqLock); + /* Set the STA flag to PSPolled, so that the frame will go out */ + STA_SET_PS_POLLED(conn); + ar6000_data_tx(skb, arPriv->arNetDev); + STA_CLR_PS_POLLED(conn); + + A_MUTEX_LOCK(&conn->psqLock); + isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); + A_MUTEX_UNLOCK(&conn->psqLock); + + } + + /* Clear the PVB for this STA if the queue has become empty */ + if (isPsqEmpty) { + wmi_set_pvb_cmd(arPriv->arWmi, conn->aid, 0); + } +} + +void ar6000_dtimexpiry_event(AR_SOFTC_DEV_T *arPriv) +{ + A_BOOL isMcastQueued = FALSE; + struct sk_buff *skb = NULL; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + + /* If there are no associated STAs, ignore the DTIM expiry event. + * There can be potential race conditions where the last associated + * STA may disconnect & before the host could clear the 'Indicate DTIM' + * request to the firmware, the firmware would have just indicated a DTIM + * expiry event. The race is between 'clear DTIM expiry cmd' going + * from the host to the firmware & the DTIM expiry event happening from + * the firmware to the host. + */ + if (arAp->sta_list_index == 0) { + return; + } + + A_MUTEX_LOCK(&arAp->mcastpsqLock); + isMcastQueued = A_NETBUF_QUEUE_EMPTY(&arAp->mcastpsq); + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + + if(isMcastQueued == TRUE) { + return; + } + + /* Flush the mcast psq to the target */ + /* Set the STA flag to DTIMExpired, so that the frame will go out */ + arAp->DTIMExpired = TRUE; + + A_MUTEX_LOCK(&arAp->mcastpsqLock); + while (!A_NETBUF_QUEUE_EMPTY(&arAp->mcastpsq)) { + skb = A_NETBUF_DEQUEUE(&arAp->mcastpsq); + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + + ar6000_data_tx(skb, arPriv->arNetDev); + + A_MUTEX_LOCK(&arAp->mcastpsqLock); + } + A_MUTEX_UNLOCK(&arAp->mcastpsqLock); + + /* Reset the DTIMExpired flag back to 0 */ + arAp->DTIMExpired = FALSE; + + /* Clear the LSB of the BitMapCtl field of the TIM IE */ + wmi_set_pvb_cmd(arPriv->arWmi, MCAST_AID, 0); +} + +static void ar6000_uapsd_trigger_frame_rx(AR_SOFTC_DEV_T *arPriv, conn_t *conn) +{ + A_BOOL isApsdqEmpty; + A_BOOL isApsdqEmptyAtStart; + A_UINT32 numFramesToDeliver; + + /* If the APSD q for this STA is not empty, dequeue and send a pkt from + * the head of the q. Also update the More data bit in the WMI_DATA_HDR + * if there are more pkts for this STA in the APSD q. If there are no more + * pkts for this STA, update the APSD bitmap for this STA. + */ + + numFramesToDeliver = (conn->apsd_info >> 4) & 0xF; + + /* Number of frames to send in a service period is indicated by the station + * in the QOS_INFO of the association request + * If it is zero, send all frames + */ + if (!numFramesToDeliver) { + numFramesToDeliver = 0xFFFF; + } + + A_MUTEX_LOCK(&conn->psqLock); + isApsdqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->apsdq); + A_MUTEX_UNLOCK(&conn->psqLock); + isApsdqEmptyAtStart = isApsdqEmpty; + + while ((!isApsdqEmpty) && (numFramesToDeliver)) { + struct sk_buff *skb = NULL; + + A_MUTEX_LOCK(&conn->psqLock); + skb = A_NETBUF_DEQUEUE(&conn->apsdq); + isApsdqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->apsdq); + A_MUTEX_UNLOCK(&conn->psqLock); + + /* Set the STA flag to Trigger delivery, so that the frame will go out */ + STA_SET_APSD_TRIGGER(conn); + numFramesToDeliver--; + + /* Last frame in the service period, set EOSP or queue empty */ + if ((isApsdqEmpty) || (!numFramesToDeliver)) { + STA_SET_APSD_EOSP(conn); + } + ar6000_data_tx(skb, arPriv->arNetDev); + STA_CLR_APSD_TRIGGER(conn); + STA_CLR_APSD_EOSP(conn); + } + + if (isApsdqEmpty) { + if (isApsdqEmptyAtStart) { + wmi_set_apsd_buffered_traffic_cmd(arPriv->arWmi, conn->aid, 0, + WMI_AP_APSD_NO_DELIVERY_FRAMES_FOR_THIS_TRIGGER); + } else { + wmi_set_apsd_buffered_traffic_cmd(arPriv->arWmi, conn->aid, 0, 0); + } + } + + return; +} + +void +read_rssi_compensation_param(AR_SOFTC_T *ar) +{ + A_UINT8 *cust_data_ptr; + USER_RSSI_CPENSATION *rssi_compensation_param; +//#define RSSICOMPENSATION_PRINT +#ifdef RSSICOMPENSATION_PRINT + A_INT16 i; + cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType); + for (i=0; i<16; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("cust_data_%d = %x \n", i, *(A_UINT8 *)cust_data_ptr)); + cust_data_ptr += 1; + } +#endif + rssi_compensation_param = &ar->rssi_compensation_param; + cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType); + + rssi_compensation_param->customerID = *(A_UINT16 *)cust_data_ptr & 0xffff; + rssi_compensation_param->enable = *(A_UINT16 *)(cust_data_ptr+2) & 0xffff; + rssi_compensation_param->bg_param_a = *(A_UINT16 *)(cust_data_ptr+4) & 0xffff; + rssi_compensation_param->bg_param_b = *(A_UINT16 *)(cust_data_ptr+6) & 0xffff; + rssi_compensation_param->a_param_a = *(A_UINT16 *)(cust_data_ptr+8) & 0xffff; + rssi_compensation_param->a_param_b = *(A_UINT16 *)(cust_data_ptr+10) &0xffff; + rssi_compensation_param->reserved = *(A_UINT32 *)(cust_data_ptr+12); + +#ifdef RSSICOMPENSATION_PRINT + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("customerID = 0x%x \n", rssi_compensation_param->customerID)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("enable = 0x%x \n", rssi_compensation_param->enable)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("bg_param_a = 0x%x and %d \n", rssi_compensation_param->bg_param_a, rssi_compensation_param->bg_param_a)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("bg_param_b = 0x%x and %d \n", rssi_compensation_param->bg_param_b, rssi_compensation_param->bg_param_b)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("a_param_a = 0x%x and %d \n", rssi_compensation_param->a_param_a, rssi_compensation_param->a_param_a)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("a_param_b = 0x%x and %d \n", rssi_compensation_param->a_param_b, rssi_compensation_param->a_param_b)); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Last 4 bytes = 0x%x \n", rssi_compensation_param->reserved)); +#endif + + if (rssi_compensation_param->enable != 0x1) { + rssi_compensation_param->enable = 0; + } + + return; +} + +A_INT32 +rssi_compensation_calc_tcmd(AR_SOFTC_T *ar, A_UINT32 freq, A_INT32 rssi, A_UINT32 totalPkt) +{ + USER_RSSI_CPENSATION *rssi_compensation_param; + + rssi_compensation_param = &ar->rssi_compensation_param; + + if (freq > 5000) + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt)); + rssi = rssi * rssi_compensation_param->a_param_a + totalPkt * rssi_compensation_param->a_param_b; + rssi = (rssi-50) /100; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); + } + } + else + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt)); + rssi = rssi * rssi_compensation_param->bg_param_a + totalPkt * rssi_compensation_param->bg_param_b; + rssi = (rssi-50) /100; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); + } + } + + return rssi; +} + +A_INT16 +rssi_compensation_calc(AR_SOFTC_DEV_T *arPriv, A_INT16 rssi) +{ + USER_RSSI_CPENSATION *rssi_compensation_param; + AR_SOFTC_T *ar = arPriv->arSoftc; + + rssi_compensation_param = &ar->rssi_compensation_param; + + if (arPriv->arBssChannel > 5000) + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi)); + rssi = rssi * rssi_compensation_param->a_param_a + rssi_compensation_param->a_param_b; + rssi = (rssi-50) /100; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); + } + } + else + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi)); + rssi = rssi * rssi_compensation_param->bg_param_a + rssi_compensation_param->bg_param_b; + rssi = (rssi-50) /100; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); + } + } + + return rssi; +} + +A_INT16 +rssi_compensation_reverse_calc(AR_SOFTC_DEV_T *arPriv, A_INT16 rssi, A_BOOL Above) +{ + A_INT16 i; + + USER_RSSI_CPENSATION *rssi_compensation_param; + AR_SOFTC_T *ar = arPriv->arSoftc; + + rssi_compensation_param = &ar->rssi_compensation_param; + + if (arPriv->arBssChannel > 5000) + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi)); + rssi = rssi * 100; + rssi = (rssi - rssi_compensation_param->a_param_b) / rssi_compensation_param->a_param_a; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi)); + } + } + else + { + if (rssi_compensation_param->enable) + { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi)); + + if (Above) { + for (i=95; i>=0; i--) { + if (rssi <= rssi_compensation_table[arPriv->arDeviceIndex][i]) { + rssi = 0 - i; + break; + } + } + } else { + for (i=0; i<=95; i++) { + if (rssi >= rssi_compensation_table[arPriv->arDeviceIndex][i]) { + rssi = 0 - i; + break; + } + } + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi)); + } + } + + return rssi; +} + +#ifdef WAPI_ENABLE +void ap_wapi_rekey_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 type, A_UINT8 *mac) +{ + union iwreq_data wrqu; + A_CHAR buf[20]; + + A_MEMZERO(buf, sizeof(buf)); + + strcpy(buf, "WAPI_REKEY"); + buf[10] = type; + A_MEMCPY(&buf[11], mac, ATH_MAC_LEN); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = 10+1+ATH_MAC_LEN; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5])); +} +#endif + +#ifdef P2P +void *get_p2p_ctx(AR_SOFTC_DEV_T *arPriv) +{ + return (arPriv->p2p_ctx); +} + +void *get_wmi_ctx(AR_SOFTC_DEV_T *arPriv) +{ + return (arPriv->arWmi); +} + +NETWORK_SUBTYPE get_network_subtype(AR_SOFTC_DEV_T *arPriv) +{ + return (arPriv->arNetworkSubType); +} + +#endif /* P2P */ + +#ifdef USER_KEYS +static A_STATUS + +ar6000_reinstall_keys(AR_SOFTC_DEV_T *arPriv, A_UINT8 key_op_ctrl) +{ + A_STATUS status = A_OK; + struct ieee80211req_key *uik = &arPriv->arSta.user_saved_keys.ucast_ik; + struct ieee80211req_key *bik = &arPriv->arSta.user_saved_keys.bcast_ik; + CRYPTO_TYPE keyType = arPriv->arSta.user_saved_keys.keyType; + + if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) { + if (NONE_CRYPT == keyType) { + goto _reinstall_keys_out; + } + + if (uik->ik_keylen) { + status = wmi_addKey_cmd(arPriv->arWmi, uik->ik_keyix, + keyType, PAIRWISE_USAGE, + uik->ik_keylen, (A_UINT8 *)&uik->ik_keyrsc, + uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG); + } + + } else { + status = wmi_add_krk_cmd(arPriv->arWmi, uik->ik_keydata); + } + + if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) { + if (NONE_CRYPT == keyType) { + goto _reinstall_keys_out; + } + + if (bik->ik_keylen) { + status = wmi_addKey_cmd(arPriv->arWmi, bik->ik_keyix, + keyType, GROUP_USAGE, + bik->ik_keylen, (A_UINT8 *)&bik->ik_keyrsc, + bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG); + } + } else { + status = wmi_add_krk_cmd(arPriv->arWmi, bik->ik_keydata); + } + +_reinstall_keys_out: + arPriv->arSta.user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; + arPriv->arSta.user_key_ctrl = 0; + + return status; +} +#endif /* USER_KEYS */ + + +void +ar6000_dset_open_req( + void *context, + A_UINT32 id, + A_UINT32 targHandle, + A_UINT32 targReplyFn, + A_UINT32 targReplyArg) +{ +} + +void +ar6000_dset_close( + void *context, + A_UINT32 access_cookie) +{ + return; +} + +void +ar6000_dset_data_req( + void *context, + A_UINT32 accessCookie, + A_UINT32 offset, + A_UINT32 length, + A_UINT32 targBuf, + A_UINT32 targReplyFn, + A_UINT32 targReplyArg) +{ +} +void +ar6000_init_mode_info(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + + arPriv->arDot11AuthMode = OPEN_AUTH; + arPriv->arAuthMode = WMI_NONE_AUTH; + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arGroupCryptoLen = 0; + arPriv->arChannelHint = 0; + arPriv->arDefTxKeyIndex = 0; + A_MEMZERO(arPriv->arBssid, sizeof(arPriv->arBssid)); + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + A_MEMZERO(arPriv->arWepKeyList, sizeof(arPriv->arWepKeyList)); + arPriv->arSsidLen = 0; + arPriv->arTxPwr = 0; + arPriv->arTxPwrSet = FALSE; + arPriv->arBitRate = -1; + arPriv->arMaxRetries = 0; + arPriv->arWmmEnabled = TRUE; + arPriv->ap_profile_flag = 0; + arPriv->num_sta = 0xFF; + ar->gNumSta = AP_MAX_NUM_STA; + + if(arPriv->arNextMode == AP_NETWORK) { + AR_SOFTC_AP_T *arAp; + if(arPriv->arNetworkType != AP_NETWORK) { + A_MEMZERO(&arPriv->arSta,sizeof(AR_SOFTC_STA_T)); + } + arAp = &arPriv->arAp; + arAp->intra_bss = 1; + ar->inter_bss = 1; + + /* init the Mutexes */ + A_NETBUF_QUEUE_INIT(&arAp->mcastpsq); + A_MUTEX_INIT(&arAp->mcastpsqLock); + A_MEMCPY(arAp->ap_country_code, DEF_AP_COUNTRY_CODE, 3); + if (arPriv->arPhyCapability == WMI_11NAG_CAPABILITY){ + arPriv->phymode = DEF_AP_WMODE_AG; + } else { + arPriv->phymode = DEF_AP_WMODE_G; + } + arAp->ap_dtim_period = DEF_AP_DTIM; + arAp->ap_beacon_interval = DEF_BEACON_INTERVAL; + A_INIT_TIMER(&arPriv->ap_acs_timer,ap_acs_handler, arPriv); + A_INIT_TIMER(&ar->ap_reconnect_timer,ap_reconnect_timer_handler, ar); + } else { + /*Station Mode intialisation*/ + AR_SOFTC_STA_T *arSta; + if(arPriv->arNetworkType == AP_NETWORK) { + A_MEMZERO(&arPriv->arAp,sizeof(AR_SOFTC_AP_T)); + } + arSta = &arPriv->arSta; + arSta->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL; + arSta->arListenIntervalB = 0; + arSta->arBmissTimeT = A_DEFAULT_BMISS_TIME; + arSta->arBmissTimeB = 0; + arSta->arRssi = 0; + arSta->arSkipScan = 0; + arSta->arBeaconInterval = 0; + arSta->scan_triggered = 0; + A_MEMZERO(&arSta->scParams, sizeof(arSta->scParams)); + arSta->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT; + arSta->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS; + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + if (!arSta->disconnect_timer_inited) { + A_INIT_TIMER(&arSta->disconnect_timer, disconnect_timer_handler, arPriv->arNetDev); + arSta->disconnect_timer_inited = 1; + } + else + { + A_UNTIMEOUT(&arSta->disconnect_timer); + } + } +} + +int +ar6000_ap_set_num_sta(AR_SOFTC_T *ar, AR_SOFTC_DEV_T *arPriv, A_UINT8 num_sta) +{ + int ret = A_OK; + A_UINT8 i, total_num_sta; + AR_SOFTC_DEV_T *tpriv = NULL; + + if(num_sta & 0x80) { + total_num_sta = (num_sta & (~0x80)); + for(i=0; inum_sta = 0xFF; + } + } else { + total_num_sta = num_sta; + arPriv->num_sta = num_sta; + ar->gNumSta = 0xFF; + for(i=0; inum_sta !=0xFF) && + (tpriv->arNetworkType == AP_NETWORK)) { + total_num_sta += tpriv->num_sta; + } + } + } + + if(total_num_sta > AP_MAX_NUM_STA) { + ret = -EINVAL; + } else { + if(num_sta & 0x80) { + ar->gNumSta = (num_sta & (~0x80)); + } else { + arPriv->num_sta = num_sta; + } + wmi_ap_set_num_sta(arPriv->arWmi, num_sta); + } + + return ret; +} + +int +check_channel(AR_SOFTC_DEV_T *arPriv) +{ + A_UINT8 i; + AR_SOFTC_DEV_T *temp_priv = NULL; + + for(i=0; iarNextMode == AP_NETWORK) && temp_priv->arConnected) { + if(!(temp_priv->arBssChannel || temp_priv->arChannelHint)) { + /* ACS inprogress */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AP%d: ACS in progress\n",temp_priv->arDeviceIndex)); + A_TIMEOUT_MS(&arPriv->ap_acs_timer, 1000, 0); + return 0; + } + } + } + + for(i=0; iarConnected) { + /* User has set the channel for this interface */ + if(arPriv->arChannelHint) { + if(temp_priv->arBssChannel != arPriv->arChannelHint) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error: Channel should be %d MHz\n", temp_priv->arBssChannel)); + return 0; + } + } else { + /* ACS is enabled for this interface */ + if(temp_priv->arBssChannel) { + arPriv->arChannelHint = temp_priv->arBssChannel; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Selected Channel %d\n", temp_priv->arBssChannel)); + return 1; + } + } + } + } + return 1; +} + +static void ap_acs_handler(unsigned long ptr) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ptr; + A_UNTIMEOUT(&arPriv->ap_acs_timer); + + if(check_channel(arPriv)) { + ar6000_ap_mode_profile_commit(arPriv); + } else { + A_TIMEOUT_MS(&arPriv->ap_acs_timer, 1000, 0); + } +} + +int +ar6000_ap_mode_profile_commit(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_CONNECT_CMD p; + unsigned long flags; + + /* No change in AP's profile configuration */ + if(arPriv->ap_profile_flag==0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("COMMIT: No change in profile!!!\n")); + return -ENODATA; + } + + if(!check_channel(arPriv)) { + return -EOPNOTSUPP; + } + + if(!arPriv->arSsidLen) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("SSID not set!!!\n")); + return -ECHRNG; + } + + switch(arPriv->arAuthMode) { + case WMI_NONE_AUTH: + if((arPriv->arPairwiseCrypto != NONE_CRYPT) && +#ifdef WAPI_ENABLE + (arPriv->arPairwiseCrypto != WAPI_CRYPT) && +#endif + (arPriv->arPairwiseCrypto != WEP_CRYPT)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Cipher not supported in AP mode Open auth\n")); + return -EOPNOTSUPP; + } + break; + case WMI_WPA_PSK_AUTH: + case WMI_WPA2_PSK_AUTH: + case (WMI_WPA_PSK_AUTH|WMI_WPA2_PSK_AUTH): + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("This key mgmt type not supported in AP mode\n")); + return -EOPNOTSUPP; + } + + if ((arPriv->arAuthMode == WMI_NONE_AUTH) && + (arPriv->arPairwiseCrypto == WEP_CRYPT)) + { + ar6000_install_static_wep_keys(arPriv); + } + + /* Update the arNetworkType */ + arPriv->arNetworkType = arPriv->arNextMode; + arPriv->arBssChannel = 0; + + A_MEMZERO(&p,sizeof(p)); + p.ssidLength = arPriv->arSsidLen; + A_MEMCPY(p.ssid,arPriv->arSsid,p.ssidLength); + + /* + * p.channel == 0 [Do ACS and choose 1, 6, or 11] + * p.channel == 1 [Do ACS and choose 1, or 6] + * p.channel == xxxx [No ACS, use xxxx freq] + */ + if (((arPriv->phymode != WMI_11AG_MODE) && (arPriv->phymode != WMI_11A_MODE)) && (arPriv->arChannelHint >=5180 && arPriv->arChannelHint<= 5825)) { + arPriv->arChannelHint = 0; + } + if ((arPriv->arChannelHint == 0) && (ar->arAcsDisableHiChannel)) { + p.channel = 1; + } else { + p.channel = arPriv->arChannelHint; + if ((arPriv->arChannelHint >=5180) && (arPriv->arChannelHint<= 5825)) { + if (! (wmi_set_channelParams_cmd(arPriv->arWmi, 0, WMI_11A_MODE, 0, NULL))){ + arPriv->phymode= WMI_11A_MODE; + } + } else if ((arPriv->phymode == WMI_11A_MODE) || (arPriv->phymode == WMI_11AG_MODE)){ + if (! (wmi_set_channelParams_cmd(arPriv->arWmi, 0, WMI_11G_MODE, 0, NULL))){ + arPriv->phymode= WMI_11G_MODE; + } + } + } + + p.networkType = arPriv->arNetworkType; + p.dot11AuthMode = arPriv->arDot11AuthMode; + p.authMode = arPriv->arAuthMode; + p.pairwiseCryptoType = arPriv->arPairwiseCrypto; + p.pairwiseCryptoLen = arPriv->arPairwiseCryptoLen; + p.groupCryptoType = arPriv->arGroupCrypto; + p.groupCryptoLen = arPriv->arGroupCryptoLen; + p.ctrl_flags = arPriv->arSta.arConnectCtrlFlags; + +#if WLAN_CONFIG_NO_DISASSOC_UPON_DEAUTH + p.ctrl_flags |= AP_NO_DISASSOC_UPON_DEAUTH; +#endif + wmi_ap_profile_commit(arPriv->arWmi, &p); + spin_lock_irqsave(&arPriv->arPrivLock, flags); + arPriv->arConnected = TRUE; + netif_carrier_on(arPriv->arNetDev); + spin_unlock_irqrestore(&arPriv->arPrivLock, flags); + arPriv->ap_profile_flag = 0; + + return 0; +} + +A_STATUS +ar6000_connect_to_ap(AR_SOFTC_DEV_T *arPriv) +{ + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + + /* The ssid length check prevents second "essid off" from the user, + to be treated as a connect cmd. The second "essid off" is ignored. + */ + if((ar->arWmiReady == TRUE) && (arPriv->arSsidLen > 0) && arPriv->arNetworkType!=AP_NETWORK) + { + A_STATUS status; + if((ADHOC_NETWORK != arPriv->arNetworkType) && + (WMI_NONE_AUTH==arPriv->arAuthMode) && + (WEP_CRYPT==arPriv->arPairwiseCrypto)) { + ar6000_install_static_wep_keys(arPriv); + } + + if (!arSta->arUserBssFilter) { + if (wmi_bssfilter_cmd(arPriv->arWmi, ALL_BSS_FILTER, 0) != A_OK) { + return -EIO; + } + } + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\ + " PW crypto %d PW crypto Len %d GRP crypto %d"\ + " GRP crypto Len %d\n", + arPriv->arAuthMode, arPriv->arDot11AuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto, arPriv->arGroupCryptoLen)); + reconnect_flag = 0; + /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn. + later set it back locally at the STA to 100/1000 TUs depending on the power mode */ + if ((arPriv->arNetworkType == INFRA_NETWORK)) { + wmi_listeninterval_cmd(arPriv->arWmi, max(arSta->arListenIntervalT, (A_UINT16)A_MAX_WOW_LISTEN_INTERVAL), 0); + } + status = wmi_connect_cmd(arPriv->arWmi, arPriv->arNetworkType, + arPriv->arDot11AuthMode, arPriv->arAuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto,arPriv->arGroupCryptoLen, + arPriv->arSsidLen, arPriv->arSsid, + arSta->arReqBssid, arPriv->arChannelHint, + arSta->arConnectCtrlFlags); + if (status != A_OK) { + wmi_listeninterval_cmd(arPriv->arWmi, arSta->arListenIntervalT, arSta->arListenIntervalB); + if (!arSta->arUserBssFilter) { + wmi_bssfilter_cmd(arPriv->arWmi, NONE_BSS_FILTER, 0); + } + return status; + } + + if ((!(arSta->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) && + ((WMI_WPA_PSK_AUTH == arPriv->arAuthMode) || (WMI_WPA2_PSK_AUTH == arPriv->arAuthMode))) + { + A_TIMEOUT_MS(&arSta->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0); + } + + arSta->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD; + + arSta->arConnectPending = TRUE; + return status; + } + return A_ERROR; +} + +A_STATUS +ar6000_disconnect(AR_SOFTC_DEV_T *arPriv) +{ + if ((arPriv->arConnected == TRUE) || (arPriv->arSta.arConnectPending == TRUE)) { + wmi_disconnect_cmd(arPriv->arWmi); +#ifdef P2P + if(arPriv->arNetworkSubType == SUBTYPE_P2PCLIENT) { + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->arConnected == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + return -EINTR; + } + } +#endif + /* + * Disconnect cmd is issued, clear connectPending. + * arConnected will be cleard in disconnect_event notification. + */ + arPriv->arSta.arConnectPending = FALSE; + } + + return A_OK; +} + +A_STATUS +ar6000_ap_mode_get_wpa_ie(AR_SOFTC_DEV_T *arPriv, struct ieee80211req_wpaie *wpaie) +{ + conn_t *conn = NULL; + conn = ieee80211_find_conn(arPriv, wpaie->wpa_macaddr); + + A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE); + A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE); + + if(conn) { + A_MEMCPY(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE); + } + + return 0; +} + +A_STATUS +is_iwioctl_allowed(A_UINT8 mode, A_UINT16 cmd) +{ + if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) { + cmd -= SIOCSIWCOMMIT; + if(sioctl_filter[cmd] == 0xFF) return A_OK; + if(sioctl_filter[cmd] & mode) return A_OK; + } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) { + cmd -= SIOCIWFIRSTPRIV; + if(pioctl_filter[cmd] == 0xFF) return A_OK; + if(pioctl_filter[cmd] & mode) return A_OK; + } else { + return A_ERROR; + } + return A_ENOTSUP; +} + +A_STATUS +is_xioctl_allowed(A_UINT8 mode, A_UINT8 submode, int cmd) +{ + A_UINT8 mode_bits, submode_bits; + A_BOOL is_valid_mode=FALSE, is_valid_submode=FALSE; + + if(sizeof(xioctl_filter)-1 < cmd) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Filter for this cmd=%d not defined\n",cmd)); + return A_OK; + } + + /* Valid for all modes/submodes */ + if(xioctl_filter[cmd] == 0xFF) return A_OK; + + /* Check if this cmd is valid for the set mode of this device. + */ +#define XIOCTL_FILTER_MODE_MASK 0x1F +#define XIOCTL_FILTER_MODE_BIT_OFFSET 0x0 + mode_bits = xioctl_filter[cmd] & XIOCTL_FILTER_MODE_MASK; + + if (mode_bits & (mode << XIOCTL_FILTER_MODE_BIT_OFFSET)) { + /* Valid cmd for this mode */ + is_valid_mode = TRUE; + } + + /* Check if this cmd is valid for the set submode of this device. + */ +#define XIOCTL_FILTER_SUBMODE_MASK 0xE0 +#define XIOCTL_FILTER_SUBMODE_BIT_OFFSET 0x0 + submode_bits = (xioctl_filter[cmd] & XIOCTL_FILTER_SUBMODE_MASK)>>XIOCTL_FILTER_SUBMODE_BIT_OFFSET; + + if (submode == SUBTYPE_P2PDEV || submode == SUBTYPE_P2PCLIENT || + submode == SUBTYPE_P2PGO) { + /* P2P Submode */ + if (submode_bits & XIOCTL_FILTER_P2P_SUBMODE) { + is_valid_submode = TRUE; + } + } else { + /* Non P2P Sub mode */ + if ((submode_bits & XIOCTL_FILTER_NONP2P_SUBMODE)) { + is_valid_submode = TRUE; + } + } + + if (is_valid_mode && is_valid_submode) { + return A_OK; + } + + return A_ERROR; +} + +#ifdef WAPI_ENABLE +int +ap_set_wapi_key(AR_SOFTC_DEV_T *arPriv, void *ikey) +{ + struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey; + KEY_USAGE keyUsage = 0; + A_STATUS status; + + if (A_MEMCMP(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) { + keyUsage = GROUP_USAGE; + } else { + keyUsage = PAIRWISE_USAGE; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n", + keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5], + ik->ik_keylen)); + + status = wmi_addKey_cmd(arPriv->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage, + ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc, + ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, + SYNC_BOTH_WMIFLAG); + + if (A_OK != status) { + return -EIO; + } + return 0; +} +#endif + +#ifdef P2P + +void ar6000_p2p_prov_disc_req_event(AR_SOFTC_DEV_T *arPriv, + const A_UINT8 *peer, A_UINT16 wps_config_method, + const A_UINT8 *dev_addr, const A_UINT8 *pri_dev_type, + const A_UINT8 *dev_name, A_UINT8 dev_name_len, + A_UINT16 supp_config_methods, A_UINT8 dev_capab, A_UINT8 group_capab) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + A_UINT8 *pos=buf; + + A_MEMZERO(pos, sizeof(buf)); + A_MEMCPY(pos, "P2PPROVDISCREQ", 14); + pos += 14; + + A_MEMCPY(pos, peer, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + A_MEMCPY(pos, dev_addr, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + A_MEMCPY(pos, pri_dev_type, 8); + pos += 8; + + A_MEMCPY(pos, dev_name, dev_name_len); + pos += dev_name_len; + *pos++ = '\0'; + + A_MEMCPY(pos, (A_UINT8 *)&supp_config_methods, 2); + pos += 2; + + A_MEMCPY(pos, (A_UINT8 *)&wps_config_method, 2); + pos += 2; + + A_MEMCPY(pos, &dev_capab, 1); + pos++; + + A_MEMCPY(pos, &group_capab, 1); + pos++; + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = (pos-buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +void ar6000_p2p_prov_disc_resp_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *peer, + A_UINT16 config_methods) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + A_UINT8 *pos=buf; + + A_MEMZERO(pos, sizeof(buf)); + A_MEMCPY(pos, "P2PPROVDISCRESP", 15); + pos += 15; + + A_MEMCPY(pos, peer, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + A_MEMCPY(pos, (A_UINT8 *)&config_methods, 2); + pos += 2; + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = (pos-buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +void ar6000_p2pdev_event(AR_SOFTC_DEV_T *arPriv, const A_UINT8 *addr, + const A_UINT8 *dev_addr, + const A_UINT8 *pri_dev_type, const A_UINT8 *dev_name, + A_UINT8 dev_name_len, A_UINT16 config_methods, A_UINT8 dev_capab, + A_UINT8 grp_capab) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + A_UINT8 *pos=buf; + + A_MEMZERO(pos, sizeof(buf)); + A_MEMCPY(pos, "P2PDEVFOUND", 11); + pos += 11; + + A_MEMCPY(pos, addr, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + A_MEMCPY(pos, dev_addr, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + /* Size of P2P Attributes hardcoded here. Can this be changed ? + */ + A_MEMCPY(pos, pri_dev_type, 8); + pos += 8; + + A_MEMCPY(pos, dev_name, dev_name_len); + pos += dev_name_len; + *pos++ = '\0'; + + A_MEMCPY(pos, (A_UINT8 *)&config_methods, 2); + pos += 2; + + A_MEMCPY(pos, &dev_capab, 1); + pos++; + + A_MEMCPY(pos, &grp_capab, 1); + pos++; + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = (pos-buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); + + return; +} + +void ar6000_p2p_sd_rx_event(AR_SOFTC_DEV_T *arPriv, WMI_P2P_SDPD_RX_EVENT *ev) +{ + union iwreq_data wrqu; + A_UINT8 *event_ptr; + A_UINT8 *pos; + A_UINT16 size; + +#define P2P_SD_REQ_RESP_STR_LEN 12 + size = P2P_SD_REQ_RESP_STR_LEN + + sizeof(WMI_P2P_SDPD_RX_EVENT) + + ev->tlv_length; + event_ptr = A_MALLOC_NOWAIT(size); + pos = event_ptr; + A_MEMZERO(pos, size); + A_MEMCPY(pos, "P2PSDREQRESP", P2P_SD_REQ_RESP_STR_LEN); + pos += P2P_SD_REQ_RESP_STR_LEN; +#undef P2P_SD_REQ_RESP_STR_LEN + + /* Copy the event followed by TLV, parsing will be dobe in supplicant */ + A_MEMCPY(pos, ev, sizeof(WMI_P2P_SDPD_RX_EVENT) + ev->tlv_length); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = size; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, event_ptr); + + A_FREE(event_ptr); + return; +} + +void p2p_go_neg_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *res, A_UINT8 len) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + + A_MEMZERO(&buf, sizeof(buf)); + A_MEMCPY(buf, "P2PNEGCOMPLETE",14); + A_MEMCPY(&buf[14], res, len); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = 14+len; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +void p2p_go_neg_req_event(AR_SOFTC_DEV_T *arPriv, const A_UINT8 *sa, A_UINT16 dev_passwd_id) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + A_UINT8 *pos=buf; + + A_MEMZERO(pos, sizeof(buf)); + A_MEMCPY(pos, "P2PNEGREQEV", 11); + pos += 11; + + A_MEMCPY(pos, sa, IEEE80211_ADDR_LEN); + pos += IEEE80211_ADDR_LEN; + + A_MEMCPY(pos, (A_UINT8 *)&dev_passwd_id, 2); + pos += 2; + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = (pos-buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + + +void p2p_invite_sent_result_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 *res, + A_UINT8 len) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + + A_MEMZERO(&buf, sizeof(buf)); + A_MEMCPY(buf, "P2PINVITESENTRESULT", 19); + A_MEMCPY(&buf[19], res, len); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = 19 + len; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +void p2p_invite_rcvd_result_event(AR_SOFTC_DEV_T *arPriv, + A_UINT8 *res, A_UINT8 len) +{ + union iwreq_data wrqu; + A_UINT8 buf[100]; + + A_MEMZERO(&buf, sizeof(buf)); + A_MEMCPY(buf, "P2PINVITERCVDRESULT", 19); + A_MEMCPY(&buf[19], res, len); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = 19 + len; + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +#endif /* P2P */ + +void ar6000_peer_event( + void *context, + A_UINT8 eventCode, + A_UINT8 *macAddr) +{ + A_UINT8 pos; + + for (pos=0;pos<6;pos++) + printk("%02x: ",*(macAddr+pos)); + printk("\n"); +} + +void ar6000_get_device_addr(AR_SOFTC_DEV_T *arPriv, A_UINT8 *addr) +{ + A_MEMCPY(addr, arPriv->arNetDev->dev_addr, IEEE80211_ADDR_LEN); + return; +} + +#ifdef HTC_TEST_SEND_PKTS +#define HTC_TEST_DUPLICATE 8 +static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb) +{ + struct ar_cookie *cookie; + struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE]; + struct sk_buff *new_skb; + int i; + int pkts = 0; + HTC_PACKET_QUEUE pktQueue; + EPPING_HEADER *eppingHdr; + + eppingHdr = A_NETBUF_DATA(dupskb); + + if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) { + /* skip test if this is already a tx perf test */ + return; + } + + for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) { + AR6000_SPIN_LOCK(&ar->arLock, 0); + cookie = ar6000_alloc_cookie(ar); + if (cookie != NULL) { + ar->arTxPending[eid]++; + ar->arTotalTxDataPending++; + } + + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + + if (NULL == cookie) { + break; + } + + new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb)); + + if (new_skb == NULL) { + AR6000_SPIN_LOCK(&ar->arLock, 0); + ar6000_free_cookie(ar,cookie); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + break; + } + + A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb)); + cookie->arc_bp[0] = (A_UINT32)new_skb; + cookie->arc_bp[1] = MapNo; + SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, + cookie, + A_NETBUF_DATA(new_skb), + A_NETBUF_LEN(new_skb), + eid, + AR6K_DATA_PKT_TAG); + + cookieArray[i] = cookie; + + { + EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb); + pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */ + } + } + + if (pkts == 0) { + return; + } + + INIT_HTC_PACKET_QUEUE(&pktQueue); + + for (i = 0; i < pkts; i++) { + HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt); + } + + HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue); + +} + +#endif + +#ifdef RK29 + +#include + +static struct wifi_platform_data *wifi_control_data = NULL; +struct semaphore wifi_control_sem; + +int wifi_set_carddetect(int on) +{ + if (wifi_control_data && wifi_control_data->set_carddetect) { + wifi_control_data->set_carddetect(on); + } + return 0; +} + +int wifi_set_power(int on, unsigned long msec) +{ + if (wifi_control_data && wifi_control_data->set_power) { + wifi_control_data->set_power(on); + } + if (msec) + mdelay(msec); + return 0; +} + +int wifi_set_reset(int on, unsigned long msec) +{ + if (wifi_control_data && wifi_control_data->set_reset) { + wifi_control_data->set_reset(on); + } + if (msec) + mdelay(msec); + return 0; +} + +static int wifi_probe(struct platform_device *pdev) +{ + struct wifi_platform_data *wifi_ctrl = + (struct wifi_platform_data *)(pdev->dev.platform_data); + + wifi_control_data = wifi_ctrl; + + /* make sure power-off */ + wifi_set_reset(0, 5); + wifi_set_power(0, 5); + + wifi_set_power(1, 50); /* Power On */ + wifi_set_reset(1, 150); /* Reset */ + wifi_set_carddetect(1); /* CardDetect (0->1) */ + + up(&wifi_control_sem); + return 0; +} + +static int wifi_remove(struct platform_device *pdev) +{ + struct wifi_platform_data *wifi_ctrl = + (struct wifi_platform_data *)(pdev->dev.platform_data); + + wifi_control_data = wifi_ctrl; + + wifi_set_reset(0, 5); /* Reset */ + wifi_set_power(0, 5); /* Power Off */ + wifi_set_carddetect(0); /* CardDetect (1->0) */ + + up(&wifi_control_sem); + return 0; +} + +static int wifi_suspend(struct platform_device *pdev, pm_message_t state) +{ + return 0; +} +static int wifi_resume(struct platform_device *pdev) +{ + return 0; +} + +static struct platform_driver wifi_device = { + .probe = wifi_probe, + .remove = wifi_remove, + .suspend = wifi_suspend, + .resume = wifi_resume, + .driver = { + .name = "bcm4329_wlan", + } +}; + +int wifi_add_dev(void) +{ + return platform_driver_register(&wifi_device); +} + +void wifi_del_dev(void) +{ + platform_driver_unregister(&wifi_device); +} + +static inline int _down_timeout(struct semaphore *sem, long jiffies) { + int i = 0, ret = 0; + static const int quantum_ms = 1000 / HZ; + + ret = down_trylock(sem); + for (i = jiffies; (i > 0 && ret != 0); i -= quantum_ms) { + schedule_timeout_interruptible(1); + ret = down_trylock(sem); + } + + return ret; +} + +int rockchip_wifi_init_module(void) +{ + int error; +#if 0//def TCHIP + extern char softmac_path[]; + char filename[256]; + extern int android_readwrite_file(const A_CHAR *filename, A_CHAR *rbuf, const A_CHAR *wbuf, size_t length); + + sprintf(filename, "%s/%s", softmac_path, "tcmd"); + if (android_readwrite_file(filename, NULL, NULL, 0) < 0) { + printk("%s :: normal mode\n", __func__); + testmode = 0; + } else { + printk("%s :: test mode\n", __func__); + testmode = 1; + } +#endif + printk("ar6003 diver rkversion: [v1.10]\n"); + + sema_init(&wifi_control_sem, 0); + error = wifi_add_dev(); + if (error) { + printk("%s: platform_driver_register failed\n", __FUNCTION__); + return -1; + } + + /* Waiting callback after platform_driver_register is done or exit with error */ + if (_down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) { + error = -EINVAL; + printk("%s: platform_driver_register timeout\n", __FUNCTION__); + wifi_del_dev(); + return -1; + } + + ifname[0] = 0; + devmode[0] = 0; + printk("ifname = %s, devmode = %s.\n", ifname, devmode); + + ar6000_init_module(); + ar6000_pm_init(); + + return 0; +} +#include "wifi_launcher/wlan_param.h" +int rockchip_wifi_init_module_param(wlan_param *param) +{ + int error; +#if 0//def TCHIP + extern char softmac_path[]; + char filename[256]; + extern int android_readwrite_file(const A_CHAR *filename, A_CHAR *rbuf, const A_CHAR *wbuf, size_t length); + + sprintf(filename, "%s/%s", softmac_path, "tcmd"); + if (android_readwrite_file(filename, NULL, NULL, 0) < 0) { + printk("%s :: normal mode\n", __func__); + testmode = 0; + } else { + printk("%s :: test mode\n", __func__); + testmode = 1; + } +#endif + + sema_init(&wifi_control_sem, 0); + error = wifi_add_dev(); + if (error) { + printk("%s: platform_driver_register failed\n", __FUNCTION__); + return -1; + } + + /* Waiting callback after platform_driver_register is done or exit with error */ + if (_down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) { + error = -EINVAL; + printk("%s: platform_driver_register timeout\n", __FUNCTION__); + wifi_del_dev(); + return -1; + } + + strcpy(ifname, param->ifname); + strcpy(devmode, param->devmode); + + printk("ifname = %s, devmode = %s.\n", ifname, devmode); + + ar6000_init_module(); + ar6000_pm_init(); + + return 0; +} +void rockchip_wifi_exit_module(void) +{ + ar6000_cleanup_module(); + ar6000_pm_exit(); + wifi_del_dev(); +} +EXPORT_SYMBOL(rockchip_wifi_init_module); +EXPORT_SYMBOL(rockchip_wifi_init_module_param); +EXPORT_SYMBOL(rockchip_wifi_exit_module); +//module_init(rockchip_wifi_init_module); +//module_exit(rockchip_wifi_exit_module); +#endif + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +EXPORT_SYMBOL(setupbtdev); +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6000_pm.c b/drivers/net/wireless/ar6003/host/os/linux/ar6000_pm.c new file mode 100644 index 000000000000..9aecfe9bd5db --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6000_pm.c @@ -0,0 +1,1115 @@ +// +// +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// +// +// + +/* + * Implementation of system power management + */ + +#include "ar6000_drv.h" +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) +#include +#endif +#include "wlan_config.h" + +#ifdef CONFIG_HAS_WAKELOCK +#include +#endif + +#define WOW_ENABLE_MAX_INTERVAL 1 +#define WOW_SET_SCAN_PARAMS 1 + +extern unsigned int wmitimeout; +extern unsigned int num_device; + +#ifdef CONFIG_PM + +#if PLAT_WOW_GPIO_PIN || PLAT_WLAN_CHIP_PWD_PIN +#include +#endif + +#if PLAT_WOW_GPIO_PIN +static int wow_irq; +#endif /* PLAT_WOW_GPIO_PIN */ + +#ifdef CONFIG_HAS_WAKELOCK +struct wake_lock ar6k_suspend_wake_lock; +struct wake_lock ar6k_wow_wake_lock; +#endif +#endif /* CONFIG_PM */ + +#ifdef ANDROID_ENV +extern void android_ar6k_check_wow_status(AR_SOFTC_T *ar, struct sk_buff *skb, A_BOOL isEvent); +#endif +#undef ATH_MODULE_NAME +#define ATH_MODULE_NAME pm +#define ATH_DEBUG_PM ATH_DEBUG_MAKE_MODULE_MASK(0) + +#ifdef DEBUG +static ATH_DEBUG_MASK_DESCRIPTION pm_debug_desc[] = { + { ATH_DEBUG_PM , "System power management"}, +}; + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(pm, + "pm", + "System Power Management", + ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_PM, + ATH_DEBUG_DESCRIPTION_COUNT(pm_debug_desc), + pm_debug_desc); + +#endif /* DEBUG */ + +A_STATUS ar6000_exit_cut_power_state(AR_SOFTC_T *ar); + +#ifdef CONFIG_PM +static void ar6k_send_asleep_event_to_app(AR_SOFTC_DEV_T *arPriv, A_BOOL asleep) +{ + char buf[128]; + union iwreq_data wrqu; + + snprintf(buf, sizeof(buf), "HOST_ASLEEP=%s", asleep ? "asleep" : "awake"); + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = strlen(buf); + wireless_send_event(arPriv->arNetDev, IWEVCUSTOM, &wrqu, buf); +} + +static void ar6000_wow_resume(AR_SOFTC_T *ar) +{ + HIF_DEVICE_POWER_CHANGE_TYPE config; + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_STA_T *arSta; + A_UINT8 i; + + if (ar->arWowState!= WLAN_WOW_STATE_NONE) { + config = HIF_DEVICE_POWER_UP; + HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + } + + for(i = 0; i < num_device; i++) { + arPriv = ar->arDev[i]; + arSta = &arPriv->arSta; + + /* + * Free all wlan_nodes (scanned APs that we detected previously) + * because during the time we were suspended, the device may have + * been moved to a new location and these APs scanned for before + * suspend may not be valid + */ + wmi_free_allnodes(arPriv->arWmi); + + if (ar->arWowState!= WLAN_WOW_STATE_NONE) { + A_UINT16 fg_start_period = (arSta->scParams.fg_start_period==0) ? 1 : arSta->scParams.fg_start_period; + A_UINT16 bg_period = (arSta->scParams.bg_period==0) ? 60 : arSta->scParams.bg_period; + WMI_SET_HOST_SLEEP_MODE_CMD hostSleepMode = {TRUE, FALSE}; + ar->arWowState = WLAN_WOW_STATE_NONE; +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_timeout(&ar6k_wow_wake_lock, 3*HZ); +#endif + if (wmi_set_host_sleep_mode_cmd(arPriv->arWmi, &hostSleepMode)!=A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup restore host awake\n")); + } + + if (arPriv->arNetworkType!=AP_NETWORK) { +#if WOW_SET_SCAN_PARAMS + wmi_scanparams_cmd(arPriv->arWmi, fg_start_period, + arSta->scParams.fg_end_period, + bg_period, + arSta->scParams.minact_chdwell_time, + arSta->scParams.maxact_chdwell_time, + arSta->scParams.pas_chdwell_time, + arSta->scParams.shortScanRatio, + arSta->scParams.scanCtrlFlags, + arSta->scParams.max_dfsch_act_time, + arSta->scParams.maxact_scan_per_ssid); +#else + (void)fg_start_period; + (void)bg_period; +#endif + + +#if WOW_ENABLE_MAX_INTERVAL /* we don't do it if the power consumption is already good enough. */ + if (wmi_listeninterval_cmd(arPriv->arWmi, arSta->arListenIntervalT, arSta->arListenIntervalB) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to restore WoW listen interval %d\n", arSta->arListenIntervalT)); + } else { + if (wmi_bmisstime_cmd(arPriv->arWmi, arSta->arBmissTimeT, arSta->arBmissTimeB) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to restore WoW bmiss %d\n", arSta->arBmissTimeT)); + } + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("WoW does not invoked. skip resume")); + } +#endif + } + ar6k_send_asleep_event_to_app(arPriv, FALSE); + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Resume WoW successfully\n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("WoW does not invoked. skip resume")); + } + } + + ar->arWlanPowerState = WLAN_POWER_STATE_ON; +} + +static void ar6000_wow_suspend(AR_SOFTC_T *ar) +{ + struct net_device *ndev; + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_STA_T *arSta; + A_INT32 i, j; + A_STATUS status; +#define WOW_LIST_ID 1 + /* Setup WoW for unicast & Arp request for our own IP + * disable background scan. Set listen interval into 1000 TUs + * Enable keepliave for 110 seconds + */ + struct in_ifaddr **ifap = NULL; + struct in_ifaddr *ifa = NULL; + HIF_DEVICE_POWER_CHANGE_TYPE config; + struct in_device *in_dev; + WMI_ADD_WOW_PATTERN_CMD addWowCmd = { .filter = { 0 } }; + WMI_DEL_WOW_PATTERN_CMD delWowCmd; + WMI_SET_HOST_SLEEP_MODE_CMD hostSleepMode = {FALSE, TRUE}; + WMI_SET_WOW_MODE_CMD wowMode = { .enable_wow = TRUE, + .hostReqDelay = 500 };/*500 ms delay*/ + + if (ar->arWowState!= WLAN_WOW_STATE_NONE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("System already go into wow mode!\n")); + return; + } + + ar6000_TxDataCleanup(ar); /* IMPORTANT, otherwise there will be 11mA after listen interval as 1000*/ + + for(j = 0; j< num_device; j++) + { + arPriv = ar->arDev[j]; + arSta = &arPriv->arSta; + ndev = arPriv->arNetDev; + /* clear up our WoW pattern first */ + for (i=0; iarWmi, &delWowCmd); + } + + if (arPriv->arNetworkType == AP_NETWORK) { + /* setup all unicast IP packet pattern for WoW */ +#if WLAN_CONFIG_SIMPLE_WOW_AP_MODE + /* IP packets except boradcast */ + A_UINT8 allData[] = { 0x08 }; /* Either IP 0x0800, ARP 0x0806 or EAPOL-like 0x8800 */ + A_UINT8 allMask[] = { 0x7f }; + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(allMask); + addWowCmd.filter_offset = 20; + status = wmi_add_wow_pattern_cmd(ar->arWmi, &addWowCmd, allData, allMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add WoW simple pattern for AP mode\n")); + } +#else + /* Unicast IP, EAPOL-like and ARP packets */ + A_UINT8 unicastData[] = { + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x08, }; + A_UINT8 unicastMask[] = { + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f }; + A_UINT8 discoverData[] = { 0xe0, 0x00, 0x00, 0xf8 }; + A_UINT8 discoverMask[] = { 0xf0, 0x00, 0x00, 0xf8 }; + A_UINT8 arpData[] = { 0x08, 0x06 }; + A_UINT8 arpMask[] = { 0xff, 0xff }; + A_UINT8 dhcpData[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x43 /* port 67 */ + }; + A_UINT8 dhcpMask[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff /* port 67 */ + }; + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(unicastMask); + addWowCmd.filter_offset = 0; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, unicastData, unicastMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add WoW unicast IP pattern for AP mode\n")); + } + /* setup all ARP packet pattern for WoW */ + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(arpMask); + addWowCmd.filter_offset = 20; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, arpData, arpMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add WoW ARP pattern for AP mode\n")); + } + /* Setup multicast pattern for mDNS 224.0.0.251, SSDP 239.255.255.250 and LLMNR 224.0.0.252*/ + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(discoverMask); + addWowCmd.filter_offset = 38; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, discoverData, discoverMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add mDNS/SSDP/LLMNR pattern for AP mode WoW\n")); + } + /* setup all DHCP broadcast packet pattern for WoW */ + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(dhcpMask); + addWowCmd.filter_offset = 0; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, dhcpData, dhcpMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add WoW DHCP broadcast pattern for AP mode\n")); + } +#endif /* WLAN_CONFIG_SIMPLE_WOW_AP_MODE */ + } else { + /* station mode */ + A_UINT8 macMask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + A_UINT16 wow_listen_interval = A_MAX_WOW_LISTEN_INTERVAL; +#if WOW_ENABLE_MAX_INTERVAL /* we don't do it if the power consumption is already good enough. */ + if (wmi_listeninterval_cmd(arPriv->arWmi, wow_listen_interval, 0) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup WoW listen interval %d\n", wow_listen_interval)); + } else { + /* + * The default bmiss is 1500ms when listen interval is 100ms + * We set listen interval x 15 times as bmiss time here + */ + A_UINT16 bmissTime = wow_listen_interval*15; + if (bmissTime > MAX_BMISS_TIME) { + bmissTime = MAX_BMISS_TIME; + } + if (wmi_bmisstime_cmd(arPriv->arWmi, bmissTime, 0) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup WoW bmiss %d\n", bmissTime)); + } + } +#else + (void)wow_listen_interval; +#endif + +#if WOW_SET_SCAN_PARAMS + status = wmi_scanparams_cmd(arPriv->arWmi, 0xFFFF, 0, 0xFFFF, 0, 0, 0, 0, 0, 0, 0); +#endif + /* setup unicast packet pattern for WoW */ + if (ndev->dev_addr[1]) { + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = 6; /* MAC address */ + addWowCmd.filter_offset = 0; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, ndev->dev_addr, macMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add WoW pattern\n")); + } + } + + /* Setup multicast pattern for mDNS 224.0.0.251, SSDP 239.255.255.250 and LLMNR 224.0.0.252*/ + if ( ndev->flags & IFF_ALLMULTI || +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + (ndev->flags & IFF_MULTICAST && ndev->mc_count>0) ) +#else + (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev)>0) ) +#endif + { + A_UINT8 discoverData[] = { 0xe0, 0x00, 0x00, 0xf8 }; + A_UINT8 discoverMask[] = { 0xf0, 0x00, 0x00, 0xf8 }; + A_MEMZERO(&addWowCmd, sizeof(addWowCmd)); + addWowCmd.filter_list_id = WOW_LIST_ID; + addWowCmd.filter_size = sizeof(discoverMask); + addWowCmd.filter_offset = 38; + status = wmi_add_wow_pattern_cmd(arPriv->arWmi, &addWowCmd, discoverData, discoverMask, addWowCmd.filter_size); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to add mDNS/SSDP/LLMNR pattern for WoW\n")); + } + } + + ar6k_send_asleep_event_to_app(arPriv, TRUE); + } + + ar->arWowState = WLAN_WOW_STATE_SUSPENDING; + + /* setup ARP request for our own IP */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) + if ((in_dev = __in_dev_get_rtnl(ndev)) != NULL) { + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; ifap = &ifa->ifa_next) { + if (!strcmp(ndev->name, ifa->ifa_label)) { + break; /* found */ + } + } + } +#endif + + if (ifa && ifa->ifa_local) { + WMI_SET_IP_CMD ipCmd; + memset(&ipCmd, 0, sizeof(ipCmd)); + ipCmd.ips[0] = ifa->ifa_local; + status = wmi_set_ip_cmd(arPriv->arWmi, &ipCmd); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup IP for ARP agent\n")); + } + } + +#ifndef ATH6K_CONFIG_OTA_MODE + wmi_powermode_cmd(arPriv->arWmi, REC_POWER); +#endif + + status = wmi_set_wow_mode_cmd(arPriv->arWmi, &wowMode); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to enable wow mode\n")); + } + + status = wmi_set_host_sleep_mode_cmd(arPriv->arWmi, &hostSleepMode); + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to set host asleep\n")); + } + + if (ar->arTxPending[ar->arControlEp]) { + A_UINT32 timeleft = wait_event_interruptible_timeout(arPriv->arEvent, + ar->arTxPending[ar->arControlEp] == 0, wmitimeout * HZ); + if (!timeleft || signal_pending(current)) { + /* what can I do? wow resume at once */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup WoW. Pending wmi control data %d\n", ar->arTxPending[ar->arControlEp])); + } + } + } + + status = hifWaitForPendingRecv(ar->arHifDevice); + + config = HIF_DEVICE_POWER_DOWN; + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + + ar->arWowState = WLAN_WOW_STATE_SUSPENDED; + ar->arWlanPowerState = WLAN_POWER_STATE_WOW; + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Setup WoW successfully\n")); +} + +A_STATUS ar6000_suspend_ev(void *context) +{ + A_STATUS status = A_OK; + AR_SOFTC_T *ar = (AR_SOFTC_T *)context; + A_INT16 pmmode = ar->arSuspendConfig; + A_INT32 i; + A_BOOL needWow = FALSE; +wow_not_connected: + switch (pmmode) { + case WLAN_SUSPEND_WOW: + for(i = 0; i< num_device; i++) { + if (ar->arDev[i]->arConnected) { + needWow = TRUE; + break; + } + } + if (ar->arWmiReady && ar->arWlanState==WLAN_ENABLED && needWow) { + ar6000_wow_suspend(ar); + status = A_EBUSY; + AR_DEBUG_PRINTF(ATH_DEBUG_PM,("%s:Suspend for wow mode %d\n", __func__, ar->arWlanPowerState)); + } else { + pmmode = ar->arWow2Config; + goto wow_not_connected; + } + break; + case WLAN_SUSPEND_CUT_PWR: + /* fall through */ + case WLAN_SUSPEND_CUT_PWR_IF_BT_OFF: + /* fall through */ + case WLAN_SUSPEND_DEEP_SLEEP: + /* fall through */ + default: + status = ar6000_update_wlan_pwr_state(ar, WLAN_DISABLED, TRUE); + if (ar->arWlanPowerState==WLAN_POWER_STATE_ON || + ar->arWlanPowerState==WLAN_POWER_STATE_WOW) { + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Strange suspend state for not wow mode %d", ar->arWlanPowerState)); + } + AR_DEBUG_PRINTF(ATH_DEBUG_PM,("%s:Suspend for %d mode pwr %d status %d\n", __func__, pmmode, ar->arWlanPowerState, status)); + if (ar->arWlanPowerState==WLAN_POWER_STATE_CUT_PWR) { + status = A_OK; + } else { + status = A_EBUSY; /* don't let mmc call sdio_init after resume */ + } + break; + } + + for(i = 0; i < num_device; i++) { + AR_SOFTC_DEV_T *arPriv = ar->arDev[i]; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + if (arSta->scan_triggered) { + ar6000_scanComplete_event(arPriv, A_OK); + } + } + return status; +} + +A_STATUS ar6000_resume_ev(void *context) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)context; + A_UINT16 powerState = ar->arWlanPowerState; + +#ifdef CONFIG_HAS_WAKELOCK + wake_lock(&ar6k_suspend_wake_lock); +#endif + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: enter previous state %d wowState %d\n", __func__, powerState, ar->arWowState)); + switch (powerState) { + case WLAN_POWER_STATE_WOW: + ar6000_wow_resume(ar); + break; + case WLAN_POWER_STATE_CUT_PWR: + /* fall through */ + case WLAN_POWER_STATE_DEEP_SLEEP: + ar6000_update_wlan_pwr_state(ar, WLAN_ENABLED, TRUE); + AR_DEBUG_PRINTF(ATH_DEBUG_PM,("%s:Resume for %d mode pwr %d\n", __func__, powerState, ar->arWlanPowerState)); + break; + case WLAN_POWER_STATE_ON: + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Strange SDIO bus power mode!!\n")); + break; + } +#ifdef CONFIG_HAS_WAKELOCK + wake_unlock(&ar6k_suspend_wake_lock); +#endif + return A_OK; +} + +void ar6000_check_wow_status(AR_SOFTC_T *ar, struct sk_buff *skb, A_BOOL isEvent) +{ + if (ar->arWowState!=WLAN_WOW_STATE_NONE) { + if (ar->arWowState==WLAN_WOW_STATE_SUSPENDING) { + AR_DEBUG_PRINTF(ATH_DEBUG_PM,("\n%s: Received IRQ while we are wow suspending!!!\n\n", __func__)); + return; + } + /* Wow resume from irq interrupt */ + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: WoW resume from irq thread status %d\n", __func__, ar->arWlanPowerState)); + ar6000_wow_resume(ar); + } else { +#ifdef ANDROID_ENV + android_ar6k_check_wow_status(ar, skb, isEvent); +#endif + } +} + +A_STATUS ar6000_power_change_ev(void *context, A_UINT32 config) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)context; + A_STATUS status = A_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: power change event callback %d \n", __func__, config)); + switch (config) { + case HIF_DEVICE_POWER_UP: + ar6000_restart_endpoint(ar); +#ifdef ANDROID_ENV + ar->arResumeDone = TRUE; + wake_up(&(ar->arDev[0]->arEvent)); +#endif /* ANDROID_ENV */ + status = A_OK; + break; + case HIF_DEVICE_POWER_DOWN: + case HIF_DEVICE_POWER_CUT: + status = A_OK; + break; + } + return status; +} + +#if PLAT_WOW_GPIO_PIN +static irqreturn_t +ar6000_wow_irq(int irq, void *dev_id) +{ + gpio_clear_detect_status(wow_irq); +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_timeout(&ar6k_wow_wake_lock, 3*HZ); +#else + /* TODO: What should I do if there is no wake lock?? */ +#endif + return IRQ_HANDLED; +} +#endif /* PLAT_WOW_GPIO_PIN */ + +#if PLAT_WLAN_CHIP_PWD_PIN +void plat_setup_power_stub(AR_SOFTC_T *ar, int on, int detect) +{ +#if 0//def RK29 +extern int wifi_turn_on_card(void); +extern int wifi_turn_off_card(void); +extern int rk29sdk_wifi_set_carddetect(int val); +extern int wifi_power_up_wifi(void); +extern int wifi_power_down_wifi(void); + + printk("%s :: on %d, detect %d\n", __func__, on, detect); + if (on) { + wifi_turn_on_card(); + wifi_power_up_wifi(); + } else { + wifi_turn_off_card(); + wifi_power_down_wifi(); + } + /* rk29sdk_wifi_set_carddetect(detect ? 1 : 0); */ + +#else + A_BOOL chip_pwd_low_val; + + if (on) { + chip_pwd_low_val = 1; + } else { + chip_pwd_low_val = 0; + } + + if (gpio_request(PLAT_WLAN_CHIP_PWD_PIN, "wlan_chip_pwd_l")!=0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Cannot request CHIP_PWD GPIO")); + } else { + gpio_direction_output(PLAT_WLAN_CHIP_PWD_PIN, 0);/* WLAN_CHIP_PWD */ + gpio_set_value(PLAT_WLAN_CHIP_PWD_PIN, chip_pwd_low_val); + A_MDELAY(100); + gpio_free(PLAT_WLAN_CHIP_PWD_PIN); + } +#endif +} +#endif /* PLAT_WLAN_CHIP_PWD_PIN */ + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) +static int ar6000_pm_probe(struct platform_device *pdev) +{ + plat_setup_power(NULL, 1, 1); + return 0; +} + +static int ar6000_pm_remove(struct platform_device *pdev) +{ +#ifdef RK29 + plat_setup_power(NULL, 0, 0); +#else + plat_setup_power(NULL, 0, 1); +#endif + return 0; +} + +static int ar6000_pm_suspend(struct platform_device *pdev, pm_message_t state) +{ + return 0; +} + +static int ar6000_pm_resume(struct platform_device *pdev) +{ + int i; + extern struct net_device *ar6000_devices[MAX_AR6000]; + for (i=0; ar6000_devices[i]; ++i) { + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[i]); + AR_SOFTC_T *ar = (AR_SOFTC_T *)arPriv->arSoftc; + if (ar && ar->arPlatPowerOff) { + A_BOOL wlanOff = ar->arWlanOff; + A_UINT16 powerState = ar->arWlanPowerState; + A_BOOL btOff = ar->arBTOff; + + if (!wlanOff) { + if (powerState == WLAN_POWER_STATE_CUT_PWR) { + plat_setup_power(ar, 1, 0); + ar->arPlatPowerOff = FALSE; + } + } +#ifdef CONFIG_PM + else if (wlanOff) { + A_BOOL allowCutPwr = ((!ar->arBTSharing) || btOff); + if ((powerState==WLAN_POWER_STATE_CUT_PWR) && (!allowCutPwr)) { + plat_setup_power(ar, 1, 0); + ar->arPlatPowerOff = FALSE; + } + } +#endif /* CONFIG_PM */ + } + } + return 0; +} + +static struct platform_driver ar6000_pm_device = { + .probe = ar6000_pm_probe, + .remove = ar6000_pm_remove, + .suspend = ar6000_pm_suspend, + .resume = ar6000_pm_resume, + .driver = { + .name = "wlan_ar6000_pm_dev", + }, +}; +#endif +#endif /* CONFIG_PM */ + +A_STATUS +ar6000_setup_cut_power_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) +{ + A_STATUS status = A_OK; + HIF_DEVICE_POWER_CHANGE_TYPE config; + + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: Cut power %d %d \n", __func__,state, ar->arWlanPowerState)); +#ifdef CONFIG_PM + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Wlan OFF %d BT OFf %d \n", ar->arWlanOff, ar->arBTOff)); +#endif + do { + if (state == WLAN_ENABLED) { + /* Not in cut power state.. exit */ + if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) { + break; + } + + if (ar->arPlatPowerOff) { + plat_setup_power(ar, 1, 0); + ar->arPlatPowerOff = FALSE; + } + + /* Change the state to ON */ + ar->arWlanPowerState = WLAN_POWER_STATE_ON; + +#ifdef ANDROID_ENV + ar->arResumeDone = FALSE; +#endif /* ANDROID_ENV */ + + /* Indicate POWER_UP to HIF */ + config = HIF_DEVICE_POWER_UP; + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + + if (status == A_PENDING) { +#ifdef ANDROID_ENV + /* Wait for resume done event */ + A_UINT32 timeleft = wait_event_interruptible_timeout(ar->arDev[0]->arEvent, + (ar->arResumeDone == TRUE), wmitimeout * HZ); + if (!timeleft || signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : Failed to get resume done event \n")); + status = A_ERROR; + break; + } +#endif + status = A_OK; + } else if (status == A_OK) { + ar6000_restart_endpoint(ar); +#ifdef ANDROID_ENV + ar->arResumeDone = TRUE; +#endif /* ANDROID_ENV */ + status = A_OK; + } + } else if (state == WLAN_DISABLED) { + + + /* Already in cut power state.. exit */ + if (ar->arWlanPowerState == WLAN_POWER_STATE_CUT_PWR) { + break; + } + ar6000_stop_endpoint(ar, TRUE, FALSE); + + config = HIF_DEVICE_POWER_CUT; + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + + plat_setup_power(ar, 0, 0); + ar->arPlatPowerOff = TRUE; + + ar->arWlanPowerState = WLAN_POWER_STATE_CUT_PWR; + } + } while (0); + + return status; +} + +A_STATUS +ar6000_setup_deep_sleep_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) +{ + A_STATUS status = A_OK; + + HIF_DEVICE_POWER_CHANGE_TYPE config; + AR_SOFTC_DEV_T *arPriv; + AR_SOFTC_STA_T *arSta; + A_UINT8 i; + + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: Deep sleep %d %d \n", __func__,state, ar->arWlanPowerState)); +#ifdef CONFIG_PM + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Wlan OFF %d BT OFf %d \n", ar->arWlanOff, ar->arBTOff)); +#endif + do { + WMI_SET_HOST_SLEEP_MODE_CMD hostSleepMode; + + if (state == WLAN_ENABLED) { + A_UINT16 fg_start_period; + + /* Not in deep sleep state.. exit */ + if (ar->arWlanPowerState != WLAN_POWER_STATE_DEEP_SLEEP) { + if (ar->arWlanPowerState != WLAN_POWER_STATE_ON) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Strange state when we resume from deep sleep %d\n", ar->arWlanPowerState)); + } + break; + } + + /* Indicate POWER_UP to HIF */ + config = HIF_DEVICE_POWER_UP; + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + + for(i = 0; i < num_device; i++) + { + arPriv = ar->arDev[i]; + arSta = &arPriv->arSta; + + /* + * Free all wlan_nodes (scanned APs that we detected previously) + * because during the time we were suspended, the device may have + * been moved to a new location and these APs scanned for before + * suspend may not be valid + */ + wmi_free_allnodes(arPriv->arWmi); + + fg_start_period = (arSta->scParams.fg_start_period==0) ? 1 : arSta->scParams.fg_start_period; + hostSleepMode.awake = TRUE; + hostSleepMode.asleep = FALSE; + + if ((status=wmi_set_host_sleep_mode_cmd(arPriv->arWmi, &hostSleepMode)) != A_OK) { + break; + } + + /* Change the state to ON */ + ar->arWlanPowerState = WLAN_POWER_STATE_ON; + + /* Enable foreground scanning */ + if ((status=wmi_scanparams_cmd(arPriv->arWmi, fg_start_period, + arSta->scParams.fg_end_period, + arSta->scParams.bg_period, + arSta->scParams.minact_chdwell_time, + arSta->scParams.maxact_chdwell_time, + arSta->scParams.pas_chdwell_time, + arSta->scParams.shortScanRatio, + arSta->scParams.scanCtrlFlags, + arSta->scParams.max_dfsch_act_time, + arSta->scParams.maxact_scan_per_ssid)) != A_OK) + { + break; + } + + if (arPriv->arSsidLen) { + if (ar6000_connect_to_ap(arPriv) != A_OK) { + /* no need to report error if connection failed */ + break; + } + } + } + } else if (state == WLAN_DISABLED){ + WMI_SET_WOW_MODE_CMD wowMode = { .enable_wow = FALSE }; + + /* Already in deep sleep state.. exit */ + if (ar->arWlanPowerState != WLAN_POWER_STATE_ON) { + if (ar->arWlanPowerState != WLAN_POWER_STATE_DEEP_SLEEP) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Strange state when we suspend for deep sleep %d\n", ar->arWlanPowerState)); + } + break; + } + + for(i = 0; i < num_device; i++) + { + arPriv = ar->arDev[i]; + arSta = &arPriv->arSta; + /* make sure we disable wow for deep sleep */ + if ((status=wmi_set_wow_mode_cmd(arPriv->arWmi, &wowMode))!=A_OK) { + break; + } + + /* Disconnect from the AP and disable foreground scanning */ + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + if (arPriv->arConnected == TRUE || arSta->arConnectPending == TRUE) { + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + ar6000_disconnect(arPriv); + } else { + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + } + + if ((status=wmi_scanparams_cmd(arPriv->arWmi, 0xFFFF, 0, 0, 0, 0, 0, 0, 0, 0, 0)) != A_OK) { + break; + } + ar6000_TxDataCleanup(ar); +#ifndef ATH6K_CONFIG_OTA_MODE + wmi_powermode_cmd(arPriv->arWmi, REC_POWER); +#endif + + hostSleepMode.awake = FALSE; + hostSleepMode.asleep = TRUE; + if ((status=wmi_set_host_sleep_mode_cmd(arPriv->arWmi, &hostSleepMode))!=A_OK) { + break; + } + if (ar->arTxPending[ar->arControlEp]) { + A_UINT32 timeleft = wait_event_interruptible_timeout(arPriv->arEvent, + ar->arTxPending[ar->arControlEp] == 0, wmitimeout * HZ); + if (!timeleft || signal_pending(current)) { + status = A_ERROR; + break; + } + } + } + status = hifWaitForPendingRecv(ar->arHifDevice); + + config = HIF_DEVICE_POWER_DOWN; + status = HIFConfigureDevice(ar->arHifDevice, + HIF_DEVICE_POWER_STATE_CHANGE, + &config, + sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + + ar->arWlanPowerState = WLAN_POWER_STATE_DEEP_SLEEP; + } + } while (0); + + if (status!=A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to enter/exit deep sleep %d\n", state)); + } + + return status; +} + +A_STATUS +ar6000_update_wlan_pwr_state(struct ar6_softc *ar, AR6000_WLAN_STATE state, A_BOOL pmEvent) +{ + A_STATUS status = A_OK; + A_UINT16 powerState, oldPowerState; + AR6000_WLAN_STATE oldstate = ar->arWlanState; + A_BOOL wlanOff = ar->arWlanOff; +#ifdef CONFIG_PM + A_BOOL btOff = ar->arBTOff; +#endif /* CONFIG_PM */ + A_UINT8 i; + AR_SOFTC_DEV_T *arPriv; + + if ((state!=WLAN_DISABLED && state!=WLAN_ENABLED)) { + return A_ERROR; + } + + if (ar->bIsDestroyProgress) { + return A_EBUSY; + } + + if (down_interruptible(&ar->arSem)) { + return A_ERROR; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return A_EBUSY; + } + + ar->arWlanState = wlanOff ? WLAN_DISABLED : state; + oldPowerState = ar->arWlanPowerState; + if (state == WLAN_ENABLED) { + powerState = ar->arWlanPowerState; + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("WLAN PWR set to ENABLE^^\n")); + if (!wlanOff) { + if (powerState == WLAN_POWER_STATE_DEEP_SLEEP) { + status = ar6000_setup_deep_sleep_state(ar, WLAN_ENABLED); + } else if (powerState == WLAN_POWER_STATE_CUT_PWR) { + status = ar6000_setup_cut_power_state(ar, WLAN_ENABLED); + } + } +#ifdef CONFIG_PM + else if (pmEvent && wlanOff) { + A_BOOL allowCutPwr = ((!ar->arBTSharing) || btOff); + if ((powerState==WLAN_POWER_STATE_CUT_PWR) && (!allowCutPwr)) { + /* Come out of cut power */ + ar6000_setup_cut_power_state(ar, WLAN_ENABLED); + status = ar6000_setup_deep_sleep_state(ar, WLAN_DISABLED); + } + } +#endif /* CONFIG_PM */ + } else if (state == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("WLAN PWR set to DISABLED~\n")); + powerState = WLAN_POWER_STATE_DEEP_SLEEP; +#ifdef CONFIG_PM + if (pmEvent) { /* disable due to suspend */ + A_BOOL suspendCutPwr = (ar->arSuspendConfig == WLAN_SUSPEND_CUT_PWR || + (ar->arSuspendConfig == WLAN_SUSPEND_WOW && + ar->arWow2Config==WLAN_SUSPEND_CUT_PWR)); + A_BOOL suspendCutIfBtOff = ((ar->arSuspendConfig == + WLAN_SUSPEND_CUT_PWR_IF_BT_OFF || + (ar->arSuspendConfig == WLAN_SUSPEND_WOW && + ar->arWow2Config==WLAN_SUSPEND_CUT_PWR_IF_BT_OFF)) && + (!ar->arBTSharing || btOff)); + if ((suspendCutPwr) || + (suspendCutIfBtOff) || + (ar->arWlanPowerState==WLAN_POWER_STATE_CUT_PWR)) + { + if (!wlanOff || ar->arWlanPowerState!=WLAN_POWER_STATE_DEEP_SLEEP) { + powerState = WLAN_POWER_STATE_CUT_PWR; + } + } + } else { + if ((wlanOff) && + (ar->arWlanOffConfig == WLAN_OFF_CUT_PWR) && + (!ar->arBTSharing || btOff)) + { + /* For BT clock sharing designs, CUT_POWER depend on BT state */ + powerState = WLAN_POWER_STATE_CUT_PWR; + } + } +#endif /* CONFIG_PM */ + + if (powerState == WLAN_POWER_STATE_DEEP_SLEEP) { + if (ar->arWlanPowerState == WLAN_POWER_STATE_CUT_PWR) { + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("Load firmware before set to deep sleep\n")); + ar6000_setup_cut_power_state(ar, WLAN_ENABLED); + } + status = ar6000_setup_deep_sleep_state(ar, WLAN_DISABLED); + } else if (powerState == WLAN_POWER_STATE_CUT_PWR) { + status = ar6000_setup_cut_power_state(ar, WLAN_DISABLED); + } + + } + + if (status!=A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Fail to setup WLAN state %d\n", ar->arWlanState)); + ar->arWlanState = oldstate; + } else if (status == A_OK) { + WMI_REPORT_SLEEP_STATE_EVENT wmiSleepEvent, *pSleepEvent = NULL; + if ((ar->arWlanPowerState == WLAN_POWER_STATE_ON) && (oldPowerState != WLAN_POWER_STATE_ON)) { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_AWAKE; + pSleepEvent = &wmiSleepEvent; + } else if ((ar->arWlanPowerState != WLAN_POWER_STATE_ON) && (oldPowerState == WLAN_POWER_STATE_ON)) { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_DEEP_SLEEP; + pSleepEvent = &wmiSleepEvent; + } + if (pSleepEvent) { + AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("SENT WLAN Sleep Event %d\n", wmiSleepEvent.sleepState)); + for(i = 0; i < num_device; i++) + { + arPriv = ar->arDev[i]; + ar6000_send_event_to_app(arPriv, WMI_REPORT_SLEEP_STATE_EVENTID, (A_UINT8*)pSleepEvent, + sizeof(WMI_REPORT_SLEEP_STATE_EVENTID)); + } + } + } + up(&ar->arSem); + return status; +} + +A_STATUS +ar6000_set_bt_hw_state(struct ar6_softc *ar, A_UINT32 enable) +{ +#ifdef CONFIG_PM + A_BOOL off = (enable == 0); + A_STATUS status; + if (ar->arBTOff == off) { + return A_OK; + } + ar->arBTOff = off; + status = ar6000_update_wlan_pwr_state(ar, ar->arWlanOff ? WLAN_DISABLED : WLAN_ENABLED, FALSE); + return status; +#else + return A_OK; +#endif +} + +A_STATUS +ar6000_set_wlan_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) +{ + A_INT32 i; + A_STATUS status; + A_BOOL off = (state == WLAN_DISABLED); + if (ar->arWlanOff == off) { + return A_OK; + } + ar->arWlanOff = off; + status = ar6000_update_wlan_pwr_state(ar, state, FALSE); + for(i = 0; i < num_device; i++) { + AR_SOFTC_DEV_T *arPriv = ar->arDev[i]; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + if (arSta->scan_triggered) { + ar6000_scanComplete_event(arPriv, A_OK); + } + } + return status; +} + +void ar6000_pm_init() +{ + A_REGISTER_MODULE_DEBUG_INFO(pm); +#ifdef CONFIG_PM +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_init(&ar6k_suspend_wake_lock, WAKE_LOCK_SUSPEND, "ar6k_suspend"); + wake_lock_init(&ar6k_wow_wake_lock, WAKE_LOCK_SUSPEND, "ar6k_wow"); +#endif + /* + * Register ar6000_pm_device into system. + * We should also add platform_device into the first item of array + * of devices[] in file arch/xxx/mach-xxx/board-xxxx.c + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) + if (platform_driver_register(&ar6000_pm_device)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: fail to register the power control driver.\n")); + } +#endif + +#if PLAT_WOW_GPIO_PIN + wow_irq = gpio_to_irq(PLAT_WOW_GPIO_PIN); + if (wow_irq) { + int ret; + ret = request_irq(wow_irq, ar6000_wow_irq, + IRQF_SHARED | IRQF_TRIGGER_RISING, + "ar6000" "sdiowakeup", &wow_irq); + if (!ret) { + ret = enable_irq_wake(wow_irq); + if (ret < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Couldn't enable WoW IRQ as wakeup interrupt")); + } + } + } +#endif /* PLAT_WOW_GPIO_PIN */ +#endif /* CONFIG_PM */ +} + +void ar6000_pm_exit() +{ +#ifdef CONFIG_PM +#if PLAT_WOW_GPIO_PIN + if (wow_irq) { + if (disable_irq_wake(wow_irq)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Couldn't disable hostwake IRQ wakeup mode\n")); + } + free_irq(wow_irq, &wow_irq); + wow_irq = 0; + } +#endif /* PLAT_WOW_GPIO_PIN */ + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) + platform_driver_unregister(&ar6000_pm_device); +#endif +#ifdef CONFIG_HAS_WAKELOCK + wake_lock_destroy(&ar6k_suspend_wake_lock); + wake_lock_destroy(&ar6k_wow_wake_lock); +#endif +#endif /* CONFIG_PM */ +} + diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6000_raw_if.c b/drivers/net/wireless/ar6003/host/os/linux/ar6000_raw_if.c new file mode 100644 index 000000000000..39e5823794a8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6000_raw_if.c @@ -0,0 +1,465 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" + +#ifdef HTC_RAW_INTERFACE + +static void +ar6000_htc_raw_read_cb(void *Context, HTC_PACKET *pPacket) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + raw_htc_buffer *busy; + HTC_RAW_STREAM_ID streamID; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + + busy = (raw_htc_buffer *)pPacket->pPktContext; + A_ASSERT(busy != NULL); + + if (pPacket->Status == A_ECANCELED) { + /* + * HTC provides A_ECANCELED status when it doesn't want to be refilled + * (probably due to a shutdown) + */ + return; + } + + streamID = arEndpoint2RawStreamID(ar,pPacket->Endpoint); + A_ASSERT(streamID != HTC_RAW_STREAM_NOT_MAPPED); + if(streamID == HTC_RAW_STREAM_NOT_MAPPED) { + return; /* in case panic_on_assert==0 */ + } + +#ifdef CF + if (down_trylock(&arRaw->raw_htc_read_sem[streamID])) { +#else + if (down_interruptible(&arRaw->raw_htc_read_sem[streamID])) { +#endif /* CF */ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to down the semaphore\n")); + } + + A_ASSERT((pPacket->Status != A_OK) || + (pPacket->pBuffer == (busy->data + HTC_HEADER_LEN))); + + busy->length = pPacket->ActualLength + HTC_HEADER_LEN; + busy->currPtr = HTC_HEADER_LEN; + arRaw->read_buffer_available[streamID] = TRUE; + //AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("raw read cb: 0x%X 0x%X \n", busy->currPtr,busy->length); + up(&arRaw->raw_htc_read_sem[streamID]); + + /* Signal the waiting process */ + AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("Waking up the StreamID(%d) read process\n", streamID)); + wake_up_interruptible(&arRaw->raw_htc_read_queue[streamID]); +} + +static void +ar6000_htc_raw_write_cb(void *Context, HTC_PACKET *pPacket) +{ + AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; + raw_htc_buffer *free; + HTC_RAW_STREAM_ID streamID; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + + free = (raw_htc_buffer *)pPacket->pPktContext; + A_ASSERT(free != NULL); + + if (pPacket->Status == A_ECANCELED) { + /* + * HTC provides A_ECANCELED status when it doesn't want to be refilled + * (probably due to a shutdown) + */ + return; + } + + streamID = arEndpoint2RawStreamID(ar,pPacket->Endpoint); + A_ASSERT(streamID != HTC_RAW_STREAM_NOT_MAPPED); + if(streamID == HTC_RAW_STREAM_NOT_MAPPED) { + return; /* in case panic_on_assert==0 */ + } +#ifdef CF + if (down_trylock(&arRaw->raw_htc_write_sem[streamID])) { +#else + if (down_interruptible(&arRaw->raw_htc_write_sem[streamID])) { +#endif + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to down the semaphore\n")); + } + + A_ASSERT(pPacket->pBuffer == (free->data + HTC_HEADER_LEN)); + + free->length = 0; + arRaw->write_buffer_available[streamID] = TRUE; + up(&arRaw->raw_htc_write_sem[streamID]); + + /* Signal the waiting process */ + AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("Waking up the StreamID(%d) write process\n", streamID)); + wake_up_interruptible(&arRaw->raw_htc_write_queue[streamID]); +} + +/* connect to a service */ +static A_STATUS ar6000_connect_raw_service(AR_SOFTC_T *ar, + HTC_RAW_STREAM_ID StreamID) +{ + A_STATUS status; + HTC_SERVICE_CONNECT_RESP response; + A_UINT8 streamNo; + HTC_SERVICE_CONNECT_REQ connect; + + do { + + A_MEMZERO(&connect,sizeof(connect)); + /* pass the stream ID as meta data to the RAW streams service */ + streamNo = (A_UINT8)StreamID; + connect.pMetaData = &streamNo; + connect.MetaDataLength = sizeof(A_UINT8); + /* these fields are the same for all endpoints */ + connect.EpCallbacks.pContext = ar; + connect.EpCallbacks.EpTxComplete = ar6000_htc_raw_write_cb; + connect.EpCallbacks.EpRecv = ar6000_htc_raw_read_cb; + /* simple interface, we don't need these optional callbacks */ + connect.EpCallbacks.EpRecvRefill = NULL; + connect.EpCallbacks.EpSendFull = NULL; + connect.MaxSendQueueDepth = RAW_HTC_WRITE_BUFFERS_NUM; + + /* connect to the raw streams service, we may be able to get 1 or more + * connections, depending on WHAT is running on the target */ + connect.ServiceID = HTC_RAW_STREAMS_SVC; + + A_MEMZERO(&response,sizeof(response)); + + /* try to connect to the raw stream, it is okay if this fails with + * status HTC_SERVICE_NO_MORE_EP */ + status = HTCConnectService(ar->arHtcTarget, + &connect, + &response); + + if (A_FAILED(status)) { + if (response.ConnectRespCode == HTC_SERVICE_NO_MORE_EP) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HTC RAW , No more streams allowed \n")); + status = A_OK; + } + break; + } + + /* set endpoint mapping for the RAW HTC streams */ + arSetRawStream2EndpointIDMap(ar,StreamID,response.Endpoint); + + AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("HTC RAW : stream ID: %d, endpoint: %d\n", + StreamID, arRawStream2EndpointID(ar,StreamID))); + + } while (FALSE); + + return status; +} + +int ar6000_htc_raw_open(AR_SOFTC_T *ar) +{ + A_STATUS status; + int streamID, endPt, count2; + raw_htc_buffer *buffer; + HTC_SERVICE_ID servicepriority; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + if (!arRaw) { + arRaw = ar->arRawHtc = A_MALLOC(sizeof(AR_RAW_HTC_T)); + if (arRaw) { + A_MEMZERO(arRaw, sizeof(AR_RAW_HTC_T)); + } + } + A_ASSERT(ar->arHtcTarget != NULL); + if (!arRaw) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Faile to allocate memory for HTC RAW interface\n")); + return -ENOMEM; + } + /* wait for target */ + status = HTCWaitTarget(ar->arHtcTarget); + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HTCWaitTarget failed (%d)\n", status)); + return -ENODEV; + } + + for (endPt = 0; endPt < ENDPOINT_MAX; endPt++) { + arRaw->arEp2RawMapping[endPt] = HTC_RAW_STREAM_NOT_MAPPED; + } + + for (streamID = HTC_RAW_STREAM_0; streamID < HTC_RAW_STREAM_NUM_MAX; streamID++) { + /* Initialize the data structures */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) + sema_init(&arRaw->raw_htc_read_sem[streamID], 1); + sema_init(&arRaw->raw_htc_write_sem[streamID], 1); +#else + init_MUTEX(&arRaw->raw_htc_read_sem[streamID]); + init_MUTEX(&arRaw->raw_htc_write_sem[streamID]); +#endif + init_waitqueue_head(&arRaw->raw_htc_read_queue[streamID]); + init_waitqueue_head(&arRaw->raw_htc_write_queue[streamID]); + + /* try to connect to the raw service */ + status = ar6000_connect_raw_service(ar,streamID); + + if (A_FAILED(status)) { + break; + } + + if (arRawStream2EndpointID(ar,streamID) == 0) { + break; + } + + for (count2 = 0; count2 < RAW_HTC_READ_BUFFERS_NUM; count2 ++) { + /* Initialize the receive buffers */ + buffer = &arRaw->raw_htc_write_buffer[streamID][count2]; + memset(buffer, 0, sizeof(raw_htc_buffer)); + buffer = &arRaw->raw_htc_read_buffer[streamID][count2]; + memset(buffer, 0, sizeof(raw_htc_buffer)); + + SET_HTC_PACKET_INFO_RX_REFILL(&buffer->HTCPacket, + buffer, + buffer->data, + HTC_RAW_BUFFER_SIZE, + arRawStream2EndpointID(ar,streamID)); + + /* Queue buffers to HTC for receive */ + if ((status = HTCAddReceivePkt(ar->arHtcTarget, &buffer->HTCPacket)) != A_OK) + { + BMIInit(); + return -EIO; + } + } + + for (count2 = 0; count2 < RAW_HTC_WRITE_BUFFERS_NUM; count2 ++) { + /* Initialize the receive buffers */ + buffer = &arRaw->raw_htc_write_buffer[streamID][count2]; + memset(buffer, 0, sizeof(raw_htc_buffer)); + } + + arRaw->read_buffer_available[streamID] = FALSE; + arRaw->write_buffer_available[streamID] = TRUE; + } + + if (A_FAILED(status)) { + return -EIO; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HTC RAW, number of streams the target supports: %d \n", streamID)); + + servicepriority = HTC_RAW_STREAMS_SVC; /* only 1 */ + + /* set callbacks and priority list */ + HTCSetCreditDistribution(ar->arHtcTarget, + ar, + NULL, /* use default */ + NULL, /* use default */ + &servicepriority, + 1); + + /* Start the HTC component */ + if ((status = HTCStart(ar->arHtcTarget)) != A_OK) { + BMIInit(); + return -EIO; + } + + (ar)->arRawIfInit = TRUE; + + return 0; +} + +int ar6000_htc_raw_close(AR_SOFTC_T *ar) +{ + A_PRINTF("ar6000_htc_raw_close called \n"); + HTCStop(ar->arHtcTarget); + + /* reset the device */ + ar6000_reset_device(ar->arHifDevice, ar->arTargetType, TRUE, FALSE); + /* Initialize the BMI component */ + BMIInit(); + + return 0; +} + +raw_htc_buffer * +get_filled_buffer(AR_SOFTC_T *ar, HTC_RAW_STREAM_ID StreamID) +{ + int count; + raw_htc_buffer *busy; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + + /* Check for data */ + for (count = 0; count < RAW_HTC_READ_BUFFERS_NUM; count ++) { + busy = &arRaw->raw_htc_read_buffer[StreamID][count]; + if (busy->length) { + break; + } + } + if (busy->length) { + arRaw->read_buffer_available[StreamID] = TRUE; + } else { + arRaw->read_buffer_available[StreamID] = FALSE; + } + + return busy; +} + +ssize_t ar6000_htc_raw_read(AR_SOFTC_T *ar, HTC_RAW_STREAM_ID StreamID, + char __user *buffer, size_t length) +{ + int readPtr; + raw_htc_buffer *busy; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + + if (arRawStream2EndpointID(ar,StreamID) == 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("StreamID(%d) not connected! \n", StreamID)); + return -EFAULT; + } + + if (down_interruptible(&arRaw->raw_htc_read_sem[StreamID])) { + return -ERESTARTSYS; + } + + busy = get_filled_buffer(ar,StreamID); + while (!arRaw->read_buffer_available[StreamID]) { + up(&arRaw->raw_htc_read_sem[StreamID]); + + /* Wait for the data */ + AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("Sleeping StreamID(%d) read process\n", StreamID)); + if (wait_event_interruptible(arRaw->raw_htc_read_queue[StreamID], + arRaw->read_buffer_available[StreamID])) + { + return -EINTR; + } + if (down_interruptible(&arRaw->raw_htc_read_sem[StreamID])) { + return -ERESTARTSYS; + } + busy = get_filled_buffer(ar,StreamID); + } + + /* Read the data */ + readPtr = busy->currPtr; + if (length > busy->length - HTC_HEADER_LEN) { + length = busy->length - HTC_HEADER_LEN; + } + if (copy_to_user(buffer, &busy->data[readPtr], length)) { + up(&arRaw->raw_htc_read_sem[StreamID]); + return -EFAULT; + } + + busy->currPtr += length; + + if (busy->currPtr == busy->length) + { + busy->currPtr = 0; + busy->length = 0; + HTC_PACKET_RESET_RX(&busy->HTCPacket); + //AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("raw read ioctl: ep for packet:%d \n", busy->HTCPacket.Endpoint)); + HTCAddReceivePkt(ar->arHtcTarget, &busy->HTCPacket); + } + arRaw->read_buffer_available[StreamID] = FALSE; + up(&arRaw->raw_htc_read_sem[StreamID]); + + return length; +} + +static raw_htc_buffer * +get_free_buffer(AR_SOFTC_T *ar, HTC_ENDPOINT_ID StreamID) +{ + int count; + raw_htc_buffer *free; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + + free = NULL; + for (count = 0; count < RAW_HTC_WRITE_BUFFERS_NUM; count ++) { + free = &arRaw->raw_htc_write_buffer[StreamID][count]; + if (free->length == 0) { + break; + } + } + if (!free->length) { + arRaw->write_buffer_available[StreamID] = TRUE; + } else { + arRaw->write_buffer_available[StreamID] = FALSE; + } + + return free; +} + +ssize_t ar6000_htc_raw_write(AR_SOFTC_T *ar, HTC_RAW_STREAM_ID StreamID, + char __user *buffer, size_t length) +{ + int writePtr; + raw_htc_buffer *free; + AR_RAW_HTC_T *arRaw = ar->arRawHtc; + if (arRawStream2EndpointID(ar,StreamID) == 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("StreamID(%d) not connected! \n", StreamID)); + return -EFAULT; + } + + if (down_interruptible(&arRaw->raw_htc_write_sem[StreamID])) { + return -ERESTARTSYS; + } + + /* Search for a free buffer */ + free = get_free_buffer(ar,StreamID); + + /* Check if there is space to write else wait */ + while (!arRaw->write_buffer_available[StreamID]) { + up(&arRaw->raw_htc_write_sem[StreamID]); + + /* Wait for buffer to become free */ + AR_DEBUG_PRINTF(ATH_DEBUG_HTC_RAW,("Sleeping StreamID(%d) write process\n", StreamID)); + if (wait_event_interruptible(arRaw->raw_htc_write_queue[StreamID], + arRaw->write_buffer_available[StreamID])) + { + return -EINTR; + } + if (down_interruptible(&arRaw->raw_htc_write_sem[StreamID])) { + return -ERESTARTSYS; + } + free = get_free_buffer(ar,StreamID); + } + + /* Send the data */ + writePtr = HTC_HEADER_LEN; + if (length > (HTC_RAW_BUFFER_SIZE - HTC_HEADER_LEN)) { + length = HTC_RAW_BUFFER_SIZE - HTC_HEADER_LEN; + } + + if (copy_from_user(&free->data[writePtr], buffer, length)) { + up(&arRaw->raw_htc_read_sem[StreamID]); + return -EFAULT; + } + + free->length = length; + + SET_HTC_PACKET_INFO_TX(&free->HTCPacket, + free, + &free->data[writePtr], + length, + arRawStream2EndpointID(ar,StreamID), + AR6K_DATA_PKT_TAG); + + HTCSendPkt(ar->arHtcTarget,&free->HTCPacket); + + arRaw->write_buffer_available[StreamID] = FALSE; + up(&arRaw->raw_htc_write_sem[StreamID]); + + return length; +} +#endif /* HTC_RAW_INTERFACE */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6k_mem_debug.c b/drivers/net/wireless/ar6003/host/os/linux/ar6k_mem_debug.c new file mode 100644 index 000000000000..cb7cd3084ba4 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6k_mem_debug.c @@ -0,0 +1,246 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ +// +#include "ar6000_drv.h" + +#define malloc(size) kmalloc((size), GFP_ATOMIC) +#define free(ptr) kfree((ptr)) + +typedef struct MemInfo { + void *ptr; + const char *caller; + int lineno; + size_t size; +} MemInfo; + + + +typedef unsigned long hash_key; + +typedef struct HashItem { + hash_key Key; + struct HashItem * Next; +} HashItem; + +typedef struct a_hash { + HashItem **Buckets; + size_t len; + int (*cmpKeyFunc)(const hash_key a, const hash_key b); + unsigned long (*hashFunc)(const hash_key key); + HashItem* (*mkNodeFunc)(hash_key key); +} a_hash; + +static a_hash* gMem; + +static int cmpMemInfo(const hash_key a, const hash_key b) +{ + return((const MemInfo*)a)->ptr - ((const MemInfo*)b)->ptr; +} + +static unsigned long hashMemInfo(const hash_key key) +{ + return(unsigned long)((const MemInfo*)key)->ptr; +} + +static HashItem* mkMemInfoItem(hash_key key) +{ + HashItem* item; + item = malloc(sizeof(HashItem)+ sizeof(MemInfo)); + item->Key = (hash_key)(item+1); + memcpy((void*)item->Key, (void*)key, sizeof(MemInfo)); + return item; +} + +static void rmItem(HashItem* item, void* data) +{ /* private function, don't use !! */ + free(item); +} + +HashItem* a_hash_add(a_hash *hash, const hash_key Key) +{ + int hashIndex = hash->hashFunc(Key) % hash->len; + HashItem* item = hash->mkNodeFunc(Key); + item->Next = hash->Buckets[hashIndex]; + hash->Buckets[hashIndex] = item; + return item; +} + +void a_hash_iterate(a_hash* hash, void (*func)(HashItem*, void*), void* data) +{ + size_t i; + HashItem *p, *next; + for (i=0; ilen; ++i) { + p = hash->Buckets[i]; + while (p) { + next = p->Next; + func(p, data); + p = next; + } + } +} + +void a_hash_clear(a_hash* hash) +{ + a_hash_iterate(hash, rmItem, NULL); + memset(hash->Buckets, 0, hash->len * sizeof(HashItem*)); +} + +void a_hash_destroy(a_hash* hash) +{ + a_hash_clear(hash); + free(hash); +} + +static HashItem** __a_hash_find(a_hash* hash, const hash_key Key) +{ + int hashIndex = hash->hashFunc(Key) % hash->len; + HashItem** result = &hash->Buckets[hashIndex]; + while (*result) { + if (hash->cmpKeyFunc((*result)->Key, Key)==0) + return result; + else + result = &(*result)->Next; + } + return result; +} + +HashItem* a_hash_find(a_hash* hash, const hash_key Key) +{ + return *__a_hash_find(hash, Key); +} + +HashItem* a_hash_findNext(a_hash* hash, HashItem* item) +{ + hash_key Key = (item) ? item->Key : 0; + if (item) + item = item->Next; + while (item) { + if (hash->cmpKeyFunc(item->Key, Key) == 0) + return item; + else + item = item->Next; + } + return item; +} + +void a_hash_erase(a_hash* hash, const hash_key Key) +{ + HashItem* p; + HashItem** prev = __a_hash_find(hash, Key); + p = *prev; + if (p) { + *prev = p->Next; + rmItem(p, NULL); + } +} + +void __a_meminfo_add(void *ptr, size_t msize, const char *func, int lineno) +{ + MemInfo info; + info.ptr = ptr; + info.lineno = lineno; + info.caller = func; + info.size = msize; + if (!gMem) { + int len = 512; + size_t size = sizeof(HashItem*) * len; + gMem = (a_hash*)malloc(sizeof(a_hash)+size); + memset(gMem, 0, sizeof(a_hash)+size); + gMem->Buckets = (HashItem**)(gMem+1); + gMem->len = len; + + gMem->mkNodeFunc = mkMemInfoItem; + gMem->cmpKeyFunc = cmpMemInfo; + gMem->hashFunc = hashMemInfo; + } + + a_hash_add(gMem, (hash_key)&info); +} + +void a_meminfo_del(void *ptr) +{ + MemInfo info; + info.ptr = ptr; + if (gMem) { + HashItem* p; + HashItem** prev = __a_hash_find(gMem, (unsigned long)&info); + p = *prev; + if (p) { + *prev = p->Next; + rmItem(p, NULL); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Warning! memory ptr %p not found!", __func__, ptr)); + } + } +} + +void* a_mem_alloc(size_t msize, int type, const char *func, int lineno) +{ + void *ptr = kmalloc(msize, type); + __a_meminfo_add(ptr, msize, func, lineno); + return ptr; +} + +void a_mem_free(void *ptr) +{ + a_meminfo_del(ptr); + kfree(ptr); +} + +static void printMemInfo(HashItem *item, void*arg) +{ + MemInfo *info = (MemInfo*)item->Key; + int *total = (int*)arg; + *total += info->size; + A_PRINTF("%s line %d size %d ptr %p\n", info->caller, info->lineno, info->size, info->ptr); +} + +void a_meminfo_report(int clear) +{ + int total = 0; + A_PRINTF("AR6K Memory Report\n"); + if (gMem) { + a_hash_iterate(gMem, printMemInfo, &total); + if (clear) { + a_hash_destroy(gMem); + } + } + A_PRINTF("Total %d bytes\n", total); +} + +A_BOOL a_meminfo_find(void *ptr) +{ + MemInfo info; + info.ptr = ptr; + if (gMem) { + HashItem* p; + HashItem** prev = __a_hash_find(gMem, (unsigned long)&info); + p = *prev; + if (p) { + return TRUE; + } else { + return FALSE; + } + } +} diff --git a/drivers/net/wireless/ar6003/host/os/linux/ar6k_pal.c b/drivers/net/wireless/ar6003/host/os/linux/ar6k_pal.c new file mode 100644 index 000000000000..179a2f05688b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ar6k_pal.c @@ -0,0 +1,471 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +/* PAL Transport driver for AR6003 */ + +#include "ar6000_drv.h" +#include +#include +#include + +extern unsigned int setupbtdev; +extern unsigned int loghci; + +#define bt_check_bit(val, bit) (val & bit) +#define bt_set_bit(val, bit) (val |= bit) +#define bt_clear_bit(val, bit) (val &= ~bit) + +/* export ATH_AR6K_DEBUG_HCI_PAL=yes in host/localmake.linux.inc + * to enable debug information */ +#ifdef HCIPAL_DEBUG +#define PRIN_LOG(format, args...) printk(KERN_ALERT "%s:%d - %s Msg:" format "\n",__FUNCTION__, __LINE__, __FILE__, ## args) +#else +#define PRIN_LOG(format, args...) +#endif + + +/*** BT Stack Entrypoints *******/ +/*************************************** + * bt_open - open a handle to the device + ***************************************/ +static int bt_open(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_open - enter - x\n"); + set_bit(HCI_RUNNING, &hdev->flags); + set_bit(HCI_UP, &hdev->flags); + set_bit(HCI_INIT, &hdev->flags); + return 0; +} + +/*************************************** + * bt_close - close handle to the device + ***************************************/ +static int bt_close(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_close - enter\n"); + clear_bit(HCI_RUNNING, &hdev->flags); + return 0; +} + +/***************************** + * bt_ioctl - ioctl processing + *****************************/ +static int bt_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) +{ + PRIN_LOG("HCI PAL: bt_ioctl - enter\n"); + return -ENOIOCTLCMD; +} + +/************************************** + * bt_flush - flush outstanding packets + **************************************/ +static int bt_flush(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_flush - enter\n"); + return 0; +} + +/*************** + * bt_destruct + ***************/ +static void bt_destruct(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_destruct - enter\n"); + /* nothing to do here */ +} + +/**************************************************** + * Invoked from bluetooth stack via hdev->send() + * to send the packet out via ar6k to PAL firmware. + * + * For HCI command packet wmi_send_hci_cmd() is invoked. + * wmi_send_hci_cmd adds WMI_CMD_HDR and sends the packet + * to PAL firmware. + * + * For HCI ACL data packet wmi_data_hdr_add is invoked + * to add WMI_DATA_HDR to the packet. ar6000_acl_data_tx + * is then invoked to send the packet to PAL firmware. + ******************************************************/ +static int btpal_send_frame(struct sk_buff *skb) +{ + struct hci_dev *hdev = (struct hci_dev *)skb->dev; + HCI_TRANSPORT_PACKET_TYPE type; + ar6k_hci_pal_info_t *pHciPalInfo; + A_STATUS status = A_OK; + struct sk_buff *txSkb = NULL; + AR_SOFTC_DEV_T *ar; + + if (!hdev) { + PRIN_LOG("HCI PAL: btpal_send_frame - no device\n"); + return -ENODEV; + } + + if (!test_bit(HCI_RUNNING, &hdev->flags)) { + PRIN_LOG("HCI PAL: btpal_send_frame - not open\n"); + return -EBUSY; + } + + pHciPalInfo = (ar6k_hci_pal_info_t *)hdev->driver_data; + A_ASSERT(pHciPalInfo != NULL); + ar = pHciPalInfo->ar; + + PRIN_LOG("+btpal_send_frame type: %d \n",bt_cb(skb)->pkt_type); + type = HCI_COMMAND_TYPE; + + switch (bt_cb(skb)->pkt_type) { + case HCI_COMMAND_PKT: + type = HCI_COMMAND_TYPE; + hdev->stat.cmd_tx++; + break; + + case HCI_ACLDATA_PKT: + type = HCI_ACL_TYPE; + hdev->stat.acl_tx++; + break; + + case HCI_SCODATA_PKT: + /* we don't support SCO over the pal */ + kfree_skb(skb); + return 0; + default: + A_ASSERT(FALSE); + kfree_skb(skb); + return 0; + } + + if(loghci) { + A_PRINTF(">>> Send HCI %s packet len: %d\n", + (type == HCI_COMMAND_TYPE) ? "COMMAND" : "ACL", + skb->len); + if (type == HCI_COMMAND_TYPE) { + A_PRINTF("HCI Command: OGF:0x%X OCF:0x%X \r\n", + (HCI_GET_OP_CODE(skb->data)) >> 10, + (HCI_GET_OP_CODE(skb->data)) & 0x3FF); + } + DebugDumpBytes(skb->data,skb->len,"BT HCI SEND Packet Dump"); + } + + do { + if(type == HCI_COMMAND_TYPE) + { + PRIN_LOG("HCI command"); + + if (ar->arSoftc->arWmiReady == FALSE) + { + PRIN_LOG("WMI not ready "); + break; + } + + if (wmi_send_hci_cmd(ar->arWmi, skb->data, skb->len) != A_OK) + { + PRIN_LOG("send hci cmd error"); + break; + } + } + else if(type == HCI_ACL_TYPE) + { + void *osbuf; + + PRIN_LOG("ACL data"); + if (ar->arSoftc->arWmiReady == FALSE) + { + PRIN_LOG("WMI not ready"); + break; + } + + /* need to add WMI header so allocate a skb with more space */ + txSkb = bt_skb_alloc(TX_PACKET_RSV_OFFSET + WMI_MAX_TX_META_SZ + + sizeof(WMI_DATA_HDR) + skb->len, + GFP_ATOMIC); + + if (txSkb == NULL) { + status = A_NO_MEMORY; + PRIN_LOG("No memory"); + break; + } + + bt_cb(txSkb)->pkt_type = bt_cb(skb)->pkt_type; + txSkb->dev = (void *)pHciPalInfo->hdev; + skb_reserve(txSkb, TX_PACKET_RSV_OFFSET + WMI_MAX_TX_META_SZ + sizeof(WMI_DATA_HDR)); + A_MEMCPY(txSkb->data, skb->data, skb->len); + skb_put(txSkb,skb->len); + /* Add WMI packet type */ + osbuf = (void *)txSkb; + + PRIN_LOG("\nAdd WMI header"); + if (wmi_data_hdr_add(ar->arWmi, osbuf, DATA_MSGTYPE, 0, WMI_DATA_HDR_DATA_TYPE_ACL,0,NULL) != A_OK) { + PRIN_LOG("XIOCTL_ACL_DATA - wmi_data_hdr_add failed\n"); + } else { + /* Send data buffer over HTC */ + PRIN_LOG("acl data tx"); + ar6000_acl_data_tx(osbuf, ar); + } + txSkb = NULL; + } + } while (FALSE); + + if (txSkb != NULL) { + PRIN_LOG("Free skb"); + kfree_skb(txSkb); + } + kfree_skb(skb); + return 0; +} + + +/*********************************************** + * Unregister HCI device and free HCI device info + ***********************************************/ +static void bt_cleanup_hci_pal(ar6k_hci_pal_info_t *pHciPalInfo) +{ + int err; + + if (bt_check_bit(pHciPalInfo->ulFlags, HCI_REGISTERED)) { + bt_clear_bit(pHciPalInfo->ulFlags, HCI_REGISTERED); + clear_bit(HCI_RUNNING, &pHciPalInfo->hdev->flags); + clear_bit(HCI_UP, &pHciPalInfo->hdev->flags); + clear_bit(HCI_INIT, &pHciPalInfo->hdev->flags); + A_ASSERT(pHciPalInfo->hdev != NULL); +#ifdef CONFIG_BT + /* unregister */ + PRIN_LOG("Unregister PAL device"); + if ((err = hci_unregister_dev(pHciPalInfo->hdev)) < 0) { + PRIN_LOG("HCI PAL: failed to unregister with bluetooth %d\n",err); + } +#else + (void)&err; +#endif + } + + if (pHciPalInfo->hdev != NULL) { + kfree(pHciPalInfo->hdev); + pHciPalInfo->hdev = NULL; + } +} + +/********************************************************* + * Allocate HCI device and store in PAL private info structure. + *********************************************************/ +static A_STATUS bt_setup_hci_pal(ar6k_hci_pal_info_t *pHciPalInfo) +{ +#ifdef CONFIG_BT + A_STATUS status = A_OK; + struct hci_dev *pHciDev = NULL; + +#if 0 //This condition is not required for PAL + if (!setupbtdev) { + return A_OK; + } +#endif + do { + /* allocate a BT HCI struct for this device */ + pHciDev = hci_alloc_dev(); + if (NULL == pHciDev) { + PRIN_LOG("HCI PAL driver - failed to allocate BT HCI struct \n"); + status = A_NO_MEMORY; + break; + } + + /* save the device, we'll register this later */ + pHciPalInfo->hdev = pHciDev; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) + SET_HCI_BUS_TYPE(pHciDev, HCI_VIRTUAL, HCI_80211); +#else + SET_HCI_BUS_TYPE(pHciDev, HCI_VIRTUAL, HCI_AMP); +#endif + pHciDev->driver_data = pHciPalInfo; + pHciDev->open = bt_open; + pHciDev->close = bt_close; + pHciDev->send = btpal_send_frame; + pHciDev->ioctl = bt_ioctl; + pHciDev->flush = bt_flush; + pHciDev->destruct = bt_destruct; + pHciDev->owner = THIS_MODULE; + /* driver is running in normal BT mode */ + PRIN_LOG("Normal mode enabled"); + bt_set_bit(pHciPalInfo->ulFlags, HCI_NORMAL_MODE); + + } while (FALSE); + + if (A_FAILED(status)) { + bt_cleanup_hci_pal(pHciPalInfo); + } + return status; +#else + (void)&bt_open; + (void)&bt_close; + (void)&btpal_send_frame; + (void)&bt_ioctl; + (void)&bt_flush; + (void)&bt_destruct; + bt_cleanup_hci_pal(pHciPalInfo); + return A_ENOTSUP; +#endif +} + +/********************************************** + * Cleanup HCI device and free HCI PAL private info + *********************************************/ +void ar6k_cleanup_hci_pal(void *ar_p) +{ + AR_SOFTC_DEV_T *ar = (AR_SOFTC_DEV_T *)ar_p; + ar6k_hci_pal_info_t *pHciPalInfo = (ar6k_hci_pal_info_t *)ar->hcipal_info; + + if (pHciPalInfo != NULL) { + bt_cleanup_hci_pal(pHciPalInfo); + A_FREE(pHciPalInfo); + ar->hcipal_info = NULL; + } +} + +/**************************** + * Register HCI device + ****************************/ +static A_BOOL ar6k_pal_transport_ready(void *pHciPal) +{ +#ifdef CONFIG_BT + ar6k_hci_pal_info_t *pHciPalInfo = (ar6k_hci_pal_info_t *)pHciPal; + + PRIN_LOG("HCI device transport ready"); + if(pHciPalInfo == NULL) + return FALSE; + + if (hci_register_dev(pHciPalInfo->hdev) < 0) { + PRIN_LOG("Can't register HCI device"); + hci_free_dev(pHciPalInfo->hdev); + return FALSE; + } + PRIN_LOG("HCI device registered"); + pHciPalInfo->ulFlags |= HCI_REGISTERED; + return TRUE; +#else + return FALSE; +#endif +} + +/************************************************** + * Called from ar6k driver when command or ACL data + * packet is received. Pass the packet to bluetooth + * stack via hci_recv_frame. + **************************************************/ +A_BOOL ar6k_pal_recv_pkt(void *pHciPal, void *osbuf) +{ + struct sk_buff *skb = (struct sk_buff *)osbuf; + ar6k_hci_pal_info_t *pHciPalInfo; + A_BOOL success = FALSE; + A_UINT8 btType = 0; + pHciPalInfo = (ar6k_hci_pal_info_t *)pHciPal; + + do { + + /* if normal mode is not enabled pass on to the stack + * by returning failure */ + if(!(pHciPalInfo->ulFlags & HCI_NORMAL_MODE)) + { + PRIN_LOG("Normal mode not enabled"); + break; + } + + if (!test_bit(HCI_RUNNING, &pHciPalInfo->hdev->flags)) { + PRIN_LOG("HCI PAL: HCI - not running\n"); + break; + } + + if(*((short *)A_NETBUF_DATA(skb)) == WMI_ACL_DATA_EVENTID) + btType = HCI_ACLDATA_PKT; + else + btType = HCI_EVENT_PKT; + /* pull 4 bytes which contains WMI packet type */ + A_NETBUF_PULL(skb, sizeof(int)); + bt_cb(skb)->pkt_type = btType; + skb->dev = (void *)pHciPalInfo->hdev; + + if(loghci) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("<<< Recv HCI %s packet len:%d \n", + (btType == HCI_EVENT_TYPE) ? "EVENT" : "ACL", + skb->len)); + DebugDumpBytes(skb->data, skb->len,"BT HCI RECV Packet Dump"); + } + /* pass the received event packet up the stack */ +#ifdef CONFIG_BT + if (hci_recv_frame(skb) != 0) { +#else + if (1) { +#endif + PRIN_LOG("HCI PAL: hci_recv_frame failed \n"); + break; + } else { + PRIN_LOG("HCI PAL: Indicated RCV of type:%d, Length:%d \n",HCI_EVENT_PKT, skb->len); + } + PRIN_LOG("hci recv success"); + success = TRUE; + }while(FALSE); + return success; +} + +/********************************************************** + * HCI PAL init function called from ar6k when it is loaded.. + * Allocates PAL private info, stores the same in ar6k private info. + * Registers a HCI device. + * Registers packet receive callback function with ar6k + **********************************************************/ +A_STATUS ar6k_setup_hci_pal(void *ar_p) +{ + A_STATUS status = A_OK; + ar6k_hci_pal_info_t *pHciPalInfo; + ar6k_pal_config_t ar6k_pal_config; + AR_SOFTC_DEV_T *ar = (AR_SOFTC_DEV_T *)ar_p; + + do { + + pHciPalInfo = (ar6k_hci_pal_info_t *)A_MALLOC(sizeof(ar6k_hci_pal_info_t)); + + if (NULL == pHciPalInfo) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pHciPalInfo, sizeof(ar6k_hci_pal_info_t)); + ar->hcipal_info = pHciPalInfo; + pHciPalInfo->ar = ar; + + status = bt_setup_hci_pal(pHciPalInfo); + if (A_FAILED(status)) { + break; + } + + if(bt_check_bit(pHciPalInfo->ulFlags, HCI_NORMAL_MODE)) + PRIN_LOG("HCI PAL: running in normal mode... \n"); + else + PRIN_LOG("HCI PAL: running in test mode... \n"); + + ar6k_pal_config.fpar6k_pal_recv_pkt = ar6k_pal_recv_pkt; + register_pal_cb(&ar6k_pal_config); + ar6k_pal_transport_ready(ar->hcipal_info); + } while (FALSE); + + if (A_FAILED(status)) { + ar6k_cleanup_hci_pal(ar); + } + return status; +} diff --git a/drivers/net/wireless/ar6003/host/os/linux/cfg80211.c b/drivers/net/wireless/ar6003/host/os/linux/cfg80211.c new file mode 100644 index 000000000000..97f6979028dd --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/cfg80211.c @@ -0,0 +1,1638 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include +#include +#include +#include +#include + +#include "ar6000_drv.h" + + +extern unsigned int wmitimeout; +extern int reconnect_flag; + + +#define RATETAB_ENT(_rate, _rateid, _flags) { \ + .bitrate = (_rate), \ + .flags = (_flags), \ + .hw_value = (_rateid), \ +} + +#define CHAN2G(_channel, _freq, _flags) { \ + .band = IEEE80211_BAND_2GHZ, \ + .hw_value = (_channel), \ + .center_freq = (_freq), \ + .flags = (_flags), \ + .max_antenna_gain = 0, \ + .max_power = 30, \ +} + +#define CHAN5G(_channel, _flags) { \ + .band = IEEE80211_BAND_5GHZ, \ + .hw_value = (_channel), \ + .center_freq = 5000 + (5 * (_channel)), \ + .flags = (_flags), \ + .max_antenna_gain = 0, \ + .max_power = 30, \ +} + +static struct +ieee80211_rate ar6k_rates[] = { + RATETAB_ENT(10, 0x1, 0), + RATETAB_ENT(20, 0x2, 0), + RATETAB_ENT(55, 0x4, 0), + RATETAB_ENT(110, 0x8, 0), + RATETAB_ENT(60, 0x10, 0), + RATETAB_ENT(90, 0x20, 0), + RATETAB_ENT(120, 0x40, 0), + RATETAB_ENT(180, 0x80, 0), + RATETAB_ENT(240, 0x100, 0), + RATETAB_ENT(360, 0x200, 0), + RATETAB_ENT(480, 0x400, 0), + RATETAB_ENT(540, 0x800, 0), +}; + +#define ar6k_a_rates (ar6k_rates + 4) +#define ar6k_a_rates_size 8 +#define ar6k_g_rates (ar6k_rates + 0) +#define ar6k_g_rates_size 12 + +static struct +ieee80211_channel ar6k_2ghz_channels[] = { + CHAN2G(1, 2412, 0), + CHAN2G(2, 2417, 0), + CHAN2G(3, 2422, 0), + CHAN2G(4, 2427, 0), + CHAN2G(5, 2432, 0), + CHAN2G(6, 2437, 0), + CHAN2G(7, 2442, 0), + CHAN2G(8, 2447, 0), + CHAN2G(9, 2452, 0), + CHAN2G(10, 2457, 0), + CHAN2G(11, 2462, 0), + CHAN2G(12, 2467, 0), + CHAN2G(13, 2472, 0), + CHAN2G(14, 2484, 0), +}; + +static struct +ieee80211_channel ar6k_5ghz_a_channels[] = { + CHAN5G(34, 0), CHAN5G(36, 0), + CHAN5G(38, 0), CHAN5G(40, 0), + CHAN5G(42, 0), CHAN5G(44, 0), + CHAN5G(46, 0), CHAN5G(48, 0), + CHAN5G(52, 0), CHAN5G(56, 0), + CHAN5G(60, 0), CHAN5G(64, 0), + CHAN5G(100, 0), CHAN5G(104, 0), + CHAN5G(108, 0), CHAN5G(112, 0), + CHAN5G(116, 0), CHAN5G(120, 0), + CHAN5G(124, 0), CHAN5G(128, 0), + CHAN5G(132, 0), CHAN5G(136, 0), + CHAN5G(140, 0), CHAN5G(149, 0), + CHAN5G(153, 0), CHAN5G(157, 0), + CHAN5G(161, 0), CHAN5G(165, 0), + CHAN5G(184, 0), CHAN5G(188, 0), + CHAN5G(192, 0), CHAN5G(196, 0), + CHAN5G(200, 0), CHAN5G(204, 0), + CHAN5G(208, 0), CHAN5G(212, 0), + CHAN5G(216, 0), +}; + +static struct +ieee80211_supported_band ar6k_band_2ghz = { + .n_channels = ARRAY_SIZE(ar6k_2ghz_channels), + .channels = ar6k_2ghz_channels, + .n_bitrates = ar6k_g_rates_size, + .bitrates = ar6k_g_rates, +}; + +static struct +ieee80211_supported_band ar6k_band_5ghz = { + .n_channels = ARRAY_SIZE(ar6k_5ghz_a_channels), + .channels = ar6k_5ghz_a_channels, + .n_bitrates = ar6k_a_rates_size, + .bitrates = ar6k_a_rates, +}; + +static int +ar6k_set_wpa_version(AR_SOFTC_DEV_T *arPriv, enum nl80211_wpa_versions wpa_version) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: %u\n", __func__, wpa_version)); + + if (!wpa_version) { + arPriv->arAuthMode = WMI_NONE_AUTH; + } else if (wpa_version & NL80211_WPA_VERSION_1) { + arPriv->arAuthMode = WMI_WPA_AUTH; + } else if (wpa_version & NL80211_WPA_VERSION_2) { + arPriv->arAuthMode = WMI_WPA2_AUTH; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: %u not spported\n", __func__, wpa_version)); + return -ENOTSUPP; + } + + return A_OK; +} + +static int +ar6k_set_auth_type(AR_SOFTC_DEV_T *arPriv, enum nl80211_auth_type auth_type) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: 0x%x\n", __func__, auth_type)); + + switch (auth_type) { + case NL80211_AUTHTYPE_OPEN_SYSTEM: + arPriv->arDot11AuthMode = OPEN_AUTH; + break; + case NL80211_AUTHTYPE_SHARED_KEY: + arPriv->arDot11AuthMode = SHARED_AUTH; + break; + case NL80211_AUTHTYPE_NETWORK_EAP: + arPriv->arDot11AuthMode = LEAP_AUTH; + break; + default: + arPriv->arDot11AuthMode = OPEN_AUTH; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: 0x%x not spported\n", __func__, auth_type)); + return -ENOTSUPP; + } + + return A_OK; +} + +static int +ar6k_set_cipher(AR_SOFTC_DEV_T *arPriv, A_UINT32 cipher, A_BOOL ucast) +{ + A_UINT8 *ar_cipher = ucast ? &arPriv->arPairwiseCrypto : + &arPriv->arGroupCrypto; + A_UINT8 *ar_cipher_len = ucast ? &arPriv->arPairwiseCryptoLen : + &arPriv->arGroupCryptoLen; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: cipher 0x%x, ucast %u\n", __func__, cipher, ucast)); + + switch (cipher) { + case 0: + case IW_AUTH_CIPHER_NONE: + *ar_cipher = NONE_CRYPT; + *ar_cipher_len = 0; + break; + case WLAN_CIPHER_SUITE_WEP40: + *ar_cipher = WEP_CRYPT; + *ar_cipher_len = 5; + break; + case WLAN_CIPHER_SUITE_WEP104: + *ar_cipher = WEP_CRYPT; + *ar_cipher_len = 13; + break; + case WLAN_CIPHER_SUITE_TKIP: +#ifdef CFG80211_WAPI_ENABLE + *ar_cipher = WAPI_CRYPT; +#else + *ar_cipher = TKIP_CRYPT; +#endif + *ar_cipher_len = 0; + break; + case WLAN_CIPHER_SUITE_CCMP: + *ar_cipher = AES_CRYPT; + *ar_cipher_len = 0; + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: cipher 0x%x not supported\n", __func__, cipher)); + return -ENOTSUPP; + } + + return A_OK; +} + +static void +ar6k_set_key_mgmt(AR_SOFTC_DEV_T *arPriv, A_UINT32 key_mgmt) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: 0x%x\n", __func__, key_mgmt)); + + if (WLAN_AKM_SUITE_PSK == key_mgmt) { + if (WMI_WPA_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_PSK_AUTH; + } else if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_PSK_AUTH; + } + } else if (WLAN_AKM_SUITE_8021X != key_mgmt) { + arPriv->arAuthMode = WMI_NONE_AUTH; + } +} + +static int +ar6k_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_connect_params *sme) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + A_STATUS status; +#ifdef CFG80211_WAPI_ENABLE + const unsigned char wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 }; + const unsigned char wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 }; + unsigned char *ie = sme->ie; +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready yet\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(ar->bIsDestroyProgress) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: destroy in progress\n", __func__)); + return -EBUSY; + } + + if(!sme->ssid_len || IEEE80211_MAX_SSID_LEN < sme->ssid_len) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ssid invalid\n", __func__)); + return -EINVAL; + } + + if(arSta->arSkipScan == TRUE && + ((sme->channel && sme->channel->center_freq == 0) || + (sme->bssid && !sme->bssid[0] && !sme->bssid[1] && !sme->bssid[2] && + !sme->bssid[3] && !sme->bssid[4] && !sme->bssid[5]))) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s:SkipScan: channel or bssid invalid\n", __func__)); + return -EINVAL; + } + + if(down_interruptible(&ar->arSem)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__)); + return -ERESTARTSYS; + } + + if(ar->bIsDestroyProgress) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, destroy in progress\n", __func__)); + up(&ar->arSem); + return -EBUSY; + } + + if(ar->arTxPending[wmi_get_control_ep(arPriv->arWmi)]) { + /* + * sleep until the command queue drains + */ + wait_event_interruptible_timeout(arPriv->arEvent, + ar->arTxPending[wmi_get_control_ep(arPriv->arWmi)] == 0, wmitimeout * HZ); + if (signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: cmd queue drain timeout\n", __func__)); + up(&ar->arSem); + return -EINTR; + } + } + up(&ar->arSem); + + if(down_interruptible(&ar->arSem)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__)); + return -ERESTARTSYS; + } + + if(arPriv->arConnected == TRUE && + arPriv->arSsidLen == sme->ssid_len && + !A_MEMCMP(arPriv->arSsid, sme->ssid, arPriv->arSsidLen)) { + reconnect_flag = TRUE; + status = wmi_reconnect_cmd(arPriv->arWmi, + arSta->arReqBssid, + arPriv->arChannelHint); + + if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_reconnect_cmd failed\n", __func__)); + return -EIO; + } + return 0; + } else if(arPriv->arSsidLen == sme->ssid_len && + !A_MEMCMP(arPriv->arSsid, sme->ssid, arPriv->arSsidLen)) { + ar6000_disconnect(arPriv); + } + + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = sme->ssid_len; + A_MEMCPY(arPriv->arSsid, sme->ssid, sme->ssid_len); + + if(sme->channel){ + arPriv->arChannelHint = sme->channel->center_freq; + } + + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + if(sme->bssid){ + if(A_MEMCMP(&sme->bssid, bcast_mac, AR6000_ETH_ADDR_LEN)) { + A_MEMCPY(arSta->arReqBssid, sme->bssid, sizeof(arSta->arReqBssid)); + } + } + + ar6k_set_wpa_version(arPriv, sme->crypto.wpa_versions); + ar6k_set_auth_type(arPriv, sme->auth_type); + + if(sme->crypto.n_ciphers_pairwise) { + ar6k_set_cipher(arPriv, sme->crypto.ciphers_pairwise[0], true); + } else { + ar6k_set_cipher(arPriv, IW_AUTH_CIPHER_NONE, true); + } + ar6k_set_cipher(arPriv, sme->crypto.cipher_group, false); + + if(sme->crypto.n_akm_suites) { + ar6k_set_key_mgmt(arPriv, sme->crypto.akm_suites[0]); + } + + if((sme->key_len) && + (WMI_NONE_AUTH == arPriv->arAuthMode) && + (WEP_CRYPT == arPriv->arPairwiseCrypto)) { + struct ar_key *key = NULL; + + if(sme->key_idx < WMI_MIN_KEY_INDEX || sme->key_idx > WMI_MAX_KEY_INDEX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: key index %d out of bounds\n", __func__, sme->key_idx)); + up(&ar->arSem); + return -ENOENT; + } + + key = &arPriv->keys[sme->key_idx]; + key->key_len = sme->key_len; + A_MEMCPY(key->key, sme->key, key->key_len); + key->cipher = arPriv->arPairwiseCrypto; + arPriv->arDefTxKeyIndex = sme->key_idx; + + wmi_addKey_cmd(arPriv->arWmi, sme->key_idx, + arPriv->arPairwiseCrypto, + GROUP_USAGE | TX_USAGE, + key->key_len, + NULL, + key->key, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + + if (!arSta->arUserBssFilter) { + if (wmi_bssfilter_cmd(arPriv->arWmi, ALL_BSS_FILTER, 0) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Couldn't set bss filtering\n", __func__)); + up(&ar->arSem); + return -EIO; + } + } + + arPriv->arNetworkType = arPriv->arNextMode; + +#ifdef CFG80211_WAPI_ENABLE +/*the following codes for wps and wapi, but ONLY test wapi*/ + if (ie[0] == WLAN_EID_VENDOR_SPECIFIC && + memcmp(ie + 2, wps_oui, sizeof(wps_oui)) == 0) { + /* WPS IE detected, notify target */ + A_PRINTF("WPS IE detected -- setting WPS flag\n"); + arPriv->arSta.arConnectCtrlFlags |= CONNECT_WPS_FLAG; + arPriv->arAuthMode = 0; + } else { + if ((ie[0]==IEEE80211_ELEMID_RSN) || + (ie[0]==IEEE80211_ELEMID_VENDOR && + memcmp(&ie[2], wpa_oui, sizeof(wpa_oui))==0)) { + sme->ie_len = 0; /* Firmware will set for us. Clear the previous one */ + } + /* for WAPI */ + else if (ie[0]==IEEE80211_ELEMID_WAPI) + { + } + /************/ + arPriv->arSta.arConnectCtrlFlags &= ~CONNECT_WPS_FLAG; + } + wmi_set_appie_cmd(arPriv->arWmi, WMI_FRAME_ASSOC_REQ, sme->ie_len, ie); +/*********************************************************/ +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Connect called with authmode %d dot11 auth %d"\ + " PW crypto %d PW crypto Len %d GRP crypto %d"\ + " GRP crypto Len %d channel hint %u\n", + __func__, arPriv->arAuthMode, arPriv->arDot11AuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto, arPriv->arGroupCryptoLen, arPriv->arChannelHint)); + reconnect_flag = 0; + status = wmi_connect_cmd(arPriv->arWmi, arPriv->arNetworkType, + arPriv->arDot11AuthMode, arPriv->arAuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto,arPriv->arGroupCryptoLen, + arPriv->arSsidLen, arPriv->arSsid, + arSta->arReqBssid, arPriv->arChannelHint, + arSta->arConnectCtrlFlags); + + up(&ar->arSem); + + if (A_EINVAL == status) { + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Invalid request\n", __func__)); + return -ENOENT; + } else if (status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_connect_cmd failed\n", __func__)); + return -EIO; + } + + if ((!(arSta->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) && + ((WMI_WPA_PSK_AUTH == arPriv->arAuthMode) || (WMI_WPA2_PSK_AUTH == arPriv->arAuthMode))) + { + A_TIMEOUT_MS(&arSta->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0); + } + + arSta->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD; + arSta->arConnectPending = TRUE; + + return 0; +} + +void +ar6k_cfg80211_connect_event(AR_SOFTC_DEV_T *arPriv, A_UINT16 channel, + A_UINT8 *bssid, A_UINT16 listenInterval, + A_UINT16 beaconInterval,NETWORK_TYPE networkType, + A_UINT8 beaconIeLen, A_UINT8 assocReqLen, + A_UINT8 assocRespLen, A_UINT8 *assocInfo) +{ + A_UINT16 size = 0; + A_UINT16 capability = 0; + struct cfg80211_bss *bss = NULL; + struct ieee80211_mgmt *mgmt = NULL; + struct ieee80211_channel *ibss_channel = NULL; + s32 signal = 50 * 100; + A_UINT8 ie_buf_len = 0; + unsigned char ie_buf[256]; + unsigned char *ptr_ie_buf = ie_buf; + unsigned char *ieeemgmtbuf = NULL; + A_UINT8 source_mac[ATH_MAC_LEN]; + + A_UINT8 assocReqIeOffset = sizeof(A_UINT16) + /* capinfo*/ + sizeof(A_UINT16); /* listen interval */ + A_UINT8 assocRespIeOffset = sizeof(A_UINT16) + /* capinfo*/ + sizeof(A_UINT16) + /* status Code */ + sizeof(A_UINT16); /* associd */ + A_UINT8 *assocReqIe = assocInfo + beaconIeLen + assocReqIeOffset; + A_UINT8 *assocRespIe = assocInfo + beaconIeLen + assocReqLen + assocRespIeOffset; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + assocReqLen -= assocReqIeOffset; + assocRespLen -= assocRespIeOffset; + + if((ADHOC_NETWORK & networkType)) { + if(NL80211_IFTYPE_ADHOC != arPriv->wdev->iftype) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: ath6k not in ibss mode\n", __func__)); + return; + } + } + + if((INFRA_NETWORK & networkType)) { + if(NL80211_IFTYPE_STATION != arPriv->wdev->iftype) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: ath6k not in station mode\n", __func__)); + return; + } + } + + /* Before informing the join/connect event, make sure that + * bss entry is present in scan list, if it not present + * construct and insert into scan list, otherwise that + * event will be dropped on the way by cfg80211, due to + * this keys will not be plumbed in case of WEP and + * application will not be aware of join/connect status. */ + bss = cfg80211_get_bss(arPriv->wdev->wiphy, NULL, bssid, + arPriv->wdev->ssid, arPriv->wdev->ssid_len, + ((ADHOC_NETWORK & networkType) ? WLAN_CAPABILITY_IBSS : WLAN_CAPABILITY_ESS), + ((ADHOC_NETWORK & networkType) ? WLAN_CAPABILITY_IBSS : WLAN_CAPABILITY_ESS)); + + if(!bss) { + if (ADHOC_NETWORK & networkType) { + /* construct 802.11 mgmt beacon */ + if(ptr_ie_buf) { + *ptr_ie_buf++ = WLAN_EID_SSID; + *ptr_ie_buf++ = arPriv->arSsidLen; + A_MEMCPY(ptr_ie_buf, arPriv->arSsid, arPriv->arSsidLen); + ptr_ie_buf +=arPriv->arSsidLen; + + *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS; + *ptr_ie_buf++ = 2; /* length */ + *ptr_ie_buf++ = 0; /* ATIM window */ + *ptr_ie_buf++ = 0; /* ATIM window */ + + /* TODO: update ibss params and include supported rates, + * DS param set, extened support rates, wmm. */ + + ie_buf_len = ptr_ie_buf - ie_buf; + } + + capability |= IEEE80211_CAPINFO_IBSS; + if(WEP_CRYPT == arPriv->arPairwiseCrypto) { + capability |= IEEE80211_CAPINFO_PRIVACY; + } + A_MEMCPY(source_mac, arPriv->arNetDev->dev_addr, ATH_MAC_LEN); + ptr_ie_buf = ie_buf; + } else { + capability = *(A_UINT16 *)(&assocInfo[beaconIeLen]); + A_MEMCPY(source_mac, bssid, ATH_MAC_LEN); + ptr_ie_buf = assocReqIe; + ie_buf_len = assocReqLen; + } + + size = offsetof(struct ieee80211_mgmt, u) + + sizeof(mgmt->u.beacon) + + ie_buf_len; + + ieeemgmtbuf = A_MALLOC_NOWAIT(size); + if(!ieeemgmtbuf) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: ieeeMgmtbuf alloc error\n", __func__)); + return; + } + + A_MEMZERO(ieeemgmtbuf, size); + mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf; + mgmt->frame_control = (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON); + A_MEMCPY(mgmt->da, bcast_mac, ATH_MAC_LEN); + A_MEMCPY(mgmt->sa, source_mac, ATH_MAC_LEN); + A_MEMCPY(mgmt->bssid, bssid, ATH_MAC_LEN); + mgmt->u.beacon.beacon_int = beaconInterval; + mgmt->u.beacon.capab_info = capability; + A_MEMCPY(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len); + + ibss_channel = ieee80211_get_channel(arPriv->wdev->wiphy, (int)channel); + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: inform bss with bssid %02x:%02x:%02x:%02x:%02x:%02x "\ + "channel %d beaconInterval %d capability 0x%x\n", + __func__, + mgmt->bssid[0], mgmt->bssid[1], mgmt->bssid[2], + mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5], + ibss_channel->hw_value, beaconInterval, capability)); + + bss = cfg80211_inform_bss_frame(arPriv->wdev->wiphy, + ibss_channel, mgmt, + le16_to_cpu(size), + signal, GFP_ATOMIC); + A_FREE(ieeemgmtbuf); + cfg80211_put_bss(bss); + } + + if((ADHOC_NETWORK & networkType)) { + cfg80211_ibss_joined(arPriv->arNetDev, bssid, GFP_ATOMIC); + return; + } + + if (FALSE == arPriv->arConnected) { + /* inform connect result to cfg80211 */ + cfg80211_connect_result(arPriv->arNetDev, bssid, + assocReqIe, assocReqLen, + assocRespIe, assocRespLen, + WLAN_STATUS_SUCCESS, GFP_ATOMIC); + } else { + /* inform roam event to cfg80211 */ + cfg80211_roamed(arPriv->arNetDev, bssid, + assocReqIe, assocReqLen, + assocRespIe, assocRespLen, + GFP_ATOMIC); + } +} + +static int +ar6k_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev, + A_UINT16 reason_code) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: reason=%u\n", __func__, reason_code)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(ar->bIsDestroyProgress) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, destroy in progress\n", __func__)); + return -EBUSY; + } + + if(down_interruptible(&ar->arSem)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__)); + return -ERESTARTSYS; + } + + reconnect_flag = 0; + ar6000_disconnect(arPriv); + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + + if (arPriv->arSta.arSkipScan == FALSE) { + A_MEMZERO(arPriv->arSta.arReqBssid, sizeof(arPriv->arSta.arReqBssid)); + } + + up(&ar->arSem); + + return 0; +} + +void +ar6k_cfg80211_disconnect_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 reason, + A_UINT8 *bssid, A_UINT8 assocRespLen, + A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: reason=%u\n", __func__, reason)); + + if((ADHOC_NETWORK & arPriv->arNetworkType)) { + if(NL80211_IFTYPE_ADHOC != arPriv->wdev->iftype) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: ath6k not in ibss mode\n", __func__)); + return; + } + A_MEMZERO(bssid, ETH_ALEN); + cfg80211_ibss_joined(arPriv->arNetDev, bssid, GFP_ATOMIC); + return; + } + + if((INFRA_NETWORK & arPriv->arNetworkType)) { + if(NL80211_IFTYPE_STATION != arPriv->wdev->iftype) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: ath6k not in station mode\n", __func__)); + return; + } + } + + if(FALSE == arPriv->arConnected) { + if(NO_NETWORK_AVAIL == reason) { + /* connect cmd failed */ + cfg80211_connect_result(arPriv->arNetDev, bssid, + NULL, 0, + NULL, 0, + WLAN_STATUS_UNSPECIFIED_FAILURE, + GFP_ATOMIC); + } + } else { + /* connection loss due to disconnect cmd or low rssi */ + cfg80211_disconnected(arPriv->arNetDev, reason, NULL, 0, GFP_ATOMIC); + } +} + +void +ar6k_cfg80211_scan_node(void *arg, bss_t *ni) +{ + struct wiphy *wiphy = (struct wiphy *)arg; + A_UINT16 size; + unsigned char *ieeemgmtbuf = NULL; + struct ieee80211_mgmt *mgmt; + struct ieee80211_channel *channel; + struct ieee80211_supported_band *band; + struct ieee80211_common_ie *cie; + s32 signal; + int freq; + + cie = &ni->ni_cie; + +#define CHAN_IS_11A(x) (!((x >= 2412) && (x <= 2484))) + if(CHAN_IS_11A(cie->ie_chan)) { + /* 11a */ + band = wiphy->bands[IEEE80211_BAND_5GHZ]; + } else if((cie->ie_erp) || (cie->ie_xrates)) { + /* 11g */ + band = wiphy->bands[IEEE80211_BAND_2GHZ]; + } else { + /* 11b */ + band = wiphy->bands[IEEE80211_BAND_2GHZ]; + } + + size = ni->ni_framelen + offsetof(struct ieee80211_mgmt, u); + ieeemgmtbuf = A_MALLOC_NOWAIT(size); + if(!ieeemgmtbuf) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ieeeMgmtbuf alloc error\n", __func__)); + return; + } + + /* Note: + TODO: Update target to include 802.11 mac header while sending bss info. + Target removes 802.11 mac header while sending the bss info to host, + cfg80211 needs it, for time being just filling the da, sa and bssid fields alone. + */ + mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf; + A_MEMCPY(mgmt->da, bcast_mac, ATH_MAC_LEN); + A_MEMCPY(mgmt->sa, ni->ni_macaddr, ATH_MAC_LEN); + A_MEMCPY(mgmt->bssid, ni->ni_macaddr, ATH_MAC_LEN); + A_MEMCPY(ieeemgmtbuf + offsetof(struct ieee80211_mgmt, u), + ni->ni_buf, ni->ni_framelen); + + freq = cie->ie_chan; + channel = ieee80211_get_channel(wiphy, freq); + signal = ni->ni_snr * 100; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: bssid %02x:%02x:%02x:%02x:%02x:%02x channel %d freq %d size %d\n", + __func__, + mgmt->bssid[0], mgmt->bssid[1], mgmt->bssid[2], + mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5], + channel->hw_value, freq, size)); + cfg80211_inform_bss_frame(wiphy, channel, mgmt, + le16_to_cpu(size), + signal, GFP_ATOMIC); + + A_FREE (ieeemgmtbuf); +} + +static int +ar6k_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev, + struct cfg80211_scan_request *request) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + int ret = 0; + A_BOOL forceFgScan = FALSE; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if (!arPriv->arSta.arUserBssFilter) { + if (wmi_bssfilter_cmd(arPriv->arWmi, + (arPriv->arConnected ? ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), + 0) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Couldn't set bss filtering\n", __func__)); + return -EIO; + } + } + + if(request->n_ssids && + request->ssids[0].ssid_len) { + A_UINT8 i; + + if(request->n_ssids > MAX_PROBED_SSID_INDEX) { + request->n_ssids = MAX_PROBED_SSID_INDEX; + } + + for (i = 0; i < request->n_ssids; i++) { + wmi_probedSsid_cmd(arPriv->arWmi, i, SPECIFIC_SSID_FLAG, + request->ssids[i].ssid_len, + request->ssids[i].ssid); + } + } + + if(arPriv->arConnected) { + forceFgScan = TRUE; + } + + if(wmi_startscan_cmd(arPriv->arWmi, WMI_LONG_SCAN, forceFgScan, FALSE, \ + 0, 0, 0, NULL) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_startscan_cmd failed\n", __func__)); + ret = -EIO; + } + + arPriv->scan_request = request; + + return ret; +} + +void +ar6k_cfg80211_scanComplete_event(AR_SOFTC_DEV_T *arPriv, A_STATUS status) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: status %d\n", __func__, status)); + + if(arPriv->scan_request) + { + /* Translate data to cfg80211 mgmt format */ + wmi_iterate_nodes(arPriv->arWmi, ar6k_cfg80211_scan_node, arPriv->wdev->wiphy); + + cfg80211_scan_done(arPriv->scan_request, + (status & A_ECANCELED) ? true : false); + + if(arPriv->scan_request->n_ssids && + arPriv->scan_request->ssids[0].ssid_len) { + A_UINT8 i; + + for (i = 0; i < arPriv->scan_request->n_ssids; i++) { + wmi_probedSsid_cmd(arPriv->arWmi, i, DISABLE_SSID_FLAG, + 0, NULL); + } + } + arPriv->scan_request = NULL; + } +} + +static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) +ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr, + struct key_params *params) +#else +ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, const A_UINT8 *mac_addr, + struct key_params *params) +#endif +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + struct ar_key *key = NULL; + A_UINT8 key_usage; + A_UINT8 key_type; + A_STATUS status = 0; +#ifdef CFG80211_WAPI_ENABLE + A_UINT32 *PN; + A_INT32 i; + A_UINT8 wapiKeyRsc[16] = {0}; + #define PN_INIT 0x5c365c36 +#endif + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s:\n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: key index %d out of bounds\n", __func__, key_index)); + return -ENOENT; + } + + key = &arPriv->keys[key_index]; + A_MEMZERO(key, sizeof(struct ar_key)); + + if(!mac_addr || is_broadcast_ether_addr(mac_addr)) { + key_usage = GROUP_USAGE; + } else { + key_usage = PAIRWISE_USAGE; + } + + if(params) { + if(params->key_len > WLAN_MAX_KEY_LEN || + params->seq_len > IW_ENCODE_SEQ_MAX_SIZE) + return -EINVAL; + + key->key_len = params->key_len; + A_MEMCPY(key->key, params->key, key->key_len); + key->seq_len = params->seq_len; + A_MEMCPY(key->seq, params->seq, key->seq_len); + key->cipher = params->cipher; + } + + switch (key->cipher) { + case WLAN_CIPHER_SUITE_WEP40: + case WLAN_CIPHER_SUITE_WEP104: + key_type = WEP_CRYPT; + break; + + case WLAN_CIPHER_SUITE_TKIP: + key_type = TKIP_CRYPT; + break; + + case WLAN_CIPHER_SUITE_CCMP: + key_type = AES_CRYPT; + break; + + default: + return -ENOTSUPP; + } + + if (((WMI_WPA_PSK_AUTH == arPriv->arAuthMode) || (WMI_WPA2_PSK_AUTH == arPriv->arAuthMode)) && + (GROUP_USAGE & key_usage)) + { + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: index %d, key_len %d, key_type 0x%x,"\ + " key_usage 0x%x, seq_len %d\n", + __func__, key_index, key->key_len, key_type, + key_usage, key->seq_len)); + arPriv->arDefTxKeyIndex = key_index; + +#ifdef CFG80211_WAPI_ENABLE + key_type = WAPI_CRYPT; + key_usage = 0; + if (is_broadcast_ether_addr(mac_addr)) { + key_usage |= GROUP_USAGE; + PN = (A_UINT32 *)wapiKeyRsc; + for (i = 0; i < 4; i++) { + PN[i] = PN_INIT; + } + } else { + key_usage |= PAIRWISE_USAGE; + } + status = wmi_addKey_cmd(arPriv->arWmi, arPriv->arDefTxKeyIndex, key_type, key_usage, + key->key_len, wapiKeyRsc, key->key, KEY_OP_INIT_VAL, + (A_UINT8*)mac_addr, SYNC_BOTH_WMIFLAG); +#else + status = wmi_addKey_cmd(arPriv->arWmi, arPriv->arDefTxKeyIndex, key_type, key_usage, + key->key_len, key->seq, key->key, KEY_OP_INIT_VAL, + (A_UINT8*)mac_addr, SYNC_BOTH_WMIFLAG); +#endif + + + if(status != A_OK) { + return -EIO; + } + + return 0; +} + +static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) +ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr) +#else +ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, const A_UINT8 *mac_addr) +#endif +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: key index %d out of bounds\n", __func__, key_index)); + return -ENOENT; + } + + if(!arPriv->keys[key_index].key_len) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d is empty\n", __func__, key_index)); + return 0; + } + + arPriv->keys[key_index].key_len = 0; + + return wmi_deleteKey_cmd(arPriv->arWmi, key_index); +} + + +static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) +ar6k_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr, + void *cookie, + void (*callback)(void *cookie, struct key_params*)) +#else +ar6k_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index, const A_UINT8 *mac_addr, void *cookie, + void (*callback)(void *cookie, struct key_params*)) +#endif +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + struct ar_key *key = NULL; + struct key_params params; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: key index %d out of bounds\n", __func__, key_index)); + return -ENOENT; + } + + key = &arPriv->keys[key_index]; + A_MEMZERO(¶ms, sizeof(params)); + params.cipher = key->cipher; + params.key_len = key->key_len; + params.seq_len = key->seq_len; + params.seq = key->seq; + params.key = key->key; + + callback(cookie, ¶ms); + + return key->key_len ? 0 : -ENOENT; +} + + +static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) +ar6k_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index,bool unicast, bool multicast) +#else +ar6k_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index) +#endif +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + struct ar_key *key = NULL; + A_STATUS status = A_OK; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: key index %d out of bounds\n", + __func__, key_index)); + return -ENOENT; + } + + if(!arPriv->keys[key_index].key_len) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: invalid key index %d\n", + __func__, key_index)); + return -EINVAL; + } + + arPriv->arDefTxKeyIndex = key_index; + key = &arPriv->keys[arPriv->arDefTxKeyIndex]; +#ifdef CFG80211_WAPI_ENABLE + /*if WAPI enable, we donot need to set it*/ +#else + status = wmi_addKey_cmd(arPriv->arWmi, arPriv->arDefTxKeyIndex, + arPriv->arPairwiseCrypto, GROUP_USAGE | TX_USAGE, + key->key_len, key->seq, key->key, KEY_OP_INIT_VAL, + NULL, SYNC_BOTH_WMIFLAG); + if (status != A_OK) { + return -EIO; + } +#endif + return 0; +} + +static int +ar6k_cfg80211_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *ndev, + A_UINT8 key_index) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__)); + return -ENOTSUPP; +} + +void +ar6k_cfg80211_tkip_micerr_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 keyid, A_BOOL ismcast) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, + ("%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast)); + + cfg80211_michael_mic_failure(arPriv->arNetDev, arPriv->arBssid, + (ismcast ? NL80211_KEYTYPE_GROUP : NL80211_KEYTYPE_PAIRWISE), + keyid, NULL, GFP_KERNEL); +} + +static int +ar6k_cfg80211_set_wiphy_params(struct wiphy *wiphy, A_UINT32 changed) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)wiphy_priv(wiphy); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: changed 0x%x\n", __func__, changed)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if (changed & WIPHY_PARAM_RTS_THRESHOLD) { + if (wmi_set_rts_cmd(arPriv->arWmi,wiphy->rts_threshold) != A_OK){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_set_rts_cmd failed\n", __func__)); + return -EIO; + } + } + + return 0; +} + +static int +ar6k_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev, + const A_UINT8 *peer, + const struct cfg80211_bitrate_mask *mask) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: mask 0x%x\n", __func__, mask->fixed)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + status = wmi_set_fixrates_cmd(arPriv->arWmi, mask->fixed); + + if(status == A_EINVAL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: invalid params\n", __func__)); + return -EINVAL; + } else if(status != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_set_fixrates_cmd failed\n", __func__)); + return -EIO; + } + + return 0; +#else + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Setting rates: Not supported\n")); + return -EIO; +#endif +} + +/* The type nl80211_tx_power_setting replaces the following data type from 2.6.36 onwards */ +static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) +ar6k_cfg80211_set_txpower(struct wiphy *wiphy, enum nl80211_tx_power_setting type, int dbm) +#else +ar6k_cfg80211_set_txpower(struct wiphy *wiphy, enum tx_power_setting type, int dbm) +#endif +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)wiphy_priv(wiphy); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UINT8 ar_dbm; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type 0x%x, dbm %d\n", __func__, type, dbm)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + arPriv->arTxPwrSet = FALSE; + switch(type) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) + case NL80211_TX_POWER_AUTOMATIC: +#else + case TX_POWER_AUTOMATIC: +#endif + return 0; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) + case NL80211_TX_POWER_LIMITED: +#else + case TX_POWER_LIMITED: +#endif + arPriv->arTxPwr = ar_dbm = dbm; + arPriv->arTxPwrSet = TRUE; + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type 0x%x not supported\n", __func__, type)); + return -EOPNOTSUPP; + } + + wmi_set_txPwr_cmd(arPriv->arWmi, ar_dbm); + + return 0; +} + +static int +ar6k_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)wiphy_priv(wiphy); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if((arPriv->arConnected == TRUE)) { + arPriv->arTxPwr = 0; + + if(wmi_get_txPwr_cmd(arPriv->arWmi) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_get_txPwr_cmd failed\n", __func__)); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->arTxPwr != 0, 5 * HZ); + + if(signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Target did not respond\n", __func__)); + return -EINTR; + } + } + + *dbm = arPriv->arTxPwr; + return 0; +} + +static int +ar6k_cfg80211_set_power_mgmt(struct wiphy *wiphy, + struct net_device *dev, + bool pmgmt, int timeout) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_POWER_MODE_CMD pwrMode; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: pmgmt %d, timeout %d\n", __func__, pmgmt, timeout)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(!pmgmt) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Max Perf\n", __func__)); + pwrMode.powerMode = MAX_PERF_POWER; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Rec Power\n", __func__)); + pwrMode.powerMode = REC_POWER; + } + + if(wmi_powermode_cmd(arPriv->arWmi, pwrMode.powerMode) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_powermode_cmd failed\n", __func__)); + return -EIO; + } + + return 0; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) +struct net_device * +ar6k_cfg80211_add_virtual_intf(struct wiphy *wiphy, char *name, + enum nl80211_iftype type, u32 *flags, + struct vif_params *params) +#else +static int +ar6k_cfg80211_add_virtual_intf(struct wiphy *wiphy, char *name, + enum nl80211_iftype type, u32 *flags, + struct vif_params *params) +#endif +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__)); + + /* Multiple virtual interface is not supported. + * The default interface supports STA and IBSS type + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) + return NULL; +#else + return -EOPNOTSUPP; +#endif +} + +static int +ar6k_cfg80211_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__)); + + /* Multiple virtual interface is not supported. + * The default interface supports STA and IBSS type + */ + return -EOPNOTSUPP; +} + +static int +ar6k_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, + enum nl80211_iftype type, u32 *flags, + struct vif_params *params) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ndev); + AR_SOFTC_T *ar = arPriv->arSoftc; + struct wireless_dev *wdev = arPriv->wdev; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type %u\n", __func__, type)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + switch (type) { + case NL80211_IFTYPE_STATION: + arPriv->arNextMode = INFRA_NETWORK; + break; + case NL80211_IFTYPE_ADHOC: + arPriv->arNextMode = ADHOC_NETWORK; + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: type %u\n", __func__, type)); + return -EOPNOTSUPP; + } + + wdev->iftype = type; + + return 0; +} + +static int +ar6k_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_ibss_params *ibss_param) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta; + A_STATUS status; + + arSta = &arPriv->arSta; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + if(!ibss_param->ssid_len || IEEE80211_MAX_SSID_LEN < ibss_param->ssid_len) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ssid invalid\n", __func__)); + return -EINVAL; + } + + arPriv->arSsidLen = ibss_param->ssid_len; + A_MEMCPY(arPriv->arSsid, ibss_param->ssid, arPriv->arSsidLen); + + if(ibss_param->channel) { + arPriv->arChannelHint = ibss_param->channel->center_freq; + } + + if(ibss_param->channel_fixed) { + /* TODO: channel_fixed: The channel should be fixed, do not search for + * IBSSs to join on other channels. Target firmware does not support this + * feature, needs to be updated.*/ + } + + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + if(ibss_param->bssid) { + if(A_MEMCMP(&ibss_param->bssid, bcast_mac, AR6000_ETH_ADDR_LEN)) { + A_MEMCPY(arSta->arReqBssid, ibss_param->bssid, sizeof(arSta->arReqBssid)); + } + } + + ar6k_set_wpa_version(arPriv, 0); + ar6k_set_auth_type(arPriv, NL80211_AUTHTYPE_OPEN_SYSTEM); + + if(ibss_param->privacy) { + ar6k_set_cipher(arPriv, WLAN_CIPHER_SUITE_WEP40, true); + ar6k_set_cipher(arPriv, WLAN_CIPHER_SUITE_WEP40, false); + } else { + ar6k_set_cipher(arPriv, IW_AUTH_CIPHER_NONE, true); + ar6k_set_cipher(arPriv, IW_AUTH_CIPHER_NONE, false); + } + + arPriv->arNetworkType = arPriv->arNextMode; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Connect called with authmode %d dot11 auth %d"\ + " PW crypto %d PW crypto Len %d GRP crypto %d"\ + " GRP crypto Len %d channel hint %u\n", + __func__, arPriv->arAuthMode, arPriv->arDot11AuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto, arPriv->arGroupCryptoLen, arPriv->arChannelHint)); + + status = wmi_connect_cmd(arPriv->arWmi, arPriv->arNetworkType, + arPriv->arDot11AuthMode, arPriv->arAuthMode, + arPriv->arPairwiseCrypto, arPriv->arPairwiseCryptoLen, + arPriv->arGroupCrypto,arPriv->arGroupCryptoLen, + arPriv->arSsidLen, arPriv->arSsid, + arSta->arReqBssid, arPriv->arChannelHint, + arSta->arConnectCtrlFlags); + arSta->arConnectPending = TRUE; + + return 0; +} + +static int +ar6k_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(ar->arWmiReady == FALSE) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__)); + return -EIO; + } + + if(ar->arWlanState == WLAN_DISABLED) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__)); + return -EIO; + } + + ar6000_disconnect(arPriv); + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + + return 0; +} + + +static const +A_UINT32 cipher_suites[] = { + WLAN_CIPHER_SUITE_WEP40, + WLAN_CIPHER_SUITE_WEP104, + WLAN_CIPHER_SUITE_TKIP, + WLAN_CIPHER_SUITE_CCMP, +}; + +static struct +cfg80211_ops ar6k_cfg80211_ops = { + .change_virtual_intf = ar6k_cfg80211_change_iface, + .add_virtual_intf = ar6k_cfg80211_add_virtual_intf, + .del_virtual_intf = ar6k_cfg80211_del_virtual_intf, + .scan = ar6k_cfg80211_scan, + .connect = ar6k_cfg80211_connect, + .disconnect = ar6k_cfg80211_disconnect, + .add_key = ar6k_cfg80211_add_key, + .get_key = ar6k_cfg80211_get_key, + .del_key = ar6k_cfg80211_del_key, + .set_default_key = ar6k_cfg80211_set_default_key, + .set_default_mgmt_key = ar6k_cfg80211_set_default_mgmt_key, + .set_wiphy_params = ar6k_cfg80211_set_wiphy_params, + .set_bitrate_mask = ar6k_cfg80211_set_bitrate_mask, + .set_tx_power = ar6k_cfg80211_set_txpower, + .get_tx_power = ar6k_cfg80211_get_txpower, + .set_power_mgmt = ar6k_cfg80211_set_power_mgmt, + .join_ibss = ar6k_cfg80211_join_ibss, + .leave_ibss = ar6k_cfg80211_leave_ibss, +}; + +struct wireless_dev * +ar6k_cfg80211_init(struct device *dev) +{ + int ret = 0; + struct wireless_dev *wdev; + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); + if(!wdev) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: Couldn't allocate wireless device\n", __func__)); + return ERR_PTR(-ENOMEM); + } + + /* create a new wiphy for use with cfg80211 */ + wdev->wiphy = wiphy_new(&ar6k_cfg80211_ops, sizeof(AR_SOFTC_T)); + if(!wdev->wiphy) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: Couldn't allocate wiphy device\n", __func__)); + kfree(wdev); + return ERR_PTR(-ENOMEM); + } + + /* set device pointer for wiphy */ + set_wiphy_dev(wdev->wiphy, dev); + + wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | + BIT(NL80211_IFTYPE_ADHOC); + /* max num of ssids that can be probed during scanning */ + wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX; + wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar6k_band_2ghz; + wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar6k_band_5ghz; + wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; + + wdev->wiphy->cipher_suites = cipher_suites; + wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); + + ret = wiphy_register(wdev->wiphy); + if(ret < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("%s: Couldn't register wiphy device\n", __func__)); + wiphy_free(wdev->wiphy); + return ERR_PTR(ret); + } + + return wdev; +} + +void +ar6k_cfg80211_deinit(AR_SOFTC_DEV_T *arPriv) +{ + struct wireless_dev *wdev = arPriv->wdev; + + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__)); + + if(arPriv->scan_request) { + cfg80211_scan_done(arPriv->scan_request, true); + arPriv->scan_request = NULL; + } + + if(!wdev) + return; + + wiphy_unregister(wdev->wiphy); + wiphy_free(wdev->wiphy); + kfree(wdev); +} + + + + + + + diff --git a/drivers/net/wireless/ar6003/host/os/linux/eeprom.c b/drivers/net/wireless/ar6003/host/os/linux/eeprom.c new file mode 100644 index 000000000000..5f6a14766aa2 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/eeprom.c @@ -0,0 +1,569 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + + +#include "ar6000_drv.h" +#include "htc.h" +#include + +#include "target_reg_table.h" +#include "host_reg_table.h +// +// defines +// + +#define MAX_FILENAME 1023 +#define EEPROM_WAIT_LIMIT 16 + +#define EEPROM_SZ 768 + +/* soft mac */ +#define ATH_MAC_LEN 6 +#define ATH_SOFT_MAC_TMP_BUF_LEN 64 +unsigned char mac_addr[ATH_MAC_LEN]; +unsigned char soft_mac_tmp_buf[ATH_SOFT_MAC_TMP_BUF_LEN]; +char *p_mac = NULL; +/* soft mac */ + +// +// static variables +// + +static A_UCHAR eeprom_data[EEPROM_SZ]; +static A_UINT32 sys_sleep_reg; +static HIF_DEVICE *p_bmi_device; + +// +// Functions +// + +/* soft mac */ +static int +wmic_ether_aton(const char *orig, A_UINT8 *eth) +{ + const char *bufp; + int i; + + i = 0; + for(bufp = orig; *bufp != '\0'; ++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 { + printk("%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 { + printk("%s: MAC value is invalid\n", __FUNCTION__); + break; + } + + eth[i] = (unsigned char) (val & 0377); + if(++i == ATH_MAC_LEN) { + /* That's it. Any trailing junk? */ + if (*bufp != '\0') { + return 0; + } + return 1; + } + if (*bufp != ':') + break; + } + return 0; +} + +static void +update_mac(unsigned char* eeprom, int size, unsigned char* macaddr) +{ + int i; + A_UINT16* ptr = (A_UINT16*)(eeprom+4); + A_UINT16 checksum = 0; + + memcpy(eeprom+10,macaddr,6); + + *ptr = 0; + ptr = (A_UINT16*)eeprom; + + for (i=0; i>7)); + + BMI_write_reg(SI_BASE_ADDRESS+SI_TX_DATA0_OFFSET, regval); + + regval = SI_CS_START_SET(1) | + SI_CS_RX_CNT_SET(8) | + SI_CS_TX_CNT_SET(3); + BMI_write_reg(SI_BASE_ADDRESS+SI_CS_OFFSET, regval); +} + +/* + * Tell the Target to start a 4-byte write to EEPROM, + * writing values from Target TX_DATA registers. + */ +static void +request_4byte_write(int offset, A_UINT32 data) +{ + A_UINT32 regval; + + printk("%s: request_4byte_write (0x%x) to offset 0x%x\n", __FUNCTION__, data, offset); + + /* SI_TX_DATA0 = write data to offset */ + regval = ((data & 0xffff) <<16) | + ((offset & 0xff)<<8) | + (0xa0 | ((offset & 0xff00)>>7)); + BMI_write_reg(SI_BASE_ADDRESS+SI_TX_DATA0_OFFSET, regval); + + regval = data >> 16; + BMI_write_reg(SI_BASE_ADDRESS+SI_TX_DATA1_OFFSET, regval); + + regval = SI_CS_START_SET(1) | + SI_CS_RX_CNT_SET(0) | + SI_CS_TX_CNT_SET(6); + BMI_write_reg(SI_BASE_ADDRESS+SI_CS_OFFSET, regval); +} + +/* + * Check whether or not an EEPROM request that was started + * earlier has completed yet. + */ +static A_BOOL +request_in_progress(void) +{ + A_UINT32 regval; + + /* Wait for DONE_INT in SI_CS */ + BMI_read_reg(SI_BASE_ADDRESS+SI_CS_OFFSET, ®val); + +// printk("%s: request in progress SI_CS=0x%x\n", __FUNCTION__, regval); + if (regval & SI_CS_DONE_ERR_MASK) { + printk("%s: EEPROM signaled ERROR (0x%x)\n", __FUNCTION__, regval); + } + + return (!(regval & SI_CS_DONE_INT_MASK)); +} + +/* + * try to detect the type of EEPROM,16bit address or 8bit address + */ + +static void eeprom_type_detect(void) +{ + A_UINT32 regval; + A_UINT8 i = 0; + + request_8byte_read(0x100); + /* Wait for DONE_INT in SI_CS */ + do{ + BMI_read_reg(SI_BASE_ADDRESS+SI_CS_OFFSET, ®val); + if (regval & SI_CS_DONE_ERR_MASK) { + printk("%s: ERROR : address type was wrongly set\n", __FUNCTION__); + break; + } + if (i++ == EEPROM_WAIT_LIMIT) { + printk("%s: EEPROM not responding\n", __FUNCTION__); + } + } while(!(regval & SI_CS_DONE_INT_MASK)); +} + +/* + * Extract the results of a completed EEPROM Read request + * and return them to the caller. + */ +inline void +read_8byte_results(A_UINT32 *data) +{ + /* Read SI_RX_DATA0 and SI_RX_DATA1 */ + BMI_read_reg(SI_BASE_ADDRESS+SI_RX_DATA0_OFFSET, &data[0]); + BMI_read_reg(SI_BASE_ADDRESS+SI_RX_DATA1_OFFSET, &data[1]); +} + + +/* + * Wait for a previously started command to complete. + * Timeout if the command is takes "too long". + */ +static void +wait_for_eeprom_completion(void) +{ + int i=0; + + while (request_in_progress()) { + if (i++ == EEPROM_WAIT_LIMIT) { + printk("%s: EEPROM not responding\n", __FUNCTION__); + } + } +} + +/* + * High-level function which starts an 8-byte read, + * waits for it to complete, and returns the result. + */ +static void +fetch_8bytes(int offset, A_UINT32 *data) +{ + request_8byte_read(offset); + wait_for_eeprom_completion(); + read_8byte_results(data); + + /* Clear any pending intr */ + BMI_write_reg(SI_BASE_ADDRESS+SI_CS_OFFSET, SI_CS_DONE_INT_MASK); +} + +/* + * High-level function which starts a 4-byte write, + * and waits for it to complete. + */ +inline void +commit_4bytes(int offset, A_UINT32 data) +{ + request_4byte_write(offset, data); + wait_for_eeprom_completion(); +} +/* ATHENV */ +#ifdef ANDROID_ENV +void eeprom_ar6000_transfer(HIF_DEVICE *device, char *fake_file, char *p_mac) +{ + A_UINT32 first_word; + A_UINT32 board_data_addr; + int i; + + printk("%s: Enter\n", __FUNCTION__); + + enable_SI(device); + eeprom_type_detect(); + + if (fake_file) { + /* + * Transfer from file to Target RAM. + * Fetch source data from file. + */ + mm_segment_t oldfs; + struct file *filp; + struct inode *inode = NULL; + int length; + + /* open file */ + oldfs = get_fs(); + set_fs(KERNEL_DS); + filp = filp_open(fake_file, O_RDONLY, S_IRUSR); + + if (IS_ERR(filp)) { + printk("%s: file %s filp_open error\n", __FUNCTION__, fake_file); + set_fs(oldfs); + return; + } + + if (!filp->f_op) { + printk("%s: File Operation Method Error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + inode = GET_INODE_FROM_FILEP(filep); + if (!inode) { + printk("%s: Get inode from filp failed\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + printk("%s file offset opsition: %xh\n", __FUNCTION__, (unsigned)filp->f_pos); + + /* file's size */ + length = i_size_read(inode->i_mapping->host); + printk("%s: length=%d\n", __FUNCTION__, length); + if (length != EEPROM_SZ) { + printk("%s: The file's size is not as expected\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data */ + if (filp->f_op->read(filp, eeprom_data, length, &filp->f_pos) != length) { + printk("%s: file read error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data out successfully */ + filp_close(filp, NULL); + set_fs(oldfs); + } else { + /* + * Read from EEPROM to file OR transfer from EEPROM to Target RAM. + * Fetch EEPROM_SZ Bytes of Board Data, 8 bytes at a time. + */ + + fetch_8bytes(0, (A_UINT32 *)(&eeprom_data[0])); + + /* Check the first word of EEPROM for validity */ + first_word = *((A_UINT32 *)eeprom_data); + + if ((first_word == 0) || (first_word == 0xffffffff)) { + printk("Did not find EEPROM with valid Board Data.\n"); + } + + for (i=8; if_op) { + printk("%s: File Operation Method Error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + inode = GET_INODE_FROM_FILEP(filep); + if (!inode) { + printk("%s: Get inode from filp failed\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + printk("%s file offset opsition: %xh\n", __FUNCTION__, (unsigned)filp->f_pos); + + /* file's size */ + length = i_size_read(inode->i_mapping->host); + printk("%s: length=%d\n", __FUNCTION__, length); + if (length > ATH_SOFT_MAC_TMP_BUF_LEN) { + printk("%s: MAC file's size is not as expected\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data */ + if (filp->f_op->read(filp, soft_mac_tmp_buf, length, &filp->f_pos) != length) { + printk("%s: file read error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + +#if 0 + /* the data we just read */ + printk("%s: mac address from the file:\n", __FUNCTION__); + for (i = 0; i < length; i++) + printk("[%c(0x%x)],", soft_mac_tmp_buf[i], soft_mac_tmp_buf[i]); + printk("\n"); +#endif + + /* read data out successfully */ + filp_close(filp, NULL); + set_fs(oldfs); + + /* convert mac address */ + if (!wmic_ether_aton(soft_mac_tmp_buf, mac_addr)) { + printk("%s: convert mac value fail\n", __FUNCTION__); + return; + } + +#if 0 + /* the converted mac address */ + printk("%s: the converted mac value\n", __FUNCTION__); + for (i = 0; i < ATH_MAC_LEN; i++) + printk("[0x%x],", mac_addr[i]); + printk("\n"); +#endif + } + /* soft mac */ + + /* Determine where in Target RAM to write Board Data */ + BMI_read_mem( AR6002_HOST_INTEREST_ITEM_ADDRESS(hi_board_data), &board_data_addr); + if (board_data_addr == 0) { + printk("hi_board_data is zero\n"); + } + + /* soft mac */ +#if 1 + /* Update MAC address in RAM */ + if (p_mac) { + update_mac(eeprom_data, EEPROM_SZ, mac_addr); + } +#endif +#if 0 + /* mac address in eeprom array */ + printk("%s: mac values in eeprom array\n", __FUNCTION__); + for (i = 10; i < 10 + 6; i++) + printk("[0x%x],", eeprom_data[i]); + printk("\n"); +#endif + /* soft mac */ + + /* Write EEPROM data to Target RAM */ + BMI_write_mem(board_data_addr, ((A_UINT8 *)eeprom_data), EEPROM_SZ); + + /* Record the fact that Board Data IS initialized */ + { + A_UINT32 one = 1; + BMI_write_mem(AR6002_HOST_INTEREST_ITEM_ADDRESS(hi_board_data_initialized), + (A_UINT8 *)&one, sizeof(A_UINT32)); + } + + disable_SI(); +} diff --git a/drivers/net/wireless/ar6003/host/os/linux/export_hci_transport.c b/drivers/net/wireless/ar6003/host/os/linux/export_hci_transport.c new file mode 100644 index 000000000000..c44311b79665 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/export_hci_transport.c @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HCI bridge implementation +// +// Author(s): ="Atheros" +//============================================================================== +#include +#include +#include "a_types.h" +#include "a_osapi.h" +#include "htc_api.h" +#include "a_drv.h" +#include "hif.h" +#include "common_drv.h" +#include "a_debug.h" +#include "hci_transport_api.h" + + +HCI_TRANSPORT_HANDLE (*_HCI_TransportAttach)(void *HTCHandle, HCI_TRANSPORT_CONFIG_INFO *pInfo); +void (*_HCI_TransportDetach)(HCI_TRANSPORT_HANDLE HciTrans); +A_STATUS (*_HCI_TransportAddReceivePkts)(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET_QUEUE *pQueue); +A_STATUS (*_HCI_TransportSendPkt)(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET *pPacket, A_BOOL Synchronous); +void (*_HCI_TransportStop)(HCI_TRANSPORT_HANDLE HciTrans); +A_STATUS (*_HCI_TransportStart)(HCI_TRANSPORT_HANDLE HciTrans); +A_STATUS (*_HCI_TransportEnableDisableAsyncRecv)(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); +A_STATUS (*_HCI_TransportRecvHCIEventSync)(HCI_TRANSPORT_HANDLE HciTrans, + HTC_PACKET *pPacket, + int MaxPollMS); +A_STATUS (*_HCI_TransportSetBaudRate)(HCI_TRANSPORT_HANDLE HciTrans, A_UINT32 Baud); +A_STATUS (*_HCI_TransportEnablePowerMgmt)(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); + +extern HCI_TRANSPORT_CALLBACKS ar6kHciTransCallbacks; + +A_STATUS ar6000_register_hci_transport(HCI_TRANSPORT_CALLBACKS *hciTransCallbacks) +{ + ar6kHciTransCallbacks = *hciTransCallbacks; + + _HCI_TransportAttach = HCI_TransportAttach; + _HCI_TransportDetach = HCI_TransportDetach; + _HCI_TransportAddReceivePkts = HCI_TransportAddReceivePkts; + _HCI_TransportSendPkt = HCI_TransportSendPkt; + _HCI_TransportStop = HCI_TransportStop; + _HCI_TransportStart = HCI_TransportStart; + _HCI_TransportEnableDisableAsyncRecv = HCI_TransportEnableDisableAsyncRecv; + _HCI_TransportRecvHCIEventSync = HCI_TransportRecvHCIEventSync; + _HCI_TransportSetBaudRate = HCI_TransportSetBaudRate; + _HCI_TransportEnablePowerMgmt = HCI_TransportEnablePowerMgmt; + + return A_OK; +} + +A_STATUS +ar6000_get_hif_dev(HIF_DEVICE *device, void *config) +{ + A_STATUS status; + + status = HIFConfigureDevice(device, + HIF_DEVICE_GET_OS_DEVICE, + (HIF_DEVICE_OS_DEVICE_INFO *)config, + sizeof(HIF_DEVICE_OS_DEVICE_INFO)); + return status; +} + +A_STATUS ar6000_set_uart_config(HIF_DEVICE *hifDevice, + A_UINT32 scale, + A_UINT32 step) +{ + A_UINT32 regAddress; + A_UINT32 regVal; + A_STATUS status; + + regAddress = WLAN_UART_BASE_ADDRESS | UART_CLKDIV_ADDRESS; + regVal = ((A_UINT32)scale << 16) | step; + /* change the HCI UART scale/step values through the diagnostic window */ + status = ar6000_WriteRegDiag(hifDevice, ®Address, ®Val); + + return status; +} + +A_STATUS ar6000_get_core_clock_config(HIF_DEVICE *hifDevice, A_UINT32 *data) +{ + A_UINT32 regAddress; + A_STATUS status; + + regAddress = WLAN_RTC_BASE_ADDRESS | WLAN_CPU_CLOCK_ADDRESS; + /* read CPU clock settings*/ + status = ar6000_ReadRegDiag(hifDevice, ®Address, data); + + return status; +} + +EXPORT_SYMBOL(ar6000_register_hci_transport); +EXPORT_SYMBOL(ar6000_get_hif_dev); +EXPORT_SYMBOL(ar6000_set_uart_config); +EXPORT_SYMBOL(ar6000_get_core_clock_config); +EXPORT_SYMBOL(_HCI_TransportAttach); +EXPORT_SYMBOL(_HCI_TransportDetach); +EXPORT_SYMBOL(_HCI_TransportAddReceivePkts); +EXPORT_SYMBOL(_HCI_TransportSendPkt); +EXPORT_SYMBOL(_HCI_TransportStop); +EXPORT_SYMBOL(_HCI_TransportStart); +EXPORT_SYMBOL(_HCI_TransportEnableDisableAsyncRecv); +EXPORT_SYMBOL(_HCI_TransportRecvHCIEventSync); +EXPORT_SYMBOL(_HCI_TransportSetBaudRate); +EXPORT_SYMBOL(_HCI_TransportEnablePowerMgmt); diff --git a/drivers/net/wireless/ar6003/host/os/linux/hci_bridge.c b/drivers/net/wireless/ar6003/host/os/linux/hci_bridge.c new file mode 100644 index 000000000000..1c6642082652 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/hci_bridge.c @@ -0,0 +1,1174 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HCI bridge implementation +// +// Author(s): ="Atheros" +//============================================================================== + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +#include +#include +#include +#include "a_types.h" +#include "a_osapi.h" +#include "htc_api.h" +#include "wmi.h" +#include "a_drv.h" +#include "hif.h" +#include "common_drv.h" +#include "a_debug.h" +#define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6) +#define ATH_DEBUG_HCI_RECV ATH_DEBUG_MAKE_MODULE_MASK(7) +#define ATH_DEBUG_HCI_SEND ATH_DEBUG_MAKE_MODULE_MASK(8) +#define ATH_DEBUG_HCI_DUMP ATH_DEBUG_MAKE_MODULE_MASK(9) +#else +#include "ar6000_drv.h" +#endif /* EXPORT_HCI_BRIDGE_INTERFACE */ + +#ifdef ATH_AR6K_ENABLE_GMBOX +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +#include "export_hci_transport.h" +#else +#include "hci_transport_api.h" +#endif +#include "epping_test.h" +#include "gmboxif.h" +#include "ar3kconfig.h" +#include +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) + /* only build on newer kernels which have BT configured */ +#if defined(CONFIG_BT_MODULE) || defined(CONFIG_BT) +#define CONFIG_BLUEZ_HCI_BRIDGE +#endif +#endif + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +unsigned int ar3khcibaud = 0; +unsigned int hciuartscale = 0; +unsigned int hciuartstep = 0; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +module_param(ar3khcibaud, int, 0644); +module_param(hciuartscale, int, 0644); +module_param(hciuartstep, int, 0644); +#else + +#define __user +/* for linux 2.4 and lower */ +MODULE_PARM(ar3khcibaud, "i"); +MODULE_PARM(hciuartscale, "i"); +MODULE_PARM(hciuartstep, "i"); +#endif +#else +extern unsigned int ar3khcibaud; +extern unsigned int hciuartscale; +extern unsigned int hciuartstep; +#endif /* EXPORT_HCI_BRIDGE_INTERFACE */ + +typedef struct { + void *pHCIDev; /* HCI bridge device */ + HCI_TRANSPORT_PROPERTIES HCIProps; /* HCI bridge props */ + struct hci_dev *pBtStackHCIDev; /* BT Stack HCI dev */ + A_BOOL HciNormalMode; /* Actual HCI mode enabled (non-TEST)*/ + A_BOOL HciRegistered; /* HCI device registered with stack */ + HTC_PACKET_QUEUE HTCPacketStructHead; + A_UINT8 *pHTCStructAlloc; + spinlock_t BridgeLock; +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + HCI_TRANSPORT_MISC_HANDLES HCITransHdl; +#else + AR_SOFTC_T *ar; +#endif /* EXPORT_HCI_BRIDGE_INTERFACE */ +} AR6K_HCI_BRIDGE_INFO; + +#define MAX_ACL_RECV_BUFS 16 +#define MAX_EVT_RECV_BUFS 8 +#define MAX_HCI_WRITE_QUEUE_DEPTH 32 +#define MAX_ACL_RECV_LENGTH 1200 +#define MAX_EVT_RECV_LENGTH 257 +#define TX_PACKET_RSV_OFFSET 32 +#define NUM_HTC_PACKET_STRUCTS ((MAX_ACL_RECV_BUFS + MAX_EVT_RECV_BUFS + MAX_HCI_WRITE_QUEUE_DEPTH) * 2) + +#define HCI_GET_OP_CODE(p) (((A_UINT16)((p)[1])) << 8) | ((A_UINT16)((p)[0])) + +extern unsigned int setupbtdev; +AR3K_CONFIG_INFO ar3kconfig; + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +AR6K_HCI_BRIDGE_INFO *g_pHcidevInfo; +#endif + +static A_STATUS bt_setup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo); +static void bt_cleanup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo); +static A_STATUS bt_register_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo); +static A_BOOL bt_indicate_recv(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, + HCI_TRANSPORT_PACKET_TYPE Type, + struct sk_buff *skb); +static struct sk_buff *bt_alloc_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, int Length); +static void bt_free_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, struct sk_buff *skb); + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +A_STATUS ar6000_setup_hci(void *ar); +void ar6000_cleanup_hci(void *ar); +A_STATUS hci_test_send(void *ar, struct sk_buff *skb); +#else +A_STATUS ar6000_setup_hci(AR_SOFTC_T *ar); +void ar6000_cleanup_hci(AR_SOFTC_T *ar); +/* HCI bridge testing */ +A_STATUS hci_test_send(AR_SOFTC_T *ar, struct sk_buff *skb); +#endif /* EXPORT_HCI_BRIDGE_INTERFACE */ + +#define LOCK_BRIDGE(dev) spin_lock_bh(&(dev)->BridgeLock) +#define UNLOCK_BRIDGE(dev) spin_unlock_bh(&(dev)->BridgeLock) + +static inline void FreeBtOsBuf(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, void *osbuf) +{ + if (pHcidevInfo->HciNormalMode) { + bt_free_buffer(pHcidevInfo, (struct sk_buff *)osbuf); + } else { + /* in test mode, these are just ordinary netbuf allocations */ + A_NETBUF_FREE(osbuf); + } +} + +static void FreeHTCStruct(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, HTC_PACKET *pPacket) +{ + LOCK_BRIDGE(pHcidevInfo); + HTC_PACKET_ENQUEUE(&pHcidevInfo->HTCPacketStructHead,pPacket); + UNLOCK_BRIDGE(pHcidevInfo); +} + +static HTC_PACKET * AllocHTCStruct(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + HTC_PACKET *pPacket = NULL; + LOCK_BRIDGE(pHcidevInfo); + pPacket = HTC_PACKET_DEQUEUE(&pHcidevInfo->HTCPacketStructHead); + UNLOCK_BRIDGE(pHcidevInfo); + return pPacket; +} + +#define BLOCK_ROUND_UP_PWR2(x, align) (((int) (x) + ((align)-1)) & ~((align)-1)) + +static void RefillRecvBuffers(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, + HCI_TRANSPORT_PACKET_TYPE Type, + int NumBuffers) +{ + int length, i; + void *osBuf = NULL; + HTC_PACKET_QUEUE queue; + HTC_PACKET *pPacket; + + INIT_HTC_PACKET_QUEUE(&queue); + + if (Type == HCI_ACL_TYPE) { + if (pHcidevInfo->HciNormalMode) { + length = HCI_MAX_FRAME_SIZE; + } else { + length = MAX_ACL_RECV_LENGTH; + } + } else { + length = MAX_EVT_RECV_LENGTH; + } + + /* add on transport head and tail room */ + length += pHcidevInfo->HCIProps.HeadRoom + pHcidevInfo->HCIProps.TailRoom; + /* round up to the required I/O padding */ + length = BLOCK_ROUND_UP_PWR2(length,pHcidevInfo->HCIProps.IOBlockPad); + + for (i = 0; i < NumBuffers; i++) { + + if (pHcidevInfo->HciNormalMode) { + osBuf = bt_alloc_buffer(pHcidevInfo,length); + } else { + osBuf = A_NETBUF_ALLOC(length); + } + + if (NULL == osBuf) { + break; + } + + pPacket = AllocHTCStruct(pHcidevInfo); + if (NULL == pPacket) { + FreeBtOsBuf(pHcidevInfo,osBuf); + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to alloc HTC struct \n")); + break; + } + + SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),length,Type); + /* add to queue */ + HTC_PACKET_ENQUEUE(&queue,pPacket); + } + + if (i > 0) { + HCI_TransportAddReceivePkts(pHcidevInfo->pHCIDev, &queue); + } +} + +static A_STATUS ar6000_hci_transport_ready(HCI_TRANSPORT_HANDLE HCIHandle, + HCI_TRANSPORT_PROPERTIES *pProps, + void *pContext) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + A_STATUS status; + AR_SOFTC_DEV_T *arDev = pHcidevInfo->ar->arDev[0]; + + + pHcidevInfo->pHCIDev = HCIHandle; + + A_MEMCPY(&pHcidevInfo->HCIProps,pProps,sizeof(*pProps)); + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE,("HCI ready (hci:0x%lX, headroom:%d, tailroom:%d blockpad:%d) \n", + (unsigned long)HCIHandle, + pHcidevInfo->HCIProps.HeadRoom, + pHcidevInfo->HCIProps.TailRoom, + pHcidevInfo->HCIProps.IOBlockPad)); + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + A_ASSERT((pProps->HeadRoom + pProps->TailRoom) <= (struct net_device *)(pHcidevInfo->HCITransHdl.netDevice)->hard_header_len); +#else + A_ASSERT((pProps->HeadRoom + pProps->TailRoom) <= arDev->arNetDev->hard_header_len); +#endif + + /* provide buffers */ + RefillRecvBuffers(pHcidevInfo, HCI_ACL_TYPE, MAX_ACL_RECV_BUFS); + RefillRecvBuffers(pHcidevInfo, HCI_EVENT_TYPE, MAX_EVT_RECV_BUFS); + + do { + /* start transport */ + status = HCI_TransportStart(pHcidevInfo->pHCIDev); + + if (A_FAILED(status)) { + break; + } + + if (!pHcidevInfo->HciNormalMode) { + /* in test mode, no need to go any further */ + break; + } + + // The delay is required when AR6K is driving the BT reset line + // where time is needed after the BT chip is out of reset (HCI_TransportStart) + // and before the first HCI command is issued (AR3KConfigure) + // FIXME + // The delay should be configurable and be only applied when AR6K driving the BT + // reset line. This could be done by some module parameter or based on some HW config + // info. For now apply 100ms delay blindly + A_MDELAY(100); + + A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig)); + ar3kconfig.pHCIDev = pHcidevInfo->pHCIDev; + ar3kconfig.pHCIProps = &pHcidevInfo->HCIProps; +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + ar3kconfig.pHIFDevice = (HIF_DEVICE *)(pHcidevInfo->HCITransHdl.hifDevice); +#else + ar3kconfig.pHIFDevice = pHcidevInfo->ar->arHifDevice; +#endif + ar3kconfig.pBtStackHCIDev = pHcidevInfo->pBtStackHCIDev; + + if (ar3khcibaud != 0) { + /* user wants ar3k baud rate change */ + ar3kconfig.Flags |= AR3K_CONFIG_FLAG_SET_AR3K_BAUD; + ar3kconfig.Flags |= AR3K_CONFIG_FLAG_AR3K_BAUD_CHANGE_DELAY; + ar3kconfig.AR3KBaudRate = ar3khcibaud; + } + + if ((hciuartscale != 0) || (hciuartstep != 0)) { + /* user wants to tune HCI bridge UART scale/step values */ + ar3kconfig.AR6KScale = (A_UINT16)hciuartscale; + ar3kconfig.AR6KStep = (A_UINT16)hciuartstep; + ar3kconfig.Flags |= AR3K_CONFIG_FLAG_SET_AR6K_SCALE_STEP; + } + + /* configure the AR3K device */ + memcpy(ar3kconfig.bdaddr,pHcidevInfo->ar->bdaddr,6); + status = AR3KConfigure(&ar3kconfig); + if (A_FAILED(status)) { + extern unsigned int setuphci; + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: Fail to configure AR3K. No device? Cleanup HCI\n")); + pHcidevInfo->ar->exitCallback = NULL; + ar6000_cleanup_hci(pHcidevInfo->ar); + setuphci = 0; + pHcidevInfo->ar->arBTSharing = 0; + break; + } + + /* Make sure both AR6K and AR3K have power management enabled */ + if (ar3kconfig.PwrMgmtEnabled) { + A_UINT32 address, hci_uart_pwr_mgmt_params; + /* Fetch the address of the hi_hci_uart_pwr_mgmt_params instance in the host interest area */ + address = TARG_VTOP(pHcidevInfo->ar->arTargetType, + HOST_INTEREST_ITEM_ADDRESS(pHcidevInfo->ar->arTargetType, hi_hci_uart_pwr_mgmt_params)); + status = ar6000_ReadRegDiag(pHcidevInfo->ar->arHifDevice, &address, &hci_uart_pwr_mgmt_params); + hci_uart_pwr_mgmt_params &= 0xFFFF; + /* wakeup timeout is [31:16] */ + hci_uart_pwr_mgmt_params |= (ar3kconfig.WakeupTimeout << 16); + status |= ar6000_WriteRegDiag(pHcidevInfo->ar->arHifDevice, &address, &hci_uart_pwr_mgmt_params); + if (A_OK != status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: failed to write hci_uart_pwr_mgmt_params!\n")); + } + + /* Fetch the address of the hi_hci_uart_pwr_mgmt_params_ext instance in the host interest area */ + address = TARG_VTOP(pHcidevInfo->ar->arTargetType, + HOST_INTEREST_ITEM_ADDRESS(pHcidevInfo->ar->arTargetType, hi_hci_uart_pwr_mgmt_params_ext)); + status = ar6000_WriteRegDiag(pHcidevInfo->ar->arHifDevice, &address, &ar3kconfig.IdleTimeout); + if (A_OK != status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: failed to write hci_uart_pwr_mgmt_params_ext!\n")); + } + + status = HCI_TransportEnablePowerMgmt(pHcidevInfo->pHCIDev, TRUE); + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: failed to enable TLPM for AR6K! \n")); + } + } + + status = bt_register_hci(pHcidevInfo); + + } while (FALSE); + + return status; +} + +static void ar6000_hci_transport_failure(void *pContext, A_STATUS Status) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: transport failure! \n")); + + if (pHcidevInfo->HciNormalMode) { + /* TODO .. */ + } +} + +static void ar6000_hci_transport_removed(void *pContext) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE, ("HCI Bridge: transport removed. \n")); + + A_ASSERT(pHcidevInfo->pHCIDev != NULL); + + HCI_TransportDetach(pHcidevInfo->pHCIDev); + bt_cleanup_hci(pHcidevInfo); + pHcidevInfo->pHCIDev = NULL; +} + +static void ar6000_hci_send_complete(void *pContext, HTC_PACKET *pPacket) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + void *osbuf = pPacket->pPktContext; + A_ASSERT(osbuf != NULL); + A_ASSERT(pHcidevInfo != NULL); + + if (A_FAILED(pPacket->Status)) { + if ((pPacket->Status != A_ECANCELED) && (pPacket->Status != A_NO_RESOURCE)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: Send Packet Failed: %d \n",pPacket->Status)); + } + } + + FreeHTCStruct(pHcidevInfo,pPacket); + FreeBtOsBuf(pHcidevInfo,osbuf); + +} + +static void ar6000_hci_pkt_recv(void *pContext, HTC_PACKET *pPacket) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + struct sk_buff *skb; + AR_SOFTC_DEV_T *arDev = pHcidevInfo->ar->arDev[0]; + + A_ASSERT(pHcidevInfo != NULL); + skb = (struct sk_buff *)pPacket->pPktContext; + A_ASSERT(skb != NULL); + + do { + + if (A_FAILED(pPacket->Status)) { + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_RECV, + ("HCI Bridge, packet received type : %d len:%d \n", + HCI_GET_PACKET_TYPE(pPacket),pPacket->ActualLength)); + + /* set the actual buffer position in the os buffer, HTC recv buffers posted to HCI are set + * to fill the front of the buffer */ + A_NETBUF_PUT(skb,pPacket->ActualLength + pHcidevInfo->HCIProps.HeadRoom); + A_NETBUF_PULL(skb,pHcidevInfo->HCIProps.HeadRoom); + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_HCI_DUMP)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("<<< Recv HCI %s packet len:%d \n", + (HCI_GET_PACKET_TYPE(pPacket) == HCI_EVENT_TYPE) ? "EVENT" : "ACL", + skb->len)); + AR_DEBUG_PRINTBUF(skb->data, skb->len,"BT HCI RECV Packet Dump"); + } + + if (pHcidevInfo->HciNormalMode) { + /* indicate the packet */ + if (bt_indicate_recv(pHcidevInfo,HCI_GET_PACKET_TYPE(pPacket),skb)) { + /* bt stack accepted the packet */ + skb = NULL; + } + break; + } + + /* for testing, indicate packet to the network stack */ +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + skb->dev = (struct net_device *)(pHcidevInfo->HCITransHdl.netDevice); + if ((((struct net_device *)pHcidevInfo->HCITransHdl.netDevice)->flags & IFF_UP) == IFF_UP) { + skb->protocol = eth_type_trans(skb, (struct net_device *)(pHcidevInfo->HCITransHdl.netDevice)); +#else + skb->dev = arDev->arNetDev; + if ((arDev->arNetDev->flags & IFF_UP) == IFF_UP) { + skb->protocol = eth_type_trans(skb, arDev->arNetDev); +#endif + A_NETIF_RX(skb); + skb = NULL; + } + + } while (FALSE); + + FreeHTCStruct(pHcidevInfo,pPacket); + + if (skb != NULL) { + /* packet was not accepted, free it */ + FreeBtOsBuf(pHcidevInfo,skb); + } + +} + +static void ar6000_hci_pkt_refill(void *pContext, HCI_TRANSPORT_PACKET_TYPE Type, int BuffersAvailable) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + int refillCount; + + if (Type == HCI_ACL_TYPE) { + refillCount = MAX_ACL_RECV_BUFS - BuffersAvailable; + } else { + refillCount = MAX_EVT_RECV_BUFS - BuffersAvailable; + } + + if (refillCount > 0) { + RefillRecvBuffers(pHcidevInfo,Type,refillCount); + } + +} + +static HCI_SEND_FULL_ACTION ar6000_hci_pkt_send_full(void *pContext, HTC_PACKET *pPacket) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)pContext; + HCI_SEND_FULL_ACTION action = HCI_SEND_FULL_KEEP; + + if (!pHcidevInfo->HciNormalMode) { + /* for epping testing, check packet tag, some epping packets are + * special and cannot be dropped */ + if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_DATA_PKT_TAG) { + action = HCI_SEND_FULL_DROP; + } + } + + return action; +} + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +A_STATUS ar6000_setup_hci(void *ar) +#else +A_STATUS ar6000_setup_hci(AR_SOFTC_T *ar) +#endif +{ + HCI_TRANSPORT_CONFIG_INFO config; + A_STATUS status = A_OK; + int i; + HTC_PACKET *pPacket; + AR6K_HCI_BRIDGE_INFO *pHcidevInfo; + + + do { + + pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)A_MALLOC(sizeof(AR6K_HCI_BRIDGE_INFO)); + + if (NULL == pHcidevInfo) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pHcidevInfo, sizeof(AR6K_HCI_BRIDGE_INFO)); +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + g_pHcidevInfo = pHcidevInfo; + pHcidevInfo->HCITransHdl = *(HCI_TRANSPORT_MISC_HANDLES *)ar; +#else + ar->hcidev_info = pHcidevInfo; + pHcidevInfo->ar = ar; +#endif + spin_lock_init(&pHcidevInfo->BridgeLock); + INIT_HTC_PACKET_QUEUE(&pHcidevInfo->HTCPacketStructHead); + + ar->exitCallback = AR3KConfigureExit; + + status = bt_setup_hci(pHcidevInfo); + if (A_FAILED(status)) { + break; + } + + if (pHcidevInfo->HciNormalMode) { + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE, ("HCI Bridge: running in normal mode... \n")); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE, ("HCI Bridge: running in test mode... \n")); + } + + pHcidevInfo->pHTCStructAlloc = (A_UINT8 *)A_MALLOC((sizeof(HTC_PACKET)) * NUM_HTC_PACKET_STRUCTS); + + if (NULL == pHcidevInfo->pHTCStructAlloc) { + status = A_NO_MEMORY; + break; + } + + pPacket = (HTC_PACKET *)pHcidevInfo->pHTCStructAlloc; + for (i = 0; i < NUM_HTC_PACKET_STRUCTS; i++,pPacket++) { + FreeHTCStruct(pHcidevInfo,pPacket); + } + + A_MEMZERO(&config,sizeof(HCI_TRANSPORT_CONFIG_INFO)); + config.ACLRecvBufferWaterMark = MAX_ACL_RECV_BUFS / 2; + config.EventRecvBufferWaterMark = MAX_EVT_RECV_BUFS / 2; + config.MaxSendQueueDepth = MAX_HCI_WRITE_QUEUE_DEPTH; + config.pContext = pHcidevInfo; + config.TransportFailure = ar6000_hci_transport_failure; + config.TransportReady = ar6000_hci_transport_ready; + config.TransportRemoved = ar6000_hci_transport_removed; + config.pHCISendComplete = ar6000_hci_send_complete; + config.pHCIPktRecv = ar6000_hci_pkt_recv; + config.pHCIPktRecvRefill = ar6000_hci_pkt_refill; + config.pHCISendFull = ar6000_hci_pkt_send_full; + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + pHcidevInfo->pHCIDev = HCI_TransportAttach(pHcidevInfo->HCITransHdl.htcHandle, &config); +#else + pHcidevInfo->pHCIDev = HCI_TransportAttach(ar->arHtcTarget, &config); +#endif + + if (NULL == pHcidevInfo->pHCIDev) { + status = A_ERROR; + } + + } while (FALSE); + + if (A_FAILED(status)) { + if (pHcidevInfo != NULL) { + if (NULL == pHcidevInfo->pHCIDev) { + /* GMBOX may not be present in older chips */ + /* just return success */ + status = A_OK; + } + } + ar6000_cleanup_hci(ar); + } + + return status; +} + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +void ar6000_cleanup_hci(void *ar) +#else +void ar6000_cleanup_hci(AR_SOFTC_T *ar) +#endif +{ +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = g_pHcidevInfo; +#else + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)ar->hcidev_info; +#endif + + if (pHcidevInfo != NULL) { + bt_cleanup_hci(pHcidevInfo); + + if (pHcidevInfo->pHCIDev != NULL) { + HCI_TransportStop(pHcidevInfo->pHCIDev); + HCI_TransportDetach(pHcidevInfo->pHCIDev); + pHcidevInfo->pHCIDev = NULL; + } + + if (pHcidevInfo->pHTCStructAlloc != NULL) { + A_FREE(pHcidevInfo->pHTCStructAlloc); + pHcidevInfo->pHTCStructAlloc = NULL; + } + + A_FREE(pHcidevInfo); +#ifndef EXPORT_HCI_BRIDGE_INTERFACE + ar->hcidev_info = NULL; + ar->exitCallback = NULL; +#endif + } + + +} + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +A_STATUS hci_test_send(void *ar, struct sk_buff *skb) +#else +A_STATUS hci_test_send(AR_SOFTC_T *ar, struct sk_buff *skb) +#endif +{ + int status = A_OK; + int length; + EPPING_HEADER *pHeader; + HTC_PACKET *pPacket; + HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG; +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = g_pHcidevInfo; +#else + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)ar->hcidev_info; +#endif + + do { + + if (NULL == pHcidevInfo) { + status = A_ERROR; + break; + } + + if (NULL == pHcidevInfo->pHCIDev) { + status = A_ERROR; + break; + } + + if (pHcidevInfo->HciNormalMode) { + /* this interface cannot run when normal WMI is running */ + status = A_ERROR; + break; + } + + pHeader = (EPPING_HEADER *)A_NETBUF_DATA(skb); + + if (!IS_EPPING_PACKET(pHeader)) { + status = A_EINVAL; + break; + } + + if (IS_EPING_PACKET_NO_DROP(pHeader)) { + htc_tag = AR6K_CONTROL_PKT_TAG; + } + + length = sizeof(EPPING_HEADER) + pHeader->DataLength; + + pPacket = AllocHTCStruct(pHcidevInfo); + if (NULL == pPacket) { + status = A_NO_MEMORY; + break; + } + + SET_HTC_PACKET_INFO_TX(pPacket, + skb, + A_NETBUF_DATA(skb), + length, + HCI_ACL_TYPE, /* send every thing out as ACL */ + htc_tag); + + HCI_TransportSendPkt(pHcidevInfo->pHCIDev,pPacket,FALSE); + pPacket = NULL; + + } while (FALSE); + + return status; +} + +void ar6000_set_default_ar3kconfig(AR_SOFTC_T *ar, void *ar3kconfig) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)ar->hcidev_info; + AR3K_CONFIG_INFO *config = (AR3K_CONFIG_INFO *)ar3kconfig; + + config->pHCIDev = pHcidevInfo->pHCIDev; + config->pHCIProps = &pHcidevInfo->HCIProps; + config->pHIFDevice = ar->arHifDevice; + config->pBtStackHCIDev = pHcidevInfo->pBtStackHCIDev; + config->Flags |= AR3K_CONFIG_FLAG_SET_AR3K_BAUD; + config->AR3KBaudRate = 115200; +} + +#ifdef CONFIG_BLUEZ_HCI_BRIDGE +/*** BT Stack Entrypoints *******/ + +/* + * bt_open - open a handle to the device +*/ +static int bt_open(struct hci_dev *hdev) +{ + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_open - enter - x\n")); + set_bit(HCI_RUNNING, &hdev->flags); + set_bit(HCI_UP, &hdev->flags); + set_bit(HCI_INIT, &hdev->flags); + return 0; +} + +/* + * bt_close - close handle to the device +*/ +static int bt_close(struct hci_dev *hdev) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_close - enter\n")); + clear_bit(HCI_RUNNING, &hdev->flags); + return 0; +} + +/* + * bt_send_frame - send data frames +*/ +static int bt_send_frame(struct sk_buff *skb) +{ + struct hci_dev *hdev = (struct hci_dev *)skb->dev; + HCI_TRANSPORT_PACKET_TYPE type; + AR6K_HCI_BRIDGE_INFO *pHcidevInfo; + HTC_PACKET *pPacket; + A_STATUS status = A_OK; + struct sk_buff *txSkb = NULL; + + if (!hdev) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("HCI Bridge: bt_send_frame - no device\n")); + return -ENODEV; + } + + if (!test_bit(HCI_RUNNING, &hdev->flags)) { + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_send_frame - not open\n")); + return -EBUSY; + } + + pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)hdev->driver_data; + A_ASSERT(pHcidevInfo != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_SEND, ("+bt_send_frame type: %d \n",bt_cb(skb)->pkt_type)); + type = HCI_COMMAND_TYPE; + + switch (bt_cb(skb)->pkt_type) { + case HCI_COMMAND_PKT: + type = HCI_COMMAND_TYPE; + hdev->stat.cmd_tx++; + break; + + case HCI_ACLDATA_PKT: + type = HCI_ACL_TYPE; + hdev->stat.acl_tx++; + break; + + case HCI_SCODATA_PKT: + /* we don't support SCO over the bridge */ + kfree_skb(skb); + return 0; + default: + A_ASSERT(FALSE); + kfree_skb(skb); + return 0; + } + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_HCI_DUMP)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,(">>> Send HCI %s packet len: %d\n", + (type == HCI_COMMAND_TYPE) ? "COMMAND" : "ACL", + skb->len)); + if (type == HCI_COMMAND_TYPE) { + A_UINT16 opcode = HCI_GET_OP_CODE(skb->data); + AR_DEBUG_PRINTF(ATH_DEBUG_ANY,(" HCI Command: OGF:0x%X OCF:0x%X \r\n", + opcode >> 10, opcode & 0x3FF)); + } + AR_DEBUG_PRINTBUF(skb->data,skb->len,"BT HCI SEND Packet Dump"); + } + + do { + + txSkb = bt_skb_alloc(TX_PACKET_RSV_OFFSET + pHcidevInfo->HCIProps.HeadRoom + + pHcidevInfo->HCIProps.TailRoom + skb->len, + GFP_ATOMIC); + + if (txSkb == NULL) { + status = A_NO_MEMORY; + break; + } + + bt_cb(txSkb)->pkt_type = bt_cb(skb)->pkt_type; + txSkb->dev = (void *)pHcidevInfo->pBtStackHCIDev; + skb_reserve(txSkb, TX_PACKET_RSV_OFFSET + pHcidevInfo->HCIProps.HeadRoom); + A_MEMCPY(txSkb->data, skb->data, skb->len); + skb_put(txSkb,skb->len); + + pPacket = AllocHTCStruct(pHcidevInfo); + if (NULL == pPacket) { + status = A_NO_MEMORY; + break; + } + + /* HCI packet length here doesn't include the 1-byte transport header which + * will be handled by the HCI transport layer. Enough headroom has already + * been reserved above for the transport header + */ + SET_HTC_PACKET_INFO_TX(pPacket, + txSkb, + txSkb->data, + txSkb->len, + type, + AR6K_CONTROL_PKT_TAG); /* HCI packets cannot be dropped */ + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_SEND, ("HCI Bridge: bt_send_frame skb:0x%lX \n",(unsigned long)txSkb)); + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_SEND, ("HCI Bridge: type:%d, Total Length:%d Bytes \n", + type, txSkb->len)); + + status = HCI_TransportSendPkt(pHcidevInfo->pHCIDev,pPacket,FALSE); + pPacket = NULL; + txSkb = NULL; + + } while (FALSE); + + if (txSkb != NULL) { + kfree_skb(txSkb); + } + + kfree_skb(skb); + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_SEND, ("-bt_send_frame \n")); + return 0; +} + +/* + * bt_ioctl - ioctl processing +*/ +static int bt_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_ioctl - enter\n")); + return -ENOIOCTLCMD; +} + +/* + * bt_flush - flush outstandingbpackets +*/ +static int bt_flush(struct hci_dev *hdev) +{ + AR6K_HCI_BRIDGE_INFO *pHcidevInfo; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_flush - enter\n")); + + pHcidevInfo = (AR6K_HCI_BRIDGE_INFO *)hdev->driver_data; + + /* TODO??? */ + + return 0; +} + + +/* + * bt_destruct - +*/ +static void bt_destruct(struct hci_dev *hdev) +{ + AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HCI Bridge: bt_destruct - enter\n")); + /* nothing to do here */ +} + +static A_STATUS bt_setup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + A_STATUS status = A_OK; + struct hci_dev *pHciDev = NULL; + HIF_DEVICE_OS_DEVICE_INFO osDevInfo; + + if (!setupbtdev) { + return A_OK; + } + + do { + + A_MEMZERO(&osDevInfo,sizeof(osDevInfo)); + /* get the underlying OS device */ +#ifdef EXPORT_HCI_BRIDGE_INTERFACE + status = ar6000_get_hif_dev((HIF_DEVICE *)(pHcidevInfo->HCITransHdl.hifDevice), + &osDevInfo); +#else + status = HIFConfigureDevice(pHcidevInfo->ar->arHifDevice, + HIF_DEVICE_GET_OS_DEVICE, + &osDevInfo, + sizeof(osDevInfo)); +#endif + + if (A_FAILED(status)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to OS device info from HIF\n")); + break; + } + + /* allocate a BT HCI struct for this device */ + pHciDev = hci_alloc_dev(); + if (NULL == pHciDev) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge - failed to allocate bt struct \n")); + status = A_NO_MEMORY; + break; + } + /* save the device, we'll register this later */ + pHcidevInfo->pBtStackHCIDev = pHciDev; + SET_HCIDEV_DEV(pHciDev,osDevInfo.pOSDevice); + SET_HCI_BUS_TYPE(pHciDev, HCI_VIRTUAL, HCI_BREDR); + pHciDev->driver_data = pHcidevInfo; + pHciDev->open = bt_open; + pHciDev->close = bt_close; + pHciDev->send = bt_send_frame; + pHciDev->ioctl = bt_ioctl; + pHciDev->flush = bt_flush; + pHciDev->destruct = bt_destruct; + pHciDev->owner = THIS_MODULE; + /* driver is running in normal BT mode */ + pHcidevInfo->HciNormalMode = TRUE; + + } while (FALSE); + + if (A_FAILED(status)) { + bt_cleanup_hci(pHcidevInfo); + } + + return status; +} + +static void bt_cleanup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + int err; + + if (pHcidevInfo->HciRegistered) { + pHcidevInfo->HciRegistered = FALSE; + clear_bit(HCI_RUNNING, &pHcidevInfo->pBtStackHCIDev->flags); + clear_bit(HCI_UP, &pHcidevInfo->pBtStackHCIDev->flags); + clear_bit(HCI_INIT, &pHcidevInfo->pBtStackHCIDev->flags); + A_ASSERT(pHcidevInfo->pBtStackHCIDev != NULL); + /* unregister */ + if ((err = hci_unregister_dev(pHcidevInfo->pBtStackHCIDev)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: failed to unregister with bluetooth %d\n",err)); + } + } + + if (pHcidevInfo->pBtStackHCIDev != NULL) { + kfree(pHcidevInfo->pBtStackHCIDev); + pHcidevInfo->pBtStackHCIDev = NULL; + } +} + +static A_STATUS bt_register_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + int err; + A_STATUS status = A_OK; + + do { + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE, ("HCI Bridge: registering HCI... \n")); + A_ASSERT(pHcidevInfo->pBtStackHCIDev != NULL); + /* mark that we are registered */ + pHcidevInfo->HciRegistered = TRUE; + if ((err = hci_register_dev(pHcidevInfo->pBtStackHCIDev)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: failed to register with bluetooth %d\n",err)); + pHcidevInfo->HciRegistered = FALSE; + status = A_ERROR; + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_BRIDGE, ("HCI Bridge: HCI registered \n")); + + } while (FALSE); + + return status; +} + +static A_BOOL bt_indicate_recv(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, + HCI_TRANSPORT_PACKET_TYPE Type, + struct sk_buff *skb) +{ + A_UINT8 btType; + int len; + A_BOOL success = FALSE; + BT_HCI_EVENT_HEADER *pEvent; + + do { + + if (!test_bit(HCI_RUNNING, &pHcidevInfo->pBtStackHCIDev->flags)) { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("HCI Bridge: bt_indicate_recv - not running\n")); + break; + } + + switch (Type) { + case HCI_ACL_TYPE: + btType = HCI_ACLDATA_PKT; + break; + case HCI_EVENT_TYPE: + btType = HCI_EVENT_PKT; + break; + default: + btType = 0; + A_ASSERT(FALSE); + break; + } + + if (0 == btType) { + break; + } + + /* set the final type */ + bt_cb(skb)->pkt_type = btType; + /* set dev */ + skb->dev = (void *)pHcidevInfo->pBtStackHCIDev; + len = skb->len; + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_HCI_RECV)) { + if (bt_cb(skb)->pkt_type == HCI_EVENT_PKT) { + pEvent = (BT_HCI_EVENT_HEADER *)skb->data; + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_RECV, ("BT HCI EventCode: %d, len:%d \n", + pEvent->EventCode, pEvent->ParamLength)); + } + } + + /* pass receive packet up the stack */ +#ifdef CONFIG_BT + if (hci_recv_frame(skb) != 0) { +#else + if (1) { +#endif + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HCI Bridge: hci_recv_frame failed \n")); + break; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_HCI_RECV, + ("HCI Bridge: Indicated RCV of type:%d, Length:%d \n",btType,len)); + } + + success = TRUE; + + } while (FALSE); + + return success; +} + +static struct sk_buff* bt_alloc_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, int Length) +{ + struct sk_buff *skb; + /* in normal HCI mode we need to alloc from the bt core APIs */ + skb = bt_skb_alloc(Length, GFP_ATOMIC); + if (NULL == skb) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to alloc bt sk_buff \n")); + } + return skb; +} + +static void bt_free_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, struct sk_buff *skb) +{ + kfree_skb(skb); +} + +#else // { CONFIG_BLUEZ_HCI_BRIDGE + + /* stubs when we only want to test the HCI bridging Interface without the HT stack */ +static A_STATUS bt_setup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + return A_OK; +} +static void bt_cleanup_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + +} +static A_STATUS bt_register_hci(AR6K_HCI_BRIDGE_INFO *pHcidevInfo) +{ + A_ASSERT(FALSE); + return A_ERROR; +} + +static A_BOOL bt_indicate_recv(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, + HCI_TRANSPORT_PACKET_TYPE Type, + struct sk_buff *skb) +{ + A_ASSERT(FALSE); + return FALSE; +} + +static struct sk_buff* bt_alloc_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, int Length) +{ + A_ASSERT(FALSE); + return NULL; +} +static void bt_free_buffer(AR6K_HCI_BRIDGE_INFO *pHcidevInfo, struct sk_buff *skb) +{ + A_ASSERT(FALSE); +} + +#endif // } CONFIG_BLUEZ_HCI_BRIDGE + +#else // { ATH_AR6K_ENABLE_GMBOX + + /* stubs when GMBOX support is not needed */ + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +A_STATUS ar6000_setup_hci(void *ar) +#else +A_STATUS ar6000_setup_hci(AR_SOFTC_T *ar) +#endif +{ + return A_OK; +} + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +void ar6000_cleanup_hci(void *ar) +#else +void ar6000_cleanup_hci(AR_SOFTC_T *ar) +#endif +{ + return; +} + +#ifndef EXPORT_HCI_BRIDGE_INTERFACE +void ar6000_set_default_ar3kconfig(AR_SOFTC_T *ar, void *ar3kconfig) +{ + return; +} +#endif + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +int hci_test_send(void *ar, struct sk_buff *skb) +#else +int hci_test_send(AR_SOFTC_T *ar, struct sk_buff *skb) +#endif +{ + return -EOPNOTSUPP; +} + +#endif // } ATH_AR6K_ENABLE_GMBOX + + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +static int __init +hcibridge_init_module(void) +{ + A_STATUS status; + HCI_TRANSPORT_CALLBACKS hciTransCallbacks; + + hciTransCallbacks.setupTransport = ar6000_setup_hci; + hciTransCallbacks.cleanupTransport = ar6000_cleanup_hci; + + status = ar6000_register_hci_transport(&hciTransCallbacks); + if(status != A_OK) + return -ENODEV; + + return 0; +} + +static void __exit +hcibridge_cleanup_module(void) +{ +} + +module_init(hcibridge_init_module); +module_exit(hcibridge_cleanup_module); +MODULE_LICENSE("GPL and additional rights"); +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/ar6000_drv.h b/drivers/net/wireless/ar6003/host/os/linux/include/ar6000_drv.h new file mode 100644 index 000000000000..762ff5fc7836 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/ar6000_drv.h @@ -0,0 +1,919 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _AR6000_H_ +#define _AR6000_H_ + +#include + + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) +#include +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#include +#else +#include +#endif +#include +#ifdef ATH6K_CONFIG_CFG80211 +#include +#endif /* ATH6K_CONFIG_CFG80211 */ +#include +#include + +#include +#include +#include "a_types.h" +#include "a_osapi.h" +#include "htc_api.h" +#include "wmi.h" +#include "a_drv.h" +#include "bmi.h" +#include +#include +#include +#include +#include "gpio_api.h" +#include "gpio.h" +#include "pkt_log.h" +#include "aggr_recv_api.h" +#include +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +#include +#else +#include +#include +#endif +#include "ar6000_api.h" +#ifdef CONFIG_HOST_TCMD_SUPPORT +#include +#endif +#include + +#include "targaddrs.h" +#include "dbglog_api.h" +#include "ar6000_diag.h" +#include "common_drv.h" +#include "roaming.h" +#include "hci_transport_api.h" +#define ATH_MODULE_NAME driver +#include "a_debug.h" + +#define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0) +#define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1) +#define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2) +#define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3) +#define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4) +#define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5) +#define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6) +#define ATH_DEBUG_HCI_RECV ATH_DEBUG_MAKE_MODULE_MASK(7) +#define ATH_DEBUG_HCI_SEND ATH_DEBUG_MAKE_MODULE_MASK(8) +#define ATH_DEBUG_HCI_DUMP ATH_DEBUG_MAKE_MODULE_MASK(9) + +#ifndef __dev_put +#define __dev_put(dev) dev_put(dev) +#endif + + + +#ifdef ATH6K_CONFIG_CFG80211 +#define NUM_SUBQUEUE 1 +#endif + +#ifdef USER_KEYS + +#define USER_SAVEDKEYS_STAT_INIT 0 +#define USER_SAVEDKEYS_STAT_RUN 1 + +// TODO this needs to move into the AR_SOFTC struct +struct USER_SAVEDKEYS { + struct ieee80211req_key ucast_ik; + struct ieee80211req_key bcast_ik; + CRYPTO_TYPE keyType; + A_BOOL keyOk; +}; +#endif + +#define DBG_INFO 0x00000001 +#define DBG_ERROR 0x00000002 +#define DBG_WARNING 0x00000004 +#define DBG_SDIO 0x00000008 +#define DBG_HIF 0x00000010 +#define DBG_HTC 0x00000020 +#define DBG_WMI 0x00000040 +#define DBG_WMI2 0x00000080 +#define DBG_DRIVER 0x00000100 + +#define DBG_DEFAULTS (DBG_ERROR|DBG_WARNING) + + +A_STATUS ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); +A_STATUS ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data); + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_AR6000 1 +#define AR6000_MAX_RX_BUFFERS 16 +#define AR6000_BUFFER_SIZE 1664 +#define AR6000_MAX_AMSDU_RX_BUFFERS 4 +#define AR6000_AMSDU_REFILL_THRESHOLD 3 +#define AR6000_AMSDU_BUFFER_SIZE (WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH + 128) +#define AR6000_MAX_RX_MESSAGE_SIZE (max(WMI_MAX_NORMAL_RX_DATA_FRAME_LENGTH,WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) + +#define AR6000_TX_TIMEOUT 10 +#define AR6000_ETH_ADDR_LEN 6 +#define AR6000_MAX_ENDPOINTS 4 +#define MAX_NODE_NUM 15 +/* MAX_HI_COOKIE_NUM are reserved for high priority traffic */ +#define MAX_DEF_COOKIE_NUM 150 +#define MAX_HI_COOKIE_NUM 15 /* 10% of MAX_COOKIE_NUM */ +#define MAX_COOKIE_NUM (MAX_DEF_COOKIE_NUM + MAX_HI_COOKIE_NUM) + +/* MAX_DEFAULT_SEND_QUEUE_DEPTH is used to set the default queue depth for the + * WMM send queues. If a queue exceeds this depth htc will query back to the + * OS specific layer by calling EpSendFull(). This gives the OS layer the + * opportunity to drop the packet if desired. Therefore changing + * MAX_DEFAULT_SEND_QUEUE_DEPTH does not affect resource utilization but + * does impact the threshold used to identify if a packet should be + * dropped. */ +// #define MAX_DEFAULT_SEND_QUEUE_DEPTH (MAX_DEF_COOKIE_NUM / WMM_NUM_AC) + +// Host Queue depth has been increased during performace chariot endpoint runs. Host may not pump +// as fast as host application expected, due to that panic/packet loss / chariot error happens +// adjusting queue depth size resolve this issue +#define MAX_DEFAULT_SEND_QUEUE_DEPTH 64 + +#define AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT 1 +#define AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT 1 +#define A_DISCONNECT_TIMER_INTERVAL 10 * 1000 +#define A_DEFAULT_LISTEN_INTERVAL 100 +#define A_DEFAULT_BMISS_TIME 1500 +#define A_MAX_WOW_LISTEN_INTERVAL 300 +#define A_MAX_WOW_BMISS_TIME 4500 + +enum { + DRV_HB_CHALLENGE = 0, + APP_HB_CHALLENGE +}; + +enum { + WLAN_INIT_MODE_NONE = 0, + WLAN_INIT_MODE_USR, + WLAN_INIT_MODE_UDEV, + WLAN_INIT_MODE_DRV +}; + +/* Suspend - configuration */ +enum { + WLAN_SUSPEND_CUT_PWR = 0, + WLAN_SUSPEND_DEEP_SLEEP, + WLAN_SUSPEND_WOW, + WLAN_SUSPEND_CUT_PWR_IF_BT_OFF +}; + +/* WiFi OFF - configuration */ +enum { + WLAN_OFF_CUT_PWR = 0, + WLAN_OFF_DEEP_SLEEP, +}; + +/* WLAN low power state */ +enum { + WLAN_POWER_STATE_ON = 0, + WLAN_POWER_STATE_CUT_PWR = 1, + WLAN_POWER_STATE_DEEP_SLEEP, + WLAN_POWER_STATE_WOW +}; + +/* WLAN WoW State */ +enum { + WLAN_WOW_STATE_NONE = 0, + WLAN_WOW_STATE_SUSPENDING, + WLAN_WOW_STATE_SUSPENDED +}; + + +typedef enum _AR6K_BIN_FILE { + AR6K_OTP_FILE, + AR6K_FIRMWARE_FILE, + AR6K_PATCH_FILE, + AR6K_BOARD_DATA_FILE, +} AR6K_BIN_FILE; + +#ifdef SETUPHCI_ENABLED +#define SETUPHCI_DEFAULT 1 +#else +#define SETUPHCI_DEFAULT 0 +#endif /* SETUPHCI_ENABLED */ + +#ifdef SETUPHCIPAL_ENABLED +#define SETUPHCIPAL_DEFAULT 1 +#else +#define SETUPHCIPAL_DEFAULT 0 +#endif /* SETUPHCIPAL_ENABLED */ + +#ifdef SETUPBTDEV_ENABLED +#define SETUPBTDEV_DEFAULT 1 +#else +#define SETUPBTDEV_DEFAULT 0 +#endif /* SETUPBTDEV_ENABLED */ + +#ifdef BMIENABLE_SET +#define BMIENABLE_DEFAULT 1 +#else +#define BMIENABLE_DEFAULT 0 +#endif /* BMIENABLE_SET */ + +#ifdef ENABLEUARTPRINT_SET +#define ENABLEUARTPRINT_DEFAULT 1 +#else +#define ENABLEUARTPRINT_DEFAULT 0 +#endif /* ENABLEARTPRINT_SET */ + +#ifdef ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER +#define NOHIFSCATTERSUPPORT_DEFAULT 1 +#else /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */ +#define NOHIFSCATTERSUPPORT_DEFAULT 0 +#endif /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */ + +#ifdef AR600x_BT_AR3001 +#define AR3KHCIBAUD_DEFAULT 3000000 +#define HCIUARTSCALE_DEFAULT 1 +#define HCIUARTSTEP_DEFAULT 8937 +#else +#define AR3KHCIBAUD_DEFAULT 0 +#define HCIUARTSCALE_DEFAULT 0 +#define HCIUARTSTEP_DEFAULT 0 +#endif /* AR600x_BT_AR3001 */ + +#ifdef INIT_MODE_DRV_ENABLED +#define WLAN_INIT_MODE_DEFAULT WLAN_INIT_MODE_DRV +#else +#define WLAN_INIT_MODE_DEFAULT WLAN_INIT_MODE_USR +#endif /* INIT_MODE_DRV_ENABLED */ + +#define AR6K_DATASET_PATCH_ADDRESS(_param, _ver) do { \ + if ((_ver) == AR6003_REV2_VERSION) { \ + (_param) = AR6003_REV2_DATASET_PATCH_ADDRESS; \ + } else if ((_ver) == AR6003_REV3_VERSION) { \ + (_param) = AR6003_REV3_DATASET_PATCH_ADDRESS; \ + } else { \ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ + A_ASSERT(0); \ + } \ +} while (0) + +#define AR6K_APP_LOAD_ADDRESS(_param, _ver) do { \ + if ((_ver) == AR6003_REV2_VERSION) { \ + (_param) = AR6003_REV2_APP_LOAD_ADDRESS; \ + } else if ((_ver) == AR6003_REV3_VERSION) { \ + (_param) = AR6003_REV3_APP_LOAD_ADDRESS; \ + } else { \ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ + A_ASSERT(0); \ + } \ +} while (0) + +#define AR6K_APP_START_OVERRIDE_ADDRESS(_param, _ver) do { \ + if ((_ver) == AR6003_REV2_VERSION) { \ + (_param) = AR6003_REV2_APP_START_OVERRIDE; \ + } else if ((_ver) == AR6003_REV3_VERSION) { \ + (_param) = AR6003_REV3_APP_START_OVERRIDE; \ + } else { \ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ + A_ASSERT(0); \ + } \ +} while (0) + +#define AR6003_SUBVER_DEFAULT 1 +#define AR6003_SUBVER_ROUTER 2 +#define AR6003_SUBVER_MOBILE 3 +#define AR6003_SUBVER_TABLET 4 + +/* AR6003 2.0 definitions */ +#define AR6003_REV2_VERSION 0x30000384 +#define AR6003_REV2_OTP_FILE "otp.bin.z77" +#define AR6003_REV2_FIRMWARE_FILE "athwlan.bin.z77" +#define AR6003_REV2_TCMD_FIRMWARE_FILE "athtcmd_ram.bin" +#define AR6003_REV2_TESTSCRIPT_FILE "testflow.bin" +#define AR6003_REV2_UTF_FIRMWARE_FILE "utf.bin" +#define AR6003_REV2_ART_FIRMWARE_FILE "device.bin" +#define AR6003_REV2_PATCH_FILE "data.patch.hw2_0.bin" +#define AR6003_REV2_EPPING_FIRMWARE_FILE "endpointping.bin" +#ifdef AR600x_SD31_XXX +#define AR6003_REV2_BOARD_DATA_FILE "bdata.SD31.bin" +#elif defined(AR600x_SD32_XXX) +#define AR6003_REV2_BOARD_DATA_FILE "bdata.SD32.bin" +#elif defined(AR600x_WB31_XXX) +#define AR6003_REV2_BOARD_DATA_FILE "bdata.WB31.bin" +#else +#define AR6003_REV2_BOARD_DATA_FILE "bdata.CUSTOM.bin" +#endif /* Board Data File */ + +/* AR6003 3.0 definitions */ +#define AR6003_REV3_VERSION 0x30000582 +#define AR6003_REV3_OTP_FILE "ath6k/AR6003/hw2.1.1/otp.bin" +#define AR6003_REV3_DEFAULT_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athwlan.bin" +#define AR6003_REV3_ROUTER_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athwlan_router.bin" +#define AR6003_REV3_MOBILE_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athwlan_mobile.bin" +#define AR6003_REV3_TABLET_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athwlan_tablet.bin" +#define AR6003_REV3_TCMD_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athtcmd_ram.bin" +#define AR6003_REV3_TESTSCRIPT_FILE "ath6k/AR6003/hw2.1.1/testflow.bin" +#define AR6003_REV3_UTF_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/utf.bin" +#define AR6003_REV3_ART_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/device.bin" +#define AR6003_REV3_PATCH_FILE "ath6k/AR6003/hw2.1.1/data.patch.hw3_0.bin" +#define AR6003_REV3_EPPING_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/endpointping.bin" +#ifdef AR600x_SD31_XXX +#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.SD31.bin" +#elif defined(AR600x_SD32_XXX) +#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.SD32.bin" +#elif defined(AR600x_WB31_XXX) +#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.WB31.bin" +#else +#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.CUSTOM.bin" +#endif /* Board Data File */ + +/* AP-STA Concurrency */ +#define GET_CONN_AP_PRIV(_ar,_priv) do { \ + int i; \ + AR_SOFTC_DEV_T *tDev =NULL; \ + for(i=0;i<_ar->arConfNumDev;i++) { \ + tDev = _ar->arDev[i]; \ + if((tDev->arNetworkType == AP_NETWORK) && \ + (tDev->arConnected)) { \ + _priv = tDev; \ + break; \ + } \ + } \ +}while(0); + +/* Power states */ +enum { + WLAN_PWR_CTRL_UP = 0, + WLAN_PWR_CTRL_CUT_PWR, + WLAN_PWR_CTRL_DEEP_SLEEP, + WLAN_PWR_CTRL_WOW, + WLAN_PWR_CTRL_DEEP_SLEEP_DISABLED +}; + +/* HTC RAW streams */ +typedef enum _HTC_RAW_STREAM_ID { + HTC_RAW_STREAM_NOT_MAPPED = -1, + HTC_RAW_STREAM_0 = 0, + HTC_RAW_STREAM_1 = 1, + HTC_RAW_STREAM_2 = 2, + HTC_RAW_STREAM_3 = 3, + HTC_RAW_STREAM_NUM_MAX +} HTC_RAW_STREAM_ID; + +#define RAW_HTC_READ_BUFFERS_NUM 4 +#define RAW_HTC_WRITE_BUFFERS_NUM 4 + +#define HTC_RAW_BUFFER_SIZE 1664 + +typedef struct { + int currPtr; + int length; + A_UINT8 _Pad1[A_CACHE_LINE_PAD]; + unsigned char data[HTC_RAW_BUFFER_SIZE]; + A_UINT8 _Pad2[A_CACHE_LINE_PAD]; + HTC_PACKET HTCPacket; +} raw_htc_buffer; + +#ifdef CONFIG_HOST_TCMD_SUPPORT +/* + * add TCMD_MODE besides wmi and bypasswmi + * in TCMD_MODE, only few TCMD releated wmi commands + * counld be hanlder + */ +enum { + AR6000_WMI_MODE = 0, + AR6000_BYPASS_MODE, + AR6000_TCMD_MODE, + AR6000_WLAN_MODE +}; +#endif /* CONFIG_HOST_TCMD_SUPPORT */ + +struct ar_wep_key { + A_UINT8 arKeyIndex; + A_UINT8 arKeyLen; + A_UINT8 arKey[64]; +} ; + +#ifdef ATH6K_CONFIG_CFG80211 +struct ar_key { + A_UINT8 key[WLAN_MAX_KEY_LEN]; + A_UINT8 key_len; + A_UINT8 seq[IW_ENCODE_SEQ_MAX_SIZE]; + A_UINT8 seq_len; + A_UINT32 cipher; +}; +#endif /* ATH6K_CONFIG_CFG80211 */ + + +struct ar_node_mapping { + A_UINT8 macAddress[6]; + A_UINT8 epId; + A_UINT8 txPending; +}; + +struct ar_cookie { + unsigned long arc_bp[2]; /* Must be first field */ + HTC_PACKET HtcPkt; /* HTC packet wrapper */ + struct ar_cookie *arc_list_next; +}; + +struct ar_hb_chlng_resp { + A_TIMER timer; + A_UINT32 frequency; + A_UINT32 seqNum; + A_BOOL outstanding; + A_UINT8 missCnt; + A_UINT8 missThres; +}; + +/* Per STA data, used in AP mode */ +/*TODO: All this should move to OS independent dir */ + +#define STA_PWR_MGMT_MASK 0x1 +#define STA_PWR_MGMT_SHIFT 0x0 +#define STA_PWR_MGMT_AWAKE 0x0 +#define STA_PWR_MGMT_SLEEP 0x1 + +#define STA_SET_PWR_SLEEP(sta) (sta->flags |= (STA_PWR_MGMT_MASK << STA_PWR_MGMT_SHIFT)) +#define STA_CLR_PWR_SLEEP(sta) (sta->flags &= ~(STA_PWR_MGMT_MASK << STA_PWR_MGMT_SHIFT)) +#define STA_IS_PWR_SLEEP(sta) ((sta->flags >> STA_PWR_MGMT_SHIFT) & STA_PWR_MGMT_MASK) + +#define STA_PS_POLLED_MASK 0x1 +#define STA_PS_POLLED_SHIFT 0x1 + +#define STA_SET_PS_POLLED(sta) (sta->flags |= (STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT)) +#define STA_CLR_PS_POLLED(sta) (sta->flags &= ~(STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT)) +#define STA_IS_PS_POLLED(sta) (sta->flags & (STA_PS_POLLED_MASK << STA_PS_POLLED_SHIFT)) + +#define STA_APSD_TRIGGER_MASK 0x1 +#define STA_APSD_TRIGGER_SHIFT 0x2 +#define STA_APSD_EOSP_MASK 0x1 +#define STA_APSD_EOSP_SHIFT 0x3 + +#define STA_SET_APSD_TRIGGER(sta) (sta->flags |= (STA_APSD_TRIGGER_MASK << STA_APSD_TRIGGER_SHIFT)) +#define STA_CLR_APSD_TRIGGER(sta) (sta->flags &= ~(STA_APSD_TRIGGER_MASK << STA_APSD_TRIGGER_SHIFT)) +#define STA_IS_APSD_TRIGGER(sta) (sta->flags & (STA_APSD_TRIGGER_MASK << STA_APSD_TRIGGER_SHIFT)) + +#define STA_SET_APSD_EOSP(sta) (sta->flags |= (STA_APSD_EOSP_MASK << STA_APSD_EOSP_SHIFT)) +#define STA_CLR_APSD_EOSP(sta) (sta->flags &= ~(STA_APSD_EOSP_MASK << STA_APSD_EOSP_SHIFT)) +#define STA_IS_APSD_EOSP(sta) (sta->flags & (STA_APSD_EOSP_MASK << STA_APSD_EOSP_SHIFT)) + +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL +#define APTC_TRAFFIC_SAMPLING_INTERVAL 100 /* msec */ +#define APTC_UPPER_THROUGHPUT_THRESHOLD 3000 /* Kbps */ +#define APTC_LOWER_THROUGHPUT_THRESHOLD 2000 /* Kbps */ + + +typedef struct aptc_traffic_record { + A_BOOL timerScheduled; + struct timeval samplingTS; + unsigned long bytesReceived; + unsigned long bytesTransmitted; +} APTC_TRAFFIC_RECORD; + +#endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ + +typedef struct user_rssi_compensation_t { + A_UINT16 customerID; + union { + A_UINT16 a_enable; + A_UINT16 bg_enable; + A_UINT16 enable; + }; + A_INT16 bg_param_a; + A_INT16 bg_param_b; + A_INT16 a_param_a; + A_INT16 a_param_b; + A_UINT32 reserved; +} USER_RSSI_CPENSATION; + + + +typedef struct { + A_UINT16 flags; + A_UINT8 mac[ATH_MAC_LEN]; + A_UINT8 aid; + A_UINT8 keymgmt; + A_UINT8 ucipher; + A_UINT8 auth; + A_UINT8 wmode; + A_UINT8 wpa_ie[IEEE80211_MAX_IE]; + A_UINT8 apsd_info; + A_NETBUF_QUEUE_T psq; /* power save q */ + A_NETBUF_QUEUE_T apsdq; /* APSD delivery enabled q */ + A_MUTEX_T psqLock; + A_UINT8 ba_state[8]; + void *conn_aggr; + void *arPriv; +} conn_t; + +typedef struct ar6_raw_htc { + HTC_ENDPOINT_ID arRaw2EpMapping[HTC_RAW_STREAM_NUM_MAX]; + HTC_RAW_STREAM_ID arEp2RawMapping[ENDPOINT_MAX]; + struct semaphore raw_htc_read_sem[HTC_RAW_STREAM_NUM_MAX]; + struct semaphore raw_htc_write_sem[HTC_RAW_STREAM_NUM_MAX]; + wait_queue_head_t raw_htc_read_queue[HTC_RAW_STREAM_NUM_MAX]; + wait_queue_head_t raw_htc_write_queue[HTC_RAW_STREAM_NUM_MAX]; + raw_htc_buffer raw_htc_read_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_READ_BUFFERS_NUM]; + raw_htc_buffer raw_htc_write_buffer[HTC_RAW_STREAM_NUM_MAX][RAW_HTC_WRITE_BUFFERS_NUM]; + A_BOOL write_buffer_available[HTC_RAW_STREAM_NUM_MAX]; + A_BOOL read_buffer_available[HTC_RAW_STREAM_NUM_MAX]; +} AR_RAW_HTC_T; + +#ifdef CONFIG_HOST_TCMD_SUPPORT +typedef struct { + A_UINT16 len; + A_UINT8 ver; + A_UINT8 reserved; + A_UINT8 buf[TC_CMDS_SIZE_MAX]; +} AR_TCMD_RESP; +#endif /* CONFIG_HOST_TCMD_SUPPORT */ + +typedef struct ar6_softc { + spinlock_t arLock; + struct semaphore arSem; + A_BOOL arWmiReady; + int arTxPending[ENDPOINT_MAX]; + int arTotalTxDataPending; + A_UINT8 arNumDataEndPts; + HTC_HANDLE arHtcTarget; + void *arHifDevice; + struct ar6000_version arVersion; + A_UINT32 arTargetType; + AR6000_WLAN_STATE arWlanState; + struct ar_cookie *arCookieList; + A_UINT32 arCookieCount; + struct ar_hb_chlng_resp arHBChallengeResp; + HTC_ENDPOINT_ID arAc2EpMapping[WMM_NUM_AC]; + A_BOOL arAcStreamActive[WMM_NUM_AC]; + A_UINT8 arAcStreamPriMap[WMM_NUM_AC]; + A_UINT8 arHiAcStreamActivePri; + A_UINT8 arEp2AcMapping[ENDPOINT_MAX]; + HTC_ENDPOINT_ID arControlEp; +#ifdef HTC_RAW_INTERFACE + AR_RAW_HTC_T *arRawHtc; +#endif + A_BOOL arRawIfInit; + COMMON_CREDIT_STATE_INFO arCreditStateInfo; + A_BOOL arWMIControlEpFull; + A_BOOL dbgLogFetchInProgress; + A_UCHAR log_buffer[DBGLOG_HOST_LOG_BUFFER_SIZE]; + A_UINT32 log_cnt; + A_UINT32 dbglog_init_done; + HTC_PACKET_QUEUE amsdu_rx_buffer_queue; + A_BOOL bIsDestroyProgress; /* flag to indicate ar6k destroy is in progress */ + A_UINT8 rxMetaVersion; + A_INT32 (*exitCallback)(void *config); /* generic callback at AR6K exit */ + HIF_DEVICE_OS_DEVICE_INFO osDevInfo; + A_UINT16 arWlanPowerState; + A_BOOL arPlatPowerOff; + USER_RSSI_CPENSATION rssi_compensation_param; +#ifdef CONFIG_HOST_TCMD_SUPPORT + A_UINT8 tcmdRxReport; + A_UINT32 tcmdRxTotalPkt; + A_INT32 tcmdRxRssi; + A_UINT32 tcmdPm; + A_UINT32 arTargetMode; + A_UINT32 tcmdRxcrcErrPkt; + A_UINT32 tcmdRxsecErrPkt; + A_UINT16 tcmdRateCnt[TCMD_MAX_RATES]; + A_UINT16 tcmdRateCntShortGuard[TCMD_MAX_RATES]; + AR_TCMD_RESP tcmdResp; +#endif + A_BOOL arWlanOff; +#if CONFIG_PM + A_UINT16 arWowState; + A_BOOL arBTOff; + A_BOOL arBTSharing; + A_UINT16 arSuspendCutPwrConfig; + A_UINT16 arSuspendConfig; + A_UINT16 arWlanOffConfig; + A_UINT16 arWow2Config; +#endif +#ifndef EXPORT_HCI_BRIDGE_INTERFACE + void *hcidev_info; +#endif + conn_t connTbl[NUM_CONN]; /* AP mode */ + WMI_PER_STA_STAT arAPStats[NUM_CONN]; /* AP mode */ + A_UINT8 inter_bss; /* enable/disable inter bss data forward */ + A_UINT8 arAcsDisableHiChannel; + /* AP-STA Concurrency */ + A_UINT8 arConfNumDev; + A_UINT8 arHoldConnection; + A_TIMER ap_reconnect_timer; + A_UINT8 gNumSta; + /* AP-STA Concurrency */ + struct ar6_softc_dev *arDev[NUM_DEV]; + A_BOOL arResumeDone; + /* Bluetooth Address to be read from OTP */ + A_UINT8 bdaddr[6]; +} AR_SOFTC_T; + +typedef struct ar6_softc_ap { + WMI_AP_ACL g_acl; /* AP mode */ + A_UINT8 sta_list_index; /* AP mode */ + struct ieee80211req_key ap_mode_bkey; /* AP mode */ + A_NETBUF_QUEUE_T mcastpsq; /* power save q for Mcast frames */ + A_MUTEX_T mcastpsqLock; + A_BOOL DTIMExpired; /* flag to indicate DTIM expired */ + A_UINT8 intra_bss; /* enable/disable intra bss data forward */ + A_UINT8 ap_hidden_ssid; + A_UINT8 ap_country_code[3]; + A_UINT8 ap_dtim_period; + A_UINT16 ap_beacon_interval; + A_UINT16 arRTS; + void *pDfs; /* Pointer to DFS state structure */ + A_BOOL deKeySet; +}AR_SOFTC_AP_T; + +typedef struct ar6_softc_sta { + A_BOOL arConnectPending; + A_UINT8 arReqBssid[ATH_MAC_LEN]; + A_UINT16 arListenIntervalB; + A_UINT16 arListenIntervalT; + A_UINT16 arBmissTimeB; + A_UINT16 arBmissTimeT; + A_INT8 arRssi; + A_UINT8 arSkipScan; + A_UINT16 arBeaconInterval; + A_UINT8 arKeepaliveConfigured; + A_UINT8 arIbssPsEnable; + A_UINT32 arMgmtFilter; + struct ar_node_mapping arNodeMap[MAX_NODE_NUM]; + A_UINT8 arNodeNum; + A_UINT8 arNexEpId; + A_UINT32 arConnectCtrlFlags; +#ifdef USER_KEYS + A_INT32 user_savedkeys_stat; + A_UINT32 user_key_ctrl; + struct USER_SAVEDKEYS user_saved_keys; +#endif + USER_RSSI_THOLD rssi_map[12]; + A_TIMER disconnect_timer; + A_UINT8 arUserBssFilter; + A_INT8 arNumChannels; + A_UINT16 arChannelList[WMI_MAX_CHANNELS]; + A_UINT8 scan_triggered; + WMI_SCAN_PARAMS_CMD scParams; + A_UINT8 scanSpecificSsid; + A_BOOL wpaOffloadEnabled; + A_BOOL disconnect_timer_inited; +}AR_SOFTC_STA_T; + +typedef struct ar6_softc_dev { + struct net_device *arNetDev; /* net_device pointer */ + void *arWmi; + A_BOOL arWmiEnabled; + wait_queue_head_t arEvent; + spinlock_t arPrivLock; + A_INT8 arMaxRetries; + A_BOOL statsUpdatePending; + A_UINT8 arPhyCapability; + A_UINT16 arChannelHint; + A_UINT16 arBssChannel; + A_BOOL arConnected; + int arSsidLen; + u_char arSsid[WMI_MAX_SSID_LEN]; + A_UINT8 arNextMode; + A_UINT8 arNetworkType; + A_UINT8 arNetworkSubType; + A_UINT8 arDot11AuthMode; + A_UINT8 arAuthMode; + A_UINT8 arPairwiseCrypto; + A_UINT8 arPairwiseCryptoLen; + A_UINT8 arGroupCrypto; + A_UINT8 arGroupCryptoLen; + A_UINT8 arDefTxKeyIndex; + struct ar_wep_key arWepKeyList[WMI_MAX_KEY_INDEX + 1]; + A_UINT8 arBssid[ATH_MAC_LEN]; + A_UINT8 arTxPwr; + A_BOOL arTxPwrSet; + A_INT32 arBitRate; + struct net_device_stats arNetStats; + struct iw_statistics arIwStats; + A_UINT32 arRateMask[WMI_MAX_RATE_MASK]; + A_BOOL arNetQueueStopped; + A_UINT8 arDeviceIndex; + A_BOOL arWmmEnabled; + A_UINT32 arRegCode; + A_UINT16 ap_profile_flag; /* AP mode */ + WMI_BTCOEX_CONFIG_EVENT arBtcoexConfig; + WMI_BTCOEX_STATS_EVENT arBtcoexStats; + WMI_GET_WAC_INFO wacInfo; +#define AR_MCAST_FILTER_MAC_ADDR_SIZE 6 + A_UINT8 mcast_filters[MAC_MAX_FILTERS_PER_LIST][AR_MCAST_FILTER_MAC_ADDR_SIZE]; + A_UINT8 bdaddr[ATH_MAC_LEN]; +#ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL + APTC_TRAFFIC_RECORD aptcTR; +#endif +#ifdef ATH6K_CONFIG_CFG80211 + struct wireless_dev *wdev; + struct cfg80211_scan_request *scan_request; + struct ar_key keys[WMI_MAX_KEY_INDEX + 1]; +#endif /* ATH6K_CONFIG_CFG80211 */ + A_TIMER ap_acs_timer; + TARGET_STATS arTargetStats; + void *conn_aggr; + void *p2p_ctx; + AR_SOFTC_AP_T arAp; + AR_SOFTC_STA_T arSta; + AR_SOFTC_T *arSoftc; + A_UINT8 arHoldConnection; + A_BOOL arDoConnectOnResume; + A_UINT8 num_sta; + void *hcipal_info; + A_BOOL isBt30amp; + A_UINT8 phymode; +}AR_SOFTC_DEV_T; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +/* Looks like we need this for 2.4 kernels */ +static inline void *ar6k_priv(struct net_device *dev) +{ + return(dev->priv); +} +#else +#ifdef ATH6K_CONFIG_CFG80211 +static inline void *ar6k_priv(struct net_device *dev) +{ + return (wdev_priv(dev->ieee80211_ptr)); +} +#else +#define ar6k_priv netdev_priv +#endif /* ATH6K_CONFIG_CFG80211 */ +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#define SET_HCI_BUS_TYPE(pHciDev, __bus, __type) do { \ + (pHciDev)->type = (__bus); \ +} while(0) +#else +#define SET_HCI_BUS_TYPE(pHciDev, __bus, __type) do { \ + (pHciDev)->bus = (__bus); \ + (pHciDev)->dev_type = (__type); \ +} while(0) +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) +#define GET_INODE_FROM_FILEP(filp) \ + (filp)->f_path.dentry->d_inode +#else +#define GET_INODE_FROM_FILEP(filp) \ + (filp)->f_dentry->d_inode +#endif + +#define arAc2EndpointID(ar,ac) (ar)->arAc2EpMapping[(ac)] +#define arSetAc2EndpointIDMap(ar,ac,ep) \ +{ (ar)->arAc2EpMapping[(ac)] = (ep); \ + (ar)->arEp2AcMapping[(ep)] = (ac); } +#define arEndpoint2Ac(ar,ep) (ar)->arEp2AcMapping[(ep)] + +#define arRawIfEnabled(ar) (ar)->arRawIfInit +#define arRawStream2EndpointID(ar,raw) (ar)->arRawHtc->arRaw2EpMapping[(raw)] +#define arSetRawStream2EndpointIDMap(ar,raw,ep) \ +{ (ar)->arRawHtc->arRaw2EpMapping[(raw)] = (ep); \ + (ar)->arRawHtc->arEp2RawMapping[(ep)] = (raw); } +#define arEndpoint2RawStreamID(ar,ep) (ar)->arRawHtc->arEp2RawMapping[(ep)] + +struct ar_giwscan_param { + char *current_ev; + char *end_buf; + A_UINT32 bytes_needed; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + struct iw_request_info *info; +#endif +}; + +#define AR6000_STAT_INC(ar, stat) (ar->arNetStats.stat++) + +#define AR6000_SPIN_LOCK(lock, param) do { \ + if (irqs_disabled()) { \ + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("IRQs disabled:AR6000_LOCK\n")); \ + } \ + spin_lock_bh(lock); \ +} while (0) + +#define AR6000_SPIN_UNLOCK(lock, param) do { \ + if (irqs_disabled()) { \ + AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("IRQs disabled: AR6000_UNLOCK\n")); \ + } \ + spin_unlock_bh(lock); \ +} while (0) + +int ar6000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); +int ar6000_ioctl_dispatcher(struct net_device *dev, struct ifreq *rq, int cmd); +void ar6000_gpio_init(void); +void ar6000_init_profile_info(AR_SOFTC_DEV_T *arPriv); +void ar6000_install_static_wep_keys(AR_SOFTC_DEV_T *arPriv); +int ar6000_init(struct net_device *dev); +int ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar); +void ar6000_TxDataCleanup(AR_SOFTC_T *ar); +int ar6000_acl_data_tx(struct sk_buff *skb, AR_SOFTC_DEV_T *arPriv); +void ar6000_restart_endpoint(AR_SOFTC_T *ar); +void ar6000_stop_endpoint(AR_SOFTC_T *ar, A_BOOL keepprofile, A_BOOL getdbglogs); + +#ifdef HTC_RAW_INTERFACE + +#ifndef __user +#define __user +#endif + +int ar6000_htc_raw_open(AR_SOFTC_T *ar); +int ar6000_htc_raw_close(AR_SOFTC_T *ar); +ssize_t ar6000_htc_raw_read(AR_SOFTC_T *ar, + HTC_RAW_STREAM_ID StreamID, + char __user *buffer, size_t count); +ssize_t ar6000_htc_raw_write(AR_SOFTC_T *ar, + HTC_RAW_STREAM_ID StreamID, + char __user *buffer, size_t count); + +#endif /* HTC_RAW_INTERFACE */ + +/* AP mode */ +/*TODO: These routines should be moved to a file that is common across OS */ +conn_t * +ieee80211_find_conn(AR_SOFTC_DEV_T *arPriv, A_UINT8 *node_addr); + +conn_t * +ieee80211_find_conn_for_aid(AR_SOFTC_DEV_T *arPriv, A_UINT8 aid); + +A_UINT8 +remove_sta(AR_SOFTC_DEV_T *arPriv, A_UINT8 *mac, A_UINT16 reason); + +void +ar6000_ap_cleanup(AR_SOFTC_DEV_T *arPriv); + +int +ar6000_ap_set_num_sta(AR_SOFTC_T *ar, AR_SOFTC_DEV_T *arPriv, A_UINT8 num_sta); + +/* HCI support */ + +#ifndef EXPORT_HCI_BRIDGE_INTERFACE +A_STATUS ar6000_setup_hci(AR_SOFTC_T *ar); +void ar6000_cleanup_hci(AR_SOFTC_T *ar); +void ar6000_set_default_ar3kconfig(AR_SOFTC_T *ar, void *ar3kconfig); + +/* HCI bridge testing */ +A_STATUS hci_test_send(AR_SOFTC_T *ar, struct sk_buff *skb); +#endif +void ar6000_init_mode_info(AR_SOFTC_DEV_T *arPriv); +ATH_DEBUG_DECLARE_EXTERN(htc); +ATH_DEBUG_DECLARE_EXTERN(wmi); +ATH_DEBUG_DECLARE_EXTERN(bmi); +ATH_DEBUG_DECLARE_EXTERN(hif); +ATH_DEBUG_DECLARE_EXTERN(wlan); +ATH_DEBUG_DECLARE_EXTERN(misc); + +extern A_UINT8 bcast_mac[]; +extern A_UINT8 null_mac[]; + +#ifdef __cplusplus +} +#endif + +#endif /* _AR6000_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/ar6k_pal.h b/drivers/net/wireless/ar6003/host/os/linux/include/ar6k_pal.h new file mode 100644 index 000000000000..98eb1db224be --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/ar6k_pal.h @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// The software source and binaries included in this development package are +// licensed, not sold. You, or your company, received the package under one +// or more license agreements. The rights granted to you are specifically +// listed in these license agreement(s). All other rights remain with Atheros +// Communications, Inc., its subsidiaries, or the respective owner including +// those listed on the included copyright notices. Distribution of any +// portion of this package must be in strict compliance with the license +// agreement(s) terms. +// +// +// +// PAL driver for AR6003 +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HCI_PAL_H_ +#define _HCI_PAL_H_ +#define HCI_GET_OP_CODE(p) (((A_UINT16)((p)[1])) << 8) | ((A_UINT16)((p)[0])) +#define TX_PACKET_RSV_OFFSET 32 +/* pal specific config structure */ +typedef A_BOOL (*ar6k_pal_recv_pkt_t)(void *pHciPalInfo, void *skb); +typedef struct ar6k_pal_config_s +{ + ar6k_pal_recv_pkt_t fpar6k_pal_recv_pkt; +}ar6k_pal_config_t; + +/********************************** + * HCI PAL private info structure + *********************************/ +typedef struct ar6k_hci_pal_info_s{ + + unsigned long ulFlags; +#define HCI_NORMAL_MODE (1) +#define HCI_REGISTERED (1<<1) + struct hci_dev *hdev; /* BT Stack HCI dev */ + AR_SOFTC_DEV_T *ar; + +}ar6k_hci_pal_info_t; + +void register_pal_cb(ar6k_pal_config_t *palConfig_p); +#endif /* _HCI_PAL_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/ar6xapi_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/ar6xapi_linux.h new file mode 100644 index 000000000000..c682f3ca7456 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/ar6xapi_linux.h @@ -0,0 +1,244 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _AR6XAPI_LINUX_H +#define _AR6XAPI_LINUX_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ar6_softc; +struct ar6_softc_dev; + +void ar6000_dfs_attach_event(struct ar6_softc_dev *arPriv, WMI_DFS_HOST_ATTACH_EVENT *capinfo); +void ar6000_dfs_init_event(struct ar6_softc_dev *arPriv, WMI_DFS_HOST_INIT_EVENT *info); +void ar6000_dfs_reset_delaylines_event(struct ar6_softc_dev *arPriv); +void ar6000_dfs_reset_radarq_event(struct ar6_softc_dev *arPriv); +void ar6000_dfs_reset_ar_event(struct ar6_softc_dev *arPriv); +void ar6000_dfs_reset_arq_event(struct ar6_softc_dev *arPriv); +void ar6000_dfs_set_dur_multiplier_event(struct ar6_softc_dev *arPriv, A_UINT32 value); +void ar6000_dfs_set_debuglevel_event(struct ar6_softc_dev *arPriv, A_UINT32 value); +void ar6000_dfs_set_bangradar_event(struct ar6_softc_dev *arPriv, A_UINT32 value); +A_STATUS ar6000_dfs_set_maxpulsedur_cmd(struct ar6_softc_dev *arPriv, A_UINT32 value); +A_STATUS ar6000_dfs_radar_detected_cmd(struct ar6_softc_dev *arPriv, A_INT16 chan_index, A_INT8 bang_radar); +A_STATUS ar6000_dfs_set_minrssithresh_cmd(struct ar6_softc_dev *arPriv, A_INT32 rssi); +void ar6000_dfs_phyerr_event(struct ar6_softc_dev *arPriv, WMI_DFS_PHYERR_EVENT *info); + +void ar6000_ready_event(void *devt, A_UINT8 *datap, A_UINT8 phyCap, + A_UINT32 sw_ver, A_UINT32 abi_ver); +A_STATUS ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid); +void ar6000_connect_event(struct ar6_softc_dev *arPriv, WMI_CONNECT_EVENT *pEvt); +void ar6000_disconnect_event(struct ar6_softc_dev *arPriv, A_UINT8 reason, + A_UINT8 *bssid, A_UINT8 assocRespLen, + A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus); +void ar6000_tkip_micerr_event(struct ar6_softc_dev *arPriv, A_UINT8 keyid, + A_BOOL ismcast); +void ar6000_bitrate_rx(void *devt, A_INT32 rateKbps); +void ar6000_channelList_rx(void *devt, A_INT8 numChan, A_UINT16 *chanList); +void ar6000_regDomain_event(struct ar6_softc_dev *arPriv, A_UINT32 regCode); +void ar6000_txPwr_rx(void *devt, A_UINT8 txPwr); +void ar6000_keepalive_rx(void *devt, A_UINT8 configured); +void ar6000_neighborReport_event(struct ar6_softc_dev *arPriv, int numAps, + WMI_NEIGHBOR_INFO *info); +void ar6000_set_numdataendpts(struct ar6_softc_dev *arPriv, A_UINT32 num); +void ar6000_scanComplete_event(struct ar6_softc_dev *arPriv, A_STATUS status); +void ar6000_targetStats_event(struct ar6_softc_dev *arPriv, A_UINT8 *ptr, A_UINT32 len); +void ar6000_rssiThreshold_event(struct ar6_softc_dev *arPriv, + WMI_RSSI_THRESHOLD_VAL newThreshold, + A_INT16 rssi); +void ar6000_reportError_event(struct ar6_softc_dev *, WMI_TARGET_ERROR_VAL errorVal); +void ar6000_cac_event(struct ar6_softc_dev *arPriv, A_UINT8 ac, A_UINT8 cac_indication, + A_UINT8 statusCode, A_UINT8 *tspecSuggestion); +void ar6000_channel_change_event(struct ar6_softc_dev *arPriv, A_UINT16 oldChannel, A_UINT16 newChannel); +void ar6000_hbChallengeResp_event(struct ar6_softc_dev *arPriv, A_UINT32 cookie, A_UINT32 source); +void +ar6000_roam_tbl_event(struct ar6_softc_dev *arPriv, WMI_TARGET_ROAM_TBL *pTbl); + +void +ar6000_roam_data_event(struct ar6_softc_dev *arPriv, WMI_TARGET_ROAM_DATA *p); + +void +ar6000_wow_list_event(struct ar6_softc_dev *ar, A_UINT8 num_filters, + WMI_GET_WOW_LIST_REPLY *wow_reply); + +void ar6000_pmkid_list_event(void *devt, A_UINT8 numPMKID, + WMI_PMKID *pmkidList, A_UINT8 *bssidList); + +void ar6000_gpio_intr_rx(struct ar6_softc_dev *arPriv, A_UINT32 intr_mask, A_UINT32 input_values); +void ar6000_gpio_data_rx(struct ar6_softc_dev *arPriv, A_UINT32 reg_id, A_UINT32 value); +void ar6000_gpio_ack_rx(struct ar6_softc_dev *arPriv); + +A_INT32 rssi_compensation_calc_tcmd(struct ar6_softc *ar, A_UINT32 freq, A_INT32 rssi, A_UINT32 totalPkt); +A_INT16 rssi_compensation_calc(struct ar6_softc_dev *arPriv, A_INT16 rssi); +A_INT16 rssi_compensation_reverse_calc(struct ar6_softc_dev *arPriv, A_INT16 rssi, A_BOOL Above); + +void ar6000_dbglog_init_done(struct ar6_softc_dev *arPriv); + +void ar6000_wacinfo_event(struct ar6_softc_dev *ar, A_UINT8 *ptr, A_UINT32 len); + +#ifdef SEND_EVENT_TO_APP +void ar6000_send_event_to_app(struct ar6_softc_dev *arPriv, A_UINT16 eventId, A_UINT8 *datap, int len); +void ar6000_send_generic_event_to_app(struct ar6_softc_dev *arPriv, A_UINT16 eventId, A_UINT8 *datap, int len); +#endif + +#ifdef CONFIG_HOST_TCMD_SUPPORT +void ar6000_tcmd_rx_report_event(struct ar6_softc_dev *arPriv, A_UINT8 * results, int len); +#endif + +void ar6000_tx_retry_err_event(void *devt); + +void ar6000_snrThresholdEvent_rx(void *devt, + WMI_SNR_THRESHOLD_VAL newThreshold, + A_UINT8 snr); + +void ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL range, A_UINT8 lqVal); + + +void ar6000_ratemask_rx(void *devt, A_UINT32 *ratemask); + +A_STATUS ar6000_get_driver_cfg(struct net_device *dev, + A_UINT16 cfgParam, + void *result); +void ar6000_bssInfo_event_rx(struct ar6_softc_dev *arPriv, A_UINT8 *data, int len); + +void ar6000_dbglog_event(struct ar6_softc_dev *arPriv, A_UINT32 dropped, + A_INT8 *buffer, A_UINT32 length); + +int ar6000_dbglog_get_debug_logs(struct ar6_softc *ar); + +void ar6000_peer_event(void *devt, A_UINT8 eventCode, A_UINT8 *bssid); + +void ar6000_indicate_tx_activity(void *devt, A_UINT8 trafficClass, A_BOOL Active); +HTC_ENDPOINT_ID ar6000_ac2_endpoint_id ( void * devt, A_UINT8 ac); +A_UINT8 ar6000_endpoint_id2_ac (void * devt, HTC_ENDPOINT_ID ep ); + +void ar6000_btcoex_config_event(struct ar6_softc_dev *arPriv, A_UINT8 *ptr, A_UINT32 len); + +void ar6000_btcoex_stats_event(struct ar6_softc_dev *arPriv, A_UINT8 *ptr, A_UINT32 len) ; + +void ar6000_dset_open_req(void *devt, + A_UINT32 id, + A_UINT32 targ_handle, + A_UINT32 targ_reply_fn, + A_UINT32 targ_reply_arg); +void ar6000_dset_close(void *devt, A_UINT32 access_cookie); +void ar6000_dset_data_req(void *devt, + A_UINT32 access_cookie, + A_UINT32 offset, + A_UINT32 length, + A_UINT32 targ_buf, + A_UINT32 targ_reply_fn, + A_UINT32 targ_reply_arg); + + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +void prof_count_rx(unsigned int addr, unsigned int count); +#endif + +A_UINT32 ar6000_getnodeAge (void); + +A_UINT32 ar6000_getclkfreq (void); + +int ar6000_ap_mode_profile_commit(struct ar6_softc_dev *arPriv); + +struct ieee80211req_wpaie; +A_STATUS +ar6000_ap_mode_get_wpa_ie(struct ar6_softc_dev *arPriv, struct ieee80211req_wpaie *wpaie); + +A_STATUS is_iwioctl_allowed(A_UINT8 mode, A_UINT16 cmd); + +A_STATUS is_xioctl_allowed(A_UINT8 mode, A_UINT8 submode, int cmd); + +void ar6000_pspoll_event(struct ar6_softc_dev *arPriv,A_UINT8 aid); + +void ar6000_dtimexpiry_event(struct ar6_softc_dev *arPriv); + +void ar6000_aggr_rcv_addba_req_evt(struct ar6_softc_dev *arPriv, WMI_ADDBA_REQ_EVENT *cmd); +void ar6000_aggr_rcv_addba_resp_evt(struct ar6_softc_dev *arPriv, WMI_ADDBA_RESP_EVENT *cmd); +void ar6000_aggr_rcv_delba_req_evt(struct ar6_softc_dev *arPriv, WMI_DELBA_EVENT *cmd); +void ar6000_hci_event_rcv_evt(struct ar6_softc_dev *arPriv, WMI_HCI_EVENT *cmd); + +#ifdef WAPI_ENABLE +int ap_set_wapi_key(struct ar6_softc_dev *arPriv, void *ik); +void ap_wapi_rekey_event(struct ar6_softc_dev *arPriv, A_UINT8 type, A_UINT8 *mac); +#endif + +#ifdef P2P +void ar6000_p2pdev_event(struct ar6_softc_dev *arPriv, const A_UINT8 *addr, + const A_UINT8 *dev_addr, + const A_UINT8 *pri_dev_type, const A_UINT8 *dev_name, + A_UINT8 dev_name_len, A_UINT16 config_methods, + A_UINT8 dev_capab, A_UINT8 grp_capab); +void p2p_go_neg_event(struct ar6_softc_dev *arPriv, A_UINT8 *res, A_UINT8 len); +void p2p_go_neg_req_event(struct ar6_softc_dev *arPriv, const A_UINT8 *sa, A_UINT16 dev_passwd_id); +void p2p_invite_sent_result_event(struct ar6_softc_dev *arPriv, A_UINT8 *res, + A_UINT8 len); +void p2p_invite_rcvd_result_event(struct ar6_softc_dev *arPriv, A_UINT8 *res, + A_UINT8 len); +void ar6000_p2p_prov_disc_req_event(struct ar6_softc_dev *arPriv, + const A_UINT8 *peer, A_UINT16 wps_config_method, + const A_UINT8 *dev_addr, const A_UINT8 *pri_dev_type, + const A_UINT8 *dev_name, A_UINT8 dev_name_len, + A_UINT16 supp_config_methods, A_UINT8 dev_capab, A_UINT8 group_capab); +void ar6000_p2p_prov_disc_resp_event(struct ar6_softc_dev *arPriv, + A_UINT8 *peer, A_UINT16 config_methods); +void *get_p2p_ctx(struct ar6_softc_dev *arPriv); +void *get_wmi_ctx(struct ar6_softc_dev *arPriv); +NETWORK_SUBTYPE get_network_subtype(struct ar6_softc_dev *arPriv); +void ar6000_p2p_sd_rx_event(struct ar6_softc_dev *arPriv, WMI_P2P_SDPD_RX_EVENT *ev); +#endif + +A_STATUS ar6000_connect_to_ap(struct ar6_softc_dev *arPriv); +A_STATUS ar6000_disconnect(struct ar6_softc_dev *arPriv); +A_STATUS ar6000_update_wlan_pwr_state(struct ar6_softc *ar, AR6000_WLAN_STATE state, A_BOOL suspending); + +A_STATUS ar6000_set_wlan_state(struct ar6_softc *ar, AR6000_WLAN_STATE state); +A_STATUS ar6000_set_bt_hw_state(struct ar6_softc *ar, A_UINT32 state); + +#ifdef CONFIG_PM +A_STATUS ar6000_suspend_ev(void *context); +A_STATUS ar6000_resume_ev(void *context); +A_STATUS ar6000_power_change_ev(void *context, A_UINT32 config); +void ar6000_check_wow_status(struct ar6_softc *ar, struct sk_buff *skb, A_BOOL isEvent); +#endif + +void ar6000_pm_init(void); +void ar6000_pm_exit(void); + +void ar6000_indicate_proberesp(struct ar6_softc_dev *arPriv , A_UINT8* pData , A_UINT16 len ,A_UINT8* bssid); +void ar6000_indicate_beacon(struct ar6_softc_dev *arPriv , A_UINT8* pData , A_UINT16 len ,A_UINT8* bssid); +void ar6000_assoc_req_report_event (void *context, A_UINT8 status, A_UINT8 rspType, A_UINT8* pData, int len); + +void ar6000_get_device_addr(struct ar6_softc_dev *arPriv, A_UINT8 *addr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/athdrv_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/athdrv_linux.h new file mode 100644 index 000000000000..1e20d6727b84 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/athdrv_linux.h @@ -0,0 +1,1470 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _ATHDRV_LINUX_H +#define _ATHDRV_LINUX_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * There are two types of ioctl's here: Standard ioctls and + * eXtended ioctls. All extended ioctls (XIOCTL) are multiplexed + * off of the single ioctl command, AR6000_IOCTL_EXTENDED. The + * arguments for every XIOCTL starts with a 32-bit command word + * that is used to select which extended ioctl is in use. After + * the command word are command-specific arguments. + */ + +/* Linux standard Wireless Extensions, private ioctl interfaces */ +#define IEEE80211_IOCTL_SETPARAM (SIOCIWFIRSTPRIV+0) +#define IEEE80211_IOCTL_SETKEY (SIOCIWFIRSTPRIV+1) +#define IEEE80211_IOCTL_DELKEY (SIOCIWFIRSTPRIV+2) +#define IEEE80211_IOCTL_SETMLME (SIOCIWFIRSTPRIV+3) +#define IEEE80211_IOCTL_ADDPMKID (SIOCIWFIRSTPRIV+4) +#define IEEE80211_IOCTL_SETOPTIE (SIOCIWFIRSTPRIV+5) +//#define IEEE80211_IOCTL_GETPARAM (SIOCIWFIRSTPRIV+6) +//#define IEEE80211_IOCTL_SETWMMPARAMS (SIOCIWFIRSTPRIV+7) +//#define IEEE80211_IOCTL_GETWMMPARAMS (SIOCIWFIRSTPRIV+8) +//#define IEEE80211_IOCTL_GETOPTIE (SIOCIWFIRSTPRIV+9) +//#define IEEE80211_IOCTL_SETAUTHALG (SIOCIWFIRSTPRIV+10) +#define IEEE80211_IOCTL_LASTONE (SIOCIWFIRSTPRIV+10) + + + +/* ====WMI Ioctls==== */ +/* + * + * Many ioctls simply provide WMI services to application code: + * an application makes such an ioctl call with a set of arguments + * that are packaged into the corresponding WMI message, and sent + * to the Target. + */ + +#define AR6000_IOCTL_WMI_GETREV (SIOCIWFIRSTPRIV+11) +/* + * arguments: + * ar6000_version *revision + */ + +#define AR6000_IOCTL_WMI_SETPWR (SIOCIWFIRSTPRIV+12) +/* + * arguments: + * WMI_POWER_MODE_CMD pwrModeCmd (see include/wmi.h) + * uses: WMI_SET_POWER_MODE_CMDID + */ + +#define AR6000_IOCTL_WMI_SETSCAN (SIOCIWFIRSTPRIV+13) +/* + * arguments: + * WMI_SCAN_PARAMS_CMD scanParams (see include/wmi.h) + * uses: WMI_SET_SCAN_PARAMS_CMDID + */ + +#define AR6000_IOCTL_WMI_SETLISTENINT (SIOCIWFIRSTPRIV+14) +/* + * arguments: + * UINT32 listenInterval + * uses: WMI_SET_LISTEN_INT_CMDID + */ + +#define AR6000_IOCTL_WMI_SETBSSFILTER (SIOCIWFIRSTPRIV+15) +/* + * arguments: + * WMI_BSS_FILTER filter (see include/wmi.h) + * uses: WMI_SET_BSS_FILTER_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_CHANNELPARAMS (SIOCIWFIRSTPRIV+16) +/* + * arguments: + * WMI_CHANNEL_PARAMS_CMD chParams + * uses: WMI_SET_CHANNEL_PARAMS_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_PROBEDSSID (SIOCIWFIRSTPRIV+17) +/* + * arguments: + * WMI_PROBED_SSID_CMD probedSsids (see include/wmi.h) + * uses: WMI_SETPROBED_SSID_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_PMPARAMS (SIOCIWFIRSTPRIV+18) +/* + * arguments: + * WMI_POWER_PARAMS_CMD powerParams (see include/wmi.h) + * uses: WMI_SET_POWER_PARAMS_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_BADAP (SIOCIWFIRSTPRIV+19) +/* + * arguments: + * WMI_ADD_BAD_AP_CMD badAPs (see include/wmi.h) + * uses: WMI_ADD_BAD_AP_CMDID + */ + +#define AR6000_IOCTL_WMI_GET_QOS_QUEUE (SIOCIWFIRSTPRIV+20) +/* + * arguments: + * ar6000_queuereq queueRequest (see below) + */ + +#define AR6000_IOCTL_WMI_CREATE_QOS (SIOCIWFIRSTPRIV+21) +/* + * arguments: + * WMI_CREATE_PSTREAM createPstreamCmd (see include/wmi.h) + * uses: WMI_CREATE_PSTREAM_CMDID + */ + +#define AR6000_IOCTL_WMI_DELETE_QOS (SIOCIWFIRSTPRIV+22) +/* + * arguments: + * WMI_DELETE_PSTREAM_CMD deletePstreamCmd (see include/wmi.h) + * uses: WMI_DELETE_PSTREAM_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_SNRTHRESHOLD (SIOCIWFIRSTPRIV+23) +/* + * arguments: + * WMI_SNR_THRESHOLD_PARAMS_CMD thresholdParams (see include/wmi.h) + * uses: WMI_SNR_THRESHOLD_PARAMS_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_ERROR_REPORT_BITMASK (SIOCIWFIRSTPRIV+24) +/* + * arguments: + * WMI_TARGET_ERROR_REPORT_BITMASK errorReportBitMask (see include/wmi.h) + * uses: WMI_TARGET_ERROR_REPORT_BITMASK_CMDID + */ + +#define AR6000_IOCTL_WMI_GET_TARGET_STATS (SIOCIWFIRSTPRIV+25) +/* + * arguments: + * TARGET_STATS *targetStats (see below) + * uses: WMI_GET_STATISTICS_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_ASSOC_INFO (SIOCIWFIRSTPRIV+26) +/* + * arguments: + * WMI_SET_ASSOC_INFO_CMD setAssocInfoCmd + * uses: WMI_SET_ASSOC_INFO_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_ACCESS_PARAMS (SIOCIWFIRSTPRIV+27) +/* + * arguments: + * WMI_SET_ACCESS_PARAMS_CMD setAccessParams (see include/wmi.h) + * uses: WMI_SET_ACCESS_PARAMS_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_BMISS_TIME (SIOCIWFIRSTPRIV+28) +/* + * arguments: + * UINT32 beaconMissTime + * uses: WMI_SET_BMISS_TIME_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_DISC_TIMEOUT (SIOCIWFIRSTPRIV+29) +/* + * arguments: + * WMI_DISC_TIMEOUT_CMD disconnectTimeoutCmd (see include/wmi.h) + * uses: WMI_SET_DISC_TIMEOUT_CMDID + */ + +#define AR6000_IOCTL_WMI_SET_IBSS_PM_CAPS (SIOCIWFIRSTPRIV+30) +/* + * arguments: + * WMI_IBSS_PM_CAPS_CMD ibssPowerMgmtCapsCmd + * uses: WMI_SET_IBSS_PM_CAPS_CMDID + */ + +/* + * There is a very small space available for driver-private + * wireless ioctls. In order to circumvent this limitation, + * we multiplex a bunch of ioctls (XIOCTLs) on top of a + * single AR6000_IOCTL_EXTENDED ioctl. + */ +#define AR6000_IOCTL_EXTENDED (SIOCIWFIRSTPRIV+31) + +typedef enum { + AR6000_XIOCTL_BMI_DONE = 1, + AR6000_XIOCTL_BMI_READ_MEMORY, + AR6000_XIOCTL_BMI_WRITE_MEMORY, + AR6000_XIOCTL_BMI_EXECUTE, + AR6000_XIOCTL_BMI_SET_APP_START, + AR6000_XIOCTL_BMI_READ_SOC_REGISTER, + AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER, + AR6000_XIOCTL_BMI_TEST, + AR6000_XIOCTL_UNUSED9, + AR6000_XIOCTL_UNUSED10, /* 10 */ + AR6000_XIOCTL_UNUSED11, + AR6000_XIOCTL_FORCE_TARGET_RESET, + AR6000_XIOCTL_HTC_RAW_OPEN, + AR6000_XIOCTL_HTC_RAW_CLOSE, + AR6000_XIOCTL_HTC_RAW_READ, + AR6000_XIOCTL_HTC_RAW_WRITE, + AR6000_XIOCTL_CHECK_TARGET_READY, + AR6000_XIOCTL_GPIO_OUTPUT_SET, + AR6000_XIOCTL_GPIO_INPUT_GET, + AR6000_XIOCTL_GPIO_REGISTER_SET, /* 20 */ + AR6000_XIOCTL_GPIO_REGISTER_GET, + AR6000_XIOCTL_GPIO_INTR_ACK, + AR6000_XIOCTL_GPIO_INTR_WAIT, + AR6000_XIOCTL_SET_ADHOC_BSSID, + AR6000_XIOCTL_UNUSED25, + AR6000_XIOCTL_UNUSED26, + AR6000_XIOCTL_SET_BEACON_INTVAL, + IEEE80211_IOCTL_SETAUTHALG, + AR6000_XIOCTL_SET_VOICE_PKT_SIZE, + AR6000_XIOCTL_SET_MAX_SP, /* 30 */ + AR6000_XIOCTL_WMI_GET_ROAM_TBL, + AR6000_XIOCTL_WMI_SET_ROAM_CTRL, + AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS, + AR6000_XIOCTRL_WMI_GET_POWER_MODE, + AR6000_XIOCTRL_WMI_SET_WLAN_STATE, + AR6000_XIOCTL_WMI_GET_ROAM_DATA, + AR6000_XIOCTL_WMI_SETRETRYLIMITS, + AR6000_XIOCTL_TCMD_CONT_TX, + AR6000_XIOCTL_TCMD_CONT_RX, + AR6000_XIOCTL_TCMD_PM, /* 40 */ + AR6000_XIOCTL_WMI_STARTSCAN, + AR6000_XIOCTL_WMI_SETFIXRATES, + AR6000_XIOCTL_WMI_GETFIXRATES, + AR6000_XIOCTL_WMI_SET_RSSITHRESHOLD, + AR6000_XIOCTL_WMI_CLR_RSSISNR, + AR6000_XIOCTL_WMI_SET_LQTHRESHOLD, + AR6000_XIOCTL_WMI_SET_RTS, + AR6000_XIOCTL_WMI_SET_LPREAMBLE, + AR6000_XIOCTL_WMI_SET_AUTHMODE, + AR6000_XIOCTL_WMI_SET_REASSOCMODE, /* 50 */ + AR6000_XIOCTL_WMI_SET_WMM, + AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS, + AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP, + AR6000_XIOCTL_WMI_GET_RD, + AR6000_XIOCTL_DIAG_READ, + AR6000_XIOCTL_DIAG_WRITE, + AR6000_XIOCTL_WMI_SET_TXOP, + AR6000_XIOCTL_USER_SETKEYS, + AR6000_XIOCTL_WMI_SET_KEEPALIVE, + AR6000_XIOCTL_WMI_GET_KEEPALIVE, /* 60 */ + AR6000_XIOCTL_BMI_ROMPATCH_INSTALL, + AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL, + AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE, + AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE, + AR6000_XIOCTL_WMI_SET_APPIE, + AR6000_XIOCTL_WMI_SET_MGMT_FRM_RX_FILTER, + AR6000_XIOCTL_DBGLOG_CFG_MODULE, + AR6000_XIOCTL_DBGLOG_GET_DEBUG_LOGS, + AR6000_XIOCTL_WMI_SET_WSC_STATUS = 70, /* 70 */ + AR6000_XIOCTL_WMI_SET_BT_STATUS, + AR6000_XIOCTL_WMI_SET_BT_PARAMS, + AR6000_XIOCTL_WMI_SET_HOST_SLEEP_MODE, + AR6000_XIOCTL_WMI_SET_WOW_MODE, + AR6000_XIOCTL_WMI_GET_WOW_LIST, + AR6000_XIOCTL_WMI_ADD_WOW_PATTERN, + AR6000_XIOCTL_WMI_DEL_WOW_PATTERN, + AR6000_XIOCTL_TARGET_INFO, + AR6000_XIOCTL_DUMP_HTC_CREDIT_STATE, + AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE, /* 80 */ + AR6000_XIOCTL_WMI_SET_CONNECT_CTRL_FLAGS, + AR6000_XIOCTL_WMI_SET_AKMP_PARAMS, + AR6000_XIOCTL_WMI_GET_PMKID_LIST, + AR6000_XIOCTL_WMI_SET_PMKID_LIST, + AR6000_XIOCTL_WMI_SET_PARAMS, + AR6000_XIOCTL_WMI_SET_MCAST_FILTER, + AR6000_XIOCTL_WMI_DEL_MCAST_FILTER, + AR6000_XIOCTL_UNUSED90 = 90, /* 90 */ + AR6000_XIOCTL_BMI_LZ_STREAM_START, + AR6000_XIOCTL_BMI_LZ_DATA, + AR6000_XIOCTL_PROF_CFG, + AR6000_XIOCTL_PROF_ADDR_SET, + AR6000_XIOCTL_PROF_START, + AR6000_XIOCTL_PROF_STOP, + AR6000_XIOCTL_PROF_COUNT_GET, + AR6000_XIOCTL_WMI_ABORT_SCAN, + AR6000_XIOCTL_AP_GET_STA_LIST, + AR6000_XIOCTL_AP_HIDDEN_SSID, /* 100 */ + AR6000_XIOCTL_AP_SET_NUM_STA, + AR6000_XIOCTL_AP_SET_ACL_MAC, + AR6000_XIOCTL_AP_GET_ACL_LIST, + AR6000_XIOCTL_AP_COMMIT_CONFIG, + IEEE80211_IOCTL_GETWPAIE, + AR6000_XIOCTL_AP_CONN_INACT_TIME, + AR6000_XIOCTL_AP_PROT_SCAN_TIME, + AR6000_XIOCTL_AP_SET_COUNTRY, + AR6000_XIOCTL_AP_SET_DTIM, + AR6000_XIOCTL_WMI_TARGET_EVENT_REPORT, /* 110 */ + AR6000_XIOCTL_SET_IP, + AR6000_XIOCTL_AP_SET_ACL_POLICY, + AR6000_XIOCTL_AP_CTRL_BSS_COMM, + AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO, + AR6000_XIOCTL_MODULE_DEBUG_SET_MASK, + AR6000_XIOCTL_MODULE_DEBUG_GET_MASK, + AR6000_XIOCTL_DUMP_RCV_AGGR_STATS, + AR6000_XIOCTL_SET_HT_CAP, + AR6000_XIOCTL_SET_HT_OP, + AR6000_XIOCTL_AP_GET_STAT, /* 120 */ + AR6000_XIOCTL_SET_TX_SELECT_RATES, + AR6000_XIOCTL_SETUP_AGGR, + AR6000_XIOCTL_ALLOW_AGGR, + AR6000_XIOCTL_AP_GET_HIDDEN_SSID, + AR6000_XIOCTL_AP_GET_COUNTRY, + AR6000_XIOCTL_AP_GET_WMODE, + AR6000_XIOCTL_AP_GET_DTIM, + AR6000_XIOCTL_AP_GET_BINTVL, + AR6000_XIOCTL_AP_GET_RTS, + AR6000_XIOCTL_DELE_AGGR, /* 130 */ + AR6000_XIOCTL_FETCH_TARGET_REGS, + AR6000_XIOCTL_HCI_CMD, + AR6000_XIOCTL_ACL_DATA, + AR6000_XIOCTL_WLAN_CONN_PRECEDENCE, + AR6000_XIOCTL_AP_SET_11BG_RATESET, + AR6000_XIOCTL_WMI_SET_AP_PS, + AR6000_XIOCTL_WMI_MCAST_FILTER, + AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT, + AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV, + AR6000_XIOCTL_WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG, /* 140 */ + AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG, + AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG, + AR6000_XIOCTL_WMI_SET_BTCOEX_ACLCOEX_CONFIG, + AR6000_XIOCTL_WMI_SET_BTCOEX_DEBUG, + AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS, + AR6000_XIOCTL_WMI_GET_BTCOEX_CONFIG, + AR6000_XIOCTL_WMI_GET_BTCOEX_STATS, + AR6000_XIOCTL_WMI_SET_QOS_SUPP, + AR6000_XIOCTL_AP_SET_DFS, + AR6000_XIOCTL_WMI_P2P_DISCOVER, /* 150 */ + AR6000_XIOCTL_WMI_P2P_STOP_FIND, + AR6000_XIOCTL_WMI_P2P_CANCEL, + AR6000_XIOCTL_WMI_P2P_LISTEN, + AR6000_XIOCTL_WMI_P2P_GO_NEG, + AR6000_XIOCTL_WMI_P2P_AUTH_GO_NEG, + AR6000_XIOCTL_WMI_P2P_REJECT, + AR6000_XIOCTL_WMI_P2P_CONFIG, + AR6000_XIOCTL_WMI_WPS_CONFIG, + AR6000_XIOCTL_WMI_P2P_FINDNODE, + AR6000_XIOCTL_WMI_P2P_GRP_INIT, /* 160 */ + AR6000_XIOCTL_WMI_P2P_GRP_FORMATION_DONE, + AR6000_XIOCTL_WMI_P2P_INVITE, + AR6000_XIOCTL_WMI_P2P_PROV_DISC, + AR6000_XIOCTL_WMI_P2P_SET, + AR6000_XIOCTL_WMI_P2P_PEER, + AR6000_XIOCTL_WMI_P2P_FLUSH, + AR6000_XIOCTL_WMI_GET_GO_PARAMS, + AR6000_XIOCTL_WMI_P2P_AUTH_INVITE, + AR6000_XIOCTL_WMI_P2P_GET_IF_ADDR, + AR6000_XIOCTL_WMI_P2P_GET_DEV_ADDR, /* 170 */ + AR6000_XIOCTL_WMI_P2P_SDPD_TX_CMD, + AR6000_XIOTCL_WMI_P2P_SD_CANCEL_REQUEST, + AR6000_XIOCTL_SET_BT_HW_POWER_STATE, + AR6000_XIOCTL_GET_BT_HW_POWER_STATE, + AR6000_XIOCTL_GET_WLAN_SLEEP_STATE, + AR6000_XIOCTL_WMI_SET_TX_SGI_PARAM, + AR6000_XIOCTL_WMI_ENABLE_WAC_PARAM, + AR6000_XIOCTL_WAC_SCAN_REPLY, + AR6000_XIOCTL_WMI_WAC_CTRL_REQ, + AR6000_XIOCTL_WMI_SET_WPA_OFFLOAD_STATE, /* 180 */ + AR6000_XIOCTL_WMI_SET_PASSPHRASE, + AR6000_XIOCTL_BMI_NVRAM_PROCESS, + AR6000_XIOCTL_WMI_SET_DIVERSITY_PARAM, + AR6000_XIOCTL_WMI_FORCE_ASSERT, + AR6000_XIOCTL_WMI_ENABLE_PKTLOG, + AR6000_XIOCTL_WMI_DISABLE_PKTLOG, + AR6000_XIOCTL_WMI_GET_PKTLOG, + AR6000_XIOCTL_AP_ACS_DISABLE_HI_CHANNELS, + AR6000_XIOCTL_TCMD_CMDS, + AR6000_XIOCTL_WMI_SET_EXCESS_TX_RETRY_THRES, /* 190 */ + AR6000_XIOCTL_AP_GET_NUM_STA, + AR6000_XIOCTL_SUSPEND_DRIVER, + AR6000_XIOCTL_RESUME_DRIVER, + AR6000_XIOCTL_GET_SUBMODE, + AR6000_XIOCTL_WMI_AP_SET_APSD, + AR6000_XIOCTL_TCMD_SETREG, + AR6000_XIOCTL_GET_HT_CAP, + AR6000_XIOCTL_WMI_GET_P2P_IE, /* 198 */ +} XTND_IOCLTS; + + + +///* ====BMI Extended Ioctls==== */ +// +//#define AR6000_XIOCTL_BMI_DONE 1 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_DONE) +// * uses: BMI_DONE +// */ +// +//#define AR6000_XIOCTL_BMI_READ_MEMORY 2 +///* +// * arguments: +// * union { +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_READ_MEMORY) +// * UINT32 address +// * UINT32 length +// * } +// * char results[length] +// * } +// * uses: BMI_READ_MEMORY +// */ +// +//#define AR6000_XIOCTL_BMI_WRITE_MEMORY 3 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_WRITE_MEMORY) +// * UINT32 address +// * UINT32 length +// * char data[length] +// * uses: BMI_WRITE_MEMORY +// */ +// +//#define AR6000_XIOCTL_BMI_EXECUTE 4 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_EXECUTE) +// * UINT32 TargetAddress +// * UINT32 parameter +// * uses: BMI_EXECUTE +// */ +// +//#define AR6000_XIOCTL_BMI_SET_APP_START 5 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_SET_APP_START) +// * UINT32 TargetAddress +// * uses: BMI_SET_APP_START +// */ +// +//#define AR6000_XIOCTL_BMI_READ_SOC_REGISTER 6 +///* +// * arguments: +// * union { +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_READ_SOC_REGISTER) +// * UINT32 TargetAddress, 32-bit aligned +// * } +// * UINT32 result +// * } +// * uses: BMI_READ_SOC_REGISTER +// */ +// +//#define AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER 7 +///* +// * arguments: +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER) +// * UINT32 TargetAddress, 32-bit aligned +// * UINT32 newValue +// * } +// * uses: BMI_WRITE_SOC_REGISTER +// */ +// +//#define AR6000_XIOCTL_BMI_TEST 8 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_TEST) +// * UINT32 address +// * UINT32 length +// * UINT32 count +// */ +// +// +// +///* Historical Host-side DataSet support */ +//#define AR6000_XIOCTL_UNUSED9 9 +//#define AR6000_XIOCTL_UNUSED10 10 +//#define AR6000_XIOCTL_UNUSED11 11 +// +///* ====Misc Extended Ioctls==== */ +// +//#define AR6000_XIOCTL_FORCE_TARGET_RESET 12 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_FORCE_TARGET_RESET) +// */ +// +// +//#ifdef HTC_RAW_INTERFACE +///* HTC Raw Interface Ioctls */ +//#define AR6000_XIOCTL_HTC_RAW_OPEN 13 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_HTC_RAW_OPEN) +// */ +// +//#define AR6000_XIOCTL_HTC_RAW_CLOSE 14 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_HTC_RAW_CLOSE) +// */ +// +//#define AR6000_XIOCTL_HTC_RAW_READ 15 +///* +// * arguments: +// * union { +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_HTC_RAW_READ) +// * UINT32 mailboxID +// * UINT32 length +// * } +// * results[length] +// * } +// */ +// +//#define AR6000_XIOCTL_HTC_RAW_WRITE 16 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_HTC_RAW_WRITE) +// * UINT32 mailboxID +// * UINT32 length +// * char buffer[length] +// */ +//#endif /* HTC_RAW_INTERFACE */ +// +//#define AR6000_XIOCTL_CHECK_TARGET_READY 17 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_CHECK_TARGET_READY) +// */ +// +// +// +///* ====GPIO (General Purpose I/O) Extended Ioctls==== */ +// +//#define AR6000_XIOCTL_GPIO_OUTPUT_SET 18 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_OUTPUT_SET) +// * ar6000_gpio_output_set_cmd_s (see below) +// * uses: WMIX_GPIO_OUTPUT_SET_CMDID +// */ +// +//#define AR6000_XIOCTL_GPIO_INPUT_GET 19 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_INPUT_GET) +// * uses: WMIX_GPIO_INPUT_GET_CMDID +// */ +// +//#define AR6000_XIOCTL_GPIO_REGISTER_SET 20 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_REGISTER_SET) +// * ar6000_gpio_register_cmd_s (see below) +// * uses: WMIX_GPIO_REGISTER_SET_CMDID +// */ +// +//#define AR6000_XIOCTL_GPIO_REGISTER_GET 21 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_REGISTER_GET) +// * ar6000_gpio_register_cmd_s (see below) +// * uses: WMIX_GPIO_REGISTER_GET_CMDID +// */ +// +//#define AR6000_XIOCTL_GPIO_INTR_ACK 22 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_INTR_ACK) +// * ar6000_cpio_intr_ack_cmd_s (see below) +// * uses: WMIX_GPIO_INTR_ACK_CMDID +// */ +// +//#define AR6000_XIOCTL_GPIO_INTR_WAIT 23 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_GPIO_INTR_WAIT) +// */ +// +// +// +///* ====more wireless commands==== */ +// +//#define AR6000_XIOCTL_SET_ADHOC_BSSID 24 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_SET_ADHOC_BSSID) +// * WMI_SET_ADHOC_BSSID_CMD setAdHocBssidCmd (see include/wmi.h) +// */ +// +//#define AR6000_XIOCTL_SET_OPT_MODE 25 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_SET_OPT_MODE) +// * WMI_SET_OPT_MODE_CMD setOptModeCmd (see include/wmi.h) +// * uses: WMI_SET_OPT_MODE_CMDID +// */ +// +//#define AR6000_XIOCTL_OPT_SEND_FRAME 26 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_OPT_SEND_FRAME) +// * WMI_OPT_TX_FRAME_CMD optTxFrameCmd (see include/wmi.h) +// * uses: WMI_OPT_TX_FRAME_CMDID +// */ +// +//#define AR6000_XIOCTL_SET_BEACON_INTVAL 27 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_SET_BEACON_INTVAL) +// * WMI_BEACON_INT_CMD beaconIntCmd (see include/wmi.h) +// * uses: WMI_SET_BEACON_INT_CMDID +// */ +// +// +//#define IEEE80211_IOCTL_SETAUTHALG 28 +// +// +//#define AR6000_XIOCTL_SET_VOICE_PKT_SIZE 29 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_SET_VOICE_PKT_SIZE) +// * WMI_SET_VOICE_PKT_SIZE_CMD setVoicePktSizeCmd (see include/wmi.h) +// * uses: WMI_SET_VOICE_PKT_SIZE_CMDID +// */ +// +// +//#define AR6000_XIOCTL_SET_MAX_SP 30 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_SET_MAX_SP) +// * WMI_SET_MAX_SP_LEN_CMD maxSPLen(see include/wmi.h) +// * uses: WMI_SET_MAX_SP_LEN_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_GET_ROAM_TBL 31 +// +//#define AR6000_XIOCTL_WMI_SET_ROAM_CTRL 32 +// +//#define AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS 33 +// +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS) +// * WMI_SET_POWERSAVE_TIMERS_CMD powerSaveTimers(see include/wmi.h) +// * WMI_SET_POWERSAVE_TIMERS_CMDID +// */ +// +//#define AR6000_XIOCTRL_WMI_GET_POWER_MODE 34 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTRL_WMI_GET_POWER_MODE) +// */ +// +//#define AR6000_XIOCTRL_WMI_SET_WLAN_STATE 35 + +typedef enum { + WLAN_DISABLED, + WLAN_ENABLED +} AR6000_WLAN_STATE; + +///* +// * arguments: +// * enable/disable +// */ +// +//#define AR6000_XIOCTL_WMI_GET_ROAM_DATA 36 +// +//#define AR6000_XIOCTL_WMI_SETRETRYLIMITS 37 +///* +// * arguments: +// * WMI_SET_RETRY_LIMITS_CMD ibssSetRetryLimitsCmd +// * uses: WMI_SET_RETRY_LIMITS_CMDID +// */ +// +//#ifdef CONFIG_HOST_TCMD_SUPPORT +///* ====extended commands for radio test ==== */ +// +//#define AR6000_XIOCTL_TCMD_CONT_TX 38 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_TCMD_CONT_TX) +// * WMI_TCMD_CONT_TX_CMD contTxCmd (see include/wmi.h) +// * uses: WMI_TCMD_CONT_TX_CMDID +// */ +// +//#define AR6000_XIOCTL_TCMD_CONT_RX 39 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_TCMD_CONT_RX) +// * WMI_TCMD_CONT_RX_CMD rxCmd (see include/wmi.h) +// * uses: WMI_TCMD_CONT_RX_CMDID +// */ +// +//#define AR6000_XIOCTL_TCMD_PM 40 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_TCMD_PM) +// * WMI_TCMD_PM_CMD pmCmd (see include/wmi.h) +// * uses: WMI_TCMD_PM_CMDID +// */ +// +//#endif /* CONFIG_HOST_TCMD_SUPPORT */ +// +//#define AR6000_XIOCTL_WMI_STARTSCAN 41 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_STARTSCAN) +// * UINT8 scanType +// * UINT8 scanConnected +// * A_BOOL forceFgScan +// * uses: WMI_START_SCAN_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_SETFIXRATES 42 +// +//#define AR6000_XIOCTL_WMI_GETFIXRATES 43 +// +// +//#define AR6000_XIOCTL_WMI_SET_RSSITHRESHOLD 44 +///* +// * arguments: +// * WMI_RSSI_THRESHOLD_PARAMS_CMD thresholdParams (see include/wmi.h) +// * uses: WMI_RSSI_THRESHOLD_PARAMS_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_CLR_RSSISNR 45 +///* +// * arguments: +// * WMI_CLR_RSSISNR_CMD thresholdParams (see include/wmi.h) +// * uses: WMI_CLR_RSSISNR_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_SET_LQTHRESHOLD 46 +///* +// * arguments: +// * WMI_LQ_THRESHOLD_PARAMS_CMD thresholdParams (see include/wmi.h) +// * uses: WMI_LQ_THRESHOLD_PARAMS_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_SET_RTS 47 +///* +// * arguments: +// * WMI_SET_RTS_MODE_CMD (see include/wmi.h) +// * uses: WMI_SET_RTS_MODE_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_SET_LPREAMBLE 48 +// +//#define AR6000_XIOCTL_WMI_SET_AUTHMODE 49 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_SET_AUTHMODE) +// * UINT8 mode +// * uses: WMI_SET_RECONNECT_AUTH_MODE_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_SET_REASSOCMODE 50 +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_SET_WMM) +// * UINT8 mode +// * uses: WMI_SET_WMM_CMDID +// */ +//#define AR6000_XIOCTL_WMI_SET_WMM 51 +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS) +// * UINT32 frequency +// * UINT8 threshold +// */ +//#define AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS 52 +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP) +// * UINT32 cookie +// */ +//#define AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP 53 +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_GET_RD) +// * UINT32 regDomain +// */ +//#define AR6000_XIOCTL_WMI_GET_RD 54 +// +//#define AR6000_XIOCTL_DIAG_READ 55 +// +//#define AR6000_XIOCTL_DIAG_WRITE 56 +// +///* +// * arguments cmd (AR6000_XIOCTL_SET_TXOP) +// * WMI_TXOP_CFG txopEnable +// */ +//#define AR6000_XIOCTL_WMI_SET_TXOP 57 +// +//#ifdef USER_KEYS +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_USER_SETKEYS) +// * UINT32 keyOpCtrl +// * uses AR6000_USER_SETKEYS_INFO +// */ +//#define AR6000_XIOCTL_USER_SETKEYS 58 +//#endif /* USER_KEYS */ +// +//#define AR6000_XIOCTL_WMI_SET_KEEPALIVE 59 +///* +// * arguments: +// * UINT8 cmd (AR6000_XIOCTL_WMI_SET_KEEPALIVE) +// * UINT8 keepaliveInterval +// * uses: WMI_SET_KEEPALIVE_CMDID +// */ +// +//#define AR6000_XIOCTL_WMI_GET_KEEPALIVE 60 +///* +// * arguments: +// * UINT8 cmd (AR6000_XIOCTL_WMI_GET_KEEPALIVE) +// * UINT8 keepaliveInterval +// * A_BOOL configured +// * uses: WMI_GET_KEEPALIVE_CMDID +// */ +// +///* ====ROM Patching Extended Ioctls==== */ +// +//#define AR6000_XIOCTL_BMI_ROMPATCH_INSTALL 61 +///* +// * arguments: +// * union { +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_ROMPATCH_INSTALL) +// * UINT32 ROM Address +// * UINT32 RAM Address +// * UINT32 number of bytes +// * UINT32 activate? (0 or 1) +// * } +// * A_UINT32 resulting rompatch ID +// * } +// * uses: BMI_ROMPATCH_INSTALL +// */ +// +//#define AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL 62 +///* +// * arguments: +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL) +// * UINT32 rompatch ID +// * } +// * uses: BMI_ROMPATCH_UNINSTALL +// */ +// +//#define AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE 63 +///* +// * arguments: +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE) +// * UINT32 rompatch count +// * UINT32 rompatch IDs[rompatch count] +// * } +// * uses: BMI_ROMPATCH_ACTIVATE +// */ +// +//#define AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE 64 +///* +// * arguments: +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE) +// * UINT32 rompatch count +// * UINT32 rompatch IDs[rompatch count] +// * } +// * uses: BMI_ROMPATCH_DEACTIVATE +// */ +// +//#define AR6000_XIOCTL_WMI_SET_APPIE 65 +///* +// * arguments: +// * struct { +// * UINT32 cmd (AR6000_XIOCTL_WMI_SET_APPIE) +// * UINT32 app_frmtype; +// * UINT32 app_buflen; +// * UINT8 app_buf[]; +// * } +// */ +//#define AR6000_XIOCTL_WMI_SET_MGMT_FRM_RX_FILTER 66 +///* +// * arguments: +// * A_UINT32 filter_type; +// */ +// +//#define AR6000_XIOCTL_DBGLOG_CFG_MODULE 67 +// +//#define AR6000_XIOCTL_DBGLOG_GET_DEBUG_LOGS 68 +// +//#define AR6000_XIOCTL_WMI_SET_WSC_STATUS 70 +///* +// * arguments: +// * A_UINT32 wsc_status; +// * (WSC_REG_INACTIVE or WSC_REG_ACTIVE) +// */ +// +///* +// * arguments: +// * struct { +// * A_UINT8 streamType; +// * A_UINT8 status; +// * } +// * uses: WMI_SET_BT_STATUS_CMDID +// */ +//#define AR6000_XIOCTL_WMI_SET_BT_STATUS 71 +// +///* +// * arguments: +// * struct { +// * A_UINT8 paramType; +// * union { +// * A_UINT8 noSCOPkts; +// * BT_PARAMS_A2DP a2dpParams; +// * BT_COEX_REGS regs; +// * }; +// * } +// * uses: WMI_SET_BT_PARAM_CMDID +// */ +//#define AR6000_XIOCTL_WMI_SET_BT_PARAMS 72 +// +//#define AR6000_XIOCTL_WMI_SET_HOST_SLEEP_MODE 73 +//#define AR6000_XIOCTL_WMI_SET_WOW_MODE 74 +//#define AR6000_XIOCTL_WMI_GET_WOW_LIST 75 +//#define AR6000_XIOCTL_WMI_ADD_WOW_PATTERN 76 +//#define AR6000_XIOCTL_WMI_DEL_WOW_PATTERN 77 +// +// +// +//#define AR6000_XIOCTL_TARGET_INFO 78 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_TARGET_INFO) +// * A_UINT32 TargetVersion (returned) +// * A_UINT32 TargetType (returned) +// * (See also bmi_msg.h target_ver and target_type) +// */ +// +//#define AR6000_XIOCTL_DUMP_HTC_CREDIT_STATE 79 +///* +// * arguments: +// * none +// */ +// +//#define AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE 80 +///* +// * This ioctl is used to emulate traffic activity +// * timeouts. Activity/inactivity will trigger the driver +// * to re-balance credits. +// * +// * arguments: +// * ar6000_traffic_activity_change +// */ +// +//#define AR6000_XIOCTL_WMI_SET_CONNECT_CTRL_FLAGS 81 +///* +// * This ioctl is used to set the connect control flags +// * +// * arguments: +// * A_UINT32 connectCtrlFlags +// */ +// +//#define AR6000_XIOCTL_WMI_SET_AKMP_PARAMS 82 +///* +// * This IOCTL sets any Authentication,Key Management and Protection +// * related parameters. This is used along with the information set in +// * Connect Command. +// * Currently this enables Multiple PMKIDs to an AP. +// * +// * arguments: +// * struct { +// * A_UINT32 akmpInfo; +// * } +// * uses: WMI_SET_AKMP_PARAMS_CMD +// */ +// +//#define AR6000_XIOCTL_WMI_GET_PMKID_LIST 83 +// +//#define AR6000_XIOCTL_WMI_SET_PMKID_LIST 84 +///* +// * This IOCTL is used to set a list of PMKIDs. This list of +// * PMKIDs is used in the [Re]AssocReq Frame. This list is used +// * only if the MultiPMKID option is enabled via the +// * AR6000_XIOCTL_WMI_SET_AKMP_PARAMS IOCTL. +// * +// * arguments: +// * struct { +// * A_UINT32 numPMKID; +// * WMI_PMKID pmkidList[WMI_MAX_PMKID_CACHE]; +// * } +// * uses: WMI_SET_PMKIDLIST_CMD +// */ +// +//#define AR6000_XIOCTL_WMI_SET_PARAMS 85 +//#define AR6000_XIOCTL_WMI_SET_MCAST_FILTER 86 +//#define AR6000_XIOCTL_WMI_DEL_MCAST_FILTER 87 +// +// +///* Historical DSETPATCH support for INI patches */ +//#define AR6000_XIOCTL_UNUSED90 90 +// +// +///* Support LZ-compressed firmware download */ +//#define AR6000_XIOCTL_BMI_LZ_STREAM_START 91 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_LZ_STREAM_START) +// * UINT32 address +// * uses: BMI_LZ_STREAM_START +// */ +// +//#define AR6000_XIOCTL_BMI_LZ_DATA 92 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_LZ_DATA) +// * UINT32 length +// * char data[length] +// * uses: BMI_LZ_DATA +// */ +// +//#define AR6000_XIOCTL_PROF_CFG 93 +///* +// * arguments: +// * A_UINT32 period +// * A_UINT32 nbins +// */ +// +//#define AR6000_XIOCTL_PROF_ADDR_SET 94 +///* +// * arguments: +// * A_UINT32 Target address +// */ +// +//#define AR6000_XIOCTL_PROF_START 95 +// +//#define AR6000_XIOCTL_PROF_STOP 96 +// +//#define AR6000_XIOCTL_PROF_COUNT_GET 97 +// +//#define AR6000_XIOCTL_WMI_ABORT_SCAN 98 +// +///* +// * AP mode +// */ +//#define AR6000_XIOCTL_AP_GET_STA_LIST 99 +// +//#define AR6000_XIOCTL_AP_HIDDEN_SSID 100 +// +//#define AR6000_XIOCTL_AP_SET_NUM_STA 101 +// +//#define AR6000_XIOCTL_AP_SET_ACL_MAC 102 +// +//#define AR6000_XIOCTL_AP_GET_ACL_LIST 103 +// +//#define AR6000_XIOCTL_AP_COMMIT_CONFIG 104 +// +//#define IEEE80211_IOCTL_GETWPAIE 105 +// +//#define AR6000_XIOCTL_AP_CONN_INACT_TIME 106 +// +//#define AR6000_XIOCTL_AP_PROT_SCAN_TIME 107 +// +//#define AR6000_XIOCTL_AP_SET_COUNTRY 108 +// +//#define AR6000_XIOCTL_AP_SET_DTIM 109 +// +// +// +// +//#define AR6000_XIOCTL_WMI_TARGET_EVENT_REPORT 110 +// +//#define AR6000_XIOCTL_SET_IP 111 +// +//#define AR6000_XIOCTL_AP_SET_ACL_POLICY 112 +// +//#define AR6000_XIOCTL_AP_CTRL_BSS_COMM 113 +// +//#define AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO 114 +// +//#define AR6000_XIOCTL_MODULE_DEBUG_SET_MASK 115 +// +//#define AR6000_XIOCTL_MODULE_DEBUG_GET_MASK 116 +// +//#define AR6000_XIOCTL_DUMP_RCV_AGGR_STATS 117 +// +//#define AR6000_XIOCTL_SET_HT_CAP 118 +// +//#define AR6000_XIOCTL_SET_HT_OP 119 +// +//#define AR6000_XIOCTL_AP_GET_STAT 120 +// +//#define AR6000_XIOCTL_SET_TX_SELECT_RATES 121 +// +//#define AR6000_XIOCTL_SETUP_AGGR 122 +// +//#define AR6000_XIOCTL_ALLOW_AGGR 123 +// +//#define AR6000_XIOCTL_AP_GET_HIDDEN_SSID 124 +// +//#define AR6000_XIOCTL_AP_GET_COUNTRY 125 +// +//#define AR6000_XIOCTL_AP_GET_WMODE 126 +// +//#define AR6000_XIOCTL_AP_GET_DTIM 127 +// +//#define AR6000_XIOCTL_AP_GET_BINTVL 128 +// +//#define AR6000_XIOCTL_AP_GET_RTS 129 +// +//#define AR6000_XIOCTL_DELE_AGGR 130 +// +//#define AR6000_XIOCTL_FETCH_TARGET_REGS 131 +// +//#define AR6000_XIOCTL_HCI_CMD 132 +// +//#define AR6000_XIOCTL_ACL_DATA 133 +// +//#define AR6000_XIOCTL_WLAN_CONN_PRECEDENCE 134 +// +//#define AR6000_XIOCTL_AP_SET_11BG_RATESET 135 +// +//#define AR6000_XIOCTL_WMI_SET_AP_PS 136 +// +//#define AR6000_XIOCTL_WMI_MCAST_FILTER 137 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT 138 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV 139 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG 140 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG 141 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG 142 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_ACLCOEX_CONFIG 143 +// +//#define AR6000_XIOCTL_WMI_SET_BTCOEX_DEBUG 144 +// +//#define AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS 145 +// +//#define AR6000_XIOCTL_WMI_GET_BTCOEX_CONFIG 146 +// +//#define AR6000_XIOCTL_WMI_GET_BTCOEX_STATS 147 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_WMI_SET_QOS_SUPP) +// * UINT8 mode +// * uses: WMI_SET_QOS_SUPP_CMDID +// */ +//#define AR6000_XIOCTL_WMI_SET_QOS_SUPP 148 +// +//#define AR6000_XIOCTL_AP_SET_DFS 149 +// +//#ifdef P2P +//#define AR6000_XIOCTL_WMI_P2P_DISCOVER 150 +//#define AR6000_XIOCTL_WMI_P2P_LISTEN 151 +//#define AR6000_XIOCTL_WMI_P2P_GO_NEG 152 +//#define AR6000_XIOCTL_WMI_P2P_CONFIG 153 +//#define AR6000_XIOCTL_WMI_WPS_CONFIG 154 +//#define AR6000_XIOCTL_WMI_P2P_FINDNODE 155 +//#endif +//#define AR6000_XIOCTL_SET_BT_HW_POWER_STATE 156 +//#define AR6000_XIOCTL_GET_BT_HW_POWER_STATE 157 +//#define AR6000_XIOCTL_GET_WLAN_SLEEP_STATE 158 +//#define AR6000_XIOCTL_WMI_SET_TX_SGI_PARAM 159 +///* +// * arguments: +// * WMI_AP_PS_CMD apPsCmd +// * uses: WMI_AP_PS_CMDID +// */ +// +// +//// WAC +//#define AR6000_XIOCTL_WMI_ENABLE_WAC_PARAM 160 +// +//#define AR6000_XIOCTL_WAC_SCAN_REPLY 161 +// +//#define AR6000_XIOCTL_WMI_WAC_CTRL_REQ 162 +// +//#define AR6000_XIOCTL_WMI_SET_WPA_OFFLOAD_STATE 163 +// +//#define AR6000_XIOCTL_WMI_SET_PASSPHRASE 164 +// +//#define AR6000_XIOCTL_BMI_NVRAM_PROCESS 165 +// +//#define AR6000_XIOCTL_AP_ACS_DISABLE_HI_CHANNELS 166 +// +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_BMI_NVRAM_PROCESS) +// * UINT8 name[BMI_NVRAM_SEG_NAME_SZ] +// * uses: BMI_NVRAM_PROCESS +// */ +// +// +//#ifdef CONFIG_HOST_TCMD_SUPPORT +///* ====additional extended commands for radio test ==== */ +// +//#define AR6000_XIOCTL_TCMD_CMDS 167 +///* +// * arguments: +// * UINT32 cmd (AR6000_XIOCTL_TCMD_CMDS) +// * WMI_TCMD_CMDS_CMD cmdsCmd (see include/wmi.h) +// * uses: WMI_TCMD_CMDS_CMDID +// */ +// +//#endif //ifdef CONFIG_HOST_TCMD_SUPPORT +// +//#define AR6000_XIOCTL_WMI_SET_DIVERSITY_PARAM 168 +// +//#define AR6000_XIOCTL_WMI_FORCE_ASSERT 169 +// +//#define AR6000_XIOCTL_WMI_SET_EXCESS_TX_RETRY_THRES 170 +// +//#define AR6000_XIOCTL_AP_GET_NUM_STA 171 +// +//#define AR6000_XIOCTL_SUSPEND_DRIVER 172 +// +//#define AR6000_XIOCTL_RESUME_DRIVER 173 + +/* used by AR6000_IOCTL_WMI_GETREV */ +struct ar6000_version { + A_UINT32 host_ver; + A_UINT32 target_ver; + A_UINT32 wlan_ver; + A_UINT32 abi_ver; + A_UINT32 targetconf_ver; +}; + +/* used by AR6000_IOCTL_WMI_GET_QOS_QUEUE */ +struct ar6000_queuereq { + A_UINT8 trafficClass; + A_UINT16 activeTsids; +}; + +/* used by AR6000_IOCTL_WMI_GET_TARGET_STATS */ +typedef struct targetStats_t { + A_UINT64 tx_packets; + A_UINT64 tx_bytes; + A_UINT64 tx_unicast_pkts; + A_UINT64 tx_unicast_bytes; + A_UINT64 tx_multicast_pkts; + A_UINT64 tx_multicast_bytes; + A_UINT64 tx_broadcast_pkts; + A_UINT64 tx_broadcast_bytes; + A_UINT64 tx_rts_success_cnt; + A_UINT64 tx_packet_per_ac[4]; + + A_UINT64 tx_errors; + A_UINT64 tx_failed_cnt; + A_UINT64 tx_retry_cnt; + A_UINT64 tx_mult_retry_cnt; + A_UINT64 tx_rts_fail_cnt; + + A_UINT64 rx_packets; + A_UINT64 rx_bytes; + A_UINT64 rx_unicast_pkts; + A_UINT64 rx_unicast_bytes; + A_UINT64 rx_multicast_pkts; + A_UINT64 rx_multicast_bytes; + A_UINT64 rx_broadcast_pkts; + A_UINT64 rx_broadcast_bytes; + A_UINT64 rx_fragment_pkt; + + A_UINT64 rx_errors; + A_UINT64 rx_crcerr; + A_UINT64 rx_key_cache_miss; + A_UINT64 rx_decrypt_err; + A_UINT64 rx_duplicate_frames; + + A_UINT64 tkip_local_mic_failure; + A_UINT64 tkip_counter_measures_invoked; + A_UINT64 tkip_replays; + A_UINT64 tkip_format_errors; + A_UINT64 ccmp_format_errors; + A_UINT64 ccmp_replays; + + A_UINT64 power_save_failure_cnt; + + A_UINT64 cs_bmiss_cnt; + A_UINT64 cs_lowRssi_cnt; + A_UINT64 cs_connect_cnt; + A_UINT64 cs_disconnect_cnt; + + A_INT32 tx_unicast_rate; + A_INT32 rx_unicast_rate; + + A_UINT32 lq_val; + + A_UINT32 wow_num_pkts_dropped; + A_UINT16 wow_num_events_discarded; + + A_INT16 noise_floor_calibation; + A_INT16 cs_rssi; + A_INT16 cs_aveBeacon_rssi; + A_UINT8 cs_aveBeacon_snr; + A_UINT8 cs_lastRoam_msec; + A_UINT8 cs_snr; + + A_UINT8 wow_num_host_pkt_wakeups; + A_UINT8 wow_num_host_event_wakeups; + + A_UINT32 arp_received; + A_UINT32 arp_matched; + A_UINT32 arp_replied; +}TARGET_STATS; + +typedef struct targetStats_cmd_t { + TARGET_STATS targetStats; + int clearStats; +} TARGET_STATS_CMD; + +/* used by AR6000_XIOCTL_USER_SETKEYS */ + +/* + * Setting this bit to 1 doesnot initialize the RSC on the firmware + */ +#define AR6000_XIOCTL_USER_SETKEYS_RSC_CTRL 1 +#define AR6000_USER_SETKEYS_RSC_UNCHANGED 0x00000002 + +typedef struct { + A_UINT32 keyOpCtrl; /* Bit Map of Key Mgmt Ctrl Flags */ +} AR6000_USER_SETKEYS_INFO; + + +/* used by AR6000_XIOCTL_GPIO_OUTPUT_SET */ +struct ar6000_gpio_output_set_cmd_s { + A_UINT32 set_mask; + A_UINT32 clear_mask; + A_UINT32 enable_mask; + A_UINT32 disable_mask; +}; + +/* + * used by AR6000_XIOCTL_GPIO_REGISTER_GET and AR6000_XIOCTL_GPIO_REGISTER_SET + */ +struct ar6000_gpio_register_cmd_s { + A_UINT32 gpioreg_id; + A_UINT32 value; +}; + +/* used by AR6000_XIOCTL_GPIO_INTR_ACK */ +struct ar6000_gpio_intr_ack_cmd_s { + A_UINT32 ack_mask; +}; + +/* used by AR6000_XIOCTL_GPIO_INTR_WAIT */ +struct ar6000_gpio_intr_wait_cmd_s { + A_UINT32 intr_mask; + A_UINT32 input_values; +}; + +/* used by the AR6000_XIOCTL_DBGLOG_CFG_MODULE */ +typedef struct ar6000_dbglog_module_config_s { + A_UINT32 valid; + A_UINT16 mmask; + A_UINT16 tsr; + A_BOOL rep; + A_UINT16 size; +} DBGLOG_MODULE_CONFIG; + +typedef struct user_rssi_thold_t { + A_INT16 tag; + A_INT16 rssi; +} USER_RSSI_THOLD; + +typedef struct user_rssi_params_t { + A_UINT8 weight; + A_UINT32 pollTime; + USER_RSSI_THOLD tholds[12]; +} USER_RSSI_PARAMS; + +typedef struct ar6000_get_btcoex_config_cmd_t{ + A_UINT32 btProfileType; + A_UINT32 linkId; + }AR6000_GET_BTCOEX_CONFIG_CMD; + +typedef struct ar6000_btcoex_config_t { + AR6000_GET_BTCOEX_CONFIG_CMD configCmd; + A_UINT32 * configEvent; +} AR6000_BTCOEX_CONFIG; + +typedef struct ar6000_btcoex_stats_t { + A_UINT32 * statsEvent; + }AR6000_BTCOEX_STATS; +/* + * Host driver may have some config parameters. Typically, these + * config params are one time config parameters. These could + * correspond to any of the underlying modules. Host driver exposes + * an api for the underlying modules to get this config. + */ +#define AR6000_DRIVER_CFG_BASE 0x8000 + +/* Should driver perform wlan node caching? */ +#define AR6000_DRIVER_CFG_GET_WLANNODECACHING 0x8001 +/*Should we log raw WMI msgs */ +#define AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS 0x8002 + +/* used by AR6000_XIOCTL_DIAG_READ & AR6000_XIOCTL_DIAG_WRITE */ +struct ar6000_diag_window_cmd_s { + unsigned int addr; + unsigned int value; +}; + + +struct ar6000_traffic_activity_change { + A_UINT32 StreamID; /* stream ID to indicate activity change */ + A_UINT32 Active; /* active (1) or inactive (0) */ +}; + +/* Used with AR6000_XIOCTL_PROF_COUNT_GET */ +struct prof_count_s { + A_UINT32 addr; /* bin start address */ + A_UINT32 count; /* hit count */ +}; + + +/* used by AR6000_XIOCTL_MODULE_DEBUG_SET_MASK */ +/* AR6000_XIOCTL_MODULE_DEBUG_GET_MASK */ +/* AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO */ +struct drv_debug_module_s { + A_CHAR modulename[128]; /* name of module */ + A_UINT32 mask; /* new mask to set .. or .. current mask */ +}; + +/* All HCI related rx events are sent up to the host app + * via a wmi event id. It can contain ACL data or HCI event, + * based on which it will be de-multiplexed. + */ +typedef enum { + PAL_HCI_EVENT = 0, + PAL_HCI_RX_DATA, +} WMI_PAL_EVENT_INFO; + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/athendpack_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/athendpack_linux.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/athstartpack_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/athstartpack_linux.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/athtypes_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/athtypes_linux.h new file mode 100644 index 000000000000..9d9ecbb2a4d7 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/athtypes_linux.h @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This file contains the definitions of the basic atheros data types. +// It is used to map the data types in atheros files to a platform specific +// type. +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _ATHTYPES_LINUX_H_ +#define _ATHTYPES_LINUX_H_ + +#ifdef __KERNEL__ +#include +#else +#include +#endif + +typedef int8_t A_INT8; +typedef int16_t A_INT16; +typedef int32_t A_INT32; +typedef int64_t A_INT64; + +typedef u_int8_t A_UINT8; +typedef u_int16_t A_UINT16; +typedef u_int32_t A_UINT32; +typedef u_int64_t A_UINT64; + +typedef int A_BOOL; +typedef char A_CHAR; +typedef unsigned char A_UCHAR; +typedef unsigned long A_ATH_TIMER; + + +#endif /* _ATHTYPES_LINUX_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/cfg80211.h b/drivers/net/wireless/ar6003/host/os/linux/include/cfg80211.h new file mode 100644 index 000000000000..eeab404be789 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/cfg80211.h @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _AR6K_CFG80211_H_ +#define _AR6K_CFG80211_H_ + +struct wireless_dev *ar6k_cfg80211_init(struct device *dev); +void ar6k_cfg80211_deinit(AR_SOFTC_DEV_T *arPriv); + +void ar6k_cfg80211_scanComplete_event(AR_SOFTC_DEV_T *arPriv, A_STATUS status); + +void ar6k_cfg80211_connect_event(AR_SOFTC_DEV_T *arPriv, A_UINT16 channel, + A_UINT8 *bssid, A_UINT16 listenInterval, + A_UINT16 beaconInterval,NETWORK_TYPE networkType, + A_UINT8 beaconIeLen, A_UINT8 assocReqLen, + A_UINT8 assocRespLen, A_UINT8 *assocInfo); + +void ar6k_cfg80211_disconnect_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 reason, + A_UINT8 *bssid, A_UINT8 assocRespLen, + A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus); + +void ar6k_cfg80211_tkip_micerr_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 keyid, A_BOOL ismcast); + +#endif /* _AR6K_CFG80211_H_ */ + + + + + + diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/config_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/config_linux.h new file mode 100644 index 000000000000..16dc80474635 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/config_linux.h @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _CONFIG_LINUX_H_ +#define _CONFIG_LINUX_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * Host-side GPIO support is optional. + * If run-time access to GPIO pins is not required, then + * this should be changed to #undef. + */ +#define CONFIG_HOST_GPIO_SUPPORT + +/* + * Host side Test Command support + * Note: when HCI SDIO is enabled, a low stack IRQ or statck overflow is + * hit on FC10. So with HCI SDIO, minimize the stack allocation by + * mutually exclude TCMD_SUPPORT, which allocates large buffers + * in AR_TCMD_RESP in AR_SOFTC_T + * + */ +#ifndef HCI_TRANSPORT_SDIO +//#define CONFIG_HOST_TCMD_SUPPORT +#endif + +/* Host-side support for Target-side profiling */ +#undef CONFIG_TARGET_PROFILE_SUPPORT +/*DIX OFFLOAD SUPPORT*/ +/*#define DIX_RX_OFFLOAD*/ +/*#define DIX_TX_OFFLOAD*/ + +/* IP/TCP checksum offload */ +/* Checksum offload is currently not supported for 64 bit platforms */ +#ifndef __LP64__ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) +#define CONFIG_CHECKSUM_OFFLOAD +#endif +#endif /* __LP64__ */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/debug_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/debug_linux.h new file mode 100644 index 000000000000..b8dba52badce --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/debug_linux.h @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _DEBUG_LINUX_H_ +#define _DEBUG_LINUX_H_ + + /* macro to remove parens */ +#define ATH_PRINTX_ARG(arg...) arg + +#ifdef DEBUG + /* NOTE: the AR_DEBUG_PRINTF macro is defined here to handle special handling of variable arg macros + * which may be compiler dependent. */ +#define AR_DEBUG_PRINTF(mask, args) do { \ + if (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (mask)) { \ + A_LOGGER(mask, ATH_MODULE_NAME, ATH_PRINTX_ARG args); \ + } \ +} while (0) +#else + /* on non-debug builds, keep in error and warning messages in the driver, all other + * message tracing will get compiled out */ +#define AR_DEBUG_PRINTF(mask, args) \ + if ((mask) & (ATH_DEBUG_ERR | ATH_DEBUG_WARN)) { A_PRINTF(ATH_PRINTX_ARG args); } + +#endif + + /* compile specific macro to get the function name string */ +#define _A_FUNCNAME_ __func__ + + +#endif /* _DEBUG_LINUX_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/export_hci_transport.h b/drivers/net/wireless/ar6003/host/os/linux/include/export_hci_transport.h new file mode 100644 index 000000000000..c1506805a4d5 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/export_hci_transport.h @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// HCI bridge implementation +// +// Author(s): ="Atheros" +//============================================================================== + +#include "hci_transport_api.h" +#include "common_drv.h" + +extern HCI_TRANSPORT_HANDLE (*_HCI_TransportAttach)(void *HTCHandle, HCI_TRANSPORT_CONFIG_INFO *pInfo); +extern void (*_HCI_TransportDetach)(HCI_TRANSPORT_HANDLE HciTrans); +extern A_STATUS (*_HCI_TransportAddReceivePkts)(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET_QUEUE *pQueue); +extern A_STATUS (*_HCI_TransportSendPkt)(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET *pPacket, A_BOOL Synchronous); +extern void (*_HCI_TransportStop)(HCI_TRANSPORT_HANDLE HciTrans); +extern A_STATUS (*_HCI_TransportStart)(HCI_TRANSPORT_HANDLE HciTrans); +extern A_STATUS (*_HCI_TransportEnableDisableAsyncRecv)(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); +extern A_STATUS (*_HCI_TransportRecvHCIEventSync)(HCI_TRANSPORT_HANDLE HciTrans, + HTC_PACKET *pPacket, + int MaxPollMS); +extern A_STATUS (*_HCI_TransportSetBaudRate)(HCI_TRANSPORT_HANDLE HciTrans, A_UINT32 Baud); +extern A_STATUS (*_HCI_TransportEnablePowerMgmt)(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable); + + +#define HCI_TransportAttach(HTCHandle, pInfo) \ + _HCI_TransportAttach((HTCHandle), (pInfo)) +#define HCI_TransportDetach(HciTrans) \ + _HCI_TransportDetach(HciTrans) +#define HCI_TransportAddReceivePkts(HciTrans, pQueue) \ + _HCI_TransportAddReceivePkts((HciTrans), (pQueue)) +#define HCI_TransportSendPkt(HciTrans, pPacket, Synchronous) \ + _HCI_TransportSendPkt((HciTrans), (pPacket), (Synchronous)) +#define HCI_TransportStop(HciTrans) \ + _HCI_TransportStop((HciTrans)) +#define HCI_TransportStart(HciTrans) \ + _HCI_TransportStart((HciTrans)) +#define HCI_TransportEnableDisableAsyncRecv(HciTrans, Enable) \ + _HCI_TransportEnableDisableAsyncRecv((HciTrans), (Enable)) +#define HCI_TransportRecvHCIEventSync(HciTrans, pPacket, MaxPollMS) \ + _HCI_TransportRecvHCIEventSync((HciTrans), (pPacket), (MaxPollMS)) +#define HCI_TransportSetBaudRate(HciTrans, Baud) \ + _HCI_TransportSetBaudRate((HciTrans), (Baud)) +#define HCI_TransportEnablePowerMgmt(HciTrans, Enable) \ + _HCI_TransportEnablePowerMgmt((HciTrans), (Enable)) + + +extern A_STATUS ar6000_register_hci_transport(HCI_TRANSPORT_CALLBACKS *hciTransCallbacks); + +extern A_STATUS ar6000_get_hif_dev(HIF_DEVICE *device, void *config); + +extern A_STATUS ar6000_set_uart_config(HIF_DEVICE *hifDevice, A_UINT32 scale, A_UINT32 step); + +/* get core clock register settings + * data: 0 - 40/44MHz + * 1 - 80/88MHz + * where (5G band/2.4G band) + * assume 2.4G band for now + */ +extern A_STATUS ar6000_get_core_clock_config(HIF_DEVICE *hifDevice, A_UINT32 *data); diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/ieee80211_ioctl.h b/drivers/net/wireless/ar6003/host/os/linux/include/ieee80211_ioctl.h new file mode 100644 index 000000000000..714441211536 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/ieee80211_ioctl.h @@ -0,0 +1,181 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _IEEE80211_IOCTL_H_ +#define _IEEE80211_IOCTL_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Extracted from the MADWIFI net80211/ieee80211_ioctl.h + */ + +/* + * WPA/RSN get/set key request. Specify the key/cipher + * type and whether the key is to be used for sending and/or + * receiving. The key index should be set only when working + * with global keys (use IEEE80211_KEYIX_NONE for ``no index''). + * Otherwise a unicast/pairwise key is specified by the bssid + * (on a station) or mac address (on an ap). They key length + * must include any MIC key data; otherwise it should be no + more than IEEE80211_KEYBUF_SIZE. + */ +struct ieee80211req_key { + u_int8_t ik_type; /* key/cipher type */ + u_int8_t ik_pad; + u_int16_t ik_keyix; /* key index */ + u_int8_t ik_keylen; /* key length in bytes */ + u_int8_t ik_flags; +#define IEEE80211_KEY_XMIT 0x01 +#define IEEE80211_KEY_RECV 0x02 +#define IEEE80211_KEY_DEFAULT 0x80 /* default xmit key */ + u_int8_t ik_macaddr[IEEE80211_ADDR_LEN]; + u_int64_t ik_keyrsc; /* key receive sequence counter */ + u_int64_t ik_keytsc; /* key transmit sequence counter */ + u_int8_t ik_keydata[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE]; +}; +/* + * Delete a key either by index or address. Set the index + * to IEEE80211_KEYIX_NONE when deleting a unicast key. + */ +struct ieee80211req_del_key { + u_int8_t idk_keyix; /* key index */ + u_int8_t idk_macaddr[IEEE80211_ADDR_LEN]; +}; +/* + * MLME state manipulation request. IEEE80211_MLME_ASSOC + * only makes sense when operating as a station. The other + * requests can be used when operating as a station or an + * ap (to effect a station). + */ +struct ieee80211req_mlme { + u_int8_t im_op; /* operation to perform */ +#define IEEE80211_MLME_ASSOC 1 /* associate station */ +#define IEEE80211_MLME_DISASSOC 2 /* disassociate station */ +#define IEEE80211_MLME_DEAUTH 3 /* deauthenticate station */ +#define IEEE80211_MLME_AUTHORIZE 4 /* authorize station */ +#define IEEE80211_MLME_UNAUTHORIZE 5 /* unauthorize station */ + u_int16_t im_reason; /* 802.11 reason code */ + u_int8_t im_macaddr[IEEE80211_ADDR_LEN]; +}; + +struct ieee80211req_addpmkid { + u_int8_t pi_bssid[IEEE80211_ADDR_LEN]; + u_int8_t pi_enable; + u_int8_t pi_pmkid[16]; +}; + +#define AUTH_ALG_OPEN_SYSTEM 0x01 +#define AUTH_ALG_SHARED_KEY 0x02 +#define AUTH_ALG_LEAP 0x04 + +struct ieee80211req_authalg { + u_int8_t auth_alg; +}; + +/* + * Request to add an IE to a Management Frame + */ +enum{ + IEEE80211_APPIE_FRAME_BEACON = 0, + IEEE80211_APPIE_FRAME_PROBE_REQ = 1, + IEEE80211_APPIE_FRAME_PROBE_RESP = 2, + IEEE80211_APPIE_FRAME_ASSOC_REQ = 3, + IEEE80211_APPIE_FRAME_ASSOC_RESP = 4, + IEEE80211_APPIE_NUM_OF_FRAME = 5 +}; + +/* + * The Maximum length of the IE that can be added to a Management frame + */ +#define IEEE80211_APPIE_FRAME_MAX_LEN 200 + +struct ieee80211req_getset_appiebuf { + u_int32_t app_frmtype; /* management frame type for which buffer is added */ + u_int32_t app_buflen; /*application supplied buffer length */ + u_int8_t app_buf[]; +}; + +/* + * The following definitions are used by an application to set filter + * for receiving management frames + */ +enum { + IEEE80211_FILTER_TYPE_BEACON = 0x1, + IEEE80211_FILTER_TYPE_PROBE_REQ = 0x2, + IEEE80211_FILTER_TYPE_PROBE_RESP = 0x4, + IEEE80211_FILTER_TYPE_ASSOC_REQ = 0x8, + IEEE80211_FILTER_TYPE_ASSOC_RESP = 0x10, + IEEE80211_FILTER_TYPE_AUTH = 0x20, + IEEE80211_FILTER_TYPE_DEAUTH = 0x40, + IEEE80211_FILTER_TYPE_DISASSOC = 0x80, + IEEE80211_FILTER_TYPE_ALL = 0xFF /* used to check the valid filter bits */ +}; + +struct ieee80211req_set_filter { + u_int32_t app_filterype; /* management frame filter type */ +}; + +enum { + IEEE80211_PARAM_AUTHMODE = 3, /* Authentication Mode */ + IEEE80211_PARAM_MCASTCIPHER = 5, + IEEE80211_PARAM_MCASTKEYLEN = 6, /* multicast key length */ + IEEE80211_PARAM_UCASTCIPHER = 8, + IEEE80211_PARAM_UCASTKEYLEN = 9, /* unicast key length */ + IEEE80211_PARAM_WPA = 10, /* WPA mode (0,1,2) */ + IEEE80211_PARAM_ROAMING = 12, /* roaming mode */ + IEEE80211_PARAM_PRIVACY = 13, /* privacy invoked */ + IEEE80211_PARAM_COUNTERMEASURES = 14, /* WPA/TKIP countermeasures */ + IEEE80211_PARAM_DROPUNENCRYPTED = 15, /* discard unencrypted frames */ + IEEE80211_PARAM_WAPI = 16, /* WAPI policy from wapid */ +}; + +/* + * Values for IEEE80211_PARAM_WPA + */ +#define WPA_MODE_WPA1 1 +#define WPA_MODE_WPA2 2 +#define WPA_MODE_AUTO 3 +#define WPA_MODE_NONE 4 + +struct ieee80211req_wpaie { + u_int8_t wpa_macaddr[IEEE80211_ADDR_LEN]; + u_int8_t wpa_ie[IEEE80211_MAX_IE]; + u_int8_t rsn_ie[IEEE80211_MAX_IE]; +}; + +#ifndef IW_ENCODE_ALG_PMK +#define IW_ENCODE_ALG_PMK 4 +#endif +#ifndef IW_ENCODE_ALG_KRK +#define IW_ENCODE_ALG_KRK 6 +#endif +#ifdef __cplusplus +} +#endif + +#endif /* _IEEE80211_IOCTL_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/osapi_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/osapi_linux.h new file mode 100644 index 000000000000..bfdbba30b3be --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/osapi_linux.h @@ -0,0 +1,432 @@ +//------------------------------------------------------------------------------ +// This file contains the definitions of the basic atheros data types. +// It is used to map the data types in atheros files to a platform specific +// type. +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _OSAPI_LINUX_H_ +#define _OSAPI_LINUX_H_ + +#ifdef __KERNEL__ + +#include +#include +#include +#include +#include +#include +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) +#include +#endif +/*************************************/ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#include +#endif +#include +#include +#include +#ifdef KERNEL_2_4 +#include +#include +#endif + +#include + +#ifdef __GNUC__ +#define __ATTRIB_PACK __attribute__ ((packed)) +#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2))) +#define __ATTRIB_NORETURN __attribute__ ((noreturn)) +#ifndef INLINE +#define INLINE __inline__ +#endif +#else /* Not GCC */ +#define __ATTRIB_PACK +#define __ATTRIB_PRINTF +#define __ATTRIB_NORETURN +#ifndef INLINE +#define INLINE __inline +#endif +#endif /* End __GNUC__ */ + +#define PREPACK +#define POSTPACK __ATTRIB_PACK + +/* + * Endianes macros + */ +#define A_BE2CPU8(x) ntohb(x) +#define A_BE2CPU16(x) ntohs(x) +#define A_BE2CPU32(x) ntohl(x) + +#define A_LE2CPU8(x) (x) +#define A_LE2CPU16(x) (x) +#define A_LE2CPU32(x) (x) + +#define A_CPU2BE8(x) htonb(x) +#define A_CPU2BE16(x) htons(x) +#define A_CPU2BE32(x) htonl(x) + +#define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len)) +#define A_MEMZERO(addr, len) memset(addr, 0, len) +#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len)) + +#ifdef AR6K_ALLOC_DEBUG +#define a_meminfo_add(p, s) __a_meminfo_add(p, s, __func__, __LINE) +void __a_meminfo_add(void *ptr, size_t msize, const char *func, int lineno); +void a_meminfo_del(void *ptr); +void* a_mem_alloc(size_t msize, int type, const char *func, int lineno); +void a_mem_free(void *ptr); +void a_meminfo_report(int clear); +A_BOOL a_meminfo_find(void *ptr); +#define A_MALLOC(size) a_mem_alloc((size), GFP_KERNEL, __func__, __LINE__) +#define A_MALLOC_NOWAIT(size) a_mem_alloc((size), GFP_ATOMIC, __func__, __LINE__) +#define A_FREE(addr) a_mem_free(addr) +#define A_NETIF_RX(skb) do { a_meminfo_del(skb); netif_rx(skb); } while (0) +#define A_NETIF_RX_NI(skb) do { a_meminfo_del(skb); netif_rx_ni(skb); } while (0) +#else +#define a_meminfo_report(_c) +#define A_MALLOC(size) kmalloc((size), GFP_KERNEL) +#define A_MALLOC_NOWAIT(size) kmalloc((size), GFP_ATOMIC) +#define A_FREE(addr) kfree(addr) +#define A_NETIF_RX(skb) netif_rx(skb) +#define A_NETIF_RX_NI(skb) netif_rx_ni(skb) +#endif + +#if defined(ANDROID_ENV) && defined(CONFIG_ANDROID_LOGGER) +extern unsigned int enablelogcat; +extern int android_logger_lv(void* module, int mask); +enum logidx { LOG_MAIN_IDX = 0 }; +extern int logger_write(const enum logidx idx, + const unsigned char prio, + const char __kernel * const tag, + const char __kernel * const fmt, + ...); +#define A_ANDROID_PRINTF(mask, module, tags, args...) do { \ + if (enablelogcat) \ + logger_write(LOG_MAIN_IDX, android_logger_lv(module, mask), tags, args); \ + else \ + printk(KERN_ALERT args); \ +} while (0) +#ifdef DEBUG +#define A_LOGGER_MODULE_NAME(x) #x +#define A_LOGGER(mask, mod, args...) \ + A_ANDROID_PRINTF(mask, &GET_ATH_MODULE_DEBUG_VAR_NAME(mod), "ar6k_" A_LOGGER_MODULE_NAME(mod), args); +#endif +#define A_PRINTF(args...) A_ANDROID_PRINTF(ATH_DEBUG_INFO, NULL, "ar6k_driver", args) +#else +#define A_LOGGER(mask, mod, args...) printk(KERN_ALERT args) +#define A_PRINTF(args...) printk(KERN_ALERT args) +#endif /* ANDROID */ +#define A_PRINTF_LOG(args...) printk(args) +#define A_SPRINTF(buf, args...) sprintf (buf, args) + +/* Mutual Exclusion */ +typedef spinlock_t A_MUTEX_T; +#define A_MUTEX_INIT(mutex) spin_lock_init(mutex) +#define A_MUTEX_LOCK(mutex) spin_lock_bh(mutex) +#define A_MUTEX_UNLOCK(mutex) spin_unlock_bh(mutex) +#define A_IS_MUTEX_VALID(mutex) TRUE /* okay to return true, since A_MUTEX_DELETE does nothing */ +#define A_MUTEX_DELETE(mutex) /* spin locks are not kernel resources so nothing to free.. */ + +/* Get current time in ms adding a constant offset (in ms) */ +#define A_GET_MS(offset) \ + (((jiffies / HZ) * 1000) + (offset)) + +/* + * Timer Functions + */ +#define A_MDELAY(msecs) mdelay(msecs) +typedef struct timer_list A_TIMER; + +#define A_INIT_TIMER(pTimer, pFunction, pArg) do { \ + init_timer(pTimer); \ + (pTimer)->function = (pFunction); \ + (pTimer)->data = (unsigned long)(pArg); \ +} while (0) + +/* + * Start a Timer that elapses after 'periodMSec' milli-seconds + * Support is provided for a one-shot timer. The 'repeatFlag' is + * ignored. + */ +#define A_TIMEOUT_MS(pTimer, periodMSec, repeatFlag) do { \ + if (repeatFlag) { \ + printk("\n" __FILE__ ":%d: Timer Repeat requested\n",__LINE__); \ + panic("Timer Repeat"); \ + } \ + mod_timer((pTimer), jiffies + HZ * (periodMSec) / 1000); \ +} while (0) + +/* + * Cancel the Timer. + */ +#define A_UNTIMEOUT(pTimer) do { \ + del_timer((pTimer)); \ +} while (0) + +#define A_DELETE_TIMER(pTimer) do { \ +} while (0) + +/* + * Wait Queue related functions + */ +typedef wait_queue_head_t A_WAITQUEUE_HEAD; +#define A_INIT_WAITQUEUE_HEAD(head) init_waitqueue_head(head) +#ifndef wait_event_interruptible_timeout +#define __wait_event_interruptible_timeout(wq, condition, ret) \ +do { \ + wait_queue_t __wait; \ + init_waitqueue_entry(&__wait, current); \ + \ + add_wait_queue(&wq, &__wait); \ + for (;;) { \ + set_current_state(TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + if (!signal_pending(current)) { \ + ret = schedule_timeout(ret); \ + if (!ret) \ + break; \ + continue; \ + } \ + ret = -ERESTARTSYS; \ + break; \ + } \ + current->state = TASK_RUNNING; \ + remove_wait_queue(&wq, &__wait); \ +} while (0) + +#define wait_event_interruptible_timeout(wq, condition, timeout) \ +({ \ + long __ret = timeout; \ + if (!(condition)) \ + __wait_event_interruptible_timeout(wq, condition, __ret); \ + __ret; \ +}) +#endif /* wait_event_interruptible_timeout */ + +#define A_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT(head, condition, timeout) do { \ + wait_event_interruptible_timeout(head, condition, timeout); \ +} while (0) + +#define A_WAKE_UP(head) wake_up(head) + +#ifdef DEBUG +extern unsigned int panic_on_assert; +#define A_ASSERT(expr) \ + if (!(expr)) { \ + printk(KERN_ALERT"Debug Assert Caught, File %s, Line: %d, Test:%s \n",__FILE__, __LINE__,#expr); \ + if (panic_on_assert) panic(#expr); \ + } +#else +#define A_ASSERT(expr) +#endif /* DEBUG */ + +#ifdef ANDROID_ENV +struct firmware; +int android_request_firmware(const struct firmware **firmware_p, const char *filename, + struct device *device); +void android_release_firmware(const struct firmware *firmware); +#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev) +#define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf) +#else +#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev) +#define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf) +#endif + +/* + * Initialization of the network buffer subsystem + */ +#define A_NETBUF_INIT() + +/* + * Network buffer queue support + */ +typedef struct sk_buff_head A_NETBUF_QUEUE_T; + +#define A_NETBUF_QUEUE_INIT(q) \ + a_netbuf_queue_init(q) + +#define A_NETBUF_ENQUEUE(q, pkt) \ + a_netbuf_enqueue((q), (pkt)) +#define A_NETBUF_PREQUEUE(q, pkt) \ + a_netbuf_prequeue((q), (pkt)) +#define A_NETBUF_DEQUEUE(q) \ + (a_netbuf_dequeue(q)) +#define A_NETBUF_QUEUE_SIZE(q) \ + a_netbuf_queue_size(q) +#define A_NETBUF_QUEUE_EMPTY(q) \ + a_netbuf_queue_empty(q) + +/* + * Network buffer support + */ +#ifdef AR6K_ALLOC_DEBUG +#define A_NETBUF_ALLOC(size) \ + a_netbuf_alloc(size, __func__, __LINE__) +#define A_NETBUF_ALLOC_RAW(size) \ + a_netbuf_alloc_raw(size, __func__, __LINE__) +#define A_NETBUF_CHECK(bufPtr) \ + a_netbuf_check(bufPtr, __func__, __LINE__) +#else +#define A_NETBUF_ALLOC(size) \ + a_netbuf_alloc(size) +#define A_NETBUF_ALLOC_RAW(size) \ + a_netbuf_alloc_raw(size) +#endif /* AR6K_ALLOC_DEBUG */ +#define A_NETBUF_FREE(bufPtr) \ + a_netbuf_free(bufPtr) +#define A_NETBUF_DATA(bufPtr) \ + a_netbuf_to_data(bufPtr) +#define A_NETBUF_LEN(bufPtr) \ + a_netbuf_to_len(bufPtr) +#define A_NETBUF_PUSH(bufPtr, len) \ + a_netbuf_push(bufPtr, len) +#define A_NETBUF_PUT(bufPtr, len) \ + a_netbuf_put(bufPtr, len) +#define A_NETBUF_TRIM(bufPtr,len) \ + a_netbuf_trim(bufPtr, len) +#define A_NETBUF_PULL(bufPtr, len) \ + a_netbuf_pull(bufPtr, len) +#define A_NETBUF_HEADROOM(bufPtr)\ + a_netbuf_headroom(bufPtr) +#define A_NETBUF_SETLEN(bufPtr,len) \ + a_netbuf_setlen(bufPtr, len) + +/* Add data to end of a buffer */ +#define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \ + a_netbuf_put_data(bufPtr, srcPtr, len) + +/* Add data to start of the buffer */ +#define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \ + a_netbuf_push_data(bufPtr, srcPtr, len) + +/* Remove data at start of the buffer */ +#define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \ + a_netbuf_pull_data(bufPtr, dstPtr, len) + +/* Remove data from the end of the buffer */ +#define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \ + a_netbuf_trim_data(bufPtr, dstPtr, len) + +/* View data as "size" contiguous bytes of type "t" */ +#define A_NETBUF_VIEW_DATA(bufPtr, t, size) \ + (t )( ((struct skbuf *)(bufPtr))->data) + +/* return the beginning of the headroom for the buffer */ +#define A_NETBUF_HEAD(bufPtr) \ + ((((struct sk_buff *)(bufPtr))->head)) + +/* + * OS specific network buffer access routines + */ +#ifdef AR6K_ALLOC_DEBUG +void *a_netbuf_alloc(int size, const char *func, int lineno); +void *a_netbuf_alloc_raw(int size, const char *func, int lineno); +void a_netbuf_check(void *bufPtr, const char *func, int lineno); +#else +void *a_netbuf_alloc(int size); +void *a_netbuf_alloc_raw(int size); +#endif +void a_netbuf_free(void *bufPtr); +void *a_netbuf_to_data(void *bufPtr); +A_UINT32 a_netbuf_to_len(void *bufPtr); +A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len); +A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len); +A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len); +A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len); +A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len); +A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len); +A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len); +A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len); +A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len); +A_INT32 a_netbuf_headroom(void *bufPtr); +void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt); +void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt); +void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q); +int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q); +int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q); +int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q); +void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q); + +/* + * Kernel v.s User space functions + */ +A_UINT32 a_copy_to_user(void *to, const void *from, A_UINT32 n); +A_UINT32 a_copy_from_user(void *to, const void *from, A_UINT32 n); + +/* In linux, WLAN Rx and Tx run in different contexts, so no need to check + * for any commands/data queued for WLAN */ +#define A_CHECK_DRV_TX() + +#define A_GET_CACHE_LINE_BYTES() L1_CACHE_BYTES + +#define A_CACHE_LINE_PAD 128 + +static inline void *A_ALIGN_TO_CACHE_LINE(void *ptr) { + return (void *)L1_CACHE_ALIGN((unsigned long)ptr); +} + +#else /* __KERNEL__ */ + +#ifdef __GNUC__ +#define __ATTRIB_PACK __attribute__ ((packed)) +#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2))) +#define __ATTRIB_NORETURN __attribute__ ((noreturn)) +#ifndef INLINE +#define INLINE __inline__ +#endif +#else /* Not GCC */ +#define __ATTRIB_PACK +#define __ATTRIB_PRINTF +#define __ATTRIB_NORETURN +#ifndef INLINE +#define INLINE __inline +#endif +#endif /* End __GNUC__ */ + +#define PREPACK +#define POSTPACK __ATTRIB_PACK + +#define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len)) +#define A_MEMZERO(addr, len) memset((addr), 0, (len)) +#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len)) +#define A_MALLOC(size) malloc(size) +#define A_FREE(addr) free(addr) + +#ifdef ANDROID +#ifndef err +#include +#define err(_s, args...) do { \ + fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \ + fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \ + exit(_s); } while (0) +#endif +#else +#include +#endif + +#endif /* __KERNEL__ */ + +#endif /* _OSAPI_LINUX_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/wlan_config.h b/drivers/net/wireless/ar6003/host/os/linux/include/wlan_config.h new file mode 100644 index 000000000000..c38db55427ef --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/wlan_config.h @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains the tunable configuration items for the WLAN module +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef _HOST_WLAN_CONFIG_H_ +#define _HOST_WLAN_CONFIG_H_ + +/* Include definitions here that can be used to tune the WLAN module behavior. + * Different customers can tune the behavior as per their needs, here. + */ + +/* This configuration item when defined will consider the barker preamble + * mentioned in the ERP IE of the beacons from the AP to determine the short + * preamble support sent in the (Re)Assoc request frames. + */ +#define WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP 0 + +/* This config item when defined will not send the power module state transition + * failure events that happen during scan, to the host. + */ +#define WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN 0 + +/* This config item disables sending a DisAssoc frame prior to sending a + * DeAuth frame. + */ +#define WLAN_CONFIG_NO_DISASSOC_UPON_DEAUTH 0 + +/* + * This configuration item enable/disable keepalive support. + * Keepalive support: In the absence of any data traffic to AP, null + * frames will be sent to the AP at periodic interval, to keep the association + * active. This configuration item defines the periodic interval. + * Use value of zero to disable keepalive support + * Default: 60 seconds + */ +#define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60 + +/* + * This configuration item sets the value of disconnect timeout + * Firmware delays sending the disconnec event to the host for this + * timeout after is gets disconnected from the current AP. + * If the firmware successly roams within the disconnect timeout + * it sends a new connect event + */ +#ifdef ANDROID_ENV +#define WLAN_CONFIG_DISCONNECT_TIMEOUT 3 +#else +#define WLAN_CONFIG_DISCONNECT_TIMEOUT 10 +#endif /* ANDROID_ENV */ + +/* + * This configuration item enable BT clock sharing support + * 1 - Enable + * 0 - Disable (Default) + */ +#define WLAN_CONFIG_BT_SHARING 0 + +/* + * This configuration item sets WIFI OFF policy + * 0 - CUT_POWER + * 1 - DEEP_SLEEP (Default) + */ +#define WLAN_CONFIG_WLAN_OFF 1 + +/* + * This configuration item disables 11n support. + * 0 - Enable + * 1 - Disable + */ +#define WLAN_CONFIG_DISABLE_11N 0 + +/* + * This configuration item sets suspend policy + * 0 - CUT_POWER (Default) + * 1 - DEEP_SLEEP + * 2 - WoW + * 3 - CUT_POWER if BT OFF (clock sharing designs only) + */ +#define WLAN_CONFIG_PM_SUSPEND 0 + +/* + * This configuration item sets suspend policy to use if PM_SUSPEND is + * set to WoW and device is not connected at the time of suspend + * 0 - CUT_POWER (Default) + * 1 - DEEP_SLEEP + * 2 - WoW + * 3 - CUT_POWER if BT OFF (clock sharing designs only) + */ +#define WLAN_CONFIG_PM_WOW2 0 + +/* + * Define GPIO number for WoW in your platform other than zero + * Wake lock will be called when GPIO asserted. + */ +#define PLAT_WOW_GPIO_PIN 0 + +/* + * This configuration item for the WOW patterns in AP mode + * 0 - Wake up host only if any unicast IP, EAPOL-like and ARP, broadcast dhcp and ARP packets. (default) + * 1 - Wake up host if any unicast/broadcast/multicast packets + */ +#define WLAN_CONFIG_SIMPLE_WOW_AP_MODE 0 + +/* + * Define the GPIO number for WLAN CHIP_PWD PIN other than zero + * Only use when you define plat_setup_power as plat_setup_power_stub + */ + +#define PLAT_WLAN_CHIP_PWD_PIN 1 + +/* + * Platform specific function to power ON/OFF AR6000 with CHIP_PWD PIN + * and enable/disable SDIO card detection + * + * Either implement wlan CHIP_PWD PIN and power GPIO control into + * plat_setup_power_stub(..) place holder in ar6000_pm.c + * or redefine plat_setup_power(..) into your export funciton. + */ + +#if PLAT_WLAN_CHIP_PWD_PIN +extern void plat_setup_power_stub(struct ar6_softc *ar, int on, int detect); +#define plat_setup_power(ar, on, detect) plat_setup_power_stub(ar, on, detect) +#else +#define plat_setup_power(ar, on, detect) /* define as your function */ +#endif + +#endif /* _HOST_WLAN_CONFIG_H_ */ diff --git a/drivers/net/wireless/ar6003/host/os/linux/include/wmi_filter_linux.h b/drivers/net/wireless/ar6003/host/os/linux/include/wmi_filter_linux.h new file mode 100644 index 000000000000..2c52f6d79484 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/include/wmi_filter_linux.h @@ -0,0 +1,346 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#ifndef _WMI_FILTER_LINUX_H_ +#define _WMI_FILTER_LINUX_H_ + +/* + * sioctl_filter - Standard ioctl + * pioctl_filter - Priv ioctl + * xioctl_filter - eXtended ioctl + * + * ---- Possible values for the WMI filter --------------- + * (0) - Block this cmd always (or) not implemented + * (INFRA_NETWORK) - Allow this cmd only in STA mode + * (ADHOC_NETWORK) - Allow this cmd only in IBSS mode + * (AP_NETWORK) - Allow this cmd only in AP mode + * (INFRA_NETWORK | ADHOC_NETWORK) - Block this cmd in AP mode + * (ADHOC_NETWORK | AP_NETWORK) - Block this cmd in STA mode + * (INFRA_NETWORK | AP_NETWORK) - Block this cmd in IBSS mode + * (INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK)- allow only when mode is set + * (0xFF) - Allow this cmd always irrespective of mode + */ + +A_UINT8 sioctl_filter[] = { +(AP_NETWORK), /* SIOCSIWCOMMIT 0x8B00 */ +(0xFF), /* SIOCGIWNAME 0x8B01 */ +(0), /* SIOCSIWNWID 0x8B02 */ +(0), /* SIOCGIWNWID 0x8B03 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWFREQ 0x8B04 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWFREQ 0x8B05 */ +(0xFF), /* SIOCSIWMODE 0x8B06 */ +(0xFF), /* SIOCGIWMODE 0x8B07 */ +(0), /* SIOCSIWSENS 0x8B08 */ +(0), /* SIOCGIWSENS 0x8B09 */ +(0), /* SIOCSIWRANGE 0x8B0A */ +(0xFF), /* SIOCGIWRANGE 0x8B0B */ +(0), /* SIOCSIWPRIV 0x8B0C */ +(0), /* SIOCGIWPRIV 0x8B0D */ +(0), /* SIOCSIWSTATS 0x8B0E */ +(0), /* SIOCGIWSTATS 0x8B0F */ +(0), /* SIOCSIWSPY 0x8B10 */ +(0), /* SIOCGIWSPY 0x8B11 */ +(0), /* SIOCSIWTHRSPY 0x8B12 */ +(0), /* SIOCGIWTHRSPY 0x8B13 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWAP 0x8B14 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWAP 0x8B15 */ +#if (WIRELESS_EXT >= 18) +(INFRA_NETWORK | ADHOC_NETWORK), /* SIOCSIWMLME 0X8B16 */ +#else +(0), /* Dummy 0 */ +#endif /* WIRELESS_EXT */ +(0), /* SIOCGIWAPLIST 0x8B17 */ +(INFRA_NETWORK | ADHOC_NETWORK), /* SIOCSIWSCAN 0x8B18 */ +(INFRA_NETWORK | ADHOC_NETWORK), /* SIOCGIWSCAN 0x8B19 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWESSID 0x8B1A */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWESSID 0x8B1B */ +(0), /* SIOCSIWNICKN 0x8B1C */ +(0), /* SIOCGIWNICKN 0x8B1D */ +(0), /* Dummy 0 */ +(0), /* Dummy 0 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWRATE 0x8B20 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWRATE 0x8B21 */ +(0), /* SIOCSIWRTS 0x8B22 */ +(0), /* SIOCGIWRTS 0x8B23 */ +(0), /* SIOCSIWFRAG 0x8B24 */ +(0), /* SIOCGIWFRAG 0x8B25 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWTXPOW 0x8B26 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWTXPOW 0x8B27 */ +(INFRA_NETWORK | ADHOC_NETWORK), /* SIOCSIWRETRY 0x8B28 */ +(INFRA_NETWORK | ADHOC_NETWORK), /* SIOCGIWRETRY 0x8B29 */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWENCODE 0x8B2A */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWENCODE 0x8B2B */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCSIWPOWER 0x8B2C */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* SIOCGIWPOWER 0x8B2D */ +}; + + + +A_UINT8 pioctl_filter[] = { +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* IEEE80211_IOCTL_SETPARAM (SIOCIWFIRSTPRIV+0) */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* IEEE80211_IOCTL_SETKEY (SIOCIWFIRSTPRIV+1) */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* IEEE80211_IOCTL_DELKEY (SIOCIWFIRSTPRIV+2) */ +(AP_NETWORK), /* IEEE80211_IOCTL_SETMLME (SIOCIWFIRSTPRIV+3) */ +(INFRA_NETWORK), /* IEEE80211_IOCTL_ADDPMKID (SIOCIWFIRSTPRIV+4) */ +(0), /* IEEE80211_IOCTL_SETOPTIE (SIOCIWFIRSTPRIV+5) */ +(0), /* (SIOCIWFIRSTPRIV+6) */ +(0), /* (SIOCIWFIRSTPRIV+7) */ +(0), /* (SIOCIWFIRSTPRIV+8) */ +(0), /* (SIOCIWFIRSTPRIV+9) */ +(0), /* IEEE80211_IOCTL_LASTONE (SIOCIWFIRSTPRIV+10) */ +(0xFF), /* AR6000_IOCTL_WMI_GETREV (SIOCIWFIRSTPRIV+11) */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_IOCTL_WMI_SETPWR (SIOCIWFIRSTPRIV+12) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SETSCAN (SIOCIWFIRSTPRIV+13) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SETLISTENINT (SIOCIWFIRSTPRIV+14) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SETBSSFILTER (SIOCIWFIRSTPRIV+15) */ +(INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_IOCTL_WMI_SET_CHANNELPARAMS (SIOCIWFIRSTPRIV+16) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_PROBEDSSID (SIOCIWFIRSTPRIV+17) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_PMPARAMS (SIOCIWFIRSTPRIV+18) */ +(INFRA_NETWORK), /* AR6000_IOCTL_WMI_SET_BADAP (SIOCIWFIRSTPRIV+19) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_GET_QOS_QUEUE (SIOCIWFIRSTPRIV+20) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_CREATE_QOS (SIOCIWFIRSTPRIV+21) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_DELETE_QOS (SIOCIWFIRSTPRIV+22) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_SNRTHRESHOLD (SIOCIWFIRSTPRIV+23) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_ERROR_REPORT_BITMASK (SIOCIWFIRSTPRIV+24)*/ +(0xFF), /* AR6000_IOCTL_WMI_GET_TARGET_STATS (SIOCIWFIRSTPRIV+25) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_ASSOC_INFO (SIOCIWFIRSTPRIV+26) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_ACCESS_PARAMS (SIOCIWFIRSTPRIV+27) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_BMISS_TIME (SIOCIWFIRSTPRIV+28) */ +(INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_DISC_TIMEOUT (SIOCIWFIRSTPRIV+29) */ +(ADHOC_NETWORK), /* AR6000_IOCTL_WMI_SET_IBSS_PM_CAPS (SIOCIWFIRSTPRIV+30) */ +}; + +/* Submode for the sake of filtering XIOCTLs are broadly set to 2 types. + * P2P Submode & Non-P2P submode. IOCLT cmds can be marked to be valid only in + * P2P Submode or Non-P2P submode or both. The bits- b5,b6,b7 are used to encode + * this information in the IOCTL filters. The LSBits b0-b4 are used to encode + * the mode information. + */ +#define XIOCTL_FILTER_P2P_SUBMODE 0x20 +#define XIOCTL_FILTER_NONP2P_SUBMODE 0x40 +#define XIOCTL_FILTER_SUBMODE_DONTCARE \ + (XIOCTL_FILTER_P2P_SUBMODE | XIOCTL_FILTER_NONP2P_SUBMODE) + +A_UINT8 xioctl_filter[] = { +(0xFF), /* Dummy 0 */ +(0xFF), /* AR6000_XIOCTL_BMI_DONE 1 */ +(0xFF), /* AR6000_XIOCTL_BMI_READ_MEMORY 2 */ +(0xFF), /* AR6000_XIOCTL_BMI_WRITE_MEMORY 3 */ +(0xFF), /* AR6000_XIOCTL_BMI_EXECUTE 4 */ +(0xFF), /* AR6000_XIOCTL_BMI_SET_APP_START 5 */ +(0xFF), /* AR6000_XIOCTL_BMI_READ_SOC_REGISTER 6 */ +(0xFF), /* AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER 7 */ +(0xFF), /* AR6000_XIOCTL_BMI_TEST 8 */ +(0xFF), /* AR6000_XIOCTL_UNUSED9 9 */ +(0xFF), /* AR6000_XIOCTL_UNUSED10 10 */ +(0xFF), /* AR6000_XIOCTL_UNUSED11 11 */ +(0xFF), /* AR6000_XIOCTL_FORCE_TARGET_RESET 12 */ +(0xFF), /* AR6000_XIOCTL_HTC_RAW_OPEN 13 */ +(0xFF), /* AR6000_XIOCTL_HTC_RAW_CLOSE 14 */ +(0xFF), /* AR6000_XIOCTL_HTC_RAW_READ 15 */ +(0xFF), /* AR6000_XIOCTL_HTC_RAW_WRITE 16 */ +(0xFF), /* AR6000_XIOCTL_CHECK_TARGET_READY 17 */ +(0xFF), /* AR6000_XIOCTL_GPIO_OUTPUT_SET 18 */ +(0xFF), /* AR6000_XIOCTL_GPIO_INPUT_GET 19 */ +(0xFF), /* AR6000_XIOCTL_GPIO_REGISTER_SET 20 */ +(0xFF), /* AR6000_XIOCTL_GPIO_REGISTER_GET 21 */ +(0xFF), /* AR6000_XIOCTL_GPIO_INTR_ACK 22 */ +(0xFF), /* AR6000_XIOCTL_GPIO_INTR_WAIT 23 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_SET_ADHOC_BSSID 24 */ +(0x00), /*AR6000_XIOCTL_UNUSED 25 */ +(0x00), /*AR6000_XIOCTL_UNUSED 26 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_SET_BEACON_INTVAL 27 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* IEEE80211_IOCTL_SETAUTHALG 28 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_SET_VOICE_PKT_SIZE 29 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_SET_MAX_SP 30 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_GET_ROAM_TBL 31 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_ROAM_CTRL 32 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS 33 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTRL_WMI_GET_POWER_MODE 34 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTRL_WMI_SET_WLAN_STATE 35 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_GET_ROAM_DATA 36 */ +(0xFF), /* AR6000_XIOCTL_WMI_SETRETRYLIMITS 37 */ +(0xFF), /* AR6000_XIOCTL_TCMD_CONT_TX 38 */ +(0xFF), /* AR6000_XIOCTL_TCMD_CONT_RX 39 */ +(0xFF), /* AR6000_XIOCTL_TCMD_PM 40 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_STARTSCAN 41 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SETFIXRATES 42 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GETFIXRATES 43 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_RSSITHRESHOLD 44 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_CLR_RSSISNR 45 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_LQTHRESHOLD 46 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_RTS 47 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_LPREAMBLE 48 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_AUTHMODE 49 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_REASSOCMODE 50 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_WMM 51 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS 52 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP 53 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_RD 54 */ +(0xFF), /* AR6000_XIOCTL_DIAG_READ 55 */ +(0xFF), /* AR6000_XIOCTL_DIAG_WRITE 56 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_TXOP 57 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK), /* AR6000_XIOCTL_USER_SETKEYS 58 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK), /* AR6000_XIOCTL_WMI_SET_KEEPALIVE 59 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK), /* AR6000_XIOCTL_WMI_GET_KEEPALIVE 60 */ +(0xFF), /* AR6000_XIOCTL_BMI_ROMPATCH_INSTALL 61 */ +(0xFF), /* AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL 62 */ +(0xFF), /* AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE 63 */ +(0xFF), /* AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE 64 */ +(0xFF), /* AR6000_XIOCTL_WMI_SET_APPIE 65 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_WMI_SET_MGMT_FRM_RX_FILTER 66 */ +(0xFF), /* AR6000_XIOCTL_DBGLOG_CFG_MODULE 67 */ +(0xFF), /* AR6000_XIOCTL_DBGLOG_GET_DEBUG_LOGS 68 */ +(0xFF), /* Dummy 69 */ +(0xFF), /* AR6000_XIOCTL_WMI_SET_WSC_STATUS 70 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_BT_STATUS 71 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_BT_PARAMS 72 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_HOST_SLEEP_MODE 73 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_WOW_MODE 74 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_WOW_LIST 75 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_ADD_WOW_PATTERN 76 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_DEL_WOW_PATTERN 77 */ +(0xFF), /* AR6000_XIOCTL_TARGET_INFO 78 */ +(0xFF), /* AR6000_XIOCTL_DUMP_HTC_CREDIT_STATE 79 */ +(0xFF), /* AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE 80 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_CONNECT_CTRL_FLAGS 81 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_AKMP_PARAMS 82 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_GET_PMKID_LIST 83 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_PMKID_LIST 84 */ +(0xFF), /* Dummy 85 */ +(0xFF), /* Dummy 86 */ +(0xFF), /* Dummy 87 */ +(0xFF), /* Dummy 88 */ +(0xFF), /* Dummy 89 */ +(0xFF), /* AR6000_XIOCTL_UNUSED90 90 */ +(0xFF), /* AR6000_XIOCTL_BMI_LZ_STREAM_START 91 */ +(0xFF), /* AR6000_XIOCTL_BMI_LZ_DATA 92 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_PROF_CFG 93 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_PROF_ADDR_SET 94 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_PROF_START 95 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_PROF_STOP 96 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_PROF_COUNT_GET 97 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_ABORT_SCAN 98 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_STA_LIST 99 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | AP_NETWORK), /* AR6000_XIOCTL_AP_HIDDEN_SSID 100 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_NUM_STA 101 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_ACL_MAC 102 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_ACL_LIST 103 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_COMMIT_CONFIG 104 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* IEEE80211_IOCTL_GETWPAIE 105 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_CONN_INACT_TIME 106 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_PROT_SCAN_TIME 107 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_COUNTRY 108 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_DTIM 109 */ +(0xFF), /* AR6000_XIOCTL_WMI_TARGET_EVENT_REPORT 110 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_SET_IP 111 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_ACL_POLICY 112 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_CTRL_BSS_COMM 113 */ +(0xFF), /* AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO 114 */ +(0xFF), /* AR6000_XIOCTL_MODULE_DEBUG_SET_MASK 115 */ +(0xFF), /* AR6000_XIOCTL_MODULE_DEBUG_GET_MASK 116 */ +(0xFF), /* AR6000_XIOCTL_DUMP_RCV_AGGR_STATS 117 */ +(0xFF), /* AR6000_XIOCTL_SET_HT_CAP 118 */ +(0xFF), /* AR6000_XIOCTL_SET_HT_OP 119 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_STAT 120 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_SET_TX_SELECT_RATES 121 */ +(0xFF), /* AR6000_XIOCTL_SETUP_AGGR 122 */ +(0xFF), /* AR6000_XIOCTL_ALLOW_AGGR 123 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_HIDDEN_SSID 124 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_COUNTRY 125 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_WMODE 126 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_DTIM 127 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_AP_GET_BINTVL 128 */ +(0xFF), /* AR6000_XIOCTL_AP_GET_RTS 129 */ +(0xFF), /* AR6000_XIOCTL_DELE_AGGR 130 */ +(0xFF), /* AR6000_XIOCTL_FETCH_TARGET_REGS 131 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_HCI_CMD 132 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_ACL_DATA 133 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_WLAN_CONN_PRECEDENCE 134 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_11BG_RATESET 135 */ +(0xFF), +(0xFF), +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT 138 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV 139 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG 140 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG 141 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG 142 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_ACLCOEX_CONFIG 143 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BTCOEX_DEBUG 144 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS 145 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_BTCOEX_CONFIG 146 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_BTCOEX_GET_STATS 147 */ +(0xFF), /* AR6000_XIOCTL_WMI_SET_QOS_SUPP 148 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_SET_DFS 149 */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* P2P CMDS BEGIN AR6000_XIOCTL_WMI_P2P_DISCOVER 150 */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_STOP_FIND */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_CANCEL */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_LISTEN */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_GO_NEG */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_AUTH_GO_NEG */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_REJECT */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_CONFIG */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_WPS_CONFIG */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_FINDNODE */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_GRP_INIT 160 */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_GRP_FORMATION_DONE */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_INVITE */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_PROV_DISC */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_SET */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_PEER */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_FLUSH */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_GO_PARAMS */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_AUTH_INVITE */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_GET_IF_ADDR */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_GET_DEV_ADDR 170 */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_P2P_SDPD_TX_CMD */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOTCL_WMI_P2P_SD_CANCEL_REQUEST */ +(0xFF), /* AR6000_XIOCTL_SET_BT_HW_POWER_STATE 173 */ +(0xFF), /* AR6000_XIOCTL_GET_BT_HW_POWER_STATE 174 */ +(0xFF), /* AR6000_XIOCTL_GET_WLAN_SLEEP_STATE 175 */ +(0xFF), /* AR6000_XIOCTL_WMI_SET_TX_SGI_PARAM 176 */ +(0xFF), /* R6000_XIOCTL_WMI_ENABLE_WAC_PARAM 177 */ +(0xFF), /* AR6000_XIOCTL_WAC_SCAN_REPLY 178 */ +(0xFF), /* AR6000_XIOCTL_WMI_WAC_CTRL_REQ 179 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_WPA_OFFLOAD_STATE 180 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_PASSPHRASE 181 */ +(0xFF), /* AR6000_XIOCTL_BMI_NVRAM_PROCESS 182 */ +(0xFF), /* AR6000_XIOCTL_WMI_SET_DIVERSITY_PARAM 183 */ +(0xFF), /* AR6000_XIOCTL_WMI_FORCE_ASSERT 184 */ +(0xFF), /* AR6000_XIOCTL_WMI_ENABLE_PKTLOG 185 */ +(0xFF), /* AR6000_XIOCTL_WMI_DISABLE_PKTLOG 186 */ +(0xFF), /* AR6000_XIOCTL_WMI_GET_PKTLOG 187 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | AP_NETWORK), /* AR6000_XIOCTL_AP_ACS_DISABLE_HI_CHANNELS 188 */ +(0xFF), /* AR6000_XIOCTL_TCMD_CMDS 189 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK), /* AR6000_XIOCTL_WMI_SET_EXCESS_TX_RETRY_THRES 190 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_AP_GET_NUM_STA 191 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_SUSPEND_DRIVER 192 */ +(XIOCTL_FILTER_NONP2P_SUBMODE | 0x1F), /* AR6000_XIOCTL_RESUME_DRIVER 193 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | INFRA_NETWORK | ADHOC_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_GET_SUBMODE 194 */ +(XIOCTL_FILTER_SUBMODE_DONTCARE | AP_NETWORK), /* AR6000_XIOCTL_WMI_AP_APSD 195 */ +(0xFF), /* AR6000_XIOCTL_TCMD_SETREG 196 */ +(0xFF), /* AR6000_XIOCTL_GET_HT_CAP 197 */ +(XIOCTL_FILTER_P2P_SUBMODE | INFRA_NETWORK | AP_NETWORK), /* AR6000_XIOCTL_WMI_GET_P2P_IE 198 */ +}; + +#endif /*_WMI_FILTER_LINUX_H_*/ diff --git a/drivers/net/wireless/ar6003/host/os/linux/ioctl.c b/drivers/net/wireless/ar6003/host/os/linux/ioctl.c new file mode 100644 index 000000000000..f507446d938e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/ioctl.c @@ -0,0 +1,5611 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" +#include "a_drv_api.h" +#include "ieee80211_ioctl.h" +#include "ar6kap_common.h" +#include "targaddrs.h" +#include "a_hci.h" +#include "wlan_config.h" +#include "wac_defs.h" +#ifdef P2P +#include "p2p_api.h" +#endif /* P2P */ + +extern int enablerssicompensation; +A_UINT32 tcmdRxFreq; +extern unsigned int wmitimeout; +extern int tspecCompliance; +extern int bmienable; +extern int bypasswmi; +extern int loghci; + +static int +ar6000_ioctl_get_roam_tbl(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if(wmi_get_roam_tbl_cmd(arPriv->arWmi) != A_OK) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_get_roam_data(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + /* currently assume only roam times are required */ + if(wmi_get_roam_data_cmd(arPriv->arWmi, ROAM_DATA_TIME) != A_OK) { + return -EIO; + } + + + return 0; +} + +static int +ar6000_ioctl_set_roam_ctrl(struct net_device *dev, char *userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_ROAM_CTRL_CMD cmd; + A_UINT8 size = sizeof(cmd); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if (cmd.roamCtrlType == WMI_SET_HOST_BIAS) { + if (cmd.info.bssBiasInfo.numBss > 1) { + size += (cmd.info.bssBiasInfo.numBss - 1) * sizeof(WMI_BSS_BIAS); + } + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if(wmi_set_roam_ctrl_cmd(arPriv->arWmi, &cmd, size) != A_OK) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_set_powersave_timers(struct net_device *dev, char *userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_POWERSAVE_TIMERS_POLICY_CMD cmd; + A_UINT8 size = sizeof(cmd); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if(wmi_set_powersave_timers_cmd(arPriv->arWmi, &cmd, size) != A_OK) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_set_qos_supp(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_QOS_SUPP_CMD cmd; + A_STATUS ret; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + ret = wmi_set_qos_supp_cmd(arPriv->arWmi, cmd.status); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_set_wmm(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_WMM_CMD cmd; + A_STATUS ret; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + if (cmd.status == WMI_WMM_ENABLED) { + arPriv->arWmmEnabled = TRUE; + } else { + arPriv->arWmmEnabled = FALSE; + } + + ret = wmi_set_wmm_cmd(arPriv->arWmi, cmd.status); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_set_txop(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_WMM_TXOP_CMD cmd; + A_STATUS ret; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + ret = wmi_set_wmm_txop(arPriv->arWmi, cmd.txopEnable); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_get_rd(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + A_STATUS ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if(copy_to_user((char *)((unsigned int*)rq->ifr_data + 1), + &arPriv->arRegCode, sizeof(arPriv->arRegCode))) + ret = -EFAULT; + + return ret; +} + +static int +ar6000_ioctl_set_country(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_AP_SET_COUNTRY_CMD cmd; + A_STATUS ret; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + + ret = wmi_set_country(arPriv->arWmi, cmd.countryCode); + A_MEMCPY(arPriv->arAp.ap_country_code, cmd.countryCode, 3); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + + +/* Get power mode command */ +static int +ar6000_ioctl_get_power_mode(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_POWER_MODE_CMD power_mode; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + power_mode.powerMode = wmi_get_power_mode_cmd(arPriv->arWmi); + if (copy_to_user(rq->ifr_data, &power_mode, sizeof(WMI_POWER_MODE_CMD))) { + ret = -EFAULT; + } + + return ret; +} + + +static int +ar6000_ioctl_set_channelParams(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_CHANNEL_PARAMS_CMD cmd, *cmdp; + int ret = 0; + int i = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_DEV_T *arTempPriv = NULL; + + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if( (arPriv->arNextMode == AP_NETWORK) && (cmd.numChannels || cmd.scanParam) ) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ERROR: Only wmode is allowed in AP mode\n")); + return -EIO; + } + + if (cmd.numChannels > 1) { + cmdp = A_MALLOC(130); + if (copy_from_user(cmdp, rq->ifr_data, + sizeof (*cmdp) + + ((cmd.numChannels - 1) * sizeof(A_UINT16)))) + { + A_FREE(cmdp); + return -EFAULT; + } + } else { + cmdp = &cmd; + } + + if ((arPriv->arPhyCapability == WMI_11NG_CAPABILITY) && + ((cmdp->phyMode == WMI_11A_MODE) || (cmdp->phyMode == WMI_11AG_MODE))) + { + ret = -EINVAL; + } + + for(i = 0;i < ar->arConfNumDev;i++){ + arTempPriv = ar->arDev[i]; + if (arTempPriv != arPriv){ + if (((arTempPriv->phymode == WMI_11A_MODE) && (cmdp->phyMode != WMI_11A_MODE)) || (((arTempPriv->phymode != WMI_11A_MODE) && arTempPriv->phymode != WMI_11AG_MODE ) && (cmdp->phyMode == WMI_11A_MODE))){ + ret = -EINVAL; + break; + } + } + + } + if (!ret && + (wmi_set_channelParams_cmd(arPriv->arWmi, cmdp->scanParam, cmdp->phyMode, + cmdp->numChannels, cmdp->channelList) + != A_OK)) + { + ret = -EIO; + } + + if (!ret) + arPriv->phymode = cmdp->phyMode; + + if (cmd.numChannels > 1) { + A_FREE(cmdp); + } + + /* Set the profile change flag to allow a commit cmd */ + if (!ret) + arPriv->ap_profile_flag = 1; + + return ret; +} + + +static int +ar6000_ioctl_set_snr_threshold(struct net_device *dev, struct ifreq *rq) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SNR_THRESHOLD_PARAMS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if( wmi_set_snr_threshold_params(arPriv->arWmi, &cmd) != A_OK ) { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_rssi_threshold(struct net_device *dev, struct ifreq *rq) +{ +#define SWAP_THOLD(thold1, thold2) do { \ + USER_RSSI_THOLD tmpThold; \ + tmpThold.tag = thold1.tag; \ + tmpThold.rssi = thold1.rssi; \ + thold1.tag = thold2.tag; \ + thold1.rssi = thold2.rssi; \ + thold2.tag = tmpThold.tag; \ + thold2.rssi = tmpThold.rssi; \ +} while (0) + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_RSSI_THRESHOLD_PARAMS_CMD cmd; + USER_RSSI_PARAMS rssiParams; + A_INT32 i, j; + int ret = 0; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user((char *)&rssiParams, (char *)((unsigned int *)rq->ifr_data + 1), sizeof(USER_RSSI_PARAMS))) { + return -EFAULT; + } + cmd.weight = rssiParams.weight; + cmd.pollTime = rssiParams.pollTime; + + A_MEMCPY(arSta->rssi_map, &rssiParams.tholds, sizeof(arSta->rssi_map)); + /* + * only 6 elements, so use bubble sorting, in ascending order + */ + for (i = 5; i > 0; i--) { + for (j = 0; j < i; j++) { /* above tholds */ + if (arSta->rssi_map[j+1].rssi < arSta->rssi_map[j].rssi) { + SWAP_THOLD(arSta->rssi_map[j+1], arSta->rssi_map[j]); + } else if (arSta->rssi_map[j+1].rssi == arSta->rssi_map[j].rssi) { + return EFAULT; + } + } + } + for (i = 11; i > 6; i--) { + for (j = 6; j < i; j++) { /* below tholds */ + if (arSta->rssi_map[j+1].rssi < arSta->rssi_map[j].rssi) { + SWAP_THOLD(arSta->rssi_map[j+1], arSta->rssi_map[j]); + } else if (arSta->rssi_map[j+1].rssi == arSta->rssi_map[j].rssi) { + return EFAULT; + } + } + } + +#ifdef DEBUG + for (i = 0; i < 12; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("thold[%d].tag: %d, thold[%d].rssi: %d \n", + i, arSta->rssi_map[i].tag, i, arSta->rssi_map[i].rssi)); + } +#endif + + if (enablerssicompensation) { + for (i = 0; i < 6; i++) + arSta->rssi_map[i].rssi = rssi_compensation_reverse_calc(arPriv, arSta->rssi_map[i].rssi, TRUE); + for (i = 6; i < 12; i++) + arSta->rssi_map[i].rssi = rssi_compensation_reverse_calc(arPriv, arSta->rssi_map[i].rssi, FALSE); + } + + cmd.thresholdAbove1_Val = arSta->rssi_map[0].rssi; + cmd.thresholdAbove2_Val = arSta->rssi_map[1].rssi; + cmd.thresholdAbove3_Val = arSta->rssi_map[2].rssi; + cmd.thresholdAbove4_Val = arSta->rssi_map[3].rssi; + cmd.thresholdAbove5_Val = arSta->rssi_map[4].rssi; + cmd.thresholdAbove6_Val = arSta->rssi_map[5].rssi; + cmd.thresholdBelow1_Val = arSta->rssi_map[6].rssi; + cmd.thresholdBelow2_Val = arSta->rssi_map[7].rssi; + cmd.thresholdBelow3_Val = arSta->rssi_map[8].rssi; + cmd.thresholdBelow4_Val = arSta->rssi_map[9].rssi; + cmd.thresholdBelow5_Val = arSta->rssi_map[10].rssi; + cmd.thresholdBelow6_Val = arSta->rssi_map[11].rssi; + + if( wmi_set_rssi_threshold_params(arPriv->arWmi, &cmd) != A_OK ) { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_lq_threshold(struct net_device *dev, struct ifreq *rq) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_LQ_THRESHOLD_PARAMS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, (char *)((unsigned int *)rq->ifr_data + 1), sizeof(cmd))) { + return -EFAULT; + } + + if( wmi_set_lq_threshold_params(arPriv->arWmi, &cmd) != A_OK ) { + ret = -EIO; + } + + return ret; +} + + +static int +ar6000_ioctl_set_probedSsid(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_PROBED_SSID_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_probedSsid_cmd(arPriv->arWmi, cmd.entryIndex, cmd.flag, cmd.ssidLength, + cmd.ssid) != A_OK) + { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_badAp(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_ADD_BAD_AP_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (cmd.badApIndex > WMI_MAX_BAD_AP_INDEX) { + return -EIO; + } + + if (A_MEMCMP(cmd.bssid, null_mac, AR6000_ETH_ADDR_LEN) == 0) { + /* + * This is a delete badAP. + */ + if (wmi_deleteBadAp_cmd(arPriv->arWmi, cmd.badApIndex) != A_OK) { + ret = -EIO; + } + } else { + if (wmi_addBadAp_cmd(arPriv->arWmi, cmd.badApIndex, cmd.bssid) != A_OK) { + ret = -EIO; + } + } + + return ret; +} + +static int +ar6000_ioctl_create_qos(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_CREATE_PSTREAM_CMD cmd; + A_STATUS ret; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_verify_tspec_params(&cmd, tspecCompliance); + if (ret == A_OK) + ret = wmi_create_pstream_cmd(arPriv->arWmi, &cmd); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_delete_qos(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_DELETE_PSTREAM_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_delete_pstream_cmd(arPriv->arWmi, cmd.trafficClass, cmd.tsid); + + switch (ret) { + case A_OK: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_get_qos_queue(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + struct ar6000_queuereq qreq; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if( copy_from_user(&qreq, rq->ifr_data, + sizeof(struct ar6000_queuereq))) + return -EFAULT; + + qreq.activeTsids = wmi_get_mapped_qos_queue(arPriv->arWmi, qreq.trafficClass); + + if (copy_to_user(rq->ifr_data, &qreq, + sizeof(struct ar6000_queuereq))) + { + ret = -EFAULT; + } + + return ret; +} + +#ifdef CONFIG_HOST_TCMD_SUPPORT +static A_STATUS +ar6000_ioctl_tcmd_cmd_resp(struct net_device *dev, struct ifreq *rq, A_UINT8 *data, A_UINT32 len) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UINT8 buf[4+TC_CMDS_SIZE_MAX]; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + ar->tcmdRxReport = 0; + if (wmi_test_cmd(arPriv->arWmi, data, len) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, ar->tcmdRxReport != 0, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + *(A_UINT16*)&(buf[0]) = ar->tcmdResp.len; + buf[2] = ar->tcmdResp.ver; + A_MEMCPY((buf+4), ar->tcmdResp.buf, sizeof(ar->tcmdResp.buf)); + + if (!ret && copy_to_user(rq->ifr_data, buf, sizeof(buf))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return ret; +} + +static A_STATUS +ar6000_ioctl_tcmd_get_rx_report(struct net_device *dev, + struct ifreq *rq, A_UINT8 *data, A_UINT32 len) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UINT32 buf[4+TCMD_MAX_RATES]; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + ar->tcmdRxReport = 0; + if (wmi_test_cmd(arPriv->arWmi, data, len) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, ar->tcmdRxReport != 0, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + buf[0] = ar->tcmdRxTotalPkt; + buf[1] = ar->tcmdRxRssi; + buf[2] = ar->tcmdRxcrcErrPkt; + buf[3] = ar->tcmdRxsecErrPkt; + A_MEMCPY(((A_UCHAR *)buf)+(4*sizeof(A_UINT32)), ar->tcmdRateCnt, sizeof(ar->tcmdRateCnt)); + A_MEMCPY(((A_UCHAR *)buf)+(4*sizeof(A_UINT32))+(TCMD_MAX_RATES *sizeof(A_UINT16)), ar->tcmdRateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + + if (!ret && copy_to_user(rq->ifr_data, buf, sizeof(buf))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return ret; +} + +void +ar6000_tcmd_rx_report_event(AR_SOFTC_DEV_T *arPriv, A_UINT8 * results, int len) +{ + + AR_SOFTC_T *ar = arPriv->arSoftc; + TCMD_CONT_RX * rx_rep = (TCMD_CONT_RX *)results; + + if (TC_CMD_RESP == rx_rep->act) { + TC_CMDS *tCmd = (TC_CMDS *)results; + ar->tcmdResp.len = tCmd->hdr.u.parm.length; + ar->tcmdResp.ver = tCmd->hdr.u.parm.version; + A_MEMZERO(ar->tcmdResp.buf, sizeof(ar->tcmdResp.buf)); + A_MEMCPY(ar->tcmdResp.buf, tCmd->buf, sizeof(ar->tcmdResp.buf)); + ar->tcmdRxReport = 1; + } + else { /*(rx_rep->act == TCMD_CONT_RX_REPORT) */ + if (enablerssicompensation) { + rx_rep->u.report.rssiInDBm = rssi_compensation_calc_tcmd(ar, tcmdRxFreq, rx_rep->u.report.rssiInDBm,rx_rep->u.report.totalPkt); + } + + + ar->tcmdRxTotalPkt = rx_rep->u.report.totalPkt; + ar->tcmdRxRssi = rx_rep->u.report.rssiInDBm; + ar->tcmdRxcrcErrPkt = rx_rep->u.report.crcErrPkt; + ar->tcmdRxsecErrPkt = rx_rep->u.report.secErrPkt; + ar->tcmdRxReport = 1; + A_MEMZERO(ar->tcmdRateCnt, sizeof(ar->tcmdRateCnt)); + A_MEMZERO(ar->tcmdRateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + A_MEMCPY(ar->tcmdRateCnt, rx_rep->u.report.rateCnt, sizeof(ar->tcmdRateCnt)); + A_MEMCPY(ar->tcmdRateCntShortGuard, rx_rep->u.report.rateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + } + + wake_up(&arPriv->arEvent); +} +#endif /* CONFIG_HOST_TCMD_SUPPORT*/ + +static int +ar6000_ioctl_set_error_report_bitmask(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_TARGET_ERROR_REPORT_BITMASK cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_set_error_report_bitmask(arPriv->arWmi, cmd.bitmask); + + return (ret==0 ? ret : -EINVAL); +} + +static int +ar6000_clear_target_stats(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + TARGET_STATS *pStats = &arPriv->arTargetStats; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + A_MEMZERO(pStats, sizeof(TARGET_STATS)); + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + return ret; +} + +static int +ar6000_ioctl_get_target_stats(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + TARGET_STATS_CMD cmd; + TARGET_STATS *pStats = &arPriv->arTargetStats; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + arPriv->statsUpdatePending = TRUE; + + if(wmi_get_stats_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(rq->ifr_data, pStats, sizeof(*pStats))) { + ret = -EFAULT; + } + + if (cmd.clearStats == 1) { + ret = ar6000_clear_target_stats(dev); + } + + up(&ar->arSem); + + a_meminfo_report(FALSE); + + return ret; +} + +static int +ar6000_ioctl_get_ap_stats(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + A_UINT32 action; /* Allocating only the desired space on the frame. Declaring is as a WMI_AP_MODE_STAT variable results in exceeding the compiler imposed limit on the maximum frame size */ + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_PER_STA_STAT *pStats = ar->arAPStats; + WMI_AP_MODE_STAT ret_stat; + A_UINT8 i, j=0; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&action, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(A_UINT32))) + { + return -EFAULT; + } + if (action == AP_CLEAR_STATS) { + AR6000_SPIN_LOCK(&ar->arLock, 0); + for(i = 0; i < NUM_CONN; i++) { + if(ar->connTbl[i].arPriv == arPriv) { + pStats[i].tx_bytes = 0; + pStats[i].tx_pkts = 0; + pStats[i].tx_error = 0; + pStats[i].tx_discard = 0; + pStats[i].rx_bytes = 0; + pStats[i].rx_pkts = 0; + pStats[i].rx_error = 0; + pStats[i].rx_discard = 0; + } + } + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + return ret; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + arPriv->statsUpdatePending = TRUE; + + if(wmi_get_stats_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + A_MEMZERO(&ret_stat, sizeof(ret_stat)); + for(i = 0; i < NUM_CONN; i++) { + if(ar->connTbl[i].arPriv == arPriv) { + ret_stat.sta[j].aid = pStats[i].aid; + ret_stat.sta[j].tx_bytes = pStats[i].tx_bytes; + ret_stat.sta[j].tx_pkts = pStats[i].tx_pkts; + ret_stat.sta[j].tx_error = pStats[i].tx_error; + ret_stat.sta[j].tx_discard = pStats[i].tx_discard; + ret_stat.sta[j].rx_bytes = pStats[i].rx_bytes; + ret_stat.sta[j].rx_pkts = pStats[i].rx_pkts; + ret_stat.sta[j].rx_error = pStats[i].rx_error; + ret_stat.sta[j].rx_discard = pStats[i].rx_discard; + j++; + } + } + + if (!ret && copy_to_user(rq->ifr_data, &ret_stat, sizeof(ret_stat))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return ret; +} + +static int +ar6000_ioctl_set_access_params(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_ACCESS_PARAMS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_access_params_cmd(arPriv->arWmi, cmd.ac, cmd.txop, cmd.eCWmin, cmd.eCWmax, + cmd.aifsn) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_ioctl_set_disconnect_timeout(struct net_device *dev, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_DISC_TIMEOUT_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_disctimeout_cmd(arPriv->arWmi, cmd.disconnectTimeout) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_voice_pkt_size(struct net_device *dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_VOICE_PKT_SIZE_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_voice_pkt_size_cmd(arPriv->arWmi, cmd.voicePktSize) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + + return (ret); +} + +static int +ar6000_xioctl_set_max_sp_len(struct net_device *dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_MAX_SP_LEN_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_max_sp_len_cmd(arPriv->arWmi, cmd.maxSPLen) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + + +static int +ar6000_xioctl_set_bt_status_cmd(struct net_device *dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BT_STATUS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_bt_status_cmd(arPriv->arWmi, cmd.streamType, cmd.status) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_bt_params_cmd(struct net_device *dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BT_PARAMS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_bt_params_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_btcoex_fe_ant_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_FE_ANT_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_fe_ant_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_colocated_bt_dev_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_colocated_bt_dev_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_btinquiry_page_config_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_btinquiry_page_config_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_sco_config_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_SCO_CONFIG_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_sco_config_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_a2dp_config_cmd(struct net_device * dev, + char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_A2DP_CONFIG_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_a2dp_config_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_aclcoex_config_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_aclcoex_config_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar60000_xioctl_set_btcoex_debug_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_DEBUG_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_debug_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_bt_operating_status_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD cmd; + int ret = 0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_bt_operating_status_cmd(arPriv->arWmi, &cmd) == A_OK) + { + ret = 0; + } else { + ret = -EINVAL; + } + return(ret); +} + +static int +ar6000_xioctl_get_btcoex_config_cmd(struct net_device * dev, char * userdata, + struct ifreq *rq) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR6000_BTCOEX_CONFIG btcoexConfig; + WMI_BTCOEX_CONFIG_EVENT *pbtcoexConfigEv = &arPriv->arBtcoexConfig; + + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + if (ar->arWmiReady == FALSE) { + return -EIO; + } + if (copy_from_user(&btcoexConfig.configCmd, userdata, sizeof(AR6000_BTCOEX_CONFIG))) { + return -EFAULT; + } + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (wmi_get_btcoex_config_cmd(arPriv->arWmi, (WMI_GET_BTCOEX_CONFIG_CMD *)&btcoexConfig.configCmd) != A_OK) + { + up(&ar->arSem); + return -EIO; + } + + arPriv->statsUpdatePending = TRUE; + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(btcoexConfig.configEvent, pbtcoexConfigEv, sizeof(WMI_BTCOEX_CONFIG_EVENT))) { + ret = -EFAULT; + } + up(&ar->arSem); + return ret; +} + +static int +ar6000_xioctl_get_btcoex_stats_cmd(struct net_device * dev, char * userdata, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR6000_BTCOEX_STATS btcoexStats; + WMI_BTCOEX_STATS_EVENT *pbtcoexStats = &arPriv->arBtcoexStats; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (copy_from_user(&btcoexStats.statsEvent, userdata, sizeof(AR6000_BTCOEX_CONFIG))) { + return -EFAULT; + } + + if (wmi_get_btcoex_stats_cmd(arPriv->arWmi) != A_OK) + { + up(&ar->arSem); + return -EIO; + } + + arPriv->statsUpdatePending = TRUE; + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(btcoexStats.statsEvent, pbtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT))) { + ret = -EFAULT; + } + + + up(&ar->arSem); + + return(ret); +} + +static int +ar6000_xioctl_set_excess_tx_retry_thres_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_SET_EXCESS_TX_RETRY_THRES_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_excess_tx_retry_thres_cmd(arPriv->arWmi, &cmd) != A_OK) + { + ret = -EINVAL; + } + return(ret); +} + +static int +ar6000_xioctl_wac_ctrl_req_get_cmd(struct net_device * dev, char * userdata, struct ifreq *rq) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_WAC_CTRL_REQ_CMD cmd; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (copy_from_user(&cmd, userdata, sizeof(WMI_WAC_CTRL_REQ_CMD))) { + return -EFAULT; + } + + if (wmi_wac_ctrl_req_cmd(arPriv->arWmi, &cmd) != A_OK) + { + up(&ar->arSem); + return -EIO; + } + + arPriv->statsUpdatePending = TRUE; + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->statsUpdatePending == FALSE, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(rq->ifr_data, &arPriv->wacInfo, sizeof(WMI_GET_WAC_INFO))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return(ret); +} + +static int +ar6000_xioctl_set_passphrase_cmd(struct net_device * dev, char * userdata) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + WMI_SET_PASSPHRASE_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_passphrase_cmd(arPriv->arWmi, &cmd) == A_OK) + { + /* enable WPA offload */ + arSta->arConnectCtrlFlags |= CONNECT_DO_WPA_OFFLOAD; + ret = 0; + } else { + ret = -EINVAL; + } + return(ret); +} + +#ifdef CONFIG_HOST_GPIO_SUPPORT +struct ar6000_gpio_intr_wait_cmd_s gpio_intr_results; +/* gpio_reg_results and gpio_data_available are protected by arSem */ +static struct ar6000_gpio_register_cmd_s gpio_reg_results; +static A_BOOL gpio_data_available; /* Requested GPIO data available */ +static A_BOOL gpio_intr_available; /* GPIO interrupt info available */ +static A_BOOL gpio_ack_received; /* GPIO ack was received */ + +/* Host-side initialization for General Purpose I/O support */ +void ar6000_gpio_init(void) +{ + gpio_intr_available = FALSE; + gpio_data_available = FALSE; + gpio_ack_received = FALSE; +} + +/* + * Called when a GPIO interrupt is received from the Target. + * intr_values shows which GPIO pins have interrupted. + * input_values shows a recent value of GPIO pins. + */ +void +ar6000_gpio_intr_rx(AR_SOFTC_DEV_T *arPriv, A_UINT32 intr_mask, A_UINT32 input_values) +{ + gpio_intr_results.intr_mask = intr_mask; + gpio_intr_results.input_values = input_values; + *((volatile A_BOOL *)&gpio_intr_available) = TRUE; + wake_up(&arPriv->arEvent); +} + +/* + * This is called when a response is received from the Target + * for a previous or ar6000_gpio_input_get or ar6000_gpio_register_get + * call. + */ +void +ar6000_gpio_data_rx(AR_SOFTC_DEV_T *arPriv, A_UINT32 reg_id, A_UINT32 value) +{ + gpio_reg_results.gpioreg_id = reg_id; + gpio_reg_results.value = value; + *((volatile A_BOOL *)&gpio_data_available) = TRUE; + wake_up(&arPriv->arEvent); +} + +/* + * This is called when an acknowledgement is received from the Target + * for a previous or ar6000_gpio_output_set or ar6000_gpio_register_set + * call. + */ +void +ar6000_gpio_ack_rx(AR_SOFTC_DEV_T *arPriv) +{ + gpio_ack_received = TRUE; + wake_up(&arPriv->arEvent); +} + +A_STATUS +ar6000_gpio_output_set(struct net_device *dev, + A_UINT32 set_mask, + A_UINT32 clear_mask, + A_UINT32 enable_mask, + A_UINT32 disable_mask) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + gpio_ack_received = FALSE; + return wmi_gpio_output_set(arPriv->arWmi, + set_mask, clear_mask, enable_mask, disable_mask); +} + +static A_STATUS +ar6000_gpio_input_get(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + *((volatile A_BOOL *)&gpio_data_available) = FALSE; + return wmi_gpio_input_get(arPriv->arWmi); +} + +static A_STATUS +ar6000_gpio_register_set(struct net_device *dev, + A_UINT32 gpioreg_id, + A_UINT32 value) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + gpio_ack_received = FALSE; + return wmi_gpio_register_set(arPriv->arWmi, gpioreg_id, value); +} + +static A_STATUS +ar6000_gpio_register_get(struct net_device *dev, + A_UINT32 gpioreg_id) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + *((volatile A_BOOL *)&gpio_data_available) = FALSE; + return wmi_gpio_register_get(arPriv->arWmi, gpioreg_id); +} + +static A_STATUS +ar6000_gpio_intr_ack(struct net_device *dev, + A_UINT32 ack_mask) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + gpio_intr_available = FALSE; + return wmi_gpio_intr_ack(arPriv->arWmi, ack_mask); +} +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +static struct prof_count_s prof_count_results; +static A_BOOL prof_count_available; /* Requested GPIO data available */ + +static A_STATUS +prof_count_get(struct net_device *dev) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + + *((volatile A_BOOL *)&prof_count_available) = FALSE; + return wmi_prof_count_get_cmd(arPriv->arWmi); +} + +/* + * This is called when a response is received from the Target + * for a previous prof_count_get call. + */ +void +prof_count_rx(A_UINT32 addr, A_UINT32 count) +{ + prof_count_results.addr = addr; + prof_count_results.count = count; + *((volatile A_BOOL *)&prof_count_available) = TRUE; + wake_up(&arEvent); +} +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ + + +static A_STATUS +ar6000_create_acl_data_osbuf(struct net_device *dev, A_UINT8 *userdata, void **p_osbuf) +{ + void *osbuf = NULL; + A_UINT8 tmp_space[8]; + HCI_ACL_DATA_PKT *acl; + A_UINT8 hdr_size, *datap=NULL; + A_STATUS ret = A_OK; + + /* ACL is in data path. There is a need to create pool + * mechanism for allocating and freeing NETBUFs - ToDo later. + */ + + *p_osbuf = NULL; + acl = (HCI_ACL_DATA_PKT *)tmp_space; + hdr_size = sizeof(acl->hdl_and_flags) + sizeof(acl->data_len); + + do { + if (a_copy_from_user(acl, userdata, hdr_size)) { + ret = A_EFAULT; + break; + } + + osbuf = A_NETBUF_ALLOC(hdr_size + acl->data_len); + if (osbuf == NULL) { + ret = A_NO_MEMORY; + break; + } + A_NETBUF_PUT(osbuf, hdr_size + acl->data_len); + datap = (A_UINT8 *)A_NETBUF_DATA(osbuf); + + /* Real copy to osbuf */ + acl = (HCI_ACL_DATA_PKT *)(datap); + A_MEMCPY(acl, tmp_space, hdr_size); + if (a_copy_from_user(acl->data, userdata + hdr_size, acl->data_len)) { + ret = A_EFAULT; + break; + } + } while(FALSE); + + if (ret == A_OK) { + *p_osbuf = osbuf; + } else { + A_NETBUF_FREE(osbuf); + } + return ret; +} + + + +int +ar6000_ioctl_ap_setparam(AR_SOFTC_DEV_T *arPriv, int param, int value) +{ + int ret=0; + + switch(param) { + case IEEE80211_PARAM_WPA: + switch (value) { + case WPA_MODE_WPA1: + arPriv->arAuthMode = WMI_WPA_AUTH; + break; + case WPA_MODE_WPA2: + arPriv->arAuthMode = WMI_WPA2_AUTH; + break; + case WPA_MODE_AUTO: + arPriv->arAuthMode = WMI_WPA_AUTH | WMI_WPA2_AUTH; + break; + case WPA_MODE_NONE: + arPriv->arAuthMode = WMI_NONE_AUTH; + break; + } + break; + case IEEE80211_PARAM_AUTHMODE: + if(value == IEEE80211_AUTH_WPA_PSK) { + if (WMI_WPA_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_PSK_AUTH; + } else if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_PSK_AUTH; + } else if ((WMI_WPA_AUTH | WMI_WPA2_AUTH) == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_PSK_AUTH | WMI_WPA2_PSK_AUTH; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error - Setting PSK "\ + "mode when WPA param was set to %d\n", + arPriv->arAuthMode)); + ret = -EIO; + } + } + break; + case IEEE80211_PARAM_UCASTCIPHER: + arPriv->arPairwiseCrypto = 0; + if(value & (1<arPairwiseCrypto |= AES_CRYPT; + } + if(value & (1<arPairwiseCrypto |= TKIP_CRYPT; + } + if(!arPriv->arPairwiseCrypto) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Error - Invalid cipher in WPA \n")); + ret = -EIO; + } + break; + case IEEE80211_PARAM_PRIVACY: + if(value == 0) { + arPriv->arDot11AuthMode = OPEN_AUTH; + arPriv->arAuthMode = WMI_NONE_AUTH; + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arGroupCryptoLen = 0; + } + break; +#ifdef WAPI_ENABLE + case IEEE80211_PARAM_WAPI: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WAPI Policy: %d\n", value)); + arPriv->arDot11AuthMode = OPEN_AUTH; + arPriv->arAuthMode = WMI_NONE_AUTH; + if(value & 0x1) { + arPriv->arPairwiseCrypto = WAPI_CRYPT; + arPriv->arGroupCrypto = WAPI_CRYPT; + } else { + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arGroupCrypto = NONE_CRYPT; + } + break; +#endif + } + return ret; +} + +int +ar6000_ioctl_setparam(AR_SOFTC_DEV_T *arPriv, int param, int value) +{ + A_BOOL profChanged = FALSE; + int ret=0; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if(arPriv->arNextMode == AP_NETWORK) { + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + switch (param) { + case IEEE80211_PARAM_WPA: + case IEEE80211_PARAM_AUTHMODE: + case IEEE80211_PARAM_UCASTCIPHER: + case IEEE80211_PARAM_PRIVACY: + case IEEE80211_PARAM_WAPI: + ret = ar6000_ioctl_ap_setparam(arPriv, param, value); + return ret; + } + } + + switch (param) { + case IEEE80211_PARAM_WPA: + switch (value) { + case WPA_MODE_WPA1: + arPriv->arAuthMode = WMI_WPA_AUTH; + profChanged = TRUE; + break; + case WPA_MODE_WPA2: + arPriv->arAuthMode = WMI_WPA2_AUTH; + profChanged = TRUE; + break; + case WPA_MODE_NONE: + arPriv->arAuthMode = WMI_NONE_AUTH; + profChanged = TRUE; + break; + } + break; + case IEEE80211_PARAM_AUTHMODE: + switch(value) { + case IEEE80211_AUTH_WPA_PSK: + if (WMI_WPA_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_PSK_AUTH; + profChanged = TRUE; + } else if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_PSK_AUTH; + profChanged = TRUE; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error - Setting PSK "\ + "mode when WPA param was set to %d\n", + arPriv->arAuthMode)); + ret = -EIO; + } + break; + case IEEE80211_AUTH_WPA_CCKM: + if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_AUTH_CCKM; + } else { + arPriv->arAuthMode = WMI_WPA_AUTH_CCKM; + } + break; + default: + break; + } + break; + case IEEE80211_PARAM_UCASTCIPHER: + switch (value) { + case IEEE80211_CIPHER_AES_CCM: + arPriv->arPairwiseCrypto = AES_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_TKIP: + arPriv->arPairwiseCrypto = TKIP_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_WEP: + arPriv->arPairwiseCrypto = WEP_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_NONE: + arPriv->arPairwiseCrypto = NONE_CRYPT; + profChanged = TRUE; + break; + } + break; + case IEEE80211_PARAM_UCASTKEYLEN: + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(value)) { + ret = -EIO; + } else { + arPriv->arPairwiseCryptoLen = value; + } + break; + case IEEE80211_PARAM_MCASTCIPHER: + switch (value) { + case IEEE80211_CIPHER_AES_CCM: + arPriv->arGroupCrypto = AES_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_TKIP: + arPriv->arGroupCrypto = TKIP_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_WEP: + arPriv->arGroupCrypto = WEP_CRYPT; + profChanged = TRUE; + break; + case IEEE80211_CIPHER_NONE: + arPriv->arGroupCrypto = NONE_CRYPT; + profChanged = TRUE; + break; + } + break; + case IEEE80211_PARAM_MCASTKEYLEN: + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(value)) { + ret = -EIO; + } else { + arPriv->arGroupCryptoLen = value; + } + break; + case IEEE80211_PARAM_COUNTERMEASURES: + if (ar->arWmiReady == FALSE) { + return -EIO; + } + wmi_set_tkip_countermeasures_cmd(arPriv->arWmi, value); + break; + default: + break; + } + if ((arPriv->arNextMode != AP_NETWORK) && (profChanged == TRUE)) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + } + + return ret; +} + +int +ar6000_sendkey(AR_SOFTC_DEV_T *arPriv, struct ieee80211req_key *ik, KEY_USAGE keyUsage) +{ + A_STATUS status; + CRYPTO_TYPE keyType = NONE_CRYPT; + + switch (ik->ik_type) { + case IEEE80211_CIPHER_WEP: + keyType = WEP_CRYPT; + break; + case IEEE80211_CIPHER_TKIP: + keyType = TKIP_CRYPT; + break; + case IEEE80211_CIPHER_AES_CCM: + keyType = AES_CRYPT; + break; + default: + break; + } + + if (IEEE80211_CIPHER_CCKM_KRK != ik->ik_type) { + if (NONE_CRYPT == keyType) { + return A_ERROR; + } + + if ((WEP_CRYPT == keyType)&&(!arPriv->arConnected)) { + int index = ik->ik_keyix; + + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(ik->ik_keylen)) { + return A_ERROR; + } + + A_MEMZERO(arPriv->arWepKeyList[index].arKey, + sizeof(arPriv->arWepKeyList[index].arKey)); + A_MEMCPY(arPriv->arWepKeyList[index].arKey, ik->ik_keydata, ik->ik_keylen); + arPriv->arWepKeyList[index].arKeyLen = ik->ik_keylen; + + if(ik->ik_flags & IEEE80211_KEY_DEFAULT){ + arPriv->arDefTxKeyIndex = index; + } + + return A_OK; + } + + status = wmi_addKey_cmd(arPriv->arWmi, ik->ik_keyix, keyType, keyUsage, + ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc, + ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, + SYNC_BOTH_WMIFLAG); + + } else { + status = wmi_add_krk_cmd(arPriv->arWmi, ik->ik_keydata); + } + + return status; +} + +int +ar6000_ioctl_setkey(AR_SOFTC_DEV_T *arPriv, struct ieee80211req_key *ik) +{ + KEY_USAGE keyUsage; + A_STATUS status; + CRYPTO_TYPE keyType = NONE_CRYPT; + + if ( (0 == memcmp(ik->ik_macaddr, null_mac, IEEE80211_ADDR_LEN)) || + (0 == memcmp(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN)) ) { + keyUsage = GROUP_USAGE; + } else { + keyUsage = PAIRWISE_USAGE; + } + + if(arPriv->arNextMode == AP_NETWORK) { + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + + if (keyUsage == GROUP_USAGE) { + A_MEMCPY(&arAp->ap_mode_bkey, ik, sizeof(struct ieee80211req_key)); + } + + #ifdef WAPI_ENABLE + if(arPriv->arPairwiseCrypto == WAPI_CRYPT) { + return ap_set_wapi_key(arPriv, ik); + } + #endif + + status = ar6000_sendkey(arPriv, ik, keyUsage); + + } else { + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + + #ifdef USER_KEYS + arSta->user_saved_keys.keyOk = FALSE; + arSta->user_saved_keys.keyType = keyType; + if (keyUsage == GROUP_USAGE) { + A_MEMCPY(&arSta->user_saved_keys.bcast_ik, ik, + sizeof(struct ieee80211req_key)); + } else { + A_MEMCPY(&arSta->user_saved_keys.ucast_ik, ik, + sizeof(struct ieee80211req_key)); + } + #endif + + if (((WMI_WPA_PSK_AUTH == arPriv->arAuthMode) || + (WMI_WPA2_PSK_AUTH == arPriv->arAuthMode)) && + (GROUP_USAGE & keyUsage)) + { + A_UNTIMEOUT(&arSta->disconnect_timer); + } + + status = ar6000_sendkey(arPriv, ik, keyUsage); + + #ifdef USER_KEYS + if (status == A_OK) { + arSta->user_saved_keys.keyOk = TRUE; + } + #endif + } + + if (status != A_OK) { + return -EIO; + } + + return 0; +} + +int ar6000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + HIF_DEVICE *hifDevice = ar->arHifDevice; + int ret = 0, param; + unsigned int address = 0; + unsigned int length = 0; + unsigned char *buffer; + char *userdata; + + /* + * ioctl operations may have to wait for the Target, so we cannot hold rtnl. + * Prevent the device from disappearing under us and release the lock during + * the ioctl operation. + */ + dev_hold(dev); + rtnl_unlock(); + + if (cmd == AR6000_IOCTL_EXTENDED) { + /* + * This allows for many more wireless ioctls than would otherwise + * be available. Applications embed the actual ioctl command in + * the first word of the parameter block, and use the command + * AR6000_IOCTL_EXTENDED_CMD on the ioctl call. + */ + get_user(cmd, (int *)rq->ifr_data); + userdata = (char *)(((unsigned int *)rq->ifr_data)+1); + if(is_xioctl_allowed(arPriv->arNextMode, + arPriv->arNetworkSubType, cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("xioctl: cmd=%d not allowed in this mode\n",cmd)); + ret = -EOPNOTSUPP; + goto ioctl_done; + } + } else { + A_STATUS ret = is_iwioctl_allowed(arPriv->arNextMode, cmd); + if(ret == A_ENOTSUP) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("iwioctl: cmd=0x%x not allowed in this mode\n", cmd)); + ret = -EOPNOTSUPP; + goto ioctl_done; + } else if (ret == A_ERROR) { + /* It is not our ioctl (out of range ioctl) */ + ret = -EOPNOTSUPP; + goto ioctl_done; + } + userdata = (char *)rq->ifr_data; + } + + if ((ar->arWlanState == WLAN_DISABLED) && + ((cmd != AR6000_XIOCTRL_WMI_SET_WLAN_STATE) && + (cmd != AR6000_XIOCTL_GET_WLAN_SLEEP_STATE) && + (cmd != AR6000_XIOCTL_DIAG_READ) && + (cmd != AR6000_XIOCTL_DIAG_WRITE) && + (cmd != AR6000_XIOCTL_SET_BT_HW_POWER_STATE) && + (cmd != AR6000_XIOCTL_GET_BT_HW_POWER_STATE) && + (cmd != AR6000_IOCTL_WMI_GETREV) && + (cmd != AR6000_XIOCTL_RESUME_DRIVER))) + { + ret = -EIO; + goto ioctl_done; + } + + + ret = 0; + switch(cmd) + { + case IEEE80211_IOCTL_SETPARAM: + { + int param, value; + int *ptr = (int *)rq->ifr_ifru.ifru_newname; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else { + param = *ptr++; + value = *ptr; + ret = ar6000_ioctl_setparam(arPriv,param,value); + } + break; + } + case IEEE80211_IOCTL_SETKEY: + { + struct ieee80211req_key keydata; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&keydata, userdata, + sizeof(struct ieee80211req_key))) { + ret = -EFAULT; + } else { + ar6000_ioctl_setkey(arPriv, &keydata); + } + break; + } + case IEEE80211_IOCTL_DELKEY: + case IEEE80211_IOCTL_SETOPTIE: + { + //ret = -EIO; + break; + } + case IEEE80211_IOCTL_SETMLME: + { + struct ieee80211req_mlme mlme; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&mlme, userdata, + sizeof(struct ieee80211req_mlme))) { + ret = -EFAULT; + } else { + switch (mlme.im_op) { + case IEEE80211_MLME_AUTHORIZE: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("setmlme AUTHORIZE %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5])); + break; + case IEEE80211_MLME_UNAUTHORIZE: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("setmlme UNAUTHORIZE %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5])); + break; + case IEEE80211_MLME_DEAUTH: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("setmlme DEAUTH %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5])); + //remove_sta(ar, mlme.im_macaddr); + break; + case IEEE80211_MLME_DISASSOC: + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("setmlme DISASSOC %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5])); + //remove_sta(ar, mlme.im_macaddr); + break; + default: + ret = 0; + goto ioctl_done; + } + + wmi_ap_set_mlme(arPriv->arWmi, mlme.im_op, mlme.im_macaddr, + mlme.im_reason); + } + break; + } + case IEEE80211_IOCTL_ADDPMKID: + { + struct ieee80211req_addpmkid req; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&req, userdata, sizeof(struct ieee80211req_addpmkid))) { + ret = -EFAULT; + } else { + A_STATUS status; + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Add pmkid for %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x en=%d\n", + req.pi_bssid[0], req.pi_bssid[1], req.pi_bssid[2], + req.pi_bssid[3], req.pi_bssid[4], req.pi_bssid[5], + req.pi_enable)); + + status = wmi_setPmkid_cmd(arPriv->arWmi, req.pi_bssid, req.pi_pmkid, + req.pi_enable); + + if (status != A_OK) { + ret = -EIO; + goto ioctl_done; + } + } + break; + } +#ifdef CONFIG_HOST_TCMD_SUPPORT + case AR6000_XIOCTL_TCMD_CONT_TX: + { + TCMD_CONT_TX txCmd; + + if ((ar->tcmdPm == TCMD_PM_SLEEP) || + (ar->tcmdPm == TCMD_PM_DEEPSLEEP)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Can NOT send tx tcmd when target is asleep! \n")); + ret = -EOPNOTSUPP; + goto ioctl_done; + } + + if(copy_from_user(&txCmd, userdata, sizeof(TCMD_CONT_TX))) { + ret = -EFAULT; + goto ioctl_done; + } else { + wmi_test_cmd(arPriv->arWmi,(A_UINT8 *)&txCmd, sizeof(TCMD_CONT_TX)); + } + } + break; + case AR6000_XIOCTL_TCMD_CONT_RX: + { + TCMD_CONT_RX rxCmd; + + if ((ar->tcmdPm == TCMD_PM_SLEEP) || + (ar->tcmdPm == TCMD_PM_DEEPSLEEP)) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Can NOT send rx tcmd when target is asleep! \n")); + ret = -EOPNOTSUPP; + goto ioctl_done; + } + if(copy_from_user(&rxCmd, userdata, sizeof(TCMD_CONT_RX))) { + ret = -EFAULT; + goto ioctl_done; + } + + switch(rxCmd.act) + { + case TCMD_CONT_RX_PROMIS: + case TCMD_CONT_RX_FILTER: + case TCMD_CONT_RX_SETMAC: + case TCMD_CONT_RX_SET_ANT_SWITCH_TABLE: + wmi_test_cmd(arPriv->arWmi,(A_UINT8 *)&rxCmd, + sizeof(TCMD_CONT_RX)); + tcmdRxFreq = rxCmd.u.para.freq; + break; + case TCMD_CONT_RX_REPORT: + ar6000_ioctl_tcmd_get_rx_report(dev, rq, + (A_UINT8 *)&rxCmd, sizeof(TCMD_CONT_RX)); + break; + default: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unknown Cont Rx mode: %d\n",rxCmd.act)); + ret = -EINVAL; + goto ioctl_done; + } + } + break; + case AR6000_XIOCTL_TCMD_PM: + { + TCMD_PM pmCmd; + + if(copy_from_user(&pmCmd, userdata, sizeof(TCMD_PM))) { + ret = -EFAULT; + goto ioctl_done; + } + ar->tcmdPm = pmCmd.mode; + wmi_test_cmd(arPriv->arWmi, (A_UINT8*)&pmCmd, sizeof(TCMD_PM)); + } + break; + + case AR6000_XIOCTL_TCMD_CMDS: + { + TC_CMDS cmdsCmd; + if(copy_from_user(&cmdsCmd, userdata, sizeof(TC_CMDS))) { + ret = -EFAULT; + goto ioctl_done; + } + ar6000_ioctl_tcmd_cmd_resp(dev, rq, (A_UINT8 *)&cmdsCmd, sizeof(TC_CMDS)); +#if 0 + wmi_test_cmd(arPriv->arWmi, (A_UINT8*)&cmdsCmd, sizeof(TC_CMDS)); +#endif + } + break; + + case AR6000_XIOCTL_TCMD_SETREG: + { + TCMD_SET_REG setRegCmd; + + if(copy_from_user(&setRegCmd, userdata, sizeof(TCMD_SET_REG))) { + ret = -EFAULT; + goto ioctl_done; + } + wmi_test_cmd(arPriv->arWmi, (A_UINT8*)&setRegCmd, sizeof(TCMD_SET_REG)); + } + break; +#endif /* CONFIG_HOST_TCMD_SUPPORT */ + + case AR6000_XIOCTL_BMI_DONE: + if(bmienable) + { + rtnl_lock(); /* ar6000_init expects to be called holding rtnl lock */ + ret = ar6000_init(dev); + rtnl_unlock(); + } + else + { + ret = BMIDone(hifDevice); + } + break; + + case AR6000_XIOCTL_BMI_READ_MEMORY: + get_user(address, (unsigned int *)userdata); + get_user(length, (unsigned int *)userdata + 1); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Read Memory (address: 0x%x, length: %d)\n", + address, length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + ret = BMIReadMemory(hifDevice, address, buffer, length); + if (copy_to_user(rq->ifr_data, buffer, length)) { + ret = -EFAULT; + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + + case AR6000_XIOCTL_BMI_WRITE_MEMORY: + get_user(address, (unsigned int *)userdata); + get_user(length, (unsigned int *)userdata + 1); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Write Memory (address: 0x%x, length: %d)\n", + address, length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(address) + + sizeof(length)], length)) + { + ret = -EFAULT; + } else { + ret = BMIWriteMemory(hifDevice, address, buffer, length); + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + + case AR6000_XIOCTL_BMI_TEST: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("No longer supported\n")); + ret = -EOPNOTSUPP; + break; + + case AR6000_XIOCTL_BMI_EXECUTE: + get_user(address, (unsigned int *)userdata); + get_user(param, (unsigned int *)userdata + 1); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Execute (address: 0x%x, param: %d)\n", + address, param)); + ret = BMIExecute(hifDevice, address, (A_UINT32*)¶m); + put_user(param, (unsigned int *)rq->ifr_data); /* return value */ + break; + + case AR6000_XIOCTL_BMI_SET_APP_START: + get_user(address, (unsigned int *)userdata); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Set App Start (address: 0x%x)\n", address)); + ret = BMISetAppStart(hifDevice, address); + break; + + case AR6000_XIOCTL_BMI_READ_SOC_REGISTER: + get_user(address, (unsigned int *)userdata); + ret = BMIReadSOCRegister(hifDevice, address, (A_UINT32*)¶m); + put_user(param, (unsigned int *)rq->ifr_data); /* return value */ + break; + + case AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER: + get_user(address, (unsigned int *)userdata); + get_user(param, (unsigned int *)userdata + 1); + ret = BMIWriteSOCRegister(hifDevice, address, param); + break; + +#ifdef HTC_RAW_INTERFACE + case AR6000_XIOCTL_HTC_RAW_OPEN: + ret = A_OK; + if (!arRawIfEnabled(ar)) { + /* make sure block size is set in case the target was reset since last + * BMI phase (i.e. flashup downloads) */ + ret = ar6000_set_htc_params(ar->arHifDevice, + ar->arTargetType, + 0, /* use default yield */ + 0 /* use default number of HTC ctrl buffers */ + ); + if (A_FAILED(ret)) { + break; + } + /* Terminate the BMI phase */ + ret = BMIDone(hifDevice); + if (ret == A_OK) { + ret = ar6000_htc_raw_open(ar); + } + } + break; + + case AR6000_XIOCTL_HTC_RAW_CLOSE: + if (arRawIfEnabled(ar)) { + ret = ar6000_htc_raw_close(ar); + arRawIfEnabled(ar) = FALSE; + } else { + ret = A_ERROR; + } + break; + + case AR6000_XIOCTL_HTC_RAW_READ: + if (arRawIfEnabled(ar)) { + unsigned int streamID; + get_user(streamID, (unsigned int *)userdata); + get_user(length, (unsigned int *)userdata + 1); + buffer = (unsigned char*)rq->ifr_data + sizeof(length); + ret = ar6000_htc_raw_read(ar, (HTC_RAW_STREAM_ID)streamID, + (char*)buffer, length); + put_user(ret, (unsigned int *)rq->ifr_data); + } else { + ret = A_ERROR; + } + break; + + case AR6000_XIOCTL_HTC_RAW_WRITE: + if (arRawIfEnabled(ar)) { + unsigned int streamID; + get_user(streamID, (unsigned int *)userdata); + get_user(length, (unsigned int *)userdata + 1); + buffer = (unsigned char*)userdata + sizeof(streamID) + sizeof(length); + ret = ar6000_htc_raw_write(ar, (HTC_RAW_STREAM_ID)streamID, + (char*)buffer, length); + put_user(ret, (unsigned int *)rq->ifr_data); + } else { + ret = A_ERROR; + } + break; +#endif /* HTC_RAW_INTERFACE */ + + case AR6000_XIOCTL_BMI_LZ_STREAM_START: + get_user(address, (unsigned int *)userdata); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Start Compressed Stream (address: 0x%x)\n", address)); + ret = BMILZStreamStart(hifDevice, address); + break; + + case AR6000_XIOCTL_BMI_LZ_DATA: + get_user(length, (unsigned int *)userdata); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Send Compressed Data (length: %d)\n", length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(length)], length)) + { + ret = -EFAULT; + } else { + ret = BMILZData(hifDevice, buffer, length); + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) + /* + * Optional support for Target-side profiling. + * Not needed in production. + */ + + /* Configure Target-side profiling */ + case AR6000_XIOCTL_PROF_CFG: + { + A_UINT32 period; + A_UINT32 nbins; + get_user(period, (unsigned int *)userdata); + get_user(nbins, (unsigned int *)userdata + 1); + + if (wmi_prof_cfg_cmd(arPriv->arWmi, period, nbins) != A_OK) { + ret = -EIO; + } + + break; + } + + /* Start a profiling bucket/bin at the specified address */ + case AR6000_XIOCTL_PROF_ADDR_SET: + { + A_UINT32 addr; + get_user(addr, (unsigned int *)userdata); + + if (wmi_prof_addr_set_cmd(arPriv->arWmi, addr) != A_OK) { + ret = -EIO; + } + + break; + } + + /* START Target-side profiling */ + case AR6000_XIOCTL_PROF_START: + wmi_prof_start_cmd(arPriv->arWmi); + break; + + /* STOP Target-side profiling */ + case AR6000_XIOCTL_PROF_STOP: + wmi_prof_stop_cmd(arPriv->arWmi); + break; + case AR6000_XIOCTL_PROF_COUNT_GET: + { + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + prof_count_available = FALSE; + ret = prof_count_get(dev); + if (ret != A_OK) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arPriv->arEvent, prof_count_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + if (copy_to_user(userdata, &prof_count_results, + sizeof(prof_count_results))) + { + ret = -EFAULT; + } + } + up(&ar->arSem); + break; + } +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ + + case AR6000_IOCTL_WMI_GETREV: + { + if (copy_to_user(rq->ifr_data, &ar->arVersion, + sizeof(ar->arVersion))) + { + ret = -EFAULT; + } + break; + } + case AR6000_IOCTL_WMI_SETPWR: + { + WMI_POWER_MODE_CMD pwrModeCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&pwrModeCmd, userdata, + sizeof(pwrModeCmd))) + { + ret = -EFAULT; + } else { + if (wmi_powermode_cmd(arPriv->arWmi, pwrModeCmd.powerMode) + != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SET_IBSS_PM_CAPS: + { + WMI_IBSS_PM_CAPS_CMD ibssPmCaps; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&ibssPmCaps, userdata, + sizeof(ibssPmCaps))) + { + ret = -EFAULT; + } else { + if (wmi_ibsspmcaps_cmd(arPriv->arWmi, ibssPmCaps.power_saving, ibssPmCaps.ttl, + ibssPmCaps.atim_windows, ibssPmCaps.timeout_value) != A_OK) + { + ret = -EIO; + } + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arPriv->arSta.arIbssPsEnable = ibssPmCaps.power_saving; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + } + break; + } + case AR6000_XIOCTL_WMI_SET_AP_PS: + { + WMI_AP_PS_CMD apPsCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&apPsCmd, userdata, + sizeof(apPsCmd))) + { + ret = -EFAULT; + } else { + if (wmi_apps_cmd(arPriv->arWmi, apPsCmd.psType, apPsCmd.idle_time, + apPsCmd.ps_period, apPsCmd.sleep_period) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SET_PMPARAMS: + { + WMI_POWER_PARAMS_CMD pmParams; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&pmParams, userdata, + sizeof(pmParams))) + { + ret = -EFAULT; + } else { + if (wmi_pmparams_cmd(arPriv->arWmi, pmParams.idle_period, + pmParams.pspoll_number, + pmParams.dtim_policy, + pmParams.tx_wakeup_policy, + pmParams.num_tx_to_wakeup, +#if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN + IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN +#else + SEND_POWER_SAVE_FAIL_EVENT_ALWAYS +#endif + ) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETSCAN: + { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&arSta->scParams, userdata, + sizeof(arSta->scParams))) + { + ret = -EFAULT; + } else { + if (CAN_SCAN_IN_CONNECT(arSta->scParams.scanCtrlFlags)) { + arSta->arSkipScan = FALSE; + } else { + arSta->arSkipScan = TRUE; + } + + if (wmi_scanparams_cmd(arPriv->arWmi, arSta->scParams.fg_start_period, + arSta->scParams.fg_end_period, + arSta->scParams.bg_period, + arSta->scParams.minact_chdwell_time, + arSta->scParams.maxact_chdwell_time, + arSta->scParams.pas_chdwell_time, + arSta->scParams.shortScanRatio, + arSta->scParams.scanCtrlFlags, + arSta->scParams.max_dfsch_act_time, + arSta->scParams.maxact_scan_per_ssid) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETLISTENINT: + { + WMI_LISTEN_INT_CMD listenCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&listenCmd, userdata, + sizeof(listenCmd))) + { + ret = -EFAULT; + } else { + if (wmi_listeninterval_cmd(arPriv->arWmi, listenCmd.listenInterval, listenCmd.numBeacons) != A_OK) { + ret = -EIO; + } else { + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arSta->arListenIntervalT = listenCmd.listenInterval; + arSta->arListenIntervalB = listenCmd.numBeacons; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + } + + } + break; + } + case AR6000_IOCTL_WMI_SET_BMISS_TIME: + { + WMI_BMISS_TIME_CMD bmissCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&bmissCmd, userdata, + sizeof(bmissCmd))) + { + ret = -EFAULT; + } else { + if (wmi_bmisstime_cmd(arPriv->arWmi, bmissCmd.bmissTime, bmissCmd.numBeacons) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETBSSFILTER: + { + WMI_BSS_FILTER_CMD filt; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&filt, userdata, + sizeof(filt))) + { + ret = -EFAULT; + } else { + if (wmi_bssfilter_cmd(arPriv->arWmi, filt.bssFilter, filt.ieMask) + != A_OK) { + ret = -EIO; + } else { + arSta->arUserBssFilter = filt.bssFilter; + } + } + break; + } + + case AR6000_IOCTL_WMI_SET_SNRTHRESHOLD: + { + ret = ar6000_ioctl_set_snr_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_RSSITHRESHOLD: + { + ret = ar6000_ioctl_set_rssi_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_CLR_RSSISNR: + { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } + ret = wmi_clr_rssi_snr(arPriv->arWmi); + break; + } + case AR6000_XIOCTL_WMI_SET_LQTHRESHOLD: + { + ret = ar6000_ioctl_set_lq_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_LPREAMBLE: + { + WMI_SET_LPREAMBLE_CMD setLpreambleCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setLpreambleCmd, userdata, + sizeof(setLpreambleCmd))) + { + ret = -EFAULT; + } else { + if (wmi_set_lpreamble_cmd(arPriv->arWmi, setLpreambleCmd.status, +#if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP + WMI_DONOT_IGNORE_BARKER_IN_ERP +#else + WMI_IGNORE_BARKER_IN_ERP +#endif + ) != A_OK) + { + ret = -EIO; + } + } + + break; + } + case AR6000_XIOCTL_WMI_SET_RTS: + { + WMI_SET_RTS_CMD rtsCmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&rtsCmd, userdata, + sizeof(rtsCmd))) + { + ret = -EFAULT; + } else { + if(arPriv->arNetworkType == AP_NETWORK) { + arAp->arRTS = rtsCmd.threshold; + } + if (wmi_set_rts_cmd(arPriv->arWmi, rtsCmd.threshold) + != A_OK) + { + ret = -EIO; + } + } + + break; + } + case AR6000_XIOCTL_WMI_SET_WMM: + { + ret = ar6000_ioctl_set_wmm(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_QOS_SUPP: + { + ret = ar6000_ioctl_set_qos_supp(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_TXOP: + { + ret = ar6000_ioctl_set_txop(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_GET_RD: + { + ret = ar6000_ioctl_get_rd(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_CHANNELPARAMS: + { + ret = ar6000_ioctl_set_channelParams(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_PROBEDSSID: + { + ret = ar6000_ioctl_set_probedSsid(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_BADAP: + { + ret = ar6000_ioctl_set_badAp(dev, rq); + break; + } + case AR6000_IOCTL_WMI_CREATE_QOS: + { + ret = ar6000_ioctl_create_qos(dev, rq); + break; + } + case AR6000_IOCTL_WMI_DELETE_QOS: + { + ret = ar6000_ioctl_delete_qos(dev, rq); + break; + } + case AR6000_IOCTL_WMI_GET_QOS_QUEUE: + { + ret = ar6000_ioctl_get_qos_queue(dev, rq); + break; + } + case AR6000_IOCTL_WMI_GET_TARGET_STATS: + { + ret = ar6000_ioctl_get_target_stats(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_ERROR_REPORT_BITMASK: + { + ret = ar6000_ioctl_set_error_report_bitmask(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_ASSOC_INFO: + { + WMI_SET_ASSOC_INFO_CMD cmd; + A_UINT8 assocInfo[WMI_MAX_ASSOC_INFO_LEN]; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else { + get_user(cmd.ieType, userdata); + if (cmd.ieType >= WMI_MAX_ASSOC_INFO_TYPE) { + ret = -EIO; + } else { + get_user(cmd.bufferSize, userdata + 1); + if (cmd.bufferSize > WMI_MAX_ASSOC_INFO_LEN) { + ret = -EFAULT; + break; + } + if (copy_from_user(assocInfo, userdata + 2, + cmd.bufferSize)) + { + ret = -EFAULT; + } else { + if (wmi_associnfo_cmd(arPriv->arWmi, cmd.ieType, + cmd.bufferSize, + assocInfo) != A_OK) + { + ret = -EIO; + } + } + } + } + break; + } + case AR6000_IOCTL_WMI_SET_ACCESS_PARAMS: + { + ret = ar6000_ioctl_set_access_params(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_DISC_TIMEOUT: + { + ret = ar6000_ioctl_set_disconnect_timeout(dev, rq); + break; + } + case AR6000_XIOCTL_FORCE_TARGET_RESET: + { + if (ar->arHtcTarget) + { +// HTCForceReset(htcTarget); + } + else + { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("ar6000_ioctl cannot attempt reset.\n")); + } + break; + } + case AR6000_XIOCTL_TARGET_INFO: + case AR6000_XIOCTL_CHECK_TARGET_READY: /* backwards compatibility */ + { + /* If we made it to here, then the Target exists and is ready. */ + + if (cmd == AR6000_XIOCTL_TARGET_INFO) { + if (copy_to_user((A_UINT32 *)rq->ifr_data, &ar->arVersion.target_ver, + sizeof(ar->arVersion.target_ver))) + { + ret = -EFAULT; + } + if (copy_to_user(((A_UINT32 *)rq->ifr_data)+1, &ar->arTargetType, + sizeof(ar->arTargetType))) + { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS: + { + WMI_SET_HB_CHALLENGE_RESP_PARAMS_CMD hbparam; + + if (copy_from_user(&hbparam, userdata, sizeof(hbparam))) + { + ret = -EFAULT; + } else { + AR6000_SPIN_LOCK(&ar->arLock, 0); + /* Start a cyclic timer with the parameters provided. */ + if (hbparam.frequency) { + ar->arHBChallengeResp.frequency = hbparam.frequency; + } + if (hbparam.threshold) { + ar->arHBChallengeResp.missThres = hbparam.threshold; + } + + /* Delete the pending timer and start a new one */ + if (timer_pending(&ar->arHBChallengeResp.timer)) { + A_UNTIMEOUT(&ar->arHBChallengeResp.timer); + } + A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } + break; + } + case AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP: + { + A_UINT32 cookie; + + if (copy_from_user(&cookie, userdata, sizeof(cookie))) { + ret = -EFAULT; + goto ioctl_done; + } + + /* Send the challenge on the control channel */ + if (wmi_get_challenge_resp_cmd(arPriv->arWmi, cookie, APP_HB_CHALLENGE) != A_OK) { + ret = -EIO; + goto ioctl_done; + } + break; + } +#ifdef USER_KEYS + case AR6000_XIOCTL_USER_SETKEYS: + { + + arSta->user_savedkeys_stat = USER_SAVEDKEYS_STAT_RUN; + + if (copy_from_user(&arSta->user_key_ctrl, userdata, + sizeof(arSta->user_key_ctrl))) + { + ret = -EFAULT; + goto ioctl_done; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000 USER set key %x\n", arSta->user_key_ctrl)); + break; + } +#endif /* USER_KEYS */ + +#ifdef CONFIG_HOST_GPIO_SUPPORT + case AR6000_XIOCTL_GPIO_OUTPUT_SET: + { + struct ar6000_gpio_output_set_cmd_s gpio_output_set_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_output_set_cmd, userdata, + sizeof(gpio_output_set_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_output_set(dev, + gpio_output_set_cmd.set_mask, + gpio_output_set_cmd.clear_mask, + gpio_output_set_cmd.enable_mask, + gpio_output_set_cmd.disable_mask); + if (ret != A_OK) { + ret = EIO; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INPUT_GET: + { + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + ret = ar6000_gpio_input_get(dev); + if (ret != A_OK) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arPriv->arEvent, gpio_data_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + A_ASSERT(gpio_reg_results.gpioreg_id == GPIO_ID_NONE); + + if (copy_to_user(userdata, &gpio_reg_results.value, + sizeof(gpio_reg_results.value))) + { + ret = -EFAULT; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_REGISTER_SET: + { + struct ar6000_gpio_register_cmd_s gpio_register_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_register_cmd, userdata, + sizeof(gpio_register_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_register_set(dev, + gpio_register_cmd.gpioreg_id, + gpio_register_cmd.value); + if (ret != A_OK) { + ret = EIO; + } + + /* Wait for acknowledgement from Target */ + wait_event_interruptible(arPriv->arEvent, gpio_ack_received); + if (signal_pending(current)) { + ret = -EINTR; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_REGISTER_GET: + { + struct ar6000_gpio_register_cmd_s gpio_register_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_register_cmd, userdata, + sizeof(gpio_register_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_register_get(dev, gpio_register_cmd.gpioreg_id); + if (ret != A_OK) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arPriv->arEvent, gpio_data_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + A_ASSERT(gpio_register_cmd.gpioreg_id == gpio_reg_results.gpioreg_id); + if (copy_to_user(userdata, &gpio_reg_results, + sizeof(gpio_reg_results))) + { + ret = -EFAULT; + } + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INTR_ACK: + { + struct ar6000_gpio_intr_ack_cmd_s gpio_intr_ack_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_intr_ack_cmd, userdata, + sizeof(gpio_intr_ack_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_intr_ack(dev, gpio_intr_ack_cmd.ack_mask); + if (ret != A_OK) { + ret = EIO; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INTR_WAIT: + { + /* Wait for Target to report an interrupt. */ + wait_event_interruptible(arPriv->arEvent, gpio_intr_available); + + if (signal_pending(current)) { + ret = -EINTR; + } else { + if (copy_to_user(userdata, &gpio_intr_results, + sizeof(gpio_intr_results))) + { + ret = -EFAULT; + } + } + break; + } +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + + case AR6000_XIOCTL_DBGLOG_CFG_MODULE: + { + struct ar6000_dbglog_module_config_s config; + + if (copy_from_user(&config, userdata, sizeof(config))) { + ret = -EFAULT; + goto ioctl_done; + } + + /* Send the challenge on the control channel */ + if (wmi_config_debug_module_cmd(arPriv->arWmi, config.mmask, + config.tsr, config.rep, + config.size, config.valid) != A_OK) + { + ret = -EIO; + goto ioctl_done; + } + break; + } + + case AR6000_XIOCTL_DBGLOG_GET_DEBUG_LOGS: + { + /* Send the challenge on the control channel */ + if (ar6000_dbglog_get_debug_logs(ar) != A_OK) + { + ret = -EIO; + goto ioctl_done; + } + break; + } + + case AR6000_XIOCTL_SET_ADHOC_BSSID: + { + WMI_SET_ADHOC_BSSID_CMD adhocBssid; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&adhocBssid, userdata, + sizeof(adhocBssid))) + { + ret = -EFAULT; + } else if (A_MEMCMP(adhocBssid.bssid, bcast_mac, + AR6000_ETH_ADDR_LEN) == 0) + { + ret = -EFAULT; + } else { + + A_MEMCPY(arSta->arReqBssid, adhocBssid.bssid, sizeof(arSta->arReqBssid)); + } + break; + } + + case AR6000_XIOCTL_WMI_SETRETRYLIMITS: + { + WMI_SET_RETRY_LIMITS_CMD setRetryParams; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setRetryParams, userdata, + sizeof(setRetryParams))) + { + ret = -EFAULT; + } else { + if (wmi_set_retry_limits_cmd(arPriv->arWmi, setRetryParams.frameType, + setRetryParams.trafficClass, + setRetryParams.maxRetries, + setRetryParams.enableNotify) != A_OK) + { + ret = -EIO; + } + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arPriv->arMaxRetries = setRetryParams.maxRetries; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + } + break; + } + + case AR6000_XIOCTL_SET_BEACON_INTVAL: + { + WMI_BEACON_INT_CMD bIntvlCmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&bIntvlCmd, userdata, + sizeof(bIntvlCmd))) + { + ret = -EFAULT; + } else if (wmi_set_adhoc_bconIntvl_cmd(arPriv->arWmi, bIntvlCmd.beaconInterval) + != A_OK) + { + ret = -EIO; + } + if(ret == 0) { + arAp->ap_beacon_interval = bIntvlCmd.beaconInterval; + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + } + break; + } + case IEEE80211_IOCTL_SETAUTHALG: + { + struct ieee80211req_authalg req; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&req, userdata, + sizeof(struct ieee80211req_authalg))) + { + ret = -EFAULT; + } else { + if (req.auth_alg & AUTH_ALG_OPEN_SYSTEM) { + arPriv->arDot11AuthMode |= OPEN_AUTH; + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arGroupCrypto = NONE_CRYPT; + } + if (req.auth_alg & AUTH_ALG_SHARED_KEY) { + arPriv->arDot11AuthMode |= SHARED_AUTH; + arPriv->arPairwiseCrypto = WEP_CRYPT; + arPriv->arGroupCrypto = WEP_CRYPT; + arPriv->arAuthMode = WMI_NONE_AUTH; + } + if (req.auth_alg == AUTH_ALG_LEAP) { + arPriv->arDot11AuthMode = LEAP_AUTH; + } + } + break; + } + + case AR6000_XIOCTL_SET_VOICE_PKT_SIZE: + ret = ar6000_xioctl_set_voice_pkt_size(dev, userdata); + break; + + case AR6000_XIOCTL_SET_MAX_SP: + ret = ar6000_xioctl_set_max_sp_len(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_GET_ROAM_TBL: + ret = ar6000_ioctl_get_roam_tbl(dev, rq); + break; + case AR6000_XIOCTL_WMI_SET_ROAM_CTRL: + ret = ar6000_ioctl_set_roam_ctrl(dev, userdata); + break; + case AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS: + ret = ar6000_ioctl_set_powersave_timers(dev, userdata); + break; + case AR6000_XIOCTRL_WMI_GET_POWER_MODE: + ret = ar6000_ioctl_get_power_mode(dev, rq); + break; + + case AR6000_XIOCTRL_WMI_SET_WLAN_STATE: + { + AR6000_WLAN_STATE state; + get_user(state, (unsigned int *)userdata); + if (ar6000_set_wlan_state(ar, state)!=A_OK) { + ret = -EIO; + } + break; + } + + case AR6000_XIOCTL_WMI_GET_ROAM_DATA: + ret = ar6000_ioctl_get_roam_data(dev, rq); + break; + + case AR6000_XIOCTL_WMI_SET_BT_STATUS: + ret = ar6000_xioctl_set_bt_status_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BT_PARAMS: + ret = ar6000_xioctl_set_bt_params_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT: + ret = ar6000_xioctl_set_btcoex_fe_ant_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV: + ret = ar6000_xioctl_set_btcoex_colocated_bt_dev_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG: + ret = ar6000_xioctl_set_btcoex_btinquiry_page_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG: + ret = ar6000_xioctl_set_btcoex_sco_config_cmd( dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG: + ret = ar6000_xioctl_set_btcoex_a2dp_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_ACLCOEX_CONFIG: + ret = ar6000_xioctl_set_btcoex_aclcoex_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_DEBUG: + ret = ar60000_xioctl_set_btcoex_debug_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS: + ret = ar6000_xioctl_set_btcoex_bt_operating_status_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_GET_BTCOEX_CONFIG: + ret = ar6000_xioctl_get_btcoex_config_cmd(dev, userdata, rq); + break; + + case AR6000_XIOCTL_WMI_GET_BTCOEX_STATS: + ret = ar6000_xioctl_get_btcoex_stats_cmd(dev, userdata, rq); + break; + + case AR6000_XIOCTL_WMI_STARTSCAN: + { + WMI_START_SCAN_CMD setStartScanCmd, *cmdp; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setStartScanCmd, userdata, + sizeof(setStartScanCmd))) + { + ret = -EFAULT; + } else { + if (setStartScanCmd.numChannels > 1) { + cmdp = A_MALLOC(130); + if (copy_from_user(cmdp, userdata, + sizeof (*cmdp) + + ((setStartScanCmd.numChannels - 1) * + sizeof(A_UINT16)))) + { + A_FREE(cmdp); + ret = -EFAULT; + goto ioctl_done; + } + } else { + cmdp = &setStartScanCmd; + } + + if (wmi_startscan_cmd(arPriv->arWmi, cmdp->scanType, + cmdp->forceFgScan, + cmdp->isLegacy, + cmdp->homeDwellTime, + cmdp->forceScanInterval, + cmdp->numChannels, + cmdp->channelList) != A_OK) + { + ret = -EIO; + } + if (setStartScanCmd.numChannels > 1) { + A_FREE(cmdp); + } + } + break; + } + case AR6000_XIOCTL_WMI_SETFIXRATES: + { + WMI_FIX_RATES_CMD setFixRatesCmd; + A_STATUS returnStatus; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setFixRatesCmd, userdata, + sizeof(setFixRatesCmd))) + { + ret = -EFAULT; + } else { + returnStatus = wmi_set_fixrates_cmd(arPriv->arWmi, setFixRatesCmd.fixRateMask); + if (returnStatus == A_EINVAL) { + ret = -EINVAL; + } else if(returnStatus != A_OK) { + ret = -EIO; + } else { + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + } + } + break; + } + + case AR6000_XIOCTL_WMI_GETFIXRATES: + { + WMI_FIX_RATES_CMD getFixRatesCmd; + int ret = 0; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + /* Used copy_from_user/copy_to_user to access user space data */ + if (copy_from_user(&getFixRatesCmd, userdata, sizeof(getFixRatesCmd))) { + ret = -EFAULT; + } else { + arPriv->arRateMask[0] = 0xFFFFFFFF; + arPriv->arRateMask[1] = 0xFFFFFFFF; + + if (wmi_get_ratemask_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + wait_event_interruptible_timeout(arPriv->arEvent, (arPriv->arRateMask[0] != 0xFFFFFFFF) && + (arPriv->arRateMask[1] != 0xFFFFFFFF), wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret) { + getFixRatesCmd.fixRateMask[0] = arPriv->arRateMask[0]; + getFixRatesCmd.fixRateMask[1] = arPriv->arRateMask[1]; + } + + if(copy_to_user(userdata, &getFixRatesCmd, sizeof(getFixRatesCmd))) { + ret = -EFAULT; + } + + up(&ar->arSem); + } + break; + } + case AR6000_XIOCTL_WMI_SET_AUTHMODE: + { + WMI_SET_AUTH_MODE_CMD setAuthMode; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setAuthMode, userdata, + sizeof(setAuthMode))) { + ret = -EFAULT; + } else { + if (wmi_set_authmode_cmd(arPriv->arWmi, setAuthMode.mode) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_REASSOCMODE: + { + WMI_SET_REASSOC_MODE_CMD setReassocMode; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setReassocMode, userdata, + sizeof(setReassocMode))) { + ret = -EFAULT; + } else { + if (wmi_set_reassocmode_cmd(arPriv->arWmi, setReassocMode.mode) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_DIAG_READ: + { + A_UINT32 addr, data; + get_user(addr, (unsigned int *)userdata); + addr = TARG_VTOP(ar->arTargetType, addr); + if (ar6000_ReadRegDiag(ar->arHifDevice, &addr, &data) != A_OK) { + ret = -EIO; + } + put_user(data, (unsigned int *)userdata + 1); + break; + } + case AR6000_XIOCTL_DIAG_WRITE: + { + A_UINT32 addr, data; + get_user(addr, (unsigned int *)userdata); + get_user(data, (unsigned int *)userdata + 1); + addr = TARG_VTOP(ar->arTargetType, addr); + if (ar6000_WriteRegDiag(ar->arHifDevice, &addr, &data) != A_OK) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_WMI_SET_KEEPALIVE: + { + WMI_SET_KEEPALIVE_CMD setKeepAlive; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&setKeepAlive, userdata, + sizeof(setKeepAlive))){ + ret = -EFAULT; + } else { + if (wmi_set_keepalive_cmd(arPriv->arWmi, setKeepAlive.keepaliveInterval) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_PARAMS: + { + WMI_SET_PARAMS_CMD cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd) + cmd.length)) + { + ret = -EFAULT; + } else { + if (wmi_set_params_cmd(arPriv->arWmi, cmd.opcode, cmd.length, cmd.buffer) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_MCAST_FILTER: + { + WMI_SET_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_set_mcast_filter_cmd(arPriv->arWmi, &cmd.multicast_mac[0]) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_DEL_MCAST_FILTER: + { + WMI_SET_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_del_mcast_filter_cmd(arPriv->arWmi, &cmd.multicast_mac[0]) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_MCAST_FILTER: + { + WMI_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_mcast_filter_cmd(arPriv->arWmi, cmd.enable) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_GET_KEEPALIVE: + { + WMI_GET_KEEPALIVE_CMD getKeepAlive; + int ret = 0; + if (ar->bIsDestroyProgress) { + ret =-EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + if (copy_from_user(&getKeepAlive, userdata,sizeof(getKeepAlive))) { + ret = -EFAULT; + } else { + getKeepAlive.keepaliveInterval = wmi_get_keepalive_cmd(arPriv->arWmi); + arSta->arKeepaliveConfigured = 0xFF; + if (wmi_get_keepalive_configured(arPriv->arWmi) != A_OK){ + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + wait_event_interruptible_timeout(arPriv->arEvent, arSta->arKeepaliveConfigured != 0xFF, wmitimeout * HZ); + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret) { + getKeepAlive.configured = arSta->arKeepaliveConfigured; + } + if (copy_to_user(userdata, &getKeepAlive, sizeof(getKeepAlive))) { + ret = -EFAULT; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_WMI_SET_APPIE: + { + WMI_SET_APPIE_CMD appIEcmd; + A_UINT8 appIeInfo[IEEE80211_APPIE_FRAME_MAX_LEN]; + A_UINT32 fType,ieLen; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } + get_user(fType, (A_UINT32 *)userdata); + appIEcmd.mgmtFrmType = fType; + if (appIEcmd.mgmtFrmType >= IEEE80211_APPIE_NUM_OF_FRAME) { + ret = -EIO; + } else { + get_user(ieLen, (A_UINT32 *)(userdata + 4)); + appIEcmd.ieLen = ieLen; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WPSIE: Type-%d, Len-%d\n",appIEcmd.mgmtFrmType, appIEcmd.ieLen)); + if (appIEcmd.ieLen > IEEE80211_APPIE_FRAME_MAX_LEN) { + ret = -EIO; + break; + } + if (copy_from_user(appIeInfo, userdata + 8, appIEcmd.ieLen)) { + ret = -EFAULT; + } else { + if (wmi_set_appie_cmd(arPriv->arWmi, appIEcmd.mgmtFrmType, + appIEcmd.ieLen, appIeInfo) != A_OK) + { + ret = -EIO; + } + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_MGMT_FRM_RX_FILTER: + { + WMI_BSS_FILTER_CMD cmd; + A_UINT32 filterType; + + if (copy_from_user(&filterType, userdata, sizeof(A_UINT32))) + { + ret = -EFAULT; + goto ioctl_done; + } + if (filterType & (IEEE80211_FILTER_TYPE_BEACON | + IEEE80211_FILTER_TYPE_PROBE_RESP)) + { + cmd.bssFilter = ALL_BSS_FILTER; + } else { + cmd.bssFilter = NONE_BSS_FILTER; + } + if (wmi_bssfilter_cmd(arPriv->arWmi, cmd.bssFilter, 0) != A_OK) { + ret = -EIO; + } else { + arSta->arUserBssFilter = cmd.bssFilter; + } + + AR6000_SPIN_LOCK(&arPriv->arPrivLock, 0); + arSta->arMgmtFilter = filterType; + AR6000_SPIN_UNLOCK(&arPriv->arPrivLock, 0); + break; + } + case AR6000_XIOCTL_WMI_SET_WSC_STATUS: + { + A_UINT32 wsc_status; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&wsc_status, userdata, sizeof(A_UINT32))) { + ret = -EFAULT; + goto ioctl_done; + } + if (wmi_set_wsc_status_cmd(arPriv->arWmi, wsc_status) != A_OK) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_BMI_ROMPATCH_INSTALL: + { + A_UINT32 ROM_addr; + A_UINT32 RAM_addr; + A_UINT32 nbytes; + A_UINT32 do_activate; + A_UINT32 rompatch_id; + + get_user(ROM_addr, (A_UINT32 *)userdata); + get_user(RAM_addr, (A_UINT32 *)userdata + 1); + get_user(nbytes, (A_UINT32 *)userdata + 2); + get_user(do_activate, (A_UINT32 *)userdata + 3); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Install rompatch from ROM: 0x%x to RAM: 0x%x length: %d\n", + ROM_addr, RAM_addr, nbytes)); + ret = BMIrompatchInstall(hifDevice, ROM_addr, RAM_addr, + nbytes, do_activate, &rompatch_id); + if (ret == A_OK) { + put_user(rompatch_id, (unsigned int *)rq->ifr_data); /* return value */ + } + break; + } + + case AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL: + { + A_UINT32 rompatch_id; + + get_user(rompatch_id, (A_UINT32 *)userdata); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("UNinstall rompatch_id %d\n", rompatch_id)); + ret = BMIrompatchUninstall(hifDevice, rompatch_id); + break; + } + + case AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE: + case AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE: + { + A_UINT32 rompatch_count; + + get_user(rompatch_count, (A_UINT32 *)userdata); + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Change rompatch activation count=%d\n", rompatch_count)); + length = sizeof(A_UINT32) * rompatch_count; + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(rompatch_count)], length)) + { + ret = -EFAULT; + } else { + if (cmd == AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE) { + ret = BMIrompatchActivate(hifDevice, rompatch_count, (A_UINT32 *)buffer); + } else { + ret = BMIrompatchDeactivate(hifDevice, rompatch_count, (A_UINT32 *)buffer); + } + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + + break; + } + case AR6000_XIOCTL_SET_IP: + { + WMI_SET_IP_CMD setIP; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setIP, userdata, + sizeof(setIP))) { + ret = -EFAULT; + } else { + if (wmi_set_ip_cmd(arPriv->arWmi, + &setIP) != A_OK) + { + ret = -EIO; + } + } + break; + } + + case AR6000_XIOCTL_WMI_SET_HOST_SLEEP_MODE: + { + WMI_SET_HOST_SLEEP_MODE_CMD setHostSleepMode; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setHostSleepMode, userdata, + sizeof(setHostSleepMode))) { + ret = -EFAULT; + } else { + if (wmi_set_host_sleep_mode_cmd(arPriv->arWmi, + &setHostSleepMode) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_WOW_MODE: + { + WMI_SET_WOW_MODE_CMD setWowMode; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&setWowMode, userdata, + sizeof(setWowMode))) { + ret = -EFAULT; + } else { + if (wmi_set_wow_mode_cmd(arPriv->arWmi, + &setWowMode) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_GET_WOW_LIST: + { + WMI_GET_WOW_LIST_CMD getWowList; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&getWowList, userdata, + sizeof(getWowList))) { + ret = -EFAULT; + } else { + if (wmi_get_wow_list_cmd(arPriv->arWmi, + &getWowList) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_ADD_WOW_PATTERN: + { +#define WOW_PATTERN_SIZE 64 +#define WOW_MASK_SIZE 64 + + WMI_ADD_WOW_PATTERN_CMD cmd; + A_UINT8 mask_data[WOW_PATTERN_SIZE]={0}; + A_UINT8 pattern_data[WOW_PATTERN_SIZE]={0}; + + do { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + break; + } + if(copy_from_user(&cmd, userdata, + sizeof(WMI_ADD_WOW_PATTERN_CMD))) + { + ret = -EFAULT; + break; + } + if (copy_from_user(pattern_data, + userdata + 3, + cmd.filter_size)) + { + ret = -EFAULT; + break; + } + if (copy_from_user(mask_data, + (userdata + 3 + cmd.filter_size), + cmd.filter_size)) + { + ret = -EFAULT; + break; + } + if (wmi_add_wow_pattern_cmd(arPriv->arWmi, + &cmd, pattern_data, mask_data, cmd.filter_size) != A_OK) + { + ret = -EIO; + } + } while(FALSE); +#undef WOW_PATTERN_SIZE +#undef WOW_MASK_SIZE + break; + } + case AR6000_XIOCTL_WMI_DEL_WOW_PATTERN: + { + WMI_DEL_WOW_PATTERN_CMD delWowPattern; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&delWowPattern, userdata, + sizeof(delWowPattern))) { + ret = -EFAULT; + } else { + if (wmi_del_wow_pattern_cmd(arPriv->arWmi, + &delWowPattern) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_DUMP_HTC_CREDIT_STATE: + if (ar->arHtcTarget != NULL) { +#ifdef ATH_DEBUG_MODULE + HTCDumpCreditStates(ar->arHtcTarget); +#endif /* ATH_DEBUG_MODULE */ +#ifdef HTC_EP_STAT_PROFILING + { + HTC_ENDPOINT_STATS stats; + int i; + + for (i = 0; i < 5; i++) { + if (HTCGetEndpointStatistics(ar->arHtcTarget, + i, + HTC_EP_STAT_SAMPLE_AND_CLEAR, + &stats)) { + A_PRINTF(KERN_ALERT"------- Profiling Endpoint : %d \n", i); + A_PRINTF(KERN_ALERT"TxCreditLowIndications : %d \n", stats.TxCreditLowIndications); + A_PRINTF(KERN_ALERT"TxIssued : %d \n", stats.TxIssued); + A_PRINTF(KERN_ALERT"TxDropped: %d \n", stats.TxDropped); + A_PRINTF(KERN_ALERT"TxPacketsBundled : %d \n", stats.TxPacketsBundled); + A_PRINTF(KERN_ALERT"TxBundles : %d \n", stats.TxBundles); + A_PRINTF(KERN_ALERT"TxCreditRpts : %d \n", stats.TxCreditRpts); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromRx : %d \n", stats.TxCreditRptsFromRx); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromOther : %d \n", stats.TxCreditRptsFromOther); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromEp0 : %d \n", stats.TxCreditRptsFromEp0); + A_PRINTF(KERN_ALERT"TxCreditsFromRx : %d \n", stats.TxCreditsFromRx); + A_PRINTF(KERN_ALERT"TxCreditsFromOther : %d \n", stats.TxCreditsFromOther); + A_PRINTF(KERN_ALERT"TxCreditsFromEp0 : %d \n", stats.TxCreditsFromEp0); + A_PRINTF(KERN_ALERT"TxCreditsConsummed : %d \n", stats.TxCreditsConsummed); + A_PRINTF(KERN_ALERT"TxCreditsReturned : %d \n", stats.TxCreditsReturned); + A_PRINTF(KERN_ALERT"RxReceived : %d \n", stats.RxReceived); + A_PRINTF(KERN_ALERT"RxPacketsBundled : %d \n", stats.RxPacketsBundled); + A_PRINTF(KERN_ALERT"RxLookAheads : %d \n", stats.RxLookAheads); + A_PRINTF(KERN_ALERT"RxBundleLookAheads : %d \n", stats.RxBundleLookAheads); + A_PRINTF(KERN_ALERT"RxBundleIndFromHdr : %d \n", stats.RxBundleIndFromHdr); + A_PRINTF(KERN_ALERT"RxAllocThreshHit : %d \n", stats.RxAllocThreshHit); + A_PRINTF(KERN_ALERT"RxAllocThreshBytes : %d \n", stats.RxAllocThreshBytes); + A_PRINTF(KERN_ALERT"---- \n"); + + } + } + } +#endif + } + break; + case AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE: + if (ar->arHtcTarget != NULL) { + struct ar6000_traffic_activity_change data; + + if (copy_from_user(&data, userdata, sizeof(data))) + { + ret = -EFAULT; + goto ioctl_done; + } + /* note, this is used for testing (mbox ping testing), indicate activity + * change using the stream ID as the traffic class */ + ar6000_indicate_tx_activity(arPriv, + (A_UINT8)data.StreamID, + data.Active ? TRUE : FALSE); + } + break; + case AR6000_XIOCTL_WMI_SET_CONNECT_CTRL_FLAGS: + { + A_UINT32 connectCtrlFlags; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&connectCtrlFlags, userdata, + sizeof(connectCtrlFlags))) + { + ret = -EFAULT; + } else { + arSta->arConnectCtrlFlags = connectCtrlFlags; + } + } + break; + case AR6000_XIOCTL_WMI_SET_AKMP_PARAMS: + { + WMI_SET_AKMP_PARAMS_CMD akmpParams; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&akmpParams, userdata, + sizeof(WMI_SET_AKMP_PARAMS_CMD))) + { + ret = -EFAULT; + } else { + if (wmi_set_akmp_params_cmd(arPriv->arWmi, &akmpParams) != A_OK) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_PMKID_LIST: + { + WMI_SET_PMKID_LIST_CMD pmkidInfo; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + break; + } + if (copy_from_user(&pmkidInfo.numPMKID, userdata, + sizeof(pmkidInfo.numPMKID))) { + ret = -EFAULT; + break; + } + if (copy_from_user(&pmkidInfo.pmkidList, + userdata + sizeof(pmkidInfo.numPMKID), + pmkidInfo.numPMKID * sizeof(WMI_PMKID))) + { + ret = -EFAULT; + break; + } + if (wmi_set_pmkid_list_cmd(arPriv->arWmi, &pmkidInfo) != A_OK) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_WMI_GET_PMKID_LIST: + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (wmi_get_pmkid_list_cmd(arPriv->arWmi) != A_OK) { + ret = -EIO; + } + break; + case AR6000_XIOCTL_WMI_ABORT_SCAN: + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } + ret = wmi_abort_scan_cmd(arPriv->arWmi); + break; + case AR6000_XIOCTL_AP_HIDDEN_SSID: + { + A_UINT8 hidden_ssid; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&hidden_ssid, userdata, sizeof(hidden_ssid))) { + ret = -EFAULT; + } else { + wmi_ap_set_hidden_ssid(arPriv->arWmi, hidden_ssid); + arAp->ap_hidden_ssid = hidden_ssid; + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + } + break; + } + case AR6000_XIOCTL_AP_GET_STA_LIST: + { + WMI_SET_HT_CAP_CMD htCap; + + htCap.band = A_BAND_24GHZ; + if(arPriv->phymode == WMI_11A_MODE) { + htCap.band = A_BAND_5GHZ; + } + wmi_get_ht_cap_cmd(arPriv->arWmi, &htCap); + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else { + A_UINT8 i, j=0; + ap_get_sta_t temp; + A_MEMZERO(&temp, sizeof(temp)); + for(i=0;iconnTbl[i].arPriv == arPriv) { + A_MEMCPY(temp.sta[j].mac, ar->connTbl[i].mac, ATH_MAC_LEN); + temp.sta[j].aid = ar->connTbl[i].aid; + temp.sta[j].keymgmt = ar->connTbl[i].keymgmt; + temp.sta[j].ucipher = ar->connTbl[i].ucipher; + temp.sta[j].auth = ar->connTbl[i].auth; + temp.sta[j].wmode = ar->connTbl[i].wmode; + if(htCap.enable == 2) { + /* Set MSB to indicate 11n-only mode */ + temp.sta[j].wmode |= 0x80; + } + j++; + } + } + if(copy_to_user((ap_get_sta_t *)rq->ifr_data, &temp, sizeof(temp))) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_AP_SET_NUM_STA: + { + A_UINT8 num_sta; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&num_sta, userdata, sizeof(num_sta))) { + ret = -EFAULT; + } else { + ret = ar6000_ap_set_num_sta(ar, arPriv, num_sta); + } + break; + } + case AR6000_XIOCTL_AP_SET_DFS: + { +#ifdef ATH_SUPPORT_DFS + A_UINT8 enable; + if (copy_from_user(&enable, userdata, sizeof(enable))) { + ret = -EFAULT; + } else { + wmi_ap_set_dfs(arPriv->arWmi, enable); + } +#else + ret = -EIO; +#endif + break; + } + + case AR6000_XIOCTL_AP_SET_ACL_POLICY: + { + A_UINT8 policy; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&policy, userdata, sizeof(policy))) { + ret = -EFAULT; + } else { + if(!(policy & AP_ACL_RETAIN_LIST_MASK)) { + /* clear ACL list */ + memset(&arAp->g_acl,0,sizeof(WMI_AP_ACL)); + } + arAp->g_acl.policy = policy; + wmi_ap_set_acl_policy(arPriv->arWmi, policy); + } + break; + } + case AR6000_XIOCTL_AP_SET_ACL_MAC: + { + WMI_AP_ACL_MAC_CMD acl; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&acl, userdata, sizeof(acl))) { + ret = -EFAULT; + } else { + if(acl_add_del_mac(&arAp->g_acl, &acl)) { + wmi_ap_acl_mac_list(arPriv->arWmi, &acl); + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ACL list error\n")); + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_ACL_LIST: + { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_ACL *)rq->ifr_data, &arAp->g_acl, + sizeof(WMI_AP_ACL))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_COMMIT_CONFIG: + { + ret = ar6000_ap_mode_profile_commit(arPriv); + break; + } + case IEEE80211_IOCTL_GETWPAIE: + { + struct ieee80211req_wpaie wpaie; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&wpaie, userdata, sizeof(wpaie))) { + ret = -EFAULT; + } else if (ar6000_ap_mode_get_wpa_ie(arPriv, &wpaie)) { + ret = -EFAULT; + } else if(copy_to_user(userdata, &wpaie, sizeof(wpaie))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_CONN_INACT_TIME: + { + A_UINT32 period; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&period, userdata, sizeof(period))) { + ret = -EFAULT; + } else { + wmi_ap_conn_inact_time(arPriv->arWmi, period); + } + break; + } + case AR6000_XIOCTL_AP_PROT_SCAN_TIME: + { + WMI_AP_PROT_SCAN_TIME_CMD bgscan; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&bgscan, userdata, sizeof(bgscan))) { + ret = -EFAULT; + } else { + wmi_ap_bgscan_time(arPriv->arWmi, bgscan.period_min, bgscan.dwell_ms); + } + break; + } + case AR6000_XIOCTL_AP_SET_COUNTRY: + { + ret = ar6000_ioctl_set_country(dev, rq); + break; + } + case AR6000_XIOCTL_AP_SET_DTIM: + { + WMI_AP_SET_DTIM_CMD d; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&d, userdata, sizeof(d))) { + ret = -EFAULT; + } else { + if(d.dtim > 0 && d.dtim < 11) { + arAp->ap_dtim_period = d.dtim; + wmi_ap_set_dtim(arPriv->arWmi, d.dtim); + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("DTIM out of range. Valid range is [1-10]\n")); + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_TARGET_EVENT_REPORT: + { + WMI_SET_TARGET_EVENT_REPORT_CMD evtCfgCmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } + if (copy_from_user(&evtCfgCmd, userdata, + sizeof(evtCfgCmd))) { + ret = -EFAULT; + break; + } + ret = wmi_set_target_event_report_cmd(arPriv->arWmi, &evtCfgCmd); + break; + } + case AR6000_XIOCTL_AP_CTRL_BSS_COMM: + { + A_UINT8 intra=0; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&intra, userdata, sizeof(intra))) { + ret = -EFAULT; + } else { + if(intra & 0x80) { /* interbss */ + ar->inter_bss = ( (intra & 0xF) ? 1 : 0 ); + } else { + arAp->intra_bss = ( intra ? 1 : 0 ); + } + } + /* If P2P is enabled on this device, also indicate intra_bss setting to the firmware + * so that it can be reflected in the Group Capability bit of the p2p-go. + */ +#ifdef P2P + { + NETWORK_SUBTYPE networkSubType = arPriv->arNetworkSubType; + + if (networkSubType == SUBTYPE_P2PDEV || + networkSubType == SUBTYPE_P2PCLIENT || + networkSubType == SUBTYPE_P2PGO) { + + WMI_P2P_SET_CMD set_p2p_config; + A_MEMZERO(&set_p2p_config, sizeof(WMI_P2P_SET_CMD)); + + set_p2p_config.config_id = WMI_P2P_CONFID_INTRA_BSS; + set_p2p_config.val.intra_bss.flag = intra; + + wmi_p2p_set_cmd(arPriv->arWmi, &set_p2p_config); + } + } +#endif /* P2P */ + break; + } + case AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + a_dump_module_debug_info_by_name(moduleinfo.modulename); + ret = 0; + break; + } + case AR6000_XIOCTL_MODULE_DEBUG_SET_MASK: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + if (A_FAILED(a_set_module_mask(moduleinfo.modulename, moduleinfo.mask))) { + ret = -EFAULT; + } + + break; + } + case AR6000_XIOCTL_MODULE_DEBUG_GET_MASK: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + if (A_FAILED(a_get_module_mask(moduleinfo.modulename, &moduleinfo.mask))) { + ret = -EFAULT; + break; + } + + if (copy_to_user(userdata, &moduleinfo, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + break; + } +#ifdef ATH_AR6K_11N_SUPPORT + case AR6000_XIOCTL_DUMP_RCV_AGGR_STATS: + { + PACKET_LOG *copy_of_pkt_log; + + aggr_dump_stats(ar->connTbl[0].conn_aggr, ©_of_pkt_log); + if (copy_to_user(rq->ifr_data, copy_of_pkt_log, sizeof(PACKET_LOG))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_SETUP_AGGR: + { + WMI_ADDBA_REQ_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_setup_aggr_cmd(arPriv->arWmi, cmd.tid); + } + } + break; + + case AR6000_XIOCTL_DELE_AGGR: + { + WMI_DELBA_REQ_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_delete_aggr_cmd(arPriv->arWmi, cmd.tid, cmd.is_sender_initiator); + } + } + break; + + case AR6000_XIOCTL_ALLOW_AGGR: + { + WMI_ALLOW_AGGR_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_allow_aggr_cmd(arPriv->arWmi, cmd.tx_allow_aggr, cmd.rx_allow_aggr); + } + } + break; + + case AR6000_XIOCTL_SET_HT_CAP: + { + WMI_SET_HT_CAP_CMD htCap; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&htCap, userdata, sizeof(htCap))) { + ret = -EFAULT; + } else if (wmi_set_ht_cap_cmd(arPriv->arWmi, &htCap) != A_OK) { + ret = -EIO; + } + break; + } + + case AR6000_XIOCTL_GET_HT_CAP: + { + WMI_SET_HT_CAP_CMD htCap; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&htCap, userdata, sizeof(htCap))) { + ret = -EFAULT; + } else if (wmi_get_ht_cap_cmd(arPriv->arWmi, &htCap) != A_OK) { + ret = -EIO; + } else if(copy_to_user((WMI_SET_HT_CAP_CMD *)rq->ifr_data, + &htCap, sizeof(htCap))) { + ret = -EFAULT; + } + break; + } + + case AR6000_XIOCTL_SET_HT_OP: + { + WMI_SET_HT_OP_CMD htOp; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&htOp, userdata, + sizeof(htOp))){ + ret = -EFAULT; + } else { + + if (wmi_set_ht_op_cmd(arPriv->arWmi, htOp.sta_chan_width) != A_OK) + { + ret = -EIO; + } + } + break; + } +#endif + case AR6000_XIOCTL_ACL_DATA: + { + void *osbuf = NULL; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (ar6000_create_acl_data_osbuf(dev, (A_UINT8*)userdata, &osbuf) != A_OK) { + ret = -EIO; + } else { + if (wmi_data_hdr_add(arPriv->arWmi, osbuf, DATA_MSGTYPE, 0, WMI_DATA_HDR_DATA_TYPE_ACL,0,NULL) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("XIOCTL_ACL_DATA - wmi_data_hdr_add failed\n")); + } else { + /* Send data buffer over HTC */ + ar6000_acl_data_tx(osbuf, arPriv); + } + } + break; + } + case AR6000_XIOCTL_HCI_CMD: + { + char tmp_buf[512]; + A_INT8 i; + WMI_HCI_CMD *cmd = (WMI_HCI_CMD *)tmp_buf; + A_UINT8 size; + + size = sizeof(cmd->cmd_buf_sz); + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(cmd, userdata, size)) { + ret = -EFAULT; + } else if(copy_from_user(cmd->buf, userdata + size, cmd->cmd_buf_sz)) { + ret = -EFAULT; + } else { + if (wmi_send_hci_cmd(arPriv->arWmi, cmd->buf, cmd->cmd_buf_sz) != A_OK) { + ret = -EIO; + }else if(loghci) { + A_PRINTF_LOG("HCI Command To PAL --> \n"); + for(i = 0; i < cmd->cmd_buf_sz; i++) { + A_PRINTF_LOG("0x%02x ",cmd->buf[i]); + if((i % 10) == 0) { + A_PRINTF_LOG("\n"); + } + } + A_PRINTF_LOG("\n"); + A_PRINTF_LOG("==================================\n"); + } + } + break; + } + case AR6000_XIOCTL_WLAN_CONN_PRECEDENCE: + { + WMI_SET_BT_WLAN_CONN_PRECEDENCE cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + if (cmd.precedence == BT_WLAN_CONN_PRECDENCE_WLAN || + cmd.precedence == BT_WLAN_CONN_PRECDENCE_PAL) { + if ( wmi_set_wlan_conn_precedence_cmd(arPriv->arWmi, cmd.precedence) != A_OK) { + ret = -EIO; + } + } else { + ret = -EINVAL; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_STAT: + { + ret = ar6000_ioctl_get_ap_stats(dev, rq); + break; + } + case AR6000_XIOCTL_SET_TX_SELECT_RATES: + { + WMI_SET_TX_SELECT_RATES_CMD masks; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&masks, userdata, + sizeof(masks))) { + ret = -EFAULT; + } else { + + if (wmi_set_tx_select_rates_cmd(arPriv->arWmi, masks.rateMasks) != A_OK) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_HIDDEN_SSID: + { + WMI_AP_HIDDEN_SSID_CMD ssid; + ssid.hidden_ssid = arAp->ap_hidden_ssid; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_HIDDEN_SSID_CMD *)rq->ifr_data, + &ssid, sizeof(WMI_AP_HIDDEN_SSID_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_COUNTRY: + { + WMI_AP_SET_COUNTRY_CMD cty; + A_MEMCPY(cty.countryCode, arAp->ap_country_code, 3); + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_SET_COUNTRY_CMD *)rq->ifr_data, + &cty, sizeof(WMI_AP_SET_COUNTRY_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_WMODE: + { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((A_UINT8 *)rq->ifr_data, + &arPriv->phymode, sizeof(A_UINT8))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_DTIM: + { + WMI_AP_SET_DTIM_CMD dtim; + dtim.dtim = arAp->ap_dtim_period; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_SET_DTIM_CMD *)rq->ifr_data, + &dtim, sizeof(WMI_AP_SET_DTIM_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_BINTVL: + { + WMI_BEACON_INT_CMD bi; + bi.beaconInterval = arAp->ap_beacon_interval; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_BEACON_INT_CMD *)rq->ifr_data, + &bi, sizeof(WMI_BEACON_INT_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_RTS: + { + WMI_SET_RTS_CMD rts; + rts.threshold = arAp->arRTS; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if(copy_to_user((WMI_SET_RTS_CMD *)rq->ifr_data, + &rts, sizeof(WMI_SET_RTS_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_FETCH_TARGET_REGS: + { + A_UINT32 targregs[AR6003_FETCH_TARG_REGS_COUNT]; + + if (ar->arTargetType == TARGET_TYPE_AR6003) { + ar6k_FetchTargetRegs(hifDevice, targregs); + if (copy_to_user((A_UINT32 *)rq->ifr_data, &targregs, sizeof(targregs))) + { + ret = -EFAULT; + } + } else { + ret = -EOPNOTSUPP; + } + break; + } + case AR6000_XIOCTL_AP_SET_11BG_RATESET: + { + WMI_AP_SET_11BG_RATESET_CMD rate; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&rate, userdata, sizeof(rate))) { + ret = -EFAULT; + } else { + wmi_ap_set_rateset(arPriv->arWmi, rate.rateset); + } + break; + } + case AR6000_XIOCTL_GET_WLAN_SLEEP_STATE: + { + WMI_REPORT_SLEEP_STATE_EVENT wmiSleepEvent ; + + if (ar->arWlanState == WLAN_ENABLED) { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_AWAKE; + } else { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_DEEP_SLEEP; + } + rq->ifr_ifru.ifru_ivalue = ar->arWlanState; /* return value */ + ar6000_send_event_to_app(arPriv, WMI_REPORT_SLEEP_STATE_EVENTID, (A_UINT8*)&wmiSleepEvent, + sizeof(WMI_REPORT_SLEEP_STATE_EVENTID)); + break; + } +#ifdef P2P + case AR6000_XIOCTL_WMI_P2P_DISCOVER: + { + WMI_BSS_FILTER_CMD filt; + + /*Issue the WMI_FIND CMD*/ + WMI_P2P_FIND_CMD find_param; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + break; + } + A_MEMZERO(&filt, sizeof(WMI_BSS_FILTER_CMD)); + /*Set BSS filter to ALL*/ + filt.bssFilter = ALL_BSS_FILTER; + + if (wmi_bssfilter_cmd(arPriv->arWmi, filt.bssFilter, filt.ieMask) + != A_OK) { + ret = -EIO; + } else { + arSta->arUserBssFilter = filt.bssFilter; + if (copy_from_user(&find_param, userdata, sizeof(WMI_P2P_FIND_CMD))) { + ret = -EFAULT; + } else { + p2p_clear_peers_reported_flag(A_WMI_GET_P2P_CTX(arPriv)); + wmi_p2p_discover(arPriv->arWmi, &find_param); + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_STOP_FIND: + { + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else { + wmi_p2p_stop_find(arPriv->arWmi); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_CANCEL: + { + wmi_p2p_cancel(arPriv->arWmi); + break; + } + case AR6000_XIOCTL_WMI_P2P_LISTEN: + { + A_UINT32 timeout; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&timeout, userdata, sizeof(timeout))) { + ret = -EFAULT; + } else { + wmi_p2p_listen(arPriv->arWmi, timeout); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_GO_NEG: + { + /*Issue the WMI_GO_NEG CMD*/ + WMI_P2P_GO_NEG_START_CMD go_param; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&go_param, userdata, sizeof(WMI_P2P_GO_NEG_START_CMD))) { + ret = -EFAULT; + } else { + if (p2p_go_neg_start(A_WMI_GET_P2P_CTX(arPriv), &go_param) + != A_OK) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_AUTH_GO_NEG: + { + WMI_P2P_GO_NEG_START_CMD go_neg_auth_param; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&go_neg_auth_param, userdata, sizeof(WMI_P2P_GO_NEG_START_CMD))) { + ret = -EFAULT; + } else { + if (p2p_auth_go_neg(A_WMI_GET_P2P_CTX(arPriv), + &go_neg_auth_param) != A_OK) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_REJECT: + { + A_UINT8 p2p_reject_peer[IEEE80211_ADDR_LEN]; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(p2p_reject_peer, userdata, + IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } else { + if (p2p_peer_reject(A_WMI_GET_P2P_CTX(arPriv), + p2p_reject_peer) != A_OK) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_CONFIG: + { + WMI_P2P_SET_CONFIG_CMD set_p2p_config; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&set_p2p_config, userdata, sizeof(WMI_P2P_SET_CONFIG_CMD))) { + ret = -EFAULT; + } else { + wmi_p2p_set_config(arPriv->arWmi, &set_p2p_config); + } + break; + } + case AR6000_XIOCTL_WMI_WPS_CONFIG: + { + WMI_WPS_SET_CONFIG_CMD set_wps_config; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&set_wps_config, userdata, sizeof(WMI_WPS_SET_CONFIG_CMD))) { + ret = -EFAULT; + } else { + wmi_wps_set_config(arPriv->arWmi, &set_wps_config); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_FINDNODE: + { + A_UINT8 macaddr[AR6000_ETH_ADDR_LEN]; + bss_t *ni; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(macaddr, userdata,AR6000_ETH_ADDR_LEN)) { + ret = -EFAULT; + } else { + ni = wmi_find_node(arPriv->arWmi, macaddr); + if (ni) { + if(copy_to_user((A_UINT16 *)rq->ifr_data, + &ni->ni_cie.ie_chan, sizeof(A_UINT16))) { + ret = -EFAULT; + } + } + else { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_GRP_INIT: + { + WMI_P2P_GRP_INIT_CMD p2p_grp_init_cmd; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&p2p_grp_init_cmd, userdata, + sizeof(WMI_P2P_GRP_INIT_CMD))) { + ret = -EFAULT; + } else { + wmi_p2p_grp_init_cmd(arPriv->arWmi, &p2p_grp_init_cmd); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_GRP_FORMATION_DONE: + { + WMI_P2P_GRP_FORMATION_DONE_CMD p2p_grp_done_cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&p2p_grp_done_cmd, userdata, + sizeof(WMI_P2P_GRP_FORMATION_DONE_CMD))) { + ret = -EFAULT; + } else { + wmi_p2p_grp_done_cmd(arPriv->arWmi, &p2p_grp_done_cmd); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_INVITE: + { + WMI_P2P_INVITE_CMD p2p_invite_param; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&p2p_invite_param, userdata, + sizeof(WMI_P2P_INVITE_CMD))) { + ret = -EFAULT; + } else { + if (p2p_invite_cmd(A_WMI_GET_P2P_CTX(arPriv), &p2p_invite_param) + != A_OK) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_PROV_DISC: + { + A_UINT8 peer[IEEE80211_ADDR_LEN]; + A_UINT16 wps_method; + A_UINT8 buf[8]; + + A_MEMZERO(peer, IEEE80211_ADDR_LEN); + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(buf, userdata, 8)) { + ret = -EFAULT; + } else { + A_MEMCPY(peer, buf, IEEE80211_ADDR_LEN); + wps_method = (*(A_UINT16 *)(&buf[6])); + + if (p2p_prov_disc_req(A_WMI_GET_P2P_CTX(arPriv), peer, wps_method) != A_OK) { + ret = -EFAULT; + } + } + + break; + } + case AR6000_XIOCTL_WMI_P2P_GET_IF_ADDR: + { + A_UINT8 buf[12]; + const A_UINT8 zero_mac[] = {0,0,0,0,0,0}; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(buf, userdata, 12)) { + ret = -EFAULT; + } else { + if (p2p_get_ifaddr(A_WMI_GET_P2P_CTX(arPriv), + buf) == A_OK) { + if(copy_to_user((A_UINT8 *)rq->ifr_data, + buf+6, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } else { + if(copy_to_user((A_UINT8 *)rq->ifr_data, + zero_mac, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_GET_DEV_ADDR: + { + A_UINT8 buf[12]; + const A_UINT8 zero_mac[] = {0,0,0,0,0,0}; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(buf, userdata, 12)) { + ret = -EFAULT; + } else { + if (p2p_get_devaddr(A_WMI_GET_P2P_CTX(arPriv), + buf) == A_OK) { + if(copy_to_user((A_UINT8 *)rq->ifr_data, + buf+6, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } else { + if(copy_to_user((A_UINT8 *)rq->ifr_data, + zero_mac, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_SET: + { + WMI_P2P_SET_CMD set_p2p_config; + A_MEMZERO(&set_p2p_config, sizeof(WMI_P2P_SET_CMD)); + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&set_p2p_config, userdata, sizeof(WMI_P2P_SET_CMD))) { + ret = -EFAULT; + } else { + wmi_p2p_set_cmd(arPriv->arWmi, &set_p2p_config); + } + break; + } + case AR6000_XIOCTL_WMI_P2P_PEER: + { + A_UINT8 buf[12]; + const A_UINT8 zero_mac[] = {0,0,0,0,0,0}; + + A_UINT8 peer_info_buf[1000]; + A_UINT32 peer_info_buf_used; + + int first_element; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(buf, userdata, 12)) { + ret = -EFAULT; + } else { + /* + * Check the "next" value set in driver_ar6003.c of the supplicant. + * This determines whether we have a "P2P_PEER FIRST" (if = 1) or + * "P2P_PEER NEXT-" (if = 2) command, or just a plain p2p_peer + * command (if = 0) + */ + if (buf[6] != 0) { + if (buf[6] == 1) { + first_element = 1; + } else { + first_element = 0; + } + peer_info_buf_used = p2p_get_next_addr(A_WMI_GET_P2P_CTX(arPriv), buf, peer_info_buf, sizeof(peer_info_buf), first_element); + if (peer_info_buf_used == 0) { + ret = -ENODEV; + } + *((A_UINT32 *)rq->ifr_data) = peer_info_buf_used; + if(copy_to_user(((A_UINT32 *)(rq->ifr_data)+1), + peer_info_buf, peer_info_buf_used)){ + ret = -EFAULT; + } + } else { + if (p2p_peer(A_WMI_GET_P2P_CTX(arPriv), + buf, *(buf+6)) == A_OK) { + peer_info_buf_used = p2p_get_peer_info(A_WMI_GET_P2P_CTX(arPriv), buf, + peer_info_buf, sizeof(peer_info_buf)); + *((A_UINT32 *)rq->ifr_data) = peer_info_buf_used; + if(copy_to_user(((A_UINT32 *)(rq->ifr_data)+1), + peer_info_buf, peer_info_buf_used)) { + ret = -EFAULT; + } + } else { + if(copy_to_user((A_UINT16 *)rq->ifr_data, + zero_mac, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_FLUSH: + { + p2p_free_all_devices(A_WMI_GET_P2P_CTX(arPriv)); + p2p_free_all_sd_queries(A_WMI_GET_P2P_CTX(arPriv)); + break; + } + case AR6000_XIOCTL_WMI_GET_GO_PARAMS: + { + A_UINT8 go_dev_addr[AR6000_ETH_ADDR_LEN]; + struct { + A_UINT16 oper_freq; + A_UINT8 ssid[WMI_MAX_SSID_LEN]; + A_UINT8 ssid_len; + } go_params; + + A_MEMZERO(&go_params, sizeof(go_params)); + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(go_dev_addr, + userdata, AR6000_ETH_ADDR_LEN)) { + ret = -EFAULT; + } else { + if (wmi_p2p_get_go_params(A_WMI_GET_P2P_CTX(arPriv), + go_dev_addr, &go_params.oper_freq, go_params.ssid, + &go_params.ssid_len) == A_OK) { + if(copy_to_user((A_UINT16 *)rq->ifr_data, + &go_params, sizeof(go_params))) { + ret = -EFAULT; + } + } else { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_AUTH_INVITE: + { + A_UINT8 auth_peer[IEEE80211_ADDR_LEN]={0,0,0,0,0,0}; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(auth_peer, userdata,IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } else { + if (p2p_auth_invite(A_WMI_GET_P2P_CTX(arPriv), + auth_peer) != A_OK) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_P2P_SDPD_TX_CMD: + { + WMI_P2P_SDPD_TX_CMD sdpd_tx_cmd; + A_UINT32 qid = 0; + + A_MEMZERO(&sdpd_tx_cmd, sizeof(WMI_P2P_SDPD_TX_CMD)); + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&sdpd_tx_cmd, userdata, + sizeof(WMI_P2P_SDPD_TX_CMD))) { + ret = -EFAULT; + } else { + if (p2p_sdpd_tx_cmd(A_WMI_GET_P2P_CTX(arPriv), + &sdpd_tx_cmd, &qid) != + A_OK) { + ret = -EFAULT; + } else { + if(copy_to_user((A_UINT8 *)rq->ifr_data, + (void *)&qid, sizeof(A_UINT32))) { + ret = -EFAULT; + } + } + } + break; + } + case AR6000_XIOTCL_WMI_P2P_SD_CANCEL_REQUEST: + { + A_UINT32 qid; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&qid, userdata, sizeof(qid))) { + ret = -EFAULT; + } else if (p2p_sd_cancel_request(A_WMI_GET_P2P_CTX(arPriv),qid) != + A_OK) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_WMI_GET_P2P_IE: + { + A_UINT8 buf[12]; + const A_UINT8 zero_mac[] = {0,0,0,0,0,0}; + A_UINT8 * p2p_buf = NULL; + A_UINT8 p2p_buf_len = 0; + + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(buf, userdata, 12)) { + ret = -EFAULT; + } else { + + if (p2p_peer(A_WMI_GET_P2P_CTX(arPriv), + buf, *(buf+6)) == A_OK) { + + p2p_get_device_p2p_buf(A_WMI_GET_P2P_CTX(arPriv),buf, &p2p_buf, &p2p_buf_len); + + if(p2p_buf) { + *((A_UINT8 *)rq->ifr_data) = p2p_buf_len; + + if(copy_to_user(((A_UINT8 *)(rq->ifr_data)+1), + p2p_buf, p2p_buf_len)) { + ret = -EFAULT; + } + } + } else { + if(copy_to_user((A_UINT16 *)rq->ifr_data, + zero_mac, IEEE80211_ADDR_LEN)) { + ret = -EFAULT; + } + } + } + break; + } +#endif /* P2P */ + +#ifdef CONFIG_PM + case AR6000_XIOCTL_SET_BT_HW_POWER_STATE: + { + unsigned int state; + get_user(state, (unsigned int *)userdata); + if (ar6000_set_bt_hw_state(ar, state)!=A_OK) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_GET_BT_HW_POWER_STATE: + rq->ifr_ifru.ifru_ivalue = !ar->arBTOff; /* return value */ + break; +#endif + + case AR6000_XIOCTL_WMI_SET_TX_SGI_PARAM: + { + WMI_SET_TX_SGI_PARAM_CMD SGICmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&SGICmd, userdata, + sizeof(SGICmd))){ + ret = -EFAULT; + } else{ + if (wmi_SGI_cmd(arPriv->arWmi, SGICmd.sgiMask, SGICmd.sgiPERThreshold) != A_OK) { + ret = -EIO; + } + + } + break; + } + + case AR6000_XIOCTL_WMI_SET_PASSPHRASE: + { + ret = ar6000_xioctl_set_passphrase_cmd(dev, userdata); + break; + } + + case AR6000_XIOCTL_WMI_SET_EXCESS_TX_RETRY_THRES: + { + ret = ar6000_xioctl_set_excess_tx_retry_thres_cmd(dev, userdata); + break; + } + + case AR6000_XIOCTL_WMI_ENABLE_WAC_PARAM: + { + WMI_WAC_ENABLE_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) + { + ret = -EFAULT; + } else { + if ( cmd.enable & 0x80 ) { + cmd.enable &= ~0x80; + ar6000_send_generic_event_to_app(arPriv, WMI_ENABLE_WAC_CMDID, + (A_UINT8*)&cmd, sizeof(WMI_WAC_ENABLE_CMD)); + } + else { + if (wmi_wac_enable_cmd(arPriv->arWmi, &cmd) + != A_OK) + { + ret = -EIO; + } + } + } + break; + } + + case AR6000_XIOCTL_WAC_SCAN_REPLY: + { + WMI_WAC_SCAN_REPLY_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) + { + ret = -EFAULT; + } else { + if (wmi_wac_scan_reply_cmd(arPriv->arWmi, cmd.cmdid) + != A_OK) + { + ret = -EIO; + } + } + break; + } + + case AR6000_XIOCTL_WMI_WAC_CTRL_REQ: + { + WMI_WAC_CTRL_REQ_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) + { + ret = -EFAULT; + } else { + if ( WAC_SET == cmd.req ) { + if (wmi_wac_ctrl_req_cmd(arPriv->arWmi, &cmd) + != A_OK) + { + ret = -EIO; + } + } + else if ( WAC_GET == cmd.req ) { + ret = ar6000_xioctl_wac_ctrl_req_get_cmd(dev, userdata, rq); + } + } + break; + } + + case AR6000_XIOCTL_WMI_SET_WPA_OFFLOAD_STATE: + { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + A_UINT8 wpaOffloadState = 0; + + if (copy_from_user(&wpaOffloadState, userdata, sizeof(A_UINT8))) { + ret = -EFAULT; + } else { + arSta->wpaOffloadEnabled = (wpaOffloadState) ? TRUE : FALSE; + } +#else + ret = -EOPNOTSUPP; +#endif /* LINUX_VERSION_CODE >= 2.6.27 */ + break; + } + + case AR6000_XIOCTL_BMI_NVRAM_PROCESS: + { + A_UCHAR seg_name[BMI_NVRAM_SEG_NAME_SZ+1]; + A_UINT32 rv = 0; + + if (copy_from_user(seg_name, userdata, sizeof(seg_name))) { + ret = -EFAULT; + break; + } + + seg_name[BMI_NVRAM_SEG_NAME_SZ] = '\0'; + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Process NVRAM segment: %s\n", seg_name)); + + if (BMInvramProcess(hifDevice, seg_name, &rv) != A_OK) { + ret = -EIO; + } + put_user(rv, (unsigned int *)rq->ifr_data); /* return value */ + + break; + } + + case AR6000_XIOCTL_AP_ACS_DISABLE_HI_CHANNELS: + { + A_UINT32 acs; + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&acs, userdata, sizeof(acs))) { + ret = -EFAULT; + } else { + ar->arAcsDisableHiChannel = acs; + } + break; + } + + case AR6000_XIOCTL_WMI_FORCE_ASSERT: + { + if (wmi_force_target_assert(arPriv->arWmi) != A_OK) + { + ret = -EIO; + } + break; + } + + case AR6000_XIOCTL_WMI_SET_DIVERSITY_PARAM: + { + WMI_DIV_PARAMS_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) + { + ret = -EFAULT; + } else + { + if (wmi_set_div_param_cmd(arPriv->arWmi, cmd.divIdleTime, cmd.antRssiThresh, cmd.divEnable, cmd.active_treshold_rate) + != A_OK) + { + ret = -EIO; + } + + } + break; + } + case AR6000_XIOCTL_AP_GET_NUM_STA: + { + A_UINT8 num_sta, ret_num_sta; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&num_sta, userdata, sizeof(num_sta))) { + ret = -EFAULT; + } else { + if(num_sta & 0x80) { + ret_num_sta = ar->gNumSta; + } else { + ret_num_sta = arPriv->num_sta; + } + if(copy_to_user((A_UINT8 *)rq->ifr_data, + &ret_num_sta, sizeof(A_UINT8))) { + ret = -EFAULT; + } + } + break; + } +#ifdef CONFIG_PM + case AR6000_XIOCTL_SUSPEND_DRIVER: + { + ar6000_suspend_ev(ar); + break; + } + case AR6000_XIOCTL_RESUME_DRIVER: + { + ar6000_resume_ev(ar); + break; + } +#endif + case AR6000_XIOCTL_GET_SUBMODE: + { + if (copy_to_user((A_UINT8 *)rq->ifr_data, &arPriv->arNetworkSubType, + sizeof(A_UINT8))) + { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_WMI_AP_SET_APSD: + { + WMI_AP_SET_APSD_CMD cmd; + + if (ar->arWmiReady == FALSE) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(WMI_AP_SET_APSD_CMD))) { + ret = -EFAULT; + } else { + if(wmi_ap_set_apsd(arPriv->arWmi, cmd.enable) != A_OK) { + ret = -EIO; + } else { + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + } + } + break; + } + + default: + ret = -EOPNOTSUPP; + } + +ioctl_done: + rtnl_lock(); /* restore rtnl state */ + dev_put(dev); + + return ret; +} + +A_UINT8 mac_cmp_wild(A_UINT8 *mac, A_UINT8 *new_mac, A_UINT8 wild, A_UINT8 new_wild) +{ + A_UINT8 i; + + for(i=0;i=0;i--) + { + if(mac_cmp_wild(a->acl_mac[i], acl->mac, a->wildcard[i], + acl->wildcard)==0) + already_avail = i; + + if(!((1 << i) & a->index)) + free_slot = i; + } + + if(acl->action == ADD_MAC_ADDR) + { + /* Dont add mac if it is already available */ + if((already_avail >= 0) || (free_slot == -1)) + return 0; + + A_MEMCPY(a->acl_mac[free_slot], acl->mac, ATH_MAC_LEN); + a->index = a->index | (1 << free_slot); + acl->index = free_slot; + a->wildcard[free_slot] = acl->wildcard; + return 1; + } + else if(acl->action == DEL_MAC_ADDR) + { + if(acl->index > AP_ACL_SIZE) + return 0; + + if(!(a->index & (1 << acl->index))) + return 0; + + A_MEMZERO(a->acl_mac[acl->index],ATH_MAC_LEN); + a->index = a->index & ~(1 << acl->index); + a->wildcard[acl->index] = 0; + return 1; + } + + return 0; +} diff --git a/drivers/net/wireless/ar6003/host/os/linux/netbuf.c b/drivers/net/wireless/ar6003/host/os/linux/netbuf.c new file mode 100644 index 000000000000..963b99e7cc9f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/netbuf.c @@ -0,0 +1,272 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ +#include +#include +#include +#include "athdefs.h" +#include "a_types.h" +#include "a_osapi.h" +#include "htc_packet.h" + +#define AR6000_DATA_OFFSET 64 + +void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt) +{ + skb_queue_tail((struct sk_buff_head *) q, (struct sk_buff *) pkt); +} + +void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt) +{ + skb_queue_head((struct sk_buff_head *) q, (struct sk_buff *) pkt); +} + +void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q) +{ + return((void *) skb_dequeue((struct sk_buff_head *) q)); +} + +int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q) +{ + return(skb_queue_len((struct sk_buff_head *) q)); +} + +int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q) +{ + return(skb_queue_empty((struct sk_buff_head *) q)); +} + +void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q) +{ + skb_queue_head_init((struct sk_buff_head *) q); +} + +#ifdef AR6K_ALLOC_DEBUG +void * +a_netbuf_alloc(int size, const char *func, int lineno) +#else +void * +a_netbuf_alloc(int size) +#endif +{ + struct sk_buff *skb; + size += 2 * (A_GET_CACHE_LINE_BYTES()); /* add some cacheline space at front and back of buffer */ + skb = dev_alloc_skb(AR6000_DATA_OFFSET + sizeof(HTC_PACKET) + size); + if (skb) { + skb_reserve(skb, AR6000_DATA_OFFSET + sizeof(HTC_PACKET) + A_GET_CACHE_LINE_BYTES()); +#ifdef AR6K_ALLOC_DEBUG + __a_meminfo_add(skb, size, func, lineno); +#endif + } + return ((void *)skb); +} + +/* + * Allocate an SKB w.o. any encapsulation requirement. + */ +#ifdef AR6K_ALLOC_DEBUG +void * +a_netbuf_alloc_raw(int size, const char *func, int lineno) +#else +void * +a_netbuf_alloc_raw(int size) +#endif +{ + struct sk_buff *skb; + + skb = dev_alloc_skb(size); +#ifdef AR6K_ALLOC_DEBUG + __a_meminfo_add(skb, size, func, lineno); +#endif + return ((void *)skb); +} + +void +a_netbuf_free(void *bufPtr) +{ + struct sk_buff *skb = (struct sk_buff *)bufPtr; +#ifdef AR6K_ALLOC_DEBUG + a_meminfo_del(bufPtr); +#endif + dev_kfree_skb(skb); +} + +A_UINT32 +a_netbuf_to_len(void *bufPtr) +{ + return (((struct sk_buff *)bufPtr)->len); +} + +void * +a_netbuf_to_data(void *bufPtr) +{ + return (((struct sk_buff *)bufPtr)->data); +} + +/* + * Add len # of bytes to the beginning of the network buffer + * pointed to by bufPtr + */ +A_STATUS +a_netbuf_push(void *bufPtr, A_INT32 len) +{ + skb_push((struct sk_buff *)bufPtr, len); + + return A_OK; +} + +/* + * Add len # of bytes to the beginning of the network buffer + * pointed to by bufPtr and also fill with data + */ +A_STATUS +a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len) +{ + skb_push((struct sk_buff *) bufPtr, len); + A_MEMCPY(((struct sk_buff *)bufPtr)->data, srcPtr, len); + + return A_OK; +} + +/* + * Add len # of bytes to the end of the network buffer + * pointed to by bufPtr + */ +A_STATUS +a_netbuf_put(void *bufPtr, A_INT32 len) +{ + skb_put((struct sk_buff *)bufPtr, len); + + return A_OK; +} + +/* + * Add len # of bytes to the end of the network buffer + * pointed to by bufPtr and also fill with data + */ +A_STATUS +a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len) +{ + char *start = (char*)(((struct sk_buff *)bufPtr)->data + + ((struct sk_buff *)bufPtr)->len); + skb_put((struct sk_buff *)bufPtr, len); + A_MEMCPY(start, srcPtr, len); + + return A_OK; +} + + +/* + * Trim the network buffer pointed to by bufPtr to len # of bytes + */ +A_STATUS +a_netbuf_setlen(void *bufPtr, A_INT32 len) +{ + skb_trim((struct sk_buff *)bufPtr, len); + + return A_OK; +} + +/* + * Chop of len # of bytes from the end of the buffer. + */ +A_STATUS +a_netbuf_trim(void *bufPtr, A_INT32 len) +{ + skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len); + + return A_OK; +} + +/* + * Chop of len # of bytes from the end of the buffer and return the data. + */ +A_STATUS +a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len) +{ + char *start = (char*)(((struct sk_buff *)bufPtr)->data + + (((struct sk_buff *)bufPtr)->len - len)); + + A_MEMCPY(dstPtr, start, len); + skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len); + + return A_OK; +} + + +/* + * Returns the number of bytes available to a a_netbuf_push() + */ +A_INT32 +a_netbuf_headroom(void *bufPtr) +{ + return (skb_headroom((struct sk_buff *)bufPtr)); +} + +/* + * Removes specified number of bytes from the beginning of the buffer + */ +A_STATUS +a_netbuf_pull(void *bufPtr, A_INT32 len) +{ + skb_pull((struct sk_buff *)bufPtr, len); + + return A_OK; +} + +/* + * Removes specified number of bytes from the beginning of the buffer + * and return the data + */ +A_STATUS +a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len) +{ + A_MEMCPY(dstPtr, ((struct sk_buff *)bufPtr)->data, len); + skb_pull((struct sk_buff *)bufPtr, len); + + return A_OK; +} + + +#ifdef AR6K_ALLOC_DEBUG +void a_netbuf_check(void *bufPtr, const char *func, int lineno) +{ + struct sk_buff *skb = (struct sk_buff *)bufPtr; + A_UINT32 len; + A_BOOL found = FALSE; + found = a_meminfo_find(skb); + + if (found == FALSE) + { + len = A_NETBUF_LEN(skb); + __a_meminfo_add(skb, len, func, lineno); + } +} +#endif + +#ifdef EXPORT_HCI_BRIDGE_INTERFACE +EXPORT_SYMBOL(a_netbuf_to_data); +EXPORT_SYMBOL(a_netbuf_put); +EXPORT_SYMBOL(a_netbuf_pull); +EXPORT_SYMBOL(a_netbuf_alloc); +EXPORT_SYMBOL(a_netbuf_free); +#endif diff --git a/drivers/net/wireless/ar6003/host/os/linux/wireless_ext.c b/drivers/net/wireless/ar6003/host/os/linux/wireless_ext.c new file mode 100644 index 000000000000..3413ba376b97 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/os/linux/wireless_ext.c @@ -0,0 +1,2945 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#define IWE_STREAM_ADD_EVENT(p1, p2, p3, p4, p5) \ + iwe_stream_add_event((p1), (p2), (p3), (p4), (p5)) +#else +#define IWE_STREAM_ADD_EVENT(p1, p2, p3, p4, p5) \ + iwe_stream_add_event((p2), (p3), (p4), (p5)) +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#define IWE_STREAM_ADD_POINT(p1, p2, p3, p4, p5) \ + iwe_stream_add_point((p1), (p2), (p3), (p4), (p5)) +#else +#define IWE_STREAM_ADD_POINT(p1, p2, p3, p4, p5) \ + iwe_stream_add_point((p2), (p3), (p4), (p5)) +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#define IWE_STREAM_ADD_VALUE(p1, p2, p3, p4, p5, p6) \ + iwe_stream_add_value((p1), (p2), (p3), (p4), (p5), (p6)) +#else +#define IWE_STREAM_ADD_VALUE(p1, p2, p3, p4, p5, p6) \ + iwe_stream_add_value((p2), (p3), (p4), (p5), (p6)) +#endif + +static void ar6000_set_quality(struct iw_quality *iq, A_INT8 rssi); +extern unsigned int wmitimeout; + +#if WIRELESS_EXT > 14 +/* + * Encode a WPA or RSN information element as a custom + * element using the hostap format. + */ +static u_int +encode_ie(void *buf, size_t bufsize, + const u_int8_t *ie, size_t ielen, + const char *leader, size_t leader_len) +{ + u_int8_t *p; + int i; + + if (bufsize < leader_len) + return 0; + p = buf; + memcpy(p, leader, leader_len); + bufsize -= leader_len; + p += leader_len; + for (i = 0; i < ielen && bufsize > 2; i++) + { + p += sprintf((char*)p, "%02x", ie[i]); + bufsize -= 2; + } + return (i == ielen ? p - (u_int8_t *)buf : 0); +} +#endif /* WIRELESS_EXT > 14 */ + +static A_UINT8 +get_bss_phy_capability(bss_t *bss) +{ + A_UINT8 capability = 0; + struct ieee80211_common_ie *cie = &bss->ni_cie; +#define CHAN_IS_11A(x) (!((x >= 2412) && (x <= 2484))) + if (CHAN_IS_11A(cie->ie_chan)) { + if (cie->ie_htcap) { + capability = WMI_11NA_CAPABILITY; + } else { + capability = WMI_11A_CAPABILITY; + } + } else if ((cie->ie_erp) || (cie->ie_xrates)) { + if (cie->ie_htcap) { + capability = WMI_11NG_CAPABILITY; + } else { + capability = WMI_11G_CAPABILITY; + } + } + return capability; +} + +void +ar6000_scan_node(void *arg, bss_t *ni) +{ + struct iw_event iwe; +#if WIRELESS_EXT > 14 + char buf[256]; +#endif + struct ar_giwscan_param *param; + A_CHAR *current_ev; + A_CHAR *end_buf; + struct ieee80211_common_ie *cie; + A_CHAR *current_val; + A_INT32 j; + A_UINT32 rate_len, data_len = 0; + + /* Node table now contains entries from P2P Action frames and Probe Request also. Return + * if the frame type is an action frame/ Probe request. + */ + if ((ni->ni_frametype == ACTION_MGMT_FTYPE) || (ni->ni_frametype == PROBEREQ_FTYPE) || (ni->ni_buf == NULL)) { + return; + } + + param = (struct ar_giwscan_param *)arg; + + current_ev = param->current_ev; + end_buf = param->end_buf; + + cie = &ni->ni_cie; + + if ((end_buf - current_ev) > IW_EV_ADDR_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWAP; + iwe.u.ap_addr.sa_family = ARPHRD_ETHER; + A_MEMCPY(iwe.u.ap_addr.sa_data, ni->ni_macaddr, 6); + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_ADDR_LEN); + } + param->bytes_needed += IW_EV_ADDR_LEN; + + data_len = cie->ie_ssid[1] + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWESSID; + iwe.u.data.flags = 1; + iwe.u.data.length = cie->ie_ssid[1]; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)&cie->ie_ssid[2]); + } + param->bytes_needed += data_len; + + if (cie->ie_capInfo & (IEEE80211_CAPINFO_ESS|IEEE80211_CAPINFO_IBSS)) { + if ((end_buf - current_ev) > IW_EV_UINT_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWMODE; + iwe.u.mode = cie->ie_capInfo & IEEE80211_CAPINFO_ESS ? + IW_MODE_MASTER : IW_MODE_ADHOC; + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_UINT_LEN); + } + param->bytes_needed += IW_EV_UINT_LEN; + } + + if ((end_buf - current_ev) > IW_EV_FREQ_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWFREQ; + iwe.u.freq.m = cie->ie_chan * 100000; + iwe.u.freq.e = 1; + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_FREQ_LEN); + } + param->bytes_needed += IW_EV_FREQ_LEN; + + if ((end_buf - current_ev) > IW_EV_QUAL_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVQUAL; + ar6000_set_quality(&iwe.u.qual, ni->ni_snr); + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_QUAL_LEN); + } + param->bytes_needed += IW_EV_QUAL_LEN; + + if ((end_buf - current_ev) > IW_EV_POINT_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWENCODE; + if (cie->ie_capInfo & IEEE80211_CAPINFO_PRIVACY) { + iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; + } else { + iwe.u.data.flags = IW_ENCODE_DISABLED; + } + iwe.u.data.length = 0; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, ""); + } + param->bytes_needed += IW_EV_POINT_LEN; + + /* supported bit rate */ + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWRATE; + iwe.u.bitrate.fixed = 0; + iwe.u.bitrate.disabled = 0; + iwe.u.bitrate.value = 0; + current_val = current_ev + IW_EV_LCP_LEN; + param->bytes_needed += IW_EV_LCP_LEN; + + if (cie->ie_rates != NULL) { + rate_len = cie->ie_rates[1]; + data_len = (rate_len * (IW_EV_PARAM_LEN - IW_EV_LCP_LEN)); + if ((end_buf - current_ev) > data_len) + { + for (j = 0; j < rate_len; j++) { + unsigned char val; + val = cie->ie_rates[2 + j]; + iwe.u.bitrate.value = + (val >= 0x80)? ((val - 0x80) * 500000): (val * 500000); + current_val = IWE_STREAM_ADD_VALUE(param->info, current_ev, + current_val, end_buf, + &iwe, IW_EV_PARAM_LEN); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_xrates != NULL) { + rate_len = cie->ie_xrates[1]; + data_len = (rate_len * (IW_EV_PARAM_LEN - IW_EV_LCP_LEN)); + if ((end_buf - current_ev) > data_len) + { + for (j = 0; j < rate_len; j++) { + unsigned char val; + val = cie->ie_xrates[2 + j]; + iwe.u.bitrate.value = + (val >= 0x80)? ((val - 0x80) * 500000): (val * 500000); + current_val = IWE_STREAM_ADD_VALUE(param->info, current_ev, + current_val, end_buf, + &iwe, IW_EV_PARAM_LEN); + } + } + param->bytes_needed += data_len; + } + /* remove fixed header if no rates were added */ + if ((current_val - current_ev) > IW_EV_LCP_LEN) + current_ev = current_val; + +#if WIRELESS_EXT >= 18 + /* IE */ + if (cie->ie_wpa != NULL) { + data_len = cie->ie_wpa[1] + 2 + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_wpa[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_wpa); + } + param->bytes_needed += data_len; + } + + if (cie->ie_rsn != NULL && cie->ie_rsn[0] == IEEE80211_ELEMID_RSN) { + data_len = cie->ie_rsn[1] + 2 + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_rsn[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_rsn); + } + param->bytes_needed += data_len; + } + +#endif /* WIRELESS_EXT >= 18 */ + + if ((end_buf - current_ev) > IW_EV_CHAR_LEN) + { + /* protocol */ + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWNAME; + switch (get_bss_phy_capability(ni)) { + case WMI_11A_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11a"); + break; + case WMI_11G_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g"); + break; + case WMI_11NA_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11na"); + break; + case WMI_11NG_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11ng"); + break; + default: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b"); + break; + } + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_CHAR_LEN); + } + param->bytes_needed += IW_EV_CHAR_LEN; + +#if WIRELESS_EXT > 14 + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = snprintf(buf, sizeof(buf), "bcn_int=%d", cie->ie_beaconInt); + data_len = iwe.u.data.length + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, buf); + } + param->bytes_needed += data_len; + +#if WIRELESS_EXT < 18 + if (cie->ie_wpa != NULL) { + static const char wpa_leader[] = "wpa_ie="; + data_len = (sizeof(wpa_leader) - 1) + ((cie->ie_wpa[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wpa, + cie->ie_wpa[1]+2, + wpa_leader, sizeof(wpa_leader)-1); + + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_rsn != NULL && cie->ie_rsn[0] == IEEE80211_ELEMID_RSN) { + static const char rsn_leader[] = "rsn_ie="; + data_len = (sizeof(rsn_leader) - 1) + ((cie->ie_rsn[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_rsn, + cie->ie_rsn[1]+2, + rsn_leader, sizeof(rsn_leader)-1); + + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } +#endif /* WIRELESS_EXT < 18 */ + + if (cie->ie_wmm != NULL) { + static const char wmm_leader[] = "wmm_ie="; + data_len = (sizeof(wmm_leader) - 1) + ((cie->ie_wmm[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wmm, + cie->ie_wmm[1]+2, + wmm_leader, sizeof(wmm_leader)-1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_ath != NULL) { + static const char ath_leader[] = "ath_ie="; + data_len = (sizeof(ath_leader) - 1) + ((cie->ie_ath[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_ath, + cie->ie_ath[1]+2, + ath_leader, sizeof(ath_leader)-1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + +#ifdef WAPI_ENABLE + if (cie->ie_wapi != NULL) { + static const char wapi_leader[] = "wapi_ie="; + data_len = (sizeof(wapi_leader) - 1) + ((cie->ie_wapi[1] + 2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wapi, + cie->ie_wapi[1] + 2, + wapi_leader, sizeof(wapi_leader) - 1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } +#endif /* WAPI_ENABLE */ + +#endif /* WIRELESS_EXT > 14 */ + +#if WIRELESS_EXT >= 18 + if (cie->ie_wsc != NULL) { + data_len = (cie->ie_wsc[1] + 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_wsc[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_wsc); + } + param->bytes_needed += data_len; + } +#endif /* WIRELESS_EXT >= 18 */ + + param->current_ev = current_ev; +} + +int +ar6000_ioctl_giwscan(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + struct ar_giwscan_param param; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + param.current_ev = extra; + param.end_buf = extra + data->length; + param.bytes_needed = 0; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + param.info = info; +#endif + + /* Translate data to WE format */ + wmi_iterate_nodes(arPriv->arWmi, ar6000_scan_node, ¶m); + + /* check if bytes needed is greater than bytes consumed */ + if (param.bytes_needed > (param.current_ev - extra)) + { + /* Request one byte more than needed, because when "data->length" equals bytes_needed, + it is not possible to add the last event data as all iwe_stream_add_xxxxx() functions + checks whether (cur_ptr + ev_len) < end_ptr, due to this one more retry would happen*/ + data->length = param.bytes_needed + 1; + + return -E2BIG; + } + + return 0; +} + +extern int reconnect_flag; +/* SIOCSIWESSID */ +static int +ar6000_ioctl_siwessid(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *ssid) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_DEV_T *arTempPriv = NULL; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + A_STATUS status; + A_UINT8 i=0; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + +#if defined(WIRELESS_EXT) + if (WIRELESS_EXT > 20) { + data->length += 1; + } +#endif + /* Handling AP-STA Concurrency */ + if((ar->arConfNumDev > 1)) { + if ((data->flags) && + (arPriv->arNetworkType == INFRA_NETWORK) && + ((arPriv->arSsidLen != (data->length - 1)) || + (A_MEMCMP(arPriv->arSsid, ssid, arPriv->arSsidLen) != 0))){ + for(i=0;iarConfNumDev;i++) { + arTempPriv = ar->arDev[i]; + if((AP_NETWORK == arTempPriv->arNetworkType) && + (arTempPriv->arConnected)) { + wmi_disconnect_cmd(arTempPriv->arWmi); + /*Restart AP only in non P2P mode*/ + if((arTempPriv->arNetworkSubType != SUBTYPE_P2PGO) && + (arTempPriv->arNetworkSubType !=SUBTYPE_P2PDEV)){ + arTempPriv->arHoldConnection = TRUE; + ar->arHoldConnection = TRUE; + arTempPriv->ap_profile_flag = TRUE; + } + } + } + } + } + /* + * iwconfig passes a null terminated string with length including this + * so we need to account for this + */ + if (data->flags && (!data->length || (data->length == 1) || + ((data->length - 1) > sizeof(arPriv->arSsid)))) + { + /* + * ssid is invalid + */ + return -EINVAL; + } + + if (arPriv->arNetworkType == AP_NETWORK) { + if(!data->flags) { + /* stop AP */ + wmi_disconnect_cmd(arPriv->arWmi); + if(arPriv->arNetworkSubType == SUBTYPE_P2PGO) { + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->arConnected == FALSE, wmitimeout * HZ); + if (signal_pending(current)) { + return -EINTR; + } + } + + } else if(A_MEMCMP(arPriv->arSsid,ssid,32) != 0) { + /* SSID change for AP network - Will take effect on commit */ + arPriv->arSsidLen = data->length - 1; + A_MEMZERO(arPriv->arSsid, WMI_MAX_SSID_LEN); + A_MEMCPY(arPriv->arSsid, ssid, arPriv->arSsidLen); + } + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + arPriv->arConnected = FALSE; + return 0; + } + + /* Added for bug 25178, return an IOCTL error instead of target returning + Illegal parameter error when either the BSSID or channel is missing + and we cannot scan during connect. + */ + if (data->flags) { + if (arSta->arSkipScan == TRUE && + (arPriv->arChannelHint == 0 || + (!arSta->arReqBssid[0] && !arSta->arReqBssid[1] && !arSta->arReqBssid[2] && + !arSta->arReqBssid[3] && !arSta->arReqBssid[4] && !arSta->arReqBssid[5]))) + { + return -EINVAL; + } + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + up(&ar->arSem); + return -EBUSY; + } + + if (ar->arTxPending[wmi_get_control_ep(arPriv->arWmi)]) { + /* + * sleep until the command queue drains + */ + wait_event_interruptible_timeout(arPriv->arEvent, + ar->arTxPending[wmi_get_control_ep(arPriv->arWmi)] == 0, wmitimeout * HZ); + if (signal_pending(current)) { + up(&ar->arSem); + return -EINTR; + } + } + + + if (!data->flags) { +#ifdef ATH6K_CONFIG_CFG80211 + if (arPriv->arConnected) { +#endif /* ATH6K_CONFIG_CFG80211 */ + ar6000_init_mode_info(arPriv); +#ifdef ATH6K_CONFIG_CFG80211 + } +#endif /* ATH6K_CONFIG_CFG80211 */ + } + + if (((arPriv->arSsidLen) || + ((arPriv->arSsidLen == 0) && (arPriv->arConnected || arSta->arConnectPending)) || + (!data->flags))) + { + if ((!data->flags) || + (A_MEMCMP(arPriv->arSsid, ssid, arPriv->arSsidLen) != 0) || + (arPriv->arSsidLen != (data->length - 1))) + { + /* + * SSID set previously or essid off has been issued. + * + * Disconnect Command is issued in two cases after wmi is ready + * (1) ssid is different from the previous setting + * (2) essid off has been issued + * + */ + if (ar->arWmiReady == TRUE) { + reconnect_flag = 0; + status = wmi_setPmkid_cmd(arPriv->arWmi, arPriv->arBssid, NULL, 0); + ar6000_disconnect(arPriv); + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + if (arSta->arSkipScan == FALSE) { + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + } + if (!data->flags) { + up(&ar->arSem); + return 0; + } + } else { + up(&ar->arSem); + } + } + else + { + /* + * SSID is same, so we assume profile hasn't changed. + * If the interface is up and wmi is ready, we issue + * a reconnect cmd. Issue a reconnect only we are already + * connected. + */ + if((arPriv->arConnected == TRUE) && (ar->arWmiReady == TRUE)) + { + reconnect_flag = TRUE; + status = wmi_reconnect_cmd(arPriv->arWmi,arSta->arReqBssid, + arPriv->arChannelHint); + up(&ar->arSem); + if (status != A_OK) { + return -EIO; + } + return 0; + } + else{ + /* + * Dont return if connect is pending. + */ + if(!(arSta->arConnectPending)) { + up(&ar->arSem); + return 0; + } + } + } + } + + arPriv->arSsidLen = data->length - 1; + A_MEMCPY(arPriv->arSsid, ssid, arPriv->arSsidLen); + + if (ar6000_connect_to_ap(arPriv)!= A_OK) { + up(&ar->arSem); + return -EIO; + }else{ + up(&ar->arSem); + } + return 0; +} + +/* SIOCGIWESSID */ +static int +ar6000_ioctl_giwessid(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *essid) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (!arPriv->arSsidLen) { + return -EINVAL; + } + + data->flags = 1; + data->length = arPriv->arSsidLen; + A_MEMCPY(essid, arPriv->arSsid, arPriv->arSsidLen); + + return 0; +} + + +void ar6000_install_static_wep_keys(AR_SOFTC_DEV_T *arPriv) +{ + A_UINT8 index; + A_UINT8 keyUsage; + AR_SOFTC_AP_T *ap = &arPriv->arAp; + + for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { + if (arPriv->arWepKeyList[index].arKeyLen) { + keyUsage = GROUP_USAGE; + if (index == arPriv->arDefTxKeyIndex) { + keyUsage |= TX_USAGE; + } + wmi_addKey_cmd(arPriv->arWmi, + index, + WEP_CRYPT, + keyUsage, + arPriv->arWepKeyList[index].arKeyLen, + NULL, + arPriv->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + } + ap->deKeySet = FALSE; +} + +/* + * SIOCSIWRATE + */ +int +ar6000_ioctl_siwrate(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + A_UINT32 kbps; + A_INT8 rate_idx; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (rrq->fixed) { + kbps = rrq->value / 1000; /* rrq->value is in bps */ + } else { + kbps = -1; /* -1 indicates auto rate */ + } + if(kbps != -1 && wmi_validate_bitrate(arPriv->arWmi, kbps, &rate_idx) != A_OK) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BitRate is not Valid %d\n", kbps)); + return -EINVAL; + } + arPriv->arBitRate = kbps; + if(ar->arWmiReady == TRUE) + { + if (wmi_set_bitrate_cmd(arPriv->arWmi, kbps, -1, -1) != A_OK) { + return -EINVAL; + } + } + return 0; +} + +/* + * SIOCGIWRATE + */ +int +ar6000_ioctl_giwrate(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + int ret = 0; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if ((arPriv->arNextMode != AP_NETWORK && !arPriv->arConnected) || ar->arWmiReady == FALSE) { + rrq->value = 1000 * 1000; + return 0; + } + + if (arPriv->arBitRate!=-1 && arPriv->arBitRate!=0xFFFF) { + rrq->fixed = TRUE; + rrq->value = arPriv->arBitRate * 1000; + return 0; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + up(&ar->arSem); + return -EBUSY; + } + + arPriv->arBitRate = 0xFFFF; + if (wmi_get_bitrate_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + return -EIO; + } + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->arBitRate != 0xFFFF, wmitimeout * HZ); + if (signal_pending(current)) { + ret = -EINTR; + } + /* If the interface is down or wmi is not ready or the target is not + connected - return the value stored in the device structure */ + if (!ret) { + if (arPriv->arBitRate == -1) { + rrq->fixed = TRUE; + rrq->value = 0; + } else { + rrq->fixed = FALSE; + rrq->value = arPriv->arBitRate * 1000; + } + arPriv->arBitRate = -1; /* clean it up for next query */ + } + + up(&ar->arSem); + + return ret; +} + +/* + * SIOCSIWTXPOW + */ +static int +ar6000_ioctl_siwtxpow(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + A_UINT8 dbM; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (rrq->disabled) { + return -EOPNOTSUPP; + } + + if (rrq->fixed) { + if (rrq->flags != IW_TXPOW_DBM) { + return -EOPNOTSUPP; + } + arPriv->arTxPwr= dbM = rrq->value; + arPriv->arTxPwrSet = TRUE; + } else { + arPriv->arTxPwr = dbM = 0; + arPriv->arTxPwrSet = FALSE; + } + if(ar->arWmiReady == TRUE) + { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("Set tx pwr cmd %d dbM\n", dbM)); + wmi_set_txPwr_cmd(arPriv->arWmi, dbM); + } + return 0; +} + +/* + * SIOCGIWTXPOW + */ +int +ar6000_ioctl_giwtxpow(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + int ret = 0; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + if((ar->arWmiReady == TRUE) && (arPriv->arConnected == TRUE)) + { + arPriv->arTxPwr = 0; + + if (wmi_get_txPwr_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arPriv->arTxPwr != 0, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + } + /* If the interace is down or wmi is not ready or target is not connected + then return value stored in the device structure */ + + if (!ret) { + if (arPriv->arTxPwrSet == TRUE) { + rrq->fixed = TRUE; + } + rrq->value = arPriv->arTxPwr; + rrq->flags = IW_TXPOW_DBM; + // + // IWLIST need this flag to get TxPower + // + rrq->disabled = 0; + } + + up(&ar->arSem); + + return ret; +} + +/* + * SIOCSIWRETRY + * since iwconfig only provides us with one max retry value, we use it + * to apply to data frames of the BE traffic class. + */ +static int +ar6000_ioctl_siwretry(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (rrq->disabled) { + return -EOPNOTSUPP; + } + + if ((rrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) { + return -EOPNOTSUPP; + } + + if ( !(rrq->value >= WMI_MIN_RETRIES) || !(rrq->value <= WMI_MAX_RETRIES)) { + return - EINVAL; + } + if(ar->arWmiReady == TRUE) + { + if (wmi_set_retry_limits_cmd(arPriv->arWmi, DATA_FRAMETYPE, WMM_AC_BE, + rrq->value, 0) != A_OK){ + return -EINVAL; + } + } + arPriv->arMaxRetries = rrq->value; + return 0; +} + +/* + * SIOCGIWRETRY + */ +static int +ar6000_ioctl_giwretry(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + rrq->disabled = 0; + switch (rrq->flags & IW_RETRY_TYPE) { + case IW_RETRY_LIFETIME: + return -EOPNOTSUPP; + break; + case IW_RETRY_LIMIT: + rrq->flags = IW_RETRY_LIMIT; + switch (rrq->flags & IW_RETRY_MODIFIER) { + case IW_RETRY_MIN: + rrq->flags |= IW_RETRY_MIN; + rrq->value = WMI_MIN_RETRIES; + break; + case IW_RETRY_MAX: + rrq->flags |= IW_RETRY_MAX; + rrq->value = arPriv->arMaxRetries; + break; + } + break; + } + return 0; +} + +/* + * SIOCSIWENCODE + */ +static int +ar6000_ioctl_siwencode(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *keybuf) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_AP_T *ap = &arPriv->arAp; + + int index; + A_INT32 auth = 0; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if(arPriv->arNextMode != AP_NETWORK) { + /* + * Static WEP Keys should be configured before setting the SSID + */ + if (arPriv->arSsid[0] && erq->length) { + return -EIO; + } + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + index = erq->flags & IW_ENCODE_INDEX; + + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) + { + return -EIO; + } + + if (erq->flags & IW_ENCODE_DISABLED) { + /* + * Encryption disabled + */ + if (index) { + /* + * If key index was specified then clear the specified key + */ + index--; + A_MEMZERO(arPriv->arWepKeyList[index].arKey, + sizeof(arPriv->arWepKeyList[index].arKey)); + arPriv->arWepKeyList[index].arKeyLen = 0; + } + arPriv->arDot11AuthMode = OPEN_AUTH; + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arAuthMode = WMI_NONE_AUTH; + } else { + /* + * Enabling WEP encryption + */ + if (index) { + index--; /* keyindex is off base 1 in iwconfig */ + } + + if (erq->flags & IW_ENCODE_OPEN) { + auth |= OPEN_AUTH; + } + if (erq->flags & IW_ENCODE_RESTRICTED) { + auth |= SHARED_AUTH; + } + + if (!auth) { + auth = OPEN_AUTH; + } + + if (!ap->deKeySet) { + arPriv->arDefTxKeyIndex = index; + } + + if (erq->length) { + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(erq->length)) { + return -EIO; + } + + A_MEMZERO(arPriv->arWepKeyList[index].arKey, + sizeof(arPriv->arWepKeyList[index].arKey)); + A_MEMCPY(arPriv->arWepKeyList[index].arKey, keybuf, erq->length); + arPriv->arWepKeyList[index].arKeyLen = erq->length; + arPriv->arDot11AuthMode = auth; + } else { + if (arPriv->arWepKeyList[index].arKeyLen == 0) { + return -EIO; + } + arPriv->arDefTxKeyIndex = index; + + if(arPriv->arSsidLen && arPriv->arWepKeyList[index].arKeyLen) { + wmi_addKey_cmd(arPriv->arWmi, + index, + WEP_CRYPT, + GROUP_USAGE | TX_USAGE, + arPriv->arWepKeyList[index].arKeyLen, + NULL, + arPriv->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + ap->deKeySet = TRUE; + } + + arPriv->arPairwiseCrypto = WEP_CRYPT; + arPriv->arGroupCrypto = WEP_CRYPT; + arPriv->arAuthMode = WMI_NONE_AUTH; + } + + if(arPriv->arNextMode != AP_NETWORK) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + } + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + return 0; +} + +static int +ar6000_ioctl_giwencode(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *key) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + A_UINT8 keyIndex; + struct ar_wep_key *wk; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (arPriv->arPairwiseCrypto == NONE_CRYPT) { + erq->length = 0; + erq->flags = IW_ENCODE_DISABLED; + } else { + if (arPriv->arPairwiseCrypto == WEP_CRYPT) { + /* get the keyIndex */ + keyIndex = erq->flags & IW_ENCODE_INDEX; + if (0 == keyIndex) { + keyIndex = arPriv->arDefTxKeyIndex; + } else if ((keyIndex - 1 < WMI_MIN_KEY_INDEX) || + (keyIndex - 1 > WMI_MAX_KEY_INDEX)) + { + keyIndex = WMI_MIN_KEY_INDEX; + } else { + keyIndex--; + } + erq->flags = keyIndex + 1; + erq->flags &= ~IW_ENCODE_DISABLED; + wk = &arPriv->arWepKeyList[keyIndex]; + if (erq->length > wk->arKeyLen) { + erq->length = wk->arKeyLen; + } + if (wk->arKeyLen) { + A_MEMCPY(key, wk->arKey, erq->length); + } + } else { + erq->flags &= ~IW_ENCODE_DISABLED; + if (arPriv->arSta.user_saved_keys.keyOk) { + erq->length = arPriv->arSta.user_saved_keys.ucast_ik.ik_keylen; + if (erq->length) { + A_MEMCPY(key, arPriv->arSta.user_saved_keys.ucast_ik.ik_keydata, erq->length); + } + } else { + erq->length = 1; // not really printing any key but let iwconfig know enc is on + } + } + + if (arPriv->arDot11AuthMode & OPEN_AUTH) { + erq->flags |= IW_ENCODE_OPEN; + } + if (arPriv->arDot11AuthMode & SHARED_AUTH) { + erq->flags |= IW_ENCODE_RESTRICTED; + } + } + + return 0; +} + +#if WIRELESS_EXT >= 18 +/* + * SIOCSIWGENIE + */ +static int +ar6000_ioctl_siwgenie(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_UCHAR *ie = extra; + A_UINT16 ieLen = erq->length; + const A_UINT8 wfa_oui[] = { 0x00, 0x50, 0xf2, 0x04 }; + const A_UINT8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 }; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + if (ieLen > IEEE80211_APPIE_FRAME_MAX_LEN) { + return -EIO; + } + + /* get the Information Element and check if it's a WPS IE */ + if (ieLen>=6 && + ((ie[0]==IEEE80211_ELEMID_VENDOR) && + memcmp(&ie[2], wfa_oui, sizeof(wfa_oui))==0)) { + /* WPS IE detected, notify target */ + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("WPS IE detected -- setting WPS flag\n")); + arPriv->arSta.arConnectCtrlFlags |= CONNECT_WPS_FLAG; + } else { + if ((ieLen>=1 && ie[0]==IEEE80211_ELEMID_RSN) || + (ieLen>=6 && ie[0]==IEEE80211_ELEMID_VENDOR && + memcmp(&ie[2], wpa_oui, sizeof(wpa_oui))==0)) { + ieLen = 0; /* Firmware will set for us. Clear the previous one */ + } +#ifdef CONFIG_WAPI + else if (ieLen>=1 && ie[0]==IEEE80211_ELEMID_WAPI) { + //A_PRINTF("Set WAPI IE\n"); + } +#endif + arPriv->arSta.arConnectCtrlFlags &= ~CONNECT_WPS_FLAG; + } + + wmi_set_appie_cmd(arPriv->arWmi, WMI_FRAME_ASSOC_REQ, ieLen, ie); + return 0; +} + + +/* + * SIOCGIWGENIE + */ +static int +ar6000_ioctl_giwgenie(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + erq->length = 0; + erq->flags = 0; + + return 0; +} + +/* + * SIOCSIWAUTH + */ +static int +ar6000_ioctl_siwauth(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *data, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + + A_BOOL profChanged; + A_UINT16 param; + A_INT32 ret; + A_INT32 value; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + param = data->flags & IW_AUTH_INDEX; + value = data->value; + profChanged = TRUE; + ret = 0; + + switch (param) { + case IW_AUTH_WPA_VERSION: + if (value & IW_AUTH_WPA_VERSION_DISABLED) { + arPriv->arAuthMode = WMI_NONE_AUTH; + } else if (value & IW_AUTH_WPA_VERSION_WPA) { + arPriv->arAuthMode = WMI_WPA_AUTH; + } else if (value & IW_AUTH_WPA_VERSION_WPA2) { + arPriv->arAuthMode = WMI_WPA2_AUTH; + } else { + ret = -1; + profChanged = FALSE; + } + break; + case IW_AUTH_CIPHER_PAIRWISE: + if (value & IW_AUTH_CIPHER_NONE) { + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP40) { + arPriv->arPairwiseCrypto = WEP_CRYPT; + arPriv->arPairwiseCryptoLen = 5; + } else if (value & IW_AUTH_CIPHER_TKIP) { + arPriv->arPairwiseCrypto = TKIP_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_CCMP) { + arPriv->arPairwiseCrypto = AES_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP104) { + arPriv->arPairwiseCrypto = WEP_CRYPT; + arPriv->arPairwiseCryptoLen = 13; +#ifdef WAPI_ENABLE + } else if (value & IW_AUTH_CIPHER_SMS4) { + arPriv->arPairwiseCrypto = WAPI_CRYPT; + arPriv->arPairwiseCryptoLen = 0; +#endif + } else { + ret = -1; + profChanged = FALSE; + } + break; + case IW_AUTH_CIPHER_GROUP: + if (value & IW_AUTH_CIPHER_NONE) { + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP40) { + arPriv->arGroupCrypto = WEP_CRYPT; + arPriv->arGroupCryptoLen = 5; + } else if (value & IW_AUTH_CIPHER_TKIP) { + arPriv->arGroupCrypto = TKIP_CRYPT; + arPriv->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_CCMP) { + arPriv->arGroupCrypto = AES_CRYPT; + arPriv->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP104) { + arPriv->arGroupCrypto = WEP_CRYPT; + arPriv->arGroupCryptoLen = 13; +#ifdef WAPI_ENABLE + } else if (value & IW_AUTH_CIPHER_SMS4) { + arPriv->arGroupCrypto = WAPI_CRYPT; + arPriv->arGroupCryptoLen = 0; +#endif + } else { + ret = -1; + profChanged = FALSE; + } + break; + case IW_AUTH_KEY_MGMT: + if (value & IW_AUTH_KEY_MGMT_PSK) { + if (WMI_WPA_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_PSK_AUTH; + } else if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_PSK_AUTH; + } else { + ret = -1; + } +#define IW_AUTH_KEY_MGMT_CCKM 8 + } else if (value & IW_AUTH_KEY_MGMT_CCKM) { + if (WMI_WPA_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA_AUTH_CCKM; + } else if (WMI_WPA2_AUTH == arPriv->arAuthMode) { + arPriv->arAuthMode = WMI_WPA2_AUTH_CCKM; + } else { + ret = -1; + } + } else if (!(value & IW_AUTH_KEY_MGMT_802_1X)) { + arPriv->arAuthMode = WMI_NONE_AUTH; + } + break; + case IW_AUTH_TKIP_COUNTERMEASURES: + wmi_set_tkip_countermeasures_cmd(arPriv->arWmi, value); + profChanged = FALSE; + break; + case IW_AUTH_DROP_UNENCRYPTED: + profChanged = FALSE; + break; + case IW_AUTH_80211_AUTH_ALG: + arPriv->arDot11AuthMode = 0; + if (value & IW_AUTH_ALG_OPEN_SYSTEM) { + arPriv->arDot11AuthMode |= OPEN_AUTH; + } + if (value & IW_AUTH_ALG_SHARED_KEY) { + arPriv->arDot11AuthMode |= SHARED_AUTH; + } + if (value & IW_AUTH_ALG_LEAP) { + arPriv->arDot11AuthMode = LEAP_AUTH; + } + if(arPriv->arDot11AuthMode == 0) { + ret = -1; + profChanged = FALSE; + } + break; + case IW_AUTH_WPA_ENABLED: + if (!value) { + arPriv->arAuthMode = WMI_NONE_AUTH; + /* when the supplicant is stopped, it calls this + * handler with value=0. The followings need to be + * reset if the STA were to connect again + * without security + */ + arPriv->arDot11AuthMode = OPEN_AUTH; + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arGroupCryptoLen = 0; + } + break; + case IW_AUTH_RX_UNENCRYPTED_EAPOL: + profChanged = FALSE; + break; + case IW_AUTH_ROAMING_CONTROL: + profChanged = FALSE; + break; + case IW_AUTH_PRIVACY_INVOKED: + if (!value) { + arPriv->arPairwiseCrypto = NONE_CRYPT; + arPriv->arPairwiseCryptoLen = 0; + arPriv->arGroupCrypto = NONE_CRYPT; + arPriv->arGroupCryptoLen = 0; + } + break; + default: + ret = -1; + profChanged = FALSE; + break; + } + + if (profChanged == TRUE) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + } + + return ret; +} + + +/* + * SIOCGIWAUTH + */ +static int +ar6000_ioctl_giwauth(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *data, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + A_UINT16 param; + A_INT32 ret; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + param = data->flags & IW_AUTH_INDEX; + ret = 0; + data->value = 0; + + + switch (param) { + case IW_AUTH_WPA_VERSION: + if (arPriv->arAuthMode == WMI_NONE_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_DISABLED; + } else if (arPriv->arAuthMode == WMI_WPA_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_WPA; + } else if (arPriv->arAuthMode == WMI_WPA2_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_WPA2; + } else { + ret = -1; + } + break; + case IW_AUTH_CIPHER_PAIRWISE: + if (arPriv->arPairwiseCrypto == NONE_CRYPT) { + data->value |= IW_AUTH_CIPHER_NONE; + } else if (arPriv->arPairwiseCrypto == WEP_CRYPT) { + if (arPriv->arPairwiseCryptoLen == 13) { + data->value |= IW_AUTH_CIPHER_WEP104; + } else { + data->value |= IW_AUTH_CIPHER_WEP40; + } + } else if (arPriv->arPairwiseCrypto == TKIP_CRYPT) { + data->value |= IW_AUTH_CIPHER_TKIP; + } else if (arPriv->arPairwiseCrypto == AES_CRYPT) { + data->value |= IW_AUTH_CIPHER_CCMP; + } else { + ret = -1; + } + break; + case IW_AUTH_CIPHER_GROUP: + if (arPriv->arGroupCrypto == NONE_CRYPT) { + data->value |= IW_AUTH_CIPHER_NONE; + } else if (arPriv->arGroupCrypto == WEP_CRYPT) { + if (arPriv->arGroupCryptoLen == 13) { + data->value |= IW_AUTH_CIPHER_WEP104; + } else { + data->value |= IW_AUTH_CIPHER_WEP40; + } + } else if (arPriv->arGroupCrypto == TKIP_CRYPT) { + data->value |= IW_AUTH_CIPHER_TKIP; + } else if (arPriv->arGroupCrypto == AES_CRYPT) { + data->value |= IW_AUTH_CIPHER_CCMP; + } else { + ret = -1; + } + break; + case IW_AUTH_KEY_MGMT: + if ((arPriv->arAuthMode == WMI_WPA_PSK_AUTH) || + (arPriv->arAuthMode == WMI_WPA2_PSK_AUTH)) { + data->value |= IW_AUTH_KEY_MGMT_PSK; + } else if ((arPriv->arAuthMode == WMI_WPA_AUTH) || + (arPriv->arAuthMode == WMI_WPA2_AUTH)) { + data->value |= IW_AUTH_KEY_MGMT_802_1X; + } + break; + case IW_AUTH_TKIP_COUNTERMEASURES: + // TODO. Save countermeassure enable/disable + data->value = 0; + break; + case IW_AUTH_DROP_UNENCRYPTED: + break; + case IW_AUTH_80211_AUTH_ALG: + if (arPriv->arDot11AuthMode == OPEN_AUTH) { + data->value |= IW_AUTH_ALG_OPEN_SYSTEM; + } else if (arPriv->arDot11AuthMode == SHARED_AUTH) { + data->value |= IW_AUTH_ALG_SHARED_KEY; + } else if (arPriv->arDot11AuthMode == LEAP_AUTH) { + data->value |= IW_AUTH_ALG_LEAP; + } else { + ret = -1; + } + break; + case IW_AUTH_WPA_ENABLED: + if (arPriv->arAuthMode == WMI_NONE_AUTH) { + data->value = 0; + } else { + data->value = 1; + } + break; + case IW_AUTH_RX_UNENCRYPTED_EAPOL: + break; + case IW_AUTH_ROAMING_CONTROL: + break; + case IW_AUTH_PRIVACY_INVOKED: + if (arPriv->arPairwiseCrypto == NONE_CRYPT) { + data->value = 0; + } else { + data->value = 1; + } + break; + default: + ret = -1; + break; + } + + return 0; +} + +/* + * SIOCSIWPMKSA + */ +static int +ar6000_ioctl_siwpmksa(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_INT32 ret; + A_STATUS status; + struct iw_pmksa *pmksa; + + pmksa = (struct iw_pmksa *)extra; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + ret = 0; + status = A_OK; + + switch (pmksa->cmd) { + case IW_PMKSA_ADD: + status = wmi_setPmkid_cmd(arPriv->arWmi, (A_UINT8*)pmksa->bssid.sa_data, pmksa->pmkid, TRUE); + break; + case IW_PMKSA_REMOVE: + status = wmi_setPmkid_cmd(arPriv->arWmi, (A_UINT8*)pmksa->bssid.sa_data, pmksa->pmkid, FALSE); + break; + case IW_PMKSA_FLUSH: + if (arPriv->arConnected == TRUE) { + status = wmi_setPmkid_cmd(arPriv->arWmi, arPriv->arBssid, NULL, 0); + } + break; + default: + ret=-1; + break; + } + if (status != A_OK) { + ret = -1; + } + + return ret; +} + +#ifdef WAPI_ENABLE + +#define PN_INIT 0x5c365c36 + +static int ar6000_set_wapi_key(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; + KEY_USAGE keyUsage = 0; + A_INT32 keyLen; + A_UINT8 *keyData; + A_INT32 index; + A_UINT32 *PN; + A_INT32 i; + A_STATUS status; + A_UINT8 wapiKeyRsc[16]; + CRYPTO_TYPE keyType = WAPI_CRYPT; + const A_UINT8 broadcastMac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + index = erq->flags & IW_ENCODE_INDEX; + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) { + return -EIO; + } + + index--; + if (index < 0 || index > 4) { + return -EIO; + } + keyData = (A_UINT8 *)(ext + 1); + keyLen = erq->length - sizeof(struct iw_encode_ext); + A_MEMCPY(wapiKeyRsc, ext->tx_seq, sizeof(wapiKeyRsc)); + + if (A_MEMCMP(ext->addr.sa_data, broadcastMac, sizeof(broadcastMac)) == 0) { + keyUsage |= GROUP_USAGE; + PN = (A_UINT32 *)wapiKeyRsc; + for (i = 0; i < 4; i++) { + PN[i] = PN_INIT; + } + } else { + keyUsage |= PAIRWISE_USAGE; + } + status = wmi_addKey_cmd(arPriv->arWmi, + index, + keyType, + keyUsage, + keyLen, + wapiKeyRsc, + keyData, + KEY_OP_INIT_WAPIPN, + NULL, + SYNC_BEFORE_WMIFLAG); + if (A_OK != status) { + return -EIO; + } + return 0; +} + +#endif + +/* + * SIOCSIWENCODEEXT + */ +static int +ar6000_ioctl_siwencodeext(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + A_INT32 index; + struct iw_encode_ext *ext; + KEY_USAGE keyUsage; + A_INT32 keyLen; + A_UINT8 *keyData; + A_UINT8 keyRsc[8]; + A_STATUS status; + CRYPTO_TYPE keyType; +#ifdef USER_KEYS + struct ieee80211req_key ik; +#endif /* USER_KEYS */ + AR_SOFTC_AP_T *arAp = &arPriv->arAp; + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + +#ifdef USER_KEYS + arPriv->arSta.user_saved_keys.keyOk = FALSE; +#endif /* USER_KEYS */ + + index = erq->flags & IW_ENCODE_INDEX; + + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) + { + return -EIO; + } + + ext = (struct iw_encode_ext *)extra; + if (erq->flags & IW_ENCODE_DISABLED) { + /* + * Encryption disabled + */ + if (index) { + /* + * If key index was specified then clear the specified key + */ + index--; + A_MEMZERO(arPriv->arWepKeyList[index].arKey, + sizeof(arPriv->arWepKeyList[index].arKey)); + arPriv->arWepKeyList[index].arKeyLen = 0; + } + } else { + /* + * Enabling WEP encryption + */ + if (index) { + index--; /* keyindex is off base 1 in iwconfig */ + } + + keyUsage = 0; + keyLen = erq->length - sizeof(struct iw_encode_ext); + + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { + keyUsage = TX_USAGE; + arPriv->arDefTxKeyIndex = index; + // Just setting the key index + if (keyLen == 0) { + return 0; + } + } + + if (keyLen <= 0) { + if (ext->alg == IW_ENCODE_ALG_KRK) { + wmi_delete_krk_cmd(arPriv->arWmi); + } + return -EIO; + } + + /* key follows iw_encode_ext */ + keyData = (A_UINT8 *)(ext + 1); + + switch (ext->alg) { + case IW_ENCODE_ALG_WEP: + keyType = WEP_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_WEP; +#endif /* USER_KEYS */ + if(arPriv->arNextMode == AP_NETWORK) { + arAp->ap_mode_bkey.ik_type = IEEE80211_CIPHER_WEP; + } + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(keyLen)) { + return -EIO; + } + + /* Check whether it is static wep. */ + if (!arPriv->arConnected) { + A_MEMZERO(arPriv->arWepKeyList[index].arKey, + sizeof(arPriv->arWepKeyList[index].arKey)); + A_MEMCPY(arPriv->arWepKeyList[index].arKey, keyData, keyLen); + arPriv->arWepKeyList[index].arKeyLen = keyLen; + + return 0; + } + break; + case IW_ENCODE_ALG_TKIP: + keyType = TKIP_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_TKIP; +#endif /* USER_KEYS */ + if(arPriv->arNextMode == AP_NETWORK) { + arAp->ap_mode_bkey.ik_type = IEEE80211_CIPHER_TKIP; + } + break; + case IW_ENCODE_ALG_CCMP: + keyType = AES_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_AES_CCM; +#endif /* USER_KEYS */ + if(arPriv->arNextMode == AP_NETWORK) { + arAp->ap_mode_bkey.ik_type = IEEE80211_CIPHER_AES_CCM; + } + break; +#ifdef WAPI_ENABLE + case IW_ENCODE_ALG_SM4: + return ar6000_set_wapi_key(dev, info, erq, extra); +#endif + case IW_ENCODE_ALG_PMK: + arPriv->arSta.arConnectCtrlFlags |= CONNECT_DO_WPA_OFFLOAD; + return wmi_set_pmk_cmd(arPriv->arWmi, keyData); + case IW_ENCODE_ALG_KRK: + return wmi_add_krk_cmd(arPriv->arWmi, keyData); + default: + return -EIO; + } + + + if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { + keyUsage |= GROUP_USAGE; + if(arPriv->arNextMode == AP_NETWORK) { + keyUsage &= ~TX_USAGE; + arAp->ap_mode_bkey.ik_keyix = index; + arAp->ap_mode_bkey.ik_keylen = keyLen; + memcpy(arAp->ap_mode_bkey.ik_keydata, keyData, keyLen); + memcpy(&arAp->ap_mode_bkey.ik_keyrsc, keyRsc, sizeof(keyRsc)); + memcpy(arAp->ap_mode_bkey.ik_macaddr, ext->addr.sa_data, ETH_ALEN); + } + } else { + keyUsage |= PAIRWISE_USAGE; + } + + if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { + A_MEMCPY(keyRsc, ext->rx_seq, sizeof(keyRsc)); + } else { + A_MEMZERO(keyRsc, sizeof(keyRsc)); + } + + if (((WMI_WPA_PSK_AUTH == arPriv->arAuthMode) || (WMI_WPA2_PSK_AUTH == arPriv->arAuthMode)) && + (GROUP_USAGE & keyUsage)) + { + A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); + } + + status = wmi_addKey_cmd(arPriv->arWmi, index, keyType, keyUsage, + keyLen, keyRsc, + keyData, KEY_OP_INIT_VAL, + (A_UINT8*)ext->addr.sa_data, + SYNC_BOTH_WMIFLAG); + if (status != A_OK) { + return -EIO; + } + +#ifdef USER_KEYS + ik.ik_keyix = index; + ik.ik_keylen = keyLen; + memcpy(ik.ik_keydata, keyData, keyLen); + memcpy(&ik.ik_keyrsc, keyRsc, sizeof(keyRsc)); + memcpy(ik.ik_macaddr, ext->addr.sa_data, ETH_ALEN); + if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { + memcpy(&arPriv->arSta.user_saved_keys.bcast_ik, &ik, + sizeof(struct ieee80211req_key)); + } else { + memcpy(&arPriv->arSta.user_saved_keys.ucast_ik, &ik, + sizeof(struct ieee80211req_key)); + } + arPriv->arSta.user_saved_keys.keyOk = TRUE; +#endif /* USER_KEYS */ + } + + + return 0; +} + +/* + * SIOCGIWENCODEEXT + */ +static int +ar6000_ioctl_giwencodeext(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (arPriv->arPairwiseCrypto == NONE_CRYPT) { + erq->length = 0; + erq->flags = IW_ENCODE_DISABLED; + } else { + erq->length = 0; + } + + return 0; +} +#endif // WIRELESS_EXT >= 18 + +#if WIRELESS_EXT > 20 +static int ar6000_ioctl_siwpower(struct net_device *dev, + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) +{ +#ifndef ATH6K_CONFIG_OTA_MODE + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_POWER_MODE power_mode; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (wrqu->power.disabled) + power_mode = MAX_PERF_POWER; + else + power_mode = REC_POWER; + + if (wmi_powermode_cmd(arPriv->arWmi, power_mode) < 0) + return -EIO; +#endif + return 0; +} + +static int ar6000_ioctl_giwpower(struct net_device *dev, + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + WMI_POWER_MODE power_mode; + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + power_mode = wmi_get_power_mode_cmd(arPriv->arWmi); + + if (power_mode == MAX_PERF_POWER) + wrqu->power.disabled = 1; + else + wrqu->power.disabled = 0; + + return 0; +} +#endif // WIRELESS_EXT > 20 + +/* + * SIOCGIWNAME + */ +int +ar6000_ioctl_giwname(struct net_device *dev, + struct iw_request_info *info, + char *name, char *extra) +{ + A_UINT8 capability; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + capability = arPriv->arPhyCapability; + if(arPriv->arNetworkType == INFRA_NETWORK && arPriv->arConnected) { + bss_t *bss = wmi_find_node(arPriv->arWmi, arPriv->arBssid); + if (bss) { + capability = get_bss_phy_capability(bss); + wmi_node_return(arPriv->arWmi, bss); + } + } + switch (capability) { + case (WMI_11A_CAPABILITY): + strncpy(name, "AR6000 802.11a", IFNAMSIZ); + break; + case (WMI_11G_CAPABILITY): + strncpy(name, "AR6000 802.11g", IFNAMSIZ); + break; + case (WMI_11AG_CAPABILITY): + strncpy(name, "AR6000 802.11ag", IFNAMSIZ); + break; + case (WMI_11NA_CAPABILITY): + strncpy(name, "AR6000 802.11na", IFNAMSIZ); + break; + case (WMI_11NG_CAPABILITY): + strncpy(name, "AR6000 802.11ng", IFNAMSIZ); + break; + case (WMI_11NAG_CAPABILITY): + strncpy(name, "AR6K 802.11nag", IFNAMSIZ); + break; + default: + strncpy(name, "AR6000 802.11b", IFNAMSIZ); + break; + } + + return 0; +} + +/* + * SIOCSIWFREQ + */ +int +ar6000_ioctl_siwfreq(struct net_device *dev, + struct iw_request_info *info, + struct iw_freq *freq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + /* + * We support limiting the channels via wmiconfig. + * + * We use this command to configure the channel hint for the connect cmd + * so it is possible the target will end up connecting to a different + * channel. + */ + if (freq->e > 1) { + return -EINVAL; + } else if (freq->e == 1) { + if ((arPriv->arPhyCapability == WMI_11NG_CAPABILITY) && (((freq->m / 100000) >= 5180) && ((freq->m / 100000) <= 5825))) { + return -EINVAL; + } + arPriv->arChannelHint = freq->m / 100000; + } else if(freq->m > 0) { + if ((arPriv->arPhyCapability == WMI_11NG_CAPABILITY) && ((wlan_ieee2freq(freq->m) >=5180) && (wlan_ieee2freq(freq->m) <= 5825))) { + return -EINVAL; + } + arPriv->arChannelHint = wlan_ieee2freq(freq->m); + } else { + /* Auto Channel Selection */ + arPriv->arChannelHint = 0; + } + + arPriv->ap_profile_flag = 1; /* There is a change in profile */ + + A_PRINTF("channel hint set to %d\n", arPriv->arChannelHint); + return 0; +} + +/* + * SIOCGIWFREQ + */ +int +ar6000_ioctl_giwfreq(struct net_device *dev, + struct iw_request_info *info, + struct iw_freq *freq, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (arPriv->arNetworkType == AP_NETWORK) { + if(arPriv->arChannelHint) { + freq->m = arPriv->arChannelHint * 100000; + } else if(arPriv->arBssChannel) { + freq->m = arPriv->arBssChannel * 100000; + } else { + return -EINVAL; + } + } else { + if (arPriv->arConnected != TRUE) { + return -EINVAL; + } else { + freq->m = arPriv->arBssChannel * 100000; + } + } + + freq->e = 1; + + return 0; +} + +/* + * SIOCSIWMODE + */ +int +ar6000_ioctl_siwmode(struct net_device *dev, + struct iw_request_info *info, + __u32 *mode, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + +#if 0 + /* + * clear SSID during mode switch in connected state + */ + if(!(arPriv->arNetworkType == (((*mode) == IW_MODE_INFRA) ? INFRA_NETWORK : ADHOC_NETWORK)) + && (arPriv->arConnected == TRUE) ){ + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + } +#endif + + switch (*mode) { + case IW_MODE_INFRA: + arPriv->arNextMode = INFRA_NETWORK; + break; + case IW_MODE_ADHOC: + arPriv->arNextMode = ADHOC_NETWORK; + break; + case IW_MODE_MASTER: + arPriv->arNextMode = AP_NETWORK; + break; + default: + return -EINVAL; + } + + if (arPriv->arNetworkType != arPriv->arNextMode) { + ar6000_init_mode_info(arPriv); + } + + /* Update the arNetworkType */ + arPriv->arNetworkType = arPriv->arNextMode; + + return 0; +} + +/* + * SIOCGIWMODE + */ +int +ar6000_ioctl_giwmode(struct net_device *dev, + struct iw_request_info *info, + __u32 *mode, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + switch (arPriv->arNetworkType) { + case INFRA_NETWORK: + *mode = IW_MODE_INFRA; + break; + case ADHOC_NETWORK: + *mode = IW_MODE_ADHOC; + break; + case AP_NETWORK: + *mode = IW_MODE_MASTER; + break; + default: + return -EIO; + } + return 0; +} + +/* + * SIOCSIWSENS + */ +int +ar6000_ioctl_siwsens(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *sens, char *extra) +{ + return 0; +} + +/* + * SIOCGIWSENS + */ +int +ar6000_ioctl_giwsens(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *sens, char *extra) +{ + sens->value = 0; + sens->fixed = 1; + + return 0; +} + +/* + * SIOCGIWRANGE + */ +int +ar6000_ioctl_giwrange(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + struct iw_range *range = (struct iw_range *) extra; + int i, j, ret = 0; + const A_INT32 rateTable[] = { + 1000, 2000, 5500, 11000, + 6000, 9000, 12000, 18000, 24000, 36000, 48000, 54000, + 6500, 13000, 19500, 26000, 39000, 52000, 58500, 65000 }; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + arSta->arNumChannels = -1; + A_MEMZERO(arSta->arChannelList, sizeof (arSta->arChannelList)); + + if (wmi_get_channelList_cmd(arPriv->arWmi) != A_OK) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arPriv->arEvent, arSta->arNumChannels != -1, wmitimeout * HZ); + + if (signal_pending(current)) { + up(&ar->arSem); + return -EINTR; + } + + data->length = sizeof(struct iw_range); + A_MEMZERO(range, sizeof(struct iw_range)); + + range->enc_capa |= IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2; + range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP|IW_ENC_CAPA_CIPHER_CCMP; + /* Event capability (kernel + driver) */ + range->event_capa[0] = (IW_EVENT_CAPA_K_0 | + IW_EVENT_CAPA_MASK(SIOCGIWAP) | + IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); + range->event_capa[1] = IW_EVENT_CAPA_K_1; + range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) | + IW_EVENT_CAPA_MASK(IWEVREGISTERED) | + IW_EVENT_CAPA_MASK(IWEVEXPIRED) | +#if WIRELESS_EXT >= 18 + IW_EVENT_CAPA_MASK(IWEVPMKIDCAND) | + IW_EVENT_CAPA_MASK(IWEVASSOCRESPIE) | + IW_EVENT_CAPA_MASK(IWEVASSOCREQIE) | + IW_EVENT_CAPA_MASK(IWEVGENIE) | +#endif + 0); + + range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_CHANNEL; + + range->txpower_capa = 0; + + range->min_pmp = 1 * 1024; + range->max_pmp = 65535 * 1024; + range->min_pmt = 1 * 1024; + range->max_pmt = 1000 * 1024; + range->pmp_flags = IW_POWER_PERIOD; + range->pmt_flags = IW_POWER_TIMEOUT; + range->pm_capa = 0; + + range->we_version_compiled = WIRELESS_EXT; + range->we_version_source = 13; + + range->retry_capa = IW_RETRY_LIMIT; + range->retry_flags = IW_RETRY_LIMIT; + range->min_retry = 0; + range->max_retry = 255; + + range->num_frequency = range->num_channels = arSta->arNumChannels; + for (i = 0; i < arSta->arNumChannels; i++) { + range->freq[i].i = wlan_freq2ieee(arSta->arChannelList[i]); + range->freq[i].m = arSta->arChannelList[i] * 100000; + range->freq[i].e = 1; + /* + * Linux supports max of 32 channels, bail out once you + * reach the max. + */ + if (i == IW_MAX_FREQUENCIES) { + break; + } + } + + /* Max quality is max field value minus noise floor */ + range->max_qual.qual = 0xff - 161; + + /* + * In order to use dBm measurements, 'level' must be lower + * than any possible measurement (see iw_print_stats() in + * wireless tools). It's unclear how this is meant to be + * done, but setting zero in these values forces dBm and + * the actual numbers are not used. + */ + range->max_qual.level = 0; + range->max_qual.noise = 0; + + range->sensitivity = 3; + + range->max_encoding_tokens = 4; + /* XXX query driver to find out supported key sizes */ + range->num_encoding_sizes = 3; + range->encoding_size[0] = 5; /* 40-bit */ + range->encoding_size[1] = 13; /* 104-bit */ + range->encoding_size[2] = 16; /* 128-bit */ + + for (i=0, j=0; iarWmi, rateTable[i], &rateIdx)==A_OK) { + range->bitrate[j] = wmi_get_rate(i) * 1000; + ++j; + } + } + range->num_bitrates = j; + + /* estimated maximum TCP throughput values (bps) */ + range->throughput = 22000000; + + range->min_rts = 0; + range->max_rts = 2347; + range->min_frag = 256; + range->max_frag = 2346; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + if (arSta->wpaOffloadEnabled) { + range->enc_capa |= IW_ENC_CAPA_4WAY_HANDSHAKE; + } +#endif /* LINUX_VERSION_CODE >= 2.6.27 */ + + up(&ar->arSem); + + return ret; +} + +/* + * SIOCSIWPRIV + * + */ +int +ar6000_ioctl_siwpriv(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + int ret = -EOPNOTSUPP; + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; +#ifdef ANDROID_ENV + extern int android_ioctl_siwpriv(struct net_device *, struct iw_request_info *, struct iw_point *, char*); + char cmd[5]; + if (data->pointer) { + if (copy_from_user(cmd, data->pointer, sizeof(cmd))) + return -EIO; + } +#endif + + if (!ar || + ( (!ar->arWmiReady || (ar->arWlanState != WLAN_ENABLED)) +#ifdef ANDROID_ENV + && (!data->pointer || strncasecmp(cmd, "START", 5)!=0) +#endif + ) + ) { + return -EIO; + } + +#ifdef ANDROID_ENV + ret = android_ioctl_siwpriv(dev, info, data, extra); + if (ret!=-EOPNOTSUPP) { + return ret; + } +#endif + return ret; +} + +/* + * SIOCSIWAP + * This ioctl is used to set the desired bssid for the connect command. + */ +int +ar6000_ioctl_siwap(struct net_device *dev, + struct iw_request_info *info, + struct sockaddr *ap_addr, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ap_addr->sa_family != ARPHRD_ETHER) { + return -EIO; + } + + if (A_MEMCMP(&ap_addr->sa_data, bcast_mac, AR6000_ETH_ADDR_LEN) == 0) { + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + } else { + A_MEMCPY(arSta->arReqBssid, &ap_addr->sa_data, sizeof(arSta->arReqBssid)); + } + + return 0; +} + +/* + * SIOCGIWAP + */ +int +ar6000_ioctl_giwap(struct net_device *dev, + struct iw_request_info *info, + struct sockaddr *ap_addr, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (arPriv->arNetworkType == AP_NETWORK) { + A_MEMCPY(&ap_addr->sa_data, dev->dev_addr, ATH_MAC_LEN); + ap_addr->sa_family = ARPHRD_ETHER; + return 0; + } + + if (arPriv->arConnected != TRUE) { + return -EINVAL; + } + + A_MEMCPY(&ap_addr->sa_data, arPriv->arBssid, sizeof(arPriv->arBssid)); + ap_addr->sa_family = ARPHRD_ETHER; + + return 0; +} + +#if (WIRELESS_EXT >= 18) +/* + * SIOCSIWMLME + */ +int +ar6000_ioctl_siwmlme(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (data->pointer && data->length == sizeof(struct iw_mlme)) { + + A_UINT8 arNetworkType; + struct iw_mlme mlme; + + if (copy_from_user(&mlme, data->pointer, sizeof(struct iw_mlme))) { + up(&ar->arSem); + return -EIO; + } + + switch (mlme.cmd) { + + case IW_MLME_DEAUTH: + /* fall through */ + case IW_MLME_DISASSOC: + if ((arPriv->arConnected != TRUE) || + (memcmp(arPriv->arBssid, mlme.addr.sa_data, 6) != 0)) { + + up(&ar->arSem); + return -EINVAL; + } + wmi_setPmkid_cmd(arPriv->arWmi, arPriv->arBssid, NULL, 0); + arNetworkType = arPriv->arNetworkType; + ar6000_init_profile_info(arPriv); + arPriv->arNetworkType = arNetworkType; + reconnect_flag = 0; + ar6000_disconnect(arPriv); + A_MEMZERO(arPriv->arSsid, sizeof(arPriv->arSsid)); + arPriv->arSsidLen = 0; + if (arSta->arSkipScan == FALSE) { + A_MEMZERO(arSta->arReqBssid, sizeof(arSta->arReqBssid)); + } + break; + + case IW_MLME_AUTH: + /* fall through */ + case IW_MLME_ASSOC: + /* fall through */ + default: + up(&ar->arSem); + return -EOPNOTSUPP; + } + } + + up(&ar->arSem); + return 0; +} +#endif /* WIRELESS_EXT >= 18 */ + +/* + * SIOCGIWAPLIST + */ +int +ar6000_ioctl_iwaplist(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + return -EIO; /* for now */ +} + +/* + * SIOCSIWSCAN + */ +int +ar6000_ioctl_siwscan(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ +#define ACT_DWELLTIME_DEFAULT 105 +#define HOME_TXDRAIN_TIME 100 +#define SCAN_INT HOME_TXDRAIN_TIME + ACT_DWELLTIME_DEFAULT + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_DEV_T *arApPriv = NULL; + AR_SOFTC_T *ar = arPriv->arSoftc; + AR_SOFTC_STA_T *arSta = &arPriv->arSta; + A_UINT16 connChannel = 0; + int ret = 0; + struct iw_scan_req *req = (struct iw_scan_req *) extra; + A_INT8 numChan = 0; + A_UINT16 channelList[IW_MAX_FREQUENCIES], *pChannelList = NULL; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (data->length < sizeof(struct iw_scan_req)) { + req = NULL; + } + + /* If scan is issued in the middle of ongoing scan or connect, + dont issue another one */ + if ( arSta->scan_triggered > 0 ) { + ++arSta->scan_triggered; + if (arSta->scan_triggered < 5) { + return 0; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("Scan request is triggered over 5 times. Not scan complete event\n")); + } + } + + if (!arSta->arUserBssFilter) { + if (wmi_bssfilter_cmd(arPriv->arWmi, ALL_BSS_FILTER, 0) != A_OK) { + return -EIO; + } + } + + if (arPriv->arConnected) { + if (wmi_get_stats_cmd(arPriv->arWmi) != A_OK) { + return -EIO; + } + } + +#if WIRELESS_EXT >= 18 + if ( req && (data->flags & IW_SCAN_THIS_ESSID) == IW_SCAN_THIS_ESSID ) { + if (wmi_probedSsid_cmd(arPriv->arWmi, 0, + SPECIFIC_SSID_FLAG, req->essid_len, req->essid) == A_OK) { + if (!arSta->scanSpecificSsid) { + arSta->scanSpecificSsid = 1; + } + } + } else { + A_UINT8 idx; + for (idx=0; idxscanSpecificSsid; ++idx) { + /* index 0 always reserves for broadcast SSID*/ + A_UINT8 flag = (idx==0) ? ANY_SSID_FLAG : DISABLE_SSID_FLAG; + wmi_probedSsid_cmd(arPriv->arWmi, idx, flag, 0, NULL); + } + arSta->scanSpecificSsid = 0; + } + + if ( req && (data->flags & IW_SCAN_THIS_FREQ) == IW_SCAN_THIS_FREQ && req->num_channels>0) { + A_UINT8 i; + for (i=0; inum_channels; ++i) { + struct iw_freq *freq = &req->channel_list[i]; + A_UINT16 *dst = &channelList[numChan]; + if (freq->e == 1) { + /* freq->m == (Freq HZ value) divided by (10 ^ freq->e) */ + *dst = freq->m / 100000; + ++numChan; + } else if (freq->e < 1 && freq->m) { + /* It is a channel number if freq->e == 0 */ + *dst = wlan_ieee2freq(freq->m); + ++numChan; + } + } + if (numChan > 0) { + pChannelList = channelList; + } + } +#endif /* WIRELESS_EXT >= 18 */ + + /* AP-STA concurrency. Allow scan only on connected channel when AP and STA + * both are functional. + */ + GET_CONN_AP_PRIV(ar,arApPriv); + if((arApPriv) && (arPriv->arConnected)){ + connChannel = arPriv->arBssChannel; + if (wmi_startscan_cmd(arPriv->arWmi, WMI_LONG_SCAN, FALSE, FALSE, \ + 0, 0, 1,&connChannel) != A_OK) { + ret = -EIO; + } + } else { + if (wmi_startscan_cmd(arPriv->arWmi, WMI_LONG_SCAN, FALSE, FALSE, \ + 0, 0, numChan, pChannelList) != A_OK) { + ret = -EIO; + } + } + if (ret == 0) { + arSta->scan_triggered = 1; + } + + return ret; +#undef ACT_DWELLTIME_DEFAULT +#undef HOME_TXDRAIN_TIME +#undef SCAN_INT +} + + +/* + * Units are in db above the noise floor. That means the + * rssi values reported in the tx/rx descriptors in the + * driver are the SNR expressed in db. + * + * If you assume that the noise floor is -95, which is an + * excellent assumption 99.5 % of the time, then you can + * derive the absolute signal level (i.e. -95 + rssi). + * There are some other slight factors to take into account + * depending on whether the rssi measurement is from 11b, + * 11g, or 11a. These differences are at most 2db and + * can be documented. + * + * NB: various calculations are based on the orinoco/wavelan + * drivers for compatibility + */ +static void +ar6000_set_quality(struct iw_quality *iq, A_INT8 rssi) +{ + if (rssi < 0) { + iq->qual = 0; + } else { + iq->qual = rssi; + } + + /* NB: max is 94 because noise is hardcoded to 161 */ + if (iq->qual > 94) + iq->qual = 94; + + iq->noise = 161; /* -95dBm */ + iq->level = iq->noise + iq->qual; + iq->updated = 7; +} + + +int +ar6000_ioctl_siwcommit(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + + AR_SOFTC_DEV_T *arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); + AR_SOFTC_T *ar = arPriv->arSoftc; + + if (is_iwioctl_allowed(arPriv->arNextMode, info->cmd) != A_OK) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd)); + return -EOPNOTSUPP; + } + + if (ar->arWmiReady == FALSE) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AP: SSID %s freq %d authmode %d dot11 auth %d"\ + " PW crypto %d GRP crypto %d\n", + arPriv->arSsid, arPriv->arChannelHint, + arPriv->arAuthMode, arPriv->arDot11AuthMode, + arPriv->arPairwiseCrypto, arPriv->arGroupCrypto)); + + /* Stop getting pkts from upper stack */ + netif_stop_queue(arPriv->arNetDev); + /* Flush the Tx queues */ + ar6000_TxDataCleanup(ar); + /* Start getting pkts from upper stack */ + netif_wake_queue(arPriv->arNetDev); + + ar6000_ap_mode_profile_commit(arPriv); + + return 0; +} + +#define W_PROTO(_x) wait_ ## _x +#define WAIT_HANDLER_IMPL(_x, type) \ +int wait_ ## _x (struct net_device *dev, struct iw_request_info *info, type wrqu, char *extra) {\ + int ret; \ + dev_hold(dev); \ + rtnl_unlock(); \ + ret = _x(dev, info, wrqu, extra); \ + rtnl_lock(); \ + dev_put(dev); \ + return ret;\ +} + +WAIT_HANDLER_IMPL(ar6000_ioctl_siwessid, struct iw_point *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwrate, struct iw_param *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwtxpow, struct iw_param *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwrange, struct iw_point*) + +/* Structures to export the Wireless Handlers */ +static const iw_handler ath_handlers[] = { + (iw_handler) ar6000_ioctl_siwcommit, /* SIOCSIWCOMMIT */ + (iw_handler) ar6000_ioctl_giwname, /* SIOCGIWNAME */ + (iw_handler) NULL, /* SIOCSIWNWID */ + (iw_handler) NULL, /* SIOCGIWNWID */ + (iw_handler) ar6000_ioctl_siwfreq, /* SIOCSIWFREQ */ + (iw_handler) ar6000_ioctl_giwfreq, /* SIOCGIWFREQ */ + (iw_handler) ar6000_ioctl_siwmode, /* SIOCSIWMODE */ + (iw_handler) ar6000_ioctl_giwmode, /* SIOCGIWMODE */ + (iw_handler) ar6000_ioctl_siwsens, /* SIOCSIWSENS */ + (iw_handler) ar6000_ioctl_giwsens, /* SIOCGIWSENS */ + (iw_handler) NULL /* not _used */, /* SIOCSIWRANGE */ + (iw_handler) W_PROTO(ar6000_ioctl_giwrange),/* SIOCGIWRANGE */ + (iw_handler) ar6000_ioctl_siwpriv, /* SIOCSIWPRIV */ + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ + (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ + (iw_handler) NULL, /* SIOCSIWSPY */ + (iw_handler) NULL, /* SIOCGIWSPY */ + (iw_handler) NULL, /* SIOCSIWTHRSPY */ + (iw_handler) NULL, /* SIOCGIWTHRSPY */ + (iw_handler) ar6000_ioctl_siwap, /* SIOCSIWAP */ + (iw_handler) ar6000_ioctl_giwap, /* SIOCGIWAP */ +#if (WIRELESS_EXT >= 18) + (iw_handler) ar6000_ioctl_siwmlme, /* SIOCSIWMLME */ +#else + (iw_handler) NULL, /* -- hole -- */ +#endif /* WIRELESS_EXT >= 18 */ + (iw_handler) ar6000_ioctl_iwaplist, /* SIOCGIWAPLIST */ + (iw_handler) ar6000_ioctl_siwscan, /* SIOCSIWSCAN */ + (iw_handler) ar6000_ioctl_giwscan, /* SIOCGIWSCAN */ + (iw_handler) W_PROTO(ar6000_ioctl_siwessid),/* SIOCSIWESSID */ + (iw_handler) ar6000_ioctl_giwessid, /* SIOCGIWESSID */ + (iw_handler) NULL, /* SIOCSIWNICKN */ + (iw_handler) NULL, /* SIOCGIWNICKN */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) ar6000_ioctl_siwrate, /* SIOCSIWRATE */ + (iw_handler) W_PROTO(ar6000_ioctl_giwrate), /* SIOCGIWRATE */ + (iw_handler) NULL, /* SIOCSIWRTS */ + (iw_handler) NULL, /* SIOCGIWRTS */ + (iw_handler) NULL, /* SIOCSIWFRAG */ + (iw_handler) NULL, /* SIOCGIWFRAG */ + (iw_handler) ar6000_ioctl_siwtxpow, /* SIOCSIWTXPOW */ + (iw_handler) W_PROTO(ar6000_ioctl_giwtxpow),/* SIOCGIWTXPOW */ + (iw_handler) ar6000_ioctl_siwretry, /* SIOCSIWRETRY */ + (iw_handler) ar6000_ioctl_giwretry, /* SIOCGIWRETRY */ + (iw_handler) ar6000_ioctl_siwencode, /* SIOCSIWENCODE */ + (iw_handler) ar6000_ioctl_giwencode, /* SIOCGIWENCODE */ +#if WIRELESS_EXT > 20 + (iw_handler) ar6000_ioctl_siwpower, /* SIOCSIWPOWER */ + (iw_handler) ar6000_ioctl_giwpower, /* SIOCGIWPOWER */ +#endif // WIRELESS_EXT > 20 +#if WIRELESS_EXT >= 18 + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) ar6000_ioctl_siwgenie, /* SIOCSIWGENIE */ + (iw_handler) ar6000_ioctl_giwgenie, /* SIOCGIWGENIE */ + (iw_handler) ar6000_ioctl_siwauth, /* SIOCSIWAUTH */ + (iw_handler) ar6000_ioctl_giwauth, /* SIOCGIWAUTH */ + (iw_handler) ar6000_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ + (iw_handler) ar6000_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */ + (iw_handler) ar6000_ioctl_siwpmksa, /* SIOCSIWPMKSA */ +#endif // WIRELESS_EXT >= 18 +}; + +struct iw_handler_def ath_iw_handler_def = { + .standard = (iw_handler *)ath_handlers, + .num_standard = ARRAY_SIZE(ath_handlers), +// .private = NULL, +// .num_private = 0, +}; diff --git a/drivers/net/wireless/ar6003/host/p2p/makefile b/drivers/net/wireless/ar6003/host/p2p/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/p2p/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/p2p/p2p_internal.h b/drivers/net/wireless/ar6003/host/p2p/p2p_internal.h new file mode 100644 index 000000000000..4dc905992538 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/p2p/p2p_internal.h @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file contains internal definitions for the host P2P module. +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef __P2P_INTERNAL_H__ +#define __P2P_INTERNAL_H__ + +#include +#include +#include +#include + +/* P2P peer device context */ +struct host_p2p_dev { + DL_LIST list; + struct p2p_device dev; + struct p2p_dev_ctx *p2p; + A_UINT8 ref_cnt; + A_UINT8 *p2p_buf; + A_UINT32 p2p_buf_len; + A_UINT8 persistent_grp; +/* Persistent P2P Info*/ + A_UINT8 role_go; + A_UINT8 ssid[WMI_MAX_SSID_LEN]; + A_UINT8 ssid_len; +}; + +/* Global P2P Context structure */ +struct p2p_ctx { + A_INT8 go_intent; +}; + +struct p2p_sd_query { + struct p2p_sd_query *next; + A_UINT8 peer[ETH_ALEN]; + A_UINT8 for_all_peers; + A_UINT8 *tlvs; + A_UINT16 tlv_len; +}; + +/* Device specific P2P context */ +struct p2p_dev_ctx { + struct p2p_ctx *p2p_ctx; + DL_LIST devices; + A_UINT8 peer_filter[ETH_ALEN]; + A_UINT8 p2p_auth_invite[ETH_ALEN]; + void *dev; /* AR6K priv context */ + struct p2p_sd_query *sd_queries; + struct p2p_sd_query *curr_sd_query; + A_UINT8 srv_update_indic; +}; + +#define P2P_MAX_GROUP_ENTRIES 10 + +struct p2p_client_info { + const A_UINT8 *p2p_device_addr; + const A_UINT8 *p2p_interface_addr; + const A_UINT8 *pri_dev_type; + const A_UINT8 *sec_dev_types; + const A_CHAR *dev_name; + A_UINT32 dev_name_len; + A_UINT16 config_methods; + A_UINT8 dev_capab; + A_UINT8 num_sec_dev_types; +}; + +struct p2p_group_info { + A_UINT32 num_clients; + struct p2p_client_info client[P2P_MAX_GROUP_ENTRIES]; +}; + +#define P2P_GROUP_CAPAB_PERSISTENT_GROUP (1<<1) +#endif /* __P2P_INTERNAL_H__ */ diff --git a/drivers/net/wireless/ar6003/host/p2p/p2p_main.c b/drivers/net/wireless/ar6003/host/p2p/p2p_main.c new file mode 100644 index 000000000000..6702fc80f7c5 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/p2p/p2p_main.c @@ -0,0 +1,2676 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// This file implements the host side P2P module. +// +// Author(s): ="Atheros" +//============================================================================== + +#include +#include +#include +#include +#include +#include +#include +#include +#include "p2p_internal.h" + +#include +#define WPS_DEV_TYPE_BUFSIZE 21 +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" +#include + +struct wmi_t; + +extern A_STATUS wmi_p2p_go_neg_rsp_cmd(struct wmi_t *wmip, A_UINT8 status, + A_UINT8 go_intent, A_UINT32 wps_method, A_UINT16 listen_freq, + A_UINT8 *wpsbuf, A_UINT32 wpslen, A_UINT8 *p2pbuf, A_UINT32 p2plen, + A_UINT8 dialog_token, A_UINT8 persistent_grp); + +extern A_STATUS wmi_p2p_invite_req_rsp_cmd(struct wmi_t *wmip, A_UINT8 status, + A_INT8 is_go, A_UINT8 *grp_bssid, A_UINT8 *p2pbuf, + A_UINT8 p2plen, A_UINT8 dialog_token); + +extern A_STATUS +wmi_p2p_go_neg_start(struct wmi_t *wmip, WMI_P2P_GO_NEG_START_CMD *go_param); + +extern A_STATUS wmi_p2p_invite_cmd(struct wmi_t *wmip, WMI_P2P_INVITE_CMD *buf); + +extern A_STATUS wmi_p2p_prov_disc_cmd(struct wmi_t *wmip, + WMI_P2P_PROV_DISC_REQ_CMD *buf); + +extern A_STATUS wmi_p2p_stop_sdpd(struct wmi_t *wmip); + +extern void wmi_node_return (struct wmi_t *wmip, bss_t *bss); + +extern void wmi_node_update_timestamp(struct wmi_t *wmip, bss_t *bss); + +extern void wmi_setup_node(struct wmi_t *wmip, bss_t *bss, const A_UINT8 *bssid); +extern bss_t *wmi_node_alloc(struct wmi_t *wmip, A_UINT8 len); + +extern bss_t *wmi_find_node(struct wmi_t *wmip, const A_UINT8 *macaddr); + + +static struct p2p_sd_query *p2p_pending_sd_req(struct p2p_dev_ctx *p2p_dev_ctx, + struct host_p2p_dev *dev); + + +/* Global P2P context */ +static struct p2p_ctx *g_p2p_ctx; + +#define IEEE80211_ELEMID_VENDOR 221 /* vendor private */ +#define IEEE80211_ELEMID_SSID 0 + +static A_STATUS p2p_parse_subelement(A_UINT8 id, const A_UINT8 *data, + A_UINT16 len, struct p2p_ie *p2p_ie) +{ + A_STATUS status = A_OK; + const A_UINT8 *pos; + A_UINT32 i, nlen; + + switch (id) { + case P2P_ATTR_CAPABILITY: + if (len < 2) { + return A_ERROR; + } + p2p_ie->capability = data; + break; + case P2P_ATTR_GROUP_OWNER_INTENT: + if (len < 1) { + return A_ERROR; + } + p2p_ie->go_intent = data; + break; + case P2P_ATTR_STATUS: + if (len < 1) { + return A_ERROR; + } + p2p_ie->status = data; + break; + case P2P_ATTR_LISTEN_CHANNEL: + if (len == 0) { + break; + } + if (len < 2) { + return A_ERROR; + } + p2p_ie->listen_channel = data; + break; + + case P2P_ATTR_OPERATING_CHANNEL: + if (len == 0) { + break; + } + if (len < 2) { + return A_ERROR; + } + p2p_ie->operating_channel = data; + break; + + case P2P_ATTR_CHANNEL_LIST: + if (len < 3) { + return A_ERROR; + } + p2p_ie->channel_list = data; + p2p_ie->channel_list_len = len; + break; + case P2P_ATTR_GROUP_INFO: + p2p_ie->group_info = data; + p2p_ie->group_info_len = len; + break; + case P2P_ATTR_DEVICE_INFO: + if (len < ETH_ALEN + 2 + 8 + 1) { + return A_ERROR; + } + p2p_ie->p2p_device_info = data; + p2p_ie->p2p_device_info_len = len; + pos = data; + p2p_ie->p2p_device_addr = pos; + pos += ETH_ALEN; + p2p_ie->config_methods = WPA_GET_BE16(pos); + pos += 2; + p2p_ie->pri_dev_type = pos; + pos += 8; + p2p_ie->num_sec_dev_types = *pos++; + if (p2p_ie->num_sec_dev_types * 8 > data + len - pos) { + return A_ERROR; + } + pos += p2p_ie->num_sec_dev_types * 8; + if (data + len - pos < 4) { + return A_ERROR; + } + if (WPA_GET_BE16(pos) != ATTR_DEV_NAME) { + return A_ERROR; + } + pos += 2; + nlen = WPA_GET_BE16(pos); + pos += 2; + if (data + len - pos < (int) nlen || nlen > 32) { + return A_ERROR; + } + A_MEMCPY(p2p_ie->device_name, pos, nlen); + p2p_ie->dev_name_len = nlen; + for (i = 0; i < nlen; i++) { + if (p2p_ie->device_name[i] == '\0') + break; + if (p2p_ie->device_name[i] < 32) + p2p_ie->device_name[i] = '_'; + } + break; + case P2P_ATTR_CONFIGURATION_TIMEOUT: + if (len < 2) { + return A_ERROR; + } + p2p_ie->config_timeout = data; + break; + case P2P_ATTR_INTENDED_INTERFACE_ADDR: + if (len < ETH_ALEN) { + return A_ERROR; + } + p2p_ie->intended_addr = data; + break; + default: + break; + } + + return status; +} + + +/** + * p2p_parse_p2p_ie - Parse P2P IE + */ +static A_STATUS p2p_parse_p2p_ie(const A_UINT8 *data, A_UINT8 len, struct p2p_ie *msg) +{ + A_STATUS status = A_OK; + const A_UINT8 *pos = data; + const A_UINT8 *end = pos + len; + + while (pos < end) { + A_UINT16 attr_len; + if (pos + 2 >= end) { + return A_ERROR; + } + attr_len = WPA_GET_LE16((pos + 1)); + if (pos + 3 + attr_len > end) { + return A_ERROR; + } + if ((status = p2p_parse_subelement(pos[0], pos + 3, attr_len, msg)) != + A_OK) { + return A_ERROR; + } + pos += 3 + attr_len; + } + + return status; +} + +static A_STATUS wps_set_attr(struct wps_parse_attr *attr, A_UINT16 type, + const A_UINT8 *pos, A_UINT16 len) +{ + A_STATUS status = A_OK; + + switch (type) { + case ATTR_VERSION: + if (len != 1) { + return A_ERROR; + } + attr->version = pos; + break; + case ATTR_MSG_TYPE: + if (len != 1) { + return A_ERROR; + } + attr->msg_type = pos; + break; + case ATTR_ENROLLEE_NONCE: + if (len != WPS_NONCE_LEN) { + return A_ERROR; + } + attr->enrollee_nonce = pos; + break; + case ATTR_REGISTRAR_NONCE: + if (len != WPS_NONCE_LEN) { + return A_ERROR; + } + attr->registrar_nonce = pos; + break; + case ATTR_UUID_E: + if (len != WPS_UUID_LEN) { + return A_ERROR; + } + attr->uuid_e = pos; + break; + case ATTR_UUID_R: + if (len != WPS_UUID_LEN) { + return A_ERROR; + } + attr->uuid_r = pos; + break; + case ATTR_AUTH_TYPE_FLAGS: + if (len != 2) { + return A_ERROR; + } + attr->auth_type_flags = pos; + break; + case ATTR_ENCR_TYPE_FLAGS: + if (len != 2) { + return A_ERROR; + } + attr->encr_type_flags = pos; + break; + case ATTR_CONN_TYPE_FLAGS: + if (len != 1) { + return A_ERROR; + } + attr->conn_type_flags = pos; + break; + case ATTR_CONFIG_METHODS: + if (len != 2) { + return A_ERROR; + } + attr->config_methods = pos; + break; + case ATTR_SELECTED_REGISTRAR_CONFIG_METHODS: + if (len != 2) { + return A_ERROR; + } + attr->sel_reg_config_methods = pos; + break; + case ATTR_PRIMARY_DEV_TYPE: + if (len != WPS_DEV_TYPE_LEN) { + return A_ERROR; + } + attr->primary_dev_type = pos; + break; + case ATTR_RF_BANDS: + if (len != 1) { + return A_ERROR; + } + attr->rf_bands = pos; + break; + case ATTR_ASSOC_STATE: + if (len != 2) { + return A_ERROR; + } + attr->assoc_state = pos; + break; + case ATTR_CONFIG_ERROR: + if (len != 2) { + return A_ERROR; + } + attr->config_error = pos; + break; + case ATTR_DEV_PASSWORD_ID: + if (len != 2) { + return A_ERROR; + } + attr->dev_password_id = pos; + break; + case ATTR_OS_VERSION: + if (len != 4) { + return A_ERROR; + } + attr->os_version = pos; + break; + case ATTR_WPS_STATE: + if (len != 1) { + return A_ERROR; + } + attr->wps_state = pos; + break; + case ATTR_AUTHENTICATOR: + if (len != WPS_AUTHENTICATOR_LEN) { + return A_ERROR; + } + attr->authenticator = pos; + break; + case ATTR_R_HASH1: + if (len != WPS_HASH_LEN) { + return A_ERROR; + } + attr->r_hash1 = pos; + break; + case ATTR_R_HASH2: + if (len != WPS_HASH_LEN) { + return A_ERROR; + } + attr->r_hash2 = pos; + break; + case ATTR_E_HASH1: + if (len != WPS_HASH_LEN) { + return A_ERROR; + } + attr->e_hash1 = pos; + break; + case ATTR_E_HASH2: + if (len != WPS_HASH_LEN) { + return A_ERROR; + } + attr->e_hash2 = pos; + break; + case ATTR_R_SNONCE1: + if (len != WPS_SECRET_NONCE_LEN) { + return A_ERROR; + } + attr->r_snonce1 = pos; + break; + case ATTR_R_SNONCE2: + if (len != WPS_SECRET_NONCE_LEN) { + return A_ERROR; + } + attr->r_snonce2 = pos; + break; + case ATTR_E_SNONCE1: + if (len != WPS_SECRET_NONCE_LEN) { + return A_ERROR; + } + attr->e_snonce1 = pos; + break; + case ATTR_E_SNONCE2: + if (len != WPS_SECRET_NONCE_LEN) { + return A_ERROR; + } + attr->e_snonce2 = pos; + break; + case ATTR_KEY_WRAP_AUTH: + if (len != WPS_KWA_LEN) { + return A_ERROR; + } + attr->key_wrap_auth = pos; + break; + case ATTR_AUTH_TYPE: + if (len != 2) { + return A_ERROR; + } + attr->auth_type = pos; + break; + case ATTR_ENCR_TYPE: + if (len != 2) { + return A_ERROR; + } + attr->encr_type = pos; + break; + case ATTR_NETWORK_INDEX: + if (len != 1) { + return A_ERROR; + } + attr->network_idx = pos; + break; + case ATTR_NETWORK_KEY_INDEX: + if (len != 1) { + return A_ERROR; + } + attr->network_key_idx = pos; + break; + case ATTR_MAC_ADDR: + if (len != ETH_ALEN) { + return A_ERROR; + } + attr->mac_addr = pos; + break; + case ATTR_KEY_PROVIDED_AUTO: + if (len != 1) { + return A_ERROR; + } + attr->key_prov_auto = pos; + break; + case ATTR_802_1X_ENABLED: + if (len != 1) { + return A_ERROR; + } + attr->dot1x_enabled = pos; + break; + case ATTR_SELECTED_REGISTRAR: + if (len != 1) { + return A_ERROR; + } + attr->selected_registrar = pos; + break; + case ATTR_REQUEST_TYPE: + if (len != 1) { + return A_ERROR; + } + attr->request_type = pos; + break; + case ATTR_RESPONSE_TYPE: + if (len != 1) { + return A_ERROR; + } + attr->request_type = pos; + break; + case ATTR_MANUFACTURER: + attr->manufacturer = pos; + attr->manufacturer_len = len; + break; + case ATTR_MODEL_NAME: + attr->model_name = pos; + attr->model_name_len = len; + break; + case ATTR_MODEL_NUMBER: + attr->model_number = pos; + attr->model_number_len = len; + break; + case ATTR_SERIAL_NUMBER: + attr->serial_number = pos; + attr->serial_number_len = len; + break; + case ATTR_DEV_NAME: + attr->dev_name = pos; + attr->dev_name_len = len; + break; + case ATTR_PUBLIC_KEY: + attr->public_key = pos; + attr->public_key_len = len; + break; + case ATTR_ENCR_SETTINGS: + attr->encr_settings = pos; + attr->encr_settings_len = len; + break; + case ATTR_CRED: + if (attr->num_cred >= MAX_CRED_COUNT) { + break; + } + attr->cred[attr->num_cred] = pos; + attr->cred_len[attr->num_cred] = len; + attr->num_cred++; + break; + case ATTR_SSID: + attr->ssid = pos; + attr->ssid_len = len; + break; + case ATTR_NETWORK_KEY: + attr->network_key = pos; + attr->network_key_len = len; + break; + case ATTR_EAP_TYPE: + attr->eap_type = pos; + attr->eap_type_len = len; + break; + case ATTR_EAP_IDENTITY: + attr->eap_identity = pos; + attr->eap_identity_len = len; + break; + default: + break; + } + + return status; +} + +static A_STATUS wps_parse_msg(const A_UINT8 *data, A_UINT8 len, struct wps_parse_attr *attr) +{ + A_STATUS status = A_OK; + const A_UINT8 *pos, *end; + A_UINT16 type; + + A_MEMZERO(attr, sizeof(*attr)); + pos = data; + end = pos + len; + + while (pos < end) { + if (end - pos < 4) { + return A_ERROR; + } + + type = WPA_GET_BE16(pos); + pos += 2; + len = WPA_GET_BE16(pos); + pos += 2; + if (len > end - pos) { + return A_ERROR; + } + + if ((status = wps_set_attr(attr, type, pos, len)) != A_OK) { + return status; + } + + pos += len; + } + + return status; +} + + +static A_STATUS p2p_parse_wps_ie(const A_UINT8 *data, A_UINT8 len, struct p2p_ie *p2p_ie) +{ + A_STATUS status = A_OK; + struct wps_parse_attr attr; + + if ( (status = wps_parse_msg(data, len, &attr)) != A_OK ) { + return status; + } + + if (attr.dev_name && attr.dev_name_len < sizeof(p2p_ie->wps_device_name)) { + A_MEMCPY(p2p_ie->wps_device_name, attr.dev_name, attr.dev_name_len); + p2p_ie->wps_dev_name_len = attr.dev_name_len; + } + + if (attr.config_methods) { + p2p_ie->wps_config_methods = WPA_GET_BE16((attr.config_methods)); + } + + if (attr.dev_password_id) { + p2p_ie->dev_password_id = WPA_GET_BE16(attr.dev_password_id); + } + + if(attr.primary_dev_type) { + p2p_ie->wps_pri_dev_type = attr.primary_dev_type; + + } + + return status; +} +static A_STATUS p2p_get_ie(WMI_BI_FTYPE fType, const A_UINT8 *data, A_UINT32 len, A_UINT32 vendor_type, A_UINT8 **ie, A_UINT32 *ie_len) +{ + const A_UINT8 *frm, *efrm; + A_STATUS status = A_ENODEV; + struct p2p_ie p2p_ie ; + A_UINT8 tlv_len; + + switch(fType) { + case BEACON_FTYPE: + case PROBERESP_FTYPE: + /* + * beacon/probe response frame format + * [8] time stamp + * [2] beacon interval + * [2] capability information + * [tlv]s... + */ + data += 12; + len -= 12; + break; + case ACTION_MGMT_FTYPE: + /* Action frame format: + * [1] Category code + * [1] Action field + * [3] WFA Specific OUI + * [1] OUI Type + * [1] OUI SubType + * [1] Dialog Token + * [TLV]s... + * - P2P IE, WSC IE + */ + data += 8; + len -= 8; + break; + case PROBEREQ_FTYPE: + + break; + default: + A_ASSERT(FALSE); + break; + } + + frm = data; + efrm = (A_UINT8 *) (frm + len); + + while (frm < efrm) { + switch (*frm) { + case IEEE80211_ELEMID_VENDOR: + tlv_len = frm[1]-4; + if(isp2poui(frm) && (vendor_type == P2P_OUI) && (tlv_len)) { + status = p2p_parse_p2p_ie(frm+6, frm[1]-4, &p2p_ie); + if(status == A_OK && (frm[1] -4 !=0)) { + *ie = (A_UINT8 *)frm+6; + *ie_len = frm[1]-4 ; + } + } + break; + default: + break; + } + /* Discontinue parsing if there is a bad IE */ + if (status != A_OK && status != A_ENODEV) { + break; + } + frm += frm[1] + 2; + } + + return status; +} +/** + * p2p_parse_ies - Parse P2P message IEs (both WPS and P2P IE) + */ +static A_STATUS p2p_parse_ies(const A_UINT8 *data, A_UINT32 len, struct p2p_ie *p2p_ie) +{ + const A_UINT8 *frm, *efrm; + A_STATUS status = A_ENODEV; + A_BOOL found = FALSE; + + frm = data; + efrm = (A_UINT8 *) (frm + len); + + while (frm < efrm) { + switch (*frm) { + case IEEE80211_ELEMID_VENDOR: + if(iswscoui(frm)) { + status = p2p_parse_wps_ie(frm+6, frm[1]-4, p2p_ie); + } else if(isp2poui(frm)) { + found = TRUE; + status = p2p_parse_p2p_ie(frm+6, frm[1]-4, p2p_ie); + } + break; + case IEEE80211_ELEMID_SSID: + p2p_ie->ssid = frm; + break; + default: + break; + } + /* Discontinue parsing if there is a bad IE */ + if (status != A_OK && status != A_ENODEV) { + break; + } + frm += frm[1] + 2; + } + + if (status == A_OK && !found) { + status = A_ENODEV; + } + + return status; +} + +/* This function prunes the frame depending on its type to point the data ptr to + * the IEs portion of the frame & calls the p2p_parse_ies() to parse the P2P & + * WPS IEs. + */ +static A_STATUS p2p_parse(WMI_BI_FTYPE fType, const A_UINT8 *data, A_UINT32 len, struct p2p_ie *p2p_ie) +{ + A_STATUS status = A_OK; + + switch(fType) { + case BEACON_FTYPE: + case PROBERESP_FTYPE: + /* + * beacon/probe response frame format + * [8] time stamp + * [2] beacon interval + * [2] capability information + * [tlv]s... + */ + data += 12; + len -= 12; + break; + case ACTION_MGMT_FTYPE: + /* Action frame format: + * [1] Category code + * [1] Action field + * [3] WFA Specific OUI + * [1] OUI Type + * [1] OUI SubType + * [1] Dialog Token + * [TLV]s... + * - P2P IE, WSC IE + */ + p2p_ie->dialog_token = *(data+7); + data += 8; + len -= 8; + break; + + case PROBEREQ_FTYPE: + + break; + default: + A_ASSERT(FALSE); + break; + } + + status = p2p_parse_ies(data, len, p2p_ie); + + return status; +} + +static A_STATUS p2p_group_info_parse(const A_UINT8 *group_info, A_UINT32 group_info_len, + struct p2p_group_info *info) +{ + const A_UINT8 *start, *end; + + A_MEMZERO(info, sizeof(*info)); + + start = group_info; + end = start + group_info_len; + + + while (start < end) { + struct p2p_client_info *cli; + + const A_UINT8 *t, *cend; + A_UINT32 count; + + cli = &info->client[info->num_clients]; + cend = start + 1 + start[0]; + + if (cend > end) { + return A_ERROR; /* invalid data */ + } + + /* 'start' at begin of P2P Client Info Descriptor */ + /* t at Device Capability Bitmap */ + t = start + 1 + 2 * ETH_ALEN; + if (t > cend) { + return A_ERROR; /* invalid data */ + } + + cli->p2p_device_addr = start + 1; + cli->p2p_interface_addr = start + 1 + ETH_ALEN; + cli->dev_capab = t[0]; + + if (t + 1 + 2 + 8 + 1 > cend) { + return A_ERROR; /* invalid data */ + } + + cli->config_methods = WPA_GET_BE16(&t[1]); + cli->pri_dev_type = &t[3]; + + t += 1 + 2 + 8; + /* t at Number of Secondary Device Types */ + cli->num_sec_dev_types = *t++; + if (t + 8 * cli->num_sec_dev_types > cend) { + return A_ERROR; /* invalid data */ + } + cli->sec_dev_types = t; + t += 8 * cli->num_sec_dev_types; + + /* t at Device Name in WPS TLV format */ + if (t + 2 + 2 > cend) { + return A_ERROR; /* invalid data */ + } + if (WPA_GET_BE16(t) != ATTR_DEV_NAME) { + return A_ERROR; /* invalid Device Name TLV */ + } + t += 2; + count = WPA_GET_BE16(t); + t += 2; + if (count > cend - t) { + return A_ERROR; /* invalid Device Name TLV */ + } + if (count >= 32) { + count = 32; + } + cli->dev_name = (const char *) t; + cli->dev_name_len = count; + + start = cend; + + info->num_clients++; + if (info->num_clients == P2P_MAX_GROUP_ENTRIES) { + return A_ERROR; + } + } + + return A_OK; +} + +static void p2p_copy_client_info(struct host_p2p_dev *dev, + struct p2p_client_info *cli) +{ + A_MEMCPY((dev->dev).device_name, cli->dev_name, cli->dev_name_len); + (dev->dev).device_name[cli->dev_name_len] = '\0'; + (dev->dev).dev_capab = cli->dev_capab; + (dev->dev).config_methods = cli->config_methods; + A_MEMCPY((dev->dev).pri_dev_type, cli->pri_dev_type, 8); +} + + +//static A_STATUS ieee802_11_vendor_ie_concat(const A_UINT8 *ies, +// A_UINT32 ies_len, A_UINT32 oui_type, A_UINT8 *buf, A_UINT32 *buflen) +//{ +// const A_UINT8 *end, *pos, *ie; +// A_UINT8 len=0; +// +// pos = ies; +// end = ies + ies_len; +// ie = NULL; +// +// while (pos + 1 < end) { +// if (pos + 2 + pos[1] > end) +// return A_ERROR; +// if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 && +// WPA_GET_BE32(&pos[2]) == oui_type) { +// ie = pos; +// break; +// } +// pos += 2 + pos[1]; +// } +// +// if (ie == NULL) { +// *buflen = 0; +// return A_OK; /* No specified vendor IE found */ +// } +// +// if (buf == NULL) +// return A_ERROR; +// +// /* +// * There may be multiple vendor IEs in the message, so need to +// * concatenate their data fields. +// */ +// while (pos + 1 < end) { +// if (pos + 2 + pos[1] > end) +// break; +// if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 && +// WPA_GET_BE32(&pos[2]) == oui_type) { +//#define MAX_BUF_SIZE 512 +// A_ASSERT((len+pos[1]-4) <= MAX_BUF_SIZE); +// A_MEMCPY(buf+len, pos+6, pos[1]-4); +// len += pos[1]-4; +// } +// pos += 2 + pos[1]; +// } +// +// /* store the length of the IE to return to the caller. +// */ +// *buflen = len; +// +// return A_OK; +//} + +static A_INT16 p2p_channel_to_freq_j4(A_UINT8 reg_class, A_UINT8 channel) +{ + /* Table J-4 in P802.11REVmb/D4.0 - Global operating classes */ + /* TODO: more regulatory classes */ + switch (reg_class) { + case 81: + /* channels 1..13 */ + if (channel < 1 || channel > 13) + return -1; + return 2407 + 5 * channel; + case 82: + /* channel 14 */ + if (channel != 14) + return -1; + return 2414 + 5 * channel; + case 83: /* channels 1..9; 40 MHz */ + case 84: /* channels 5..13; 40 MHz */ + if (channel < 1 || channel > 13) + return -1; + return 2407 + 5 * channel; + case 115: /* channels 36,40,44,48; indoor only */ + case 118: /* channels 52,56,60,64; dfs */ + if (channel < 36 || channel > 64) + return -1; + return 5000 + 5 * channel; + case 124: /* channels 149,153,157,161 */ + case 125: /* channels 149,153,157,161,165,169 */ + if (channel < 149 || channel > 161) + return -1; + return 5000 + 5 * channel; + case 116: /* channels 36,44; 40 MHz; indoor only */ + case 117: /* channels 40,48; 40 MHz; indoor only */ + case 119: /* channels 52,60; 40 MHz; dfs */ + case 120: /* channels 56,64; 40 MHz; dfs */ + if (channel < 36 || channel > 64) + return -1; + return 5000 + 5 * channel; + case 126: /* channels 149,157; 40 MHz */ + case 127: /* channels 153,161; 40 MHz */ + if (channel < 149 || channel > 161) + return -1; + return 5000 + 5 * channel; + } + return -1; +} + + +/** + * p2p_channel_to_freq - Convert channel info to frequency + * @country: Country code + * @reg_class: Regulatory class + * @channel: Channel number + * Returns: Frequency in MHz or -1 if the specified channel is unknown + */ +static A_INT16 p2p_channel_to_freq(const A_CHAR *country, A_UINT8 reg_class, A_UINT8 channel) +{ + if (country[2] == 0x04) { + return p2p_channel_to_freq_j4(reg_class, channel); + } + + /* These are mainly for backwards compatibility; to be removed */ + switch (reg_class) { + case 1: /* US/1, EU/1, JP/1 = 5 GHz, channels 36,40,44,48 */ + if (channel < 36 || channel > 48) + return -1; + return 5000 + 5 * channel; + case 3: /* US/3 = 5 GHz, channels 149,153,157,161 */ + case 5: /* US/5 = 5 GHz, channels 149,153,157,161 */ + if (channel < 149 || channel > 161) + return -1; + return 5000 + 5 * channel; + case 4: /* EU/4 = 2.407 GHz, channels 1..13 */ + case 12: /* US/12 = 2.407 GHz, channels 1..11 */ + case 30: /* JP/30 = 2.407 GHz, channels 1..13 */ + if (channel < 1 || channel > 13) + return -1; + return 2407 + 5 * channel; + case 31: /* JP/31 = 2.414 GHz, channel 14 */ + if (channel != 14) + return -1; + return 2414 + 5 * channel; + } + + return -1; +} + +static void p2p_add_device_info_from_scan_data(struct p2p_dev_ctx *p2p_dev_ctx, struct host_p2p_dev *p2p_peer, A_UINT8 *addr, A_UINT16 channel, const A_UINT8 *p2p_dev_addr, struct p2p_ie *msg, const A_UINT8 *data, A_UINT32 len) +{ + if (A_MEMCMP(addr, p2p_dev_addr, ETH_ALEN) != 0) { + A_MEMCPY(p2p_peer->dev.interface_addr, addr, ETH_ALEN); + } + + if (msg->ssid && + (msg->ssid[1] != P2P_WILDCARD_SSID_LEN || + A_MEMCMP(msg->ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) + != 0)) { + A_MEMCPY(p2p_peer->dev.oper_ssid, msg->ssid + 2, msg->ssid[1]); + p2p_peer->dev.oper_ssid_len = msg->ssid[1]; + + A_MEMCPY(p2p_peer->dev.interface_addr, addr, ETH_ALEN); + } + + p2p_peer->dev.listen_freq = channel; + + if (msg->group_info) { + p2p_peer->dev.oper_freq = channel; + } + + if (msg->pri_dev_type) { + A_MEMCPY(p2p_peer->dev.pri_dev_type, msg->pri_dev_type, + sizeof(p2p_peer->dev.pri_dev_type)); + } + + A_MEMCPY(p2p_peer->dev.device_name, msg->device_name, sizeof(p2p_peer->dev.device_name)); + + p2p_peer->dev.config_methods = msg->config_methods ? msg->config_methods : + msg->wps_config_methods; + + if (msg->capability) { + p2p_peer->dev.dev_capab = msg->capability[0]; + p2p_peer->dev.group_capab = msg->capability[1]; + } + + if (msg->ext_listen_timing) { + p2p_peer->dev.ext_listen_period = WPA_GET_LE16(msg->ext_listen_timing); + p2p_peer->dev.ext_listen_interval = + WPA_GET_LE16(msg->ext_listen_timing + 2); + } + + /* TODO: Add group clients if this is a beacon containing grp info attribute + * in the P2P IE. + */ + + /* If the device reported by other then probe req only then DONOT report again. + * But if this dev is reported ONLY by probe req, report again with mode info. + */ + if ((p2p_peer->dev.flags & P2P_DEV_REPORTED) && ((p2p_peer->dev.flags & P2P_DEV_PROBE_REQ_ONLY) == 0)) + return; + + if (p2p_peer->dev.flags & P2P_DEV_USER_REJECTED) { + return; + } + + /* report device to driver & App */ + A_WMI_P2PDEV_EVENT(p2p_dev_ctx->dev, addr, p2p_dev_addr, msg->pri_dev_type, + msg->device_name, msg->dev_name_len, + msg->config_methods, + msg->capability[0], msg->capability[1]); + + p2p_peer->dev.flags |= P2P_DEV_REPORTED; + + p2p_peer->dev.flags &= + ~(P2P_DEV_PROBE_REQ_ONLY | P2P_DEV_GROUP_CLIENT_ONLY); + return; +} + +static void p2p_add_device_info_from_action_frame(struct p2p_dev_ctx + *p2p_dev_ctx, struct host_p2p_dev *p2p_peer, + A_UINT8 *addr, struct p2p_ie *msg) +{ + A_INT16 freq; + + if (msg->pri_dev_type) { + A_MEMCPY(p2p_peer->dev.pri_dev_type, msg->pri_dev_type, + sizeof(p2p_peer->dev.pri_dev_type)); + } + + A_MEMCPY(p2p_peer->dev.device_name, msg->device_name, sizeof(p2p_peer->dev.device_name)); + + p2p_peer->dev.config_methods = msg->config_methods ? msg->config_methods : + msg->wps_config_methods; + + if (msg->capability) { + p2p_peer->dev.dev_capab = msg->capability[0]; + p2p_peer->dev.group_capab = msg->capability[1]; + } + + if (msg->listen_channel) { + freq = p2p_channel_to_freq((const A_CHAR *)msg->listen_channel, + msg->listen_channel[3], msg->listen_channel[4]); + if (freq > 0) { + p2p_peer->dev.listen_freq = freq; + } + } + + if (msg->ext_listen_timing) { + p2p_peer->dev.ext_listen_period = WPA_GET_LE16(msg->ext_listen_timing); + p2p_peer->dev.ext_listen_interval = + WPA_GET_LE16(msg->ext_listen_timing + 2); + } + + if (p2p_peer->dev.flags & P2P_DEV_PROBE_REQ_ONLY) { + p2p_peer->dev.flags &= ~P2P_DEV_PROBE_REQ_ONLY; + } + + p2p_peer->dev.flags &= ~P2P_DEV_GROUP_CLIENT_ONLY; + + + /* report device to driver & App */ + A_WMI_P2PDEV_EVENT(p2p_dev_ctx->dev, addr, p2p_peer->dev.p2p_device_addr, + msg->pri_dev_type, + msg->device_name, msg->dev_name_len, + msg->config_methods, + (msg->capability) ? msg->capability[0]:0, (msg->capability)?msg->capability[1]:0); + + p2p_peer->dev.flags |= P2P_DEV_REPORTED; + + return; +} + +struct host_p2p_dev *p2p_get_device(void *ctx, const A_UINT8 *addr) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *dev; + PDL_LIST pListItem; + + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + if (A_MEMCMP((dev->dev).p2p_device_addr, addr, ETH_ALEN) == 0) { + return dev; + } + } + + return NULL; +} + +struct host_p2p_dev *p2p_get_next_device(void *ctx, const A_UINT8 *addr, int first_element) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *dev; + PDL_LIST pListItem; + + if (first_element) { + /* + * If the request is for the FIRST element, there is no + * address of the item before the desired item to return, + * so we just return the first element in the list. + */ + if (DL_LIST_IS_EMPTY(&p2p_dev_ctx->devices)) { + return NULL; + } + pListItem = DL_LIST_GET_ITEM_AT_HEAD(&p2p_dev_ctx->devices); + return A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + } + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + /* + * Iterate over the list. If we find the item with the + * matching address, return the NEXT element in the list. + * The DL_LIST is a doubly-linked list with &p2p_dev_ctx->devices + * at both the head and tail of the list. This struct is + * not a list element itself, but is used to mark where the list + * begins and ends. Therefore, if the NEXT item in the list + * is &p2p_dev_ctx->devices, we've reached the end, and we should + * continue (which will break out of the ITERATE_OVER_LIST loop + * and then return NULL + */ + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + if (A_MEMCMP((dev->dev).p2p_device_addr, addr, ETH_ALEN) == 0) { + if (pListItem->pNext == &p2p_dev_ctx->devices) { + continue; + } + return A_CONTAINING_STRUCT(pListItem->pNext, struct host_p2p_dev, list); + } + } + return NULL; +} + +struct host_p2p_dev *p2p_get_device_intf_addrs(void *ctx, const A_UINT8 *intfaddr) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *dev; + PDL_LIST pListItem; + + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + if (A_MEMCMP((dev->dev).interface_addr, intfaddr, ETH_ALEN) == 0) { + return dev; + } + } + + return NULL; +} + +static struct host_p2p_dev *p2p_create_device(struct p2p_dev_ctx *p2p_dev_ctx, + const A_UINT8 *addr) +{ + struct host_p2p_dev *p2p_dev = NULL; + + /* check if the device is already in the list. If so return the dev, + */ + p2p_dev = p2p_get_device(p2p_dev_ctx, addr); + + if (p2p_dev) { + return p2p_dev; + } + + p2p_dev = A_MALLOC_NOWAIT(sizeof(struct host_p2p_dev)); + if (!p2p_dev) { + return NULL; + } + A_MEMZERO(p2p_dev, sizeof(struct host_p2p_dev)); + DL_LIST_INIT(&p2p_dev->list); + p2p_dev->p2p = p2p_dev_ctx; + + /* Add to the device list */ + DL_ListAdd(&p2p_dev_ctx->devices,&p2p_dev->list); + A_MEMCPY((p2p_dev->dev).p2p_device_addr, addr, ETH_ALEN); + p2p_dev->p2p_buf = NULL; + p2p_dev->p2p_buf_len = 0; + + A_PRINTF("+: %x:%x\n", addr[4], addr[5]); + + return p2p_dev; +} + +/* API Routines */ + +void *p2p_init(void *dev) +{ + struct p2p_dev_ctx *p2p_dev_ctx = NULL; + + /* Allocate the global P2P context if not yet allocated */ + if (!g_p2p_ctx) { + g_p2p_ctx = (struct p2p_ctx *) A_MALLOC_NOWAIT(sizeof(struct p2p_ctx)); + if (!g_p2p_ctx) { + return NULL; + } + A_MEMZERO(g_p2p_ctx, sizeof(struct p2p_ctx)); + + /* Initialize dev common state. + */ + g_p2p_ctx->go_intent = -1; + } + + /* Allocate the device specific P2P context. + */ + p2p_dev_ctx = (struct p2p_dev_ctx *) + A_MALLOC_NOWAIT(sizeof(struct p2p_dev_ctx)); + if (!p2p_dev_ctx) { + return NULL; + } + A_MEMZERO(p2p_dev_ctx, sizeof(struct p2p_dev_ctx)); + p2p_dev_ctx->p2p_ctx = g_p2p_ctx; + + /* Store a ref to the dev in the device context + */ + p2p_dev_ctx->dev = dev; + DL_LIST_INIT(&p2p_dev_ctx->devices); + + return (void *)p2p_dev_ctx; +} + +void *p2p_bssinfo_rx(void *ctx, WMI_BI_FTYPE fType, A_UINT8 *addr, A_UINT16 channel, const A_UINT8 *data, A_UINT32 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_ie msg; + struct host_p2p_dev *peer_dev = NULL; + A_STATUS status = A_OK; + const A_UINT8 *p2p_dev_addr=NULL; + A_UINT8 myaddr[ETH_ALEN]; + + A_MEMZERO(&msg, sizeof(struct p2p_ie)); + + A_WMI_GET_DEVICE_ADDR(p2p_dev_ctx->dev, myaddr); + + status = p2p_parse(fType, data, len, &msg); + if (status != A_OK) { + /* No P2P IE or Bad P2P/WPS IE */ + return NULL; + } else { + if (fType == BEACON_FTYPE || fType == PROBERESP_FTYPE) { + /* If the bssinfo msg is of Beacon|Probe-resp type check if + * the device address or device id is present in the msg. if + * not ignore scan data without p2p device info or device id. + */ + if (msg.p2p_device_addr) { + p2p_dev_addr = msg.p2p_device_addr; + } else if (msg.device_id) { + p2p_dev_addr = msg.device_id; + } else { + /* No p2p device id or device address. Ignore this dev */ + return NULL; + } + + if (!is_zero_mac_addr(p2p_dev_ctx->peer_filter) && + A_MEMCMP(p2p_dev_addr, p2p_dev_ctx->peer_filter, + ETH_ALEN) != 0) { + /* dev does not match the set peer filter. Ignore this dev */ + return NULL; + } + + peer_dev = p2p_create_device(p2p_dev_ctx, p2p_dev_addr); + + if (!peer_dev) { + return NULL; + } + + /* Update device info frm scan data */ + p2p_add_device_info_from_scan_data(p2p_dev_ctx, peer_dev, addr, + channel, p2p_dev_addr, &msg, data, len); + + p2p_get_ie(fType, data, len, P2P_OUI, &peer_dev->p2p_buf, &peer_dev->p2p_buf_len); + + /* Mark the device for SD if any. + */ + if (p2p_pending_sd_req(p2p_dev_ctx, peer_dev)) { + peer_dev->dev.flags |= P2P_DEV_SD_SCHEDULE; + } + + /* Add device nodes for each client info descriptor in the Group Info element, + * if the Group Info element is present in the probe-resp frame. + */ + if (msg.group_info && msg.group_info_len) { + struct p2p_group_info info; + + /* Group Info element present. + */ + if (p2p_group_info_parse(msg.group_info, msg.group_info_len, &info) == A_OK) { + PDL_LIST pListItem; + struct host_p2p_dev *dev; + A_UINT8 num; + + /* Clear old data for this group. + */ + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + if (A_MEMCMP((dev->dev).member_in_go_iface, addr, ETH_ALEN) == 0) { + A_MEMZERO((dev->dev).member_in_go_iface, ETH_ALEN); + A_MEMZERO((dev->dev).member_in_go_dev, ETH_ALEN); + } + } + + /* Update device list based on latest client info desc from this + * group. + */ + + for (num=0; num < info.num_clients; num++) { + struct p2p_client_info *cli = &info.client[num]; + + /* If this client info desc. is our own, discard it. + */ + if (A_MEMCMP(cli->p2p_device_addr, myaddr, ETH_ALEN) + == 0) { + continue; + } + + dev = p2p_get_device(p2p_dev_ctx, cli->p2p_device_addr); + if (dev) { + bss_t *bss=NULL; + /* Update device details if what is present is not got directly from the + * client. + */ + if ((dev->dev).flags & (P2P_DEV_GROUP_CLIENT_ONLY | P2P_DEV_PROBE_REQ_ONLY)) { + p2p_copy_client_info(dev, cli); + } + + if ((dev->dev).flags & P2P_DEV_PROBE_REQ_ONLY) { + (dev->dev).flags &= ~P2P_DEV_PROBE_REQ_ONLY; + } + + + /* Update the WLAN Node timestamp for this dev. + */ + bss = wmi_find_node(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), cli->p2p_device_addr); + if (bss) { + wmi_node_update_timestamp(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), bss); + wmi_node_return(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), bss); + } + } else { + bss_t *bss=NULL; + /* Add new device to the list. Also setup a Node entry in the WLAN node + * (Scan table). + */ + dev = p2p_create_device(p2p_dev_ctx, cli->p2p_device_addr); + if (dev == NULL) { + continue; + } + + (dev->dev).flags |= P2P_DEV_GROUP_CLIENT_ONLY; + p2p_copy_client_info(dev, cli); + (dev->dev).oper_freq = channel; + + /* Mark the device for SD if any. + */ + if (p2p_pending_sd_req(p2p_dev_ctx, peer_dev)) { + peer_dev->dev.flags |= P2P_DEV_SD_SCHEDULE; + } + + /* Setup a WLAN node entry */ + bss = wmi_node_alloc(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), 0); + + if (bss == NULL) { + p2p_device_free(dev); + continue; + } + + wmi_setup_node(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), bss, cli->p2p_device_addr); + + /* Initialize bss state. + */ + bss->p2p_dev = dev; + /* Bump up the p2p dev ref. count. + */ + p2p_increment_dev_ref_count(dev); + bss->ni_frametype = fType; + + /* report device to driver & App */ + A_WMI_P2PDEV_EVENT(p2p_dev_ctx->dev, addr, cli->p2p_device_addr, cli->pri_dev_type, + cli->dev_name, cli->dev_name_len, + cli->config_methods, + cli->dev_capab, 0); + + dev->dev.flags |= P2P_DEV_REPORTED; + } + + A_MEMCPY((dev->dev).interface_addr, cli->p2p_interface_addr, ETH_ALEN); + A_MEMCPY((dev->dev).member_in_go_dev, p2p_dev_addr, ETH_ALEN); + A_MEMCPY((dev->dev).member_in_go_iface, addr, ETH_ALEN); + } + } + } + } /* BEACON_FTYPE || PROBERESP_FTYPE */ + else if (fType == ACTION_MGMT_FTYPE) { + peer_dev = p2p_create_device(p2p_dev_ctx, addr); + + if (!peer_dev) { + return NULL; + } + + /* Update device info from ACTION frame (GO Neg. Req. or Invitation + * or Provisional Disc Req. frames). + */ + p2p_add_device_info_from_action_frame(p2p_dev_ctx, peer_dev, addr, + &msg); + p2p_get_ie(fType, data, len, P2P_OUI, &peer_dev->p2p_buf, &peer_dev->p2p_buf_len); + + /* Mark the device for SD if any. + */ + if (p2p_pending_sd_req(p2p_dev_ctx, peer_dev)) { + peer_dev->dev.flags |= P2P_DEV_SD_SCHEDULE; + } + + } /* ACTION_MGMT_FTYPE */ + else if (fType == PROBEREQ_FTYPE) { + + /* Add this peer to device list only if it is a probe req with wildcard SSID. Probe + * req frames with non-wildcard SSID shall come from p2p groups & hence not used to + * populate our device list. + */ + if (msg.ssid == NULL || msg.ssid[1] != P2P_WILDCARD_SSID_LEN || + A_MEMCMP(msg.ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) + != 0) { + return NULL; + } + + peer_dev = p2p_create_device(p2p_dev_ctx, addr); + + if (!peer_dev) { + return NULL; + } + + if (msg.capability) { + peer_dev->dev.dev_capab = msg.capability[0]; + peer_dev->dev.group_capab = msg.capability[1]; + } + + if (msg.listen_channel) { + A_MEMCPY(peer_dev->dev.country, msg.listen_channel, 3); + peer_dev->dev.listen_freq = p2p_channel_to_freq(peer_dev->dev.country, + msg.listen_channel[3], + msg.listen_channel[4]); + } + + A_MEMCPY(peer_dev->dev.device_name, msg.wps_device_name, sizeof(peer_dev->dev.device_name)); + + if (msg.pri_dev_type) { + A_MEMCPY(peer_dev->dev.pri_dev_type, msg.pri_dev_type, + sizeof(peer_dev->dev.pri_dev_type)); + } + else if(msg.wps_pri_dev_type) { + A_MEMCPY(peer_dev->dev.pri_dev_type, msg.wps_pri_dev_type, + sizeof(peer_dev->dev.pri_dev_type)); + } + + /* Mark the device for SD if any. + */ + if (p2p_pending_sd_req(p2p_dev_ctx, peer_dev)) { + peer_dev->dev.flags |= P2P_DEV_SD_SCHEDULE; + } + + if (peer_dev->dev.flags & P2P_DEV_REPORTED || + peer_dev->dev.flags & P2P_DEV_USER_REJECTED) { + return (void *)peer_dev; + } + peer_dev->dev.flags |= P2P_DEV_PROBE_REQ_ONLY; + + /* report device to driver & App */ + A_WMI_P2PDEV_EVENT(p2p_dev_ctx->dev, addr, peer_dev->dev.p2p_device_addr, + peer_dev->dev.pri_dev_type, + msg.wps_device_name, msg.wps_dev_name_len, + msg.wps_config_methods, + (msg.capability) ? msg.capability[0]:0, (msg.capability)?msg.capability[1]:0); + + peer_dev->dev.flags |= P2P_DEV_REPORTED; + + } /* PROBEREQ_FTYPE */ + } + + return (void *)peer_dev; +} + +void p2p_go_neg_req_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_ctx *p2p_cmn_ctx = (struct p2p_ctx *)p2p_dev_ctx->p2p_ctx; + WMI_P2P_GO_NEG_REQ_EVENT *ev = (WMI_P2P_GO_NEG_REQ_EVENT *)datap; + struct host_p2p_dev *peer = NULL; + enum p2p_status_code result = P2P_SC_SUCCESS; + + /* Get hold of the peer device from the device list. + */ + peer = p2p_get_device(p2p_dev_ctx, ev->sa); + + A_ASSERT(peer != NULL); + + if (peer->dev.flags & P2P_DEV_USER_REJECTED) { + result = P2P_SC_FAIL_REJECTED_BY_USER; + goto send_rsp; + } + + if (peer->dev.wps_method == WPS_NOT_READY) { + struct p2p_ie p2p_ie; + + A_MEMZERO(&p2p_ie, sizeof(struct p2p_ie)); + result = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; + peer->dev.flags |= P2P_DEV_PEER_WAITING_RESPONSE; + + /* Parse the dev passwd id from the WPS iE in the GO Neg. req. + */ + p2p_parse_wps_ie(ev->wps_buf, ev->wps_buflen, &p2p_ie); + + A_WMI_P2PGONEG_REQ_EVENT(p2p_dev_ctx->dev, ev->sa, p2p_ie.dev_password_id); + goto send_rsp; + } + /*Parse P2P IE */ + { + struct p2p_ie p2p_ie; + A_MEMZERO(&p2p_ie, sizeof(struct p2p_ie)); + p2p_parse_p2p_ie(ev->p2p_buf, ev->p2p_buflen, &p2p_ie); + if(p2p_ie.capability[1] & P2P_GROUP_CAPAB_PERSISTENT_GROUP) + peer->persistent_grp = 1; + } + + /* The P2P/WPS IEs from the req buffer are copied to the resp. buffer. + */ + + /* Send WMI_P2P_GO_NEG_REQ_RSP_CMD with the user result + * , WPS method to use, go_intent to use. + */ +send_rsp: + wmi_p2p_go_neg_rsp_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), result, + p2p_cmn_ctx->go_intent, peer->dev.wps_method, peer->dev.listen_freq, + ev->wps_buf, ev->wps_buflen, ev->p2p_buf, ev->p2p_buflen, + ev->dialog_token, peer->persistent_grp); + + return; +} + +void p2p_invite_req_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + WMI_P2P_INVITE_REQ_EVENT *inv_req_ev = (WMI_P2P_INVITE_REQ_EVENT *)datap; + struct host_p2p_dev *dev = NULL; + enum p2p_status_code status = P2P_SC_SUCCESS; + A_INT8 is_go=0; + A_UINT8 grp_bssid[ETH_ALEN]; + + /* Get hold of the peer device from the device list. + */ + dev = p2p_get_device(p2p_dev_ctx, inv_req_ev->sa); + + /* Device is not there in the list. Send a failure response for the + * Invitation. + */ + if (dev == NULL) { + status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; + } else { + /* if the peer device is present in our dev list, check if the user has + * authorized to accept an invitation from this peer to join an active + * group. + */ + if (!inv_req_ev->is_persistent) { + if (is_zero_mac_addr(p2p_dev_ctx->p2p_auth_invite) || + (A_MEMCMP(inv_req_ev->sa, + p2p_dev_ctx->p2p_auth_invite, ETH_ALEN) && + (!is_zero_mac_addr(inv_req_ev->go_dev_addr) && + A_MEMCMP(inv_req_ev->go_dev_addr, + p2p_dev_ctx->p2p_auth_invite, ETH_ALEN) + ))) + { + /* Do not accept Invitation automatically. TODO: We can + * notify the user here & request approval. + */ + status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; + } + } else { + /*Persistent Group */ + if(A_MEMCMP(dev->ssid, inv_req_ev->ssid.ssid, dev->ssid_len) == 0) { + if(dev->role_go) { + A_MEMCPY(grp_bssid, inv_req_ev->go_dev_addr, ETH_ALEN); + is_go = 1; + } + } + } + } /* dev != NULL */ + + /* The P2P/WPS IEs from the req buffer are copied to the resp. buffer. + */ + wmi_p2p_invite_req_rsp_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), status, + is_go, grp_bssid, inv_req_ev->p2p_buf, + inv_req_ev->p2p_buflen, inv_req_ev->dialog_token); + + return; +} + +void p2p_prov_disc_req_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + WMI_P2P_PROV_DISC_REQ_EVENT *prov_disc_req_ev = + (WMI_P2P_PROV_DISC_REQ_EVENT *)datap; + struct host_p2p_dev *peer = NULL; + + /* Get hold of the peer device from the device list. The peer dev should + * be present in our dev list.(atleast added to the list from the bss_info + * ev that the firmware would have sent prior to this event). + */ + peer = p2p_get_device(p2p_dev_ctx, prov_disc_req_ev->sa); + + /* Set up the WPS method in use by the peer in the device context. + */ + if (peer) { + peer->dev.flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); + } + if (prov_disc_req_ev->wps_config_method & WPS_CONFIG_DISPLAY) { + if (peer) { + peer->dev.flags |= P2P_DEV_PD_PEER_KEYPAD; + } + } else if (prov_disc_req_ev->wps_config_method & WPS_CONFIG_KEYPAD) { + if (peer) { + peer->dev.flags |= P2P_DEV_PD_PEER_DISPLAY; + } + } + + /* Report PD request event to the Supplicant so that the user App can + * be prompted for any necessary inputs. + */ + +printk(KERN_ALERT "wps_cfg_method: %d, dev_cfg_method: %d, \ + dev_capab: %d, grp_capab: %d\n", prov_disc_req_ev->wps_config_method, + prov_disc_req_ev->dev_config_methods, prov_disc_req_ev->device_capab, + prov_disc_req_ev->group_capab); + + A_WMI_P2P_PROV_DISC_REQ_EVENT(p2p_dev_ctx->dev, prov_disc_req_ev->sa, + prov_disc_req_ev->wps_config_method, prov_disc_req_ev->dev_addr, + prov_disc_req_ev->pri_dev_type, prov_disc_req_ev->device_name, + prov_disc_req_ev->dev_name_len, + prov_disc_req_ev->dev_config_methods, prov_disc_req_ev->device_capab, + prov_disc_req_ev->group_capab); + + return; +} + +void p2p_prov_disc_resp_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + WMI_P2P_PROV_DISC_RESP_EVENT *prov_disc_resp_ev = + (WMI_P2P_PROV_DISC_RESP_EVENT *)datap; + struct host_p2p_dev *peer = NULL; + + /* Get hold of the peer device from the device list. The peer dev should + * be present in our dev list.(atleast added to the list from the bss_info + * ev that the firmware would have sent prior to this event). + */ + peer = p2p_get_device(p2p_dev_ctx, prov_disc_resp_ev->peer); + + /* Set up the WPS method in use by the peer in the device context. + */ + if (peer) { + peer->dev.flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); + } + if (prov_disc_resp_ev->config_methods & WPS_CONFIG_DISPLAY) { + if (peer) { + peer->dev.flags |= P2P_DEV_PD_PEER_KEYPAD; + } + } else if (prov_disc_resp_ev->config_methods & WPS_CONFIG_KEYPAD) { + if (peer) { + peer->dev.flags |= P2P_DEV_PD_PEER_DISPLAY; + } + } + + peer->dev.req_config_methods = 0; + + /* Report PD response event to the Supplicant so that the user App can + * be prompted for any necessary inputs. + */ + A_WMI_P2P_PROV_DISC_RESP_EVENT(p2p_dev_ctx->dev, prov_disc_resp_ev->peer, + prov_disc_resp_ev->config_methods); + + return; +} + +A_STATUS p2p_auth_invite(void *ctx, A_UINT8 *auth_peer) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + A_STATUS status = A_OK; + + /* Mark the peer as authorized by the user for Invitation. + */ + A_MEMCPY(p2p_dev_ctx->p2p_auth_invite, auth_peer, ETH_ALEN); + + return status; +} + +A_STATUS p2p_auth_go_neg(void *ctx, WMI_P2P_GO_NEG_START_CMD *auth_go_neg_param) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_ctx *p2p_cmn_ctx = (struct p2p_ctx *)p2p_dev_ctx->p2p_ctx; + struct host_p2p_dev *peer = NULL; + A_STATUS status = A_OK; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, auth_go_neg_param->peer_addr); + if (peer == NULL) { + /* Unknown peer device. + */ + status = A_ERROR; + } else { + /* Mark the peer as authorized by the user & ready for GO Negotiation. + */ + peer->dev.flags &= ~P2P_DEV_NOT_YET_READY; + peer->dev.flags &= ~P2P_DEV_USER_REJECTED; + + p2p_cmn_ctx->go_intent = auth_go_neg_param->go_intent; + peer->persistent_grp = auth_go_neg_param->persistent_grp; + peer->dev.wps_method = auth_go_neg_param->wps_method; + } + + return status; +} + +A_STATUS p2p_peer_reject(void *ctx, A_UINT8 *peer_addr) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status = A_OK; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, peer_addr); + if (peer == NULL) { + /* Unknown peer device. + */ + status = A_ERROR; + } else { + peer->dev.flags |= P2P_DEV_USER_REJECTED; + } + + return status; +} + +A_STATUS p2p_go_neg_start(void *ctx, WMI_P2P_GO_NEG_START_CMD *go_neg_param) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *peer = NULL; + struct host_p2p_dev *peer_go = NULL; + A_STATUS status = A_OK; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, go_neg_param->peer_addr); + if (peer == NULL) { + /* Unknown peer device. + */ + return A_ERROR; + } + + /* Monotonically increasing per device dialog tokens - generated from host + * & wraps back to 0. Send in WMI param from host. + */ + peer->dev.dialog_token++; + if (peer->dev.dialog_token == 0) { + peer->dev.dialog_token = 1; + } + + /* Mark the peer as authorized by the user & ready for GO Negotiation. + */ + peer->dev.flags &= ~P2P_DEV_NOT_YET_READY; + peer->dev.flags &= ~P2P_DEV_USER_REJECTED; + + peer->dev.wps_method = go_neg_param->wps_method; + + if (peer->dev.listen_freq) { + go_neg_param->listen_freq = peer->dev.listen_freq; + } else if (peer->dev.oper_freq) { + go_neg_param->listen_freq = peer->dev.oper_freq; + } + + go_neg_param->dialog_token = peer->dev.dialog_token; + go_neg_param->dev_capab = peer->dev.dev_capab; + + + /* If this peer is a member of a group, then get info about the GO of that group. This is + * useful to send device discoverability request to its GO, in case this peer does not + * respond to our GO Negotiation request. + */ + if (!is_zero_mac_addr(peer->dev.member_in_go_dev)) { + A_MEMCPY(go_neg_param->member_in_go_dev, peer->dev.member_in_go_dev, ETH_ALEN); + + peer_go = p2p_get_device(ctx, peer->dev.member_in_go_dev); + + if (peer_go) { + + peer_go->dev.dialog_token++; + if (peer_go->dev.dialog_token == 0) { + peer_go->dev.dialog_token = 1; + } + go_neg_param->go_dev_dialog_token = peer_go->dev.dialog_token; + + go_neg_param->go_oper_freq = peer_go->dev.oper_freq; + + if (peer_go->dev.oper_ssid_len) { + A_MEMCPY(go_neg_param->peer_go_ssid.ssid, peer_go->dev.oper_ssid, + peer_go->dev.oper_ssid_len); + go_neg_param->peer_go_ssid.ssidLength = peer_go->dev.oper_ssid_len; + } + } + } + + status = wmi_p2p_go_neg_start(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), + go_neg_param); + + return status; +} + +A_STATUS p2p_invite_cmd(void *ctx, WMI_P2P_INVITE_CMD *invite_param) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *peer = NULL; + A_STATUS status = A_OK; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, invite_param->peer_addr); + if (peer == NULL) { + /* Unknown peer device. + */ + return A_ERROR; + } + + /* Monotonically increasing per device dialog tokens - generated from host + * & wraps back to 0. Send in WMI param from host. + */ + peer->dev.dialog_token++; + if (peer->dev.dialog_token == 0) { + peer->dev.dialog_token = 1; + } + + invite_param->dialog_token = peer->dev.dialog_token; + + status = wmi_p2p_invite_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), + invite_param); + + return status; +} + +A_STATUS p2p_prov_disc_req(void *ctx, A_UINT8 *peer_addr, A_UINT16 wps_method) +{ + + struct host_p2p_dev *peer = NULL; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, peer_addr); + if (peer == NULL) { + /* Unknown peer device. + */ + peer = p2p_get_device_intf_addrs(ctx, peer_addr); + } + + if (peer == NULL || (peer->dev.flags & P2P_DEV_PROBE_REQ_ONLY)) { + return A_ERROR; + } + + peer->dev.req_config_methods = wps_method; + + /* Return from here. PD will happen in the context of p2p_find(). + */ + return A_OK; +} + + +void p2p_send_prov_disc_req(struct host_p2p_dev *peer) +{ + struct p2p_dev_ctx *p2p_dev_ctx = peer->p2p; + WMI_P2P_PROV_DISC_REQ_CMD prov_disc_req; + + + /* Set up the PD Request cmd params. + */ + A_MEMZERO(&prov_disc_req, sizeof(WMI_P2P_PROV_DISC_REQ_CMD)); + + A_MEMCPY(prov_disc_req.peer, peer->dev.p2p_device_addr, ATH_MAC_LEN); + prov_disc_req.wps_method = peer->dev.req_config_methods; + + /* Monotonically increasing per device dialog tokens - generated from host + * & wraps back to 0. Send in WMI param from host. + */ + peer->dev.dialog_token++; + if (peer->dev.dialog_token == 0) { + peer->dev.dialog_token = 1; + } + prov_disc_req.dialog_token = peer->dev.dialog_token; + + if (peer->dev.listen_freq) { + prov_disc_req.listen_freq = peer->dev.listen_freq; + } else if (peer->dev.oper_freq) { + prov_disc_req.listen_freq = peer->dev.oper_freq; + } + + if (peer->dev.oper_ssid_len) { + A_MEMCPY(prov_disc_req.go_oper_ssid.ssid, peer->dev.oper_ssid, peer->dev.oper_ssid_len); + prov_disc_req.go_oper_ssid.ssidLength = peer->dev.oper_ssid_len; + + if (!is_zero_mac_addr(peer->dev.interface_addr)) { + A_MEMCPY(prov_disc_req.go_dev_addr, peer->dev.interface_addr, + ATH_MAC_LEN); + } else { + A_MEMCPY(prov_disc_req.go_dev_addr, prov_disc_req.peer, + ATH_MAC_LEN); + } + } + + wmi_p2p_prov_disc_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), &prov_disc_req); + + return; +} + +void p2p_free_all_devices(void *ctx) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + + /* + * In order to free all of the devices from the dl_list, we CANNOT + * simply call p2p_device_free on all of the peers. This is because + * there might be references to these devices from the scan table, and + * just freeing the devices would potentially cause a segfault. + * Therefore, we use wmi_free_allnodes to eliminate all references from + * the scan table as well as to free the devices from the dl_list. + */ + wmi_free_allnodes(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev)); +} + +void p2p_device_free(void *peer_dev) +{ + struct host_p2p_dev *peer = (struct host_p2p_dev *)peer_dev; + + /* decrement the ref count & free up the node if the ref. cnt becomes + * zero. + */ + if (--peer->ref_cnt == 0) { + DL_ListRemove(&peer->list); + A_PRINTF("-: %x:%x\n", (peer->dev).p2p_device_addr[4], + (peer->dev).p2p_device_addr[5]); + A_FREE(peer); + } + + A_PRINTF("-%d\n", peer->ref_cnt); + return; +} + +A_STATUS p2p_peer(void *ctx, A_UINT8 *peer_addr, A_UINT8 next) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, peer_addr); + if (peer) { + A_PRINTF("peer Found\n"); + status = A_OK; + } else { + A_PRINTF("peer NOTFound\n"); + status = A_DEVICE_NOT_FOUND; + } + + return status; +} + + +A_STATUS p2p_get_device_p2p_buf(void *ctx, A_UINT8 *peer_addr, A_UINT8 **ni_buf, A_UINT8 *ni_buf_len) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status; + /* Get hold of the peer device */ + peer = p2p_get_device(ctx, peer_addr); + if (peer) { + *ni_buf = peer->p2p_buf; + *ni_buf_len = peer->p2p_buf_len; + status = A_OK; + } else { + status = A_DEVICE_NOT_FOUND; + } + + return status; + +} + +A_STATUS p2p_get_ifaddr (void *ctx, A_UINT8 *dev_addr) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, dev_addr); + if (peer) { + A_MEMCPY((dev_addr+6), peer->dev.interface_addr, ATH_MAC_LEN); + status = A_OK; + } else { + status = A_DEVICE_NOT_FOUND; + } + + return status; + +} + +A_STATUS p2p_get_devaddr (void *ctx, A_UINT8 *intf_addr) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status; + + /* Get hold of the peer device by interface address. + */ + peer = p2p_get_device_intf_addrs(ctx, intf_addr); + if (peer) { + A_MEMCPY((intf_addr+6), (peer->dev).p2p_device_addr, ATH_MAC_LEN); + status = A_OK; + } else { + status = A_DEVICE_NOT_FOUND; + } + + return status; + +} + +A_STATUS wmi_p2p_get_go_params(void *ctx, A_UINT8 *go_dev_addr, + A_UINT16 *oper_freq, A_UINT8 *ssid, A_UINT8 *ssid_len) +{ + struct host_p2p_dev *peer = NULL; + A_STATUS status; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, go_dev_addr); + if (peer) { + A_PRINTF("peer Found\n"); + *oper_freq = peer->dev.oper_freq; + + if (peer->dev.oper_ssid) { + A_MEMCPY(ssid, peer->dev.oper_ssid, peer->dev.oper_ssid_len); + *ssid_len = peer->dev.oper_ssid_len; + } + status = A_OK; + } else { + A_PRINTF("peer NOTFound\n"); + status = A_DEVICE_NOT_FOUND; + } + + return status; +} + +void p2p_increment_dev_ref_count(struct host_p2p_dev *dev) +{ + /* Increment the ref count. The dev ages out in 2 mins time (configurable) + * Unlikely to have more than 255 references to the dev before it + * ages out. + */ + dev->ref_cnt++; + + A_PRINTF("+%d\n", dev->ref_cnt); + + return; +} + +static void p2p_free_sd_query(struct p2p_sd_query *q) +{ + if (q == NULL) { + return; + } + if (q->tlvs) { + A_FREE(q->tlvs); + } + A_FREE(q); +} + +static int p2p_unlink_sd_query(void *ctx, struct p2p_sd_query *query) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_sd_query *q, *prev; + + q = p2p_dev_ctx->sd_queries; + prev = NULL; + + while (q) { + if (q == query) { + if (prev) + prev->next = q->next; + else + p2p_dev_ctx->sd_queries = q->next; + if (p2p_dev_ctx->sd_queries == query) + p2p_dev_ctx->sd_queries = NULL; + return 1; + } + prev = q; + q = q->next; + } + return 0; +} + +void p2p_free_all_sd_queries(void *ctx) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_sd_query *q, *next; + + /* + * Walk through the list and free all of the p2p_sd_queries + */ + q = p2p_dev_ctx->sd_queries; + + while (q) { + next = q->next; + if (p2p_unlink_sd_query(p2p_dev_ctx, q)) { + p2p_free_sd_query(q); + } + q = next; + } + + /* + * Null out the sd_queries pointer in the p2p_dev_ctx. This + * item no longer exists! + */ + p2p_dev_ctx->sd_queries = NULL; + + /* + * Now null out the curr_sd_query pointer because if it exists, + * the sd_query has been freed already. + */ + p2p_dev_ctx->curr_sd_query = NULL; +} + +A_STATUS p2p_sd_request(void *ctx, A_UINT8 *peer_addr, A_UINT8 *tlv_buf, A_UINT8 tlv_buflen, A_UINT32 *qid) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct p2p_sd_query *q; + + q = A_MALLOC_NOWAIT(sizeof(struct p2p_sd_query)); + if (q == NULL) { + return A_ERROR; + } + + A_MEMZERO(q, sizeof(struct p2p_sd_query)); + + if (is_zero_mac_addr(peer_addr)) { + q->for_all_peers = 1; + } else { + A_MEMCPY(q->peer, peer_addr, ETH_ALEN); + } + + q->tlvs = A_MALLOC_NOWAIT(tlv_buflen); + if (q->tlvs == NULL) { + p2p_free_sd_query(q); + return A_ERROR; + } + A_MEMZERO(q->tlvs, tlv_buflen); + + A_MEMCPY(q->tlvs, tlv_buf, tlv_buflen); + q->tlv_len = tlv_buflen; + + q->next = p2p_dev_ctx->sd_queries; + p2p_dev_ctx->sd_queries = q; + + *qid = (A_UINT32)q; + + return A_OK; +} + +A_STATUS p2p_sdpd_tx_cmd(void *ctx, WMI_P2P_SDPD_TX_CMD *sdpd_tx_cmd, A_UINT32 *qid) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + A_STATUS status; + + *qid = 0; + if (sdpd_tx_cmd->type == WMI_P2P_SD_TYPE_GAS_INITIAL_REQ) { + status = p2p_sd_request(ctx, sdpd_tx_cmd->peer_addr, sdpd_tx_cmd->tlv, sdpd_tx_cmd->tlv_length, qid); + } else { + status = wmi_p2p_sdpd_tx_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), sdpd_tx_cmd); + } + + return status; +} + +A_STATUS p2p_sd_cancel_request(void *ctx, A_UINT32 qid) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + + if (p2p_unlink_sd_query(p2p_dev_ctx, (void *)qid)) { + p2p_free_sd_query((void *)qid); + } + + return A_OK; +} + +void p2p_start_sdpd_event_rx(void *ctx) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *dev; + PDL_LIST pListItem; + WMI_P2P_SDPD_TX_CMD p2p_sdpd_req; + struct p2p_sd_query *query; + + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + + /* DO Service Discovery */ + if (dev->dev.flags & P2P_DEV_SD_SCHEDULE) { + A_MEMZERO(&p2p_sdpd_req, sizeof(WMI_P2P_SDPD_TX_CMD)); + + query = p2p_pending_sd_req(p2p_dev_ctx, dev); + + p2p_dev_ctx->curr_sd_query = query; + + if (query == NULL) { + continue; + } else { + if (dev->dev.listen_freq) { + p2p_sdpd_req.freq = dev->dev.listen_freq; + } else if (dev->dev.oper_freq) { + p2p_sdpd_req.freq = dev->dev.oper_freq; + } + p2p_sdpd_req.type = WMI_P2P_SD_TYPE_GAS_INITIAL_REQ; + A_MEMCPY(p2p_sdpd_req.peer_addr, dev->dev.p2p_device_addr, ETH_ALEN); + A_MEMCPY(p2p_sdpd_req.tlv, query->tlvs, query->tlv_len); + p2p_sdpd_req.tlv_length = query->tlv_len; + p2p_sdpd_req.update_indic = p2p_dev_ctx->srv_update_indic; + + wmi_p2p_sdpd_tx_cmd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), &p2p_sdpd_req); + return; + } + } else if (dev->dev.req_config_methods && !(dev->dev.flags & P2P_DEV_PD_FOR_JOIN)) { + /*Do Provisional Discovery */ + p2p_send_prov_disc_req(dev); + return; + } + } + + /* Send the WMI_P2P_SDPD_STOP_CMD for the firmware to continue with Listen in FIND. + */ + wmi_p2p_stop_sdpd(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev)); + + return; +} + +void p2p_sdpd_rx_event_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + WMI_P2P_SDPD_RX_EVENT *ev; + + ev = (WMI_P2P_SDPD_RX_EVENT *)datap; + + /* Pass the event up to the Supplicant */ + switch (ev->type) { + case WMI_P2P_SD_TYPE_GAS_INITIAL_REQ: + case WMI_P2P_SD_TYPE_GAS_COMEBACK_REQ: + case WMI_P2P_SD_TYPE_GAS_INITIAL_RESP: + case WMI_P2P_SD_TYPE_GAS_COMEBACK_RESP: + A_WMI_P2P_SD_RX_EVENT(p2p_dev_ctx->dev, ev); + break; + case WMI_P2P_SD_TYPE_STATUS_IND: + A_PRINTF("SDPD Status Indication\n"); + break; + case WMI_P2P_PD_TYPE_RESP: + A_PRINTF("PD response got\n"); + break; + default: + A_PRINTF("SDPD resp event %x not supported \n", ev->type); + break; + } + + /* Check the SD transaction status if it is a SD response & drive the FSM appropriately. + */ + switch (ev->type) { + case WMI_P2P_SD_TYPE_GAS_INITIAL_RESP: + case WMI_P2P_SD_TYPE_GAS_COMEBACK_RESP: + + if (ev->transaction_status == WMI_P2P_SDPD_TRANSACTION_COMP) { + struct host_p2p_dev *sd_peer = NULL; + + sd_peer = p2p_get_device(p2p_dev_ctx, ev->peer_addr); + + if (sd_peer) { + sd_peer->dev.flags |= P2P_DEV_SD_INFO; + } + + /* Remove directed queries that have been handled. + */ + if (p2p_dev_ctx->curr_sd_query && !(p2p_dev_ctx->curr_sd_query->for_all_peers)) { + if (p2p_unlink_sd_query(p2p_dev_ctx, p2p_dev_ctx->curr_sd_query)) { + p2p_free_sd_query((void *)p2p_dev_ctx->curr_sd_query); + } + } + } + + case WMI_P2P_SD_TYPE_STATUS_IND: + + if (ev->transaction_status == WMI_P2P_SDPD_TRANSACTION_COMP) { + struct host_p2p_dev *sd_peer = NULL; + + /* Clean up SD pending state for this dev for which the SD transaction + * completed. + */ + sd_peer = p2p_get_device(p2p_dev_ctx, ev->peer_addr); + + /* Query for this device completed. + */ + if (sd_peer) { + sd_peer->dev.flags &= ~P2P_DEV_SD_SCHEDULE; + } + + /* Proceed with the next SD/PD. + */ + p2p_start_sdpd_event_rx(ctx); + } + break; + + case WMI_P2P_PD_TYPE_RESP: + + /* Proceed with the next SD/PD. + */ + p2p_start_sdpd_event_rx(ctx); + break; + + default: + break; + } + + return; +} + +static struct p2p_sd_query *p2p_pending_sd_req(struct p2p_dev_ctx *p2p_dev_ctx, + struct host_p2p_dev *dev) +{ + struct p2p_sd_query *q; + + if (!(dev->dev.dev_capab & P2P_DEV_CAPAB_SERVICE_DISCOVERY)) { + return NULL; /* peer does not support SD */ + } + + for (q = p2p_dev_ctx->sd_queries; q; q = q->next) { + if (q->for_all_peers && !(dev->dev.flags & P2P_DEV_SD_INFO)) { + return q; + } + if (!q->for_all_peers && + A_MEMCMP(q->peer, dev->dev.p2p_device_addr, ETH_ALEN) == 0) + return q; + } + + return NULL; +} + +void p2p_go_neg_complete_rx(void *ctx, const A_UINT8 *datap, A_UINT8 len) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + WMI_P2P_GO_NEG_RESULT_EVENT *ev = (WMI_P2P_GO_NEG_RESULT_EVENT *)datap; + struct host_p2p_dev *peer = NULL; + + /* Get hold of the peer device from the device list. + */ + peer = p2p_get_device(p2p_dev_ctx, ev->peer_device_addr); + + A_ASSERT(peer != NULL); + /*Store minimal persistent group info for Invitation processing*/ + if(ev->persistent_grp) { + peer->persistent_grp = ev->persistent_grp; + peer->role_go = ev->role_go; + peer->ssid_len = ev->ssid_len; + A_MEMCPY(peer->ssid, ev->ssid, ev->ssid_len); + } + return; +} +/** + * wpa_ssid_txt - Convert SSID to a printable string + * @ssid: SSID (32-octet string) + * @ssid_len: Length of ssid in octets + * Returns: Pointer to a printable string + * + * This function can be used to convert SSIDs into printable form. In most + * cases, SSIDs do not use unprintable characters, but IEEE 802.11 standard + * does not limit the used character set, so anything could be used in an SSID. + * + * This function uses a static buffer, so only one call can be used at the + * time, i.e., this is not re-entrant and the returned buffer must be used + * before calling this again. + */ +static const char * wpa_ssid_txt(const u8 *ssid, A_UINT8 ssid_len) +{ + static char ssid_txt[33]; + char *pos; + + if (ssid_len > 32) + ssid_len = 32; + memcpy(ssid_txt, ssid, ssid_len); + ssid_txt[ssid_len] = '\0'; + for (pos = ssid_txt; *pos != '\0'; pos++) { + if ((u8) *pos < 32 || (u8) *pos >= 127) + *pos = '_'; + } + return ssid_txt; +} + +static const char * p2p_go_state_text(enum p2p_go_state go_state) +{ + switch (go_state) { + case UNKNOWN_GO: + return "unknown"; + case LOCAL_GO: + return "local"; + case REMOTE_GO: + return "remote"; + } + + return "??"; +} + +static char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf, + A_UINT32 buf_len) +{ + int ret; + + ret = snprintf(buf, buf_len, "%u-%08X-%u", + WPA_GET_BE16(dev_type), WPA_GET_BE32(&dev_type[2]), + WPA_GET_BE16(&dev_type[6])); + if (ret < 0 || (unsigned int) ret >= buf_len) + return NULL; + + return buf; +} + + +static const char * p2p_wps_method_text(enum p2p_wps_method method) +{ + switch (method) { + case WPS_NOT_READY: + return "not-ready"; + case WPS_PIN_LABEL: + return "Label"; + case WPS_PIN_DISPLAY: + return "Display"; + case WPS_PIN_KEYPAD: + return "Keypad"; + case WPS_PBC: + return "PBC"; + } + + return "??"; +} + + +int p2p_get_peer_info(void *ctx, A_UINT8 *peer_addr, A_UINT8 *buf, A_UINT32 buflen) +{ + struct host_p2p_dev *peer = NULL; + struct p2p_device *dev; + int res; + A_UINT8 *pos, *end; + A_UINT8 devtype[WPS_DEV_TYPE_BUFSIZE]; + bss_t *bss; + A_UINT32 level = 0; + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + + /* Get hold of the peer device + */ + peer = p2p_get_device(ctx, peer_addr); + if (!peer) { + return 0; + } + + dev = &peer->dev; + + bss = wmi_find_node(A_WMI_GET_WMI_CTX(p2p_dev_ctx->dev), dev->p2p_device_addr); + if(bss) { + level = bss->ni_snr; + /* NB: max is 94 because noise is hardcoded to 161 */ + if (level > 94) + level = 94; + + level += 161; /*Add Noise -95dBm*/ + /*level greater than Noise max_level*/ + if(level >=64) + level -=0x100; + } + pos = buf; + end = buf + buflen; + + res = snprintf(pos, end - pos, MACSTR "\n", + MAC2STR(dev->p2p_device_addr)); + + if (res < 0 || res >= end - pos) { + return pos - buf; + return A_NO_MEMORY; + } + + pos += res; + + res = snprintf(pos, end - pos, + "listen_freq=%d\n" + "level=%d\n" + "wps_method=%s\n" + "interface_addr=" MACSTR "\n" + "member_in_go_dev=" MACSTR "\n" + "member_in_go_iface=" MACSTR "\n" + "pri_dev_type=%s\n" + "device_name=%s\n" + "config_methods=0x%x\n" + "dev_capab=0x%x\n" + "group_capab=0x%x\n" + "go_neg_req_sent=%d\n" + "go_state=%s\n" + "dialog_token=%u\n" + "intended_addr=" MACSTR "\n" + "country=%c%c\n" + "oper_freq=%d\n" + "req_config_methods=0x%x\n" + "flags=%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n" + "status=%d\n" + "wait_count=%u\n" + "invitation_reqs=%u\n", + dev->listen_freq, + level, + p2p_wps_method_text(dev->wps_method), + MAC2STR(dev->interface_addr), + MAC2STR(dev->member_in_go_dev), + MAC2STR(dev->member_in_go_iface), + wps_dev_type_bin2str(dev->pri_dev_type, + devtype, sizeof(devtype)), + dev->device_name, + dev->config_methods, + dev->dev_capab, + dev->group_capab, + dev->go_neg_req_sent, + p2p_go_state_text(dev->go_state), + dev->dialog_token, + MAC2STR(dev->intended_addr), + dev->country[0] ? dev->country[0] : '_', + dev->country[1] ? dev->country[1] : '_', + dev->oper_freq, + dev->req_config_methods, + dev->flags & P2P_DEV_PROBE_REQ_ONLY ? + "[PROBE_REQ_ONLY]" : "", + dev->flags & P2P_DEV_REPORTED ? "[REPORTED]" : "", + dev->flags & P2P_DEV_NOT_YET_READY ? + "[NOT_YET_READY]" : "", + dev->flags & P2P_DEV_SD_INFO ? "[SD_INFO]" : "", + dev->flags & P2P_DEV_SD_SCHEDULE ? "[SD_SCHEDULE]" : + "", + dev->flags & P2P_DEV_PD_PEER_DISPLAY ? + "[PD_PEER_DISPLAY]" : "", + dev->flags & P2P_DEV_PD_PEER_KEYPAD ? + "[PD_PEER_KEYPAD]" : "", + dev->flags & P2P_DEV_USER_REJECTED ? + "[USER_REJECTED]" : "", + dev->flags & P2P_DEV_PEER_WAITING_RESPONSE ? + "[PEER_WAITING_RESPONSE]" : "", + dev->flags & P2P_DEV_PREFER_PERSISTENT_GROUP ? + "[PREFER_PERSISTENT_GROUP]" : "", + dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE ? + "[WAIT_GO_NEG_RESPONSE]" : "", + dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM ? + "[WAIT_GO_NEG_CONFIRM]" : "", + dev->flags & P2P_DEV_GROUP_CLIENT_ONLY ? + "[GROUP_CLIENT_ONLY]" : "", + dev->flags & P2P_DEV_FORCE_FREQ ? + "[FORCE_FREQ]" : "", + dev->status, + dev->wait_count, + dev->invitation_reqs); + if (res < 0 || res >= end - pos) { + return pos - buf; + } + + pos += res; + + if (dev->ext_listen_period) { + res = snprintf(pos, end - pos, + "ext_listen_period=%u\n" + "ext_listen_interval=%u\n", + dev->ext_listen_period, + dev->ext_listen_interval); + if (res < 0 || res >= end - pos) { + return pos - buf; + } + pos += res; + } + + if (dev->oper_ssid_len) { + res = snprintf(pos, end - pos, + "oper_ssid=%s\n", + wpa_ssid_txt(dev->oper_ssid, + dev->oper_ssid_len)); + if (res < 0 || res >= end - pos) { + return pos - buf; + } + } + return pos - buf; +} + +int p2p_get_next_addr(void *ctx, A_UINT8 *addr, A_UINT8 *buf, A_UINT32 buflen, int first_element) +{ + struct host_p2p_dev *peer = NULL; + struct p2p_device *dev; + int res; + A_UINT8 *pos, *end; + + peer = p2p_get_next_device(ctx, addr, first_element); + + if (!peer) { + return 0; + } + + dev = &peer->dev; + + pos = buf; + end = buf + buflen; + + res = snprintf(pos, end - pos, MACSTR "\n", + MAC2STR(dev->p2p_device_addr)); + + if (res < 0 || res >= end - pos) { + return pos - buf; + return A_NO_MEMORY; + } + + pos += res; + + return pos - buf; +} + +void p2p_clear_peers_reported_flag(void *ctx) +{ + struct p2p_dev_ctx *p2p_dev_ctx = (struct p2p_dev_ctx *)ctx; + struct host_p2p_dev *dev; + PDL_LIST pListItem; + + ITERATE_OVER_LIST(&p2p_dev_ctx->devices, pListItem) { + dev = A_CONTAINING_STRUCT(pListItem, struct host_p2p_dev, list); + dev->dev.flags &= (~P2P_DEV_REPORTED); + } +} + +void p2p_clear_peers_authorized_flag(void *ctx, const A_UINT8 *addr) +{ + struct host_p2p_dev *peer = NULL; + + /* Get hold of the peer device. + */ + peer = p2p_get_device(ctx, addr); + if (peer == NULL) { + /* Find using interface addr. + */ + peer = p2p_get_device_intf_addrs(ctx, addr); + } + + if (peer) { + peer->dev.wps_method = WPS_NOT_READY; + } + + return; +} + diff --git a/drivers/net/wireless/ar6003/host/regtable/AR6002def.c b/drivers/net/wireless/ar6003/host/regtable/AR6002def.c new file mode 100644 index 000000000000..5bc66e246b2f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/AR6002def.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#if defined(AR6002_HEADERS_DEF) || defined(ATHR_WIN_DEF) +#define AR6002 1 +#define AR6002_REV 2 + +#define UNDEFINED 0x0fffffff + +#include "common_drv.h" +#include "AR6002/hw2.0/hw/apb_map.h" +#include "AR6002/hw2.0/hw/gpio_reg.h" +#include "AR6002/hw2.0/hw/rtc_reg.h" +#include "AR6002/hw2.0/hw/si_reg.h" +#include "AR6002/hw2.0/hw/mbox_reg.h" +#include "AR6002/hw2.0/hw/mbox_host_reg.h" + +#define MY_TARGET_DEF AR6002_TARGETdef +#define MY_HOST_DEF AR6002_HOSTdef +#define MY_TARGET_BOARD_DATA_SZ AR6002_BOARD_DATA_SZ +#define MY_TARGET_BOARD_EXT_DATA_SZ AR6002_BOARD_EXT_DATA_SZ +#define RTC_WMAC_BASE_ADDRESS RTC_BASE_ADDRESS +#define RTC_SOC_BASE_ADDRESS RTC_BASE_ADDRESS +#define WLAN_SYSTEM_SLEEP_OFFSET SYSTEM_SLEEP_OFFSET +#define WLAN_SYSTEM_SLEEP_DISABLE_LSB SYSTEM_SLEEP_DISABLE_LSB +#define WLAN_SYSTEM_SLEEP_DISABLE_MASK SYSTEM_SLEEP_DISABLE_MASK +#define WLAN_RESET_CONTROL_OFFSET RESET_CONTROL_OFFSET +#define WLAN_RESET_CONTROL_COLD_RST_MASK RESET_CONTROL_COLD_RST_MASK +#define WLAN_RESET_CONTROL_WARM_RST_MASK RESET_CONTROL_WARM_RST_MASK + + +/* Should not be used for AR6002 */ +#define CLOCK_GPIO_OFFSET UNDEFINED +#define CLOCK_GPIO_BT_CLK_OUT_EN_LSB UNDEFINED +#define CLOCK_GPIO_BT_CLK_OUT_EN_MASK UNDEFINED + +#include "targetdef.h" +#include "hostdef.h" +#else +#include "common_drv.h" +#include "targetdef.h" +#include "hostdef.h" +struct targetdef_s *AR6002_TARGETdef=NULL; +struct hostdef_s *AR6002_HOSTdef=NULL; +#endif /* AR6002_HEADERS_DEF */ diff --git a/drivers/net/wireless/ar6003/host/regtable/AR6003def.c b/drivers/net/wireless/ar6003/host/regtable/AR6003def.c new file mode 100644 index 000000000000..144b1bdcca7b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/AR6003def.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#if defined(AR6003_HEADERS_DEF) || defined(ATHR_WIN_DEF) +#define AR6002 1 +#define AR6002_REV 4 + +#define WLAN_HEADERS 1 +#include "common_drv.h" +#include "AR6002/hw4.0/hw/apb_map.h" +#include "AR6002/hw4.0/hw/gpio_reg.h" +#include "AR6002/hw4.0/hw/rtc_reg.h" +#include "AR6002/hw4.0/hw/si_reg.h" +#include "AR6002/hw4.0/hw/mbox_reg.h" +#include "AR6002/hw4.0/hw/mbox_wlan_host_reg.h" + +#define MY_TARGET_DEF AR6003_TARGETdef +#define MY_HOST_DEF AR6003_HOSTdef +#define MY_TARGET_BOARD_DATA_SZ AR6003_BOARD_DATA_SZ +#define MY_TARGET_BOARD_EXT_DATA_SZ AR6003_BOARD_EXT_DATA_SZ +#define RTC_WMAC_BASE_ADDRESS RTC_BASE_ADDRESS +#define RTC_SOC_BASE_ADDRESS RTC_BASE_ADDRESS + +#include "targetdef.h" +#include "hostdef.h" +#else +#include "common_drv.h" +#include "targetdef.h" +#include "hostdef.h" +struct targetdef_s *AR6003_TARGETdef=NULL; +struct hostdef_s *AR6003_HOSTdef=NULL; +#endif /*AR6003_HEADERS_DEF */ diff --git a/drivers/net/wireless/ar6003/host/regtable/MCKINLEYdef.c b/drivers/net/wireless/ar6003/host/regtable/MCKINLEYdef.c new file mode 100644 index 000000000000..6829bae5f0cc --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/MCKINLEYdef.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ +#if defined(MCKINLEY_HEADERS_DEF) || defined(ATHR_WIN_DEF) +#define AR6002 1 +#define AR6002_REV 6 + +#define WLAN_HEADERS 1 +#include "common_drv.h" +#include "AR6002/hw6.0/hw/apb_map.h" +#include "AR6002/hw6.0/hw/gpio_reg.h" +#include "AR6002/hw6.0/hw/rtc_reg.h" +#include "AR6002/hw6.0/hw/si_reg.h" +#include "AR6002/hw6.0/hw/mbox_reg.h" +#include "AR6002/hw6.0/hw/mbox_wlan_host_reg.h" + +#define SYSTEM_SLEEP_OFFSET SOC_SYSTEM_SLEEP_OFFSET + +#define MY_TARGET_DEF MCKINLEY_TARGETdef +#define MY_HOST_DEF MCKINLEY_HOSTdef +#define MY_TARGET_BOARD_DATA_SZ MCKINLEY_BOARD_DATA_SZ +#define MY_TARGET_BOARD_EXT_DATA_SZ MCKINLEY_BOARD_EXT_DATA_SZ +#include "targetdef.h" +#include "hostdef.h" +#else +#include "common_drv.h" +#include "targetdef.h" +#include "hostdef.h" +struct targetdef_s *MCKINLEY_TARGETdef=NULL; +struct hostdef_s *MCKINLEY_HOSTdef=NULL; +#endif /*MCKINLEY_HEADERS_DEF */ diff --git a/drivers/net/wireless/ar6003/host/regtable/hostdef.h b/drivers/net/wireless/ar6003/host/regtable/hostdef.h new file mode 100644 index 000000000000..e1544751e462 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/hostdef.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#ifndef HOSTDEFS_H_ +#define HOSTDEFS_H_ + +#include +#include +#include +#include +#include "host_reg_table.h" + +extern struct hostdef_s *AR6002_HOSTdef; +extern struct hostdef_s *AR6003_HOSTdef; +extern struct hostdef_s *MCKINLEY_HOSTdef; + +#endif diff --git a/drivers/net/wireless/ar6003/host/regtable/makefile b/drivers/net/wireless/ar6003/host/regtable/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/regtable/regtable.c b/drivers/net/wireless/ar6003/host/regtable/regtable.c new file mode 100644 index 000000000000..000a72df8168 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/regtable.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + + +#include "common_drv.h" +#include "bmi_msg.h" + +#include "targetdef.h" +#include "hostdef.h" +#include "hif.h" + + +/* Target-dependent addresses and definitions */ +struct targetdef_s *targetdef; +/* HIF-dependent addresses and definitions */ +struct hostdef_s *hostdef; + +void target_register_tbl_attach(A_UINT32 target_type) +{ + switch (target_type) { + case TARGET_TYPE_AR6002: + targetdef = AR6002_TARGETdef; + break; + case TARGET_TYPE_AR6003: + targetdef = AR6003_TARGETdef; + break; + case TARGET_TYPE_MCKINLEY: + targetdef = MCKINLEY_TARGETdef; + break; + default: + break; + } +} + +void hif_register_tbl_attach(A_UINT32 hif_type) +{ + switch (hif_type) { + case HIF_TYPE_AR6002: + hostdef = AR6002_HOSTdef; + break; + case HIF_TYPE_AR6003: + hostdef = AR6003_HOSTdef; + break; + case HIF_TYPE_MCKINLEY: + hostdef = MCKINLEY_HOSTdef; + break; + default: + break; + } +} + +EXPORT_SYMBOL(targetdef); +EXPORT_SYMBOL(hostdef); diff --git a/drivers/net/wireless/ar6003/host/regtable/targetdef.h b/drivers/net/wireless/ar6003/host/regtable/targetdef.h new file mode 100644 index 000000000000..bc8b8f7db7ea --- /dev/null +++ b/drivers/net/wireless/ar6003/host/regtable/targetdef.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008 Atheros Communications, Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#ifndef TARGETDEFS_H_ +#define TARGETDEFS_H_ + +#include +#include +#include +#include +#include "target_reg_table.h" + +extern struct targetdef_s *AR6002_TARGETdef; +extern struct targetdef_s *AR6003_TARGETdef; +extern struct targetdef_s *MCKINLEY_TARGETdef; + +#endif diff --git a/drivers/net/wireless/ar6003/host/reorder/aggr_rx_internal.h b/drivers/net/wireless/ar6003/host/reorder/aggr_rx_internal.h new file mode 100644 index 000000000000..00531c808430 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/reorder/aggr_rx_internal.h @@ -0,0 +1,125 @@ +/* + * + * Copyright (c) 2004-2010 Atheros Communications Inc. + * All rights reserved. + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#ifndef __AGGR_RX_INTERNAL_H__ +#define __AGGR_RX_INTERNAL_H__ + +#include "a_osapi.h" +#include "aggr_recv_api.h" + +//#define AGGR_DEBUG + +#define AGGR_WIN_IDX(x, y) ((x) % (y)) +#define AGGR_INCR_IDX(x, y) AGGR_WIN_IDX(((x)+1), (y)) +#define AGGR_DCRM_IDX(x, y) AGGR_WIN_IDX(((x)-1), (y)) +#define IEEE80211_MAX_SEQ_NO 0xFFF +#define IEEE80211_NEXT_SEQ_NO(x) (((x) + 1) & IEEE80211_MAX_SEQ_NO) + + +#define NUM_OF_TIDS 8 +#define AGGR_SZ_DEFAULT 8 + +#define AGGR_WIN_SZ_MIN 2 +#define AGGR_WIN_SZ_MAX 8 +/* TID Window sz is double of what is negotiated. Derive TID_WINDOW_SZ from win_sz, per tid */ +#define TID_WINDOW_SZ(_x) ((_x) << 1) + +#define AGGR_NUM_OF_FREE_NETBUFS 16 + +#define AGGR_GET_RXTID_STATS(_p, _x) (&(_p->stat[(_x)])) +#define AGGR_GET_RXTID(_p, _x) (&(_p->RxTid[(_x)])) + +/* Hold q is a function of win_sz, which is negotiated per tid */ +#define HOLD_Q_SZ(_x) (TID_WINDOW_SZ((_x))*sizeof(OSBUF_HOLD_Q)) +/* AGGR_RX_TIMEOUT value is important as a (too) small value can cause frames to be + * delivered out of order and a (too) large value can cause undesirable latency in + * certain situations. */ +#define AGGR_RX_TIMEOUT 400 /* Timeout(in ms) for delivery of frames, if they are stuck */ + +typedef enum { + ALL_SEQNO = 0, + CONTIGUOUS_SEQNO = 1, +}DELIVERY_ORDER; + +typedef struct { + void *osbuf; + A_BOOL is_amsdu; + A_UINT16 seq_no; +}OSBUF_HOLD_Q; + + +#if 0 +typedef struct { + A_UINT16 seqno_st; + A_UINT16 seqno_end; +}WINDOW_SNAPSHOT; +#endif + +typedef struct { + A_BOOL aggr; /* is it ON or OFF */ + A_BOOL progress; /* TRUE when frames have arrived after a timer start */ + A_BOOL timerMon; /* TRUE if the timer started for the sake of this TID */ + A_UINT16 win_sz; /* negotiated window size */ + A_UINT16 seq_next; /* Next seq no, in current window */ + A_UINT32 hold_q_sz; /* Num of frames that can be held in hold q */ + OSBUF_HOLD_Q *hold_q; /* Hold q for re-order */ +#if 0 + WINDOW_SNAPSHOT old_win; /* Sliding window snapshot - for timeout */ +#endif + A_NETBUF_QUEUE_T q; /* q head for enqueuing frames for dispatch */ + A_MUTEX_T lock; +}RXTID; + +typedef struct { + A_UINT32 num_into_aggr; /* hitting at the input of this module */ + A_UINT32 num_dups; /* duplicate */ + A_UINT32 num_oow; /* out of window */ + A_UINT32 num_mpdu; /* single payload 802.3/802.11 frame */ + A_UINT32 num_amsdu; /* AMSDU */ + A_UINT32 num_delivered; /* frames delivered to IP stack */ + A_UINT32 num_timeouts; /* num of timeouts, during which frames delivered */ + A_UINT32 num_hole; /* frame not present, when window moved over */ + A_UINT32 num_bar; /* num of resets of seq_num, via BAR */ +}RXTID_STATS; + +typedef struct { + void *dev; /* dev handle */ + A_UINT8 aggr_sz; /* config value of aggregation size */ + A_UINT8 timerScheduled; + A_TIMER timer; /* timer for returning held up pkts in re-order que */ + RXTID RxTid[NUM_OF_TIDS]; /* Per tid window */ +#ifdef AGGR_DEBUG + RXTID_STATS stat[NUM_OF_TIDS]; /* Tid based statistics */ +#endif +}AGGR_CONN_INFO; + +typedef struct { + RX_CALLBACK rx_fn; /* callback function to return frames; to upper layer */ + ALLOC_NETBUFS netbuf_allocator; /* OS netbuf alloc fn */ + A_NETBUF_QUEUE_T freeQ; /* pre-allocated buffers - for A_MSDU slicing */ +#ifdef AGGR_DEBUG + PACKET_LOG pkt_log; /* Log info of the packets */ +#endif +}AGGR_INFO; + +#endif /* __AGGR_RX_INTERNAL_H__ */ diff --git a/drivers/net/wireless/ar6003/host/reorder/makefile b/drivers/net/wireless/ar6003/host/reorder/makefile new file mode 100644 index 000000000000..1ba034c4900e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/reorder/makefile @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +!INCLUDE $(_MAKEENVROOT)\makefile.def + + + diff --git a/drivers/net/wireless/ar6003/host/reorder/rcv_aggr.c b/drivers/net/wireless/ar6003/host/reorder/rcv_aggr.c new file mode 100644 index 000000000000..047b06ed85c8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/reorder/rcv_aggr.c @@ -0,0 +1,749 @@ +/* + * + * Copyright (c) 2010 Atheros Communications Inc. + * All rights reserved. + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#ifdef ATH_AR6K_11N_SUPPORT + +#include +#include +#include +#include +#include +#include "ieee80211.h" +#include "pkt_log.h" +#include "aggr_recv_api.h" +#include "aggr_rx_internal.h" +#include "wmi.h" + +extern A_STATUS +wmi_dot3_2_dix(void *osbuf); + +static void +aggr_slice_amsdu(AGGR_CONN_INFO *p_aggr_conn, RXTID *rxtid, void **osbuf); + +static void +aggr_timeout(A_ATH_TIMER arg); + +static void +aggr_deque_frms(AGGR_CONN_INFO *p_aggr_conn, A_UINT8 tid, A_UINT16 seq_no, A_UINT8 order); + +static void +aggr_dispatch_frames(AGGR_CONN_INFO *p_aggr_conn, A_NETBUF_QUEUE_T *q); + +static void * +aggr_get_osbuf(void); + +static AGGR_INFO *p_aggr = NULL; + +#define QOS_PAD_LEN 2 + +A_UINT8 +aggr_init(ALLOC_NETBUFS netbuf_allocator, RX_CALLBACK fn) +{ + p_aggr = A_MALLOC(sizeof(AGGR_INFO)); + + if(p_aggr) { + /* Init data structures */ + A_MEMZERO(p_aggr, sizeof(AGGR_INFO)); + A_NETBUF_QUEUE_INIT(&p_aggr->freeQ); + p_aggr->rx_fn = fn; + p_aggr->netbuf_allocator = netbuf_allocator; + p_aggr->netbuf_allocator(&p_aggr->freeQ, AGGR_NUM_OF_FREE_NETBUFS); + return A_OK; + } + + A_PRINTF("Failed to allocate memory for aggr_node\n"); + return ((A_UINT8)A_ERROR); +} + +void * +aggr_init_conn(void) +{ + AGGR_CONN_INFO *p_aggr_conn = NULL; + RXTID *rxtid; + A_UINT8 i; + + do { + p_aggr_conn = A_MALLOC(sizeof(AGGR_CONN_INFO)); + if(!p_aggr_conn) { + A_PRINTF("Failed to allocate memory for aggr_node_conn \n"); + break; + } + + /* Init timer and data structures */ + A_MEMZERO(p_aggr_conn, sizeof(AGGR_CONN_INFO)); + p_aggr_conn->aggr_sz = AGGR_SZ_DEFAULT; + A_INIT_TIMER(&p_aggr_conn->timer, aggr_timeout, p_aggr_conn); + p_aggr_conn->timerScheduled = FALSE; + + for(i = 0; i < NUM_OF_TIDS; i++) { + rxtid = AGGR_GET_RXTID(p_aggr_conn, i); + rxtid->aggr = FALSE; + rxtid->progress = FALSE; + rxtid->timerMon = FALSE; + A_NETBUF_QUEUE_INIT(&rxtid->q); + A_MUTEX_INIT(&rxtid->lock); + } + }while(FALSE); + + return (p_aggr_conn); +} + +/* utility function to clear rx hold_q for a tid */ +static void +aggr_delete_tid_state(AGGR_CONN_INFO *p_aggr_conn, A_UINT8 tid) +{ + RXTID *rxtid; + + A_ASSERT(tid < NUM_OF_TIDS && p_aggr_conn); + if (!(tid < NUM_OF_TIDS && p_aggr)) { + return; /* in case panic_on_assert==0 */ + } + rxtid = AGGR_GET_RXTID(p_aggr_conn, tid); + if(rxtid->aggr) { + aggr_deque_frms(p_aggr_conn, tid, 0, ALL_SEQNO); + } + + rxtid->aggr = FALSE; + rxtid->progress = FALSE; + rxtid->timerMon = FALSE; + rxtid->win_sz = 0; + rxtid->seq_next = 0; + rxtid->hold_q_sz = 0; + + if(rxtid->hold_q) { + A_FREE(rxtid->hold_q); + rxtid->hold_q = NULL; + } + +#ifdef AGGR_DEBUG + { + RXTID_STATS *stats; + stats = AGGR_GET_RXTID_STATS(p_aggr_conn, tid); + A_MEMZERO(stats, sizeof(RXTID_STATS)); + } +#endif + +} + +void +aggr_module_destroy(void) +{ + if(p_aggr) { + /* free the freeQ and its contents*/ + while(A_NETBUF_QUEUE_SIZE(&p_aggr->freeQ)) { + A_NETBUF_FREE(A_NETBUF_DEQUEUE(&p_aggr->freeQ)); + } + A_FREE(p_aggr); + p_aggr = NULL; + } +} + +void +aggr_module_destroy_timers(void *cntxt) +{ + + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + + if(p_aggr_conn) { + if(p_aggr_conn->timerScheduled) { + A_UNTIMEOUT(&p_aggr_conn->timer); + p_aggr_conn->timerScheduled = FALSE; + } + + A_DELETE_TIMER (&p_aggr_conn->timer); + } +} + +void +aggr_module_destroy_conn(void *cntxt) +{ + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + RXTID *rxtid; + A_UINT8 i, k; + A_ASSERT(p_aggr_conn); + + if(p_aggr_conn) { + if(p_aggr_conn->timerScheduled) { + A_UNTIMEOUT(&p_aggr_conn->timer); + p_aggr_conn->timerScheduled = FALSE; + } + + A_DELETE_TIMER (&p_aggr_conn->timer); + + for(i = 0; i < NUM_OF_TIDS; i++) { + rxtid = AGGR_GET_RXTID(p_aggr_conn, i); + /* Free the hold q contents and hold_q*/ + if(rxtid->hold_q) { + for(k = 0; k< rxtid->hold_q_sz; k++) { + if(rxtid->hold_q[k].osbuf) { + A_NETBUF_FREE(rxtid->hold_q[k].osbuf); + } + } + A_FREE(rxtid->hold_q); + rxtid->hold_q = NULL; + } + /* Free the dispatch q contents*/ + while(A_NETBUF_QUEUE_SIZE(&rxtid->q)) { + A_NETBUF_FREE(A_NETBUF_DEQUEUE(&rxtid->q)); + } + if (A_IS_MUTEX_VALID(&rxtid->lock)) { + A_MUTEX_DELETE(&rxtid->lock); + } + } + A_FREE(p_aggr_conn); + p_aggr_conn = NULL; + } +} + +void +aggr_process_bar(void *cntxt, A_UINT8 tid, A_UINT16 seq_no) +{ + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + + A_ASSERT(p_aggr_conn); + +#ifdef AGGR_DEBUG + { + RXTID_STATS *stats; + stats = AGGR_GET_RXTID_STATS(p_aggr_conn, tid); + stats->num_bar++; + } +#endif + + aggr_deque_frms(p_aggr_conn, tid, seq_no, ALL_SEQNO); +} + + +void +aggr_recv_addba_req_evt(void *cntxt, A_UINT8 tid, A_UINT16 seq_no, A_UINT8 win_sz) +{ + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + RXTID *rxtid; + + A_ASSERT(p_aggr_conn); + rxtid = AGGR_GET_RXTID(p_aggr_conn, tid); + + if(rxtid->aggr) { + /* Just go and deliver all the frames up from this + * queue, as if we got DELBA and re-initialize the queue + */ + aggr_delete_tid_state(p_aggr_conn, tid); + } + + rxtid->seq_next = seq_no; + /* create these queues, only upon receiving of ADDBA for a + * tid, reducing memory requirement + */ + rxtid->hold_q = A_MALLOC(HOLD_Q_SZ(win_sz)); + if((rxtid->hold_q == NULL)) { + A_PRINTF("Failed to allocate memory, tid = %d\n", tid); + A_ASSERT(0); + return; /* in case panic_on_assert==0 */ + } + A_MEMZERO(rxtid->hold_q, HOLD_Q_SZ(win_sz)); + + /* Update rxtid for the window sz */ + rxtid->win_sz = win_sz; + /* hold_q_sz inicates the depth of holding q - which is + * a factor of win_sz. Compute once, as it will be used often + */ + rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz); + /* There should be no frames on q - even when second ADDBA comes in. + * If aggr was previously ON on this tid, we would have cleaned up + * the q + */ + if(A_NETBUF_QUEUE_SIZE(&rxtid->q) != 0) { + A_PRINTF("ERROR: Frames still on queue ?\n"); + A_ASSERT(0); + } + + rxtid->aggr = TRUE; +} + +void +aggr_recv_delba_req_evt(void *cntxt, A_UINT8 tid) +{ + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + RXTID *rxtid; + + A_ASSERT(p_aggr_conn); + + rxtid = AGGR_GET_RXTID(p_aggr_conn, tid); + + if(rxtid->aggr) { + aggr_delete_tid_state(p_aggr_conn, tid); + } +} + +static void +aggr_deque_frms(AGGR_CONN_INFO *p_aggr_conn, A_UINT8 tid, A_UINT16 seq_no, A_UINT8 order) +{ + RXTID *rxtid; + OSBUF_HOLD_Q *node; + A_UINT16 idx, idx_end, seq_end; +#ifdef AGGR_DEBUG + RXTID_STATS *stats; +#endif + + A_ASSERT(p_aggr_conn); + rxtid = AGGR_GET_RXTID(p_aggr_conn, tid); +#ifdef AGGR_DEBUG + stats = AGGR_GET_RXTID_STATS(p_aggr_conn, tid); +#endif + + /* idx is absolute location for first frame */ + idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); + + /* idx_end is typically the last possible frame in the window, + * but changes to 'the' seq_no, when BAR comes. If seq_no + * is non-zero, we will go up to that and stop. + * Note: last seq no in current window will occupy the same + * index position as index that is just previous to start. + * An imp point : if win_sz is 7, for seq_no space of 4095, + * then, there would be holes when sequence wrap around occurs. + * Target should judiciously choose the win_sz, based on + * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz + * 2, 4, 8, 16 win_sz works fine). + * We must deque from "idx" to "idx_end", including both. + */ + seq_end = (seq_no) ? seq_no : rxtid->seq_next; + idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz); + + /* Critical section begins */ + A_MUTEX_LOCK(&rxtid->lock); + do { + + node = &rxtid->hold_q[idx]; + + if((order == CONTIGUOUS_SEQNO) && (!node->osbuf)) + break; + + /* chain frames and deliver frames bcos: + * 1. either the frames are in order and window is contiguous, OR + * 2. we need to deque frames, irrespective of holes + */ + if(node->osbuf) { + if(node->is_amsdu) { + aggr_slice_amsdu(p_aggr_conn, rxtid, &node->osbuf); + } else { + A_NETBUF_ENQUEUE(&rxtid->q, node->osbuf); + } + node->osbuf = NULL; + } +#ifdef AGGR_DEBUG + else { + stats->num_hole++; + } +#endif + /* window is moving */ + rxtid->seq_next = IEEE80211_NEXT_SEQ_NO(rxtid->seq_next); + idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); + } while(idx != idx_end); + /* Critical section ends */ + A_MUTEX_UNLOCK(&rxtid->lock); + +#ifdef AGGR_DEBUG + stats->num_delivered += A_NETBUF_QUEUE_SIZE(&rxtid->q); +#endif + aggr_dispatch_frames(p_aggr_conn, &rxtid->q); +} + +static void * +aggr_get_osbuf(void) +{ + void *buf = NULL; + + /* Starving for buffers? get more from OS + * check for low netbuffers( < 1/4 AGGR_NUM_OF_FREE_NETBUFS) : + * re-allocate bufs if so + * allocate a free buf from freeQ + */ + if (A_NETBUF_QUEUE_SIZE(&p_aggr->freeQ) < (AGGR_NUM_OF_FREE_NETBUFS >> 2)) { + p_aggr->netbuf_allocator(&p_aggr->freeQ, AGGR_NUM_OF_FREE_NETBUFS); + } + + if (A_NETBUF_QUEUE_SIZE(&p_aggr->freeQ)) { + buf = A_NETBUF_DEQUEUE(&p_aggr->freeQ); + } + + return buf; +} + + +static void +aggr_slice_amsdu(AGGR_CONN_INFO *p_aggr_conn, RXTID *rxtid, void **osbuf) +{ + void *new_buf; + A_UINT16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len; + A_UINT8 *framep; + + + /* Frame format at this point: + * [DIX hdr | 802.3 | 802.3 | ... | 802.3] + * + * Strip the DIX header. + * Iterate through the osbuf and do: + * grab a free netbuf from freeQ + * find the start and end of a frame + * copy it to netbuf(Vista can do better here) + * convert all msdu's(802.3) frames to upper layer format - os routine + * -for now lets convert from 802.3 to dix + * enque this to dispatch q of tid + * repeat + * free the osbuf - to OS. It's been sliced. + */ + /* Frame format in native wifi path: + * [802.11 hdr | 802.3 | 802.3 |...|802.3] + * Save a pointer to the start of 802.11 Hdr and Strip the 802.11 hdr + * Iterate through the osbuf and do: + * grab a free netbuf from freeQ + * Find the start and end of the frame + * Copy the dot 11 header,followed by the payload data. 802.3 hdr in the + individual msdu must not be copied + * repeat + * free the osbuf containing the A-MSDU. + */ + + + mac_hdr_len = sizeof(ATH_MAC_HDR); + + framep = A_NETBUF_DATA(*osbuf) + mac_hdr_len; + amsdu_len = A_NETBUF_LEN(*osbuf) - mac_hdr_len; + + while(amsdu_len > mac_hdr_len) { + /* Begin of a 802.3 frame */ + payload_8023_len = A_BE2CPU16(((ATH_MAC_HDR *)framep)->typeOrLen); +#define MAX_MSDU_SUBFRAME_PAYLOAD_LEN 1508 +#define MIN_MSDU_SUBFRAME_PAYLOAD_LEN 46 + if(payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN || payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) { + A_PRINTF("802.3 AMSDU frame bound check failed. len %d\n", payload_8023_len); + break; + } + frame_8023_len = payload_8023_len + mac_hdr_len; + new_buf = aggr_get_osbuf(); + if(new_buf == NULL) { + A_PRINTF("No buffer available \n"); + break; + } + + A_MEMCPY(A_NETBUF_DATA(new_buf), framep, frame_8023_len); + A_NETBUF_PUT(new_buf, frame_8023_len); + if (wmi_dot3_2_dix(new_buf) != A_OK) { + A_PRINTF("dot3_2_dix err..\n"); + A_NETBUF_FREE(new_buf); + break; + } + + + A_NETBUF_ENQUEUE(&rxtid->q, new_buf); + + /* Is this the last subframe within this aggregate ? */ + if ((amsdu_len - frame_8023_len) == 0) { + break; + } + + /* Add the length of A-MSDU subframe padding bytes - + * Round to nearest word. + */ + frame_8023_len = ((frame_8023_len + 3) & ~3); + + framep += frame_8023_len; + amsdu_len -= frame_8023_len; + } + + A_NETBUF_FREE(*osbuf); + *osbuf = NULL; +} + +void +aggr_process_recv_frm(void *cntxt, A_UINT8 tid, A_UINT16 seq_no, A_BOOL is_amsdu, void **osbuf) +{ + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + RXTID *rxtid; +#ifdef AGGR_DEBUG + RXTID_STATS *stats; +#endif + A_UINT16 idx, st, cur, end; + OSBUF_HOLD_Q *node; + + A_ASSERT(p_aggr_conn); + A_ASSERT(tid < NUM_OF_TIDS); + + rxtid = AGGR_GET_RXTID(p_aggr_conn, tid); +#ifdef AGGR_DEBUG + stats = AGGR_GET_RXTID_STATS(p_aggr_conn, tid); + stats->num_into_aggr++; +#endif + + if(!rxtid->aggr) { + if(is_amsdu) { + aggr_slice_amsdu(p_aggr_conn, rxtid, osbuf); +#ifdef AGGR_DEBUG + stats->num_amsdu++; +#endif + aggr_dispatch_frames(p_aggr_conn, &rxtid->q); + } + return; + } + + /* Check the incoming sequence no, if it's in the window */ + st = rxtid->seq_next; + cur = seq_no; + end = (st + rxtid->hold_q_sz-1) & IEEE80211_MAX_SEQ_NO; + +#ifdef AGGR_DEBUG + { + A_UINT16 *log_idx; + PACKET_LOG *log; + + /* Log the pkt info for future analysis */ + log = &p_aggr->pkt_log; + log_idx = &log->last_idx; + log->info[*log_idx].cur = cur; + log->info[*log_idx].st = st; + log->info[*log_idx].end = end; + *log_idx = IEEE80211_NEXT_SEQ_NO(*log_idx); + } +#endif + + if(((st < end) && (cur < st || cur > end)) || + ((st > end) && (cur > end) && (cur < st))) { + /* the cur frame is outside the window. Since we know + * our target would not do this without reason it must + * be assumed that the window has moved for some valid reason. + * Therefore, we dequeue all frames and start fresh. + */ + A_UINT16 extended_end; + + extended_end = (end + rxtid->hold_q_sz-1) & IEEE80211_MAX_SEQ_NO; + + if(((end < extended_end) && (cur < end || cur > extended_end)) || + ((end > extended_end) && (cur > extended_end) && (cur < end))) { + // dequeue all frames in queue and shift window to new frame + aggr_deque_frms(p_aggr_conn, tid, 0, ALL_SEQNO); + //set window start so that new frame is last frame in window + if(cur >= rxtid->hold_q_sz-1) { + rxtid->seq_next = cur - (rxtid->hold_q_sz-1); + }else{ + rxtid->seq_next = IEEE80211_MAX_SEQ_NO - (rxtid->hold_q_sz-2 - cur); + } + } else { + // dequeue only those frames that are outside the new shifted window + if(cur >= rxtid->hold_q_sz-1) { + st = cur - (rxtid->hold_q_sz-1); + }else{ + st = IEEE80211_MAX_SEQ_NO - (rxtid->hold_q_sz-2 - cur); + } + + aggr_deque_frms(p_aggr_conn, tid, st, ALL_SEQNO); + } +#ifdef AGGR_DEBUG + stats->num_oow++; +#endif + } + + idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz); + + /*enque the frame, in hold_q */ + node = &rxtid->hold_q[idx]; + + A_MUTEX_LOCK(&rxtid->lock); + if(node->osbuf) { + /* Is the cur frame duplicate or something beyond our + * window(hold_q -> which is 2x, already)? + * 1. Duplicate is easy - drop incoming frame. + * 2. Not falling in current sliding window. + * 2a. is the frame_seq_no preceding current tid_seq_no? + * -> drop the frame. perhaps sender did not get our ACK. + * this is taken care of above. + * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ); + * -> Taken care of it above, by moving window forward. + * + */ + A_NETBUF_FREE(node->osbuf); +#ifdef AGGR_DEBUG + stats->num_dups++; +#endif + } + + node->osbuf = *osbuf; + node->is_amsdu = is_amsdu; + node->seq_no = seq_no; +#ifdef AGGR_DEBUG + if(node->is_amsdu) { + stats->num_amsdu++; + } else { + stats->num_mpdu++; + } +#endif + A_MUTEX_UNLOCK(&rxtid->lock); + + *osbuf = NULL; + aggr_deque_frms(p_aggr_conn, tid, 0, CONTIGUOUS_SEQNO); + + if(p_aggr_conn->timerScheduled) { + rxtid->progress = TRUE; + }else{ + for(idx=0 ; idxhold_q_sz ; idx++) { + if(rxtid->hold_q[idx].osbuf) { + /* there is a frame in the queue and no timer so + * start a timer to ensure that the frame doesn't remain + * stuck forever. */ + p_aggr_conn->timerScheduled = TRUE; + A_TIMEOUT_MS(&p_aggr_conn->timer, AGGR_RX_TIMEOUT, 0); + rxtid->progress = FALSE; + rxtid->timerMon = TRUE; + break; + } + } + } +} + +/* + * aggr_reset_state -- Called when it is deemed necessary to clear the aggregate + * hold Q state. Examples include when a Connect event or disconnect event is + * received. + */ +void +aggr_reset_state(void *cntxt, void *dev) +{ + A_UINT8 tid; + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + + A_ASSERT(p_aggr_conn); + + p_aggr_conn->dev = dev; + for(tid=0 ; tidaggr == FALSE || + rxtid->timerMon == FALSE || + rxtid->progress == TRUE) { + continue; + } + // dequeue all frames in for this tid +#ifdef AGGR_DEBUG + stats->num_timeouts++; +#endif + A_PRINTF("TO: st %d end %d\n", rxtid->seq_next, ((rxtid->seq_next + rxtid->hold_q_sz-1) & IEEE80211_MAX_SEQ_NO)); + aggr_deque_frms(p_aggr_conn, i, 0, ALL_SEQNO); + } + + p_aggr_conn->timerScheduled = FALSE; + // determine whether a new timer should be started. + for(i = 0; i < NUM_OF_TIDS; i++) { + rxtid = AGGR_GET_RXTID(p_aggr_conn, i); + + if(rxtid->aggr == TRUE && rxtid->hold_q) { + for(j = 0 ; j < rxtid->hold_q_sz ; j++) + { + if(rxtid->hold_q[j].osbuf) + { + p_aggr_conn->timerScheduled = TRUE; + rxtid->timerMon = TRUE; + rxtid->progress = FALSE; + break; + } + } + + if(j >= rxtid->hold_q_sz) { + rxtid->timerMon = FALSE; + } + } + } + + if(p_aggr_conn->timerScheduled) { + /* Rearm the timer*/ + A_TIMEOUT_MS(&p_aggr_conn->timer, AGGR_RX_TIMEOUT, 0); + } + +} + +static void +aggr_dispatch_frames(AGGR_CONN_INFO *p_aggr_conn, A_NETBUF_QUEUE_T *q) +{ + void *osbuf; + + if(p_aggr_conn->dev == NULL) { + while(A_NETBUF_QUEUE_SIZE(q)) { + A_NETBUF_FREE(A_NETBUF_DEQUEUE(q)); + } + } + else { + while((osbuf = A_NETBUF_DEQUEUE(q))!= NULL) { + p_aggr->rx_fn(p_aggr_conn->dev, osbuf); + } + } +} + +void +aggr_dump_stats(void *cntxt, PACKET_LOG **log_buf) +{ +#ifdef AGGR_DEBUG + AGGR_CONN_INFO *p_aggr_conn = (AGGR_CONN_INFO *)cntxt; + RXTID *rxtid; + RXTID_STATS *stats; + A_UINT8 i; + + *log_buf = &p_aggr->pkt_log; + A_PRINTF("\n\n================================================\n"); + A_PRINTF("tid: num_into_aggr, dups, oow, mpdu, amsdu, delivered, timeouts, holes, bar, seq_next\n"); + for(i = 0; i < NUM_OF_TIDS; i++) { + stats = AGGR_GET_RXTID_STATS(p_aggr_conn, i); + rxtid = AGGR_GET_RXTID(p_aggr_conn, i); + A_PRINTF("%d: %d %d %d %d %d %d %d %d %d : %d\n", i, stats->num_into_aggr, stats->num_dups, + stats->num_oow, stats->num_mpdu, + stats->num_amsdu, stats->num_delivered, stats->num_timeouts, + stats->num_hole, stats->num_bar, + rxtid->seq_next); + } + A_PRINTF("================================================\n\n"); +#else + A_PRINTF("AGGR_DEBUG is not enabled\n"); +#endif +} + +#endif /* ATH_AR6K_11N_SUPPORT */ diff --git a/drivers/net/wireless/ar6003/host/tools/Android.mk b/drivers/net/wireless/ar6003/host/tools/Android.mk new file mode 100644 index 000000000000..b3c34c55204e --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/Android.mk @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + + +ifneq ($(TARGET_SIMULATOR),true) + include $(call all-subdir-makefiles) +endif diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android.mk b/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android.mk new file mode 100644 index 000000000000..2af8bc3c67b9 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android.mk @@ -0,0 +1,28 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +ifneq ($(TARGET_SIMULATOR),true) +ifeq ($(BOARD_HAVE_BLUETOOTH),true) + include $(call all-subdir-makefiles) +endif +endif diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android_Readme b/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android_Readme new file mode 100644 index 000000000000..0c5eb5b9dcfa --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/Android_Readme @@ -0,0 +1,7 @@ +# +# +# To generate the Android buildable files/directory +# execute the filter.sh script ONLY ONCE and move the +# whole athbtfilter directory to Android external +# directoy for compilation. +# \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Android.mk b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Android.mk new file mode 100644 index 000000000000..fc1882e904d6 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Android.mk @@ -0,0 +1,100 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +# +# link or copy whole olca driver into external/athwlan/olca/ +# + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +ifeq ($(BT_ALT_STACK),true) +# Define AR6K_PREBUILT_HCIUTILS_LIB:= true if you want to force to enable HCIUTILS +# Otherwise, we will try to load the hciutil.so dynamically to determinate whether we use hciutils or hci socket +# Uncomment the following if you want to use static library + +#AR6K_PREBUILT_HCIUTILS_LIB := true + +endif + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := abtfilt_bluez_dbus.c \ + abtfilt_core.c \ + abtfilt_main.c \ + abtfilt_utils.c \ + abtfilt_wlan.c \ + btfilter_action.c \ + btfilter_core.c + +ifeq ($(BT_ALT_STACK),true) +LOCAL_SRC_FILES += abtfilt_bluez_hciutils.c + +ifeq ($(AR6K_PREBUILT_HCIUTILS_LIB),true) +LOCAL_STATIC_LIBRARIES := hciutils +LOCAL_CFLAGS += -DSTATIC_LINK_HCILIBS +endif +AR6K_PREBUILT_HCIUTILS_LIB := + +else +LOCAL_CFLAGS += -DCONFIG_NO_HCILIBS +endif + +LOCAL_SHARED_LIBRARIES := \ + libdbus \ + libbluetooth \ + libcutils \ + libdl + +ifeq ($(AR6K_PREBUILT_HCIUTILS_LIB),true) +LOCAL_STATIC_LIBRARIES := hciutils +LOCAL_CFLAGS += -DSTATIC_LINK_HCILIBS +endif +AR6K_PREBUILT_HCIUTILS_LIB := + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/../../../include \ + $(LOCAL_PATH)/../../../tools/athbtfilter/bluez \ + $(LOCAL_PATH)/../../../../include \ + $(LOCAL_PATH)/../../../os/linux/include \ + $(LOCAL_PATH)/../../../btfilter \ + $(LOCAL_PATH)/../../.. \ + $(call include-path-for, dbus) \ + $(call include-path-for, bluez-libs) + +ifneq ($(PLATFORM_VERSION),$(filter $(PLATFORM_VERSION),1.5 1.6)) +LOCAL_C_INCLUDES += external/bluetooth/bluez/include/bluetooth external/bluetooth/bluez/lib/bluetooth +LOCAL_CFLAGS+=-DBLUEZ4_3 +else +LOCAL_C_INCLUDES += external/bluez/libs/include/bluetooth +endif + +LOCAL_CFLAGS+= \ + -DDBUS_COMPILATION -DABF_DEBUG + + +LOCAL_MODULE := abtfilt +LOCAL_MODULE_TAGS := debug eng optional +#LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) + +include $(BUILD_EXECUTABLE) diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Makefile b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Makefile new file mode 100644 index 000000000000..7d48c4cb5aaf --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/Makefile @@ -0,0 +1,96 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2008 Atheros Corporation. All rights reserved. +# +# The software source and binaries included in this development package are +# licensed, not sold. You, or your company, received the package under one +# or more license agreements. The rights granted to you are specifically +# listed in these license agreement(s). All other rights remain with Atheros +# Communications, Inc., its subsidiaries, or the respective owner including +# those listed on the included copyright notices. Distribution of any +# portion of this package must be in strict compliance with the license +# agreement(s) terms. +# +# +# +# Wifi driver for AR6002 +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +#USE_GLIB=1 +#USE_HCIUTILS=1 + +ifdef V210 +V210_DIR=/tftpboot/ubuntu-taiwan +endif + +ifdef V210 +CC= $(ATH_CROSS_COMPILE_TYPE)gcc +LD= $(ATH_CROSS_COMPILE_TYPE)ld +else +CC= $(ATH_CROSSS_COMPILE_TYPE)gcc +LD= $(ATH_CROSSS_COMPILE_TYPE)ld +endif +SOURCES=abtfilt_main.c \ + abtfilt_wlan.c \ + abtfilt_core.c \ + abtfilt_utils.c \ + btfilter_action.c\ + btfilter_core.c + +INCLUDES= -I../../../include \ + -I../../../os/linux/include \ + -I../../../../include \ + -I../../../ \ + -I$(V210_DIR)/usr/include/dbus-1.0/ \ + -I$(V210_DIR)/usr/lib/dbus-1.0/include \ + -I$(V210_DIR)/usr/include/bluetooth \ + +CFLAGS= -Wall -g -DABF_DEBUG +#LIBS= -ldbus-1 -lpthread -lbtfilt -lrt -lbluetooth +LIBS= -ldbus-1 -lpthread -lrt -lbluetooth + +ifdef USE_HCIUTILS +SOURCES += abtfilt_bluez_hciutils.c +LIBS += -ldl +else +CFLAGS += -DCONFIG_NO_HCILIBS +endif + +ifdef USE_GLIB +SOURCES += abtfilt_bluez_dbus_glib.c + +LIBS += -lgobject-2.0 -lglib-2.0 -ldbus-glib-1 + +INCLUDES += -I/usr/include/glib-2.0 \ + -I/usr/lib/glib-2.0/include \ + +OBJECTS= $(SOURCES:.c=.o) + +else +SOURCES += abtfilt_bluez_dbus.c + +OBJECTS= $(SOURCES:.c=.o) +endif + + + +#LDFLAGS= -L$(WORKAREA)/host/btfilter +#copy libbluetooth.so from /tftpboot/ubuntu-taiwan/usr/lib to /tftpboot/ubuntu-taiwan/lib [for V210] +ifdef V210 +LDFLAGS= -L/tftpboot/ubuntu-taiwan/lib +endif +FILTERAPP= abtfilt + +all: $(OBJECTS) + $(CC) -o $(FILTERAPP) $(OBJECTS) $(LDFLAGS) $(LIBS) + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ + +clean: + rm -f $(FILTERAPP) $(OBJECTS) diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.c new file mode 100644 index 000000000000..be7b6d826d30 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.c @@ -0,0 +1,2634 @@ + +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +/* + * Bluetooth Filter - BT module + * + */ + +#include "abtfilt_bluez_dbus.h" + +#undef HCI_INQUIRY +#include +#include +#include +#include + +/* Definitions */ + +#define BLUEZ_NAME "org.bluez" +#define ADAPTER_INTERFACE "org.bluez.Adapter" +#define MANAGER_INTERFACE "org.bluez.Manager" + +#ifndef ANDROID +/* This should be undef'ed if compiled at FC9 using BlueZ 3.x */ +#define BLUEZ4_3 +#endif /* ANDROID */ + +#define ABTH_MAX_CONNECTIONS 16 + +#ifdef BLUEZ4_3 + +#define BLUEZ_PATH "/" +#define AUDIO_MANAGER_PATH "/org/bluez/" +#define AUDIO_MANAGER_INTERFACE "org.bluez" +#define AUDIO_SINK_INTERFACE "org.bluez.AudioSink" +#define AUDIO_SOURCE_INTERFACE "org.bluez.AudioSource" +#define AUDIO_HEADSET_INTERFACE "org.bluez.Headset" +#define AUDIO_GATEWAY_INTERFACE "org.bluez.Gateway" +#define AUDIO_DEVICE_INTERFACE "org.bluez.Device" + +#else + +#define BLUEZ_PATH "/org/bluez" +#define AUDIO_MANAGER_PATH "/org/bluez/audio" +#define AUDIO_SINK_INTERFACE "org.bluez.audio.Sink" +#define AUDIO_SOURCE_INTERFACE "org.bluez.audio.Source" +#define AUDIO_HEADSET_INTERFACE "org.bluez.audio.Headset" +#define AUDIO_GATEWAY_INTERFACE "org.bluez.audio.Gateway" +#define AUDIO_MANAGER_INTERFACE "org.bluez.audio.Manager" +#define AUDIO_DEVICE_INTERFACE "org.bluez.audio.Device" +#endif + +#define INVALID_INTERFACE NULL + +#define BTEV_GET_BT_CONN_LINK_TYPE(p) ((p)[9]) +#define BTEV_GET_TRANS_INTERVAL(p) ((p)[10]) +#define BTEV_GET_RETRANS_INTERVAL(p) ((p)[11]) +#define BTEV_GET_RX_PKT_LEN(p) ((A_UINT16)((p)[12]) | (((A_UINT16)((p)[13])) << 8)) +#define BTEV_GET_TX_PKT_LEN(p) ((A_UINT16)((p)[14]) | (((A_UINT16)((p)[15])) << 8)) +#define BTEV_CMD_COMPLETE_GET_OPCODE(p) ((A_UINT16)((p)[1]) | (((A_UINT16)((p)[2])) << 8)) +#define BTEV_CMD_COMPLETE_GET_STATUS(p) ((p)[3]) + +#define DBUS_METHOD_CALL_TIMEOUT (-1) /* no timeout */ +#define DBUS_MESSAGE_RECV_TIMEOUT (-1) /* no timeout */ + +#define USE_DBUS_FOR_HEADSET_PROFILE(pInfo) (!((pInfo)->Flags & ABF_USE_HCI_FILTER_FOR_HEADSET_PROFILE)) +#define MAKE_BTSTATE_MASK(state) (1 << (state)) + +typedef enum { + ARG_INVALID = 0, + ARG_NONE, + ARG_STRING, +} BT_CB_TYPE; + +typedef struct _BT_NOTIFICATION_CONFIG_PARAMS { + const char *signal_name; + const char *interface; + BT_CB_TYPE arg; +} BT_NOTIFICATION_CONFIG_PARAMS; + + +ABF_BT_INFO * g_pAbfBtInfo = NULL; + +static BT_NOTIFICATION_CONFIG_PARAMS g_NotificationConfig[BT_EVENTS_NUM_MAX] = +{ + /* BT_ADAPTER_ADDED */ + {"AdapterAdded", MANAGER_INTERFACE, ARG_STRING}, + /* BT_ADAPTER_REMOVED */ + {"AdapterRemoved", MANAGER_INTERFACE, ARG_STRING}, + /* DEVICE_DISCOVERY_STARTED */ + {"DiscoveryStarted", ADAPTER_INTERFACE, ARG_NONE}, + /* DEVICE_DISCOVERY_FINISHED */ + {"DiscoveryCompleted", ADAPTER_INTERFACE, ARG_NONE}, + /* REMOTE_DEVICE_CONNECTED */ + {"RemoteDeviceConnected", ADAPTER_INTERFACE, ARG_STRING}, + /* REMOTE_DEVICE_DISCONNECTED */ + {"RemoteDeviceDisconnected", ADAPTER_INTERFACE, ARG_STRING}, + /* AUDIO_DEVICE_ADDED */ + {"DeviceCreated", AUDIO_MANAGER_INTERFACE, ARG_STRING}, + /* AUDIO_DEVICE_REMOVED */ + {"DeviceRemoved", AUDIO_MANAGER_INTERFACE, ARG_STRING}, + /* AUDIO_HEADSET_CONNECTED */ + {"Connected", AUDIO_HEADSET_INTERFACE, ARG_NONE}, + /* AUDIO_HEADSET_DISCONNECTED */ + {"Disconnected", AUDIO_HEADSET_INTERFACE, ARG_NONE}, + /* AUDIO_HEADSET_STREAM_STARTED */ + {"Playing", AUDIO_HEADSET_INTERFACE, ARG_NONE}, + /* AUDIO_HEADSET_STREAM_STOPPED */ + {"Stopped", AUDIO_HEADSET_INTERFACE, ARG_NONE}, + /* AUDIO_GATEWAY_CONNECTED */ + {NULL, INVALID_INTERFACE, ARG_INVALID}, + /* AUDIO_GATEWAY_DISCONNECTED */ + {NULL, INVALID_INTERFACE, ARG_INVALID}, + /* AUDIO_SINK_CONNECTED */ + {"Connected", AUDIO_SINK_INTERFACE, ARG_NONE}, + /* AUDIO_SINK_DISCONNECTED */ + {"Disconnected", AUDIO_SINK_INTERFACE, ARG_NONE}, + /* AUDIO_SINK_STREAM_STARTED */ + {"Playing", AUDIO_SINK_INTERFACE, ARG_NONE}, + /* AUDIO_SINK_STREAM_STOPPED */ + {"Stopped", AUDIO_SINK_INTERFACE, ARG_NONE}, + /* AUDIO_SOURCE_CONNECTED */ + {NULL, INVALID_INTERFACE, ARG_INVALID}, + /* AUDIO_SOURCE_DISCONNECTED */ + {NULL, INVALID_INTERFACE, ARG_INVALID}, +}; + +typedef struct { + char *str; + unsigned int val; +} hci_map; + +static const hci_map ver_map[] = { + { "1.0b", 0x00 }, + { "1.1", 0x01 }, + { "1.2", 0x02 }, + { "2.0", 0x03 }, + { "2.1", 0x04 }, + { NULL } +}; + +/* Function Prototypes */ +static void BtAdapterAdded(const char *string, + void * user_data); +static void BtAdapterRemoved(const char *string, + void * user_data); +static A_STATUS AcquireBtAdapter(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseBTAdapter(ABF_BT_INFO *pAbfBtInfo); +static void *BtEventThread(void *arg); +static void RegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, + BT_STACK_EVENT event, BT_EVENT_HANDLER handler); +static void DeRegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event); +static A_STATUS GetAdapterInfo(ABF_BT_INFO *pAbfBtInfo); +static void RemoteDeviceDisconnected(const char *string, + void * user_data); +static void RemoteDeviceConnected(const char *string, + void * user_data); +static void AudioDeviceAdded(const char *string, + void * user_data); +static void AudioDeviceRemoved(const char *string, + void * user_data); +static void DeviceDiscoveryStarted(void *arg, void * user_data); +static void DeviceDiscoveryFinished(void *arg, void * user_data); +static void AudioHeadsetConnected(void *arg, void * user_data); +static void AudioHeadsetDisconnected(void *arg, void * user_data); +static void AudioHeadsetStreamStarted(void *arg, void * user_data); +static void AudioHeadsetStreamStopped(void *arg, void * user_data); +static void AudioGatewayConnected(void *arg, void * user_data); +static void AudioGatewayDisconnected(void *arg, void * user_data); +static void AudioSinkConnected(void *arg, void * user_data); +static void AudioSinkDisconnected(void *arg, void * user_data); +static void AudioSinkStreamStarted(void *arg, void * user_data); +static void AudioSinkStreamStopped(void *arg, void * user_data); +static void AudioSourceConnected(void *arg, void * user_data); +static void AudioSourceDisconnected(void *arg, void * user_data); +static A_STATUS CheckAndAcquireDefaultAdapter(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseDefaultAdapter(ABF_BT_INFO *pAbfBtInfo); +static void AcquireDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo); +static void GetBtAudioConnectionProperties(ABF_BT_INFO *pAbfBtInfo, + ATHBT_STATE_INDICATION Indication); +static void GetBtAudioDeviceProperties(ABF_BT_INFO *pAbfBtInfo); + +static A_STATUS SetupHciEventFilter(ABF_BT_INFO *pAbfBtInfo); +static void CleanupHciEventFilter(ABF_BT_INFO *pAbfBtInfo); +static void CheckHciEventFilter(ABF_BT_INFO *pAbfBtInfo); + +static A_STATUS IssueHCICommand(ABF_BT_INFO *pAbfBtInfo, + A_UINT16 OpCode, + A_UCHAR *pCmdData, + int CmdLength, + int EventRecvTimeoutMS, + A_UCHAR *pEventBuffer, + int MaxLength, + A_UCHAR **ppEventPtr, + int *pEventLength); + + /* method call that involves only 1 input string (can be NULL) and/or 1 output string */ +static A_STATUS DoMethodCall(DBusConnection *Bus, + char *BusName, + char *Path, + char *Interface, + char *Method, + void *InputArg, + int InputType, + int MaxInLength, + void *OutputArg, + int OutputType, + int MaxOutLength); + +static A_STATUS ProcessDBusMessage(ABF_BT_INFO *pAbfBtInfo, DBusMessage *Msg); +static A_STATUS CheckRemoteDeviceEDRCapable(ABF_BT_INFO *pAbfBtInfo, A_BOOL *pEDRCapable); + +/* New function to check Remote LMP version */ +static A_STATUS GetRemoteDeviceLMPVersion(ABF_BT_INFO *pAbfBtInfo); + +static void *HCIFilterThread(void *arg); + +A_BOOL g_AppShutdown = FALSE; + + +#define ForgetRemoteAudioDevice(pA) \ +{ \ + A_MEMZERO((pA)->DefaultRemoteAudioDeviceAddress,sizeof((pA)->DefaultRemoteAudioDeviceAddress)); \ + (pA)->DefaultRemoteAudioDevicePropsValid = FALSE; \ +} + +/* APIs exported to other modules */ +A_STATUS +Abf_BtStackNotificationInit(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 Flags) +{ + A_STATUS status = A_ERROR; + ATHBT_FILTER_INFO *pInfo; + ABF_BT_INFO *pAbfBtInfo; + DBusError error; + + pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + if (pInfo->pBtInfo) { + return A_OK; + } + + if (g_AppShutdown) { + A_ERR (" App was already shutdown cannot call Abf_BtStackNotificationInit again!!!"); + return A_ERROR; + } + + pAbfBtInfo = (ABF_BT_INFO *)A_MALLOC(sizeof(ABF_BT_INFO)); + A_MEMZERO(pAbfBtInfo,sizeof(ABF_BT_INFO)); + + A_MUTEX_INIT(&pAbfBtInfo->hWaitEventLock); + A_MEMZERO(pAbfBtInfo, sizeof(ABF_BT_INFO)); + + pInfo->Flags = Flags; + + if (pInfo->Flags & ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION) { + A_INFO("AFH Classification Command will be issued on WLAN connect/disconnect \n"); + } + + if (pInfo->Flags & ABF_USE_HCI_FILTER_FOR_HEADSET_PROFILE) { + A_INFO("Headset Profile notifications will use HCI filter instead of DBUS \n"); + +#ifdef BLUEZ4_3 + /* We don't want to ignore INQUIRY message to implement "DiscoveryStarted" (deprecated in BlueZ 4.x) */ + pInfo->FilterCore.StateFilterIgnore = MAKE_BTSTATE_MASK(ATH_BT_A2DP); //| MAKE_BTSTATE_MASK(ATH_BT_CONNECT); +#else + /* ignore certain state detections that we can handle through dbus */ + pInfo->FilterCore.StateFilterIgnore = MAKE_BTSTATE_MASK(ATH_BT_CONNECT) | + MAKE_BTSTATE_MASK(ATH_BT_INQUIRY) | + MAKE_BTSTATE_MASK(ATH_BT_A2DP); +#endif + + } + + pAbfBtInfo->AdapterAvailable = FALSE; + pAbfBtInfo->pInfo = pInfo; + pAbfBtInfo->HCIEventListenerSocket = -1; + pInfo->pBtInfo = pAbfBtInfo; + + dbus_error_init(&error); + + do { + + pAbfBtInfo->Bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (NULL == pAbfBtInfo->Bus ) { + A_ERR("[%s] Couldn't connect to system bus: %s\n", + __FUNCTION__, error.message); + break; + } + + /* check for default adapter at startup */ + CheckAndAcquireDefaultAdapter(pAbfBtInfo); + RegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_ADDED, (BT_EVENT_HANDLER)BtAdapterAdded); + RegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_REMOVED, (BT_EVENT_HANDLER)BtAdapterRemoved); + + if(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING) { + Abf_RegisterToHciLib(pAbfBtInfo); + } + + /* Spawn a thread which will be used to process events from dbus */ + status = A_TASK_CREATE(&pInfo->hBtThread, BtEventThread, pAbfBtInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to spawn a BT thread\n", __FUNCTION__); + break; + } + + pAbfBtInfo->ThreadCreated = TRUE; + status = A_OK; + + } while (FALSE); + + dbus_error_free(&error); + + if (A_FAILED(status)) { + Abf_BtStackNotificationDeInit(pInstance); + } + A_INFO("BT Stack Notification init complete\n"); + + return status; +} + +void +Abf_BtStackNotificationDeInit(ATH_BT_FILTER_INSTANCE *pInstance) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_BT_INFO *pAbfBtInfo = pInfo->pBtInfo; + + g_AppShutdown = TRUE; + + if (!pAbfBtInfo) return; + + /* acquire lock to sync with thread */ + A_MUTEX_LOCK(&pAbfBtInfo->hWaitEventLock); + + if (pAbfBtInfo->Bus != NULL) { + A_INFO("Cleaning up dbus connection ... \n"); + + /* NOTE: there is really no need to de-register callbacks and cleanup state since we + * are exiting the application and cleaning up the bus connection. When the dbus conneciont + * is cleaned up, all signal registrations are cleanedup by the dbus library anyways. + * + DeRegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_ADDED); + DeRegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_REMOVED); + ReleaseDefaultAdapter(pAbfBtInfo); + */ + + /* Release the system bus */ + dbus_connection_unref(pAbfBtInfo->Bus); + pAbfBtInfo->Bus = NULL; + } + + Abf_UnRegisterToHciLib(pAbfBtInfo); + + /* Flush all the BT actions from the filter core TODO */ + + /* Free the remaining resources */ + pAbfBtInfo->AdapterAvailable = FALSE; + pInfo->pBtInfo = NULL; + A_MUTEX_DEINIT(&pAbfBtInfo->hWaitEventLock); + A_MEMZERO(pAbfBtInfo, sizeof(ABF_BT_INFO)); + A_FREE(pAbfBtInfo); + + A_INFO("BT Stack Notification de-init complete\n"); +} + +static void * +BtEventThread(void *arg) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)arg; + DBusMessage *msg = NULL; + A_BOOL error = FALSE; + + g_pAbfBtInfo = (ABF_BT_INFO *) arg; + A_INFO("Starting the BT Event Handler task\n"); + + A_INFO("Entering DBus Message loop \n"); + + Abf_WlanGetSleepState(pAbfBtInfo->pInfo); + + while (!g_AppShutdown && !error) { + + dbus_connection_read_write(pAbfBtInfo->Bus, DBUS_MESSAGE_RECV_TIMEOUT); + + if (g_AppShutdown) { + break; + } + /* while we retrieve and process messages we don't want this thread killed */ + A_MUTEX_LOCK(&pAbfBtInfo->hWaitEventLock); + + while (!error) { + msg = dbus_connection_pop_message(pAbfBtInfo->Bus); + if (NULL == msg) { + break; + } + A_DEBUG(" Got DBus Message ... \n"); + if (A_FAILED(ProcessDBusMessage(pAbfBtInfo, msg))) { + error = TRUE; + } + dbus_message_unref(msg); + msg = NULL; + } + + A_MUTEX_UNLOCK(&pAbfBtInfo->hWaitEventLock); + + } + + A_INFO("Leaving DBus Message loop \n"); + A_INFO("Leaving the BT Event Handler task\n"); + + return NULL; +} + +static A_STATUS +CheckAndAcquireDefaultAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status = A_OK; + + do { + + if (pAbfBtInfo->AdapterAvailable) { + /* already available */ + break; + } + + /* acquire the adapter */ + status = AcquireBtAdapter(pAbfBtInfo); + + } while (FALSE); + + return status; +} + +static void ReleaseDefaultAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + + if (pAbfBtInfo->AdapterAvailable) { + /* Release the BT adapter */ + ReleaseBTAdapter(pAbfBtInfo); + A_INFO("[%s] BT Adapter Removed\n",pAbfBtInfo->HCI_AdapterName); + } + + A_MEMZERO(pAbfBtInfo->HCI_AdapterName, sizeof(pAbfBtInfo->HCI_AdapterName)); + +} +/* Event Notifications */ +static void +BtAdapterAdded(const char *string, void * user_data) +{ + A_DEBUG("BtAdapterAdded (%s) Callback ... \n", (string != NULL) ? string : "UNKNOWN"); + + /* BUG!!!, the BtAdapterAdded callback is indicated too early by the BT service, on some systems + * the method call to "DefaultAdapter" through the Manager interface will fail because no + * default adapter exist yet even though this callback was indicated (there should be a default) + * + * Workaround is to delay before acquiring the default adapter. + * Acquiring the BT adapter should not be very infrequent though. + * + * */ + sleep(5); + CheckAndAcquireDefaultAdapter((ABF_BT_INFO *)user_data); +} + + +static void +BtAdapterRemoved(const char *string, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("BtAdapterRemoved (%s) Callback ... \n", (string != NULL) ? string : "UNKNOWN"); + + if (!pAbfBtInfo->AdapterAvailable) return; + + if ((string != NULL) && strcmp(string,pAbfBtInfo->HCI_AdapterName) == 0) { + /* the adapter we are watching has been removed */ + ReleaseDefaultAdapter(pAbfBtInfo); + } + +} + +static void +DeviceDiscoveryStarted(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Inquiry Started\n"); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); +} + +static void +DeviceDiscoveryFinished(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Inquiry Completed\n"); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); +} + +static void +RemoteDeviceConnected(const char *string, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Connected: %s\n", string); + A_STR2ADDR(string, pAbfBtInfo->RemoteDevice); + AthBtIndicateState(pInstance, ATH_BT_CONNECT, STATE_ON); +} + +static void +RemoteDeviceDisconnected(const char *string, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Disconnected: %s\n", string); + A_MEMZERO(pAbfBtInfo->RemoteDevice, sizeof(pAbfBtInfo->RemoteDevice)); + AthBtIndicateState(pInstance, ATH_BT_CONNECT, STATE_OFF); +} + +static void ReleaseDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + + if (pAbfBtInfo->AudioCbRegistered) { + if (USE_DBUS_FOR_HEADSET_PROFILE(pInfo)) { + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_CONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_DISCONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STARTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STOPPED); + } + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_CONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_DISCONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_CONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_DISCONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STARTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STOPPED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_CONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_DISCONNECTED); + pAbfBtInfo->AudioCbRegistered = FALSE; + } + + if (pAbfBtInfo->DefaultAudioDeviceAvailable) { + pAbfBtInfo->DefaultAudioDeviceAvailable = FALSE; + A_DEBUG("Default Audio Device Removed: %s\n", pAbfBtInfo->DefaultAudioDeviceName); + A_MEMZERO(pAbfBtInfo->DefaultAudioDeviceName,sizeof(pAbfBtInfo->DefaultAudioDeviceName)); + } + +} + +static A_STATUS DoMethodCall(DBusConnection *Bus, + char *BusName, + char *Path, + char *Interface, + char *Method, + void *InputArg, + int InputType, + int InputLength, + void *OutputArg, + int OutputType, + int MaxOutLength) +{ + A_STATUS status = A_ERROR; + DBusError error; + DBusMessage *msg = NULL; + DBusMessage *reply = NULL; + void *replyData; + DBusMessageIter args; + + dbus_error_init(&error); + + do { + msg = dbus_message_new_method_call(BusName, Path, Interface, Method); + + if (NULL == msg) { + A_ERR("[%s] failed new method call line \n", __FUNCTION__); + break; + } + + /* see if caller is providing an argument */ + if (InputArg != NULL) { + dbus_message_iter_init_append(msg, &args); + if (InputType == DBUS_TYPE_STRING) { + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, (char **)&InputArg)) { + A_ERR("[%s] Failed to add string input argument \n", __FUNCTION__); + break; + } + } else { + A_ERR("[%s] unsupported input arg type: %c \n", __FUNCTION__, (char)InputType); + break; + } + } + + reply = dbus_connection_send_with_reply_and_block(Bus, msg, DBUS_METHOD_CALL_TIMEOUT, &error); + + + if (dbus_error_is_set(&error)) { + A_ERR("[%s] Failed to invoke method call (%s : method : %s) %s \n", + __FUNCTION__, Interface, Method, error.message); + break; + } + + /* check if caller expects a return string */ + if (OutputArg != NULL) { + + replyData = NULL; + + + if (OutputType == DBUS_TYPE_ARRAY) { + + DBusMessageIter iter,subIter; + dbus_message_iter_init (reply, &iter); + if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) { + + /* recurse into the array */ + dbus_message_iter_recurse(&iter, &subIter); + /* get a pointer to the start of the array */ + + dbus_message_iter_get_fixed_array(&subIter, &replyData, &MaxOutLength); + } else { + A_ERR("[%s] ARG Type (%s) is not an array! \n", __FUNCTION__, + (char)dbus_message_iter_get_arg_type(&iter)); + break; + } + + } else if (OutputType == DBUS_TYPE_STRING) { + + dbus_message_get_args(reply, &error, OutputType, &replyData, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&error)) { + A_ERR("[%s] dbus_message_get_args failed (%s : method : %s) %s \n", + __FUNCTION__, Interface, Method, error.message); + break; + } + + } else if (OutputType == DBUS_TYPE_OBJECT_PATH) { + + dbus_message_get_args(reply, &error, OutputType, &replyData, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&error)) { + A_ERR("[%s] dbus_message_get_args failed (%s : method : %s) %s \n", + __FUNCTION__, Interface, Method, error.message); + break; + } + + } else { + A_ERR("[%s] unsupported output arg type: %c \n", __FUNCTION__,(char)OutputType); + break; + } + + if (NULL == replyData) { + A_ERR("[%s] type %c data pointer was not returned from method call \n", + __FUNCTION__, (char)OutputType); + break; + } + + if (OutputType == DBUS_TYPE_STRING) { + strncpy(OutputArg, (char *)replyData, MaxOutLength); + } else if (OutputType == DBUS_TYPE_ARRAY) { + A_ERR(" (p:0x%X) Array has %d elements: \n", replyData, MaxOutLength); + /* just copy what the caller expects for data */ + + A_MEMCPY(OutputArg, replyData, MaxOutLength); + + } else if (OutputType == DBUS_TYPE_OBJECT_PATH) { /* Added by YG, November 19, 2009 */ + strncpy(OutputArg, (char *)replyData, MaxOutLength); + } + } + + status = A_OK; + + } while (FALSE); + + if (msg != NULL) { + dbus_message_unref(msg); + } + + if (reply != NULL) { + dbus_message_unref(reply); + } + + dbus_error_free(&error); + + return status; +} + +static void AcquireDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo) +{ + A_BOOL success = FALSE; +#ifndef BLUEZ4_3 + A_STATUS status; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; +#endif + + A_INFO("[%s]StartRegister\n", __FUNCTION__); + do { + + if (pAbfBtInfo->DefaultAudioDeviceAvailable) { + /* already acquired */ + success = TRUE; + break; + } +#ifdef BLUEZ4_3 + pAbfBtInfo->DefaultAudioDeviceAvailable = FALSE; +#else + A_INFO("Checking for a default audio device .. \n"); + + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + AUDIO_MANAGER_PATH, + AUDIO_MANAGER_INTERFACE, + "DefaultDevice", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->DefaultAudioDeviceName, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->DefaultAudioDeviceName)); + + if (A_FAILED(status)) { + break; + } + + A_INFO("Default Audio Device: %s \n", pAbfBtInfo->DefaultAudioDeviceName); + + pAbfBtInfo->DefaultAudioDeviceAvailable = TRUE; +#endif /* BLUEZ4_3 */ + + /* Register for audio specific events */ +#ifdef BLUEZ4_3 + if (1) { +#else + if (USE_DBUS_FOR_HEADSET_PROFILE(pInfo)) { +#endif + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_CONNECTED, AudioHeadsetConnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_DISCONNECTED, AudioHeadsetDisconnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STARTED, AudioHeadsetStreamStarted); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STOPPED, AudioHeadsetStreamStopped); + } +#ifndef BLUEZ4_3 + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_CONNECTED, AudioGatewayConnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_DISCONNECTED, AudioGatewayDisconnected); +#endif /* !BLUEZ4_3 */ + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_CONNECTED,AudioSinkConnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_DISCONNECTED, AudioSinkDisconnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STARTED,AudioSinkStreamStarted); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STOPPED, AudioSinkStreamStopped); +#ifndef BLUEZ4_3 + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_CONNECTED, AudioSourceConnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_DISCONNECTED, AudioSourceDisconnected); +#endif /* !BLUEZ4_3 */ + + pAbfBtInfo->AudioCbRegistered = TRUE; + + success = TRUE; + + A_INFO("[%s]EndRegister\n", __FUNCTION__); + } while (FALSE); + + if (!success) { + /* cleanup */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + } +} + +static void +AudioDeviceAdded(const char *string, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("Audio Device Added: %s\n", string); + /* release current one if any */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + /* re-acquire the new default, it could be the same one */ + AcquireDefaultAudioDevice(pAbfBtInfo); + +} + +static void +AudioDeviceRemoved(const char *string, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("Audio Device Removed: %s\n", string); + if (strcmp(string,pAbfBtInfo->DefaultAudioDeviceName) == 0) { + /* release current one */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + /* re-acquire the new default (if any) */ + AcquireDefaultAudioDevice(pAbfBtInfo); + } + +} + + +static void +AudioHeadsetConnected(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + + A_DEBUG("Audio Headset Connected \n"); + + if(!(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + GetBtAudioDeviceProperties(pAbfBtInfo); + } +} + +static void +AudioHeadsetDisconnected(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + A_DEBUG("Audio Headset (%s) Disconnected\n",pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + ForgetRemoteAudioDevice(pAbfBtInfo); +} + +static void +AudioHeadsetStreamStarted(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + if(!(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + if (!pAbfBtInfo->DefaultRemoteAudioDevicePropsValid) { + GetBtAudioDeviceProperties(pAbfBtInfo); + } + } + A_DEBUG("Audio Headset (%s) Stream Started \n",pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + /* make the indication */ + /* get properties of this headset connection */ + GetBtAudioConnectionProperties(pAbfBtInfo, ATH_BT_SCO); + + AthBtIndicateState(pInstance, + pAbfBtInfo->CurrentSCOLinkType == SCO_LINK ? ATH_BT_SCO : ATH_BT_ESCO, + STATE_ON); +} + +static void +AudioHeadsetStreamStopped(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + /* This event can also be used to indicate the SCO state */ + A_DEBUG("Audio Headset (%s) Stream Stopped \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + AthBtIndicateState(pInstance, + pAbfBtInfo->CurrentSCOLinkType == SCO_LINK ? ATH_BT_SCO : ATH_BT_ESCO, + STATE_OFF); +} + +static void +AudioGatewayConnected(void *arg, void * user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Gateway Connected\n"); +} + +static void +AudioGatewayDisconnected(void *arg, void * user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Gateway disconnected\n"); +} + +static void +AudioSinkConnected(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + A_DEBUG("Audio Sink Connected \n"); + + if(!(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + GetBtAudioDeviceProperties(pAbfBtInfo); + } +} + +static void +AudioSinkDisconnected(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + A_DEBUG("Audio Sink (%s) Disconnected \n",pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_OFF); + ForgetRemoteAudioDevice(pAbfBtInfo); +} + +static void +AudioSinkStreamStarted(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + if (!pAbfBtInfo->DefaultRemoteAudioDevicePropsValid) { + GetBtAudioDeviceProperties(pAbfBtInfo); + } + + A_DEBUG("Audio Sink (%s) Stream Started \n",pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + /* get connection properties */ + GetBtAudioConnectionProperties(pAbfBtInfo, ATH_BT_A2DP); + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_ON); +} + +static void +AudioSinkStreamStopped(void *arg, void * user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Audio Sink (%s) Stream Stopped \n",pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_OFF); +} + +static void +AudioSourceConnected(void *arg, void * user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Source Connected \n"); +} + +static void +AudioSourceDisconnected(void *arg, void * user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Source Disconnected \n"); +} + + +static A_STATUS ProcessDBusMessage(ABF_BT_INFO *pAbfBtInfo, DBusMessage *Msg) +{ + A_STATUS status = A_OK; + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + int i, argType; + DBusMessageIter msgiter; + char *argString; + + pNotificationConfig = &g_NotificationConfig[0]; + + for (i = 0; i < BT_EVENTS_NUM_MAX; i++, pNotificationConfig++) { + if ((pNotificationConfig->interface != NULL) && + (pNotificationConfig->signal_name != NULL)) { + + if (dbus_message_is_signal(Msg, + pNotificationConfig->interface, + pNotificationConfig->signal_name)) { + + /* found a match */ + break; + } + } + + } + + if (i >= BT_EVENTS_NUM_MAX) { + /* not a signal we registered for */ + return A_OK; + } + + do { + if (pAbfBtInfo->SignalHandlers[i] == NULL) { + /* no registered handler for this signal, just ignore */ + break; + } + if (pNotificationConfig->arg == ARG_NONE) { + /* call zero-argument handler */ + pAbfBtInfo->SignalHandlers[i](NULL, pAbfBtInfo); + } else if (pNotificationConfig->arg == ARG_STRING) { + /* we are expecting a string argument */ + if (!dbus_message_iter_init(Msg, &msgiter)) { + A_ERR("[%s] event: %d (if:%s , sig: %s) expecting a string argument but there are none \n", + __FUNCTION__, i, pNotificationConfig->interface, + pNotificationConfig->signal_name ); + break; + } + + argType = dbus_message_iter_get_arg_type(&msgiter); + if(!((argType == DBUS_TYPE_STRING) || argType == DBUS_TYPE_OBJECT_PATH)) { + A_ERR("[%s] event: %d (if:%s , sig: %s) expecting a string /object path argument !\n", + __FUNCTION__, i, pNotificationConfig->interface, + pNotificationConfig->signal_name); + break; + } + + dbus_message_iter_get_basic(&msgiter, &argString); + /* call string arg handler */ + pAbfBtInfo->SignalHandlers[i](argString, pAbfBtInfo); + } + + } while (FALSE); + + return status; +} + +static void +RegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event, + BT_EVENT_HANDLER handler) +{ + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + DBusError error; + char tempStr[STRING_SIZE_MAX]; + dbus_error_init(&error); + + do { + + if (event >= BT_EVENTS_NUM_MAX) { + A_ERR("[%s] Invalid Event: %d\n", __FUNCTION__, event); + break; + } + pNotificationConfig = &g_NotificationConfig[event]; + + if (pAbfBtInfo->SignalHandlers[event] != NULL) { + A_ERR("[%s] event: %d already in use \n", __FUNCTION__); + break; + } + if (pNotificationConfig->interface == NULL) { + /* no interface, may not be implemented yet */ + A_ERR("[%s] Event: %d not implemented yet \n", __FUNCTION__, event); + break; + } + + snprintf(tempStr, sizeof(tempStr), "type='signal',interface='%s'",pNotificationConfig->interface); + + A_DEBUG(" rule to add: %s \n", tempStr); + + + /* add signal */ + dbus_bus_add_match(pAbfBtInfo->Bus, tempStr, &error); + + if (dbus_error_is_set(&error)) { + A_ERR("[%s] dbus_bus_add_match failed: %s n", __FUNCTION__, error.message); + break; + } + dbus_connection_flush(pAbfBtInfo->Bus); + + /* install handler */ + pAbfBtInfo->SignalHandlers[event] = handler; + + } while (FALSE); + + dbus_error_free(&error); +} + + +static void +DeRegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event) +{ + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + DBusError error; + char tempStr[STRING_SIZE_MAX]; + + dbus_error_init(&error); + + do { + + if (event >= BT_EVENTS_NUM_MAX) { + A_ERR("[%s] Invalid Event: %d\n", __FUNCTION__, event); + break; + } + + pNotificationConfig = &g_NotificationConfig[event]; + + if (pAbfBtInfo->SignalHandlers[event] == NULL) { + A_ERR("[%s] event: %d is not in use! \n", __FUNCTION__, event); + break; + } + + snprintf(tempStr, sizeof(tempStr),"type='signal',interface='%s'",pNotificationConfig->interface); + + A_DEBUG(" rule to remove : %s \n", tempStr); + + /* remove rule */ + dbus_bus_remove_match(pAbfBtInfo->Bus, tempStr, &error); + + if (dbus_error_is_set(&error)) { + A_ERR("[%s] dbus_bus_remove_match failed: %s n", __FUNCTION__, error.message); + break; + } + + dbus_connection_flush(pAbfBtInfo->Bus); + + /* delete handler */ + pAbfBtInfo->SignalHandlers[event] = NULL; + + } while (FALSE); + + dbus_error_free(&error); + +} + +/* Misc */ +static A_STATUS +AcquireBtAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status = A_ERROR; + char *hciName; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + + do { + + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + BLUEZ_PATH, + MANAGER_INTERFACE, + "DefaultAdapter", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->HCI_AdapterName, +#ifdef BLUEZ4_3 + DBUS_TYPE_OBJECT_PATH, +#else + DBUS_TYPE_STRING, +#endif + sizeof(pAbfBtInfo->HCI_AdapterName)); + + if (A_FAILED(status)) { + A_ERR("[%s] Get Default Adapter failed \n", __FUNCTION__); + break; + } + + /* assume ID 0 */ + pAbfBtInfo->AdapterId = 0; + + if ((hciName = strstr(pAbfBtInfo->HCI_AdapterName, "hci")) != NULL) { + /* get the number following the hci name, this is the ID used for + * socket calls to the HCI layer */ + pAbfBtInfo->AdapterId = (int)hciName[3] - (int)'0'; + if (pAbfBtInfo->AdapterId < 0) { + pAbfBtInfo->AdapterId = 0; + } + } + + if(!(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + if (!A_SUCCESS(SetupHciEventFilter(pAbfBtInfo))) { + break; + } + GetAdapterInfo(pAbfBtInfo); + } + + + pAbfBtInfo->pInfo->LMPVersion = pAbfBtInfo->HCI_LMPVersion; + + pAbfBtInfo->AdapterAvailable = TRUE; + /* Register to get notified of different stack events */ + RegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_STARTED, DeviceDiscoveryStarted); + RegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_FINISHED, DeviceDiscoveryFinished); + RegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_CONNECTED, (BT_EVENT_HANDLER)RemoteDeviceConnected); + RegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_DISCONNECTED, (BT_EVENT_HANDLER)RemoteDeviceDisconnected); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_ADDED, (BT_EVENT_HANDLER)AudioDeviceAdded); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_REMOVED, (BT_EVENT_HANDLER)AudioDeviceRemoved); + + pAbfBtInfo->AdapterCbRegistered = TRUE; + + A_INFO("[%s] BT Adapter Added\n",pAbfBtInfo->HCI_AdapterName); + + /* acquire default audio device */ + AcquireDefaultAudioDevice(pAbfBtInfo); + + status = A_OK; + + } while (FALSE); + + + return status; +} + +static void +ReleaseBTAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + + if (pAbfBtInfo->AdapterCbRegistered) { + pAbfBtInfo->AdapterCbRegistered = FALSE; + /* Free the resources held for the event handlers */ + DeRegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_STARTED); + DeRegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_FINISHED); + DeRegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_CONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_DISCONNECTED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_ADDED); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_REMOVED); + } + + ReleaseDefaultAudioDevice(pAbfBtInfo); + + CleanupHciEventFilter(pAbfBtInfo); + + A_MEMZERO(pAbfBtInfo->HCI_DeviceAddress, + sizeof(pAbfBtInfo->HCI_DeviceAddress)); + A_MEMZERO(pAbfBtInfo->HCI_DeviceName, + sizeof(pAbfBtInfo->HCI_DeviceName)); + A_MEMZERO(pAbfBtInfo->HCI_ManufacturerName, + sizeof(pAbfBtInfo->HCI_ManufacturerName)); + A_MEMZERO(pAbfBtInfo->HCI_ProtocolVersion, + sizeof(pAbfBtInfo->HCI_ProtocolVersion)); + pAbfBtInfo->HCI_LMPVersion = 0; + + pAbfBtInfo->AdapterAvailable = FALSE; +} + +#ifdef BLUEZ4_3 + +static A_STATUS +GetAdapterInfo(ABF_BT_INFO *pAbfBtInfo) +{ + + A_STATUS status; + + int i; + A_UCHAR eventBuffer[HCI_MAX_EVENT_SIZE]; + A_UCHAR *eventPtr; + int eventLen; + + /* Get adapter/device address by issuing HCI command, Read_BD_ADDR */ + status = IssueHCICommand(pAbfBtInfo, + cmd_opcode_pack(OGF_INFO_PARAM, OCF_READ_BD_ADDR), + 0, + 0, + 2000, + eventBuffer, + sizeof(eventBuffer), + &eventPtr, + &eventLen); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get BD_ADDR \n", __FUNCTION__); + return status; + } + + if (eventBuffer[6] == 0) { /* READ_BD_ADDR was a success */ + for (i = 0; i < BD_ADDR_SIZE; i++) { + pAbfBtInfo->HCI_DeviceAddress[i] = eventBuffer[i+7]; + } + A_DEBUG("BT-HCI Device Address: (%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X)\n", + pAbfBtInfo->HCI_DeviceAddress[0], pAbfBtInfo->HCI_DeviceAddress[1], + pAbfBtInfo->HCI_DeviceAddress[2], pAbfBtInfo->HCI_DeviceAddress[3], + pAbfBtInfo->HCI_DeviceAddress[4], pAbfBtInfo->HCI_DeviceAddress[5]); + } + + status = A_OK; + + return status; +} + +#else + +static A_STATUS +GetAdapterInfo(ABF_BT_INFO *pAbfBtInfo) +{ + int count; + A_STATUS status = A_OK; + char tempStr[STRING_SIZE_MAX]; + + do { + /* device name */ + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetName", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->HCI_DeviceName, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->HCI_DeviceName)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to complete GetName \n", __FUNCTION__); + break; + } + + /* Manufacturer name */ + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetManufacturer", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->HCI_ManufacturerName, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->HCI_ManufacturerName)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to complete GetManufacturer \n", __FUNCTION__); + break; + } + + /* get LMP version */ + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetVersion", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->HCI_ProtocolVersion, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->HCI_ProtocolVersion)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to complete GetVersion \n", __FUNCTION__); + break; + } + + + for (count = 0; + ((count < sizeof(ver_map)/sizeof(hci_map)) && (ver_map[count].str)); + count++) + { + if (strstr(pAbfBtInfo->HCI_ProtocolVersion, ver_map[count].str)) { + pAbfBtInfo->HCI_LMPVersion = ver_map[count].val; + break; + } + } + + /* Device address */ + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetAddress", + NULL, + DBUS_TYPE_INVALID, + 0, + tempStr, + DBUS_TYPE_STRING, + sizeof(tempStr)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get Address \n", __FUNCTION__); + break; + } + + A_STR2ADDR(tempStr, pAbfBtInfo->HCI_DeviceAddress); + + } while (FALSE); + + + if (A_SUCCESS(status)) { + A_INFO("BT-HCI Device Address: (%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X)\n", + pAbfBtInfo->HCI_DeviceAddress[0], pAbfBtInfo->HCI_DeviceAddress[1], + pAbfBtInfo->HCI_DeviceAddress[2], pAbfBtInfo->HCI_DeviceAddress[3], + pAbfBtInfo->HCI_DeviceAddress[4], pAbfBtInfo->HCI_DeviceAddress[5]); + A_INFO("BT-HCI Device Name: %s\n", pAbfBtInfo->HCI_DeviceName); + A_INFO("BT-HCI Manufacturer Name: %s\n", pAbfBtInfo->HCI_ManufacturerName); + A_INFO("BT-HCI Protocol Version: %s\n", pAbfBtInfo->HCI_ProtocolVersion); + A_INFO("BT-HCI LMP Version: %d\n", pAbfBtInfo->HCI_LMPVersion); + + } + + return status; +} +#endif + + +static A_STATUS GetConnectedDeviceRole(ABF_BT_INFO *pAbfBtInfo, + A_CHAR *Address, + A_BOOL IsSCO, + A_UCHAR *pRole) +{ + A_STATUS status = A_ERROR; + struct hci_conn_list_req *connList = NULL; + struct hci_conn_info *connInfo = NULL; + int i, sk = -1; + int len; + + do { + + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (sk < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + len = (sizeof(*connInfo)) * ABTH_MAX_CONNECTIONS + sizeof(*connList); + + connList = (struct hci_conn_list_req *)A_MALLOC(len); + if (connList == NULL) { + break; + } + + A_MEMZERO(connList,len); + + connList->dev_id = pAbfBtInfo->AdapterId; + connList->conn_num = ABTH_MAX_CONNECTIONS; + connInfo = connList->conn_info; + + if (ioctl(sk, HCIGETCONNLIST, (void *)connList)) { + A_ERR("[%s] Failed to get connection list %d \n", __FUNCTION__, errno); + break; + } + /* walk through connection list */ + for (i = 0; i < connList->conn_num; i++, connInfo++) { + char addr[32]; + + /* convert to a string to compare */ + ba2str(&connInfo->bdaddr, addr); + + if (strcmp(addr,Address) != 0) { + continue; + } + + if (IsSCO) { + /* look for first non-ACL connection */ + if (connInfo->type == ACL_LINK) { + continue; + } + pAbfBtInfo->CurrentSCOLinkType = connInfo->type; + } else { + /* look for first ACL connection */ + if (connInfo->type != ACL_LINK) { + continue; + } + } + /* if we get here we have a connection we are interested in */ + if (connInfo->link_mode & HCI_LM_MASTER) { + /* master */ + *pRole = 0; + } else { + /* slave */ + *pRole = 1; + } + + A_INFO("[%s] Found Connection (Link-Type : %d), found role:%d \n", + Address, connInfo->type, *pRole); + break; + } + + if (i == connList->conn_num) { + A_ERR("[%s] Could not find connection info for %s %d \n", __FUNCTION__, Address); + break; + } + status = A_OK; + + } while (FALSE); + + if (sk >= 0) { + close(sk); + } + + if (connList != NULL) { + A_FREE(connList); + } + + return status; +} + +#ifdef BLUEZ4_3 + +static void GetBtAudioDeviceProperties(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status; + + pAbfBtInfo->DefaultRemoteAudioDevicePropsValid = FALSE; + + do { + + /* Need RemoteDeviceAddress */ + + + status = GetRemoteDeviceLMPVersion(pAbfBtInfo); + + /* assume 2.1 or later */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 4; + + if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.0") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 0; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.1") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 1; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.2") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"2.0") != NULL) { + /* NOTE: contrary to what the DBUS documentation says, the BT string will + * not indicate +EDR to indiate the remote device is EDR capable! + * */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 3; + } + + if (pAbfBtInfo->DefaultAudioDeviceLmpVersion >= 3) { + A_BOOL EDRCapable = FALSE; + /* double check that the device is EDR capable, a 2.0 device can be EDR or non EDR */ + status = CheckRemoteDeviceEDRCapable(pAbfBtInfo, &EDRCapable); + if (A_SUCCESS(status)) { + if (!EDRCapable) { + A_INFO("Remote Audio Device (%s) is not EDR Capable, downgrading lmp version.. \n", + pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + /* for audio coex, treat this like a 1.2 device */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + } + } + } + pAbfBtInfo->DefaultRemoteAudioDevicePropsValid = TRUE; + + } while (FALSE); + +} + +#else + +static void GetBtAudioDeviceProperties(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status; + + pAbfBtInfo->DefaultRemoteAudioDevicePropsValid = FALSE; + + do { + /* Device address */ + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_DEVICE_INTERFACE, + "GetAddress", + NULL, + DBUS_TYPE_INVALID, + 0, + pAbfBtInfo->DefaultRemoteAudioDeviceAddress, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->DefaultRemoteAudioDeviceAddress)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get address \n", __FUNCTION__); + break; + } + + A_INFO("Connected audio device address: %s \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetRemoteVersion", + pAbfBtInfo->DefaultRemoteAudioDeviceAddress, + DBUS_TYPE_STRING, + strlen(pAbfBtInfo->DefaultRemoteAudioDeviceAddress) + 1, + pAbfBtInfo->DefaultRemoteAudioDeviceVersion, + DBUS_TYPE_STRING, + sizeof(pAbfBtInfo->DefaultRemoteAudioDeviceVersion)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get remote version \n", __FUNCTION__); + break; + } + + A_INFO("Connected audio device remote version: %s \n", + pAbfBtInfo->DefaultRemoteAudioDeviceVersion); + + + /* assume 2.1 or later */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 4; + + if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.0") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 0; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.1") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 1; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"1.2") != NULL) { + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + } else if (strstr(pAbfBtInfo->DefaultRemoteAudioDeviceVersion,"2.0") != NULL) { + /* NOTE: contrary to what the DBUS documentation says, the BT string will + * not indicate +EDR to indiate the remote device is EDR capable! + * */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 3; + } + + if (pAbfBtInfo->DefaultAudioDeviceLmpVersion >= 3) { + A_BOOL EDRCapable = FALSE; + /* double check that the device is EDR capable, a 2.0 device can be EDR or non EDR */ + status = CheckRemoteDeviceEDRCapable(pAbfBtInfo, &EDRCapable); + if (A_SUCCESS(status)) { + if (!EDRCapable) { + A_INFO("Remote Audio Device (%s) is not EDR Capable, downgrading lmp version.. \n", + pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + /* for audio coex, treat this like a 1.2 device */ + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + } + } + } + + pAbfBtInfo->DefaultRemoteAudioDevicePropsValid = TRUE; + + } while (FALSE); + +} + +#endif + +#define LMP_FEATURE_ACL_EDR_2MBPS_BYTE_INDEX 3 +#define LMP_FEATURE_ACL_EDR_2MBPS_BIT_MASK 0x2 +#define LMP_FEATURE_ACL_EDR_3MBPS_BYTE_INDEX 3 +#define LMP_FEATURE_ACL_EDR_3MBPS_BIT_MASK 0x4 +#define LMP_FEATURES_LENGTH 8 + +#ifdef BLUEZ4_3 + +#define HCI_REMOTE_COMMAND_TIMEOUT 2000 +static A_STATUS GetRemoteAclDeviceHandle(ABF_BT_INFO *pAbfBtInfo, A_UINT16 *pConn_handle) +{ + A_STATUS status = A_OK; + int i, len, sk = -1; + struct hci_conn_list_req *connList = NULL; + struct hci_conn_info *connInfo = NULL; + do { + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (sk < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d\n", __FUNCTION__, errno); + status = A_NO_RESOURCE; + break; + } + + len = (sizeof(*connInfo)) * ABTH_MAX_CONNECTIONS + sizeof(*connList); + connList = (struct hci_conn_list_req *)A_MALLOC(len); + + if (connList == NULL) { + A_DEBUG("No connection found during calling function [%s]\n", __FUNCTION__); + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(connList, len); + + connList->dev_id = pAbfBtInfo->AdapterId; + connList->conn_num = ABTH_MAX_CONNECTIONS; + connInfo = connList->conn_info; + + if (ioctl(sk, HCIGETCONNLIST, (void *)connList)) { + A_ERR("[%s] Failed to get connection list: %d\n", __FUNCTION__, errno); + status = A_EPERM; + break; + } + + for (i = 0; i < connList->conn_num; i++, connInfo++) { + if (connInfo->type == ACL_LINK) { + *pConn_handle = connInfo->handle; + break; + } + } + + if (i==connList->conn_num) { + status = A_ENOENT; + break; + } + } while (0); + if (connList != NULL) { + A_FREE(connList); + } + if (sk>=0) { + close(sk); + } + return status; +} + +static A_STATUS CheckRemoteDeviceEDRCapable(ABF_BT_INFO *pAbfBtInfo, A_BOOL *pEDRCapable) +{ + A_STATUS status; + A_UINT16 conn_handle; + A_UCHAR evtBuffer[HCI_MAX_EVENT_SIZE]; + A_UCHAR *eventPtr; + int eventLen; + A_UINT8 *lmp_features; + do { + status = GetRemoteAclDeviceHandle(pAbfBtInfo, &conn_handle); + if (A_FAILED(status)) { + break; + } + status = IssueHCICommand(pAbfBtInfo, + cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_FEATURES), + (A_UCHAR *)&conn_handle, + 2, + HCI_REMOTE_COMMAND_TIMEOUT, + evtBuffer, + sizeof(evtBuffer), + &eventPtr, + &eventLen); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get remote features \n", __FUNCTION__); + break; + } + + /* Process LMP Features */ + lmp_features = &eventPtr[3]; + + A_DUMP_BUFFER(lmp_features,sizeof(lmp_features),"Remote Device LMP Features:"); + + if ((lmp_features[LMP_FEATURE_ACL_EDR_2MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_2MBPS_BIT_MASK) || + (lmp_features[LMP_FEATURE_ACL_EDR_3MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_3MBPS_BIT_MASK)) { + A_INFO("Device (%s) is EDR capable \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + *pEDRCapable = TRUE; + } else { + A_INFO("Device (%s) is NOT EDR capable \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + *pEDRCapable = FALSE; + } + } while (0); + + return status; +} + +/* This is new function to check remote device LMP version */ +static A_STATUS GetRemoteDeviceLMPVersion(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status; + A_UINT16 conn_handle; + A_UCHAR evtBuffer[HCI_MAX_EVENT_SIZE]; + A_UCHAR *eventPtr; + int eventLen; + + do { + status = GetRemoteAclDeviceHandle(pAbfBtInfo, &conn_handle); + if (A_FAILED(status)) { + break; + } + status = IssueHCICommand(pAbfBtInfo, + cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_VERSION), + (A_UCHAR *)&conn_handle, + 2, + HCI_REMOTE_COMMAND_TIMEOUT, + evtBuffer, + sizeof(evtBuffer), + &eventPtr, + &eventLen); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get remote Version \n", __FUNCTION__); + break; + } + + /* Process LMP Version */ + + if (eventPtr[3] == 0) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.0"); + } else if (eventPtr[3] == 1) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.1"); + } else if (eventPtr[3] == 2) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.2"); + } else if (eventPtr[3] == 3) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "2.0"); + } + + A_INFO("[%s], Remote Device LMP Version: %d, in string format this is: %s\n", __FUNCTION__, eventPtr[3], + pAbfBtInfo->DefaultRemoteAudioDeviceVersion); + } while (0); + + return status; +} + + +#else + +static A_STATUS CheckRemoteDeviceEDRCapable(ABF_BT_INFO *pAbfBtInfo, A_BOOL *pEDRCapable) +{ + A_STATUS status = A_OK; + A_UINT8 lmp_features[LMP_FEATURES_LENGTH]; + + do { + + A_MEMZERO(lmp_features,sizeof(lmp_features)); + + status = DoMethodCall(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->HCI_AdapterName, + ADAPTER_INTERFACE, + "GetRemoteFeatures", + pAbfBtInfo->DefaultRemoteAudioDeviceAddress, + DBUS_TYPE_STRING, + strlen(pAbfBtInfo->DefaultRemoteAudioDeviceAddress) + 1, + lmp_features, + DBUS_TYPE_ARRAY, + sizeof(lmp_features)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get remote features \n", __FUNCTION__); + break; + } + + A_DUMP_BUFFER(lmp_features,sizeof(lmp_features),"Remote Device LMP Features:"); + + if ((lmp_features[LMP_FEATURE_ACL_EDR_2MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_2MBPS_BIT_MASK) || + (lmp_features[LMP_FEATURE_ACL_EDR_3MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_3MBPS_BIT_MASK)) { + A_INFO("Device (%s) is EDR capable \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + *pEDRCapable = TRUE; + } else { + A_INFO("Device (%s) is NOT EDR capable \n", pAbfBtInfo->DefaultRemoteAudioDeviceAddress); + *pEDRCapable = FALSE; + } + + } while (FALSE); + + return status; +} + +#endif + +static void GetBtAudioConnectionProperties(ABF_BT_INFO *pAbfBtInfo, + ATHBT_STATE_INDICATION Indication) +{ + A_UCHAR role = 0; + A_CHAR *pDescr = NULL; + A_STATUS status; + + do { + if (!pAbfBtInfo->DefaultRemoteAudioDevicePropsValid) { + break; + } + + /* Incases where HciX is not supported, don't check for the role */ + if((pAbfBtInfo->pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + return; + } + /* get role */ + status = GetConnectedDeviceRole(pAbfBtInfo, + pAbfBtInfo->DefaultRemoteAudioDeviceAddress, + Indication == ATH_BT_A2DP ?FALSE : TRUE, + &role); + if (A_FAILED(status)) { + role = 0; + } + if (Indication == ATH_BT_A2DP) { + pDescr = "A2DP"; + pAbfBtInfo->pInfo->A2DPConnection_LMPVersion = pAbfBtInfo->DefaultAudioDeviceLmpVersion; + pAbfBtInfo->pInfo->A2DPConnection_Role = role; + } else if (Indication == ATH_BT_SCO) { + if (pAbfBtInfo->CurrentSCOLinkType == SCO_LINK) { + pDescr = "SCO"; + } else { + pDescr = "eSCO"; + } + pAbfBtInfo->pInfo->SCOConnection_LMPVersion = pAbfBtInfo->DefaultAudioDeviceLmpVersion; + pAbfBtInfo->pInfo->SCOConnection_Role = role; + + if((pAbfBtInfo->pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING)) { + + pAbfBtInfo->pInfo->SCOConnectInfo.Valid = TRUE; + }else{ + /* for SCO connections check if the event filter captured + * the SYNCH connection complete event */ + CheckHciEventFilter(pAbfBtInfo); + } + } else { + pDescr = "UNKNOWN!!"; + } + + A_INFO("BT Audio connection properties: (%s) (role: %s, lmp version: %d) \n", + pDescr, role ? "SLAVE" : "MASTER", pAbfBtInfo->DefaultAudioDeviceLmpVersion); + + } while (FALSE); + +} + + +static A_STATUS WaitForHCIEvent(int Socket, + int TimeoutMs, + A_UCHAR *pBuffer, + int MaxLength, + A_UCHAR EventCode, + A_UINT16 OpCode, + A_UCHAR **ppEventPtr, + int *pEventLength) +{ + + int eventLen; + hci_event_hdr *eventHdr; + struct pollfd pfd; + int result; + A_UCHAR *eventPtr; + A_STATUS status = A_OK; + + *ppEventPtr = NULL; + A_MEMZERO(&pfd,sizeof(pfd)); + pfd.fd = Socket; + pfd.events = POLLIN; + + if (EventCode == EVT_CMD_COMPLETE) { + A_INFO("Waiting for HCI CMD Complete Event, Opcode: 0x%4.4X (%d MS) \n",OpCode, TimeoutMs); + } else { + A_INFO("Waiting for HCI Event: %d (%d MS) \n",EventCode, TimeoutMs); + } + + while (1) { + + /* check socket for a captured event using a short timeout + * the caller usually calls this function when it knows there + * is an event that is likely to be captured */ + result = poll(&pfd, 1, TimeoutMs); + + if (result < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) { + /* interrupted */ + } else { + A_ERR("[%s] Socket Poll Failed! : %d \n", __FUNCTION__, errno); + status = A_ERROR; + } + break; + } + + if (result == 0) { + A_ERR("[%s], poll returned with 0 \n",__FUNCTION__); + status = A_ERROR; + break; + } + + if (!(pfd.revents & POLLIN)) { + A_ERR("[%s], POLLIN check failed\n",__FUNCTION__); + status = A_ERROR; + break; + } + /* get the packet */ + eventLen = read(Socket, pBuffer, MaxLength); + if (eventLen == 0) { + /* no event */ + A_INFO("[%s], No Event\n",__FUNCTION__); + status = A_ERROR; + break; + } + if(eventLen > MaxLength) { + A_ERR("[%s] Length longer than expected (%d) : %d \n", __FUNCTION__, MaxLength, + eventLen); + status = A_ERROR; + break; + } + if (eventLen < (1 + HCI_EVENT_HDR_SIZE)) { + A_ERR("[%s] Unknown receive packet! len : %d \n", __FUNCTION__, eventLen); + status = A_ERROR; + break; + } + if (pBuffer[0] != HCI_EVENT_PKT) { + A_ERR("[%s] Unsupported packet type : %d \n", __FUNCTION__, pBuffer[0]); + status = A_ERROR; + break; + } + + eventPtr = &pBuffer[1]; + eventLen--; + eventHdr = (hci_event_hdr *)eventPtr; + eventPtr += HCI_EVENT_HDR_SIZE; + eventLen -= HCI_EVENT_HDR_SIZE; + + if (eventHdr->evt != EventCode) { + /* not interested in this one */ + continue; + } + if(eventPtr == NULL) { + A_ERR("[%s] Socket read points to NULL\n", __FUNCTION__); + status = A_ERROR; + break; + } + if (eventHdr->evt == EVT_CMD_COMPLETE) { + if (eventLen < sizeof(evt_cmd_complete)) { + A_ERR("[%s] EVT_CMD_COMPLETE event is too small! len=%d \n", __FUNCTION__, eventLen); + status = A_ERROR; + break; + } else { + A_UINT16 evOpCode = btohs(BTEV_CMD_COMPLETE_GET_OPCODE(eventPtr)); + /* check for opCode match */ + if (OpCode != evOpCode) { + /* keep searching */ + continue; + } + } + } + /* found it */ + *ppEventPtr = eventPtr; + *pEventLength = eventLen; + + break; + + } + + return status; +} + +static void CheckHciEventFilter(ABF_BT_INFO *pAbfBtInfo) +{ + A_UCHAR buffer[HCI_MAX_EVENT_SIZE]; + A_STATUS status; + A_UCHAR *eventPtr; + int eventLen; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + + do { + + if (!USE_DBUS_FOR_HEADSET_PROFILE(pInfo)) { + A_ERR("Calling CheckHciEventFilter is not valid in this mode! \n"); + break; + } + + status = WaitForHCIEvent(pAbfBtInfo->HCIEventListenerSocket, + 100, + buffer, + sizeof(buffer), + EVT_SYNC_CONN_COMPLETE, + 0, + &eventPtr, + &eventLen); + + if (A_FAILED(status)) { + break; + } + + if (eventPtr == NULL) { + break; + } + + if (eventLen < sizeof(evt_sync_conn_complete)) { + A_ERR("SYNC_CONN_COMPLETE Event is too small! : %d \n", eventLen); + break; + } + + pAbfBtInfo->pInfo->SCOConnectInfo.LinkType = BTEV_GET_BT_CONN_LINK_TYPE(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.TransmissionInterval = BTEV_GET_TRANS_INTERVAL(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.RetransmissionInterval = BTEV_GET_RETRANS_INTERVAL(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.RxPacketLength = BTEV_GET_RX_PKT_LEN(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.TxPacketLength = BTEV_GET_TX_PKT_LEN(eventPtr); + + A_INFO("HCI SYNC_CONN_COMPLETE event captured, conn info (%d, %d, %d, %d, %d) \n", + pAbfBtInfo->pInfo->SCOConnectInfo.LinkType, + pAbfBtInfo->pInfo->SCOConnectInfo.TransmissionInterval, + pAbfBtInfo->pInfo->SCOConnectInfo.RetransmissionInterval, + pAbfBtInfo->pInfo->SCOConnectInfo.RxPacketLength, + pAbfBtInfo->pInfo->SCOConnectInfo.TxPacketLength); + + /* now valid */ + pAbfBtInfo->pInfo->SCOConnectInfo.Valid = TRUE; + + } while (FALSE); + +} + +static void CleanupHciEventFilter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status; + + if (pAbfBtInfo->HCIEventListenerSocket >= 0) { + pAbfBtInfo->HCIFilterThreadShutdown = TRUE; + /* close socket, if there is a thread waiting on this socket, it will error and then exit */ + close(pAbfBtInfo->HCIEventListenerSocket); + pAbfBtInfo->HCIEventListenerSocket = -1; + + if (pAbfBtInfo->HCIFilterThreadCreated) { + A_INFO("[%s] Waiting for HCI filter thread to exit... \n", + __FUNCTION__); + /* wait for thread to exit + * note: JOIN cleans up thread resources as per POSIX spec. */ + status = A_TASK_JOIN(&pAbfBtInfo->hBtHCIFilterThread); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to JOIN HCI filter thread \n", + __FUNCTION__); + } + A_MEMZERO(&pAbfBtInfo->hBtHCIFilterThread,sizeof(pAbfBtInfo->hBtHCIFilterThread)); + pAbfBtInfo->HCIFilterThreadCreated = FALSE; + } + + pAbfBtInfo->HCIFilterThreadShutdown = FALSE; + } + +} + + +static A_STATUS SetupHciEventFilter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status = A_ERROR; + struct hci_filter filterSetting; + struct sockaddr_hci addr; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + do { + + if (pAbfBtInfo->HCIEventListenerSocket >= 0) { + /* close previous */ + CleanupHciEventFilter(pAbfBtInfo); + } + + pAbfBtInfo->HCIEventListenerSocket = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (pAbfBtInfo->HCIEventListenerSocket < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + /* To caputre INQUIRY command capture */ + hci_filter_set_ptype(HCI_COMMAND_PKT, &filterSetting); + + /* capture SYNC_CONN Complete */ + hci_filter_set_event(EVT_SYNC_CONN_COMPLETE, &filterSetting); + + /* Capture INQUIRY_COMPLETE event */ + hci_filter_set_event(EVT_INQUIRY_COMPLETE, &filterSetting); + hci_filter_set_event(EVT_CONN_REQUEST, &filterSetting); + hci_filter_set_event(EVT_PIN_CODE_REQ, &filterSetting); + hci_filter_set_event(EVT_LINK_KEY_REQ, &filterSetting); + hci_filter_set_event(EVT_CONN_COMPLETE, &filterSetting); + hci_filter_set_event(EVT_LINK_KEY_NOTIFY, &filterSetting); + + + + if (!USE_DBUS_FOR_HEADSET_PROFILE(pInfo)) { + /* if we are not using DBUS for the headset profile, we need + * to capture other HCI event packets */ + hci_filter_set_event(EVT_DISCONN_COMPLETE, &filterSetting); + hci_filter_set_event(EVT_CONN_COMPLETE, &filterSetting); + } + + if (setsockopt(pAbfBtInfo->HCIEventListenerSocket, + SOL_HCI, + HCI_FILTER, + &filterSetting, + sizeof(filterSetting)) < 0) { + A_ERR("[%s] Failed to set socket opt: %d \n", __FUNCTION__, errno); + break; + } + + A_MEMZERO(&addr,sizeof(addr)); + /* bind to the current adapter */ + addr.hci_family = AF_BLUETOOTH; + addr.hci_dev = pAbfBtInfo->AdapterId; + + if (bind(pAbfBtInfo->HCIEventListenerSocket, + (struct sockaddr *)&addr, + sizeof(addr)) < 0) { + A_ERR("[%s] Can't bind to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + A_INFO("BT Event Filter Set, Mask: 0x%8.8X:%8.8X \n", + filterSetting.event_mask[1], filterSetting.event_mask[0]); +#ifdef BLUEZ4_3 + if (1) { +#else + if (!USE_DBUS_FOR_HEADSET_PROFILE(pInfo)) { +#endif + /* spawn a thread that will capture HCI events from the adapter */ + status = A_TASK_CREATE(&pAbfBtInfo->hBtHCIFilterThread, HCIFilterThread, pAbfBtInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to spawn a BT thread\n", __FUNCTION__); + break; + } + pAbfBtInfo->HCIFilterThreadCreated = TRUE; + } + + status = A_OK; + + } while (FALSE); + + if (A_FAILED(status)) { + CleanupHciEventFilter(pAbfBtInfo); + } + + return status; +} + + + /* issue HCI command, currently this ONLY supports simple commands that + * only expect a command complete, the event pointer returned points to the command + * complete event structure for the caller to decode */ +static A_STATUS IssueHCICommand(ABF_BT_INFO *pAbfBtInfo, + A_UINT16 OpCode, + A_UCHAR *pCmdData, + int CmdLength, + int EventRecvTimeoutMS, + A_UCHAR *pEventBuffer, + int MaxLength, + A_UCHAR **ppEventPtr, + int *pEventLength) +{ + A_STATUS status = A_ERROR; + A_UCHAR hciType = HCI_COMMAND_PKT; + hci_command_hdr hciCommandHdr; + struct iovec iv[3]; + int ivcount = 0; + int sk,result; + struct hci_filter filterSetting; + struct sockaddr_hci addr; + + do { + + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (sk < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + hciCommandHdr.opcode = htobs(OpCode); + hciCommandHdr.plen= CmdLength; + + iv[0].iov_base = &hciType; + iv[0].iov_len = 1; + ivcount++; + iv[1].iov_base = &hciCommandHdr; + iv[1].iov_len = HCI_COMMAND_HDR_SIZE; + ivcount++; + + if (pCmdData != NULL) { + iv[2].iov_base = pCmdData; + iv[2].iov_len = CmdLength; + ivcount++; + } + + /* setup socket to capture the event */ + if (OpCode == cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_FEATURES)) { + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + hci_filter_set_event(EVT_READ_REMOTE_FEATURES_COMPLETE, &filterSetting); + } else if (OpCode == cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_VERSION)) { + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + hci_filter_set_event(EVT_READ_REMOTE_VERSION_COMPLETE, &filterSetting); + } + else { + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + hci_filter_set_event(EVT_CMD_COMPLETE, &filterSetting); + } + + if (setsockopt(sk, SOL_HCI, HCI_FILTER, &filterSetting, sizeof(filterSetting)) < 0) { + A_ERR("[%s] Failed to set socket opt: %d \n", __FUNCTION__, errno); + break; + } + + A_MEMZERO(&addr,sizeof(addr)); + addr.hci_family = AF_BLUETOOTH; + addr.hci_dev = pAbfBtInfo->AdapterId; + + if (bind(sk,(struct sockaddr *)&addr, sizeof(addr)) < 0) { + A_ERR("[%s] Can't bind to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + while ((result = writev(sk, iv, ivcount)) < 0) { + if (errno == EAGAIN || errno == EINTR) { + continue; + } + break; + } + + if (result <= 0) { + A_ERR("[%s] Failed to write to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + /* To support new HCI Commands */ + switch (OpCode) { + case cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_FEATURES): + status = WaitForHCIEvent(sk, + EventRecvTimeoutMS, + pEventBuffer, + MaxLength, + EVT_READ_REMOTE_FEATURES_COMPLETE, + OpCode, + ppEventPtr, + pEventLength); + break; + case cmd_opcode_pack(OGF_LINK_CTL, OCF_READ_REMOTE_VERSION): + status = WaitForHCIEvent(sk, + EventRecvTimeoutMS, + pEventBuffer, + MaxLength, + EVT_READ_REMOTE_VERSION_COMPLETE, + OpCode, + ppEventPtr, + pEventLength); + break; + default: + status = WaitForHCIEvent(sk, + EventRecvTimeoutMS, + pEventBuffer, + MaxLength, + EVT_CMD_COMPLETE, + OpCode, + ppEventPtr, + pEventLength); + break; + } + + if (A_FAILED(status)) { + break; + } + + status = A_OK; + + } while (FALSE); + + if (sk >= 0) { + close(sk); + } + + return status; +} + +#define AFH_CHANNEL_MAP_BYTES 10 + +typedef struct _WLAN_CHANNEL_MAP { + A_UCHAR Map[AFH_CHANNEL_MAP_BYTES]; +} WLAN_CHANNEL_MAP; + +#define MAX_WLAN_CHANNELS 14 + +typedef struct _WLAN_CHANNEL_RANGE { + int ChannelNumber; + int Center; /* in Mhz */ +} WLAN_CHANNEL_RANGE; + +const WLAN_CHANNEL_RANGE g_ChannelTable[MAX_WLAN_CHANNELS] = { + { 1 , 2412}, + { 2 , 2417}, + { 3 , 2422}, + { 4 , 2427}, + { 5 , 2432}, + { 6 , 2437}, + { 7 , 2442}, + { 8 , 2447}, + { 9 , 2452}, + { 10 , 2457}, + { 11 , 2462}, + { 12 , 2467}, + { 13 , 2472}, + { 14 , 2484}, +}; + +static WLAN_CHANNEL_MAP g_ChannelMapTable[MAX_WLAN_CHANNELS + 1] = { + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 0 -- no WLAN */ + { {0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 1 */ + { {0x0F,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 2 */ + { {0xFF,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 3 */ + { {0xFF,0x3F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 4 */ + { {0xFF,0xFF,0x07,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x7F}}, /* 5 */ + { {0xFF,0xFF,0xFF,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F}}, /* 6 */ + { {0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0x7F}}, /* 7 */ + { {0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFE,0xFF,0x7F}}, /* 8 */ + { {0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xC0,0xFF,0x7F}}, /* 9 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF8,0x7F}}, /* 10 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x7F}}, /* 11 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x60}}, /* 12 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00}}, /* 13 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00}}, /* 14 */ +}; + +#define AFH_COMMAND_COMPLETE_TIMEOUT_MS 2000 + +static int LookUpChannel(int FreqMhz) +{ + int i; + + if (FreqMhz == 0) { + /* not connected */ + return 0; + } + + for (i = 0; i < MAX_WLAN_CHANNELS; i++) { + if (FreqMhz <= g_ChannelTable[i].Center) { + break; + } + } + return (i < MAX_WLAN_CHANNELS) ? g_ChannelTable[i].ChannelNumber : 0; +} + +static A_STATUS IssueAFHChannelClassification(ABF_BT_INFO *pAbfBtInfo, int CurrentWLANChannel) +{ + A_UCHAR evtBuffer[HCI_MAX_EVENT_SIZE]; + A_STATUS status; + A_UCHAR *eventPtr; + int eventLen; + A_UCHAR *pChannelMap; + + A_INFO("WLAN Operating Channel: %d \n", CurrentWLANChannel); + + if (CurrentWLANChannel > MAX_WLAN_CHANNELS) { + /* check if this is expressed in Mhz */ + if (CurrentWLANChannel >= 2412) { + /* convert Mhz into a channel number */ + CurrentWLANChannel = LookUpChannel(CurrentWLANChannel); + } else { + return A_ERROR; + } + } + + pChannelMap = &(g_ChannelMapTable[CurrentWLANChannel].Map[0]); + + do { + + status = IssueHCICommand(pAbfBtInfo, + cmd_opcode_pack(3,0x3F), + pChannelMap, + AFH_CHANNEL_MAP_BYTES, + AFH_COMMAND_COMPLETE_TIMEOUT_MS, + evtBuffer, + sizeof(evtBuffer), + &eventPtr, + &eventLen); + + + if (A_FAILED(status)) { + break; + } + + status = A_ERROR; + + if (eventPtr == NULL) { + A_ERR("[%s] Failed to capture AFH command complete event \n", __FUNCTION__); + break; + } + + if (eventLen < (sizeof(evt_cmd_complete) + 1)) { + A_ERR("[%s] not enough bytes in AFH command complete event %d \n", __FUNCTION__, eventLen); + break; + } + + /* check status parameter that follows the command complete event body */ + if (eventPtr[sizeof(evt_cmd_complete)] != 0) { + A_ERR("[%s] AFH command complete event indicated failure : %d \n", __FUNCTION__, + eventPtr[sizeof(evt_cmd_complete)]); + break; + } + + A_INFO(" AFH Command successfully issued \n"); + //A_DUMP_BUFFER(pChannelMap, AFH_CHANNEL_MAP_BYTES, "AFH Channel Classification Map"); + + status = A_OK; + + } while (FALSE); + + return status; +} + +void IndicateCurrentWLANOperatingChannel(ATHBT_FILTER_INFO *pFilterInfo, int CurrentWLANChannel) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)pFilterInfo->pBtInfo; + ATHBT_FILTER_INFO *pInfo = pAbfBtInfo->pInfo; + + if (NULL == pAbfBtInfo) { + return; + } + + if (pFilterInfo->Flags & ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION) { + IssueAFHChannelClassification(pAbfBtInfo,CurrentWLANChannel); + } + + if(pInfo->Flags & ABF_USE_ONLY_DBUS_FILTERING) { + Abf_IssueAFHViaHciLib(pAbfBtInfo, CurrentWLANChannel); + } +} + +#ifdef BLUEZ4_3 +static void *HCIFilterThread(void *arg) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)arg; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + A_UINT8 buffer[300]; + A_UINT8 *pBuffer; + int eventLen; + + A_INFO("[%s] starting up \n", __FUNCTION__); + + while (1) { + + pBuffer = buffer; + + if (pAbfBtInfo->HCIFilterThreadShutdown) { + break; + } + /* get the packet */ + eventLen = read(pAbfBtInfo->HCIEventListenerSocket, pBuffer, sizeof(buffer)); + + if (eventLen < 0) { + if (!pAbfBtInfo->HCIFilterThreadShutdown) { + A_ERR("[%s] socket error %d \n", __FUNCTION__, eventLen); + } + break; + } + + if (eventLen == 0) { + /* no event */ + continue; + } + + if (eventLen < (1 + HCI_EVENT_HDR_SIZE)) { + A_ERR("[%s] Unknown receive packet! len : %d \n", __FUNCTION__, eventLen); + continue; + } + + /* first byte is a tag for the HCI packet type, we only care about events */ + if (pBuffer[0] == HCI_EVENT_PKT) { + /* pass this raw HCI event to the filter core */ + AthBtFilterHciEvent(pInstance,&pBuffer[1],eventLen - 1); + A_UINT8 *eventCode = &pBuffer[1]; + /* revive deprecated "DiscoveryCompleted" signal in BlueZ 4.x */ + if (*eventCode == EVT_INQUIRY_COMPLETE) { + A_DEBUG("Device Inquiry Completed\n"); + pAbfBtInfo->btInquiryState &= ~(1 << 0); + if(!pAbfBtInfo->btInquiryState) { + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + if (*eventCode == EVT_PIN_CODE_REQ) { + A_DEBUG("Pin Code Request\n"); + pAbfBtInfo->btInquiryState |= (1 << 0xF); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); + } + if (*eventCode == EVT_LINK_KEY_NOTIFY) { + A_DEBUG("link key notify\n"); + pAbfBtInfo->btInquiryState &= ~(1 << 0xF); + if(!pAbfBtInfo->btInquiryState) { + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + + if(*eventCode == EVT_CONN_COMPLETE) { + A_DEBUG("Conn complete\n"); + pAbfBtInfo->btInquiryState &= ~(1 << 2); + if(!pAbfBtInfo->btInquiryState) { + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + /* revive deprecated "DiscoveryStarted" signal by capturing INQUIRY commands */ + } else if (pBuffer[0] == HCI_COMMAND_PKT) { + A_UINT16 *packedOpCode = (A_UINT16 *)&pBuffer[1]; + if(cmd_opcode_ogf(*packedOpCode) == 0x1 && + cmd_opcode_ocf(*packedOpCode) == 0x5 ) + { + A_DEBUG("Bt-Connect\n"); + pAbfBtInfo->btInquiryState |= (1 << 2); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); + } + + + if (*packedOpCode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY) + || *packedOpCode == cmd_opcode_pack(OGF_LINK_CTL, OCF_PERIODIC_INQUIRY)) { + // AthBtFilterHciEvent(pInstance,&pBuffer[1],eventLen - 1); + A_DEBUG("Device Inquiry Started\n"); + pAbfBtInfo->btInquiryState |= (1 << 0); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); + } else if (*packedOpCode == cmd_opcode_pack(OGF_LINK_CTL, OCF_CREATE_CONN)) { + /* "Connected" signal is deprecated and won't record BD_ADDR of remote device connected */ + ba2str((const bdaddr_t *)&pBuffer[4], &pAbfBtInfo->DefaultRemoteAudioDeviceAddress[0]); + } + } else { + A_ERR("[%s] Unsupported packet type : %d \n", __FUNCTION__, buffer[0]); + continue; + } + } + + A_INFO("[%s] exiting \n", __FUNCTION__); + + return NULL; +} + +#else + +static void *HCIFilterThread(void *arg) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)arg; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + A_UINT8 buffer[300]; + A_UINT8 *pBuffer; + int eventLen; + + A_INFO("[%s] starting up \n", __FUNCTION__); + + while (1) { + + pBuffer = buffer; + + if (pAbfBtInfo->HCIFilterThreadShutdown) { + break; + } + + /* get the packet */ + eventLen = read(pAbfBtInfo->HCIEventListenerSocket, pBuffer, sizeof(buffer)); + + if (eventLen < 0) { + if (!pAbfBtInfo->HCIFilterThreadShutdown) { + A_ERR("[%s] socket error %d \n", __FUNCTION__, eventLen); + } + break; + } + + if (eventLen == 0) { + /* no event */ + continue; + } + + if (eventLen < (1 + HCI_EVENT_HDR_SIZE)) { + A_ERR("[%s] Unknown receive packet! len : %d \n", __FUNCTION__, eventLen); + continue; + } + + /* first byte is a tag for the HCI packet type, we only care about events */ + if (pBuffer[0] != HCI_EVENT_PKT) { + A_ERR("[%s] Unsupported packet type : %d \n", __FUNCTION__, buffer[0]); + continue; + } + + /* pass this raw HCI event to the filter core */ + AthBtFilterHciEvent(pInstance,&pBuffer[1],eventLen - 1); + } + + A_INFO("[%s] exiting \n", __FUNCTION__); + + return NULL; +} + +#endif + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.h new file mode 100644 index 000000000000..4bc7c55dc0cb --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus.h @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +#ifndef ABTFILT_BTSTACK_DBUS_H_ +#define ABTFILT_BTSTACK_DBUS_H_ +#include "abtfilt_int.h" +#include + +/*-----------------------------------------------------------------------*/ +/* BT Section */ +#define STRING_SIZE_MAX 128 +#define BD_ADDR_SIZE 6 + + +typedef void (* BT_EVENT_HANDLER)(void *,void *); + +typedef enum { + BT_ADAPTER_ADDED = 0, + BT_ADAPTER_REMOVED, + DEVICE_DISCOVERY_STARTED, + DEVICE_DISCOVERY_FINISHED, + REMOTE_DEVICE_CONNECTED, + REMOTE_DEVICE_DISCONNECTED, + AUDIO_DEVICE_ADDED, + AUDIO_DEVICE_REMOVED, + AUDIO_HEADSET_CONNECTED, + AUDIO_HEADSET_DISCONNECTED, + AUDIO_HEADSET_STREAM_STARTED, + AUDIO_HEADSET_STREAM_STOPPED, + AUDIO_GATEWAY_CONNECTED, /* Not Implemented */ + AUDIO_GATEWAY_DISCONNECTED, /* Not Implemented */ + AUDIO_SINK_CONNECTED, + AUDIO_SINK_DISCONNECTED, + AUDIO_SINK_STREAM_STARTED, + AUDIO_SINK_STREAM_STOPPED, + AUDIO_SOURCE_CONNECTED, /* Not Implemented */ + AUDIO_SOURCE_DISCONNECTED, /* Not Implemented */ + BT_EVENTS_NUM_MAX, +} BT_STACK_EVENT; + +typedef struct _ABF_BT_INFO { + ATHBT_FILTER_INFO *pInfo; + A_MUTEX_OBJECT hWaitEventLock; + A_BOOL AdapterAvailable; + DBusConnection *Bus; + A_UINT8 HCIVersion; + A_UINT16 HCIRevision; + A_UINT8 HCI_LMPVersion; + A_UINT16 HCI_LMPSubVersion; + A_UINT8 RemoteDevice[BD_ADDR_SIZE]; + A_UINT8 HCI_DeviceAddress[BD_ADDR_SIZE]; + A_CHAR HCI_AdapterName[STRING_SIZE_MAX]; + A_CHAR HCI_DeviceName[STRING_SIZE_MAX]; + A_CHAR HCI_ManufacturerName[STRING_SIZE_MAX]; + A_CHAR HCI_ProtocolVersion[STRING_SIZE_MAX]; + A_BOOL AdapterCbRegistered; + A_CHAR DefaultAudioDeviceName[STRING_SIZE_MAX]; + A_CHAR DefaultRemoteAudioDeviceAddress[32]; + A_CHAR DefaultRemoteAudioDeviceVersion[32]; + A_UINT8 DefaultAudioDeviceLmpVersion; + A_BOOL DefaultAudioDeviceAvailable; + A_BOOL AudioCbRegistered; + A_UCHAR CurrentSCOLinkType; + int AdapterId; + int HCIEventListenerSocket; + A_TASK_HANDLE hBtHCIFilterThread; + A_BOOL HCIFilterThreadCreated; + A_BOOL HCIFilterThreadShutdown; + BT_EVENT_HANDLER SignalHandlers[BT_EVENTS_NUM_MAX]; + A_BOOL DefaultRemoteAudioDevicePropsValid; + A_BOOL ThreadCreated; + A_UINT32 btInquiryState; +} ABF_BT_INFO; + +#endif /*ABTFILT_BTSTACK_DBUS_H_*/ diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.c new file mode 100644 index 000000000000..c9018366e529 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.c @@ -0,0 +1,1855 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +/* + * Bluetooth Filter - BT module + * + */ +static const char athId[] __attribute__ ((unused)) = "$Id: //depot/sw/releases/olca3.1-RC/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.c#1 $"; + +#include "abtfilt_bluez_dbus_glib.h" + +#include +#undef HCI_INQUIRY +#include +#include +#include +#include + +/* Definitions */ +#define BLUEZ_NAME "org.bluez" +#define BLUEZ_PATH "/org/bluez" +#define ADAPTER_INTERFACE "org.bluez.Adapter" +#define MANAGER_INTERFACE "org.bluez.Manager" +#define AUDIO_MANAGER_PATH "/org/bluez/audio" +#define AUDIO_SINK_INTERFACE "org.bluez.audio.Sink" +#define AUDIO_SOURCE_INTERFACE "org.bluez.audio.Source" +#define AUDIO_MANAGER_INTERFACE "org.bluez.audio.Manager" +#define AUDIO_HEADSET_INTERFACE "org.bluez.audio.Headset" +#define AUDIO_GATEWAY_INTERFACE "org.bluez.audio.Gateway" +#define AUDIO_DEVICE_INTERFACE "org.bluez.audio.Device" + +#define BTEV_GET_BT_CONN_LINK_TYPE(p) ((p)[9]) +#define BTEV_GET_TRANS_INTERVAL(p) ((p)[10]) +#define BTEV_GET_RETRANS_INTERVAL(p) ((p)[11]) +#define BTEV_GET_RX_PKT_LEN(p) ((A_UINT16)((p)[12]) | (((A_UINT16)((p)[13])) << 8)) +#define BTEV_GET_TX_PKT_LEN(p) ((A_UINT16)((p)[14]) | (((A_UINT16)((p)[15])) << 8)) +#define BTEV_CMD_COMPLETE_GET_OPCODE(p) ((A_UINT16)((p)[1]) | (((A_UINT16)((p)[2])) << 8)) +#define BTEV_CMD_COMPLETE_GET_STATUS(p) ((p)[3]) + +typedef enum { + BT_ADAPTER_ADDED = 0, + BT_ADAPTER_REMOVED, + DEVICE_DISCOVERY_STARTED, + DEVICE_DISCOVERY_FINISHED, + REMOTE_DEVICE_CONNECTED, + REMOTE_DEVICE_DISCONNECTED, + AUDIO_DEVICE_ADDED, + AUDIO_DEVICE_REMOVED, + AUDIO_HEADSET_CONNECTED, + AUDIO_HEADSET_DISCONNECTED, + AUDIO_HEADSET_STREAM_STARTED, + AUDIO_HEADSET_STREAM_STOPPED, + AUDIO_GATEWAY_CONNECTED, /* Not Implemented */ + AUDIO_GATEWAY_DISCONNECTED, /* Not Implemented */ + AUDIO_SINK_CONNECTED, + AUDIO_SINK_DISCONNECTED, + AUDIO_SINK_STREAM_STARTED, + AUDIO_SINK_STREAM_STOPPED, + AUDIO_SOURCE_CONNECTED, /* Not Implemented */ + AUDIO_SOURCE_DISCONNECTED, /* Not Implemented */ + BT_EVENTS_NUM_MAX, +} BT_STACK_EVENT; + +typedef enum { + PROXY_INVALID = 0, + DEVICE_MANAGER, + DEVICE_ADAPTER, + AUDIO_MANAGER, + AUDIO_HEADSET, + AUDIO_GATEWAY, + AUDIO_SOURCE, + AUDIO_SINK, +} BT_PROXY_TYPE; + +typedef enum { + ARG_INVALID = 0, + ARG_NONE, + ARG_STRING, +} BT_CB_TYPE; + +typedef struct _BT_NOTIFICATION_CONFIG_PARAMS { + const char *name; + BT_PROXY_TYPE proxy; + BT_CB_TYPE arg; +} BT_NOTIFICATION_CONFIG_PARAMS; + +static BT_NOTIFICATION_CONFIG_PARAMS g_NotificationConfig[BT_EVENTS_NUM_MAX] = +{ + /* BT_ADAPTER_ADDED */ + {"AdapterAdded", DEVICE_MANAGER, ARG_STRING}, + /* BT_ADAPTER_REMOVED */ + {"AdapterRemoved", DEVICE_MANAGER, ARG_STRING}, + /* DEVICE_DISCOVERY_STARTED */ + {"DiscoveryStarted", DEVICE_ADAPTER, ARG_NONE}, + /* DEVICE_DISCOVERY_FINISHED */ + {"DiscoveryCompleted", DEVICE_ADAPTER, ARG_NONE}, + /* REMOTE_DEVICE_CONNECTED */ + {"RemoteDeviceConnected", DEVICE_ADAPTER, ARG_STRING}, + /* REMOTE_DEVICE_DISCONNECTED */ + {"RemoteDeviceDisconnected", DEVICE_ADAPTER, ARG_STRING}, + /* AUDIO_DEVICE_ADDED */ + {"DeviceCreated", AUDIO_MANAGER, ARG_STRING}, + /* AUDIO_DEVICE_REMOVED */ + {"DeviceRemoved", AUDIO_MANAGER, ARG_STRING}, + /* AUDIO_HEADSET_CONNECTED */ + {"Connected", AUDIO_HEADSET, ARG_NONE}, + /* AUDIO_HEADSET_DISCONNECTED */ + {"Disconnected", AUDIO_HEADSET, ARG_NONE}, + /* AUDIO_HEADSET_STREAM_STARTED */ + {"Playing", AUDIO_HEADSET, ARG_NONE}, + /* AUDIO_HEADSET_STREAM_STOPPED */ + {"Stopped", AUDIO_HEADSET, ARG_NONE}, + /* AUDIO_GATEWAY_CONNECTED */ + {NULL, PROXY_INVALID, ARG_INVALID}, + /* AUDIO_GATEWAY_DISCONNECTED */ + {NULL, PROXY_INVALID, ARG_INVALID}, + /* AUDIO_SINK_CONNECTED */ + {"Connected", AUDIO_SINK, ARG_NONE}, + /* AUDIO_SINK_DISCONNECTED */ + {"Disconnected", AUDIO_SINK, ARG_NONE}, + /* AUDIO_SINK_STREAM_STARTED */ + {"Playing", AUDIO_SINK, ARG_NONE}, + /* AUDIO_SINK_STREAM_STOPPED */ + {"Stopped", AUDIO_SINK, ARG_NONE}, + /* AUDIO_SOURCE_CONNECTED */ + {NULL, PROXY_INVALID, ARG_INVALID}, + /* AUDIO_SOURCE_DISCONNECTED */ + {NULL, PROXY_INVALID, ARG_INVALID}, +}; + +typedef struct { + char *str; + unsigned int val; +} hci_map; + +static const hci_map ver_map[] = { + { "1.0b", 0x00 }, + { "1.1", 0x01 }, + { "1.2", 0x02 }, + { "2.0", 0x03 }, + { "2.1", 0x04 }, + { NULL } +}; + +/* Function Prototypes */ +static void BtAdapterAdded(DBusGProxy *proxy, const char *string, + gpointer user_data); +static void BtAdapterRemoved(DBusGProxy *proxy, const char *string, + gpointer user_data); +static A_STATUS AcquireBtAdapter(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseBTAdapter(ABF_BT_INFO *pAbfBtInfo); +static void *BtEventThread(void *arg); +static void RegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, + BT_STACK_EVENT event, GCallback handler); +static void DeRegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, + BT_STACK_EVENT event, GCallback handler); +static A_STATUS GetAdapterInfo(ABF_BT_INFO *pAbfBtInfo); +static void RemoteDeviceDisconnected(DBusGProxy *proxy, const char *string, + gpointer user_data); +static void RemoteDeviceConnected(DBusGProxy *proxy, const char *string, + gpointer user_data); +static void AudioDeviceAdded(DBusGProxy *proxy, const char *string, + gpointer user_data); +static void AudioDeviceRemoved(DBusGProxy *proxy, const char *string, + gpointer user_data); +static void DeviceDiscoveryStarted(DBusGProxy *proxy, gpointer user_data); +static void DeviceDiscoveryFinished(DBusGProxy *proxy, gpointer user_data); +static void AudioHeadsetConnected(DBusGProxy *proxy, gpointer user_data); +static void AudioHeadsetDisconnected(DBusGProxy *proxy, gpointer user_data); +static void AudioHeadsetStreamStarted(DBusGProxy *proxy, gpointer user_data); +static void AudioHeadsetStreamStopped(DBusGProxy *proxy, gpointer user_data); +static void AudioGatewayConnected(DBusGProxy *proxy, gpointer user_data); +static void AudioGatewayDisconnected(DBusGProxy *proxy, gpointer user_data); +static void AudioSinkConnected(DBusGProxy *proxy, gpointer user_data); +static void AudioSinkDisconnected(DBusGProxy *proxy, gpointer user_data); +static void AudioSinkStreamStarted(DBusGProxy *proxy, gpointer user_data); +static void AudioSinkStreamStopped(DBusGProxy *proxy, gpointer user_data); +static void AudioSourceConnected(DBusGProxy *proxy, gpointer user_data); +static void AudioSourceDisconnected(DBusGProxy *proxy, gpointer user_data); +static A_STATUS CheckAndAcquireDefaultAdapter(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseDefaultAdapter(ABF_BT_INFO *pAbfBtInfo); +static void AcquireDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo); +static void ReleaseDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo); +static void GetBtAudioConnectionProperties(ABF_BT_INFO *pAbfBtInfo, + ATHBT_STATE_INDICATION Indication); +static A_STATUS SetupHciEventFilter(ABF_BT_INFO *pAbfBtInfo); +static void CheckHciEventFilter(ABF_BT_INFO *pAbfBtInfo); +static A_STATUS IssueHCICommand(ABF_BT_INFO *pAbfBtInfo, + A_UINT16 OpCode, + A_UCHAR *pCmdData, + int CmdLength, + int EventRecvTimeoutMS, + A_UCHAR *pEventBuffer, + int MaxLength, + A_UCHAR **ppEventPtr, + int *pEventLength); + +/* APIs exported to other modules */ +A_STATUS +Abf_BtStackNotificationInit(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 Flags) +{ + A_STATUS status; + GMainLoop *mainloop; + ATHBT_FILTER_INFO *pInfo; + ABF_BT_INFO *pAbfBtInfo; + + pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + if (pInfo->pBtInfo) { + return A_OK; + } + + pAbfBtInfo = (ABF_BT_INFO *)A_MALLOC(sizeof(ABF_BT_INFO)); + A_MEMZERO(pAbfBtInfo,sizeof(ABF_BT_INFO)); + + A_MUTEX_INIT(&pAbfBtInfo->hWaitEventLock); + A_COND_INIT(&pAbfBtInfo->hWaitEvent); + A_MEMZERO(pAbfBtInfo, sizeof(ABF_BT_INFO)); + + pAbfBtInfo->Flags = Flags; + + if (pAbfBtInfo->Flags & ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION) { + A_INFO("AFH Classification Command will be issued on WLAN connect/disconnect \n"); + } + + /* Set up the main loop */ + mainloop = g_main_loop_new(NULL, FALSE); + pAbfBtInfo->AdapterAvailable = FALSE; + pAbfBtInfo->Mainloop = mainloop; + pAbfBtInfo->Loop = TRUE; + pAbfBtInfo->pInfo = pInfo; + pAbfBtInfo->HCIEventListenerSocket = -1; + + /* Spawn a thread which will be used to process events from BT */ + status = A_TASK_CREATE(&pInfo->hBtThread, BtEventThread, pAbfBtInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to spawn a BT thread\n", __FUNCTION__); + return A_ERROR; + } + + pInfo->pBtInfo = pAbfBtInfo; + A_INFO("BT Stack Notification init complete\n"); + + return A_OK; +} + +void +Abf_BtStackNotificationDeInit(ATH_BT_FILTER_INSTANCE *pInstance) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_BT_INFO *pAbfBtInfo = pInfo->pBtInfo; + + if (!pAbfBtInfo) return; + + if (pAbfBtInfo->Mainloop != NULL) { + /* Terminate and wait for the BT Event Handler task to finish */ + A_MUTEX_LOCK(&pAbfBtInfo->hWaitEventLock); + if (pAbfBtInfo->Loop) { + pAbfBtInfo->Loop = FALSE; + A_COND_WAIT(&pAbfBtInfo->hWaitEvent, &pAbfBtInfo->hWaitEventLock, + WAITFOREVER); + } + A_MUTEX_UNLOCK(&pAbfBtInfo->hWaitEventLock); + } + + /* Flush all the BT actions from the filter core TODO */ + + /* Free the remaining resources */ + g_main_loop_unref(pAbfBtInfo->Mainloop); + pAbfBtInfo->AdapterAvailable = FALSE; + pInfo->pBtInfo = NULL; + A_MUTEX_DEINIT(&pAbfBtInfo->hWaitEventLock); + A_COND_DEINIT(&pAbfBtInfo->hWaitEvent); + A_MEMZERO(pAbfBtInfo, sizeof(ABF_BT_INFO)); + A_FREE(pAbfBtInfo); + + A_INFO("BT Stack Notification de-init complete\n"); +} + +/* Internal functions */ + +static gboolean MainLoopQuitCheck(gpointer arg) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)arg; + + /* this is the only way to end a glib main loop + without creating an external g_source, this check is periodically + made to check the shutdown flag */ + if (!pAbfBtInfo->Loop) { + g_main_loop_quit(pAbfBtInfo->Mainloop); + return FALSE; + } + + /* reschedule */ + return TRUE; +} + +static void * +BtEventThread(void *arg) +{ + DBusGConnection *bus; + GError *error = NULL; + DBusGProxy *manager; + GLogLevelFlags fatal_mask; + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)arg; + + A_INFO("Starting the BT Event Handler task\n"); + + g_type_init(); + + fatal_mask = g_log_set_always_fatal(G_LOG_FATAL_MASK); + fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; + g_log_set_always_fatal(fatal_mask); + + do { + bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (!bus) { + A_ERR("[%s] Couldn't connect to system bus: %d\n", + __FUNCTION__, error); + break; + } + + pAbfBtInfo->Bus = bus; + manager = dbus_g_proxy_new_for_name(bus, BLUEZ_NAME, BLUEZ_PATH, + MANAGER_INTERFACE); + if (!manager) { + A_ERR("[%s] Failed to get name owner\n", __FUNCTION__); + dbus_g_connection_unref(bus); + pAbfBtInfo->Bus = NULL; + break; + } + pAbfBtInfo->DeviceManager = manager; + + /* check for default adapter at startup */ + CheckAndAcquireDefaultAdapter(pAbfBtInfo); + + RegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_ADDED, + G_CALLBACK(BtAdapterAdded)); + RegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_REMOVED, + G_CALLBACK(BtAdapterRemoved)); + g_timeout_add(1000, MainLoopQuitCheck, pAbfBtInfo); + g_main_loop_run(pAbfBtInfo->Mainloop); + + DeRegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_ADDED, + G_CALLBACK(BtAdapterAdded)); + DeRegisterBtStackEventCb(pAbfBtInfo, BT_ADAPTER_REMOVED, + G_CALLBACK(BtAdapterRemoved)); + + ReleaseDefaultAdapter(pAbfBtInfo); + + g_object_unref(pAbfBtInfo->DeviceManager); + pAbfBtInfo->DeviceManager = NULL; + + /* Release the system bus */ + dbus_g_connection_unref(bus); + pAbfBtInfo->Bus = NULL; + } while (FALSE); + + /* Clean up the resources allocated in this task */ + A_INFO("Terminating the BT Event Handler task\n"); + A_MUTEX_LOCK(&pAbfBtInfo->hWaitEventLock); + pAbfBtInfo->Loop = FALSE; + A_COND_SIGNAL(&pAbfBtInfo->hWaitEvent); + A_MUTEX_UNLOCK(&pAbfBtInfo->hWaitEventLock); + + return NULL; +} + +static A_STATUS +CheckAndAcquireDefaultAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status = A_OK; + + do { + + if (pAbfBtInfo->AdapterAvailable) { + /* already available */ + break; + } + + /* acquire the adapter */ + status = AcquireBtAdapter(pAbfBtInfo); + + } while (FALSE); + + return status; +} + +static void ReleaseDefaultAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + + if (pAbfBtInfo->AdapterAvailable) { + /* Release the BT adapter */ + ReleaseBTAdapter(pAbfBtInfo); + A_INFO("[%s] BT Adapter Removed\n",pAbfBtInfo->AdapterName); + } + + A_MEMZERO(pAbfBtInfo->AdapterName, sizeof(pAbfBtInfo->AdapterName)); + +} +/* Event Notifications */ +static void +BtAdapterAdded(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + A_DEBUG("BtAdapterAdded Proxy Callback ... \n"); + + /* BUG!!!, the BtAdapterAdded callback is indicated too early by the BT service, on some systems + * the method call to "DefaultAdapter" through the Manager interface will fail because no + * default adapter exist yet even though this callback was indicated (there should be a default) + * + * Workaround is to delay before acquiring the default adapter. + * Acquiring the BT adapter should not be very infrequent though. + * + * */ + sleep(1); + CheckAndAcquireDefaultAdapter((ABF_BT_INFO *)user_data); +} + + +static void +BtAdapterRemoved(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("BtAdapterRemoved Proxy Callback ... \n"); + + if (!pAbfBtInfo->AdapterAvailable) return; + + if (strcmp(string,pAbfBtInfo->AdapterName) == 0) { + /* the adapter we are watching has been removed */ + ReleaseDefaultAdapter(pAbfBtInfo); + } + +} + +static void +DeviceDiscoveryStarted(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Inquiry Started\n"); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); +} + +static void +DeviceDiscoveryFinished(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Inquiry Completed\n"); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); +} + +static void +RemoteDeviceConnected(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Connected: %s\n", string); + A_STR2ADDR(string, pAbfBtInfo->RemoteDevice); + AthBtIndicateState(pInstance, ATH_BT_CONNECT, STATE_ON); +} + +static void +RemoteDeviceDisconnected(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Device Disconnected: %s\n", string); + A_MEMZERO(pAbfBtInfo->RemoteDevice, sizeof(pAbfBtInfo->RemoteDevice)); + AthBtIndicateState(pInstance, ATH_BT_CONNECT, STATE_OFF); +} + +static void ReleaseDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo) +{ + + if (pAbfBtInfo->AudioCbRegistered) { + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_CONNECTED, + G_CALLBACK(AudioHeadsetConnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_DISCONNECTED, + G_CALLBACK(AudioHeadsetDisconnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STARTED, + G_CALLBACK(AudioHeadsetStreamStarted)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STOPPED, + G_CALLBACK(AudioHeadsetStreamStopped)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_CONNECTED, + G_CALLBACK(AudioGatewayConnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_DISCONNECTED, + G_CALLBACK(AudioGatewayDisconnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_CONNECTED, + G_CALLBACK(AudioSinkConnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_DISCONNECTED, + G_CALLBACK(AudioSinkDisconnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STARTED, + G_CALLBACK(AudioSinkStreamStarted)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STOPPED, + G_CALLBACK(AudioSinkStreamStopped)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_CONNECTED, + G_CALLBACK(AudioSourceConnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_DISCONNECTED, + G_CALLBACK(AudioSourceDisconnected)); + pAbfBtInfo->AudioCbRegistered = FALSE; + } + + if (pAbfBtInfo->AudioHeadset != NULL) { + g_object_unref(pAbfBtInfo->AudioHeadset); + pAbfBtInfo->AudioHeadset = NULL; + } + + if (pAbfBtInfo->AudioGateway != NULL) { + g_object_unref(pAbfBtInfo->AudioGateway); + pAbfBtInfo->AudioGateway = NULL; + } + + if (pAbfBtInfo->AudioSource != NULL) { + g_object_unref(pAbfBtInfo->AudioSource); + pAbfBtInfo->AudioSource = NULL; + } + + if (pAbfBtInfo->AudioSink != NULL) { + g_object_unref(pAbfBtInfo->AudioSink); + pAbfBtInfo->AudioSink = NULL; + } + + if (pAbfBtInfo->AudioDevice != NULL) { + g_object_unref(pAbfBtInfo->AudioDevice); + pAbfBtInfo->AudioDevice = NULL; + } + + if (pAbfBtInfo->DefaultAudioDeviceAvailable) { + pAbfBtInfo->DefaultAudioDeviceAvailable = FALSE; + A_DEBUG("Default Audio Device Removed: %s\n", pAbfBtInfo->DefaultAudioDeviceName); + A_MEMZERO(pAbfBtInfo->DefaultAudioDeviceName,sizeof(pAbfBtInfo->DefaultAudioDeviceName)); + } + +} + +static void AcquireDefaultAudioDevice(ABF_BT_INFO *pAbfBtInfo) +{ + A_BOOL success = FALSE; + char *audioDevice; + GError *error = NULL; + + do { + + if (pAbfBtInfo->DefaultAudioDeviceAvailable) { + /* already acquired */ + success = TRUE; + break; + } + + A_INFO("Checking for a default audio device .. \n"); + + if (!dbus_g_proxy_call(pAbfBtInfo->AudioManager, + "DefaultDevice", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, + &audioDevice, + G_TYPE_INVALID)) { + A_ERR("[%s] DefaultDevice method call failed \n", __FUNCTION__); + break; + } + + if (error != NULL) { + A_ERR("[%s] Failed to get default audio device: %s \n", __FUNCTION__, error->message); + g_free(error); + break; + } + + strncpy(pAbfBtInfo->DefaultAudioDeviceName, + audioDevice, + sizeof(pAbfBtInfo->DefaultAudioDeviceName)); + + g_free(audioDevice); + + A_INFO("Default Audio Device: %s \n", pAbfBtInfo->DefaultAudioDeviceName); + + pAbfBtInfo->DefaultAudioDeviceAvailable = TRUE; + + /* get various proxies for the audio device */ + + pAbfBtInfo->AudioHeadset = dbus_g_proxy_new_for_name(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_HEADSET_INTERFACE); + if (NULL == pAbfBtInfo->AudioHeadset) { + A_ERR("[%s] Failed to get audio headset interface \n", __FUNCTION__); + break; + } + + pAbfBtInfo->AudioGateway = dbus_g_proxy_new_for_name(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_GATEWAY_INTERFACE); + if (NULL == pAbfBtInfo->AudioGateway) { + A_ERR("[%s] Failed to get audio gateway interface \n", __FUNCTION__); + break; + } + + pAbfBtInfo->AudioSource = dbus_g_proxy_new_for_name(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_SOURCE_INTERFACE); + + if (NULL == pAbfBtInfo->AudioSource) { + A_ERR("[%s] Failed to get audio source interface \n", __FUNCTION__); + break; + } + + pAbfBtInfo->AudioSink = dbus_g_proxy_new_for_name(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_SINK_INTERFACE); + + if (NULL == pAbfBtInfo->AudioSink) { + A_ERR("[%s] Failed to get audio sink interface \n", __FUNCTION__); + break; + } + + pAbfBtInfo->AudioDevice = dbus_g_proxy_new_for_name(pAbfBtInfo->Bus, + BLUEZ_NAME, + pAbfBtInfo->DefaultAudioDeviceName, + AUDIO_DEVICE_INTERFACE); + + if (NULL == pAbfBtInfo->AudioDevice) { + A_ERR("[%s] Failed to get audio device interface \n", __FUNCTION__); + break; + } + + /* Register for audio specific events */ + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_CONNECTED, + G_CALLBACK(AudioHeadsetConnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_DISCONNECTED, + G_CALLBACK(AudioHeadsetDisconnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STARTED, + G_CALLBACK(AudioHeadsetStreamStarted)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_HEADSET_STREAM_STOPPED, + G_CALLBACK(AudioHeadsetStreamStopped)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_CONNECTED, + G_CALLBACK(AudioGatewayConnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_GATEWAY_DISCONNECTED, + G_CALLBACK(AudioGatewayDisconnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_CONNECTED, + G_CALLBACK(AudioSinkConnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_DISCONNECTED, + G_CALLBACK(AudioSinkDisconnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STARTED, + G_CALLBACK(AudioSinkStreamStarted)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SINK_STREAM_STOPPED, + G_CALLBACK(AudioSinkStreamStopped)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_CONNECTED, + G_CALLBACK(AudioSourceConnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_SOURCE_DISCONNECTED, + G_CALLBACK(AudioSourceDisconnected)); + + pAbfBtInfo->AudioCbRegistered = TRUE; + + success = TRUE; + + } while (FALSE); + + if (!success) { + /* cleanup */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + } +} + +static void +AudioDeviceAdded(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("Audio Device Added: %s\n", string); + /* release current one if any */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + /* re-acquire the new default, it could be the same one */ + AcquireDefaultAudioDevice(pAbfBtInfo); + +} + +static void +AudioDeviceRemoved(DBusGProxy *proxy, const char *string, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + + A_DEBUG("Audio Device Removed: %s\n", string); + + if (strcmp(string,pAbfBtInfo->DefaultAudioDeviceName) == 0) { + /* release current one */ + ReleaseDefaultAudioDevice(pAbfBtInfo); + /* re-acquire the new default (if any) */ + AcquireDefaultAudioDevice(pAbfBtInfo); + } + +} + +static void +AudioHeadsetConnected(DBusGProxy *proxy, gpointer user_data) +{ + A_DEBUG("Audio Headset Connected\n"); +} + +static void +AudioHeadsetDisconnected(DBusGProxy *proxy, gpointer user_data) +{ + A_DEBUG("Audio Headset Disconnected\n"); +} + +static void +AudioHeadsetStreamStarted(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Audio Headset Stream Started\n"); + /* get properties of this headset connection */ + GetBtAudioConnectionProperties(pAbfBtInfo, ATH_BT_SCO); + /* make the indication */ + AthBtIndicateState(pInstance, + pAbfBtInfo->CurrentSCOLinkType == SCO_LINK ? ATH_BT_SCO : ATH_BT_ESCO, + STATE_ON); +} + +static void +AudioHeadsetStreamStopped(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + /* This event can also be used to indicate the SCO state */ + A_DEBUG("Audio Headset Stream Stopped\n"); + AthBtIndicateState(pInstance, + pAbfBtInfo->CurrentSCOLinkType == SCO_LINK ? ATH_BT_SCO : ATH_BT_ESCO, + STATE_OFF); +} + +static void +AudioGatewayConnected(DBusGProxy *proxy, gpointer user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Gateway Connected\n"); +} + +static void +AudioGatewayDisconnected(DBusGProxy *proxy, gpointer user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Gateway disconnected\n"); +} + +static void +AudioSinkConnected(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + A_DEBUG("Audio Sink Connected\n"); + /* get connection properties */ + GetBtAudioConnectionProperties(pAbfBtInfo, ATH_BT_A2DP); +} + +static void +AudioSinkDisconnected(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Audio Sink Disconnected\n"); + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_OFF); +} + +static void +AudioSinkStreamStarted(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + A_DEBUG("Audio Sink Stream Started\n"); + + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_ON); +} + +static void +AudioSinkStreamStopped(DBusGProxy *proxy, gpointer user_data) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)user_data; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + A_DEBUG("Audio Sink Stream Stopped\n"); + AthBtIndicateState(pInstance, ATH_BT_A2DP, STATE_OFF); +} + +static void +AudioSourceConnected(DBusGProxy *proxy, gpointer user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Source Connected\n"); +} + +static void +AudioSourceDisconnected(DBusGProxy *proxy, gpointer user_data) +{ + /* Not yet implemented */ + A_DEBUG("Audio Source Disconnected\n"); +} + +/* (De)Registration */ +static DBusGProxy * +GetDBusProxy(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event) +{ + DBusGProxy *proxy = NULL; + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + + pNotificationConfig = &g_NotificationConfig[event]; + if (pNotificationConfig->proxy == DEVICE_MANAGER) { + proxy = pAbfBtInfo->DeviceManager; + } else if (pNotificationConfig->proxy == DEVICE_ADAPTER) { + proxy = pAbfBtInfo->DeviceAdapter; + } else if (pNotificationConfig->proxy == AUDIO_MANAGER) { + proxy = pAbfBtInfo->AudioManager; + } else if (pNotificationConfig->proxy == AUDIO_HEADSET) { + proxy = pAbfBtInfo->AudioHeadset; + } else if (pNotificationConfig->proxy == AUDIO_SINK) { + proxy = pAbfBtInfo->AudioSink; + } else { + A_ERR("[%s] Unknown proxy %d for event : %d \n", __FUNCTION__, pNotificationConfig->proxy, event); + } + + return proxy; +} + +static void +RegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event, + GCallback handler) +{ + const char *name; + DBusGProxy *proxy; + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + + pNotificationConfig = &g_NotificationConfig[event]; + name = pNotificationConfig->name; + + if (event >= BT_EVENTS_NUM_MAX) { + A_ERR("[%s] Unknown Event: %d\n", __FUNCTION__, event); + return; + } + + if (pNotificationConfig->proxy == PROXY_INVALID) { + /* not supported yet, so ignore registration */ + return; + } + + if ((proxy = GetDBusProxy(pAbfBtInfo, event)) == NULL) { + A_ERR("[%s] Unknown Proxy: %d (event:%d) \n", __FUNCTION__, + pNotificationConfig->proxy, event); + return; + } + + if (pNotificationConfig->arg == ARG_NONE) { + dbus_g_proxy_add_signal(proxy, name, G_TYPE_INVALID); + } else if (pNotificationConfig->arg == ARG_STRING) { + dbus_g_proxy_add_signal(proxy, name, G_TYPE_STRING, + G_TYPE_INVALID); + } else { + A_ERR("[%s] Unkown Arg Type: %d\n", __FUNCTION__, + pNotificationConfig->arg); + return; + } + + dbus_g_proxy_connect_signal(proxy, name, handler, (void *)pAbfBtInfo, + NULL); +} + +static void +DeRegisterBtStackEventCb(ABF_BT_INFO *pAbfBtInfo, BT_STACK_EVENT event, + GCallback handler) +{ + const char *name; + DBusGProxy *proxy; + BT_NOTIFICATION_CONFIG_PARAMS *pNotificationConfig; + + pNotificationConfig = &g_NotificationConfig[event]; + name = pNotificationConfig->name; + + if (event >= BT_EVENTS_NUM_MAX) { + A_ERR("[%s] Unknown Event: %d\n", __FUNCTION__, event); + return; + } + + if (pNotificationConfig->proxy == PROXY_INVALID) { + /* not supported yet, so ignore de-registration */ + return; + } + + if ((proxy = GetDBusProxy(pAbfBtInfo, event)) == NULL) { + A_ERR("[%s] Unknown Proxy: %d\n", __FUNCTION__, + pNotificationConfig->proxy); + return; + } + + dbus_g_proxy_disconnect_signal(proxy, name, handler, (void *)pAbfBtInfo); +} + +/* Misc */ +static A_STATUS +AcquireBtAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + DBusGProxy *DeviceAdapter, *AudioManager; + DBusGConnection *bus = pAbfBtInfo->Bus; + A_STATUS status = A_ERROR; + char *adapterName; + GError *error = NULL; + char *hciName; + + do { + + if (!dbus_g_proxy_call(pAbfBtInfo->DeviceManager, + "DefaultAdapter", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, + &adapterName, + G_TYPE_INVALID)) { + A_ERR("[%s] DefaultAdapter Method call failure \n", __FUNCTION__); + break; + } + + if (error != NULL) { + A_ERR("[%s] Failed to get default adapter: %s \n", __FUNCTION__, error->message); + g_free(error); + break; + } + + strcpy(pAbfBtInfo->AdapterName, adapterName); + + /* assume ID 0 */ + pAbfBtInfo->AdapterId = 0; + + if ((hciName = strstr(pAbfBtInfo->AdapterName, "hci")) != NULL) { + /* get the number following the hci name, this is the ID used for + * socket calls to the HCI layer */ + pAbfBtInfo->AdapterId = (int)hciName[3] - (int)'0'; + if (pAbfBtInfo->AdapterId < 0) { + pAbfBtInfo->AdapterId = 0; + } + } + + if (!A_SUCCESS(SetupHciEventFilter(pAbfBtInfo))) { + break; + } + + g_free(adapterName); + + DeviceAdapter = dbus_g_proxy_new_for_name(bus, BLUEZ_NAME, + pAbfBtInfo->AdapterName, + ADAPTER_INTERFACE); + if (!DeviceAdapter) { + A_ERR("[%s] Failed to get device adapter (%s) \n", __FUNCTION__, pAbfBtInfo->AdapterName); + break; + } + + AudioManager = dbus_g_proxy_new_for_name(bus, BLUEZ_NAME, + AUDIO_MANAGER_PATH, + AUDIO_MANAGER_INTERFACE); + if (!AudioManager) { + A_ERR("[%s] Failed to get name owner\n", __FUNCTION__); + break; + } + + pAbfBtInfo->DeviceAdapter = DeviceAdapter; + pAbfBtInfo->AudioManager = AudioManager; + + GetAdapterInfo(pAbfBtInfo); + + pAbfBtInfo->pInfo->LMPVersion = pAbfBtInfo->LMPVersion; + pAbfBtInfo->AdapterAvailable = TRUE; + + /* Register to get notified of different stack events */ + RegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_STARTED, + G_CALLBACK(DeviceDiscoveryStarted)); + RegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_FINISHED, + G_CALLBACK(DeviceDiscoveryFinished)); + RegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_CONNECTED, + G_CALLBACK(RemoteDeviceConnected)); + RegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_DISCONNECTED, + G_CALLBACK(RemoteDeviceDisconnected)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_ADDED, + G_CALLBACK(AudioDeviceAdded)); + RegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_REMOVED, + G_CALLBACK(AudioDeviceRemoved)); + + pAbfBtInfo->AdapterCbRegistered = TRUE; + + A_INFO("[%s] BT Adapter Added\n",pAbfBtInfo->AdapterName); + + /* acquire default audio device */ + AcquireDefaultAudioDevice(pAbfBtInfo); + + + status = A_OK; + + } while (FALSE); + + return status; +} + +static void +ReleaseBTAdapter(ABF_BT_INFO *pAbfBtInfo) +{ + + if (pAbfBtInfo->AdapterCbRegistered) { + pAbfBtInfo->AdapterCbRegistered = FALSE; + /* Free the resources held for the event handlers */ + DeRegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_STARTED, + G_CALLBACK(DeviceDiscoveryStarted)); + DeRegisterBtStackEventCb(pAbfBtInfo, DEVICE_DISCOVERY_FINISHED, + G_CALLBACK(DeviceDiscoveryFinished)); + DeRegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_CONNECTED, + G_CALLBACK(RemoteDeviceConnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, REMOTE_DEVICE_DISCONNECTED, + G_CALLBACK(RemoteDeviceDisconnected)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_ADDED, + G_CALLBACK(AudioDeviceAdded)); + DeRegisterBtStackEventCb(pAbfBtInfo, AUDIO_DEVICE_REMOVED, + G_CALLBACK(AudioDeviceRemoved)); + } + + ReleaseDefaultAudioDevice(pAbfBtInfo); + + if (pAbfBtInfo->HCIEventListenerSocket >= 0) { + close(pAbfBtInfo->HCIEventListenerSocket); + pAbfBtInfo->HCIEventListenerSocket = -1; + } + + if (pAbfBtInfo->AudioManager != NULL) { + g_object_unref(pAbfBtInfo->AudioManager); + pAbfBtInfo->AudioManager = NULL; + } + + A_MEMZERO(pAbfBtInfo->DeviceAddress, + sizeof(pAbfBtInfo->DeviceAddress)); + A_MEMZERO(pAbfBtInfo->DeviceName, + sizeof(pAbfBtInfo->DeviceName)); + A_MEMZERO(pAbfBtInfo->ManufacturerName, + sizeof(pAbfBtInfo->ManufacturerName)); + A_MEMZERO(pAbfBtInfo->ProtocolVersion, + sizeof(pAbfBtInfo->ProtocolVersion)); + pAbfBtInfo->LMPVersion = 0; + + if (pAbfBtInfo->DeviceAdapter != NULL) { + g_object_unref(pAbfBtInfo->DeviceAdapter); + pAbfBtInfo->DeviceAdapter = NULL; + } + pAbfBtInfo->AdapterAvailable = FALSE; +} + +static A_STATUS +GetAdapterInfo(ABF_BT_INFO *pAbfBtInfo) +{ + int count; + char *reply; + GError *error = NULL; + DBusGProxy *DeviceAdapter; + + if ((DeviceAdapter = pAbfBtInfo->DeviceAdapter) == NULL) return A_ERROR; + + /* Device name */ + if (!dbus_g_proxy_call(DeviceAdapter, "GetName", &error, G_TYPE_INVALID, + G_TYPE_STRING, &reply, G_TYPE_INVALID)) + { + A_ERR("[%s] Failed to complete GetName: %d\n", __FUNCTION__, error); + return A_ERROR; + } + strcpy(pAbfBtInfo->DeviceName, reply); + g_free(reply); + + /* Manufacturer name */ + if (!dbus_g_proxy_call(DeviceAdapter, "GetManufacturer", &error, + G_TYPE_INVALID, G_TYPE_STRING, &reply, + G_TYPE_INVALID)) + { + A_ERR("[%s] Failed to complete GetManufacturer: %d\n", + __FUNCTION__, error); + return A_ERROR; + } + strcpy(pAbfBtInfo->ManufacturerName, reply); + g_free(reply); + + /* Bluetooth protocol Version */ + if (!dbus_g_proxy_call(DeviceAdapter, "GetVersion", &error, G_TYPE_INVALID, + G_TYPE_STRING, &reply, G_TYPE_INVALID)) + { + A_ERR("[%s] Failed to complete GetVersion: %d\n", __FUNCTION__, error); + return A_ERROR; + } + strcpy(pAbfBtInfo->ProtocolVersion, reply); + for (count = 0; + ((count < sizeof(ver_map)/sizeof(hci_map)) && (ver_map[count].str)); + count++) + { + if (strstr(pAbfBtInfo->ProtocolVersion, ver_map[count].str)) { + pAbfBtInfo->LMPVersion = ver_map[count].val; + break; + } + } + g_free(reply); + + /* Device address */ + if (!dbus_g_proxy_call(DeviceAdapter, "GetAddress", &error, G_TYPE_INVALID, + G_TYPE_STRING, &reply, G_TYPE_INVALID)) + { + A_ERR("[%s] Failed to complete GetAddress: %d\n", __FUNCTION__, error); + return A_ERROR; + } + A_STR2ADDR(reply, pAbfBtInfo->DeviceAddress); + g_free(reply); + + A_INFO("BT-HCI Device Address: (%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X)\n", + pAbfBtInfo->DeviceAddress[0], pAbfBtInfo->DeviceAddress[1], + pAbfBtInfo->DeviceAddress[2], pAbfBtInfo->DeviceAddress[3], + pAbfBtInfo->DeviceAddress[4], pAbfBtInfo->DeviceAddress[5]); + A_INFO("BT-HCI Device Name: %s\n", pAbfBtInfo->DeviceName); + A_INFO("BT-HCI Manufacturer Name: %s\n", pAbfBtInfo->ManufacturerName); + A_INFO("BT-HCI Protocol Version: %s\n", pAbfBtInfo->ProtocolVersion); + A_INFO("BT-HCI LMP Version: %d\n", pAbfBtInfo->LMPVersion); + + return A_OK; +} + +#define ABTH_MAX_CONNECTIONS 16 + +static A_STATUS GetConnectedDeviceRole(ABF_BT_INFO *pAbfBtInfo, + A_CHAR *Address, + A_BOOL IsSCO, + A_UCHAR *pRole) +{ + A_STATUS status = A_ERROR; + struct hci_conn_list_req *connList = NULL; + struct hci_conn_info *connInfo = NULL; + int i, sk = -1; + int len; + + do { + + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (sk < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + len = (sizeof(*connInfo)) * ABTH_MAX_CONNECTIONS + sizeof(*connList); + + connList = (struct hci_conn_list_req *)A_MALLOC(len); + + if (connList == NULL) { + break; + } + + A_MEMZERO(connList,len); + + connList->dev_id = pAbfBtInfo->AdapterId; + connList->conn_num = ABTH_MAX_CONNECTIONS; + connInfo = connList->conn_info; + + if (ioctl(sk, HCIGETCONNLIST, (void *)connList)) { + A_ERR("[%s] Failed to get connection list %d \n", __FUNCTION__, errno); + break; + } + + /* walk through connection list */ + for (i = 0; i < connList->conn_num; i++, connInfo++) { + char addr[32]; + + /* convert to a string to compare */ + ba2str(&connInfo->bdaddr, addr); + + if (strcmp(addr,Address) != 0) { + continue; + } + + if (IsSCO) { + /* look for first non-ACL connection */ + if (connInfo->type == ACL_LINK) { + continue; + } + pAbfBtInfo->CurrentSCOLinkType = connInfo->type; + + } else { + /* look for first ACL connection */ + if (connInfo->type != ACL_LINK) { + continue; + } + } + + /* if we get here we have a connection we are interested in */ + if (connInfo->link_mode & HCI_LM_MASTER) { + /* master */ + *pRole = 0; + } else { + /* slave */ + *pRole = 1; + } + + A_INFO("[%s] Found Connection (Link-Type : %d), found role:%d \n", + Address, connInfo->type, *pRole); + break; + } + + if (i == connList->conn_num) { + A_ERR("[%s] Could not find connection info for %s %d \n", __FUNCTION__, Address); + break; + } + + status = A_OK; + + } while (FALSE); + + if (sk >= 0) { + close(sk); + } + + if (connList != NULL) { + A_FREE(connList); + } + + return status; +} + +static void GetBtAudioConnectionProperties(ABF_BT_INFO *pAbfBtInfo, + ATHBT_STATE_INDICATION Indication) +{ + A_UCHAR role = 0; + A_UCHAR lmpversion = 0; + A_CHAR *pDescr = NULL; + char *address = NULL; + char *version = NULL; + GError *error = NULL; + A_STATUS status; + + do { + + /* get remote device address */ + if (!dbus_g_proxy_call(pAbfBtInfo->AudioDevice, + "GetAddress", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, + &address, + G_TYPE_INVALID)) { + A_ERR("[%s] GetAddress method call failed \n", __FUNCTION__); + break; + } + + if (error != NULL) { + A_ERR("[%s] Failed to GetAddress for audio device: %s \n", __FUNCTION__, error->message); + g_free(error); + break; + } + + A_INFO("Connected audio device address: %s \n", address); + + if (!dbus_g_proxy_call(pAbfBtInfo->DeviceAdapter, + "GetRemoteVersion", + &error, + G_TYPE_STRING, + address, + G_TYPE_INVALID, + G_TYPE_STRING, + &version, + G_TYPE_INVALID)) { + A_ERR("[%s] GetRemoteVersion method call failed \n", __FUNCTION__); + break; + } + + if (error != NULL) { + A_ERR("[%s] Failed to GetRemoteVersion for audio device: %s \n", __FUNCTION__, error->message); + g_free(error); + break; + } + + A_INFO("Connected audio device remote version: %s \n", version); + + /* assume 2.1 or later */ + lmpversion = 4; + + if (strstr(version,"1.0") != NULL) { + lmpversion = 0; + } else if (strstr(version,"1.1") != NULL) { + lmpversion = 1; + } else if (strstr(version,"1.2") != NULL) { + lmpversion = 2; + } else if (strstr(version,"2.0") != NULL) { + lmpversion = 3; + } + + /* get role */ + status = GetConnectedDeviceRole(pAbfBtInfo, + address, + Indication == ATH_BT_A2DP ? FALSE : TRUE, + &role); + + if (A_FAILED(status)) { + role = 0; + } + + if (Indication == ATH_BT_A2DP) { + pDescr = "A2DP"; + pAbfBtInfo->pInfo->A2DPConnection_LMPVersion = lmpversion; + pAbfBtInfo->pInfo->A2DPConnection_Role = role; + } else if (Indication == ATH_BT_SCO) { + if (pAbfBtInfo->CurrentSCOLinkType == SCO_LINK) { + pDescr = "SCO"; + } else { + pDescr = "eSCO"; + } + pAbfBtInfo->pInfo->SCOConnection_LMPVersion = lmpversion; + pAbfBtInfo->pInfo->SCOConnection_Role = role; + + /* for SCO connections check if the event filter captured + * the SYNCH connection complete event */ + CheckHciEventFilter(pAbfBtInfo); + + } else { + pDescr = "UNKNOWN!!"; + } + + A_INFO("BT Audio connection properties: (%s) (role: %s, lmp version: %d) \n", + pDescr, role ? "SLAVE" : "MASTER", lmpversion); + + } while (FALSE); + + if (address != NULL) { + g_free(address); + } + + if (version != NULL) { + g_free(version); + } + +} + + +static A_STATUS WaitForHCIEvent(int Socket, + int TimeoutMs, + A_UCHAR *pBuffer, + int MaxLength, + A_UCHAR EventCode, + A_UINT16 OpCode, + A_UCHAR **ppEventPtr, + int *pEventLength) +{ + + int eventLen; + hci_event_hdr *eventHdr; + struct pollfd pfd; + int result; + A_UCHAR *eventPtr; + A_STATUS status = A_OK; + + *ppEventPtr = NULL; + A_MEMZERO(&pfd,sizeof(pfd)); + pfd.fd = Socket; + pfd.events = POLLIN; + + if (EventCode == EVT_CMD_COMPLETE) { + A_INFO("Waiting for HCI CMD Complete Event, Opcode:0x%4.4X (%d MS) \n",OpCode, TimeoutMs); + } else { + A_INFO("Waiting for HCI Event: %d (%d MS) \n",EventCode, TimeoutMs); + } + + while (1) { + + /* check socket for a captured event using a short timeout + * the caller usually calls this function when it knows there + * is an event that is likely to be captured */ + result = poll(&pfd, 1, TimeoutMs); + + if (result < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) { + /* interrupted */ + } else { + A_ERR("[%s] Socket Poll Failed! : %d \n", __FUNCTION__, errno); + status = A_ERROR; + } + break; + } + + if (result == 0) { + /* no event*/ + break; + } + + if (!(pfd.revents & POLLIN)) { + break; + } + /* get the packet */ + eventLen = read(Socket, pBuffer, MaxLength); + + if (eventLen == 0) { + /* no event */ + break; + } + + if (eventLen < (1 + HCI_EVENT_HDR_SIZE)) { + A_ERR("[%s] Unknown receive packet! len : %d \n", __FUNCTION__, eventLen); + status = A_ERROR; + break; + } + + if (pBuffer[0] != HCI_EVENT_PKT) { + A_ERR("[%s] Unsupported packet type : %d \n", __FUNCTION__, pBuffer[0]); + status = A_ERROR; + break; + } + + eventPtr = &pBuffer[1]; + eventLen--; + eventHdr = (hci_event_hdr *)eventPtr; + eventPtr += HCI_EVENT_HDR_SIZE; + eventLen -= HCI_EVENT_HDR_SIZE; + + if (eventHdr->evt != EventCode) { + /* not interested in this one */ + continue; + } + + if (eventHdr->evt == EVT_CMD_COMPLETE) { + if (eventLen < sizeof(evt_cmd_complete)) { + A_ERR("[%s] EVT_CMD_COMPLETE event is too small! len=%d \n", __FUNCTION__, eventLen); + status = A_ERROR; + break; + } else { + A_UINT16 evOpCode = btohs(BTEV_CMD_COMPLETE_GET_OPCODE(eventPtr)); + /* check for opCode match */ + if (OpCode != evOpCode) { + /* keep searching */ + continue; + } + } + } + + /* found it */ + *ppEventPtr = eventPtr; + *pEventLength = eventLen; + + break; + + } + + return status; +} + + + + +static void CheckHciEventFilter(ABF_BT_INFO *pAbfBtInfo) +{ + A_UCHAR buffer[HCI_MAX_EVENT_SIZE]; + A_STATUS status; + A_UCHAR *eventPtr; + int eventLen; + + + do { + + status = WaitForHCIEvent(pAbfBtInfo->HCIEventListenerSocket, + 100, + buffer, + sizeof(buffer), + EVT_SYNC_CONN_COMPLETE, + 0, + &eventPtr, + &eventLen); + + if (A_FAILED(status)) { + break; + } + + if (eventPtr == NULL) { + break; + } + + if (eventLen < sizeof(evt_sync_conn_complete)) { + A_ERR("SYNC_CONN_COMPLETE Event is too small! : %d \n", eventLen); + break; + } + + pAbfBtInfo->pInfo->SCOConnectInfo.LinkType = BTEV_GET_BT_CONN_LINK_TYPE(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.TransmissionInterval = BTEV_GET_TRANS_INTERVAL(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.RetransmissionInterval = BTEV_GET_RETRANS_INTERVAL(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.RxPacketLength = BTEV_GET_RX_PKT_LEN(eventPtr); + pAbfBtInfo->pInfo->SCOConnectInfo.TxPacketLength = BTEV_GET_TX_PKT_LEN(eventPtr); + + A_INFO("HCI SYNC_CONN_COMPLETE event captured, conn info (%d, %d, %d, %d, %d) \n", + pAbfBtInfo->pInfo->SCOConnectInfo.LinkType, + pAbfBtInfo->pInfo->SCOConnectInfo.TransmissionInterval, + pAbfBtInfo->pInfo->SCOConnectInfo.RetransmissionInterval, + pAbfBtInfo->pInfo->SCOConnectInfo.RxPacketLength, + pAbfBtInfo->pInfo->SCOConnectInfo.TxPacketLength); + + /* now valid */ + pAbfBtInfo->pInfo->SCOConnectInfo.Valid = TRUE; + + } while (FALSE); + +} + +static A_STATUS SetupHciEventFilter(ABF_BT_INFO *pAbfBtInfo) +{ + A_STATUS status = A_ERROR; + struct hci_filter filterSetting; + struct sockaddr_hci addr; + + do { + + if (pAbfBtInfo->HCIEventListenerSocket >= 0) { + /* close previous */ + close(pAbfBtInfo->HCIEventListenerSocket); + } + + pAbfBtInfo->HCIEventListenerSocket = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (pAbfBtInfo->HCIEventListenerSocket < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + + /* capture SYNC_CONN Complete */ + hci_filter_set_event(EVT_SYNC_CONN_COMPLETE, &filterSetting); + + if (setsockopt(pAbfBtInfo->HCIEventListenerSocket, + SOL_HCI, + HCI_FILTER, + &filterSetting, + sizeof(filterSetting)) < 0) { + A_ERR("[%s] Failed to set socket opt: %d \n", __FUNCTION__, errno); + break; + } + + A_MEMZERO(&addr,sizeof(addr)); + /* bind to the current adapter */ + addr.hci_family = AF_BLUETOOTH; + addr.hci_dev = pAbfBtInfo->AdapterId; + + if (bind(pAbfBtInfo->HCIEventListenerSocket, + (struct sockaddr *)&addr, + sizeof(addr)) < 0) { + A_ERR("[%s] Can't bind to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + A_INFO("BT Event Filter Set, Mask: 0x%8.8X:%8.8X \n", + filterSetting.event_mask[1], filterSetting.event_mask[0]); + + status = A_OK; + + } while (FALSE); + + if (A_FAILED(status)) { + if (pAbfBtInfo->HCIEventListenerSocket >= 0) { + close(pAbfBtInfo->HCIEventListenerSocket); + pAbfBtInfo->HCIEventListenerSocket = -1; + } + } + + return status; +} + + /* issue HCI command, currently this ONLY supports simple commands that + * only expect a command complete, the event pointer returned points to the command + * complete event structure for the caller to decode */ +static A_STATUS IssueHCICommand(ABF_BT_INFO *pAbfBtInfo, + A_UINT16 OpCode, + A_UCHAR *pCmdData, + int CmdLength, + int EventRecvTimeoutMS, + A_UCHAR *pEventBuffer, + int MaxLength, + A_UCHAR **ppEventPtr, + int *pEventLength) +{ + A_STATUS status = A_ERROR; + A_UCHAR hciType = HCI_COMMAND_PKT; + hci_command_hdr hciCommandHdr; + struct iovec iv[3]; + int ivcount = 0; + int sk,result; + struct hci_filter filterSetting; + struct sockaddr_hci addr; + + do { + + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + + if (sk < 0) { + A_ERR("[%s] Failed to get raw BT socket: %d \n", __FUNCTION__, errno); + break; + } + + hciCommandHdr.opcode = htobs(OpCode); + hciCommandHdr.plen= CmdLength; + + iv[0].iov_base = &hciType; + iv[0].iov_len = 1; + ivcount++; + iv[1].iov_base = &hciCommandHdr; + iv[1].iov_len = HCI_COMMAND_HDR_SIZE; + ivcount++; + + if (pCmdData != NULL) { + iv[2].iov_base = pCmdData; + iv[2].iov_len = CmdLength; + ivcount++; + } + + /* setup socket to capture the event */ + hci_filter_clear(&filterSetting); + hci_filter_set_ptype(HCI_EVENT_PKT, &filterSetting); + hci_filter_set_event(EVT_CMD_COMPLETE, &filterSetting); + + if (setsockopt(sk, SOL_HCI, HCI_FILTER, &filterSetting, sizeof(filterSetting)) < 0) { + A_ERR("[%s] Failed to set socket opt: %d \n", __FUNCTION__, errno); + break; + } + + A_MEMZERO(&addr,sizeof(addr)); + addr.hci_family = AF_BLUETOOTH; + addr.hci_dev = pAbfBtInfo->AdapterId; + + if (bind(sk,(struct sockaddr *)&addr, sizeof(addr)) < 0) { + A_ERR("[%s] Can't bind to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + while ((result = writev(sk, iv, ivcount)) < 0) { + if (errno == EAGAIN || errno == EINTR) { + continue; + } + break; + } + + if (result <= 0) { + A_ERR("[%s] Failed to write to hci:%d (err:%d) \n", __FUNCTION__, pAbfBtInfo->AdapterId, errno); + break; + } + + + status = WaitForHCIEvent(sk, + EventRecvTimeoutMS, + pEventBuffer, + MaxLength, + EVT_CMD_COMPLETE, + OpCode, + ppEventPtr, + pEventLength); + + if (A_FAILED(status)) { + break; + } + + status = A_OK; + + } while (FALSE); + + if (sk >= 0) { + close(sk); + } + + return status; +} + +#define AFH_CHANNEL_MAP_BYTES 10 + +typedef struct _WLAN_CHANNEL_MAP { + A_UCHAR Map[AFH_CHANNEL_MAP_BYTES]; +} WLAN_CHANNEL_MAP; + +#define MAX_WLAN_CHANNELS 14 + +typedef struct _WLAN_CHANNEL_RANGE { + int ChannelNumber; + int Center; /* in Mhz */ +} WLAN_CHANNEL_RANGE; + +const WLAN_CHANNEL_RANGE g_ChannelTable[MAX_WLAN_CHANNELS] = { + { 1 , 2412}, + { 2 , 2417}, + { 3 , 2422}, + { 4 , 2427}, + { 5 , 2432}, + { 6 , 2437}, + { 7 , 2442}, + { 8 , 2447}, + { 9 , 2452}, + { 10 , 2457}, + { 11 , 2462}, + { 12 , 2467}, + { 13 , 2472}, + { 14 , 2484}, +}; + +static WLAN_CHANNEL_MAP g_ChannelMapTable[MAX_WLAN_CHANNELS + 1] = { + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 0 -- no WLAN */ + { {0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 1 */ + { {0x0F,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 2 */ + { {0xFF,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 3 */ + { {0xFF,0x3F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 4 */ + { {0xFF,0xFF,0x07,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x7F}}, /* 5 */ + { {0xFF,0xFF,0xFF,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F}}, /* 6 */ + { {0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0x7F}}, /* 7 */ + { {0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFE,0xFF,0x7F}}, /* 8 */ + { {0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xC0,0xFF,0x7F}}, /* 9 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF8,0x7F}}, /* 10 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x7F}}, /* 11 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x60}}, /* 12 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00}}, /* 13 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00}}, /* 14 */ +}; + +#define AFH_COMMAND_COMPLETE_TIMEOUT_MS 2000 + +static int LookUpChannel(int FreqMhz) +{ + int i; + + if (FreqMhz == 0) { + /* not connected */ + return 0; + } + + for (i = 0; i < MAX_WLAN_CHANNELS; i++) { + if (FreqMhz <= g_ChannelTable[i].Center) { + break; + } + } + return (i < MAX_WLAN_CHANNELS) ? g_ChannelTable[i].ChannelNumber : 0; +} + +static A_STATUS IssueAFHChannelClassification(ABF_BT_INFO *pAbfBtInfo, int CurrentWLANChannel) +{ + A_UCHAR evtBuffer[HCI_MAX_EVENT_SIZE]; + A_STATUS status; + A_UCHAR *eventPtr; + int eventLen; + A_UCHAR *pChannelMap; + + A_INFO("WLAN Operating Channel: %d \n", CurrentWLANChannel); + + if (CurrentWLANChannel > MAX_WLAN_CHANNELS) { + /* check if this is expressed in Mhz */ + if (CurrentWLANChannel >= 2412) { + /* convert Mhz into a channel number */ + CurrentWLANChannel = LookUpChannel(CurrentWLANChannel); + } else { + return A_ERROR; + } + } + + pChannelMap = &(g_ChannelMapTable[CurrentWLANChannel].Map[0]); + + do { + + status = IssueHCICommand(pAbfBtInfo, + cmd_opcode_pack(3,0x3F), + pChannelMap, + AFH_CHANNEL_MAP_BYTES, + AFH_COMMAND_COMPLETE_TIMEOUT_MS, + evtBuffer, + sizeof(evtBuffer), + &eventPtr, + &eventLen); + + + if (A_FAILED(status)) { + break; + } + + status = A_ERROR; + + if (eventPtr == NULL) { + A_ERR("[%s] Failed to capture AFH command complete event \n", __FUNCTION__); + break; + } + + if (eventLen < (sizeof(evt_cmd_complete) + 1)) { + A_ERR("[%s] not enough bytes in AFH command complete event %d \n", __FUNCTION__, eventLen); + break; + } + + /* check status parameter that follows the command complete event body */ + if (eventPtr[sizeof(evt_cmd_complete)] != 0) { + A_ERR("[%s] AFH command complete event indicated failure : %d \n", __FUNCTION__, + eventPtr[sizeof(evt_cmd_complete)]); + break; + } + + A_INFO(" AFH Command successfully issued \n"); + //A_DUMP_BUFFER(pChannelMap, AFH_CHANNEL_MAP_BYTES, "AFH Channel Classification Map"); + + status = A_OK; + + } while (FALSE); + + return status; +} + + +void IndicateCurrentWLANOperatingChannel(ATHBT_FILTER_INFO *pFilterInfo, int CurrentWLANChannel) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)pFilterInfo->pBtInfo; + + if (NULL == pAbfBtInfo) { + return; + } + + if (pAbfBtInfo->Flags & ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION) { + IssueAFHChannelClassification(pAbfBtInfo,CurrentWLANChannel); + } +} + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.h new file mode 100644 index 000000000000..f9bb3274d811 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_dbus_glib.h @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +#ifndef ABTFILT_BTSTACK_DBUS_GLIB_H_ +#define ABTFILT_BTSTACK_DBUS_GLIB_H_ +#include "abtfilt_int.h" +#include + +/*-----------------------------------------------------------------------*/ +/* BT Section */ +#define STRING_SIZE_MAX 64 +#define BD_ADDR_SIZE 6 + +typedef struct _ABF_BT_INFO { + ATHBT_FILTER_INFO *pInfo; + A_COND_OBJECT hWaitEvent; + A_MUTEX_OBJECT hWaitEventLock; + A_BOOL Loop; + A_BOOL AdapterAvailable; + GMainLoop *Mainloop; + DBusGConnection *Bus; + DBusGProxy *DeviceAdapter; + DBusGProxy *DeviceManager; + DBusGProxy *AudioManager; + DBusGProxy *AudioHeadset; + DBusGProxy *AudioGateway; + DBusGProxy *AudioSink; + DBusGProxy *AudioSource; + DBusGProxy *AudioDevice; + A_UINT8 HCIVersion; + A_UINT16 HCIRevision; + A_UINT8 LMPVersion; + A_UINT16 LMPSubVersion; + A_UINT8 RemoteDevice[BD_ADDR_SIZE]; + A_UINT8 DeviceAddress[BD_ADDR_SIZE]; + A_CHAR AdapterName[STRING_SIZE_MAX]; + A_CHAR DeviceName[STRING_SIZE_MAX]; + A_CHAR ManufacturerName[STRING_SIZE_MAX]; + A_CHAR ProtocolVersion[STRING_SIZE_MAX]; + A_BOOL AdapterCbRegistered; + A_CHAR DefaultAudioDeviceName[STRING_SIZE_MAX]; + A_BOOL DefaultAudioDeviceAvailable; + A_BOOL AudioCbRegistered; + A_UCHAR CurrentSCOLinkType; + int AdapterId; + int HCIEventListenerSocket; + A_UINT32 Flags; +} ABF_BT_INFO; + +#endif /*ABTFILT_BTSTACK_DBUS_GLIB_H_*/ diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_hciutils.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_hciutils.c new file mode 100644 index 000000000000..6939c07ee9f7 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_bluez_hciutils.c @@ -0,0 +1,382 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2011 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +#include "abtfilt_bluez_dbus.h" + +#undef HCI_INQUIRY +#include +#include +#include + +#include "hciutils.h" +#include + +extern ABF_BT_INFO * g_pAbfBtInfo; + +#define ForgetRemoteAudioDevice(pA) \ +{ \ + A_MEMZERO((pA)->DefaultRemoteAudioDeviceAddress,sizeof((pA)->DefaultRemoteAudioDeviceAddress)); \ + (pA)->DefaultRemoteAudioDevicePropsValid = FALSE; \ +} + +#if !defined(STATIC_LINK_HCILIBS) +static void *g_hciHandle; +#endif + +static tHCIUTILS_STATUS (* pfn_HCIUTILS_RegisterHCINotification) ( tHCIUTILS_NOTIFICATION_TYPE t_type, int nOpCode, tHCIUTILS_EVENT_CALLBACK eventNotificationCallback ,void * p_appdata ) = NULL; +static void ( *pfn_HCIUTILS_SendCmd) (tHCIUTILS_HCI_CMD tCmd, void * p_hci_cmd_params) = NULL; +static void (*pfn_HCIUTILS_UnRegisterHCINotification)(tHCIUTILS_NOTIFICATION_TYPE t_type,int nOpCode) = NULL; + +static A_UINT32 hciEventList[] = +{ + HCI_EVT_REMOTE_DEV_LMP_VERSION, /* 0xb*/ + HCI_EVT_REMOTE_DEV_VERSION, /* 0xc */ + EVT_INQUIRY_COMPLETE, + EVT_PIN_CODE_REQ, + EVT_LINK_KEY_NOTIFY, + HCI_EVT_ROLE_CHANGE, /* 0x12*/ + EVT_CONN_COMPLETE, + HCI_EVT_SCO_CONNECT_COMPLETE, + HCI_EVT_DISCONNECT, +}; + +static A_UINT32 hciCmdList[] = +{ + HCI_CMD_OPCODE_INQUIRY_START, + HCI_CMD_OPCODE_INQUIRY_CANCEL, + HCI_CMD_OPCODE_CONNECT, +} ; + +static void eventNotificationCallback ( tHCIUTILS_NOTIFICATION * pEvent) +{ + ABF_BT_INFO *pAbfBtInfo = (ABF_BT_INFO *)g_pAbfBtInfo; + ATHBT_FILTER_INFO *pInfo = pAbfBtInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + if(pEvent->tType == HCIUTILS_COMMAND) { + if(pEvent->nOpCode == HCI_CMD_OPCODE_INQUIRY_START) { + A_DEBUG("Device Inquiry Started \n"); + pAbfBtInfo->btInquiryState |= (1 << 0); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_ON); + } + if(pEvent->nOpCode == HCI_CMD_OPCODE_INQUIRY_CANCEL ) { + A_DEBUG("Device Inquiry cancelled \n"); + if(pAbfBtInfo->btInquiryState) { + pAbfBtInfo->btInquiryState &= ~(1 << 0); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + if(pEvent->nOpCode == HCI_CMD_OPCODE_CONNECT) { + A_DEBUG("Bt-Connect\n"); + } + } + if(pEvent->tType == HCIUTILS_EVENT) { + +#define LMP_FEATURE_ACL_EDR_2MBPS_BYTE_INDEX 3 +#define LMP_FEATURE_ACL_EDR_2MBPS_BIT_MASK 0x2 +#define LMP_FEATURE_ACL_EDR_3MBPS_BYTE_INDEX 3 +#define LMP_FEATURE_ACL_EDR_3MBPS_BIT_MASK 0x4 +#define LMP_FEATURES_LENGTH 8 + if(pEvent->nOpCode == HCI_EVT_REMOTE_DEV_LMP_VERSION) { + A_UINT32 i = 0; + A_UINT32 len = pEvent->n_data_length; + A_UCHAR * eventPtr = (A_UCHAR *)pEvent->p_notification_data_buf; + A_UINT8 *lmp_features; + + /* Process LMP Features */ + + + A_DUMP_BUFFER(eventPtr, len,"Remote Device LMP Features:"); + + eventPtr += 1; + len -= 1 ; + lmp_features = &eventPtr[3]; + A_DUMP_BUFFER(lmp_features, sizeof(lmp_features),"Remote Device LMP Features:"); + + if ((lmp_features[LMP_FEATURE_ACL_EDR_2MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_2MBPS_BIT_MASK) || + (lmp_features[LMP_FEATURE_ACL_EDR_3MBPS_BYTE_INDEX] & LMP_FEATURE_ACL_EDR_3MBPS_BIT_MASK)) + { + A_DEBUG("Device is EDR capable \n"); + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 3; + } else { + A_DEBUG("Device is NOT EDR capable \n"); + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + } + pAbfBtInfo->DefaultRemoteAudioDevicePropsValid = TRUE; + pInfo->A2DPConnection_LMPVersion = pInfo->SCOConnection_LMPVersion = + pAbfBtInfo->DefaultAudioDeviceLmpVersion; + } + if(pEvent->nOpCode == HCI_EVT_REMOTE_DEV_VERSION) { + A_UCHAR * eventPtr = (A_UCHAR *)pEvent->p_notification_data_buf; + A_UINT32 len = pEvent->n_data_length; + + A_DUMP_BUFFER(eventPtr, len,"Remote Device Version"); + eventPtr += 1; + len -= 1; + A_DUMP_BUFFER(eventPtr, len,"Remote Device Version"); + + if (eventPtr[3] == 0) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.0"); + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 0; + A_DEBUG("Its 1.0 \n"); + } else if (eventPtr[3] == 1) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.1"); + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 1; + A_DEBUG("Its 1.1 \n"); + } else if (eventPtr[3] == 2) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "1.2"); + pAbfBtInfo->DefaultAudioDeviceLmpVersion = 2; + A_DEBUG("Its 1.2 \n"); + } else if (eventPtr[3] == 3) { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "2.0"); +/* pAbfBtInfo->DefaultAudioDeviceLmpVersion = 3; */ + A_DEBUG("Its 2.0 \n"); + }else { + strcpy(&pAbfBtInfo->DefaultRemoteAudioDeviceVersion[0], "2.1"); +/* pAbfBtInfo->DefaultAudioDeviceLmpVersion = 4; */ + A_DEBUG("Its 2.1 \n"); + } + + pInfo->A2DPConnection_LMPVersion = pInfo->SCOConnection_LMPVersion = + pAbfBtInfo->DefaultAudioDeviceLmpVersion; + } + if (pEvent->nOpCode == EVT_INQUIRY_COMPLETE) { + A_DEBUG("Device Inquiry Completed\n"); + if(pAbfBtInfo->btInquiryState) { + pAbfBtInfo->btInquiryState &= ~(1 << 0); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + if (pEvent->nOpCode == EVT_PIN_CODE_REQ) { + A_DEBUG("Pin Code Request\n"); + } + + if (pEvent->nOpCode == EVT_LINK_KEY_NOTIFY) { + A_DEBUG("link key notify\n"); + } + if(pEvent->nOpCode == HCI_EVT_ROLE_CHANGE) { + A_DEBUG("Role Change\n"); + A_UCHAR * eventPtr = (A_UCHAR *)pEvent->p_notification_data_buf; + A_UINT32 len = pEvent->n_data_length; + + A_DUMP_BUFFER(eventPtr, len,"Remote Device Role "); + eventPtr += 8; + len -= 8; + if(*eventPtr == 0x00) { + A_DEBUG("ROLE IS MASTER \n"); + pAbfBtInfo->pInfo->A2DPConnection_Role = 0x0; + } + if(*eventPtr == 0x01) { + A_DEBUG("ROLE IS SLAVE \n"); + pAbfBtInfo->pInfo->A2DPConnection_Role = 0x1; + } + } + if(pEvent->nOpCode == EVT_CONN_COMPLETE) { + A_DEBUG("Conn complete\n"); + if(pAbfBtInfo->btInquiryState) { + pAbfBtInfo->btInquiryState &= ~(1 << 1); + AthBtIndicateState(pInstance, ATH_BT_INQUIRY, STATE_OFF); + } + } + + if(pEvent->nOpCode == HCI_EVT_SCO_CONNECT_COMPLETE) { + A_UINT32 len = pEvent->n_data_length; + A_UCHAR * eventPtr = (A_UCHAR*)pEvent->p_notification_data_buf; + + A_DUMP_BUFFER(eventPtr, len,"SCO CONNECT_COMPLETE"); + A_DEBUG("SCO CONNECT COMPLETE \n"); + pInfo->SCOConnection_LMPVersion = + pAbfBtInfo->DefaultAudioDeviceLmpVersion; + + pInfo->SCOConnectInfo.LinkType = eventPtr[10]; + pInfo->SCOConnectInfo.TransmissionInterval = eventPtr[11]; + pInfo->SCOConnectInfo.RetransmissionInterval = eventPtr[12]; + pInfo->SCOConnectInfo.RxPacketLength = eventPtr[13]; + pInfo->SCOConnectInfo.TxPacketLength = eventPtr[15]; + pInfo->SCOConnectInfo.Valid = TRUE; + + A_INFO("HCI SYNC_CONN_COMPLETE event captured, conn info (%d, %d, %d, %d, %d) \n", + pInfo->SCOConnectInfo.LinkType, + pInfo->SCOConnectInfo.TransmissionInterval, + pInfo->SCOConnectInfo.RetransmissionInterval, + pInfo->SCOConnectInfo.RxPacketLength, + pInfo->SCOConnectInfo.TxPacketLength); + + AthBtIndicateState(pInstance, + pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO? ATH_BT_ESCO: ATH_BT_SCO, + STATE_ON); + } + if(pEvent->nOpCode == HCI_EVT_DISCONNECT) { + A_UINT32 bitmap = FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore); + + A_DEBUG("HCI_EVT_DISCONNECT event \n"); + + if( (bitmap & (1 << ATH_BT_SCO))|| (bitmap & (1 << ATH_BT_ESCO))) { + AthBtIndicateState(pInstance, + pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO? ATH_BT_ESCO: ATH_BT_SCO, + STATE_OFF); + } + ForgetRemoteAudioDevice(pAbfBtInfo); + pInfo->SCOConnectInfo.Valid = FALSE; + pAbfBtInfo->pInfo->A2DPConnection_Role = 0x0; + } + } +} + +void +Abf_RegisterToHciLib( ABF_BT_INFO * pAbfBtInfo) +{ + void * handle = 0; + tHCIUTILS_STATUS ret; + + char * pparam = NULL; + int n_opcode = 0, n_type = 0; + int i; + A_INFO("Register To HCI LIB \n"); + + if (pfn_HCIUTILS_RegisterHCINotification) { + for (i=0; i <= 2;i++) { + ret = (*pfn_HCIUTILS_RegisterHCINotification) + ( + HCIUTILS_COMMAND, + hciCmdList[i], + eventNotificationCallback, + (void *) pAbfBtInfo + ); + A_DEBUG("Registered for HCI cmd %x, ret= %d\n", hciCmdList[i],ret); + } + for (i=0; i <= 8; i++) { + ret = (*pfn_HCIUTILS_RegisterHCINotification) + ( + HCIUTILS_EVENT, + hciEventList[i], + eventNotificationCallback, + (void *)pAbfBtInfo + ); + A_DEBUG("Hcievent List[%d] =%x, ret =%x\n",i, hciEventList[i], ret); + } + } +} + +void +Abf_UnRegisterToHciLib( ABF_BT_INFO * pAbfBtInfo) +{ + A_DEBUG("Unregistering HCI library handler\n"); + if(pfn_HCIUTILS_UnRegisterHCINotification) { + int i; + for (i=0; i <= 2;i++) { + (*pfn_HCIUTILS_UnRegisterHCINotification) + ( + HCIUTILS_COMMAND, + hciCmdList[i] + ); + A_DEBUG("Unregistered for HCI cmd %x\n", hciCmdList[i]); + } + for (i=0; i <= 8; i++) { + (*pfn_HCIUTILS_UnRegisterHCINotification) + ( + HCIUTILS_EVENT, + hciEventList[i] + ); + A_DEBUG("Unregistered Hcievent List[%d] =%x\n",i, hciEventList[i]); + } + } +} + +A_STATUS Abf_IssueAFHViaHciLib (ABF_BT_INFO * pAbfBtInfo, + int CurrentWLANChannel) +{ + A_UINT32 center; + tHCIUTILS_HCICMD_SET_AFH_CHANNELS setChannels; + + A_INFO("WLAN Operating Channel: %d \n", CurrentWLANChannel); + + if(!CurrentWLANChannel) { + setChannels.first = 79; + setChannels.last = 79; + center = 0; + }else { + if( (CurrentWLANChannel < 2412) || + (CurrentWLANChannel > 2470)) + { + return A_ERROR; + } + center = CurrentWLANChannel; + center = center - 2400; + setChannels.first = center - 10; + setChannels.last = center + 10; + } + + if (pfn_HCIUTILS_SendCmd) { + (*pfn_HCIUTILS_SendCmd) (HCIUTILS_SET_AFH_CHANNELS, &setChannels); + A_DEBUG("Issue AFH first =%x, last = %x, center =%x\n", + setChannels.first, setChannels.last, center); + } else { + A_ERR( "%s : Fail to issue AFH due to NULL pointer of pfn_HCIUTILS_SendCmd\n", __FUNCTION__); + return A_ERROR; + } + + return A_OK; +} + +A_STATUS Abf_HciLibInit(A_UINT32 *btfiltFlags) +{ +#ifdef STATIC_LINK_HCILIBS + pfn_HCIUTILS_RegisterHCINotification = HCIUTILS_RegisterHCINotification; + pfn_HCIUTILS_SendCmd = HCIUTILS_SendCmd; + pfn_HCIUTILS_UnRegisterHCINotification = HCIUTILS_UnRegisterHCINotification; + /* We don't force to set ONLY DBUS flags here since we are static linking */ + return A_OK; +#else + g_hciHandle = dlopen("hciutils.so", RTLD_NOW); + if( g_hciHandle == NULL){ + A_ERR( "%s : Error loading library hciutils.so %s\n", __FUNCTION__, dlerror()); + return A_ERROR; + } else { + A_DEBUG( "Load hciutils.so successfully\n"); + pfn_HCIUTILS_RegisterHCINotification = dlsym(g_hciHandle, "HCIUTILS_RegisterHCINotification"); + pfn_HCIUTILS_SendCmd = dlsym(g_hciHandle, "HCIUTILS_SendCmd"); + pfn_HCIUTILS_UnRegisterHCINotification = dlsym(g_hciHandle, "HCIUTILS_UnRegisterHCINotification"); + if ( (NULL == pfn_HCIUTILS_RegisterHCINotification) || (NULL == pfn_HCIUTILS_SendCmd) || + (NULL == pfn_HCIUTILS_UnRegisterHCINotification) ) + { + A_ERR("ERROR GETTING HCIUTILS SYMBOLS \n"); + dlclose(g_hciHandle); + g_hciHandle = NULL; + return A_ERROR; + } + /* Make sure we enable ONLY DBUS flags */ + *btfiltFlags |= ABF_USE_ONLY_DBUS_FILTERING; + return A_OK; + } +#endif +} + +void Abf_HciLibDeInit(void) +{ +#ifndef STATIC_LINK_HCILIBS + if(g_hciHandle) { + dlclose(g_hciHandle); + g_hciHandle = NULL; + } +#endif +} + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_core.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_core.c new file mode 100644 index 000000000000..14fd28682b98 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_core.c @@ -0,0 +1,1422 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2011 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +//============================================================================== +/* + * Bluetooth Filter Front End + * + */ + +#include "abtfilt_int.h" + +/* Defines */ +#define MAX_VAL_DATA_LENGTH 128 + +const A_CHAR *g_IndicationStrings[ATH_BT_MAX_STATE_INDICATION] = +{ + "NOP", + "INQUIRY", + "CONNECT", + "SCO", + "ACL", + "A2DP", + "ESCO", +}; + +extern A_FILE_HANDLE gConfigFile; + +/* Function Prototypes */ +static void BtStateActionProper(ATHBT_FILTER_INFO *pInfo, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State); +static void DoBtStateAction(ATHBT_FILTER_INFO *pInfo, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State); +static void AthFilterCmdEventsCallback(void *pContext, + ATHBT_HCI_CTRL_TYPE Type, + unsigned char *pBuffer, int Length); +static void AthFilterIndicateStateCallback(void *pContext, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + unsigned char LMPVersion); +static void AthFilterAclDataOutCallback(void *pContext, + unsigned char *pBuffer, int Length); +static void AthFilterAclDataInCallback(void *pContext, + unsigned char *pBuffer, int Length); +static void ProcessBTActionMessages(ATHBT_FILTER_INFO *pInfo, + BTACTION_QUEUE_PROC Process, + ATHBT_STATE_INDICATION StateToFlush); +static void ExecuteBtAction(ATHBT_FILTER_INFO *pInfo, + BT_ACTION_MSG *pBtActionMsg); +static ATHBT_STATE_INDICATION IndicateA2DP(ATHBT_FILTER_INFO *pInfo , + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + unsigned char *pACLBuffer); +static void *FilterThread(void *arg); +static void SyncBTState(ATHBT_FILTER_INFO *pInfo); +static void ProcessActionOverride(ATHBT_FILTER_INFO *pInfo, + A_CHAR *pIndicationStr, + A_CHAR *pModifyAction, + A_CHAR *pAction); +static void GetActionStringOverrides(ATHBT_FILTER_INFO *pInfo); + +/* APIs exported to other modules */ +void +AthBtFilter_State_Off(ATHBT_FILTER_INFO *pInfo) +{ + /* + * before we exit we need to counter-act the coexistence + * settings. Currently we just indicate that each state is now + * OFF (if they are ON). This state synchronization is typically + * required on HOT-removable BT adapters or where the low level + * adapter can be surprise removed before the BT stack can clean + * up HCI connections and states + */ + if (pInfo->AdapterAvailable) { + int indication, newIndication; + ATHBT_STATE newState; + + /* + * the BT adapter is going away, indicate that all indications + * are now in the OFF state, this may queue up control action + * messages, which is okay + */ + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; + indication++) + { + A_LOCK_FILTER(pInfo); + newIndication = + FCore_FilterIndicatePreciseState(&pInfo->FilterCore, + indication, STATE_OFF, &newState); + A_UNLOCK_FILTER(pInfo); + + if (newIndication == ATH_BT_NOOP) { + continue; + } + + DoBtStateAction(pInfo, indication, newState); + } + + /* issue control actions */ + ProcessBTActionMessages(pInfo, BTACTION_QUEUE_SYNC_STATE, + ATH_BT_NOOP); + } + + +} + +int +AthBtFilter_Attach(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 flags) +{ + int i; + int retVal = -1; + ATHBT_FILTER_INFO *pInfo = NULL; + BT_ACTION_MSG *pBTActionMsg; + A_UINT32 maxBTActionMsgs = MAX_BT_ACTION_MESSAGES; + A_STATUS status; + BT_FILTER_CORE_INFO * pCoreInfo = NULL; + + do { + pInfo = (ATHBT_FILTER_INFO *)A_MALLOC(sizeof(ATHBT_FILTER_INFO) + + maxBTActionMsgs * (sizeof(BT_ACTION_MSG))); + if (NULL == pInfo) { + A_ERR("[%s] Failed to allocate BT filter info\n", __FUNCTION__); + break; + } + A_MEMZERO(pInfo, sizeof(ATHBT_FILTER_INFO)); + + pInstance->pContext = pInfo; + pInfo->pInstance = pInstance; + pInfo->MaxBtActionMessages = (int)maxBTActionMsgs; + pInfo->AdapterAvailable = FALSE; + pInfo->Shutdown = FALSE; + + status = A_MUTEX_INIT(&pInfo->CritSection); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to initialize critical section\n", + __FUNCTION__); + break; + } + + DL_LIST_INIT(&pInfo->BTActionMsgList); + DL_LIST_INIT(&pInfo->FreeActionMsgList); + pCoreInfo = &pInfo->FilterCore; + pCoreInfo->FilterState.btFilterFlags = flags; + + A_DEBUG("Calling Fcore Init\n"); + if (!FCore_Init(pCoreInfo)) { + A_DEBUG(" Fcore Init failed \n"); + break; + } + + GetActionStringOverrides(pInfo); + + status = FCore_RefreshActionList(&pInfo->FilterCore); + if (A_FAILED(status)) { + A_ERR("[%s] Failed refresh action list (status:%d)\n", + __FUNCTION__, status); + break; + } + + /* message buffers are at the end of our context blob */ + pBTActionMsg = (BT_ACTION_MSG *)((A_UCHAR *)pInfo + + sizeof(ATHBT_FILTER_INFO)); + + for (i = 0; i < pInfo->MaxBtActionMessages; i++, pBTActionMsg++) { + /* create the event for blocking requests */ + status = A_COND_INIT(&pBTActionMsg->hWaitEvent); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to allocate BT action event wait object\n", + __FUNCTION__); + /* if we are running out of memory we'll fail farther down */ + break; + } + + status = A_MUTEX_INIT(&pBTActionMsg->hWaitEventLock); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to initialize the mutex\n", __FUNCTION__); + /* if we are running out of memory we'll fail farther down */ + break; + } + + /* free to list */ + FREE_BT_ACTION_MSG(pInfo, pBTActionMsg); + } + + /* create the wake event for our dispatcher thread */ + status = A_COND_INIT(&pInfo->hWakeEvent); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to allocate wakeup event\n", __FUNCTION__); + break; + } + + status = A_MUTEX_INIT(&pInfo->hWakeEventLock); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to initialize critical section\n", + __FUNCTION__); + break; + } + + /* + * get the event types that the filter core can ignore. The BT + * notification side can handle them TODO + */ + pInfo->FilterCore.StateFilterIgnore = 0; + + pInstance->pFilterCmdEvents = AthFilterCmdEventsCallback; + pInstance->pIndicateState = AthFilterIndicateStateCallback; + pInstance->pFilterAclDataOut = AthFilterAclDataOutCallback; + pInstance->pFilterAclDataIn = AthFilterAclDataInCallback; + + /* + * We are fully initialized and ready to filter. The filter core + * needs to stay in sync with the BT radio state until the WLAN + * driver comes up, when the WLAN driver comes on-line the filter + * will issue operating parameters for the current BT radio state + * (see HandleAdapterEvent) + */ + pInstance->FilterEnabled = TRUE; + + status = A_TASK_CREATE(&pInfo->hFilterThread, FilterThread, pInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to create filter thread\n", __FUNCTION__); + break; + } + + pInfo->FilterThreadValid = TRUE; + + retVal = 0; + A_INFO("BT Filter Core init complete\n"); + } while (FALSE); + + if (retVal < 0) { + AthBtFilter_Detach(pInstance); + } + + return retVal; +} + +void +AthBtFilter_Detach(ATH_BT_FILTER_INSTANCE *pInstance) +{ + A_STATUS status; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + BT_ACTION_MSG *pBTActionMsg; + int i; + + /* make sure filter is disabled */ + pInstance->FilterEnabled = FALSE; + + if (NULL == pInfo) { + return; + } + + pInfo->Shutdown = TRUE; + + /* wake filter thread */ + A_MUTEX_LOCK(&pInfo->hWakeEventLock); + A_COND_SIGNAL(&pInfo->hWakeEvent); + A_MUTEX_UNLOCK(&pInfo->hWakeEventLock); + + if (pInfo->FilterThreadValid) { + pInfo->FilterThreadValid = FALSE; + /* wait for thread to exit */ + status = A_TASK_JOIN(&pInfo->hFilterThread); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to JOIN filter thread \n", + __FUNCTION__); + } + } + + A_COND_DEINIT(&pInfo->hWakeEvent); + A_MUTEX_DEINIT(&pInfo->hWakeEventLock); + + pBTActionMsg = (BT_ACTION_MSG *)((A_UCHAR *)pInfo + + sizeof(ATHBT_FILTER_INFO)); + /* close all action message wait objects */ + for (i = 0; i < pInfo->MaxBtActionMessages; i++, pBTActionMsg++) { + A_COND_DEINIT(&pBTActionMsg->hWaitEvent); + A_MUTEX_DEINIT(&pBTActionMsg->hWaitEventLock); + } + + pInstance->pContext = NULL; + A_MUTEX_DEINIT(&pInfo->CritSection); + FCore_Cleanup(&pInfo->FilterCore); + A_FREE(pInfo); + + A_INFO("BT Filter Core de-init complete\n"); +} + +/* Internal functions */ +static void +AdjustBtControlAction(ATHBT_FILTER_INFO *pInfo, + BT_ACTION_MSG *pActionMsg) +{ + +#define A2DP_CONFIG_ALLOW_OPTIMIZATION ( 1 << 0) +#define A2DP_CONFIG_EDR_CAPABLE ( 1 << 1) +#define A2DP_CONFIG_IS_COLOCATED_IS_MASTER ( 1 << 2) +#define A2DP_CONFIG_A2DP_IS_HIGH_PRI ( 1 << 3) + + if (pActionMsg->StateForControlAction != STATE_ON) { + /* nothing to adjust in OFF case */ + return; + } + + if (pActionMsg->ControlAction.Type != BT_CONTROL_ACTION_PARAMS) { + /* only modify action that issues a PARAMS control action */ + return; + } + + if(pInfo->Flags & ABF_WIFI_CHIP_IS_VENUS) { + + if (pActionMsg->IndicationForControlAction == ATH_BT_A2DP) { + WMI_SET_BTCOEX_A2DP_CONFIG_CMD *pA2dpParamsCmd = + (WMI_SET_BTCOEX_A2DP_CONFIG_CMD *) + (pActionMsg->ControlAction.Buffer); + BTCOEX_A2DP_CONFIG *pA2dpGenericConfig = + &pA2dpParamsCmd->a2dpConfig; + BTCOEX_PSPOLLMODE_A2DP_CONFIG * pA2dpPspollConfig = + &pA2dpParamsCmd->a2dppspollConfig; + BTCOEX_OPTMODE_A2DP_CONFIG * pA2dpOptModeConfig = + &pA2dpParamsCmd->a2dpOptConfig; + + pA2dpGenericConfig->a2dpFlags = 0; + /*Role =0 is Master, Role =1, is slave */ + if(pInfo->A2DPConnection_Role == 0) { + pA2dpGenericConfig->a2dpFlags |= A2DP_CONFIG_IS_COLOCATED_IS_MASTER; + }else { + pA2dpGenericConfig->a2dpFlags &= ~A2DP_CONFIG_IS_COLOCATED_IS_MASTER; + } + + switch (pInfo->A2DPConnection_LMPVersion) { + case 0: // 1.0 + case 1: // 1.1 + case 2: // 1.2 + pA2dpPspollConfig->a2dpWlanMaxDur = 30; + pA2dpOptModeConfig->a2dpMaxAggrSize = 1; + pA2dpOptModeConfig->a2dpMinlowRateMbps =52; + pA2dpPspollConfig->a2dpDataRespTimeout = 10; + pA2dpPspollConfig->a2dpMinBurstCnt = 4; + break; + case 3: // 2.0 + case 4: // 2.1 + default: + pA2dpPspollConfig->a2dpDataRespTimeout = 20; + pA2dpPspollConfig->a2dpWlanMaxDur = 50; + pA2dpOptModeConfig->a2dpMaxAggrSize = 16; + pA2dpOptModeConfig->a2dpMinlowRateMbps =36; +#ifdef MSM_7230 + if(pA2dpGenericConfig->a2dpFlag & A2DP_CONFIG_IS_COLOCATED_IS_MASTER) { + pA2dpPspollConfig->a2dpMinBurstCnt = 1; + }else{ + pA2dpPspollConfig->a2dpMinBurstCnt = 2; + } + + +#else + pA2dpPspollConfig->a2dpMinBurstCnt = 2; + +#endif + /* Indicate that remote device is EDR capable */ + pA2dpGenericConfig->a2dpFlags |= A2DP_CONFIG_EDR_CAPABLE; + break; + } + if(pInfo->Flags & ABF_BT_CHIP_IS_ATHEROS) { + pA2dpGenericConfig->a2dpFlags |= A2DP_CONFIG_A2DP_IS_HIGH_PRI ; + /* Enable optmization for all the modes */ + pA2dpGenericConfig->a2dpFlags |= A2DP_CONFIG_ALLOW_OPTIMIZATION; + }else { + /* Enable optmization for only for master role */ + if(pInfo->A2DPConnection_Role == 0) { + pA2dpGenericConfig->a2dpFlags |= A2DP_CONFIG_ALLOW_OPTIMIZATION; + }else { + pA2dpGenericConfig->a2dpFlags &= ~A2DP_CONFIG_ALLOW_OPTIMIZATION; + pA2dpPspollConfig->a2dpWlanMaxDur = 30; + } + + } + pA2dpOptModeConfig->a2dpLowRateCnt =5; + pA2dpOptModeConfig->a2dpHighPktRatio = 5; + pA2dpOptModeConfig->a2dpPktStompCnt = 6; + /* Continuation of addressing EV#80876 and EV#80859. Disabling OPT mode always as + * device is forced to SLAVE */ + pA2dpGenericConfig->a2dpFlags &= ~A2DP_CONFIG_ALLOW_OPTIMIZATION; + + A_DEBUG(("ATHBT: BT PARAMS A2DP Adjustments :\r\n")); + A_DEBUG((" a2dpWlanUsageLimit : %d\r\n"), + pA2dpPspollConfig->a2dpWlanMaxDur); + A_DEBUG((" a2dpBurstCntMin : %d\r\n"), + pA2dpPspollConfig->a2dpMinBurstCnt); + A_DEBUG((" a2dpDataRespTimeout : %d\r\n"), + pA2dpPspollConfig->a2dpDataRespTimeout); + A_DEBUG((" A2DP OptMode Config-MaxAggrSize : %d\r\n"), + pA2dpOptModeConfig->a2dpMaxAggrSize); + A_DEBUG((" A2DP Flags : %d\r\n"), + pA2dpGenericConfig->a2dpFlags); +#if 0 + A_DEBUG((" A2DP OptMode Config - MinLowRateMbps : %d\r\n"), + pA2dpOptModeConfig->a2dpMinlowRateMbps); + A_DEBUG((" A2DP OptMode Config - LowRateCnt : %d\r\n"), + pA2dpOptModeConfig->a2dpLowRateCnt ); + A_DEBUG((" A2DP High Pkt Ratio Config- PktRatio : %d\r\n"), + pA2dpOptModeConfig->a2dpHighPktRatio ); + A_DEBUG((" A2DP High Pkt Ratio Config- StompCnt : %d\r\n"), + pA2dpOptModeConfig->a2dpPktStompCnt ); +#endif + } + /* adjust control action for BT_PARAMS_SCO control action */ + if ((pActionMsg->IndicationForControlAction == ATH_BT_SCO) || + (pActionMsg->IndicationForControlAction == ATH_BT_ESCO)) + { + WMI_SET_BTCOEX_SCO_CONFIG_CMD *pScoParamsCmd = + (WMI_SET_BTCOEX_SCO_CONFIG_CMD *) + (pActionMsg->ControlAction.Buffer); + BTCOEX_SCO_CONFIG *pScoGenericConfig = + &pScoParamsCmd->scoConfig; + BTCOEX_PSPOLLMODE_SCO_CONFIG * pScoPspollConfig = + &pScoParamsCmd->scoPspollConfig; + BTCOEX_OPTMODE_SCO_CONFIG * pScoOptModeConfig = + &pScoParamsCmd->scoOptModeConfig; + BTCOEX_WLANSCAN_SCO_CONFIG * pScoWlanScanConfig = + &pScoParamsCmd->scoWlanScanConfig; + + pScoGenericConfig->scoFlags = 0; + do { + if ((pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO) && + (pInfo->SCOConnectInfo.Valid)) + { + A_UCHAR scoSlots; + /* decode packet length to get packet type */ + if (pInfo->SCOConnectInfo.TxPacketLength <= 30) { + /* EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 60) { + /* 2-EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 90) { + /*3-EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 120) { + /* EV4: */ + scoSlots = 3; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 180) { + /* EV5: */ + scoSlots = 3; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 360) { + /* 2-EV5 */ + scoSlots = 3; + } else { + /* 3-EV5 */ + scoSlots = 3; + } + + scoSlots *= 2; + pScoGenericConfig->scoSlots = scoSlots; + + if (pInfo->SCOConnectInfo.TransmissionInterval >= scoSlots) { + pScoGenericConfig->scoIdleSlots = + pInfo->SCOConnectInfo.TransmissionInterval - scoSlots; + } else { + A_DEBUG(("Invalid scoSlot, got:%d, transInt: %d\n"), + scoSlots, + pInfo->SCOConnectInfo.TransmissionInterval); + } + } else { + /* legacy SCO */ + pScoGenericConfig->scoSlots = 2; + pScoGenericConfig->scoIdleSlots = 4; + } + // pScoGenericConfig->scoFlags |= WMI_SCO_CONFIG_FLAG_ALLOW_OPTIMIZATION; + if(pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO) { + pScoGenericConfig->scoFlags |= WMI_SCO_CONFIG_FLAG_IS_EDR_CAPABLE; + } + if(pScoGenericConfig->scoIdleSlots >= 10) { + pScoPspollConfig->scoPsPollLatencyFraction = 2; + pScoPspollConfig->scoStompDutyCyleVal = 2; + pScoWlanScanConfig->scanInterval = 100; + pScoWlanScanConfig->maxScanStompCnt = 2; + }else { + pScoPspollConfig->scoPsPollLatencyFraction = 1; + pScoPspollConfig->scoStompDutyCyleVal = 5; + pScoWlanScanConfig->scanInterval = 100; + pScoWlanScanConfig->maxScanStompCnt = 4; + } + }while(FALSE); + pScoPspollConfig->scoCyclesForceTrigger = 10; + pScoPspollConfig->scoDataResponseTimeout = 10; + pScoPspollConfig->scoStompDutyCyleMaxVal = 6; + + A_DEBUG(("ATHBT: BT PARAMS SCO adjustment (%s) \n"), + pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO ? "eSCO":"SCO"); + A_DEBUG((" numScoCyclesForceTrigger : %d \n"), + pScoPspollConfig->scoCyclesForceTrigger); + A_DEBUG((" dataResponseTimeout : %d \n"), + pScoPspollConfig->scoDataResponseTimeout = 20); + A_DEBUG((" stompDutyCyleVal : %d \n"), + pScoPspollConfig->scoStompDutyCyleVal); + A_DEBUG((" psPollLatencyFraction : %d \n"), + pScoPspollConfig->scoPsPollLatencyFraction); + A_DEBUG((" noSCOSlots : %d \n"), + pScoGenericConfig->scoSlots); + A_DEBUG((" noIdleSlots : %d \n"), + pScoGenericConfig->scoIdleSlots); + A_DEBUG((" scoFlags : %d \n"), + pScoGenericConfig->scoFlags); + + pScoOptModeConfig->scoStompCntIn100ms = 3; + pScoOptModeConfig->scoContStompMax = 3; + pScoOptModeConfig->scoMinlowRateMbps = 36; + pScoOptModeConfig->scoLowRateCnt = 5; + pScoOptModeConfig->scoHighPktRatio = 5; + + if(pScoGenericConfig->scoIdleSlots >= 10) { + pScoOptModeConfig->scoMaxAggrSize = 8; + }else { + pScoOptModeConfig->scoMaxAggrSize = 1; + } + + } + } + else + { + WMI_SET_BT_PARAMS_CMD *pParamsCmd; + if (pActionMsg->IndicationForControlAction == ATH_BT_A2DP) { + do { + pParamsCmd = + (WMI_SET_BT_PARAMS_CMD *)(pActionMsg->ControlAction.Buffer); + + if (pParamsCmd->paramType != BT_PARAM_A2DP) { + /* only modify A2DP params */ + break; + } + /*Role =0 is Master, Role =1, is slave */ + if(pInfo->A2DPConnection_Role == 0) { + pParamsCmd->info.a2dpParams.isCoLocatedBtRoleMaster = 1; + }else { + pParamsCmd->info.a2dpParams.isCoLocatedBtRoleMaster = 0; + /* workaround for local BT radio that disables EDR + * rates when operating as a slave. We downgrade + * the remote lmp version to protect A2DP as if the radio was 1.2 */ + pInfo->A2DPConnection_LMPVersion = 2; + } + + switch (pInfo->A2DPConnection_LMPVersion) { + case 0: // 1.0 + case 1: // 1.1 + case 2: // 1.2 + pParamsCmd->info.a2dpParams.a2dpWlanUsageLimit = 30; + pParamsCmd->info.a2dpParams.a2dpBurstCntMin = 3; + pParamsCmd->info.a2dpParams.a2dpDataRespTimeout =10; + break; + case 3: // 2.0 + case 4: // 2.1 + default: + if( pParamsCmd->info.a2dpParams.isCoLocatedBtRoleMaster) { + /* allow close range optimization for newer BT radios */ + } + pParamsCmd->info.a2dpParams.a2dpWlanUsageLimit = 100; + pParamsCmd->info.a2dpParams.a2dpBurstCntMin = 1; + pParamsCmd->info.a2dpParams.a2dpDataRespTimeout =10; + break; + } + + A_DEBUG(("ATHBT: BT PARAMS A2DP Adjustments :\r\n")); + A_DEBUG((" a2dpWlanUsageLimit : %d\r\n"), + pParamsCmd->info.a2dpParams.a2dpWlanUsageLimit); + A_DEBUG((" a2dpBurstCntMin : %d\r\n"), + pParamsCmd->info.a2dpParams.a2dpBurstCntMin); + A_DEBUG((" a2dpDataRespTimeout : %d\r\n"), + pParamsCmd->info.a2dpParams.a2dpDataRespTimeout); + }while (FALSE); + } + + /* adjust control action for BT_PARAMS_SCO control action */ + if ((pActionMsg->IndicationForControlAction == ATH_BT_SCO) || + (pActionMsg->IndicationForControlAction == ATH_BT_ESCO)) + { + do { + pParamsCmd = + (WMI_SET_BT_PARAMS_CMD *)(pActionMsg->ControlAction.Buffer); + + if (pParamsCmd->paramType != BT_PARAM_SCO) { + /* only modify SCO params */ + break; + } + + if ((pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO) && + (pInfo->SCOConnectInfo.Valid)) { + A_UCHAR scoSlots; + pInfo->SCOConnectInfo.Valid = FALSE; + /* decode packet length to get packet type */ + if (pInfo->SCOConnectInfo.TxPacketLength <= 30) { + /* EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 60) { + /* 2-EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 90) { + /*3-EV3 */ + scoSlots = 1; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 120) { + /* EV4: */ + scoSlots = 3; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 180) { + /* EV5: */ + scoSlots = 3; + } else if (pInfo->SCOConnectInfo.TxPacketLength <= 360) { + /* 2-EV5 */ + scoSlots = 3; + } else { + /* 3-EV5 */ + scoSlots = 3; + } + + /* account for RX/TX */ + scoSlots *= 2; + pParamsCmd->info.scoParams.noSCOSlots = scoSlots; + + if (pInfo->SCOConnectInfo.TransmissionInterval >= scoSlots) { + pParamsCmd->info.scoParams.noIdleSlots = + pInfo->SCOConnectInfo.TransmissionInterval - scoSlots; + } else { + A_DEBUG(("Invalid scoSlot, got:%d, transInt: %d\n"), + scoSlots, + pInfo->SCOConnectInfo.TransmissionInterval); + } + } else { + /* legacy SCO */ + pParamsCmd->info.scoParams.noSCOSlots = 2; + pParamsCmd->info.scoParams.noIdleSlots = 4; + } + + A_DEBUG(("ATHBT: BT PARAMS SCO adjustment (%s) \n"), + pInfo->SCOConnectInfo.LinkType == BT_LINK_TYPE_ESCO ? "eSCO":"SCO"); + A_DEBUG((" numScoCyclesForceTrigger : %d \n"), + pParamsCmd->info.scoParams.numScoCyclesForceTrigger); + A_DEBUG((" dataResponseTimeout : %d \n"), + pParamsCmd->info.scoParams.dataResponseTimeout); + A_DEBUG((" stompScoRules : %d \n"), + pParamsCmd->info.scoParams.stompScoRules); + A_DEBUG((" stompDutyCyleVal : %d \n"), + pParamsCmd->info.scoParams.stompDutyCyleVal); + A_DEBUG((" psPollLatencyFraction : %d \n"), + pParamsCmd->info.scoParams.psPollLatencyFraction); + A_DEBUG((" noSCOSlots : %d \n"), + pParamsCmd->info.scoParams.noSCOSlots); + A_DEBUG((" noIdleSlots : %d \n"), + pParamsCmd->info.scoParams.noIdleSlots); + } while (FALSE); + } + } +} + +static void +BtStateActionProper(ATHBT_FILTER_INFO *pInfo, + ATHBT_STATE_INDICATION Indication, ATHBT_STATE State) +{ + A_COND_OBJECT *hWait = NULL; + BT_ACTION_MSG *pActionMsg; + DL_LIST *pListEntry; + BT_CONTROL_ACTION_ITEM *pBtControlAction; + int queued = 0; + + A_LOCK_FILTER(pInfo); + + pBtControlAction = FCore_GetControlAction(&pInfo->FilterCore, + Indication, + State, + NULL); + + A_DEBUG("[%s], Indication =%d, state=%d,ControlAction.Length=%d\n", + __FUNCTION__, Indication, State, + ( (pBtControlAction == NULL)? 0 : pBtControlAction->ControlAction.Length)); + + while (pBtControlAction != NULL) { + /* allocate an action message */ + pListEntry = DL_ListRemoveItemFromHead(&pInfo->FreeActionMsgList); + + if (NULL == pListEntry) { + A_DEBUG("action messages exhausted\n"); + break; + } + + pActionMsg = A_CONTAINING_STRUCT(pListEntry, BT_ACTION_MSG, + ListEntry); + + /* save state for later flushing */ + pActionMsg->StateForControlAction = State; + pActionMsg->IndicationForControlAction = Indication; + + /* we need to buffer the control actions */ + A_MEMCPY(&pActionMsg->ControlAction, + &pBtControlAction->ControlAction, + sizeof(pActionMsg->ControlAction)); + + /* When is it ever set to blocking TODO */ + if (pActionMsg->Blocking) { + /* this is the action to wait on */ + hWait = &pActionMsg->hWaitEvent; + A_COND_RESET(hWait); + } + /* allow for adjustments to the control action beyond the defaults */ + AdjustBtControlAction(pInfo, pActionMsg); + + /* queue action */ + QUEUE_BT_ACTION_MSG(pInfo, pActionMsg); + queued++; + + /* get the next action using the current one as a starter */ + pBtControlAction = FCore_GetControlAction(&pInfo->FilterCore, + Indication, + State, + pBtControlAction); + } + + A_UNLOCK_FILTER(pInfo); + + if (queued > 0) { + /* wake thread to process all the queued up actions */ + A_MUTEX_LOCK(&pInfo->hWakeEventLock); + A_COND_SIGNAL(&pInfo->hWakeEvent); + A_MUTEX_UNLOCK(&pInfo->hWakeEventLock); + } + + /* check if we need to block until the dispatch thread issued the + * last action if the adapter becomes unavailable we cannot block + * the thread (queue will stall), so only block if the adapter is + * available and use a reasonable timeout + */ + if (hWait) { + A_COND_WAIT(hWait, &pInfo->CritSection, ACTION_WAIT_TIMEOUT); + } +} + +static void DoBtStateAction(ATHBT_FILTER_INFO *pInfo, ATHBT_STATE_INDICATION Indication, ATHBT_STATE State) +{ + A_UINT32 bitmap = FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore); + + if ((Indication == ATH_BT_INQUIRY) && (State == STATE_ON)) { + int i; + for (i=0; iShutdown) { + return; + } + + /* + * the filter state machine needs to be protected in case the HCI layer + * can process commands and events in an unserialize manner + */ + A_LOCK_FILTER(pInfo); + + if (Type == ATHBT_HCI_COMMAND) { + A_DUMP_BUFFER(pBuffer, Length, "BT HCI Command"); + indication = FCore_FilterBTCommand(&pInfo->FilterCore, pBuffer, + Length, &state); + } else { + A_DUMP_BUFFER(pBuffer, Length, "BT HCI Event"); + indication = FCore_FilterBTEvent(&pInfo->FilterCore, pBuffer, + Length, &state); + /* check SCO and ESCO connection events */ + if ((indication == ATH_BT_SCO) || (indication == ATH_BT_ESCO)) { + if (HCI_GET_EVENT_CODE(pBuffer) == HCI_EVT_SCO_CONNECT_COMPLETE) { + A_DEBUG(("SCO_CONNECT_COMPLETE (%s)\n"), + (state == STATE_ON) ? "ON" : "OFF"); + if (state == STATE_ON) { + /* save these off for the BT Action adjustment */ + pInfo->SCOConnectInfo.LinkType = + GET_BT_CONN_LINK_TYPE(pBuffer); + pInfo->SCOConnectInfo.TransmissionInterval = + GET_TRANS_INTERVAL(pBuffer); + pInfo->SCOConnectInfo.RetransmissionInterval = + GET_RETRANS_INTERVAL(pBuffer); + pInfo->SCOConnectInfo.RxPacketLength = + GET_RX_PKT_LEN(pBuffer); + pInfo->SCOConnectInfo.TxPacketLength = + GET_TX_PKT_LEN(pBuffer); + A_DEBUG(("ATHBT: SCO conn info (%d, %d, %d, %d, %d))\n"), + pInfo->SCOConnectInfo.LinkType, + pInfo->SCOConnectInfo.TransmissionInterval, + pInfo->SCOConnectInfo.RetransmissionInterval, + pInfo->SCOConnectInfo.RxPacketLength, + pInfo->SCOConnectInfo.TxPacketLength); + /* now valid */ + pInfo->SCOConnectInfo.Valid = TRUE; + } else { + /* disconnected, invalidate */ + pInfo->SCOConnectInfo.Valid = FALSE; + } + } + } + } + + A_UNLOCK_FILTER(pInfo); + + if (indication == ATH_BT_NOOP) { + return; + } + + A_DEBUG(("New Indication :%d State:%s (map:0x%X)\n"), + indication, (state == STATE_ON) ? "ON" : "OFF", + FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore)); + + if (pInfo->AdapterAvailable) { + DoBtStateAction(pInfo, indication, state); + } +} + +static ATHBT_STATE_INDICATION +IndicateA2DP(ATHBT_FILTER_INFO *pInfo, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + unsigned char *pACLBuffer) +{ + A_ERR("[%s] Not yet implemented\n", __FUNCTION__); + + return ATH_BT_NOOP; /* TODO */ +} + +static void +AthFilterAclDataOutCallback(void *pContext, unsigned char *pBuffer, int Length) +{ + ATHBT_STATE_INDICATION indication; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pContext; + ATHBT_STATE state; + + if (pInfo->Shutdown) { + return; + } + + A_LOCK_FILTER(pInfo); + + indication = FCore_FilterACLDataOut(&pInfo->FilterCore, + pBuffer, + Length, + &state); + + if (indication == ATH_BT_A2DP) { + indication = IndicateA2DP(pInfo, + ATH_BT_A2DP, + state, + pBuffer); + } + + A_UNLOCK_FILTER(pInfo); + + if (indication == ATH_BT_NOOP) { + return; + } + + A_DEBUG(("New Indication :%d State:%s (map:0x%X)\n"), + indication, (state == STATE_ON) ? "ON" : "OFF", + FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore)); + + if (pInfo->AdapterAvailable) { + DoBtStateAction(pInfo, indication, state); + } + +} + +static void +AthFilterAclDataInCallback(void *pContext, unsigned char *pBuffer, int Length) +{ + ATHBT_STATE_INDICATION indication; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pContext; + ATHBT_STATE state; + + if (pInfo->Shutdown) { + return; + } + + A_LOCK_FILTER(pInfo); + + indication = FCore_FilterACLDataIn(&pInfo->FilterCore, + pBuffer, + Length, + &state); + + if (indication == ATH_BT_A2DP) { + indication = IndicateA2DP(pInfo, + ATH_BT_A2DP, + state, + pBuffer); + } + + A_UNLOCK_FILTER(pInfo); + + if (indication == ATH_BT_NOOP) { + return; + } + + A_DEBUG(("New Indication :%d State:%s (map:0x%X)\n"), + indication, (state == STATE_ON) ? "ON" : "OFF", + FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore)); + + if (pInfo->AdapterAvailable) { + DoBtStateAction(pInfo, indication, state); + } +} + +static void +AthFilterIndicateStateCallback(void *pContext, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, unsigned char LMPVersion) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pContext; + ATHBT_STATE newState; + + if (pInfo->Shutdown) { + return; + } + + A_LOCK_FILTER(pInfo); + Indication = FCore_FilterIndicatePreciseState(&pInfo->FilterCore, + Indication, State, &newState); + A_UNLOCK_FILTER(pInfo); + + if (Indication == ATH_BT_NOOP) { + return; + } + + A_DEBUG(("New Indication :%d State:%s (map:0x%X) \r\n"), + Indication, (newState == STATE_ON) ? "ON" : "OFF", + FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore)); + + if ((newState == STATE_ON) && (LMPVersion < 5)) { + pInfo->LMPVersion = LMPVersion; + } + + if (pInfo->AdapterAvailable) { + DoBtStateAction(pInfo, Indication, newState); + } +} + +static void * +FilterThread(void *pContext) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pContext; + + A_INFO("Starting the BT Filter task\n"); + while (1) { + /* Wait to be woken up the BT thread */ + A_MUTEX_LOCK(&pInfo->hWakeEventLock); + A_COND_WAIT(&pInfo->hWakeEvent, &pInfo->hWakeEventLock, WAITFOREVER); + A_MUTEX_UNLOCK(&pInfo->hWakeEventLock); + + if (pInfo->AdapterAvailable) { + ProcessBTActionMessages(pInfo, BTACTION_QUEUE_NORMAL, ATH_BT_NOOP); + } + + if (pInfo->Shutdown) { + /* + * before we exit we need to counter-act the coexistence + * settings. Currently we just indicate that each state is now + * OFF (if they are ON). This state synchronization is typically + * required on HOT-removable BT adapters or where the low level + * adapter can be surprise removed before the BT stack can clean + * up HCI connections and states + */ + if (pInfo->AdapterAvailable) { + int indication, newIndication; + ATHBT_STATE newState; + + /* + * the BT adapter is going away, indicate that all indications + * are now in the OFF state, this may queue up control action + * messages, which is okay + */ + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; + indication++) + { + A_LOCK_FILTER(pInfo); + newIndication = + FCore_FilterIndicatePreciseState(&pInfo->FilterCore, + indication, STATE_OFF, &newState); + A_UNLOCK_FILTER(pInfo); + + if (newIndication == ATH_BT_NOOP) { + continue; + } + + DoBtStateAction(pInfo, indication, newState); + } + + /* issue control actions */ + ProcessBTActionMessages(pInfo, BTACTION_QUEUE_SYNC_STATE, + ATH_BT_NOOP); + } + + break; + } + } + + A_INFO("Terminating the BT Filter task\n"); + return NULL; +} + +static void +ProcessBTActionMessages(ATHBT_FILTER_INFO *pInfo, + BTACTION_QUEUE_PROC Process, + ATHBT_STATE_INDICATION StateToFlush) +{ + BT_ACTION_MSG *pActionMsg = NULL; + DL_LIST *pListEntry = NULL; + + A_LOCK_FILTER(pInfo); + + while (1) { + /* determine how we want to pull the message out */ + if (BTACTION_QUEUE_FLUSH_STATE == Process) { + if (NULL == pListEntry) { + /* first time through */ + if (!DL_LIST_IS_EMPTY(&pInfo->BTActionMsgList)) { + /* get the entry at the head of the list , don't remove */ + pListEntry = + DL_LIST_GET_ITEM_AT_HEAD(&pInfo->BTActionMsgList); + } + } else { + /* move onto the next one */ + pListEntry = pListEntry->pNext; + if (pListEntry == &pInfo->BTActionMsgList) { + /* reached the end */ + pListEntry = NULL; + } + } + } else { + /* + * for all others we are removing items from the head of the + * queue + */ + pListEntry = DL_ListRemoveItemFromHead(&pInfo->BTActionMsgList); + } + + if (NULL == pListEntry) { + /* queue was empty */ + break; + } + + pActionMsg = A_CONTAINING_STRUCT(pListEntry, BT_ACTION_MSG, ListEntry); + + /* now determine what to do with the message that was found */ + switch (Process) { + case BTACTION_QUEUE_FLUSH_STATE: + /* + * caller wants to just flush action messages matching a + * state + */ + if (pActionMsg->StateForControlAction == StateToFlush) { + A_DEBUG(("Removed action for state=%d from queue\n"), + StateToFlush); + + /* remove from list, it will get freed below */ + DL_ListRemove(&pActionMsg->ListEntry); + + /* + * this would re-start the scan to the head of the list + * each time we found one. This type of flush doesn't + * happen very often so restarting from the head of the + * list and rescanning isn't time consuming + */ + pListEntry = NULL; + } else { + /* not the one we are interested in */ + pActionMsg = NULL; + } + break; + + case BTACTION_QUEUE_NORMAL: + case BTACTION_QUEUE_SYNC_STATE: + /* issue/execute actions */ + A_UNLOCK_FILTER(pInfo); + A_DEBUG(("Processing action for indication=%d (%s) (%s)\n"), + pActionMsg->IndicationForControlAction, + (pActionMsg->StateForControlAction == STATE_ON) ? + "ON" : "OFF", (BTACTION_QUEUE_SYNC_STATE == Process) ? + "Sync State" : "Normal"); + + if (BTACTION_QUEUE_SYNC_STATE == Process) { + /* let's not issue these too fast ... */ + usleep(10000); + } + + ExecuteBtAction(pInfo, pActionMsg); + + if (pActionMsg->Blocking) { + pActionMsg->Blocking = FALSE; + + /* set the event to unblock the caller */ + A_MUTEX_LOCK(&pActionMsg->hWaitEventLock); + A_COND_SIGNAL(&pActionMsg->hWaitEvent); + A_MUTEX_UNLOCK(&pActionMsg->hWaitEventLock); + } + A_LOCK_FILTER(pInfo); + break; + + case BTACTION_QUEUE_FLUSH_ALL: + A_DEBUG(("Flushed action for state=%d from queue\n"), + pActionMsg->StateForControlAction); + /* + * nothing to do here, the action message will get + * recycled below + */ + break; + + default: + break; + } + + if (pActionMsg) { + /* recycle message */ + FREE_BT_ACTION_MSG(pInfo, pActionMsg); + } + } + + A_UNLOCK_FILTER(pInfo); +} + +static void +SyncBTState(ATHBT_FILTER_INFO *pInfo) +{ + int stateIndication; + A_UINT32 stateBitMap; + + A_LOCK_FILTER(pInfo); + stateBitMap = FCore_GetCurrentBTStateBitMap(&pInfo->FilterCore); + A_UNLOCK_FILTER(pInfo); + + /* + * the state bit map is a simple STATE ON/OFF bit map, if we detect + * that one of the states is ON we process the BT action to synchronize + * the WLAN side with the BT radio state + */ + for (stateIndication = 0; stateIndication < ATH_BT_MAX_STATE_INDICATION; + stateIndication++) + { + if (stateBitMap & (1 << stateIndication)) { + /* this state is ON */ + DoBtStateAction(pInfo, stateIndication, STATE_ON); + } + } + +} + +void +HandleAdapterEvent(ATHBT_FILTER_INFO *pInfo, ATH_ADAPTER_EVENT Event) +{ + A_UINT32 btfiltFlags; + switch (Event) { + case ATH_ADAPTER_ARRIVED: + A_INFO("BT Filter Core : WLAN Arrived \n"); + btfiltFlags = pInfo->Flags; + Abf_WlanCheckSettings(pInfo->pWlanInfo->IfName, &btfiltFlags); + if (btfiltFlags != pInfo->Flags) { + A_STATUS status; + BT_FILTER_CORE_INFO *pCoreInfo = &pInfo->FilterCore; + pInfo->Flags &= ~ABF_WIFI_CHIP_IS_VENUS; + pInfo->Flags |= (btfiltFlags & ABF_WIFI_CHIP_IS_VENUS); + pCoreInfo->FilterState.btFilterFlags &= ~ABF_WIFI_CHIP_IS_VENUS; + pCoreInfo->FilterState.btFilterFlags |= (btfiltFlags & ABF_WIFI_CHIP_IS_VENUS); + FCore_ResetActionDescriptors(pCoreInfo); + GetActionStringOverrides(pInfo); + status = FCore_RefreshActionList(pCoreInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed refresh action list (status:%d)\n", + __FUNCTION__, status); + } + } + + pInfo->AdapterAvailable = TRUE; + + Abf_WlanIssueFrontEndConfig(pInfo); + + Abf_WlanGetCurrentWlanOperatingFreq(pInfo); + /* sync BT state */ + SyncBTState(pInfo); + +#if 0 + /* + * the call to sync BT state may queue a bunch of actions to + * the action queue, we want to issues these differently + */ + ProcessBTActionMessages(pInfo, BTACTION_QUEUE_SYNC_STATE, + ATH_BT_NOOP); +#endif + break; + + case ATH_ADAPTER_REMOVED: + A_INFO("BT Filter Core : WLAN removed \n"); + pInfo->AdapterAvailable = FALSE; + + /* flush messages */ + ProcessBTActionMessages(pInfo, BTACTION_QUEUE_FLUSH_ALL, + ATH_BT_NOOP); + break; + default: + break; + } +} + +/* execute the BT action + * this function is called by the single dispatcher thread + */ +static void +ExecuteBtAction(ATHBT_FILTER_INFO *pInfo, BT_ACTION_MSG *pBtActionMsg) +{ + A_UINT32 size; + A_UINT32 controlCode; + A_STATUS status; + + + if(pInfo->Flags & ABF_WIFI_CHIP_IS_VENUS) { + if (pBtActionMsg->ControlAction.Type == BT_CONTROL_ACTION_STATUS) { + /* this action issues a STATUS OID command */ + controlCode = AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS; + size = sizeof(WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD); + } else { + if(pBtActionMsg->IndicationForControlAction == ATH_BT_SCO || + pBtActionMsg->IndicationForControlAction == ATH_BT_ESCO) + { + controlCode = AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG; + size = sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD); + } + if(pBtActionMsg->IndicationForControlAction == ATH_BT_A2DP){ + controlCode = AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG; + size = sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD); + } + } + }else { + if (pBtActionMsg->ControlAction.Type == BT_CONTROL_ACTION_STATUS) { + /* this action issues a STATUS OID command */ + controlCode = AR6000_XIOCTL_WMI_SET_BT_STATUS; + } else { + /* this action issues a PARAMS OID command */ + controlCode = AR6000_XIOCTL_WMI_SET_BT_PARAMS; + } + size = sizeof(WMI_SET_BT_PARAMS_CMD); + } + if (pBtActionMsg->ControlAction.Length > size) { + A_ERR("Bad control action length : %d \n", pBtActionMsg->ControlAction.Length); + return; + } + do + { + A_UCHAR buf[sizeof(A_UINT32) + size]; + + A_MEMZERO(buf, sizeof(buf)); + A_MEMCPY(buf, &controlCode, sizeof(A_UINT32)); + A_MEMCPY((buf + sizeof(A_UINT32)), (void *)pBtActionMsg->ControlAction.Buffer, + pBtActionMsg->ControlAction.Length); + status = Abf_WlanDispatchIO(pInfo, AR6000_IOCTL_EXTENDED, (void *)buf, + pBtActionMsg->ControlAction.Length + sizeof(A_UINT32)); + + if (A_FAILED(status)) { + /* these can actually fail if the device powers down */ + A_ERR("[%s] BT Action issue failed, Ioctl: 0x%x, Len: %d\n", + __FUNCTION__, ((int *)buf)[0], + pBtActionMsg->ControlAction.Length); + } else { + A_DEBUG("BT Action issued to WLAN Adapter, Ioctl: 0x%x, Len: %d\n", + ((int *)buf)[0], pBtActionMsg->ControlAction.Length); + A_DUMP_BUFFER(pBtActionMsg->ControlAction.Buffer, + pBtActionMsg->ControlAction.Length, + "BT Control Action"); + } + }while(FALSE); +} + +static void +ProcessActionOverride(ATHBT_FILTER_INFO *pInfo, + A_CHAR *pIndicationStr, + A_CHAR *pModifyAction, + A_CHAR *pAction) +{ + int i; + ATHBT_STATE_INDICATION indication; + ATHBT_STATE state = STATE_MAX; + ATHBT_MODIFY_CONTROL_ACTION modifyAction = + ATHBT_MODIFY_CONTROL_ACTION_NOOP; + char charBuffer[MAX_VAL_DATA_LENGTH]; + + /* + * parse the indication string to figure which indication and state + * to change i.e. -ON or -OFF + */ + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; + indication++) + { + if (strstr(pIndicationStr, g_IndicationStrings[indication]) != NULL) { + /* found one */ + if (strstr(pIndicationStr, "-ON") != NULL) { + state = STATE_ON; + } + + if (strstr(pIndicationStr, "-OFF") != NULL) { + state = STATE_OFF; + } + + if (strstr(pModifyAction, "REPLACE") != NULL) { + modifyAction = ATHBT_MODIFY_CONTROL_ACTION_REPLACE; + } + + if (strstr(pModifyAction, "APPEND") != NULL) { + modifyAction = ATHBT_MODIFY_CONTROL_ACTION_APPEND; + } + + break; + } + } + + if ((indication == ATH_BT_MAX_STATE_INDICATION) || + (state == STATE_MAX) || + (modifyAction == ATHBT_MODIFY_CONTROL_ACTION_NOOP)) + { + return; + } + + A_DEBUG("Found Action override : %s (%s) (%s)\n", + pIndicationStr, pModifyAction, pAction); + + A_MEMZERO(charBuffer, sizeof(charBuffer)); + + for (i = 0; (i < (int)strlen(pAction)) && (i < (MAX_VAL_DATA_LENGTH - 1)); + i++) + { + charBuffer[i] = (char)pAction[i]; + } + + FCore_ModifyControlActionString(&pInfo->FilterCore, + indication, + state, + charBuffer, + i, + modifyAction); +} + +static void +GetActionStringOverrides(ATHBT_FILTER_INFO *pInfo) +{ + A_CHAR *ptr, *indication, *modify, *action; + A_CHAR *string = (A_CHAR *)A_MALLOC(MAX_VAL_DATA_LENGTH); + + if (!(gConfigFile)) return; + + fgets(string, MAX_VAL_DATA_LENGTH, gConfigFile); + while (!(feof(gConfigFile))) { + ptr = string; + indication = strsep(&string, ":"); + modify = strsep(&string, ":"); + action = string; + ProcessActionOverride(pInfo, indication, modify, action); + string = ptr; + fgets(string, MAX_VAL_DATA_LENGTH, gConfigFile); + } + + A_FREE(string); +} diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_int.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_int.h new file mode 100644 index 000000000000..a8e51e27e93f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_int.h @@ -0,0 +1,281 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +/* + * Bluetooth filter internal definitions + * + */ + + +#ifndef ABTFILT_INT_H_ +#define ABTFILT_INT_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "a_config.h" +#include "a_osapi.h" +#include "athdefs.h" +#include "a_types.h" +#include "a_debug.h" +#include "dl_list.h" +#include "athbtfilter.h" +#include "btfilter_core.h" +#include "athdrv_linux.h" +#include "wmi.h" + +#ifndef IW_EV_LCP_PK_LEN +#define IW_EV_LCP_PK_LEN (4) +#define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4) +#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \ + (char *) NULL) +#define IW_EV_POINT_LEN (IW_EV_LCP_LEN + sizeof(struct iw_point) - \ + IW_EV_POINT_OFF) +#endif + +/* Forward Declarations */ +struct _ABF_BT_INFO; +struct _ABF_WLAN_INFO; + +/*-----------------------------------------------------------------------*/ +/* Utils Section */ + +/* Task Management operations and definitions */ +#define WAITFOREVER -1 +#define A_TASK_HANDLE pthread_t +#define A_COND_OBJECT pthread_cond_t +#define A_MUTEX_OBJECT pthread_mutex_t +#define A_FILE_HANDLE FILE * + +/* Function Prototypes */ +INLINE A_STATUS A_TASK_CREATE(A_TASK_HANDLE *handle, + void *(*func)(void *), void *arg); +INLINE A_STATUS A_TASK_JOIN(A_TASK_HANDLE *handle); +INLINE void A_TASK_CLEANUP(void); + +INLINE A_STATUS A_MUTEX_INIT(A_MUTEX_OBJECT *mutex); +INLINE void A_MUTEX_LOCK(A_MUTEX_OBJECT *mutex); +INLINE void A_MUTEX_UNLOCK(A_MUTEX_OBJECT *mutex); +INLINE void A_MUTEX_DEINIT(A_MUTEX_OBJECT *mutex); + +INLINE A_STATUS A_COND_INIT(A_COND_OBJECT *cond); +INLINE A_STATUS A_COND_WAIT(A_COND_OBJECT *cond, + A_MUTEX_OBJECT *mutex, int timeout); +INLINE void A_COND_SIGNAL(A_COND_OBJECT *cond); +INLINE void A_COND_DEINIT(A_COND_OBJECT *cond); +INLINE A_STATUS A_COND_RESET(A_COND_OBJECT *cond); + +INLINE void A_STR2ADDR(const char *str, A_UINT8 *addr); + +#ifdef ABF_DEBUG +INLINE void A_DBG_INIT(const char *ident, const char *message, ...); +INLINE void A_DEBUG(const char *format, ...); +INLINE void A_INFO(const char *format, ...); +INLINE void A_ERR(const char *format, ...); +INLINE void A_SET_DEBUG(int enable); +INLINE void A_DBG_DEINIT(void); +void A_DUMP_BUFFER(A_UCHAR *buffer, int length, char *pDescription); +void A_DBG_SET_OUTPUT_TO_CONSOLE(void); +#else +#define A_DBG_INIT(args...) +#define A_DEBUG(args...) +#define A_INFO(args...) +#define A_ERR(args...) +#define A_SET_DEBUG(arg) +#define A_DBG_DEINIT() +#define A_DUMP_BUFFER(buffer, length, pDescription) +#define A_DBG_SET_OUTPUT_TO_CONSOLE() + +#endif /* ABF_DEBUG */ +/*-----------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------*/ +/* Filter Section */ +#define MAX_BT_ACTION_MESSAGES 16 +#define ACTION_WAIT_TIMEOUT 100 + +#define QUEUE_BT_ACTION_MSG(p,a) \ + DL_ListInsertTail(&(p)->BTActionMsgList,&(a)->ListEntry) +#define FREE_BT_ACTION_MSG(p,a) \ + DL_ListInsertTail(&(p)->FreeActionMsgList,&(a)->ListEntry) + +#define A_LOCK_FILTER(p) \ + A_MUTEX_LOCK(&((p)->CritSection)) + +#define A_UNLOCK_FILTER(p) \ + A_MUTEX_UNLOCK(&((p)->CritSection)) + +typedef enum _BTACTION_QUEUE_PROC { + BTACTION_QUEUE_NORMAL = 0, /* normal processing of the action queue */ + BTACTION_QUEUE_FLUSH_ALL = 1, /* flush all actions for shutdown */ + BTACTION_QUEUE_FLUSH_STATE, /* flush all actions associated with a + specific state */ + BTACTION_QUEUE_SYNC_STATE /* issue queued actions when we are + syncing radio state on adapter + available */ +} BTACTION_QUEUE_PROC; + +typedef enum _ATH_ADAPTER_EVENT { + ATH_ADAPTER_ARRIVED = 0, + ATH_ADAPTER_REMOVED = 1, +} ATH_ADAPTER_EVENT; + +typedef struct _BT_ACTION_MSG { + DL_LIST ListEntry; + A_COND_OBJECT hWaitEvent; /* wait object for + blocking requests */ + A_MUTEX_OBJECT hWaitEventLock; + A_BOOL Blocking; /* this action requires + the calling thread to + block until the + dispatcher submits + the command */ + ATHBT_STATE_INDICATION IndicationForControlAction; /* indication + associated + with the + control + action */ + ATHBT_STATE StateForControlAction; + BT_CONTROL_ACTION ControlAction; +} BT_ACTION_MSG; + +typedef struct _ATHBT_SCO_CONNECTION_INFO { + A_BOOL Valid; + A_UCHAR LinkType; + A_UCHAR TransmissionInterval; + A_UCHAR RetransmissionInterval; + A_UINT16 RxPacketLength; + A_UINT16 TxPacketLength; +} ATHBT_SCO_CONNECTION_INFO; + +typedef struct _ATHBT_FILTER_INFO { + ATH_BT_FILTER_INSTANCE *pInstance; + A_UINT32 MaxBtActionMessages; + A_MUTEX_OBJECT CritSection; + DL_LIST BTActionMsgList; + DL_LIST FreeActionMsgList; + BT_FILTER_CORE_INFO FilterCore; + A_BOOL Shutdown; + A_COND_OBJECT hWakeEvent; + A_MUTEX_OBJECT hWakeEventLock; + A_TASK_HANDLE hFilterThread; + A_BOOL FilterThreadValid; + ATHBT_SCO_CONNECTION_INFO SCOConnectInfo; + A_UCHAR LMPVersion; + A_BOOL AdapterAvailable; + A_TASK_HANDLE hBtThread; + A_TASK_HANDLE hWlanThread; + struct _ABF_WLAN_INFO *pWlanInfo; + struct _ABF_BT_INFO *pBtInfo; + A_UCHAR SCOConnection_LMPVersion; /* lmp version of remote SCO device */ + A_UCHAR A2DPConnection_LMPVersion; /* lmp version of remote A2DP device */ + A_UCHAR SCOConnection_Role; /* role of remote SCO device */ + A_UCHAR A2DPConnection_Role; /* role of remote A2DP device */ + A_UINT32 Flags; +} ATHBT_FILTER_INFO; + +/* Function Prototypes */ +void HandleAdapterEvent(ATHBT_FILTER_INFO *pInfo, ATH_ADAPTER_EVENT Event); +/*-----------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------*/ +/* WLAN Section */ +#define WLAN_ADAPTER_NAME_SIZE_MAX 31 + +#define WLAN_GET_HOME_CHANNEL(pInfo) \ + (pInfo)->pAbfWlanInfo->Channel + +typedef struct _ABF_WLAN_INFO { + ATHBT_FILTER_INFO *pInfo; + A_INT32 Handle; + A_UINT8 PhyCapability; + A_UCHAR AdapterName[WLAN_ADAPTER_NAME_SIZE_MAX+1]; + A_UINT32 HostVersion; + A_UINT32 TargetVersion; + A_CHAR IfName[IFNAMSIZ]; + A_INT32 IfIndex; + A_BOOL Loop; + A_COND_OBJECT hWaitEvent; + A_MUTEX_OBJECT hWaitEventLock; + A_UINT16 Channel; +} ABF_WLAN_INFO; + +/* Function Prototypes */ +void Abf_WlanCheckSettings(A_CHAR *wifname, A_UINT32 *btfiltFlags); +A_STATUS Abf_WlanStackNotificationInit(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 flags); +void Abf_WlanStackNotificationDeInit(ATH_BT_FILTER_INSTANCE *pInstance); +A_STATUS Abf_WlanDispatchIO(ATHBT_FILTER_INFO *pInfo, unsigned long int req, + void *data, int size); +/*-----------------------------------------------------------------------*/ + +/* Function Prototypes */ + +#define ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION (1 << 0) +#define ABF_USE_HCI_FILTER_FOR_HEADSET_PROFILE (1 << 1) +#define ABF_WIFI_CHIP_IS_VENUS (1 << 2) +#define ABF_BT_CHIP_IS_ATHEROS (1 << 3) +#define ABF_USE_ONLY_DBUS_FILTERING (1 << 4) +#define ABF_FE_ANT_IS_SA (1 << 5) + +A_STATUS Abf_BtStackNotificationInit(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 Flags); +void Abf_BtStackNotificationDeInit(ATH_BT_FILTER_INSTANCE *pInstance); + +#ifdef CONFIG_NO_HCILIBS +#define Abf_HciLibInit(_flags) (A_ERROR) +#define Abf_HciLibDeInit() +#define Abf_RegisterToHciLib(_pInfo) +#define Abf_UnRegisterToHciLib(_pInfo) +#define Abf_IssueAFHViaHciLib(_pInfo, _ch) do { } while (0) +#else +A_STATUS Abf_HciLibInit(A_UINT32 *flags); +void Abf_HciLibDeInit(void); +void Abf_RegisterToHciLib(struct _ABF_BT_INFO * pAbfBtInfo); +void Abf_UnRegisterToHciLib(struct _ABF_BT_INFO * pAbfBtInfo); +A_STATUS Abf_IssueAFHViaHciLib (struct _ABF_BT_INFO * pAbfBtInfo, int CurrentWLANChannel); +#endif + +/* WLAN channel number can be expressed as either 1-14 or expressed in Mhz (i.e. 2412) */ +void IndicateCurrentWLANOperatingChannel(ATHBT_FILTER_INFO *pFilterInfo, int CurrentWLANChannel); + +/*-----------------------------------------------------------------------*/ + +A_STATUS Abf_WlanGetSleepState(ATHBT_FILTER_INFO * pInfo); +A_STATUS Abf_WlanGetCurrentWlanOperatingFreq(ATHBT_FILTER_INFO * pInfo); +A_STATUS Abf_WlanIssueFrontEndConfig(ATHBT_FILTER_INFO * pInfo); +#endif /* ABTFILT_INT_H_ */ diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_main.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_main.c new file mode 100644 index 000000000000..ceec73e8d4a2 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_main.c @@ -0,0 +1,237 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +/* + * Bluetooth Filter Main Routine + * + */ +#include "abtfilt_int.h" + +const char *progname; +A_CHAR wifname[IFNAMSIZ]; +static ATH_BT_FILTER_INSTANCE g_AthBtFilterInstance; +A_FILE_HANDLE gConfigFile; +static volatile sig_atomic_t terminated; +ATHBT_FILTER_INFO *GpInfo=NULL; +static void +usage(void) +{ + fprintf(stderr, "usage:\n%s [options] \n", progname); + fprintf(stderr, " -n : do not run as a daemon \n"); + fprintf(stderr, " -d : enable debug logging \n"); + fprintf(stderr, " -c : output debug logs to the console \n"); + fprintf(stderr, " -a : issue AFH channel classification when WLAN connects \n"); + fprintf(stderr, " -f : specify configuration file with overrides \n"); + fprintf(stderr, " -z : use HCI filtering for headset profile state notifications (Android-Only) \n"); + fprintf(stderr, " -x : co-located bt is Atheros \n"); + fprintf(stderr, " -w : wlan adapter name (wlan0/eth1, etc.)\n"); + fprintf(stderr, " -b : Use only d-bus filtering (on interfaces which doesnt support hciX\n"); + fprintf(stderr, " -s : Front End is single antenna (if not specified, its assumed to be dual antenna with atleast 25 dB of isolation)\n"); +} + +void +Abf_ShutDown(void) +{ + A_INFO("Shutting Down\n"); + + /* Clean up all the resources */ + Abf_BtStackNotificationDeInit(&g_AthBtFilterInstance); + Abf_WlanStackNotificationDeInit(&g_AthBtFilterInstance); + AthBtFilter_Detach(&g_AthBtFilterInstance); + + A_INFO("Shutting Down Complete\n"); +} + +static void +Abf_SigTerm(int sig) +{ + /* unblock main thread */ + terminated = 1; +} + +int +main(int argc, char *argv[]) +{ + int ret; + char *config_file = NULL; + int opt = 0, daemonize = 1, debug = 0, console_output=0; + progname = argv[0]; + A_STATUS status; + struct sigaction sa; + ATHBT_FILTER_INFO *pInfo; + A_UINT32 btfiltFlags = 0; + + A_MEMZERO(&g_AthBtFilterInstance, sizeof(ATH_BT_FILTER_INSTANCE)); + + /* + * Keep an option to specify the wireless extension. By default, + * assume it to be equal to WIRELESS_EXT TODO + */ + + /* Get user specified options */ + while ((opt = getopt(argc, argv, "bsvandczxf:w:")) != EOF) { + switch (opt) { + case 'n': + daemonize = 0; + break; + + case 'd': + debug = 1; + break; + + case 'f': + if (optarg) { + config_file = strdup(optarg); + } + break; + case 'c': + console_output = 1; + break; + case 'a': + btfiltFlags |= ABF_ENABLE_AFH_CHANNEL_CLASSIFICATION; + break; + case 'z': + btfiltFlags |= ABF_USE_HCI_FILTER_FOR_HEADSET_PROFILE; + break; + case 'v': + btfiltFlags |= ABF_WIFI_CHIP_IS_VENUS ; + A_DEBUG("wifi chip is venus\n"); + break; + case 'x': + btfiltFlags |= ABF_BT_CHIP_IS_ATHEROS ; + A_DEBUG("bt chip is atheros\n"); + break; + case 's': + btfiltFlags |= ABF_FE_ANT_IS_SA ; + A_DEBUG("Front End Antenna Configuration is single antenna \n"); + break; + case 'w': + memset(wifname, '\0', IFNAMSIZ); + strcpy(wifname, optarg); + g_AthBtFilterInstance.pWlanAdapterName = (A_CHAR *)&wifname; + break; + case 'b': + btfiltFlags |= ABF_USE_ONLY_DBUS_FILTERING; + break; + default: + usage(); + exit(1); + } + } + + /* Launch the daemon if desired */ + if (daemonize && daemon(0, console_output ? 1 : 0)) { + printf("Can't daemonize: %s\n", strerror(errno)); + exit(1); + } + + /* Initialize the debug infrastructure */ + A_DBG_INIT("ATHBT", "Ath BT Filter Daemon"); + if (debug) { + if (console_output) { + A_DBG_SET_OUTPUT_TO_CONSOLE(); + } + // setlogmask(LOG_INFO | LOG_DEBUG | LOG_ERR); + A_INFO("Enabling Debug Information\n"); + A_SET_DEBUG(1); + } + + if (config_file) { + A_DEBUG("Config file: %s\n", config_file); + if (!(gConfigFile = fopen(config_file, "r"))) + { + A_ERR("[%s] fopen failed\n", __FUNCTION__); + } + } + + A_MEMZERO(&sa, sizeof(struct sigaction)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = Abf_SigTerm; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + + sa.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sa, NULL); + + Abf_HciLibInit(&btfiltFlags); + + /* Initialize the Filter core */ + do { + Abf_WlanCheckSettings(wifname, &btfiltFlags); + ret = AthBtFilter_Attach(&g_AthBtFilterInstance, btfiltFlags ); + if (ret) { + A_ERR("Filter initialization failed\n"); + break; + } + + /* Initialize the WLAN notification mechanism */ + status = Abf_WlanStackNotificationInit(&g_AthBtFilterInstance, btfiltFlags ); + if (A_FAILED(status)) { + AthBtFilter_Detach(&g_AthBtFilterInstance); + A_ERR("WLAN stack notification init failed\n"); + break; + } + + /* Initialize the BT notification mechanism */ + status = Abf_BtStackNotificationInit(&g_AthBtFilterInstance,btfiltFlags); + if (A_FAILED(status)) { + Abf_WlanStackNotificationDeInit(&g_AthBtFilterInstance); + AthBtFilter_Detach(&g_AthBtFilterInstance); + A_ERR("BT stack notification init failed\n"); + break; + } + + /* Check for errors on the return value TODO */ + pInfo = g_AthBtFilterInstance.pContext; + GpInfo = pInfo; + + A_DEBUG("Service running, waiting for termination .... \n"); + + /* wait for termination signal */ + while (!terminated) { + sleep(1); + } + } while(FALSE); + + /* Initiate the shutdown sequence */ + if(GpInfo != NULL) { + AthBtFilter_State_Off(GpInfo); + } + Abf_ShutDown(); + + Abf_HciLibDeInit(); + /* Shutdown */ + if (gConfigFile) { + fclose(gConfigFile); + } + + if (config_file) { + A_FREE(config_file); + } + + A_DEBUG("Service terminated \n"); + A_MEMZERO(&g_AthBtFilterInstance, sizeof(ATH_BT_FILTER_INSTANCE)); + A_DBG_DEINIT(); + + return 0; +} diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_utils.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_utils.c new file mode 100644 index 000000000000..99b7bab6d3ae --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_utils.c @@ -0,0 +1,320 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2008 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Author(s): ="Atheros" +//============================================================================== + +/* + * Bluetooth Filter utils + * + */ +static const char athId[] __attribute__ ((unused)) = "$Id: //depot/sw/releases/olca3.1-RC/host/tools/athbtfilter/bluez/abtfilt_utils.c#2 $"; + +#include "abtfilt_int.h" +#ifdef ANDROID +#include +#endif + +#ifdef ANDROID +#define LOG_TAGS "abtfilt" +#define A_LOG_INFO ANDROID_LOG_INFO +#define A_LOG_ERR ANDROID_LOG_ERROR +#define A_LOG_DEBUG ANDROID_LOG_DEBUG +#define A_VSYSLOG(level, msg, ap) __android_log_vprint(level, LOG_TAGS, msg, ap); +#define A_SYSLOG(level, msg, args...) __android_log_print(level, LOG_TAGS, msg, ##args); +#else +#define A_LOG_INFO LOG_INFO +#define A_LOG_ERR LOG_ERR +#define A_LOG_DEBUG LOG_DEBUG +#define A_VSYSLOG(level, msg, ap) vsyslog(LOG_ERR, msg, ap) +#define A_SYSLOG syslog +#endif + +/* Task specific operations */ +INLINE A_STATUS +A_TASK_CREATE(A_TASK_HANDLE *handle, void *(*func)(void *), void *arg) +{ + int ret; + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + ret = pthread_create(handle, &attr, func, arg); + if (ret) { + A_ERR("%s Failed: %d\n", __FUNCTION__, ret); + return A_ERROR; + } + + pthread_attr_destroy(&attr); + return A_OK; +} + +INLINE A_STATUS +A_TASK_JOIN(A_TASK_HANDLE *handle) +{ + int ret; + + ret = pthread_join(*handle, NULL); + if (ret) { + A_ERR("%s Failed: %d\n", __FUNCTION__, ret); + return A_ERROR; + } + + return A_OK; +} + +INLINE void +A_TASK_CLEANUP(void) +{ + pthread_exit(NULL); +} + +/* Mutual exclusion operations */ +INLINE A_STATUS +A_MUTEX_INIT(A_MUTEX_OBJECT *mutex) +{ + int ret; + + ret = pthread_mutex_init(mutex, NULL); + if (ret) { + A_ERR("%s Failed: %d\n", __FUNCTION__, ret); + return A_ERROR; + } + + return A_OK; +} + +INLINE void +A_MUTEX_LOCK(A_MUTEX_OBJECT *mutex) +{ + pthread_mutex_lock(mutex); +} + +INLINE void +A_MUTEX_UNLOCK(A_MUTEX_OBJECT *mutex) +{ + pthread_mutex_unlock(mutex); +} + +INLINE void +A_MUTEX_DEINIT(A_MUTEX_OBJECT *mutex) +{ + pthread_mutex_destroy(mutex); +} + +/* Conditional Variable operations */ +INLINE A_STATUS +A_COND_INIT(A_COND_OBJECT *cond) +{ + int ret; + + ret = pthread_cond_init(cond, NULL); + if (ret) { + A_ERR("%s Failed: %d\n", __FUNCTION__, ret); + return A_ERROR; + } + + return A_OK; +} + +INLINE A_STATUS +A_COND_WAIT(A_COND_OBJECT *cond, A_MUTEX_OBJECT *mutex, int timeout) +{ + int ret; + struct timespec ts; + + if (timeout != WAITFOREVER) { + /* TODO: support for values equal to or more than a second */ + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_nsec += (timeout * 1000000); + ret = pthread_cond_timedwait(cond, mutex, &ts); + } else { + ret = pthread_cond_wait(cond, mutex); + } + + if (ret) { + A_ERR("%s Failed: %d\n", __FUNCTION__, ret); + return A_ERROR; + } + + return A_OK; +} + +INLINE void +A_COND_SIGNAL(A_COND_OBJECT *cond) +{ + pthread_cond_signal(cond); +} + +INLINE void +A_COND_DEINIT(A_COND_OBJECT *cond) +{ + pthread_cond_destroy(cond); +} + +INLINE A_STATUS +A_COND_RESET(A_COND_OBJECT *cond) +{ + A_COND_DEINIT(cond); + return (A_COND_INIT(cond)); +} + +/* Debug Infrastructure */ +#ifdef ABF_DEBUG +static volatile int debug_enabled = 0; +int dump_console = 0; + +void A_DBG_SET_OUTPUT_TO_CONSOLE(void) +{ + dump_console = 1; +} + + +INLINE void +A_DBG_INIT(const char *ident, const char *message, ...) +{ + va_list ap; + + openlog(ident, LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); + + va_start(ap, message); + A_VSYSLOG(A_LOG_INFO, message, ap); + va_end(ap); +} + +static void dump_to_console(const char *format, va_list args) +{ + char buffer[384]; + + vsprintf(buffer,format,args); + printf("%s", buffer); + +} + +INLINE void +A_DEBUG(const char *format, ...) +{ + va_list ap; + + if (!debug_enabled) + return; + + va_start(ap, format); + if (dump_console) { + dump_to_console(format,ap); + } else { + A_VSYSLOG(A_LOG_DEBUG, format, ap); + } + + va_end(ap); +} + +INLINE void +A_INFO(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + if (dump_console) { + dump_to_console(format,ap); + } else { + A_VSYSLOG(A_LOG_INFO, format, ap); + } + va_end(ap); +} + +INLINE void +A_ERR(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + if (dump_console) { + dump_to_console(format,ap); + } else { + A_VSYSLOG(A_LOG_ERR, format, ap); + A_SYSLOG(A_LOG_ERR, "Last Error: %s\n", strerror(errno)); + } + va_end(ap); +} + +INLINE void +A_SET_DEBUG(int enable) +{ + debug_enabled = enable; +} + +INLINE void +A_DBG_DEINIT(void) +{ + A_SET_DEBUG(0); + closelog(); +} + +void +A_DUMP_BUFFER(A_UCHAR *buffer, int length, char *pDescription) +{ + A_CHAR stream[60]; + int i; + int offset, count; + + if (!debug_enabled) { + return; + } + + A_DEBUG("<---------Dumping %d Bytes : %s ------>\n", length, pDescription); + + count = 0; + offset = 0; + for(i = 0; i < length; i++) { + sprintf(stream + offset, "%2.2X ", buffer[i]); + count ++; + offset += 3; + + if (count == 16) { + count = 0; + offset = 0; + A_DEBUG("[H]: %s\n", stream); + A_MEMZERO(stream, sizeof(stream)); + } + } + + if (offset != 0) { + A_DEBUG("[H]: %s\n", stream); + } + + A_DEBUG("<------------------------------------------------->\n"); +} +#endif /* ABF_DEBUG */ + +INLINE void +A_STR2ADDR(const char *str, A_UINT8 *addr) +{ + const char *ptr = str; + int i; + + for (i = 0; i < 6; i++) { + addr[i] = (A_UINT8) strtol(ptr, NULL, 16); + if (i != 5 && !(ptr = strchr(ptr, ':'))) { + ptr = ":00:00:00:00:00"; + } + ptr++; + } +} diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_wlan.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_wlan.c new file mode 100644 index 000000000000..2b534c99c879 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/abtfilt_wlan.c @@ -0,0 +1,836 @@ + +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Bluetooth filter core action tables and action lookup +// +// Author(s): ="Atheros" +//============================================================================== +/* + * Bluetooth Filter - WLAN module + * + */ + +#include "abtfilt_int.h" +#ifdef ANDROID +#include "cutils/properties.h" +#endif + +/* Definitions */ +#define WLAN_EVENT_SIZE_MAX 1024 +#define IW_HEADER_TYPE_POINT 8 + +/* Function Prototypes */ +static void NewLinkEvent(ATH_BT_FILTER_INSTANCE *pInstance, + struct nlmsghdr *h, int len); +static void DelLinkEvent(ATH_BT_FILTER_INSTANCE *pInstance, + struct nlmsghdr *h, int len); +static void WirelessEvent(ATH_BT_FILTER_INSTANCE *pInstance, + char *data, int len); +static A_STATUS WirelessCustomEvent(ATH_BT_FILTER_INSTANCE *pInstance, + char *buf, int len); +static A_STATUS AcquireWlanAdapter(ABF_WLAN_INFO *pAbfWlanInfo); +static void ReleaseWlanAdapter(ABF_WLAN_INFO *pAbfWlanInfo); +static void *WlanEventThread(void *arg); +static A_STATUS GetAdapterInfo(ABF_WLAN_INFO *pAbfWlanInfo); + +/* APIs exported to other modules */ +A_STATUS +Abf_WlanStackNotificationInit(ATH_BT_FILTER_INSTANCE *pInstance, A_UINT32 flags) +{ + A_STATUS status; + ATHBT_FILTER_INFO *pInfo; + ABF_WLAN_INFO *pAbfWlanInfo; + + pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + if (pInfo->pWlanInfo) { + return A_OK; + } + + pAbfWlanInfo = (ABF_WLAN_INFO *)A_MALLOC(sizeof(ABF_WLAN_INFO)); + A_MEMZERO(pAbfWlanInfo,sizeof(ABF_WLAN_INFO)); + + A_MUTEX_INIT(&pAbfWlanInfo->hWaitEventLock); + A_COND_INIT(&pAbfWlanInfo->hWaitEvent); + A_MEMZERO(pAbfWlanInfo, sizeof(ABF_WLAN_INFO)); + pAbfWlanInfo->pInfo = pInfo; + pAbfWlanInfo->Loop = TRUE; + pInfo->pWlanInfo = pAbfWlanInfo; + + /* Spawn a thread which will be used to process events from WLAN */ + status = A_TASK_CREATE(&pInfo->hWlanThread, WlanEventThread, pAbfWlanInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to spawn a WLAN thread\n", __FUNCTION__); + return A_ERROR; + } + + A_INFO("WLAN Stack Notification init complete\n"); + + return A_OK; +} + +void +Abf_WlanStackNotificationDeInit(ATH_BT_FILTER_INSTANCE *pInstance) +{ + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_WLAN_INFO *pAbfWlanInfo = pInfo->pWlanInfo; + + if (!pAbfWlanInfo) return; + + /* Terminate and wait for the WLAN Event Handler task to finish */ + A_MUTEX_LOCK(&pAbfWlanInfo->hWaitEventLock); + if (pAbfWlanInfo->Loop) { + pAbfWlanInfo->Loop = FALSE; + A_COND_WAIT(&pAbfWlanInfo->hWaitEvent, &pAbfWlanInfo->hWaitEventLock, + WAITFOREVER); + } + A_MUTEX_UNLOCK(&pAbfWlanInfo->hWaitEventLock); + + /* Flush all the BT actions from the filter core */ + HandleAdapterEvent(pInfo, ATH_ADAPTER_REMOVED); + pInfo->pWlanInfo = NULL; + A_MUTEX_DEINIT(&pAbfWlanInfo->hWaitEventLock); + A_COND_DEINIT(&pAbfWlanInfo->hWaitEvent); + A_MEMZERO(pAbfWlanInfo, sizeof(ABF_WLAN_INFO)); + A_FREE(pAbfWlanInfo); + + A_INFO("WLAN Stack Notification de-init complete\n"); +} + +A_STATUS +Abf_WlanDispatchIO(ATHBT_FILTER_INFO *pInfo, unsigned long int req, + void *data, int size) +{ + int ret; + struct ifreq ifr; + char ifname[IFNAMSIZ], *ethIf; + ABF_WLAN_INFO *pAbfWlanInfo = pInfo->pWlanInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + + if (!pAbfWlanInfo->Handle) { + /* No adapter to issue ioctl on */ + return A_DEVICE_NOT_FOUND; + } + + /* Get the adpater name from command line if specified */ + if (pInstance->pWlanAdapterName != NULL) { + ethIf = pInstance->pWlanAdapterName; + } else { + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = pAbfWlanInfo->IfName; + } + } + /* Frame and issue the requested ioctl to the WLAN adapter */ + A_MEMZERO(ifname, IFNAMSIZ); + strcpy(ifname, ethIf); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + ifr.ifr_data = (void *)data; + if ((ret = ioctl(pAbfWlanInfo->Handle, req, &ifr)) < 0) { + A_ERR("[%s] [%s] IOCTL (req:0x%X, data: 0x%X size:%d) call failed!: %d\n", + __FUNCTION__, ifr.ifr_name, req, (A_UINT32)ifr.ifr_data, size, ret); + return A_ERROR; + } + return A_OK; +} + +/* Internal functions */ +static void * +WlanEventThread(void *arg) +{ + int left, ret, sd; + struct timeval tv; + socklen_t fromlen; + struct nlmsghdr *h; + fd_set readfds, tempfds; + char buf[WLAN_EVENT_SIZE_MAX]; + struct sockaddr_nl from, local; + ABF_WLAN_INFO *pAbfWlanInfo = (ABF_WLAN_INFO *)arg; + ATHBT_FILTER_INFO *pInfo = pAbfWlanInfo->pInfo; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + A_STATUS status; + + A_INFO("Starting the WLAN Event Handler task\n"); + + A_INFO("Checking WLAN adapter on startup .. \n"); + + if (!pInstance->pWlanAdapterName) { + Abf_WlanCheckSettings(pAbfWlanInfo->IfName, NULL); + if (pAbfWlanInfo->IfName[0]) { + pAbfWlanInfo->IfIndex = if_nametoindex(pAbfWlanInfo->IfName); + } + } + status = AcquireWlanAdapter(pAbfWlanInfo); + + if (A_FAILED(status)) { + A_INFO("No WLAN adapter on startup (OKAY) \n"); + }else { + /* Communicate this to the Filter task */ + HandleAdapterEvent(pInfo, ATH_ADAPTER_ARRIVED); + A_INFO("WLAN Adapter Added\n"); + } + + + do { + sd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (sd < 0) { + A_ERR("[%s] socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE): %d\n", + __FUNCTION__, sd); + break; + } + + A_MEMZERO(&local, sizeof(struct sockaddr_nl)); + local.nl_family = AF_NETLINK; + local.nl_groups = RTMGRP_LINK; + if ((ret = bind(sd, (struct sockaddr *) &local, sizeof(local))) < 0) { + A_ERR("[%s] bind(netlink): %d\n", __FUNCTION__, ret); + close(sd); + break; + } + + FD_ZERO(&readfds); + FD_SET(sd, &readfds); + while (pAbfWlanInfo->Loop) { + A_MEMCPY(&tempfds, &readfds, sizeof(fd_set)); + tv.tv_sec = 1; + tv.tv_usec = 0; + ret = select(sd+1, &tempfds, NULL, NULL, &tv); + if ((ret < 0) && (errno != EINTR)) { + A_ERR("[%s] select failed: %d\n", __FUNCTION__, ret); + break; + } else if ((ret > 0) && (FD_ISSET(sd, &tempfds))) { + fromlen = sizeof(from); + do { + left = recvfrom(sd, buf, sizeof(buf), 0, + (struct sockaddr *) &from, &fromlen); + } while (left == -1 && errno == EINTR); + + if (left < 0) { + A_ERR("[%s] recvfrom(netlink)\n", __FUNCTION__); + continue; + // break; + } + + h = (struct nlmsghdr *) buf; + while (left >= sizeof(*h)) { + int len, plen; + + len = h->nlmsg_len; + plen = len - sizeof(*h); + if (len > left || plen < 0) { + A_ERR("[%s] malformed netlink message\n", __FUNCTION__); + continue; + } + + //A_DEBUG("RTM Message Type: %s\n", + // ((h->nlmsg_type == RTM_NEWLINK) ? + // "RTM_NEWLINK" : ((h->nlmsg_type == RTM_DELLINK) ? + // "RTM_DELLINK" : "RTM_OTHER"))); + switch (h->nlmsg_type) { + case RTM_NEWLINK: + NewLinkEvent(pInstance, h, plen); + break; + case RTM_DELLINK: + DelLinkEvent(pInstance, h, plen); + break; + default: + break; + } + + len = NLMSG_ALIGN(len); + left -= len; + h = (struct nlmsghdr *) ((char *) h + len); + } + } + } + + close(sd); + } while (FALSE); + + /* Clean up the resources allocated in this task */ + A_INFO("Terminating the WLAN Event Handler task\n"); + A_MUTEX_LOCK(&pAbfWlanInfo->hWaitEventLock); + pAbfWlanInfo->Loop = FALSE; + A_COND_SIGNAL(&pAbfWlanInfo->hWaitEvent); + A_MUTEX_UNLOCK(&pAbfWlanInfo->hWaitEventLock); + + return NULL; +} + +A_STATUS +Abf_WlanIssueFrontEndConfig(ATHBT_FILTER_INFO * pInfo) +{ + WMI_SET_BTCOEX_FE_ANT_CMD btcoexFeAntCmd; + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD btcoexCoLocatedBtCmd; + A_UINT32 buf_fe_ant_cmd[sizeof(A_UINT32) + sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)]; + A_UINT32 buf_co_located_bt_cmd[sizeof(A_UINT32) + sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)]; + A_STATUS status; + + /* Set co-located bt type to 1, generic for any PTA based bluetooth */ + buf_co_located_bt_cmd[0] = AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV; + + btcoexCoLocatedBtCmd.btcoexCoLocatedBTdev = 1; + A_MEMCPY(&buf_co_located_bt_cmd[1], (void *)&btcoexCoLocatedBtCmd, + sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)); + + status = Abf_WlanDispatchIO(pInfo, AR6000_IOCTL_EXTENDED, + (void *)buf_co_located_bt_cmd, + (sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD) + sizeof(A_UINT32))); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to issue Co-located BT configuration\n", __FUNCTION__); + return A_ERROR; + } + + if(pInfo->Flags & ABF_FE_ANT_IS_SA) { + /* Indicate front end antenna configuration as single antenna */ + A_INFO("FLAGS = %x, Issue FE antenna configuration as single \n", pInfo->Flags); + btcoexFeAntCmd.btcoexFeAntType = WMI_BTCOEX_FE_ANT_SINGLE; + }else { + A_INFO("FLAGS = %x, Issue FE antenna configuration as dual \n", pInfo->Flags); + btcoexFeAntCmd.btcoexFeAntType = WMI_BTCOEX_FE_ANT_DUAL; + } + + buf_fe_ant_cmd[0] = AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT; + + A_MEMCPY(&buf_fe_ant_cmd[1], (void *)&btcoexFeAntCmd, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)); + + + status = Abf_WlanDispatchIO(pInfo, AR6000_IOCTL_EXTENDED, + (void *)buf_fe_ant_cmd, + (sizeof(WMI_SET_BTCOEX_FE_ANT_CMD) + sizeof(A_UINT32))); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to issue FE ant configuration\n", __FUNCTION__); + return A_ERROR; + } + + return A_OK; + +} + +A_STATUS +Abf_WlanGetSleepState(ATHBT_FILTER_INFO * pInfo) +{ + /* setup ioctl cmd */ + A_UINT32 cmd = AR6000_XIOCTL_GET_WLAN_SLEEP_STATE; + + A_STATUS status = Abf_WlanDispatchIO(pInfo, AR6000_IOCTL_EXTENDED, + (void *)&cmd, + sizeof(A_UINT32)); + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to issue get WLAN sleep state\n", __FUNCTION__); + return A_ERROR; + } + + return A_OK; +} + +A_STATUS +Abf_WlanGetCurrentWlanOperatingFreq( ATHBT_FILTER_INFO * pInfo) +{ + A_STATUS status; + struct iwreq wrq; + char ifname[IFNAMSIZ], *ethIf; + ATH_BT_FILTER_INSTANCE *pInstance = pInfo->pInstance; + ABF_WLAN_INFO *pAbfWlanInfo = pInfo->pWlanInfo; + + /* Get the adpater name from command line if specified */ + if (pInstance->pWlanAdapterName != NULL) { + ethIf = pInstance->pWlanAdapterName; + } else { + if ((ethIf = getenv("NETIF")) == NULL) { + ethIf = pAbfWlanInfo->IfName; + } + } + A_MEMZERO(ifname, IFNAMSIZ); + strcpy(ifname, ethIf); + strncpy(wrq.ifr_name, ifname, sizeof(wrq.ifr_name)); + if ((status = ioctl(pAbfWlanInfo->Handle, SIOCGIWFREQ, &wrq)) < 0) { + return A_ERROR; + } + /*Freq is in Hz, converted into to MhZ */ + pAbfWlanInfo->Channel = (wrq.u.freq.m/100000); + + IndicateCurrentWLANOperatingChannel(pInfo, pAbfWlanInfo->Channel); + return status; +} + +static void +NewLinkEvent(ATH_BT_FILTER_INSTANCE *pInstance, struct nlmsghdr *h, int len) +{ + struct ifinfomsg *ifi; + struct rtattr * attr; + int attrlen, nlmsg_len, rta_len; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_WLAN_INFO *pAbfWlanInfo = (ABF_WLAN_INFO *)pInfo->pWlanInfo; + + if (len < sizeof(*ifi)) { + A_DEBUG("packet too short\n"); + return; + } + + ifi = NLMSG_DATA(h); + + nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg)); + + attrlen = h->nlmsg_len - nlmsg_len; + if (attrlen < 0) { + A_DEBUG("bad attrlen\n"); + return; + } + + attr = (struct rtattr *) (((char *) ifi) + nlmsg_len); + + rta_len = RTA_ALIGN(sizeof(struct rtattr)); + while (RTA_OK(attr, attrlen)) { + if (attr->rta_type == IFLA_WIRELESS) { + /* + * We need to ensure that the event is from the WLAN instance + * that we are interested in TODO + */ + WirelessEvent(pInstance, ((char*)attr) + rta_len, + attr->rta_len - rta_len); + } else if (attr->rta_type == IFLA_IFNAME) { + /* + * Shall be used to get the socket descriptor. Also we should do + * it only until we get the adapter we are interested in + */ + if (!pAbfWlanInfo->Handle) { + A_DEBUG("WLAN Adapter Interface: %s, Len: %d\n", + (((char *)attr) + rta_len), attr->rta_len - rta_len); + A_MEMCPY(pAbfWlanInfo->IfName, ((char *)attr + rta_len), + attr->rta_len - rta_len); + pAbfWlanInfo->IfIndex = if_nametoindex(pAbfWlanInfo->IfName); + } else if (ifi->ifi_change && pAbfWlanInfo->IfIndex == ifi->ifi_index) { + A_CHAR ifName[IFNAMSIZ]; + A_MEMCPY(ifName, ((char *)attr + rta_len), attr->rta_len - rta_len); + if (A_MEMCMP(pAbfWlanInfo->IfName, ifName, sizeof(ifName))!=0) { + A_MEMCPY(pAbfWlanInfo->IfName, ifName, sizeof(ifName)); + } + } + } + attr = RTA_NEXT(attr, attrlen); + } +} + +static void +DelLinkEvent(ATH_BT_FILTER_INSTANCE *pInstance, struct nlmsghdr *h, int len) +{ + A_BOOL found; + struct ifinfomsg *ifi; + struct rtattr * attr; + int attrlen, nlmsg_len, rta_len; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_WLAN_INFO *pAbfWlanInfo = (ABF_WLAN_INFO *)pInfo->pWlanInfo; + + if (!pAbfWlanInfo->Handle) return; + + if (len < sizeof(*ifi)) { + A_DEBUG("packet too short\n"); + return; + } + + ifi = NLMSG_DATA(h); + + nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg)); + + attrlen = h->nlmsg_len - nlmsg_len; + if (attrlen < 0) { + A_DEBUG("bad attrlen\n"); + return; + } + + attr = (struct rtattr *) (((char *) ifi) + nlmsg_len); + + rta_len = RTA_ALIGN(sizeof(struct rtattr)); + found = FALSE; + while (RTA_OK(attr, attrlen)) { + if (attr->rta_type == IFLA_IFNAME) { + /* + * Shall be used to get the socket descriptor. Also we should do + * it only until we get the adapter we are interested in + */ + if (!(strcmp(pAbfWlanInfo->IfName, ((char *)attr + rta_len)))) { + found = TRUE; + } + } + + attr = RTA_NEXT(attr, attrlen); + } + + if (!found) return; + + /* Flush all the BT actions from the filter core */ + HandleAdapterEvent(pInfo, ATH_ADAPTER_REMOVED); + + ReleaseWlanAdapter(pAbfWlanInfo); + + /* Reset the WLAN adapter specific info */ + A_MEMZERO(pAbfWlanInfo->AdapterName, WLAN_ADAPTER_NAME_SIZE_MAX); + pAbfWlanInfo->PhyCapability = 0; + + A_INFO("WLAN Adapter Removed\n"); +} + +static void +WirelessEvent(ATH_BT_FILTER_INSTANCE *pInstance, char *data, int len) +{ + A_STATUS status = A_OK; + struct iw_event iwe_buf, *iwe = &iwe_buf; + char *pos, *end, *custom, *buf; + + pos = data; + end = data + len; + + while ((pos + IW_EV_LCP_PK_LEN <= end) && (status == A_OK)) { + /* Event data may be unaligned, so make a local, aligned copy + * before processing. */ + A_MEMCPY(&iwe_buf, pos, IW_EV_LCP_LEN); + if (iwe->len <= IW_EV_LCP_LEN) { + status = A_ERROR; + break; + } + + custom = pos + IW_EV_POINT_LEN; + if (WIRELESS_EXT > 18 && + (iwe->cmd == IWEVMICHAELMICFAILURE || + iwe->cmd == IWEVCUSTOM || + iwe->cmd == IWEVASSOCREQIE || + iwe->cmd == IWEVASSOCRESPIE || + iwe->cmd == IWEVPMKIDCAND || + iwe->cmd == IWEVGENIE)) { + /* WE-19 removed the pointer from struct iw_point */ + char *dpos = (char *) &iwe_buf.u.data.length; + int dlen = dpos - (char *) &iwe_buf; + A_MEMCPY(dpos, pos + IW_EV_LCP_LEN, + sizeof(struct iw_event) - dlen); + } else { + A_MEMCPY(&iwe_buf, pos, sizeof(struct iw_event)); + custom += IW_EV_POINT_OFF; + } + + switch (iwe->cmd) { + case SIOCGIWAP: + break; + case IWEVCUSTOM: + if (custom + iwe->u.data.length > end) { + A_ERR("[%s:%d] Check Failed\n", __FUNCTION__, __LINE__); + status = A_ERROR; + break; + } + buf = A_MALLOC(iwe->u.data.length + 1); + if (buf == NULL) { + A_ERR("[%s:%d] Check Failed\n", __FUNCTION__, __LINE__); + status = A_ERROR; + break; + } + A_MEMCPY(buf, custom, iwe->u.data.length); + status = WirelessCustomEvent(pInstance, buf, iwe->u.data.length); + A_FREE(buf); + break; + case SIOCGIWSCAN: + break; + case SIOCSIWESSID: + break; + case IWEVGENIE: + if (custom + iwe->u.data.length > end || (iwe->u.data.length < 2)) { + A_ERR("event = IWEVGENIE with wrong length %d remain %d\n", + iwe->u.data.length, (end-custom)); + status = A_ERROR; + break; + } + buf = A_MALLOC(iwe->u.data.length + 1); + if (buf == NULL) { + A_ERR("[%s:%d] Check Failed\n", __FUNCTION__, __LINE__); + status = A_ERROR; + break; + } + A_MEMCPY(buf, custom, iwe->u.data.length); + status = WirelessCustomEvent(pInstance, buf, iwe->u.data.length); + A_FREE(buf); + break; + default: + break; + } + + pos += iwe->len; + } +} + +static A_STATUS +WirelessCustomEvent(ATH_BT_FILTER_INSTANCE *pInstance, char *buf, int len) +{ + char *ptr; + int length, i; + A_UINT16 eventid; + WMI_READY_EVENT *ev1; + WMI_CONNECT_EVENT *ev2; + WMI_REPORT_SLEEP_STATE_EVENT * ev3; + A_STATUS status = A_OK; + ATHBT_FILTER_INFO *pInfo = (ATHBT_FILTER_INFO *)pInstance->pContext; + ABF_WLAN_INFO *pAbfWlanInfo = pInfo->pWlanInfo; + + do { + eventid = *((A_UINT16 *)buf); + ptr = buf + 2; //Skip the event id + length = len - 2; + switch (eventid) { + case (WMI_READY_EVENTID): + if (length < sizeof(WMI_READY_EVENT)) { + A_ERR("[%s:%d] Check Failed\n", __FUNCTION__, __LINE__); + status = A_ERROR; + break; + } + ev1 = (WMI_READY_EVENT *)ptr; + A_MEMCPY(pAbfWlanInfo->AdapterName, ev1->macaddr, ATH_MAC_LEN); + pAbfWlanInfo->PhyCapability = ev1->phyCapability; + A_DEBUG("WMI READY: Capability: %d, Address: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", + pAbfWlanInfo->PhyCapability, + (pAbfWlanInfo->AdapterName[0]), + (pAbfWlanInfo->AdapterName[1]), + (pAbfWlanInfo->AdapterName[2]), + (pAbfWlanInfo->AdapterName[3]), + (pAbfWlanInfo->AdapterName[4]), + (pAbfWlanInfo->AdapterName[5])); + + /* + * Open a handle for the ioctls that will be issued later + * Try 10 times because the driver may not yet be ready to receive + * IOCTLs, so we give the driver time to get ready by looping here + */ + for (i = 0; i <= 10; i++) { + status = AcquireWlanAdapter(pAbfWlanInfo); + if (A_SUCCESS(status)) { + break; /* Break out of FOR loop, but not out of switch case statement */ + } + sleep(1); + } + + if (A_FAILED(status)) { + A_ERR("[%s] Failed to acquire WLAN adapter\n", __FUNCTION__); + break; + } + + /* Communicate this to the Filter task */ + HandleAdapterEvent(pInfo, ATH_ADAPTER_ARRIVED); + A_INFO("WLAN Adapter Added\n"); + break; + case (WMI_CONNECT_EVENTID): + if (length < sizeof(WMI_CONNECT_EVENT)) { + A_ERR("[%s:%d] Check Failed\n", __FUNCTION__, __LINE__); + status = A_ERROR; + break; + } + ev2 = (WMI_CONNECT_EVENT *)ptr; + pAbfWlanInfo->Channel = ev2->u.infra_ibss_bss.channel; + A_DEBUG("WMI CONNECT: Channel: %d\n", ev2->u.infra_ibss_bss.channel); + IndicateCurrentWLANOperatingChannel(pInfo, pAbfWlanInfo->Channel); + break; + case (WMI_DISCONNECT_EVENTID): + A_DEBUG("WMI DISCONNECT: %d\n", len); + IndicateCurrentWLANOperatingChannel(pInfo, 0); + break; + case (WMI_ERROR_REPORT_EVENTID): + A_DEBUG("WMI ERROR REPORT: %d\n", len); + break; + case (WMI_SCAN_COMPLETE_EVENTID): + A_DEBUG("WMI SCAN COMPLETE: %d\n", len); + break; + case (WMI_REPORT_SLEEP_STATE_EVENTID): + A_DEBUG("WMI_REPORT_SLEEP_STATE_EVENTID: %d\n", len); + if(length < sizeof(WMI_REPORT_SLEEP_STATE_EVENT)) { + A_ERR("[%s]Incorrect length passed - length = %d, len =%d\n", __FUNCTION__, length, len); + } + ev3 = (WMI_REPORT_SLEEP_STATE_EVENT *)ptr; + switch(ev3->sleepState) { + case WMI_REPORT_SLEEP_STATUS_IS_DEEP_SLEEP: + HandleAdapterEvent(pInfo, ATH_ADAPTER_REMOVED); + break; + case WMI_REPORT_SLEEP_STATUS_IS_AWAKE: + Abf_WlanIssueFrontEndConfig( pInfo); + HandleAdapterEvent(pInfo, ATH_ADAPTER_ARRIVED); + break; + } + break; + default: + //A_DEBUG("Event: 0x%x, Not Handled\n", eventid); + break; + } + } while (FALSE); + + return status; +} + +static A_STATUS +AcquireWlanAdapter(ABF_WLAN_INFO *pAbfWlanInfo) +{ + int sd; + A_STATUS status; + + if (pAbfWlanInfo->Handle != 0) { + return A_OK; + } + + if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + A_ERR("[%s] Error creating socket: %d\n", __FUNCTION__, sd); + return A_ERROR; + } + + pAbfWlanInfo->Handle = sd; + status = GetAdapterInfo(pAbfWlanInfo); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get Adapter Info\n", __FUNCTION__); + close(sd); + pAbfWlanInfo->Handle = 0; + return A_ERROR; + } else { + /* Try to get RTS to determinate that wlan is enabled */ + A_UCHAR buf[sizeof(int)+sizeof(WMI_SET_RTS_CMD)]; + ((int *)buf)[0] = AR6000_XIOCTL_AP_GET_RTS; + status = Abf_WlanDispatchIO(pAbfWlanInfo->pInfo, AR6000_IOCTL_EXTENDED, + (void *)buf, sizeof(buf)); + if (A_FAILED(status)) { + A_INFO("WMI is ready but wlan is disabled.\n"); + return A_ERROR; + } + } + + return A_OK; +} + +static A_STATUS +GetAdapterInfo(ABF_WLAN_INFO *pAbfWlanInfo) +{ + A_STATUS status; + struct ar6000_version *revinfo; + + revinfo = (struct ar6000_version *)A_MALLOC(sizeof(struct ar6000_version)); + + if (revinfo == NULL) { + A_ERR("[%s] Failed to alloc WLAN revision info\n", __FUNCTION__); + return A_ERROR; + } + + + /* Get the revision info */ + status = Abf_WlanDispatchIO(pAbfWlanInfo->pInfo, AR6000_IOCTL_WMI_GETREV, + (void *)revinfo, sizeof(struct ar6000_version)); + if (A_FAILED(status)) { + A_ERR("[%s] Failed to get WLAN revision\n", __FUNCTION__); + return A_ERROR; + } + + pAbfWlanInfo->HostVersion = revinfo->host_ver; + pAbfWlanInfo->TargetVersion = revinfo->target_ver; + A_INFO("Host Rev: 0x%x(%u.%u.%u.%u), Target Rev: 0x%x(%u.%u.%u.%u)\n", + revinfo->host_ver, + ((revinfo->host_ver)&0xf0000000)>>28, + ((revinfo->host_ver)&0x0f000000)>>24, + ((revinfo->host_ver)&0x00ff0000)>>16, + ((revinfo->host_ver)&0x0000ffff), + revinfo->target_ver, + ((revinfo->target_ver)&0xf0000000)>>28, + ((revinfo->target_ver)&0x0f000000)>>24, + ((revinfo->target_ver)&0x00ff0000)>>16, + ((revinfo->target_ver)&0x0000ffff)); + + A_FREE(revinfo); + + return A_OK; +} + +static void +ReleaseWlanAdapter(ABF_WLAN_INFO *pAbfWlanInfo) +{ + close(pAbfWlanInfo->Handle); + pAbfWlanInfo->Handle = 0; + pAbfWlanInfo->HostVersion = 0; + pAbfWlanInfo->TargetVersion = 0; +} + +void Abf_WlanCheckSettings(A_CHAR *wifname, A_UINT32 *btfiltFlags) +{ + int sd; + A_CHAR ifname[IFNAMSIZ]; +#ifdef ANDROID + char ifprop[PROPERTY_VALUE_MAX]; + if (wifname[0] == '\0' && property_get("wifi.interface", ifprop, NULL)) { + strcpy(wifname, ifprop); + } +#endif + + { + A_BOOL found = FALSE; + A_CHAR linebuf[1024]; + FILE *f = fopen("/proc/net/wireless", "r"); + if (f) { + while(fgets(linebuf, sizeof(linebuf)-1, f)) { + if (strchr(linebuf, ':')) { + char *dest = ifname; + char *p = linebuf; + while(*p && isspace(*p)) ++p; + while (*p && *p != ':') + *dest++ = *p++; + *dest = '\0'; + if (strcmp(wifname, ifname)==0) { + found = TRUE; + break; + } + } + } + if (!found && ifname[0]!='\0') { + strcpy(wifname, ifname); + } + fclose(f); + } + } + A_DEBUG("%s : wlan: %s\n", __FUNCTION__, wifname); + if (wifname[0] == '\0' || !btfiltFlags) { + return; + } + + if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + A_ERR("[%s] Error creating socket: %d\n", __FUNCTION__, sd); + return; + } + + do { + A_UINT32 flags = *btfiltFlags; + struct ifreq ifr; + struct ar6000_version revinfo; + A_MEMZERO(&revinfo, sizeof(revinfo)); + strncpy(ifr.ifr_name, wifname, sizeof(ifr.ifr_name)); + ifr.ifr_data = (void *)&revinfo; + if (ioctl(sd, AR6000_IOCTL_WMI_GETREV, &ifr) < 0) { + break; + } + if ( (revinfo.target_ver & 0xf0000000)==0x30000000) { + *btfiltFlags |= ABF_WIFI_CHIP_IS_VENUS; + } else { + *btfiltFlags &= ~ABF_WIFI_CHIP_IS_VENUS; + } + if (*btfiltFlags != flags) { + A_DEBUG("Change btfilt flags from %u to %u isVenus %d\n", flags, *btfiltFlags, + (*btfiltFlags & ABF_WIFI_CHIP_IS_VENUS) ? "yes" : "no"); + } + } while (0); + close(sd); +} diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btdefs.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btdefs.h new file mode 100644 index 000000000000..0f51e5698ce9 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btdefs.h @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Bluetooth spec definitions +// +// Author(s): ="Atheros" +//============================================================================== + + +#ifndef BTDEFS_H_ +#define BTDEFS_H_ + +#define OGF_SHIFT 10 +#define OGF_MASK 0xFC + +#define MAKE_HCI_COMMAND(ogf,ocf) (((ogf) << OGF_SHIFT) | (ocf)) +#define HCI_GET_OP_CODE(p) (((A_UINT16)((p)[1])) << 8) | ((A_UINT16)((p)[0])) +#define HCI_TEST_OGF(p,ogf) (((p)[1] & OGF_MASK) == ((ogf) << 2)) + +#define HCI_LINK_CONTROL_OGF 0x01 +#define IS_LINK_CONTROL_CMD(p) HCI_TEST_OGF(p,HCI_LINK_CONTROL_OGF) +#define HCI_INQUIRY MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0001) +#define HCI_INQUIRY_CANCEL MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0002) +#define HCI_PER_INQUIRY MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0003) +#define HCI_PER_INQUIRY_CANCEL MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0004) +#define HCI_CREATE_CONNECTION MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0005) +#define HCI_DISCONNECT MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0006) +#define HCI_ADD_SCO MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0007) +#define HCI_ACCEPT_CONN_REQ MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0009) +#define HCI_REJECT_CONN_REQ MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x000A) +#define HCI_SETUP_SCO_CONN MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, 0x0028) /* BT 2.0 */ + +//#define HCI_ MAKE_HCI_COMMAND(HCI_LINK_CONTROL_OGF, x) + +#define HCI_GET_EVENT_CODE(p) ((p)[0]) +#define GET_BT_EVENT_LENGTH(p) ((p)[1]) +#define HCI_EVT_INQUIRY_COMPLETE 0x01 +#define HCI_EVT_CONNECT_COMPLETE 0x03 +#define HCI_EVT_CONNECT_REQUEST 0x04 +#define HCI_EVT_REMOTE_DEV_LMP_VERSION 0x0b +#define HCI_EVT_REMOTE_DEV_VERSION 0x0c +#define HCI_EVT_DISCONNECT 0x05 +#define HCI_EVT_REMOTE_NAME_REQ 0x07 +#define HCI_EVT_ROLE_CHANGE 0x12 +#define HCI_EVT_NUM_COMPLETED_PKTS 0x13 +#define HCI_EVT_MODE_CHANGE 0x14 +#define HCI_EVT_SCO_CONNECT_COMPLETE 0x2C /* new to 2.0 */ + + +#define HCI_CMD_OPCODE_INQUIRY_START 0x401 +#define HCI_CMD_OPCODE_INQUIRY_CANCEL 0x402 +#define HCI_CMD_OPCODE_CONNECT 0x405 + +/* HCI Connection Complete Event macros */ +#define GET_BT_CONN_EVENT_STATUS(p) ((p)[2]) +#define GET_BT_CONN_HANDLE(p) ((A_UINT16)((p)[3]) | (((A_UINT16)((p)[4])) << 8)) +#define GET_BT_CONN_LINK_TYPE(p) ((p)[11]) +#define BT_CONN_EVENT_STATUS_SUCCESS(p) (GET_BT_CONN_EVENT_STATUS(p) == 0) +#define INVALID_BT_CONN_HANDLE 0xFFFF +#define BT_LINK_TYPE_SCO 0x00 +#define BT_LINK_TYPE_ACL 0x01 +#define BT_LINK_TYPE_ESCO 0x02 + + +/* SCO Connection Complete Event macros */ +#define GET_TRANS_INTERVAL(p) ((p)[12]) +#define GET_RETRANS_INTERVAL(p) ((p)[13]) +#define GET_RX_PKT_LEN(p) ((A_UINT16)((p)[14]) | (((A_UINT16)((p)[15])) << 8)) +#define GET_TX_PKT_LEN(p) ((A_UINT16)((p)[16]) | (((A_UINT16)((p)[17])) << 8)) + + +/* L2CAP Definitions */ +#define SIGNALING 0x0001 +#define CONNECTIONLESS 0x0002 +#define NULL_ID 0x0000 + +#define CONNECT_REQ 0x02 +#define CONNECT_RSP 0x03 +#define DISCONNECT_REQ 0x06 +#define DISCONNECT_RSP 0x07 + +#define STATE_SUCCESS 0 +#define STATE_PENDING 1 + +#define STATE_DISCONNECT 0x00 +#define STATE_CONNECTING 0x01 +#define STATE_CONNECTED 0x02 + +#define TYPE_ACPT 0x02 +#define TYPE_REJ 0x03 + +#define A2DP_TYPE 0x0019 +#define RFCOMM_TYPE 0x0003 +#define SDP_TYPE 0x0001 +#define AVDTP_START 0x07 +#define AVDTP_SUSPEND 0x08 +#define AVDTP_CLOSE 0x09 +#define AVDTP_OPEN 0x06 + +#define GETUINT16(p)(((A_UINT16)((p)[1])) << 8) | ((A_UINT16)((p)[0])) + +#include "athstartpack.h" + +typedef PREPACK struct _ACL_HEADER{ + A_UINT16 HANDLE; + A_UINT16 Length; +} POSTPACK ACL_HEADER, *PACL_HEADER; + +typedef PREPACK struct _L2CAP_HEADER{ + A_UINT16 Length; + A_UINT16 CID; +} POSTPACK L2CAP_HEADER, *PL2CAP_HEADER; + +typedef PREPACK struct _L2CAP_CONTROL{ + A_UINT8 CODE; + A_UINT8 ID; + A_UINT16 Length; + A_UINT16 PSM; + A_UINT16 DESTINATION_CID; + A_UINT16 SOURCE_CID; + A_UINT16 RESULT; + A_UINT16 STATUS; +} POSTPACK L2CAP_CONTROL, *PL2CAP_CONTROL; + +typedef PREPACK struct _AVDTP_HEADER{ + A_UINT8 MESSAGE_TYPE; + A_UINT8 CMD_ID; +} POSTPACK AVDTP_HEADER, *PAVDTP_HEADER; + +#include "athendpack.h" + +#endif /*BTDEFS_H_*/ + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_action.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_action.c new file mode 100644 index 000000000000..1a543617923a --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_action.c @@ -0,0 +1,640 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Bluetooth filter core action tables and action lookup +// +// Author(s): ="Atheros" +//============================================================================== + +#include +#include +#include "athdefs.h" +#define ATH_MODULE_NAME btfilt +#include "a_debug.h" +#include "a_types.h" +#include "a_osapi.h" +#include "wmi.h" +#include "athbtfilter.h" +#include "btfilter_core.h" + +#include "abtfilt_int.h" +#define ACTION_NOOP NULL +#define ACTION_TODO_TBD NULL + +static void CleanupModifiedControlActionDescChain(BT_CONTROL_ACTION_DESC *pDesc); + +/* default actions descriptor table + * + * NOTE: the pNext member of each entry must be set to NULL, when this table is copied + * to a RAM table so that the pNext field can be altered at run time in case the entry must be + * extended or overridden by the user */ +static const BT_CONTROL_ACTION_DESC_STATE g_ActionDefaults[ATH_BT_MAX_STATE_INDICATION] = +{ + /* STATE OFF */ /* STATE ON */ + /* ATH_BT_NOOP */ {{{ ACTION_NOOP, 0, NULL }, { ACTION_NOOP, 0, NULL }}}, + /* ATH_BT_INQUIRY */ {{{ "-s 3 2", 0, NULL }, { "-s 3 1", 0, NULL }}}, + /* ATH_BT_CONNECT */ {{{ ACTION_TODO_TBD, 0, NULL }, { ACTION_TODO_TBD, 0, NULL }}}, + /* ATH_BT_SCO */ {{{ "-s 1 2", 0, NULL }, { "-pSCO 10 20 2 0 2 6 1 0 0 60 50 5; -s 1 1", 0, NULL }}}, + /* ATH_BT_ACL */ {{{ ACTION_TODO_TBD, 0, NULL }, { ACTION_TODO_TBD, 0, NULL }}}, + /* ATH_BT_A2DP */ {{{ "-s 2 2", 0, NULL }, { "-pA2DP 30 3 20 0 0 60 50 20; -s 2 1", 0, NULL }}}, + /* ATH_BT_ESCO */ {{{ "-s 4 2", 0, NULL }, { "-pSCO 1 20 2 0 2 6 3 0 0 60 50 5 ; -s 4 1",0, NULL }}}, +}; + + +static const BT_CONTROL_ACTION_DESC_STATE g_ActionDefaultsVenus[ATH_BT_MAX_STATE_INDICATION] = +{ + /* STATE OFF */ /* STATE ON */ + /* ATH_BT_NOOP */ {{{ ACTION_NOOP, 0, NULL }, { ACTION_NOOP, 0, NULL }}}, + /* ATH_BT_INQUIRY */ {{{ "-s 3 2 0", 0, NULL }, { "-s 3 1 0", 0, NULL }}}, + /* ATH_BT_CONNECT */ {{{ ACTION_TODO_TBD, 0, NULL }, { ACTION_TODO_TBD, 0, NULL }}}, + /* ATH_BT_SCO */ {{{ "-s 1 2 0", 0, NULL }, { "-pSCO 2 4 1 0 10 20 2 6 2 3 3 36 5 5 1 100 2; -s 1 1 0 ", 0, NULL }}}, + /* ATH_BT_ACL */ {{{ ACTION_TODO_TBD, 0, NULL }, { ACTION_TODO_TBD, 0, NULL }}}, + /* ATH_BT_A2DP */ {{{ "-s 2 2 0", 0, NULL }, { "-pA2DP 5 0 30 3 20 36 5 5 1 3; -s 2 1 0", 0, NULL }}}, + /* ATH_BT_ESCO */ {{{ "-s 4 2 0", 0, NULL }, { "-pSCO 2 10 1 0 10 20 2 6 2 3 3 36 5 5 1 100 2; -s 4 1 0", 0, NULL }}}, +}; + +typedef enum _BT_COMMAND_TAG { + BT_STATUS_TAG = 0, + BT_PARAM_SCO_TAG = 1, + BT_PARAM_A2DP_TAG, + /* add new tags here */ + BT_COMMAND_TAGS_MAX +} BT_COMMAND_TAG; + + +static const A_CHAR *g_TagStrings[BT_COMMAND_TAGS_MAX] = { + "-s", + "-pSCO", + "-pA2DP", +}; + +static int FindActionString(A_CHAR *pString, A_CHAR **ppStart) +{ + int count = 0; + A_BOOL found = FALSE; + + if (*pString == ';') { + /* skip if this is the first one we hit */ + pString++; + } + + while ((*pString != '\0') && (*pString != ';')) { + if (!found) { + if (*pString == '-') { + /* found start of one action string */ + *ppStart = pString; + found = TRUE; + count++; + } + } else { + count++; + } + pString++; + } + + return count; +} + +#define ACTION_STRING_DELIMIT ' ' + + /* assemble an array of pointers to each argument in the string */ +static int GetArgStrings(A_CHAR *pString, + A_CHAR Delimit, + A_CHAR *pArgArray[], + int MaxArgs) +{ + int totalArgs = 0; + int length; + A_BOOL done = FALSE; + + while (!done && (totalArgs < MaxArgs)) { + + pArgArray[totalArgs] = pString; + length = 0; + + /* walk through the string and assemble substrings */ + while (1) { + + if ((*pString == '\0') || (*pString == Delimit)) { + + if (*pString == '\0') { + /* reached the end of the string */ + done = TRUE; + } else { + /* terminate */ + *pString = (A_CHAR)0; + } + /* advance pass NULL */ + pString++; + + if (length) { + /* only increment arg if we found a non-zero length string */ + totalArgs++; + } + + break; + } + + pString++; + length++; + } + + } + + return totalArgs; +} + +static int GetArguments(A_CHAR *pString, A_INT32 *pArgArray, int MaxArgs) +{ + int i; + int totalArgs; + int argsFound; + A_CHAR *argStrings[BT_ACTION_MAX_ARGS]; + + + totalArgs = GetArgStrings(pString, + ACTION_STRING_DELIMIT, + argStrings, + BT_ACTION_MAX_ARGS); + + argsFound = 0; + + for (i = 0; (i < totalArgs); i++) { + + if (argStrings[i][0] == '-') { + /* skip the action tag */ + continue; + } + if (argsFound < MaxArgs) { + /* got an arg */ + pArgArray[argsFound] = atol(argStrings[i]); + argsFound++; + } + } + + return argsFound; +} + +static A_STATUS BuildActionFromString(BT_FILTER_CORE_INFO * pCore, A_CHAR *pActionString, int Length, + BT_CONTROL_ACTION_ITEM **pControlItem) +{ + A_CHAR stringBuf[BT_ACTION_STRING_MAX_LENGTH + 1]; + int stringLength = min(Length,BT_ACTION_STRING_MAX_LENGTH); + BT_COMMAND_TAG tag = BT_COMMAND_TAGS_MAX; + BT_CONTROL_ACTION_ITEM *pItem = NULL; + A_STATUS status = A_OK; + A_INT32 args[BT_ACTION_MAX_ARGS]; + int argCount; + + + pItem = (BT_CONTROL_ACTION_ITEM *)A_MALLOC(sizeof(BT_CONTROL_ACTION_ITEM)); + + if (NULL == pItem) { + return A_NO_MEMORY; + } + + A_MEMZERO(pItem,sizeof(BT_CONTROL_ACTION_ITEM)); + /* copy string to temp buffer */ + A_MEMCPY(stringBuf, pActionString, stringLength); + stringBuf[stringLength] = '\0'; + + /* Parse string for command type */ + for (tag = 0; tag < BT_COMMAND_TAGS_MAX; tag++) { + if (strstr(stringBuf, g_TagStrings[tag]) != NULL) { + argCount = GetArguments(stringBuf,args,BT_ACTION_MAX_ARGS); + break; + } + } + +/* + * BT STATUS: + * "-s " + * + * BT PARAM SCO: + * "-pSCO + * " + * + * BT PARAM A2DP + * "-pA2DP ControlAction.Type = BT_CONTROL_ACTION_STATUS; + if(pCore->FilterState.btFilterFlags & ABF_WIFI_CHIP_IS_VENUS) { + WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD *pOperatingStatus = + (WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD *)pItem->ControlAction.Buffer; + + pItem->ControlAction.Length = sizeof(WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD); + + if (argCount != 3) { + status = A_EINVAL; + break; + } + + pOperatingStatus->btProfileType = (A_UINT8)args[0]; + pOperatingStatus->btOperatingStatus =(A_UINT8)args[1]; + pOperatingStatus->btLinkId =(A_UINT8)args[2]; + }else { + + WMI_SET_BT_STATUS_CMD *pStatusCmd = (WMI_SET_BT_STATUS_CMD *)pItem->ControlAction.Buffer; + pItem->ControlAction.Length = sizeof(WMI_SET_BT_STATUS_CMD); + + if (argCount != 2) { + status = A_EINVAL; + break; + } + + pStatusCmd->streamType = (A_UINT8)args[0]; + pStatusCmd->status = (A_UINT8)args[1]; + } + break; + + case BT_PARAM_SCO_TAG: + pItem->ControlAction.Type = BT_CONTROL_ACTION_PARAMS; + if(pCore->FilterState.btFilterFlags & ABF_WIFI_CHIP_IS_VENUS) { + WMI_SET_BTCOEX_SCO_CONFIG_CMD * pScoConfigCmd = + (WMI_SET_BTCOEX_SCO_CONFIG_CMD *)pItem->ControlAction.Buffer; + pItem->ControlAction.Length = sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD); + BTCOEX_SCO_CONFIG * pScoGenericConfig = &pScoConfigCmd->scoConfig; + BTCOEX_PSPOLLMODE_SCO_CONFIG * pScoPspollConfig = &pScoConfigCmd->scoPspollConfig; + BTCOEX_OPTMODE_SCO_CONFIG * pScoOptModeConfig = &pScoConfigCmd->scoOptModeConfig; + BTCOEX_WLANSCAN_SCO_CONFIG * pScoWlanScanConfig = &pScoConfigCmd->scoWlanScanConfig; + if (argCount != 17) { + status = A_EINVAL; + break; + } + pScoGenericConfig->scoSlots = (A_UINT32) args[0]; + pScoGenericConfig->scoIdleSlots = (A_UINT32) args[1]; + pScoGenericConfig->scoFlags = (A_UINT32) args[2]; + pScoGenericConfig->linkId = (A_UINT32) args[3]; + pScoPspollConfig->scoCyclesForceTrigger = (A_UINT32) args[4]; + pScoPspollConfig->scoDataResponseTimeout = (A_UINT32) args[5]; + pScoPspollConfig->scoStompDutyCyleVal = (A_UINT32) args[6]; + pScoPspollConfig->scoStompDutyCyleMaxVal = (A_UINT32) args[7]; + pScoPspollConfig->scoPsPollLatencyFraction = (A_UINT32) args[8]; + pScoOptModeConfig->scoStompCntIn100ms = (A_UINT32) args[9]; + pScoOptModeConfig->scoContStompMax = (A_UINT32) args[10]; + pScoOptModeConfig->scoMinlowRateMbps = (A_UINT32) args[11]; + pScoOptModeConfig->scoLowRateCnt = (A_UINT32) args[12]; + pScoOptModeConfig->scoHighPktRatio = (A_UINT32) args[13]; + pScoOptModeConfig->scoMaxAggrSize = (A_UINT32) args[14]; + pScoWlanScanConfig->scanInterval = (A_UINT32) args[15]; + pScoWlanScanConfig->maxScanStompCnt = (A_UINT32) args[16]; + } else { + pItem->ControlAction.Type = BT_CONTROL_ACTION_PARAMS; + pItem->ControlAction.Length = sizeof(WMI_SET_BT_PARAMS_CMD); + WMI_SET_BT_PARAMS_CMD *pParamsCmd = + (WMI_SET_BT_PARAMS_CMD *)pItem->ControlAction.Buffer; + + pParamsCmd->paramType = BT_PARAM_SCO; + pParamsCmd->info.scoParams.numScoCyclesForceTrigger = + (A_UINT8)args[0]; + pParamsCmd->info.scoParams.dataResponseTimeout = + (A_UINT8)args[1]; + pParamsCmd->info.scoParams.stompScoRules = + (A_UINT8)args[2]; + pParamsCmd->info.scoParams.scoOptFlags = (A_UINT8)args[3]; + pParamsCmd->info.scoParams.stompDutyCyleVal = + (A_UINT8)args[4]; + pParamsCmd->info.scoParams.stompDutyCyleMaxVal = + (A_UINT8)args[5]; + pParamsCmd->info.scoParams.psPollLatencyFraction = + (A_UINT8)args[6]; + pParamsCmd->info.scoParams.noSCOSlots = (A_UINT8)args[7]; + pParamsCmd->info.scoParams.noIdleSlots = (A_UINT8)args[8]; + /*only a place holder. modify num args if scoOpt flag bits + need to be modified here*/ + pParamsCmd->info.scoParams.scoOptOffRssi= (A_UINT8)args[9]; + pParamsCmd->info.scoParams.scoOptOnRssi = (A_UINT8)args[10]; + pParamsCmd->info.scoParams.scoOptRtsCount =(A_UINT8)args[11]; + } + break; + case BT_PARAM_A2DP_TAG: + pItem->ControlAction.Type = BT_CONTROL_ACTION_PARAMS; + if(pCore->FilterState.btFilterFlags & ABF_WIFI_CHIP_IS_VENUS) { + WMI_SET_BTCOEX_A2DP_CONFIG_CMD * pA2dpConfigCmd = + (WMI_SET_BTCOEX_A2DP_CONFIG_CMD *)pItem->ControlAction.Buffer; + pItem->ControlAction.Length = sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD); + BTCOEX_A2DP_CONFIG * pA2dpGenericConfig = &pA2dpConfigCmd->a2dpConfig; + BTCOEX_PSPOLLMODE_A2DP_CONFIG * pA2dpPspollConfig = &pA2dpConfigCmd->a2dppspollConfig; + BTCOEX_OPTMODE_A2DP_CONFIG * pA2dpOptModeConfig = &pA2dpConfigCmd->a2dpOptConfig; + if (argCount != 10) { + status = A_EINVAL; + break; + } + pA2dpGenericConfig->a2dpFlags = (A_UINT32) args[0]; + pA2dpGenericConfig->linkId = (A_UINT32) args[1]; + pA2dpPspollConfig->a2dpWlanMaxDur = (A_UINT32) args[2]; + pA2dpPspollConfig->a2dpMinBurstCnt = (A_UINT32) args[3]; + pA2dpPspollConfig->a2dpDataRespTimeout = (A_UINT32) args[4]; + pA2dpOptModeConfig->a2dpMinlowRateMbps = (A_UINT32) args[5]; + pA2dpOptModeConfig->a2dpLowRateCnt = (A_UINT32) args[6]; + pA2dpOptModeConfig->a2dpHighPktRatio = (A_UINT32) args[7]; + pA2dpOptModeConfig->a2dpMaxAggrSize = (A_UINT32) args[8]; + pA2dpOptModeConfig->a2dpPktStompCnt = (A_UINT32) args[9]; + }else { + pItem->ControlAction.Type = BT_CONTROL_ACTION_PARAMS; + pItem->ControlAction.Length = sizeof(WMI_SET_BT_PARAMS_CMD); + WMI_SET_BT_PARAMS_CMD *pParamsCmd = + (WMI_SET_BT_PARAMS_CMD *)pItem->ControlAction.Buffer; + if (argCount != 8) { + status = A_EINVAL; + break; + } + pParamsCmd->paramType = BT_PARAM_A2DP; + pParamsCmd->info.a2dpParams.a2dpWlanUsageLimit = (A_UINT8)args[0]; + pParamsCmd->info.a2dpParams.a2dpBurstCntMin = (A_UINT8)args[1]; + pParamsCmd->info.a2dpParams.a2dpDataRespTimeout = (A_UINT8)args[2]; + pParamsCmd->info.a2dpParams.a2dpOptFlags = (A_UINT8)args[3]; + pParamsCmd->info.a2dpParams.isCoLocatedBtRoleMaster = (A_UINT8)args[4]; + pParamsCmd->info.a2dpParams.a2dpOptOffRssi = (A_UINT8)args[5]; + pParamsCmd->info.a2dpParams.a2dpOptOnRssi = (A_UINT8)args[6]; + pParamsCmd->info.a2dpParams.a2dpOptRtsCount = (A_UINT8)args[7]; + } + break; + + default: + break; + + } + + if (A_FAILED(status)) { + A_FREE(pItem); + } else { + *pControlItem = pItem; + } + + return status; +} + +/* assemble the action list based on the descriptor list */ +static A_STATUS AssembleActionList(BT_FILTER_CORE_INFO * pCore, BT_CONTROL_ACTION_DESC *pDesc, DL_LIST *pActionListHead) +{ + BT_CONTROL_ACTION_ITEM *pControlItem; + A_CHAR *pActionString; + A_CHAR *pStringToScan; + int length; + A_STATUS status = A_OK; + + for ( ;((pDesc != NULL) && A_SUCCESS(status)); pDesc = pDesc->pNext) { + if (NULL == pDesc->pActionString) { + continue; + } + /* scan the action string and assemble all actions */ + pStringToScan = pDesc->pActionString; + + while (1) { + + length = FindActionString(pStringToScan, &pActionString); + + if (0 == length) { + break; + } + /* found the string, now build the action */ + status = BuildActionFromString(pCore, pActionString, length , &pControlItem); + + if (A_FAILED(status)) { + break; + } + + /* insert into the list head in FIFO order */ + DL_ListInsertTail(pActionListHead,&pControlItem->ListEntry); + + /* scan the rest of the string */ + pStringToScan = pActionString + length; + } + } + + return status; +} + + +static void CleanListItems(DL_LIST *pListHead) +{ + DL_LIST *pListItem; + BT_CONTROL_ACTION_ITEM *pControlItem; + + while (1) { + pListItem = DL_ListRemoveItemFromHead(pListHead); + if (NULL == pListItem) { + break; + } + pControlItem = A_CONTAINING_STRUCT(pListItem, BT_CONTROL_ACTION_ITEM, ListEntry); + /* free it */ + A_FREE(pControlItem); + } +} + + +static void CleanupActionLists(BT_FILTER_CORE_INFO *pCore) +{ + int indication,state; + + for (state = 0; state < STATE_MAX; state++) { + /* free all action list items */ + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; indication++) { + CleanListItems(&pCore->ActionListsState[indication][state]); + } + } +} + +/* API implementation */ +void FCore_ResetActionDescriptors(BT_FILTER_CORE_INFO *pCore) +{ + int indication,state; + + for (state = 0; state < STATE_MAX; state++) { + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; indication++) { + CleanupModifiedControlActionDescChain(&pCore->ActionDescriptors[indication].Action[state]); + } + } + + if(pCore->FilterState.btFilterFlags & ABF_WIFI_CHIP_IS_VENUS) { + memcpy(pCore->ActionDescriptors, g_ActionDefaultsVenus, sizeof(pCore->ActionDescriptors)); + }else { + memcpy(pCore->ActionDescriptors, g_ActionDefaults, sizeof(pCore->ActionDescriptors)); + } +} + +A_BOOL FCore_Init(BT_FILTER_CORE_INFO *pCore) +{ + int indication,state; + + for (state = 0; state < STATE_MAX; state++) { + /* initialize all action list heads */ + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; indication++) { + DL_LIST_INIT(&pCore->ActionListsState[indication][state]); + } + } + /* load up the default action descriptors */ + FCore_ResetActionDescriptors(pCore); + + pCore->FilterState.ACL_ConnectionHandle = INVALID_BT_CONN_HANDLE; + pCore->FilterState.eSCO_ConnectionHandle = INVALID_BT_CONN_HANDLE; + pCore->FilterState.SCO_ConnectionHandle = INVALID_BT_CONN_HANDLE; + + return TRUE; +} + +/* assembly action lists from the action table, this is called after the OS-porting layer + * has had a chance to alter the action table */ +A_STATUS FCore_RefreshActionList(BT_FILTER_CORE_INFO *pCore) +{ + int indication,state; + A_STATUS status = A_OK; + + /* clean up previous ones */ + CleanupActionLists(pCore); + + for (state = 0; (state < STATE_MAX) && A_SUCCESS(status); state++) { + for (indication = 0; (indication < ATH_BT_MAX_STATE_INDICATION) && A_SUCCESS(status); indication++) { + status = AssembleActionList(pCore, &pCore->ActionDescriptors[indication].Action[state], + &pCore->ActionListsState[indication][state]); + } + } + + if (A_FAILED(status)) { + FCore_Cleanup(pCore); + } + + return status; +} + +void FCore_Cleanup(BT_FILTER_CORE_INFO *pCore) +{ + int indication,state; + + for (state = 0; state < STATE_MAX; state++) { + for (indication = 0; indication < ATH_BT_MAX_STATE_INDICATION; indication++) { + CleanupModifiedControlActionDescChain(&pCore->ActionDescriptors[indication].Action[state]); + } + } + + CleanupActionLists(pCore); +} + + +BT_CONTROL_ACTION_ITEM *FCore_GetControlAction(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + BT_CONTROL_ACTION_ITEM *pStart) +{ + DL_LIST *pListHead; + BT_CONTROL_ACTION_ITEM *pBtControlAction = NULL; + + if (State >= STATE_MAX) { + return NULL; + } + + pListHead = &pCore->ActionListsState[Indication][State]; + + if (NULL == pStart) { + /* caller wants the first item in the list */ + if (pListHead->pNext == pListHead) { + /* list is empty */ + return NULL; + } + pBtControlAction = A_CONTAINING_STRUCT(pListHead->pNext, BT_CONTROL_ACTION_ITEM, ListEntry); + } else { + /* caller wants the next list item */ + if (pStart->ListEntry.pNext == pListHead) { + /* reached the end */ + return NULL; + } + pBtControlAction = A_CONTAINING_STRUCT(pStart->ListEntry.pNext, BT_CONTROL_ACTION_ITEM, ListEntry); + } + + return pBtControlAction; +} + +static void CleanupModifiedControlActionDescChain(BT_CONTROL_ACTION_DESC *pDesc) +{ + BT_CONTROL_ACTION_DESC *pNextDesc; + + while (pDesc) { + pNextDesc = pDesc->pNext; + if (pDesc->Flags & BT_CA_DESC_FLAGS_ALLOCATED) { + A_FREE(pDesc); + } + pDesc = pNextDesc; + } + +} + +A_STATUS FCore_ModifyControlActionString(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + A_CHAR *pAction, + int StringLength, + ATHBT_MODIFY_CONTROL_ACTION ModifyAction) +{ + BT_CONTROL_ACTION_DESC *pNewDesc; + BT_CONTROL_ACTION_DESC *pDescHead; + A_CHAR *pString; + + /* get first entry at the head */ + pDescHead = &pCore->ActionDescriptors[Indication].Action[State]; + + /* allocate and assemble an entry for this action */ + pNewDesc = (BT_CONTROL_ACTION_DESC *)A_MALLOC(sizeof(BT_CONTROL_ACTION_DESC) + StringLength + 1); + + if (NULL == pNewDesc) { + return A_NO_MEMORY; + } + + A_MEMZERO(pNewDesc,sizeof(BT_CONTROL_ACTION_DESC)); + + /* setup and copy string */ + pString = (A_CHAR *)((A_UINT8 *)pNewDesc + sizeof(BT_CONTROL_ACTION_DESC)); + A_MEMCPY(pString,pAction,StringLength); + pString[StringLength] = 0; + pNewDesc->pActionString = pString; + /* mark that it was allocated so we can clean it up later */ + pNewDesc->Flags = BT_CA_DESC_FLAGS_ALLOCATED; + + switch (ModifyAction) { + case ATHBT_MODIFY_CONTROL_ACTION_APPEND: + /* append to the end of the list */ + while (pDescHead->pNext != NULL) { + pDescHead = pDescHead->pNext; + } + pDescHead->pNext = pNewDesc; + break; + + case ATHBT_MODIFY_CONTROL_ACTION_REPLACE: + /* remove any existing replacements or append operations */ + CleanupModifiedControlActionDescChain(pDescHead); + /* ignore the first entry's action string */ + pDescHead->pActionString = NULL; + /* add new replacement */ + pDescHead->pNext = pNewDesc; + break; + + default: + A_FREE(pNewDesc); + break; + } + + + return A_OK; +} diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.c b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.c new file mode 100644 index 000000000000..3d42822bf1c8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.c @@ -0,0 +1,620 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Bluetooth filter core action tables and action lookup +// +// Author(s): ="Atheros" +//============================================================================== + +#include +#include +#include "athdefs.h" +#define ATH_MODULE_NAME btfilt +#include "a_debug.h" +#include "a_types.h" +#include "a_osapi.h" +#include "wmi.h" +#include "athbtfilter.h" +#include "btfilter_core.h" + +#ifdef DEBUG + +ATH_DEBUG_INSTANTIATE_MODULE_VAR(btfilt, + "btfilt", + "BT Filter Core", + ATH_DEBUG_MASK_DEFAULTS, + 0, + NULL); + +#endif + +#define IS_STATE_FILTER_IGNORED(pCore,indication) ((pCore)->StateFilterIgnore & (1 << (indication))) + +static A_BOOL IsACLSignaling(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length); + +static A_BOOL IsA2DPConnection(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length); + +static void ParseACLPacket(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length); + +static void ProcessA2DPconnection(BT_FILTER_CORE_INFO *pCore, + L2CAP_CONTROL *pL2Ctrl, + A_BOOL IsConnect); + +static ATHBT_STATE_INDICATION A2DP_StateIndication(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState); + +static ATHBT_STATE_INDICATION ProcessA2DPCMD(BT_FILTER_CORE_INFO *pCore, + A_UINT8 CMDID, + ATHBT_STATE *pNewState, + A_BOOL IsACPT); + +ATHBT_STATE_INDICATION FCore_FilterBTCommand(BT_FILTER_CORE_INFO *pCore, A_UINT8 *pBuffer, int Length, ATHBT_STATE *pNewState) +{ + ATHBT_STATE_INDICATION indication = ATH_BT_NOOP; + ATHBT_STATE state = STATE_OFF; + A_UINT16 command; + + + if (!IS_LINK_CONTROL_CMD(pBuffer)) { + /* we only filter link control commands */ + return indication; + } + + command = HCI_GET_OP_CODE(pBuffer); + + switch (command) { + case HCI_INQUIRY : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_INQUIRY)) { + break; + } + indication = ATH_BT_INQUIRY; + state = STATE_ON; + break; + + case HCI_INQUIRY_CANCEL : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_INQUIRY)) { + break; + } + indication = ATH_BT_INQUIRY; + state = STATE_OFF; + break; + + case HCI_CREATE_CONNECTION : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_CONNECT)) { + break; + } + indication = ATH_BT_CONNECT; + state = STATE_ON; + break; + + case HCI_ACCEPT_CONN_REQ : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_CONNECT)) { + break; + } + indication = ATH_BT_CONNECT; + state = STATE_ON; + break; + + case HCI_ADD_SCO : + /* we do not need to handle this command, we can pick up the connection complete event */ + case HCI_DISCONNECT : + /* we don't need to handle this command as we can pick up the disconnect event */ + case HCI_PER_INQUIRY : + case HCI_PER_INQUIRY_CANCEL : + /* we do not handle these currently */ + default : + break; + } + + if (indication != ATH_BT_NOOP) { + /* the HCI filter simply determines the "precise" state and calls the shared function */ + return FCore_FilterIndicatePreciseState(pCore, indication, state, pNewState); + } + + return ATH_BT_NOOP; +} + + +void FilterConnectDisconnectComplete(BT_FILTER_CORE_INFO *pCore, + A_UINT8 LinkType, + A_UINT16 ConnectionHandle, + A_BOOL Connected, + ATHBT_STATE_INDICATION *pIndication, + ATHBT_STATE *pState) +{ + + + do { + if (Connected) { + + if (LinkType == BT_LINK_TYPE_SCO) { + + /* SCO connection */ + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_SCO)) { + break; + } + + pCore->FilterState.SCO_ConnectionHandle = ConnectionHandle; + *pIndication = ATH_BT_SCO; + *pState = STATE_ON; + + } else if (LinkType == BT_LINK_TYPE_ACL) { + + /* ACL connection */ + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_ACL)) { + break; + } + + /**** TODO , currently we do not keep track of ACL connections + at the moment we rely on upper layer stack to detect specific + traffic types like A2DP. Since there can be multiple ACL connections + it is not practical to provide a single action for all ACL connections. + This is just a place holder in case a customer does require specific + actions to take for an ACL connection *****/ + + } else if (LinkType == BT_LINK_TYPE_ESCO) { + + /* eSCO connection */ + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_ESCO)) { + break; + } + + pCore->FilterState.eSCO_ConnectionHandle = ConnectionHandle; + *pIndication = ATH_BT_ESCO; + *pState = STATE_ON; + } + + break; + } + + /* if we get here, we are handling the disconnect case */ + + if (ConnectionHandle == pCore->FilterState.ACL_ConnectionHandle) { + + /*** TODO, we currently do not keep track of these, see note above */ + + } else if (ConnectionHandle == pCore->FilterState.SCO_ConnectionHandle) { + + pCore->FilterState.SCO_ConnectionHandle = INVALID_BT_CONN_HANDLE; + *pIndication = ATH_BT_SCO; + *pState = STATE_OFF; + + } else if (ConnectionHandle == pCore->FilterState.eSCO_ConnectionHandle) { + + pCore->FilterState.eSCO_ConnectionHandle = INVALID_BT_CONN_HANDLE; + *pIndication = ATH_BT_ESCO; + *pState = STATE_OFF; + } + + } while (FALSE); + +} + + +ATHBT_STATE_INDICATION FCore_FilterBTEvent(BT_FILTER_CORE_INFO *pCore, A_UINT8 *pBuffer, int Length, ATHBT_STATE *pNewState) +{ + ATHBT_STATE_INDICATION indication = ATH_BT_NOOP; + ATHBT_STATE state = STATE_OFF; + + switch HCI_GET_EVENT_CODE(pBuffer) { + case HCI_EVT_INQUIRY_COMPLETE : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_INQUIRY)) { + break; + } + indication = ATH_BT_INQUIRY; + state = STATE_OFF; + break; + + case HCI_EVT_CONNECT_COMPLETE : + + if (BT_CONN_EVENT_STATUS_SUCCESS(pBuffer)) { + FilterConnectDisconnectComplete(pCore, + GET_BT_CONN_LINK_TYPE(pBuffer), + GET_BT_CONN_HANDLE(pBuffer), + TRUE, /* connected */ + &indication, + &state); + } + + break; + + case HCI_EVT_CONNECT_REQUEST : + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_CONNECT)) { + break; + } + + indication = ATH_BT_CONNECT; + state = STATE_ON; + break; + + case HCI_EVT_SCO_CONNECT_COMPLETE: + + if (BT_CONN_EVENT_STATUS_SUCCESS(pBuffer)) { + FilterConnectDisconnectComplete(pCore, + GET_BT_CONN_LINK_TYPE(pBuffer), + GET_BT_CONN_HANDLE(pBuffer), + TRUE, /* connected */ + &indication, + &state); + } + + break; + + case HCI_EVT_DISCONNECT : + + FilterConnectDisconnectComplete(pCore, + GET_BT_CONN_LINK_TYPE(pBuffer), + GET_BT_CONN_HANDLE(pBuffer), + FALSE, /* disconnected */ + &indication, + &state); + break; + + case HCI_EVT_REMOTE_NAME_REQ : + + /* TODO */ + break; + + case HCI_EVT_ROLE_CHANGE : + /* TODO */ + break; + + default: + break; + } + + if (indication != ATH_BT_NOOP) { + /* the HCI filter simply determines the "precise" state and calls the shared function */ + return FCore_FilterIndicatePreciseState(pCore, indication, state, pNewState); + } + + return ATH_BT_NOOP; +} + +/* a precise state can be indicated by the porting layer or indicated by the HCI command/event filtering. + * The caller needs to protect this call with a lock */ +ATHBT_STATE_INDICATION FCore_FilterIndicatePreciseState(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE StateOn, + ATHBT_STATE *pNewState) +{ + A_UINT32 bitmap = (1 << Indication); + A_UINT32 oldBitMap; + + oldBitMap = pCore->FilterState.StateBitMap; + + if (StateOn == STATE_ON) { + pCore->FilterState.StateBitMap |= bitmap; + } else { + pCore->FilterState.StateBitMap &= ~bitmap; + } + + if (oldBitMap ^ pCore->FilterState.StateBitMap) { + *pNewState = StateOn; + return Indication; + } else { + /* no state change */ + return ATH_BT_NOOP; + } +} + +A_UINT32 FCore_GetCurrentBTStateBitMap(BT_FILTER_CORE_INFO *pCore) +{ + return pCore->FilterState.StateBitMap; +} + +ATHBT_STATE_INDICATION FCore_FilterACLDataIn(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState) +{ + ATHBT_STATE_INDICATION stateIndication = ATH_BT_NOOP; + + *pNewState = STATE_OFF; + + do { + + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_A2DP)) { + /* we only filter for A2DP stream state if the OS-ported layer + * cannot do it */ + break; + } + + /***** the following code filters for A2DP stream state ONLY *****/ + + /* filter ACL packets for application specific traffic */ + if (IsACLSignaling(pCore,pBuffer,Length)) { + ParseACLPacket(pCore,pBuffer,Length); + } else if ( IsA2DPConnection(pCore,pBuffer,Length)) { + stateIndication = A2DP_StateIndication(pCore,pBuffer,Length,pNewState); + } + + } while (FALSE); + + return stateIndication; +} + +ATHBT_STATE_INDICATION FCore_FilterACLDataOut(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState) +{ + ATHBT_STATE_INDICATION stateIndication = ATH_BT_NOOP; + + *pNewState = STATE_OFF; + + do { + + if (IS_STATE_FILTER_IGNORED(pCore, ATH_BT_A2DP)) { + /* we only filter for A2DP stream state if the OS-ported layer + * cannot do it */ + break; + } + + /***** the following code filters for A2DP stream state ONLY *****/ + + if (IsACLSignaling(pCore,pBuffer,Length)) { + ParseACLPacket(pCore,pBuffer,Length); + } else if (IsA2DPConnection(pCore,pBuffer,Length)) { + stateIndication = A2DP_StateIndication(pCore,pBuffer,Length,pNewState); + } + + } while (FALSE); + + return stateIndication; +} + +static INLINE A_BOOL ParseCAPheader(L2CAP_HEADER *pL2hdr, + A_UINT8 *pBuffer, + int Length) +{ + A_UCHAR *pTemp = pBuffer + sizeof(ACL_HEADER); + + if (Length < (sizeof(ACL_HEADER)+sizeof(L2CAP_HEADER))) { + return FALSE; + } + + pL2hdr->Length = GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + pL2hdr->CID = GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + return TRUE; +} + + +static INLINE A_BOOL ParseCAPCtrl(L2CAP_CONTROL *pL2Ctrl, + A_UINT8 *pBuffer, + int Length) +{ + A_UCHAR *pTemp = pBuffer + sizeof(ACL_HEADER); + + if (Length < (sizeof(ACL_HEADER)+sizeof(L2CAP_HEADER)+sizeof(L2CAP_CONTROL)-6)) { + return FALSE; + } + + pTemp +=sizeof(L2CAP_HEADER); + + pL2Ctrl->CODE = *pTemp++; + pL2Ctrl->ID = *pTemp++; + pL2Ctrl->Length = GETUINT16(pTemp) ; + pTemp += sizeof(A_UINT16); + pL2Ctrl->PSM = pL2Ctrl->DESTINATION_CID=GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + pL2Ctrl->SOURCE_CID = GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + + if (Length >= (sizeof(ACL_HEADER)+sizeof(L2CAP_HEADER)+sizeof(L2CAP_CONTROL)-sizeof(A_UINT16))) { + pL2Ctrl->RESULT = GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + pL2Ctrl->STATUS = GETUINT16(pTemp); + pTemp += sizeof(A_UINT16); + } + + return TRUE; +} + +static A_BOOL IsACLSignaling(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length) +{ + L2CAP_HEADER L2hdr; + + A_MEMZERO(&L2hdr,sizeof(L2CAP_HEADER)); + + if (!ParseCAPheader(&L2hdr,pBuffer,Length)) { + return FALSE; + } + + if (L2hdr.CID == SIGNALING) { + return TRUE; + } + + return FALSE; +} + +static A_BOOL IsA2DPConnection(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length) +{ + L2CAP_HEADER L2hdr; + + A_MEMZERO(&L2hdr,sizeof(L2CAP_HEADER)); + + if (!ParseCAPheader(&L2hdr,pBuffer,Length)) { + /* not L2CAP header */ + return FALSE; + } + + if (pCore->FilterState.AVDTP_state==STATE_CONNECTED && + ((L2hdr.CID==pCore->FilterState.AVDTP_DESTINATION_CID) || + (L2hdr.CID==pCore->FilterState.AVDTP_SOURCE_CID))) { + //ACL normal packet + return TRUE; + } + + return FALSE; +} + +static void ParseACLPacket(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length) +{ + L2CAP_CONTROL L2ctrl; + + A_MEMZERO(&L2ctrl,sizeof(L2CAP_CONTROL)); + + if (!ParseCAPCtrl(&L2ctrl,pBuffer,Length)) { + return; + } + + switch( L2ctrl.CODE) { + case CONNECT_REQ: + case CONNECT_RSP: + ProcessA2DPconnection(pCore,&L2ctrl,TRUE); + break; + case DISCONNECT_REQ: + case DISCONNECT_RSP: + ProcessA2DPconnection(pCore,&L2ctrl,FALSE); + break; + } +} + +static void ProcessA2DPconnection(BT_FILTER_CORE_INFO *pCore, + PL2CAP_CONTROL pL2Ctrl, + A_BOOL IsConnect) +{ + + if (IsConnect) { + if (pL2Ctrl->CODE==CONNECT_REQ) { + if (pCore->FilterState.AVDTP_state==STATE_DISCONNECT) { + pCore->FilterState.AVDTP_state = pL2Ctrl->PSM == + A2DP_TYPE ? STATE_CONNECTING:STATE_DISCONNECT; + } else if (pCore->FilterState.RFCOMM_state==STATE_DISCONNECT) { + pCore->FilterState.RFCOMM_state= pL2Ctrl->PSM == + RFCOMM_TYPE ? STATE_CONNECTING:STATE_DISCONNECT; + } + } else if (pL2Ctrl->CODE==CONNECT_RSP) { + switch (pL2Ctrl->RESULT) { + case STATE_SUCCESS: + if (pCore->FilterState.AVDTP_state == STATE_CONNECTING) { + pCore->FilterState.AVDTP_SOURCE_CID=NULL_ID; + pCore->FilterState.AVDTP_DESTINATION_CID=NULL_ID; + if ( pL2Ctrl->STATUS==STATE_SUCCESS) { + pCore->FilterState.AVDTP_state= STATE_CONNECTED; + pCore->FilterState.AVDTP_SOURCE_CID= pL2Ctrl->SOURCE_CID; + pCore->FilterState.AVDTP_DESTINATION_CID= pL2Ctrl->DESTINATION_CID; + } + } else if (pCore->FilterState.RFCOMM_state == STATE_CONNECTING) { + pCore->FilterState.RFCOMM_SOURCE_CID=NULL_ID; + pCore->FilterState.RFCOMM_DESTINATION_CID=NULL_ID; + if ( pL2Ctrl->STATUS==STATE_SUCCESS) { + pCore->FilterState.RFCOMM_state= STATE_CONNECTED; + pCore->FilterState.RFCOMM_SOURCE_CID= pL2Ctrl->SOURCE_CID; + pCore->FilterState.RFCOMM_DESTINATION_CID= pL2Ctrl->DESTINATION_CID; + } + } + break; + case STATE_PENDING: + break; + default: + pCore->FilterState.RFCOMM_state=STATE_DISCONNECT; + pCore->FilterState.RFCOMM_SOURCE_CID=NULL_ID; + pCore->FilterState.RFCOMM_DESTINATION_CID=NULL_ID; + pCore->FilterState.AVDTP_state=STATE_DISCONNECT; + pCore->FilterState.AVDTP_SOURCE_CID = NULL_ID; + pCore->FilterState.AVDTP_DESTINATION_CID=NULL_ID; + break; + } + } + } else { + pCore->FilterState.AVDTP_state=STATE_DISCONNECT; + pCore->FilterState.RFCOMM_state=STATE_DISCONNECT; + } + +} + + +static ATHBT_STATE_INDICATION A2DP_StateIndication(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState) + +{ + AVDTP_HEADER Avdtphdr; + ATHBT_STATE_INDICATION stateIndication = ATH_BT_NOOP; + A_UCHAR *pTemp = pBuffer+sizeof(ACL_HEADER)+sizeof(L2CAP_HEADER); + + Avdtphdr.MESSAGE_TYPE= (*pTemp++) & 0x03; // get Message Type + Avdtphdr.CMD_ID = (*pTemp++) & 0x3F; //Get command code + + switch (Avdtphdr.MESSAGE_TYPE) { + case TYPE_ACPT: + stateIndication = ProcessA2DPCMD(pCore,Avdtphdr.CMD_ID,pNewState,TRUE); + break; + case TYPE_REJ: + stateIndication = ProcessA2DPCMD(pCore,Avdtphdr.CMD_ID,pNewState,FALSE); + break; + default: + break; + } + + return stateIndication; +} + +static ATHBT_STATE_INDICATION ProcessA2DPCMD(BT_FILTER_CORE_INFO *pCore, + A_UINT8 CMDID, + ATHBT_STATE *pNewState, + A_BOOL IsACPT) + +{ + ATHBT_STATE_INDICATION stateIndication = ATH_BT_NOOP; + + switch(CMDID) { + case AVDTP_START: + stateIndication = ATH_BT_A2DP; + *pNewState = IsACPT ? STATE_ON:STATE_OFF; + break; + case AVDTP_OPEN: + // don't assign any state in here. + break; + case AVDTP_SUSPEND: + stateIndication = ATH_BT_A2DP; + *pNewState = STATE_OFF; + break; + case AVDTP_CLOSE: + stateIndication = ATH_BT_A2DP; + *pNewState = STATE_OFF; + break; + default: + break; + } + + return stateIndication; +} + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.h new file mode 100644 index 000000000000..f0230f64e6db --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/btfilter_core.h @@ -0,0 +1,204 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2007 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// Internal APIs and definitions for Bluetooth filter core +// +// Author(s): ="Atheros" +//============================================================================== +#ifndef BTFILTER_INTERNAL_H_ +#define BTFILTER_INTERNAL_H_ + +#include "btdefs.h" +#include "athdefs.h" +#include "dl_list.h" +#include "wmi.h" + +typedef enum _BT_CONTROL_ACTION_TYPE { + BT_CONTROL_ACTION_STATUS = 0, + BT_CONTROL_ACTION_PARAMS = 1 +} BT_CONTROL_ACTION_TYPE; + +typedef union _BT_CONTROL_ACTION_BUFFER { + WMI_SET_BT_STATUS_CMD AsStatusCmd; /* parameters for a status command */ + WMI_SET_BT_PARAMS_CMD AsParamCmd; /* parameters for a set params command */ + WMI_SET_BTCOEX_SCO_CONFIG_CMD scoConfigCmd; + WMI_SET_BTCOEX_A2DP_CONFIG_CMD a2dpConfigCmd; +} BT_CONTROL_ACTION_BUFFER; + +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define A_ROUND_UP_PWR2(x, align) (((int) (x) + ((align)-1)) & ~((align)-1)) + +#define MAX_BT_CONTROL_ACTION_DATA_SIZE A_ROUND_UP_PWR2(sizeof(BT_CONTROL_ACTION_BUFFER),4) /* nicely aligned */ + + /* core state flags and variables */ +typedef struct _BT_FILTER_CORE_STATE { + A_UINT16 SCO_ConnectionHandle; + A_UINT16 ACL_ConnectionHandle; + A_UINT16 eSCO_ConnectionHandle; + A_UINT32 StateBitMap; + A_UINT8 AVDTP_state; + A_UINT8 RFCOMM_state; + A_UINT16 AVDTP_SOURCE_CID; + A_UINT16 AVDTP_DESTINATION_CID; + A_UINT16 RFCOMM_SOURCE_CID; + A_UINT16 RFCOMM_DESTINATION_CID; + A_UINT32 btFilterFlags; +} BT_FILTER_CORE_STATE; + +#define BT_ACTION_STRING_MAX_LENGTH 64 /* maximum action string length */ +#define BT_ACTION_MAX_ARGS 18 /* maximum number of numberic arguments */ + +#define BT_CA_DESC_FLAGS_ALLOCATED (1 << 0) + + /* a control action descriptor */ +typedef struct _BT_CONTROL_ACTION_DESC { + A_CHAR *pActionString; /* action string (described below) */ + A_UINT32 Flags; /* flags for this entry */ + struct _BT_CONTROL_ACTION_DESC *pNext; /* link to next action */ +} BT_CONTROL_ACTION_DESC; + + /* control action descriptor containing actions for each state */ +typedef struct _BT_CONTROL_ACTION_DESC_STATE { + BT_CONTROL_ACTION_DESC Action[STATE_MAX]; +} BT_CONTROL_ACTION_DESC_STATE; + + +/* ACTION strings: + * The BT control actions are described in string format. The string is parsed for parameters + * (based on tags and order) and the parameter list passed to a function that assembles the WMI + * commands (status or params) to issue. + * + * The string format is selected to follow the command line ordering from the WMI config application. + * + * + * BT STATUS: + * "-s " + * + * BT PARAM SCO: + * "-pSCO + * " + * + * BT PARAM A2DP: + * "-pA2DP " + * + * BT PARAM MISC - WLAN Tx Protection: + * "-pMISC_TxProtect " + * + * BT PARAM MISC - Coex Policy: + * "-pMISC_Coex " + * + * BT PARAM REGISTERS : + * "-pREGS " + * + * A string may contain multiple commands delimited by a continuation character ';' . For example: + * + * "-pA2DP 100 40 1 ; -s 2 1" + * + * Would issue a BT PARAM-A2DP command followed by a BT STATUS command. + * + */ + +typedef struct _BT_CONTROL_ACTION { + BT_CONTROL_ACTION_TYPE Type; /* the action type (i.e. status, params) */ + A_UCHAR Buffer[MAX_BT_CONTROL_ACTION_DATA_SIZE]; /* buffer holding parameters */ + int Length; /* length of parameters */ +} BT_CONTROL_ACTION; + +typedef struct _BT_CONTROL_ACTION_ITEM { + DL_LIST ListEntry; + BT_CONTROL_ACTION ControlAction; +} BT_CONTROL_ACTION_ITEM; + + /* BT Core state blob */ +typedef struct _BT_FILTER_CORE_INFO { + BT_FILTER_CORE_STATE FilterState; + A_UINT32 StateFilterIgnore; /* bitmap of state to ignore*/ + BT_CONTROL_ACTION_DESC_STATE ActionDescriptors[ATH_BT_MAX_STATE_INDICATION]; + DL_LIST ActionListsState[ATH_BT_MAX_STATE_INDICATION][STATE_MAX]; +} BT_FILTER_CORE_INFO; + +/* filter core APIs called by the OS adaptation layer */ + +A_BOOL FCore_Init(BT_FILTER_CORE_INFO *pCore); +void FCore_Cleanup(BT_FILTER_CORE_INFO *pCore); +void FCore_ResetActionDescriptors(BT_FILTER_CORE_INFO *pCore); + +/* filter BT commands and events and extract current BT radio state + * ***** NOTE: the caller must protect this function with locks to protect internal + * state. This is however stack dependent. Some stacks may serialize HCI command and + * event processing. Some may allow these two operations to overlap. + */ +ATHBT_STATE_INDICATION FCore_FilterBTCommand(BT_FILTER_CORE_INFO *pCore, A_UINT8 *pBuffer, int Length, ATHBT_STATE *pNewState); +ATHBT_STATE_INDICATION FCore_FilterBTEvent(BT_FILTER_CORE_INFO *pCore, A_UINT8 *pBuffer, int Length, ATHBT_STATE *pNewState); + +/* filter ACL IN and OUT data to obtain BT application states + * ***** NOTE: the caller must protect this function with locks to protect internal + * state. + */ +ATHBT_STATE_INDICATION FCore_FilterACLDataOut(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState); + +ATHBT_STATE_INDICATION FCore_FilterACLDataIn(BT_FILTER_CORE_INFO *pCore, + A_UINT8 *pBuffer, + int Length, + ATHBT_STATE *pNewState); + +/* core state reset, usually called when the WLAN side goes away */ +#define FCore_ResetState(p) /* doesn't do anything now */ + +/* get the action list tem for this state indication + * The caller should pass pStart=NULL to obtain the first item. Then using each item returned, + * the caller can set pStart to that item and obtain the *next* item */ +BT_CONTROL_ACTION_ITEM *FCore_GetControlAction(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + BT_CONTROL_ACTION_ITEM *pStart); + +A_STATUS FCore_RefreshActionList(BT_FILTER_CORE_INFO *pCore); + +/* called to indicate the precise state of the BT radio when determined by external means */ +ATHBT_STATE_INDICATION FCore_FilterIndicatePreciseState(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + ATHBT_STATE *pNewState); + +A_UINT32 FCore_GetCurrentBTStateBitMap(BT_FILTER_CORE_INFO *pCore); + +typedef enum _ATHBT_MODIFY_CONTROL_ACTION { + ATHBT_MODIFY_CONTROL_ACTION_NOOP, + ATHBT_MODIFY_CONTROL_ACTION_APPEND, + ATHBT_MODIFY_CONTROL_ACTION_REPLACE +} ATHBT_MODIFY_CONTROL_ACTION; + +/* called to modify a control action string (Replace or Append) */ +A_STATUS FCore_ModifyControlActionString(BT_FILTER_CORE_INFO *pCore, + ATHBT_STATE_INDICATION Indication, + ATHBT_STATE State, + A_CHAR *pAction, + int StringLength, + ATHBT_MODIFY_CONTROL_ACTION ModifyAction); + + +#endif /*BTFILTER_INTERNAL_H_*/ + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/hciutils.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/hciutils.h new file mode 100644 index 000000000000..728776401615 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/hciutils.h @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2011 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== + +#ifndef __HCI_UTILS_H__ +#define __HCI_UTILS_H__ + + +// +// Return codes +// +typedef enum +{ + HCIUTILS_SUCCESS, // Success + HCIUTILS_FAILURE, // Generic Failure + HCIUTILS_ALREADY_REGISTERED, // Filter already registered + HCIUTILS_OUT_OF_MEMORY //out of memory +}tHCIUTILS_STATUS; + +// +// Notification Type - Or to get notification for both types +// +typedef enum +{ + HCIUTILS_COMMAND=0x1, + HCIUTILS_EVENT =0x2 +}tHCIUTILS_NOTIFICATION_TYPE; + +// +// OpCode to get notifications for all hci commands and events +// +#define HCIUTILS_NOTIFICATION_OPCODE_ALL 0xffff + +typedef struct +{ + tHCIUTILS_NOTIFICATION_TYPE tType; + unsigned short nOpCode; + void * p_notification_data_buf; + int n_data_length; + void * p_appdata; +}tHCIUTILS_NOTIFICATION; + +typedef void ( *tHCIUTILS_EVENT_CALLBACK) ( tHCIUTILS_NOTIFICATION * pEvent); + +tHCIUTILS_STATUS HCIUTILS_RegisterHCINotification + ( + tHCIUTILS_NOTIFICATION_TYPE t_type, + unsigned short nOpCode, + tHCIUTILS_EVENT_CALLBACK eventCallback , + void * p_appdata + ); + +void HCIUTILS_UnRegisterHCINotification + ( + tHCIUTILS_NOTIFICATION_TYPE t_type, + unsigned short nOpCode + ); + +typedef enum +{ + HCIUTILS_SET_AFH_CHANNELS = 0x01, + HCIUTILS_SET_AFH_CHANNEL_ASSESSMENT + +}tHCIUTILS_HCI_CMD; + +typedef struct +{ + unsigned char first; + unsigned char last; +}tHCIUTILS_HCICMD_SET_AFH_CHANNELS; + +typedef struct +{ + int enable_or_disable; +}tHCIUTILS_HCICMD_SET_AFH_CHANNEL_ASSESSMENT; + + +void HCIUTILS_SendCmd + ( + tHCIUTILS_HCI_CMD tCmd, + void * p_hci_cmd_params + ); + + +#endif //__HCI_UTILS_H__ + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/sample.conf b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/sample.conf new file mode 100644 index 000000000000..870c351c2e5c --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/sample.conf @@ -0,0 +1 @@ +INQUIRY-OFF:REPLACE:-s 2 2 diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthmonoheadset.py b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthmonoheadset.py new file mode 100644 index 000000000000..2d362153fc18 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthmonoheadset.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +import dbus +import os +import sys + +def printusage(): + print 'bthmonoheadset.py ' + print ' create - create a mono headset' + print ' start - connect and play ' + print ' stop - stop and disconnect' + return + +headsetAddress = os.getenv("BTMONO_HEADSET") + +print 'BT Mono Headset Is : => %s' % headsetAddress + +bus = dbus.SystemBus() +manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager') +bus_id = manager.ActivateService('audio') +audio = dbus.Interface(bus.get_object(bus_id, '/org/bluez/audio'), 'org.bluez.audio.Manager') + +if len(sys.argv) == 1 : + printusage() +elif len(sys.argv) > 1 and sys.argv[1] == 'create' : + path = audio.CreateHeadset(headsetAddress) + audio.ChangeDefaultHeadset(path) + headset = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Headset') + headset.Connect() + print 'Mono headset setup complete' +elif len(sys.argv) > 1 and sys.argv[1] == 'start' : + path = audio.DefaultDevice() + headset = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Headset') + if not headset.IsConnected() : + headset.Connect() + if len(sys.argv) > 2 and sys.argv[2] == 'pcm' : + print "Turning on PCM ...." + try : + headset.Play() + except dbus.exceptions.DBusException: + print 'Play Failed' +elif len(sys.argv) > 1 and sys.argv[1] == 'stop' : + path = audio.DefaultDevice() + headset = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Headset') + try : + headset.Stop() + except dbus.exceptions.DBusException: + print 'Stop Failed' + headset.Disconnect() + print 'Mono headset disconnect complete' +elif len(sys.argv) > 1 and sys.argv[1] == 'delete' : + path = audio.DefaultDevice() + print 'Deleting: %s ' % path + audio.RemoveDevice(path) + + + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthstereoheadset.py b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthstereoheadset.py new file mode 100644 index 000000000000..87ff4ec9ed1d --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/bthstereoheadset.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +import dbus +import os +import sys + +def printusage(): + print 'bthstereoheadset.py ' + print ' create - create a stereo headset' + print ' start - connect sink' + print ' stop - disconnect sink' + return + +headsetAddress = os.getenv("BTSTEREO_HEADSET") + +print 'BT Stereo Headset Is : => %s' % headsetAddress + +bus = dbus.SystemBus() +manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager') +bus_id = manager.ActivateService('audio') +audio = dbus.Interface(bus.get_object(bus_id, '/org/bluez/audio'), 'org.bluez.audio.Manager') + +if len(sys.argv) == 1 : + printusage() +elif len(sys.argv) > 1 and sys.argv[1] == 'create' : + path = audio.CreateDevice(headsetAddress) + audio.ChangeDefaultDevice(path) + sink = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Sink') + sink.Connect() + print 'Stereo Headset Connect Done' +elif len(sys.argv) > 1 and sys.argv[1] == 'start' : + path = audio.DefaultDevice() + sink = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Sink') + if not sink.IsConnected() : + sink.Connect() + print 'Audio connected' +elif len(sys.argv) > 1 and sys.argv[1] == 'stop' : + path = audio.DefaultDevice() + sink = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Sink') + try : + sink.Disconnect() + except dbus.exceptions.DBusException: + print 'Disconnect Failed' + print 'Stereo headset disconnect complete' +elif len(sys.argv) > 1 and sys.argv[1] == 'delete' : + path = audio.DefaultDevice() + print 'Deleting: %s ' % path + audio.RemoveDevice(path) + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btmonoloop.sh b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btmonoloop.sh new file mode 100644 index 000000000000..35900e64a89b --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btmonoloop.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +arecord -D bluetooth -f S16_LE | aplay -D bluetooth -f S16_LE + + + + + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btplaywav.sh b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btplaywav.sh new file mode 100644 index 000000000000..e79e816f9887 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/btplaywav.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +aplay -D bluetooth $1 + + + + + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/fc9_setup_readme.txt b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/fc9_setup_readme.txt new file mode 100644 index 000000000000..24382f2eaac8 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/fc9_setup_readme.txt @@ -0,0 +1,165 @@ +This document provides setup instructions for setting up and testing bluetooth on +a Fedora Core 9 system. + +9/25/2008 + + +Setting up Fedora Core 9 +======================== + +You can try to install FC9 via a DVD onto a hard-drive based system or +create a liveUSB disk (if you use the same PC for testing other versions of +linux). + + +Install to HD from DVD install: + + You can install FC9 from here: http://fedoraproject.org/get-fedora + + +Install FC9-liveCD to USB disk (create a liveUSB): + + **** MAKE SURE YOUR PC CAN BOOT TO USB DISKS, older PCs may not support this in their BIOS ****** + + A 4GB USB drive will be sufficient although 8GB is recommended. + + **** Limitations: + Using LiveUSB has some limitations: + 1. USB flash drives have limited writes (typically 100,000). The swap partition is disabled on + a liveUSB. If you expect to do local compilation and editing you should use a hardisk install + or use a USB-based harddisk (laptop drive size would be okay). + 2. USB HD access is slower than USB disk. But I have not noticed any terrible slowdowns. + + *** If your USB disk has U3 support (Sandisk Cruzer), you must disable it. The disk contains a utility to disable + U3 support. As an added check, you should also re-format the drive (as FAT) after your disable U3. + + Making FAT-based USB image on Windows Host PC : + =============================================== + + A windowsPC Utility is available to install a liveCD ISO image directly onto a USB disk and make the disk + bootable. See: https://fedorahosted.org/liveusb-creator + + This method requires a liveCD ISO file for FC9. FC9 is the current version that + support LiveUSB's persistent data storage. You can install applications, new tools, SDKs etc.. + + You can find the FC9 liveCD here: + + http://fedoraproject.org/get-fedora + + When using the utility, you can setup a persistent area. I recommend at least 2GB (max). + + *********** WARNING WARNING, FAT16 is unreliable and not recommended as a liveUSB boot + disk. Newer version of the liveusb-creator now support installations and syslinux binaries for + EXT2 filesystems. I highly recommend using a liveUSB image on an EXT2 formated USB drive. + + Making Ext2-based USB image on Linux Host (for use on FC9 or later host) : + ============================================================================ + + Get the liveCD ISO image from http://fedoraproject.org/get-fedora + + Install the liveusb-creator utilities (as super user) : + + > yum install liveusb-creator + > yum --enablerepo=rawhide update syslinux + + Partition USB disk: + + > fdisk /dev/ + + <--------- fdisk interactive dump: ----> + Command (m for help): d + Selected partition 1 + + Command (m for help): n + Command action + e extended + p primary partition (1-4) + p + Partition number (1-4): 1 + First cylinder (1-960, default 1): + Using default value 1 + Last cylinder or +size or +sizeM or +sizeK (1-960, default 960): + Using default value 960 + + Command (m for help): t + Selected partition 1 + Hex code (type L to list codes): 83 + + Command (m for help): a + Partition number (1-4): 1 + + Command (m for help): w + The partition table has been altered! + + <-----------------------------------------> + + Format partition as ext2: + + > umount /dev/ + > mkfs.ext2 /dev/ + + Run liveusb-creator GUI application: + + > liveusb-creator + + Select ISO image, kernel type (FC9-i686) and persistent storage size. + + see : https://fedorahosted.org/liveusb-creator + + + +Checking and installing packages: +================================= + +To compile our SDK, certain development packages must be installed. + +Log in as superuser + +execute the following: + + yum install yum-utils rpmdevtools + yum install kernel-devel + yum install gtk2-devel + yum install dbus-glib-devel + yum install bluez-utils-gstreamer + yum install openssl-devel + yum install libpcap-devel + yum install bluez-libs-devel + yum install alsa-lib-devel + yum install dbus-devel + +Some useful utilities: + + yum install telnet-server + yum install iperf + +For compilation of newer BlueZ utilities and BlueZ stack: + + yum install byacc + yum install flex + yum install bison + + +Setting up and BUILDING OLCA +============================= + +1. Export ATH_BUILD_TYPE=LOCAL_FC9_i686 + Export ATH_BUS_TYPE=SDIO + + The default kernel path is set to: + + ATH_LINUXPATH=/lib/modules/2.6.25-14.fc9.i686/build + +2. Set your WORKAREA and build normally. + + +Testing AR6K +============ + +1. Unload sdhci (MMC-stack standard host driver) + + as root, execute "rmmod sdhci" + +2. Set NETIF, WORKAREA, ATH_PLATFORM variables and execute the load script (same procedure as FC3). + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/linux_setup_readme.txt b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/linux_setup_readme.txt new file mode 100644 index 000000000000..95c209fbb2ef --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/testscripts/linux_setup_readme.txt @@ -0,0 +1,188 @@ +This document provides setup instructions for setting up and testing bluetooth on +a Fedora Core 9 system. + +Setting up Bluetooth Stack +========================== + +1). The following configurations can be made to /etc/bluetooth/audio.conf + + For HCI devices that use a separate PCM audio path, you must uncomment + + #SCORouting=PCM + + the default is to route audio through the HCI interface (used for USB adapters). + + If you wish to disable role switching (local radio is always master uncomment: + + #Master=true + + To enable A2DP uncomment all lines: + + #[A2DP] + #.. + #.. + +** NOTE **** + + Some linux documents indicate the use of sdpd and bluetoothd-service-audio. These are now deprecated. The hcid application + now functions as an SDP daemon (launched as "hcid -s"). The bluetoothd-service-audio is also deprecated as the hcid + application will load shared libraries (libaudio.so or audio.so) from the /usr/lib/bluetooth/plugin directory. + + +2). Setting up alsa audio devices: + + Create/edit .asoundrc at your home directory ~ + + Add the following: + + pcm.bluetooth { + type bluetooth + } + + +Testing Bluetooth +================== + +*** FC9 ships with BlueZ 3.30 pre-installed. A USB-HCI transport is available in the kernel. +Installing a USB adapter supporting the BT-USB class will automatically be recognized by the BT stack. + + +A). Preparing to add a bluetooth headset + + 1. Make sure HCI adapter is up and running + + For USB, plug in USB-BT adapter. + + For Serial HCI devices (example: csr serial on ttyS0 ): + + hciattach /dev/ttyS0 bcsp 115200 + + hciconfig -a + + 2. Log into FC9 desktop session. Select System->Preference->Internet and Network->Bluetooth + + Set radio button to "Other devices can connect". + + Leave desktop session active. You will need this to enter a pin code because the default PIN code agent is + the GNOME desktop Bluetooth applet. + + + 3. Scan for your headset device: + + > hcitool -i hci0 scan + + make note of the BT address of your headset e.g.: 00:1C:A4:2D:8D:5A + + + *** DEBUGGING BLUEZ stack *** + + You can capture BT stack debug prints (including BT-related dbus prints). + + ** the following can be done as superuser + + 1. Stop Bluetooth service : > service stop bluetooth + 2. launch hcid with debugging enabled : > /usr/sbin/hcid -x -s -n -d + + +B). Pairing Mono headset + + export the following environment variable: + + export BTMONO_HEADSET=00:1C:A4:2D:8D:5A + + run the following python script in $WORKAREA\host\tools\athbtfilter\bluez\testscripts + + > bthmonoheadset.py create + + The desktop applet will ask for a PIN code. Once the pairing has completed you should be able to see "Bonded Devices" + in the Bluetooth applet. You can make this device "TRUSTED" which will store the PIN code and will no longer + require you to input the PIN code. + + To do a quick test (only for BT adapters that route SC(see above).O over HCI): + + > bthmonoheadset.py start + > arecord -D bluetooth -f S16_LE | aplay -D bluetooth -f S16_LE + + This command records the headset microphone input and echos it back to the headset speakers. + + If you have a BT adapter that routes SCO over a PCM interface you can simply turn on the SCO path + using the following command: + + > bthmonoheadset.py start pcm + + To stop: + + > bthmonoheadset.py stop + + **** NOTE: you must configure /etc/bluetooth/audio.conf and set "SCORouting=PCM" (see above) + + You can disconnect the mono headset : + + > bthmonoheadset.py stop + +C). Pairing Stereo headset + + export the following environment variable: + + > export BTSTEREO_HEADSET=00:1C:A4:2D:8D:5A + + run the following python script in $WORKAREA\host\tools\athbtfilter\bluez\testscripts + + > bthstereoheadset.py create + + The desktop applet will ask for a PIN code. Once the pairing has completed you should be able to see "Bonded Devices" + in the Bluetooth applet. You can make this device "TRUSTED" which will store the PIN code and will no longer + require you to input the PIN code. + + To do a quick test: + > bthstereoheadset.py start + > aplay -D bluetooth + + You can disconnect the mono headset : + + > bthstereoheadset.py stop + +Testing Atheros BT Filter +========================= + + The filter resides in $WORKAREA\host\.output\$ATH_PLATFORM\image as 'abtfilt'. + + To operate as a silent daemon execute : > ./abtfilt + To operate the daemon with sysloging: > ./abtfilt -d + To operate the daemon with console logging: > ./abtfilt -c -d + To operate as an ordinary application just add -n to the command line. + + The option "-a" enables the filter to issue the AFH classification HCI command when WLAN connects. + The channel mask is derived from the 2.4 Ghz operating channel (1-14). Upon WLAN disconnect or when + WLAN is switches to 11a, the default AFH classification mask (all channels okay) is issued. + + The following table shows the AFH channel mapping for channels 1-14, channel 0 is a special case + (WLAN disconnected or not operating in 2.4 Ghz band). The channel map is read LSB to the far left + to MSB to the far right and covers the 10 octets defined in the BT specification for the AFH + map. + + LSB ------------------------------------------> MSB + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 0 -- no WLAN */ + { {0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 1 */ + { {0x0F,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 2 */ + { {0xFF,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 3 */ + { {0xFF,0x3F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x7F}}, /* 4 */ + { {0xFF,0xFF,0x07,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x7F}}, /* 5 */ + { {0xFF,0xFF,0xFF,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F}}, /* 6 */ + { {0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0x7F}}, /* 7 */ + { {0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFE,0xFF,0x7F}}, /* 8 */ + { {0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xC0,0xFF,0x7F}}, /* 9 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF8,0x7F}}, /* 10 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x7F}}, /* 11 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x60}}, /* 12 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00}}, /* 13 */ + { {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00}}, /* 14 */ + + + + + + + + + diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/wireless.h b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/wireless.h new file mode 100644 index 000000000000..76cca2a6edfa --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/bluez/wireless.h @@ -0,0 +1,1121 @@ +/* + * This file define a set of standard wireless extensions + * + * Version : 21 14.3.06 + * + * Authors : Jean Tourrilhes - HPL - + * Copyright (c) 1997-2005 Jean Tourrilhes, All Rights Reserved. + */ + +#ifndef _LINUX_WIRELESS_H_LCL +#define _LINUX_WIRELESS_H_LCL + +/************************** DOCUMENTATION **************************/ +/* + * Initial APIs (1996 -> onward) : + * ----------------------------- + * Basically, the wireless extensions are for now a set of standard ioctl + * call + /proc/net/wireless + * + * The entry /proc/net/wireless give statistics and information on the + * driver. + * This is better than having each driver having its entry because + * its centralised and we may remove the driver module safely. + * + * Ioctl are used to configure the driver and issue commands. This is + * better than command line options of insmod because we may want to + * change dynamically (while the driver is running) some parameters. + * + * The ioctl mechanimsm are copied from standard devices ioctl. + * We have the list of command plus a structure descibing the + * data exchanged... + * Note that to add these ioctl, I was obliged to modify : + * # net/core/dev.c (two place + add include) + * # net/ipv4/af_inet.c (one place + add include) + * + * /proc/net/wireless is a copy of /proc/net/dev. + * We have a structure for data passed from the driver to /proc/net/wireless + * Too add this, I've modified : + * # net/core/dev.c (two other places) + * # include/linux/netdevice.h (one place) + * # include/linux/proc_fs.h (one place) + * + * New driver API (2002 -> onward) : + * ------------------------------- + * This file is only concerned with the user space API and common definitions. + * The new driver API is defined and documented in : + * # include/net/iw_handler.h + * + * Note as well that /proc/net/wireless implementation has now moved in : + * # net/core/wireless.c + * + * Wireless Events (2002 -> onward) : + * -------------------------------- + * Events are defined at the end of this file, and implemented in : + * # net/core/wireless.c + * + * Other comments : + * -------------- + * Do not add here things that are redundant with other mechanisms + * (drivers init, ifconfig, /proc/net/dev, ...) and with are not + * wireless specific. + * + * These wireless extensions are not magic : each driver has to provide + * support for them... + * + * IMPORTANT NOTE : As everything in the kernel, this is very much a + * work in progress. Contact me if you have ideas of improvements... + */ + +/***************************** INCLUDES *****************************/ + +/* This header is used in user-space, therefore need to be sanitised + * for that purpose. Those includes are usually not compatible with glibc. + * To know which includes to use in user-space, check iwlib.h. */ +#ifdef __KERNEL__ +#include /* for "caddr_t" et al */ +#include /* for "struct sockaddr" et al */ +#include /* for IFNAMSIZ and co... */ +#endif /* __KERNEL__ */ + +/***************************** VERSION *****************************/ +/* + * This constant is used to know the availability of the wireless + * extensions and to know which version of wireless extensions it is + * (there is some stuff that will be added in the future...) + * I just plan to increment with each new version. + */ +#undef WIRELESS_EXT +#define WIRELESS_EXT 21 + +/* + * Changes : + * + * V2 to V3 + * -------- + * Alan Cox start some incompatibles changes. I've integrated a bit more. + * - Encryption renamed to Encode to avoid US regulation problems + * - Frequency changed from float to struct to avoid problems on old 386 + * + * V3 to V4 + * -------- + * - Add sensitivity + * + * V4 to V5 + * -------- + * - Missing encoding definitions in range + * - Access points stuff + * + * V5 to V6 + * -------- + * - 802.11 support (ESSID ioctls) + * + * V6 to V7 + * -------- + * - define IW_ESSID_MAX_SIZE and IW_MAX_AP + * + * V7 to V8 + * -------- + * - Changed my e-mail address + * - More 802.11 support (nickname, rate, rts, frag) + * - List index in frequencies + * + * V8 to V9 + * -------- + * - Support for 'mode of operation' (ad-hoc, managed...) + * - Support for unicast and multicast power saving + * - Change encoding to support larger tokens (>64 bits) + * - Updated iw_params (disable, flags) and use it for NWID + * - Extracted iw_point from iwreq for clarity + * + * V9 to V10 + * --------- + * - Add PM capability to range structure + * - Add PM modifier : MAX/MIN/RELATIVE + * - Add encoding option : IW_ENCODE_NOKEY + * - Add TxPower ioctls (work like TxRate) + * + * V10 to V11 + * ---------- + * - Add WE version in range (help backward/forward compatibility) + * - Add retry ioctls (work like PM) + * + * V11 to V12 + * ---------- + * - Add SIOCSIWSTATS to get /proc/net/wireless programatically + * - Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space + * - Add new statistics (frag, retry, beacon) + * - Add average quality (for user space calibration) + * + * V12 to V13 + * ---------- + * - Document creation of new driver API. + * - Extract union iwreq_data from struct iwreq (for new driver API). + * - Rename SIOCSIWNAME as SIOCSIWCOMMIT + * + * V13 to V14 + * ---------- + * - Wireless Events support : define struct iw_event + * - Define additional specific event numbers + * - Add "addr" and "param" fields in union iwreq_data + * - AP scanning stuff (SIOCSIWSCAN and friends) + * + * V14 to V15 + * ---------- + * - Add IW_PRIV_TYPE_ADDR for struct sockaddr private arg + * - Make struct iw_freq signed (both m & e), add explicit padding + * - Add IWEVCUSTOM for driver specific event/scanning token + * - Add IW_MAX_GET_SPY for driver returning a lot of addresses + * - Add IW_TXPOW_RANGE for range of Tx Powers + * - Add IWEVREGISTERED & IWEVEXPIRED events for Access Points + * - Add IW_MODE_MONITOR for passive monitor + * + * V15 to V16 + * ---------- + * - Increase the number of bitrates in iw_range to 32 (for 802.11g) + * - Increase the number of frequencies in iw_range to 32 (for 802.11b+a) + * - Reshuffle struct iw_range for increases, add filler + * - Increase IW_MAX_AP to 64 for driver returning a lot of addresses + * - Remove IW_MAX_GET_SPY because conflict with enhanced spy support + * - Add SIOCSIWTHRSPY/SIOCGIWTHRSPY and "struct iw_thrspy" + * - Add IW_ENCODE_TEMP and iw_range->encoding_login_index + * + * V16 to V17 + * ---------- + * - Add flags to frequency -> auto/fixed + * - Document (struct iw_quality *)->updated, add new flags (INVALID) + * - Wireless Event capability in struct iw_range + * - Add support for relative TxPower (yick !) + * + * V17 to V18 (From Jouni Malinen ) + * ---------- + * - Add support for WPA/WPA2 + * - Add extended encoding configuration (SIOCSIWENCODEEXT and + * SIOCGIWENCODEEXT) + * - Add SIOCSIWGENIE/SIOCGIWGENIE + * - Add SIOCSIWMLME + * - Add SIOCSIWPMKSA + * - Add struct iw_range bit field for supported encoding capabilities + * - Add optional scan request parameters for SIOCSIWSCAN + * - Add SIOCSIWAUTH/SIOCGIWAUTH for setting authentication and WPA + * related parameters (extensible up to 4096 parameter values) + * - Add wireless events: IWEVGENIE, IWEVMICHAELMICFAILURE, + * IWEVASSOCREQIE, IWEVASSOCRESPIE, IWEVPMKIDCAND + * + * V18 to V19 + * ---------- + * - Remove (struct iw_point *)->pointer from events and streams + * - Remove header includes to help user space + * - Increase IW_ENCODING_TOKEN_MAX from 32 to 64 + * - Add IW_QUAL_ALL_UPDATED and IW_QUAL_ALL_INVALID macros + * - Add explicit flag to tell stats are in dBm : IW_QUAL_DBM + * - Add IW_IOCTL_IDX() and IW_EVENT_IDX() macros + * + * V20 to V21 + * ---------- + * - Remove (struct net_device *)->get_wireless_stats() + * - Change length in ESSID and NICK to strlen() instead of strlen()+1 + * - Add SIOCSIWMODUL/SIOCGIWMODUL for modulation setting + * - Add IW_RETRY_SHORT/IW_RETRY_LONG retry modifiers + * - Add IW_POWER_SAVING power type + * - Power/Retry relative values no longer * 100000 + * - Add bitrate flags for unicast/broadcast + */ + +/**************************** CONSTANTS ****************************/ + +/* -------------------------- IOCTL LIST -------------------------- */ + +/* Wireless Identification */ +#define SIOCSIWCOMMIT 0x8B00 /* Commit pending changes to driver */ +#define SIOCGIWNAME 0x8B01 /* get name == wireless protocol */ +/* SIOCGIWNAME is used to verify the presence of Wireless Extensions. + * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"... + * Don't put the name of your driver there, it's useless. */ + +/* Basic operations */ +#define SIOCSIWNWID 0x8B02 /* set network id (pre-802.11) */ +#define SIOCGIWNWID 0x8B03 /* get network id (the cell) */ +#define SIOCSIWFREQ 0x8B04 /* set channel/frequency (Hz) */ +#define SIOCGIWFREQ 0x8B05 /* get channel/frequency (Hz) */ +#define SIOCSIWMODE 0x8B06 /* set operation mode */ +#define SIOCGIWMODE 0x8B07 /* get operation mode */ +#define SIOCSIWSENS 0x8B08 /* set sensitivity (dBm) */ +#define SIOCGIWSENS 0x8B09 /* get sensitivity (dBm) */ + +/* Informative stuff */ +#define SIOCSIWRANGE 0x8B0A /* Unused */ +#define SIOCGIWRANGE 0x8B0B /* Get range of parameters */ +#define SIOCSIWPRIV 0x8B0C /* Unused */ +#define SIOCGIWPRIV 0x8B0D /* get private ioctl interface info */ +#define SIOCSIWSTATS 0x8B0E /* Unused */ +#define SIOCGIWSTATS 0x8B0F /* Get /proc/net/wireless stats */ +/* SIOCGIWSTATS is strictly used between user space and the kernel, and + * is never passed to the driver (i.e. the driver will never see it). */ + +/* Spy support (statistics per MAC address - used for Mobile IP support) */ +#define SIOCSIWSPY 0x8B10 /* set spy addresses */ +#define SIOCGIWSPY 0x8B11 /* get spy info (quality of link) */ +#define SIOCSIWTHRSPY 0x8B12 /* set spy threshold (spy event) */ +#define SIOCGIWTHRSPY 0x8B13 /* get spy threshold */ + +/* Access Point manipulation */ +#define SIOCSIWAP 0x8B14 /* set access point MAC addresses */ +#define SIOCGIWAP 0x8B15 /* get access point MAC addresses */ +#define SIOCGIWAPLIST 0x8B17 /* Deprecated in favor of scanning */ +#define SIOCSIWSCAN 0x8B18 /* trigger scanning (list cells) */ +#define SIOCGIWSCAN 0x8B19 /* get scanning results */ + +/* 802.11 specific support */ +#define SIOCSIWESSID 0x8B1A /* set ESSID (network name) */ +#define SIOCGIWESSID 0x8B1B /* get ESSID */ +#define SIOCSIWNICKN 0x8B1C /* set node name/nickname */ +#define SIOCGIWNICKN 0x8B1D /* get node name/nickname */ +/* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit + * within the 'iwreq' structure, so we need to use the 'data' member to + * point to a string in user space, like it is done for RANGE... */ + +/* Other parameters useful in 802.11 and some other devices */ +#define SIOCSIWRATE 0x8B20 /* set default bit rate (bps) */ +#define SIOCGIWRATE 0x8B21 /* get default bit rate (bps) */ +#define SIOCSIWRTS 0x8B22 /* set RTS/CTS threshold (bytes) */ +#define SIOCGIWRTS 0x8B23 /* get RTS/CTS threshold (bytes) */ +#define SIOCSIWFRAG 0x8B24 /* set fragmentation thr (bytes) */ +#define SIOCGIWFRAG 0x8B25 /* get fragmentation thr (bytes) */ +#define SIOCSIWTXPOW 0x8B26 /* set transmit power (dBm) */ +#define SIOCGIWTXPOW 0x8B27 /* get transmit power (dBm) */ +#define SIOCSIWRETRY 0x8B28 /* set retry limits and lifetime */ +#define SIOCGIWRETRY 0x8B29 /* get retry limits and lifetime */ + +/* Encoding stuff (scrambling, hardware security, WEP...) */ +#define SIOCSIWENCODE 0x8B2A /* set encoding token & mode */ +#define SIOCGIWENCODE 0x8B2B /* get encoding token & mode */ +/* Power saving stuff (power management, unicast and multicast) */ +#define SIOCSIWPOWER 0x8B2C /* set Power Management settings */ +#define SIOCGIWPOWER 0x8B2D /* get Power Management settings */ +/* Modulation bitmask */ +#define SIOCSIWMODUL 0x8B2E /* set Modulations settings */ +#define SIOCGIWMODUL 0x8B2F /* get Modulations settings */ + +/* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM). + * This ioctl uses struct iw_point and data buffer that includes IE id and len + * fields. More than one IE may be included in the request. Setting the generic + * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers + * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers + * are required to report the used IE as a wireless event, e.g., when + * associating with an AP. */ +#define SIOCSIWGENIE 0x8B30 /* set generic IE */ +#define SIOCGIWGENIE 0x8B31 /* get generic IE */ + +/* WPA : IEEE 802.11 MLME requests */ +#define SIOCSIWMLME 0x8B16 /* request MLME operation; uses + * struct iw_mlme */ +/* WPA : Authentication mode parameters */ +#define SIOCSIWAUTH 0x8B32 /* set authentication mode params */ +#define SIOCGIWAUTH 0x8B33 /* get authentication mode params */ + +/* WPA : Extended version of encoding configuration */ +#define SIOCSIWENCODEEXT 0x8B34 /* set encoding token & mode */ +#define SIOCGIWENCODEEXT 0x8B35 /* get encoding token & mode */ + +/* WPA2 : PMKSA cache management */ +#define SIOCSIWPMKSA 0x8B36 /* PMKSA cache operation */ + +/* -------------------- DEV PRIVATE IOCTL LIST -------------------- */ + +/* These 32 ioctl are wireless device private, for 16 commands. + * Each driver is free to use them for whatever purpose it chooses, + * however the driver *must* export the description of those ioctls + * with SIOCGIWPRIV and *must* use arguments as defined below. + * If you don't follow those rules, DaveM is going to hate you (reason : + * it make mixed 32/64bit operation impossible). + */ +#define SIOCIWFIRSTPRIV 0x8BE0 +#define SIOCIWLASTPRIV 0x8BFF +/* Previously, we were using SIOCDEVPRIVATE, but we now have our + * separate range because of collisions with other tools such as + * 'mii-tool'. + * We now have 32 commands, so a bit more space ;-). + * Also, all 'odd' commands are only usable by root and don't return the + * content of ifr/iwr to user (but you are not obliged to use the set/get + * convention, just use every other two command). More details in iwpriv.c. + * And I repeat : you are not forced to use them with iwpriv, but you + * must be compliant with it. + */ + +/* ------------------------- IOCTL STUFF ------------------------- */ + +/* The first and the last (range) */ +#define SIOCIWFIRST 0x8B00 +#define SIOCIWLAST SIOCIWLASTPRIV /* 0x8BFF */ +#define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST) + +/* Even : get (world access), odd : set (root access) */ +#define IW_IS_SET(cmd) (!((cmd) & 0x1)) +#define IW_IS_GET(cmd) ((cmd) & 0x1) + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* Those are *NOT* ioctls, do not issue request on them !!! */ +/* Most events use the same identifier as ioctl requests */ + +#define IWEVTXDROP 0x8C00 /* Packet dropped to excessive retry */ +#define IWEVQUAL 0x8C01 /* Quality part of statistics (scan) */ +#define IWEVCUSTOM 0x8C02 /* Driver specific ascii string */ +#define IWEVREGISTERED 0x8C03 /* Discovered a new node (AP mode) */ +#define IWEVEXPIRED 0x8C04 /* Expired a node (AP mode) */ +#define IWEVGENIE 0x8C05 /* Generic IE (WPA, RSN, WMM, ..) + * (scan results); This includes id and + * length fields. One IWEVGENIE may + * contain more than one IE. Scan + * results may contain one or more + * IWEVGENIE events. */ +#define IWEVMICHAELMICFAILURE 0x8C06 /* Michael MIC failure + * (struct iw_michaelmicfailure) + */ +#define IWEVASSOCREQIE 0x8C07 /* IEs used in (Re)Association Request. + * The data includes id and length + * fields and may contain more than one + * IE. This event is required in + * Managed mode if the driver + * generates its own WPA/RSN IE. This + * should be sent just before + * IWEVREGISTERED event for the + * association. */ +#define IWEVASSOCRESPIE 0x8C08 /* IEs used in (Re)Association + * Response. The data includes id and + * length fields and may contain more + * than one IE. This may be sent + * between IWEVASSOCREQIE and + * IWEVREGISTERED events for the + * association. */ +#define IWEVPMKIDCAND 0x8C09 /* PMKID candidate for RSN + * pre-authentication + * (struct iw_pmkid_cand) */ + +#define IWEVFIRST 0x8C00 +#define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST) + +/* ------------------------- PRIVATE INFO ------------------------- */ +/* + * The following is used with SIOCGIWPRIV. It allow a driver to define + * the interface (name, type of data) for its private ioctl. + * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV + */ + +#define IW_PRIV_TYPE_MASK 0x7000 /* Type of arguments */ +#define IW_PRIV_TYPE_NONE 0x0000 +#define IW_PRIV_TYPE_BYTE 0x1000 /* Char as number */ +#define IW_PRIV_TYPE_CHAR 0x2000 /* Char as character */ +#define IW_PRIV_TYPE_INT 0x4000 /* 32 bits int */ +#define IW_PRIV_TYPE_FLOAT 0x5000 /* struct iw_freq */ +#define IW_PRIV_TYPE_ADDR 0x6000 /* struct sockaddr */ + +#define IW_PRIV_SIZE_FIXED 0x0800 /* Variable or fixed number of args */ + +#define IW_PRIV_SIZE_MASK 0x07FF /* Max number of those args */ + +/* + * Note : if the number of args is fixed and the size < 16 octets, + * instead of passing a pointer we will put args in the iwreq struct... + */ + +/* ----------------------- OTHER CONSTANTS ----------------------- */ + +/* Maximum frequencies in the range struct */ +#define IW_MAX_FREQUENCIES 32 +/* Note : if you have something like 80 frequencies, + * don't increase this constant and don't fill the frequency list. + * The user will be able to set by channel anyway... */ + +/* Maximum bit rates in the range struct */ +#define IW_MAX_BITRATES 32 + +/* Maximum tx powers in the range struct */ +#define IW_MAX_TXPOWER 8 +/* Note : if you more than 8 TXPowers, just set the max and min or + * a few of them in the struct iw_range. */ + +/* Maximum of address that you may set with SPY */ +#define IW_MAX_SPY 8 + +/* Maximum of address that you may get in the + list of access points in range */ +#define IW_MAX_AP 64 + +/* Maximum size of the ESSID and NICKN strings */ +#define IW_ESSID_MAX_SIZE 32 + +/* Modes of operation */ +#define IW_MODE_AUTO 0 /* Let the driver decides */ +#define IW_MODE_ADHOC 1 /* Single cell network */ +#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */ +#define IW_MODE_MASTER 3 /* Synchronisation master or Access Point */ +#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */ +#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ +#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ + +/* Statistics flags (bitmask in updated) */ +#define IW_QUAL_QUAL_UPDATED 0x01 /* Value was updated since last read */ +#define IW_QUAL_LEVEL_UPDATED 0x02 +#define IW_QUAL_NOISE_UPDATED 0x04 +#define IW_QUAL_ALL_UPDATED 0x07 +#define IW_QUAL_DBM 0x08 /* Level + Noise are dBm */ +#define IW_QUAL_QUAL_INVALID 0x10 /* Driver doesn't provide value */ +#define IW_QUAL_LEVEL_INVALID 0x20 +#define IW_QUAL_NOISE_INVALID 0x40 +#define IW_QUAL_RCPI 0x80 /* Level + Noise are 802.11k RCPI */ +#define IW_QUAL_ALL_INVALID 0x70 + +/* Frequency flags */ +#define IW_FREQ_AUTO 0x00 /* Let the driver decides */ +#define IW_FREQ_FIXED 0x01 /* Force a specific value */ + +/* Maximum number of size of encoding token available + * they are listed in the range structure */ +#define IW_MAX_ENCODING_SIZES 8 + +/* Maximum size of the encoding token in bytes */ +#define IW_ENCODING_TOKEN_MAX 64 /* 512 bits (for now) */ + +/* Flags for encoding (along with the token) */ +#define IW_ENCODE_INDEX 0x00FF /* Token index (if needed) */ +#define IW_ENCODE_FLAGS 0xFF00 /* Flags defined below */ +#define IW_ENCODE_MODE 0xF000 /* Modes defined below */ +#define IW_ENCODE_DISABLED 0x8000 /* Encoding disabled */ +#define IW_ENCODE_ENABLED 0x0000 /* Encoding enabled */ +#define IW_ENCODE_RESTRICTED 0x4000 /* Refuse non-encoded packets */ +#define IW_ENCODE_OPEN 0x2000 /* Accept non-encoded packets */ +#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ +#define IW_ENCODE_TEMP 0x0400 /* Temporary key */ + +/* Power management flags available (along with the value, if any) */ +#define IW_POWER_ON 0x0000 /* No details... */ +#define IW_POWER_TYPE 0xF000 /* Type of parameter */ +#define IW_POWER_PERIOD 0x1000 /* Value is a period/duration of */ +#define IW_POWER_TIMEOUT 0x2000 /* Value is a timeout (to go asleep) */ +#define IW_POWER_SAVING 0x4000 /* Value is relative (how aggressive)*/ +#define IW_POWER_MODE 0x0F00 /* Power Management mode */ +#define IW_POWER_UNICAST_R 0x0100 /* Receive only unicast messages */ +#define IW_POWER_MULTICAST_R 0x0200 /* Receive only multicast messages */ +#define IW_POWER_ALL_R 0x0300 /* Receive all messages though PM */ +#define IW_POWER_FORCE_S 0x0400 /* Force PM procedure for sending unicast */ +#define IW_POWER_REPEATER 0x0800 /* Repeat broadcast messages in PM period */ +#define IW_POWER_MODIFIER 0x000F /* Modify a parameter */ +#define IW_POWER_MIN 0x0001 /* Value is a minimum */ +#define IW_POWER_MAX 0x0002 /* Value is a maximum */ +#define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ + +/* Transmit Power flags available */ +#define IW_TXPOW_TYPE 0x00FF /* Type of value */ +#define IW_TXPOW_DBM 0x0000 /* Value is in dBm */ +#define IW_TXPOW_MWATT 0x0001 /* Value is in mW */ +#define IW_TXPOW_RELATIVE 0x0002 /* Value is in arbitrary units */ +#define IW_TXPOW_RANGE 0x1000 /* Range of value between min/max */ + +/* Retry limits and lifetime flags available */ +#define IW_RETRY_ON 0x0000 /* No details... */ +#define IW_RETRY_TYPE 0xF000 /* Type of parameter */ +#define IW_RETRY_LIMIT 0x1000 /* Maximum number of retries*/ +#define IW_RETRY_LIFETIME 0x2000 /* Maximum duration of retries in us */ +#define IW_RETRY_MODIFIER 0x00FF /* Modify a parameter */ +#define IW_RETRY_MIN 0x0001 /* Value is a minimum */ +#define IW_RETRY_MAX 0x0002 /* Value is a maximum */ +#define IW_RETRY_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ +#define IW_RETRY_SHORT 0x0010 /* Value is for short packets */ +#define IW_RETRY_LONG 0x0020 /* Value is for long packets */ + +/* Scanning request flags */ +#define IW_SCAN_DEFAULT 0x0000 /* Default scan of the driver */ +#define IW_SCAN_ALL_ESSID 0x0001 /* Scan all ESSIDs */ +#define IW_SCAN_THIS_ESSID 0x0002 /* Scan only this ESSID */ +#define IW_SCAN_ALL_FREQ 0x0004 /* Scan all Frequencies */ +#define IW_SCAN_THIS_FREQ 0x0008 /* Scan only this Frequency */ +#define IW_SCAN_ALL_MODE 0x0010 /* Scan all Modes */ +#define IW_SCAN_THIS_MODE 0x0020 /* Scan only this Mode */ +#define IW_SCAN_ALL_RATE 0x0040 /* Scan all Bit-Rates */ +#define IW_SCAN_THIS_RATE 0x0080 /* Scan only this Bit-Rate */ +/* struct iw_scan_req scan_type */ +#define IW_SCAN_TYPE_ACTIVE 0 +#define IW_SCAN_TYPE_PASSIVE 1 +/* Maximum size of returned data */ +#define IW_SCAN_MAX_DATA 4096 /* In bytes */ + +/* Max number of char in custom event - use multiple of them if needed */ +#define IW_CUSTOM_MAX 256 /* In bytes */ + +/* Generic information element */ +#define IW_GENERIC_IE_MAX 1024 + +/* MLME requests (SIOCSIWMLME / struct iw_mlme) */ +#define IW_MLME_DEAUTH 0 +#define IW_MLME_DISASSOC 1 + +/* SIOCSIWAUTH/SIOCGIWAUTH struct iw_param flags */ +#define IW_AUTH_INDEX 0x0FFF +#define IW_AUTH_FLAGS 0xF000 +/* SIOCSIWAUTH/SIOCGIWAUTH parameters (0 .. 4095) + * (IW_AUTH_INDEX mask in struct iw_param flags; this is the index of the + * parameter that is being set/get to; value will be read/written to + * struct iw_param value field) */ +#define IW_AUTH_WPA_VERSION 0 +#define IW_AUTH_CIPHER_PAIRWISE 1 +#define IW_AUTH_CIPHER_GROUP 2 +#define IW_AUTH_KEY_MGMT 3 +#define IW_AUTH_TKIP_COUNTERMEASURES 4 +#define IW_AUTH_DROP_UNENCRYPTED 5 +#define IW_AUTH_80211_AUTH_ALG 6 +#define IW_AUTH_WPA_ENABLED 7 +#define IW_AUTH_RX_UNENCRYPTED_EAPOL 8 +#define IW_AUTH_ROAMING_CONTROL 9 +#define IW_AUTH_PRIVACY_INVOKED 10 + +/* IW_AUTH_WPA_VERSION values (bit field) */ +#define IW_AUTH_WPA_VERSION_DISABLED 0x00000001 +#define IW_AUTH_WPA_VERSION_WPA 0x00000002 +#define IW_AUTH_WPA_VERSION_WPA2 0x00000004 + +/* IW_AUTH_PAIRWISE_CIPHER and IW_AUTH_GROUP_CIPHER values (bit field) */ +#define IW_AUTH_CIPHER_NONE 0x00000001 +#define IW_AUTH_CIPHER_WEP40 0x00000002 +#define IW_AUTH_CIPHER_TKIP 0x00000004 +#define IW_AUTH_CIPHER_CCMP 0x00000008 +#define IW_AUTH_CIPHER_WEP104 0x00000010 + +/* IW_AUTH_KEY_MGMT values (bit field) */ +#define IW_AUTH_KEY_MGMT_802_1X 1 +#define IW_AUTH_KEY_MGMT_PSK 2 + +/* IW_AUTH_80211_AUTH_ALG values (bit field) */ +#define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001 +#define IW_AUTH_ALG_SHARED_KEY 0x00000002 +#define IW_AUTH_ALG_LEAP 0x00000004 + +/* IW_AUTH_ROAMING_CONTROL values */ +#define IW_AUTH_ROAMING_ENABLE 0 /* driver/firmware based roaming */ +#define IW_AUTH_ROAMING_DISABLE 1 /* user space program used for roaming + * control */ + +/* SIOCSIWENCODEEXT definitions */ +#define IW_ENCODE_SEQ_MAX_SIZE 8 +/* struct iw_encode_ext ->alg */ +#define IW_ENCODE_ALG_NONE 0 +#define IW_ENCODE_ALG_WEP 1 +#define IW_ENCODE_ALG_TKIP 2 +#define IW_ENCODE_ALG_CCMP 3 +/* struct iw_encode_ext ->ext_flags */ +#define IW_ENCODE_EXT_TX_SEQ_VALID 0x00000001 +#define IW_ENCODE_EXT_RX_SEQ_VALID 0x00000002 +#define IW_ENCODE_EXT_GROUP_KEY 0x00000004 +#define IW_ENCODE_EXT_SET_TX_KEY 0x00000008 + +/* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */ +#define IW_MICFAILURE_KEY_ID 0x00000003 /* Key ID 0..3 */ +#define IW_MICFAILURE_GROUP 0x00000004 +#define IW_MICFAILURE_PAIRWISE 0x00000008 +#define IW_MICFAILURE_STAKEY 0x00000010 +#define IW_MICFAILURE_COUNT 0x00000060 /* 1 or 2 (0 = count not supported) + */ + +/* Bit field values for enc_capa in struct iw_range */ +#define IW_ENC_CAPA_WPA 0x00000001 +#define IW_ENC_CAPA_WPA2 0x00000002 +#define IW_ENC_CAPA_CIPHER_TKIP 0x00000004 +#define IW_ENC_CAPA_CIPHER_CCMP 0x00000008 + +/* Event capability macros - in (struct iw_range *)->event_capa + * Because we have more than 32 possible events, we use an array of + * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */ +#define IW_EVENT_CAPA_BASE(cmd) ((cmd >= SIOCIWFIRSTPRIV) ? \ + (cmd - SIOCIWFIRSTPRIV + 0x60) : \ + (cmd - SIOCSIWCOMMIT)) +#define IW_EVENT_CAPA_INDEX(cmd) (IW_EVENT_CAPA_BASE(cmd) >> 5) +#define IW_EVENT_CAPA_MASK(cmd) (1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F)) +/* Event capability constants - event autogenerated by the kernel + * This list is valid for most 802.11 devices, customise as needed... */ +#define IW_EVENT_CAPA_K_0 (IW_EVENT_CAPA_MASK(0x8B04) | \ + IW_EVENT_CAPA_MASK(0x8B06) | \ + IW_EVENT_CAPA_MASK(0x8B1A)) +#define IW_EVENT_CAPA_K_1 (IW_EVENT_CAPA_MASK(0x8B2A)) +/* "Easy" macro to set events in iw_range (less efficient) */ +#define IW_EVENT_CAPA_SET(event_capa, cmd) (event_capa[IW_EVENT_CAPA_INDEX(cmd)] |= IW_EVENT_CAPA_MASK(cmd)) +#define IW_EVENT_CAPA_SET_KERNEL(event_capa) {event_capa[0] |= IW_EVENT_CAPA_K_0; event_capa[1] |= IW_EVENT_CAPA_K_1; } + +/* Modulations bitmasks */ +#define IW_MODUL_ALL 0x00000000 /* Everything supported */ +#define IW_MODUL_FH 0x00000001 /* Frequency Hopping */ +#define IW_MODUL_DS 0x00000002 /* Original Direct Sequence */ +#define IW_MODUL_CCK 0x00000004 /* 802.11b : 5.5 + 11 Mb/s */ +#define IW_MODUL_11B (IW_MODUL_DS | IW_MODUL_CCK) +#define IW_MODUL_PBCC 0x00000008 /* TI : 5.5 + 11 + 22 Mb/s */ +#define IW_MODUL_OFDM_A 0x00000010 /* 802.11a : 54 Mb/s */ +#define IW_MODUL_11A (IW_MODUL_OFDM_A) +#define IW_MODUL_11AB (IW_MODUL_11B | IW_MODUL_11A) +#define IW_MODUL_OFDM_G 0x00000020 /* 802.11g : 54 Mb/s */ +#define IW_MODUL_11G (IW_MODUL_11B | IW_MODUL_OFDM_G) +#define IW_MODUL_11AG (IW_MODUL_11G | IW_MODUL_11A) +#define IW_MODUL_TURBO 0x00000040 /* ATH : bonding, 108 Mb/s */ +/* In here we should define MIMO stuff. Later... */ +#define IW_MODUL_CUSTOM 0x40000000 /* Driver specific */ + +/* Bitrate flags available */ +#define IW_BITRATE_TYPE 0x00FF /* Type of value */ +#define IW_BITRATE_UNICAST 0x0001 /* Maximum/Fixed unicast bitrate */ +#define IW_BITRATE_BROADCAST 0x0002 /* Fixed broadcast bitrate */ + +/****************************** TYPES ******************************/ + +/* --------------------------- SUBTYPES --------------------------- */ +/* + * Generic format for most parameters that fit in an int + */ +struct iw_param +{ + __s32 value; /* The value of the parameter itself */ + __u8 fixed; /* Hardware should not use auto select */ + __u8 disabled; /* Disable the feature */ + __u16 flags; /* Various specifc flags (if any) */ +}; + +/* + * For all data larger than 16 octets, we need to use a + * pointer to memory allocated in user space. + */ +struct iw_point +{ + void __user *pointer; /* Pointer to the data (in user space) */ + __u16 length; /* number of fields or size in bytes */ + __u16 flags; /* Optional params */ +}; + +/* + * A frequency + * For numbers lower than 10^9, we encode the number in 'm' and + * set 'e' to 0 + * For number greater than 10^9, we divide it by the lowest power + * of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')... + * The power of 10 is in 'e', the result of the division is in 'm'. + */ +struct iw_freq +{ + __s32 m; /* Mantissa */ + __s16 e; /* Exponent */ + __u8 i; /* List index (when in range struct) */ + __u8 flags; /* Flags (fixed/auto) */ +}; + +/* + * Quality of the link + */ +struct iw_quality +{ + __u8 qual; /* link quality (%retries, SNR, + %missed beacons or better...) */ + __u8 level; /* signal level (dBm) */ + __u8 noise; /* noise level (dBm) */ + __u8 updated; /* Flags to know if updated */ +}; + +/* + * Packet discarded in the wireless adapter due to + * "wireless" specific problems... + * Note : the list of counter and statistics in net_device_stats + * is already pretty exhaustive, and you should use that first. + * This is only additional stats... + */ +struct iw_discarded +{ + __u32 nwid; /* Rx : Wrong nwid/essid */ + __u32 code; /* Rx : Unable to code/decode (WEP) */ + __u32 fragment; /* Rx : Can't perform MAC reassembly */ + __u32 retries; /* Tx : Max MAC retries num reached */ + __u32 misc; /* Others cases */ +}; + +/* + * Packet/Time period missed in the wireless adapter due to + * "wireless" specific problems... + */ +struct iw_missed +{ + __u32 beacon; /* Missed beacons/superframe */ +}; + +/* + * Quality range (for spy threshold) + */ +struct iw_thrspy +{ + struct sockaddr addr; /* Source address (hw/mac) */ + struct iw_quality qual; /* Quality of the link */ + struct iw_quality low; /* Low threshold */ + struct iw_quality high; /* High threshold */ +}; + +/* + * Optional data for scan request + * + * Note: these optional parameters are controlling parameters for the + * scanning behavior, these do not apply to getting scan results + * (SIOCGIWSCAN). Drivers are expected to keep a local BSS table and + * provide a merged results with all BSSes even if the previous scan + * request limited scanning to a subset, e.g., by specifying an SSID. + * Especially, scan results are required to include an entry for the + * current BSS if the driver is in Managed mode and associated with an AP. + */ +struct iw_scan_req +{ + __u8 scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */ + __u8 essid_len; + __u8 num_channels; /* num entries in channel_list; + * 0 = scan all allowed channels */ + __u8 flags; /* reserved as padding; use zero, this may + * be used in the future for adding flags + * to request different scan behavior */ + struct sockaddr bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or + * individual address of a specific BSS */ + + /* + * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using + * the current ESSID. This allows scan requests for specific ESSID + * without having to change the current ESSID and potentially breaking + * the current association. + */ + __u8 essid[IW_ESSID_MAX_SIZE]; + + /* + * Optional parameters for changing the default scanning behavior. + * These are based on the MLME-SCAN.request from IEEE Std 802.11. + * TU is 1.024 ms. If these are set to 0, driver is expected to use + * reasonable default values. min_channel_time defines the time that + * will be used to wait for the first reply on each channel. If no + * replies are received, next channel will be scanned after this. If + * replies are received, total time waited on the channel is defined by + * max_channel_time. + */ + __u32 min_channel_time; /* in TU */ + __u32 max_channel_time; /* in TU */ + + struct iw_freq channel_list[IW_MAX_FREQUENCIES]; +}; + +/* ------------------------- WPA SUPPORT ------------------------- */ + +/* + * Extended data structure for get/set encoding (this is used with + * SIOCSIWENCODEEXT/SIOCGIWENCODEEXT. struct iw_point and IW_ENCODE_* + * flags are used in the same way as with SIOCSIWENCODE/SIOCGIWENCODE and + * only the data contents changes (key data -> this structure, including + * key data). + * + * If the new key is the first group key, it will be set as the default + * TX key. Otherwise, default TX key index is only changed if + * IW_ENCODE_EXT_SET_TX_KEY flag is set. + * + * Key will be changed with SIOCSIWENCODEEXT in all cases except for + * special "change TX key index" operation which is indicated by setting + * key_len = 0 and ext_flags |= IW_ENCODE_EXT_SET_TX_KEY. + * + * tx_seq/rx_seq are only used when respective + * IW_ENCODE_EXT_{TX,RX}_SEQ_VALID flag is set in ext_flags. Normal + * TKIP/CCMP operation is to set RX seq with SIOCSIWENCODEEXT and start + * TX seq from zero whenever key is changed. SIOCGIWENCODEEXT is normally + * used only by an Authenticator (AP or an IBSS station) to get the + * current TX sequence number. Using TX_SEQ_VALID for SIOCSIWENCODEEXT and + * RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for + * debugging/testing. + */ +struct iw_encode_ext +{ + __u32 ext_flags; /* IW_ENCODE_EXT_* */ + __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast + * (group) keys or unicast address for + * individual keys */ + __u16 alg; /* IW_ENCODE_ALG_* */ + __u16 key_len; + __u8 key[0]; +}; + +/* SIOCSIWMLME data */ +struct iw_mlme +{ + __u16 cmd; /* IW_MLME_* */ + __u16 reason_code; + struct sockaddr addr; +}; + +/* SIOCSIWPMKSA data */ +#define IW_PMKSA_ADD 1 +#define IW_PMKSA_REMOVE 2 +#define IW_PMKSA_FLUSH 3 + +#define IW_PMKID_LEN 16 + +struct iw_pmksa +{ + __u32 cmd; /* IW_PMKSA_* */ + struct sockaddr bssid; + __u8 pmkid[IW_PMKID_LEN]; +}; + +/* IWEVMICHAELMICFAILURE data */ +struct iw_michaelmicfailure +{ + __u32 flags; + struct sockaddr src_addr; + __u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ +}; + +/* IWEVPMKIDCAND data */ +#define IW_PMKID_CAND_PREAUTH 0x00000001 /* RNS pre-authentication enabled */ +struct iw_pmkid_cand +{ + __u32 flags; /* IW_PMKID_CAND_* */ + __u32 index; /* the smaller the index, the higher the + * priority */ + struct sockaddr bssid; +}; + +/* ------------------------ WIRELESS STATS ------------------------ */ +/* + * Wireless statistics (used for /proc/net/wireless) + */ +struct iw_statistics +{ + __u16 status; /* Status + * - device dependent for now */ + + struct iw_quality qual; /* Quality of the link + * (instant/mean/max) */ + struct iw_discarded discard; /* Packet discarded counts */ + struct iw_missed miss; /* Packet missed counts */ +}; + +/* ------------------------ IOCTL REQUEST ------------------------ */ +/* + * This structure defines the payload of an ioctl, and is used + * below. + * + * Note that this structure should fit on the memory footprint + * of iwreq (which is the same as ifreq), which mean a max size of + * 16 octets = 128 bits. Warning, pointers might be 64 bits wide... + * You should check this when increasing the structures defined + * above in this file... + */ +union iwreq_data +{ + /* Config - generic */ + char name[IFNAMSIZ]; + /* Name : used to verify the presence of wireless extensions. + * Name of the protocol/provider... */ + + struct iw_point essid; /* Extended network name */ + struct iw_param nwid; /* network id (or domain - the cell) */ + struct iw_freq freq; /* frequency or channel : + * 0-1000 = channel + * > 1000 = frequency in Hz */ + + struct iw_param sens; /* signal level threshold */ + struct iw_param bitrate; /* default bit rate */ + struct iw_param txpower; /* default transmit power */ + struct iw_param rts; /* RTS threshold threshold */ + struct iw_param frag; /* Fragmentation threshold */ + __u32 mode; /* Operation mode */ + struct iw_param retry; /* Retry limits & lifetime */ + + struct iw_point encoding; /* Encoding stuff : tokens */ + struct iw_param power; /* PM duration/timeout */ + struct iw_quality qual; /* Quality part of statistics */ + + struct sockaddr ap_addr; /* Access point address */ + struct sockaddr addr; /* Destination address (hw/mac) */ + + struct iw_param param; /* Other small parameters */ + struct iw_point data; /* Other large parameters */ +}; + +/* + * The structure to exchange data for ioctl. + * This structure is the same as 'struct ifreq', but (re)defined for + * convenience... + * Do I need to remind you about structure size (32 octets) ? + */ +struct iwreq +{ + union + { + char ifrn_name[IFNAMSIZ]; /* if name, e.g. "eth0" */ + } ifr_ifrn; + + /* Data part (defined just above) */ + union iwreq_data u; +}; + +/* -------------------------- IOCTL DATA -------------------------- */ +/* + * For those ioctl which want to exchange mode data that what could + * fit in the above structure... + */ + +/* + * Range of parameters + */ + +struct iw_range +{ + /* Informative stuff (to choose between different interface) */ + __u32 throughput; /* To give an idea... */ + /* In theory this value should be the maximum benchmarked + * TCP/IP throughput, because with most of these devices the + * bit rate is meaningless (overhead an co) to estimate how + * fast the connection will go and pick the fastest one. + * I suggest people to play with Netperf or any benchmark... + */ + + /* NWID (or domain id) */ + __u32 min_nwid; /* Minimal NWID we are able to set */ + __u32 max_nwid; /* Maximal NWID we are able to set */ + + /* Old Frequency (backward compat - moved lower ) */ + __u16 old_num_channels; + __u8 old_num_frequency; + + /* Wireless event capability bitmasks */ + __u32 event_capa[6]; + + /* signal level threshold range */ + __s32 sensitivity; + + /* Quality of link & SNR stuff */ + /* Quality range (link, level, noise) + * If the quality is absolute, it will be in the range [0 ; max_qual], + * if the quality is dBm, it will be in the range [max_qual ; 0]. + * Don't forget that we use 8 bit arithmetics... */ + struct iw_quality max_qual; /* Quality of the link */ + /* This should contain the average/typical values of the quality + * indicator. This should be the threshold between a "good" and + * a "bad" link (example : monitor going from green to orange). + * Currently, user space apps like quality monitors don't have any + * way to calibrate the measurement. With this, they can split + * the range between 0 and max_qual in different quality level + * (using a geometric subdivision centered on the average). + * I expect that people doing the user space apps will feedback + * us on which value we need to put in each driver... */ + struct iw_quality avg_qual; /* Quality of the link */ + + /* Rates */ + __u8 num_bitrates; /* Number of entries in the list */ + __s32 bitrate[IW_MAX_BITRATES]; /* list, in bps */ + + /* RTS threshold */ + __s32 min_rts; /* Minimal RTS threshold */ + __s32 max_rts; /* Maximal RTS threshold */ + + /* Frag threshold */ + __s32 min_frag; /* Minimal frag threshold */ + __s32 max_frag; /* Maximal frag threshold */ + + /* Power Management duration & timeout */ + __s32 min_pmp; /* Minimal PM period */ + __s32 max_pmp; /* Maximal PM period */ + __s32 min_pmt; /* Minimal PM timeout */ + __s32 max_pmt; /* Maximal PM timeout */ + __u16 pmp_flags; /* How to decode max/min PM period */ + __u16 pmt_flags; /* How to decode max/min PM timeout */ + __u16 pm_capa; /* What PM options are supported */ + + /* Encoder stuff */ + __u16 encoding_size[IW_MAX_ENCODING_SIZES]; /* Different token sizes */ + __u8 num_encoding_sizes; /* Number of entry in the list */ + __u8 max_encoding_tokens; /* Max number of tokens */ + /* For drivers that need a "login/passwd" form */ + __u8 encoding_login_index; /* token index for login token */ + + /* Transmit power */ + __u16 txpower_capa; /* What options are supported */ + __u8 num_txpower; /* Number of entries in the list */ + __s32 txpower[IW_MAX_TXPOWER]; /* list, in bps */ + + /* Wireless Extension version info */ + __u8 we_version_compiled; /* Must be WIRELESS_EXT */ + __u8 we_version_source; /* Last update of source */ + + /* Retry limits and lifetime */ + __u16 retry_capa; /* What retry options are supported */ + __u16 retry_flags; /* How to decode max/min retry limit */ + __u16 r_time_flags; /* How to decode max/min retry life */ + __s32 min_retry; /* Minimal number of retries */ + __s32 max_retry; /* Maximal number of retries */ + __s32 min_r_time; /* Minimal retry lifetime */ + __s32 max_r_time; /* Maximal retry lifetime */ + + /* Frequency */ + __u16 num_channels; /* Number of channels [0; num - 1] */ + __u8 num_frequency; /* Number of entry in the list */ + struct iw_freq freq[IW_MAX_FREQUENCIES]; /* list */ + /* Note : this frequency list doesn't need to fit channel numbers, + * because each entry contain its channel index */ + + __u32 enc_capa; /* IW_ENC_CAPA_* bit field */ + + /* More power management stuff */ + __s32 min_pms; /* Minimal PM saving */ + __s32 max_pms; /* Maximal PM saving */ + __u16 pms_flags; /* How to decode max/min PM saving */ + + /* All available modulations for driver (hw may support less) */ + __s32 modul_capa; /* IW_MODUL_* bit field */ + + /* More bitrate stuff */ + __u32 bitrate_capa; /* Types of bitrates supported */ +}; + +/* + * Private ioctl interface information + */ + +struct iw_priv_args +{ + __u32 cmd; /* Number of the ioctl to issue */ + __u16 set_args; /* Type and number of args */ + __u16 get_args; /* Type and number of args */ + char name[IFNAMSIZ]; /* Name of the extension */ +}; + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* + * Wireless events are carried through the rtnetlink socket to user + * space. They are encapsulated in the IFLA_WIRELESS field of + * a RTM_NEWLINK message. + */ + +/* + * A Wireless Event. Contains basically the same data as the ioctl... + */ +struct iw_event +{ + __u16 len; /* Real lenght of this stuff */ + __u16 cmd; /* Wireless IOCTL */ + union iwreq_data u; /* IOCTL fixed payload */ +}; + +/* Size of the Event prefix (including padding and alignement junk) */ +#define IW_EV_LCP_LEN (sizeof(struct iw_event) - sizeof(union iwreq_data)) +/* Size of the various events */ +#define IW_EV_CHAR_LEN (IW_EV_LCP_LEN + IFNAMSIZ) +#define IW_EV_UINT_LEN (IW_EV_LCP_LEN + sizeof(__u32)) +#define IW_EV_FREQ_LEN (IW_EV_LCP_LEN + sizeof(struct iw_freq)) +#define IW_EV_PARAM_LEN (IW_EV_LCP_LEN + sizeof(struct iw_param)) +#define IW_EV_ADDR_LEN (IW_EV_LCP_LEN + sizeof(struct sockaddr)) +#define IW_EV_QUAL_LEN (IW_EV_LCP_LEN + sizeof(struct iw_quality)) + +/* iw_point events are special. First, the payload (extra data) come at + * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second, + * we omit the pointer, so start at an offset. */ +#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \ + (char *) NULL) +#define IW_EV_POINT_LEN (IW_EV_LCP_LEN + sizeof(struct iw_point) - \ + IW_EV_POINT_OFF) + +#endif /* _LINUX_WIRELESS_H */ diff --git a/drivers/net/wireless/ar6003/host/tools/athbtfilter/filter.sh b/drivers/net/wireless/ar6003/host/tools/athbtfilter/filter.sh new file mode 100644 index 000000000000..f2386548db3f --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/athbtfilter/filter.sh @@ -0,0 +1,24 @@ + +#!/bin/bash + +mkdir ../athbtfilter.bk +cp -r ../athbtfilter ../athbtfilter.bk + +mkdir include +mkdir host +mkdir host/include +mkdir host/os +mkdir host/os/linux +mkdir host/os/linux/include +mkdir host/tools +mkdir host/tools/athbtfilter + +mv bluez host/tools/athbtfilter + +cp Android.mk host +cp Android.mk host/tools +cp Android.mk host/tools/athbtfilter + +cp ../../include/*.h host/include +cp ../../os/linux/include/*.h host/os/linux/include +cp ../../../include/*.h include diff --git a/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Android.mk b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Android.mk new file mode 100644 index 000000000000..e05064ce93b6 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Android.mk @@ -0,0 +1,39 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../../include \ + $(LOCAL_PATH)/../../os/linux/include \ + $(LOCAL_PATH)/../../../include \ + +LOCAL_CFLAGS+= +LOCAL_SRC_FILES:= debugctrl.c +LOCAL_MODULE := drvdebugctrl +LOCAL_MODULE_TAGS := debug eng optional +include $(BUILD_EXECUTABLE) + diff --git a/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Makefile b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Makefile new file mode 100644 index 000000000000..75dffd2ae356 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/Makefile @@ -0,0 +1,5 @@ +CC := $(ATH_CROSS_COMPILE_TYPE)gcc + +all: + $(CC) -g -Wall -I../../include -I../../os/linux/include debugctrl.c -o drvdebugctrl + \ No newline at end of file diff --git a/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/debugctrl.c b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/debugctrl.c new file mode 100644 index 000000000000..c0053ff1063d --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/drvdebugctrl/debugctrl.c @@ -0,0 +1,299 @@ + +/* + * Copyright (c) 2009 Atheros Communications Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +const char *prog_name; +struct ifreq ifr; +int sock; + +char module_name[128]; + +const char cmd_args[] = +"arguments:\n\ + --module= , -m name of module (htc,bmi,wmi,wlan) \n\ + --set= , -s set the current debug mask \n\ + --setbit= , -b set a single bit (0..31) \n\ + --clrbit= , -c clear a single bit (0..31) \n\ + --dumpinfo , -d dump info for this module \n\ + --dumpall dump all registered module debug info \n\ + --interface=, -i (e.g. eth1) \n\ +\n"; + +void +usage(void) +{ + fprintf(stderr, "usage:\n%s arguments...\n", prog_name); + fprintf(stderr, "%s\n", cmd_args); + exit(1); +} + +void +do_ioctl(void *ioctl_data) +{ + ifr.ifr_data = (char *)ioctl_data; + + if (ioctl(sock, AR6000_IOCTL_EXTENDED, &ifr) < 0) { + err(1, "%s", ifr.ifr_name); + exit (1); + } +} + +void DumpModuleDebugInfo(char *name) +{ + struct debuginfocmd { + int cmd; + struct drv_debug_module_s modinfo; + } command; + + memset(&command,0,sizeof(command)); + + command.cmd = AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO; + strncpy(command.modinfo.modulename,name,sizeof(command.modinfo.modulename)); + printf("Dumping module : %s info.... \n",name); + do_ioctl(&command); +} + +void SetDebugBitMask(char *name,unsigned int mask) +{ + struct debuginfocmd { + int cmd; + struct drv_debug_module_s modinfo; + } command; + + memset(&command,0,sizeof(command)); + + command.cmd = AR6000_XIOCTL_MODULE_DEBUG_SET_MASK; + command.modinfo.mask = mask; + strncpy(command.modinfo.modulename,name,sizeof(command.modinfo.modulename)); + printf("Setting module : %s mask to: 0x%X \n", module_name, mask); + do_ioctl(&command); +} + +unsigned int GetDebugBitMask(char *name) +{ + struct debuginfocmd { + int cmd; + struct drv_debug_module_s modinfo; + } command; + + memset(&command,0,sizeof(command)); + + command.cmd = AR6000_XIOCTL_MODULE_DEBUG_GET_MASK; + strncpy(command.modinfo.modulename,name,sizeof(command.modinfo.modulename)); + do_ioctl(&command); + printf("Got module : %s mask : 0x%X \n", module_name, command.modinfo.mask); + return command.modinfo.mask; +} + +void SetDebugBitNo(char *name,unsigned int bit) +{ + unsigned int mask = GetDebugBitMask(name); + + mask |= (1 << bit); + SetDebugBitMask(name, mask); +} + +void ClearDebugBitNo(char *name,unsigned int bit) +{ + unsigned int mask = GetDebugBitMask(name); + + mask &= ~(1 << bit); + SetDebugBitMask(name, mask); +} + +typedef enum { + MASK_ACTION_NONE = 0, + MASK_ACTION_SET_MASK, + MASK_ACTION_SET_BIT, + MASK_ACTION_CLR_BIT, + MASK_ACTION_DUMP_INFO, + MASK_ACTION_DUMP_ALL_INFO +} MASK_ACTION; + +int +main (int argc, char **argv) +{ + + int c; + int gotname = 0; + MASK_ACTION action = MASK_ACTION_NONE; + unsigned int bitmask; + unsigned int bitpos; + + prog_name = argv[0]; + + if (argc == 1) { + usage(); + } + + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + err(1, "socket"); + } + + memset(ifr.ifr_name, '\0', sizeof(ifr.ifr_name)); + strcpy(ifr.ifr_name, "eth1"); /* default */ + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"module", 1, NULL, 'm'}, + {"set", 1, NULL, 's'}, + {"setbit", 1, NULL, 'b'}, + {"clrbit", 1, NULL, 'c'}, + {"interface", 1, NULL, 'i'}, + {"dumpall", 0, NULL, 'a'}, + {"dumpinfo", 0, NULL, 'd'}, + {0, 0, 0, 0} + }; + + c = getopt_long (argc, argv, "m:s:b:c:i:d", + long_options, &option_index); + if (c == -1) { + break; + } + + switch (c) { + + case 'm': + { + strncpy(module_name, optarg, sizeof(module_name)); + gotname = 1; + break; + } + case 's': + { + bitmask = strtoul(optarg, NULL, 0); + action = MASK_ACTION_SET_MASK; + break; + } + + case 'b': + { + bitpos = strtoul(optarg, NULL, 0); + if (bitpos > 31) { + printf(" bit number is too high"); + break; + } + action = MASK_ACTION_SET_BIT; + break; + } + + case 'c': + { + bitpos = strtoul(optarg, NULL, 0); + if (bitpos > 31) { + printf(" bit number is too high"); + break; + } + + action = MASK_ACTION_CLR_BIT; + break; + } + + case 'a': + { + action = MASK_ACTION_DUMP_ALL_INFO; + break; + } + case 'd': + action = MASK_ACTION_DUMP_INFO; + break; + case 'i': + { + memset(ifr.ifr_name, '\0', sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, optarg, sizeof(ifr.ifr_name)); + break; + } + + default: + { + usage(); + break; + } + } + } + + if (action == MASK_ACTION_NONE) { + usage(); + exit(1); + } + + if (action != MASK_ACTION_DUMP_ALL_INFO) { + if (!gotname) { + printf("** must specify module name\n"); + usage(); + exit(1); + } + } + + switch (action) { + + case MASK_ACTION_DUMP_ALL_INFO : + DumpModuleDebugInfo("all"); + break; + case MASK_ACTION_DUMP_INFO: + DumpModuleDebugInfo(module_name); + break; + case MASK_ACTION_CLR_BIT : + ClearDebugBitNo(module_name,bitpos); + DumpModuleDebugInfo(module_name); + break; + case MASK_ACTION_SET_BIT : + SetDebugBitNo(module_name,bitpos); + DumpModuleDebugInfo(module_name); + break; + case MASK_ACTION_SET_MASK : + SetDebugBitMask(module_name,bitmask); + DumpModuleDebugInfo(module_name); + break; + default: + break; + } + + + exit(0); +} diff --git a/drivers/net/wireless/ar6003/host/tools/recEvent/Android.mk b/drivers/net/wireless/ar6003/host/tools/recEvent/Android.mk new file mode 100644 index 000000000000..0edeb4aca1ea --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/recEvent/Android.mk @@ -0,0 +1,43 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2010 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../../include \ + $(LOCAL_PATH)/../../os/linux/include \ + $(LOCAL_PATH)/../../../include \ + $(LOCAL_PATH)/../../wlan/include \ + $(KERNEL_HEADER) + +LOCAL_CFLAGS+= +LOCAL_SRC_FILES:= recEvent.c dbgFormatter.c +LOCAL_MODULE := recEvent +LOCAL_MODULE_TAGS := debug eng optional +LOCAL_SHARED_LIBRARIES := libcutils + +include $(BUILD_EXECUTABLE) + + diff --git a/drivers/net/wireless/ar6003/host/tools/recEvent/Makefile b/drivers/net/wireless/ar6003/host/tools/recEvent/Makefile new file mode 100644 index 000000000000..efee70986568 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/recEvent/Makefile @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2005-2007 Atheros Corporation. All rights reserved. +# +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +#------------------------------------------------------------------------------ +#============================================================================== +# Author(s): ="Atheros" +#============================================================================== +CC := $(ATH_CROSS_COMPILE_TYPE)gcc +KERNEL_SRC :=$(ATH_LINUXPATH) + +all: + $(CC) -Wall -I./ -I$(KERNEL_SRC)/include -I../../include -I../../../include -I../../wlan/include -I../../os/linux/include recEvent.c dbgFormatter.c -o recEvent diff --git a/drivers/net/wireless/ar6003/host/tools/recEvent/dbgFormatter.c b/drivers/net/wireless/ar6003/host/tools/recEvent/dbgFormatter.c new file mode 100644 index 000000000000..b4dd31c111a3 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/recEvent/dbgFormatter.c @@ -0,0 +1,1790 @@ +// +// Copyright (c) 2006 Atheros Communications Inc. +// All rights reserved. +// +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// + +/* This tool parses the recevent logs stored in the binary format + by the wince athsrc */ +#define WAPI_ENABLE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef int (*DbgCmdFormatter)(char *output, size_t len, const A_UINT8 *); +typedef int (*DbgLogFormatter)(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer); + +struct dbglog_desc { + A_INT32 oid; + const char *desc; + DbgLogFormatter formatter; +}; + +struct module_desc { + int module; + const char *name; + struct dbglog_desc *descs; + size_t len; + int bsearch; +}; + +struct wmi_id_desc { + A_INT32 oid; + const char *desc; + DbgCmdFormatter formatter; + size_t cmdSize; +}; + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) +#define CASE_STR_CONST(_s, _n, _val) case _n: (_val) = #_s; break +#define CASE_STR(_x, _val) case _x: (_val) = #_x; break +#define CASE_DEF_STR(_val) default: (_val) = "Unknown"; break +#define BIT_STR(_b, _l, _r, _s, _c, _v) if (((_v) & (_c)) == (_c)) (_r) += snprintf((_b)+(_r), (_l)-(_r), _s) + +#define DBG_DESC(_x) { _x, #_x, NULL } +#define DBG_DESC_FMT(_x) { _x, #_x, _x ## _fmt } + +#define WM_ID_DESC(_x) { _x, #_x, NULL, 0 } +#define WM_ID_DESC_FMT(_x, s) { _x, #_x, _x ## _fmt, s } + +#define MODULE_DESC(_x, _d) { DBGLOG_MODULEID_ ## _x, #_x, _d, ARRAY_SIZE(_d),0} + +extern A_CHAR dbglog_id_tag[DBGLOG_MODULEID_NUM_MAX][DBGLOG_DBGID_NUM_MAX][DBGLOG_DBGID_DEFINITION_LEN_MAX]; +static int check_ids; + +static const char *pmmode2text(A_INT32 mode) +{ + const char *pm; + switch (mode) { + case 1: pm = "sleep"; break; + case 2: pm = "awake"; break; + case 3: pm = "fake_sleep"; break; + default: pm = "unknown"; break; + } + return pm; +} + +#if 0 +static const char *module2text(A_INT32 moduleid) +{ + const char *msg; + switch (moduleid) { + CASE_STR_CONST(INF, DBGLOG_MODULEID_INF, msg); + CASE_STR_CONST(WMI, DBGLOG_MODULEID_WMI, msg); + CASE_STR_CONST(MISC, DBGLOG_MODULEID_MISC, msg); + CASE_STR_CONST(PM, DBGLOG_MODULEID_PM, msg); + CASE_STR_CONST(MGMTBUF, DBGLOG_MODULEID_TXRX_MGMTBUF, msg); + CASE_STR_CONST(TXBUF, DBGLOG_MODULEID_TXRX_TXBUF, msg); + CASE_STR_CONST(RXBUF, DBGLOG_MODULEID_TXRX_RXBUF, msg); + CASE_STR_CONST(WOW, DBGLOG_MODULEID_WOW, msg); + CASE_STR_CONST(WHAL, DBGLOG_MODULEID_WHAL, msg); + CASE_STR_CONST(DC, DBGLOG_MODULEID_DC, msg); + CASE_STR_CONST(CO, DBGLOG_MODULEID_CO, msg); + CASE_STR_CONST(RO, DBGLOG_MODULEID_RO, msg); + CASE_STR_CONST(CM, DBGLOG_MODULEID_CM, msg); + CASE_STR_CONST(MGMT, DBGLOG_MODULEID_MGMT, msg); + CASE_STR_CONST(TMR, DBGLOG_MODULEID_TMR, msg); + CASE_STR_CONST(BTCOEX, DBGLOG_MODULEID_BTCOEX, msg); + CASE_DEF_STR(msg); + } + return msg; +} +#endif + +static const char *pmmodule2text(A_INT32 moduleid) +{ + const char *msg; + switch (moduleid) { + CASE_STR_CONST(CSERV, 1, msg); + CASE_STR_CONST(MLME , 2, msg); + CASE_STR_CONST(TXRX , 3, msg); + CASE_STR_CONST(PM , 4, msg); + CASE_STR_CONST(BT_COEX, 5, msg); + CASE_STR_CONST(CO , 6, msg); + CASE_STR_CONST(DC , 7, msg); + CASE_STR_CONST(RO , 8, msg); + CASE_STR_CONST(CM , 9, msg); + CASE_STR_CONST(RRM , 10, msg); + CASE_STR_CONST(AP , 11, msg); + CASE_STR_CONST(KEYMGMT, 12, msg); + CASE_STR_CONST(CCX , 13, msg); + CASE_STR_CONST(MISC , 14, msg); + CASE_STR_CONST(DFS , 15, msg); + CASE_STR_CONST(TIMER , 16, msg); + CASE_DEF_STR(msg); + } + return msg; +} + +static const char *status2text(A_STATUS status) +{ + const char *msg; + switch (status) { + CASE_STR(A_ERROR, msg); + CASE_STR(A_OK, msg); /* success */ + /* Following values start at 1 */ + CASE_STR(A_DEVICE_NOT_FOUND, msg); /* not able to find PCI device */ + CASE_STR(A_NO_MEMORY, msg); /* not able to allocate memory, msg); not available */ + CASE_STR(A_MEMORY_NOT_AVAIL, msg); /* memory region is not free for mapping */ + CASE_STR(A_NO_FREE_DESC, msg); /* no free descriptors available */ + CASE_STR(A_BAD_ADDRESS, msg); /* address does not match descriptor */ + CASE_STR(A_WIN_DRIVER_ERROR, msg); /* used in NT_HW version, msg); if problem at init */ + CASE_STR(A_REGS_NOT_MAPPED, msg); /* registers not correctly mapped */ + CASE_STR(A_EPERM, msg); /* Not superuser */ + CASE_STR(A_EACCES, msg); /* Access denied */ + CASE_STR(A_ENOENT, msg); /* No such entry, msg); search failed, msg); etc. */ + CASE_STR(A_EEXIST, msg); /* The object already exists (can't create) */ + CASE_STR(A_EFAULT, msg); /* Bad address fault */ + CASE_STR(A_EBUSY, msg); /* Object is busy */ + CASE_STR(A_EINVAL, msg); /* Invalid parameter */ + CASE_STR(A_EMSGSIZE, msg); /* Inappropriate message buffer length */ + CASE_STR(A_ECANCELED, msg); /* Operation canceled */ + CASE_STR(A_ENOTSUP, msg); /* Operation not supported */ + CASE_STR(A_ECOMM, msg); /* Communication error on send */ + CASE_STR(A_EPROTO, msg); /* Protocol error */ + CASE_STR(A_ENODEV, msg); /* No such device */ + CASE_STR(A_EDEVNOTUP, msg); /* device is not UP */ + CASE_STR(A_NO_RESOURCE, msg); /* No resources for requested operation */ + CASE_STR(A_HARDWARE, msg); /* Hardware failure */ + CASE_STR(A_PENDING, msg); /* Asynchronous routine; will send up results la +ter (typically in callback) */ + CASE_STR(A_EBADCHANNEL, msg); /* The channel cannot be used */ + CASE_STR(A_DECRYPT_ERROR, msg); /* Decryption error */ + CASE_STR(A_PHY_ERROR, msg); /* RX PHY error */ + CASE_STR(A_CONSUMED, msg); /* Object was consumed */ + CASE_DEF_STR(msg); + } + return msg; +} + +static const char *btStatus2text(A_INT32 status) +{ + const char *btState; + switch (status) { + CASE_STR_CONST(BT_UNDEF, 1, btState); + CASE_STR_CONST(BT_ON, 2, btState); + CASE_STR_CONST(BT_OFF, 3, btState); + CASE_STR_CONST(BT_IGNORE, 4, btState); + CASE_DEF_STR(btState); + } + return btState; +} + +static int cipher2text(char *buf, size_t len, A_UINT8 cipher) +{ + int ret = 0; + BIT_STR(buf, len, ret, "none ", NONE_CRYPT, cipher); + BIT_STR(buf, len, ret, "wep ", WEP_CRYPT, cipher); + BIT_STR(buf, len, ret, "tkip ", TKIP_CRYPT, cipher); + BIT_STR(buf, len, ret, "aes ", AES_CRYPT, cipher); + buf[(ret>0) ? --ret : ret] = 0; + return ret; +} + +static const char* enable2text(A_INT32 enable) +{ + return enable ? "ENABLE" : "DISABLE"; +} + +static const char* txrxstatus2text(A_INT32 status) +{ + const char *txstatus; + switch (status) { + CASE_STR_CONST(TXRX_ERROR, -1, txstatus); + CASE_STR_CONST(TXRX_OK , 0, txstatus); + CASE_STR_CONST(TXRX_FAILED , 1, txstatus); + CASE_STR_CONST(TXRX_Q_IS_EMPTY , 2, txstatus); + CASE_STR_CONST(TXRX_Q_NOT_DRAINED , 3, txstatus); + CASE_STR_CONST(TXRX_Q_DRAINED_ALL , 4, txstatus); + CASE_STR_CONST(TXRX_Q_DRAIN_PENDING , 5, txstatus); + CASE_STR_CONST(TXRX_IS_MGMT_PKT , 6, txstatus); + CASE_STR_CONST(TXRX_IS_DATA_PKT , 7, txstatus); + CASE_STR_CONST(TXRX_SAVED_AS_FRAG , 8, txstatus); + CASE_STR_CONST(TXRX_Q_IS_PAUSED , 9, txstatus); + CASE_STR_CONST(TXRX_RX_SEND_TO_HOST , 10, txstatus); + CASE_STR_CONST(TXRX_ERROR_PKT_DRAINED , 11, txstatus); + CASE_STR_CONST(TXRX_EOL_EXPIRED , 12, txstatus); + CASE_STR_CONST(TXRX_PS_FILTERED , 13, txstatus); + CASE_STR_CONST(TXRX_RX_SEND_TO_TX , 14, txstatus); + CASE_DEF_STR(txstatus); + } + return txstatus; +} + +static int rxfilter2text(char *buf, size_t blen, A_INT32 rxfilter) +{ + int ret = 0; + BIT_STR(buf, blen, ret, "UCAST " , 0x00000001, rxfilter); + BIT_STR(buf, blen, ret, "MCAST " , 0x00000002, rxfilter); + BIT_STR(buf, blen, ret, "BCAST " , 0x00000004, rxfilter); + BIT_STR(buf, blen, ret, "CONTROL " , 0x00000008, rxfilter); + BIT_STR(buf, blen, ret, "BEACON " , 0x00000010, rxfilter); + BIT_STR(buf, blen, ret, "PROM " , 0x00000020, rxfilter); + BIT_STR(buf, blen, ret, "PROBEREQ ", 0x00000080, rxfilter); + BIT_STR(buf, blen, ret, "MYBEACON ", 0x00000200, rxfilter); + BIT_STR(buf, blen, ret, "COMP_BAR ", 0x00000400, rxfilter); + BIT_STR(buf, blen, ret, "COMP_BA " , 0x00000800, rxfilter); + BIT_STR(buf, blen, ret, "UNCOMP_BA_BAR " , 0x00001000, rxfilter); + BIT_STR(buf, blen, ret, "PS_POLL " , 0x00004000, rxfilter); + BIT_STR(buf, blen, ret, "MCAST_BCAST_ALL " , 0x00008000, rxfilter); + BIT_STR(buf, blen, ret, "FROM_TO_DS " , 0x00020000, rxfilter); + buf[(ret>0) ? --ret : ret] = 0; + return ret; +} + +static int btState2text(char *buf, size_t blen, A_INT32 btState) +{ + int bret = 0; + BIT_STR(buf, blen, bret, "SCO ", (1<<1), btState); + BIT_STR(buf, blen, bret, "A2DP ", (1<<2), btState); + BIT_STR(buf, blen, bret, "SCAN ", (1<<3), btState); + BIT_STR(buf, blen, bret, "ESCO ", (1<<4), btState); + buf[(bret>0) ? --bret : bret] = 0; + return bret; +} + +static int btcoexFlags2text(char *buf, size_t blen, A_INT32 btCoexFlags) +{ + int bret = 0; + BIT_STR(buf, blen, bret, "SCO_ON ", 0x0001, btCoexFlags); + BIT_STR(buf, blen, bret, "A2DP_ON ", 0x0002, btCoexFlags); + BIT_STR(buf, blen, bret, "ACL_ON ", 0x0004, btCoexFlags); + BIT_STR(buf, blen, bret, "INQUIRY_ON ", 0x0008, btCoexFlags); + BIT_STR(buf, blen, bret, "VOIP ", 0x0010, btCoexFlags); + BIT_STR(buf, blen, bret, "RXDATA_PENDING ", 0x0020, btCoexFlags); + BIT_STR(buf, blen, bret, "SLEEP_PENDING ", 0x0040, btCoexFlags); + BIT_STR(buf, blen, bret, "FAKESLEEP_ON ", 0x0080, btCoexFlags); + BIT_STR(buf, blen, bret, "ADD_BA_PENDING ", 0x0100, btCoexFlags); + BIT_STR(buf, blen, bret, "WAKEUP_TIM_INTR ", 0x0200, btCoexFlags); + BIT_STR(buf, blen, bret, "OPT_MODE ", 0x0400, btCoexFlags); + BIT_STR(buf, blen, bret, "FIRST_BMISS ", 0x0800, btCoexFlags); + BIT_STR(buf, blen, bret, "BEACON_PROTECION_ON ", 0x1000, btCoexFlags); + BIT_STR(buf, blen, bret, "WAIT_FOR_NULL_COMP ", 0x4000, btCoexFlags); + BIT_STR(buf, blen, bret, "PROTECT_POST_INQUIRY ", 0x8000, btCoexFlags); + BIT_STR(buf, blen, bret, "DUAL_ANT_ACTIVE ", 0x10000, btCoexFlags); + BIT_STR(buf, blen, bret, "DUAL_ANT_WAKEUP_TIM ", 0x20000, btCoexFlags); + BIT_STR(buf, blen, bret, "STOMP_FOR_DTIM_RECV ", 0x40000, btCoexFlags); + BIT_STR(buf, blen, bret, "ENABLE_COEX_ON_BCN_RECV ", 0x80000, btCoexFlags); + buf[(bret>0) ? --bret : bret] = 0; + return bret; +} + +static int WMI_SET_MCAST_FILTER_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_SET_MCAST_FILTER_CMD *cmd = (WMI_SET_MCAST_FILTER_CMD*)cmdbuf; + return snprintf(output, len, "%02X:%02X:%02X:%02X:%02X:%02X", + cmd->multicast_mac[0], cmd->multicast_mac[1], cmd->multicast_mac[2], + cmd->multicast_mac[3], cmd->multicast_mac[4], cmd->multicast_mac[5]); +} + +static int WMI_DEL_MCAST_FILTER_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + return WMI_SET_MCAST_FILTER_CMDID_fmt(output, len, cmdbuf); +} + +static int WMI_MCAST_FILTER_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_MCAST_FILTER_CMD *cmd = (WMI_MCAST_FILTER_CMD*)cmdbuf; + return snprintf(output, len, "%s", enable2text(cmd->enable)); +} + +static int WMI_START_SCAN_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + int i; + int ret = 0; + WMI_START_SCAN_CMD *cmd = (WMI_START_SCAN_CMD*)cmdbuf; + const char *scanType = (cmd->scanType == WMI_SHORT_SCAN) ? "short" : "long"; + if (cmd->forceFgScan) { + ret += snprintf(output+ret, len-ret, "forceFg "); + } + ret += snprintf(output+ret, len-ret, "hmdwell %u ", cmd->homeDwellTime); + ret += snprintf(output+ret, len-ret, "fscanint %u ", cmd->forceScanInterval); + ret += snprintf(output+ret, len-ret, "%s ", scanType); + for (i=0; inumChannels; ++i) { + ret += snprintf(output+ret, len-ret, "%d ", cmd->channelList[i]); + } + return ret; +} + +static int WMI_CONNECT_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_CONNECT_CMD *cmd = (WMI_CONNECT_CMD*)cmdbuf; + char ssid[33]; + char pairwise[128], group[128]; + const char *dot11Auth, *authMode; + memcpy(ssid, cmd->ssid, 32); + ssid[cmd->ssidLength] = 0; + cipher2text(pairwise, sizeof(pairwise), cmd->pairwiseCryptoType); + cipher2text(group, sizeof(group), cmd->groupCryptoType); + + switch (cmd->dot11AuthMode) { + CASE_STR(OPEN_AUTH, dot11Auth); + CASE_STR(SHARED_AUTH, dot11Auth); + CASE_STR(LEAP_AUTH, dot11Auth); + CASE_DEF_STR(dot11Auth); + } + + switch (cmd->authMode) { + CASE_STR(WMI_NONE_AUTH, authMode); + CASE_STR(WMI_WPA_AUTH, authMode); + CASE_STR(WMI_WPA2_AUTH, authMode); + CASE_STR(WMI_WPA_PSK_AUTH, authMode); + CASE_STR(WMI_WPA2_PSK_AUTH, authMode); + CASE_STR(WMI_WPA_AUTH_CCKM, authMode); + CASE_STR(WMI_WPA2_AUTH_CCKM, authMode); + CASE_DEF_STR(authMode); + } + return snprintf(output, len, "'%s' ch %d %s %s uni:%s grp:%s %02X:%02X:%02X:%02X:%02X:%02X ctrl 0x%x", + ssid, cmd->channel, + dot11Auth, authMode, pairwise, group, + cmd->bssid[0], cmd->bssid[1], cmd->bssid[2], + cmd->bssid[3], cmd->bssid[4], cmd->bssid[5], + cmd->ctrl_flags); +} + +static int WMI_SET_BTCOEX_FE_ANT_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_SET_BTCOEX_FE_ANT_CMD *cmd = (WMI_SET_BTCOEX_FE_ANT_CMD*)cmdbuf; + const char *fe; + switch (cmd->btcoexFeAntType) { + CASE_STR(WMI_BTCOEX_NOT_ENABLED, fe); + CASE_STR(WMI_BTCOEX_FE_ANT_SINGLE, fe); + CASE_STR(WMI_BTCOEX_FE_ANT_DUAL, fe); + CASE_STR(WMI_BTCOEX_FE_ANT_DUAL_HIGH_ISO, fe); + CASE_DEF_STR(fe); + } + return snprintf(output, len, "%s", fe); +} + +static int WMI_SET_BTCOEX_SCO_CONFIG_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_SET_BTCOEX_SCO_CONFIG_CMD *cmd = (WMI_SET_BTCOEX_SCO_CONFIG_CMD*)cmdbuf; + char scoFlags[512]; + int blen = sizeof(scoFlags); + int bret = 0; + BIT_STR(scoFlags, blen, bret, "OPT ", (1<<0), cmd->scoConfig.scoFlags); + BIT_STR(scoFlags, blen, bret, "EDR ", (1<<1), cmd->scoConfig.scoFlags); + BIT_STR(scoFlags, blen, bret, "MASTER ", (1<<2), cmd->scoConfig.scoFlags); + BIT_STR(scoFlags, blen, bret, "FRM ", (1<<3), cmd->scoConfig.scoFlags); + scoFlags[(bret>0) ? --bret : bret] = 0; + + return snprintf(output, len, "%d/%d slots [%s] ps %u-%u-%u opt %u-%u-%u-%u-%u-%u scan %u/%u", + cmd->scoConfig.scoSlots, cmd->scoConfig.scoIdleSlots, scoFlags, + + cmd->scoPspollConfig.scoCyclesForceTrigger, + cmd->scoPspollConfig.scoDataResponseTimeout, + cmd->scoPspollConfig.scoPsPollLatencyFraction, + + cmd->scoOptModeConfig.scoStompCntIn100ms, + cmd->scoOptModeConfig.scoContStompMax, + cmd->scoOptModeConfig.scoMinlowRateMbps, + cmd->scoOptModeConfig.scoLowRateCnt, + cmd->scoOptModeConfig.scoHighPktRatio, + cmd->scoOptModeConfig.scoMaxAggrSize, + + cmd->scoWlanScanConfig.scanInterval, + cmd->scoWlanScanConfig.maxScanStompCnt); +} + +static int WMI_SET_BTCOEX_A2DP_CONFIG_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + return 0; +} + +static int WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + return 0; +} + +static int WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD *cmd = (WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD*)cmdbuf; + return snprintf(output, len, "pspoll every %u inquiry duration %u", + cmd->btInquiryDataFetchFrequency, + cmd->protectBmissDurPostBtInquiry); +} + +static int WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD *cmd = (WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD*)cmdbuf; + const char *profile; + const char *op = (cmd->btOperatingStatus==1) ? "START" : "STOP"; + switch (cmd->btProfileType) { + CASE_STR_CONST(SCO, 1, profile); + CASE_STR_CONST(A2DP, 2, profile); + CASE_STR_CONST(Inquiry, 3, profile); + CASE_STR_CONST(ACL, 4, profile); + CASE_DEF_STR(profile); + } + return snprintf(output, len, "%s %s", profile, op); +} + +static int WMI_SET_LISTEN_INT_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_LISTEN_INT_CMD *cmd = (WMI_LISTEN_INT_CMD*)cmdbuf; + return snprintf(output, len, "interval %d numBeacons %d", cmd->listenInterval, cmd->numBeacons); +} + +static int WMI_SET_BSS_FILTER_CMDID_fmt(char *output, size_t len, const A_UINT8 *cmdbuf) +{ + WMI_BSS_FILTER_CMD *cmd = (WMI_BSS_FILTER_CMD*)cmdbuf; + const char *filter; + switch (cmd->bssFilter) { + CASE_STR(NONE_BSS_FILTER, filter); + CASE_STR(ALL_BSS_FILTER, filter); + CASE_STR(PROFILE_FILTER, filter); + CASE_STR(ALL_BUT_PROFILE_FILTER, filter); + CASE_STR(CURRENT_BSS_FILTER, filter); + CASE_STR(ALL_BUT_BSS_FILTER, filter); + CASE_STR(PROBED_SSID_FILTER, filter); + CASE_STR(LAST_BSS_FILTER, filter); + CASE_DEF_STR(filter); + } + return snprintf(output, len, "[%s]", filter); +} + +static int CO_CHANGE_CHANNEL_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 freq = buffer[1]; + A_INT32 duration = buffer[2]; + return snprintf(output, len, "freq %d duration %d", freq, duration); +} + +static int CO_CHANGE_STATE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 stateLog = (numargs==1) ? buffer[1] : buffer[2]; + int op = stateLog & 0xff; + const char *opstr = op ? "set" : "clr"; + int opState = (stateLog >> 8) & 0xff; + int oldState = stateLog >> 16; + int newState = (op) ? (oldState | opState) : (oldState & ~(opState)); + char state[256]; + size_t blen = sizeof(state); + int ret = 0; + BIT_STR(state, blen, ret, "DRAIN_IN_PROGRESS ", 0x01, newState); + BIT_STR(state, blen, ret, "FAKE_SLEEP_ENABLE_IN_PROGRESS ", 0x02, newState); + BIT_STR(state, blen, ret, "FAKE_SLEEP_ENABLED ", 0x04, newState); + BIT_STR(state, blen, ret, "TXQ_PAUSED ", 0x08, newState); + BIT_STR(state, blen, ret, "CHANNEL_CHANGE_IN_PROGRESS ", 0x10, newState); + state[(ret>0) ? --ret : ret] = 0; + + ret = 0; + if (numargs==2) { + ret = snprintf(output+ret, len-ret, "dev %d ", buffer[1]); + } + ret += snprintf(output+ret, len-ret, "0x%x %s 0x%x->0x%x [%s]", + oldState, opstr, opState, newState, state); + return ret; +} + +static int TXRX_MGMTBUF_WLAN_RESET_ON_ERROR_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + if (numargs==1) { + char buf[512]; + A_INT32 rxfilter = buffer[1]; + rxfilter2text(buf, sizeof(buf),rxfilter); + return snprintf(output, len, "rxfilter:[%s]", buf); + } else if (numargs==2) { + return snprintf(output, len, "rstCnt %d caller %p", + buffer[1], (void*)buffer[2]); + } else { + return 0; + } +} +static int TXRX_MGMTBUF_WAIT_FOR_TXQ_DRAIN_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *mid; + switch (buffer[2]) { + CASE_STR_CONST(CO, 0x001, mid); + CASE_STR_CONST(PM, 0x002, mid); + CASE_STR_CONST(BTCOEX, 0x004, mid); + CASE_DEF_STR(mid); + } + return snprintf(output, len, "wait drain %d ms %s ", buffer[1], mid); +} + +static int TXRX_MGMTBUF_REAPED_BUF_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *txstatus = txrxstatus2text(buffer[2]); + return snprintf(output, len, "mgt %p %s", (void*)buffer[1], txstatus); +} + +static int TXRX_MGMTBUF_DRAINQ_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 hwq = buffer[1]; + A_INT32 depth = buffer[2]; + return snprintf(output, len, "hwq 0x%x depth 0x%x", hwq, depth); +} + +static int DC_RECEIVED_ANY_BEACON_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + if (numargs==1) { + A_INT32 addr3 = buffer[1]; + return snprintf(output, len, "addr3 ??:??:%02X:%02X:%02X:%02X", + (addr3 & 0xff), ((addr3>>8)&0xff), ((addr3>>16)&0xff), ((addr3>>24)&0xff)); + } else if (numargs==2) { + A_UINT64 tsf; + A_UINT8 ie_tstamp[8]; + ie_tstamp[4] = buffer[1] & 0xff; + ie_tstamp[5] = (buffer[1]>>8) & 0xff; + ie_tstamp[6] = (buffer[1]>>16) & 0xff; + ie_tstamp[7] = (buffer[1]>>24) & 0xff; + ie_tstamp[0] = buffer[2] & 0xff; + ie_tstamp[1] = (buffer[2]>>8) & 0xff; + ie_tstamp[2] = (buffer[2]>>16) & 0xff; + ie_tstamp[3] = (buffer[2]>>24) & 0xff; + A_MEMCPY((A_UINT8 *)&tsf, ie_tstamp, sizeof(ie_tstamp)); + return snprintf(output, len, "ie_tsf %llu", tsf); + } + return 0; +} + +static int DC_SET_POWER_MODE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *pm = pmmode2text(buffer[1]); + return snprintf(output, len, "%s caller %p", pm, (void*)buffer[2]); +} + +static int DC_SSID_PROBE_CB_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *txstatus = txrxstatus2text(buffer[1]); + return snprintf(output, len, "%s", txstatus); +} + +static int DC_SEARCH_OPPORTUNITY_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *opt; + switch (buffer[1]) { + CASE_STR_CONST(SCAN_IN_PROGRESS, 1, opt); + CASE_STR_CONST(NOT_SCAN_IN_PROGRESS, 0, opt); + CASE_DEF_STR(opt); + } + return snprintf(output, len, "%s", opt); +} + +static int DC_SEND_NEXT_SSID_PROBE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *flags; + switch (buffer[2]) { + CASE_STR(DISABLE_SSID_FLAG, flags); + CASE_STR(SPECIFIC_SSID_FLAG, flags); + CASE_STR(ANY_SSID_FLAG, flags); + CASE_DEF_STR(flags); + } + return snprintf(output, len, "idx %d %s", buffer[1], flags); +} + +static int DC_SCAN_CHAN_FINISH_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_UINT16 freq = buffer[1] & 0xffff; + A_UINT16 status = (buffer[1] >> 16) & 0xffff; + A_INT32 rxfilter = buffer[2]; + char rxfilterMsg[1024]; + rxfilter2text(rxfilterMsg, sizeof(rxfilterMsg), rxfilter); + return snprintf(output, len, "freq %d status %s(%d), %s", + freq, status2text(status), status, rxfilterMsg); +} + +static int DC_SCAN_CHAN_START_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 rxfilter = buffer[2]; + char rxfilterMsg[1024]; + A_UINT16 freq; + A_UINT16 attrib; + const char *probed; + rxfilter2text(rxfilterMsg, sizeof(rxfilterMsg), rxfilter); + freq = buffer[1] & 0xffff; + attrib = (buffer[1] >> 16) & 0xffff; + probed = ((attrib & (0x0100|0x10))==(0x0100|0x10)) && !(attrib & 0x0800) ? "allow" : "not allow"; + + return snprintf(output, len, "freq %d attrib %d probed %s %s", + freq, attrib, probed, rxfilterMsg); +} + +static int DC_START_SEARCH_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + if (numargs==1) { + return snprintf(output, len, "devid %d", buffer[1]); + } else { + A_INT32 stype = buffer[1]; + int ret = 0; + char buf[1024]; + size_t blen = sizeof(buf); + if (stype == 0) { + BIT_STR(buf, blen, ret, "RESET " , 0, stype); + } + BIT_STR(buf, blen, ret, "ALL " , (0x01|0x02|0x04|0x08), stype); + if (((0x01|0x02|0x04|0x08)& stype)!=(0x01|0x02|0x04|0x08)) { + BIT_STR(buf, blen, ret, "POPULAR " , (0x02 | 0x04 | 0x08), stype); + if (((0x02|0x04|0x08)& stype)!=(0x02|0x04|0x08)) { + BIT_STR(buf, blen, ret, "SSIDS " , (0x04 | 0x08), stype); + if (((0x04|0x08)& stype)!=(0x04|0x08)) { + BIT_STR(buf, blen, ret, "PROF_MASK " , (0x08), stype); + } + } + } + + BIT_STR(buf, blen, ret, "MULTI_CHANNEL " , 0x000100, stype); + BIT_STR(buf, blen, ret, "DETERMINISTIC " , 0x000200, stype); + BIT_STR(buf, blen, ret, "PROFILE_MATCH_TERMINATED " , 0x000400, stype); + BIT_STR(buf, blen, ret, "HOME_CHANNEL_SKIP " , 0x000800, stype); + BIT_STR(buf, blen, ret, "CHANNEL_LIST_CONTINUE " , 0x001000, stype); + BIT_STR(buf, blen, ret, "CURRENT_SSID_SKIP " , 0x002000, stype); + BIT_STR(buf, blen, ret, "ACTIVE_PROBE_DISABLE " , 0x004000, stype); + BIT_STR(buf, blen, ret, "CHANNEL_HINT_ONLY " , 0x008000, stype); + BIT_STR(buf, blen, ret, "ACTIVE_CHANNELS_ONLY " , 0x010000, stype); + BIT_STR(buf, blen, ret, "UNUSED1 " , 0x020000, stype); + BIT_STR(buf, blen, ret, "PERIODIC " , 0x040000, stype); + BIT_STR(buf, blen, ret, "FIXED_DURATION " , 0x080000, stype); + BIT_STR(buf, blen, ret, "AP_ASSISTED " , 0x100000, stype); + buf[(ret>0) ? --ret : ret] = 0; + return snprintf(output, len, "%s cb 0x%x", buf, buffer[2]); + } +} + +static int PM_CHAN_OP_REQ_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *start = (buffer[1]==1) ? "start" : "stop"; + A_INT32 chanOpReq = buffer[2]; + return snprintf(output, len, "%s chan OpReq %d", start, chanOpReq); +} + +static int PM_SET_ALL_BEACON_POLICY_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *policyMsg; + A_UINT16 policy = buffer[1]; + A_UINT32 cnt = buffer[2]; + switch (policy) { + CASE_STR_CONST(disallow, 1, policyMsg); + CASE_STR_CONST(allow, 2, policyMsg); + CASE_DEF_STR(policyMsg); + } + return snprintf(output, len, "%s beacons filterCnt %d", policyMsg, cnt); +} + +static int PM_SET_MY_BEACON_POLICY_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *policyMsg; + A_UINT16 policy = buffer[1] & 0xff; + A_UINT32 bMiss = (buffer[1] >> 8); + A_UINT32 myBeaconCnt = buffer[2]; + switch (policy) { + CASE_STR_CONST(disallow, 1, policyMsg); + CASE_STR_CONST(allow, 2, policyMsg); + CASE_DEF_STR(policyMsg); + } + return snprintf(output, len, "bmiss %d %s during sleep filterCnt %d", bMiss, policyMsg, myBeaconCnt); +} + + +static int PM_SET_STATE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT16 pmStateWakeupCount = (buffer[1] >> 16) & 0xffff; + A_INT16 pmState = buffer[1] & 0xffff; + A_INT16 pmAwakeCount = (buffer[2] >> 16) & 0xffff; + A_INT8 pmSleepCount = (buffer[2] >> 8) & 0xff; + A_INT8 pmOldState = buffer[2] & 0xff; + return snprintf(output, len, "StateWakeupCnt %d AwakeCnt %d, SleepCnt %d, %s to %s", + pmStateWakeupCount, pmAwakeCount, pmSleepCount, + pmmode2text(pmOldState), pmmode2text(pmState)); +} + +static int PM_SET_POWERMODE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_UINT16 wcnt = buffer[1] >> 16; + A_UINT16 fakeSleep = buffer[1] & 0xffff; + A_UINT16 oldPowerMode = buffer[2] >> 16; + A_UINT8 powerMode = (buffer[2] >> 8) & 0xff; + A_UINT8 moduleId = buffer[2] & 0xff; + return snprintf(output, len, "wakeCnt %d fakeSleep %d %s(%d)=>%s(%d) %s(%d)", + wcnt, fakeSleep, pmmode2text(oldPowerMode), oldPowerMode, pmmode2text(powerMode), powerMode, pmmodule2text(moduleId), moduleId); +} + +static int PM_FAKE_SLEEP_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT16 enable = (buffer[1] >> 16) & 0xffff; + const char *state = enable2text(enable); + A_INT8 pmFakeSleepCount = (buffer[1] >> 8) & 0xff; + A_INT8 fakeSleepEnable = (buffer[1] & 0xff); + A_INT16 forceAwake = (buffer[2] >> 16) & 0xffff; + A_INT8 dontWaitForDrain = (buffer[2] >> 8) & 0xff; + A_INT8 module = buffer[2] & 0xff; + return snprintf(output, len, "%s cnt %d hasCnt %d forceAwake %d dontWaitDrain %d %s(%d)", + state, pmFakeSleepCount, fakeSleepEnable, forceAwake, dontWaitForDrain, pmmodule2text(module), module); +} + +static int BTCOEX_DBG_pmwakeupcnt_flags(char *output, size_t len, A_INT32 pmWakeupCnt, A_INT32 btCoexFlags) +{ + int ret = 0; + ret += snprintf(output+ret, len-ret, "coexPmWakeupCnt %d", pmWakeupCnt); + if (btCoexFlags!=-1) { + char buf[512]; + btcoexFlags2text(buf, sizeof(buf), btCoexFlags); + ret += snprintf(output+ret, len-ret, " coex [%s]", buf); + } + return ret; +} + +static int BTCOEX_ACL_COEX_STATUS_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 btStatus = (buffer[1] >> 16) & 0xffff; + A_INT32 redoAggr = buffer[1] & 0xffff; + return snprintf(output, len, "%s redoAggr %d", btStatus2text(btStatus), redoAggr); +} + +static int BTCOEX_DBG_PM_SLEEP_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 pmWakeupCnt = buffer[1]; + A_INT32 btCoexFlags = buffer[2]; + return BTCOEX_DBG_pmwakeupcnt_flags(output,len,pmWakeupCnt,btCoexFlags); +} + +static int BTCOEX_PSPOLL_QUEUED_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT16 isEolEnabled = (buffer[1] >> 16) & 0xffff; + A_INT8 bSendAtLowestRate = (buffer[1] >>8) & 0xff; + A_INT8 isPmSleep = (buffer[1]) & 0xff; + return snprintf(output, len, "Eol:%s LowestRate:%s PmSleep:%s", + enable2text(isEolEnabled), enable2text(bSendAtLowestRate), + enable2text(isPmSleep)); +} + +static int BTCOEX_PSPOLL_COMPLETE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + return snprintf(output, len, "%s", txrxstatus2text(buffer[1])); +} + +static int BTCOEX_DBG_PM_AWAKE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + return BTCOEX_DBG_PM_SLEEP_fmt(output,len,numargs,buffer); +} + +static int BTCOEX_DBG_GO_TO_SLEEP_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + return BTCOEX_DBG_pmwakeupcnt_flags(output,len,buffer[1],-1); +} + +static int BTCOEX_WAKEUP_ON_DATA_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + return BTCOEX_DBG_pmwakeupcnt_flags(output,len,buffer[2], buffer[1]); +} + +static int BTCOEX_TIM_NOTIFICATION_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + int ret = 0; + A_INT32 btCoexFlags = buffer[1]; + A_INT32 btStatus = (buffer[2]>>16) & 0xffff; + A_INT32 pmWakeupCnt = (buffer[2] & 0xffff); + ret = BTCOEX_DBG_pmwakeupcnt_flags(output,len, pmWakeupCnt, btCoexFlags); + ret += snprintf(output+ret, len-ret, " %s", btStatus2text(btStatus)); + return ret; +} + +static int BTCOEX_DBG_ALLOW_SCAN_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + char buf[512]; + A_INT32 retStatus = buffer[2]; + A_INT32 btState = buffer[1]; + btState2text(buf, sizeof(buf), btState); + return snprintf(output, len, "state: [%s] allow:%d", buf, retStatus); +} + +static int BTCOEX_DBG_SCAN_REQUEST_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + char buf[512]; + A_INT32 scanReqEnabled = buffer[2]; + A_INT32 btState = buffer[1]; + btState2text(buf, sizeof(buf), btState); + return snprintf(output, len, "state: [%s] scanReqEnabled:%d", buf, scanReqEnabled); +} + +static int BTCOEX_DBG_SET_WLAN_STATE_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 btCoexFlags = buffer[2]; + char buf[512]; + const char *wlanState; + switch (buffer[1]) { + CASE_STR_CONST(IDLE , 1, wlanState); + CASE_STR_CONST(CONNECTED , 2, wlanState); + CASE_STR_CONST(SCAN_START , 3, wlanState); + CASE_STR_CONST(CONNECT_START ,4, wlanState); + CASE_STR_CONST(SCAN_END , 5, wlanState); + CASE_STR_CONST(APMODE_STA_CONNECTED , 6, wlanState); + CASE_STR_CONST(APMODE_IDLE , 7, wlanState); + CASE_STR_CONST(APMODE_SWITCH , 8, wlanState); + CASE_STR_CONST(APMODE_TEARDOWN , 9, wlanState); + CASE_DEF_STR(wlanState); + } + btcoexFlags2text(buf, sizeof(buf), btCoexFlags); + return snprintf(output, len, "wlan %s coex [%s]", wlanState, buf); +} + +static int BTCOEX_DBG_BT_INQUIRY_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *btState = btStatus2text(buffer[1]); + A_INT32 btCoexFlags = buffer[2]; + char buf[512]; + btcoexFlags2text(buf, sizeof(buf), btCoexFlags); + return snprintf(output, len, "%s coex [%s]", btState, buf); +} + +static int BTCOEX_SET_WEIGHTS_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *weights; + switch (buffer[1]) { + CASE_STR_CONST(ALL_BT_TRAFFIC,1,weights); + CASE_STR_CONST(ONLY_HIGH_PRI_BT_TRAFFIC,2,weights); + CASE_STR_CONST(STOMP_ALL_BT_TRAFFIC,3,weights); + CASE_STR_CONST(ONLY_A2DP_TRAFFIC,4,weights); + CASE_STR_CONST(ONLY_HIGH_PRIO_AND_A2DP,5,weights); + CASE_STR_CONST(A2DP_STOMPED,6,weights); + CASE_STR_CONST(ALL_BT_TRAFFIC_WTX,7,weights); + CASE_STR_CONST(ALL_BT_TRAFFIC_WTX_HIGHISO_TXRX,8,weights); + CASE_STR_CONST(HIGH_PRI_TRAFFIC_WTX,9,weights); + CASE_STR_CONST(HIGH_PRI_TRAFFIC_WTX_HIGHISO_TXRX,0xa,weights); + CASE_STR_CONST(MCI_TEST,0xb,weights); + CASE_DEF_STR(weights); + } + + return snprintf(output, len, "%s val 0x%x", weights, buffer[2]); +} + +static int BTCOEX_PM_FAKE_SLEEP_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *enable = enable2text(buffer[1]); + A_STATUS status = buffer[2]; + return snprintf(output, len, "%s -> %s", enable, status2text(status)); +} + +static const struct wmi_id_desc evt_desc[] = { + WM_ID_DESC(WMI_READY_EVENTID), + WM_ID_DESC(WMI_CONNECT_EVENTID), + WM_ID_DESC(WMI_DISCONNECT_EVENTID), + WM_ID_DESC(WMI_BSSINFO_EVENTID), + WM_ID_DESC(WMI_CMDERROR_EVENTID), + WM_ID_DESC(WMI_REGDOMAIN_EVENTID), + WM_ID_DESC(WMI_PSTREAM_TIMEOUT_EVENTID), + WM_ID_DESC(WMI_NEIGHBOR_REPORT_EVENTID), + WM_ID_DESC(WMI_TKIP_MICERR_EVENTID), + WM_ID_DESC(WMI_SCAN_COMPLETE_EVENTID), /* 0x100a */ + WM_ID_DESC(WMI_REPORT_STATISTICS_EVENTID), + WM_ID_DESC(WMI_RSSI_THRESHOLD_EVENTID), + WM_ID_DESC(WMI_ERROR_REPORT_EVENTID), + WM_ID_DESC(WMI_OPT_RX_FRAME_EVENTID), + WM_ID_DESC(WMI_REPORT_ROAM_TBL_EVENTID), + WM_ID_DESC(WMI_EXTENSION_EVENTID), + WM_ID_DESC(WMI_CAC_EVENTID), + WM_ID_DESC(WMI_SNR_THRESHOLD_EVENTID), + WM_ID_DESC(WMI_LQ_THRESHOLD_EVENTID), + WM_ID_DESC(WMI_TX_RETRY_ERR_EVENTID), /* 0x1014 */ + WM_ID_DESC(WMI_REPORT_ROAM_DATA_EVENTID), + WM_ID_DESC(WMI_TEST_EVENTID), + WM_ID_DESC(WMI_APLIST_EVENTID), + WM_ID_DESC(WMI_GET_WOW_LIST_EVENTID), + WM_ID_DESC(WMI_GET_PMKID_LIST_EVENTID), + WM_ID_DESC(WMI_CHANNEL_CHANGE_EVENTID), + WM_ID_DESC(WMI_PEER_NODE_EVENTID), + WM_ID_DESC(WMI_PSPOLL_EVENTID), + WM_ID_DESC(WMI_DTIMEXPIRY_EVENTID), + WM_ID_DESC(WMI_WLAN_VERSION_EVENTID), + WM_ID_DESC(WMI_SET_PARAMS_REPLY_EVENTID), + WM_ID_DESC(WMI_ADDBA_REQ_EVENTID), /*0x1020 */ + WM_ID_DESC(WMI_ADDBA_RESP_EVENTID), + WM_ID_DESC(WMI_DELBA_REQ_EVENTID), + WM_ID_DESC(WMI_TX_COMPLETE_EVENTID), + WM_ID_DESC(WMI_HCI_EVENT_EVENTID), + WM_ID_DESC(WMI_ACL_DATA_EVENTID), + WM_ID_DESC(WMI_REPORT_SLEEP_STATE_EVENTID), + + WM_ID_DESC(WMI_WAPI_REKEY_EVENTID), + + WM_ID_DESC(WMI_REPORT_BTCOEX_STATS_EVENTID), + WM_ID_DESC(WMI_REPORT_BTCOEX_CONFIG_EVENTID), + WM_ID_DESC(WMI_GET_PMK_EVENTID), + + /* DFS Events */ + WM_ID_DESC(WMI_DFS_HOST_ATTACH_EVENTID), + WM_ID_DESC(WMI_DFS_HOST_INIT_EVENTID), + WM_ID_DESC(WMI_DFS_RESET_DELAYLINES_EVENTID), + WM_ID_DESC(WMI_DFS_RESET_RADARQ_EVENTID), + WM_ID_DESC(WMI_DFS_RESET_AR_EVENTID), + WM_ID_DESC(WMI_DFS_RESET_ARQ_EVENTID), /*0x1030*/ + WM_ID_DESC(WMI_DFS_SET_DUR_MULTIPLIER_EVENTID), + WM_ID_DESC(WMI_DFS_SET_BANGRADAR_EVENTID), + WM_ID_DESC(WMI_DFS_SET_DEBUGLEVEL_EVENTID), + WM_ID_DESC(WMI_DFS_PHYERR_EVENTID), + /* CCX Evants */ + WM_ID_DESC(WMI_CCX_RM_STATUS_EVENTID), + + /* P2P Events */ + WM_ID_DESC(WMI_P2P_GO_NEG_RESULT_EVENTID), + + WM_ID_DESC(WMI_WAC_SCAN_DONE_EVENTID), + WM_ID_DESC(WMI_WAC_REPORT_BSS_EVENTID), + WM_ID_DESC(WMI_WAC_START_WPS_EVENTID), + WM_ID_DESC(WMI_WAC_CTRL_REQ_REPLY_EVENTID), + + /*RFKILL Events*/ + WM_ID_DESC(WMI_RFKILL_STATE_CHANGE_EVENTID), + WM_ID_DESC(WMI_RFKILL_GET_MODE_CMD_EVENTID), + + /* More P2P Events */ + WM_ID_DESC(WMI_P2P_GO_NEG_REQ_EVENTID), + WM_ID_DESC(WMI_P2P_INVITE_REQ_EVENTID), + WM_ID_DESC(WMI_P2P_INVITE_RCVD_RESULT_EVENTID), + WM_ID_DESC(WMI_P2P_INVITE_SENT_RESULT_EVENTID), /*1040*/ + WM_ID_DESC(WMI_P2P_PROV_DISC_RESP_EVENTID), + WM_ID_DESC(WMI_P2P_PROV_DISC_REQ_EVENTID), + WM_ID_DESC(WMI_P2P_START_SDPD_EVENTID), + WM_ID_DESC(WMI_P2P_SDPD_RX_EVENTID), +}; + +static const struct wmi_id_desc cmds_desc[] = { + WM_ID_DESC_FMT(WMI_CONNECT_CMDID, sizeof(WMI_CONNECT_CMD)), + WM_ID_DESC(WMI_RECONNECT_CMDID), + WM_ID_DESC(WMI_DISCONNECT_CMDID), + WM_ID_DESC(WMI_SYNCHRONIZE_CMDID), + WM_ID_DESC(WMI_CREATE_PSTREAM_CMDID), + WM_ID_DESC(WMI_DELETE_PSTREAM_CMDID), + WM_ID_DESC_FMT(WMI_START_SCAN_CMDID, sizeof(WMI_START_SCAN_CMD)), + WM_ID_DESC(WMI_SET_SCAN_PARAMS_CMDID), + WM_ID_DESC_FMT(WMI_SET_BSS_FILTER_CMDID, sizeof(WMI_BSS_FILTER_CMD)), + WM_ID_DESC(WMI_SET_PROBED_SSID_CMDID), /* 10 */ + WM_ID_DESC_FMT(WMI_SET_LISTEN_INT_CMDID, sizeof(WMI_LISTEN_INT_CMD)), + WM_ID_DESC(WMI_SET_BMISS_TIME_CMDID), + WM_ID_DESC(WMI_SET_DISC_TIMEOUT_CMDID), + WM_ID_DESC(WMI_GET_CHANNEL_LIST_CMDID), + WM_ID_DESC(WMI_SET_BEACON_INT_CMDID), + WM_ID_DESC(WMI_GET_STATISTICS_CMDID), + WM_ID_DESC(WMI_SET_CHANNEL_PARAMS_CMDID), + WM_ID_DESC(WMI_SET_POWER_MODE_CMDID), + WM_ID_DESC(WMI_SET_IBSS_PM_CAPS_CMDID), + WM_ID_DESC(WMI_SET_POWER_PARAMS_CMDID), /* 20 */ + WM_ID_DESC(WMI_SET_POWERSAVE_TIMERS_POLICY_CMDID), + WM_ID_DESC(WMI_ADD_CIPHER_KEY_CMDID), + WM_ID_DESC(WMI_DELETE_CIPHER_KEY_CMDID), + WM_ID_DESC(WMI_ADD_KRK_CMDID), + WM_ID_DESC(WMI_DELETE_KRK_CMDID), + WM_ID_DESC(WMI_SET_PMKID_CMDID), + WM_ID_DESC(WMI_SET_TX_PWR_CMDID), + WM_ID_DESC(WMI_GET_TX_PWR_CMDID), + WM_ID_DESC(WMI_SET_ASSOC_INFO_CMDID), + WM_ID_DESC(WMI_ADD_BAD_AP_CMDID), /* 30 */ + WM_ID_DESC(WMI_DELETE_BAD_AP_CMDID), + WM_ID_DESC(WMI_SET_TKIP_COUNTERMEASURES_CMDID), + WM_ID_DESC(WMI_RSSI_THRESHOLD_PARAMS_CMDID), + WM_ID_DESC(WMI_TARGET_ERROR_REPORT_BITMASK_CMDID), + WM_ID_DESC(WMI_SET_ACCESS_PARAMS_CMDID), + WM_ID_DESC(WMI_SET_RETRY_LIMITS_CMDID), + WM_ID_DESC(WMI_RESERVED1), + WM_ID_DESC(WMI_RESERVED2), + WM_ID_DESC(WMI_SET_VOICE_PKT_SIZE_CMDID), + WM_ID_DESC(WMI_SET_MAX_SP_LEN_CMDID), /* 40 */ + WM_ID_DESC(WMI_SET_ROAM_CTRL_CMDID), + WM_ID_DESC(WMI_GET_ROAM_TBL_CMDID), + WM_ID_DESC(WMI_GET_ROAM_DATA_CMDID), + WM_ID_DESC(WMI_ENABLE_RM_CMDID), + WM_ID_DESC(WMI_SET_MAX_OFFHOME_DURATION_CMDID), + WM_ID_DESC(WMI_EXTENSION_CMDID), /* Non-wireless extensions */ + WM_ID_DESC(WMI_SNR_THRESHOLD_PARAMS_CMDID), + WM_ID_DESC(WMI_LQ_THRESHOLD_PARAMS_CMDID), + WM_ID_DESC(WMI_SET_LPREAMBLE_CMDID), + WM_ID_DESC(WMI_SET_RTS_CMDID), /* 50 */ + WM_ID_DESC(WMI_CLR_RSSI_SNR_CMDID), + WM_ID_DESC(WMI_SET_FIXRATES_CMDID), + WM_ID_DESC(WMI_GET_FIXRATES_CMDID), + WM_ID_DESC(WMI_SET_AUTH_MODE_CMDID), + WM_ID_DESC(WMI_SET_REASSOC_MODE_CMDID), + WM_ID_DESC(WMI_SET_WMM_CMDID), + WM_ID_DESC(WMI_SET_WMM_TXOP_CMDID), + WM_ID_DESC(WMI_TEST_CMDID), + /* COEX AR6002 only*/ + WM_ID_DESC(WMI_SET_BT_STATUS_CMDID), + WM_ID_DESC(WMI_SET_BT_PARAMS_CMDID), /* 60 */ + + WM_ID_DESC(WMI_SET_KEEPALIVE_CMDID), + WM_ID_DESC(WMI_GET_KEEPALIVE_CMDID), + WM_ID_DESC(WMI_SET_APPIE_CMDID), + WM_ID_DESC(WMI_GET_APPIE_CMDID), + WM_ID_DESC(WMI_SET_WSC_STATUS_CMDID), + + /* Wake on Wireless */ + WM_ID_DESC(WMI_SET_HOST_SLEEP_MODE_CMDID), + WM_ID_DESC(WMI_SET_WOW_MODE_CMDID), + WM_ID_DESC(WMI_GET_WOW_LIST_CMDID), + WM_ID_DESC(WMI_ADD_WOW_PATTERN_CMDID), + WM_ID_DESC(WMI_DEL_WOW_PATTERN_CMDID), /* 70 */ + + WM_ID_DESC(WMI_SET_FRAMERATES_CMDID), + WM_ID_DESC(WMI_SET_AP_PS_CMDID), + WM_ID_DESC(WMI_SET_QOS_SUPP_CMDID), +}; + +static const struct wmi_id_desc cmdxs_desc[] = { + WM_ID_DESC(WMI_SET_BITRATE_CMDID), + WM_ID_DESC(WMI_GET_BITRATE_CMDID), + WM_ID_DESC(WMI_SET_WHALPARAM_CMDID), + + + /*Should add the new command to the tail for compatible with + * etna. + */ + WM_ID_DESC(WMI_SET_MAC_ADDRESS_CMDID), + WM_ID_DESC(WMI_SET_AKMP_PARAMS_CMDID), + WM_ID_DESC(WMI_SET_PMKID_LIST_CMDID), + WM_ID_DESC(WMI_GET_PMKID_LIST_CMDID), + WM_ID_DESC(WMI_ABORT_SCAN_CMDID), + WM_ID_DESC(WMI_SET_TARGET_EVENT_REPORT_CMDID), + + /* Unused */ + WM_ID_DESC(WMI_UNUSED1), + WM_ID_DESC(WMI_UNUSED2), + + /* + * AP mode commands + */ + WM_ID_DESC(WMI_AP_HIDDEN_SSID_CMDID), + WM_ID_DESC(WMI_AP_SET_NUM_STA_CMDID), + WM_ID_DESC(WMI_AP_ACL_POLICY_CMDID), + WM_ID_DESC(WMI_AP_ACL_MAC_LIST_CMDID), + WM_ID_DESC(WMI_AP_CONFIG_COMMIT_CMDID), + WM_ID_DESC(WMI_AP_SET_MLME_CMDID), + WM_ID_DESC(WMI_AP_SET_PVB_CMDID), + WM_ID_DESC(WMI_AP_CONN_INACT_CMDID), + WM_ID_DESC(WMI_AP_PROT_SCAN_TIME_CMDID), + WM_ID_DESC(WMI_AP_SET_COUNTRY_CMDID), + WM_ID_DESC(WMI_AP_SET_DTIM_CMDID), + WM_ID_DESC(WMI_AP_MODE_STAT_CMDID), + + WM_ID_DESC(WMI_SET_IP_CMDID), + WM_ID_DESC(WMI_SET_PARAMS_CMDID), + WM_ID_DESC_FMT(WMI_SET_MCAST_FILTER_CMDID, sizeof(WMI_SET_MCAST_FILTER_CMD)), + WM_ID_DESC_FMT(WMI_DEL_MCAST_FILTER_CMDID, sizeof(WMI_SET_MCAST_FILTER_CMD)), + + WM_ID_DESC(WMI_ALLOW_AGGR_CMDID), + WM_ID_DESC(WMI_ADDBA_REQ_CMDID), + WM_ID_DESC(WMI_DELBA_REQ_CMDID), + WM_ID_DESC(WMI_SET_HT_CAP_CMDID), + WM_ID_DESC(WMI_SET_HT_OP_CMDID), + WM_ID_DESC(WMI_SET_TX_SELECT_RATES_CMDID), + WM_ID_DESC(WMI_SET_TX_SGI_PARAM_CMDID), + WM_ID_DESC(WMI_SET_RATE_POLICY_CMDID), + + WM_ID_DESC(WMI_HCI_CMD_CMDID), + WM_ID_DESC(WMI_RX_FRAME_FORMAT_CMDID), + WM_ID_DESC(WMI_SET_THIN_MODE_CMDID), + WM_ID_DESC(WMI_SET_BT_WLAN_CONN_PRECEDENCE_CMDID), + + WM_ID_DESC(WMI_AP_SET_11BG_RATESET_CMDID), + WM_ID_DESC(WMI_SET_PMK_CMDID), + WM_ID_DESC_FMT(WMI_MCAST_FILTER_CMDID, sizeof(WMI_MCAST_FILTER_CMD)), + /* COEX CMDID AR6003*/ + WM_ID_DESC_FMT(WMI_SET_BTCOEX_FE_ANT_CMDID, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)), + WM_ID_DESC(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMDID), + WM_ID_DESC_FMT(WMI_SET_BTCOEX_SCO_CONFIG_CMDID, sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD)), + WM_ID_DESC_FMT(WMI_SET_BTCOEX_A2DP_CONFIG_CMDID, sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD)), + WM_ID_DESC_FMT(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMDID, sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD)), + WM_ID_DESC_FMT(WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMDID, sizeof(WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD)), + WM_ID_DESC(WMI_SET_BTCOEX_DEBUG_CMDID), + WM_ID_DESC_FMT(WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMDID, sizeof(WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD)), + WM_ID_DESC(WMI_GET_BTCOEX_STATS_CMDID), + WM_ID_DESC(WMI_GET_BTCOEX_CONFIG_CMDID), + + WM_ID_DESC(WMI_SET_DFS_ENABLE_CMDID), /* F034 */ + WM_ID_DESC(WMI_SET_DFS_MINRSSITHRESH_CMDID), + WM_ID_DESC(WMI_SET_DFS_MAXPULSEDUR_CMDID), + WM_ID_DESC(WMI_DFS_RADAR_DETECTED_CMDID), + + /* P2P CMDS */ + WM_ID_DESC(WMI_P2P_SET_CONFIG_CMDID), /* F038 */ + WM_ID_DESC(WMI_WPS_SET_CONFIG_CMDID), + WM_ID_DESC(WMI_SET_REQ_DEV_ATTR_CMDID), + WM_ID_DESC(WMI_P2P_FIND_CMDID), + WM_ID_DESC(WMI_P2P_STOP_FIND_CMDID), + WM_ID_DESC(WMI_P2P_GO_NEG_START_CMDID), + WM_ID_DESC(WMI_P2P_LISTEN_CMDID), + + WM_ID_DESC(WMI_CONFIG_TX_MAC_RULES_CMDID), + WM_ID_DESC(WMI_SET_PROMISCUOUS_MODE_CMDID),/* F040 */ + WM_ID_DESC(WMI_RX_FRAME_FILTER_CMDID), + WM_ID_DESC(WMI_SET_CHANNEL_CMDID), + + /* WAC commands */ + WM_ID_DESC(WMI_ENABLE_WAC_CMDID), + WM_ID_DESC(WMI_WAC_SCAN_REPLY_CMDID), + WM_ID_DESC(WMI_WAC_CTRL_REQ_CMDID), + WM_ID_DESC(WMI_SET_DIV_PARAMS_CMDID), + + WM_ID_DESC(WMI_GET_PMK_CMDID), + WM_ID_DESC(WMI_SET_PASSPHRASE_CMDID), + WM_ID_DESC(WMI_SEND_ASSOC_RES_CMDID), + WM_ID_DESC(WMI_SET_ASSOC_REQ_RELAY_CMDID), + WM_ID_DESC(WMI_GET_RFKILL_MODE_CMDID), + WM_ID_DESC(WMI_SET_RFKILL_MODE_CMDID), + + /* ACS command, consists of sub-commands */ + WM_ID_DESC(WMI_ACS_CTRL_CMDID), + + /* Ultra low power store / recall commands */ + WM_ID_DESC(WMI_STORERECALL_CONFIGURE_CMDID), + WM_ID_DESC(WMI_STORERECALL_RECALL_CMDID), + WM_ID_DESC(WMI_STORERECALL_HOST_READY_CMDID), + WM_ID_DESC(WMI_FORCE_TARGET_ASSERT_CMDID), + WM_ID_DESC(WMI_SET_EXCESS_TX_RETRY_THRES_CMDID), + + WM_ID_DESC(WMI_P2P_GO_NEG_REQ_RSP_CMDID), /* F053 */ + WM_ID_DESC(WMI_P2P_GRP_INIT_CMDID), + WM_ID_DESC(WMI_P2P_GRP_FORMATION_DONE_CMDID), + WM_ID_DESC(WMI_P2P_INVITE_CMDID), + WM_ID_DESC(WMI_P2P_INVITE_REQ_RSP_CMDID), + WM_ID_DESC(WMI_P2P_PROV_DISC_REQ_CMDID), + WM_ID_DESC(WMI_P2P_SET_CMDID), + + WM_ID_DESC(WMI_AP_SET_APSD_CMDID), /* F05A */ + WM_ID_DESC(WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID), + + WM_ID_DESC(WMI_P2P_SDPD_TX_CMDID), /* F05C */ + WM_ID_DESC(WMI_P2P_STOP_SDPD_CMDID), + WM_ID_DESC(WMI_P2P_CANCEL_CMDID), +}; + +static int dbg_wmi_cmd_params_pos, dbg_wmi_cmd_params_cmdid; +static A_UINT8 *dbg_wmi_cmd_params_buf; + +static int WMI_EVENT_SEND_XTND_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + const char *txt; + A_INT32 evt = buffer[1]; + switch (evt) { + CASE_STR(WMIX_DSETOPENREQ_EVENTID, txt); + CASE_STR(WMIX_DSETCLOSE_EVENTID, txt); + CASE_STR(WMIX_DSETDATAREQ_EVENTID, txt); + CASE_STR(WMIX_GPIO_INTR_EVENTID, txt); + CASE_STR(WMIX_GPIO_DATA_EVENTID, txt); + CASE_STR(WMIX_GPIO_ACK_EVENTID, txt); + CASE_STR(WMIX_HB_CHALLENGE_RESP_EVENTID, txt); + CASE_STR(WMIX_DBGLOG_EVENTID, txt); + CASE_STR(WMIX_PROF_COUNT_EVENTID, txt); + CASE_DEF_STR(txt); + } + return snprintf(output, len, "%s", txt); +} + +static int WMI_EVENT_SEND_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 idx = buffer[1]; + A_INT32 sidx; + if (idx>=(A_INT32)WMI_READY_EVENTID && + idx<(A_INT32)(WMI_READY_EVENTID+ARRAY_SIZE(evt_desc))) { + sidx = idx - WMI_READY_EVENTID; + return snprintf(output, len, "%s", evt_desc[sidx].desc); + } else if (idx>=(A_INT32)WMI_SET_BITRATE_CMDID && + idx<(A_INT32)(WMI_SET_BITRATE_CMDID+ARRAY_SIZE(cmdxs_desc))) { + sidx = idx - WMI_SET_BITRATE_CMDID; + return snprintf(output, len, "%s", cmdxs_desc[sidx].desc); + } + return 0; +} + + +static int WMI_CMD_RX_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 idx = buffer[1]; + A_INT32 length = buffer[2]; + A_INT32 sidx; + if (idx>=(A_INT32)WMI_CONNECT_CMDID && + idx<(A_INT32)(WMI_CONNECT_CMDID+ARRAY_SIZE(cmds_desc))) { + sidx = idx-WMI_CONNECT_CMDID; + return snprintf(output, len, "%s, len %d", + cmds_desc[sidx].desc, length); + } else if (idx>=(A_INT32)WMI_SET_BITRATE_CMDID && + idx<(A_INT32)(WMI_SET_BITRATE_CMDID+ARRAY_SIZE(cmdxs_desc))) { + sidx = idx - WMI_SET_BITRATE_CMDID; + return snprintf(output, len, "%s, len %d", + cmdxs_desc[sidx].desc, length); + } + return 0; +} + +static int WMI_CMD_PARAMS_DUMP_START_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + A_INT32 paramslen = buffer[2]; + paramslen += (sizeof(A_INT32) * 2); /* adding pad */ + dbg_wmi_cmd_params_pos = 0; + dbg_wmi_cmd_params_cmdid = buffer[1]; + dbg_wmi_cmd_params_buf = (paramslen>0) ? malloc(paramslen) : NULL; + return 0; +} + +static int WMI_CMD_PARAMS_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + if (dbg_wmi_cmd_params_buf == NULL) { + /* partial debug log where there is no START. Skip it*/ + return 0; + } + memcpy(&dbg_wmi_cmd_params_buf[dbg_wmi_cmd_params_pos], &buffer[1], sizeof(A_INT32)); + memcpy(&dbg_wmi_cmd_params_buf[dbg_wmi_cmd_params_pos+4], &buffer[2], sizeof(A_INT32)); + dbg_wmi_cmd_params_pos += (sizeof(A_INT32) * 2); + return 0; +} + +static int WMI_CMD_PARAMS_DUMP_END_fmt(char *output, size_t len, A_UINT32 numargs, A_INT32 *buffer) +{ + int ret = 0; + A_INT32 idx = dbg_wmi_cmd_params_cmdid; + DbgCmdFormatter cmdFormatter = NULL; + size_t cmdSize; + if (dbg_wmi_cmd_params_buf == NULL) { + /* partial debug log where there is no START. Skip it*/ + return 0; + } + if (idx>=(A_INT32)WMI_CONNECT_CMDID && + idx<(A_INT32)(WMI_CONNECT_CMDID+ARRAY_SIZE(cmds_desc)) ) { + cmdFormatter = cmds_desc[idx-WMI_CONNECT_CMDID].formatter; + cmdSize = cmds_desc[idx-WMI_CONNECT_CMDID].cmdSize; + } else if (idx>=(A_INT32)WMI_SET_BITRATE_CMDID && + idx<(A_INT32)(WMI_SET_BITRATE_CMDID+ARRAY_SIZE(cmdxs_desc))) { + cmdFormatter = cmdxs_desc[idx-WMI_SET_BITRATE_CMDID].formatter; + cmdSize = cmdxs_desc[idx-WMI_SET_BITRATE_CMDID].cmdSize; + } + if (cmdFormatter) { + ret += snprintf(output+ret, len-ret, " "); + if (dbg_wmi_cmd_params_pos>=cmdSize) { + ret += cmdFormatter(output+ret, len-ret, dbg_wmi_cmd_params_buf); + } else { + ret += snprintf(output+ret, len-ret, "malformed cmd. size too small %d < %d", + dbg_wmi_cmd_params_pos, cmdSize); + } + } + dbg_wmi_cmd_params_pos = 0; + dbg_wmi_cmd_params_cmdid = 0; + free(dbg_wmi_cmd_params_buf); + dbg_wmi_cmd_params_buf = NULL; + return ret; +} + +static struct dbglog_desc wmi_desc[] = { + DBG_DESC(0), + DBG_DESC(WMI_CMD_RX_XTND_PKT_TOO_SHORT), + DBG_DESC(WMI_EXTENDED_CMD_NOT_HANDLED), + DBG_DESC(WMI_CMD_RX_PKT_TOO_SHORT), + DBG_DESC(WMI_CALLING_WMI_EXTENSION_FN), + DBG_DESC(WMI_CMD_NOT_HANDLED), + DBG_DESC(WMI_IN_SYNC), + DBG_DESC(WMI_TARGET_WMI_SYNC_CMD), + DBG_DESC(WMI_SET_SNR_THRESHOLD_PARAMS), + DBG_DESC(WMI_SET_RSSI_THRESHOLD_PARAMS), + DBG_DESC(WMI_SET_LQ_TRESHOLD_PARAMS), + DBG_DESC(WMI_TARGET_CREATE_PSTREAM_CMD), + DBG_DESC(WMI_WI_DTM_INUSE), + DBG_DESC(WMI_TARGET_DELETE_PSTREAM_CMD), + DBG_DESC(WMI_TARGET_IMPLICIT_DELETE_PSTREAM_CMD), + DBG_DESC(WMI_TARGET_GET_BIT_RATE_CMD), + DBG_DESC(WMI_GET_RATE_MASK_CMD_FIX_RATE_MASK_IS), + DBG_DESC(WMI_TARGET_GET_AVAILABLE_CHANNELS_CMD), + DBG_DESC(WMI_TARGET_GET_TX_PWR_CMD), + DBG_DESC(WMI_FREE_EVBUF_WMIBUF), + DBG_DESC(WMI_FREE_EVBUF_DATABUF), + DBG_DESC(WMI_FREE_EVBUF_BADFLAG), + DBG_DESC(WMI_HTC_RX_ERROR_DATA_PACKET), + DBG_DESC(WMI_HTC_RX_SYNC_PAUSING_FOR_MBOX), + DBG_DESC(WMI_INCORRECT_WMI_DATA_HDR_DROPPING_PKT), + DBG_DESC(WMI_SENDING_READY_EVENT), + DBG_DESC(WMI_SETPOWER_MDOE_TO_MAXPERF), + DBG_DESC(WMI_SETPOWER_MDOE_TO_REC), + DBG_DESC(WMI_BSSINFO_EVENT_FROM), + DBG_DESC(WMI_TARGET_GET_STATS_CMD), + DBG_DESC(WMI_SENDING_SCAN_COMPLETE_EVENT), + DBG_DESC(WMI_SENDING_RSSI_INDB_THRESHOLD_EVENT), + DBG_DESC(WMI_SENDING_RSSI_INDBM_THRESHOLD_EVENT), + DBG_DESC(WMI_SENDING_LINK_QUALITY_THRESHOLD_EVENT), + DBG_DESC(WMI_SENDING_ERROR_REPORT_EVENT), + DBG_DESC(WMI_SENDING_CAC_EVENT), + DBG_DESC(WMI_TARGET_GET_ROAM_TABLE_CMD), + DBG_DESC(WMI_TARGET_GET_ROAM_DATA_CMD), + DBG_DESC(WMI_SENDING_GPIO_INTR_EVENT), + DBG_DESC(WMI_SENDING_GPIO_ACK_EVENT), + DBG_DESC(WMI_SENDING_GPIO_DATA_EVENT), + DBG_DESC_FMT(WMI_CMD_RX), + DBG_DESC(WMI_CMD_RX_XTND), + DBG_DESC_FMT(WMI_EVENT_SEND), + DBG_DESC_FMT(WMI_EVENT_SEND_XTND), + DBG_DESC_FMT(WMI_CMD_PARAMS_DUMP_START), + DBG_DESC_FMT(WMI_CMD_PARAMS_DUMP_END), + DBG_DESC_FMT(WMI_CMD_PARAMS), +}; + +static struct dbglog_desc co_desc[] = { + DBG_DESC(0), + DBG_DESC(CO_INIT), + DBG_DESC(CO_ACQUIRE_LOCK), + DBG_DESC(CO_START_OP1), + DBG_DESC(CO_START_OP2), + DBG_DESC(CO_DRAIN_TX_COMPLETE_CB), + DBG_DESC(CO_CHANGE_CHANNEL_CB), + DBG_DESC(CO_RETURN_TO_HOME_CHANNEL), + DBG_DESC(CO_FINISH_OP_TIMEOUT), + DBG_DESC(CO_OP_END), + DBG_DESC(CO_CANCEL_OP), + DBG_DESC_FMT(CO_CHANGE_CHANNEL), + DBG_DESC(CO_RELEASE_LOCK), + DBG_DESC_FMT(CO_CHANGE_STATE), +}; + +static struct dbglog_desc mgmtbuf_desc[] = { + DBG_DESC(0), + DBG_DESC(TXRX_MGMTBUF_ALLOCATE_BUF), + DBG_DESC(TXRX_MGMTBUF_ALLOCATE_SM_BUF), + DBG_DESC(TXRX_MGMTBUF_ALLOCATE_RMBUF), + DBG_DESC(TXRX_MGMTBUF_GET_BUF), + DBG_DESC(TXRX_MGMTBUF_GET_SM_BUF), + DBG_DESC(TXRX_MGMTBUF_QUEUE_BUF_TO_TXQ), + DBG_DESC_FMT(TXRX_MGMTBUF_REAPED_BUF), + DBG_DESC(TXRX_MGMTBUF_REAPED_SM_BUF), + DBG_DESC_FMT(TXRX_MGMTBUF_WAIT_FOR_TXQ_DRAIN), + DBG_DESC(TXRX_MGMTBUF_WAIT_FOR_TXQ_SFQ_DRAIN), + DBG_DESC(TXRX_MGMTBUF_ENQUEUE_INTO_DATA_SFQ), + DBG_DESC(TXRX_MGMTBUF_DEQUEUE_FROM_DATA_SFQ), + DBG_DESC(TXRX_MGMTBUF_PAUSE_DATA_TXQ), + DBG_DESC(TXRX_MGMTBUF_RESUME_DATA_TXQ), + DBG_DESC(TXRX_MGMTBUF_WAIT_FORTXQ_DRAIN_TIMEOUT), + DBG_DESC_FMT(TXRX_MGMTBUF_DRAINQ), + DBG_DESC(TXRX_MGMTBUF_INDICATE_Q_DRAINED), + DBG_DESC(TXRX_MGMTBUF_ENQUEUE_INTO_HW_SFQ), + DBG_DESC(TXRX_MGMTBUF_DEQUEUE_FROM_HW_SFQ), + DBG_DESC(TXRX_MGMTBUF_PAUSE_HW_TXQ), + DBG_DESC(TXRX_MGMTBUF_RESUME_HW_TXQ), + DBG_DESC(TXRX_MGMTBUF_TEAR_DOWN_BA), + DBG_DESC(TXRX_MGMTBUF_PROCESS_ADDBA_REQ), + DBG_DESC(TXRX_MGMTBUF_PROCESS_DELBA), + DBG_DESC(TXRX_MGMTBUF_PERFORM_BA), + DBG_DESC_FMT(TXRX_MGMTBUF_WLAN_RESET_ON_ERROR), +}; + +static struct dbglog_desc dc_desc[] = { + DBG_DESC(0), + DBG_DESC_FMT(DC_SCAN_CHAN_START), + DBG_DESC_FMT(DC_SCAN_CHAN_FINISH), + DBG_DESC(DC_BEACON_RECEIVE7), + DBG_DESC_FMT(DC_SSID_PROBE_CB), + DBG_DESC_FMT(DC_SEND_NEXT_SSID_PROBE), + DBG_DESC_FMT(DC_START_SEARCH), + DBG_DESC(DC_CANCEL_SEARCH_CB), + DBG_DESC(DC_STOP_SEARCH), + DBG_DESC(DC_END_SEARCH), + DBG_DESC(DC_MIN_CHDWELL_TIMEOUT), + DBG_DESC(DC_START_SEARCH_CANCELED), + DBG_DESC_FMT(DC_SET_POWER_MODE), + DBG_DESC(DC_INIT), + DBG_DESC_FMT(DC_SEARCH_OPPORTUNITY), + DBG_DESC_FMT(DC_RECEIVED_ANY_BEACON), + DBG_DESC(DC_RECEIVED_MY_BEACON), + DBG_DESC(DC_PROFILE_IS_ADHOC_BUT_BSS_IS_INFRA), + DBG_DESC(DC_PS_ENABLED_BUT_ATHEROS_IE_ABSENT), + DBG_DESC(DC_BSS_ADHOC_CHANNEL_NOT_ALLOWED), + DBG_DESC(DC_SET_BEACON_UPDATE), + DBG_DESC(DC_BEACON_UPDATE_COMPLETE), + DBG_DESC(DC_END_SEARCH_BEACON_UPDATE_COMP_CB), + DBG_DESC(DC_BSSINFO_EVENT_DROPPED), + DBG_DESC(DC_IEEEPS_ENABLED_BUT_ATIM_ABSENT), +}; + +static struct dbglog_desc btcoex_desc[] = { + DBG_DESC(0), + DBG_DESC(BTCOEX_STATUS_CMD), + DBG_DESC(BTCOEX_PARAMS_CMD), + DBG_DESC(BTCOEX_ANT_CONFIG), + DBG_DESC(BTCOEX_COLOCATED_BT_DEVICE), + DBG_DESC(BTCOEX_CLOSE_RANGE_SCO_ON), + DBG_DESC(BTCOEX_CLOSE_RANGE_SCO_OFF), + DBG_DESC(BTCOEX_CLOSE_RANGE_A2DP_ON), + DBG_DESC(BTCOEX_CLOSE_RANGE_A2DP_OFF), + DBG_DESC(BTCOEX_A2DP_PROTECT_ON), + DBG_DESC(BTCOEX_A2DP_PROTECT_OFF), + DBG_DESC(BTCOEX_SCO_PROTECT_ON), + DBG_DESC(BTCOEX_SCO_PROTECT_OFF), + DBG_DESC(BTCOEX_CLOSE_RANGE_DETECTOR_START), + DBG_DESC(BTCOEX_CLOSE_RANGE_DETECTOR_STOP), + DBG_DESC(BTCOEX_CLOSE_RANGE_TOGGLE), + DBG_DESC(BTCOEX_CLOSE_RANGE_TOGGLE_RSSI_LRCNT), + DBG_DESC(BTCOEX_CLOSE_RANGE_RSSI_THRESH), + DBG_DESC(BTCOEX_CLOSE_RANGE_LOW_RATE_THRESH), + DBG_DESC(BTCOEX_PTA_PRI_INTR_HANDLER), + DBG_DESC_FMT(BTCOEX_PSPOLL_QUEUED), + DBG_DESC_FMT(BTCOEX_PSPOLL_COMPLETE), + DBG_DESC_FMT(BTCOEX_DBG_PM_AWAKE), + DBG_DESC_FMT(BTCOEX_DBG_PM_SLEEP), + DBG_DESC(BTCOEX_DBG_SCO_COEX_ON), + DBG_DESC(BTCOEX_SCO_DATARECEIVE), + DBG_DESC(BTCOEX_INTR_INIT), + DBG_DESC(BTCOEX_PTA_PRI_DIFF), + DBG_DESC_FMT(BTCOEX_TIM_NOTIFICATION), + DBG_DESC(BTCOEX_SCO_WAKEUP_ON_DATA), + DBG_DESC(BTCOEX_SCO_SLEEP), + DBG_DESC_FMT(BTCOEX_SET_WEIGHTS), + DBG_DESC(BTCOEX_SCO_DATARECEIVE_LATENCY_VAL), + DBG_DESC(BTCOEX_SCO_MEASURE_TIME_DIFF), + DBG_DESC(BTCOEX_SET_EOL_VAL), + DBG_DESC(BTCOEX_OPT_DETECT_HANDLER), + DBG_DESC(BTCOEX_SCO_TOGGLE_STATE), + DBG_DESC(BTCOEX_SCO_STOMP), + DBG_DESC(BTCOEX_NULL_COMP_CALLBACK), + DBG_DESC(BTCOEX_RX_INCOMING), + DBG_DESC(BTCOEX_RX_INCOMING_CTL), + DBG_DESC(BTCOEX_RX_INCOMING_MGMT), + DBG_DESC(BTCOEX_RX_INCOMING_DATA), + DBG_DESC(BTCOEX_RTS_RECEPTION), + DBG_DESC(BTCOEX_FRAME_PRI_LOW_RATE_THRES), + DBG_DESC_FMT(BTCOEX_PM_FAKE_SLEEP), + DBG_DESC_FMT(BTCOEX_ACL_COEX_STATUS), + DBG_DESC(BTCOEX_ACL_COEX_DETECTION), + DBG_DESC(BTCOEX_A2DP_COEX_STATUS), + DBG_DESC(BTCOEX_SCO_STATUS), + DBG_DESC_FMT(BTCOEX_WAKEUP_ON_DATA), + DBG_DESC(BTCOEX_DATARECEIVE), + DBG_DESC(0), + DBG_DESC(BTCOEX_GET_MAX_AGGR_SIZE), + DBG_DESC(BTCOEX_MAX_AGGR_AVAIL_TIME), + DBG_DESC(BTCOEX_DBG_WBTIMER_INTR), + DBG_DESC(0), + DBG_DESC(BTCOEX_DBG_SCO_SYNC), + DBG_DESC(0), + DBG_DESC(BTCOEX_UPLINK_QUEUED_RATE), + DBG_DESC(BTCOEX_DBG_UPLINK_ENABLE_EOL), + DBG_DESC(BTCOEX_UPLINK_FRAME_DURATION), + DBG_DESC(BTCOEX_UPLINK_SET_EOL), + DBG_DESC(BTCOEX_DBG_EOL_EXPIRED), + DBG_DESC(BTCOEX_DBG_DATA_COMPLETE), + DBG_DESC(BTCOEX_UPLINK_QUEUED_TIMESTAMP), + DBG_DESC(BTCOEX_DBG_DATA_COMPLETE_TIME), + DBG_DESC(BTCOEX_DBG_A2DP_ROLE_IS_SLAVE), + DBG_DESC(BTCOEX_DBG_A2DP_ROLE_IS_MASTER), + DBG_DESC(BTCOEX_DBG_UPLINK_SEQ_NUM), + DBG_DESC(BTCOEX_UPLINK_AGGR_SEQ), + DBG_DESC(BTCOEX_DBG_TX_COMP_SEQ_NO), + DBG_DESC(BTCOEX_DBG_MAX_AGGR_PAUSE_STATE), + DBG_DESC(BTCOEX_DBG_ACL_TRAFFIC), + DBG_DESC(BTCOEX_CURR_AGGR_PROP), + DBG_DESC(BTCOEX_DBG_SCO_GET_PER_TIME_DIFF), + DBG_DESC(BTCOEX_PSPOLL_PROCESS), + DBG_DESC(BTCOEX_RETURN_FROM_MAC), + DBG_DESC(BTCOEX_FREED_REQUEUED_CNT), + DBG_DESC(BTCOEX_DBG_TOGGLE_LOW_RATES), + DBG_DESC(BTCOEX_MAC_GOES_TO_SLEEP), + DBG_DESC(BTCOEX_DBG_A2DP_NO_SYNC), + DBG_DESC(BTCOEX_RETURN_FROM_MAC_HOLD_Q_INFO), + DBG_DESC(BTCOEX_RETURN_FROM_MAC_AC), + DBG_DESC(BTCOEX_DBG_DTIM_RECV), + DBG_DESC(0), + DBG_DESC(BTCOEX_IS_PRE_UPDATE), + DBG_DESC(BTCOEX_ENQUEUED_BIT_MAP), + DBG_DESC(BTCOEX_TX_COMPLETE_FIRST_DESC_STATS), + DBG_DESC(BTCOEX_UPLINK_DESC), + DBG_DESC(BTCOEX_SCO_GET_PER_FIRST_FRM_TIMESTAMP), + DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), + DBG_DESC(BTCOEX_DBG_RECV_ACK), + DBG_DESC(BTCOEX_DBG_ADDBA_INDICATION), + DBG_DESC(BTCOEX_TX_COMPLETE_EOL_FAILED), + DBG_DESC(BTCOEX_DBG_A2DP_USAGE_COMPLETE), + DBG_DESC(BTCOEX_DBG_A2DP_STOMP_FOR_BCN_HANDLER), + DBG_DESC(BTCOEX_DBG_A2DP_SYNC_INTR), + DBG_DESC(BTCOEX_DBG_A2DP_STOMP_FOR_BCN_RECEPTION), + DBG_DESC(BTCOEX_FORM_AGGR_CURR_AGGR), + DBG_DESC(BTCOEX_DBG_TOGGLE_A2DP_BURST_CNT), + DBG_DESC(BTCOEX_DBG_BT_TRAFFIC), + DBG_DESC(BTCOEX_DBG_STOMP_BT_TRAFFIC), + DBG_DESC(BTCOEX_RECV_NULL), + DBG_DESC(BTCOEX_DBG_A2DP_MASTER_BT_END), + DBG_DESC(BTCOEX_DBG_A2DP_BT_START), + DBG_DESC(BTCOEX_DBG_A2DP_SLAVE_BT_END), + DBG_DESC(BTCOEX_DBG_A2DP_STOMP_BT), + DBG_DESC_FMT(BTCOEX_DBG_GO_TO_SLEEP), + DBG_DESC(BTCOEX_DBG_A2DP_PKT), + DBG_DESC(BTCOEX_DBG_A2DP_PSPOLL_DATA_RECV), + DBG_DESC(BTCOEX_DBG_A2DP_NULL), + DBG_DESC(BTCOEX_DBG_UPLINK_DATA), + DBG_DESC(BTCOEX_DBG_A2DP_STOMP_LOW_PRIO_NULL), + DBG_DESC(BTCOEX_DBG_ADD_BA_RESP_TIMEOUT), + DBG_DESC(BTCOEX_DBG_TXQ_STATE), + DBG_DESC_FMT(BTCOEX_DBG_ALLOW_SCAN), + DBG_DESC_FMT(BTCOEX_DBG_SCAN_REQUEST), + DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), + DBG_DESC(BTCOEX_A2DP_SLEEP), + DBG_DESC(BTCOEX_DBG_DATA_ACTIV_TIMEOUT), + DBG_DESC(BTCOEX_DBG_SWITCH_TO_PSPOLL_ON_MODE), + DBG_DESC(BTCOEX_DBG_SWITCH_TO_PSPOLL_OFF_MODE), + DBG_DESC(BTCOEX_DATARECEIVE_AGGR), + DBG_DESC(BTCOEX_DBG_DATA_RECV_SLEEPING_PENDING), + DBG_DESC(BTCOEX_DBG_DATARESP_TIMEOUT), + DBG_DESC(BTCOEX_BDG_BMISS), + DBG_DESC(BTCOEX_DBG_DATA_RECV_WAKEUP_TIM), + DBG_DESC(BTCOEX_DBG_SECOND_BMISS), + DBG_DESC(0), + DBG_DESC_FMT(BTCOEX_DBG_SET_WLAN_STATE), + DBG_DESC(BTCOEX_BDG_FIRST_BMISS), + DBG_DESC(BTCOEX_DBG_A2DP_CHAN_OP), + DBG_DESC(BTCOEX_DBG_A2DP_INTR), + DBG_DESC_FMT(BTCOEX_DBG_BT_INQUIRY), + DBG_DESC(BTCOEX_DBG_BT_INQUIRY_DATA_FETCH), + DBG_DESC(BTCOEX_DBG_POST_INQUIRY_FINISH), + DBG_DESC(BTCOEX_DBG_SCO_OPT_MODE_TIMER_HANDLER), + DBG_DESC(BTCOEX_DBG_NULL_FRAME_SLEEP), + DBG_DESC(BTCOEX_DBG_NULL_FRAME_AWAKE), + DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), DBG_DESC(0), + DBG_DESC(BTCOEX_DBG_SET_AGGR_SIZE), + DBG_DESC(BTCOEX_DBG_TEAR_BA_TIMEOUT), + DBG_DESC(BTCOEX_DBG_MGMT_FRAME_SEQ_NO), + DBG_DESC(BTCOEX_DBG_SCO_STOMP_HIGH_PRI), + DBG_DESC(BTCOEX_DBG_COLOCATED_BT_DEV), + DBG_DESC(BTCOEX_DBG_FE_ANT_TYPE), + DBG_DESC(BTCOEX_DBG_BT_INQUIRY_CMD), + DBG_DESC(BTCOEX_DBG_SCO_CONFIG), + DBG_DESC(BTCOEX_DBG_SCO_PSPOLL_CONFIG), + DBG_DESC(BTCOEX_DBG_SCO_OPTMODE_CONFIG), + DBG_DESC(BTCOEX_DBG_A2DP_CONFIG), + DBG_DESC(BTCOEX_DBG_A2DP_PSPOLL_CONFIG), + DBG_DESC(BTCOEX_DBG_A2DP_OPTMODE_CONFIG), + DBG_DESC(BTCOEX_DBG_ACLCOEX_CONFIG), + DBG_DESC(BTCOEX_DBG_ACLCOEX_PSPOLL_CONFIG), + DBG_DESC(BTCOEX_DBG_ACLCOEX_OPTMODE_CONFIG), + DBG_DESC(BTCOEX_DBG_DEBUG_CMD), + DBG_DESC(BTCOEX_DBG_SET_BT_OPERATING_STATUS), + DBG_DESC(BTCOEX_DBG_GET_CONFIG), + DBG_DESC(BTCOEX_DBG_GET_STATS), + DBG_DESC(BTCOEX_DBG_BT_OPERATING_STATUS), + DBG_DESC(BTCOEX_DBG_PERFORM_RECONNECT), + DBG_DESC(0), + DBG_DESC(BTCOEX_DBG_ACL_WLAN_MED), + DBG_DESC(BTCOEX_DBG_ACL_BT_MED), + DBG_DESC(BTCOEX_DBG_WLAN_CONNECT), + DBG_DESC(BTCOEX_DBG_A2DP_DUAL_START), + DBG_DESC(BTCOEX_DBG_PMAWAKE_NOTIFY), + DBG_DESC(BTCOEX_DBG_BEACON_SCAN_ENABLE), + DBG_DESC(BTCOEX_DBG_BEACON_SCAN_DISABLE), + DBG_DESC(BTCOEX_DBG_RX_NOTIFY), + DBG_DESC(BTCOEX_SCO_GET_PER_SECOND_FRM_TIMESTAMP), + DBG_DESC(BTCOEX_DBG_TXQ_DETAILS), + DBG_DESC(BTCOEX_DBG_SCO_STOMP_LOW_PRI), + DBG_DESC(BTCOEX_DBG_A2DP_FORCE_SCAN), + DBG_DESC(BTCOEX_DBG_DTIM_STOMP_COMP), + DBG_DESC(BTCOEX_ACL_PRESENCE_TIMER), + DBG_DESC(BTCOEX_DBG_QUEUE_SELF_CTS), + DBG_DESC(BTCOEX_DBG_SELF_CTS_COMP), + DBG_DESC(BTCOEX_DBG_APMODE_WAIT_FOR_CTS_COMP_FAILED), + DBG_DESC(BTCOEX_DBG_APMODE_A2DP_MED_TO_BT), + DBG_DESC(BTCOEX_DBG_APMODE_SET_BTSTATE), + DBG_DESC(BTCOEX_DBG_APMODE_A2DP_STATUS), + DBG_DESC(BTCOEX_DBG_APMODE_SCO_CTS_HANDLER), + DBG_DESC(BTCOEX_DBG_APMODE_SCO_STATUS), + DBG_DESC(BTCOEX_DBG_APMODE_TXQ_DRAINED), + DBG_DESC(BTCOEX_DBG_APMODE_SCO_ARM_TIMER), + DBG_DESC(BTCOEX_DBG_APMODE_SWITCH_MED_TO_WLAN), + DBG_DESC(BTCOEX_APMODE_BCN_TX_HANDLER), + DBG_DESC(BTCOEX_APMODE_BCN_TX), + DBG_DESC(BTCOEX_APMODE_SCO_RTS_HANDLER), +}; + +static struct dbglog_desc pm_desc[] = { + DBG_DESC(0), + DBG_DESC(PM_INIT), + DBG_DESC(PM_ENABLE), + DBG_DESC_FMT(PM_SET_STATE), + DBG_DESC_FMT(PM_SET_POWERMODE), + DBG_DESC(PM_CONN_NOTIFY), + DBG_DESC(PM_REF_COUNT_NEGATIVE), + DBG_DESC(PM_INFRA_STA_APSD_ENABLE), + DBG_DESC(PM_INFRA_STA_UPDATE_APSD_STATE), + DBG_DESC_FMT(PM_CHAN_OP_REQ), + DBG_DESC_FMT(PM_SET_MY_BEACON_POLICY), + DBG_DESC_FMT(PM_SET_ALL_BEACON_POLICY), + DBG_DESC(PM_INFRA_STA_SET_PM_PARAMS1), + DBG_DESC(PM_INFRA_STA_SET_PM_PARAMS2), + DBG_DESC(PM_ADHOC_SET_PM_CAPS_FAIL), + DBG_DESC(PM_ADHOC_UNKNOWN_IBSS_ATTRIB_ID), + DBG_DESC(PM_ADHOC_SET_PM_PARAMS), + DBG_DESC(0), + DBG_DESC(PM_ADHOC_STATE1), + DBG_DESC(PM_ADHOC_STATE2), + DBG_DESC(PM_ADHOC_CONN_MAP), + DBG_DESC_FMT(PM_FAKE_SLEEP), + DBG_DESC(PM_AP_STATE1), + DBG_DESC(PM_AP_SET_PM_PARAMS), + DBG_DESC(PM_P2P_STATE1), +}; + +static struct dbglog_desc dummy_desc[] = { + DBG_DESC(0), +}; + +static struct module_desc modules[] = { + MODULE_DESC(INF, dummy_desc), + MODULE_DESC(WMI, wmi_desc), + MODULE_DESC(MISC, dummy_desc), + MODULE_DESC(PM, pm_desc), + MODULE_DESC(TXRX_MGMTBUF, mgmtbuf_desc), + MODULE_DESC(TXRX_TXBUF, dummy_desc), + MODULE_DESC(TXRX_RXBUF, dummy_desc), + MODULE_DESC(WOW, dummy_desc), + MODULE_DESC(WHAL, dummy_desc), + MODULE_DESC(DC, dc_desc), + MODULE_DESC(CO, co_desc), + MODULE_DESC(RO, dummy_desc), + MODULE_DESC(CM, dummy_desc), + MODULE_DESC(MGMT, dummy_desc), + MODULE_DESC(TMR, dummy_desc), + MODULE_DESC(BTCOEX, btcoex_desc), +}; + +static int compOid(const void *a, const void *b) +{ + return *(A_INT32*)a - *(A_INT32*)b; +} + +static void do_check_ids() +{ + size_t m, d, td; + for (m=0; dbglog_id_tag[m][1][0]!='\0'; ++m) { + size_t mlen; + struct dbglog_desc *dlog; + if (m >= ARRAY_SIZE(modules)) { + printf("module does not matched\n"); + break; + } + dlog = modules[m].descs; + mlen = modules[m].len; + d=td=1; + while (dlog && (d=mlen) { + if (dlog != dummy_desc) { + printf("m %s dbgid %s(%d) is larger than max internal table %d host/firmware mismatch?\n", + modules[m].name, dbglog_id_tag[m][td], td, mlen); + } + break; + } + + if (dbglog_id_tag[m][td][0]=='\0' && dlog[d].oid!=0) { + for (;td < DBGLOG_DBGID_NUM_MAX && dbglog_id_tag[m][td][0]=='\0'; ++td); + } + if (strcmp(dbglog_id_tag[m][td], dlog[d].desc)!=0 && dlog[d].oid!=0) { + printf("debug id does not matched '%s' <> '%s'\n", dbglog_id_tag[m][td], dlog[d].desc); + break; + } else { + if (td!=d && !modules[m].bsearch) { + printf("Module %s debugid %s(%d) mismatched. using binary search for debugid", + modules[m].name, dbglog_id_tag[m][td], td); + modules[m].bsearch = 1; + } + } + ++d; ++td; + } + if (modules[m].bsearch && dlog) { + qsort(dlog, mlen, sizeof(dlog[0]), compOid); + } + } + check_ids = 1; +} + +static DbgLogFormatter getFormatter(A_INT32 moduleid, A_INT32 debugid) +{ + if (!check_ids) { + do_check_ids(); + } + + if ( moduleid < ARRAY_SIZE(modules)) { + const struct module_desc *m = &modules[moduleid]; + if (m->descs ) { + if (m->bsearch){ + struct dbglog_desc *d; + d = (struct dbglog_desc*)bsearch(&debugid, m->descs, m->len, sizeof(m->descs[0]), compOid); + return d ? d->formatter : NULL; + } else if (debugid>0 && debugidlen) { + return m->descs[debugid].formatter; + } + } + } + return NULL; +} + +int dbg_formater(int lv, char *output, size_t len, A_UINT32 ts, A_INT32 *logbuf) +{ + int ret = 0; + A_UINT32 debugid = DBGLOG_GET_DBGID(logbuf[0]); + A_UINT32 moduleid = DBGLOG_GET_MODULEID(logbuf[0]); + A_UINT32 numargs = DBGLOG_GET_NUMARGS(logbuf[0]); + A_UINT32 timestamp = DBGLOG_GET_TIMESTAMP(logbuf[0]); + DbgLogFormatter dbgFormatter = NULL; + + if (numargs>2) { + return ret; + } + + if (lv > 0) { + dbgFormatter = getFormatter(moduleid, debugid); + } + + if (ts>0) { + if (lv == 0) { + ret += snprintf(output+ret, len-ret, "%8d: ", ts); + } else { + ret += strftime(output+ret, len-ret, "%m-%d %H:%M:%S ", gmtime((time_t*)&ts)); + } + } + ret += snprintf(output+ret, len-ret, "%s (%d)", dbglog_id_tag[moduleid][debugid], + timestamp); + if (lv>1 || lv == 0 || !dbgFormatter) { + if (numargs>0) { + ret += snprintf(output+ret, len-ret, ": 0x%x", logbuf[1]); + } + if (numargs>1) { + ret += snprintf(output+ret, len-ret, ", 0x%x", logbuf[2]); + } + if (dbgFormatter && numargs>0 && lv > 0) { + ret += snprintf(output+ret, len-ret, ", "); + } + } else { + ret += snprintf(output+ret, len-ret, ": "); + } + + if (dbgFormatter && lv > 0) { + int pos = ret; + int addlen; + addlen = dbgFormatter(output+ret, len-ret, numargs, logbuf); + if (addlen>0) { + ret += addlen; + } else if (lv<=1) { + /* skip this message */ + (void)pos; + return 0; + } + } + ret += snprintf(output+ret, len-ret, "\n"); + return ret; +} + diff --git a/drivers/net/wireless/ar6003/host/tools/recEvent/recEvent.c b/drivers/net/wireless/ar6003/host/tools/recEvent/recEvent.c new file mode 100644 index 000000000000..161b7453e852 --- /dev/null +++ b/drivers/net/wireless/ar6003/host/tools/recEvent/recEvent.c @@ -0,0 +1,950 @@ +/* + * Copyright (c) 2006 Atheros Communications Inc. + * All rights reserved. + * + * + * +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +extern char *if_indextoname (unsigned int __ifindex, char *__ifname); +#include +#ifdef ANDROID +#include "wireless_copy.h" +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#undef DEBUG +#undef DBGLOG_DEBUG + +#define ID_LEN 2 +#define DBGLOG_FILE "dbglog.h" +#define DBGLOGID_FILE "dbglog_id.h" + +#define GET_CURRENT_TIME(s) do { \ + time_t t; \ + t = time(NULL); \ + s = strtok(ctime(&t), "\n"); \ +} while (0); + +#ifdef ANDROID +#define DEBUG 1 +#include +#endif + + +#define AR6K_DBG_BUFFER_SIZE 256 + +struct dbg_binary_header { + A_UINT8 sig; + A_UINT8 ver; + A_UINT16 len; + A_UINT32 reserved; +}; + +struct dbg_binary_record { + A_UINT32 ts; /* Timestamp of the log */ + A_UINT32 length; /* Length of the log */ + A_UINT8 log[AR6K_DBG_BUFFER_SIZE]; /* log message */ +}; + +static int ATH_WE_VERSION = 0; + +#define SRCDIR_FLAG 0x01 +#define LOGFILE_FLAG 0x02 +#define DBGREC_LIMIT_FLAG 0x04 +#define RESTORE_FLAG 0x08 +#define BINARY_FLAG 0x10 + +const char *progname; +char restorefile[PATH_MAX]; +char dbglogfile[PATH_MAX]; +char dbglogidfile[PATH_MAX]; +char dbglogoutfile[PATH_MAX]; +FILE *fpout; +int dbgRecLimit = 1000000; /* Million records is a good default */ +int optionflag; +char dbglog_id_tag[DBGLOG_MODULEID_NUM_MAX][DBGLOG_DBGID_NUM_MAX][DBGLOG_DBGID_DEFINITION_LEN_MAX]; +const char options[] = +"Options:\n\ +-f, --logfile= [Mandatory]\n\ +-g, --debug (-gg to print out dbglog info together) [Optional]\n\ +-b, --binary\n\ +-d, --srcdir= [Mandatory if not binary]\n\ +-l, --reclimit= [Optional]\n\ +-r, --restore=