summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2012-12-12 16:00:35 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2012-12-12 16:00:35 -0800
commit5738f83aeb59361a0a2eda2460113f6dc9194271 (patch)
treebf9fb1c890a681253207fe5d48e2cd56b94de3a7 /main
downloadexternal_bluetooth_bluedroid-5738f83aeb59361a0a2eda2460113f6dc9194271.zip
external_bluetooth_bluedroid-5738f83aeb59361a0a2eda2460113f6dc9194271.tar.gz
external_bluetooth_bluedroid-5738f83aeb59361a0a2eda2460113f6dc9194271.tar.bz2
Snapshot cdeccf6fdd8c2d494ea2867cb37a025bf8879baf
Change-Id: Ia2de32ccb97a9641462c72363b0a8c4288f4f36d
Diffstat (limited to 'main')
-rw-r--r--main/Android.mk129
-rw-r--r--main/bte_conf.c449
-rw-r--r--main/bte_init.c521
-rw-r--r--main/bte_logmsg.c636
-rw-r--r--main/bte_main.c570
-rw-r--r--main/bte_version.c22
6 files changed, 2327 insertions, 0 deletions
diff --git a/main/Android.mk b/main/Android.mk
new file mode 100644
index 0000000..8ecb3c3
--- /dev/null
+++ b/main/Android.mk
@@ -0,0 +1,129 @@
+LOCAL_PATH:= $(call my-dir)
+
+#
+# Bluetooth HW module
+#
+
+include $(CLEAR_VARS)
+
+# HAL layer
+LOCAL_SRC_FILES:= \
+ ../btif/src/bluetooth.c
+
+# platform specific
+LOCAL_SRC_FILES+= \
+ bte_main.c \
+ bte_init.c \
+ bte_version.c \
+ bte_logmsg.c \
+ bte_conf.c
+
+# BTIF
+LOCAL_SRC_FILES += \
+ ../btif/src/btif_core.c \
+ ../btif/src/btif_dm.c \
+ ../btif/src/btif_storage.c \
+ ../btif/src/btif_util.c \
+ ../btif/src/btif_sm.c \
+ ../btif/src/btif_hf.c \
+ ../btif/src/btif_av.c \
+ ../btif/src/btif_rc.c \
+ ../btif/src/btif_media_task.c \
+ ../btif/src/btif_hh.c \
+ ../btif/src/btif_hl.c \
+ ../btif/src/btif_sock.c \
+ ../btif/src/btif_sock_rfc.c \
+ ../btif/src/btif_sock_thread.c \
+ ../btif/src/btif_sock_sdp.c \
+ ../btif/src/btif_sock_util.c \
+ ../btif/src/btif_pan.c \
+ ../btif/src/btif_config.c \
+ ../btif/src/btif_config_util.cpp \
+ ../btif/src/btif_profile_queue.c
+
+# callouts
+LOCAL_SRC_FILES+= \
+ ../btif/co/bta_sys_co.c \
+ ../btif/co/bta_fs_co.c \
+ ../btif/co/bta_ag_co.c \
+ ../btif/co/bta_dm_co.c \
+ ../btif/co/bta_av_co.c \
+ ../btif/co/bta_hh_co.c \
+ ../btif/co/bta_hl_co.c \
+ ../btif/co/bta_pan_co.c
+
+# sbc encoder
+LOCAL_SRC_FILES+= \
+ ../embdrv/sbc/encoder/srce/sbc_analysis.c \
+ ../embdrv/sbc/encoder/srce/sbc_dct.c \
+ ../embdrv/sbc/encoder/srce/sbc_dct_coeffs.c \
+ ../embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c \
+ ../embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c \
+ ../embdrv/sbc/encoder/srce/sbc_enc_coeffs.c \
+ ../embdrv/sbc/encoder/srce/sbc_encoder.c \
+ ../embdrv/sbc/encoder/srce/sbc_packing.c \
+
+LOCAL_SRC_FILES+= \
+ ../udrv/ulinux/uipc.c
+
+LOCAL_C_INCLUDES+= . \
+ $(LOCAL_PATH)/../bta/include \
+ $(LOCAL_PATH)/../bta/sys \
+ $(LOCAL_PATH)/../bta/dm \
+ $(LOCAL_PATH)/../gki/common \
+ $(LOCAL_PATH)/../gki/ulinux \
+ $(LOCAL_PATH)/../include \
+ $(LOCAL_PATH)/../stack/include \
+ $(LOCAL_PATH)/../stack/l2cap \
+ $(LOCAL_PATH)/../stack/a2dp \
+ $(LOCAL_PATH)/../stack/btm \
+ $(LOCAL_PATH)/../stack/avdt \
+ $(LOCAL_PATH)/../hcis \
+ $(LOCAL_PATH)/../hcis/include \
+ $(LOCAL_PATH)/../hcis/patchram \
+ $(LOCAL_PATH)/../udrv/include \
+ $(LOCAL_PATH)/../btif/include \
+ $(LOCAL_PATH)/../btif/co \
+ $(LOCAL_PATH)/../hci/include\
+ $(LOCAL_PATH)/../brcm/include \
+ $(LOCAL_PATH)/../embdrv/sbc/encoder/include \
+ $(LOCAL_PATH)/../audio_a2dp_hw \
+ $(LOCAL_PATH)/../utils/include \
+ $(bdroid_C_INCLUDES) \
+ external/tinyxml2
+
+LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Werror -Wno-error=maybe-uninitialized -Wno-error=uninitialized
+
+ifeq ($(TARGET_PRODUCT), full_crespo)
+ LOCAL_CFLAGS += -DTARGET_CRESPO
+endif
+ifeq ($(TARGET_PRODUCT), full_crespo4g)
+ LOCAL_CFLAGS += -DTARGET_CRESPO
+endif
+ifeq ($(TARGET_PRODUCT), full_maguro)
+ LOCAL_CFLAGS += -DTARGET_MAGURO
+endif
+
+# Fix this
+#ifeq ($(TARGET_VARIANT), eng)
+# LOCAL_CFLAGS += -O2 # and other production release flags
+#else
+# LOCAL_CFLAGS +=
+#endif
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ libpower \
+ libbt-hci \
+ libbt-utils
+
+#LOCAL_WHOLE_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_stack libbt-brcm_bta
+LOCAL_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_bta libbt-brcm_stack libtinyxml2
+
+LOCAL_MODULE := bluetooth.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_REQUIRED_MODULES := libbt-hci libbt-vendor bt_stack.conf bt_did.conf auto_pair_devlist.conf
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/main/bte_conf.c b/main/bte_conf.c
new file mode 100644
index 0000000..e001d59
--- /dev/null
+++ b/main/bte_conf.c
@@ -0,0 +1,449 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009-2012 Broadcom Corporation
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Filename: bte_conf.c
+ *
+ * Description: Contains functions to conduct run-time module configuration
+ * based on entries present in the .conf file
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bte_conf"
+
+#include <utils/Log.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "bt_target.h"
+#include "bta_api.h"
+
+/******************************************************************************
+** Externs
+******************************************************************************/
+extern BOOLEAN hci_logging_enabled;
+extern char hci_logfile[256];
+extern BOOLEAN trace_conf_enabled;
+void bte_trace_conf(char *p_name, char *p_conf_value);
+int device_name_cfg(char *p_conf_name, char *p_conf_value);
+int device_class_cfg(char *p_conf_name, char *p_conf_value);
+int logging_cfg_onoff(char *p_conf_name, char *p_conf_value);
+int logging_set_filepath(char *p_conf_name, char *p_conf_value);
+int trace_cfg_onoff(char *p_conf_name, char *p_conf_value);
+
+BD_NAME local_device_default_name = BTM_DEF_LOCAL_NAME;
+DEV_CLASS local_device_default_class = {0x40, 0x02, 0x0C};
+
+/******************************************************************************
+** Local type definitions
+******************************************************************************/
+#define CONF_DBG 0
+#define info(format, ...) ALOGI (format, ## __VA_ARGS__)
+#define debug(format, ...) if (CONF_DBG) ALOGD (format, ## __VA_ARGS__)
+#define error(format, ...) ALOGE (format, ## __VA_ARGS__)
+
+#define CONF_KEY_LEN 32
+#define CONF_VALUE_LEN 96
+
+#define CONF_COMMENT '#'
+#define CONF_DELIMITERS " =\n\r\t"
+#define CONF_VALUES_DELIMITERS "\"=\n\r\t"
+#define CONF_COD_DELIMITERS " {,}\t"
+#define CONF_MAX_LINE_LEN 255
+
+typedef int (conf_action_t)(char *p_conf_name, char *p_conf_value);
+
+typedef struct {
+ const char *conf_entry;
+ conf_action_t *p_action;
+} conf_entry_t;
+
+typedef struct {
+ char key[CONF_KEY_LEN];
+ char value[CONF_VALUE_LEN];
+} tKEY_VALUE_PAIRS;
+
+enum {
+ CONF_DID,
+ CONF_DID_RECORD_NUM,
+ CONF_DID_PRIMARY_RECORD,
+ CONF_DID_VENDOR_ID,
+ CONF_DID_VENDOR_ID_SOURCE,
+ CONF_DID_PRODUCT_ID,
+ CONF_DID_VERSION,
+ CONF_DID_CLIENT_EXECUTABLE_URL,
+ CONF_DID_SERVICE_DESCRIPTION,
+ CONF_DID_DOCUMENTATION_URL,
+ CONF_DID_MAX
+};
+typedef UINT8 tCONF_DID;
+/******************************************************************************
+** Static variables
+******************************************************************************/
+
+/*
+ * Current supported entries and corresponding action functions
+ */
+/* TODO: Name and Class are duplicated with NVRAM adapter_info. Need to be sorted out */
+static const conf_entry_t conf_table[] = {
+ /*{"Name", device_name_cfg},
+ {"Class", device_class_cfg},*/
+ {"BtSnoopLogOutput", logging_cfg_onoff},
+ {"BtSnoopFileName", logging_set_filepath},
+ {"TraceConf", trace_cfg_onoff},
+ {(const char *) NULL, NULL}
+};
+
+static tKEY_VALUE_PAIRS did_conf_pairs[CONF_DID_MAX] = {
+ { "[DID]", "" },
+ { "recordNumber", "" },
+ { "primaryRecord", "" },
+ { "vendorId", "" },
+ { "vendorIdSource", "" },
+ { "productId", "" },
+ { "version", "" },
+ { "clientExecutableURL", "" },
+ { "serviceDescription", "" },
+ { "documentationURL", "" },
+};
+/*****************************************************************************
+** FUNCTIONS
+*****************************************************************************/
+
+int device_name_cfg(char *p_conf_name, char *p_conf_value)
+{
+ strcpy((char *)local_device_default_name, p_conf_value);
+ return 0;
+}
+
+int device_class_cfg(char *p_conf_name, char *p_conf_value)
+{
+ char *p_token;
+ unsigned int x;
+
+ p_token = strtok(p_conf_value, CONF_COD_DELIMITERS);
+ sscanf(p_token, "%x", &x);
+ local_device_default_class[0] = (UINT8) x;
+ p_token = strtok(NULL, CONF_COD_DELIMITERS);
+ sscanf(p_token, "%x", &x);
+ local_device_default_class[1] = (UINT8) x;
+ p_token = strtok(NULL, CONF_COD_DELIMITERS);
+ sscanf(p_token, "%x", &x);
+ local_device_default_class[2] = (UINT8) x;
+
+ return 0;
+}
+
+int logging_cfg_onoff(char *p_conf_name, char *p_conf_value)
+{
+ if (strcmp(p_conf_value, "true") == 0)
+ hci_logging_enabled = TRUE;
+ else
+ hci_logging_enabled = FALSE;
+ return 0;
+}
+
+int logging_set_filepath(char *p_conf_name, char *p_conf_value)
+{
+ strcpy(hci_logfile, p_conf_value);
+ return 0;
+}
+
+int trace_cfg_onoff(char *p_conf_name, char *p_conf_value)
+{
+ trace_conf_enabled = (strcmp(p_conf_value, "true") == 0) ? TRUE : FALSE;
+ return 0;
+}
+
+/*****************************************************************************
+** CONF INTERFACE FUNCTIONS
+*****************************************************************************/
+
+/*******************************************************************************
+**
+** Function bte_load_conf
+**
+** Description Read conf entry from p_path file one by one and call
+** the corresponding config function
+**
+** Returns None
+**
+*******************************************************************************/
+void bte_load_conf(const char *p_path)
+{
+ FILE *p_file;
+ char *p_name;
+ char *p_value;
+ conf_entry_t *p_entry;
+ char line[CONF_MAX_LINE_LEN+1]; /* add 1 for \0 char */
+ BOOLEAN name_matched;
+
+ ALOGI("Attempt to load stack conf from %s", p_path);
+
+ if ((p_file = fopen(p_path, "r")) != NULL)
+ {
+ /* read line by line */
+ while (fgets(line, CONF_MAX_LINE_LEN+1, p_file) != NULL)
+ {
+ if (line[0] == CONF_COMMENT)
+ continue;
+
+ p_name = strtok(line, CONF_DELIMITERS);
+
+ if (NULL == p_name)
+ {
+ continue;
+ }
+
+ p_value = strtok(NULL, CONF_VALUES_DELIMITERS);
+
+ if (NULL == p_value)
+ {
+ ALOGW("bte_load_conf: missing value for name: %s", p_name);
+ continue;
+ }
+
+ name_matched = FALSE;
+ p_entry = (conf_entry_t *)conf_table;
+
+ while (p_entry->conf_entry != NULL)
+ {
+ if (strcmp(p_entry->conf_entry, (const char *)p_name) == 0)
+ {
+ name_matched = TRUE;
+ if (p_entry->p_action != NULL)
+ p_entry->p_action(p_name, p_value);
+ break;
+ }
+
+ p_entry++;
+ }
+
+ if ((name_matched == FALSE) && (trace_conf_enabled == TRUE))
+ {
+ /* Check if this is a TRC config item */
+ bte_trace_conf(p_name, p_value);
+ }
+ }
+
+ fclose(p_file);
+ }
+ else
+ {
+ ALOGI( "bte_load_conf file >%s< not found", p_path);
+ }
+}
+
+/*******************************************************************************
+**
+** Function bte_parse_did_conf
+**
+** Description Read conf entry from p_path file one by one and get
+** the corresponding config value
+**
+** Returns TRUE if success, else FALSE
+**
+*******************************************************************************/
+static BOOLEAN bte_parse_did_conf (const char *p_path, UINT32 num,
+ tKEY_VALUE_PAIRS *conf_pairs, UINT32 conf_pairs_num)
+{
+ UINT32 i, param_num=0, count=0, start_count=0, end_count=0, conf_num=0;
+ BOOLEAN key=TRUE, conf_found=FALSE;
+
+ FILE *p_file;
+ char *p;
+ char line[CONF_MAX_LINE_LEN+1]; /* add 1 for \0 char */
+
+ ALOGI("Attempt to load did conf from %s", p_path);
+
+ if ((p_file = fopen(p_path, "r")) != NULL)
+ {
+ /* read line by line */
+ while (fgets(line, CONF_MAX_LINE_LEN+1, p_file) != NULL)
+ {
+ count++;
+ if (line[0] == CONF_COMMENT)
+ continue;
+
+ if (conf_found && (conf_num == num) && (*line == '[')) {
+ conf_found = FALSE;
+ end_count = count-1;
+ break;
+ }
+
+ p = strtok(line, CONF_DELIMITERS);
+ while (p != NULL) {
+ if (conf_num <= num) {
+ if (key) {
+ if (!strcmp(p, conf_pairs[0].key)) {
+ if (++conf_num == num) {
+ conf_found = TRUE;
+ start_count = count;
+ strncpy(conf_pairs[0].value, "1", CONF_VALUE_LEN);
+ }
+ } else {
+ if (conf_num == num) {
+ for (i=1; i<conf_pairs_num; i++) {
+ if (!strcmp(p, conf_pairs[i].key)) {
+ param_num = i;
+ break;
+ }
+ }
+ if (i == conf_pairs_num) {
+ error("Attribute %s does not belong to %s configuration",
+ p, conf_pairs[0].key);
+ fclose(p_file);
+ return FALSE;
+ }
+ }
+ key = FALSE;
+ }
+ } else {
+ if ((conf_num == num) && param_num) {
+ strncpy(conf_pairs[param_num].value, p, CONF_VALUE_LEN-1);
+ param_num = 0;
+ }
+ key = TRUE;
+ }
+ }
+ p = strtok(NULL, CONF_DELIMITERS);
+ }
+ }
+
+ fclose(p_file);
+ }
+ else
+ {
+ ALOGI( "bte_parse_did_conf file >%s< not found", p_path);
+ }
+ if (!end_count)
+ end_count = count;
+
+ if (start_count) {
+ debug("Read %s configuration #%u from lines %u to %u in file %s",
+ conf_pairs[0].key, (unsigned int)num, (unsigned int)start_count,
+ (unsigned int)end_count, p_path);
+ return TRUE;
+ }
+
+ error("%s configuration not found in file %s", conf_pairs[0].key, p_path);
+ return FALSE;
+}
+
+/*******************************************************************************
+**
+** Function bte_load_did_conf
+**
+** Description Set local Device ID records, reading from configuration files
+**
+** Returns None
+**
+*******************************************************************************/
+
+void bte_load_did_conf (const char *p_path)
+{
+ tBTA_DI_RECORD rec;
+ UINT32 rec_num, i, j;
+
+ for (i=1; i<=BTA_DI_NUM_MAX; i++) {
+ for (j=0; j<CONF_DID_MAX; j++) {
+ *did_conf_pairs[j].value = 0;
+ }
+
+ if (bte_parse_did_conf(p_path, i, did_conf_pairs, CONF_DID_MAX)) {
+ memset(&rec, 0, sizeof(rec));
+
+ if (*did_conf_pairs[CONF_DID_RECORD_NUM].value) {
+ rec_num = (UINT32)(strtoul(did_conf_pairs[CONF_DID_RECORD_NUM].value, NULL, 0)-1);
+ } else {
+ debug("[%d] Unknown %s", (unsigned int)i, did_conf_pairs[CONF_DID_RECORD_NUM].key);
+ continue;
+ }
+
+ if (*did_conf_pairs[CONF_DID_VENDOR_ID].value) {
+ rec.vendor = (UINT16)strtoul(did_conf_pairs[CONF_DID_VENDOR_ID].value, NULL, 0);
+ } else {
+ rec.vendor = LMP_COMPID_BROADCOM;
+ }
+
+ if (*did_conf_pairs[CONF_DID_VENDOR_ID_SOURCE].value) {
+ rec.vendor_id_source = (UINT16)strtoul(did_conf_pairs[CONF_DID_VENDOR_ID_SOURCE].value, NULL, 0);
+ } else {
+ rec.vendor_id_source = DI_VENDOR_ID_SOURCE_BTSIG;
+ }
+
+ if ((*did_conf_pairs[CONF_DID].value == 0) ||
+ (rec_num >= BTA_DI_NUM_MAX) ||
+ (!((rec.vendor_id_source >= DI_VENDOR_ID_SOURCE_BTSIG) &&
+ (rec.vendor_id_source <= DI_VENDOR_ID_SOURCE_USBIF))) ||
+ (rec.vendor == DI_VENDOR_ID_DEFAULT)) {
+
+ error("DID record #%u not set", (unsigned int)i);
+ for (j=0; j<CONF_DID_MAX; j++) {
+ error("%s:%s", did_conf_pairs[j].key, did_conf_pairs[j].value);
+ }
+ continue;
+ }
+
+ rec.product = (UINT16)strtoul(did_conf_pairs[CONF_DID_PRODUCT_ID].value, NULL, 0);
+ rec.version = (UINT16)strtoul(did_conf_pairs[CONF_DID_VERSION].value, NULL, 0);
+
+ strncpy(rec.client_executable_url,
+ did_conf_pairs[CONF_DID_CLIENT_EXECUTABLE_URL].value,
+ SDP_MAX_ATTR_LEN);
+ strncpy(rec.service_description,
+ did_conf_pairs[CONF_DID_SERVICE_DESCRIPTION].value,
+ SDP_MAX_ATTR_LEN);
+ strncpy(rec.documentation_url,
+ did_conf_pairs[CONF_DID_DOCUMENTATION_URL].value,
+ SDP_MAX_ATTR_LEN);
+
+ for (j=0; j<strlen(did_conf_pairs[CONF_DID_PRIMARY_RECORD].value); j++) {
+ did_conf_pairs[CONF_DID_PRIMARY_RECORD].value[j] =
+ tolower(did_conf_pairs[CONF_DID_PRIMARY_RECORD].value[j]);
+ }
+ if ((!strcmp(did_conf_pairs[CONF_DID_PRIMARY_RECORD].value, "true")) ||
+ (!strcmp(did_conf_pairs[CONF_DID_PRIMARY_RECORD].value, "1"))) {
+ rec.primary_record = TRUE;
+ } else {
+ rec.primary_record = FALSE;
+ }
+
+ info("[%u] primary_record=%d vendor_id=0x%04X vendor_id_source=0x%04X product_id=0x%04X version=0x%04X",
+ (unsigned int)rec_num+1, rec.primary_record, rec.vendor,
+ rec.vendor_id_source, rec.product, rec.version);
+ if (*rec.client_executable_url) {
+ info(" client_executable_url=%s", rec.client_executable_url);
+ }
+ if (*rec.service_description) {
+ info(" service_description=%s", rec.service_description);
+ }
+ if (*rec.documentation_url) {
+ info(" documentation_url=%s", rec.documentation_url);
+ }
+
+ if (BTA_DmSetLocalDiRecord(&rec, &rec_num) != BTA_SUCCESS) {
+ error("SetLocalDiInfo failed for #%u!", (unsigned int)i);
+ }
+ }
+ }
+}
+
diff --git a/main/bte_init.c b/main/bte_init.c
new file mode 100644
index 0000000..b189281
--- /dev/null
+++ b/main/bte_init.c
@@ -0,0 +1,521 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2000-2012 Broadcom Corporation
+ *
+ * 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 module contains the routines that initialize the stack components.
+ * It must be called before the BTU task is started.
+ *
+ ******************************************************************************/
+
+#include "bt_target.h"
+#include <string.h>
+
+#ifndef BTA_INCLUDED
+#define BTA_INCLUDED FALSE
+#endif
+
+/* Include initialization functions definitions */
+#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
+#include "port_api.h"
+#endif
+
+#if (defined(TCS_INCLUDED) && TCS_INCLUDED == TRUE)
+#include "tcs_api.h"
+#endif
+
+#if (defined(OBX_INCLUDED) && OBX_INCLUDED == TRUE)
+#include "obx_api.h"
+#endif
+
+#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
+#include "bnep_api.h"
+#endif
+
+#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
+#include "gap_api.h"
+#endif
+
+#if ((defined(CTP_INCLUDED) && CTP_INCLUDED == TRUE))
+#include "ctp_api.h"
+#endif
+
+#if ((defined(ICP_INCLUDED) && ICP_INCLUDED == TRUE))
+#include "icp_api.h"
+#endif
+
+#if (defined(SPP_INCLUDED) && SPP_INCLUDED == TRUE)
+#include "spp_api.h"
+#endif
+
+#if (defined(DUN_INCLUDED) && DUN_INCLUDED == TRUE)
+#include "dun_api.h"
+#endif
+
+#if (defined(GOEP_INCLUDED) && GOEP_INCLUDED == TRUE)
+#include "goep_util.h"
+#endif /* GOEP included */
+
+#if (defined(FTP_INCLUDED) && FTP_INCLUDED == TRUE)
+#include "ftp_api.h"
+#endif /* FTP */
+
+#if (defined(OPP_INCLUDED) && OPP_INCLUDED == TRUE)
+#include "opp_api.h"
+#endif /* OPP */
+
+#if (defined(BIP_INCLUDED) && BIP_INCLUDED == TRUE)
+#include "bip_api.h"
+#endif
+
+#if (defined(BTU_BTA_INCLUDED) && BTU_BTA_INCLUDED == TRUE)
+#if (defined(BTA_BI_INCLUDED) && BTA_BI_INCLUDED == TRUE)
+#include "bta_bi_api.h"
+#endif
+#endif
+
+#if (defined(HFP_INCLUDED) && HFP_INCLUDED == TRUE)
+#include "hfp_api.h"
+#endif
+
+#if ((defined(HSP2_INCLUDED) && HSP2_INCLUDED == TRUE)) || \
+ ((defined(HFP_INCLUDED) && HFP_INCLUDED == TRUE))
+#include "hsp2_api.h"
+#endif
+
+#if (defined(HCRP_INCLUDED) && HCRP_INCLUDED == TRUE)
+#if (defined(HCRP_CLIENT_INCLUDED) && HCRP_CLIENT_INCLUDED == TRUE)
+#include "hcrp_api.h"
+#endif
+#if (defined(HCRP_SERVER_INCLUDED) && HCRP_SERVER_INCLUDED == TRUE)
+#include "hcrpm_api.h"
+#endif
+#endif
+
+#if (defined(BPP_INCLUDED) && BPP_INCLUDED == TRUE)
+#include "bpp_api.h"
+#endif
+
+#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
+#include "pan_api.h"
+#endif
+
+#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
+#include "avrc_api.h"
+#endif
+
+#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
+#include "a2d_api.h"
+#endif
+
+
+#if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE)
+#include "hidd_api.h"
+#endif
+
+#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
+#include "hidh_api.h"
+#endif
+
+#if (defined(SAP_SERVER_INCLUDED) && SAP_SERVER_INCLUDED == TRUE)
+#include "sap_api.h"
+#endif /* SAP_SERVER_INCLUDED */
+
+#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
+#include "mca_api.h"
+#endif
+
+#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
+#include "gatt_api.h"
+#if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
+#include "smp_api.h"
+#endif
+#endif
+
+// btla-specific ++
+/***** BTA Modules ******/
+#if BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE
+#include "bta_api.h"
+#include "bta_sys.h"
+
+#if BTA_AC_INCLUDED == TRUE
+#include "bta_acs_int.h"
+#include "bta_acc_int.h"
+#endif
+
+#if BTA_AG_INCLUDED == TRUE
+#include "bta_ag_int.h"
+#endif
+
+#if BTA_HS_INCLUDED == TRUE
+#include "bta_hs_int.h"
+#endif
+
+#include "bta_dm_int.h"
+
+#if BTA_DG_INCLUDED == TRUE
+#include "bta_dg_api.h"
+#include "bta_dg_int.h"
+#endif
+
+#if BTA_FT_INCLUDED == TRUE
+#include "bta_ftc_int.h"
+#include "bta_fts_int.h"
+#endif
+
+#if BTA_PBC_INCLUDED == TRUE
+#include "bta_pbc_int.h"
+#endif
+
+#if BTA_PBS_INCLUDED == TRUE
+#include "bta_pbs_int.h"
+#endif
+
+#if BTA_OP_INCLUDED == TRUE
+#include "bta_opc_int.h"
+#include "bta_ops_int.h"
+#endif
+
+#if BTA_SS_INCLUDED==TRUE
+#include "bta_ss_int.h"
+#endif
+
+#if BTA_CT_INCLUDED==TRUE
+#include "bta_ct_int.h"
+#endif
+
+#if BTA_CG_INCLUDED==TRUE
+#include "bta_cg_int.h"
+#endif
+
+#if BTA_BI_INCLUDED==TRUE
+#include "bta_bic_int.h"
+#include "bta_bis_int.h"
+#endif
+
+#if BTA_PR_INCLUDED==TRUE
+#include "bta_pr_int.h"
+#endif
+
+#if BTA_AR_INCLUDED==TRUE
+#include "bta_ar_int.h"
+#endif
+#if BTA_AV_INCLUDED==TRUE
+#include "bta_av_int.h"
+#endif
+
+#if BTA_SC_INCLUDED==TRUE
+#include "bta_sc_int.h"
+#endif
+
+#if BTA_HD_INCLUDED==TRUE
+#include "bta_hd_int.h"
+#endif
+
+#if BTA_HH_INCLUDED==TRUE
+#include "bta_hh_int.h"
+#endif
+
+#if BTA_FM_INCLUDED==TRUE
+#include "bta_fm_int.h"
+#endif
+
+#if BTA_FMTX_INCLUDED==TRUE
+#include "bta_fmtx_int.h"
+#endif
+
+#if BTA_JV_INCLUDED==TRUE
+#include "bta_jv_int.h"
+tBTA_JV_CB *bta_jv_cb_ptr = NULL;
+#endif
+
+#if BTA_MCE_INCLUDED == TRUE
+#include "bta_mce_int.h"
+#endif
+
+#if BTA_MSE_INCLUDED == TRUE
+#include "bta_mse_int.h"
+#endif
+
+#if BTA_HL_INCLUDED == TRUE
+#include "bta_hl_int.h"
+#endif
+
+#if BTA_GATT_INCLUDED == TRUE
+#include "bta_gattc_int.h"
+#include "bta_gatts_int.h"
+#endif
+
+#if BTA_PAN_INCLUDED==TRUE
+#include "bta_pan_int.h"
+#endif
+
+#include "bta_sys_int.h"
+
+/* control block for patch ram downloading */
+#include "bta_prm_int.h"
+
+#endif /* BTA_INCLUDED */
+// btla-specific --
+
+/*****************************************************************************
+** F U N C T I O N S *
+******************************************************************************/
+
+/*****************************************************************************
+**
+** Function BTE_InitStack
+**
+** Description Initialize control block memory for each component.
+**
+** Note: The core stack components must be called
+** before creating the BTU Task. The rest of the
+** components can be initialized at a later time if desired
+** as long as the component's init function is called
+** before accessing any of its functions.
+**
+** Returns void
+**
+******************************************************************************/
+BT_API void BTE_InitStack(void)
+{
+/* Initialize the optional stack components */
+
+/****************************
+** RFCOMM and its profiles **
+*****************************/
+#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
+ RFCOMM_Init();
+
+#if (defined(SPP_INCLUDED) && SPP_INCLUDED == TRUE)
+ SPP_Init();
+#endif /* SPP */
+
+#if (defined(DUN_INCLUDED) && DUN_INCLUDED == TRUE)
+ DUN_Init();
+#endif /* DUN */
+
+#if (defined(HSP2_INCLUDED) && HSP2_INCLUDED == TRUE)
+ HSP2_Init();
+#endif /* HSP2 */
+
+#if (defined(HFP_INCLUDED) && HFP_INCLUDED == TRUE)
+ HFP_Init();
+#endif /* HFP */
+
+/**************************
+** OBEX and its profiles **
+***************************/
+#if (defined(OBX_INCLUDED) && OBX_INCLUDED == TRUE)
+ OBX_Init();
+#if (defined(BIP_INCLUDED) && BIP_INCLUDED == TRUE)
+ BIP_Init();
+#if (defined(BTU_BTA_INCLUDED) && BTU_BTA_INCLUDED == TRUE)
+#if (defined(BTA_BI_INCLUDED) && BTA_BI_INCLUDED == TRUE)
+ BTA_BicInit();
+#endif /* BTA BI */
+#endif
+#endif /* BIP */
+
+#if (defined(GOEP_INCLUDED) && GOEP_INCLUDED == TRUE)
+ GOEP_Init();
+#endif /* GOEP */
+
+
+#if (defined(FTP_INCLUDED) && FTP_INCLUDED == TRUE)
+ FTP_Init();
+#endif
+#if (defined(OPP_INCLUDED) && OPP_INCLUDED == TRUE)
+ OPP_Init();
+#endif
+
+#if (defined(BPP_INCLUDED) && BPP_INCLUDED == TRUE)
+ BPP_Init();
+#endif /* BPP */
+#endif /* OBX */
+
+
+#endif /* RFCOMM Included */
+
+/*************************
+** TCS and its profiles **
+**************************/
+#if (defined(TCS_INCLUDED) && TCS_INCLUDED == TRUE)
+ TCS_Init();
+
+#if (defined(CTP_INCLUDED) && CTP_INCLUDED == TRUE)
+ CTP_Init();
+#endif /* CTP_INCLUDED */
+
+#if (defined(ICP_INCLUDED) && ICP_INCLUDED == TRUE)
+ ICP_Init();
+#endif /* ICP_INCLUDED */
+
+#endif /* TCS_INCLUDED */
+
+
+/**************************
+** BNEP and its profiles **
+***************************/
+#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
+ BNEP_Init();
+
+#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
+ PAN_Init();
+#endif /* PAN */
+#endif /* BNEP Included */
+
+
+/**************************
+** AVDT and its profiles **
+***************************/
+#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
+ A2D_Init();
+#endif /* AADP */
+
+
+#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
+ AVRC_Init();
+#endif
+
+
+/***********
+** Others **
+************/
+#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
+ GAP_Init();
+#endif /* GAP Included */
+
+#if (defined(HCRP_INCLUDED) && HCRP_INCLUDED == TRUE)
+#if (defined(HCRP_CLIENT_INCLUDED) && HCRP_CLIENT_INCLUDED == TRUE)
+ HCRP_Init();
+#endif
+#if (defined(HCRP_SERVER_INCLUDED) && HCRP_SERVER_INCLUDED == TRUE)
+ HCRPM_Init();
+#endif
+#endif /* HCRP Included */
+
+#if (defined(SAP_SERVER_INCLUDED) && SAP_SERVER_INCLUDED == TRUE)
+ SAP_Init();
+#endif /* SAP_SERVER_INCLUDED */
+
+#if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE)
+ HID_DevInit();
+#endif
+#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
+ HID_HostInit();
+#endif
+
+#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
+ MCA_Init();
+#endif /* SAP_SERVER_INCLUDED */
+
+/****************
+** BTA Modules **
+*****************/
+// btla-specific ++
+#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
+ memset((void*)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
+ memset((void*)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
+ memset((void*)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
+ memset((void*)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
+ memset((void*)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
+
+#if BTA_AC_INCLUDED == TRUE
+ memset((void*)bta_acc_cb_ptr, 0, sizeof(tBTA_ACC_CB));
+ memset((void*)bta_acs_cb_ptr, 0, sizeof(tBTA_ACS_CB));
+#endif
+#if BTA_AG_INCLUDED == TRUE
+ memset((void*)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB));
+#endif
+#if BTA_HS_INCLUDED == TRUE
+ memset((void*)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
+#endif
+#if BTA_DG_INCLUDED == TRUE
+ memset((void*)bta_dg_cb_ptr, 0, sizeof(tBTA_DG_CB));
+#endif
+#if BTA_FT_INCLUDED==TRUE
+ memset((void*)bta_ftc_cb_ptr, 0, sizeof(tBTA_FTC_CB));
+ memset((void*)bta_fts_cb_ptr, 0, sizeof(tBTA_FTS_CB));
+#endif
+#if BTA_PBC_INCLUDED==TRUE
+ memset((void*)bta_pbc_cb_ptr, 0, sizeof(tBTA_PBC_CB));
+#endif
+#if BTA_PBS_INCLUDED==TRUE
+ memset((void*)bta_pbs_cb_ptr, 0, sizeof(tBTA_PBS_CB));
+#endif
+#if BTA_OP_INCLUDED==TRUE
+ memset((void*)bta_opc_cb_ptr, 0, sizeof(tBTA_OPC_CB));
+ memset((void*)bta_ops_cb_ptr, 0, sizeof(tBTA_OPS_CB));
+#endif
+#if BTA_SS_INCLUDED==TRUE
+ memset((void*)bta_ss_cb_ptr, 0, sizeof(tBTA_SS_CB));
+#endif
+#if BTA_CT_INCLUDED==TRUE
+ memset((void*)bta_ct_cb_ptr, 0, sizeof(tBTA_CT_CB));
+#endif
+#if BTA_CG_INCLUDED==TRUE
+ memset((void*)bta_cg_cb_ptr, 0, sizeof(tBTA_CG_CB));
+#endif
+#if BTA_BI_INCLUDED==TRUE
+ memset((void *)bta_bic_cb_ptr, 0, sizeof(tBTA_BIC_CB));
+ memset((void *)bta_bis_cb_ptr, 0, sizeof(tBTA_BIS_CB));
+#endif
+#if BTA_AR_INCLUDED==TRUE
+ memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
+#endif
+#if BTA_AV_INCLUDED==TRUE
+ memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
+#endif
+#if BTA_PR_INCLUDED==TRUE
+ memset((void *)bta_pr_cb_ptr, 0, sizeof(tBTA_PR_CB));
+#endif
+#if BTA_SC_INCLUDED==TRUE
+ memset((void *)bta_sc_cb_ptr, 0, sizeof(tBTA_SC_CB));
+#endif
+#if BTA_HD_INCLUDED==TRUE
+ memset((void *)bta_hd_cb_ptr, 0, sizeof(tBTA_HD_CB));
+#endif
+#if BTA_HH_INCLUDED==TRUE
+ memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
+#endif
+#if BTA_FM_INCLUDED==TRUE
+ memset((void *)bta_fm_cb_ptr, 0, sizeof(tBTA_FM_CB));
+#endif
+#if BTA_FMTX_INCLUDED==TRUE
+ memset((void *)bta_fmtx_cb_ptr, 0, sizeof(tBTA_FMTX_CB));
+#endif
+#if 0
+#if BTA_JV_INCLUDED==TRUE
+ memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));
+#endif
+#endif
+#if BTA_HL_INCLUDED==TRUE
+ memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
+#endif
+#if BTA_GATT_INCLUDED==TRUE
+ memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
+ memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
+#endif
+#if BTA_PAN_INCLUDED==TRUE
+ memset((void *)bta_pan_cb_ptr, 0, sizeof(tBTA_PAN_CB));
+#endif
+
+#endif /* BTA_INCLUDED == TRUE */
+// btla-specific --
+}
diff --git a/main/bte_logmsg.c b/main/bte_logmsg.c
new file mode 100644
index 0000000..52502ae
--- /dev/null
+++ b/main/bte_logmsg.c
@@ -0,0 +1,636 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2001-2012 Broadcom Corporation
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Contains the LogMsg wrapper routines for BTE. It routes calls the
+ * appropriate application's LogMsg equivalent.
+ *
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "gki.h"
+#include "bte.h"
+
+#include "bte_appl.h"
+
+#if MMI_INCLUDED == TRUE
+#include "mmi.h"
+#endif
+
+/* always enable trace framework */
+
+#include "btu.h"
+#include "l2c_api.h"
+#if (RFCOMM_INCLUDED==TRUE)
+#include "port_api.h"
+#endif
+#if (OBX_INCLUDED==TRUE)
+#include "obx_api.h"
+#endif
+#if (AVCT_INCLUDED==TRUE)
+#include "avct_api.h"
+#endif
+#if (AVDT_INCLUDED==TRUE)
+#include "avdt_api.h"
+#endif
+#if (AVRC_INCLUDED==TRUE)
+#include "avrc_api.h"
+#endif
+#if (AVDT_INCLUDED==TRUE)
+#include "avdt_api.h"
+#endif
+#if (A2D_INCLUDED==TRUE)
+#include "a2d_api.h"
+#endif
+#if (BIP_INCLUDED==TRUE)
+#include "bip_api.h"
+#endif
+#if (BNEP_INCLUDED==TRUE)
+#include "bnep_api.h"
+#endif
+#if (BPP_INCLUDED==TRUE)
+#include "bpp_api.h"
+#endif
+#include "btm_api.h"
+#if (DUN_INCLUDED==TRUE)
+#include "dun_api.h"
+#endif
+#if (GAP_INCLUDED==TRUE)
+#include "gap_api.h"
+#endif
+#if (GOEP_INCLUDED==TRUE)
+#include "goep_util.h"
+#endif
+#if (HCRP_INCLUDED==TRUE)
+#include "hcrp_api.h"
+#endif
+#if (PAN_INCLUDED==TRUE)
+#include "pan_api.h"
+#endif
+#include "sdp_api.h"
+
+#if (BLE_INCLUDED==TRUE)
+#include "gatt_api.h"
+#endif
+
+ /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
+#if (BTA_INCLUDED==TRUE)
+#include "bta_api.h"
+#endif
+
+
+#if defined(__CYGWIN__) || defined(__linux__)
+#undef RPC_INCLUDED
+#define RPC_INCLUDED TRUE
+
+#include <sys/time.h>
+#include <time.h>
+
+#if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
+const char * const bt_layer_tags[] = {
+ "bt-btif",
+ "bt-usb",
+ "bt-serial",
+ "bt-socket",
+ "bt-rs232",
+ "bt-lc",
+ "bt-lm",
+ "bt-hci",
+ "bt-l2cap",
+ "bt-rfcomm",
+ "bt-sdp",
+ "bt-tcs",
+ "bt-obex",
+ "bt-btm",
+ "bt-gap",
+ "bt-dun",
+ "bt-goep",
+ "bt-icp",
+ "bt-hsp2",
+ "bt-spp",
+ "bt-ctp",
+ "bt-bpp",
+ "bt-hcrp",
+ "bt-ftp",
+ "bt-opp",
+ "bt-btu",
+ "bt-gki",
+ "bt-bnep",
+ "bt-pan",
+ "bt-hfp",
+ "bt-hid",
+ "bt-bip",
+ "bt-avp",
+ "bt-a2d",
+ "bt-sap",
+ "bt-amp",
+ "bt-mca",
+ "bt-att",
+ "bt-smp",
+ "bt-nfc",
+ "bt-nci",
+ "bt-idep",
+ "bt-ndep",
+ "bt-llcp",
+ "bt-rw",
+ "bt-ce",
+ "bt-snep",
+ "bt-ndef",
+ "bt-nfa",
+};
+
+#ifndef LINUX_NATIVE
+#include <cutils/log.h>
+#define LOGI0(t,s) __android_log_write(ANDROID_LOG_INFO, t, s)
+#define LOGD0(t,s) __android_log_write(ANDROID_LOG_DEBUG, t, s)
+#define LOGW0(t,s) __android_log_write(ANDROID_LOG_WARN, t, s)
+#define LOGE0(t,s) __android_log_write(ANDROID_LOG_ERROR, t, s)
+
+#else
+#undef ANDROID_USE_LOGCAT
+#endif
+
+#endif
+
+
+//#include "btl_cfg.h"
+#define BTL_GLOBAL_PROP_TRC_FLAG "TRC_BTAPP"
+#ifndef DEFAULT_CONF_TRACE_LEVEL
+#define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
+#endif
+
+#ifndef BTE_LOG_BUF_SIZE
+#define BTE_LOG_BUF_SIZE 1024
+#endif
+#define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
+
+
+//#define BTE_MAP_TRACE_LEVEL FALSE
+/* map by default BTE trace levels onto android trace levels */
+#ifndef BTE_MAP_TRACE_LEVEL
+#define BTE_MAP_TRACE_LEVEL TRUE
+#endif
+
+// #define BTE_ANDROID_INTERNAL_TIMESTAMP TRUE
+/* by default no internal timestamp. adb logcate -v time allows having timestamps */
+#ifndef BTE_ANDROID_INTERNAL_TIMESTAMP
+#define BTE_ANDROID_INTERNAL_TIMESTAMP FALSE
+#endif
+#if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
+#define MSG_BUFFER_OFFSET strlen(buffer)
+#else
+#define MSG_BUFFER_OFFSET 0
+#endif
+
+//#define DBG_TRACE
+
+#if defined( DBG_TRACE )
+#define DBG_TRACE_API0( m ) BT_TRACE_0( TRACE_LAYER_HCI, TRACE_TYPE_API, m )
+#define DBG_TRACE_WARNING2( m, p0, p1 ) BT_TRACE_2( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_WARNING), m, p0, p1 )
+#else
+#define DBG_TRACE_API0( m )
+#define DBG_TRACE_WARNING2( m, p0, p1 )
+#endif
+#define DBG_TRACE_DEBUG2( m, p0, p1 ) BT_TRACE_2( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_DEBUG), m, p0, p1 )
+
+void
+LogMsg(UINT32 trace_set_mask, const char *fmt_str, ...)
+{
+ static char buffer[BTE_LOG_BUF_SIZE];
+ int trace_layer = TRACE_GET_LAYER(trace_set_mask);
+ if (trace_layer >= TRACE_LAYER_MAX_NUM)
+ trace_layer = 0;
+
+ va_list ap;
+#if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
+ struct timeval tv;
+ struct timezone tz;
+ struct tm *tm;
+ time_t t;
+
+ gettimeofday(&tv, &tz);
+ time(&t);
+ tm = localtime(&t);
+
+ sprintf(buffer, "%02d:%02d:%02d.%03d ", tm->tm_hour, tm->tm_min, tm->tm_sec,
+ tv.tv_usec / 1000);
+#endif
+ va_start(ap, fmt_str);
+ vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
+ va_end(ap);
+
+#if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
+#if (BTE_MAP_TRACE_LEVEL==TRUE)
+ switch ( TRACE_GET_TYPE(trace_set_mask) )
+ {
+ case TRACE_TYPE_ERROR:
+ LOGE0(bt_layer_tags[trace_layer], buffer);
+ break;
+ case TRACE_TYPE_WARNING:
+ LOGW0(bt_layer_tags[trace_layer], buffer);
+ break;
+ case TRACE_TYPE_API:
+ case TRACE_TYPE_EVENT:
+ LOGI0(bt_layer_tags[trace_layer], buffer);
+ break;
+ case TRACE_TYPE_DEBUG:
+ LOGD0(bt_layer_tags[trace_layer], buffer);
+ break;
+ default:
+ LOGE0(bt_layer_tags[trace_layer], buffer); /* we should never get this */
+ break;
+ }
+#else
+ LOGI0(bt_layer_tags[trace_layer], buffer);
+#endif
+#else
+ write(2, buffer, strlen(buffer));
+ write(2, "\n", 1);
+#endif
+}
+
+void
+ScrLog(UINT32 trace_set_mask, const char *fmt_str, ...)
+{
+ static char buffer[BTE_LOG_BUF_SIZE];
+
+ va_list ap;
+ struct timeval tv;
+ struct timezone tz;
+ struct tm *tm;
+ time_t t;
+ int trace_layer = TRACE_GET_LAYER(trace_set_mask);
+ if (trace_layer >= TRACE_LAYER_MAX_NUM)
+ trace_layer = 0;
+
+ gettimeofday(&tv, &tz);
+ time(&t);
+ tm = localtime(&t);
+
+ sprintf(buffer, "%02d:%02d:%02d.%03ld ", tm->tm_hour, tm->tm_min, tm->tm_sec,
+ tv.tv_usec / 1000);
+
+ va_start(ap, fmt_str);
+ vsnprintf(&buffer[strlen(buffer)], BTE_LOG_MAX_SIZE, fmt_str, ap);
+ va_end(ap);
+
+#if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
+ LOGI0(bt_layer_tags[trace_layer], buffer);
+#else
+ write(2, buffer, strlen(buffer));
+ write(2, "\n", 1);
+#endif
+}
+
+/* this function should go into BTAPP_DM for example */
+BT_API UINT8 BTAPP_SetTraceLevel( UINT8 new_level )
+{
+ if (new_level != 0xFF)
+ appl_trace_level = new_level;
+
+ return (appl_trace_level);
+}
+
+BTU_API UINT8 BTU_SetTraceLevel( UINT8 new_level )
+{
+ if (new_level != 0xFF)
+ btu_cb.trace_level = new_level;
+
+ return (btu_cb.trace_level);
+}
+
+BOOLEAN trace_conf_enabled = FALSE;
+
+void bte_trace_conf(char *p_conf_name, char *p_conf_value)
+{
+ tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
+
+ while (p_f_map->trc_name != NULL)
+ {
+ if (strcmp(p_f_map->trc_name, (const char *)p_conf_name) == 0)
+ {
+ p_f_map->trace_level = (UINT8) atoi(p_conf_value);
+ break;
+ }
+ p_f_map++;
+ }
+}
+
+/********************************************************************************
+ **
+ ** Function Name: BTA_SysSetTraceLevel
+ **
+ ** Purpose: set or reads the different Trace Levels of layer IDs (see bt_trace.h,
+ ** BTTRC_ID_xxxx
+ **
+ ** Input Parameters: Array with trace layers to set to a given level or read. a layer ID of 0
+ ** defines the end of the list
+ ** WARNING: currently type should be 0-5! or FF for reading!!!!
+ **
+ ** Returns:
+ ** input array with trace levels for given layer id
+ **
+ *********************************************************************************/
+BT_API tBTTRC_LEVEL * BTA_SysSetTraceLevel(tBTTRC_LEVEL * p_levels)
+{
+ const tBTTRC_FUNC_MAP *p_f_map;
+ tBTTRC_LEVEL *p_l = p_levels;
+
+ DBG_TRACE_API0( "BTA_SysSetTraceLevel()" );
+
+ while (0 != p_l->layer_id)
+ {
+ p_f_map = &bttrc_set_level_map[0];
+
+ while (0 != p_f_map->layer_id_start)
+ {
+ printf("BTA_SysSetTraceLevel - trace id in map start = %d end= %d, paramter id = %d\r\n", p_f_map->layer_id_start, p_f_map->layer_id_end, p_l->layer_id );
+ /* as p_f_map is ordered by increasing layer id, go to next map entry as long end id
+ * is smaller */
+ //if (p_f_map->layer_id_end < p_l->layer_id)
+ //{
+ //p_f_map++;
+ //}
+ //else
+ {
+ /* check if layer_id actually false into a range or if it is note existing in the map */
+ if ((NULL != p_f_map->p_f) && (p_f_map->layer_id_start <= p_l->layer_id) && (p_f_map->layer_id_end >= p_l->layer_id) )
+ {
+ DBG_TRACE_DEBUG2( "BTA_SysSetTraceLevel( id:%d, level:%d ): setting/reading",
+ p_l->layer_id, p_l->type );
+ p_l->type = p_f_map->p_f(p_l->type);
+ break;
+ }
+ else
+ {
+ DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): MISSING Set function OR ID in map!",
+ p_l->layer_id, p_l->type );
+ }
+ /* set/read next trace level by getting out ot map loop */
+ //p_l++;
+ //break;
+ }
+ p_f_map++;
+ }
+ //if (0 == p_f_map->layer_id_start)
+ {
+ DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): ID NOT FOUND in map. Skip to next",
+ p_l->layer_id, p_l->type );
+ p_l++;
+ }
+ }
+
+ return p_levels;
+} /* BTA_SysSetTraceLevel() */
+
+/* make sure list is order by increasing layer id!!! */
+tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
+ {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL},
+ {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL},
+#if (RFCOMM_INCLUDED==TRUE)
+ {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (OBX_INCLUDED==TRUE)
+ {BTTRC_ID_STK_OBEX, BTTRC_ID_STK_OBEX, OBX_SetTraceLevel, "TRC_OBEX", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (AVCT_INCLUDED==TRUE)
+ //{BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, NULL, "TRC_AVCT", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (AVDT_INCLUDED==TRUE)
+ {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (AVRC_INCLUDED==TRUE)
+ {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (AVDT_INCLUDED==TRUE)
+ //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (A2D_INCLUDED==TRUE)
+ {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (BIP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_BIP, BTTRC_ID_STK_BIP, BIP_SetTraceLevel, "TRC_BIP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (BNEP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (BPP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_BPP, BTTRC_ID_STK_BPP, BPP_SetTraceLevel, "TRC_BPP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+ {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL},
+#if (DUN_INCLUDED==TRUE)
+ {BTTRC_ID_STK_DUN, BTTRC_ID_STK_DUN, DUN_SetTraceLevel, "TRC_DUN", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (GAP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (GOEP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_GOEP, BTTRC_ID_STK_GOEP, GOEP_SetTraceLevel, "TRC_GOEP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (HCRP_INCLUDED==TRUE)
+ {BTTRC_ID_STK_HCRP, BTTRC_ID_STK_HCRP, HCRP_SetTraceLevel, "TRC_HCRP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (PAN_INCLUDED==TRUE)
+ {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (SAP_SERVER_INCLUDED==TRUE)
+ {BTTRC_ID_STK_SAP, BTTRC_ID_STK_SAP, NULL, "TRC_SAP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+ {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL},
+#if (BLE_INCLUDED==TRUE)
+ {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+#if (BLE_INCLUDED==TRUE)
+ {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL},
+#endif
+
+#if (BTA_INCLUDED==TRUE)
+ /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
+ * BTL_GLOBAL_PROP_TRC_FLAG serves as flag in conf.
+ */
+ {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, BTL_GLOBAL_PROP_TRC_FLAG, DEFAULT_CONF_TRACE_LEVEL},
+#endif
+
+ {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
+};
+
+const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
+#endif
+
+/********************************************************************************
+ **
+ ** Function Name: BTE_InitTraceLevels
+ **
+ ** Purpose: This function can be used to set the boot time reading it from the
+ ** platform.
+ ** WARNING: it is called under BTU context and it blocks the BTU task
+ ** till it returns (sync call)
+ **
+ ** Input Parameters: None, platform to provide levels
+ ** Returns:
+ ** Newly set levels, if any!
+ **
+ *********************************************************************************/
+BT_API void BTE_InitTraceLevels( void )
+{
+ /* read and set trace levels by calling the different XXX_SetTraceLevel().
+ */
+#if ( BT_USE_TRACES==TRUE )
+ if (trace_conf_enabled == TRUE)
+ {
+ tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
+
+ while (p_f_map->trc_name != NULL)
+ {
+ ALOGI("BTE_InitTraceLevels -- %s", p_f_map->trc_name);
+
+ if (p_f_map->p_f)
+ p_f_map->p_f(p_f_map->trace_level);
+
+ p_f_map++;
+ }
+ }
+ else
+ {
+ ALOGI("[bttrc] using compile default trace settings");
+ }
+#endif
+}
+
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_0
+ **
+ ** Purpose: Encodes a trace message that has no parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_0(UINT32 trace_set_mask, const char *fmt_str) {
+ LogMsg(trace_set_mask, fmt_str);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_1
+ **
+ ** Purpose: Encodes a trace message that has one parameter argument
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_1(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1) {
+
+ LogMsg(trace_set_mask, fmt_str, p1);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_2
+ **
+ ** Purpose: Encodes a trace message that has two parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_2(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2) {
+ LogMsg(trace_set_mask, fmt_str, p1, p2);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_3
+ **
+ ** Purpose: Encodes a trace message that has three parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_3(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2,
+ UINT32 p3) {
+ LogMsg(trace_set_mask, fmt_str, p1, p2, p3);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_4
+ **
+ ** Purpose: Encodes a trace message that has four parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_4(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2,
+ UINT32 p3, UINT32 p4) {
+ LogMsg(trace_set_mask, fmt_str, p1, p2, p3, p4);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_5
+ **
+ ** Purpose: Encodes a trace message that has five parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_5(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2,
+ UINT32 p3, UINT32 p4, UINT32 p5) {
+ LogMsg(trace_set_mask, fmt_str, p1, p2, p3, p4, p5);
+}
+
+/********************************************************************************
+ **
+ ** Function Name: LogMsg_6
+ **
+ ** Purpose: Encodes a trace message that has six parameter arguments
+ **
+ ** Input Parameters: trace_set_mask: tester trace type.
+ ** fmt_str: displayable string.
+ ** Returns:
+ ** Nothing.
+ **
+ *********************************************************************************/
+void LogMsg_6(UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2,
+ UINT32 p3, UINT32 p4, UINT32 p5, UINT32 p6) {
+ LogMsg(trace_set_mask, fmt_str, p1, p2, p3, p4, p5, p6);
+}
diff --git a/main/bte_main.c b/main/bte_main.c
new file mode 100644
index 0000000..4e7e37c
--- /dev/null
+++ b/main/bte_main.c
@@ -0,0 +1,570 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009-2012 Broadcom Corporation
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Filename: bte_main.c
+ *
+ * Description: Contains BTE core stack initialization and shutdown code
+ *
+ ******************************************************************************/
+#include <fcntl.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "gki.h"
+#include "bd.h"
+#include "btu.h"
+#include "bte.h"
+#include "bta_api.h"
+#include "bt_hci_lib.h"
+
+/*******************************************************************************
+** Constants & Macros
+*******************************************************************************/
+
+/* Run-time configuration file */
+#ifndef BTE_STACK_CONF_FILE
+#define BTE_STACK_CONF_FILE "/etc/bluetooth/bt_stack.conf"
+#endif
+
+/* if not specified in .txt file then use this as default */
+#ifndef HCI_LOGGING_FILENAME
+#define HCI_LOGGING_FILENAME "/data/misc/bluedroid/btsnoop_hci.log"
+#endif
+
+/*******************************************************************************
+** Local type definitions
+*******************************************************************************/
+
+/******************************************************************************
+** Variables
+******************************************************************************/
+BOOLEAN hci_logging_enabled = FALSE; /* by default, turn hci log off */
+char hci_logfile[256] = HCI_LOGGING_FILENAME;
+
+
+/*******************************************************************************
+** Static variables
+*******************************************************************************/
+static bt_hc_interface_t *bt_hc_if=NULL;
+static const bt_hc_callbacks_t hc_callbacks;
+static BOOLEAN lpm_enabled = FALSE;
+
+/*******************************************************************************
+** Static functions
+*******************************************************************************/
+static void bte_main_in_hw_init(void);
+
+/*******************************************************************************
+** Externs
+*******************************************************************************/
+BTU_API extern UINT32 btu_task (UINT32 param);
+BTU_API extern void BTE_Init (void);
+BT_API extern void BTE_LoadStack(void);
+BT_API void BTE_UnloadStack(void);
+extern void scru_flip_bda (BD_ADDR dst, const BD_ADDR src);
+extern void bte_load_conf(const char *p_path);
+
+
+/*******************************************************************************
+** System Task Configuration
+*******************************************************************************/
+
+/* bluetooth protocol stack (BTU) task */
+#ifndef BTE_BTU_STACK_SIZE
+#define BTE_BTU_STACK_SIZE 0//0x2000 /* In bytes */
+#endif
+#define BTE_BTU_TASK_STR ((INT8 *) "BTU")
+UINT32 bte_btu_stack[(BTE_BTU_STACK_SIZE + 3) / 4];
+
+/******************************************************************************
+**
+** Function bte_main_in_hw_init
+**
+** Description Internal helper function for chip hardware init
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_in_hw_init(void)
+{
+ if ( (bt_hc_if = (bt_hc_interface_t *) bt_hc_get_interface()) \
+ == NULL)
+ {
+ APPL_TRACE_ERROR0("!!! Failed to get BtHostControllerInterface !!!");
+ }
+}
+
+/******************************************************************************
+**
+** Function bte_main_boot_entry
+**
+** Description BTE MAIN API - Entry point for BTE chip/stack initialization
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_boot_entry(void)
+{
+ /* initialize OS */
+ GKI_init();
+
+ bte_main_in_hw_init();
+
+ bte_load_conf(BTE_STACK_CONF_FILE);
+
+#if (BTTRC_INCLUDED == TRUE)
+ /* Initialize trace feature */
+ BTTRC_TraceInit(MAX_TRACE_RAM_SIZE, &BTE_TraceLogBuf[0], BTTRC_METHOD_RAM);
+#endif
+}
+
+/******************************************************************************
+**
+** Function bte_main_shutdown
+**
+** Description BTE MAIN API - Shutdown code for BTE chip/stack
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_shutdown()
+{
+ GKI_shutdown();
+}
+
+/******************************************************************************
+**
+** Function bte_main_enable
+**
+** Description BTE MAIN API - Creates all the BTE tasks. Should be called
+** part of the Bluetooth stack enable sequence
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_enable(uint8_t *local_addr)
+{
+ APPL_TRACE_DEBUG1("%s", __FUNCTION__);
+
+ /* Initialize BTE control block */
+ BTE_Init();
+
+ lpm_enabled = FALSE;
+
+ if (bt_hc_if)
+ {
+ int result = bt_hc_if->init(&hc_callbacks, local_addr);
+ APPL_TRACE_EVENT1("libbt-hci init returns %d", result);
+
+ assert(result == BT_HC_STATUS_SUCCESS);
+
+ if (hci_logging_enabled == TRUE)
+ bt_hc_if->logging(BT_HC_LOGGING_ON, hci_logfile);
+
+#if (defined (BT_CLEAN_TURN_ON_DISABLED) && BT_CLEAN_TURN_ON_DISABLED == TRUE)
+ APPL_TRACE_DEBUG1("%s Not Turninig Off the BT before Turninig ON", __FUNCTION__);
+
+ /* Do not power off the chip before powering on if BT_CLEAN_TURN_ON_DISABLED flag
+ is defined and set to TRUE to avoid below mentioned issue.
+
+ Wingray kernel driver maintains a combined counter to keep track of
+ BT-Wifi state. Invoking set_power(BT_HC_CHIP_PWR_OFF) when the BT is already
+ in OFF state causes this counter to be incorrectly decremented and results in undesired
+ behavior of the chip.
+
+ This is only a workaround and when the issue is fixed in the kernel this work around
+ should be removed. */
+#else
+ /* toggle chip power to ensure we will reset chip in case
+ a previous stack shutdown wasn't completed gracefully */
+ bt_hc_if->set_power(BT_HC_CHIP_PWR_OFF);
+#endif
+ bt_hc_if->set_power(BT_HC_CHIP_PWR_ON);
+
+ bt_hc_if->preload(NULL);
+ }
+
+ GKI_create_task((TASKPTR)btu_task, BTU_TASK, BTE_BTU_TASK_STR,
+ (UINT16 *) ((UINT8 *)bte_btu_stack + BTE_BTU_STACK_SIZE),
+ sizeof(bte_btu_stack));
+
+ GKI_run(0);
+}
+
+/******************************************************************************
+**
+** Function bte_main_disable
+**
+** Description BTE MAIN API - Destroys all the BTE tasks. Should be called
+** part of the Bluetooth stack disable sequence
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_disable(void)
+{
+ APPL_TRACE_DEBUG1("%s", __FUNCTION__);
+
+ if (bt_hc_if)
+ {
+ bt_hc_if->cleanup();
+ bt_hc_if->set_power(BT_HC_CHIP_PWR_OFF);
+ }
+
+ GKI_destroy_task(BTU_TASK);
+
+ GKI_freeze();
+}
+
+/******************************************************************************
+**
+** Function bte_main_postload_cfg
+**
+** Description BTE MAIN API - Stack postload configuration
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_postload_cfg(void)
+{
+ if (bt_hc_if)
+ bt_hc_if->postload(NULL);
+}
+
+#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
+/******************************************************************************
+**
+** Function bte_main_enable_lpm
+**
+** Description BTE MAIN API - Enable/Disable low power mode operation
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_enable_lpm(BOOLEAN enable)
+{
+ int result = -1;
+
+ if (bt_hc_if)
+ result = bt_hc_if->lpm( \
+ (enable == TRUE) ? BT_HC_LPM_ENABLE : BT_HC_LPM_DISABLE \
+ );
+
+ APPL_TRACE_EVENT2("HC lib lpm enable=%d return %d", enable, result);
+}
+
+/******************************************************************************
+**
+** Function bte_main_lpm_allow_bt_device_sleep
+**
+** Description BTE MAIN API - Allow BT controller goest to sleep
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_lpm_allow_bt_device_sleep()
+{
+ int result = -1;
+
+ if ((bt_hc_if) && (lpm_enabled == TRUE))
+ result = bt_hc_if->lpm(BT_HC_LPM_WAKE_DEASSERT);
+
+ APPL_TRACE_DEBUG1("HC lib lpm deassertion return %d", result);
+}
+
+/******************************************************************************
+**
+** Function bte_main_lpm_wake_bt_device
+**
+** Description BTE MAIN API - Wake BT controller up if it is in sleep mode
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_lpm_wake_bt_device()
+{
+ int result = -1;
+
+ if ((bt_hc_if) && (lpm_enabled == TRUE))
+ result = bt_hc_if->lpm(BT_HC_LPM_WAKE_ASSERT);
+
+ APPL_TRACE_DEBUG1("HC lib lpm assertion return %d", result);
+}
+#endif // HCILP_INCLUDED
+
+/******************************************************************************
+**
+** Function bte_main_hci_send
+**
+** Description BTE MAIN API - This function is called by the upper stack to
+** send an HCI message. The function displays a protocol trace
+** message (if enabled), and then calls the 'transmit' function
+** associated with the currently selected HCI transport
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_hci_send (BT_HDR *p_msg, UINT16 event)
+{
+ UINT16 sub_event = event & BT_SUB_EVT_MASK; /* local controller ID */
+
+ p_msg->event = event;
+
+
+ if((sub_event == LOCAL_BR_EDR_CONTROLLER_ID) || \
+ (sub_event == LOCAL_BLE_CONTROLLER_ID))
+ {
+ if (bt_hc_if)
+ bt_hc_if->transmit_buf((TRANSAC)p_msg, \
+ (char *) (p_msg + 1), \
+ p_msg->len);
+ else
+ GKI_freebuf(p_msg);
+ }
+ else
+ {
+ APPL_TRACE_ERROR0("Invalid Controller ID. Discarding message.");
+ GKI_freebuf(p_msg);
+ }
+}
+
+/******************************************************************************
+**
+** Function bte_main_post_reset_init
+**
+** Description BTE MAIN API - This function is mapped to BTM_APP_DEV_INIT
+** and shall be automatically called from BTE after HCI_Reset
+**
+** Returns None
+**
+******************************************************************************/
+void bte_main_post_reset_init()
+{
+ BTM_ContinueReset();
+}
+
+/*****************************************************************************
+**
+** libbt-hci Callback Functions
+**
+*****************************************************************************/
+
+/******************************************************************************
+**
+** Function preload_cb
+**
+** Description HOST/CONTROLLER LIB CALLBACK API - This function is called
+** when the libbt-hci completed stack preload process
+**
+** Returns None
+**
+******************************************************************************/
+static void preload_cb(TRANSAC transac, bt_hc_preload_result_t result)
+{
+ APPL_TRACE_EVENT1("HC preload_cb %d [0:SUCCESS 1:FAIL]", result);
+
+ /* notify BTU task that libbt-hci is ready */
+ /* even if PRELOAD process failed */
+ GKI_send_event(BTU_TASK, TASK_MBOX_0_EVT_MASK);
+}
+
+/******************************************************************************
+**
+** Function postload_cb
+**
+** Description HOST/CONTROLLER LIB CALLBACK API - This function is called
+** when the libbt-hci lib completed stack postload process
+**
+** Returns None
+**
+******************************************************************************/
+static void postload_cb(TRANSAC transac, bt_hc_postload_result_t result)
+{
+ APPL_TRACE_EVENT1("HC postload_cb %d", result);
+}
+
+/******************************************************************************
+**
+** Function lpm_cb
+**
+** Description HOST/CONTROLLER LIB CALLBACK API - This function is called
+** back from the libbt-hci to indicate the current LPM state
+**
+** Returns None
+**
+******************************************************************************/
+static void lpm_cb(bt_hc_lpm_request_result_t result)
+{
+ APPL_TRACE_EVENT1("HC lpm_result_cb %d", result);
+ lpm_enabled = (result == BT_HC_LPM_ENABLED) ? TRUE : FALSE;
+}
+
+/******************************************************************************
+**
+** Function hostwake_ind
+**
+** Description HOST/CONTROLLER LIB CALLOUT API - This function is called
+** from the libbt-hci to indicate the HostWake event
+**
+** Returns None
+**
+******************************************************************************/
+static void hostwake_ind(bt_hc_low_power_event_t event)
+{
+ APPL_TRACE_EVENT1("HC hostwake_ind %d", event);
+}
+
+/******************************************************************************
+**
+** Function alloc
+**
+** Description HOST/CONTROLLER LIB CALLOUT API - This function is called
+** from the libbt-hci to request for data buffer allocation
+**
+** Returns NULL / pointer to allocated buffer
+**
+******************************************************************************/
+static char *alloc(int size)
+{
+ BT_HDR *p_hdr = NULL;
+
+ /*
+ APPL_TRACE_DEBUG1("HC alloc size=%d", size);
+ */
+
+ p_hdr = (BT_HDR *) GKI_getbuf ((UINT16) size);
+
+ if (p_hdr == NULL)
+ {
+ APPL_TRACE_WARNING0("alloc returns NO BUFFER!");
+ }
+
+ return ((char *) p_hdr);
+}
+
+/******************************************************************************
+**
+** Function dealloc
+**
+** Description HOST/CONTROLLER LIB CALLOUT API - This function is called
+** from the libbt-hci to release the data buffer allocated
+** through the alloc call earlier
+**
+** Bluedroid libbt-hci library uses 'transac' parameter to
+** pass data-path buffer/packet across bt_hci_lib interface
+** boundary. The 'p_buf' is not intended to be used here
+** but might point to data portion of data-path buffer.
+**
+** Returns bt_hc_status_t
+**
+******************************************************************************/
+static int dealloc(TRANSAC transac, char *p_buf)
+{
+ GKI_freebuf(transac);
+ return BT_HC_STATUS_SUCCESS;
+}
+
+/******************************************************************************
+**
+** Function data_ind
+**
+** Description HOST/CONTROLLER LIB CALLOUT API - This function is called
+** from the libbt-hci to pass in the received HCI packets
+**
+** The core stack is responsible for releasing the data buffer
+** passed in from the libbt-hci once the core stack has done
+** with it.
+**
+** Bluedroid libbt-hci library uses 'transac' parameter to
+** pass data-path buffer/packet across bt_hci_lib interface
+** boundary. The 'p_buf' and 'len' parameters are not intended
+** to be used here but might point to data portion in data-
+** path buffer and length of valid data respectively.
+**
+** Returns bt_hc_status_t
+**
+******************************************************************************/
+static int data_ind(TRANSAC transac, char *p_buf, int len)
+{
+ BT_HDR *p_msg = (BT_HDR *) transac;
+
+ /*
+ APPL_TRACE_DEBUG2("HC data_ind event=0x%04X (len=%d)", p_msg->event, len);
+ */
+
+ GKI_send_msg (BTU_TASK, BTU_HCI_RCV_MBOX, transac);
+ return BT_HC_STATUS_SUCCESS;
+}
+
+/******************************************************************************
+**
+** Function tx_result
+**
+** Description HOST/CONTROLLER LIB CALLBACK API - This function is called
+** from the libbt-hci once it has processed/sent the prior data
+** buffer which core stack passed to it through transmit_buf
+** call earlier.
+**
+** The core stack is responsible for releasing the data buffer
+** if it has been completedly processed.
+**
+** Bluedroid libbt-hci library uses 'transac' parameter to
+** pass data-path buffer/packet across bt_hci_lib interface
+** boundary. The 'p_buf' is not intended to be used here
+** but might point to data portion in data-path buffer.
+**
+** Returns bt_hc_status_t
+**
+******************************************************************************/
+static int tx_result(TRANSAC transac, char *p_buf, \
+ bt_hc_transmit_result_t result)
+{
+ /*
+ APPL_TRACE_DEBUG2("HC tx_result %d (event=%04X)", result, \
+ ((BT_HDR *)transac)->event);
+ */
+
+ if (result == BT_HC_TX_FRAGMENT)
+ {
+ GKI_send_msg (BTU_TASK, BTU_HCI_RCV_MBOX, transac);
+ }
+ else
+ {
+ GKI_freebuf(transac);
+ }
+
+ return BT_HC_STATUS_SUCCESS;
+}
+
+/*****************************************************************************
+** The libbt-hci Callback Functions Table
+*****************************************************************************/
+static const bt_hc_callbacks_t hc_callbacks = {
+ sizeof(bt_hc_callbacks_t),
+ preload_cb,
+ postload_cb,
+ lpm_cb,
+ hostwake_ind,
+ alloc,
+ dealloc,
+ data_ind,
+ tx_result
+};
+
diff --git a/main/bte_version.c b/main/bte_version.c
new file mode 100644
index 0000000..0751e1d
--- /dev/null
+++ b/main/bte_version.c
@@ -0,0 +1,22 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2001-2012 Broadcom Corporation
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+#include "bt_types.h"
+
+const UINT8 bte_version_string[] = "BCM1200_PI_10.3.20.33";
+