[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/connectivity/bt_others/boots/.gitignore b/src/connectivity/bt_others/boots/.gitignore
new file mode 100644
index 0000000..652f005
--- /dev/null
+++ b/src/connectivity/bt_others/boots/.gitignore
@@ -0,0 +1,4 @@
+out
+boots
+boots_srv
+*.o
diff --git a/src/connectivity/bt_others/boots/.gn b/src/connectivity/bt_others/boots/.gn
new file mode 100644
index 0000000..9cf8956
--- /dev/null
+++ b/src/connectivity/bt_others/boots/.gn
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2017 MediaTek, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This file is used by the GN meta build system to find the root of the source
+# tree and to set startup options. For documentation on the values set in this
+# file, run "gn help dotfile" at the command line.
+
+buildconfig = "//build/config/BUILDCONFIG.gn"
+secondary_source = "//build/secondary/"
diff --git a/src/connectivity/bt_others/boots/Android.mk b/src/connectivity/bt_others/boots/Android.mk
new file mode 100644
index 0000000..d1e49c8
--- /dev/null
+++ b/src/connectivity/bt_others/boots/Android.mk
@@ -0,0 +1,91 @@
+# 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) 2017. 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.
+
+LOCAL_PATH := $(call my-dir)
+
+boots_socket_path := "\"/data/misc/\""
+
+#- boots -------------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_CFLAGS := -Werror -Wall
+LOCAL_SRC_FILES := \
+ boots.c \
+ boots_pkt.c \
+ boots_skt.c \
+ boots_eth.c \
+ boots_uart.c \
+ boots_script.c \
+ boots_stress.c \
+ boots_country.c \
+ boots_osi.c
+
+LOCAL_CFLAGS += -DBOOTS_SOCKET_PATH=$(boots_socket_path)
+LOCAL_CFLAGS += -DMTK_ANDROID_PLATFORM
+LOCAL_C_INCLUDES := system/core/libcutils/include
+LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_MODULE := boots
+LOCAL_MODULE_TAGS := optional
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_MODULE_OWNER := mtk
+LOCAL_MODULE_CLASS := EXECUTABLES
+include $(BUILD_EXECUTABLE)
+
+#- boots_srv ----------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_CFLAGS := -Werror -Wall
+LOCAL_SRC_FILES := \
+ boots_srv.c \
+ boots_btif.c \
+ boots_hci.c \
+ boots_pkt.c \
+ boots_skt.c \
+ boots_eth.c \
+ boots_mt6xx.c \
+ boots_uart.c \
+ boots_script.c \
+ boots_stress.c \
+ boots_osi.c
+
+LOCAL_CFLAGS += -DBOOTS_SOCKET_PATH=$(boots_socket_path)
+LOCAL_CFLAGS += -DMTK_ANDROID_PLATFORM
+LOCAL_C_INCLUDES := system/core/libcutils/include
+LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_MODULE := boots_srv
+LOCAL_MODULE_TAGS := optional
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_MODULE_OWNER := mtk
+LOCAL_MODULE_CLASS := EXECUTABLES
+include $(BUILD_EXECUTABLE)
diff --git a/src/connectivity/bt_others/boots/BUILD.gn b/src/connectivity/bt_others/boots/BUILD.gn
new file mode 100644
index 0000000..9bedcd0
--- /dev/null
+++ b/src/connectivity/bt_others/boots/BUILD.gn
@@ -0,0 +1,77 @@
+#
+# Copyright (C) 2017 MediaTek, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# This is the root build file for GN. GN will start processing by loading this
+# file, and recursively load all dependencies until all dependencies are either
+# resolved or known not to exist (which will cause the build to fail). So if
+# you add a new build file, there must be some path of dependencies from this
+# file to your new one or GN won't know about it.
+# This pulls in main/BUILD.gn and all of its dependencies.
+
+group("bluetooth_boots") {
+ deps = [
+ "//:boots",
+ "//:boots_srv",
+ ]
+}
+
+executable("boots") {
+ output_name = "boots"
+ sources = [
+ "boots.c",
+ "boots_pkt.c",
+ "boots_skt.c",
+ "boots_eth.c",
+ "boots_uart.c",
+ "boots_script.c",
+ "boots_stress.c",
+ "boots_country.c",
+ "boots_osi.c",
+ ]
+
+ libs = [
+ "-lpthread"
+ ]
+}
+
+executable("boots_srv") {
+ output_name = "boots_srv"
+ sources = [
+ "boots_srv.c",
+ "boots_btif.c",
+ "boots_hci.c",
+ "boots_pkt.c",
+ "boots_skt.c",
+ "boots_eth.c",
+ "boots_mt6xx.c",
+ "boots_uart.c",
+ "boots_script.c",
+ "boots_stress.c",
+ "boots_osi.c",
+ ]
+
+ include_dirs = [
+ ]
+
+ deps = [
+ ]
+
+ cflags_c = [
+ ]
+
+ libs = [
+ "-lpthread"
+ ]
+}
diff --git a/src/connectivity/bt_others/boots/LICENSE b/src/connectivity/bt_others/boots/LICENSE
new file mode 100644
index 0000000..71cfb79
--- /dev/null
+++ b/src/connectivity/bt_others/boots/LICENSE
@@ -0,0 +1,35 @@
+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) 2014,2016~2017. 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.
diff --git a/src/connectivity/bt_others/boots/Makefile b/src/connectivity/bt_others/boots/Makefile
new file mode 100644
index 0000000..cf7fa2b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/Makefile
@@ -0,0 +1,81 @@
+include ./Makefile.rules
+
+OBJS_BOOTS = \
+ boots.o \
+ boots_pkt.o \
+ boots_skt.o \
+ boots_eth.o \
+ boots_uart.o \
+ boots_script.o \
+ boots_stress.o \
+ boots_country.o \
+ boots_osi.o \
+ $(NULL)
+
+OBJS_BOOTS_SRV = \
+ boots_srv.o \
+ boots_btif.o \
+ boots_hci.o \
+ boots_pkt.o \
+ boots_skt.o \
+ boots_eth.o \
+ boots_mt6xx.o \
+ boots_uart.o \
+ boots_script.o \
+ boots_stress.o \
+ boots_osi.o \
+ $(NULL)
+
+#---------------------------------------------------------------------------
+# $(BT_VCOM_RELAYER)
+# is used to define how to OPEN VCOM port.
+# If VCOM port is opened default, no need to open by boots,
+# Set BT_VCOM_RELAYER=-DVCOM_OPENED
+# If open VCOM port by set property "sys.usb.config",
+# Set BT_VCOM_RELAYER=-DOPEN_VCOM_BY_SET_PROP
+#---------------------------------------------------------------------------
+CCFLAGS = \
+ -Wall \
+ $(LOCAL_CFLAGS) \
+ $(BT_VCOM_RELAYER) \
+ $(BOOTS_SOCKET_PATH) \
+ $(NULL)
+
+LINKFLAGS = \
+ -lpthread \
+ $(NULL)
+
+#---------------------------------------------------------------------------
+ifeq ($(CC),)
+ifeq ($(CROSS_COMPILE),)
+ CC = gcc
+ STRIP = strip
+else
+ CC = $(CROSS_COMPILE)-gcc
+ STRIP = $(CROSS_COMPILE)-strip
+endif
+else ifeq ($(STRIP),)
+ STRIP = strip
+endif
+#---------------------------------------------------------------------------
+all: boots boots_srv
+
+%.o: %.c Makefile
+ $(CC) $(CCFLAGS) $(INCLUDES) -c -o $@ $<
+
+boots: $(OBJS_BOOTS)
+ $(CC) $(OBJS_BOOTS) $(LINKFLAGS) -o boots
+ $(STRIP) boots
+
+boots_srv: $(OBJS_BOOTS_SRV)
+ $(CC) $(OBJS_BOOTS_SRV) $(LINKFLAGS) -o boots_srv
+ $(STRIP) boots_srv
+
+clean:
+ rm -rf boots
+ rm -rf boots_srv
+ rm -rf boots_clisk
+ rm -rf boots_srvsk
+ rm -rf *.o
+
+#---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/Makefile.rules b/src/connectivity/bt_others/boots/Makefile.rules
new file mode 100644
index 0000000..6b9eb44
--- /dev/null
+++ b/src/connectivity/bt_others/boots/Makefile.rules
@@ -0,0 +1,19 @@
+
+#---------- System Variable define begin ---------
+ifneq ($(filter MTK_MT6630,$(MTK_BT_CHIP)),)
+LOCAL_CFLAGS += -DMTK_CHIP_COMBO
+endif
+ifneq ($(filter MTK_MT8167,$(MTK_BT_CHIP)),)
+LOCAL_CFLAGS += -DMTK_CHIP_CONSYS
+endif
+
+ifeq ($(MTK_MERGE_INTERFACE_SUPPORT), yes)
+LOCAL_CFLAGS += -D__MTK_MERGE_INTERFACE_SUPPORT__
+endif
+
+ifeq ($(TARGET_BUILD_VARIANT), eng)
+LOCAL_CFLAGS += -DBD_ADDR_AUTOGEN
+endif
+#---------- System Variable define end -----------
+
+
diff --git a/src/connectivity/bt_others/boots/NOTE b/src/connectivity/bt_others/boots/NOTE
new file mode 100644
index 0000000..2e342a8
--- /dev/null
+++ b/src/connectivity/bt_others/boots/NOTE
@@ -0,0 +1,12 @@
+[1.6.x]
+ * Support MT8167
+
+[1.5.x]
+ * Add script file support
+
+[1.4.x]
+ * Currently, 1.4.x supports
+ - stpbt interface
+ - RAW data input
+ - hci interface
+ - Modular command set
diff --git a/src/connectivity/bt_others/boots/NOTICE b/src/connectivity/bt_others/boots/NOTICE
new file mode 100755
index 0000000..c9e65d7
--- /dev/null
+++ b/src/connectivity/bt_others/boots/NOTICE
@@ -0,0 +1,35 @@
+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) 2017. 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.
\ No newline at end of file
diff --git a/src/connectivity/bt_others/boots/adbc.sh b/src/connectivity/bt_others/boots/adbc.sh
new file mode 100755
index 0000000..fd9b1f9
--- /dev/null
+++ b/src/connectivity/bt_others/boots/adbc.sh
@@ -0,0 +1,2 @@
+wget "http://mirrors.neusoft.edu.cn/android/repository/platform-tools_r23.0.1-linux.zip"
+unzip platform-tools_r23.0.1-linux.zip
diff --git a/src/connectivity/bt_others/boots/boots.c b/src/connectivity/bt_others/boots/boots.c
new file mode 100644
index 0000000..ac68a3b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots.c
@@ -0,0 +1,874 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#include "boots.h"
+#include "boots_skt.h"
+#include "boots_uart.h"
+#include "boots_eth.h"
+#include "boots_pkt.h"
+#include "boots_stress.h"
+#include "boots_country.h"
+#include "boots_osi.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots"
+
+//---------------------------------------------------------------------------
+static boots_if_s boots_if;
+static uint8_t boots_local_exe;
+int boots_loop_timer;
+rssi_set_s rssi_setting;
+
+//---------------------------------------------------------------------------
+static void boots_chk_if(int argc, char **argv)
+{
+ // Please follow the boots_if_e
+ char *c_inf[] = {"None", "stpbt", "hci", "All", "Socket", "UART", "Ethernet",
+ "User", "Tester_UART"};
+ int i = 0;
+#ifdef BOOTS_VERBOSE_MSG
+ BPRINT_D("%s: argc = %d", __func__, argc);
+ for (i = 0; i < argc; i++)
+ BPRINT_D("argv[%d]:%s", i, argv[i]);
+ i = 0;
+#endif
+
+#if 0
+ if (*argv[0] == '-') {
+ if (memcmp(argv[0], "-relay", strlen("-relay"))) {
+ boots_if.clif = BOOTS_CLIF_USER;
+ boots_if.csif = BOOTS_CSIF_SKT;
+ } else if (argc >= 2) {
+ // boots_srv as relayer in PC/NB
+ boots_if.csif = BOOTS_CSIF_UART;
+ if (argc == 2)
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "%s", argv[1]);
+ else if (argc >= 3)
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "%s %s", argv[1], argv[2]);
+ goto exit;
+ }
+ } else if (!memcmp(argv[0], "tty", strlen("tty"))) {
+ boots_if.csif = BOOTS_CSIF_UART;
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "/dev/%s", argv[0]);
+ } else if (!memcmp(argv[0], "eth", strlen("eth"))) {
+ boots_if.csif = BOOTS_CSIF_ETH;
+ memcpy(boots_if.cs, argv[1], strlen(argv[1]));
+ }
+
+ if (argc > 2 && !memcmp(argv[1], "-relay", strlen("-relay"))) {
+ boots_if.clif = BOOTS_CLIF_UART;
+ snprintf(boots_if.cli, sizeof(boots_if.cli), "/dev/%s", argv[2]);
+ } else {
+ boots_if.clif = BOOTS_CLIF_USER;
+ }
+#else
+ while (i < argc) {
+ // check interface for BT side
+ if (!memcmp(argv[i], "tty", strlen("tty"))) {
+ if (i + 1 < argc) {
+ boots_if.csif = BOOTS_CSIF_UART;
+ if (memcmp(argv[i], "/dev/", strlen("/dev/")))
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "/dev/%s", argv[i]);
+ boots_if.cs_speed = strtol(argv[i + 1], NULL, 10);
+ BPRINT_D("cs_speed: %d", boots_if.cs_speed);
+ i += 2;
+ } else {
+ BPRINT_E("Lack a parameter for %s", argv[i]);
+ return;
+ }
+ } else if (!memcmp(argv[i], "eth", strlen("eth"))) {
+ boots_if.csif = BOOTS_CSIF_ETH;
+ long cp_len = strlen(argv[i + 1]) > sizeof(boots_if.cs) ? sizeof(boots_if.cs) : strlen(argv[i + 1]);
+ memcpy(boots_if.cs, argv[i + 1], cp_len);
+ i += 2;
+ } else if (!memcmp(argv[i], "-relay", strlen("-relay"))) {
+ if (boots_if.csif == BOOTS_IF_NONE) {
+ // boots_srv as relayer in PC/NB
+ if (i + 2 < argc && strtol(argv[i + 2], NULL, 10) != 0) {
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "%s %s", argv[i + 1], argv[i + 2]);
+ i += 2;
+ } else if (i + 1 < argc) {
+ snprintf(boots_if.cs, sizeof(boots_if.cs), "%s", argv[i + 1]);
+ i++;
+ } else {
+ BPRINT_E("Lack a parameter for %s", argv[i]);
+ return;
+ }
+ boots_if.csif = BOOTS_CSIF_UART;
+ } else {
+ // boots CLI
+ if (i + 2 < argc && !memcmp(argv[i + 1], "tty", strlen("tty"))
+ && strtol(argv[i + 2], NULL, 10) != 0) {
+ snprintf(boots_if.cli, sizeof(boots_if.cli), "/dev/%s", argv[i + 1]);
+ boots_if.cli_speed = strtol(argv[i + 2], NULL, 10);
+ boots_if.clif = BOOTS_CLIF_UART;
+ i += 2;
+ } else {
+ BPRINT_E("Incorrect argument for %s", argv[i]);
+ return;
+ }
+ }
+ } else if (*argv[i] == '-') {
+ boots_if.clif = BOOTS_CLIF_USER;
+ i++;
+ } else {
+ i++;
+ }
+ }
+
+ if (boots_if.csif == BOOTS_IF_NONE) {
+ boots_if.csif = BOOTS_CSIF_SKT;
+ boots_if.clif = BOOTS_CLIF_USER;
+ }
+#endif
+ BPRINT_D("cs: %s, cs_speed: %d", boots_if.cs, boots_if.cs_speed);
+ BPRINT_I("%s(%d) <-> %s(%d) <-> server", c_inf[boots_if.clif],
+ boots_if.clif, c_inf[boots_if.csif], boots_if.csif);
+}
+
+//---------------------------------------------------------------------------
+static char *boots_chk_btif(char *interface)
+{
+#define BOOTS_SRV_LOCAL "./boots_srv "
+#define BOOTS_SRV "boots_srv "
+#define BOOTS_AND " &"
+
+#define BTPROTO_HCI 1
+
+ int i = 0;
+ static char server[64] = {0};
+
+ if (*interface == '-') { // no assign btif or clif
+ // do auto detect
+ BPRINT_D("%s: DO auto detect", __func__);
+ if (access(boots_btif[0].p, R_OK) == 0) {
+ // STPBT
+ i = 0;
+ boots_if.btif = BOOTS_BTIF_STPBT;
+ } else if ((i = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) != -1) {
+ // HCI
+ BPRINT_D("%s: HCI: %d", __func__, i);
+ close(i);
+ i = 1;
+ boots_if.btif = BOOTS_BTIF_HCI;
+ } else {
+ BPRINT_E("%s: stpbt/HCI are all not exist", __func__);
+ return NULL;
+ }
+ } else {
+ BPRINT_D("%s: btif assigned %s", __func__, interface);
+ while (boots_btif[i].inf) {
+ if (!strcmp(interface, boots_btif[i].n))
+ break;
+ i++;
+ }
+ boots_if.btif = boots_btif[i].inf;
+ if (i + 1 == ARRAY_SIZE(boots_btif)) {
+ BPRINT_E("%s: boots doesn't support \"%s\"", __func__, interface);
+ return NULL;
+ }
+ }
+
+ if (boots_if.clif == BOOTS_IF_NONE && boots_if.csif == BOOTS_CSIF_UART && strlen(boots_if.cs)) {
+ snprintf(server, sizeof(server), boots_local_exe ? BOOTS_SRV_LOCAL "%s %s &" : BOOTS_SRV "%s %s &", boots_if.cs, boots_btif[i].n);
+ } else {
+ snprintf(server, sizeof(server), boots_local_exe ? BOOTS_SRV_LOCAL "%s &" : BOOTS_SRV "%s &", boots_btif[i].n);
+ }
+ BPRINT_D("%s: server: %s", __func__, server);
+ return server;
+}
+
+//---------------------------------------------------------------------------
+static int boots_invoke_boots_srv(char *path)
+{
+ int cont = 0;
+ if (path == NULL) return 0;
+
+ // check boots_srv is running or not
+ if (osi_system("pidof boots_srv > /dev/null") != 0) {
+ if (osi_system(path) == 0) {
+ BPRINT_I("Server(%s) executing...", path);
+ while(access(BOOTS_SRVSK_NAME, F_OK) == -1) {
+ usleep(100 * 1000);
+ cont++;
+ if (cont > 20) {
+ BPRINT_E("access BOOTS_SRVSK_NAME(%s) failed: %s(%d)", BOOTS_SRVSK_NAME, strerror(errno), errno);
+ return 0;
+ }
+ }
+ } else {
+ BPRINT_E("***** WARNING: Please input # %s, if boots_srv isn't running *****",
+ path);
+ }
+ }
+ return 1;
+}
+
+//---------------------------------------------------------------------------
+static int boots_killall_boots_srv(void)
+{
+ int ret = -1;
+
+ ret = osi_system("killall boots_srv > /dev/null");
+ if (ret) {
+ BPRINT_W("*** Please input #killall boots_srv ***");
+ BPRINT_D("%s: kill boots_srv(%d)", __func__, ret);
+ }
+
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+static void boots_sig_handler(int signum)
+{
+ UNUSED(signum);
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_deinit();
+ exit(0);
+}
+
+//---------------------------------------------------------------------------
+static void boots_tell_socket_end(int fd, struct sockaddr_un *addr)
+{
+ char skend[] = {'s', 'e', 'n', 'd'};
+
+ boots_sk_send(fd, (void *)skend, sizeof(skend), addr, BOOTS_SRVSK_NAME);
+}
+
+static void boots_tell_ethernet_end(int fd, struct sockaddr_in *addr)
+{
+ char skend[] = {'s', 'e', 'n', 'd'};
+ addr->sin_family = AF_INET;
+ addr->sin_port = ETH_UDP_SRV_PORT;
+ addr->sin_addr.s_addr = inet_addr(boots_if.cs);
+ boots_eth_send(fd, (void *)skend, sizeof(skend), addr);
+}
+
+//---------------------------------------------------------------------------
+#define USAGE_DETAILS (1 << 0)
+#define USAGE_DETAILS_MTK (1 << 1)
+static void boots_cmd_usage(uint8_t detail)
+{
+ int i = 0;
+ extern boots_cmds_s commands[];
+
+ printf("Boots - MTK Bluetooth Test Suite ver:%s(rev:%s)\n", VERSION, REV);
+ printf("Modular Commands:\n");
+ for (i = 0; commands[i].cmd; i++) {
+ if (commands[i].hidden == false)
+ printf(" "BLUE"%s"NONE" - %s\n", commands[i].cmd, commands[i].comment);
+ else if (detail & USAGE_DETAILS_MTK)
+ printf(" "BLUE"%s"NONE" - %s\n", commands[i].cmd, commands[i].comment);
+
+ if (detail & USAGE_DETAILS && commands[i].details) {
+ if (commands[i].hidden == false)
+ printf("%s\n", commands[i].details);
+ else if (detail & USAGE_DETAILS_MTK)
+ printf("%s\n", commands[i].details);
+ }
+ }
+ printf("For specfic command details use: ./boots -c <CMD> -h\n");
+}
+
+//---------------------------------------------------------------------------
+static void boots_country_cmd_usage(uint8_t detail)
+{
+ int i = 0;
+ extern boots_country_cmds_s country_commands[];
+
+ printf("Boots - MTK Bluetooth Test Suite ver:%s(rev:%s)\n", VERSION, REV);
+ printf("Power Limit Commands:\n");
+ for (i = 0; country_commands[i].cmd; i++) {
+ if (country_commands[i].hidden == false)
+ printf(" "BLUE"%s"NONE" - %s\n", country_commands[i].cmd, country_commands[i].comment);
+ else if (detail & USAGE_DETAILS_MTK)
+ printf(" "BLUE"%s"NONE" - %s\n", country_commands[i].cmd, country_commands[i].comment);
+
+ if (detail & USAGE_DETAILS && country_commands[i].details) {
+ if (country_commands[i].hidden == false)
+ printf("%s\n", country_commands[i].details);
+ else if (detail & USAGE_DETAILS_MTK)
+ printf("%s\n", country_commands[i].details);
+ }
+ }
+ printf("For specfic command details use: ./boots -c <CMD> -h\n");
+}
+
+//---------------------------------------------------------------------------
+static void boots_help(void)
+{
+ printf("Boots - MTK Bluetooth Test Suite ver:%s(rev:%s)\n", VERSION, REV);
+ printf("Usage:\n");
+ printf(BLUE" boots [BT Interface] <InputMethod/RelayMode> [parameters]\n"NONE);
+ printf(" NOTE: DO NOTE reorder\n");
+ printf(" BT Interface:\n");
+ printf("\tPlease ignore this if not through UART/Ethernet to connect platform(BT)\n");
+ printf("\tttyX Through UART send to BT\n");
+ printf("\t ex: ./boots ttyACM0 115200 ...\n");
+ printf("\tethX Through Ethernet send to BT, need server IP\n");
+ printf("\t ex: ./boots eth0 10.1.1.1 ...\n");
+ printf(" InputMethod: [parameters]\n");
+ printf("\t-f File, ex: ./boots -f test.boots\n");
+ printf("\t-r Raw data, ex: ./boots -r CMD 03 0C 00\n");
+ printf("\t-c Command, for more command information on the usage of everyone command use:\n");
+ printf("\t ./boots -c [detail]\n");
+ printf("\t-relay Through serial port to input\n");
+ printf("\t ex: ./boots ttyACM0 115200 -relay ttyUSB0 115200\n");
+ printf("\t ex: ./boots -relay ttyGS2\n");
+ printf("\t ex: ./boots -relay eth0 10.1.1.1\n");
+ printf(" Others:\n");
+ printf("\tstop Stop service since boots_srv is running in background\n");
+}
+
+//---------------------------------------------------------------------------
+static ssize_t boots_read(int fd, void *buf, size_t buf_size, int inf)
+{
+ ssize_t ret = 0;
+
+ if (!buf || !buf_size || !inf) {
+ BPRINT_E("%s: Invalid argument(buf: %p, buf size: %d, inf: %d)",
+ __func__, buf, (int)buf_size, inf);
+ return -EINVAL;
+ } else if (fd < 0) {
+ BPRINT_E("%s: Bad file descriptor(%d)", __func__, fd);
+ return -EBADFD;
+ }
+
+ if (inf == BOOTS_CSIF_SKT) {
+ ret = boots_sk_recv(fd, buf, buf_size, 0, NULL, NULL);
+ } else if (inf == BOOTS_CSIF_UART || inf == BOOTS_CLIF_UART) {
+ ret = boots_uart_read(fd, buf, buf_size);
+ } else if (inf == BOOTS_CSIF_ETH) {
+ ret = boots_eth_recv(fd, buf, buf_size, 0);
+ } else {
+ BPRINT_E("%s: Incorrect interface(%d)", __func__, inf);
+ }
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+static ssize_t boots_write(int fd, const void *buf, size_t len, int inf)
+{
+ ssize_t ret = 0;
+
+ if (!buf || !len || !inf) {
+ BPRINT_E("%s: Invalid argument(buf: %p, len: %d, inf: %d)", __func__, buf, (int)len, inf);
+ return -EINVAL;
+ } else if (fd < 0) {
+ BPRINT_E("%s: Bad file descriptor(%d)", __func__, fd);
+ return -EBADFD;
+ }
+
+ if (inf == BOOTS_CSIF_SKT) {
+ ret = boots_sk_send(fd, buf, len, NULL, BOOTS_SRVSK_NAME);
+ } else if (inf == BOOTS_CSIF_UART || inf == BOOTS_CLIF_UART) {
+ ret = boots_uart_write(fd, buf, len);
+ } else if (inf == BOOTS_CSIF_ETH) {
+ struct sockaddr_in sockaddr;
+ sockaddr.sin_family = AF_INET;
+ sockaddr.sin_port = ETH_UDP_SRV_PORT;
+ sockaddr.sin_addr.s_addr = inet_addr(boots_if.cs);
+ ret = boots_eth_send(fd, buf, len, &sockaddr);
+ } else {
+ BPRINT_E("%s: Incorrect interface(%d)", __func__, inf);
+ }
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+void boots_chk_local_exe(char *argv)
+{
+ if (argv == NULL) {
+ BPRINT_E("%s: argv should not NULL", __func__);
+ return;
+ }
+
+ if (*argv == '.' && *(argv + 1) == '/') {
+ boots_local_exe = 1;
+ } else {
+ boots_local_exe = 0;
+ }
+}
+
+//---------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ static pkt_list_s *pkt = NULL;
+ static script_set_s sfile = {NULL, 0, 0, 0, 0};
+ static uint8_t buf[HCI_BUF_SIZE] = {0};
+ static int cont = 0;
+ size_t len = 0;
+ ssize_t read_len = 0;
+ int csw_fd = -1;
+ int csr_fd = -1;
+ int cli_uartfd = -1;
+ int type = 0;
+ struct sockaddr_un skaddr_cli;
+ struct sockaddr_un skaddr_srv;
+ socklen_t sklen_cli = {0};
+ socklen_t sklen_srv = {0};
+ struct sockaddr_in ethaddr_cli;
+ struct sockaddr_in ethaddr_srv;
+ fd_set readfs;
+ struct sigaction sigact;
+ struct timeval time_start;
+ struct timeval time_end;
+ uint32_t diff_time;
+ int which = PRIO_PROCESS;
+ id_t pid;
+ int priority = -20;
+ int ret;
+
+ // Register signal handler
+ sigact.sa_handler = boots_sig_handler;
+ sigact.sa_flags = 0;
+ sigemptyset(&sigact.sa_mask);
+ sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGTERM, &sigact, NULL);
+ sigaction(SIGQUIT, &sigact, NULL);
+ sigaction(SIGKILL, &sigact, NULL);
+
+ // For root permission
+ CHECK_USERID();
+
+ // Local execute or not
+ boots_chk_local_exe(argv[0]);
+
+ if (argc == 2 && !memcmp("-c", argv[1], strlen("-c"))) {
+ // Print commands
+ boots_cmd_usage(0);
+ exit(0);
+ } else if (argc == 2 && !memcmp("-o", argv[1], strlen("-o"))) {
+ // Print commands
+ boots_country_cmd_usage(0);
+ exit(0);
+ } else if (argc == 3 && !memcmp("-c", argv[1], strlen("-c"))) {
+ if (!memcmp("detail", argv[2], strlen("detail"))) {
+ boots_cmd_usage(1);
+ exit(0);
+ } else if (!memcmp("mtk", argv[2], strlen("mtk"))) {
+ boots_cmd_usage(3);
+ exit(0);
+ } else {
+ // do nothing for command without any parameters.
+ }
+ } else if (argc == 2 && !memcmp("stop", argv[1], strlen("stop"))) {
+ boots_killall_boots_srv();
+ return 0;
+ } else if (argc == 3 && !memcmp("-o", argv[1], strlen("-o"))) {
+ if (!memcmp("detail", argv[2], strlen("detail"))) {
+ boots_country_cmd_usage(1);
+ exit(0);
+ } else if (!memcmp("mtk", argv[2], strlen("mtk"))) {
+ boots_country_cmd_usage(3);
+ exit(0);
+ } else {
+ // do nothing for command without any parameters.
+ }
+ } else if (argc < 3) {
+ // Print help
+ boots_help();
+ exit(0);
+ }
+
+ /** country command set, because it's not related controller operation
+ * Only access file
+ */
+ if (!memcmp("-o", argv[1], strlen("-o"))) {
+ boots_country_set_handler(argv + 2, argc - 2);
+ goto exit;
+ }
+
+ // Confirm interface between client/server, upper layer
+ boots_chk_if(argc - 1, &argv[1]);
+
+ /** Communication Interface with boots_srv */
+ if (boots_if.csif == BOOTS_CSIF_SKT) {
+ // Check interface is support or not
+ if (!boots_invoke_boots_srv(boots_chk_btif(argv[1])))
+ exit(1);
+
+ // create socket
+ if (boots_sk_create(&csr_fd, &skaddr_cli, &sklen_cli, BOOTS_CLISK_NAME, 0)) {
+ BPRINT_E("Create socket failed");
+ exit(1);
+ }
+
+ // connect socket
+ if (boots_sk_create(&csw_fd, &skaddr_srv, &sklen_srv, BOOTS_SRVSK_NAME, 1)) {
+ BPRINT_E("Connect socket failed");
+ boots_sk_close(&csr_fd);
+ exit(1);
+ }
+
+ } else if (boots_if.csif == BOOTS_CSIF_UART) {
+ if (boots_if.clif == BOOTS_IF_NONE) {
+ // Maybe last time user use command ask BT into DUT mode
+ boots_killall_boots_srv();
+ sleep(1);
+ // means boots_srv as relayer in PC/NB
+ boots_invoke_boots_srv(boots_chk_btif(argv[1]));
+ exit(1);
+
+ } else {
+ // client/server communication interface
+ csw_fd = boots_uart_init(boots_if.cs, boots_if.cs_speed);
+ if (csw_fd < 0) {
+ BPRINT_E("%s: Open serial port:%s failed(%d)!", __func__, boots_if.cs, csw_fd);
+ exit(1);
+ }
+ csr_fd = csw_fd;
+ }
+
+ } else if (boots_if.csif == BOOTS_CSIF_ETH) {
+ // create socket
+ if (boots_eth_create(&csr_fd, ðaddr_cli, 0)) {
+ BPRINT_E("Create socket failed");
+ exit(1);
+ }
+ // connect socket
+ if (boots_eth_create(&csw_fd, ðaddr_srv, 1)) {
+ BPRINT_E("Connect socket failed");
+ boots_eth_close(&csr_fd);
+ exit(1);
+ }
+ } else {
+ BPRINT_E("Unknown communication interface");
+ exit(1);
+ }
+
+ /** Input Interface for boots */
+ if (boots_if.clif == BOOTS_CLIF_UART) {
+ cli_uartfd = boots_uart_init(boots_if.cli, boots_if.cli_speed);
+ if (cli_uartfd < 0) {
+ BPRINT_E("Open serial port:%s failed(%d)!!", boots_if.cli, cli_uartfd);
+ goto exit;
+ }
+ cont = 1;
+
+ } else {
+ if ((type = getopt(argc, argv, "frco")) != -1) {
+ BPRINT_D("optopt: %d, opterr: %d, optind: %d", optopt, opterr, optind);
+ switch (type) {
+ case 'f': /** script file */
+ sfile.script = boots_script_open(*(argv + optind));
+ if (!sfile.script) {
+ goto exit;
+ }
+ break;
+ case 'r': /** raw data */
+ pkt = boots_raw_cmd_handler(argv + optind, argc - optind);
+ break;
+ case 'c': /** command set */
+ pkt = boots_cmd_set_handler(argv + optind, argc - optind);
+ break;
+ #if 0 /** process this in above */
+ case 'o':
+ pkt = boots_country_set_handler(argv + optind, argc - optind);
+ break;
+ #endif
+ default:
+ BPRINT_W("Unknown type: %c", type);
+ break;
+ };
+ if (!pkt && !sfile.script) goto exit;
+ }
+ }
+
+ pid = getpid();
+ ret = setpriority(which, pid, priority);
+ if (ret != 0) {
+ BPRINT_I("setpriority fail: %s(%d)", strerror(errno), errno);
+ }
+
+ /** Process handler */
+ do {
+ int ret = -1;
+ struct timeval timo;
+
+ if (sfile.script) {
+ pkt = boots_script_get(sfile.script);
+ if (pkt == NULL)
+ break; // Could end of file
+ }
+
+ // default timeout
+ if (sfile.timo) {
+ timo.tv_sec = sfile.timo / 1000;
+ timo.tv_usec = (sfile.timo % 1000) * 1000;
+ } else {
+ timo.tv_sec = 3;
+ timo.tv_usec = 0;
+ }
+ if (pkt) {
+ BPRINT_D("s_type: %d", pkt->s_type);
+ switch (pkt->s_type) {
+ case SCRIPT_NONE: // modular commands
+ case SCRIPT_CMD: // hci_cmd script
+ case SCRIPT_STRESS: // stress test script
+ case SCRIPT_LOOPBACK: // loopback test script
+ case SCRIPT_LPTIMER: // loopback test script with timer
+ pkt = boots_pkt_node_pop(pkt, buf, &len);
+ break;
+ case SCRIPT_TX: // combo tool script
+ pkt = boots_pkt_node_pop(pkt, buf, &len);
+ if (len) {
+ // Send command, if input by user or script
+ boots_write(csw_fd, (void *)buf, len, boots_if.csif);
+ boots_pkt_handler(buf, len, NULL);
+ memset(buf, 0, sizeof(buf));
+ len = 0;
+ }
+ continue;
+ case SCRIPT_RX:
+ case SCRIPT_WAITRX:
+ FD_ZERO(&readfs);
+ if (csr_fd >= 0)
+ FD_SET(csr_fd, &readfs);
+ ret = select(csr_fd + 1, &readfs, NULL, NULL, &timo);
+ if (ret > 0) {
+ read_len = boots_read(csr_fd, buf, sizeof(buf), boots_if.csif);
+ if (read_len > 0) {
+ cont = boots_pkt_handler(buf, (size_t)read_len, pkt ? &pkt : NULL);
+ memset(buf, 0, sizeof(buf));
+ read_len = 0;
+ }
+ } else if (ret == 0) {
+ goto exit;
+ }
+ continue;
+ case SCRIPT_TITLE:
+ case SCRIPT_PROC:
+ BPRINT_I("%s", pkt->u_cnt.msg); // Just print msg
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ continue;
+ case SCRIPT_TIMEOUT:
+ if (pkt->u_cnt.timo) {
+ sfile.timo = pkt->u_cnt.timo;
+ }
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ continue;
+ case SCRIPT_WAIT:
+ if (pkt->u_cnt.wait) {
+ (void)usleep(pkt->u_cnt.wait * 1000);
+ }
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ continue;
+ case SCRIPT_USBALT:
+ // TODO
+ continue;
+ case SCRIPT_LOOP:
+ sfile.loop = pkt->u_cnt.loop;
+ if (sfile.script)
+ sfile.loop_pos = ftell(sfile.script);
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ BPRINT_D("Looping");
+ continue;
+ case SCRIPT_LOOPEND:
+ if (!sfile.loop) {
+ sfile.loop_pos = 0;
+ BPRINT_D("Loop End");
+ } else {
+ if ((--sfile.loop) && sfile.script && sfile.loop_pos >= 0)
+ boots_script_loop(sfile.script, sfile.loop_pos);
+ }
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ continue;
+ case SCRIPT_RSSI: // Background RSSI scan
+ if (pkt->u_cnt.rssi_s->stop)
+ boots_pkt_cleanup_report_rssi(1);
+ else {
+ boots_pkt_cleanup_report_rssi(0);
+ memcpy(&rssi_setting, pkt->u_cnt.rssi_s, sizeof(rssi_set_s));
+ }
+ buf[0] = SCRIPT_RSSI;
+ memcpy(&buf[1], pkt->u_cnt.rssi_s, sizeof(rssi_set_s));
+ len = sizeof(rssi_set_s) + 1;
+ boots_write(csw_fd, (void *)buf, len, boots_if.csif);
+ memset(buf, 0, sizeof(buf));
+ len = 0;
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ break;
+ case SCRIPT_END:
+ BPRINT_I("Script End");
+ pkt = boots_pkt_node_pop(pkt, NULL, NULL);
+ boots_script_close(sfile.script);
+ sfile.script = NULL;
+ goto exit;
+ default:
+ break;
+ }
+ }
+
+ if (len) {
+ if (pkt && (pkt->s_type == SCRIPT_STRESS || pkt->s_type == SCRIPT_LOOPBACK || pkt->s_type == SCRIPT_LPTIMER)) {
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_SEND_CMD_START);
+ }
+
+ // Send command, if input by user or script
+ boots_write(csw_fd, (void *)buf, len, boots_if.csif);
+
+ if (pkt && (pkt->s_type == SCRIPT_STRESS || pkt->s_type == SCRIPT_LOOPBACK || pkt->s_type == SCRIPT_LPTIMER)) {
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_SEND_CMD_FINISH);
+ if (BOOTS_STRESS_SHOW_ALL_CMD)
+ boots_pkt_handler(buf, len, NULL);
+ if (pkt->s_type == SCRIPT_LPTIMER)
+ gettimeofday(&time_start, NULL);
+ } else
+ boots_pkt_handler(buf, len, NULL);
+ memset(buf, 0, sizeof(buf));
+ len = 0;
+ }
+
+ FD_ZERO(&readfs);
+
+ if (cli_uartfd >= 0)
+ FD_SET(cli_uartfd, &readfs);
+ if (csr_fd >= 0)
+ FD_SET(csr_fd, &readfs);
+
+ ret = select(MAX(cli_uartfd, csr_fd) + 1, &readfs, NULL, NULL, &timo);
+ if (ret > 0) {
+ if (cli_uartfd >= 0 && FD_ISSET(cli_uartfd, &readfs)) {
+ // read from UART(CBT)
+ read_len = boots_read(cli_uartfd, buf, sizeof(buf), boots_if.clif);
+ if (read_len > 0) {
+ // write to platform
+ boots_write(csw_fd, (void *)buf, (size_t)read_len, boots_if.csif);
+ boots_pkt_handler(buf, (size_t)read_len, NULL);
+ memset(buf, 0, sizeof(buf));
+ read_len = 0;
+ }
+ }
+ if (FD_ISSET(csr_fd, &readfs)) {
+ // read from platform
+ read_len = boots_read(csr_fd, buf, sizeof(buf), boots_if.csif);
+
+ if (read_len > 0 && boots_if.clif == BOOTS_CLIF_USER) {
+ cont = boots_pkt_handler(buf, read_len, pkt ? &pkt : NULL);
+ } else if (read_len > 0 && boots_if.clif == BOOTS_CLIF_UART) {
+ // write to UART(CBT)
+ boots_write(cli_uartfd, (void *)buf, read_len, boots_if.clif);
+ boots_pkt_handler(buf, read_len, NULL);
+ }
+
+ if (pkt && pkt->s_type == SCRIPT_STRESS) {
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH);
+ } else if (pkt && (pkt->s_type == SCRIPT_LOOPBACK || pkt->s_type == SCRIPT_LPTIMER)) {
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS && !BOOTS_STRESS_MEASURE_LBT_TOTAL_LATENCY)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH);
+ if (buf[0] == HCI_EVENT_PKT && read_len == 8) {
+ // should read again (Titan:Why read again but not use it?)
+ boots_read(csr_fd, buf, sizeof(buf), boots_if.csif);
+ } else if (buf[0] == HCI_EVENT_PKT && buf[8] == HCI_ACL_PKT && ((size_t)read_len) == (8 + pkt->len)) {
+ // current loopback test iteration is finished
+ } else if (buf[0] == HCI_ACL_PKT) {
+ // current loopback test iteration is finished
+ } else {
+ BPRINT_E("Receive unknonw type %02X, len=%d(EVENT/ACL is expected)", buf[0], (int)read_len);
+ exit(0);
+ }
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS && BOOTS_STRESS_MEASURE_LBT_TOTAL_LATENCY)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH);
+ if (pkt->s_type == SCRIPT_LPTIMER) {
+ gettimeofday(&time_end, NULL);
+ diff_time = (time_end.tv_usec + time_end.tv_sec * 1000000) - (time_start.tv_usec + time_start.tv_sec * 1000000);
+ if (boots_loop_timer > 0 && (unsigned int)boots_loop_timer > (diff_time / 1000))
+ usleep(boots_loop_timer*1000 - diff_time);
+ }
+ }
+ memset(buf, 0, sizeof(buf));
+ read_len = 0;
+ }
+ } else if (ret == 0) {
+ // timeout
+ if (boots_if.clif == BOOTS_CLIF_UART)
+ cont = 1;
+ else
+ cont = 0;
+ } else {
+ BPRINT_D("Unexpect return: %d", ret);
+ }
+ } while (cont || sfile.script);
+
+exit:
+ if (boots_if.csif == BOOTS_CSIF_SKT) {
+ if (csw_fd >= 0)
+ boots_tell_socket_end(csw_fd, &skaddr_srv);
+ (void)usleep(1000);
+ if (csw_fd >= 0)
+ boots_sk_close(&csw_fd);
+ if (csr_fd >= 0)
+ boots_sk_close(&csr_fd);
+ unlink(BOOTS_CLISK_NAME);
+ } else if (boots_if.csif == BOOTS_CSIF_UART) {
+ if (csw_fd >= 0)
+ close(csw_fd);
+ } else if (boots_if.csif == BOOTS_CSIF_ETH) {
+ if (csw_fd >= 0)
+ boots_tell_ethernet_end(csw_fd, ðaddr_srv);
+ (void)usleep(1000);
+ if (csw_fd >= 0)
+ boots_eth_close(&csw_fd);
+ if (csr_fd >= 0)
+ boots_eth_close(&csr_fd);
+ }
+ if (boots_if.clif == BOOTS_CLIF_UART) {
+ if (cli_uartfd >= 0)
+ close(cli_uartfd);
+ }
+ boots_pkt_list_destroy(pkt);
+ pkt = NULL;
+ boots_script_close(sfile.script);
+ BPRINT_D("Input End");
+ return 0;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots.h b/src/connectivity/bt_others/boots/boots.h
new file mode 100644
index 0000000..34e7c98
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots.h
@@ -0,0 +1,177 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_H__
+#define __BOOTS_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <memory.h>
+#include <stdbool.h>
+
+#include "boots_cfg.h"
+
+/** VERSION:
+ * Major is for architecture or big change.,
+ * Minor is for feature add or change.,
+ * Revision is for bugfix.
+ * REV: For branch
+ */
+#define VERSION "1.26.1"
+#define REV "trunk-200918"
+
+#if HELP_COLOR_SUPPORT
+#define NONE "\033[m"
+#define BLUE "\033[0;32;34m"
+#define RED "\033[0;32;31m"
+#else
+#define NONE ""
+#define BLUE ""
+#define RED ""
+#endif
+
+#define HCI_BUF_SIZE 0x1000
+
+#define BOOTS_MSG_LVL_DBG 4
+#define BOOTS_MSG_LVL_INFO 3
+#define BOOTS_MSG_LVL_WARN 2
+#define BOOTS_MSG_LVL_ERR 1
+#define BOOTS_MSG_LVL_NONE 0
+
+#define BPRINT_D_RAW(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_DBG) \
+ printf(fmt, ##__VA_ARGS__); } while (0);
+#define BPRINT_D(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_DBG) \
+ printf("[%s:D] "fmt"\n", LOG_TAG, ##__VA_ARGS__); } while (0);
+#define BPRINT_I_RAW(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_INFO) \
+ printf(fmt, ##__VA_ARGS__); } while (0);
+#define BPRINT_I(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_INFO) \
+ printf("[%s] "fmt"\n", LOG_TAG, ##__VA_ARGS__); } while (0);
+#define BPRINT_W(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_WARN) \
+ printf(BLUE "[%s:W] "fmt NONE"\n", LOG_TAG, ##__VA_ARGS__); } while (0);
+#define BPRINT_E(fmt, ...) \
+ do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_ERR) \
+ printf(RED "[%s:E] " fmt " !!!" NONE "\n", LOG_TAG, ##__VA_ARGS__);} while (0);
+
+#define SHOW_RAW(len, buf) \
+ do { \
+ int i = 0; \
+ while (i < len) { \
+ printf("%02X ", buf[i]); \
+ i++; \
+ } \
+ printf("\n"); \
+ } while (0);
+
+#define MAX(a, b) \
+ (((a) > (b)) ? (a) : (b))
+
+#define ARRAY_SIZE(arr) \
+ (sizeof(arr) / sizeof((arr)[0]))
+
+#define CHECK_USERID() \
+ if (getuid() != 0) { \
+ BPRINT_E("Please run boots as ROOT!!!"); \
+ exit(1); \
+ }
+
+#ifndef UNUSED
+#define UNUSED(x) ((void)x)
+#endif
+
+#define STREAM_TO_UINT32(p) \
+ (((uint32_t)(*(p))) | (((uint32_t)(*(p + 1))) << 8) | \
+ (((uint32_t)(*(p + 2))) << 16) | (((uint32_t)(*(p + 3))) << 24))
+#define STREAM_TO_UINT16(p) \
+ (((uint16_t)(*(p))) | (((uint16_t)(*(p + 1))) << 8))
+
+#define UINT32_TO_STREAM(p, val) { \
+ *(p) = (uint8_t)(val); \
+ *(p + 1) = (uint8_t)((val) >> 8); \
+ *(p + 2) = (uint8_t)((val) >> 16); \
+ *(p + 3) = (uint8_t)((val) >> 24); \
+}
+#define UINT16_TO_STREAM(p, val) { \
+ *(p) = (uint8_t)(val); \
+ *(p + 1) = (uint8_t)((val) >> 8); \
+}
+
+/** Boots BT Interface */
+typedef enum {
+ BOOTS_IF_NONE = 0,
+ BOOTS_BTIF_STPBT,
+ BOOTS_BTIF_HCI,
+ BOOTS_BTIF_ALL,
+ BOOTS_CSIF_SKT,
+ BOOTS_CSIF_UART,
+ BOOTS_CSIF_ETH,
+ BOOTS_CLIF_USER,
+ BOOTS_CLIF_UART,
+} boots_if_e;
+
+typedef struct {
+ boots_if_e inf; // interface
+ char *n; // name
+ char *p; // path
+} boots_btif_s;
+
+typedef struct {
+ boots_if_e btif;
+ boots_if_e csif;
+ boots_if_e clif;
+ char bt[16];
+ char cs[16];
+ char cli[16];
+ int cs_speed;
+ int cli_speed;
+} boots_if_s;
+
+//---------------------------------------------------------------------------
+static boots_btif_s boots_btif[] = {
+ {BOOTS_BTIF_STPBT, "stpbt", "/dev/stpbt"},
+ {BOOTS_BTIF_HCI, "hci", NULL},
+ {BOOTS_IF_NONE, "", NULL}, // Should leave bottom
+};
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_H__
diff --git a/src/connectivity/bt_others/boots/boots_btif.c b/src/connectivity/bt_others/boots/boots_btif.c
new file mode 100644
index 0000000..a5c4d14
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_btif.c
@@ -0,0 +1,224 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "boots.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_btif"
+
+//---------------------------------------------------------------------------
+extern int fd[BOOTS_BTIF_ALL];
+extern int mtk_66xx_Init(int comPort, unsigned int chipId);
+extern uint32_t mtk_66xx_detect(void);
+extern int boots_hci_enable(char *arg, void *func_cb);
+extern int boots_hci_disable(int bt_fd);
+
+//---------------------------------------------------------------------------
+static char *get_inf_path(boots_if_e interface)
+{
+ int i = 0;
+
+ while (boots_btif[i].inf != interface) {
+ i++;
+ }
+ BPRINT_D("path: %s", boots_btif[i].p);
+ return boots_btif[i].p;
+}
+
+//---------------------------------------------------------------------------
+static int bt_init(int fd, uint32_t chip)
+{
+ /* Patch download is moved to WMT driver on combo chip */
+ /* Invoke HCI transport entrance */
+ if (mtk_66xx_Init(fd, chip) != 0) {
+ BPRINT_E("mtk_66xx_Init failed");
+ return -1;
+ }
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+static int stpbt_enable(char *dev)
+{
+ int fd = -1;
+
+ if (dev == NULL) return fd;
+
+ fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK);
+ if (fd < 0) {
+ BPRINT_E("Can't open BT port, errno: %d", fd);
+ return -1;
+ } else {
+ BPRINT_D("Open %s(%d) successfully", dev, fd);
+ }
+
+ return fd;
+}
+
+//---------------------------------------------------------------------------
+static void stpbt_disable(int fd)
+{
+ if (fd > 0)
+ close(fd);
+
+ return;
+}
+
+//---------------------------------------------------------------------------
+int boots_btif_open(boots_if_e interface)
+{
+ uint32_t chip = 0x0000;
+ /**
+ * Depends on different interface:
+ * HCI, STPBT, UART & ETHERNET
+ * to do.
+ */
+ switch (interface) {
+ case BOOTS_BTIF_STPBT:
+ fd[interface] = stpbt_enable(get_inf_path(interface));
+ break;
+ case BOOTS_BTIF_HCI:
+ fd[interface] = boots_hci_enable(get_inf_path(interface), NULL);
+ break;
+ default:
+ BPRINT_E("%s: Incorrect interface: %d", __func__, interface);
+ return -1;
+ break;
+ }
+
+ if (fd[interface] > 0) {
+ chip = mtk_66xx_detect();
+ switch (chip) {
+ case 0x6630:
+// case 0x8167:
+ BPRINT_I("chip: %04X", chip);
+ if (bt_init(fd[interface], chip) != 0) {
+ return -1;
+ }
+ break;
+ default:
+ break;
+ };
+ }
+
+ return fd[interface];
+}
+
+//---------------------------------------------------------------------------
+int boots_btif_close(boots_if_e interface)
+{
+ /** bt deinit */
+ if (fd[interface] < 0) {
+ return -1;
+ }
+
+ switch (interface) {
+ case BOOTS_BTIF_STPBT:
+ stpbt_disable(fd[interface]);
+ break;
+ case BOOTS_BTIF_HCI:
+ boots_hci_disable(fd[interface]);
+ break;
+ default:
+ BPRINT_E("%s: Incorrect interface: %d", __func__, interface);
+ break;
+ }
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_btif_read(int fd, uint8_t *buf, size_t size)
+{
+ ssize_t nRead = 0;
+
+ if (fd < 0) {
+ BPRINT_E("File descriptor in bad state");
+ return -EIO;
+ } else if (!buf || !size) {
+ BPRINT_E("%s: Invalid argument buf:%p, size:%d", __func__, buf, (int)size);
+ return -EINVAL;
+ }
+
+ nRead = read(fd, buf, size);
+ if (nRead <= 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ BPRINT_W("%s: %s(%d)", __func__, strerror(errno), errno);
+ return 0;
+ } else {
+ BPRINT_E("%s: %s(%d)", __func__, strerror(errno), errno);
+ return -errno;
+ }
+ }
+
+ return nRead;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_btif_write(int fd, uint8_t *buf, size_t len)
+{
+ ssize_t ret = 0;
+ size_t bytesToWrite = len;
+
+ if (fd < 0) {
+ BPRINT_E("%s: No available com port", __func__);
+ return -EIO;
+ }
+
+ while (bytesToWrite > 0) {
+ ret = write(fd, buf, bytesToWrite);
+ if (ret <= 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ BPRINT_W("%s: %s(%d)", __func__, strerror(errno), errno);
+ return 0;
+ } else {
+ BPRINT_E("%s: %s(%d)", __func__, strerror(errno), errno);
+ return -errno;
+ }
+ }
+ bytesToWrite -= ret;
+ buf += ret;
+ }
+
+ return (len - bytesToWrite);
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_btif.h b/src/connectivity/bt_others/boots/boots_btif.h
new file mode 100644
index 0000000..7ca8ce3
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_btif.h
@@ -0,0 +1,49 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_BTIF_H__
+#define __BOOTS_BTIF_H__
+
+//---------------------------------------------------------------------------
+int boots_btif_open(boots_if_e interface);
+int boots_btif_close(boots_if_e interface);
+int boots_btif_read(int fd, uint8_t *buf, int len);
+int boots_btif_write(int fd, uint8_t *buf, int len);
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_BTIF_H__
diff --git a/src/connectivity/bt_others/boots/boots_cfg.h b/src/connectivity/bt_others/boots/boots_cfg.h
new file mode 100644
index 0000000..2abf6aa
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_cfg.h
@@ -0,0 +1,69 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_CFG_H__
+#define __BOOTS_CFG_H__
+
+/** In MTK Android base platform need enable this to get CHIP ID */
+//#define MTK_ANDROID_PLATFORM
+
+/**
+ * boots would crete socket for communication, assign writable folder for it.
+ * If ignore this define socket would be created in the same directory with boots
+ */
+//#define BOOTS_SOCKET_PATH "/tmp/"
+
+/**
+ * For mt66xx series chip ID, please make sure it be defined
+ * - MTK Android environment default is "persist.mtk.wcn.combo.chipid" in property
+ * - Pure Linux please set it in environment variable
+ */
+#define WCN_COMBO_LOADER_CHIP_ID_PROP "persist.mtk.wcn.combo.chipid"
+
+/** For easy to read */
+#define HELP_COLOR_SUPPORT 1
+
+/** Debug log level */
+#define BOOTS_MSG_LVL_DEFAULT BOOTS_MSG_LVL_INFO
+//#define BOOTS_VERBOSE_MSG /* VERBOSE Log */
+
+/** For raw data print length */
+#define DEF_SHOW_LEN 26
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_CFG_H__
diff --git a/src/connectivity/bt_others/boots/boots_country.c b/src/connectivity/bt_others/boots/boots_country.c
new file mode 100644
index 0000000..bea51f7
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_country.c
@@ -0,0 +1,755 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include "boots_country.h"
+
+#define LOG_TAG "boots_country"
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_get_limit(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_set_limit(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_dump_limit(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_create_limit_table(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_get_srs(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_set_srs(char *cmd[], size_t len, int index);
+static pkt_list_s *mtk_boots_country_dump_srs(char *cmd[], size_t len, int index);
+
+//---------------------------------------------------------------------------
+#define USAGE_COUNTRY_GET_LIMIT_DETAILS \
+ " [c] Country code: country code value\n" \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtCountryLimit.dat"
+
+#define USAGE_COUNTRY_SET_LIMIT_DETAILS \
+ " [c] Country code: country code value\n" \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtCountryLimit.dat" \
+ " [b] BT TX power level\n" \
+ " [e] BLE TX power level\n" \
+ " [m] Max TX power level"
+
+#define USAGE_COUNTRY_DUMP_LIMIT_DETAILS \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtCountryLimit.dat"
+
+#define USAGE_COUNTRY_CREATE_LIMIT_DETAILS \
+ " [c] Country code: country code value\n" \
+ " [t] File path: full path and name of country code [t]able file, default:/vendor/firmware/BtCountryLimit.dat\n" \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtTxPwrLimit.bin"
+
+#define USAGE_COUNTRY_GET_SRS_DETAILS \
+ " [c] Country code: country code value\n" \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtSRS.dat"
+
+#define USAGE_COUNTRY_SET_SRS_DETAILS \
+ " [c] Country_code: country code value\n" \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtSRS.dat\n" \
+ " [s] SRS: SRS value"
+
+#define USAGE_COUNTRY_DUMP_SRS_DETAILS \
+ " [f] File path: full path and name of table file, default:/vendor/firmware/BtSRS.dat"
+
+boots_country_cmds_s country_commands[] = {
+ { "get_limit", mtk_boots_country_get_limit,
+ "Get power limit with country code. [-c <country_code>] [-f <file_path>]",
+ USAGE_COUNTRY_GET_LIMIT_DETAILS, false },
+ { "set_limit", mtk_boots_country_set_limit,
+ "Set power limit with country code. [-c <country_code>] [-f <file_path>] [-b <0-9>] [-e <0-9>] [-m <0-9>]",
+ USAGE_COUNTRY_SET_LIMIT_DETAILS, false },
+ { "dump_limit", mtk_boots_country_dump_limit,
+ "Dump power limit with all country code. [-f <file_path>]",
+ USAGE_COUNTRY_DUMP_LIMIT_DETAILS, false },
+ { "create_table", mtk_boots_country_create_limit_table,
+ "Create power limit table. [-c <country_code>] [-t <file_path>] [-f <file_path>]",
+ USAGE_COUNTRY_CREATE_LIMIT_DETAILS, false },
+ { "get_srs", mtk_boots_country_get_srs,
+ "Get SRS with country code. [-c <country_code>] [-f <file_path>]",
+ USAGE_COUNTRY_GET_SRS_DETAILS, false },
+ { "set_srs", mtk_boots_country_set_srs,
+ "Set SRS with country code. [-c <country_code>] [-f <file_path>] [-s <SRS>]",
+ USAGE_COUNTRY_SET_SRS_DETAILS, false },
+ { "dump_srs", mtk_boots_country_dump_srs,
+ "Dump SRS with all country code. [-f <file_path>]",
+ USAGE_COUNTRY_DUMP_SRS_DETAILS, false },
+ { NULL, NULL, NULL, NULL, NULL }
+};
+
+/****************************************************
+ Table format:
+ Country code|BT TX power level|BLE TX power level|Max TX power level|Diff mode
+****************************************************/
+static pkt_list_s *mtk_boots_country_get_limit(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t line_len = 0;
+ ssize_t read;
+ char path[64] = DEFAULT_COUNTRY_LIMIT;
+ size_t i = 1;
+ int country_code = 0;
+ int temp_code = 0;
+ int bt_pwr = 0;
+ int ble_pwr = 0;
+ int max_pwr = 0;
+ uint8_t find = 0;
+ char *delim = "|";
+ char *pch = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ i += 2;
+ break;
+ case 'c':
+ country_code = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ } else {
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0) {
+ temp_code = atoi(pch);
+ if (temp_code != country_code)
+ break;
+ else
+ find = 1;
+ } else if (i == 1)
+ bt_pwr = atoi(pch);
+ else if (i == 2)
+ ble_pwr = atoi(pch);
+ else if (i == 3)
+ max_pwr = atoi(pch);
+ else
+ BPRINT_D("Out of table");
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ if (find == 1)
+ break;
+ }
+ free(line);
+ fclose(fp);
+ if (find == 1) {
+ BPRINT_I("Country_code:%d BT_Power:%d BLE_Power:%d Max_Power:%d", country_code, bt_pwr, ble_pwr, max_pwr);
+ } else {
+ BPRINT_I("Country_code:%d Not Find.", country_code);
+ }
+ }
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_set_limit(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ ssize_t read;
+ size_t line_len = 0;
+ char *wbuf = NULL;
+ char *line = NULL;
+ char *line_cp = NULL;
+ int fp_len = 0;
+ char path[64] = DEFAULT_COUNTRY_LIMIT;
+ char path_cp[64] = DEFAULT_COUNTRY_LIMIT;
+ size_t i = 1;
+ ssize_t w_size = 0;
+ int country_code = 0;
+ int temp_code = 0;
+ int bt_pwr = 0;
+ int ble_pwr = 0;
+ int max_pwr = 0;
+ char *delim = "|";
+ char *pch = NULL;
+ char str_buf[13];
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ strncpy(path_cp, cmd[i + 1], sizeof(path_cp) - 1);
+ i += 2;
+ break;
+ case 'c':
+ country_code = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 'b':
+ bt_pwr = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 'e':
+ ble_pwr = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 'm':
+ max_pwr = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r+");
+ if (fp != NULL) {
+ fseek(fp, 0L, SEEK_END);
+ fp_len = ftell(fp);
+ wbuf = malloc(fp_len + 1 + 12);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ fclose(fp);
+ return NULL;
+ }
+ fseek(fp, 0L, SEEK_SET);
+
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ line_cp = malloc(read);
+ if (!line_cp) {
+ BPRINT_E("%s: Alloc line_cp failed", __func__);
+ free(line);
+ free(wbuf);
+ fclose(fp);
+ return NULL;
+ }
+ memcpy(line_cp, line, read);
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0) {
+ temp_code = atoi(pch);
+ if (temp_code != country_code) {
+ memcpy(&wbuf[w_size], line_cp, read);
+ w_size += read;
+ }
+ }
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ free(line_cp);
+ }
+ free(line);
+ fclose(fp);
+ } else {
+ wbuf = malloc(13);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ return NULL;
+ }
+ }
+
+ i = sprintf(str_buf, "%03d|%01d|%01d|%01d|0\n", country_code, bt_pwr, ble_pwr, max_pwr);
+ str_buf[12] = '\0';
+ memcpy(&wbuf[w_size], str_buf, i);
+ w_size += i;
+ fp = fopen(path_cp, "w");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path_cp, strerror(errno), errno);
+ free(wbuf);
+ return NULL;
+ }
+ fwrite(wbuf, 1, w_size, fp);
+ fclose(fp);
+ free(wbuf);
+
+ BPRINT_I("Set Country_code:%d BT_Power:%d BLE_Power:%d Max_Power:%d", country_code, bt_pwr, ble_pwr, max_pwr);
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_dump_limit(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t line_len = 0;
+ ssize_t read;
+ char path[64] = DEFAULT_COUNTRY_LIMIT;
+ size_t i = 1;
+ int country_code = 0;
+ int bt_pwr = 0;
+ int ble_pwr = 0;
+ int max_pwr = 0;
+ char *delim = "|";
+ char *pch = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ } else {
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0)
+ country_code = atoi(pch);
+ else if (i == 1)
+ bt_pwr = atoi(pch);
+ else if (i == 2)
+ ble_pwr = atoi(pch);
+ else if (i == 3)
+ max_pwr = atoi(pch);
+ else if (i == 4) {
+ BPRINT_I("Country_code:%d BT_Power:%d BLE_Power:%d Max_Power:%d", country_code, bt_pwr, ble_pwr, max_pwr);
+ } else
+ BPRINT_D("Out of table");
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ }
+ free(line);
+ fclose(fp);
+ }
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_create_limit_table(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t line_len = 0;
+ ssize_t read;
+ char path[64] = DEFAULT_COUNTRY_LIMIT;
+ char table_path[64] = DEFAULT_POWER_LIMIT;
+ size_t i = 1;
+ int country_code = 0;
+ int temp_code = 0;
+ uint8_t bt_pwr = 0;
+ uint8_t ble_pwr = 0;
+ uint8_t max_pwr = 0;
+ uint8_t diff = 0;
+ uint8_t find = 0;
+ char *delim = "|";
+ char *pch = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 't':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ i += 2;
+ break;
+ case 'f':
+ memset(table_path, 0x00, sizeof(table_path));
+ strncpy(table_path, cmd[i + 1], sizeof(table_path) - 1);
+ i += 2;
+ break;
+ case 'c':
+ country_code = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ return NULL;
+ } else {
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0) {
+ temp_code = atoi(pch);
+ if (temp_code != country_code)
+ break;
+ else
+ find = 1;
+ } else if (i == 1)
+ bt_pwr = atoi(pch);
+ else if (i == 2)
+ ble_pwr = atoi(pch);
+ else if (i == 3)
+ max_pwr = atoi(pch);
+ else if (i == 4)
+ diff = atoi(pch);
+ else
+ BPRINT_D("Out of table");
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ if (find == 1)
+ break;
+ }
+ free(line);
+ fclose(fp);
+ if (find == 1) {
+ BPRINT_I("Country_code:%d BT_Power:%d BLE_Power:%d Max_Power:%d", country_code, bt_pwr, ble_pwr, max_pwr);
+ } else {
+ BPRINT_I("Country_code:%d Not Find.", country_code);
+ return NULL;
+ }
+ }
+ fp = fopen(table_path, "wb");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ return NULL;
+ }
+
+ BPRINT_I("Write to table: %s", table_path);
+ fwrite(&bt_pwr, 1, sizeof(uint8_t), fp);
+ fwrite(&ble_pwr, 1, sizeof(uint8_t), fp);
+ fwrite(&max_pwr, 1, sizeof(uint8_t), fp);
+ fwrite(&diff, 1, sizeof(uint8_t), fp);
+ fclose(fp);
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+/****************************************************
+ Table format:
+ Country code|SRS
+****************************************************/
+
+static pkt_list_s *mtk_boots_country_get_srs(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t line_len = 0;
+ ssize_t read;
+ char path[64] = DEFAULT_SRS;
+ size_t i = 1;
+ int country_code = 0;
+ int temp_code = 0;
+ int srs = 0;
+ uint8_t find = 0;
+ char *delim = "|";
+ char *pch = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ i += 2;
+ break;
+ case 'c':
+ country_code = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ } else {
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0) {
+ temp_code = atoi(pch);
+ if (temp_code != country_code)
+ break;
+ else
+ find = 1;
+ } else if (i == 1)
+ srs = atoi(pch);
+ else
+ BPRINT_D("Out of table");
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ if (find == 1)
+ break;
+ }
+ free(line);
+ fclose(fp);
+ if (find == 1) {
+ BPRINT_I("Country_code:%d SRS:%d", country_code, srs);
+ } else {
+ BPRINT_I("Country_code:%d Not Find.", country_code);
+ }
+ }
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_set_srs(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ ssize_t read;
+ size_t line_len = 0;
+ char *wbuf = NULL;
+ char *line = NULL;
+ char *line_cp = NULL;
+ int fp_len = 0;
+ char path[64] = DEFAULT_SRS;
+ char path_cp[64] = DEFAULT_SRS;
+ size_t i = 1;
+ ssize_t w_size = 0;
+ int country_code = 0;
+ int temp_code = 0;
+ int srs = 0;
+ char *delim = "|";
+ char *pch = NULL;
+ char str_buf[12];
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ strncpy(path_cp, cmd[i + 1], sizeof(path_cp) - 1);
+ i += 2;
+ break;
+ case 'c':
+ country_code = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 's':
+ srs = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r+");
+ if (fp != NULL) {
+ fseek(fp, 0L, SEEK_END);
+ fp_len = ftell(fp);
+ wbuf = malloc(fp_len + 1 + 12);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ fclose(fp);
+ return NULL;
+ }
+ fseek(fp, 0L, SEEK_SET);
+
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ line_cp = malloc(read);
+ if (!line_cp) {
+ BPRINT_E("%s: Alloc line_cp failed", __func__);
+ free(line);
+ free(wbuf);
+ fclose(fp);
+ return NULL;
+ }
+ memcpy(line_cp, line, read);
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0) {
+ temp_code = atoi(pch);
+ if (temp_code != country_code) {
+ memcpy(&wbuf[w_size], line_cp, read);
+ w_size += read;
+ }
+ }
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ free(line_cp);
+ }
+ free(line);
+ fclose(fp);
+ } else {
+ wbuf = malloc(13);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ return NULL;
+ }
+ }
+ i = sprintf(str_buf, "%03d|%d\n", country_code, srs);
+ memcpy(&wbuf[w_size], str_buf, i);
+ w_size += i;
+ fp = fopen(path_cp, "w");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path_cp, strerror(errno), errno);
+ free(wbuf);
+ return NULL;
+ }
+ fwrite(wbuf, 1, w_size, fp);
+ fclose(fp);
+ free(wbuf);
+
+ BPRINT_I("Set Country_code:%d SRS:%d", country_code, srs);
+ return NULL;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_country_dump_srs(char *cmd[], size_t len, int index)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t line_len = 0;
+ ssize_t read;
+ char path[64] = DEFAULT_SRS;
+ size_t i = 1;
+ int country_code = 0;
+ int srs = 0;
+ char *delim = "|";
+ char *pch = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ BPRINT_I("%s\n%s", country_commands[index].comment, country_commands[index].details);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path, strerror(errno), errno);
+ } else {
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ i = 0;
+ pch = strtok(line, delim);
+ while (pch != NULL) {
+ if (i == 0)
+ country_code = atoi(pch);
+ else if (i == 1) {
+ srs = atoi(pch);
+ BPRINT_I("Country_code:%d SRS:%d", country_code, srs);
+ }
+ else
+ BPRINT_D("Out of table");
+ pch = strtok (NULL, delim);
+ i++;
+ }
+ }
+ free(line);
+ fclose(fp);
+ }
+ return NULL;
+}
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_country_set_handler(char *cmd[], size_t len)
+{
+ uint8_t i = 0;
+ pkt_list_s *list = NULL;
+ UNUSED(boots_btif);
+
+ if (!cmd || !len) return NULL;
+
+ for (i = 0; i < ARRAY_SIZE(country_commands); i++) {
+ if (country_commands[i].cmd && !memcmp(cmd[0], country_commands[i].cmd, strlen(cmd[0]))) {
+ list = country_commands[i].func(cmd, len, i);
+ return list;
+ }
+ }
+ BPRINT_I("%s: Command Not Found(%s)", __func__, cmd[0]);
+
+ return NULL;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_country.h b/src/connectivity/bt_others/boots/boots_country.h
new file mode 100644
index 0000000..ffd4444
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_country.h
@@ -0,0 +1,61 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_COUNTRY_H__
+#define __BOOTS_COUNTRY_H__
+
+#include "boots.h"
+#include "boots_pkt.h"
+
+typedef struct {
+ char *cmd; // Shows command
+ pkt_list_s *(*func)(char *cmd[], size_t len, int index); // Implementeded functions
+ char *comment; // Shows comment
+ char *details; // Command details
+ bool hidden; // hidden command
+} boots_country_cmds_s;
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_country_set_handler(char *raw[], size_t len);
+//---------------------------------------------------------------------------
+
+#define DEFAULT_COUNTRY_LIMIT "/vendor/firmware/BtCountryLimit.dat"
+#define DEFAULT_POWER_LIMIT "/vendor/firmware/BtTxPwrLimit.bin"
+#define DEFAULT_SRS "/vendor/firmware/BtSRS.dat"
+
+#endif
diff --git a/src/connectivity/bt_others/boots/boots_eth.c b/src/connectivity/bt_others/boots/boots_eth.c
new file mode 100644
index 0000000..4ec5776
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_eth.c
@@ -0,0 +1,128 @@
+/* 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) 2016~2017. 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 <errno.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+
+#include "boots.h"
+#include "boots_eth.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_eth"
+
+//---------------------------------------------------------------------------
+int boots_eth_create(int * sk, struct sockaddr_in * sockaddr, int client)
+{
+ UNUSED(boots_btif);
+
+ // Create server socket
+ *sk = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (*sk < 0) {
+ BPRINT_E("Create socket failed: %s(%d)", strerror(errno), errno);
+ return errno;
+ }
+
+ // Init server socket
+ if (!client) {
+ memset(sockaddr, 0, sizeof(struct sockaddr_in));
+ sockaddr->sin_family = AF_INET;
+ sockaddr->sin_port = ETH_UDP_SRV_PORT;
+ sockaddr->sin_addr.s_addr = INADDR_ANY;
+ if (bind(*sk, (struct sockaddr *)sockaddr, sizeof(struct sockaddr)) < 0) {
+ BPRINT_E("Bind socket failed: %s(%d)", strerror(errno), errno);
+ return errno;
+ }
+ }
+
+ BPRINT_D("Socket %s create success", client ? "Client" : "Server");
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+int boots_eth_close(int * sk)
+{
+ if (sk == NULL) {
+ BPRINT_E("%s: Incorrect socket", __func__);
+ return -1;
+ }
+ close(*sk);
+ *sk = -1;
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_eth_send(int s, const void * buf, size_t len, struct sockaddr_in * to)
+{
+ ssize_t ret = 0;
+
+ if (!buf || !len) {
+ BPRINT_E("%s: Incorrect parameters", __func__);
+ return -1;
+ }
+#if 1
+ ret = sendto(s, buf, len, 0, (const struct sockaddr *)to,
+ sizeof(struct sockaddr));
+#else
+ ret = send(s, buf, len, 0);
+#endif
+ if (ret < 0)
+ BPRINT_E("%s: Send message failed: %s(%d)", __func__, strerror(errno), errno);
+
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_eth_recv(int s, const void * buf, size_t len, int flags)
+{
+ ssize_t ret = 0;
+ struct sockaddr srcaddr;
+ socklen_t srcaddr_len = sizeof(struct sockaddr);
+
+ if (!buf || !len) {
+ BPRINT_E("%s: Incorrect parameters", __func__);
+ return -1;
+ }
+
+ ret = recvfrom(s, (void *)buf, len, flags, &srcaddr, &srcaddr_len);
+ if (ret < 0)
+ BPRINT_E("%s: Receive message failed: %s(%d)", __func__, strerror(errno), errno);
+
+ return ret;
+}
+
diff --git a/src/connectivity/bt_others/boots/boots_eth.h b/src/connectivity/bt_others/boots/boots_eth.h
new file mode 100644
index 0000000..d7d6b5b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_eth.h
@@ -0,0 +1,63 @@
+/* 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) 2016~2017. 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.
+ */
+
+#ifndef __BOOTS_ETHERNET_H__
+#define __BOOTS_ETHERNET_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+//---------------------------------------------------------------------------
+
+//---------------------------------------------------------------------------
+#define ETH_UDP_SRV_PORT 4567
+#define ETH_UDP_CLT_PORT 4568
+
+//---------------------------------------------------------------------------
+int boots_eth_create(int * sk, struct sockaddr_in * sockaddr, int client);
+
+int boots_eth_close(int * sk);
+
+ssize_t boots_eth_send(int s, const void * buf, size_t len, struct sockaddr_in * to);
+
+ssize_t boots_eth_recv(int s, const void * buf, size_t len, int flags);
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_ETHERNET_H__
+
diff --git a/src/connectivity/bt_others/boots/boots_hci.c b/src/connectivity/bt_others/boots/boots_hci.c
new file mode 100644
index 0000000..29ad374
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_hci.c
@@ -0,0 +1,278 @@
+/* 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) 2016~2017. 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 <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include "boots.h"
+
+#define LOG_TAG "boots_hci"
+
+#define HCI_MAX_DEV 1
+#define BTPROTO_HCI 1
+
+#define HCIDEVUP _IOW('H', 201, int)
+#define HCIDEVDOWN _IOW('H', 202, int)
+#define HCIDEVRESET _IOW('H', 203, int)
+#define HCIDEVRESTAT _IOW('H', 204, int)
+#define HCIGETDEVLIST _IOR('H', 210, int)
+#define HCISETRAW _IOW('H', 220, int)
+
+enum {
+ HCI_UP,
+ HCI_INIT,
+ HCI_RUNNING,
+
+ HCI_PSCAN,
+ HCI_ISCAN,
+ HCI_AUTH,
+ HCI_ENCRYPT,
+ HCI_INQUIRY,
+
+ HCI_RAW,
+
+ HCI_RESET,
+};
+
+struct sockaddr_hci {
+ unsigned short family;
+ unsigned short device;
+ unsigned short channel;
+};
+
+struct dev_info {
+ int index;
+ int skt_fd;
+};
+
+struct hci_dev_req {
+ uint16_t dev_id;
+ uint32_t dev_opt;
+};
+
+struct hci_dev_list_req {
+ uint16_t dev_num;
+ struct hci_dev_req dev_req[0]; /* hci_dev_req structures */
+};
+
+static int commPort = 0;
+static struct dev_info hci_dev_info[HCI_MAX_DEV];
+
+//---------------------------------------------------------------------------
+static int boots_hci_open_dev(uint16_t index)
+{
+ struct sockaddr_hci addr_hci;
+ int skt_fd;
+
+ /* Create HCI socket */
+ skt_fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (skt_fd < 0)
+ return skt_fd;
+
+ BPRINT_D("sock = %x", skt_fd);
+ /* Bind socket to the HCI device */
+ memset(&addr_hci, 0, sizeof(addr_hci));
+ addr_hci.family = AF_BLUETOOTH;
+ addr_hci.device = index;
+ /* 1 means HCI_USER_CHANNEL */
+ addr_hci.channel = 1;
+ if (bind(skt_fd, (struct sockaddr *) &addr_hci, sizeof(addr_hci)) < 0)
+ goto failed;
+
+ return skt_fd;
+
+failed:
+ close(skt_fd);
+ return -1;
+}
+
+//---------------------------------------------------------------------------
+static int boots_hci_close_dev(int skt_fd)
+{
+ if (skt_fd < 0) {
+ BPRINT_E("boots_hci_close_dev %d", skt_fd);
+ return -1;
+ }
+ return close(skt_fd);
+}
+
+//---------------------------------------------------------------------------
+static struct dev_info *boots_hci_init_device(uint16_t index)
+{
+ struct dev_info *dev = NULL;
+ int skt_fd;
+
+ BPRINT_I("open HCI%d", index);
+ skt_fd = boots_hci_open_dev(index);
+ if (skt_fd < 0) {
+ BPRINT_E("Unable to open HCI%d: %s (%d)", index, strerror(errno), errno);
+ return NULL;
+ }
+
+ dev = &hci_dev_info[index];
+ memset(dev, 0, sizeof(*dev));
+
+ dev->index = index;
+ dev->skt_fd = skt_fd;
+ commPort = skt_fd;
+
+ /* HCI_CHANNEL_USER don't need to set filter */
+
+ /* Start HCI device */
+ /* If we use HCI_CHANNEL_RAW, we must be send HCIDEVUP to bluez stack */
+ /*
+ while (ioctl(dd, HCIDEVUP, index) < 0 && errno != EALREADY) {
+ BPRINT_E("Can't init device HCI%d: %s (%d)",
+ index, strerror(errno), errno);
+ sleep(1);
+ }*/
+ return dev;
+}
+
+//---------------------------------------------------------------------------
+static int boots_hci_init_all_devices(void)
+{
+ int skt_fd;
+ struct hci_dev_list_req *dev_list = NULL;
+ struct hci_dev_req *dev_req = NULL;
+ int i, ret = 0;
+
+ /* Create HCI socket to get HCI devices number*/
+ skt_fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (skt_fd < 0) {
+ BPRINT_E("Can't open HCI socket: %s (%d)", strerror(errno), errno);
+ ret = -1;
+ goto exit;
+ }
+ BPRINT_D("sock = %d", skt_fd);
+
+ dev_list = (struct hci_dev_list_req *)malloc(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t));
+ if (!dev_list) {
+ BPRINT_E("Can't allocate devlist buffer");
+ ret = -1;
+ goto exit;
+ }
+ dev_req = dev_list->dev_req;
+
+ dev_list->dev_num = HCI_MAX_DEV;
+ if (ioctl(skt_fd, HCIGETDEVLIST, dev_list) < 0) {
+ BPRINT_E("Can't get device list: %s (%d)", strerror(errno), errno);
+ ret = -1;
+ goto exit;
+ }
+
+ if (dev_list->dev_num == 0) {
+ BPRINT_E("No BT device.");
+ ret = -1;
+ goto exit;
+ }
+
+ BPRINT_I("BT dev_num = %d", dev_list->dev_num);
+ for (i = 0; i < dev_list->dev_num; i++, dev_req++) {
+ /* only support HCI0 */
+ if (dev_req->dev_id >= HCI_MAX_DEV)
+ continue;
+
+ boots_hci_init_device(dev_req->dev_id);
+ }
+exit:
+ if (skt_fd >= 0)
+ close(skt_fd);
+ if (dev_list)
+ free(dev_list);
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+static int boots_hci_deinit_device(int index)
+{
+ struct dev_info *dev = NULL;
+
+ dev = &hci_dev_info[index];
+ if (dev->skt_fd < 0)
+ return -1;
+
+ BPRINT_I("Stopping HCI%d socket %d", index, dev->skt_fd);
+
+ boots_hci_close_dev(dev->skt_fd);
+ memset(dev, 0, sizeof(*dev));
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+static int boots_hci_deinit_all_devices(void)
+{
+ int i;
+
+ for (i = 0; i < HCI_MAX_DEV; i++)
+ boots_hci_deinit_device(i);
+
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+int boots_hci_enable(char *arg, void *func_cb)
+{
+ UNUSED(boots_btif);
+ UNUSED(arg);
+ UNUSED(func_cb);
+
+ if (boots_hci_init_all_devices() < 0) {
+ BPRINT_E("adapter_ops_setup failed");
+ return -1;
+ }
+ else {
+ return commPort;
+ }
+}
+
+//---------------------------------------------------------------------------
+int boots_hci_disable(int bt_fd)
+{
+ UNUSED(bt_fd);
+
+ if (commPort >= 0) {
+ boots_hci_deinit_all_devices();
+ commPort = -1;
+ }
+ return 0;
+}
+
diff --git a/src/connectivity/bt_others/boots/boots_mt6xx.c b/src/connectivity/bt_others/boots/boots_mt6xx.c
new file mode 100644
index 0000000..5153366
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_mt6xx.c
@@ -0,0 +1,1089 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "boots.h"
+#include "boots_osi.h"
+#include "boots_mt6xx.h"
+
+/**************************************************************************
+ * D E F I N I T I O N S *
+***************************************************************************/
+#define LOG_TAG "boots_mt6xx"
+ /* BT NVRAM FILE */
+#define BT_NVRAM_MANUFACTURE "bt_init_value"
+
+/**************************************************************************
+ * G L O B A L V A R I A B L E S *
+***************************************************************************/
+
+static HCI_CMD_T hciCmd;
+static BT_INIT_VAR_T btinit[1];
+static INT32 bt_com_port;
+
+/**************************************************************************
+ * F U N C T I O N D E C L A R A T I O N S *
+***************************************************************************/
+// Common
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Local_BD_Addr(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_PCM(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Radio(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_TX_Power_Offset(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Sleep_Timeout(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_RESET(VOID);
+static ENUM_BT_STATUS_T GORMcmd_HCC_Coex_Performance_Adjust(VOID);
+
+//===================================================================
+// Combo chip
+HCI_SEQ_T bt_init_script_6630[] =
+{
+ { GORMcmd_HCC_Set_Local_BD_Addr }, /*0xFC1A*/
+ { GORMcmd_HCC_Set_PCM }, /*0xFC72*/
+ { GORMcmd_HCC_Set_Radio }, /*0xFC79*/
+ { GORMcmd_HCC_Set_TX_Power_Offset }, /*0xFC93*/
+ { GORMcmd_HCC_Set_Sleep_Timeout }, /*0xFC7A*/
+ { GORMcmd_HCC_Coex_Performance_Adjust }, /*0xFC22*/
+ { 0 },
+};
+
+HCI_SEQ_T bt_init_script_8167[] =
+{
+ { GORMcmd_HCC_Set_Local_BD_Addr }, /*0xFC1A*/
+ { GORMcmd_HCC_Set_Radio }, /*0xFC79*/
+ { GORMcmd_HCC_Set_TX_Power_Offset }, /*0xFC93*/
+ { GORMcmd_HCC_Set_Sleep_Timeout }, /*0xFC7A*/
+ { GORMcmd_HCC_RESET }, /*0x0C03*/
+ { 0 },
+};
+
+static ap_nvram_btradio_struct stBtDefault_6630 =
+{
+ {0x00, 0x00, 0x46, 0x66, 0x30, 0x01},
+ {0x60, 0x00}, //not used
+#if defined(__MTK_MERGE_INTERFACE_SUPPORT__)
+ {0x63, 0x10, 0x00, 0x00},
+#elif defined(__MTK_BT_I2S_SUPPORT__)
+ {0x03, 0x10, 0x00, 0x02},
+#else
+ {0x23, 0x10, 0x00, 0x00},
+#endif
+ {0x06, 0x80, 0x00, 0x06, 0x05, 0x06}, // Align 8516 others product
+ {0x03, 0x40, 0x1F, 0x40, 0x1F, 0x00, 0x04},
+ {0x80, 0x00}, //not used
+ {0xFF, 0xFF, 0xFF},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00}, // not used
+ {0x00, 0x00, 0x00, 0x00}, // not used
+ ///////////// Reserved /////////////
+ {0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+};
+
+static ap_nvram_btradio_struct stBtDefault_8167 =
+{
+ {0x00, 0x00, 0x46, 0x81, 0x67, 0x01},
+ {0x60, 0x00}, //not used
+#if defined(__MTK_MERGE_INTERFACE_SUPPORT__)
+ {0x63, 0x10, 0x00, 0x00},
+#elif defined(__MTK_BT_I2S_SUPPORT__)
+ {0x03, 0x10, 0x00, 0x02},
+#else
+ {0x23, 0x10, 0x00, 0x00},
+#endif
+ {0x07, 0x80, 0x00, 0x06, 0x05, 0x07},
+ {0x03, 0x40, 0x1F, 0x40, 0x1F, 0x00, 0x04},
+ {0x80, 0x00}, //not used
+ {0xFF, 0xFF, 0xFF},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00}, // not used
+ {0x00, 0x00, 0x00, 0x00}, // not used
+ ///////////// Reserved /////////////
+ {0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+};
+
+/**************************************************************************
+ * F U N C T I O N S *
+***************************************************************************/
+static BOOL is_memzero(unsigned char *buf, int size)
+{
+ int i;
+ for (i = 0; i < size; i++) {
+ if (*(buf+i) != 0) return FALSE;
+ }
+ return TRUE;
+}
+
+static void get_bt_structure(unsigned char *pucBTStructure)
+{
+ int fd = -1;
+ int i;
+ char bt_structure[128] = {0};
+ char buf[3] = {0};
+ int size = 0;
+ BPRINT_D("Get BT structure");
+
+ fd = open(BT_NVRAM_MANUFACTURE, O_RDONLY);
+ if (fd < 0) {
+ BPRINT_E("Open BT structure fails");
+ return;
+ }
+
+ size = read(fd, bt_structure, sizeof(bt_structure));
+
+ if (size < 0 || size != 128) {
+ BPRINT_E("Read BT structure fails, size:%d", size);
+ close(fd);
+ return;
+ }
+
+ for (i = 0; i < 128; i += 2) {
+ buf[0] = bt_structure[i];
+ buf[1] = bt_structure[i + 1];
+ pucBTStructure[i >> 1] = (unsigned char)strtoul(buf, NULL, 16);
+ }
+
+ close(fd);
+ BPRINT_D("Get BT structure PASS");
+}
+
+static int write_com_port(int fd, unsigned char *buf, unsigned int len)
+{
+ int nWritten = 0;
+ unsigned int bytesToWrite = len;
+
+ if (fd < 0) {
+ BPRINT_E("No available com port");
+ return -EIO;
+ }
+
+ while (bytesToWrite > 0) {
+ nWritten = write(fd, buf, bytesToWrite);
+ if (nWritten < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ break;
+ else
+ return -errno; /* errno used for whole chip reset */
+ }
+ bytesToWrite -= nWritten;
+ buf += nWritten;
+ }
+
+ return (len - bytesToWrite);
+}
+
+static int read_com_port(int fd, unsigned char *buf, unsigned int len)
+{
+ int nRead = 0;
+ unsigned int bytesToRead = len;
+
+ if (fd < 0) {
+ BPRINT_E("No available com port");
+ return -EIO;
+ }
+
+ nRead = read(fd, buf, bytesToRead);
+ if (nRead < 0) {
+ if(errno == EINTR || errno == EAGAIN)
+ return 0;
+ else
+ return -errno; /* errno used for whole chip reset */
+ }
+
+ return nRead;
+}
+
+static int bt_send_data(int fd, unsigned char *buf, unsigned int len)
+{
+ int bytesWritten = 0;
+ unsigned int bytesToWrite = len;
+
+ /* Try to send len bytes data in buffer */
+ while (bytesToWrite > 0) {
+ bytesWritten = write_com_port(fd, buf, bytesToWrite);
+ if (bytesWritten < 0) {
+ return -1;
+ }
+ bytesToWrite -= bytesWritten;
+ buf += bytesWritten;
+ }
+
+ return 0;
+}
+
+static int bt_receive_data(int fd, unsigned char *buf, unsigned int len)
+{
+ int bytesRead = 0;
+ unsigned int bytesToRead = len;
+
+ int ret = 0;
+ struct timeval tv;
+ fd_set readfd;
+
+ tv.tv_sec = 5; /* SECOND */
+ tv.tv_usec = 0; /* USECOND */
+ FD_ZERO(&readfd);
+
+ /* Try to receive len bytes */
+ while (bytesToRead > 0) {
+
+ FD_SET(fd, &readfd);
+ ret = select(fd + 1, &readfd, NULL, NULL, &tv);
+
+ if (ret > 0) {
+ bytesRead = read_com_port(fd, buf, bytesToRead);
+ if (bytesRead < 0) {
+ return -1;
+ }
+ else {
+ bytesToRead -= bytesRead;
+ buf += bytesRead;
+ }
+ }
+ else if (ret == 0) {
+ BPRINT_E("Read com port timeout 5000ms!");
+ return -1;
+ }
+ else if ((ret == -1) && (errno == EINTR)) {
+ BPRINT_E("select error EINTR");
+ }
+ else {
+ BPRINT_E("select error %s(%d)!", strerror(errno), errno);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static BOOL BT_SendHciCommand(INT32 comPort, HCI_CMD_T *pHciCommand)
+{
+ UINT8 ucHciCmd[256+4] = {0x01, 0x00, 0x00, 0x00};
+
+ ucHciCmd[1] = (UINT8)pHciCommand->opCode;
+ ucHciCmd[2] = (UINT8)(pHciCommand->opCode >> 8);
+ ucHciCmd[3] = pHciCommand->len;
+
+ BPRINT_D("OpCode 0x%04x len %d", pHciCommand->opCode, (INT32)pHciCommand->len);
+
+ if (pHciCommand->len) {
+ memcpy(&ucHciCmd[4], pHciCommand->parms, pHciCommand->len);
+ }
+
+ if (bt_send_data(comPort, ucHciCmd, pHciCommand->len + 4) < 0) {
+ BPRINT_E("Write HCI command fails errno %d", errno);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static BOOL BT_ReadPacketHeader(
+ INT32 comPort,
+ UINT8* pPacketType, /* Command, Event, ACL data, SCO data */
+ UINT16* pRemainLen, /* Remaining len for parameters */
+ UINT16* pOpCode, /* Command OpCode */
+ UINT16* pConnHandle, /* Connection handle */
+ UINT8* pEventCode /* Event code */
+ )
+{
+ UINT8 ucCmdHdr[3];
+ UINT8 ucAclHdr[4];
+ UINT8 ucScoHdr[3];
+ UINT8 ucEventHdr[2];
+ UINT8 type = 0;
+
+ /* Read UART header */
+ if (bt_receive_data(comPort, &type, 1) < 0) {
+ BPRINT_E("Read packet header fails");
+ return FALSE;
+ }
+
+ *pPacketType = type;
+
+ switch (type) {
+ case 1: /* Command */
+ if (bt_receive_data(comPort, ucCmdHdr, 3) < 0) {
+ BPRINT_E("Read command header fails %d", errno);
+ return FALSE;
+ }
+
+ *pOpCode = (((UINT16)ucCmdHdr[0]) | (((UINT16)ucCmdHdr[1]) << 8));
+ *pRemainLen = ucCmdHdr[2];
+ break;
+
+ case 2: /* ACL data */
+ if (bt_receive_data(comPort, ucAclHdr, 4) < 0) {
+ BPRINT_E("Read ACL header fails %d", errno);
+ return FALSE;
+ }
+
+ *pConnHandle = (((UINT16)ucAclHdr[0]) | (((UINT16)ucAclHdr[1]) << 8));
+ *pRemainLen = (((UINT16)ucAclHdr[2]) | (((UINT16)ucAclHdr[3]) << 8));
+ break;
+
+ case 3: /* SCO data */
+ if (bt_receive_data(comPort, ucScoHdr, 3) < 0) {
+ BPRINT_E("Read SCO header fails %d", errno);
+ return FALSE;
+ }
+
+ *pConnHandle = (((UINT16)ucScoHdr[0]) | (((UINT16)ucScoHdr[1]) << 8));
+ *pRemainLen = ucScoHdr[2];
+ break;
+
+ case 4: /* Event */
+ if (bt_receive_data(comPort, ucEventHdr, 2) < 0) {
+ BPRINT_E("Read event header fails %d", errno);
+ return FALSE;
+ }
+
+ *pEventCode = ucEventHdr[0];
+ *pRemainLen = ucEventHdr[1];
+ break;
+
+ default: /* other */
+ BPRINT_E("Unknown packet type %02x", type);
+ return FALSE;
+ break;
+ }
+
+ return TRUE;
+}
+
+static BOOL BT_ReadPacket(
+ INT32 comPort,
+ UINT8* pPacket,
+ UINT32 u4MaxBufSz,
+ UINT32* pu4PktLen
+ )
+{
+ UINT8 packetType;
+ UINT16 remainLen;
+ UINT16 opCode = 0, connHandle = 0;
+ UINT8 eventCode = 0;
+ UINT32 u4PktLen = 0;
+
+ if (u4MaxBufSz == 0) {
+ BPRINT_E("Read buffer size is zero!");
+ return FALSE;
+ }
+
+ if (BT_ReadPacketHeader(
+ comPort,
+ &packetType,
+ &remainLen,
+ &opCode,
+ &connHandle,
+ &eventCode) == FALSE) {
+
+ BPRINT_E("Read packet header fails");
+ return FALSE;
+ }
+
+ pPacket[0] = packetType;
+ u4PktLen ++;
+
+ /* Command packet */
+ if (packetType == 1) {
+ if (u4MaxBufSz < (UINT32)(4 + remainLen)) {
+ BPRINT_E("Read command buffer is too short!");
+ return FALSE;
+ }
+
+ pPacket[u4PktLen] = (UINT8)opCode;
+ pPacket[u4PktLen + 1] = (UINT8)(opCode >> 8);
+ u4PktLen += 2;
+
+ pPacket[u4PktLen] = (UINT8)remainLen;
+ u4PktLen ++;
+
+ if (bt_receive_data(comPort, pPacket + u4PktLen, remainLen) < 0) {
+ BPRINT_E("Read remain packet fails %d", errno);
+ return FALSE;
+ }
+
+ u4PktLen += remainLen;
+ *pu4PktLen = u4PktLen;
+
+ return TRUE;
+ }
+
+ /* ACL data */
+ if (packetType == 2) {
+ if (u4MaxBufSz < (UINT32)(5 + remainLen)) {
+ BPRINT_E("Read ACL buffer is too short!");
+ return FALSE;
+ }
+
+ pPacket[u4PktLen] = (UINT8)connHandle;
+ pPacket[u4PktLen + 1] = (UINT8)(connHandle >> 8);
+ u4PktLen += 2;
+
+ pPacket[u4PktLen] = (UINT8)remainLen;
+ pPacket[u4PktLen + 1] = (UINT8)(remainLen >> 8);
+ u4PktLen += 2;
+
+ if (bt_receive_data(comPort, pPacket + u4PktLen, remainLen) < 0) {
+ BPRINT_E("Read remain packet fails %d", errno);
+ return FALSE;
+ }
+
+ u4PktLen += remainLen;
+ *pu4PktLen = u4PktLen;
+
+ return TRUE;
+ }
+
+ /* SCO data */
+ if (packetType == 3) {
+ if (u4MaxBufSz < (UINT32)(4 + remainLen)) {
+ BPRINT_E("Read SCO buffer is too short!");
+ return FALSE;
+ }
+
+ pPacket[u4PktLen] = (UINT8)connHandle;
+ pPacket[u4PktLen + 1] = (UINT8)(connHandle >> 8);
+ u4PktLen += 2;
+
+ pPacket[u4PktLen] = (UINT8)remainLen;
+ u4PktLen ++;
+
+ if (bt_receive_data(comPort, pPacket + u4PktLen, remainLen) < 0) {
+ BPRINT_E("Read remain packet fails %d", errno);
+ return FALSE;
+ }
+
+ u4PktLen += remainLen;
+ *pu4PktLen = u4PktLen;
+
+ return TRUE;
+ }
+
+ /* Event packet */
+ if (packetType == 4) {
+ if(u4MaxBufSz < (UINT32)(3 + remainLen)) {
+ BPRINT_E("Read event buffer is too short!");
+ return FALSE;
+ }
+
+ pPacket[u4PktLen] = eventCode;
+ pPacket[u4PktLen + 1] = (UINT8)remainLen;
+ u4PktLen += 2;
+
+ if (bt_receive_data(comPort, pPacket + u4PktLen, remainLen) < 0) {
+ BPRINT_E("Read remain packet fails %d", errno);
+ return FALSE;
+ }
+
+ u4PktLen += remainLen;
+ *pu4PktLen = u4PktLen;
+
+ return TRUE;
+ }
+
+ BPRINT_E("Unknown packet type");
+
+ return FALSE;
+}
+
+BOOL BT_ReadExpectedEvent(
+ INT32 comPort,
+ UINT8* pEventPacket,
+ UINT32 u4MaxBufSz,
+ UINT32* pu4PktLen,
+ UINT8 ucExpectedEventCode,
+ BOOL fCheckCompleteOpCode,/* whether to check command OpCode */
+ UINT16 u2ExpectedOpCode,
+ BOOL fCheckCommandStatus, /* whether to check command status */
+ UINT8 ucExpectedStatus
+ )
+{
+ UINT16 u2OpCode;
+ UINT8 ucEventCode, ucStatus;
+
+ if (BT_ReadPacket(
+ comPort,
+ pEventPacket,
+ u4MaxBufSz,
+ pu4PktLen) == FALSE) {
+
+ BPRINT_E("Read packet fails");
+ return FALSE;
+ }
+
+ /* Expect Event only */
+ if (pEventPacket[0] != 4) {
+ BPRINT_E("Unexpected packet type");
+ return FALSE;
+ }
+
+ ucEventCode = pEventPacket[1];
+
+ if (ucEventCode != ucExpectedEventCode) {
+ BPRINT_E("Unexpected event code");
+ return FALSE;
+ }
+
+ if (ucEventCode == 0x0E) {
+ if (fCheckCompleteOpCode) {
+ u2OpCode = ((UINT16)pEventPacket[4]) | (((UINT16)pEventPacket[5]) << 8);
+
+ if (u2OpCode != u2ExpectedOpCode) {
+ BPRINT_E("Unexpected OpCode");
+ return FALSE;
+ }
+ }
+ if (fCheckCommandStatus) {
+ ucStatus = pEventPacket[6];
+
+ if (ucStatus != ucExpectedStatus) {
+ BPRINT_E("Unexpected status %02x", ucStatus);
+ return FALSE;
+ }
+ }
+ }
+
+ if (ucEventCode == 0x0F) {
+ if (fCheckCompleteOpCode) {
+ u2OpCode = ((UINT16)pEventPacket[5]) | (((UINT16)pEventPacket[6]) << 8);
+
+ if (u2OpCode != u2ExpectedOpCode) {
+ BPRINT_E("Unexpected OpCode");
+ return FALSE;
+ }
+ }
+
+ if (fCheckCommandStatus) {
+ ucStatus = pEventPacket[3];
+
+ if (ucStatus != ucExpectedStatus) {
+ BPRINT_E("Unexpected status %02x", ucStatus);
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+static BOOL WriteBDAddrToNvram(UCHAR *pucBDAddr)
+{
+ UNUSED(pucBDAddr);
+ // TODO
+ return TRUE;
+}
+
+static BOOL BT_Get_Local_BD_Addr(UCHAR *pucBDAddr)
+{
+ HCI_CMD_T cmd;
+ UINT32 u4ReadLen = 0;
+ UINT8 ucAckEvent[20];
+
+ cmd.opCode = 0x1009;
+ cmd.len = 0;
+
+ BPRINT_D("BT_Get_Local_BD_Addr");
+
+ if (BT_SendHciCommand(bt_com_port, &cmd) == FALSE) {
+ BPRINT_E("Write get BD address command fails");
+ return FALSE;
+ }
+
+ /* Read local BD address from F/W */
+ if (BT_ReadExpectedEvent(
+ bt_com_port,
+ ucAckEvent,
+ sizeof(ucAckEvent),
+ &u4ReadLen,
+ 0x0E,
+ TRUE,
+ 0x1009,
+ TRUE,
+ 0x00) == FALSE) {
+
+ BPRINT_E("Read local BD address fails");
+ return FALSE;
+ }
+
+ BPRINT_W("Local BD address: %02x-%02x-%02x-%02x-%02x-%02x",
+ ucAckEvent[12], ucAckEvent[11], ucAckEvent[10],
+ ucAckEvent[9], ucAckEvent[8], ucAckEvent[7]);
+
+ pucBDAddr[0] = ucAckEvent[12];
+ pucBDAddr[1] = ucAckEvent[11];
+ pucBDAddr[2] = ucAckEvent[10];
+ pucBDAddr[3] = ucAckEvent[9];
+ pucBDAddr[4] = ucAckEvent[8];
+ pucBDAddr[5] = ucAckEvent[7];
+
+ return TRUE;
+}
+
+#ifdef BD_ADDR_AUTOGEN
+static VOID GetRandomValue(UCHAR string[6])
+{
+ INT32 iRandom = 0;
+ INT32 fd = 0;
+ UINT32 seed;
+
+ BPRINT_W("Enable random generation");
+
+ /* Initialize random seed */
+ srand(time(NULL));
+ iRandom = rand();
+ BPRINT_W("iRandom = [%d]", iRandom);
+ string[0] = (((iRandom>>24|iRandom>>16) & (0xFE)) | (0x02)); /* Must use private bit(1) and no BCMC bit(0) */
+
+ /* second seed */
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ srand(tv.tv_usec);
+ iRandom = rand();
+ BPRINT_W("iRandom = [%d]", iRandom);
+ string[1] = ((iRandom>>8) & 0xFF);
+
+ /* third seed */
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd >= 0) {
+ if (read(fd, &seed, sizeof(UINT32)) > 0) {
+ srand(seed);
+ iRandom = rand();
+ }
+ close(fd);
+ }
+
+ BPRINT_W("iRandom = [%d]", iRandom);
+ string[5] = (iRandom & 0xFF);
+
+ return;
+}
+#endif // BD_ADDR_AUTOGEN
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Local_BD_Addr(VOID)
+{
+ UCHAR ucDefaultAddr[6] = {0};
+ UCHAR ucZeroAddr[6] = {0};
+
+ hciCmd.opCode = 0xFC1A;
+ hciCmd.len = 6;
+
+ BPRINT_D("GORMcmd_HCC_Set_Local_BD_Addr");
+
+ switch (btinit->chip_id) {
+ case 0x6630:
+ memcpy(ucDefaultAddr, stBtDefault_6630.addr, 6);
+ break;
+ case 0x8167:
+ memcpy(ucDefaultAddr, stBtDefault_8167.addr, 6);
+ break;
+ default:
+ BPRINT_E("Unknown combo chip id: %04x", btinit->chip_id);
+ break;
+ }
+
+ if ((0 == memcmp(btinit->bt_nvram.fields.addr, ucDefaultAddr, 6)) ||
+ (0 == memcmp(btinit->bt_nvram.fields.addr, ucZeroAddr, 6))) {
+ BPRINT_W("NVRAM BD address default value");
+ /* Want to retrieve module eFUSE address on combo chip */
+ BT_Get_Local_BD_Addr(btinit->bt_nvram.fields.addr);
+
+ if ((0 == memcmp(btinit->bt_nvram.fields.addr, ucDefaultAddr, 6)) ||
+ (0 == memcmp(btinit->bt_nvram.fields.addr, ucZeroAddr, 6))) {
+ BPRINT_W("eFUSE address default value");
+ #ifdef BD_ADDR_AUTOGEN
+ GetRandomValue(btinit->bt_nvram.fields.addr);
+ #endif
+ }
+ else {
+ BPRINT_W("eFUSE address has valid value");
+ }
+
+ /* Save BD address to NVRAM */
+ WriteBDAddrToNvram(btinit->bt_nvram.fields.addr);
+ }
+ else {
+ BPRINT_W("NVRAM BD address has valid value");
+ }
+
+ hciCmd.parms[0] = btinit->bt_nvram.fields.addr[5];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.addr[4];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.addr[3];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.addr[2];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.addr[1];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.addr[0];
+
+ BPRINT_W("Write BD address: %02x-%02x-%02x-%02x-%02x-%02x",
+ hciCmd.parms[5], hciCmd.parms[4], hciCmd.parms[3],
+ hciCmd.parms[2], hciCmd.parms[1], hciCmd.parms[0]);
+
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_PCM(VOID)
+{
+ hciCmd.opCode = 0xFC72;
+ hciCmd.len = 4;
+
+ hciCmd.parms[0] = btinit->bt_nvram.fields.Codec[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.Codec[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.Codec[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.Codec[3];
+
+ BPRINT_D("GORMcmd_HCC_Set_PCM");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Radio(VOID)
+{
+ hciCmd.opCode = 0xFC79;
+
+ if (btinit->chip_id != 0x6632) {
+ hciCmd.len = 6;
+ hciCmd.parms[0] = btinit->bt_nvram.fields.Radio[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.Radio[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.Radio[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.Radio[3];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.Radio[4];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.Radio[5];
+ } else {
+ hciCmd.len = 8;
+ hciCmd.parms[0] = btinit->bt_nvram.fields.Radio[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.Radio[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.Radio[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.Radio[3];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.Radio[4];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.Radio[5];
+ hciCmd.parms[6] = btinit->bt_nvram.fields.Radio_ext[0];
+ hciCmd.parms[7] = btinit->bt_nvram.fields.Radio_ext[1];
+ }
+
+ BPRINT_D("GORMcmd_HCC_Set_Radio");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_TX_Power_Offset(VOID)
+{
+ hciCmd.opCode = 0xFC93;
+
+ if (btinit->chip_id != 0x6632) {
+ hciCmd.len = 3;
+ hciCmd.parms[0] = btinit->bt_nvram.fields.TxPWOffset[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.TxPWOffset[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.TxPWOffset[2];
+ } else {
+ hciCmd.len = 6;
+ hciCmd.parms[0] = btinit->bt_nvram.fields.TxPWOffset[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.TxPWOffset[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.TxPWOffset[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.TxPWOffset_ext[0];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.TxPWOffset_ext[1];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.TxPWOffset_ext[2];
+ }
+
+ BPRINT_D("GORMcmd_HCC_Set_TX_Power_Offset");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Set_Sleep_Timeout(VOID)
+{
+ hciCmd.opCode = 0xFC7A;
+ hciCmd.len = 7;
+
+ hciCmd.parms[0] = btinit->bt_nvram.fields.Sleep[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.Sleep[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.Sleep[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.Sleep[3];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.Sleep[4];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.Sleep[5];
+ hciCmd.parms[6] = btinit->bt_nvram.fields.Sleep[6];
+
+ BPRINT_D("GORMcmd_HCC_Set_Sleep_Timeout");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_RESET(VOID)
+{
+ hciCmd.opCode = 0x0C03;
+ hciCmd.len = 0;
+
+ BPRINT_D("GORMcmd_HCC_RESET");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else {
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORMcmd_HCC_Coex_Performance_Adjust(VOID)
+{
+ hciCmd.opCode = 0xFC22;
+ hciCmd.len = 6;
+
+ hciCmd.parms[0] = btinit->bt_nvram.fields.CoexAdjust[0];
+ hciCmd.parms[1] = btinit->bt_nvram.fields.CoexAdjust[1];
+ hciCmd.parms[2] = btinit->bt_nvram.fields.CoexAdjust[2];
+ hciCmd.parms[3] = btinit->bt_nvram.fields.CoexAdjust[3];
+ hciCmd.parms[4] = btinit->bt_nvram.fields.CoexAdjust[4];
+ hciCmd.parms[5] = btinit->bt_nvram.fields.CoexAdjust[5];
+
+ BPRINT_D("GORMcmd_HCC_Coex_Performance_Adjust");
+
+ if (BT_SendHciCommand(bt_com_port, &hciCmd) == TRUE) {
+ return BT_STATUS_SUCCESS;
+ }
+ else{
+ return BT_STATUS_FAILED;
+ }
+}
+
+static ENUM_BT_STATUS_T GORM_Init(
+ INT32 comPort,
+ UINT32 chipId,
+ PUCHAR pucPatchExtData,
+ UINT32 u4PatchExtLen,
+ PUCHAR pucPatchData,
+ UINT32 u4PatchLen,
+ PUCHAR pucNvRamData,
+ UINT32 u4Baud,
+ UINT32 u4HostBaud,
+ UINT32 u4FlowControl
+ )
+{
+ INT32 i = 0;
+ ENUM_BT_STATUS_T status;
+ UINT8 ucEventBuf[MAX_EVENT_SIZE];
+ UINT32 u4EventLen;
+ UNUSED(pucPatchExtData);
+ UNUSED(u4PatchExtLen);
+ UNUSED(pucPatchData);
+ UNUSED(u4PatchLen);
+ UNUSED(u4Baud);
+ UNUSED(u4HostBaud);
+ UNUSED(u4FlowControl);
+
+ BPRINT_D("GORM_Init");
+
+ /* Save com port fd for GORMcmds */
+ bt_com_port = comPort;
+ /* Save chip id */
+ btinit->chip_id = chipId;
+ /* Copy NVRAM data */
+ memcpy(btinit->bt_nvram.raw, pucNvRamData, sizeof(ap_nvram_btradio_struct));
+
+ /* General init script */
+ switch (btinit->chip_id) {
+ case 0x6630:
+ btinit->cur_script = bt_init_script_6630;
+ break;
+ case 0x8167:
+ btinit->cur_script = bt_init_script_8167;
+ break;
+ default:
+ BPRINT_E("Unknown combo chip id: %04x", btinit->chip_id);
+ break;
+ }
+
+ /* Can not find matching script, simply skip */
+ if ((btinit->cur_script) == NULL) {
+ BPRINT_E("No matching init script");
+ return BT_STATUS_FAILED;
+ }
+
+ i = 0;
+
+ while (btinit->cur_script[i].command_func)
+ {
+ status = btinit->cur_script[i].command_func();
+ if (status == BT_STATUS_CANCELLED) {
+ i ++;
+ continue; /*skip*/
+ }
+
+ if (status == BT_STATUS_FAILED) {
+ BPRINT_E("Command %d fails", i);
+ return status;
+ }
+
+ if (BT_ReadExpectedEvent(
+ comPort,
+ ucEventBuf,
+ MAX_EVENT_SIZE,
+ &u4EventLen,
+ 0x0E,
+ TRUE,
+ hciCmd.opCode,
+ TRUE,
+ 0x00) == FALSE) {
+
+ BPRINT_E("Read event of command %d fails", i);
+ return BT_STATUS_FAILED;
+ }
+
+ i ++;
+ }
+
+ return BT_STATUS_SUCCESS;
+}
+
+uint32_t mtk_66xx_detect(void)
+{
+ uint32_t chipId = 0;
+#ifdef MTK_ANDROID_PLATFORM
+ char chipId_val[64];
+
+ if (osi_property_get(WCN_COMBO_LOADER_CHIP_ID_PROP, chipId_val, NULL) &&
+ strcmp(chipId_val, "-1") != 0)
+ chipId = (uint32_t)strtoul(chipId_val, NULL, 16);
+ else
+ BPRINT_D("Can't find \"%s\" property for chip ID",
+ WCN_COMBO_LOADER_CHIP_ID_PROP);
+#elif defined(MTK_CHIP_COMBO)
+ chipId = 0x6630;
+#elif defined(MTK_CHIP_CONSYS)
+ chipId = 0x8167;
+#else
+ // Pure Linux system detect chip id
+ char *chipId_val = getenv(WCN_COMBO_LOADER_CHIP_ID_PROP);
+ if (chipId_val)
+ chipId = (uint32_t)strtoul(chipId_val, NULL, 16);
+ else
+ BPRINT_D("Can't find \"%s\" environment variable for chip ID",
+ WCN_COMBO_LOADER_CHIP_ID_PROP);
+#endif
+
+ BPRINT_D("chip id %x", chipId);
+ return chipId;
+}
+
+int mtk_66xx_Init(int comPort, unsigned int chipId)
+{
+ UNUSED(boots_btif);
+ ENUM_BT_STATUS_T status;
+ unsigned char ucNvRamData[sizeof(ap_nvram_btradio_struct)] = {0};
+
+ get_bt_structure(ucNvRamData);
+
+ if (is_memzero(ucNvRamData, sizeof(ap_nvram_btradio_struct))) {
+ BPRINT_E("Read NVRAM data fails or NVRAM data all zero!!");
+ BPRINT_W("Use %x default value", chipId);
+ switch (chipId) {
+ case 0x6630:
+ /* Use MT6630 default value */
+ memcpy(ucNvRamData, &stBtDefault_6630, sizeof(ap_nvram_btradio_struct));
+ break;
+ case 0x8167:
+ /* Use MT8167 default value */
+ memcpy(ucNvRamData, &stBtDefault_8167, sizeof(ap_nvram_btradio_struct));
+ break;
+ default:
+ BPRINT_E("Unknown combo chip id: %04x\n", chipId);
+ return -1;
+ }
+ }
+
+ BPRINT_I("[BDAddr:%02x-%02x-%02x-%02x-%02x-%02x]",
+ ucNvRamData[0], ucNvRamData[1], ucNvRamData[2],
+ ucNvRamData[3], ucNvRamData[4], ucNvRamData[5]);
+ BPRINT_I("[Voice :%02x %02x]", ucNvRamData[6], ucNvRamData[7]);
+ BPRINT_I("[Codec :%02x %02x %02x %02x]",
+ ucNvRamData[8], ucNvRamData[9], ucNvRamData[10], ucNvRamData[11]);
+ BPRINT_I("[Radio :%02x %02x %02x %02x %02x %02x]",
+ ucNvRamData[12], ucNvRamData[13], ucNvRamData[14],
+ ucNvRamData[15], ucNvRamData[16], ucNvRamData[17]);
+ BPRINT_I("[Sleep :%02x %02x %02x %02x %02x %02x %02x]",
+ ucNvRamData[18], ucNvRamData[19], ucNvRamData[20], ucNvRamData[21],
+ ucNvRamData[22], ucNvRamData[23], ucNvRamData[24]);
+ BPRINT_I("[BtFTR: %02x %02x]", ucNvRamData[25], ucNvRamData[26]);
+ BPRINT_I("[TxPWOffset:%02x %02x %02x]", ucNvRamData[27], ucNvRamData[28], ucNvRamData[29]);
+ BPRINT_I("[CoexAdjust:%02x %02x %02x %02x %02x %02x]",
+ ucNvRamData[30], ucNvRamData[31], ucNvRamData[32],
+ ucNvRamData[33], ucNvRamData[34], ucNvRamData[35]);
+ BPRINT_I("[Radio_ext :%02x %02x]", ucNvRamData[36], ucNvRamData[37]);
+ BPRINT_I("[TxPWOffset_ext:%02x %02x %02x]", ucNvRamData[38], ucNvRamData[39], ucNvRamData[40]);
+
+ status = GORM_Init(comPort, chipId, NULL, 0, NULL, 0, ucNvRamData, 0, 0, 0);
+
+ return (int)status;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_mt6xx.h b/src/connectivity/bt_others/boots/boots_mt6xx.h
new file mode 100644
index 0000000..da2b02a
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_mt6xx.h
@@ -0,0 +1,152 @@
+/* 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) 2016~2017. 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.
+ */
+
+#ifndef __BOOTS_MT6XX_H__
+#define __BOOTS_MT6XX_H__
+
+#include <stdbool.h>
+/**
+ * Type definition
+ */
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef BOOL
+#define BOOL bool
+#endif
+
+typedef unsigned char UCHAR;
+typedef unsigned char UINT8;
+typedef unsigned short UINT16;
+typedef unsigned int UINT32;
+typedef char INT8;
+typedef short INT16;
+typedef int INT32;
+typedef long long INT64;
+typedef void VOID;
+typedef unsigned char* PUCHAR;
+
+
+/*
+ * Structure Definitions
+ */
+#define HCI_CMD_PARM_LEN 256
+#define MAX_EVENT_SIZE 256
+
+typedef struct _HCI_CMD_T {
+ UINT16 opCode; /* HCI command OpCode */
+ UINT8 len; /* Length of the command parameters */
+ UINT8 parms[HCI_CMD_PARM_LEN];
+} HCI_CMD_T;
+
+typedef struct _HCI_EVENT_T {
+ UINT8 event; /* HCI event type */
+ UINT8 len; /* Length of the event parameters */
+ UINT8 *parms; /* Event specific parameters */
+} HCI_EVENT_T;
+
+
+typedef enum _ENUM_BT_STATUS_T {
+ BT_STATUS_SUCCESS = 0,
+ BT_STATUS_FAILED,
+ BT_STATUS_PENDING,
+ BT_STATUS_BUSY,
+ BT_STATUS_NO_RESOURCES,
+ BT_STATUS_NOT_FOUND,
+ BT_STATUS_DEVICE_NOT_FOUND,
+ BT_STATUS_CONNECTION_FAILED,
+ BT_STATUS_TIMEOUT,
+ BT_STATUS_NO_CONNECTION,
+ BT_STATUS_INVALID_PARM,
+ BT_STATUS_IN_PROGRESS,
+ BT_STATUS_RESTRICTED,
+ BT_STATUS_INVALID_TYPE,
+ BT_STATUS_HCI_INIT_ERR,
+ BT_STATUS_NOT_SUPPORTED,
+ BT_STATUS_IN_USE,
+ BT_STATUS_SDP_CONT_STATE,
+ BT_STATUS_CANCELLED,
+ BT_STATUS_NOSERVICES,
+ BT_STATUS_SCO_REJECT,
+ BT_STATUS_CHIP_REASON,
+ BT_STATUS_BLOCK_LIST,
+ BT_STATUS_SCATTERNET_REJECT
+} ENUM_BT_STATUS_T;
+
+/* The record structure of bt nvram file */
+typedef struct
+{
+ unsigned char addr[6]; /* BT address */
+ unsigned char Voice[2]; /* Voice setting for SCO connection */
+ unsigned char Codec[4]; /* PCM codec setting */
+ unsigned char Radio[6]; /* RF configuration */
+ unsigned char Sleep[7]; /* Sleep mode configuration */
+ unsigned char BtFTR[2]; /* Other feature setting */
+ unsigned char TxPWOffset[3]; /* TX power channel offset compensation */
+ unsigned char CoexAdjust[6]; /* BT/WIFI coexistence performance adjustment */
+ unsigned char Radio_ext[2]; /* RF configuration extended parameters */
+ unsigned char TxPWOffset_ext[4]; /* Tx power channel offset compensation with new range */
+ unsigned char Reserved1[2]; /* Reserved */
+ unsigned char Reserved2[4]; /* Reserved */
+ unsigned char Reserved3[8]; /* Reserved */
+ unsigned char Reserved4[8]; /* Reserved */
+}__attribute__((packed)) ap_nvram_btradio_struct;
+
+
+typedef union {
+ ap_nvram_btradio_struct fields;
+ unsigned char raw[sizeof(ap_nvram_btradio_struct)];
+} BT_NVRAM_DATA_T;
+
+typedef ENUM_BT_STATUS_T (*HCI_CMD_FUNC_T)(VOID);
+typedef struct {
+ HCI_CMD_FUNC_T command_func;
+} HCI_SEQ_T;
+
+typedef struct {
+ UINT32 chip_id;
+ BT_NVRAM_DATA_T bt_nvram;
+ HCI_SEQ_T *cur_script;
+} BT_INIT_VAR_T;
+
+/*
+* Function Declaration
+*/
+#endif // __BOOTS_MT6XX_H__
diff --git a/src/connectivity/bt_others/boots/boots_osi.c b/src/connectivity/bt_others/boots/boots_osi.c
new file mode 100644
index 0000000..03dbb78
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_osi.c
@@ -0,0 +1,107 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#ifdef MTK_ANDROID_PLATFORM
+#include <cutils/properties.h>
+#endif
+
+#include "boots.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_osi"
+
+//---------------------------------------------------------------------------
+int osi_property_get(const char *key, char *value, const char *default_value)
+{
+ UNUSED(boots_btif);
+#ifdef MTK_ANDROID_PLATFORM
+ return property_get(key, value, default_value);
+#else
+ UNUSED(key);
+ UNUSED(value);
+ UNUSED(default_value);
+ BPRINT_E("%s: Do not support this OSI currently", __func__);
+ return -1;
+#endif
+}
+
+//---------------------------------------------------------------------------
+int osi_property_set(const char *key, const char *value)
+{
+#ifdef MTK_ANDROID_PLATFORM
+ return property_set(key, value);
+#else
+ UNUSED(key);
+ UNUSED(value);
+ BPRINT_E("%s: Do not support this OSI currently", __func__);
+ return -1;
+#endif
+}
+
+int osi_system(const char *cmd)
+{
+ FILE *fp;
+ int ret;
+
+ if (cmd == NULL) {
+ BPRINT_E("%s: cmd is NULL", __func__);
+ return -1;
+ }
+
+ fp = popen(cmd, "w");
+ if (fp == NULL) {
+ BPRINT_E("%s: (%s) failed", __func__, cmd);
+ return -1;
+ }
+
+ BPRINT_I("Command: %s\n", cmd);
+
+ ret = pclose(fp);
+ if (ret < 0) {
+ BPRINT_E("%s: pclose ret = %d", __func__, ret);
+ } else if (ret > 0) {
+ BPRINT_I("%s: pclose ret = %d", __func__, ret);
+ }
+ return ret;
+}
+
diff --git a/src/connectivity/bt_others/boots/boots_osi.h b/src/connectivity/bt_others/boots/boots_osi.h
new file mode 100644
index 0000000..960af0b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_osi.h
@@ -0,0 +1,47 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_OSI_H__
+#define __BOOTS_OSI_H__
+
+int osi_property_get(const char *key, char *value, const char *default_value);
+int osi_property_set(const char *key, const char *value);
+
+int osi_system(const char *cmd);
+
+#endif // __BOOTS_OSI_H__
diff --git a/src/connectivity/bt_others/boots/boots_pkt.c b/src/connectivity/bt_others/boots/boots_pkt.c
new file mode 100644
index 0000000..0712874
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_pkt.c
@@ -0,0 +1,3308 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "boots_pkt.h"
+#include "boots_stress.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_pkt"
+
+#define HCE_INQUIRY_COMPLETE 0x01
+#define HCE_INQUIRY_RESULT 0x02
+#define HCE_CONNECTION_COMPLETE 0x03
+#define HCE_COMMAND_COMPLETE 0x0E
+#define HCE_INQUIRY_RESULT_WITH_RSSI 0x22
+#define HCE_EXT_INQUIRY_RESULT 0x2F
+
+#define DEFAULT_WIFI_CFG "/vendor/firmware/wifi.cfg"
+#define E2P_MODE "EfuseBufferModeCal"
+
+//---------------------------------------------------------------------------
+typedef struct {
+ uint8_t pt; // Packet Type
+ uint16_t len; // Data Length
+} packet_info_s;
+
+typedef enum {
+ WR_FLAG_NO,
+ WR_FLAG_READ,
+ WR_FLAG_WRITE
+} wr_flag_e;
+
+typedef struct {
+ uint32_t addr;
+ uint32_t value;
+ wr_flag_e wr_flag;
+} efuse_reg_wr_s;
+
+static const packet_info_s tx_pi[] = { // TX packet info
+ {0x00, 0x0000}, {0x01, 0x0000}, {0x02, 0x0000}, {0x03, 0x0011},
+ {0x04, 0x001B}, {0x05, 0x000A}, {0x06, 0x0014}, {0x07, 0x001E},
+ {0x08, 0x0013}, {0x09, 0x000A}, {0x0A, 0x0079}, {0x0B, 0x00B7},
+ {0x0E, 0x00E0}, {0x0F, 0x0153}, {0x17, 0x001E}, {0x1C, 0x0078},
+ {0x1D, 0x00B4}, {0x24, 0x0036}, {0x28, 0x0053}, {0x2A, 0x016F},
+ {0x2B, 0x0228}, {0x2E, 0x02A7}, {0x2F, 0x03FD}, {0x36, 0x003C},
+ {0x37, 0x005A}, {0x3C, 0x0168}, {0x3D, 0x021C}};
+
+static const packet_info_s rx_pi[] = { // RX packet info
+ {0x03, 0x0011}, {0x04, 0x001B}, {0x0A, 0x0079}, {0x0B, 0x00B7},
+ {0x0E, 0x00E0}, {0x0F, 0x0153}, {0x24, 0x0036}, {0x28, 0x0053},
+ {0x2A, 0x016F}, {0x2B, 0x0053}, {0x2E, 0x02A7}, {0x2F, 0x03FD}};
+
+static efuse_reg_wr_s efuse_reg_wr = {0, 0, WR_FLAG_NO};
+static int rssi_channels[79];
+static int rssi_count = 0;
+
+extern int boots_loop_timer;
+extern rssi_set_s rssi_setting;
+
+//---------------------------------------------------------------------------
+static void boots_write_stpbtfwlog(char *buf);
+
+//---------------------------------------------------------------------------
+void boots_pkt_cleanup_report_rssi(uint8_t stop)
+{
+ int i = 0;
+
+ if ((rssi_setting.report == true) && (rssi_count != 0) && (stop == 1)) {
+ BPRINT_I_RAW("\nPackage count: %d, RSSI: \n", rssi_count);
+ for (i = 0; i < 79 ; i++) {
+ rssi_channels[i] = rssi_channels[i] / rssi_count;
+ if (i >= rssi_setting.ch_start && i <= rssi_setting.ch_end) {
+ BPRINT_I_RAW("% 4d ", rssi_channels[i]);
+ } else {
+ BPRINT_I_RAW(" ");
+ }
+ if ((i + 1) % 10 == 0 || i == 78) {
+ BPRINT_I_RAW("\n");
+ }
+ }
+ }
+ rssi_count = 0;
+ memset(rssi_channels, 0x00, sizeof(rssi_channels));
+ memset(&rssi_setting, 0x00, sizeof(rssi_set_s));
+}
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_pkt_node_push(uint8_t s_type, uint8_t p_type, void *content,
+ size_t len, pkt_list_s *front, pkt_list_s *head)
+{
+ // Create node
+ pkt_list_s *node = (pkt_list_s *)malloc(sizeof(pkt_list_s));
+
+ if (!node) {
+ BPRINT_D("%s: List allocate fail", __func__);
+ return NULL;
+ }
+
+ node->s_type = s_type;
+ switch (s_type) {
+ case SCRIPT_NONE:
+ case SCRIPT_TX:
+ case SCRIPT_RX:
+ case SCRIPT_WAITRX:
+ case SCRIPT_CMD:
+ case SCRIPT_STRESS:
+ case SCRIPT_LOOPBACK:
+ case SCRIPT_LPTIMER:
+ node->p_type = p_type;
+ if (len > 0)
+ node->u_cnt.data = (uint8_t *)malloc(len);
+ if (content && node->u_cnt.data) {
+ memcpy(node->u_cnt.data, (uint8_t *)content, len);
+ node->len = len;
+ }
+ break;
+ case SCRIPT_TITLE:
+ case SCRIPT_PROC:
+ if (len > 0)
+ node->u_cnt.msg = (char *)malloc(len);
+ if (content && node->u_cnt.msg) {
+ memcpy(node->u_cnt.msg, (char *)content, len);
+ node->len = len;
+ }
+ break;
+ case SCRIPT_RSSI:
+ if (len > 0)
+ node->u_cnt.rssi_s = (rssi_set_s *)malloc(len);
+ if (content && node->u_cnt.rssi_s) {
+ memcpy(node->u_cnt.rssi_s, content, len);
+ node->len = len;
+ }
+ break;
+ case SCRIPT_LOOP:
+ if (content)
+ node->u_cnt.loop = *((int *)content);
+ break;
+ case SCRIPT_TIMEOUT:
+ if (content)
+ node->u_cnt.timo = *((int *)content);
+ break;
+ case SCRIPT_WAIT:
+ if (content)
+ node->u_cnt.wait = *((int *)content);
+ break;
+ case SCRIPT_USBALT:
+ if (content)
+ node->u_cnt.usbalt = *((int *)content);
+ break;
+ case SCRIPT_LOOPEND:
+ case SCRIPT_END:
+ break;
+ default:
+ BPRINT_W("Incorrect Script Type: %d", s_type);
+ break;
+ }
+ if (front)
+ front->next = node;
+ node->next = head ? head : node;
+
+ // return node point
+ return node;
+}
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_pkt_node_pop(pkt_list_s *list, uint8_t *buf, size_t *len)
+{
+ pkt_list_s *tmp = NULL;
+
+ if (!list) return NULL;
+ //BPRINT_D("%s node: %p, next: %p", __func__, list, list->next);
+
+ if (buf && len) {
+ memcpy(buf, list->u_cnt.data, list->len);
+ *len = list->len;
+ }
+
+ // Remove this node from head
+ if (list->next == list) {
+ tmp = NULL;
+ } else {
+ pkt_list_s *tail = NULL;
+
+ tmp = list->next;
+ // round circle
+ tail = tmp;
+ while (tail->next != list) {
+ tail = tail->next;
+ }
+ tail->next = tmp;
+ }
+
+ switch (list->s_type) {
+ case SCRIPT_NONE:
+ case SCRIPT_TX:
+ case SCRIPT_RX:
+ case SCRIPT_WAITRX:
+ case SCRIPT_CMD:
+ free(list->u_cnt.data);
+ break;
+ case SCRIPT_TITLE:
+ case SCRIPT_PROC:
+ free(list->u_cnt.msg);
+ break;
+ case SCRIPT_STRESS:
+ case SCRIPT_LOOPBACK:
+ case SCRIPT_LPTIMER:
+ // return list directly, result in infinite loop.
+ return list;
+ case SCRIPT_RSSI:
+ free(list->u_cnt.rssi_s);
+ break;
+ default:
+ break;
+ }
+ free(list);
+
+ return tmp;
+}
+
+//---------------------------------------------------------------------------
+void boots_pkt_list_destroy(pkt_list_s *list)
+{
+ pkt_list_s *cur = list;
+ pkt_list_s *next = NULL;
+
+ if (!list) return;
+
+ do {
+ if (next) cur = next;
+ next = cur->next;
+ //BPRINT_D("%s cur: %p, next: %p", __func__, cur, next);
+ switch (cur->s_type) {
+ case SCRIPT_NONE:
+ case SCRIPT_TX:
+ case SCRIPT_RX:
+ case SCRIPT_WAITRX:
+ case SCRIPT_CMD:
+ free(cur->u_cnt.data);
+ break;
+ case SCRIPT_TITLE:
+ case SCRIPT_PROC:
+ free(cur->u_cnt.msg);
+ break;
+ default:
+ break;
+ }
+ free(cur);
+ } while (next != list && next != NULL);
+}
+
+//---------------------------------------------------------------------------
+size_t boots_pkt_list_amount(pkt_list_s *list)
+{
+ size_t amount = 1;
+ pkt_list_s *tmp = list;
+
+ if (!list) return 0;
+
+ while (tmp->next != list) {
+ amount++;
+ tmp = tmp->next;
+ }
+ return amount;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *boots_efuse_write(pkt_list_s *list, uint8_t *buf)
+{
+ pkt_list_s * pkt = NULL;
+ uint8_t efuse[] = {0x01, 0x6F, 0xFC, 0x18,
+ 0x01, 0x0D, 0x14, 0x00, 0x01, 0x01,
+ 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+ size_t len = 0;
+ uint16_t addr = 0;
+
+ boots_pkt_node_pop(list, efuse, &len);
+ if (len != sizeof(efuse)) {
+ BPRINT_E("Error! %d != %d", (int)len, (int)sizeof(efuse));
+ }
+
+ addr = efuse_reg_wr.addr / 16 * 4;
+ efuse[10] = addr & 0xFF;
+ efuse[11] = (addr & 0xFF00) >> 8;
+ memcpy(&efuse[12], &buf[2], 4);
+ memcpy(&efuse[16], &buf[8], 4);
+ memcpy(&efuse[20], &buf[14], 4);
+ memcpy(&efuse[24], &buf[20], 4);
+
+ memcpy(&efuse[12 + efuse_reg_wr.addr % 16], &efuse_reg_wr.value, 1);
+
+ pkt = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, efuse, sizeof(efuse),
+ NULL, NULL);
+
+ return pkt;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_file_wr(uint8_t *buf, ssize_t *len)
+{
+ int fd = 0;
+ uint32_t addr = 0;
+ uint8_t value = 0;
+ uint8_t wr = 0;
+ size_t ret = 0; // For compiling error
+
+ /****************************************************
+ format:
+ CMD: 01 01 FF LEN WR ADDR VALUE FILE_PATH
+ EVENT: 04 0E LEN 01 01 FF ERRNO WR ADDR VALUE
+
+ LEN: 1 byte
+ WR: 1 byte
+ ADDR: 4 bytes
+ VALUE: 1 byte
+ ERRNO: 2 bytes
+ FILE_PATH:
+ ****************************************************/
+
+ errno = 0;
+
+ fd = open((char *)&buf[10], O_RDWR);
+ if (fd < 0) {
+ printf("open file %s failed, errno = %s(%d)\n", &buf[10], strerror(errno), errno);
+ } else {
+ memcpy(&addr, &buf[5], sizeof(addr));
+ wr = buf[4];
+
+ (void)lseek(fd, addr, SEEK_SET);
+
+ if (wr == WR_FLAG_WRITE) {
+ value = buf[9];
+ ret = write(fd, &value, 1);
+ } else {
+ ret = read(fd, &value, 1);
+ }
+
+ close(fd);
+ }
+
+ buf[0] = 0x04;
+ buf[1] = 0x0E;
+ buf[2] = 0x0B;
+ buf[3] = 0x01;
+ buf[4] = 0x01;
+ buf[5] = 0xFF;
+ buf[6] = errno & 0xFF;
+ buf[7] = (errno & 0xFF00) >> 8;
+ buf[8] = wr;
+ memcpy(&buf[9], &addr, sizeof(addr));
+ buf[13] = value;
+ *len = 14;
+ return ret;
+}
+
+//--------------------------------------------------------------------------
+void boots_pkt_parsing(uint8_t *buf, size_t len)
+{
+ int i = 0;
+ float alpha_filter = 0;
+
+ if (!buf || !len) return;
+
+ if (buf[0] == HCI_EVENT_PKT) {
+ if (buf[1] == HCE_COMMAND_COMPLETE && len >= 7) {
+ switch (STREAM_TO_UINT16(buf + 4)) {
+ case 0x0C03: // RESET
+ BPRINT_I_RAW("(HCI_RESET)");
+ break;
+ case 0x1009: // Read BD address
+ if (len >= 13)
+ BPRINT_I_RAW("(Read BDADD: 0x%02X-%02X-%02X-%02X-%02X-%02X)",
+ buf[12], buf[11], buf[10], buf[9], buf[8], buf[7]);
+ break;
+ case 0xFC0D: // RF test
+ if (buf[2] == 20) { // length is 20 for RF RX results
+ uint32_t result = 0;
+
+ BPRINT_I_RAW("\n");
+ result = STREAM_TO_UINT32(buf + 7);
+ BPRINT_I_RAW("\t RX Packet Count: %d\n", result);
+ result = STREAM_TO_UINT32(buf + 11);
+ BPRINT_I_RAW("\t RX Error Rate: %f%%\n", (float)result / 1000000.f);
+ result = STREAM_TO_UINT32(buf + 15);
+ BPRINT_I_RAW("\t RX Byte Count: %d\n", result);
+ result = STREAM_TO_UINT32(buf + 19);
+ BPRINT_I_RAW("\t Bit Error Rate: %f%%", (float)result / 1000000.f);
+ }
+ break;
+ case 0x201F: // BLE RX test
+ BPRINT_I_RAW("\n");
+ if (buf[2] >= 6 && buf[6] == 0) {
+ uint16_t pktcount = STREAM_TO_UINT16(buf + 7);
+ BPRINT_I_RAW("\t RX Packet Count: %d", pktcount);
+ } else {
+ BPRINT_W("status or length is incorrect");
+ }
+ break;
+ case 0xFC61: // packet rssi
+ BPRINT_I_RAW("\n");
+ BPRINT_I_RAW("\t Packet handle is 0x%02X%02X, RSSI is %d\n", buf[8], buf[7], (int8_t)buf[9]);
+ break;
+ case 0xFCD1: // register read
+ BPRINT_I_RAW("(register addr: 0x%08X, value: 0x%02X%02X%02X%02X)", efuse_reg_wr.addr, buf[10], buf[9], buf[8], buf[7]);
+ break;
+ case 0xFF01: // file read/write
+ if (buf[6] == 0 && buf[7] == 0) {
+ if (buf[8] == WR_FLAG_READ)
+ BPRINT_I_RAW("(offset: 0x%02X%02X%02X%02X, value: 0x%02X)", buf[12], buf[11], buf[10], buf[9], buf[13]);
+ } else {
+ uint16_t err = buf[6] | (buf[7] << 8);
+ BPRINT_I_RAW("(Error(%d): %s)", err, strerror(err));
+ }
+ break;
+ case 0x1802: // loopback
+ BPRINT_I_RAW("(LOOP_BACK)");
+ break;
+ case 0xFCEA: // get xo mode
+ if (buf[7] == 0x00) {
+ BPRINT_I_RAW("(AX_MODE)");
+ } else if (buf[7] == 0x01) {
+ BPRINT_I_RAW("(BT_MODE)");
+ }
+ break;
+ }
+ } else if (buf[1] == HCE_INQUIRY_RESULT || buf[1] == HCE_INQUIRY_RESULT_WITH_RSSI
+ || buf[1] == HCE_EXT_INQUIRY_RESULT) {
+ BPRINT_I_RAW("(BDADDR:0x%02X-%02X-%02X-%02X-%02X-%02X",
+ buf[9], buf[8], buf[7], buf[6], buf[5], buf[4]);
+ if (buf[1] == HCE_INQUIRY_RESULT_WITH_RSSI || buf[1] == HCE_EXT_INQUIRY_RESULT) {
+ int8_t rssi = ~buf[17] + 1;
+ BPRINT_I_RAW(", RSSI:%s%d", buf[17] > 0x7F ? "-" : "",
+ buf[17] > 0x7F ? rssi : buf[17]);
+ }
+ if (buf[1] == HCE_EXT_INQUIRY_RESULT) {
+ size_t i = 18;
+ while (buf[i]) {
+ if (buf[i + 1] == 8 || buf[i + 1] == 9) {
+ char name[256] = {0};
+ memcpy(name, &buf[i + 2], buf[i] - 1);
+ name[buf[i] - 1] = '\0';
+ BPRINT_I_RAW(", Name:%s", name);
+ }
+ i += (buf[i] + 1);
+ }
+ }
+ BPRINT_I_RAW(")");
+ } else if (buf[1] == HCE_INQUIRY_COMPLETE) {
+ BPRINT_I_RAW("(Inquiry_Complete)");
+ } else if (buf[1] == HCE_CONNECTION_COMPLETE) {
+ if (buf[12] == 0x01) {
+ BPRINT_I_RAW("(Connection_Complete)(ConnHandle:0x%04X)(ACL)", (((buf[5] << 8) & 0xff00) | buf[4]));
+ } else if(buf[12] == 0x00) {
+ BPRINT_I_RAW("(Connection_Complete)(ConnHandle:0x%04X)(SCO)", (((buf[5] << 8) & 0xff00) | buf[4]));
+ } else {
+ BPRINT_I_RAW("(Connection_Complete)(ConnHandle:%d)", ((buf[5] << 8 & 0xff00) | buf[4]));
+ }
+ } else if (buf[1] == 0xE4 && efuse_reg_wr.wr_flag == WR_FLAG_READ) {
+ if ((efuse_reg_wr.addr / 16 * 4) != (buf[9] | (buf[10] << 8))) {
+ BPRINT_I_RAW("(Read efuse error!)");
+ } else {
+ int8_t offset = 9 + ((efuse_reg_wr.addr / 4) % 4) * 6 + 2 + (efuse_reg_wr.addr % 4);
+
+ BPRINT_I_RAW("(efuse addr: 0x%04X, value: 0x%02X)", efuse_reg_wr.addr, buf[offset]);
+ }
+ } else if (buf[1] == 0x4F && buf[2] == 0x50 && buf[3] == 0xCC) {
+ for (i = 0; i < 79 ; i++) {
+ if (rssi_setting.alpha_filter > 0) {
+ if (rssi_count == 0)
+ rssi_channels[i] += (int8_t)buf[4 + i] * -1;
+ else {
+ alpha_filter = 1.0 / rssi_setting.alpha_filter;
+ rssi_channels[i] = (int)((rssi_channels[i] * (1 - alpha_filter)) + ((int8_t)buf[4 + i] * -1 * alpha_filter));
+ }
+ } else {
+ rssi_channels[i] += (int8_t)buf[4 + i] * -1;
+ }
+ }
+ rssi_count++;
+ if (rssi_setting.report == false) {
+ if (rssi_count == rssi_setting.avg_package || rssi_setting.alpha_filter > 0) {
+ BPRINT_I_RAW("\nRSSI: \n");
+ for (i = 0; i < 79 ; i++) {
+ if (rssi_setting.alpha_filter == 0)
+ rssi_channels[i] = rssi_channels[i] / rssi_count;
+ if (i >= rssi_setting.ch_start && i <= rssi_setting.ch_end) {
+ BPRINT_I_RAW("% 4d ", rssi_channels[i]);
+ } else {
+ BPRINT_I_RAW(" ");
+ }
+ if ((i + 1) % 10 == 0 || i == 78) {
+ BPRINT_I_RAW("\n");
+ }
+ }
+ if (rssi_setting.one_shot == 1) {
+ boots_pkt_cleanup_report_rssi(1);
+ boots_write_stpbtfwlog("01 73 FD 01 00");
+ }
+ if (rssi_setting.alpha_filter == 0) {
+ for (i = 0; i < 79; i++)
+ rssi_channels[i] = 0;
+ rssi_count = 0;
+ }
+ }
+ }
+ }
+ }
+}
+
+size_t boots_pkt_handler_parse(uint8_t *buf, size_t len, pkt_list_s **pList)
+{
+ size_t i = 0;
+ size_t ret = 0;
+ pkt_list_s *list = NULL;
+ uint16_t show_len = BOOTS_MSG_LVL_DEFAULT <= BOOTS_MSG_LVL_INFO ? DEF_SHOW_LEN : 0xFFFF;
+
+ if (pList)
+ list = *pList;
+
+ if ((pList == NULL && !(buf[1] == 0x4F && buf[2] == 0x50 && buf[3] == 0xCC))||
+ (list && list->s_type != SCRIPT_STRESS && list->s_type != SCRIPT_LOOPBACK && list->s_type != SCRIPT_LPTIMER) ||
+ (list && (list->s_type == SCRIPT_STRESS || list->s_type == SCRIPT_LOOPBACK || list->s_type == SCRIPT_LPTIMER) && BOOTS_STRESS_SHOW_ALL_EVENT))
+ {
+ switch (buf[0]) {
+ case HCI_CMD_PKT:
+ BPRINT_I_RAW("\t CMD:");
+ break;
+ case HCI_ACL_PKT:
+ BPRINT_I_RAW("\t ACL:");
+ break;
+ case HCI_SCO_PKT:
+ BPRINT_I_RAW("\t SCO:");
+ break;
+ case HCI_EVENT_PKT:
+ BPRINT_I_RAW("\tEvent:");
+ break;
+ default:
+ BPRINT_E("Receive unknonw type %02X", buf[0]);
+ BPRINT_I_RAW(" Unknown %02X:", buf[0]);
+ exit(0);
+ }
+
+ // exclude extended
+ for (i = 1; i < len && i <= show_len; i++) {
+ BPRINT_I_RAW(" %02X", buf[i]);
+ }
+ BPRINT_I_RAW("%s ", len > show_len ? "..." : "");
+ boots_pkt_parsing(buf, len); // Parsing
+ BPRINT_I_RAW("\n");
+ }
+
+ if (len > 2 && buf[0] == HCI_EVENT_PKT) {
+ if (len >= (buf[2] + 3)) {
+ if (buf[1] == HCE_COMMAND_COMPLETE || buf[1] == HCE_INQUIRY_COMPLETE) {
+ // means received Command_Complete or Inquiry_Complete
+ ret = 0;
+ } else if (buf[1] == 0xE4 && buf[2] == 0x1E
+ && efuse_reg_wr.wr_flag == WR_FLAG_WRITE) {
+ if (pList) {
+ *pList = boots_efuse_write(list, &buf[9]);
+ if (*pList) ret = 1;
+ }
+ } else if (buf[1] == 0x4F && buf[2] == 0x50 && buf[3] == 0xCC) {
+ boots_pkt_parsing(buf, len); // Parsing
+ ret = 1;
+ } else {
+ ret = 1;
+ }
+ } else {
+ BPRINT_E("len = %d, buf[2] = %d", len, buf[2]);
+ ret = -1;
+ }
+ }
+ return ret;
+}
+
+//--------------------------------------------------------------------------
+size_t boots_pkt_handler(uint8_t *buf, size_t len, pkt_list_s **pList)
+{
+ UNUSED(boots_btif);
+ size_t i = 0;
+ size_t ret = 0;
+ pkt_list_s *list = NULL;
+ size_t pkt_len = 0;
+ uint8_t *buf_parse = 0;
+ size_t buf_index = 0;
+
+ if (!buf || !len) return 0;
+
+ buf_parse = &buf[0];
+
+ while (len > 0) {
+ if (HCI_CMD_PKT == buf_parse[0])
+ pkt_len = len;
+ else if (HCI_EVENT_PKT == buf_parse[0])
+ pkt_len = buf_parse[2] + HCI_EVENT_PKT_HDR_LEN;
+ else if (HCI_ACL_PKT == buf_parse[0])
+ pkt_len = (buf_parse[4] << 8) + buf_parse[3] + HCI_ACL_PKT_HDR_LEN;
+ else {
+ BPRINT_E("Receive unknonw type %02X %02X %02X %02X", buf_parse[0], buf_parse[1],buf_parse[2], buf_parse[3]);
+ exit(0);
+ }
+
+ if (boots_pkt_handler_parse(buf_parse, pkt_len, pList))
+ ret = 1;
+ len -= pkt_len;
+ buf_index += pkt_len;
+ buf_parse = &buf[buf_index];
+ }
+
+ if (pList)
+ list = *pList;
+
+ /** For next action */
+ if (list) {
+ if (list->p_type == HCI_EVENT_PKT && buf[0] == HCI_EVENT_PKT) {
+ if (memcmp(buf, list->u_cnt.data, list->len)) {
+ BPRINT_I("Received is not match with script");
+ BPRINT_I_RAW("\tScript:");
+ for (i = 0; i < list->len; i++)
+ BPRINT_I_RAW("%02X ", list->u_cnt.data[i]);
+ BPRINT_I_RAW("\n");
+
+ if (list->s_type == SCRIPT_WAITRX) {
+ // waiting specific RX
+ BPRINT_I("Retry to get specific event");
+ return 1;
+ }
+ boots_pkt_list_destroy(list);
+ *pList = NULL;
+ return 0;
+
+ }
+ *pList = boots_pkt_node_pop(list, NULL, NULL);
+ }
+ if (*pList) ret = 1;
+ }
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+static void boots_write_stpbtfwlog(char *buf)
+{
+ int fd = -1;
+
+ fd = open("/dev/stpbtfwlog", O_WRONLY);
+ if (fd < 0) {
+ BPRINT_E("Open /dev/stpbtfwlog fail");
+ return;
+ }
+ write(fd, buf, strlen(buf));
+ close(fd);
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_reset(char *cmd[], size_t len)
+{
+ uint8_t reset[] = {0x01, 0x03, 0x0C, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, reset, sizeof(reset),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_inquiry(char *cmd[], size_t len)
+{
+ uint8_t inq_mode[] = {0x01, 0x45, 0x0C, 0x01, 0x02};
+ uint8_t inq[] = {0x01, 0x01, 0x04, 0x05, 0x33, 0x8B, 0x9E, 2, 0x00};
+ pkt_list_s *list = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len > 2 && *(cmd[1] + 1) == 't') {
+ inq[7] = strtol(cmd[2], NULL, 16);
+ } else if (len > 1) {
+ return NULL;
+ }
+ list = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, inq_mode, sizeof(inq_mode),
+ NULL, NULL);
+ if (list)
+ boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, inq, sizeof(inq), list, list);
+ return list;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_enter_dut(char *cmd[], size_t len)
+{
+ uint8_t reset[] = {0x01, 0x03, 0x0C, 0x00};
+ uint8_t scan_enable[] = {0x01, 0x1A, 0x0C, 0x01, 0x03};
+ uint8_t event_filter[] = {0x01, 0x05, 0x0C, 0x03, 0x02, 0x00, 0x02};
+ uint8_t dut[] = {0x01, 0x03, 0x18, 0x00};
+ pkt_list_s *list = NULL;
+ pkt_list_s *tmp = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ list = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, reset, sizeof(reset),
+ NULL, NULL);
+ if (list)
+ tmp = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, scan_enable,
+ sizeof(scan_enable), list, list);
+ if (tmp)
+ tmp = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, event_filter,
+ sizeof(event_filter), tmp, list);
+ if (tmp)
+ boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, dut, sizeof(dut), tmp, list);
+
+ return list;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_read_bd_addr(char *cmd[], size_t len)
+{
+ uint8_t raddr[] = {0x01, 0x09, 0x10, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, raddr, sizeof(raddr),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_write_bd_addr(char *cmd[], size_t len)
+{
+ uint8_t waddr[] = {0x01, 0x1A, 0xFC, 0x06, 0, 0, 0, 0, 0, 0};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ if (len >= 2 && strlen(cmd[1]) == 17) {
+ waddr[9] = strtol(cmd[1], NULL, 16);
+ waddr[8] = strtol(cmd[1] + 3, NULL, 16);
+ waddr[7] = strtol(cmd[1] + 6, NULL, 16);
+ waddr[6] = strtol(cmd[1] + 9, NULL, 16);
+ waddr[5] = strtol(cmd[1] + 12, NULL, 16);
+ waddr[4] = strtol(cmd[1] + 15, NULL, 16);
+ /** Don't suppport separated address
+ } else if (len == 7) {
+ int i = 0;
+ for (i = 0; i < 6; i++)
+ waddr[9 - i] = strtol(cmd[i + 1], NULL, 16);
+ */
+ } else {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ if (!waddr[4] && !waddr[5] && !waddr[6] && !waddr[7] && !waddr[8] && !waddr[9]) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, waddr, sizeof(waddr),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_power_level(char *cmd[], size_t len)
+{
+ uint8_t power_level[] = {0x01, 0x17, 0xFC, 0x04, 0x00, 0x00, 0, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ power_level[6] = strtol(cmd[1], NULL, 16);
+ if (power_level[6] > 9 || (power_level[6] == 0 && *cmd[1] != '0')) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ BPRINT_W("%s: NOTE, this command only affects RFTX", __func__);
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, power_level,
+ sizeof(power_level), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_whiten(char *cmd[], size_t len)
+{
+ uint8_t whiten[] = {0x01, 0x15, 0xFC, 0x01, 0};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ whiten[4] = strtol(cmd[1], NULL, 16);
+ if (whiten[4] > 1 || (whiten[4] == 0 && *cmd[1] != '0')) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, whiten, sizeof(whiten),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_rf_tx(char *cmd[], size_t len)
+{
+ uint8_t rf_test[] = {0x01, 0x0D, 0xFC, 0x17, 0x00, 0x00,
+ 0, // pattern
+ 1, // hopping:1, fixed channel:0
+ 0, // channel if fixed
+ 0, // channel if fixed
+ 0x00,
+ 0x02, // poll period, unit: 1.25ms
+ 0, // packet type
+ 0, 0, // packet length
+ 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ pkt_list_s *node = NULL;
+ size_t i = 1, j = 0;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'p': // Pattern
+ rf_test[6] = strtol(cmd[i + 1], NULL, 16);
+ if (rf_test[6] == 0x0A) {
+ rf_test[7] = 0; // fix channel
+ } else if (rf_test[6] != 1 && rf_test[6] != 2 && rf_test[6] != 3
+ && rf_test[6] != 4 && rf_test[6] != 9 && rf_test[6] != 0xa) {
+ BPRINT_E("%s: Incorrect format: -p %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'c': // channel
+ rf_test[7] = 0;
+ rf_test[8] = strtol(cmd[i + 1], NULL, 10);
+ rf_test[9] = rf_test[8];
+ if (rf_test[8] > 78) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 't': // packet type
+ rf_test[12] = strtol(cmd[i + 1], NULL, 16);
+ while (j < ARRAY_SIZE(tx_pi)) {
+ if (tx_pi[j].pt == rf_test[12])
+ break;
+ else
+ j++;
+ }
+ if (j >= ARRAY_SIZE(tx_pi)) {
+ BPRINT_E("%s: Incorrect format: -t %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ if (STREAM_TO_UINT16(rf_test + 13) == 0)
+ UINT16_TO_STREAM(rf_test + 13, tx_pi[j].len);
+ i += 2;
+ BPRINT_D("t/l: %02X %02X", rf_test[13], rf_test[14]);
+ break;
+ case 'l':
+ UINT16_TO_STREAM(rf_test + 13, strtol(cmd[i + 1], NULL, 10));
+ i += 2;
+ BPRINT_D("l: %02X %02X", rf_test[13], rf_test[14]);
+ break;
+ case 'o': // Period
+ rf_test[11] = (uint8_t)strtol(cmd[i + 1], NULL, 10);
+ if (rf_test[11] < 1 || rf_test[11] > 255) {
+ BPRINT_E("%s: Incorrect format: -o %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, rf_test,
+ sizeof(rf_test), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_rf_rx(char *cmd[], size_t len)
+{
+ uint8_t rf_test[] = {0x01, 0x0D, 0xFC, 0x17, 0x00,
+ 0, // pattern
+ 0x0B, // rx start:0x0B, rx stop:0xFF, rx result:0x0C
+ 0x00, 0x00,
+ 0, // channel
+ 0x00, 0x01,
+ 3, // packet type
+ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0xA5, 0xF0, 0xC3, // address
+ 0x00, 0x00};
+ pkt_list_s *node = NULL;
+ size_t i = 1, j = 0;
+
+ BPRINT_D("%s: %s", __func__, cmd[0]);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ if (!memcmp("rfr_stop", cmd[0], strlen("rfr_stop"))) {
+ rf_test[6] = 0xFF;
+ }
+
+ if (!memcmp("rfr_result", cmd[0], strlen("rfr_result"))) {
+ rf_test[6] = 0x0C;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'p': // Pattern
+ rf_test[5] = strtol(cmd[i + 1], NULL, 16);
+ if (rf_test[5] != 1 && rf_test[5] != 2 && rf_test[5] != 3
+ && rf_test[5] != 4 && rf_test[5] != 9) {
+ BPRINT_E("%s: Incorrect format: -p %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'c': // channel
+ rf_test[9] = strtol(cmd[i + 1], NULL, 10);
+ if (rf_test[9] > 78) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 't': // packet type
+ rf_test[12] = strtol(cmd[i + 1], NULL, 16);
+ while (j < ARRAY_SIZE(rx_pi)) {
+ if (rx_pi[j].pt == rf_test[12])
+ break;
+ else
+ j++;
+ }
+ if (j >= ARRAY_SIZE(rx_pi)) {
+ BPRINT_E("%s: Incorrect format: -t %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'a':
+ if (strlen(cmd[i + 1]) == 11) {
+ rf_test[21] = strtol(cmd[i + 1], NULL, 16);
+ rf_test[22] = strtol(cmd[i + 1] + 3, NULL, 16);
+ rf_test[23] = strtol(cmd[i + 1] + 6, NULL, 16);
+ rf_test[24] = strtol(cmd[i + 1] + 9, NULL, 16);
+ } else {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ if (!rf_test[21] && !rf_test[22] && !rf_test[23] && !rf_test[24]) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ if (!rf_test[21] && !rf_test[22] && !rf_test[23] && !rf_test[24]) {
+ BPRINT_E("Please input Tester Address");
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, rf_test,
+ sizeof(rf_test), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_rf_stop(char *cmd[], size_t len)
+{
+ uint8_t rf_stop[] = {0x01, 0x0D, 0xFC, 0x17, 0x00, 0x00,
+ 0xFF, /* 0xFF: rf stop */
+ 0x00, 0x00,
+ 0x00,
+ 0x00, 0x00,
+ 0x00,
+ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, rf_stop,
+ sizeof(rf_stop), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ble_tx(char *cmd[], size_t len)
+{
+ uint8_t ble_tx[] = {0x01, 0x1E, 0x20, 0x03, 0, 37, 0};
+ uint16_t length = 0;
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'c': // Channel
+ ble_tx[4] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_tx[4] > 39) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'p': // Pattern
+ ble_tx[6] = strtol(cmd[i + 1], NULL, 16);
+ if (ble_tx[6] > 7) {
+ BPRINT_E("%s: Incorrect format: -p %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'l': // length
+ length = strtol(cmd[i + 1], NULL, 10);
+ if ((length == 0 && strtol(cmd[i + 1], NULL, 16) != 0) || length > 255) {
+ BPRINT_E("%s: Incorrect format: -l %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ ble_tx[5] = length;
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ble_tx, sizeof(ble_tx),
+ NULL, NULL);
+
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ble_rx(char *cmd[], size_t len)
+{
+ uint8_t ble_rx[] = {0x01, 0x1D, 0x20, 0x01, 0 /* channel */};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'c': // Channel
+ ble_rx[4] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_rx[4] > 39) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ble_rx, sizeof(ble_rx),
+ NULL, NULL);
+
+ return node;
+}
+
+//--------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ble_test_stop(char *cmd[], size_t len)
+{
+ uint8_t ble_stop[] = {0x01, 0x1F, 0x20, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ble_stop, sizeof(ble_stop), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ble_etx(char *cmd[], size_t len)
+{
+ uint8_t ble_etx[] = {0x01, 0x34, 0x20, 0x04, 0, 0, 0, 1};
+ uint16_t length = 0;
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'c': // Channel
+ ble_etx[4] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_etx[4] > 39) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ case 'l': // Packet length in bytes
+ length = strtol(cmd[i + 1], NULL, 10);
+ if ((length == 0 && strtol(cmd[i + 1], NULL, 16) != 0) || length > 255) {
+ BPRINT_E("%s: Incorrect format: -l %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ ble_etx[5] = length;
+ break;
+ case 'p': // Packet Payload
+ ble_etx[6] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_etx[6] > 0x07) { // So far 0x08-0xFF reserved for future use
+ BPRINT_E("%s: Incorrect format: -p %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ case 'y': // PHY
+ ble_etx[7] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_etx[7] == 0 || ble_etx[7] > 0x05) { // So far 0 and 0x05-0xFF reserved for future use
+ BPRINT_E("%s: Incorrect format: -y %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ i += 2;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ble_etx, sizeof(ble_etx),
+ NULL, NULL);
+
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ble_erx(char *cmd[], size_t len)
+{
+ uint8_t ble_erx[] = {0x01, 0x33, 0x20, 0x03, 0, 1, 0};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'c': // Channel
+ ble_erx[4] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_erx[4] > 39) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ case 'y': // PHY
+ ble_erx[5] = strtol(cmd[i + 1], NULL, 10);
+ /** So far 0 and 0x04-0xFF reserved for future use
+ 7668/6632 not support 0x03:LE Coded PHY */
+ if (ble_erx[5] == 0 || ble_erx[5] > 0x04) {
+ BPRINT_E("%s: Incorrect format: -y %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ case 'm': // Modulation Index
+ ble_erx[6] = strtol(cmd[i + 1], NULL, 10);
+ if (ble_erx[6] > 0x01) {
+ BPRINT_E("%s: Incorrect format: -m %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ i += 2;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ble_erx, sizeof(ble_erx),
+ NULL, NULL);
+
+ return node;
+}
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_tx_tone(char *cmd[], size_t len)
+{
+ uint8_t txtone[] = {0x01, 0xD5, 0xFC, 0x05, 0, 0, 0, 0, 0};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 't': // Tone Type
+ txtone[5] = strtol(cmd[i + 1], NULL, 10);
+ if (txtone[5] > 4) {
+ BPRINT_E("%s: Incorrect format: -t %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'c': // TX frequency
+ txtone[4] = strtol(cmd[i + 1], NULL, 10);
+ if (txtone[4] > 78) {
+ BPRINT_E("%s: Incorrect format: -c %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'm': // Mode
+ txtone[6] = strtol(cmd[i + 1], NULL, 10);
+ if (txtone[6] > 1) {
+ BPRINT_E("%s: Incorrect format: -m %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'd': // Modulation Type
+ txtone[7] = strtol(cmd[i + 1], NULL, 10);
+ if (txtone[7] > 6) {
+ BPRINT_E("%s: Incorrect format: -d %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'p': // Pattern Type
+ txtone[8] = strtol(cmd[i + 1], NULL, 10);
+ if (txtone[8] > 1) {
+ BPRINT_E("%s: Incorrect format: -p %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ if (txtone[5] <= 3) {
+ // Only for Modulation Tone
+ txtone[6] = txtone[7] = txtone[8] = 0;
+ } else if (txtone[6] == 1) {
+ // Only for BT mode
+ txtone[7] = 0;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, txtone, sizeof(txtone),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_radio_setting(char *cmd[], size_t len)
+{
+ uint8_t set_radio[] = {0x01, 0x79, 0xFC, 0x08,
+ 7, 0x00, 0x00, 0x00, 7, 7, 0, 0};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /**
+ * for 7668, 7663
+ * Level: radio setting -b <0~7> -e <0~7> -m <0~7> -s <0~3> -o <0/1>
+ */
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'b': // BT TX power level
+ set_radio[4] = strtol(cmd[i + 1], NULL, 10);
+ if (set_radio[4] > 7 || set_radio[4] < 0) {
+ BPRINT_E("%s: Incorrect format: -b %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'e': // BLE TX power level
+ set_radio[8] = strtol(cmd[i + 1], NULL, 10);
+ if (set_radio[8] > 7 || set_radio[8] < 0) {
+ BPRINT_E("%s: Incorrect format: -e %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'm': // MAX TX power level
+ set_radio[9] = strtol(cmd[i + 1], NULL, 10);
+ if (set_radio[9] > 7 || set_radio[9] < 0) {
+ BPRINT_E("%s: Incorrect format: -m %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 's': // 1db adjust
+ set_radio[10] = strtol(cmd[i + 1], NULL, 10);
+ if (set_radio[10] > 3 || set_radio[10] < 0) {
+ BPRINT_E("%s: Incorrect format: -s %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'o': // 3db diff mode
+ set_radio[11] = strtol(cmd[i + 1], NULL, 10);
+ if (set_radio[11] > 1 || set_radio[11] < 0) {
+ BPRINT_E("%s: Incorrect format: -o %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, set_radio, sizeof(set_radio),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_tx_power_setting(char *cmd[], size_t len)
+{
+ int8_t set_txpow[] = {0x01, 0x2C, 0xFC, 0x08,
+ 7, 0x00, 0x00, 0x00, 7, 7, 0, 0};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /**
+ * for Buzzard
+ * dbm: radio setting -b <-32~12> -e <-29~20> -m <-32~12> -n <0/1> -o <0/1>
+ */
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'b': // EDR init TX power dbm
+ set_txpow[4] = strtol(cmd[i + 1], NULL, 10);
+ if (set_txpow[4] > 12 || set_txpow[4] < -32) {
+ BPRINT_E("%s: Incorrect format: -b %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'e': // BLE TX power dbm
+ set_txpow[8] = strtol(cmd[i + 1], NULL, 10);
+ if (set_txpow[8] > 20 || set_txpow[8] < -29) {
+ BPRINT_E("%s: Incorrect format: -e %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'm': // ECR Max TX power dbm
+ set_txpow[9] = strtol(cmd[i + 1], NULL, 10);
+ if (set_txpow[9] > 12 || set_txpow[9] < -32) {
+ BPRINT_E("%s: Incorrect format: -m %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'n': // enable Lv9
+ set_txpow[10] = strtol(cmd[i + 1], NULL, 10);
+ if (set_txpow[10] > 1 || set_txpow[10] < 0) {
+ BPRINT_E("%s: Incorrect format: -n %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ case 'o': // 3db diff mode
+ set_txpow[11] = strtol(cmd[i + 1], NULL, 10);
+ if (set_txpow[11] > 1 || set_txpow[11] < 0) {
+ BPRINT_E("%s: Incorrect format: -o %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, set_txpow, sizeof(set_txpow),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_tx_power_offset(char *cmd[], size_t len)
+{
+ /* 4 is header, 7668 MAX has 22 bytes, 7663 MAX has 20 bytes */
+ uint8_t txpoweroffset[] = {0x01, 0x93, 0xFC, 0x06,
+ /* g: power offset, for 7662/7668 only 6 groups, but in 7663 have 16 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* r/i: power offset/PDC value for level 8 ONLY for 7668. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* e: ePA offset ONLY for 7668 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ uint8_t hybridmode[] = {0x01, 0x74, 0xFD, 0x01, 0x02};
+ pkt_list_s *list = NULL;
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+ size_t cmd_len = 10; /* 16 bytes command supporting since 2018/5, 22 bytes command supporting since 2018/7 */
+ int8_t temp = 0x00;
+ uint8_t lvl_8_temp[] = {0, 0, 0, 0, 0, 0};
+ bool hybrid = false;
+ bool lvl_8 = false;
+ bool pwr16 = false; /* false: 7662/7668 has 6 groups., true: 7663 has 16 groups */
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2) && memcmp(cmd[1], "g16", strlen("g16")) != 0) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /**
+ * TX power offset -g0 <-16~16> -g1 <-16~16> -g2 <-16~16>
+ * -g3 <-16~16> -g4 <-16~16> -g5 <-16~16> ...
+ * TX power offset for ePA -e0 <-16~8> -e1 <-16~8> -e2 <-16~8>
+ * -e3 <-16~8> -e4 <-16~8> -e5 <-16~8>
+ * TX power offset for level 8 RFCR -r0 <-2~4> -r1 <-2~4> -r2 <-2~4>
+ * -r3 <-2~4> -r4 <-2~4> -r5 <-2~4>
+ * TX power offset for level 8 DPC -i0 <-6~6> -i1 <-6~6> -i2 <-6~6>
+ * -i3 <-6~6> -i4 <-6~6> -i5 <-6~6>
+ * One step is +/-0.25dbm
+ */
+
+ if (memcmp(cmd[i], "g16", strlen("g16")) == 0) {
+ pwr16 = true;
+ i++;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'g': { // Tone Type
+ uint8_t gpidx = strtol(cmd[i] + 2, NULL, 10);
+
+ if (hybrid == true) {
+ BPRINT_E("%s: Incorrect format: %s - You are in hybrid mode", __func__, cmd[i]);
+ return NULL;
+ }
+ if (gpidx < 16 && gpidx > 5)
+ pwr16 = true;
+ else if (gpidx >= 16) {
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 16 || temp < -16) {
+ BPRINT_E("%s: Incorrect range: %s %d", __func__, cmd[i], temp);
+ return NULL;
+ }
+ txpoweroffset[gpidx + 4] = temp;
+ i += 2;
+ } break;
+ case 'r': // lvl 8 offset RFCR value
+ if (pwr16 == true) {
+ BPRINT_E("%s: Incorrect format: %s - 7668 groups should only 0~5", __func__, cmd[i]);
+ return NULL;
+ }
+
+ if (cmd_len == 10) {
+ cmd_len = 22;
+ txpoweroffset[3] = 0x12;
+ }
+ hybrid = true;
+ lvl_8 = true;
+ switch (*(cmd[i] + 2)) {
+ case '0':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[10] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ case '1':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[11] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ case '2':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[12] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ case '3':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[13] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ case '4':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[14] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ case '5':
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 4 || temp < -2) {
+ BPRINT_E("%s: Incorrect range: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ txpoweroffset[15] |= ((temp << 4) & 0xF0);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ break;
+ case 'i': // lvl 8 offset DPC value
+ if (pwr16 == true) {
+ BPRINT_E("%s: Incorrect format: %s - 7668 groups should only 0~5", __func__, cmd[i]);
+ return NULL;
+ }
+ if (cmd_len == 10) {
+ cmd_len = 22;
+ txpoweroffset[3] = 0x12;
+ }
+ hybrid = true;
+ switch (*(cmd[i] + 2)) {
+ case '0':
+ lvl_8_temp[0] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '1':
+ lvl_8_temp[1] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '2':
+ lvl_8_temp[2] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '3':
+ lvl_8_temp[3] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '4':
+ lvl_8_temp[4] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '5':
+ lvl_8_temp[5] = (char)strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ break;
+ case 'e': // ePA offset
+ if (pwr16 == true) {
+ BPRINT_E("%s: Incorrect format: %s - 7668 groups should only 0~5", __func__, cmd[i]);
+ return NULL;
+ }
+ if (cmd_len == 10) {
+ cmd_len = 22;
+ txpoweroffset[3] = 0x12;
+ }
+ hybrid = true;
+ switch (*(cmd[i] + 2)) {
+ case '0':
+ txpoweroffset[16] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '1':
+ txpoweroffset[17] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '2':
+ txpoweroffset[18] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '3':
+ txpoweroffset[19] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '4':
+ txpoweroffset[20] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case '5':
+ txpoweroffset[21] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ break;
+ default:
+ i++;
+ }
+ }
+ if (pwr16 == true) {
+ txpoweroffset[3] = 0x10;
+ cmd_len = txpoweroffset[3] + 4;
+ BPRINT_I("%s: "BLUE"This is 16 groups setting for 7663, 7921"NONE, __func__);
+ } else if (lvl_8 == true) {
+ for (i = 0 ; i < 6 ; i++)
+ txpoweroffset[i + 10] |= (lvl_8_temp[i] & 0x0F);
+ hybridmode[4] = 0x02;
+ } else {
+ BPRINT_I("%s: "BLUE"This is 6 groups setting for 7662, 7668 etc."NONE, __func__);
+ for (i = 0 ; i < 6 ; i++)
+ txpoweroffset[i + 10] = lvl_8_temp[i];
+ hybridmode[4] = 0x01;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, txpoweroffset, cmd_len , NULL, NULL);
+ if (hybrid == true) {
+ list = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, hybridmode, sizeof(hybridmode), node, node);
+ return list;
+ }
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_efuse_wr(char *cmd[], size_t len)
+{
+ uint8_t efuse_r[] = {0x01, 0x6F, 0xFC, 0x0E,
+ 0x01, 0x0D, 0x0A, 0x00, 0x02, 0x04,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+ uint8_t efuse_w[] = {0x01, 0x6F, 0xFC, 0x18,
+ 0x01, 0x0D, 0x14, 0x00, 0x01, 0x01,
+ 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+ pkt_list_s *node = NULL;
+ uint16_t addr = 0;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len % 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /*
+ * efuse -w -a <> -v <>
+ * efuse -r -a <>
+ */
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'w':
+ /* read value first
+ efuse[3] = 24;
+ efuse[6] = 0x14;
+ efuse[8] = 0x01;
+ efuse[8] = 0x01;
+ */
+ efuse_r[3] = 14; /* length */
+ efuse_r[6] = 0x0A;
+ efuse_r[8] = 0x02;
+ efuse_r[9] = 0x04;
+ efuse_reg_wr.wr_flag = WR_FLAG_WRITE;
+ i += 1;
+ break;
+ case 'r':
+ efuse_r[3] = 14; /* length */
+ efuse_r[6] = 0x0A;
+ efuse_r[8] = 0x02;
+ efuse_r[9] = 0x04;
+ efuse_reg_wr.wr_flag = WR_FLAG_READ;
+ i += 1;
+ break;
+ case 'a':
+ efuse_reg_wr.addr = strtoul(cmd[i + 1], NULL, 16);
+ addr = efuse_reg_wr.addr / 16 * 4;
+ efuse_r[10] = addr & 0xFF;
+ efuse_r[11] = (addr & 0xFF00) >> 8;
+ efuse_r[12] = (addr + 1) & 0xFF;
+ efuse_r[13] = ((addr + 1) & 0xFF00) >> 8;
+ efuse_r[14] = (addr + 2) & 0xFF;
+ efuse_r[15] = ((addr + 2) & 0xFF00) >> 8;
+ efuse_r[16] = (addr + 3) & 0xFF;
+ efuse_r[17] = ((addr + 3) & 0xFF00) >> 8;
+ i += 2;
+ break;
+ case 'v':
+ efuse_reg_wr.value = strtoul(cmd[i + 1], NULL, 16);
+ i += 2;
+ break;
+
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, efuse_r, (efuse_r[3] + 4),
+ NULL, NULL);
+ if (efuse_reg_wr.wr_flag == WR_FLAG_WRITE && node)
+ {
+ boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, efuse_w, (efuse_w[3] + 4),
+ node, node);
+ }
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_register_wr(char *cmd[], size_t len)
+{
+ uint8_t reg[] = {0x01, 0x00, 0xFC, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len % 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /*
+ * register -w -a <> -v <>
+ * register -r -a <>
+ */
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'w':
+ reg[1] = 0xD0;
+ reg[3] = 0x08; /* length */
+ efuse_reg_wr.wr_flag = WR_FLAG_WRITE;
+ i += 1;
+ break;
+ case 'r':
+ reg[1] = 0xD1;
+ reg[3] = 0x04; /* length */
+ efuse_reg_wr.wr_flag = WR_FLAG_READ;
+ i += 1;
+ break;
+ case 'a':
+ efuse_reg_wr.addr = strtoul(cmd[i + 1], NULL, 16);
+ reg[4] = efuse_reg_wr.addr & 0xFF;
+ reg[5] = (efuse_reg_wr.addr & 0xFF00) >> 8;
+ reg[6] = (efuse_reg_wr.addr & 0xFF0000) >> 16;
+ reg[7] = (efuse_reg_wr.addr & 0xFF000000) >> 24;
+ i += 2;
+ break;
+ case 'v':
+ efuse_reg_wr.value = strtoul(cmd[i + 1], NULL, 16);
+ reg[8] = efuse_reg_wr.value & 0xFF;
+ reg[9] = (efuse_reg_wr.value & 0xFF00) >> 8;
+ reg[10] = (efuse_reg_wr.value & 0xFF0000) >> 16;
+ reg[11] = (efuse_reg_wr.value & 0xFF000000) >> 24;
+ i += 2;
+ break;
+
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, reg, (reg[3] + 4),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_file_wr(char *cmd[], size_t len)
+{
+ uint8_t file[256] = {0x01, 0x01, 0xFF, 0x06,
+ 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00,
+ 0x00};
+ uint32_t addr = 0;
+ uint8_t file_path = 0;
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len % 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ /****************************************************
+ format:
+ CMD: 01 01 FF LEN WR ADDR VALUE FILE_PATH
+ EVENT: 04 0E LEN 01 01 FF ERRNO WR ADDR VALUE
+
+ LEN: 1 byte
+ WR: 1 byte
+ ADDR: 4 bytes
+ VALUE: 1 byte
+ ERRNO: 2 bytes
+ FILE_PATH:
+ ****************************************************/
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'w':
+ file[4] = WR_FLAG_WRITE;
+ i += 1;
+ break;
+ case 'r':
+ file[4] = WR_FLAG_READ;
+ i += 1;
+ break;
+ case 'a':
+ addr = strtoul(cmd[i + 1], NULL, 16);
+ file[5] = addr & 0xFF;
+ file[6] = (addr & 0xFF00) >> 8;
+ file[7] = (addr & 0xFF0000) >> 16;
+ file[8] = (addr & 0xFF000000) >> 24;
+ i += 2;
+ break;
+ case 'v':
+ file[9] = strtol(cmd[i + 1], NULL, 16);
+ i += 2;
+ break;
+ case 'f':
+ strncpy((char *)&file[10], cmd[i + 1], strlen(cmd[i + 1]) < (256 - 10 - 1) ? strlen(cmd[i + 1]) : (256 - 10 - 1));
+ file[3] += strlen((char *)&file[10]) + 1;
+ file_path = 1;
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ if (file_path == 0)
+ {
+ BPRINT_E("%s: please input the file path and name(-f)", __func__);
+ return NULL;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, file, (file[3] + 4),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_sync(char *cmd[], size_t len)
+{
+ uint8_t access_code[] = {0x01, 0x12, 0xFC, 0x08, 0, 0, 0, 0, 0, 0, 0, 0};
+ pkt_list_s *node = NULL;
+
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len >= 2 && strlen(cmd[1]) == 23) {
+ access_code[11] = strtol(cmd[1], NULL, 16);
+ access_code[10] = strtol(cmd[1] + 3, NULL, 16);
+ access_code[9] = strtol(cmd[1] + 6, NULL, 16);
+ access_code[8] = strtol(cmd[1] + 9, NULL, 16);
+ access_code[7] = strtol(cmd[1] + 12, NULL, 16);
+ access_code[6] = strtol(cmd[1] + 15, NULL, 16);
+ access_code[5] = strtol(cmd[1] + 18, NULL, 16);
+ access_code[4] = strtol(cmd[1] + 21, NULL, 16);
+ } else {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ if (!access_code[4] && !access_code[5] && !access_code[6] && !access_code[7]
+ && !access_code[8] && !access_code[9] && !access_code[10] && !access_code[11]) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, access_code,
+ sizeof(access_code), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_stress_test(char *cmd[], size_t len)
+{
+ uint8_t cmd_buf[BOOTS_STRESS_STRESS_TEST_MAX_PKT_SIZE + HCI_CMD_PKT_HDR_LEN] = {0};
+ pkt_list_s *node = NULL;
+ uint32_t packetSize = 1;
+ uint32_t i;
+
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ if (len == 2)
+ packetSize = atoi(cmd[1]);
+
+ if (packetSize > BOOTS_STRESS_STRESS_TEST_MAX_PKT_SIZE) {
+ BPRINT_E("Packet Size should be smaller than %d!", BOOTS_STRESS_STRESS_TEST_MAX_PKT_SIZE);
+ return NULL;
+ }
+
+ BPRINT_I("%s : Test with 'Write Local Name', Packet Size = %d", __func__, packetSize);
+ cmd_buf[0] = 0x01;
+ cmd_buf[1] = 0x13;
+ cmd_buf[2] = 0x0c;
+ cmd_buf[3] = packetSize;
+ for (i = 0; i < packetSize; i++)
+ cmd_buf[i + HCI_CMD_PKT_HDR_LEN] = ((i + 1) & 0xff);
+
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_init();
+
+ node = boots_pkt_node_push(SCRIPT_STRESS, HCI_CMD_PKT, cmd_buf, packetSize + HCI_CMD_PKT_HDR_LEN, NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_loop_back_test(char *cmd[], size_t len)
+{
+ uint8_t cmd_reset[] = {0x01, 0x03, 0x0C, 0x00};
+ uint8_t cmd_loopback[] = {0x01, 0x02, 0x18, 0x01, 0x01};
+ uint8_t cmd_buf[BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE + HCI_ACL_PKT_HDR_LEN] = {0};
+ pkt_list_s *node = NULL;
+ pkt_list_s *node_tmp = NULL;
+ uint32_t packetSize = 1;
+ uint32_t i;
+ int32_t wait = 1;
+
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ if (len == 2)
+ packetSize = atoi(cmd[1]);
+
+ if (packetSize > BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE) {
+ BPRINT_E("Packet Size should be smaller than %d!", BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE);
+ return NULL;
+ }
+
+ BPRINT_I("%s : Test with ACL loopback, Packet Size = %d", __func__, packetSize);
+ cmd_buf[0] = 0x02;
+ cmd_buf[1] = 0x32;
+ cmd_buf[2] = 0x00;
+ cmd_buf[3] = (packetSize & 0x00ff);
+ cmd_buf[4] = ((packetSize & 0xff00) >> 8);
+ for (i = 0; i < packetSize; i++)
+ cmd_buf[i + HCI_ACL_PKT_HDR_LEN] = ((i + 1) & 0xff);
+
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_init();
+
+ node = boots_pkt_node_push(SCRIPT_CMD, HCI_CMD_PKT, cmd_reset, sizeof(cmd_reset), NULL, NULL);
+ if (node)
+ node_tmp = boots_pkt_node_push(SCRIPT_CMD, HCI_CMD_PKT, cmd_loopback, sizeof(cmd_loopback), node, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ boots_pkt_node_push(SCRIPT_LOOPBACK, HCI_ACL_PKT, cmd_buf, packetSize + HCI_ACL_PKT_HDR_LEN, node_tmp, node);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_loop_timer_test(char *cmd[], size_t len)
+{
+ uint8_t cmd_reset[] = {0x01, 0x03, 0x0C, 0x00};
+ uint8_t cmd_loopback[] = {0x01, 0x02, 0x18, 0x01, 0x01};
+ uint8_t cmd_buf[BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE + HCI_ACL_PKT_HDR_LEN] = {0};
+ pkt_list_s *node = NULL;
+ pkt_list_s *node_tmp = NULL;
+ uint32_t packetSize = 1;
+ uint32_t i = 1;
+ int32_t wait = 1;
+
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ boots_loop_timer = 0;
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 't': // timer
+ boots_loop_timer = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 's': // package size
+ packetSize = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ if (packetSize > BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE) {
+ BPRINT_E("Packet Size should be smaller than %d!", BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE);
+ return NULL;
+ }
+
+ BPRINT_I("%s : Test with ACL loopback, Timer = %d, Packet Size = %d", __func__, boots_loop_timer, packetSize);
+ cmd_buf[0] = 0x02;
+ cmd_buf[1] = 0x32;
+ cmd_buf[2] = 0x00;
+ cmd_buf[3] = (packetSize & 0x00ff);
+ cmd_buf[4] = ((packetSize & 0xff00) >> 8);
+ for (i = 0; i < packetSize; i++)
+ cmd_buf[i + HCI_ACL_PKT_HDR_LEN] = ((i + 1) & 0xff);
+
+ if (BOOTS_STRESS_MEASURE_IN_BOOTS)
+ boots_stress_init();
+
+ node = boots_pkt_node_push(SCRIPT_CMD, HCI_CMD_PKT, cmd_reset, sizeof(cmd_reset), NULL, NULL);
+ if (node)
+ node_tmp = boots_pkt_node_push(SCRIPT_CMD, HCI_CMD_PKT, cmd_loopback, sizeof(cmd_loopback), node, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ node_tmp = boots_pkt_node_push(SCRIPT_WAITRX, HCI_EVENT_PKT, (void*)&wait, 0, node_tmp, node);
+ if (node_tmp)
+ boots_pkt_node_push(SCRIPT_LPTIMER, HCI_ACL_PKT, cmd_buf, packetSize + HCI_ACL_PKT_HDR_LEN, node_tmp, node);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_pa(char *cmd[], size_t len)
+{
+ uint8_t epa[] = {0x01, 0x70, 0xFD, 0x09,
+ 0x00, // 00 : Disable ePA, 01 : Enable ePA
+ 0x07, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00 // power Level, same as pwrlvl and radio
+ };
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ epa[4] = strtol(cmd[1], NULL, 16);
+ if (epa[4] > 1 || (epa[4] == 0 && *cmd[1] != '0')) {
+ BPRINT_E("%s: Incorrect format: %d", __func__, epa[4]);
+ return NULL;
+ }
+ if (epa[4] == 1) {
+ BPRINT_D("ePA mode, change power level to level 9.");
+ epa[5] = 0x09;
+ epa[9] = 0x09;
+ epa[10] = 0x09;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, epa, sizeof(epa),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_ant(char *cmd[], size_t len)
+{
+ uint8_t ant[] = {0x01, 0x71, 0xFD, 0x01, 0}; //00 : BT uses ANT2,FDD 01 : BT uses ANT1,TDD
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ ant[4] = strtol(cmd[1], NULL, 16);
+ if (ant[4] > 1 || (ant[4] == 0 && *cmd[1] != '0')) {
+ BPRINT_E("%s: Incorrect format: %d", __func__, ant[4]);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ant, sizeof(ant),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_background_rssi_scan(char *cmd[], size_t len)
+{
+ uint8_t ant[] = {0x01, 0x73, 0xFD, 0x01, 0}; //00 : disable 01 : enable
+ pkt_list_s *list = NULL;
+ pkt_list_s *node = NULL;
+ rssi_set_s rssi;
+ uint32_t i = 2;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+ ant[4] = strtol(cmd[1], NULL, 16);
+
+ rssi.avg_package = 1;
+ rssi.ch_start = 0;
+ rssi.ch_end = 78;
+ rssi.report = false;
+ rssi.stop = !ant[4];
+ rssi.alpha_filter = 0;
+ rssi.one_shot = 0;
+
+ if (ant[4] > 1 || (ant[4] == 0 && *cmd[1] != '0')) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'o': // output report when stop
+ rssi.report = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 's': // start channel
+ rssi.ch_start = atoi(cmd[i + 1]);
+ if (rssi.ch_start < 0 || rssi.ch_start > 78)
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ i += 2;
+ break;
+ case 'e': // end chennel
+ rssi.ch_end = atoi(cmd[i + 1]);
+ if (rssi.ch_end < 0 || rssi.ch_end > 78)
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ i += 2;
+ break;
+ case 'a': // average package
+ rssi.avg_package = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 'f': // alpha filter
+ rssi.alpha_filter = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ case 'n': // report only one
+ rssi.one_shot = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ if (rssi.ch_end < rssi.ch_start)
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+
+ node = boots_pkt_node_push(SCRIPT_RSSI, HCI_CMD_PKT, &rssi, sizeof(rssi), NULL, NULL);
+ list = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, ant, sizeof(ant), node, node);
+
+ return list;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_packet_rssi(char *cmd[], size_t len)
+{
+ uint8_t rssi[] = {0x01, 0x61, 0xFC, 0x02, 0x32, 0x00};
+ pkt_list_s *node = NULL;
+ uint16_t handle = 0;
+ uint32_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'a': // handle, default 0x0032, opt.
+ handle = (uint16_t)strtoul(cmd[i + 1], NULL, 16);
+ rssi[4] = (uint8_t)(handle & 0x00FF);
+ rssi[5] = (uint8_t)((handle & 0xFF00) >> 8);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, &rssi, sizeof(rssi), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_buffer_mode(char *cmd[], size_t len)
+{
+ FILE *fp = NULL;
+ ssize_t read = 0;
+ size_t line_len = 0;
+ char *wbuf = NULL;
+ char *line = NULL;
+ int fp_len = 0;
+ char path[64] = DEFAULT_WIFI_CFG;
+ char path_cp[64] = DEFAULT_WIFI_CFG;
+ size_t i = 1;
+ ssize_t w_size = 0;
+ int enable = 0;
+ char *pch = NULL;
+ char str_buf[64];
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ memset(path, 0x00, sizeof(path));
+ strncpy(path, cmd[i + 1], sizeof(path) - 1);
+ strncpy(path_cp, cmd[i + 1], sizeof(path_cp) - 1);
+ i += 2;
+ break;
+ case 'e':
+ enable = atoi(cmd[i + 1]);
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ fp = fopen(path, "r+");
+ if (fp != NULL) {
+ fseek(fp, 0L, SEEK_END);
+ fp_len = ftell(fp);
+ wbuf = malloc(fp_len + 1 + 21);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ fclose(fp);
+ return NULL;
+ }
+ fseek(fp, 0L, SEEK_SET);
+
+ while ((read = getline(&line, &line_len, fp)) != -1) {
+ pch = strstr(line, E2P_MODE);
+ if (!pch) {
+ memcpy(&wbuf[w_size], line, read);
+ w_size += read;
+ } else
+ continue;
+ }
+ free(line);
+ fclose(fp);
+ } else {
+ wbuf = malloc(21);
+ if (!wbuf) {
+ BPRINT_E("%s: Alloc wbuf failed", __func__);
+ return NULL;
+ }
+ }
+
+ i = snprintf(str_buf, sizeof(str_buf),"%s %d\n", E2P_MODE, enable);
+ memcpy(&wbuf[w_size], str_buf, i);
+ w_size += i;
+ fp = fopen(path_cp, "w");
+ if (fp == NULL) {
+ BPRINT_E("open file %s failed, errno = %s(%d)\n", path_cp, strerror(errno), errno);
+ free(wbuf);
+ return NULL;
+ }
+ fwrite(wbuf, 1, w_size, fp);
+ fclose(fp);
+ free(wbuf);
+ // Please note driver also need support this after ...[TODO]
+ boots_write_stpbtfwlog("reload_setting");
+ BPRINT_I("Set %s:%d, if no efficacy please reboot platform.", E2P_MODE, enable);
+ return NULL;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_tx_hopping(char *cmd[], size_t len)
+{
+ uint8_t tx_hopping[] = {0x01, 0x90, 0xFD, 0x01, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len != 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ if (!memcmp("low", cmd[1], strlen("low"))) {
+ tx_hopping[4] = 0x00;
+ } else if (!memcmp("middle", cmd[1], strlen("middle"))) {
+ tx_hopping[4] = 0x01;
+ } else if (!memcmp("high", cmd[1], strlen("high"))) {
+ tx_hopping[4] = 0x02;
+ } else {
+ BPRINT_E("%s: Incorrect format: %s)", __func__, cmd[1]);
+ return NULL;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, tx_hopping,
+ sizeof(tx_hopping), NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_switch_bt(char *cmd[], size_t len)
+{
+ uint8_t switch_bt[] = {0x01, 0xF4, 0xFC, 0x02, 0xFD, 0}; // 0 : BT0 1 : BT1
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ switch_bt[5] = strtoul(cmd[1], NULL, 16);
+
+ if (switch_bt[5] > 1 || switch_bt[5] < 0) {
+ BPRINT_E("%s: Incorrect format: %d)", __func__, switch_bt[5]);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, switch_bt, sizeof(switch_bt),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_power_compensation(char *cmd[], size_t len)
+{
+ uint8_t power_comp[] = {0x01, 0xEA, 0xFC, 0x0A, 0x02, 0x0A,
+ 0, // ANT index
+ 0, // offset level
+ 0, 0, 0, 0, 0, 0}; // group value
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+ int8_t temp = 0x00;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'a': // ANT index
+ power_comp[6] = strtoul(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case 'l': // offset level
+ power_comp[7] = strtoul(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case 'g': { // group value
+ uint8_t gpidx = strtoul(cmd[i] + 2, NULL, 10);
+ if (gpidx > 5 || gpidx < 0) {
+ BPRINT_E("%s: Incorrect format: %d", __func__, gpidx);
+ return NULL;
+ }
+ temp = (int8_t)strtol(cmd[i + 1], NULL, 10);
+ if (temp > 16 || temp < -16) {
+ BPRINT_E("%s: Incorrect range: %s %d", __func__, cmd[i], temp);
+ return NULL;
+ }
+ power_comp[gpidx + 8] = temp;
+ i += 2;
+ }
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, power_comp, sizeof(power_comp),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_power_boundary(char *cmd[], size_t len)
+{
+ uint8_t power_bdry[] = {0x01, 0xEA, 0xFC, 0x09, 0x02, 0x0B,
+ 0, // ANT index
+ 0, // reserve
+ 0, 0, 0, 0, 0}; // group channel boundry
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'a': // ANT index
+ power_bdry[6] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ break;
+ case 'b': { // boundary value
+ uint8_t bdidx = strtol(cmd[i] + 2, NULL, 10);
+ if (bdidx > 4 || bdidx < 0) {
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ power_bdry[bdidx + 8] = strtol(cmd[i + 1], NULL, 10);
+ i += 2;
+ } break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, power_bdry, sizeof(power_bdry),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_sx(char *cmd[], size_t len)
+{
+ uint8_t sxtrx[] = {0x01, 0xEA, 0xFC, 0x03, 0x02,
+ 0, // 0x06 : st_tx 0x07 : st_rx
+ 0}; // as below
+ /*
+ BT0 SX Configration 0x15[3:0]
+ 4'b0001:DIV2 for Rx
+ 4'b0011:SSB 8/3 for T/Rx
+ 4'b0100:SSB 16/5 for T/Rx
+ 4'b0101:DIV2 LP for Rx
+ BT1 SX Configration 0x15[3:0]
+ 4'b0000:VCDL 5/2 for T/Rx
+ 4'b0001:DIV2 for Rx
+ 4'b0010:VCDL 7/2 for T/Rx
+ 4'b0101:DIV2 LP for Rx
+ */
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ if (!memcmp("sxtx", cmd[0], strlen("sxtx"))) {
+ sxtrx[5] = 0x06;
+ }
+
+ if (!memcmp("sxrx", cmd[0], strlen("sxrx")) ||
+ !memcmp("swrxmode", cmd[0], strlen("swrxmode"))) {
+ sxtrx[5] = 0x07;
+ }
+
+ sxtrx[6] = strtol(cmd[1], NULL, 10);
+
+ if (sxtrx[6] > 5 || sxtrx[6] < 0) {
+ BPRINT_E("%s: Incorrect format: %d", __func__, sxtrx[6]);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, sxtrx, sizeof(sxtrx),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_ant_to_pin_loss(char *cmd[], size_t len)
+{
+ uint8_t a2ploss[] = {0x01, 0xEA, 0xFC, 0x03, 0x02, 0x09, 0};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ a2ploss[6] = strtol(cmd[1], NULL, 10);
+
+ if (a2ploss[6] > 20 || a2ploss[6] < 0) {
+ BPRINT_E("%s: Incorrect format: %d", __func__, a2ploss[6]);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, a2ploss, sizeof(a2ploss),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_read_edr_info(char *cmd[], size_t len)
+{
+ uint8_t redrinfo[] = {0x01, 0xEA, 0xFC, 0x03, 0x02, 0x08, 0x00};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, redrinfo, sizeof(redrinfo),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_epa_elna(char *cmd[], size_t len)
+{
+ uint8_t palna[] = {0x01, 0x97, 0xFC, 0x03, 0x02, 0x02, 0};
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'p': // epa
+ palna[6] |= strtol(cmd[i + 1], NULL, 16);
+ i += 2;
+ break;
+ case 'l': // elna
+ palna[6] |= strtol(cmd[i + 1], NULL, 16) << 4;
+ i += 2;
+ break;
+
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, palna, sizeof(palna),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_set_xomode(char *cmd[], size_t len)
+{
+ uint8_t set_xomode[] = {0x01, 0xEA, 0xFC, 0x02, 0x04, 0}; // 0 : AX mode 1 :BT mode
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (len < 2) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ set_xomode[5] = strtoul(cmd[1], NULL, 16);
+
+ if (set_xomode[5] > 1 || set_xomode[5] < 0) {
+ BPRINT_E("%s: Incorrect format: %d)", __func__, set_xomode[5]);
+ return NULL;
+ }
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, set_xomode, sizeof(set_xomode),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_get_xomode(char *cmd[], size_t len)
+{
+ uint8_t get_xomode[] = {0x01, 0xEA, 0xFC, 0x01, 0x03};
+ pkt_list_s *node = NULL;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h')
+ return NULL;
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, get_xomode, sizeof(get_xomode),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+static pkt_list_s *mtk_boots_cmd_bt_xo_trim(char *cmd[], size_t len)
+{
+ uint8_t xo_trim[] = {0x01, 0xEA, 0xFC, 0x07, 0x06,
+ 0, // Frequency offset ( XO_C1_SEL_BTM)
+ 0, // XO trim2 compensation (XO_C1_SEL_BTM)
+ 0, // XO trim3 compensation (XO_C1_SEL_BTM)
+ 0, // XO trim4 compensation (XO_C1_SEL_BTM)
+ 0x81, // C2 ratio (default 0x81, don’t change)
+ 0x05}; // C1 ratio (default 0x05 , don’t change)
+ pkt_list_s *node = NULL;
+ size_t i = 1;
+ int tmp_val = 0;
+
+ BPRINT_D("%s", __func__);
+ if (len == 2 && *(cmd[1] + 1) == 'h') {
+ return NULL;
+ } else if (!(len % 2)) {
+ BPRINT_E("%s: Incorrect format", __func__);
+ return NULL;
+ }
+
+ /*
+ xo_trim[] = 01 EA FC 07 06 UU VV WW XX YY ZZ
+ UU: [eFuse 0x400] : Frequency offset ( XO_C1_SEL_BTM)
+ BIT[7] : C1 BTM valid bit
+ BIT[6:0] : C1 BTM value
+ VV: [eFuse 0x406] : XO trim2 compensation (XO_C1_SEL_BTM)
+ BIT[7] : C1 BTM COMP enable bit
+ BIT[6] : 0: increase bit; 1 : decrease bit
+ BIT[5:0] : C1 BTM trim2 value
+ WW: [eFuse 0x40C] : XO trim3 compensation (XO_C1_SEL_BTM)
+ BIT[7] : C1 BTM COMP enable bit
+ BIT[6] : 0: increase bit; 1 : decrease bit
+ BIT[5:0] : C1 BTM trim3 value
+ XX: [eFuse 0x412] : XO trim4 compensation (XO_C1_SEL_BTM)
+ BIT[7] : C1 BTM COMP enable bit
+ BIT[6] : 0: increase bit; 1 : decrease bit
+ BIT[5:0] : C1 BTM trim4 value
+ YY: [eFuse 0x403] : C2 ratio (default 0x81, don’t change)
+ BIT[7] : enable bit
+ BIT[6:0] : C2 ratio
+ ZZ: [eFuse 0x409] : C1 ratio (default 0x05 , don’t change)
+ BIT[7:0] : C1 ratio
+ For example, C1 ratio and C2 ratio is 5 and 1, and C1 value is 10, C2 is 10 * (1/5) = 2
+ */
+
+ while (i + 1 < len) {
+ switch (*(cmd[i] + 1)) {
+ case 'f':
+ tmp_val = strtol(cmd[i + 1], NULL, 10);
+ if (tmp_val > 127 || tmp_val < 0) {
+ BPRINT_E("%s: Incorrect format: -f %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ xo_trim[5] = tmp_val | (1 << 7); // enable bit
+ i += 2;
+ break;
+ case 'x':
+ tmp_val = strtol(cmd[i + 1], NULL, 10);
+ if (tmp_val > 63 || tmp_val < -63) {
+ BPRINT_E("%s: Incorrect format: -x %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ if (tmp_val == 0) {
+ xo_trim[6] = tmp_val;
+ } else if (tmp_val < 0) {
+ tmp_val = tmp_val * (-1);
+ xo_trim[6] = tmp_val | (1 << 7); // enable bit
+ xo_trim[6] = xo_trim[6] | (1 << 6); // increase/decrease bit
+ } else {
+ xo_trim[6] = tmp_val | (1 << 7); // enable bit
+ }
+ i += 2;
+ break;
+ case 'y':
+ tmp_val = strtol(cmd[i + 1], NULL, 10);
+ if (tmp_val > 63 || tmp_val < -63) {
+ BPRINT_E("%s: Incorrect format: -y %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ if (tmp_val == 0) {
+ xo_trim[7] = tmp_val;
+ } else if (tmp_val < 0) {
+ tmp_val = tmp_val * (-1);
+ xo_trim[7] = tmp_val | (1 << 7); // enable bit
+ xo_trim[7] = xo_trim[7] | (1 << 6); // increase/decrease bit
+ } else {
+ xo_trim[7] = tmp_val | (1 << 7); // enable bit
+ }
+ i += 2;
+ break;
+ case 'z':
+ tmp_val = strtol(cmd[i + 1], NULL, 10);
+ if (tmp_val > 63 || tmp_val < -63) {
+ BPRINT_E("%s: Incorrect format: -z %s", __func__, cmd[i + 1]);
+ return NULL;
+ }
+ if (tmp_val == 0) {
+ xo_trim[8] = tmp_val;
+ } else if (tmp_val < 0) {
+ tmp_val = tmp_val * (-1);
+ xo_trim[8] = tmp_val | (1 << 7); // enable bit
+ xo_trim[8] = xo_trim[8] | (1 << 6); // increase/decrease bit
+ } else {
+ xo_trim[8] = tmp_val | (1 << 7); // enable bit
+ }
+ i += 2;
+ break;
+ default:
+ BPRINT_E("%s: Incorrect format: %s", __func__, cmd[i]);
+ return NULL;
+ }
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, HCI_CMD_PKT, xo_trim, sizeof(xo_trim),
+ NULL, NULL);
+ return node;
+}
+
+//---------------------------------------------------------------------------
+#define USAGE_RESET_DETAILS \
+ " EX: # ./boots -c reset"
+#define USAGE_INQ_DETAILS \
+ " EX: # ./boots -c inq -t 5"
+#define USAGE_DUT_DETAILS \
+ " EX: # ./boots -c dut"
+#define USAGE_RADDR_DETAILS \
+ " EX: # ./boots -c raddr"
+#define USAGE_WADDR_DETAILS \
+ " NAP-UAP-LAP\n" \
+ " EX: # ./boots -c waddr 0E:8D:76:68:00:01"
+#define USAGE_PWRL_DETAILS \
+ " EX: # ./boots -c pwrlvl 7"
+#define USAGE_RFTX_PREFACE \
+ "RF TX test [-p <XX>] [-c <0-78>] [-t <XX>] [-l <DEC>] [-o <DEC>]"
+#define USAGE_RFTX_DETAILS \
+ " [p] Pattern:\n" \
+ " 01:0000 02:1111\n" \
+ " 03:1010 04:Pseudo Random Bit Sequence 9(Default)\n" \
+ " 09:11110000 0A:Tx single tone\n" \
+ " [c] Channel: 0-78, hopping if ignore this\n" \
+ " [t] Packet Type:\n" \
+ " 00:NULL 01:POLL 02:FHS 03:DM1 04:DH1 05:HV1 06:HV2 07:HV3\n" \
+ " 08:DV 09:AUX 0A:DM3 0B:DH3 0E:DM5 0F:DH5 17:EV3 1C:EV4\n" \
+ " 1D:EV5 24:2DH1 28:3DH1 2A:2DH3 2B:3DH3 2E:2DH5 2F:3DH5 36:2EV3\n" \
+ " 37:3EV3 3C:2EV5 3D:3EV5\n" \
+ " [l] Length: Decimal value., If ignore this boots will use the default value\n" \
+ " [o] Poll Period: Decimal value. Unit: 1.25ms. If ignore this boots will use the default value\n" \
+ " NOTE: For other parameters command order is Whiten -> RFTX -> Sync -> PowerLvl\n" \
+ " EX: # ./boots -c rft -p A -c 78 -t 3D"
+#define USAGE_RFRX_PREFACE \
+ "RF RX test start [-p <XX>] [-c <0-78>] [-t <XX>] [-a <XX:XX:XX:XX>]"
+#define USAGE_RF_STOP_PREFACE \
+ "RF TX/RX test stop(Except SignalTone \"rft -p a ...\", for that need \"reset\" to stop)"
+#define USAGE_RF_STOP_DETAILS \
+ " EX: # ./boots -c rf_stop"
+#define USAGE_RFRX_STOP_PREFACE \
+ "RF RX test stop [-p <XX>] [-c <0-78>] [-t <XX>] [-a <XX:XX:XX:XX>]"
+#define USAGE_RFRX_RESULT_PREFACE \
+ "RF RX test result [-p <XX>] [-c <0-78>] [-t <XX>] [-a <XX:XX:XX:XX>]"
+#define USAGE_RFRX_DETAILS \
+ " [p] Pattern:\n" \
+ " 01:0000 02:1111\n" \
+ " 03:1010 04:Pseudo Random Bit Sequence 9(Default)\n" \
+ " 09:11110000\n" \
+ " [c] Channel: 0-78\n" \
+ " [t] Packet Type:\n" \
+ " 03:DM1 04:DH1 0A:DM3 0B:DH3 0E:DM5 0F:DH5\n" \
+ " 24:2DH1 28:3DH1 2A:2DH3 2B:3DH3 2E:2DH5 2F:3DH5\n" \
+ " [a] Tester Address: UAP:LAP1:LAP2:LAP3(Default: 0x00A5F0C3 if ignore it)\n"
+#define RFR_EX \
+ " EX: # ./boots -c rfr -p 9 -c 78 -t 2F"
+#define RFR_S_EX \
+ " EX: # ./boots -c rfr_stop -p 9 -c 78 -t 2F"
+#define RFR_R_EX \
+ " EX: # ./boots -c rfr_result -p 9 -c 78 -t 2F"
+#define USAGE_BLETX_PREFACE \
+ "BLE TX test [-c <0-39>] [-l <0-255>] [-p <0-7>]"
+#define USAGE_BLETX_DETAILS \
+BLUE" Can replace this by ble_etx, EX: \"ble_etx -y 1 ...\"\n"NONE \
+ " [c] Channel: 0-39\n" \
+ " [l] Length in bytes of packet: 0-255(DEC, Default is 37 if ignore this)\n" \
+ " [p] Pattern:\n" \
+ " 0:PRBS9 1:11110000 2:10101010 3:PRBS15\n" \
+ " 4:11111111 5:00000000 6:00001111 7:01010101\n" \
+ " EX: # ./boots -c ble_tx -c 39 -p 2"
+#define USAGE_BLERX_DETAILS \
+ " EX: # ./boots -c ble_rx -c 39"
+#define USAGE_BLEETX_PREFACE \
+ "BLE Enhanced TX test [-c <0-39>] [-l <0-255>] [-p <0-7>] [-y <1-4>]"
+#define USAGE_BLEETX_DETAILS \
+ " [c] Channel: 0-39\n" \
+ " [l] Length in bytes of packet: 0-255(DEC)\n" \
+ " [p] Payload of packet:\n" \
+ " 0:PRBS9 1:11110000 2:10101010 3:PRBS15\n" \
+ " 4:11111111 5:00000000 6:00001111 7:01010101\n" \
+ " [y] Phy:\n" \
+ " 1:LE 1M 2:LE 2M 3:LE Coded(S=8) 4:LE Coded(S=2)\n" \
+ " MT7668 only supports LE-1M and LE-2M\n" \
+ " EX: # ./boots -c ble_etx -c 39 -l 255 -p 7 -y 2"
+#define USAGE_BLEERX_PREFACE \
+ "BLE Enhanced RX test [-c <0-39>] [-y <1-3>] [-m <0-1>]"
+#define USAGE_BLEERX_DETAILS \
+ " [c] Channel: 0-39\n" \
+ " [y] Phy: 1:LE 1M 2:LE 2M 3: LE Coded \n" \
+ " LE Coded MT7668/6632 not support\n" \
+ " [m] Modulation: 0:Standard 1:Stable\n" \
+ " EX: # ./boots -c ble_erx -c 39 -y 2 -m 0"
+#define USAGE_BLE_S_DETAILS \
+ " EX: # ./boots -c ble_stop"
+#define USAGE_TXTONE_PREFACE \
+ "TX tone test(before BLE5.0) [-t <0-4>] [-c <0-78>] [-m <0/1>] [-d <0-2>] [-p <0/1>]\n" \
+ " (after BLE5.0) [-t <0-4>] [-c <0-78>] [-d <0-6>] [-p <0/1>]"
+#define USAGE_TXTONE_DETAILS \
+ RED" before BLE5.0 please following define\n"NONE \
+ " [t] Tone Type:\n" \
+ " 0:SingleTone_DC 1:SingleTone_250K 2:SignleTone_400K\n" \
+ " 3:SignleTone_1M 4:ModulationTone\n" \
+ " [c] Channel: 0-78\n" \
+ " The following parameters only for Modulation Tone\n" \
+ " [m] Mode: 0:BT 1:BLE\n" \
+ " [d] Modulation(Only for BT mode): 0:1M 1:2M 2:3M\n" \
+ " [p] Pattern: 0:PRBS9 1:PRBS15\n" \
+ " EX: # ./boots -c txtone -t 4 -c 78 -m 0 -d 0 -p 1\n" \
+ RED" after BLE5.0 please following define\n"NONE \
+ " [t] Tone Type:\n" \
+ " 0:SingleTone_DC 1:SingleTone_250K 2:SignleTone_400K\n" \
+ " 3:SignleTone_1M 4:ModulationTone\n" \
+ " [c] Channel: 0-78\n" \
+ " The following parameters only for Modulation Tone\n" \
+ " [d] Modulation: 0:BT EDR 1M 1:BT EDR 2M 2:BT EDR 3M\n" \
+ " 3:BLE 1M 4:BLE 2M 5:BLR 125K 6:BLR 500K \n" \
+ " [p] Pattern: 0:PRBS9 1:PRBS15\n" \
+ " EX: # ./boots -c txtone -t 4 -c 78 -d 3 -p 1"
+
+#define USAGE_RADIOSETTING_PREFACE \
+ "Radio setting"RED"(in level for 7663/7668 only)"NONE" [-b <0~7>] [-e <0~7>] [-m <0~7>] [-s <0~3>] [-o <0/1>]"
+#define USAGE_RADIOSETTING_DETAILS \
+ " [b] BT TX power level\n" \
+ " [e] BLE TX power level\n" \
+ " [m] Max TX power level\n" \
+ " [s] use for 1db adjust\n" \
+ " [o] 0 - Default 3db diff, 1 - 0db diff mode to BR/EDR\n" \
+ " EX: # ./boots -c radio -b 7 -e 7 -m 7 -s 3 -o 0\n"
+#define USAGE_TXPOWSETTING_PREFACE \
+ "Tx power setting"RED"(in dbm for 7921 only)"NONE" [-b <-32~12>] [-e <-29~20>] [-m <-32~12>] [-n <0/1>] [-o <0/1>]"
+#define USAGE_TXPOWSETTING_DETAILS \
+ " for Buzzard below\n" \
+ " [b] EDR init TX power dbm\n" \
+ " [e] BLE TX power dbm\n" \
+ " [m] EDR Max TX power dbm\n" \
+ " [n] 0 - Default disable Lv9, 1 - enable Lv9\n" \
+ " [o] 0 - Default 3db diff, 1 - 0db diff mode to BR/EDR\n" \
+ " EX: # ./boots -c txpow -b 10 -e 10 -m 10 -n 1 -o 0"
+#define USAGE_TXPOWEROFFSET_PREFACE \
+ "TX power offset\n" \
+ " 7662/7668(6 groups)., 7663/7921(16 groups):\n" \
+ " [g16]\n" \
+ " [-g0 <-16~16>] [-g1 <-16~16>] [-g2 <-16~16>] [-g3 <-16~16>] [-g4 <-16~16>] [-g5 <-16~16>] ...\n" \
+ " The following ONLY for 7668\n" \
+ " [-r0 <-2~4>] [-r1 <-2~4>] [-r2 <-2~4>] [-r3 <-2~4>] [-r4 <-2~4>] [-r5 <-2~4>]\n" \
+ " [-i0 <-6~6> or <-16~8>] [-i1 <-6~6> or <-16~8>] [-i2 <-6~6> or <-16~8>]\n" \
+ " [-i3 <-6~6> or <-16~8>] [-i4 <-6~6> or <-16~8>] [-i5 <-6~6> or <-16~8>]\n" \
+ " [-e0 <-16~8>] [-e1 <-16~8>] [-e2 <-16~8>] [-e3 <-16~8>] [-e4 <-16~8>] [-e5 <-16~8>]"
+#define USAGE_TXPOWEROFFSET_DETAILS \
+ "\n [g16]: Force setting 16 groups, ONLY for 7663/7921\n" \
+ " [g] GroupX: 7662/7668 have 6 groups, 7663 have 16 groups\n" \
+ " 7668 group\n" \
+ " Group0: CH0 - 12 Group1: CH13 - 25 Group2: CH26 - 38\n" \
+ " Group3: CH39 - 51 Group4: CH52 - 64 Group5: CH65 - 78\n" \
+ " 7663/7921 group\n" \
+ " Group0: CH0 - 3 Group1: CH4 - 8 Group2: CH9 - 13 Group3: CH14 - 18\n" \
+ " Group4: CH19 - 23 Group5: CH24 - 28 Group6: CH29 - 33 Group7: CH34 - 38\n" \
+ " Group8: CH39 - 43 Group9: CH44 - 48 Group10:CH49 - 53 Group11:CH54 - 58\n" \
+ " Group12:CH59 - 63 Group13:CH64 - 68 Group14:CH69 - 73 Group15:CH74 - 78\n" \
+ " The following ONLY for 7668\n" \
+ " [r] RF CR for level 8 GroupX:\n" \
+ " [i] Level 8 GroupX:\n" \
+ " [e] ePA GroupX:\n" \
+ " Group0: CH0 - 12 Group1: CH13 - 25 Group2: CH26 - 38\n" \
+ " Group3: CH39 - 51 Group4: CH52 - 64 Group5: CH65 - 78\n" \
+ " <-16~8>: Unit is +/-0.25db per step and 0 is default value\n" \
+ " Note: set -i only, Boots will use stage 1, set -r and -i together, Boots will use stage 2.\n" \
+ " EX: [7662/7668] # ./boots -c txpwoffset -g0 6 -g1 5 -g2 4 -g3 3 -g4 2 -g5 1\n" \
+ " [7668 only] # ./boots -c txpwoffset -g0 6 ... -r0 4 ... -i0 6 ... -e0 8 ...\n" \
+ " [7663/7921] # ./boots -c txpwoffset -g0 6 ... -g15 8\n" \
+ " [7663/7921] # ./boots -c txpwoffset g16 -g0 6"
+#define USAGE_WH_DETAILS \
+ " EX: # ./boots -c whiten 1"
+#define USAGE_SYNC_DETAILS \
+ " EX: # ./boots -c sync 11:33:55:77:99:BB:DD:FF"
+#define USAGE_EFUSE_WR_PREFACE \
+ "Read/Write eFuse [-r/w] [-a <HEX:0-0xFFFF>] [-v <HEX:0-0xFF>]"
+#define USAGE_EFUSE_WR_DETAILS \
+ " [w] Write: write efuse value\n" \
+ " [r] Read: read efuse value\n" \
+ " [a] Addr: address of efuse\n" \
+ " [v] Value: value of efuse\n" \
+ " EX: # ./boots -c efuse -r -a 1A5F"
+#define USAGE_REGISTER_WR_PREFACE \
+ "Read/Write Register [-r/w] [-a <HEX:0-0xFFFFFFFF>] [-v <HEX:0-0xFFFFFFFF>]"
+#define USAGE_REGISTER_WR_DETAILS \
+ " [w] Write: write register value\n" \
+ " [r] Read: read register value\n" \
+ " [a] Addr: address of register\n" \
+ " [v] Value: value of register\n" \
+ " EX: # ./boots -c reg -r -a 11111111"
+#define USAGE_FILE_WR_PREFACE \
+ "Read/Write File [-r/w] [-a <HEX>] [-v <HEX:0-0xFF>] [-f <file_path>]"
+#define USAGE_FILE_WR_DETAILS \
+ " [w] Write: write bin_file value\n" \
+ " [r] Read: read bin_file value\n" \
+ " [a] Addr: offset of bin_file\n" \
+ " [v] Value: value of bin_file\n" \
+ " [f] File path: full path and name of bin file\n" \
+ " EX: # ./boots -c file -w -a 0 -v 6 -f boots.bin"
+#define USAGE_STT_PREFACE \
+ "Stress test using \"Write Local Name HCI Command\" <pkt size 1-248>"
+#define USAGE_STT_DETAILS \
+ " EX: # ./boots -c stt 248"
+#define USAGE_LBT_PREFACE \
+ "Loopback test using \"ACL packet\" <pkt size 1-1021>"
+#define USAGE_LBT_DETAILS \
+ " EX: # ./boots -c lbt 255"
+#define USAGE_LTT_PREFACE \
+ "Loopback test with timer using \"ACL packet\" [-t <ms>] [-s <pkt size>]"
+#define USAGE_LTT_DETAILS \
+ " EX: # ./boots -c ltt -t 100 -s 255"
+#define USAGE_PA_DETAILS \
+ " EX: # ./boots -c pa 1"
+#define USAGE_DUPLEX_DETAILS \
+ " EX: # ./boots -c duplex 1"
+#define USAGE_BG_RSSI_PREFACE \
+ "Enable/Disable background RSSI scan <0/1> [-o <0/1>] [-s <0-78>] [-e <0-78>] [-a <DEC>] [-f <DEC>] [-n <0/1>]"
+#define USAGE_BG_RSSI_DETAILS \
+ " <0/1> 0:disable 1:enable\n" \
+ " 1: mt7668 will continue report rssi value for each channels and packages\n" \
+ " Boots will output it to the log depend on the setting parameter.\n" \
+ " [o] Output: output report when disable background rssi, 0:disable 1:enable\n" \
+ " [s] Start channel: 0-78. default:0\n" \
+ " [e] End channel: 0-78. default:78\n" \
+ " [a] Average package(s): calculate average when gatting n rssi channel packages. default:1\n" \
+ " [f] Alpha filter: calculate 1/n alpha filter for each rssi channel packages.\n" \
+ " [n] Report once: display only one report and stop background rssi immediately. 0:disable 1:enable\n" \
+ " EX: # ./boots -c rssi 1 -o 1 -s 0 -e 78 -f 100"
+#define USAGE_PK_RSSI_DETAILS \
+ " [a] Handle: handle to get rssi value, if ignore this boots will use the default value: 0x0032\n" \
+ " EX: # ./boots -c pk_rssi"
+#define USAGE_BUF_MODE_DETAILS \
+ " EX: # ./boots -c buf_mode -e 1"
+#define CMD_BUF_MODE "buf_mode"
+#define USAGE_TX_HOPPING_PREFACE \
+ "Set hopping 20 channel: low/middle/high\n" \
+ " low: hopping 2402~2421MHz\n" \
+ " middle: hopping 2432~2451MHz\n" \
+ " high: hopping 2461~2480MHz"
+#define USAGE_TX_HOPPING_DETAILS \
+ " EX: # ./boots -c tx_hopping low"
+#define USAGE_SWITCH_BT_PREFACE \
+ "Switch BT0/1 <0:BT0/1:BT1>" \
+ RED"(for 7921)"NONE
+#define USAGE_SWITCH_BT_DETAILS \
+ " EX: # ./boots -c swbt 0"
+#define USAGE_POWER_COMPENSATION_PREFACE \
+ "Power compensation [-a <0/1>] [-l <0-3>]" \
+ RED"(for 7921)\n"NONE \
+ " 7921(6 groups):\n" \
+ " [-g0 <-16~16>] [-g1 <-16~16>] [-g2 <-16~16>] [-g3 <-16~16>] [-g4 <-16~16>] [-g5 <-16~16>]"
+#define USAGE_POWER_COMPENSATION_DETAILS \
+ " [a] Antenna index: 0: Antenna0 1: Antenna1\n" \
+ " [l] Offset level: 0: LMAX offset 1: LMAX-1 offset\n" \
+ " 2: LMAX-2 offset 3: LMAX-3 offset\n" \
+ " [g] GroupX: 7921 have 6 groups\n" \
+ " EX: # ./boots -c pwcomp -a 0 -l 1 -g0 6 -g1 5 -g2 4 -g3 3 -g4 2 -g5 1"
+#define USAGE_POWER_BOUNDARY_PREFACE \
+ "Power boundary [-a <0/1>]" \
+ RED"(for 7921)\n"NONE \
+ " 7921(5 boundaries):\n" \
+ " [-b0 <0~80>] [-b1 <0~79>] [-b2 <0~79>] [-b3 <0~79>] [-b4 <0~79>]"
+#define USAGE_POWER_BOUNDARY_DETAILS \
+ " [a] Antenna index: 0: Antenna0, 1: Antenna1\n" \
+ " [b] BoundaryX: 7921 can set 5 boundaries\n" \
+ " EX: # ./boots -c pwbdry -a 0 -b0 12 -b1 21 -b2 45 -b3 60 -b4 79"
+#define USAGE_SET_SX_TX_PREFACE \
+ "Set SX TX Type" \
+ RED"(for 7921)\n"NONE \
+ " BT0/1 according to SWITCH_BT command setting\n" \
+ " BT0 SX Configration: 1: DIV2 for Rx , 3: SSB 8/3 for T/Rx\n" \
+ " 4: SSB 16/5 for T/Rx, 5: DIV2 LP for Rx\n" \
+ " BT1 SX Configration: 0: VCDL 5/2 for T/Rx, 1: DIV2 for Rx\n" \
+ " 2: VCDL 7/2 for T/Rx, 5: DIV2 LP for Rx"
+#define USAGE_SET_SX_TX_DETAILS \
+ " EX: # ./boots -c sxtx 0"
+#define USAGE_SET_SX_RX_PREFACE \
+ "Set SX RX Type" \
+ RED"(for 7921)\n"NONE \
+ " BT0/1 according to SWITCH_BT command setting\n" \
+ " BT0 SX Configration: 1: DIV2 for Rx , 3: SSB 8/3 for T/Rx\n" \
+ " 4: SSB 16/5 for T/Rx, 5: DIV2 LP for Rx\n" \
+ " BT1 SX Configration: 0: VCDL 5/2 for T/Rx, 1: DIV2 for Rx\n" \
+ " 2: VCDL 7/2 for T/Rx, 5: DIV2 LP for Rx"
+#define USAGE_SET_SX_RX_DETAILS \
+ " EX: # ./boots -c sxrx 0"
+#define USAGE_ANT_TO_PIN_LOSS_PREFACE \
+ "Set ANT-to-ChipPin loss 1dB/step, suggested range from 0-5dB" \
+ RED"(for 7921)\n"NONE \
+ " <0~20> 0.25dB/step"
+#define USAGE_ANT_TO_PIN_LOSS_DETAILS \
+ " EX: # ./boots -c a2ploss 0"
+#define USAGE_READ_EDR_INFO_PREFACE \
+ "Read EDR infomation" \
+ RED"(for 7921)"NONE
+#define USAGE_READ_EDR_INFO_DETAILS \
+ " EX: # ./boots -c redrinfo"
+#define USAGE_EPA_ELNA_PREFACE \
+ "ePA/eLNA 0: disable 1: enable" \
+ RED"(for 7921)"NONE
+#define USAGE_EPA_ELNA_DETAILS \
+ " [p] ePA: 0: disable, 1: enable\n" \
+ " [l] eLNA: 0: disable, 1: enable\n" \
+ " EX: # ./boots -c palna -p 0 -l 0"
+#define USAGE_SWITCH_RX_MODE_PREFACE \
+ "Switch RX normal mode/low power mode" \
+ RED"(for 7921)\n"NONE \
+ " 1: div2 normal mode, 5: div2 low power mode"
+#define USAGE_SWITCH_RX_MODE_DETAILS \
+ " EX: # ./boots -c swrxmode 1"
+#define USAGE_SET_XO_MODE_PREFACE \
+ "Set XO mode 0: AX mode 1: BT Mode" \
+ RED"(for 7921)"NONE
+#define USAGE_SET_XO_MODE_DETAILS \
+ " EX: # ./boots -c setxo 1"
+#define USAGE_GET_XO_MODE_PREFACE \
+ "Get XO mode 0: AX mode 1: BT Mode" \
+ RED"(for 7921)"NONE
+#define USAGE_GET_XO_MODE_DETAILS \
+ " EX: # ./boots -c getxo"
+#define USAGE_BT_MODE_XO_TRIM_PREFACE \
+ "BT mode XO trim [-f <5~127>] [-x <-63~63>] [-y <-63~63>] [-z <-63~63>]" \
+ RED"(for 7921)"NONE
+#define USAGE_BT_MODE_XO_TRIM_DETAILS \
+ " [f] Frequency offset ( XO_C1_SEL_BTM)\n" \
+ " [x] XO trim2 compensation (XO_C1_SEL_BTM)\n" \
+ " [y] XO trim3 compensation (XO_C1_SEL_BTM)\n" \
+ " [z] XO trim4 compensation (XO_C1_SEL_BTM)\n" \
+ " EX: # ./boots -c trimxo -f 10 -x 10 -y 10 -z 10"
+
+boots_cmds_s commands[] = {
+ { "reset", mtk_boots_cmd_reset, "HCI Reset", USAGE_RESET_DETAILS, false },
+ { "inq", mtk_boots_cmd_inquiry, "Inquiry [-t <X * 1.28 sec>]", USAGE_INQ_DETAILS, false },
+ { "dut", mtk_boots_cmd_enter_dut, "Enter DUT mode", USAGE_DUT_DETAILS, false },
+ { "raddr", mtk_boots_cmd_read_bd_addr, "Read BD address", USAGE_RADDR_DETAILS, false },
+ { "waddr", mtk_boots_cmd_write_bd_addr, "Write BD address <0E:8D:76:68:00:01>", USAGE_WADDR_DETAILS, false },
+ { "pwrlvl", mtk_boots_cmd_set_power_level, "Set power level(0xFC17) ONLY for RFTX since per link handle <0-7>", USAGE_PWRL_DETAILS, false },
+ { "radio", mtk_boots_cmd_radio_setting, USAGE_RADIOSETTING_PREFACE, USAGE_RADIOSETTING_DETAILS, false },
+ { "txpow", mtk_boots_cmd_tx_power_setting, USAGE_TXPOWSETTING_PREFACE, USAGE_TXPOWSETTING_DETAILS, false },
+ { "txpwoffset", mtk_boots_cmd_tx_power_offset, USAGE_TXPOWEROFFSET_PREFACE, USAGE_TXPOWEROFFSET_DETAILS, false },
+ { "whiten", mtk_boots_cmd_set_whiten, "Set whiten <0:disable/1:enable>", USAGE_WH_DETAILS, false },
+ { "sync", mtk_boots_cmd_sync, "Access Code <XX:XX:XX:XX:XX:XX:XX:XX>", USAGE_SYNC_DETAILS, false },
+ { "rft", mtk_boots_cmd_rf_tx, USAGE_RFTX_PREFACE, USAGE_RFTX_DETAILS, false },
+ { "rfr", mtk_boots_cmd_rf_rx, USAGE_RFRX_PREFACE, USAGE_RFRX_DETAILS RFR_EX, false },
+ { "rf_stop", mtk_boots_cmd_rf_stop, USAGE_RF_STOP_PREFACE, USAGE_RF_STOP_DETAILS, false },
+ { "rfr_stop", mtk_boots_cmd_rf_rx, USAGE_RFRX_STOP_PREFACE, USAGE_RFRX_DETAILS RFR_S_EX, false },
+ { "rfr_result", mtk_boots_cmd_rf_rx, USAGE_RFRX_RESULT_PREFACE, USAGE_RFRX_DETAILS RFR_R_EX, false },
+ { "ble_tx", mtk_boots_cmd_ble_tx, USAGE_BLETX_PREFACE, USAGE_BLETX_DETAILS, false },
+ { "ble_rx", mtk_boots_cmd_ble_rx, "BLE RX test [-c <0-39>]", USAGE_BLERX_DETAILS, false },
+ { "ble_etx", mtk_boots_cmd_ble_etx, USAGE_BLEETX_PREFACE, USAGE_BLEETX_DETAILS, false },
+ { "ble_erx", mtk_boots_cmd_ble_erx, USAGE_BLEERX_PREFACE, USAGE_BLEERX_DETAILS, false },
+ { "ble_stop", mtk_boots_cmd_ble_test_stop, "Stop BLE test", USAGE_BLE_S_DETAILS, false },
+ { "txtone", mtk_boots_cmd_tx_tone, USAGE_TXTONE_PREFACE, USAGE_TXTONE_DETAILS, false },
+ { "efuse", mtk_boots_cmd_efuse_wr, USAGE_EFUSE_WR_PREFACE, USAGE_EFUSE_WR_DETAILS, false },
+ { "reg", mtk_boots_cmd_register_wr, USAGE_REGISTER_WR_PREFACE, USAGE_REGISTER_WR_DETAILS, true },
+ { "file", mtk_boots_cmd_file_wr, USAGE_FILE_WR_PREFACE, USAGE_FILE_WR_DETAILS, true },
+ { "stt", mtk_boots_cmd_stress_test, USAGE_STT_PREFACE, USAGE_STT_DETAILS, false },
+ { "lbt", mtk_boots_cmd_loop_back_test, USAGE_LBT_PREFACE, USAGE_LBT_DETAILS, false },
+ { "ltt", mtk_boots_cmd_loop_timer_test, USAGE_LTT_PREFACE, USAGE_LTT_DETAILS, false },
+ { "pa", mtk_boots_cmd_set_pa, "Set ePA or iPA <0:iPA/1:ePA> ONLY for 7668", USAGE_PA_DETAILS, false },
+ { "duplex", mtk_boots_cmd_set_ant, "Set TDD mode(ANT1) or FDD mode(ANT2) <0:FDD/1:TDD>", USAGE_DUPLEX_DETAILS, false },
+ { "rssi", mtk_boots_cmd_background_rssi_scan, USAGE_BG_RSSI_PREFACE, USAGE_BG_RSSI_DETAILS, false },
+ { "pk_rssi", mtk_boots_cmd_packet_rssi, "Get BT packet RSSI [-a <HEX>]", USAGE_PK_RSSI_DETAILS, false },
+ { CMD_BUF_MODE, mtk_boots_cmd_set_buffer_mode, "Set buffer mode [-f <file_path>] [-e <0:disable/1:enable>]", USAGE_BUF_MODE_DETAILS, false },
+ { "tx_hopping", mtk_boots_cmd_set_tx_hopping, USAGE_TX_HOPPING_PREFACE, USAGE_TX_HOPPING_DETAILS, false },
+ { "swbt", mtk_boots_cmd_switch_bt, USAGE_SWITCH_BT_PREFACE, USAGE_SWITCH_BT_DETAILS, false },
+ { "pwcomp", mtk_boots_cmd_power_compensation, USAGE_POWER_COMPENSATION_PREFACE, USAGE_POWER_COMPENSATION_DETAILS, false },
+ { "pwbdry", mtk_boots_cmd_power_boundary, USAGE_POWER_BOUNDARY_PREFACE, USAGE_POWER_BOUNDARY_DETAILS, false },
+ { "sxtx", mtk_boots_cmd_set_sx, USAGE_SET_SX_TX_PREFACE, USAGE_SET_SX_TX_DETAILS, true },
+ { "sxrx", mtk_boots_cmd_set_sx, USAGE_SET_SX_RX_PREFACE, USAGE_SET_SX_RX_DETAILS, true },
+ { "a2ploss", mtk_boots_cmd_ant_to_pin_loss, USAGE_ANT_TO_PIN_LOSS_PREFACE, USAGE_ANT_TO_PIN_LOSS_DETAILS, false },
+ { "redrinfo", mtk_boots_cmd_read_edr_info, USAGE_READ_EDR_INFO_PREFACE, USAGE_READ_EDR_INFO_DETAILS, false },
+ { "palna", mtk_boots_cmd_epa_elna, USAGE_EPA_ELNA_PREFACE, USAGE_EPA_ELNA_DETAILS, false },
+ { "swrxmode", mtk_boots_cmd_set_sx, USAGE_SWITCH_RX_MODE_PREFACE, USAGE_SWITCH_RX_MODE_DETAILS, true },
+ { "setxo", mtk_boots_cmd_set_xomode, USAGE_SET_XO_MODE_PREFACE, USAGE_SET_XO_MODE_DETAILS, false },
+ { "getxo", mtk_boots_cmd_get_xomode, USAGE_GET_XO_MODE_PREFACE, USAGE_GET_XO_MODE_DETAILS, false },
+ { "trimxo", mtk_boots_cmd_bt_xo_trim, USAGE_BT_MODE_XO_TRIM_PREFACE, USAGE_BT_MODE_XO_TRIM_DETAILS, false },
+ { NULL, NULL, NULL, NULL, NULL }
+};
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_raw_cmd_handler(char *raw[], size_t len)
+{
+ size_t i = 0;
+ uint8_t type = 0;
+ pkt_list_s *node = NULL;
+
+ if (!raw || len < 4) {
+ BPRINT_E("Incorrect input(len: %d)", (int)len);
+ return 0;
+ }
+
+ if (!memcmp(raw[0], "CMD", strlen(raw[0])) || !memcmp(raw[0], "cmd", strlen(raw[0]))) {
+ size_t rawlen = strtol(raw[3], NULL, 16);
+ if (len != rawlen + 4) {
+ BPRINT_E("Incorrect command length: %d", (int)rawlen);
+ return 0;
+ }
+ type = 0x01;
+ i = 1;
+ } else if (!memcmp(raw[0], "ACL", strlen(raw[0])) || !memcmp(raw[0], "acl", strlen(raw[0]))) {
+ type = 0x02;
+ i = 1;
+ } else if (!memcmp(raw[0], "SCO", strlen(raw[0])) || !memcmp(raw[0], "sco", strlen(raw[0]))) {
+ BPRINT_E("%s: SCO not support yet", __func__);
+ return 0;
+ } else {
+ BPRINT_E("%s: Incorrect argument", __func__);
+ return 0;
+ }
+
+ node = boots_pkt_node_push(SCRIPT_NONE, type, NULL, len, NULL, NULL);
+ if (!node) {
+ BPRINT_D("%s: node push fail", __func__);
+ return NULL;
+ }
+
+ node->u_cnt.data[0] = type;
+ while (raw[i] && i < len) {
+ node->u_cnt.data[i] = strtol(raw[i], NULL, 16);
+ i++;
+ }
+ node->len = i;
+ // TODO check packet length & content
+ return node; // actually raw data length
+}
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_cmd_set_handler(char *cmd[], size_t len)
+{
+ uint8_t i = 0;
+ pkt_list_s *list = NULL;
+
+ if (!cmd || !len) return NULL;
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ if (commands[i].cmd && !memcmp(cmd[0], commands[i].cmd, strlen(cmd[0]))) {
+ if ((list = commands[i].func(cmd, len)) == NULL) {
+ // ignore this command since no controller operation
+ if (memcmp(*cmd, CMD_BUF_MODE, strlen(CMD_BUF_MODE)))
+ BPRINT_I("%s\n%s", commands[i].comment, commands[i].details);
+ return NULL;
+ } else {
+ return list;
+ }
+ }
+ }
+ BPRINT_I("%s: Command Not Found(%s)", __func__, cmd[0]);
+
+ return NULL;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_pkt.h b/src/connectivity/bt_others/boots/boots_pkt.h
new file mode 100644
index 0000000..befbd14
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_pkt.h
@@ -0,0 +1,141 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_PKT_H__
+#define __BOOTS_PKT_H__
+
+#include "boots.h"
+
+/** Bluetooth Packet Header Length */
+#define HCI_CMD_PKT_HDR_LEN 4
+#define HCI_EVENT_PKT_HDR_LEN 3
+#define HCI_ACL_PKT_HDR_LEN 5
+
+/** Bluetooth Packet Type */
+#define HCI_CMD_PKT 0x01
+#define HCI_ACL_PKT 0x02
+#define HCI_SCO_PKT 0x03
+#define HCI_EVENT_PKT 0x04
+
+/** Script Action Type */
+#define SCRIPT_NONE 0x00
+#define SCRIPT_TITLE 0x01
+#define SCRIPT_PROC 0x02
+#define SCRIPT_TX 0x03
+#define SCRIPT_RX 0x04
+#define SCRIPT_WAITRX 0x05
+#define SCRIPT_LOOP 0x06
+#define SCRIPT_LOOPEND 0x07
+#define SCRIPT_TIMEOUT 0x08
+#define SCRIPT_WAIT 0x09
+#define SCRIPT_USBALT 0x0A
+#define SCRIPT_CMD 0x0B
+#define SCRIPT_STRESS 0x0C
+#define SCRIPT_LOOPBACK 0x0D
+#define SCRIPT_LPTIMER 0x0E
+#define SCRIPT_RSSI 0x0F
+#define SCRIPT_END 0x10 // script end
+
+/** Script setting */
+typedef struct script_set {
+ FILE *script; /** script FD */
+ int loop; /** loop counter */
+ long loop_pos; /** record loop header */
+ int timo; /** timeout */
+ int wait; /** sleep */
+} script_set_s;
+
+/** Background RSSI setting */
+typedef struct rssi_set {
+ int ch_start; /** start channel */
+ int ch_end; /** end channel */
+ int avg_package; /** number of average package */
+ int alpha_filter; /** alpha filter */
+ uint8_t report; /** olny create RSSI report in stop command */
+ uint8_t stop; /** stop rssi reporting */
+ uint8_t one_shot; /** only report once */
+} rssi_set_s;
+
+/** Store packet list */
+typedef struct pkt_list {
+ uint8_t s_type; /** script file type, for SCRIPT_TX/RX/WAITRX please fill packet type */
+ uint8_t p_type; /** packet type */
+ union {
+ uint8_t *data; /** for command, ACL, SCO & event content */
+ char *msg; /** for title & proc would show message */
+ int loop; /** for loop tims */
+ int timo; /** for timeout */
+ int wait; /** for wait */
+ int usbalt; /** for USB alternate */
+ rssi_set_s *rssi_s; /** for rssi setting */
+ } u_cnt;
+ size_t len;
+ struct pkt_list *next;
+} pkt_list_s;
+
+/** Modular commands */
+typedef struct {
+ char *cmd; // Shows command
+ pkt_list_s *(*func)(char *cmd[], size_t len); // Implementeded functions
+ char *comment; // Shows comment
+ char *details; // Command details
+ bool hidden; // hidden command
+} boots_cmds_s;
+
+//---------------------------------------------------------------------------
+
+void boots_pkt_cleanup_report_rssi(uint8_t stop);
+pkt_list_s *boots_pkt_node_push(uint8_t s_type, uint8_t p_type, void *content,
+ size_t len, pkt_list_s *front, pkt_list_s *head);
+pkt_list_s *boots_pkt_node_pop(pkt_list_s *list, uint8_t *buf, size_t *len);
+void boots_pkt_list_destroy(pkt_list_s *list);
+size_t boots_pkt_list_amount(pkt_list_s *list);
+
+size_t boots_pkt_handler(uint8_t *buf, size_t len, pkt_list_s **pList);
+pkt_list_s *boots_raw_cmd_handler(char *raw[], size_t len);
+pkt_list_s *boots_cmd_set_handler(char *raw[], size_t len);
+
+FILE *boots_script_open(char *file);
+void boots_script_close(FILE *fd);
+void boots_script_loop(FILE * fd, long size);
+pkt_list_s *boots_script_get(FILE *fd);
+
+ssize_t boots_file_wr(uint8_t *buf, ssize_t *len);
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_PKT_H__
diff --git a/src/connectivity/bt_others/boots/boots_script.c b/src/connectivity/bt_others/boots/boots_script.c
new file mode 100644
index 0000000..c51dbb1
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_script.c
@@ -0,0 +1,590 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <errno.h>
+
+#include "boots_pkt.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_script"
+
+#define LINESIZE 8192
+#define LINEVALUESIZE 4096
+
+#define SCRIPTLINE(name) {#name, SCRIPT_##name, sizeof(#name)-1, FUN_##name}
+
+//---------------------------------------------------------------------------
+typedef struct per_cmd_info {
+ char *name;
+ uint8_t scriptType;
+ int nameLen;
+ void* (*func_cmd)(int, char*, uint8_t*, void **, int *); // reserved.now, only print log, if needed to preprocess cmd, please register for each one
+} S_per_cmd_info;
+
+//---------------------------------------------------------------------------
+static void* FUN_TITLE(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_PROC(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_TX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_RX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_WAITRX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_LOOP(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_LOOPEND(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_TIMEOUT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_WAIT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_USBALT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_CMD(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+static void* FUN_END(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen);
+
+//---------------------------------------------------------------------------
+static S_per_cmd_info script_line_s[] = {
+ SCRIPTLINE(TITLE),
+ SCRIPTLINE(PROC),
+ SCRIPTLINE(TX),
+ SCRIPTLINE(RX),
+ SCRIPTLINE(WAITRX),
+ SCRIPTLINE(LOOPEND), /* should be ahead of LOOP */
+ SCRIPTLINE(LOOP),
+ SCRIPTLINE(WAIT),
+ SCRIPTLINE(TIMEOUT),
+ SCRIPTLINE(USBALT),
+ SCRIPTLINE(TIMEOUT),
+ SCRIPTLINE(CMD),
+ SCRIPTLINE(END)
+};
+
+static int script_line_num = sizeof(script_line_s)/sizeof(S_per_cmd_info);
+
+static uint8_t packet_value_array[LINEVALUESIZE];
+static int paramValue = 0;
+
+static char *line = NULL;
+
+//---------------------------------------------------------------------------
+#if 0
+static char hextoascii(int i)
+{
+ i &= 0x0F;
+
+ if (i >= 0 && i <= 9)
+ return i + '0';
+ else
+ return i + ('A' - 0x0A);
+}
+
+static int print_hexes(char *hex, int len)
+{
+ int i;
+ printf("\tFormat in HEX -- ");
+ for (i = 0; i < len; i++, hex++) {
+ putchar(hextoascii(*hex >> 4));
+ putchar(hextoascii(*hex & 0x0f));
+ putchar(' ');
+ }
+ putchar('\r');
+ putchar('\n');
+ return 0;
+}
+
+static char* xitoa(int val, int base)
+{
+ static char sbuf[32] = {0};
+ int i = 30;
+ for(; val && i; --i, val /= base)
+ {
+ sbuf[i]="0123456789abcdef"[val % base];
+ }
+ return &sbuf[i+1];
+}
+#endif
+
+static uint8_t xatoi(char *p, int len)
+{
+ int n= 0;
+ uint8_t v = 0;
+
+ for(n=0; n<len; n++){
+ if((*p>='0')&&(*p<='9')) v = v*16 + (*p-'0');
+ else if((*p>='A')&&(*p<='F')) v = v*16 + (10+*p-'A');
+ else if((*p>='a')&&(*p<='f')) v = v*16 + (10+*p-'a');
+ else return(-1);
+ p++;
+ }
+ return v;
+}
+
+static void filter_space_c(char** ppStr, int head_filter, int tail_filter)
+{
+ char* str;
+ int start, end, strLen;
+
+ if (ppStr != NULL && *ppStr != NULL){
+ str = *ppStr;
+ //1. head fliter
+ if ((head_filter == 1) && (*str != '\0')){
+ for (start=0; *str==' '; start++){
+ str++;
+ }
+ }
+ //2. tail filter
+ if ((tail_filter == 1) && (*str != '\0')){
+ strLen = strlen(str);
+ for (end = strLen - 1; end >= 0 && str[end]==' '; end--){
+ str[end] = '\0';
+ }
+ }
+ *ppStr = str;
+ }
+}
+
+static int packet_safe_atoi(char valueStr[], uint8_t value[], int size)
+{
+ char *token = NULL, *savepStr=NULL;
+ uint8_t *valueIs = value;
+ int i = 0, repeat = 0, split_num = 0, len = 0;
+ int num = 0;
+ int ret = 0;
+
+ if (size > LINEVALUESIZE) {
+ BPRINT_W("Incorrect size %d", size);
+ size = LINEVALUESIZE;
+ }
+
+ memset(valueIs, 0, size);
+
+ token=strtok_r(valueStr, " ", &savepStr);
+ while(token != NULL){
+ len = strlen(token);
+ repeat = len/2 + len%2;
+ do{
+ split_num = ((len >= 2)?(2):(1));
+ ret = xatoi((token + i * 2), split_num);
+ if (ret < 0) {
+ BPRINT_E("Illegal string(%s), abort <\n", token + i*2);
+ num = 0;
+ break;
+ } else {
+ valueIs[num] = ret;
+ }
+ ++num;
+ ++i;
+ len -= i*2;
+ }while((--repeat) > 0);
+
+ if(num > 0){
+ token=strtok_r(NULL, " ", &savepStr);
+ i = 0;
+ }
+ else{
+ break;
+ }
+ }
+/*
+ if(num != 0){
+ int i = 0, tmpN = num;
+ printf("packet[num==%d]>", num);
+ while(tmpN){
+ printf("%02x", valueIs[i]);
+ printf(" ");
+ --tmpN;
+ ++i;
+ }
+ printf("\n");
+ }
+*/
+ return num;
+}
+
+static void* FUN_TITLE(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = ((Invalue == NULL)?0:(strlen(Invalue) + 1));
+ *oValue = (void*)((*oLen == 0)?NULL:Invalue);
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_PROC(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = ((Invalue == NULL)?0:(strlen(Invalue) + 1));
+ *oValue = (void*)((*oLen == 0)?NULL:Invalue);
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+static void* FUN_TX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = ((Invalue != NULL)?(xatoi(Invalue, 2)):(0));
+ *oLen = 0;
+ *oValue = NULL;
+
+ if((Invalue != NULL)){
+ *oLen = packet_safe_atoi(Invalue, packet_value_array, sizeof(packet_value_array));
+ if (*oLen > 0){
+ *oValue = packet_value_array;
+ }
+ else{
+ *oLen = 0;
+ *oValue = NULL;
+ }
+ }
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+static void* FUN_RX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = ((Invalue != NULL)?(xatoi(Invalue, 2)):(0));
+ *oLen = 0;
+ *oValue = NULL;
+
+ if((Invalue != NULL)){
+ *oLen = packet_safe_atoi(Invalue, packet_value_array, sizeof(packet_value_array));
+ if (*oLen > 0){
+ *oValue = packet_value_array;
+ }
+ else{
+ *oLen = 0;
+ *oValue = NULL;
+ }
+ }
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+static void* FUN_WAITRX(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = ((Invalue != NULL)?(xatoi(Invalue, 2)):(0));
+ *oLen = 0;
+ *oValue = NULL;
+
+ if((Invalue != NULL)){
+ *oLen = packet_safe_atoi(Invalue, packet_value_array, sizeof(packet_value_array));
+ if (*oLen > 0){
+ *oValue = packet_value_array;
+ }
+ else{
+ *oLen = 0;
+ *oValue = NULL;
+ }
+ }
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_LOOP(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = 1;
+ paramValue = ((*oLen == 0)?(0):(atoi(Invalue)));
+ *oValue = ¶mValue;
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<LOOP Count>%d",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType, *((int*)(*oValue)));
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_LOOPEND(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = 0;
+ *oValue = NULL;
+ UNUSED(Invalue);
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType);
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_TIMEOUT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = 1;
+ paramValue = ((*oLen == 0)?(0):(atoi(Invalue)));
+ *oValue = ¶mValue;
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<TIMEOUT>%d",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType, *((int*)(*oValue)));
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_WAIT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = ((Invalue == NULL)?0:(strlen(Invalue) + 1));
+ paramValue = ((*oLen == 0)?(0):(atoi(Invalue)));
+ *oValue = ¶mValue;
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<WAIT>%d",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType, *((int*)(*oValue)));
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_USBALT(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = 1;
+ paramValue = ((*oLen == 0)?(0):(atoi(Invalue)));
+ *oValue = ¶mValue;
+
+ BPRINT_D("lineName>%s<Type>0x%02x-0x%02x<USBALT>%d",
+ script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType, *opktType, *((int*)(*oValue)));
+
+ return (void*)NULL;
+}
+
+
+static void* FUN_CMD(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0x01;
+ *oLen = 0;
+ *oValue = NULL;
+
+ if((Invalue != NULL)){
+ *oLen = packet_safe_atoi(Invalue, &(packet_value_array[1]), sizeof(packet_value_array) - 1);
+ if (*oLen > 0){
+ packet_value_array[0] = 0x01;
+ *oLen += 1;
+ *oValue = packet_value_array;
+ }
+ else{
+ *oLen = 0;
+ *oValue = NULL;
+ }
+ }
+
+ BPRINT_D("lineName>%s<packetType>0x%02x<", script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType);
+ return (void*)NULL;
+}
+
+static void* FUN_END(int InfoundIndex, char* Invalue, uint8_t* opktType, void** oValue, int* oLen)
+{
+ *opktType = 0;
+ *oLen = 0;
+ *oValue = NULL;
+ UNUSED(Invalue);
+
+ BPRINT_D("lineName>%s<packetType>0x%02x<", script_line_s[InfoundIndex].name, script_line_s[InfoundIndex].scriptType);
+ return (void*)NULL;
+}
+
+
+static pkt_list_s *script_line_handle(char *lineName, char *lineValue)
+{
+ int i;
+ uint8_t pktType = 0;
+ void *value = NULL;
+ int valueLen;
+ UNUSED(boots_btif);
+
+ for(i = 0 ;i < script_line_num; i++){
+ if(!strncmp(lineName, script_line_s[i].name, script_line_s[i].nameLen)){
+ script_line_s[i].func_cmd(i, lineValue, &pktType, &value, &valueLen);
+#if 0
+ int num;
+ switch (script_line_s[i].scriptType) {
+ case SCRIPT_TX:
+ case SCRIPT_RX:
+ case SCRIPT_WAITRX:
+ case SCRIPT_CMD:
+ num = 0;
+ printf("[boots_script:D] TYPE = %02x < ", script_line_s[i].scriptType);
+ while(num < valueLen){
+ printf("%02x ", *((uint8_t*)value + num));
+ ++num;
+ }
+ printf("\n");
+ break;
+ case SCRIPT_TITLE:
+ case SCRIPT_PROC:
+ BPRINT_D("TYPE = %02x < %s", script_line_s[i].scriptType, (char*)value);
+ break;
+ case SCRIPT_LOOP:
+ BPRINT_D("TYPE = %02x < %d", script_line_s[i].scriptType, *((int*)value));
+ break;
+ case SCRIPT_TIMEOUT:
+ BPRINT_D("TYPE = %02x < %d", script_line_s[i].scriptType, *((int*)value));
+ break;
+ case SCRIPT_WAIT:
+ BPRINT_D("TYPE = %02x < %d", script_line_s[i].scriptType, *((int*)value));
+ break;
+ case SCRIPT_USBALT:
+ BPRINT_D("TYPE = %02x < %d", script_line_s[i].scriptType, *((int*)value));
+ break;
+ default:
+ break;
+ }
+#endif
+ return boots_pkt_node_push(script_line_s[i].scriptType, pktType, value, valueLen, NULL, NULL);
+ }
+
+ }
+ return NULL;
+}
+
+static pkt_list_s *script_line_parse(char *line)
+{
+ char *tmpStr = line;
+ char *delimStr = ":=";
+ char *subdelimStr = "//";
+ char *lineName, *lineValue;//, *lineAnno;
+ char *saveptr;
+ int slen;
+
+ // 1. filter out space until found out a char
+ filter_space_c(&tmpStr, 1, 0);
+
+ // 2. filter out annotation line
+ if ((*tmpStr == '#') || (strncmp(tmpStr, "//", 2) == 0)) {
+ // do nothing, just ignore
+
+ } else {
+ slen = strlen(tmpStr);
+ // 3. filter out new line('\n' 0A) & carriage ret ('\r' 0D)
+ if (tmpStr[slen - 1] == 0x0A) {
+ tmpStr[slen - 1] = '\0';
+ if (tmpStr[slen - 2] == 0x0D) {
+ tmpStr[slen - 2] = '\0';
+ }
+ }
+ slen = strlen(tmpStr);
+
+ if (slen == 0) {
+ // do nothing--only ignore
+ } else {
+ //BPRINT_D("line <%s>", tmpStr);
+ // 4. parse
+ lineName = strtok_r(tmpStr, delimStr, &saveptr);
+ if (lineName != NULL) {
+ lineValue = strtok_r(saveptr, subdelimStr, &lineValue);
+ } else {
+ return NULL;
+ }
+ //BPRINT_D("orgName <%s>", lineName);
+ //BPRINT_D("orgValue <%s>", lineValue);
+ //BPRINT_D("filter out space ...");
+
+ // 5. filter out space
+ filter_space_c(&lineName, 1, 1);
+ filter_space_c(&lineValue, 1, 1);
+
+ //BPRINT_D("newName <%s>", lineName);
+ //BPRINT_D("newValue <%s>", lineValue);
+
+ // 6. map Type and create node
+ return script_line_handle(lineName, lineValue);
+ }
+ }
+ return NULL;
+}
+
+//---------------------------------------------------------------------------
+FILE *boots_script_open(char *file)
+{
+ BPRINT_D("%s: %s", __func__, file);
+ return fopen(file, "r");
+}
+
+//---------------------------------------------------------------------------
+void boots_script_close(FILE *fd)
+{
+ if (line) {
+ free(line);
+ line = NULL;
+ }
+ if (fd) fclose(fd);
+}
+
+//---------------------------------------------------------------------------
+pkt_list_s *boots_script_get(FILE *fd)
+{
+ pkt_list_s *n = NULL;
+ char *buf = NULL;
+ size_t buf_size = 0;
+ ssize_t nread;
+
+ if (!fd) return NULL;
+
+ do {
+ if ((nread = getline(&buf, &buf_size, fd)) < 0)
+ break;
+ n = script_line_parse(buf);
+
+ } while (!n || nread == 0);
+
+ free(buf);
+
+ return n;
+}
+
+//---------------------------------------------------------------------------
+void boots_script_loop(FILE * fd, long size)
+{
+ (void)fseek(fd, size, SEEK_SET);
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_skt.c b/src/connectivity/bt_others/boots/boots_skt.c
new file mode 100644
index 0000000..5ea6be1
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_skt.c
@@ -0,0 +1,166 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+
+#include "boots.h"
+#include "boots_skt.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_skt"
+
+//---------------------------------------------------------------------------
+int boots_sk_create(int * sk, struct sockaddr_un * sockaddr, socklen_t * socklen,
+ char * name, int client)
+{
+ UNUSED(boots_btif);
+ int retry_counter = 10;
+
+ // Create server socket
+ *sk = socket(client ? PF_LOCAL : AF_UNIX, SOCK_DGRAM, 0);
+ if (*sk < 0) {
+ BPRINT_E("Create socket failed: %s %s(%d)", name, strerror(errno), errno);
+ return errno;
+ }
+
+ // Init server socket
+ sockaddr->sun_family = AF_UNIX;
+ memset(sockaddr->sun_path, 0, sizeof(sockaddr->sun_path));
+ strncpy(sockaddr->sun_path, name, strlen(name));
+ *socklen = (offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr->sun_path) + 1);
+
+ if (!client) {
+ // Remove the socket first
+ unlink(sockaddr->sun_path);
+ if (bind(*sk, (struct sockaddr *)sockaddr, *socklen) < 0) {
+ BPRINT_E("Bind socket failed: %s(%d)", strerror(errno), errno);
+ return errno;
+ }
+
+ } else {
+ int memsize = HCI_BUF_SIZE;
+ if (setsockopt(*sk, SOL_SOCKET, SO_RCVBUF, &memsize, sizeof(memsize)) < 0)
+ BPRINT_E("Set socket buffer size failed: %s(%d)", strerror(errno), errno);
+
+ while (retry_counter > 0) {
+ retry_counter--;
+ if (connect(*sk, (struct sockaddr *)sockaddr, *socklen) < 0) {
+ if (retry_counter > 0) {
+ BPRINT_W("Failed to connect to socket: %s(%d). Retry...", strerror(errno), errno);
+ sleep(1);
+ continue;
+ } else {
+ BPRINT_E("Failed to connect to socket: %s(%d). Stop Retry!", strerror(errno), errno);
+ return errno;
+ }
+ } else {
+ break;
+ }
+ }
+ }
+
+ BPRINT_D("Socket %s create success", name);
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+int boots_sk_close(int * sk)
+{
+ if (sk == NULL) {
+ BPRINT_E("%s: Incorrect socket", __func__);
+ return -1;
+ }
+ close(*sk);
+ *sk = -1;
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_sk_send(int s, const void * buf, size_t len, struct sockaddr_un * to,
+ char * name)
+{
+ ssize_t ret = 0;
+
+ if (!buf || !len) {
+ BPRINT_E("%s: Incorrect argument", __func__);
+ return -1;
+ }
+ if (s < 0) {
+ BPRINT_E("%s: Incorrect FD(%d)", __func__, s);
+ return -1;
+ }
+#if 0
+ ret = sendto(s, buf, len, 0, (const struct sockaddr *)to,
+ sizeof(struct sockaddr_un));
+#else
+ UNUSED(to);
+ UNUSED(name);
+ ret = send(s, buf, len, 0);
+#endif
+ if (ret < 0)
+ BPRINT_E("%s: Send message failed: %s(%d)", __func__, strerror(errno), errno);
+
+ return ret;
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_sk_recv(int s, const void * buf, size_t len, int flags,
+ struct sockaddr * src_addr, socklen_t * addrlen)
+{
+ ssize_t ret = 0;
+
+ if (!buf || !len) {
+ BPRINT_E("%s: Incorrect argument", __func__);
+ return -1;
+ }
+ if (s < 0) {
+ BPRINT_E("%s: Incorrect FD(%d)", __func__, s);
+ return -1;
+ }
+
+ ret = recvfrom(s, (void *)buf, len, flags, src_addr, addrlen);
+ if (ret < 0)
+ BPRINT_E("%s: Receive message failed: %s(%d)", __func__, strerror(errno), errno);
+
+ return ret;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_skt.h b/src/connectivity/bt_others/boots/boots_skt.h
new file mode 100644
index 0000000..74a8e5c
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_skt.h
@@ -0,0 +1,73 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_SOCKET_H__
+#define __BOOTS_SOCKET_H__
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "boots_cfg.h"
+
+//---------------------------------------------------------------------------
+#ifndef BOOTS_SOCKET_PATH
+#define BOOTS_SOCKET_PATH ""
+#endif
+
+#define BOOTS_SRVSK_NAME BOOTS_SOCKET_PATH"boots_srvsk"
+#define BOOTS_CLISK_NAME BOOTS_SOCKET_PATH"boots_clisk"
+
+//---------------------------------------------------------------------------
+#ifndef HCI_BUF_SIZE
+#define HCI_BUF_SIZE 0x1000
+#endif
+
+//---------------------------------------------------------------------------
+int boots_sk_create(int * sk, struct sockaddr_un * sockaddr,
+ socklen_t * socklen, char * name, int client);
+
+int boots_sk_close(int * sk);
+
+ssize_t boots_sk_send(int s, const void * buf, size_t len,
+ struct sockaddr_un * to, char * name);
+
+ssize_t boots_sk_recv(int s, const void * buf, size_t len, int flags,
+ struct sockaddr * src_addr, socklen_t * addrlen);
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_SOCKET_H__
diff --git a/src/connectivity/bt_others/boots/boots_srv.c b/src/connectivity/bt_others/boots/boots_srv.c
new file mode 100644
index 0000000..049737f
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_srv.c
@@ -0,0 +1,451 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include <signal.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/resource.h>
+
+#include "boots.h"
+#include "boots_pkt.h"
+#include "boots_btif.h"
+#include "boots_skt.h"
+#include "boots_uart.h"
+#include "boots_eth.h"
+#include "boots_stress.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_srv"
+
+//---------------------------------------------------------------------------
+static boots_if_s boots_srv_if;
+static int cont = 1;
+static int uart_speed = 0;
+int fd[BOOTS_BTIF_ALL] = {-1};
+int boots_loop_timer;
+rssi_set_s rssi_setting;
+
+/****************************************************************************
+ * F U N C T I O N D E C L A R A T I O N S *
+ ****************************************************************************/
+
+//---------------------------------------------------------------------------
+static void boots_srv_sig_handler(int signum)
+{
+ BPRINT_D("%s: signum: %d", __func__, signum);
+ cont = 0;
+}
+
+//---------------------------------------------------------------------------
+static void boots_srv_help(void)
+{
+ printf("Boots(server) - MTK Bluetooth Test Suite ver:%s(rev:%s)\n", VERSION, REV);
+ printf("Usage:\n");
+ printf(" boots_srv <[Input interface] [buadrate]> [BT Interface]\n");
+ printf("Input Interface:\n");
+ printf("\tCli/Srv connection by socket if you ignore this argument\n");
+ printf("\tttyX Specific UART for data issuer, baudate is for real port\n");
+ printf("\t ex: ./boots_srv ttyGS2\n");
+ printf("\t ex: ./boots_srv ttyUSB0 115200\n");
+ printf("\tethX Specific Eth for data issuer, need client IP\n");
+ printf("\t ex: ./boots_srv eth0 10.1.1.2\n");
+ printf("BT Interface:\n");
+ printf("\tAuto detect stpbt/HCI, if you ignore this argument\n");
+ printf("\tstpbt MTK stpbt Interface for BT controller, ex: ./boots_srv stpbt\n");
+ printf("\thci HCI Interface for BT controller\n");
+}
+
+//---------------------------------------------------------------------------
+static void boots_srv_chk_if(int argc, char **argv)
+{
+ int i = 0;
+#ifdef BOOTS_VERBOSE_MSG
+ BPRINT_D("%s: argc = %d", __func__, argc);
+ for (i = 0; i < argc; i++)
+ BPRINT_D("argv[%d]:%s", i, argv[i]);
+ i = 0;
+#endif
+
+ while (i < argc) {
+ if (!memcmp(argv[i], "stpbt", strlen("stpbt"))) {
+ boots_srv_if.btif = BOOTS_BTIF_STPBT;
+
+ } else if (!memcmp(argv[i], "hci", strlen("hci"))) {
+ boots_srv_if.btif = BOOTS_BTIF_HCI;
+
+ } else if (!memcmp(argv[i], "tty", strlen("tty"))) {
+ boots_srv_if.csif = BOOTS_CSIF_UART;
+ snprintf(boots_srv_if.cs, sizeof(boots_srv_if.cs), "/dev/%s", argv[i]);
+ BPRINT_D("%s: %s", __func__, boots_srv_if.cs);
+ if (i + 1 < argc) {
+ uart_speed = atoi(argv[i + 1]);
+ BPRINT_D("%s: UART speed: %d", __func__, uart_speed);
+ i += 2;
+ continue;
+ }
+
+ } else if (!memcmp(argv[i], "eth", strlen("eth"))) {
+ boots_srv_if.csif = BOOTS_CSIF_ETH;
+ memcpy(boots_srv_if.cs, argv[i + 1],
+ strlen(argv[i + 1]) > (16 - 1) ? (16 - 1) : strlen(argv[i + 1]));
+ i++;
+ }
+ i++;
+ }
+
+ if (boots_srv_if.csif == BOOTS_IF_NONE)
+ boots_srv_if.csif = BOOTS_CSIF_SKT;
+
+ if (boots_srv_if.btif == BOOTS_IF_NONE) {
+ if (access(boots_btif[0].p, R_OK) == 0) {
+ boots_srv_if.btif = BOOTS_BTIF_STPBT;
+ } else {
+ boots_srv_if.btif = BOOTS_BTIF_HCI;
+ }
+ }
+}
+
+//---------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ static uint8_t buf[HCI_BUF_SIZE] = {0};
+ int btfd = -1; // Interface file descriptor with BT controller
+ ssize_t len = 0;
+ struct sigaction sigact;
+ fd_set readfs;
+ rssi_set_s *temp_rssi_setting;
+ int which = PRIO_PROCESS;
+ id_t pid;
+ int priority = -20;
+ int ret;
+
+ // For root permission
+ CHECK_USERID();
+
+ if (argc >= 2 && !memcmp("-h", argv[1], strlen("-h"))) {
+ boots_srv_help();
+ exit(0);
+ }
+
+ sigact.sa_handler = boots_srv_sig_handler;
+ sigact.sa_flags = 0;
+ sigemptyset(&sigact.sa_mask);
+ sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGTERM, &sigact, NULL);
+ sigaction(SIGQUIT, &sigact, NULL);
+ sigaction(SIGKILL, &sigact, NULL);
+
+ boots_srv_chk_if(argc - 1, &argv[1]);
+
+ /** Communication Interface with BT controller */
+ if (boots_srv_if.btif != BOOTS_IF_NONE)
+ btfd = boots_btif_open(boots_srv_if.btif);
+ if (btfd < 0) {
+ BPRINT_E("Set interface failed(%d), please check driver and controller", boots_srv_if.btif);
+ boots_srv_help();
+ exit(1);
+ } else {
+ // Please follow the boots_if_e
+ char *c_inf[] = {"None", "stpbt", "hci", "All", "Socket", "UART", "Ethernet",
+ "User", "Tester_UART"};
+
+ BPRINT_I("client <-> %s(%d) <-> %s(%d) <-> BT", c_inf[boots_srv_if.csif],
+ boots_srv_if.csif, c_inf[boots_srv_if.btif], boots_srv_if.btif);
+ }
+
+ pid = getpid();
+ ret = setpriority(which, pid, priority);
+ if (ret != 0) {
+ BPRINT_I("setpriority fail: %s(%d)", strerror(errno), errno);
+ }
+
+ /** open interface to connect upper layer */
+ if (boots_srv_if.csif == BOOTS_CSIF_SKT) {
+ int skfd_srv = -1; // Interface file descriptor with host
+ int skfd_cli = -1; // Interface file descriptor with host
+ int boots_stress_enabled = 0;
+ struct sockaddr_un skaddr_srv;
+ struct sockaddr_un skaddr_cli;
+ socklen_t sklen_srv = {0};
+ socklen_t sklen_cli = {0};
+
+ if (boots_sk_create(&skfd_srv, &skaddr_srv, &sklen_srv, BOOTS_SRVSK_NAME, 0)) {
+ BPRINT_E("%s: Create server socket failed", __func__);
+ goto BTOFF;
+ }
+
+ BPRINT_I("Local relaying...");
+ while (cont && btfd >= 0) {
+ FD_ZERO(&readfs);
+ memset(buf, 0, sizeof(buf));
+
+ if (btfd >= 0)
+ FD_SET(btfd, &readfs);
+ if (skfd_srv >= 0)
+ FD_SET(skfd_srv, &readfs);
+
+ if (select(MAX(btfd, skfd_srv) + 1, &readfs, NULL, NULL, NULL) > 0) {
+ // Process the event from BT controller, read
+ if (FD_ISSET(btfd, &readfs)) {
+ len = boots_btif_read(btfd, buf, sizeof(buf));
+ if (boots_stress_enabled &&
+ ((buf[0] == 0x04 && buf[1] == 0x19) || // Write local name
+ (buf[0] == 0x04 && buf[1] == 0x0e) || // Write local name, FW bug
+#if BOOTS_STRESS_MEASURE_LBT_TOTAL_LATENCY
+ (buf[0] == 0x02 && buf[1] == 0x32) // ACL
+#else
+ (buf[0] == 0x04 && buf[1] == 0x13) // NOCP
+#endif
+ )) {
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH);
+ }
+
+ if (len > 0 && skfd_cli >= 0) {
+ boots_sk_send(skfd_cli, (void *)buf, len, &skaddr_cli, BOOTS_CLISK_NAME);
+ } else if (len > 0) {
+ boots_pkt_handler(buf, len, NULL);
+ } else if (len < 0) {
+ BPRINT_E("%s: Read data from chip failed", __func__);
+ btfd = -1;
+ break;
+ }
+ }
+ // Process the command from host, write
+ if (FD_ISSET(skfd_srv, &readfs)) {
+ // connect socket, server
+ if (skfd_cli == -1) {
+ int cont = 0;
+ while(access(BOOTS_CLISK_NAME, F_OK) == -1) {
+ usleep(100 * 1000);
+ cont++;
+ if (cont > 20) {
+ BPRINT_E("access BOOTS_CLISK_NAME failed: %s(%d)", strerror(errno), errno);
+ return 0;
+ }
+ }
+ if (boots_sk_create(&skfd_cli, &skaddr_cli, &sklen_cli, BOOTS_CLISK_NAME, 1)) {
+ BPRINT_E("%s: Connect client socket failed", __func__);
+ boots_sk_close(&skfd_srv);
+ goto BTOFF;
+ }
+ }
+ len = boots_sk_recv(skfd_srv, buf, sizeof(buf), 0, NULL, NULL);
+ if (len < 0)
+ break;
+
+ if (!BOOTS_STRESS_MEASURE_IN_BOOTS &&
+ boots_stress_enabled == 0 &&
+ ((buf[0] == 0x01 && buf[1] == 0x13 && buf[2] == 0x0c) ||// Write Local Name
+ (buf[0] == 0x01 && buf[1] == 0x02 && buf[2] == 0x18) // Write Loopback Mode
+ )) {
+ boots_stress_init();
+ boots_stress_enabled = 1;
+ }
+ if (boots_stress_enabled)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_SEND_CMD_START);
+
+ if (len == 4 && buf[0] == 's' && buf[1] == 'e' && buf[2] == 'n' && buf[3] == 'd') {
+ // client socket end
+ boots_sk_close(&skfd_cli);
+ skfd_cli = -1;
+ } else if (buf[0] == 0x01 && buf[1] == 0x01 && buf[2] == 0xFF) {
+ // read/write file
+ boots_file_wr(buf, &len);
+ boots_sk_send(skfd_cli, (void *)buf, len, &skaddr_cli, BOOTS_CLISK_NAME);
+ // write it to BT chip
+ } else if (buf[0] == SCRIPT_RSSI) {
+ temp_rssi_setting = (rssi_set_s *)(&buf[1]);
+ if (temp_rssi_setting->stop)
+ boots_pkt_cleanup_report_rssi(1);
+ else {
+ boots_pkt_cleanup_report_rssi(0);
+ memcpy(&rssi_setting, temp_rssi_setting, sizeof(rssi_set_s));
+ }
+ } else if (!boots_btif_write(btfd, buf, len)) {
+ BPRINT_E("Write data to chip failed, please check controller");
+ btfd = -1;
+ break;
+ }
+ if (boots_stress_enabled)
+ boots_stress_record_timestamp(BOOTS_STRESS_TIMESTAMP_SEND_CMD_FINISH);
+ }
+ }
+ }
+ if (boots_stress_enabled)
+ boots_stress_deinit();
+ if (skfd_cli >= 0) {
+ boots_sk_close(&skfd_cli);
+ }
+ if (skfd_srv >= 0) {
+ boots_sk_close(&skfd_srv);
+ }
+ unlink(BOOTS_SRVSK_NAME);
+ } else if (boots_srv_if.csif == BOOTS_CSIF_UART) {
+ int uartfd = -1;
+
+ uartfd = boots_uart_init(boots_srv_if.cs, uart_speed);
+ if (uartfd < 0) {
+ BPRINT_E("%s: Open serial port:%s failed(%d)", __func__, boots_srv_if.cs, uartfd);
+ goto BTOFF;
+ }
+
+ BPRINT_I("With UART(%s) Relaying...", boots_srv_if.cs);
+ while (cont && btfd >= 0) {
+ FD_ZERO(&readfs);
+ memset(buf, 0, sizeof(buf));
+
+ if (btfd >= 0)
+ FD_SET(btfd, &readfs);
+ if (uartfd >= 0)
+ FD_SET(uartfd, &readfs);
+
+ if (select(MAX(btfd, uartfd) + 1, &readfs, NULL, NULL, NULL) > 0) {
+ // Process the event from BT controller, read
+ if (FD_ISSET(btfd, &readfs)) {
+ len = boots_btif_read(btfd, buf, sizeof(buf));
+ if (len > 0) {
+ boots_uart_write(uartfd, buf, len);
+ boots_pkt_handler(buf, len, NULL);
+ } else if (len < 0) {
+ BPRINT_E("%s: Read data from chip failed", __func__);
+ btfd = -1;
+ break;
+ }
+ }
+ // Process the command from host, write
+ if (FD_ISSET(uartfd, &readfs)) {
+ len = boots_uart_read(uartfd, buf, sizeof(buf));
+ if (len > 0) {
+ if (!boots_btif_write(btfd, buf, len)) {
+ BPRINT_E("%s: Write command to chip failed", __func__);
+ }
+ boots_pkt_handler(buf, len, NULL);
+ }
+ }
+ fsync(btfd);
+ fsync(uartfd);
+ } else {
+ BPRINT_D("%s(%d)", strerror(errno), errno);
+ }
+ }
+ close(uartfd);
+ } else if (boots_srv_if.csif == BOOTS_CSIF_ETH) {
+ int skfd_srv = -1; // Interface file descriptor with host
+ int skfd_cli = -1; // Interface file descriptor with host
+ struct sockaddr_in skaddr_srv;
+ struct sockaddr_in skaddr_cli;
+
+ if (boots_eth_create(&skfd_srv, &skaddr_srv, 0)) {
+ BPRINT_E("%s: Create server socket failed", __func__);
+ goto BTOFF;
+ }
+
+ BPRINT_I("Ethernet relaying...");
+ while (cont && btfd >= 0) {
+ FD_ZERO(&readfs);
+ memset(buf, 0, sizeof(buf));
+
+ if (btfd >= 0)
+ FD_SET(btfd, &readfs);
+ if (skfd_srv >= 0)
+ FD_SET(skfd_srv, &readfs);
+
+ if (select(MAX(btfd, skfd_srv) + 1, &readfs, NULL, NULL, NULL) > 0) {
+ // Process the event from BT controller, read
+ if (FD_ISSET(btfd, &readfs)) {
+ len = boots_btif_read(btfd, buf, sizeof(buf));
+ if (len > 0 && skfd_cli >= 0) {
+ skaddr_cli.sin_family = AF_INET;
+ skaddr_cli.sin_port = ETH_UDP_SRV_PORT;
+ skaddr_cli.sin_addr.s_addr = inet_addr(boots_srv_if.cs);
+ boots_eth_send(skfd_cli, (void *)buf, len, &skaddr_cli);
+ } else if (len > 0) {
+ boots_pkt_handler(buf, len, NULL);
+ } else if (len < 0) {
+ BPRINT_E("%s: Read data from chip failed", __func__);
+ btfd = -1;
+ break;
+ }
+ }
+ // Process the command from host, write
+ if (FD_ISSET(skfd_srv, &readfs)) {
+ // connect socket, server
+ if (skfd_cli == -1 &&
+ boots_eth_create(&skfd_cli, &skaddr_cli, 1)) {
+ BPRINT_E("%s: Connect client socket failed", __func__);
+ boots_eth_close(&skfd_srv);
+ goto BTOFF;
+ }
+ len = boots_eth_recv(skfd_srv, buf, sizeof(buf), 0);
+ if (len < 0) {
+ btfd = -1;
+ break;
+ } else if (len == 4 && buf[0] == 's' && buf[1] == 'e' && buf[2] == 'n' && buf[3] == 'd') {
+ // client socket end
+ boots_eth_close(&skfd_cli);
+ skfd_cli = -1;
+ } else if (buf[0] == 0x01 && buf[1] == 0x01 && buf[2] == 0xFF) {
+ // read/write file
+ boots_file_wr(buf, &len);
+ boots_eth_send(skfd_cli, (void *)buf, len, &skaddr_cli);
+ // write it to BT chip
+ } else if (!boots_btif_write(btfd, buf, len)) {
+ BPRINT_E("%s: Write command to chip failed", __func__);
+ btfd = -1;
+ break;
+ }
+ }
+ }
+ }
+ if (skfd_cli >= 0) {
+ boots_eth_close(&skfd_cli);
+ }
+ if (skfd_srv >= 0) {
+ boots_eth_close(&skfd_srv);
+ }
+ }
+
+BTOFF:
+ boots_btif_close(boots_srv_if.btif);
+ BPRINT_I("Service STOP!");
+ return 0;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_stress.c b/src/connectivity/bt_others/boots/boots_stress.c
new file mode 100644
index 0000000..5ab821c
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_stress.c
@@ -0,0 +1,429 @@
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <stdint.h>
+#include <pthread.h>
+
+#include "boots.h"
+#include "boots_stress.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_stress"
+
+//---------------------------------------------------------------------------
+static pthread_mutex_t boots_stress_thread_lock;
+static int boots_stress_inited;
+static pthread_t boots_stress_thread;
+static uint32_t boots_stress_thread_status;
+static uint32_t boots_stress_thread_should_stop;
+
+static uint32_t boots_stress_timestamp_record_num;
+static uint32_t* boots_stress_timestamp_record_send_cmd_start;
+static uint32_t* boots_stress_timestamp_record_send_cmd_finish;
+static uint32_t* boots_stress_timestamp_record_receive_event_finish;
+static uint32_t boots_stress_timestamp_record_num_analysis;
+static uint32_t* boots_stress_timestamp_record_send_cmd_start_analysis;
+static uint32_t* boots_stress_timestamp_record_send_cmd_finish_analysis;
+static uint32_t* boots_stress_timestamp_record_receive_event_finish_analysis;
+
+static uint32_t boots_stress_timestamp_record_count_0us;
+static uint32_t boots_stress_timestamp_record_count_1us;
+static uint32_t boots_stress_timestamp_record_count_2us;
+static uint32_t boots_stress_timestamp_record_count_3us;
+static uint32_t boots_stress_timestamp_record_count_4us;
+static uint32_t boots_stress_timestamp_record_count_5us;
+static uint32_t boots_stress_timestamp_record_count_6us;
+static uint32_t boots_stress_timestamp_record_count_7us;
+static uint32_t boots_stress_timestamp_record_count_8us;
+static uint32_t boots_stress_timestamp_record_count_9us;
+static uint32_t boots_stress_timestamp_record_count_10us;
+static uint32_t boots_stress_timestamp_record_count_20us;
+static uint32_t boots_stress_timestamp_record_count_30us;
+static uint32_t boots_stress_timestamp_record_count_40us;
+static uint32_t boots_stress_timestamp_record_count_50us;
+static uint32_t boots_stress_timestamp_record_count_60us;
+static uint32_t boots_stress_timestamp_record_count_70us;
+static uint32_t boots_stress_timestamp_record_count_80us;
+static uint32_t boots_stress_timestamp_record_count_90us;
+static uint32_t boots_stress_timestamp_record_count_100us;
+static uint32_t boots_stress_timestamp_record_min;
+static uint32_t boots_stress_timestamp_record_max;
+static uint32_t boots_stress_timestamp_record_average;
+static uint32_t boots_stress_timestamp_record_count_time;
+static uint32_t boots_stress_timestamp_record_count_packet;
+
+//---------------------------------------------------------------------------
+static uint32_t boots_stress_get_timestamp(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ //BPRINT_I("%u", (uint32_t)(tv.tv_usec + tv.tv_sec * 1000000));
+ return (tv.tv_usec + tv.tv_sec * 1000000);
+}
+
+static void boots_stress_mem_init(void)
+{
+ boots_stress_timestamp_record_num = 0;
+ boots_stress_timestamp_record_num_analysis = 0;
+ if (boots_stress_timestamp_record_send_cmd_start == NULL)
+ boots_stress_timestamp_record_send_cmd_start =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ if (boots_stress_timestamp_record_send_cmd_finish == NULL)
+ boots_stress_timestamp_record_send_cmd_finish =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ if (boots_stress_timestamp_record_receive_event_finish == NULL)
+ boots_stress_timestamp_record_receive_event_finish =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ if (boots_stress_timestamp_record_send_cmd_start_analysis == NULL)
+ boots_stress_timestamp_record_send_cmd_start_analysis =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ if (boots_stress_timestamp_record_send_cmd_finish_analysis == NULL)
+ boots_stress_timestamp_record_send_cmd_finish_analysis =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ if (boots_stress_timestamp_record_receive_event_finish_analysis == NULL)
+ boots_stress_timestamp_record_receive_event_finish_analysis =
+ (uint32_t *)calloc(sizeof(uint32_t), BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+
+ if (!boots_stress_timestamp_record_send_cmd_start || !boots_stress_timestamp_record_send_cmd_finish
+ || !boots_stress_timestamp_record_receive_event_finish
+ || !boots_stress_timestamp_record_send_cmd_start_analysis
+ || !boots_stress_timestamp_record_send_cmd_finish_analysis
+ || !boots_stress_timestamp_record_receive_event_finish_analysis) {
+ BPRINT_E("%s allocate memory failed!", __func__);
+ exit(0);
+ }
+
+ boots_stress_timestamp_record_count_0us = 0;
+ boots_stress_timestamp_record_count_1us = 0;
+ boots_stress_timestamp_record_count_2us = 0;
+ boots_stress_timestamp_record_count_3us = 0;
+ boots_stress_timestamp_record_count_4us = 0;
+ boots_stress_timestamp_record_count_5us = 0;
+ boots_stress_timestamp_record_count_6us = 0;
+ boots_stress_timestamp_record_count_7us = 0;
+ boots_stress_timestamp_record_count_8us = 0;
+ boots_stress_timestamp_record_count_9us = 0;
+ boots_stress_timestamp_record_count_10us = 0;
+ boots_stress_timestamp_record_count_20us = 0;
+ boots_stress_timestamp_record_count_30us = 0;
+ boots_stress_timestamp_record_count_40us = 0;
+ boots_stress_timestamp_record_count_50us = 0;
+ boots_stress_timestamp_record_count_60us = 0;
+ boots_stress_timestamp_record_count_70us = 0;
+ boots_stress_timestamp_record_count_80us = 0;
+ boots_stress_timestamp_record_count_90us = 0;
+ boots_stress_timestamp_record_count_100us = 0;
+ boots_stress_timestamp_record_min = 9999999;
+ boots_stress_timestamp_record_max = 0;
+ boots_stress_timestamp_record_average = 0;
+ boots_stress_timestamp_record_count_time = 0;
+ boots_stress_timestamp_record_count_packet = 0;
+}
+
+static void boots_stress_mem_free(void)
+{
+ if (boots_stress_timestamp_record_send_cmd_start == NULL)
+ free(boots_stress_timestamp_record_send_cmd_start);
+ if (boots_stress_timestamp_record_send_cmd_finish == NULL)
+ free(boots_stress_timestamp_record_send_cmd_finish);
+ if (boots_stress_timestamp_record_receive_event_finish == NULL)
+ free(boots_stress_timestamp_record_receive_event_finish);
+ if (boots_stress_timestamp_record_send_cmd_start_analysis == NULL)
+ free(boots_stress_timestamp_record_send_cmd_start_analysis);
+ if (boots_stress_timestamp_record_send_cmd_finish_analysis == NULL)
+ free(boots_stress_timestamp_record_send_cmd_finish_analysis);
+ if (boots_stress_timestamp_record_receive_event_finish_analysis == NULL)
+ free(boots_stress_timestamp_record_receive_event_finish_analysis);
+}
+
+static void boots_stress_mem_copy(void)
+{
+ uint32_t buf_size = sizeof(uint32_t)*BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM;
+
+ if (boots_stress_timestamp_record_send_cmd_start_analysis && boots_stress_timestamp_record_send_cmd_start)
+ memcpy(boots_stress_timestamp_record_send_cmd_start_analysis, boots_stress_timestamp_record_send_cmd_start, buf_size);
+ if (boots_stress_timestamp_record_send_cmd_finish_analysis && boots_stress_timestamp_record_send_cmd_finish)
+ memcpy(boots_stress_timestamp_record_send_cmd_finish_analysis, boots_stress_timestamp_record_send_cmd_finish, buf_size);
+ if (boots_stress_timestamp_record_receive_event_finish_analysis && boots_stress_timestamp_record_receive_event_finish)
+ memcpy(boots_stress_timestamp_record_receive_event_finish_analysis, boots_stress_timestamp_record_receive_event_finish, buf_size);
+ boots_stress_timestamp_record_num_analysis = boots_stress_timestamp_record_num;
+}
+
+static void boots_stress_mem_reset(void)
+{
+ uint32_t buf_size = sizeof(uint32_t) * BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM;
+
+ boots_stress_timestamp_record_num = 0;
+ if (boots_stress_timestamp_record_send_cmd_start)
+ memset(boots_stress_timestamp_record_send_cmd_start, 0, buf_size);
+ if (boots_stress_timestamp_record_send_cmd_finish)
+ memset(boots_stress_timestamp_record_send_cmd_finish, 0, buf_size);
+ if (boots_stress_timestamp_record_receive_event_finish)
+ memset(boots_stress_timestamp_record_receive_event_finish, 0, buf_size);
+}
+
+static void boots_stress_mem_reset_analysis(void)
+{
+ uint32_t buf_size = sizeof(uint32_t) * BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM;
+
+ boots_stress_timestamp_record_num_analysis = 0;
+ if (boots_stress_timestamp_record_send_cmd_start_analysis)
+ memset(boots_stress_timestamp_record_send_cmd_start_analysis, 0, buf_size);
+ if (boots_stress_timestamp_record_send_cmd_finish_analysis)
+ memset(boots_stress_timestamp_record_send_cmd_finish_analysis, 0, buf_size);
+ if (boots_stress_timestamp_record_receive_event_finish_analysis)
+ memset(boots_stress_timestamp_record_receive_event_finish_analysis, 0, buf_size);
+}
+
+static uint32_t boots_stress_mem_analysis(void)
+{
+ uint32_t i;
+ uint32_t min_delta_time = 999999;
+ uint32_t max_delta_time = 0;
+ uint32_t avg_delta_time = 0;
+ uint32_t iteration_delta_time = 0;
+ static uint32_t time_counter = 0;
+
+ if (boots_stress_timestamp_record_num_analysis == 0) {
+ BPRINT_E("%s: Timestamp record num is 0 !", __func__);
+ return 0;
+ }
+ if (boots_stress_timestamp_record_num_analysis >= BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM) {
+ BPRINT_E("%s: Timestamp record num > BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM(%d)",
+ __func__, BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ return 0;
+ }
+
+ if (boots_stress_timestamp_record_num_analysis == 1) {
+ max_delta_time = boots_stress_timestamp_record_receive_event_finish_analysis[0] - boots_stress_timestamp_record_send_cmd_start_analysis[0];
+ BPRINT_I("[%d] Total count = %d (latency = %dus)",
+ time_counter++,
+ boots_stress_timestamp_record_num_analysis,
+ max_delta_time);
+ return 1;
+ }
+
+ // Skip first & latest entry since it's possible that the first or latest entry is not completed in this second.
+ for (i = 1 ; i < boots_stress_timestamp_record_num_analysis - 1 ; i++) {
+ if (boots_stress_timestamp_record_receive_event_finish_analysis[i] - boots_stress_timestamp_record_send_cmd_start_analysis[i] > max_delta_time)
+ max_delta_time = boots_stress_timestamp_record_receive_event_finish_analysis[i] - boots_stress_timestamp_record_send_cmd_start_analysis[i];
+ if (boots_stress_timestamp_record_receive_event_finish_analysis[i] - boots_stress_timestamp_record_send_cmd_start_analysis[i] < min_delta_time)
+ min_delta_time = boots_stress_timestamp_record_receive_event_finish_analysis[i] - boots_stress_timestamp_record_send_cmd_start_analysis[i];
+
+ iteration_delta_time = boots_stress_timestamp_record_receive_event_finish_analysis[i] - boots_stress_timestamp_record_send_cmd_start_analysis[i];
+ avg_delta_time += iteration_delta_time;
+ if (iteration_delta_time < 1000)
+ boots_stress_timestamp_record_count_0us += 1;
+ else if(iteration_delta_time < 2000)
+ boots_stress_timestamp_record_count_1us += 1;
+ else if(iteration_delta_time < 3000)
+ boots_stress_timestamp_record_count_2us += 1;
+ else if(iteration_delta_time < 4000)
+ boots_stress_timestamp_record_count_3us += 1;
+ else if(iteration_delta_time < 5000)
+ boots_stress_timestamp_record_count_4us += 1;
+ else if(iteration_delta_time < 6000)
+ boots_stress_timestamp_record_count_5us += 1;
+ else if(iteration_delta_time < 7000)
+ boots_stress_timestamp_record_count_6us += 1;
+ else if(iteration_delta_time < 8000)
+ boots_stress_timestamp_record_count_7us += 1;
+ else if(iteration_delta_time < 9000)
+ boots_stress_timestamp_record_count_8us += 1;
+ else if(iteration_delta_time < 10000)
+ boots_stress_timestamp_record_count_9us += 1;
+ else if(iteration_delta_time < 20000)
+ boots_stress_timestamp_record_count_10us += 1;
+ else if(iteration_delta_time < 30000)
+ boots_stress_timestamp_record_count_20us += 1;
+ else if(iteration_delta_time < 40000)
+ boots_stress_timestamp_record_count_30us += 1;
+ else if(iteration_delta_time < 50000)
+ boots_stress_timestamp_record_count_40us += 1;
+ else if(iteration_delta_time < 60000)
+ boots_stress_timestamp_record_count_50us += 1;
+ else if(iteration_delta_time < 70000)
+ boots_stress_timestamp_record_count_60us += 1;
+ else if(iteration_delta_time < 80000)
+ boots_stress_timestamp_record_count_70us += 1;
+ else if(iteration_delta_time < 90000)
+ boots_stress_timestamp_record_count_80us += 1;
+ else if(iteration_delta_time < 100000)
+ boots_stress_timestamp_record_count_90us += 1;
+ else
+ boots_stress_timestamp_record_count_100us += 1;
+ }
+ avg_delta_time /= (boots_stress_timestamp_record_num_analysis - 2);
+ BPRINT_I("[%d] Total count = %d (min:max:avg = %dus:%dus:%dus)",
+ time_counter++,
+ boots_stress_timestamp_record_num_analysis - 2,
+ min_delta_time, max_delta_time, avg_delta_time);
+
+ if ( max_delta_time > BOOTS_STRESS_MAX_ALLOWED_LATENCY)
+ {
+ BPRINT_E("!!!!!!!!!!! max_delta_time > %dms, Test Stopped !!!!!!", BOOTS_STRESS_MAX_ALLOWED_LATENCY/1000);
+ boots_stress_thread_should_stop = 1;
+ }
+
+ boots_stress_timestamp_record_count_time++;
+ boots_stress_timestamp_record_count_packet += (boots_stress_timestamp_record_num_analysis - 2);
+ boots_stress_timestamp_record_average += avg_delta_time;
+ if (min_delta_time < boots_stress_timestamp_record_min)
+ boots_stress_timestamp_record_min = min_delta_time;
+ if (max_delta_time > boots_stress_timestamp_record_max)
+ boots_stress_timestamp_record_max = max_delta_time;
+
+ return (boots_stress_timestamp_record_num_analysis - 2);
+}
+
+static void boots_stress_mem_record(uint8_t timestamp_type)
+{
+ if (boots_stress_timestamp_record_num < BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM) {
+ pthread_mutex_lock(&boots_stress_thread_lock);
+ switch (timestamp_type) {
+ case BOOTS_STRESS_TIMESTAMP_SEND_CMD_START:
+ boots_stress_timestamp_record_send_cmd_start[boots_stress_timestamp_record_num] = boots_stress_get_timestamp();
+ break;
+ case BOOTS_STRESS_TIMESTAMP_SEND_CMD_FINISH:
+ boots_stress_timestamp_record_send_cmd_finish[boots_stress_timestamp_record_num] = boots_stress_get_timestamp();
+ break;
+ case BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH:
+ boots_stress_timestamp_record_receive_event_finish[boots_stress_timestamp_record_num] = boots_stress_get_timestamp();
+ boots_stress_timestamp_record_num++;
+ break;
+ default:
+ BPRINT_W("%s: unknow timestamp type! (%d)", __func__, timestamp_type);
+ break;
+ }
+ pthread_mutex_unlock(&boots_stress_thread_lock);
+ } else {
+ BPRINT_W("%s: BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM(%d) should be increased!", __func__, BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM);
+ }
+}
+
+static void *boots_stress_thread_main(void *arg)
+{
+ uint32_t time_begin;
+ uint32_t time_end;
+ uint32_t test_iteration = 0;
+ UNUSED(arg);
+
+ boots_stress_thread_status = BOOTS_STRESS_THREAD_STATE_THREAD_RUNNING;
+ usleep(1000000);
+ while (!boots_stress_thread_should_stop) {
+ time_begin = boots_stress_get_timestamp();
+
+ pthread_mutex_lock(&boots_stress_thread_lock);
+ boots_stress_mem_copy();
+ boots_stress_mem_reset();
+ pthread_mutex_unlock(&boots_stress_thread_lock);
+
+ test_iteration = boots_stress_mem_analysis();
+ if (test_iteration == 0 || test_iteration == 1) {
+ boots_stress_thread_should_stop = 1;
+ break;
+ }
+
+ boots_stress_mem_reset_analysis();
+ time_end = boots_stress_get_timestamp();
+ if ((1000000 - (time_end - time_begin)) > 0)
+ usleep(1000000 - (time_end - time_begin));
+ }
+ boots_stress_thread_should_stop = 0;
+ boots_stress_thread_status = BOOTS_STRESS_THREAD_STATE_THREAD_STOPPED;
+
+ if (boots_stress_timestamp_record_count_packet > 1) {
+ BPRINT_I("Bus Stress Test Result Summary : ");
+ BPRINT_I(" Min Latency : %d us", boots_stress_timestamp_record_min);
+ BPRINT_I(" Max Latency : %d us", boots_stress_timestamp_record_max);
+ BPRINT_I(" Average Latency : %d us", boots_stress_timestamp_record_average / boots_stress_timestamp_record_count_time);
+ BPRINT_I(" Total Time : %d seconds", boots_stress_timestamp_record_count_time);
+ BPRINT_I(" Total Packets : %d", boots_stress_timestamp_record_count_packet);
+ if (boots_stress_timestamp_record_count_0us)
+ BPRINT_I(" 0ms ~ 1ms : %d", boots_stress_timestamp_record_count_0us);
+ if (boots_stress_timestamp_record_count_1us)
+ BPRINT_I(" 1ms ~ 2ms : %d", boots_stress_timestamp_record_count_1us);
+ if (boots_stress_timestamp_record_count_2us)
+ BPRINT_I(" 2ms ~ 3ms : %d", boots_stress_timestamp_record_count_2us);
+ if (boots_stress_timestamp_record_count_3us)
+ BPRINT_I(" 3ms ~ 4ms : %d", boots_stress_timestamp_record_count_3us);
+ if (boots_stress_timestamp_record_count_4us)
+ BPRINT_I(" 4ms ~ 5ms : %d", boots_stress_timestamp_record_count_4us);
+ if (boots_stress_timestamp_record_count_5us)
+ BPRINT_I(" 5ms ~ 6ms : %d", boots_stress_timestamp_record_count_5us);
+ if (boots_stress_timestamp_record_count_6us)
+ BPRINT_I(" 6ms ~ 7ms : %d", boots_stress_timestamp_record_count_6us);
+ if (boots_stress_timestamp_record_count_7us)
+ BPRINT_I(" 7ms ~ 8ms : %d", boots_stress_timestamp_record_count_7us);
+ if (boots_stress_timestamp_record_count_8us)
+ BPRINT_I(" 8ms ~ 9ms : %d", boots_stress_timestamp_record_count_8us);
+ if (boots_stress_timestamp_record_count_9us)
+ BPRINT_I(" 9ms ~10ms : %d", boots_stress_timestamp_record_count_9us);
+ if (boots_stress_timestamp_record_count_10us)
+ BPRINT_I(" 10ms ~20ms : %d", boots_stress_timestamp_record_count_10us);
+ if (boots_stress_timestamp_record_count_20us)
+ BPRINT_I(" 20ms ~30ms : %d", boots_stress_timestamp_record_count_20us);
+ if (boots_stress_timestamp_record_count_30us)
+ BPRINT_I(" 30ms ~40ms : %d", boots_stress_timestamp_record_count_30us);
+ if (boots_stress_timestamp_record_count_40us)
+ BPRINT_I(" 40ms ~50ms : %d", boots_stress_timestamp_record_count_40us);
+ if (boots_stress_timestamp_record_count_50us)
+ BPRINT_I(" 50ms ~60ms : %d", boots_stress_timestamp_record_count_50us);
+ if (boots_stress_timestamp_record_count_60us)
+ BPRINT_I(" 60ms ~70ms : %d", boots_stress_timestamp_record_count_60us);
+ if (boots_stress_timestamp_record_count_70us)
+ BPRINT_I(" 70ms ~80ms : %d", boots_stress_timestamp_record_count_70us);
+ if (boots_stress_timestamp_record_count_80us)
+ BPRINT_I(" 80ms ~90ms : %d", boots_stress_timestamp_record_count_80us);
+ if (boots_stress_timestamp_record_count_90us)
+ BPRINT_I(" 90ms~1000ms: %d", boots_stress_timestamp_record_count_90us);
+ if (boots_stress_timestamp_record_count_100us)
+ BPRINT_I(" > 100 ms : %d", boots_stress_timestamp_record_count_100us);
+ }
+
+#if BOOTS_STRESS_MEASURE_IN_BOOTS
+ BPRINT_I(" Measured Process : boots");
+ system("killall boots_srv > /dev/null");
+#else
+ BPRINT_I(" Measured Process : boots_srv");
+ system("killall boots > /dev/null");
+#endif
+ exit(0);
+ return 0;
+}
+
+void boots_stress_record_timestamp(uint8_t timestamp_type)
+{
+ if (boots_stress_inited == 0)
+ return;
+ boots_stress_mem_record(timestamp_type);
+}
+
+void boots_stress_init(void)
+{
+ UNUSED(boots_btif);
+ if (boots_stress_inited == 0) {
+ pthread_mutex_init(&boots_stress_thread_lock, NULL);
+ boots_stress_mem_init();
+ pthread_create(&boots_stress_thread, NULL, boots_stress_thread_main, NULL);
+ boots_stress_inited = 1;
+ }
+}
+
+void boots_stress_deinit(void)
+{
+ if (boots_stress_inited == 1) {
+ boots_stress_thread_should_stop = 1;
+ pthread_join(boots_stress_thread, NULL);
+ pthread_mutex_lock(&boots_stress_thread_lock);
+ boots_stress_mem_free();
+ pthread_mutex_unlock(&boots_stress_thread_lock);
+ pthread_mutex_destroy(&boots_stress_thread_lock);
+ boots_stress_inited = 0;
+ }
+}
+
diff --git a/src/connectivity/bt_others/boots/boots_stress.h b/src/connectivity/bt_others/boots/boots_stress.h
new file mode 100644
index 0000000..ea3670b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_stress.h
@@ -0,0 +1,40 @@
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_STRESS_H__
+#define __BOOTS_STRESS_H__
+
+// Print all CMD log in console
+#define BOOTS_STRESS_SHOW_ALL_CMD 0
+// Print all EVENT log in console
+#define BOOTS_STRESS_SHOW_ALL_EVENT 0
+// Measure the latency in 1:boots, 0:boots_srv
+#define BOOTS_STRESS_MEASURE_IN_BOOTS 0
+// The latency result includes :
+// 1 : ACL_OUT + EVENT_IN(NOCP) + ACL_IN
+// 0 : ACL_OUT + EVENT_IN(NOCP)
+#define BOOTS_STRESS_MEASURE_LBT_TOTAL_LATENCY 0
+
+// Maximum allowed latency (us)
+#define BOOTS_STRESS_MAX_ALLOWED_LATENCY 50000
+// Maximum records per second
+#define BOOTS_STRESS_TIMESTAMP_RECORD_MAX_NUM 2048
+// Maximum stress test packet size (Max Local Name Size)
+#define BOOTS_STRESS_STRESS_TEST_MAX_PKT_SIZE 248
+// Maximum loopback test packet size (Max ACL Size)
+#define BOOTS_STRESS_LOOPBACK_TEST_MAX_PKT_SIZE 1021
+
+enum{
+ BOOTS_STRESS_THREAD_STATE_UNKNOWN,
+ BOOTS_STRESS_THREAD_STATE_THREAD_RUNNING,
+ BOOTS_STRESS_THREAD_STATE_THREAD_STOPPED,
+};
+
+enum{
+ BOOTS_STRESS_TIMESTAMP_SEND_CMD_START,
+ BOOTS_STRESS_TIMESTAMP_SEND_CMD_FINISH,
+ BOOTS_STRESS_TIMESTAMP_RECEIVE_EVENT_FINISH,
+};
+
+extern void boots_stress_record_timestamp(uint8_t timestamp_type);
+extern void boots_stress_init(void);
+extern void boots_stress_deinit(void);
+#endif // __BOOTS_STRESS_H__
\ No newline at end of file
diff --git a/src/connectivity/bt_others/boots/boots_uart.c b/src/connectivity/bt_others/boots/boots_uart.c
new file mode 100644
index 0000000..ae4742d
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_uart.c
@@ -0,0 +1,473 @@
+/* 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) 2014,2016~2017. 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/time.h>
+#include <sys/select.h>
+
+#include "boots.h"
+#include "boots_osi.h"
+
+//---------------------------------------------------------------------------
+#define LOG_TAG "boots_uart"
+
+#define VCOM_PROP_NAME "sys.usb.config"
+#define VCOM_PROP_VALUE_TTYGS0 "acm"
+#define VCOM_PROP_VALUE_TTYGS2 "acm_third"
+
+#define CHECK_VCOM_DEV "/sys/class/android_usb/android0/enable"
+#ifdef SPECIAL_USB_RELAY
+#define OPEN_VCOM_FOR_TTYGS2 "usb_switch adb,bt"
+#else
+#define OPEN_VCOM_FOR_TTYGS2 \
+ "echo > /sys/class/android_usb/android0/enable 0;" \
+ "sleep 1;" \
+ "echo > /sys/class/android_usb/android0/idVendor 0E8D;" \
+ "echo > /sys/class/android_usb/android0/idProduct 2006;" \
+ "echo > /sys/class/android_usb/android0/f_acm/port_index 3;" \
+ "echo > /sys/class/android_usb/android0/functions mass_storage,adb,acm;" \
+ "sleep 1;" \
+ "echo > /sys/class/android_usb/android0/enable 1"
+#endif
+
+#define CHECK_VCOM_DEV_FOR_NEW_USB_1 "/sys/kernel/config/usb_gadget/g1/UDC"
+#define CHECK_VCOM_DEV_FOR_NEW_USB_2 "/config/usb_gadget/g1/UDC"
+#ifdef UDC_SSUSB //for new USB IP SSUSB
+#define OPEN_VCOM_FOR_TTYGS2_NEW_USB \
+ "echo -n none > /sys/kernel/config/usb_gadget/g1/UDC;" \
+ "rm /sys/kernel/config/usb_gadget/g1/configs/c.1/f*;" \
+ "sleep 1;" \
+ "mount -t configfs none /sys/kernel/config;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1;" \
+ "echo -n 0x0E8D > /sys/kernel/config/usb_gadget/g1/idVendor;" \
+ "echo -n 0x2010 > /sys/kernel/config/usb_gadget/g1/idProduct;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409;" \
+ "echo -n 0123456789ABCDEF > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber;" \
+ "echo -n Mediatek Inc. > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer;" \
+ "echo -n rndis_adb_acm > /sys/kernel/config/usb_gadget/g1/strings/0x409/product;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409;" \
+ "echo -n rndis_adb_acm > /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409/configuration;" \
+ "echo -n 400 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb;" \
+ "mkdir /dev/usb-ffs;" \
+ "chmod 775 /dev/usb-ffs -R;" \
+ "mkdir /dev/usb-ffs/adb;" \
+ "chmod 775 /dev/usb-ffs/adb -R;" \
+ "mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/acm.gs0;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4 /sys/kernel/config/usb_gadget/g1/configs/c.1/f1;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/c.1/f2;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/c.1/f3;" \
+ "sleep 1;" \
+ "echo -n '11201000.usb' > /sys/kernel/config/usb_gadget/g1/UDC;"
+#else //for MUSB
+#define OPEN_VCOM_FOR_TTYGS2_NEW_USB \
+ "echo -n none > /sys/kernel/config/usb_gadget/g1/UDC;" \
+ "rm /sys/kernel/config/usb_gadget/g1/configs/c.1/f*;" \
+ "sleep 1;" \
+ "mount -t configfs none /sys/kernel/config;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1;" \
+ "echo -n 0x0E8D > /sys/kernel/config/usb_gadget/g1/idVendor;" \
+ "echo -n 0x2010 > /sys/kernel/config/usb_gadget/g1/idProduct;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409;" \
+ "echo -n 0123456789ABCDEF > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber;" \
+ "echo -n Mediatek Inc. > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer;" \
+ "echo -n rndis_adb_acm > /sys/kernel/config/usb_gadget/g1/strings/0x409/product;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409;" \
+ "echo -n rndis_adb_acm > /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409/configuration;" \
+ "echo -n 400 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb;" \
+ "mkdir /dev/usb-ffs;" \
+ "chmod 775 /dev/usb-ffs -R;" \
+ "mkdir /dev/usb-ffs/adb;" \
+ "chmod 775 /dev/usb-ffs/adb -R;" \
+ "mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4;" \
+ "mkdir /sys/kernel/config/usb_gadget/g1/functions/acm.gs0;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4 /sys/kernel/config/usb_gadget/g1/configs/c.1/f1;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/c.1/f2;" \
+ "ln -s /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/c.1/f3;" \
+ "sleep 1;" \
+ "echo -n musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC;"
+#endif
+
+//---------------------------------------------------------------------------
+static int boots_uart_speed(int speed)
+{
+ switch (speed) {
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ }
+ return B57600;
+}
+
+//---------------------------------------------------------------------------
+int boots_uart_init(char *dev, int speed)
+{
+ UNUSED(boots_btif);
+ struct termios ti;
+ int fd, retry = 0;
+ int baudenum;
+#ifndef VCOM_OPENED
+ char usb_prop[128];
+ char *prop_value = NULL;
+ bool set_vcom_cmd = false;
+#endif
+
+ memset(&ti, 0x0, sizeof(ti));
+ /* USB VCOM port */
+ if (0 == speed) {
+#ifndef VCOM_OPENED
+ /* Set USB property to acm_third: add 1 acm port to /dev/ttyGS2 */
+ if (!memcmp(dev, "/dev/ttyGS0", strlen("/dev/ttyGS0")))
+ prop_value = VCOM_PROP_VALUE_TTYGS0;
+ else if (!memcmp(dev, "/dev/ttyGS2", strlen("/dev/ttyGS2")))
+ prop_value = VCOM_PROP_VALUE_TTYGS2;
+ else {
+ BPRINT_E("%s do not support VCOM port", dev);
+ return -1;
+ }
+
+ if (osi_property_get(VCOM_PROP_NAME, usb_prop, NULL) < 0) {
+ set_vcom_cmd = true;
+ } else {
+ if (strcmp(usb_prop, prop_value)) {
+ if (osi_property_set(VCOM_PROP_NAME, prop_value) < 0)
+ set_vcom_cmd = true;
+ }
+ }
+
+ if (set_vcom_cmd == true) {
+#ifndef SPECIAL_USB_RELAY
+ if (access(CHECK_VCOM_DEV, F_OK) == 0) {
+#endif
+ if (osi_system(OPEN_VCOM_FOR_TTYGS2) < 0) {
+ BPRINT_E("Open default VCOM failed!");
+ return -1;
+ } else {
+ BPRINT_I("Open default VCOM successfully");
+ }
+#ifndef SPECIAL_USB_RELAY
+ } else {
+ BPRINT_I("Use new usb");
+ }
+
+ if (access(CHECK_VCOM_DEV_FOR_NEW_USB_1, F_OK) == 0 ||
+ access(CHECK_VCOM_DEV_FOR_NEW_USB_2, F_OK) == 0) {
+ if (osi_system(OPEN_VCOM_FOR_TTYGS2_NEW_USB) < 0) {
+ BPRINT_E("Open default VCOM failed!");
+ return -1;
+ } else {
+ BPRINT_I("Open default VCOM successfully");
+ }
+ }
+#endif
+ }
+#endif
+ }
+
+ while(1) {
+ sleep(1);
+ fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK);
+ if (fd >= 0)
+ break;
+ if (retry > 10) {
+ BPRINT_E("Can't open serial port %s", dev);
+ return -1;
+ }
+ retry++;
+ }
+
+ if (0 != speed) {
+ ti.c_cflag |= CLOCAL;
+ ti.c_lflag = 0;
+
+ ti.c_cflag &= ~CRTSCTS;
+ ti.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+ /* Set baudrate */
+ baudenum = boots_uart_speed(speed);
+ if ((baudenum == B57600) && (speed != 57600)) {
+ BPRINT_E("Serial port baudrate not supported!");
+ close(fd);
+ return -1;
+ }
+
+ cfsetospeed(&ti, baudenum);
+ cfsetispeed(&ti, baudenum);
+ }
+
+ tcflush(fd, TCIOFLUSH);
+
+ if (tcgetattr(fd, &ti) < 0) {
+ BPRINT_E("Can't get serial port setting");
+ close(fd);
+ return -1;
+ }
+
+ cfmakeraw(&ti);
+
+ sleep(1);
+
+ if (tcsetattr(fd, TCSANOW, &ti) < 0) {
+ BPRINT_E("Can't set serial port setting");
+ close(fd);
+ return -1;
+ }
+
+ tcflush(fd, TCIOFLUSH);
+
+ return fd;
+}
+
+//---------------------------------------------------------------------------
+static ssize_t uart_read(int fd, uint8_t *buf, size_t len)
+{
+ ssize_t bytesRead = 0;
+ size_t bytesToRead = len;
+ int ret = 0;
+ struct timeval tv;
+ fd_set readfd;
+
+ tv.tv_sec = 1; /* SECOND */
+ tv.tv_usec = 0; /* USECOND */
+ FD_ZERO(&readfd);
+
+ if (fd < 0)
+ return -1;
+
+ /* Try to receive len bytes */
+ while (bytesToRead > 0) {
+ FD_SET(fd, &readfd);
+
+ ret = select(fd + 1, &readfd, NULL, NULL, &tv);
+ if (ret > 0) {
+ bytesRead = read(fd, buf, bytesToRead);
+ if (bytesRead < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ else
+ return -1;
+ } else {
+ bytesToRead -= bytesRead;
+ buf += bytesRead;
+ }
+ } else if (ret == 0) {
+ /* Read com port timeout */
+ return -1;
+ } else if ((ret == -1) && (errno == EINTR)) {
+ continue;
+ } else {
+ return -1;
+ }
+ }
+
+ return (len - bytesToRead);
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_uart_write(int fd, uint8_t const *buf, size_t len)
+{
+ ssize_t ret = 0;
+ size_t bytesToWrite = len;
+
+ if (buf == NULL) {
+ BPRINT_E("%s: buffer is NULL!", __func__);
+ return -EINVAL;
+ } else if (fd < 0) {
+ BPRINT_E("%s: File descriptor in bad state(%d)!", __func__, fd);
+ return -EBADFD;
+ }
+
+ while (bytesToWrite > 0) {
+ ret = write(fd, buf, bytesToWrite);
+ if (ret < 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ else
+ return -errno;
+ }
+ bytesToWrite -= ret;
+ buf += ret;
+ }
+
+ return (len - bytesToWrite);
+}
+
+//---------------------------------------------------------------------------
+ssize_t boots_uart_read(int fd, uint8_t *buf, size_t size)
+{
+ uint8_t ucHeader = 0;
+ size_t u4Len = 0, pkt_len = 0;
+ int count = 0;
+ size_t len = size;
+
+ if (buf == NULL) {
+ BPRINT_E("%s: buffer is NULL", __func__);
+ return -EINVAL;
+ } else if (fd < 0) {
+ BPRINT_E("%s: File descriptor in bad state(%d)!", __func__, fd);
+ return -EBADFD;
+ }
+
+LOOP:
+ if (uart_read(fd, &ucHeader, sizeof(ucHeader)) < 0) {
+ count ++;
+ if (count < 3) {
+ goto LOOP;
+ } else {
+ return -2;
+ }
+ }
+ buf[0] = ucHeader;
+ u4Len++;
+
+ switch (ucHeader) {
+ case 0x01: /* HCI command */
+ if (uart_read(fd, buf + u4Len, 3) < 0) {
+ BPRINT_E("Read command header fails");
+ return -3;
+ }
+ u4Len += 3;
+ pkt_len = (size_t)buf[3];
+ if ((u4Len + pkt_len) > len) {
+ BPRINT_E("Too large packet from UART! packet len %d", (int)(u4Len + pkt_len));
+ return -4;
+ }
+
+ if (uart_read(fd, buf + u4Len, pkt_len) < 0) {
+ BPRINT_E("Read command param fails");
+ return -5;
+ }
+ u4Len += pkt_len;
+ break;
+
+ case 0x02: /* ACL data */
+ if (uart_read(fd, buf + u4Len, 4) < 0) {
+ BPRINT_E("Read ACL header fails");
+ return -6;
+ }
+ u4Len += 4;
+ /* length 2 bytes is little endian */
+ pkt_len = (((size_t)buf[4]) << 8);
+ pkt_len += (size_t)buf[3];
+ if ((u4Len + pkt_len) > len) {
+ BPRINT_E("Too large packet from UART! packet len %d", (int)(u4Len + pkt_len));
+ return -7;
+ }
+
+ if (uart_read(fd, buf + u4Len, pkt_len) < 0) {
+ BPRINT_E("Read ACL data fails");
+ return -8;
+ }
+ u4Len += pkt_len;
+ break;
+
+ case 0x03: /* SCO data */
+ if (uart_read(fd, buf + u4Len, 3) < 0) {
+ BPRINT_E("Read SCO header fails");
+ return -9;
+ }
+ u4Len += 3;
+ pkt_len = (size_t)buf[3];
+ if ((u4Len + pkt_len) > len) {
+ BPRINT_E("Too large packet from UART! packet len %d", (int)(u4Len + pkt_len));
+ return -10;
+ }
+
+ if (uart_read(fd, buf + u4Len, pkt_len) < 0) {
+ BPRINT_E("Read SCO data fails");
+ return -11;
+ }
+ u4Len += pkt_len;
+ break;
+
+ case 0x04: /* Event */
+ if (uart_read(fd, buf + u4Len, 2) < 0) {
+ BPRINT_E("Read Event header fails");
+ return -12;
+ }
+ u4Len += 2;
+ pkt_len = (size_t)buf[2];
+ if ((u4Len + pkt_len) > len) {
+ BPRINT_E("Too large packet from UART! packet len %d", (int)(u4Len + pkt_len));
+ return -13;
+ }
+
+ if (uart_read(fd, buf + u4Len, pkt_len) < 0) {
+ BPRINT_E("Read Event data fails");
+ return -14;
+ }
+ u4Len += pkt_len;
+ break;
+
+ default: /* Filter UART garbage data */
+ BPRINT_E("Invalid packet type %02x from UART", ucHeader);
+ return -15;
+ }
+
+ return u4Len;
+}
+
+//---------------------------------------------------------------------------
diff --git a/src/connectivity/bt_others/boots/boots_uart.h b/src/connectivity/bt_others/boots/boots_uart.h
new file mode 100644
index 0000000..846afea
--- /dev/null
+++ b/src/connectivity/bt_others/boots/boots_uart.h
@@ -0,0 +1,49 @@
+/* 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) 2016~2017. 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.
+ */
+
+//- vim: set ts=4 sts=4 sw=4 et: --------------------------------------------
+#ifndef __BOOTS_UART_H__
+#define __BOOTS_UART_H__
+
+//---------------------------------------------------------------------------
+int boots_uart_init(char *dev, int speed);
+ssize_t boots_uart_write(int fd, uint8_t const *buf, size_t len);
+ssize_t boots_uart_read(int fd, uint8_t *buf, size_t len);
+
+//---------------------------------------------------------------------------
+#endif // __BOOTS_UART_H__
+
diff --git a/src/connectivity/bt_others/boots/build/BUILD.gn b/src/connectivity/bt_others/boots/build/BUILD.gn
new file mode 100644
index 0000000..be49182
--- /dev/null
+++ b/src/connectivity/bt_others/boots/build/BUILD.gn
@@ -0,0 +1,76 @@
+#
+# Copyright (C) 2017 MediaTek, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+declare_args() {
+ boots_socket_path = ""
+ boots_vcom_opened = ""
+ usb_udc_type = ""
+}
+
+#assert(boots_socket_path != "", "boots_socket_path build argument wasn't provided.")
+
+config("default_include_dirs") {
+ include_dirs = [
+ ]
+}
+
+config("linux") {
+ # TODO(keybuk): AndroidConfig.h or equivalent
+
+ cflags = [
+ "-Wall",
+ #"-Werror",
+ "-g",
+ "-O0",
+ "-fpic",
+ "-fdata-sections",
+ "-ffunction-sections",
+ "-fvisibility=hidden",
+ boots_vcom_opened,
+ usb_udc_type,
+ ]
+
+ cflags_c = [ "-std=c99" ]
+
+ cflags_cc = [
+#TODO(jpawlowski): we should use same c++ version as Android, which is c++11,
+# but we use some c++14 features. Uncomment when this get fixed in code.:
+ "-std=c++1y",
+ "-fno-exceptions",
+ ]
+
+ defines = [
+ "_FORTIFY_SOURCE=2",
+ "_GNU_SOURCE",
+ "LOG_NDEBUG=1",
+ "EXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
+ "KERNEL_MISSING_CLOCK_BOOTTIME_ALARM=TRUE",
+
+ # This is a macro to that can be used by source code to detect if the
+ # current build is done by GN or via Android.mk. This is a temporary
+ # workaround until we can remove all Android-specific dependencies.
+
+ "BOOTS_SOCKET_PATH=\"$boots_socket_path/\"",
+ ]
+}
+
+config("pic") {
+ cflags = [ "-fPIC" ]
+}
+
+config("gc") {
+ ldflags = [ "-Wl,--gc-sections" ]
+}
diff --git a/src/connectivity/bt_others/boots/build/config/BUILDCONFIG.gn b/src/connectivity/bt_others/boots/build/config/BUILDCONFIG.gn
new file mode 100644
index 0000000..ce5640b
--- /dev/null
+++ b/src/connectivity/bt_others/boots/build/config/BUILDCONFIG.gn
@@ -0,0 +1,49 @@
+#
+# Copyright (C) 2017 MediaTek, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set_default_toolchain("//build/toolchain/gcc")
+
+set_defaults("executable") {
+ configs = [
+ "//build:linux",
+ "//build:gc",
+ "//build:default_include_dirs",
+ ]
+}
+
+set_defaults("shared_library") {
+ configs = [
+ "//build:linux",
+ "//build:gc",
+ "//build:default_include_dirs",
+ ]
+}
+
+set_defaults("source_set") {
+ configs = [
+ "//build:linux",
+ "//build:gc",
+ "//build:default_include_dirs",
+ ]
+}
+
+set_defaults("static_library") {
+ configs = [
+ "//build:linux",
+ "//build:gc",
+ "//build:default_include_dirs",
+ ]
+}
diff --git a/src/connectivity/bt_others/boots/build/toolchain/gcc/BUILD.gn b/src/connectivity/bt_others/boots/build/toolchain/gcc/BUILD.gn
new file mode 100644
index 0000000..756a2e6
--- /dev/null
+++ b/src/connectivity/bt_others/boots/build/toolchain/gcc/BUILD.gn
@@ -0,0 +1,103 @@
+#
+# Copyright (C) 2017 MediaTek, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+declare_args() {
+ cc = ""
+ cxx = ""
+}
+
+assert(cc != "", "cc build argument wasn't provided.")
+assert(cxx != "", "cxx build argument wasn't provided.")
+
+toolchain("gcc") {
+ tool("cc") {
+ depfile = "{{output}}.d"
+ command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "CC {{output}}"
+ outputs = [
+ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+ ]
+ }
+
+ tool("cxx") {
+ depfile = "{{output}}.d"
+ command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "CXX {{output}}"
+ outputs = [
+ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+ ]
+ }
+
+ tool("alink") {
+ rspfile = "{{output}}.rsp"
+ command = "rm -f {{output}} && ar rcs {{output}} @$rspfile"
+ description = "AR {{target_output_name}}{{output_extension}}"
+ rspfile_content = "{{inputs}}"
+ outputs = [
+ "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
+ ]
+ default_output_extension = ".a"
+
+ output_prefix = "lib"
+ }
+
+ tool("solink") {
+ soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
+ rspfile = soname + ".rsp"
+
+ command =
+ "$cxx -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile"
+ rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
+
+ description = "SOLINK $soname"
+
+ # Use this for {{output_extension}} expansions unless a target manually
+ # overrides it (in which case {{output_extension}} will be what the target
+ # specifies).
+ default_output_extension = ".so"
+
+ outputs = [
+ soname,
+ ]
+ link_output = soname
+ depend_output = soname
+
+ output_prefix = "lib"
+ }
+
+ tool("link") {
+ outfile = "{{target_output_name}}{{output_extension}}"
+ rspfile = "$outfile.rsp"
+ command = "$cxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}"
+ description = "LINK $outfile"
+ rspfile_content = "{{inputs}}"
+ outputs = [
+ outfile,
+ ]
+ }
+
+ tool("stamp") {
+ command = "touch {{output}}"
+ description = "STAMP {{output}}"
+ }
+
+ tool("copy") {
+ command = "cp -af {{source}} {{output}}"
+ description = "COPY {{source}} {{output}}"
+ }
+}
diff --git a/src/connectivity/bt_others/boots/example.sh b/src/connectivity/bt_others/boots/example.sh
new file mode 100644
index 0000000..8d2f772
--- /dev/null
+++ b/src/connectivity/bt_others/boots/example.sh
@@ -0,0 +1,20 @@
+# bt signaling test
+./boots -c dut
+
+# ble signaling test for USB module
+./boots -relay ttyUSB0
+
+# ble signaling test for BT CoB platform
+./boots -relay ttyGS2 &
+ => Run it on platform
+./boots ttyACM0 115200 -relay ttyUSB0 115200
+ => Run it on NB/PC
+
+# bt rf tx test
+./boots -c rft -p xx -c xx -t xx
+
+# bt rf rx test
+./boots -c rfr -p xx -c xx -t xx -a xx:xx:xx:xx:xx:xx
+
+# bt rf rx stop to get result
+./boots -c rfr_stop -p xx -c xx -t xx -a xx:xx:xx:xx:xx:xx
diff --git a/src/connectivity/bt_others/boots/init.boots b/src/connectivity/bt_others/boots/init.boots
new file mode 100644
index 0000000..e516f9d
--- /dev/null
+++ b/src/connectivity/bt_others/boots/init.boots
@@ -0,0 +1,32 @@
+# Default BT initialize commands
+CMD=03 0C 00
+CMD=03 10 00
+CMD=01 10 00
+CMD=09 10 00
+CMD=05 10 00
+CMD=23 0C 00
+CMD=14 0C 00
+CMD=25 0C 00
+CMD=38 0C 00
+CMD=39 0C 00
+CMD=05 0C 01 00
+CMD=16 0C 02 00 7D
+CMD=1B 0C 00
+CMD=46 0C 00
+CMD=02 20 00
+CMD=03 20 00
+CMD=07 20 00
+CMD=0F 20 00
+CMD=1C 20 00
+CMD=01 0C 08 FF FF FB FF 07 F8 BF 3D
+CMD=01 20 08 1F 00 00 00 00 00 00 00
+CMD=02 10 00
+CMD=52 0C F1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+CMD=45 0C 01 02
+CMD=58 0C 00
+CMD=04 10 01 01
+CMD=12 0C 07 00 00 00 00 00 00 01
+CMD=0F 08 02 05 00
+CMD=04 10 01 02
+CMD=63 0C 08 00 C0 30 00 00 00 00 00
+CMD=77 0C 00