[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/connectivity/wifitesttool/LICENSE b/src/connectivity/wifitesttool/LICENSE
new file mode 100644
index 0000000..77f59ed
--- /dev/null
+++ b/src/connectivity/wifitesttool/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MediaTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+the prior written permission of MediaTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MediaTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MediaTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
diff --git a/src/connectivity/wifitesttool/Makefile.am b/src/connectivity/wifitesttool/Makefile.am
new file mode 100644
index 0000000..5775c48
--- /dev/null
+++ b/src/connectivity/wifitesttool/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = libwifitest wifi_hw_test_tool
diff --git a/src/connectivity/wifitesttool/configure.ac b/src/connectivity/wifitesttool/configure.ac
new file mode 100644
index 0000000..1a5116c
--- /dev/null
+++ b/src/connectivity/wifitesttool/configure.ac
@@ -0,0 +1,37 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([wifihwtesttool], [1.0])
+AM_INIT_AUTOMAKE([foreign])
+
+AC_CONFIG_SRCDIR([wifi_hw_test_tool/lib.h])
+AC_CONFIG_HEADERS([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_RANLIB
+
+# Checks for libraries.
+# FIXME: Replace `main' with a function in `-lm':
+AC_CHECK_LIB([m], [main])
+# FIXME: Replace `main' with a function in `-lwifitest':
+AC_CHECK_LIB([wifitest], [main])
+
+# Checks for header files.
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_CHECK_HEADER_STDBOOL
+AC_C_INLINE
+AC_TYPE_SIZE_T
+AC_TYPE_UINT32_T
+AC_TYPE_UINT8_T
+
+# Checks for library functions.
+AC_CHECK_FUNCS([memset socket strerror strrchr])
+
+AC_CONFIG_FILES([Makefile
+                 libwifitest/Makefile
+                 wifi_hw_test_tool/Makefile])
+AC_OUTPUT
diff --git a/src/connectivity/wifitesttool/libwifitest/Android.mk b/src/connectivity/wifitesttool/libwifitest/Android.mk
new file mode 100644
index 0000000..dc53786
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/Android.mk
@@ -0,0 +1,32 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_SHARED_LIBRARIES := libcutils libnvram
+# LOCAL_STATIC_LIBRARIES := libiw
+# LOCAL_MODULE_TAGS := optional
+LOCAL_SRC_FILES := libwifitest.c
+
+LOCAL_C_INCLUDES := \
+ $(MTK_PATH_SOURCE)/external/nvram/libnvram \
+ $(MTK_PATH_CUSTOM)/cgen/cfgfileinc \
+ $(MTK_PATH_CUSTOM)/cgen/cfgdefault \
+ $(MTK_PATH_CUSTOM)/cgen/inc
+
+#LOCAL_CFLAGS += -Wall -Werror
+LOCAL_PRELINK_MODULE := false
+LOCAL_MODULE := libwifitest
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_SHARED_LIBRARY)
+
+BUILD_TEST_APP = false
+ifeq ($(BUILD_TEST_APP),true)
+  include $(CLEAR_VARS)
+  LOCAL_SHARED_LIBRARIES := libnvram libcutils libwifitest
+# LOCAL_STATIC_LIBRARIES := libiw
+  LOCAL_MODULE_TAGS := eng
+  LOCAL_SRC_FILES := main.c
+  LOCAL_CFLAGS += -Wall -Werror
+  LOCAL_MODULE := wifitest
+  LOCAL_MODULE_TAGS := optional
+  include $(BUILD_EXECUTABLE)
+endif
+
diff --git a/src/connectivity/wifitesttool/libwifitest/Makefile.am b/src/connectivity/wifitesttool/libwifitest/Makefile.am
new file mode 100644
index 0000000..490970b
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/Makefile.am
@@ -0,0 +1,4 @@
+lib_LIBRARIES = libwifitest.a
+AM_CFLAGS = -I./
+
+libwifitest_a_SOURCES = libwifitest.c
diff --git a/src/connectivity/wifitesttool/libwifitest/README b/src/connectivity/wifitesttool/libwifitest/README
new file mode 100644
index 0000000..f0ddfe0
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/README
@@ -0,0 +1,33 @@
+This directory contains WIFI libwifitest.so library
+
+
+WHAT IT DOES?
+=============
+It provide WIFI LGE feature, which allow read and write WIFI items by AT command.
+
+
+HOW IT WAS BUILT?
+==================
+It needs the following libs from AOSP:
+1.  libc.so
+
+and the following libs from MediaTek:
+1. libnvram.so
+
+
+All source/dependency modules of this module are already put in
+'hardware/mediatek/wlan/libwifitest' 'vendor/mediatek/proprietary/external/atcid' folder.
+
+
+HOW TO USE IT?
+==============
+Files in this directory is used to generate a library which's name is 'libwifitest.so'
+
+
+WIFI Tool
+The lib  'libwifitest.so' is loaded when SP LGE MTK_TC1_FEATURE macro enabled,
+all WIFI opertations will call LGE_RFT_xxx API, then it calls IOCtl to access WIFI driver data.
+
+
+All the source code of this library were written by MediaTek co..
+
diff --git a/src/connectivity/wifitesttool/libwifitest/libwifitest.c b/src/connectivity/wifitesttool/libwifitest/libwifitest.c
new file mode 100644
index 0000000..3b1036a
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/libwifitest.c
@@ -0,0 +1,2488 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+ * the prior written permission of MediaTek inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of MediaTek Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+ * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+ * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek
+ * Software") have been modified by MediaTek Inc. All revisions are subject to
+ * any receiver's applicable license agreements with MediaTek Inc.
+ */
+
+/*
+ * This is sample code for WLAN test library implementation
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sched.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifndef __linux__
+#include <net/if.h>
+#endif
+#include <arpa/inet.h>
+
+#ifdef ANDROID
+#include <cutils/log.h>
+#include <cutils/misc.h> /* load_file() */
+#include <libnvram.h>
+#include <Custom_NvRam_LID.h>
+#include <CFG_Wifi_File.h>
+#endif
+
+#include "libwifitest.h"
+
+#define DBG 1
+
+extern int init_module(void *, unsigned long, const char *);
+
+/*******************************************************************************
+ *                                 M A C R O S
+ *******************************************************************************
+ */
+
+#ifndef BIT
+#define BIT(n)          ((uint32_t) 1 << (n))
+#define BITS(m,n)       (~(BIT(m)-1) & ((BIT(n) - 1) | BIT(n)))
+#endif /* BIT */
+
+#define MAC_ADDR_LEN                            6
+
+#define IS_BMCAST_MAC_ADDR(_pucDestAddr)            \
+        ((bool) ( ((uint8_t *)(_pucDestAddr))[0] & BIT(0) ))
+
+#define EQUAL_MAC_ADDR(_pucDestAddr, _pucSrcAddr)   \
+        (!memcmp(_pucDestAddr, _pucSrcAddr, MAC_ADDR_LEN))
+
+/* Debug print format string for the MAC Address */
+#define MACSTR      "%02x:%02x:%02x:%02x:%02x:%02x"
+
+/* Debug print argument for the MAC Address */
+#define MAC2STR(a)  ((uint8_t *)a)[0], ((uint8_t *)a)[1], ((uint8_t *)a)[2], \
+    ((uint8_t *)a)[3], ((uint8_t *)a)[4], ((uint8_t *)a)[5]
+
+/*******************************************************************************
+ *                              C O N S T A N T S
+ *******************************************************************************
+ */
+
+#ifndef WIFI_DRIVER_MODULE_PATH
+#define WIFI_DRIVER_MODULE_PATH     "/system/lib/modules/wlan.ko"
+#endif
+#ifndef WIFI_DRIVER_MODULE_NAME
+#define WIFI_DRIVER_MODULE_NAME     "wlan"
+#endif
+#ifndef WIFI_DRIVER_MODULE_ARG
+#define WIFI_DRIVER_MODULE_ARG      ""
+#endif
+
+#if 0
+#ifndef WIFI_IF_NAME
+#define WIFI_IF_NAME                "wlan0"
+#endif
+#endif
+
+char WIFI_IF_NAME[256] = "wlan0";
+bool fgDebugMode = false;
+
+static const char DRIVER_PROP_NAME[]    = "wlan.driver.status";
+static const char DRIVER_MODULE_NAME[]  = WIFI_DRIVER_MODULE_NAME;
+//static const char DRIVER_MODULE_TAG[]   = WIFI_DRIVER_MODULE_NAME " ";
+static const char DRIVER_MODULE_TAG[]   = WIFI_DRIVER_MODULE_NAME;
+static const char DRIVER_MODULE_PATH[]  = WIFI_DRIVER_MODULE_PATH;
+static const char DRIVER_MODULE_ARG[]   = WIFI_DRIVER_MODULE_ARG;
+static const char MODULE_FILE[]         = "/proc/modules";
+
+#define IOCTL_SET_STRUCT                (SIOCIWFIRSTPRIV + 8)
+#define IOCTL_GET_STRUCT                (SIOCIWFIRSTPRIV + 9)
+#define IOCTL_SET_STRUCT_FOR_EM         (SIOCIWFIRSTPRIV + 11)
+
+#define PRIV_CMD_OID                    15
+
+/* RF Test specific OIDs */
+#define OID_CUSTOM_TEST_MODE                            0xFFA0C901
+#define OID_CUSTOM_ABORT_TEST_MODE                      0xFFA0C906
+#define OID_CUSTOM_MTK_WIFI_TEST_                       0xFFA0C911
+#define OID_CUSTOM_MCR_RW                               0xFFA0c801
+
+/* command mask */
+#define TEST_FUNC_IDX_MASK              BITS(0,7)
+#define TEST_SET_CMD_OFFSET_MASK        BITS(16,31)
+#define TEST_SET_CMD_OFFSET             16
+
+/* RF Test Properties */
+#define RF_AT_PARAM_RATE_MCS_MASK   BIT(31)
+#define RF_AT_PARAM_RATE_MASK       BITS(0,7)
+#define RF_AT_PARAM_RATE_1M         0
+#define RF_AT_PARAM_RATE_2M         1
+#define RF_AT_PARAM_RATE_5_5M       2
+#define RF_AT_PARAM_RATE_11M        3
+#define RF_AT_PARAM_RATE_6M         4
+#define RF_AT_PARAM_RATE_9M         5
+#define RF_AT_PARAM_RATE_12M        6
+#define RF_AT_PARAM_RATE_18M        7
+#define RF_AT_PARAM_RATE_24M        8
+#define RF_AT_PARAM_RATE_36M        9
+#define RF_AT_PARAM_RATE_48M        10
+#define RF_AT_PARAM_RATE_54M        11
+
+#define NULL_MAC_ADDR               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+
+#ifndef ALOGD
+#define ALOGD printf
+#endif
+#ifndef ALOGE
+#define ALOGE printf
+#endif
+#ifndef ALOGW
+#define ALOGW
+#endif
+
+/*******************************************************************************
+ *                             D A T A   T Y P E S
+ *******************************************************************************
+ */
+typedef struct _NDIS_TRANSPORT_STRUCT {
+    uint32_t    ndisOidCmd;
+    uint32_t    inNdisOidlength;
+    uint32_t    outNdisOidLength;
+    uint8_t     ndisOidContent[16];
+} NDIS_TRANSPORT_STRUCT, *P_NDIS_TRANSPORT_STRUCT;
+
+typedef struct _PARAM_MTK_WIFI_TEST_STRUC_T {
+    uint32_t u4FuncIndex;
+    uint32_t u4FuncData;
+} PARAM_MTK_WIFI_TEST_STRUC_T, *P_PARAM_MTK_WIFI_TEST_STRUC_T;
+
+typedef struct _PARAM_CUSTOM_MCR_RW_STRUC_T {
+    uint32_t    u4McrOffset;
+    uint32_t    u4McrData;
+} PARAM_CUSTOM_MCR_RW_STRUC_T, *P_PARAM_CUSTOM_MCR_RW_STRUC_T;
+
+typedef enum _ENUM_RF_AT_BW_T {
+
+    RF_AT_BW_20 = 0,
+    RF_AT_BW_40,
+    RF_AT_BW_U20,
+    RF_AT_BW_L20,
+    RF_AT_BW_NUM
+
+} ENUM_RF_AT_BW_T, *P_ENUM_RF_AT_BW_T;
+
+typedef enum _ENUM_RF_AT_RXOK_MATCH_RULE_T {
+
+    RF_AT_RXOK_DISABLED = 0,
+    RF_AT_RXOK_MATCH_RA_ONLY,
+    RF_AT_RXOK_MATCH_TA_ONLY,
+    RF_AT_RXOK_MATCH_RA_TA,
+    RF_AT_RXOK_NUM
+
+} ENUM_RF_AT_RXOK_MATCH_RULE_T, *P_ENUM_RF_AT_RXOK_MATCH_RULE_T;
+
+
+
+/*******************************************************************************
+ *                           P R I V A T E   D A T A
+ *******************************************************************************
+ */
+//static int wifi_rfkill_id = -1;
+//static char *wifi_rfkill_state_path = NULL;
+static int skfd = -1;
+static bool fgIsTesting = false;
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is called to initial rfkill variables
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+#if 0
+static int
+wifi_init_rfkill(
+    void
+    )
+{
+    char path[64];
+    char buf[16];
+    int fd;
+    int sz;
+    int id;
+
+    for (id = 0; ; id++) {
+        snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id);
+        fd = open(path, O_RDONLY);
+        if (fd < 0) {
+            ALOGW("[%s] open(%s) failed: %s (%d)\n", __func__, path, strerror(errno), errno);
+            return -1;
+        }
+        sz = read(fd, &buf, sizeof(buf));
+        close(fd);
+        if (sz >= 4 && memcmp(buf, "wlan", 4) == 0) {
+            wifi_rfkill_id = id;
+            break;
+        }
+    }
+
+    asprintf(&wifi_rfkill_state_path, "/sys/class/rfkill/rfkill%d/state",
+            wifi_rfkill_id);
+    return 0;
+}
+#endif
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is called to turn on/off Wi-Fi interface
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+#if 0
+static int
+wifi_set_power(
+    int on
+    )
+{
+    int sz;
+    int fd = -1;
+    int ret = -1;
+    const char buffer = (on ? '1' : '0');
+
+    ALOGD("[%s] %d", __func__, on);
+
+    if (wifi_rfkill_id == -1) {
+        if (wifi_init_rfkill()) {
+            goto out;
+        }
+    }
+
+    fd = open(wifi_rfkill_state_path, O_WRONLY);
+    ALOGD("[%s] %s", __func__, wifi_rfkill_state_path);
+    if (fd < 0) {
+        ALOGE("open(%s) for write failed: %s (%d)",
+                wifi_rfkill_state_path,
+                strerror(errno),
+                errno);
+        goto out;
+    }
+    sz = write(fd, &buffer, 1);
+    if (sz < 0) {
+        ALOGE("write(%s) failed: %s (%d)",
+                wifi_rfkill_state_path,
+                strerror(errno),
+                errno);
+        goto out;
+    }
+    ret = 0;
+
+out:
+    if (fd >= 0) {
+        close(fd);
+    }
+    return ret;
+}
+#else
+#define WIFI_POWER_PATH                 "/dev/wmtWifi"
+
+int wifi_set_power(int enable) {
+    int sz;
+    int fd = -1;
+    const char buffer = (enable ? '1' : '0');
+
+    fd = open(WIFI_POWER_PATH, O_WRONLY);
+    if (fd < 0) {
+        ALOGE("Open \"%s\" failed", WIFI_POWER_PATH);
+        goto out;
+    }
+    sz = write(fd, &buffer, 1);
+    if (sz < 0) {
+        ALOGE("Set \"%s\" [%c] failed", WIFI_POWER_PATH, buffer);
+        goto out;
+    }
+
+out:
+    if (fd >= 0) close(fd);
+    return 0;
+}
+
+#endif
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is to insert module
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static int
+insmod(
+    const char *filename,
+    const char *args
+    )
+{
+#if 1
+	ALOGE("%s not supported\n", __func__);
+	return -1;
+#else
+    void *module;
+    unsigned int size;
+    int ret;
+
+    module = load_file(filename, &size);
+    if (!module)
+        return -1;
+
+    ret = init_module(module, size, args);
+
+    free(module);
+
+    return ret;
+#endif
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is to check if driver is loaded or not
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static int
+check_driver_loaded(
+    void
+    )
+{
+#if 1
+	return 1;
+#else
+    FILE *proc;
+    char line[sizeof(DRIVER_MODULE_TAG)+10];
+
+    if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
+        ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
+        return 0;
+    }
+
+    while ((fgets(line, sizeof(line), proc)) != NULL) {
+        if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) {
+            fclose(proc);
+            return 1;
+        }
+    }
+
+    fclose(proc);
+    return 0;
+#endif
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is to extract interface name
+ *
+ * @param   name    pointer to name buffer
+ *          nsize   size of name buffer
+ *          buf     current position in buffer
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static inline char *
+iw_get_ifname(
+    char *name,
+    int	  nsize,
+    char *buf
+    )
+{
+    char *end;
+
+    /* Skip leading spaces */
+    while(isspace(*buf))
+        buf++;
+
+    end = strrchr(buf, ':');
+
+    /* Not found ??? To big ??? */
+    if((end == NULL) || (((end - buf) + 1) > nsize))
+        return(NULL);
+
+    /* Copy */
+    memcpy(name, buf, (end - buf));
+    name[end - buf] = '\0';
+
+    /* Return value currently unused, just make sure it's non-NULL */
+    return(end);
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This function is to check whether wlan0 has been spawn or not
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static int
+find_wifi_device(
+    void
+    )
+{
+    FILE *fh;
+    char  buff[1024];
+    int   ret = -1;
+
+    fh = fopen(PROC_NET_DEV, "r");
+
+    if(fh != NULL) {
+        /* Success : use data from /proc/net/wireless */
+        /* Eat 2 lines of header */
+        fgets(buff, sizeof(buff), fh);
+        fgets(buff, sizeof(buff), fh);
+
+        /* Read each device line */
+        while(fgets(buff, sizeof(buff), fh)) {
+            char  name[IFNAMSIZ + 1];
+            char *s;
+
+            /* Skip empty or almost empty lines. It seems that in some
+             * *        * cases fgets return a line with only a newline. */
+            if ((buff[0] == '\0') || (buff[1] == '\0'))
+                continue;
+            /* Extract interface name */
+            s = iw_get_ifname(name, sizeof(name), buff);
+
+            if(s) {
+                ALOGD("[%s] %s", __func__, name);
+                if (strcmp(name, WIFI_IF_NAME) == 0 ){
+                    ret = 0;
+                    break;
+                }
+            }
+        }
+
+        fclose(fh);
+    }
+
+    return ret;
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief   Wrapper to push some Wireless Parameter in the driver
+ *
+ * @param   request Wireless extension identifier
+ *          pwrq    Pointer to wireless extension request
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static inline int
+ioctl_iw_ext(
+    int             request,
+    struct iwreq   *pwrq
+    )
+{
+    if(skfd > 0) {
+        /* Set device name */
+        strncpy(pwrq->ifr_name, WIFI_IF_NAME, (IFNAMSIZ - 1));
+
+        /* Do the request */
+        return(ioctl(skfd, request, pwrq));
+    }
+    else {
+        return -1;
+    }
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API is to ask underlying software to enter/leave RF test mode
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static int
+wifi_switch_test_mode(
+    int on
+    )
+{
+    int retval;
+    struct iwreq wrq;
+    NDIS_TRANSPORT_STRUCT rNdisStruct;
+
+    /* zeroize */
+    memset(&wrq, 0, sizeof(struct iwreq));
+
+    /* configure NDIS_TRANSPORT_STRUC */
+    if(on == 1) {
+        rNdisStruct.ndisOidCmd = OID_CUSTOM_TEST_MODE;
+    }
+    else if(on == 0) {
+        rNdisStruct.ndisOidCmd = OID_CUSTOM_ABORT_TEST_MODE;
+    }
+    else {
+        return -1;
+    }
+
+    rNdisStruct.inNdisOidlength = 0;
+    rNdisStruct.outNdisOidLength = 0;
+
+    /* configure struct iwreq */
+    wrq.u.data.pointer = &rNdisStruct;
+    wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT);
+    wrq.u.data.flags = PRIV_CMD_OID;
+
+    retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq);
+
+    if(retval == 0) {
+        if(on == 1) {
+            fgIsTesting = true;
+        }
+        else {
+            fgIsTesting = false;
+        }
+    }
+
+    return retval;
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a generic service for RF test set commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+int
+WIFI_TEST_set(
+    uint32_t  u4FuncIndex,
+    uint32_t  u4FuncData,
+    uint32_t *pu4FuncIndex,
+    uint32_t *pu4FuncData
+    )
+{
+    int retval;
+    struct iwreq wrq;
+    NDIS_TRANSPORT_STRUCT rNdisStruct;
+    P_PARAM_MTK_WIFI_TEST_STRUC_T prTestStruct;
+
+    prTestStruct = (P_PARAM_MTK_WIFI_TEST_STRUC_T)rNdisStruct.ndisOidContent;
+
+    /* zeroize */
+    memset(&wrq, 0, sizeof(struct iwreq));
+
+    /* configure TEST_STRUCT */
+    prTestStruct->u4FuncIndex = u4FuncIndex;
+    prTestStruct->u4FuncData = u4FuncData;
+
+    /* configure NDIS_TRANSPORT_STRUC */
+    rNdisStruct.ndisOidCmd = OID_CUSTOM_MTK_WIFI_TEST_;
+    rNdisStruct.inNdisOidlength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T);
+    rNdisStruct.outNdisOidLength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T);
+
+    /* configure struct iwreq */
+    wrq.u.data.pointer = &rNdisStruct;
+    wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT);
+    wrq.u.data.flags = PRIV_CMD_OID;
+
+    retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq);
+
+    if(retval == 0) {
+        if(pu4FuncIndex) {
+            *pu4FuncIndex = prTestStruct->u4FuncIndex;
+        }
+
+        if(pu4FuncData) {
+            *pu4FuncData = prTestStruct->u4FuncData;
+        }
+
+        DBGLOG("<ok> Set CMD[%03u] DATA[0x%08x]\n",
+            (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData);
+    }
+    else {
+        DBGLOG("<failed> Set CMD[%03u] DATA[0x%08x]\n",
+            (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData);
+    }
+
+    return retval;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a generic service for RF test query commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+static int
+WIFI_TEST_get(
+    uint32_t  u4FuncIndex,
+    uint32_t  u4FuncData,
+    uint32_t *pu4FuncIndex,
+    uint32_t *pu4FuncData
+    )
+{
+    int retval;
+    struct iwreq wrq;
+    NDIS_TRANSPORT_STRUCT rNdisStruct;
+    P_PARAM_MTK_WIFI_TEST_STRUC_T prTestStruct;
+
+    prTestStruct = (P_PARAM_MTK_WIFI_TEST_STRUC_T)rNdisStruct.ndisOidContent;
+
+    /* zeroize */
+    memset(&wrq, 0, sizeof(struct iwreq));
+
+    /* configure TEST_STRUCT */
+    prTestStruct->u4FuncIndex = u4FuncIndex;
+    prTestStruct->u4FuncData = u4FuncData;
+
+    /* configure NDIS_TRANSPORT_STRUC */
+    rNdisStruct.ndisOidCmd = OID_CUSTOM_MTK_WIFI_TEST_;
+    rNdisStruct.inNdisOidlength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T);
+    rNdisStruct.outNdisOidLength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T);
+
+    /* configure struct iwreq */
+    wrq.u.data.pointer = &rNdisStruct;
+    wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT);
+    wrq.u.data.flags = PRIV_CMD_OID;
+
+    retval = ioctl_iw_ext(IOCTL_GET_STRUCT, &wrq);
+
+    if(retval == 0) {
+        if(pu4FuncIndex) {
+            *pu4FuncIndex = prTestStruct->u4FuncIndex;
+        }
+
+        if(pu4FuncData) {
+            *pu4FuncData = prTestStruct->u4FuncData;
+        }
+
+        DBGLOG("<ok> Get CMD[%03u] DATA[0x%08x] RESULT[0x%08x]\n",
+            (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData, *pu4FuncData);
+    }
+    else {
+        DBGLOG("<failed> Get CMD[%03u] DATA[0x%08x]\n",
+            (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData);
+    }
+
+    return retval;
+}
+
+
+/* API
+ * ========================================================================== */
+bool WIFI_TEST_OpenDUT(void)
+{
+    int count = 60;
+    bool retval = false;
+
+    ALOGD("[%s] entry\n", __func__);
+
+    wifi_set_power(1);
+
+    if (!check_driver_loaded()) {
+        ALOGD("[%s] loading wifi driver ... ...\n", __func__);
+
+        if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
+            ALOGD("[%s] failed to load wifi driver!!\n", __func__);
+            goto error;
+        }
+    }
+
+    sched_yield();
+
+    while(count -- > 0) {
+        if(find_wifi_device()==0) {
+            retval = true;
+            ALOGD("[%s] find wifi device\n", __func__);
+            break;
+        }
+        usleep(50000);
+    }
+
+    if (retval == false) {
+        goto error;
+    }
+    else {
+        /* initialize skfd */
+        if ((skfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+            ALOGE("[%s] failed to open net socket\n", __func__);
+            goto error;
+        }
+    }
+
+    /* switch into test mode */
+    if(wifi_switch_test_mode(1) != 0) {
+        goto error;
+    }
+
+    return true;
+
+error:
+    ALOGD("[%s] failure", __func__);
+
+    WIFI_TEST_CloseDUT();
+
+    return false;
+}
+
+bool WIFI_TEST_CloseDUT(void)
+{
+    /* turn off test mode */
+    wifi_switch_test_mode(0);
+
+    /* close socket if necessary */
+    if(skfd > 0) {
+        close(skfd);
+        skfd = -1;
+    }
+
+    /* no need to remove module, just turn off host power via rfkill */
+    wifi_set_power(0);
+
+    return true;
+}
+
+bool WIFI_TEST_TxDataRate(int TxDataRate)
+{
+    int retval;
+
+	switch (TxDataRate) {
+	case WIFI_TEST_RATE_AUTO:
+        return false;   //@FIXME
+
+	case WIFI_TEST_RATE_1MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_1M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_2MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_2M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_5_5MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_5_5M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_6MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_6M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_9MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_9M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_11MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_11M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_12MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_12M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_18MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_18M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_24MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_24M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_36MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_36M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_48MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_48M,
+                NULL,
+                NULL);
+        break;
+
+	case WIFI_TEST_RATE_54MBPS:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                RF_AT_PARAM_RATE_54M,
+                NULL,
+                NULL);
+        break;
+
+	default:
+        return false;
+
+	}
+
+    /* return value checking */
+    if(retval == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_SetPreamble(WIFI_PreambleType_t PreambleType)
+{
+	int retval;
+
+	switch (PreambleType) {
+	case WIFI_TEST_PREAMBLE_LONG:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE,
+                RF_AT_PREAMBLE_NORMAL,
+                NULL,
+                NULL);
+		break;
+
+	case WIFI_TEST_PREAMBLE_SHORT:
+        retval = WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE,
+                RF_AT_PREAMBLE_CCK_SHORT,
+                NULL,
+                NULL);
+		break;
+
+	default:
+        return false;
+	}
+
+    /* return value checking */
+    if(retval == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_Channel(int ChannelNo)
+{
+    uint32_t u4Freq;
+
+    if(ChannelNo < 0) {
+        return false; /* invalid channel number */
+    }
+    /* 2.4GHz band */
+    else if(ChannelNo <= 13) {
+        u4Freq = 2412000 + (ChannelNo - 1) * 5000;
+    }
+    else if(ChannelNo == 14) {
+        u4Freq = 2484000;
+    }
+    /* 5GHz band */
+    else if(ChannelNo >= 36) {
+        u4Freq = 5180000 + (ChannelNo - 36) * 5000;
+    }
+    else {
+        return false; /* invalid channel number */
+    }
+
+    if(WIFI_TEST_set(RF_AT_FUNCID_CHNL_FREQ,
+            u4Freq,
+            NULL,
+            NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxGain(float TxGain)
+{
+    /* assign TX power gain */
+    if(WIFI_TEST_set(RF_AT_FUNCID_POWER,
+            (uint32_t)(TxGain * 2.0), // in unit of 0.5dBm
+            NULL,
+            NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxBurstInterval(int SIFS)
+{
+	if (SIFS < 20 || SIFS > 1000)
+		return false;
+
+    /* specify packet interval */
+    if(WIFI_TEST_set(RF_AT_FUNCID_PKTINTERVAL,
+            SIFS,
+            NULL,
+            NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxPayloadLength(int TxPayLength)
+{
+	if (TxPayLength <= 0)
+		return false;
+
+    /* specify packet length */
+    if(WIFI_TEST_set(RF_AT_FUNCID_PKTLEN,
+            TxPayLength,
+            NULL,
+            NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxBurstFrames(int Frames)
+{
+	if (Frames < 0)
+		return false;
+
+    /* specify packet count */
+    if(WIFI_TEST_set(RF_AT_FUNCID_PKTCNT,
+                Frames,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxDestAddress(unsigned char *addr)
+{
+    uint8_t aucMacAddr[4];
+    uint32_t u4MacAddr;
+
+    /* specify MAC address[0:3] */
+    memcpy(aucMacAddr, addr, sizeof(uint8_t) * 4);
+    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS,
+                u4MacAddr,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    /* specify MAC address[4:5] */
+    memset(aucMacAddr, 0, sizeof(uint8_t) * 4);
+    memcpy(aucMacAddr, addr + 4, sizeof(uint8_t) * 2);
+    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS | (4 << TEST_SET_CMD_OFFSET),
+                u4MacAddr,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    return true;
+}
+
+bool WIFI_TEST_TxStart(void)
+{
+	/* tx start: without ack, async mode */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_STARTTX,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxStop(void)
+{
+    /* checking for testing mode */
+    if(WIFI_TEST_IsRunning() == false) {
+        WIFI_TEST_OpenDUT();
+    }
+
+	/* tx stop */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_STOPTEST,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_RxStart(void)
+{
+	/* rx start: without ack, async mode */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_STARTRX,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_RxStop(void)
+{
+    /* checking for testing mode */
+    if(WIFI_TEST_IsRunning() == false) {
+        WIFI_TEST_OpenDUT();
+    }
+
+	/* rx stop */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_STOPTEST,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_FRError(int *FError)
+{
+	if (!FError)
+		return false;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT,
+                0,
+                NULL,
+                (uint32_t *)FError) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_FRGood(int *FRGood)
+{
+	if (!FRGood)
+		return false;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT,
+                0,
+                NULL,
+                (uint32_t *)FRGood) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxCount(uint32_t *TxCount)
+{
+	if (!TxCount)
+		return false;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_TXED_COUNT,
+                0,
+                NULL,
+                (uint32_t *)TxCount) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TxGoodCount(uint32_t *TxGoodCount)
+{
+	if (!TxGoodCount)
+		return false;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_TXOK_COUNT,
+                0,
+                NULL,
+                (uint32_t *)TxGoodCount) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_RSSI(int *RSSI)
+{
+    uint32_t u4Result;
+
+	if (!RSSI)
+		return false;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_RX_RSSI,
+                0,
+                NULL,
+                &u4Result) == 0) {
+        /* u4Result[0:7]    Average RSSI (dbM)
+         * u4Result[8:15]   Minimum RCPI
+         * u4Result[16:23]  Maximum RCPI
+         * u4Result[24:31]  Last RCPI
+         */
+        *RSSI = (int)(u4Result & BITS(0,7));
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_IsRunning(void)
+{
+	return fgIsTesting;
+}
+
+bool WIFI_TEST_IsUp(void)
+{
+    struct ifreq ifr;
+    int sk, up;
+
+    /* NULL ptr checking */
+    sk = socket(PF_INET, SOCK_STREAM, 0);
+    if (sk == -1) {
+        return false;
+    }
+
+    strncpy(ifr.ifr_name, WIFI_IF_NAME, sizeof(ifr.ifr_name)-1);
+    ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0';
+
+    /* retrieve hardware address */
+    if (ioctl(sk, SIOCGIFFLAGS, &ifr) == -1) {
+        close(sk);
+        return false;
+    }
+
+    up = ifr.ifr_flags & IFF_UP;
+
+    close(sk);
+
+    if(up) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+/* for 11n test */
+// FrameFormat        : 1 (Mixed Mode), 2 (Green field mode)
+// GI (Gard interval) : 1 (Long GI), 2 (Short GI)
+bool WIFI_TEST_TxDataRate11n(
+    ENUM_WIFI_TEST_MCS_RATE eTxDataRate11n,
+    ENUM_WIFI_TEST_PREAMBLE_TYPE ePreambleType,
+    ENUM_WIFI_TEST_GI_TYPE eGIType
+    )
+{
+    uint32_t u4Rate, u4Preamble;
+
+	if( eTxDataRate11n > WIFI_TEST_MCS_RATE_7 && eTxDataRate11n != WIFI_TEST_MCS_RATE_32 )
+	{
+        DBGLOG("<failed> Unsupported MCS rate index[%u]\n", eTxDataRate11n);
+		return false;
+	}
+
+	if( (ePreambleType != 0) && (ePreambleType != 1) )
+	{
+	    DBGLOG("<failed> Unsupported N mode preamable type[%u]\n", ePreambleType);
+		return false;
+	}
+
+	if( (eGIType != 0) && (eGIType != 1) )
+	{
+		return false;
+	}
+
+    /* specify 11n rate */
+    u4Rate = RF_AT_PARAM_RATE_MCS_MASK | (uint32_t)(eTxDataRate11n);
+    if(WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                u4Rate,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    /* specify preamble type */
+    switch(ePreambleType) {
+    case WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE:
+        u4Preamble = RF_AT_PREAMBLE_11N_MM;
+        break;
+
+    case WIFI_TEST_PREAMBLE_TYPE_GREENFIELD:
+        u4Preamble = RF_AT_PREAMBLE_11N_GF;
+        break;
+
+    default:
+        return false;
+    }
+
+    if(WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE,
+                u4Preamble,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    /* specify Guard Interval type */
+    if(WIFI_TEST_set(RF_AT_FUNCID_GI,
+                eGIType,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+	return true;
+}
+
+
+/* for 11ac test */
+// GI (Gard interval) : 1 (Long GI), 2 (Short GI)
+bool WIFI_TEST_TxDataRate11ac(
+    ENUM_WIFI_TEST_MCS_RATE eTxMcsRate,
+    ENUM_WIFI_TEST_GI_TYPE eGIType
+    )
+{
+    uint32_t u4Rate;
+
+	if(eTxMcsRate > WIFI_TEST_MCS_RATE_9)
+	{
+		return false;
+	}
+
+	if( (eGIType != 0) && (eGIType != 1) )
+	{
+		return false;
+	}
+
+    /* specify MCS rate */
+    u4Rate = RF_AT_PARAM_RATE_MCS_MASK | (uint32_t)(eTxMcsRate);
+    if(WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                u4Rate,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    if(WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE,
+                RF_AT_PREAMBLE_11AC,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    /* specify Guard Interval type */
+    if(WIFI_TEST_set(RF_AT_FUNCID_GI,
+                eGIType,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+	return true;
+}
+
+/* for 11n test */
+bool WIFI_TEST_FrequencyAccuracy(int ChannelNo)
+{
+    /* set channel */
+    if(WIFI_TEST_Channel(ChannelNo) == false) {
+        return false;
+    }
+
+    /* start carrier tone */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_LO_LEAKAGE,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+/* for 11n test */
+bool WIFI_TEST_FrequencyAccuracy_Stop()
+{
+    /* checking for testing mode */
+    if(WIFI_TEST_IsRunning() == false) {
+        WIFI_TEST_OpenDUT();
+    }
+
+	/* stop */
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_STOPTEST,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+
+/*******************************************************************************
+ * STYLE #B Control API
+ *******************************************************************************
+ */
+/* static variables for Style #B Control API */
+static ENUM_WIFI_TEST_MODE eWifiTestMode = WIFI_TEST_MODE_BY_API_CONTROL;
+static ENUM_WIFI_BANDWIDTH eWifiBw = WIFI_TEST_BW_20MHZ;
+static uint32_t u4NumGoodFrames = 0;
+static uint32_t u4NumBadFrames = 0;
+
+bool WIFI_TEST_SetMode(ENUM_WIFI_TEST_MODE eMode)
+{
+    if(eMode >= WIFI_TEST_MODE_NUM) {
+        return false;
+    }
+    else {
+        eWifiTestMode = eMode;
+        return true;
+    }
+}
+
+bool WIFI_TEST_GetSupportedMode(uint32_t *pu4SupportedMode) {
+    uint8_t ucSupportVht = 1;
+
+    if(pu4SupportedMode == NULL) {
+        return false;
+    }
+    else {
+#if 1
+		ALOGE("%s: not supported\n", __func__);
+#else
+        /* read fgEnable5GBand / fgSupport5GBand field from NVRAM */
+        uint8_t ucSupport5GBand = 0, ucEnable5GBand = 0;
+        F_INFO rFileInfo;
+        int fd;
+
+        rFileInfo = NVM_ReadFileVerInfo(AP_CFG_RDEB_FILE_WIFI_LID);
+        fd = open(rFileInfo.cFileName, O_RDONLY, S_IRUSR);
+        if(fd != -1) {
+            lseek(fd, offsetof(WIFI_CFG_PARAM_STRUCT, ucSupport5GBand), SEEK_SET);
+            read(fd, &ucSupport5GBand, sizeof(uint8_t));
+
+            lseek(fd, offsetof(WIFI_CFG_PARAM_STRUCT, ucEnable5GBand), SEEK_SET);
+            read(fd, &ucEnable5GBand, sizeof(uint8_t));
+
+            close(fd);
+        }
+
+        if(ucSupport5GBand && ucEnable5GBand) {
+            *pu4SupportedMode = BIT((int)WIFI_TEST_MODE_80211A_ONLY)
+                                    | BIT((int)WIFI_TEST_MODE_80211B_ONLY)
+                                    | BIT((int)WIFI_TEST_MODE_80211G_ONLY)
+                                    | BIT((int)WIFI_TEST_MODE_80211N_ONLY);
+        }
+        else {
+            *pu4SupportedMode = BIT((int)WIFI_TEST_MODE_80211B_ONLY)
+                                    | BIT((int)WIFI_TEST_MODE_80211G_ONLY)
+                                    | BIT((int)WIFI_TEST_MODE_80211N_ONLY);
+        }
+
+        if(ucSupportVht) {
+            *pu4SupportedMode |= BIT((int)WIFI_TEST_MODE_80211AC_ONLY);
+        }
+
+        return true;
+#endif
+    }
+
+	return false;
+}
+
+bool WIFI_TEST_SetBandwidth(ENUM_WIFI_BANDWIDTH eBandwidth)
+{
+    int result = 0;
+    ENUM_WIFI_CHANNEL_BANDWIDTH eChBw;
+
+    if(eBandwidth >= WIFI_TEST_BW_NUM) {
+        return false;
+    }
+
+    /* Legacy/11n BW */
+    if(eBandwidth < WIFI_TEST_BW_80MHZ) {
+        result = WIFI_TEST_set(RF_AT_FUNCID_BANDWIDTH, (uint32_t)eBandwidth,
+                        NULL, NULL);
+    } else {
+        switch(eBandwidth) {
+        case WIFI_TEST_BW_80MHZ:
+            eChBw = WIFI_TEST_CH_BW_80MHZ;
+            break;
+
+        case WIFI_TEST_BW_160MHZ:
+            eChBw = WIFI_TEST_CH_BW_160MHZ;
+            break;
+
+        default:
+            return false;
+        }
+
+        result = WIFI_TEST_set(RF_AT_FUNCID_SET_CHANNEL_BANDWIDTH,
+                (uint32_t)eChBw, NULL, NULL);
+    }
+
+    if(result == 0) {
+        eWifiBw = eBandwidth;
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_SetBandwidthV2(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth)
+{
+    int result = 0;
+
+    if(eBandwidth >= WIFI_TEST_CH_BW_NUM) {
+        return false;
+    }
+
+    result = WIFI_TEST_set(RF_AT_FUNCID_SET_CHANNEL_BANDWIDTH,
+            (uint32_t)eBandwidth, NULL, NULL);
+
+    return (result == 0)? true:false;
+}
+
+bool WIFI_TEST_SetPriChannelSetting(uint8_t ucPrimaryChSetting)
+{
+    int result = 0;
+
+    if(ucPrimaryChSetting >= WIFI_TEST_PRI_CH_SETTING_NUM) {
+        return false;
+    }
+
+    result = WIFI_TEST_set(RF_AT_FUNCID_SET_PRI_SETTING,
+            (uint32_t)ucPrimaryChSetting, NULL, NULL);
+
+    return (result == 0)? true:false;
+}
+
+bool WIFI_TEST_SetTxBandwidth(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth)
+{
+    int result = 0;
+
+    if(eBandwidth >= WIFI_TEST_CH_BW_NUM) {
+        return false;
+    }
+
+    result = WIFI_TEST_set(RF_AT_FUNCID_SET_DATA_BANDWIDTH,
+            (uint32_t)eBandwidth, NULL, NULL);
+
+    return (result == 0)? true:false;
+}
+
+bool WIFI_TEST_SetFrequency(uint32_t u4FreqInMHz, uint32_t u4OffsetInKHz)
+{
+    if(u4OffsetInKHz != 0) {
+        /* not supporting offset frequency */
+        return false;
+    }
+    else {
+        switch(eWifiTestMode) {
+        case WIFI_TEST_MODE_80211B_ONLY:
+        case WIFI_TEST_MODE_80211G_ONLY:
+            /* check for channel #1 ~ channel #14 */
+            switch(u4FreqInMHz) {
+            case 2412:
+                return WIFI_TEST_Channel(1);
+            case 2417:
+                return WIFI_TEST_Channel(2);
+            case 2422:
+                return WIFI_TEST_Channel(3);
+            case 2427:
+                return WIFI_TEST_Channel(4);
+            case 2432:
+                return WIFI_TEST_Channel(5);
+            case 2437:
+                return WIFI_TEST_Channel(6);
+            case 2442:
+                return WIFI_TEST_Channel(7);
+            case 2447:
+                return WIFI_TEST_Channel(8);
+            case 2452:
+                return WIFI_TEST_Channel(9);
+            case 2457:
+                return WIFI_TEST_Channel(10);
+            case 2462:
+                return WIFI_TEST_Channel(11);
+            case 2467:
+                return WIFI_TEST_Channel(12);
+            case 2472:
+                return WIFI_TEST_Channel(13);
+            case 2484:
+                return WIFI_TEST_Channel(14);
+            default:
+                break;
+            }
+            break;
+
+        case WIFI_TEST_MODE_80211A_ONLY:
+            switch(u4FreqInMHz) {
+            case 4915:
+                return WIFI_TEST_Channel(183);
+            case 4920:
+                return WIFI_TEST_Channel(184);
+            case 4925:
+                return WIFI_TEST_Channel(185);
+            case 4935:
+                return WIFI_TEST_Channel(187);
+            case 4940:
+                return WIFI_TEST_Channel(188);
+            case 4945:
+                return WIFI_TEST_Channel(189);
+            case 4960:
+                return WIFI_TEST_Channel(192);
+            case 4980:
+                return WIFI_TEST_Channel(196);
+            case 5170:
+                return WIFI_TEST_Channel(34);
+            case 5180:
+                return WIFI_TEST_Channel(36);
+            case 5190:
+                return WIFI_TEST_Channel(38);
+            case 5200:
+                return WIFI_TEST_Channel(40);
+            case 5210:
+                return WIFI_TEST_Channel(42);
+            case 5220:
+                return WIFI_TEST_Channel(44);
+            case 5230:
+                return WIFI_TEST_Channel(46);
+            case 5240:
+                return WIFI_TEST_Channel(48);
+            case 5260:
+                return WIFI_TEST_Channel(52);
+            case 5280:
+                return WIFI_TEST_Channel(56);
+            case 5300:
+                return WIFI_TEST_Channel(60);
+            case 5320:
+                return WIFI_TEST_Channel(64);
+            case 5500:
+                return WIFI_TEST_Channel(100);
+            case 5520:
+                return WIFI_TEST_Channel(104);
+            case 5540:
+                return WIFI_TEST_Channel(108);
+            case 5560:
+                return WIFI_TEST_Channel(112);
+            case 5580:
+                return WIFI_TEST_Channel(116);
+            case 5600:
+                return WIFI_TEST_Channel(120);
+            case 5620:
+                return WIFI_TEST_Channel(124);
+            case 5640:
+                return WIFI_TEST_Channel(128);
+            case 5660:
+                return WIFI_TEST_Channel(132);
+            case 5680:
+                return WIFI_TEST_Channel(136);
+            case 5700:
+                return WIFI_TEST_Channel(140);
+            case 5745:
+                return WIFI_TEST_Channel(149);
+            case 5765:
+                return WIFI_TEST_Channel(153);
+            case 5785:
+                return WIFI_TEST_Channel(157);
+            case 5805:
+                return WIFI_TEST_Channel(161);
+            case 5825:
+                return WIFI_TEST_Channel(165);
+            default:
+                break;
+            }
+            break;
+
+        case WIFI_TEST_MODE_80211N_ONLY:
+        case WIFI_TEST_MODE_80211AC_ONLY:
+            switch(u4FreqInMHz) {
+            case 2412:
+                return WIFI_TEST_Channel(1);
+            case 2417:
+                return WIFI_TEST_Channel(2);
+            case 2422:
+                return WIFI_TEST_Channel(3);
+            case 2427:
+                return WIFI_TEST_Channel(4);
+            case 2432:
+                return WIFI_TEST_Channel(5);
+            case 2437:
+                return WIFI_TEST_Channel(6);
+            case 2442:
+                return WIFI_TEST_Channel(7);
+            case 2447:
+                return WIFI_TEST_Channel(8);
+            case 2452:
+                return WIFI_TEST_Channel(9);
+            case 2457:
+                return WIFI_TEST_Channel(10);
+            case 2462:
+                return WIFI_TEST_Channel(11);
+            case 2467:
+                return WIFI_TEST_Channel(12);
+            case 2472:
+                return WIFI_TEST_Channel(13);
+            case 2484:
+                return WIFI_TEST_Channel(14);
+            case 4915:
+                return WIFI_TEST_Channel(183);
+            case 4920:
+                return WIFI_TEST_Channel(184);
+            case 4925:
+                return WIFI_TEST_Channel(185);
+            case 4935:
+                return WIFI_TEST_Channel(187);
+            case 4940:
+                return WIFI_TEST_Channel(188);
+            case 4945:
+                return WIFI_TEST_Channel(189);
+            case 4960:
+                return WIFI_TEST_Channel(192);
+            case 4980:
+                return WIFI_TEST_Channel(196);
+            case 5170:
+                return WIFI_TEST_Channel(34);
+            case 5180:
+                return WIFI_TEST_Channel(36);
+            case 5190:
+                return WIFI_TEST_Channel(38);
+            case 5200:
+                return WIFI_TEST_Channel(40);
+            case 5210:
+                return WIFI_TEST_Channel(42);
+            case 5220:
+                return WIFI_TEST_Channel(44);
+            case 5230:
+                return WIFI_TEST_Channel(46);
+            case 5240:
+                return WIFI_TEST_Channel(48);
+            case 5260:
+                return WIFI_TEST_Channel(52);
+            case 5280:
+                return WIFI_TEST_Channel(56);
+            case 5300:
+                return WIFI_TEST_Channel(60);
+            case 5320:
+                return WIFI_TEST_Channel(64);
+            case 5500:
+                return WIFI_TEST_Channel(100);
+            case 5520:
+                return WIFI_TEST_Channel(104);
+            case 5540:
+                return WIFI_TEST_Channel(108);
+            case 5560:
+                return WIFI_TEST_Channel(112);
+            case 5580:
+                return WIFI_TEST_Channel(116);
+            case 5600:
+                return WIFI_TEST_Channel(120);
+            case 5620:
+                return WIFI_TEST_Channel(124);
+            case 5640:
+                return WIFI_TEST_Channel(128);
+            case 5660:
+                return WIFI_TEST_Channel(132);
+            case 5680:
+                return WIFI_TEST_Channel(136);
+            case 5700:
+                return WIFI_TEST_Channel(140);
+            case 5745:
+                return WIFI_TEST_Channel(149);
+            case 5765:
+                return WIFI_TEST_Channel(153);
+            case 5785:
+                return WIFI_TEST_Channel(157);
+            case 5805:
+                return WIFI_TEST_Channel(161);
+            case 5825:
+                return WIFI_TEST_Channel(165);
+            default:
+                break;
+            }
+            break;
+
+        default:
+            break;
+        }
+
+        return false;
+    }
+}
+
+bool WIFI_TEST_SetRate(uint32_t u4Rate)
+{
+    ENUM_WIFI_TEST_GI_TYPE eGIType;
+    uint32_t u4RateCode;
+    ALOGD("[%s] Rate=[%d]\n", __func__, u4Rate);
+
+    /* validate rate by mode/bandwidth settings */
+    if(eWifiTestMode == WIFI_TEST_MODE_80211B_ONLY) {
+        switch(u4Rate) {
+        case 100:
+            u4RateCode = RF_AT_PARAM_RATE_1M;
+            break;
+
+        case 200:
+            u4RateCode = RF_AT_PARAM_RATE_2M;
+            break;
+
+        case 550:
+            u4RateCode = RF_AT_PARAM_RATE_5_5M;
+            break;
+
+        case 1100:
+            u4RateCode = RF_AT_PARAM_RATE_11M;
+            break;
+
+        default:
+            return false;
+        }
+    }
+    else if(eWifiTestMode == WIFI_TEST_MODE_80211G_ONLY || eWifiTestMode == WIFI_TEST_MODE_80211A_ONLY) {
+        switch(u4Rate) {
+        case 600:
+            u4RateCode = RF_AT_PARAM_RATE_6M;
+            break;
+
+        case 900:
+            u4RateCode = RF_AT_PARAM_RATE_9M;
+            break;
+
+        case 1200:
+            u4RateCode = RF_AT_PARAM_RATE_12M;
+            break;
+
+        case 1800:
+            u4RateCode = RF_AT_PARAM_RATE_18M;
+            break;
+
+        case 2400:
+            u4RateCode = RF_AT_PARAM_RATE_24M;
+            break;
+
+        case 3600:
+            u4RateCode = RF_AT_PARAM_RATE_36M;
+            break;
+
+        case 4800:
+            u4RateCode = RF_AT_PARAM_RATE_48M;
+            break;
+
+        case 5400:
+            u4RateCode = RF_AT_PARAM_RATE_54M;
+            break;
+
+        default:
+            return false;
+        }
+    }
+    else if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY && eWifiBw == WIFI_TEST_BW_20MHZ) {
+        switch(u4Rate) {
+        case 650:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 720:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 1300:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 1440:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 1950:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 2170:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 2600:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 2890:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 3900:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 4330:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 5200:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 5780:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 5850:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_6;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 6500:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 7200:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        default:
+            return false;
+        }
+    }
+    else if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY && eWifiBw == WIFI_TEST_BW_40MHZ) {
+        switch(u4Rate) {
+        case 1350:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 1500:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 2700:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 3000:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 4050:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 4500:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 5400:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 6000:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 8100:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 9000:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 10800:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 12000:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        case 12150:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_6;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 13500:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7;
+            eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+            break;
+        case 15000:
+            u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7;
+            eGIType = WIFI_TEST_GI_TYPE_SHORT_GI;
+            break;
+        default:
+            return false;
+        }
+    }
+    else {
+        return false;
+    }
+
+    /* set GI type */
+    if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY &&
+            WIFI_TEST_set(RF_AT_FUNCID_GI,
+                eGIType,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+
+    /* set rate code */
+    if(WIFI_TEST_set(RF_AT_FUNCID_RATE,
+                u4RateCode,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_SetTXPower(uint32_t u4Gain)
+{
+    if(u4Gain > 6350) {
+        return false;
+    }
+    else if(WIFI_TEST_set(RF_AT_FUNCID_POWER,
+            u4Gain / 50, // convert to unit of 0.5dBm
+            NULL,
+            NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_SetTX(bool fgEnable)
+{
+    if(fgEnable == true) {
+        return WIFI_TEST_TxStart();
+    }
+    else {
+        return WIFI_TEST_TxStop();
+    }
+}
+
+bool WIFI_TEST_SetRX(bool fgEnable, char *aucSrcAddr, char *aucDstAddr)
+{
+	uint8_t aucMacAddr[4];
+	uint32_t u4MacAddr;
+	ENUM_RF_AT_RXOK_MATCH_RULE_T eRxRule;
+
+	if(fgEnable == true) {
+		if(aucSrcAddr && aucDstAddr) {
+		    eRxRule = RF_AT_RXOK_DISABLED;
+		}
+		else if(aucDstAddr) {
+		    eRxRule = RF_AT_RXOK_MATCH_RA_ONLY;
+		}
+		else if(aucSrcAddr) {
+		    eRxRule = RF_AT_RXOK_MATCH_TA_ONLY;
+		}
+		else {
+		    eRxRule = RF_AT_RXOK_DISABLED;
+		}
+
+		/* specify policy */
+		if(WIFI_TEST_set(RF_AT_FUNCID_SET_RXOK_MATCH_RULE,
+		            eRxRule,
+		            NULL,
+		            NULL) != 0) {
+		    return false;
+		}
+
+		if(aucDstAddr) {
+		    /* specify MAC address[0:3] */
+		    memcpy(aucMacAddr, aucDstAddr, sizeof(uint8_t) * 4);
+		    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+		    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS,
+		                u4MacAddr,
+		                NULL,
+		                NULL) != 0) {
+		        return false;
+		    }
+
+		    /* specify MAC address[4:5] */
+		    memset(aucMacAddr, 0, sizeof(uint8_t) * 4);
+		    memcpy(aucMacAddr, &(aucDstAddr[4]), sizeof(uint8_t) * 2);
+		    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+		    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS | (4 << TEST_SET_CMD_OFFSET),
+		                u4MacAddr,
+		                NULL,
+		                NULL) != 0) {
+		        return false;
+		    }
+		}
+
+		if(aucSrcAddr) {
+		    /* specify MAC address[0:3] */
+		    memcpy(aucMacAddr, aucSrcAddr, sizeof(uint8_t) * 4);
+		    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+		    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_SRC_ADDRESS,
+		                u4MacAddr,
+		                NULL,
+		                NULL) != 0) {
+		        return false;
+		    }
+
+		    /* specify MAC address[4:5] */
+		    memset(aucMacAddr, 0, sizeof(uint8_t) * 4);
+		    memcpy(aucMacAddr, &(aucSrcAddr[4]), sizeof(uint8_t) * 2);
+		    u4MacAddr = *(uint32_t *)(&(aucMacAddr[0]));
+		    if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_SRC_ADDRESS | (4 << TEST_SET_CMD_OFFSET),
+		                u4MacAddr,
+		                NULL,
+		                NULL) != 0) {
+		        return false;
+		    }
+		}
+
+		/* Start RX */
+		//return WIFI_TEST_RxStart();
+		return true;
+	}
+	else {
+		if(aucSrcAddr && aucDstAddr) {
+			eRxRule = RF_AT_RXOK_DISABLED;
+		}
+		else if(aucDstAddr) {
+			eRxRule = RF_AT_RXOK_MATCH_RA_ONLY;
+		}
+		else if(aucSrcAddr) {
+			eRxRule = RF_AT_RXOK_MATCH_TA_ONLY;
+		}
+		else {
+			eRxRule = RF_AT_RXOK_DISABLED;
+		}
+		/* specify policy */
+		if(WIFI_TEST_set(RF_AT_FUNCID_SET_RXOK_MATCH_RULE,
+		        eRxRule,
+		        NULL,
+		        NULL) != 0) {
+			return false;
+		}
+		//return WIFI_TEST_RxStop();
+		return true;
+	}
+}
+
+bool WIFI_TEST_ClearResult(void)
+{
+    if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT,
+                0,
+                NULL,
+                &u4NumGoodFrames) == 0 &&
+            WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT,
+                0,
+                NULL,
+                &u4NumBadFrames) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_GetResult(uint32_t *pu4GoodFrameCount, uint32_t *pu4BadFrameCount)
+{
+    uint32_t u4GoodCnt, u4BadCnt;
+
+    if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT,
+                0,
+                NULL,
+                &u4GoodCnt) == 0 &&
+            WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT,
+                0,
+                NULL,
+                &u4BadCnt) == 0) {
+
+        if(pu4GoodFrameCount) {
+            *pu4GoodFrameCount = u4GoodCnt - u4NumGoodFrames;
+        }
+        if(pu4BadFrameCount) {
+            *pu4BadFrameCount = u4BadCnt - u4NumBadFrames;
+        }
+
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+
+/* Set Rx default antenna for Rx diversity */
+/* 0: main antenna */
+/* 1: AUX antenna */
+bool WIFI_TEST_SetRxDefaultAnt(uint8_t ucUseAuxAnt)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_RX_DEF_ANT,
+                ucUseAuxAnt,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+/* Set Tx encoding mode */
+/* 0: BCC */
+/* 1: LDPC */
+bool WIFI_TEST_SetTxCodingMode(uint8_t ucLdpc)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_TX_ENCODE_MODE,
+                ucLdpc,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+/* Set J mode */
+/* 0: disable */
+/* 1: 5M single tone */
+/* 2: 10M single tone */
+bool WIFI_TEST_SetJMode(ENUM_WIFI_J_MODE eJModeSetting)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_J_MODE_SETTING,
+                eJModeSetting,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+//for cw mode
+bool WIFI_TEST_TxTraining(void)
+{
+    bool result = false;
+
+    result = WIFI_TEST_TxBurstInterval(20);
+    if(!result)
+        return result;
+
+    result = WIFI_TEST_TxBurstFrames(50);
+    if(!result)
+        return result;
+
+    result = WIFI_TEST_TxPayloadLength(500);
+    if(!result)
+        return result;
+
+    result = WIFI_TEST_TxStart();
+    if(!result)
+        return result;
+
+    usleep(200000);
+
+    result = WIFI_TEST_TxStop();
+    if(!result)
+        return result;
+
+    return true;
+}
+
+bool WIFI_TEST_CW_MODE(int mode)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_SET_CW_MODE,
+                (uint32_t)mode,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_DPD_MODE(int mode)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_DPD_MODE,
+                (uint32_t)mode,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TEMP_COMPEN_MODE(int mode)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_TEMP_COMPEN,
+                (uint32_t)mode,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_TX_POWER_MODE(int mode)
+{
+    if(WIFI_TEST_set(RF_AT_FUNCID_TX_PWR_MODE,
+                (uint32_t)mode,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+bool WIFI_TEST_CW_MODE_START(void)
+{
+	/* cw mode start */
+    if(WIFI_TEST_TxTraining() == false) {
+        return false;
+    }
+
+    if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND,
+                RF_AT_COMMAND_CW,
+                NULL,
+                NULL) == 0) {
+        return true;
+    }
+    else {
+        return false;
+    }
+
+
+}
+
+bool WIFI_TEST_init(void) {
+	/* initialize skfd */
+    if (skfd < 0 && (skfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+        ALOGE("[%s] failed to open net socket\n", __func__);
+        return false;
+    }
+	return true;
+}
+
+void WIFI_TEST_deinit(void) {
+	/* close socket if necessary */
+    if(skfd > 0) {
+        close(skfd);
+        skfd = -1;
+    }
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a service for EFUSE query commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+
+bool WIFI_TEST_EFUSE_Read(unsigned int offset, unsigned int *val)
+{
+    if (!val) {
+        return false;
+    }
+
+    if (WIFI_TEST_get(RF_AT_FUNCID_READ_EFUSE,
+                offset,
+                NULL,
+                (uint32_t *)val) != 0) {
+        return false;
+    }
+    return true;
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a service for EFUSE write commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+
+bool WIFI_TEST_EFUSE_Write(unsigned int offset, unsigned int val)
+{
+    if (WIFI_TEST_set(RF_AT_FUNCID_WRITE_EFUSE | (offset << TEST_SET_CMD_OFFSET),
+                val,
+                NULL,
+                NULL) != 0) {
+        return false;
+    }
+    return true;
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a service for MCR query commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+
+bool WIFI_TEST_MCR_Read(unsigned int addr, unsigned int *val)
+{
+    int retval = -1;
+    struct iwreq wrq;
+    NDIS_TRANSPORT_STRUCT rNdisStruct;
+    P_PARAM_CUSTOM_MCR_RW_STRUC_T prMCRStruct;
+
+    prMCRStruct = (P_PARAM_CUSTOM_MCR_RW_STRUC_T)rNdisStruct.ndisOidContent;
+    /* zeroize */
+    memset(&wrq, 0, sizeof(struct iwreq));
+
+    prMCRStruct->u4McrOffset = addr;
+    /* zeroize */
+    rNdisStruct.ndisOidCmd = OID_CUSTOM_MCR_RW;
+    rNdisStruct.inNdisOidlength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T);
+    rNdisStruct.outNdisOidLength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T);
+
+    wrq.u.data.pointer = &rNdisStruct;
+    wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT);
+    wrq.u.data.flags = PRIV_CMD_OID;
+
+    retval = ioctl_iw_ext(IOCTL_GET_STRUCT, &wrq);
+
+    if (retval == 0) {
+        *val = prMCRStruct->u4McrData;
+    }
+
+	return !retval;
+}
+
+/*----------------------------------------------------------------------------*/
+/*!
+ * @brief This API provided a service for MCR set commands
+ *
+ * @param
+ *
+ * @return
+ */
+/*----------------------------------------------------------------------------*/
+
+bool WIFI_TEST_MCR_Write(unsigned int addr, unsigned int val)
+{
+    int retval = -1;
+    struct iwreq wrq;
+    NDIS_TRANSPORT_STRUCT rNdisStruct;
+    P_PARAM_CUSTOM_MCR_RW_STRUC_T prMCRStruct;
+
+    prMCRStruct = (P_PARAM_CUSTOM_MCR_RW_STRUC_T)rNdisStruct.ndisOidContent;
+    /* zeroize */
+    memset(&wrq, 0, sizeof(struct iwreq));
+
+    prMCRStruct->u4McrOffset = addr;
+    prMCRStruct->u4McrData = val;
+    /* zeroize */
+    rNdisStruct.ndisOidCmd = OID_CUSTOM_MCR_RW;
+    rNdisStruct.inNdisOidlength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T);
+    rNdisStruct.outNdisOidLength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T);
+
+    wrq.u.data.pointer = &rNdisStruct;
+    wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT);
+    wrq.u.data.flags = PRIV_CMD_OID;
+
+    retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq);
+
+    return !retval;
+}
+
diff --git a/src/connectivity/wifitesttool/libwifitest/libwifitest.h b/src/connectivity/wifitesttool/libwifitest/libwifitest.h
new file mode 100644
index 0000000..d48d360
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/libwifitest.h
@@ -0,0 +1,386 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+ * the prior written permission of MediaTek inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of MediaTek Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+ * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+ * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek
+ * Software") have been modified by MediaTek Inc. All revisions are subject to
+ * any receiver's applicable license agreements with MediaTek Inc.
+ */
+
+/*
+ * This is sample code for WLAN Test Mode Control
+ */
+
+#ifndef __LIBWIFITEST_H__
+#define __LIBWIFITEST_H__
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifndef __linux__
+#include <net/if.h>
+#endif
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <netdb.h>
+#include <netinet/if_ether.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <linux/types.h>
+#include <linux/wireless.h>
+
+/* basic definitions
+ * -------------------------------------------------------------------------- */
+#ifndef bool
+#define bool int
+#endif
+
+#ifndef true
+#define true 1
+#endif
+
+#ifndef false
+#define false 0
+#endif
+
+#define PROC_NET_DEV "/proc/net/dev"
+
+/* types
+ * -------------------------------------------------------------------------- */
+typedef enum {
+	WIFI_TEST_PREAMBLE_LONG,
+	WIFI_TEST_PREAMBLE_SHORT,
+} WIFI_PreambleType_t;
+
+/* WIFI_TEST_TxDataRate */
+#define WIFI_TEST_RATE_AUTO         0
+#define WIFI_TEST_RATE_1MBPS		1
+#define WIFI_TEST_RATE_2MBPS		2
+#define WIFI_TEST_RATE_5_5MBPS		3
+#define WIFI_TEST_RATE_6MBPS		4
+#define WIFI_TEST_RATE_9MBPS		5
+#define WIFI_TEST_RATE_11MBPS		6
+#define WIFI_TEST_RATE_12MBPS		7
+#define WIFI_TEST_RATE_18MBPS		8
+#define WIFI_TEST_RATE_24MBPS		9
+#define WIFI_TEST_RATE_36MBPS		10
+#define WIFI_TEST_RATE_48MBPS		11
+#define WIFI_TEST_RATE_54MBPS		12
+
+/* Supported MCS rates */
+typedef enum _tagENUM_WIFI_TEST_MCS_RATE {
+	WIFI_TEST_MCS_RATE_0 = 0,
+	WIFI_TEST_MCS_RATE_1 = 1,
+	WIFI_TEST_MCS_RATE_2 = 2,
+	WIFI_TEST_MCS_RATE_3 = 3,
+	WIFI_TEST_MCS_RATE_4 = 4,
+	WIFI_TEST_MCS_RATE_5 = 5,
+	WIFI_TEST_MCS_RATE_6 = 6,
+	WIFI_TEST_MCS_RATE_7 = 7,
+	WIFI_TEST_MCS_RATE_8 = 8,
+	WIFI_TEST_MCS_RATE_9 = 9,
+	WIFI_TEST_MCS_RATE_10 = 10,
+	WIFI_TEST_MCS_RATE_11 = 11,
+	WIFI_TEST_MCS_RATE_12 = 12,
+	WIFI_TEST_MCS_RATE_13 = 13,
+	WIFI_TEST_MCS_RATE_14 = 14,
+	WIFI_TEST_MCS_RATE_15 = 15,
+	WIFI_TEST_MCS_RATE_32= 32
+} ENUM_WIFI_TEST_MCS_RATE, *P_ENUM_WIFI_TEST_MCS_RATE;
+
+/* Preamble Type */
+typedef enum _tagENUM_WIFI_TEST_PREAMBLE_TYPE {
+    WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE = 0,
+    WIFI_TEST_PREAMBLE_TYPE_GREENFIELD = 1
+} ENUM_WIFI_TEST_PREAMBLE_TYPE, *P_ENUM_WIFI_TEST_PREAMBLE_TYPE;
+
+/* Guard Interval Type */
+typedef enum _tagENUM_WIFI_TEST_GI_TYPE {
+    WIFI_TEST_GI_TYPE_NORMAL_GI = 0,
+    WIFI_TEST_GI_TYPE_SHORT_GI  = 1
+} ENUM_WIFI_TEST_GI_TYPE, *P_ENUM_WIFI_TEST_GI_TYPE;
+
+/* Legacy/11n Bandwidth Type */
+typedef enum _tagENUM_WIFI_BANDWIDTH {
+    WIFI_TEST_BW_20MHZ  = 0,
+    WIFI_TEST_BW_40MHZ  = 1,
+    WIFI_TEST_BW_U20MHZ = 2,
+    WIFI_TEST_BW_D20MHZ = 3,
+    WIFI_TEST_BW_80MHZ  = 4,
+    WIFI_TEST_BW_160MHZ = 5,
+    WIFI_TEST_BW_NUM    = 6
+} ENUM_WIFI_BANDWIDTH, *P_ENUM_WIFI_BANDWIDTH;
+
+/* Channel Bandwidth Type */
+typedef enum _tagENUM_WIFI_CHANNEL_BANDWIDTH {
+    WIFI_TEST_CH_BW_20MHZ = 0,
+    WIFI_TEST_CH_BW_40MHZ,
+    WIFI_TEST_CH_BW_80MHZ,
+    WIFI_TEST_CH_BW_160MHZ,
+    WIFI_TEST_CH_BW_NUM
+}ENUM_WIFI_CHANNEL_BANDWIDTH, *P_ENUM_WIFI_CHANNEL_BANDWIDTH;
+
+/* Primary channel offset (in unit of 20MHZ) */
+typedef enum _tagENUM_WIFI_PRI_CHANNEL_SETTING {
+    WIFI_TEST_PRI_CH_SETTING_0 = 0,
+    WIFI_TEST_PRI_CH_SETTING_1,
+    WIFI_TEST_PRI_CH_SETTING_2,
+    WIFI_TEST_PRI_CH_SETTING_3,
+    WIFI_TEST_PRI_CH_SETTING_4,
+    WIFI_TEST_PRI_CH_SETTING_5,
+    WIFI_TEST_PRI_CH_SETTING_6,
+    WIFI_TEST_PRI_CH_SETTING_7,
+    WIFI_TEST_PRI_CH_SETTING_NUM
+}ENUM_WIFI_PRI_CHANNEL_SETTING, *P_ENUM_WIFI_PRI_CHANNEL_SETTING;
+
+/* Wi-Fi TEST MODE */
+typedef enum _tagENUM_WIFI_TEST_MODE {
+    WIFI_TEST_MODE_BY_API_CONTROL   = 0,
+    WIFI_TEST_MODE_CW_ONLY          = 1,
+    WIFI_TEST_MODE_80211A_ONLY      = 2,
+    WIFI_TEST_MODE_80211B_ONLY      = 3,
+    WIFI_TEST_MODE_80211G_ONLY      = 4,
+    WIFI_TEST_MODE_80211N_ONLY      = 5,
+    WIFI_TEST_MODE_80211AC_ONLY     = 6,
+    WIFI_TEST_MODE_NUM              = 7
+} ENUM_WIFI_TEST_MODE, *P_ENUM_WIFI_TEST_MODE;
+
+/* J MODE setting */
+typedef enum _tagENUM_WIFI_J_MODE {
+    WIFI_TEST_J_MODE_DISABLE            = 0,
+    WIFI_TEST_J_MODE_5M_SINGLE_TONE     = 1,
+    WIFI_TEST_J_MODE_10M_SINGLE_TINE    = 2,
+    WIFI_TEST_J_MODE_NUM                = 3
+} ENUM_WIFI_J_MODE, *P_ENUM_WIFI_J_MODE;
+
+typedef enum _ENUM_RF_AT_FUNCID_T {
+
+    RF_AT_FUNCID_VERSION = 0,
+    RF_AT_FUNCID_COMMAND,
+    RF_AT_FUNCID_POWER,
+    RF_AT_FUNCID_RATE,
+    RF_AT_FUNCID_PREAMBLE,
+    RF_AT_FUNCID_ANTENNA,
+    RF_AT_FUNCID_PKTLEN,
+    RF_AT_FUNCID_PKTCNT,
+    RF_AT_FUNCID_PKTINTERVAL,
+    RF_AT_FUNCID_TEMP_COMPEN,
+    RF_AT_FUNCID_TXOPLIMIT,
+    RF_AT_FUNCID_ACKPOLICY,
+    RF_AT_FUNCID_PKTCONTENT,
+    RF_AT_FUNCID_RETRYLIMIT,
+    RF_AT_FUNCID_QUEUE,
+    RF_AT_FUNCID_BANDWIDTH,
+    RF_AT_FUNCID_GI,
+    RF_AT_FUNCID_STBC,
+    RF_AT_FUNCID_CHNL_FREQ,
+    RF_AT_FUNCID_RIFS,
+    RF_AT_FUNCID_TRSW_TYPE,
+    RF_AT_FUNCID_RF_SX_SHUTDOWN,
+    RF_AT_FUNCID_PLL_SHUTDOWN,
+    RF_AT_FUNCID_SLOW_CLK_MODE,
+    RF_AT_FUNCID_ADC_CLK_MODE,
+    RF_AT_FUNCID_MEASURE_MODE,
+    RF_AT_FUNCID_VOLT_COMPEN,
+    RF_AT_FUNCID_DPD_TX_GAIN,
+    RF_AT_FUNCID_DPD_MODE,
+    RF_AT_FUNCID_TSSI_MODE,
+    RF_AT_FUNCID_TX_GAIN_CODE,
+    RF_AT_FUNCID_TX_PWR_MODE,
+
+    /* Query command */
+    RF_AT_FUNCID_TXED_COUNT = 32,
+    RF_AT_FUNCID_TXOK_COUNT,
+    RF_AT_FUNCID_RXOK_COUNT,
+    RF_AT_FUNCID_RXERROR_COUNT,
+    RF_AT_FUNCID_RESULT_INFO,
+    RF_AT_FUNCID_TRX_IQ_RESULT,
+    RF_AT_FUNCID_TSSI_RESULT,
+    RF_AT_FUNCID_DPD_RESULT,
+    RF_AT_FUNCID_RXV_DUMP,
+    RF_AT_FUNCID_RX_PHY_STATIS,
+    RF_AT_FUNCID_MEASURE_RESULT,
+    RF_AT_FUNCID_TEMP_SENSOR,
+    RF_AT_FUNCID_VOLT_SENSOR,
+    RF_AT_FUNCID_READ_EFUSE,
+    RF_AT_FUNCID_RX_RSSI,
+
+    /* Set command */
+    RF_AT_FUNCID_SET_RX_DEF_ANT = 63,
+    RF_AT_FUNCID_SET_DPD_RESULT = 64,
+    RF_AT_FUNCID_SET_CW_MODE,
+    RF_AT_FUNCID_SET_JAPAN_CH14_FILTER,
+    RF_AT_FUNCID_WRITE_EFUSE,
+    RF_AT_FUNCID_SET_MAC_DST_ADDRESS,
+    RF_AT_FUNCID_SET_MAC_SRC_ADDRESS,
+    RF_AT_FUNCID_SET_RXOK_MATCH_RULE,
+    RF_AT_FUNCID_SET_CHANNEL_BANDWIDTH = 71,
+    RF_AT_FUNCID_SET_DATA_BANDWIDTH = 72,
+    RF_AT_FUNCID_SET_PRI_SETTING = 73,
+    RF_AT_FUNCID_SET_TX_ENCODE_MODE = 74,
+    RF_AT_FUNCID_SET_J_MODE_SETTING = 75
+} ENUM_RF_AT_FUNCID_T;
+
+typedef enum _ENUM_RF_AT_COMMAND_T {
+
+    RF_AT_COMMAND_STOPTEST = 0,
+    RF_AT_COMMAND_STARTTX,
+    RF_AT_COMMAND_STARTRX,
+    RF_AT_COMMAND_RESET,
+    RF_AT_COMMAND_OUTPUT_POWER,     /* Payload */
+    RF_AT_COMMAND_LO_LEAKAGE,       /* Local freq is renamed to Local leakage */
+    RF_AT_COMMAND_CARRIER_SUPPR,    /* OFDM (LTF/STF), CCK (PI,PI/2) */
+    RF_AT_COMMAND_TRX_IQ_CAL,
+    RF_AT_COMMAND_TSSI_CAL,
+    RF_AT_COMMAND_DPD_CAL,
+    RF_AT_COMMAND_CW,
+    RF_AT_COMMAND_NUM
+
+} ENUM_RF_AT_COMMAND_T;
+
+typedef enum _ENUM_RF_AT_PREAMBLE_T {
+
+    RF_AT_PREAMBLE_NORMAL = 0,
+    RF_AT_PREAMBLE_CCK_SHORT,
+    RF_AT_PREAMBLE_11N_MM,
+    RF_AT_PREAMBLE_11N_GF,
+    RF_AT_PREAMBLE_11AC,
+    RF_AT_PREAMBLE_NUM
+
+} ENUM_RF_AT_PREAMBLE_T;
+
+
+#ifndef BIT
+#define BIT(n)          ((uint32_t) 1 << (n))
+#define BITS(m,n)       (~(BIT(m)-1) & ((BIT(n) - 1) | BIT(n)))
+#endif /* BIT */
+
+/* RF Test Properties */
+#define RF_AT_PARAM_RATE_MCS_MASK   BIT(31)
+#define RF_AT_PARAM_RATE_MASK       BITS(0,7)
+#define RF_AT_PARAM_RATE_1M         0
+#define RF_AT_PARAM_RATE_2M         1
+#define RF_AT_PARAM_RATE_5_5M       2
+#define RF_AT_PARAM_RATE_11M        3
+#define RF_AT_PARAM_RATE_6M         4
+#define RF_AT_PARAM_RATE_9M         5
+#define RF_AT_PARAM_RATE_12M        6
+#define RF_AT_PARAM_RATE_18M        7
+#define RF_AT_PARAM_RATE_24M        8
+#define RF_AT_PARAM_RATE_36M        9
+#define RF_AT_PARAM_RATE_48M        10
+#define RF_AT_PARAM_RATE_54M        11
+
+/* DBG mode log */
+#define DBGLOG(_fmt...)  \
+    if(fgDebugMode) { \
+        printf("<DBG> " _fmt); \
+    }
+
+/* Wi-Fi test Library version */
+#define LIB_WIFI_TEST_VER_MAJOR     0
+#define LIB_WIFI_TEST_VER_MINOR     1
+
+/* functions
+ * -------------------------------------------------------------------------- */
+bool WIFI_TEST_OpenDUT(void);
+bool WIFI_TEST_CloseDUT(void);
+
+/* Style #A - Control API */
+bool WIFI_TEST_TxDataRate(int TxDataRate);
+bool WIFI_TEST_SetPreamble(WIFI_PreambleType_t PreambleType);
+bool WIFI_TEST_Channel(int ChannelNo);
+bool WIFI_TEST_TxGain(float TxGain);
+bool WIFI_TEST_TxBurstInterval(int SIFS);
+bool WIFI_TEST_TxPayloadLength(int TxPayLength);
+bool WIFI_TEST_TxBurstFrames(int Frames);
+bool WIFI_TEST_TxDestAddress(unsigned char *addr);
+bool WIFI_TEST_TxStart(void);
+bool WIFI_TEST_TxStop(void);
+bool WIFI_TEST_RxStart(void);
+bool WIFI_TEST_RxStop(void);
+bool WIFI_TEST_FRError(int *FError);
+bool WIFI_TEST_FRGood(int *FRGood);
+bool WIFI_TEST_RSSI(int *RSSI);
+bool WIFI_TEST_IsRunning(void);
+bool WIFI_TEST_IsUp(void);
+bool WIFI_TEST_TxDataRate11n(ENUM_WIFI_TEST_MCS_RATE eDataRate11n, ENUM_WIFI_TEST_PREAMBLE_TYPE ePreambleType, ENUM_WIFI_TEST_GI_TYPE eGIType);
+bool WIFI_TEST_TxDataRate11ac(ENUM_WIFI_TEST_MCS_RATE eTxMcsRate,
+    ENUM_WIFI_TEST_GI_TYPE eGIType);
+bool WIFI_TEST_FrequencyAccuracy(int ChannelNo);
+bool WIFI_TEST_FrequencyAccuracy_Stop();
+
+/* Style #B - Control API */
+bool WIFI_TEST_SetMode(ENUM_WIFI_TEST_MODE eMode);
+bool WIFI_TEST_GetSupportedMode(uint32_t *pu4SupportedMode);
+bool WIFI_TEST_SetBandwidth(ENUM_WIFI_BANDWIDTH eBandwidth);
+bool WIFI_TEST_SetFrequency(uint32_t u4FreqInMHz, uint32_t u4OffsetInKHz);
+bool WIFI_TEST_SetRate(uint32_t u4Rate);
+bool WIFI_TEST_SetTXPower(uint32_t u4Gain);
+bool WIFI_TEST_SetTX(bool fgEnable);
+bool WIFI_TEST_SetRX(bool fgEnable, char *aucSrcAddr, char *aucDstAddr);
+bool WIFI_TEST_ClearResult(void);
+bool WIFI_TEST_GetResult(uint32_t *pu4GoodFrameCount, uint32_t *pu4BadFrameCount);
+
+bool WIFI_TEST_CW_MODE(int mode);
+bool WIFI_TEST_DPD_MODE(int mode);
+bool WIFI_TEST_TEMP_COMPEN_MODE(int mode);
+bool WIFI_TEST_TX_POWER_MODE(int mode);
+bool WIFI_TEST_CW_MODE_START(void);
+
+bool WIFI_TEST_init(void);
+void WIFI_TEST_deinit(void);
+
+bool WIFI_TEST_EFUSE_Read(unsigned int offset, unsigned int *val);
+bool WIFI_TEST_EFUSE_Write(unsigned int offset, unsigned int val);
+bool WIFI_TEST_MCR_Read(unsigned int addr, unsigned int *val);
+bool WIFI_TEST_MCR_Write(unsigned int addr, unsigned int val);
+
+bool WIFI_TEST_SetBandwidthV2(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth);
+bool WIFI_TEST_SetPriChannelSetting(uint8_t ucPrimaryChSetting);
+bool WIFI_TEST_SetTxBandwidth(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth);
+bool WIFI_TEST_SetTxCodingMode(uint8_t ucLdpc);
+bool WIFI_TEST_SetJMode(ENUM_WIFI_J_MODE eJModeSetting);
+
+bool WIFI_TEST_SetRxDefaultAnt(uint8_t ucUseAuxAnt);
+
+bool WIFI_TEST_TxCount(uint32_t *TxCount);
+bool WIFI_TEST_TxGoodCount(uint32_t *TxGoodCount);
+
+#endif /* __LIBWIFITEST_H__ */
diff --git a/src/connectivity/wifitesttool/libwifitest/main.c b/src/connectivity/wifitesttool/libwifitest/main.c
new file mode 100644
index 0000000..1a306d1
--- /dev/null
+++ b/src/connectivity/wifitesttool/libwifitest/main.c
@@ -0,0 +1,75 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+ * the prior written permission of MediaTek inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of MediaTek Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+ * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+ * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek
+ * Software") have been modified by MediaTek Inc. All revisions are subject to
+ * any receiver's applicable license agreements with MediaTek Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "libwifitest.h"
+
+int main(void) {
+    int i;
+    uint32_t rxOk, rxErr;
+    bool retval;
+
+    printf("entering RF testing mode ..\n");
+
+    retval = WIFI_TEST_OpenDUT();
+    printf("(%d) entered RF testing mode ..\n", retval);
+
+    retval = WIFI_TEST_SetMode(WIFI_TEST_MODE_80211N_ONLY);
+    printf("(%d) changed mode to 802.11n ..\n", retval);
+
+    retval = WIFI_TEST_SetFrequency(2412, 0);
+    printf("(%d) changed channel to #1..\n", retval);
+
+    retval = WIFI_TEST_SetRX(true, NULL, NULL);
+    printf("(%d) RX test started..\n", retval);
+
+    for(i = 0 ; i < 10 ; i++) {
+        retval = WIFI_TEST_GetResult(&rxOk, &rxErr);
+        printf("(%d) RX OK: %d / RX ERR: %d\n", retval, rxOk, rxErr);
+        sleep(1);
+    }
+
+    retval = WIFI_TEST_SetRX(false, NULL, NULL);
+    printf("(%d) RX test stopped ..\n", retval);
+
+    retval = WIFI_TEST_CloseDUT();
+    printf("(%d) left RF testing mode ..\n", retval);
+
+    return 0;
+}
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/Android.mk b/src/connectivity/wifitesttool/wifi_hw_test_tool/Android.mk
new file mode 100644
index 0000000..1c5837e
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_MODULE := wifitesttool
+LOCAL_MODULE_TAGS := optional
+LOCAL_SHARED_LIBRARIES := libwifitest libcutils
+LOCAL_CFLAGS += -Wall
+LOCAL_SRC_FILES := main.c lib.c
+LOCAL_C_INCLUDES = $(LOCAL_PATH)/../libwifitest
+$(warning $(LOCAL_C_INCLUDES))
+include $(BUILD_EXECUTABLE)
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/Makefile.am b/src/connectivity/wifitesttool/wifi_hw_test_tool/Makefile.am
new file mode 100644
index 0000000..31b5b3c
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/Makefile.am
@@ -0,0 +1,6 @@
+bin_PROGRAMS = wifitesttool
+
+AM_CFLAGS = -I../libwifitest
+
+wifitesttool_SOURCES = main.c lib.c
+wifitesttool_LDADD = ../libwifitest/libwifitest.a
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/README b/src/connectivity/wifitesttool/wifi_hw_test_tool/README
new file mode 100644
index 0000000..f550023
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/README
@@ -0,0 +1,27 @@
+This directory contains Wi-Fi test tool function
+
+
+WHAT IT DOES?
+=============
+It provide test tool for Wi-Fi HW related test
+
+
+HOW IT WAS BUILT?
+==================
+It needs the following libs from AOSP:
+1. libcutils
+
+and the following libs from MediaTek:
+1. libwifitest
+
+All source/dependency modules of this module are already put in
+'hardware/mediatek/wlan/wifi_hw_test_tool' folder.
+
+
+HOW TO USE IT?
+==============
+Files in this directory is used for Wi-Fi test tool
+
+
+All the source code of this directory were written by MediaTek co..
+
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.c b/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.c
new file mode 100644
index 0000000..37abb9c
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.c
@@ -0,0 +1,114 @@
+// Converts a hexadecimal string to integer
+//   0    - Conversion is successful
+//   1    - String is empty
+//   2    - String has more than 8 bytes
+//   4    - Conversion is in process but abnormally terminated by
+//          illegal hexadecimal character
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int xtoi(const char* xs, unsigned int* result)
+{
+    size_t szlen = strlen(xs);
+    int i, xv, fact;
+
+    if(szlen >= 2) {
+        /* filter out 0x prefix */
+        if(xs[0] == '0' && (xs[1] == 'x' || xs[1] == 'X')) {
+            xs += 2;
+            szlen -= 2;
+        }
+    }
+
+    if (szlen > 0)
+    {
+
+        //Converting more than 32bit hexadecimal value?
+        if (szlen > 8)
+            return 2;
+
+        // Begin conversion here
+        *result = 0;
+        fact = 1;
+
+        for(i=szlen-1; i>=0 ;i--)
+        {
+            if (isxdigit(*(xs+i)))
+            {
+                if (*(xs+i)>=97)
+                {
+                    xv = ( *(xs+i) - 97) + 10;
+                }
+                else if ( *(xs+i) >= 65)
+                {
+                    xv = (*(xs+i) - 65) + 10;
+                }
+                else
+                {
+                    xv = *(xs+i) - 48;
+                }
+                *result += (xv * fact);
+                fact *= 16;
+            }
+            else
+            {
+                return 4;
+            }
+        }
+    }
+    return 1;
+}
+
+
+int xtoAddrptr(const char* xs, unsigned char* ptr)
+{
+    size_t szlen = strlen(xs);
+    unsigned int i, xv, res;
+
+    if (szlen != 12)
+	return 0;
+
+    for (i=0 ;i<szlen; i+=2)
+    {
+	res = 0;
+	if (isxdigit(*(xs+i)) && isxdigit(*(xs+i+1)))
+	{
+	    if (*(xs+i)>=97)
+            {
+                xv = ( *(xs+i) - 97) + 10;
+            }
+            else if ( *(xs+i) >= 65)
+            {
+                xv = (*(xs+i) - 65) + 10;
+            }
+            else
+            {
+                xv = *(xs+i) - 48;
+            }
+	    res += xv << 4;
+
+	    if (*(xs+i+1)>=97)
+            {
+                xv = ( *(xs+i+1) - 97) + 10;
+            }
+            else if ( *(xs+i+1) >= 65)
+            {
+                xv = (*(xs+i+1) - 65) + 10;
+            }
+            else
+            {
+                xv = *(xs+i+1) - 48;
+            }
+	    res += xv;
+	    *(ptr+(i>>1)) = res;
+        }
+    }
+    return 1;
+}
+
+
+
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.h b/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.h
new file mode 100644
index 0000000..1c087ee
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/lib.h
@@ -0,0 +1,5 @@
+#ifndef _LIB_C_
+#define _LIB_C_
+int xtoi(const char* xs, unsigned int* result);
+int xtoAddrptr(const char* xs, unsigned char* ptr);
+#endif
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/main.c b/src/connectivity/wifitesttool/wifi_hw_test_tool/main.c
new file mode 100644
index 0000000..443afdc
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/main.c
@@ -0,0 +1,953 @@
+/* MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "libwifitest.h"
+#include "lib.h"
+#ifdef ANDROID
+#include <cutils/properties.h>
+#include <sys/system_properties.h>
+#endif
+#include <errno.h>
+
+#define PACKAGE     "WifiHwTestTool"
+
+char proc_name[256];
+
+typedef enum {
+	WLAN_MODE_OFF,
+	NORMAL_MODE_ON,
+	TEST_MODE_ON
+}WlanStatus;
+
+typedef enum {
+	OPER_NONE,
+	TEST_TX,
+	TEST_RX,
+	READ_EFUSE,
+	WRITE_EFUSE,
+	READ_MCR,
+	WRITE_MCR,
+	TEST_STOP,
+	QUERY_RESULT
+}Oper_Mode;
+
+typedef enum _ENUM_RX_MATCH_RULE_T {
+    RX_MATCH_RULE_DISABLE,
+    RX_MATCH_RULE_RA,           /* RA only */
+    RX_MATCH_RULE_TA,           /* TA only */
+    RX_MATCH_RULE_RA_TA,        /* Both RA and TA */
+    RX_MATCH_RULE_NUM
+} ENUM_RX_MATCH_RULE_T, *P_ENUM_RX_MATCH_RULE_T;
+
+typedef enum _ENUM_FUNCTION_MODE {
+    MODE_DISABLE = 0,
+    MODE_ENABLE
+} ENUM_FUNCTION_MODE_T, *P__ENUM_FUNCTION_MODE_T;
+
+char *bg_rate[] = {
+"RATE_AUTO",
+"RATE_1MBPS",
+"RATE_2MBPS",
+"RATE_5_5MBPS",
+"RATE_6MBPS",
+"RATE_9MBPS",
+"RATE_11MBPS",
+"RATE_12MBPS",
+"RATE_18MBPS",
+"RATE_24MBPS",
+"RATE_36MBPS",
+"RATE_48MBPS",
+"RATE_54MBPS",
+};
+char *preamble[] = {
+"LONG",
+"SHORT",
+};
+char *bandwidth[] = {
+"BW20",
+"BW40",
+"BW20U",
+"BW20L",
+"BW80",
+"BW160"
+};
+
+char *bandwidthV2[] = {
+"BW20",
+"BW40",
+"BW80",
+"BW160"
+};
+
+static void wifi_sensitivity(int, int);
+static void wifi_tx();
+static WlanStatus wifiStatus();
+void wifiTestStop();
+void wifiGetResult();
+
+void signal_handler(int sig)
+{
+    int retval = 0;
+
+    retval = WIFI_TEST_CloseDUT();
+    printf("\n(%d) aborted .., sig=%d\n", retval,sig);
+
+    signal(SIGINT, SIG_DFL);
+    exit(0);
+}
+
+//  "E:e:M:g:G:I:B:R:N:T:m:s:p:b:t:hVw:v:l:f    :c:rn:"
+
+
+void print_help(int exval)
+{
+    printf("Usage: %s [options]\n", proc_name);
+    printf("\n");
+
+    printf("<Test mode control>\n");
+    printf("    %s -O                       Enable Wi-Fi test mode\n", proc_name);
+    printf("    %s -C                       Disable Wi-Fi test mode\n", proc_name);
+    printf("\n");
+
+    printf("<MCR read/write>\n");
+    printf("    %s [-M addr]                Read value from CR address\n", proc_name);
+    printf("    %s [-w addr] [-v value]     Write value to CR address\n", proc_name);
+    printf("\n");
+
+    printf("<EFUSE read/write>\n");
+    printf("    %s [-E offset]              Read value from EFUSE at offset\n", proc_name);
+    printf("    %s [-e offset] [-v value]   Write value to EFUSE at offset\n", proc_name);
+    printf("\n");
+
+    printf("<Tx test>\n");
+    printf("A/B/G Mode:\n");
+    printf("    %s [-t 0] [-R legacy rate] [-s preamble] [options]\n", proc_name);
+
+    printf("N Mode:\n");
+    printf("    %s [-t 1] [-N MCS rate] [-g greenfield] [-G SGI] [options]\n", proc_name);
+
+    printf("AC Mode:\n");
+    printf("    %s [-t 2] [-N MCS rate] [-G SGI] [options]\n", proc_name);
+    printf("\n");
+
+    printf("<Rx test>\n");
+    printf("    %s [-r] [-n time] [options]\n", proc_name);
+    printf("\n");
+
+    printf("Common for Tx/Rx:\n");
+    printf("    -c #           Central channel number\n");
+    printf("    -b [0~3]       RF bandwidth <0:20/1:40/2:80/3:160>Mhz <default 20Mhz>\n");
+    printf("    -P [0~7]       Primary channel setting in unit of 20Mhz <default 0>\n");
+    printf("    -B [0~3]       Bandwidth <0:20/1:40/2:20U/3:20L>Mhz (Legacy commaand, *deprecated)\n");
+    printf("    -j [0~2]       J mode setting <0:disable/1:5Mhz/2:10Mhz>\n");
+    printf("    -d [0/1]       Set Rx default antenna <0:main/1:AUX>\n");
+
+    printf("    -S #           Test mode <0:non-blocking/others:blocking mode timeout in seconds>\n");
+    printf("    -T             Test terminate command for non-blocking test\n");
+    printf("    -a #           Blocking mode test result query interval in seconds\n");
+    printf("    -o #           Max Tx/Rx packet count in blocking mode test\n");
+
+    printf("    -q             Query test result\n");
+
+    printf("    -D             Enable debug mode(dump AT command sequence)\n");
+
+    printf("    -f             RX Filter type <0:default,Disalbe,1:filter RA>\n");
+    printf("    -A             Set RA address on enabling RX Filter. ex:-A 123456789ABC is set mac 12:34:56:78:9A:BC to RA address\n");
+    printf("\n");
+
+    printf("Rx specific:\n");
+    printf("    -n #           Test time in seconds.\n");
+    printf("\n");
+
+    printf("Tx specific:\n");
+
+	printf("    -n #           TX Packet number, 0 is meaning that TX Packet number = unlimited\n");
+
+    printf("    -t [0/1/2]     Tx mode <0:11abg/1:11n/2:11ac>\n");
+    printf("    -x [0~3]       Tx bandwidth <0:20/1:40/2:80/3:160>Mhz <default follow RF BW>\n");
+    printf("    -p #           Tx gain in dBm\n");
+
+
+
+    printf("    -n #           Frame count\n");
+    printf("    -l #           Frame length in bytes\n");
+
+    printf("    -R [1~12]      Legacy rate code\n");
+    printf("                   <1M/2M/5.5M/6M/9M/11M/12M/18M/24M/36M/48M/54M>\n");
+    printf("    -s [0/1]       <0:short/1:long> preamble\n");
+
+    printf("    -N [0~15/32]   MCS rate index\n");
+    printf("    -g [0/1]       <0:mixed mode/1:greenfield> \n");
+    printf("    -G [0/1]       <0:normal/1:short> guard interval\n");
+    printf("    -L             Enable LDPC <default BCC>\n");
+
+    printf("    -m [0/3]       <0:disable/3:enable> continuous waveform mode\n");
+    printf("\n");
+
+    exit(exval);
+}
+
+static int channel = 1;
+static int times = 10;
+//static int numBurst = 0;
+static int txMode = 0;
+static unsigned char macAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+#define Default_TxGain -1.0
+static float txGain = Default_TxGain;
+static int payloadLength = 1024;
+static int g_rate = 6;
+static ENUM_WIFI_TEST_MCS_RATE gMCSrate = WIFI_TEST_MCS_RATE_0;
+static int g_bandwidth = WIFI_TEST_BW_20MHZ;
+static ENUM_WIFI_TEST_PREAMBLE_TYPE gMode = WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE;
+static ENUM_WIFI_TEST_GI_TYPE giType = WIFI_TEST_GI_TYPE_NORMAL_GI;
+extern char WIFI_IF_NAME[256];
+static WIFI_PreambleType_t pType = WIFI_TEST_PREAMBLE_SHORT;
+static unsigned int mcr_addr = 0;
+static unsigned int mcr_value = 0;
+static unsigned int efuse_addr = 0;
+static int cw_mode = -1;
+static int sleep_time = 10;
+static bool sleepModeSet = false;
+
+static int priSetting = 0;
+static bool isNewBwSet = false;
+static ENUM_WIFI_CHANNEL_BANDWIDTH rfBw = WIFI_TEST_CH_BW_20MHZ;
+static bool isTxBwSet = false;
+static ENUM_WIFI_CHANNEL_BANDWIDTH txBw = WIFI_TEST_CH_BW_20MHZ;
+static int coding = 0; /* BCC */
+static int rxDefaultAnt = 0;
+static int jModeSetting = 0;
+static int printInterval = 1;
+static uint32_t maxPktCount = 0;
+static int user_expect = 0;
+
+static ENUM_RX_MATCH_RULE_T eRxOkMatchRule = RX_MATCH_RULE_DISABLE;
+static bool bRxFilterMacAddrLegalFg = false;
+static unsigned char aucRxFilterMacAddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+#define WIFI_TEST_BW_MAX 5
+
+extern bool fgDebugMode;
+
+int main(int argc, char *argv[])
+{
+    int opt = 0;
+    int result = 0;
+    Oper_Mode operation = OPER_NONE;
+    WlanStatus wlan_status = 0;
+	int band_width[] = {WIFI_TEST_BW_20MHZ, WIFI_TEST_BW_40MHZ,
+        WIFI_TEST_BW_U20MHZ, WIFI_TEST_BW_D20MHZ, WIFI_TEST_BW_80MHZ,
+        WIFI_TEST_BW_160MHZ};
+
+    strncpy(proc_name, argv[0], 255);
+    proc_name[255] = '\0';
+
+    if (argc == 1){
+        fprintf(stderr, "Needs arguments....\n\n");
+        print_help(1);
+    }
+	// set up the Ctrl + C handler
+	signal(SIGINT, signal_handler);
+    while ((opt = getopt(argc, argv, "A:f:E:e:M:g:G:I:B:R:N:Tm:S:s:p:b:t:hVw:v:k:l:f:c:rOCn:DP:x:Ld:j:qa:o")) != -1) {
+	    switch(opt) {
+	        case 'e':
+	        	if (operation == OPER_NONE){
+		            operation = WRITE_EFUSE;
+		            xtoi(optarg, &efuse_addr);
+		        }
+	            break;
+	        case 'E':
+	        	if (operation == OPER_NONE){
+		            operation = READ_EFUSE;
+		            xtoi(optarg, &efuse_addr);
+	            }
+	            break;
+	        case 'w':
+	        	if (operation == OPER_NONE){
+		            operation = WRITE_MCR;
+		            xtoi(optarg, &mcr_addr);
+	            }
+	            break;
+	        case 'M':
+	        	if (operation == OPER_NONE){
+		            operation = READ_MCR;
+		            xtoi(optarg, &mcr_addr);
+	            }
+	            break;
+	        case 'r':
+	        	if (operation == OPER_NONE)
+	            	operation = TEST_RX;
+	            break;
+			case 't':
+				if (operation == OPER_NONE)
+					operation = TEST_TX;
+				txMode = atoi(optarg);
+				break;
+
+	        case 'q':
+				if (operation == OPER_NONE)
+					operation = QUERY_RESULT;
+	            break;
+
+	        case 'g':
+	        	gMode = !atoi(optarg) ? WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE:WIFI_TEST_PREAMBLE_TYPE_GREENFIELD;
+	            break;
+	        case 'G':
+	        	giType = !atoi(optarg) ? WIFI_TEST_GI_TYPE_NORMAL_GI:WIFI_TEST_GI_TYPE_SHORT_GI;
+	            break;
+	        case 'I':
+	            strncpy(WIFI_IF_NAME, optarg, strlen(WIFI_IF_NAME) - 1);
+	            WIFI_IF_NAME[sizeof(WIFI_IF_NAME) - 1] = '\0';
+	            break;
+	        case 'B':
+	        	{
+	        		int index = atoi(optarg);
+	        		if (index > WIFI_TEST_BW_MAX){
+	        			printf("not support this band");
+	        			return -1;
+	        		}
+					g_bandwidth = band_width[index];
+		            break;
+				}
+	        case 'N':
+                gMCSrate = atoi(optarg);
+	            break;
+	        case 'R':
+	            g_rate = atoi(optarg);
+	            break;
+	        case 'p':
+	            txGain = strtod(optarg, NULL);
+	            break;
+	        case 'l':
+	            payloadLength = atoi(optarg);
+	            break;
+
+	        case 'b':
+                rfBw = atoi(optarg);
+                isNewBwSet = true;
+	            break;
+
+	        case 'j':
+                jModeSetting = atoi(optarg);
+	            break;
+
+	        case 'P':
+                priSetting = atoi(optarg);
+	            break;
+
+	        case 'x':
+                txBw = atoi(optarg);
+                isTxBwSet = true;
+	            break;
+
+	        case 'L':
+                coding = 1;
+	            break;
+
+	        case 'd':
+                rxDefaultAnt = atoi(optarg);
+	            break;
+
+	        case 'a':
+                printInterval = atoi(optarg);
+	            break;
+
+	        case 'o':
+                maxPktCount = atoi(optarg);
+	            break;
+
+	        case 'h':
+	        case ':':
+	            print_help(0);
+	            break;
+	        case 'n':
+	            times = atoi(optarg);
+	            break;
+	        case 'c':
+	            channel = atoi(optarg);
+	            break;
+	        case 'V':
+	            break;
+	        case 'v':
+	            xtoi(optarg, &mcr_value);
+	            break;
+	        case 's':
+	            pType = !atoi(optarg) ? WIFI_TEST_PREAMBLE_SHORT:WIFI_TEST_PREAMBLE_LONG;
+				break;
+	    	case 'm':
+	            cw_mode = atoi(optarg);
+	            break;
+	        case '?':
+	            fprintf(stderr, "%s: Error - No such option: `%c`\r", proc_name, optopt);
+	            print_help(1);
+	            break;
+			case 'S':
+				sleep_time = atoi(optarg);
+                sleepModeSet = true;
+				break;
+			case 'O':
+				user_expect = 1;
+				break;
+			case 'C':
+				user_expect |= 2;
+				break;
+			case 'T':
+				operation = TEST_STOP;
+				break;
+        	case 'D':
+	            fgDebugMode = true;
+	            break;
+	    	case 'f':
+	            eRxOkMatchRule = atoi(optarg);
+	            break;
+	    	case 'A':
+	            result = xtoAddrptr(optarg, aucRxFilterMacAddr);
+	            if (!result)
+	            {
+	        	    printf("Address format doesn't support\n");
+	        	    return -1;
+	            }
+	            else
+	            {
+	        	    bRxFilterMacAddrLegalFg = true;
+	            }
+	            break;
+                case 'k':
+                    result = xtoAddrptr(optarg, macAddr);
+                    if (!result)
+                    {
+                        printf("Address format doesn't support\n");
+                        return -1;
+                    }
+                    break;
+	    }
+	}
+
+    /* Decide RF/Tx bandwidth */
+    if(isNewBwSet) {
+        if(!isTxBwSet) {
+            txBw = rfBw;
+        }
+        else if(txBw > rfBw){
+            txBw = rfBw;
+        }
+    }
+    else if(isTxBwSet) {
+        isNewBwSet = true;
+        rfBw = txBw;
+    }
+
+    /* BW coding check */
+    if((txBw >= WIFI_TEST_CH_BW_NUM) || (rfBw >= WIFI_TEST_CH_BW_NUM)) {
+        printf("Invalid bandwidth setting RF[%u] Tx[%u]", rfBw, txBw);
+        return -1;
+    }
+
+	wlan_status = wifiStatus();
+	switch (wlan_status){
+		case WLAN_MODE_OFF:
+			if ((user_expect & 0x1) == 1){
+				bool ret = false;
+				if ((user_expect & 0x2)==0x2 && operation == OPER_NONE){
+					return 0;
+				}
+				ret = WIFI_TEST_OpenDUT();
+				printf("[%s] Enable Wi-Fi test mode %s\n",
+                    WIFI_IF_NAME, ret==true ? "success":"fail");
+				if (ret == true){
+					wlan_status = TEST_MODE_ON;
+					break;
+				}
+			}
+			printf("[%s] Not in test mode, use -O to enable.\n",
+                WIFI_IF_NAME);
+			return 0;
+
+		case TEST_MODE_ON:
+			if ((user_expect & 0x1) == 1)
+				printf("[%s] Already in test mode\n", WIFI_IF_NAME);
+			break;
+
+		case NORMAL_MODE_ON:
+			printf("Please turn off normal mode wlan first!\n");
+			return 0;
+	}
+
+	WIFI_TEST_init();
+
+    /* J mode setting */
+    if(jModeSetting) {
+        bool retval = false;
+        retval = WIFI_TEST_SetJMode(jModeSetting);
+        printf("(%s) Set J mode to %d\n", retval ? "success":"fail",
+            jModeSetting);
+	if (retval == 0) return -1;
+    }
+
+	switch (operation){
+		case WRITE_EFUSE:
+		{
+			bool retval = WIFI_TEST_EFUSE_Write(efuse_addr, mcr_value);
+	        printf("(%s) Wirte EFUSE addr 0x%x value 0x%x\n", retval ? "success":"fail", efuse_addr, mcr_value);
+	        break;
+		}
+		case READ_EFUSE:
+		{
+			unsigned int val = 0;
+	        bool retval = WIFI_TEST_EFUSE_Read(efuse_addr, &val);
+	        printf("(%s) EFUSE addr 0x%x value 0x%x\n", retval ? "success":"fail", efuse_addr, val);
+	        break;
+	    }
+		case WRITE_MCR:
+		{
+			bool retval = WIFI_TEST_MCR_Write(mcr_addr, mcr_value);
+	        printf("(%s) MCR addr 0x%x is set to value 0x%x\n", retval ? "success":"fail", mcr_addr, mcr_value);
+	        break;
+		}
+		case READ_MCR:
+		{
+			unsigned int val = 0;
+	        bool retval = WIFI_TEST_MCR_Read(mcr_addr, &val);
+	        printf("(%s) MCR addr 0x%x value 0x%x\n", retval ? "success":"fail", mcr_addr, val);
+	        break;
+		}
+		case TEST_RX:
+        {
+            int testDuration;
+
+            if(sleepModeSet) {
+                testDuration = sleep_time;
+            }
+            else {
+                testDuration = times;
+            }
+
+			wifi_sensitivity(testDuration, channel);
+			break;
+        }
+		case TEST_TX:
+			wifi_tx();
+			break;
+		case TEST_STOP:
+			wifiTestStop();
+			break;
+
+        case QUERY_RESULT:
+            wifiGetResult();
+            break;
+
+        default:
+		case OPER_NONE:
+			//printf("not give any operation\n");
+			break;
+	}
+	WIFI_TEST_deinit();
+
+	if ((user_expect & 0x2) == 0x2 && wlan_status == TEST_MODE_ON){
+		int ret = WIFI_TEST_CloseDUT();
+		printf("[%s] Disable Wi-Fi test mode %s\n", WIFI_IF_NAME,
+            ret==true ? "success":"fail");
+	}
+    return 0;
+}
+
+void wifi_sensitivity(int times, int channel)
+{
+    int i, nextInterval;
+    int rxOk, rxErr;
+    int rxRssisFinal;
+    bool retval;
+    bool finalResult = false;
+    bool ret[3];
+
+    retval = WIFI_TEST_Channel(channel);
+    printf("(%s) Set central channel number to %d\n", retval ? "success":"fail",
+        channel);
+	if (retval == 0) return;
+
+    retval = WIFI_TEST_SetRxDefaultAnt(rxDefaultAnt);
+    printf("(%s) Set Rx default antenna to %s\n", retval ? "success":"fail",
+        rxDefaultAnt?"AUX":"main");
+	if (retval == 0) return;
+
+    if(isNewBwSet) {
+        retval = WIFI_TEST_SetBandwidthV2(rfBw);
+        printf("(%s) Set RF bandwidth to %s\n", retval ? "success":"fail",
+            bandwidthV2[rfBw]);
+    	if (retval == 0) return;
+
+        retval = WIFI_TEST_SetPriChannelSetting(priSetting);
+        printf("(%s) Set primary channel index to %u\n",
+            retval ? "success":"fail", priSetting);
+	if (retval == 0) return;
+    }
+    else {
+        retval = WIFI_TEST_SetBandwidth(g_bandwidth);
+        printf("(%s) Set bandwidth to %s\n", retval ? "success":"fail",
+            bandwidth[g_bandwidth]);
+    	if (retval == 0) return;
+    }
+    if (eRxOkMatchRule == RX_MATCH_RULE_DISABLE) {
+        retval = WIFI_TEST_SetRX(false, NULL, NULL);
+        printf("(%s) Disable RX filter\n", retval ? "success":"fail");
+    } else if (eRxOkMatchRule == RX_MATCH_RULE_RA) {
+        if (bRxFilterMacAddrLegalFg) {
+            retval = WIFI_TEST_SetRX(true, NULL, (char *)aucRxFilterMacAddr);
+            printf("(%s) Enable RX filter, Set RA Address to %02x:%02x:%02x:%02x:%02x:%02x\n", retval ? "success":"fail",
+                aucRxFilterMacAddr[0],
+            	aucRxFilterMacAddr[1],
+            	aucRxFilterMacAddr[2],
+            	aucRxFilterMacAddr[3],
+            	aucRxFilterMacAddr[4],
+            	aucRxFilterMacAddr[5]
+            	);
+            if (retval == 0) return;
+        } else {
+            printf("Enalbe RX filter, need to set RA address\n");
+            return;
+        }
+    } else if (eRxOkMatchRule == RX_MATCH_RULE_TA) {
+        if (bRxFilterMacAddrLegalFg) {
+            retval = WIFI_TEST_SetRX(true, (char *)aucRxFilterMacAddr, NULL);
+            printf("(%s) Enable TA filter, Set TA Address to %02x:%02x:%02x:%02x:%02x:%02x\n", retval ? "success":"fail",
+                aucRxFilterMacAddr[0],
+                aucRxFilterMacAddr[1],
+                aucRxFilterMacAddr[2],
+                aucRxFilterMacAddr[3],
+                aucRxFilterMacAddr[4],
+                aucRxFilterMacAddr[5]
+                );
+            if (retval == 0) return;
+        } else {
+            printf("Enalbe TA filter, need to set TA address\n");
+            return;
+        }
+    }
+
+    retval = WIFI_TEST_RxStart();
+    printf("(%s) RX test started\n", retval ? "success":"fail");
+	if (retval == 0) return;
+
+    nextInterval = printInterval;
+
+    for(i = 0; (i < times) || !finalResult; i += nextInterval) {
+
+        if(i >= times) {
+            finalResult = true;
+        }
+
+        ret[0] = WIFI_TEST_FRGood(&rxOk);
+        ret[1] = WIFI_TEST_FRError(&rxErr);
+        ret[2] = WIFI_TEST_RSSI(&rxRssisFinal);
+		if ((rxOk + rxErr) == 0){
+			fprintf(stdout, "[%3d] (%d)RX OK: %4d / (%d)RX ERR: %4d\n",
+                i, ret[0], rxOk, ret[1], rxErr);
+		}
+        else{
+            fprintf(stdout, "[%3d] (%d)RX OK: %4d / (%d)RX ERR: %4d / PER: %2d .. /"
+                " (%d)RSSI: %i\r\n", i, ret[0], rxOk, ret[1], rxErr,
+                (100 * rxErr)/(rxOk + rxErr), ret[2], (signed char)rxRssisFinal);
+		}
+        fflush(stdout);
+
+        if((times - i) < printInterval) {
+            nextInterval = times - i;
+        }
+
+        if((rxOk + rxErr >= (int)maxPktCount) && maxPktCount) {
+            printf("Rx packet count[%u] >= max count[%u], break!\n",
+                rxOk + rxErr, maxPktCount);
+            break;
+        }
+
+        sleep(nextInterval);
+    }
+
+	if (times == 0) {
+        printf("Rx test is running! use -T to stop Rx test...\n");
+    }
+    else {
+        retval = WIFI_TEST_RxStop();
+    }
+}
+
+void wifi_tx(void)
+{
+    bool retval;
+    bool finalResult = false;
+
+    WIFI_TEST_TxDestAddress(macAddr);
+
+    retval = WIFI_TEST_Channel(channel);
+    printf("(%s) Set central channel number to %d\n", retval ? "success":"fail",
+        channel);
+    if (retval == 0) return;
+
+    retval = WIFI_TEST_SetRxDefaultAnt(rxDefaultAnt);
+    printf("(%s) Set Rx default antenna to %s\n", retval ? "success":"fail",
+        rxDefaultAnt?"AUX":"main");
+	if (retval == 0) return;
+
+    if(isNewBwSet) {
+        retval = WIFI_TEST_SetBandwidthV2(rfBw);
+        printf("(%s) Set RF bandwidth to %s\n", retval ? "success":"fail",
+            bandwidthV2[rfBw]);
+    	if (retval == 0) return;
+
+        retval = WIFI_TEST_SetTxBandwidth(txBw);
+        printf("(%s) Set Tx bandwidth to %s\n", retval ? "success":"fail",
+            bandwidthV2[txBw]);
+    	if (retval == 0) return;
+
+        retval = WIFI_TEST_SetPriChannelSetting(priSetting);
+        printf("(%s) Set primary channel index to %u\n",
+            retval ? "success":"fail", priSetting);
+	if (retval == 0) return;
+    }
+    else {
+        retval = WIFI_TEST_SetBandwidth(g_bandwidth);
+        printf("(%s) Set bandwidth to %s\n", retval ? "success":"fail",
+            bandwidth[g_bandwidth]);
+    	if (retval == 0) return;
+    }
+
+    // if txGain = Default_TxGain, then use NVRAM tx pwr setting
+    if(txGain != Default_TxGain){
+        retval = WIFI_TEST_TxGain(txGain);
+        printf("(%s) Set Tx power gain to %.2f dBm\n", retval ? "success":"fail",
+            txGain);
+        if (retval == 0) return;
+    }
+    else{
+        printf("(success) Set Tx power gain by NVRAM Setting\n");
+    }
+
+    retval = WIFI_TEST_TxPayloadLength(payloadLength);
+    printf("(%s) Set Tx payload to %d bytes..\n", retval ? "success":"fail", payloadLength);
+	if (retval == 0) return;
+
+    retval = WIFI_TEST_DPD_MODE(MODE_DISABLE);
+    printf("(%s) Disable DPD\n", retval ? "success":"fail");
+    if (retval == 0) return;
+
+    retval = WIFI_TEST_TEMP_COMPEN_MODE(MODE_DISABLE);
+    printf("(%s) Disable TEMP_COMP\n", retval ? "success":"fail");
+    if (retval == 0) return;
+
+    retval = WIFI_TEST_TX_POWER_MODE(MODE_DISABLE);
+    printf("(%s) TX power mode 0\n", retval ? "success":"fail");
+    if (retval == 0) return;
+
+    retval = WIFI_TEST_TxBurstFrames(times);
+    printf("(%s) Set frame count to %d \n", retval ? "success":"fail", times);
+    if (retval == 0) return;
+
+    switch(txMode) {
+    case 0: /* A/B/G mode */
+        retval = WIFI_TEST_SetPreamble(pType);
+        printf("(%s) Set %s preamble\n", retval ? "success":"fail", preamble[pType]);
+    	if (retval == 0) return;
+
+        retval = WIFI_TEST_TxDataRate(g_rate);
+        printf("(%s) Set Tx mode to 11a/b/g, tx rate %s\n", retval ? "success":"fail", bg_rate[g_rate]);
+        if (retval == 0) return;
+        break;
+
+    case 1: /* N mode */
+        retval = WIFI_TEST_TxDataRate11n(gMCSrate, gMode, giType);
+        printf("(%s) Set Tx mode to 11n, MCS%u, %s, %s GI, %s\n", retval ? "success":"fail",
+            gMCSrate, gMode?"greenfield":"mixed-mode", giType?"Short":"Normal",
+            coding?"LDPC":"BCC");
+        if (retval == 0) return;
+
+        retval = WIFI_TEST_SetTxCodingMode(coding);
+        if (retval == 0) return;
+
+        break;
+
+    case 2: /* AC mode */
+        retval = WIFI_TEST_TxDataRate11ac(gMCSrate, giType);
+        printf("(%s) Set Tx mode to 11ac MCS%u, %s GI, %s\n", retval ? "success":"fail",
+            gMCSrate, giType?"Short":"Normal", coding?"LDPC":"BCC");
+        if (retval == 0) return;
+
+        retval = WIFI_TEST_SetTxCodingMode(coding);
+        if (retval == 0) return;
+
+        break;
+
+    default:
+        printf("Unsupported Tx mode[%u]!\n", txMode);
+        return;
+    }
+
+    //for CW mode
+    if(-1 != cw_mode){
+		retval = WIFI_TEST_CW_MODE(cw_mode);
+		printf("(%s) cw mode set to %d\n", retval ? "success":"fail", cw_mode);
+		if (retval == 0) return;
+
+		retval = WIFI_TEST_CW_MODE_START();
+		printf("(%s) cw mode start.\n", retval ? "success":"fail");
+		if (retval == 0) return;
+    }else{
+    	printf("no cw mode configuration.\n");
+    	retval = WIFI_TEST_TxStart();
+    	printf("(%s) TX test started..\n", retval ? "success":"fail");
+	if (retval == 0) return;
+    }
+
+	if (sleep_time == 0) {
+        printf("Tx test is running! use -T to stop Tx test...\n");
+        return;
+    }
+    else {
+        int i, nextInterval;
+        uint32_t u4TxOk, u4Tx;
+
+        nextInterval = printInterval;
+
+        printf("Tx test is running! wait for %us...\n", sleep_time);
+
+        for(i = 0; (i < sleep_time) || !finalResult; i += nextInterval) {
+            if(i >= sleep_time) {
+                finalResult = true;
+            }
+
+            retval = WIFI_TEST_TxCount(&u4Tx);
+            retval = WIFI_TEST_TxGoodCount(&u4TxOk);
+
+            if(retval == 0) {
+                printf("(%s) Cannot get test result!\n", retval ?"success":"fail");
+            }
+            else {
+                printf("[%u] Tx total/good count: %u/%u\n", i, u4Tx, u4TxOk);
+            }
+
+            if(i >= sleep_time) {
+                break;
+            }
+
+            if((u4Tx >= maxPktCount) && maxPktCount) {
+                printf("Tx packet count[%u] >= max count[%u], break!\n",
+                    u4Tx, maxPktCount);
+                break;
+            }
+
+            if((sleep_time - i) < printInterval) {
+                nextInterval = (sleep_time - i);
+            }
+
+            sleep(nextInterval);
+        }
+
+        printf("Stop Tx test!\n");
+    }
+
+    retval = WIFI_TEST_TxStop();
+}
+
+void wifiGetResult(void) {
+    uint32_t u4RxOk, u4RxFailed, u4Rssi;
+    uint32_t u4TxOk, u4Tx;
+    bool retval;
+
+    do {
+
+        retval = WIFI_TEST_FRGood((int*)&u4RxOk);
+    	if (retval == 0) break;
+
+        retval = WIFI_TEST_FRError((int*)&u4RxFailed);
+    	if (retval == 0) break;
+
+        retval = WIFI_TEST_RSSI((int*)&u4Rssi);
+    	if (retval == 0) break;
+
+        retval = WIFI_TEST_TxCount(&u4Tx);
+    	if (retval == 0) break;
+
+        retval = WIFI_TEST_TxGoodCount(&u4TxOk);
+    	if (retval == 0) break;
+
+    } while(false);
+
+    if(retval == 0) {
+        printf("(%s) Cannot get test result!\n", retval ?"success":"fail");
+    }
+    else {
+        printf("Tx total/good count: %u/%u\n", u4Tx, u4TxOk);
+        printf("Rx good/err count: %u/%u PER: %u RSSI:%i\n", u4RxOk, u4RxFailed,
+            (100 * u4RxFailed)/(u4RxOk + u4RxFailed), (signed char)u4Rssi);
+    }
+}
+
+void wifiTestStop(void){
+	bool retval = WIFI_TEST_TxStop();
+	printf("(%s) stop Tx\n", retval ? "success":"fail");
+
+	retval = WIFI_TEST_RxStop();
+	printf("(%s) stop Rx\n", retval ? "success":"fail");
+}
+
+/* if wlan.driver.status is ok, then wlan normal mode is on
+	if /sys/class/net/wlan0 is not exist, then wlan is off
+	otherwise, we think the wlan may be turned on by us */
+static WlanStatus wifiStatus(void){
+#ifdef ANDROID
+	char driver_status[PROP_VALUE_MAX];
+	bool normal_mode_on = false;
+    char netdevPath[256];
+
+	struct stat buf;
+	property_get("wlan.driver.status", driver_status, "unloaded");
+	if (strncmp(driver_status, "ok", 2) == 0){
+		normal_mode_on = true;
+	}
+
+    snprintf(netdevPath, 255, "/sys/class/net/%s", WIFI_IF_NAME);
+
+	if (stat(netdevPath, &buf) < 0 && errno==ENOENT)
+		return WLAN_MODE_OFF;
+	return normal_mode_on ? NORMAL_MODE_ON:TEST_MODE_ON;
+#else
+	bool normal_mode_on = false;
+	char netdevPath[256];
+	struct stat buf;
+
+    	snprintf(netdevPath, 255, "/sys/class/net/%s", WIFI_IF_NAME);
+
+	if (stat(netdevPath, &buf) < 0 && errno==ENOENT)
+		return WLAN_MODE_OFF;
+
+	return TEST_MODE_ON;
+#endif
+}
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/rx.sh b/src/connectivity/wifitesttool/wifi_hw_test_tool/rx.sh
new file mode 100644
index 0000000..00fb3bfa
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/rx.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+#
+# a sample RX test script
+#
+./wifitesttool -r -n 10000 -I wlan229 -c 10
diff --git a/src/connectivity/wifitesttool/wifi_hw_test_tool/tx.sh b/src/connectivity/wifitesttool/wifi_hw_test_tool/tx.sh
new file mode 100644
index 0000000..5e6b61d
--- /dev/null
+++ b/src/connectivity/wifitesttool/wifi_hw_test_tool/tx.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+#
+# a sample TX test script
+#
+./wifitesttool -I wlan229 -t 1 -n 0  -c 6 -p 10 -s 1 -B 0 -g 0 -G 0 -N 32 -i 30