diff options
author | Etan Cohen <etancohen@google.com> | 2015-03-31 10:41:53 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2015-03-31 10:41:53 -0700 |
commit | e1a9e52ff59d36bd1bb5b7b3a02fafba6394edfe (patch) | |
tree | 0a82ebb8b0be6acf27f7cbf38a44c9f70425e141 /main | |
parent | dd05445e57161ac40ae8b37252ae9f453bb31e85 (diff) | |
parent | f7f839985b3931682363d2ef3b7c5cae55a842ee (diff) | |
download | android_system_bt-e1a9e52ff59d36bd1bb5b7b3a02fafba6394edfe.tar.gz android_system_bt-e1a9e52ff59d36bd1bb5b7b3a02fafba6394edfe.tar.bz2 android_system_bt-e1a9e52ff59d36bd1bb5b7b3a02fafba6394edfe.zip |
Merge commit 'f7f839985b3931682363d2ef3b7c5cae55a842ee' into merge
Change-Id: Iaaec1ea0bf3009b7e32a9a60f697631a3f56e889
Diffstat (limited to 'main')
-rw-r--r-- | main/Android.mk | 139 | ||||
-rw-r--r-- | main/bte_conf.c | 65 | ||||
-rw-r--r-- | main/bte_init.c | 316 | ||||
-rw-r--r-- | main/bte_logmsg.c | 598 | ||||
-rwxr-xr-x | main/bte_main.c | 704 | ||||
-rw-r--r-- | main/stack_config.c | 99 |
6 files changed, 418 insertions, 1503 deletions
diff --git a/main/Android.mk b/main/Android.mk index 3357b8e16..631204b07 100644 --- a/main/Android.mk +++ b/main/Android.mk @@ -1,4 +1,4 @@ -LOCAL_PATH := $(call my-dir) +LOCAL_PATH:= $(call my-dir) # # Bluetooth HW module @@ -11,58 +11,59 @@ LOCAL_SRC_FILES:= \ ../btif/src/bluetooth.c # platform specific -LOCAL_SRC_FILES += \ - bte_conf.c \ +LOCAL_SRC_FILES+= \ + bte_main.c \ bte_init.c \ bte_logmsg.c \ - bte_main.c + bte_conf.c \ + stack_config.c # BTIF LOCAL_SRC_FILES += \ - ../btif/src/btif_av.c \ - ../btif/src/btif_config.c \ - ../btif/src/btif_config_util.cpp \ - ../btif/src/btif_core.c \ - ../btif/src/btif_dm.c \ - ../btif/src/btif_gatt.c \ - ../btif/src/btif_gatt_client.c \ - ../btif/src/btif_gatt_multi_adv_util.c \ - ../btif/src/btif_gatt_server.c \ - ../btif/src/btif_gatt_test.c \ - ../btif/src/btif_gatt_util.c \ - ../btif/src/btif_hf.c \ - ../btif/src/btif_hf_client.c \ - ../btif/src/btif_hh.c \ - ../btif/src/btif_hl.c \ - ../btif/src/btif_mce.c \ - ../btif/src/btif_media_task.c \ - ../btif/src/btif_pan.c \ - ../btif/src/btif_profile_queue.c \ - ../btif/src/btif_rc.c \ - ../btif/src/btif_sm.c \ - ../btif/src/btif_sock.c \ - ../btif/src/btif_sock_rfc.c \ - ../btif/src/btif_sock_sdp.c \ - ../btif/src/btif_sock_thread.c \ - ../btif/src/btif_sock_util.c \ - ../btif/src/btif_storage.c \ - ../btif/src/btif_util.c + ../btif/src/btif_av.c \ + ../btif/src/btif_config.c \ + ../btif/src/btif_config_transcode.cpp \ + ../btif/src/btif_core.c \ + ../btif/src/btif_dm.c \ + ../btif/src/btif_gatt.c \ + ../btif/src/btif_gatt_client.c \ + ../btif/src/btif_gatt_multi_adv_util.c \ + ../btif/src/btif_gatt_server.c \ + ../btif/src/btif_gatt_test.c \ + ../btif/src/btif_gatt_util.c \ + ../btif/src/btif_hf.c \ + ../btif/src/btif_hf_client.c \ + ../btif/src/btif_hh.c \ + ../btif/src/btif_hl.c \ + ../btif/src/btif_mce.c \ + ../btif/src/btif_media_task.c \ + ../btif/src/btif_pan.c \ + ../btif/src/btif_profile_queue.c \ + ../btif/src/btif_rc.c \ + ../btif/src/btif_sm.c \ + ../btif/src/btif_sock.c \ + ../btif/src/btif_sock_rfc.c \ + ../btif/src/btif_sock_sco.c \ + ../btif/src/btif_sock_sdp.c \ + ../btif/src/btif_sock_thread.c \ + ../btif/src/btif_sock_util.c \ + ../btif/src/btif_storage.c \ + ../btif/src/btif_util.c \ + ../btif/src/stack_manager.c # callouts -LOCAL_SRC_FILES += \ - ../btif/co/bta_ag_co.c \ - ../btif/co/bta_av_co.c \ - ../btif/co/bta_dm_co.c \ - ../btif/co/bta_fs_co.c \ - ../btif/co/bta_gattc_co.c \ - ../btif/co/bta_gatts_co.c \ - ../btif/co/bta_hh_co.c \ - ../btif/co/bta_hl_co.c \ - ../btif/co/bta_pan_co.c \ - ../btif/co/bta_sys_co.c +LOCAL_SRC_FILES+= \ + ../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 \ + ../btif/co/bta_gattc_co.c \ + ../btif/co/bta_gatts_co.c \ # sbc encoder -LOCAL_SRC_FILES += \ +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 \ @@ -72,13 +73,15 @@ LOCAL_SRC_FILES += \ ../embdrv/sbc/encoder/srce/sbc_encoder.c \ ../embdrv/sbc/encoder/srce/sbc_packing.c \ -LOCAL_SRC_FILES += \ +LOCAL_SRC_FILES+= \ ../udrv/ulinux/uipc.c -LOCAL_C_INCLUDES += . \ +LOCAL_C_INCLUDES+= . \ + $(LOCAL_PATH)/../ \ $(LOCAL_PATH)/../bta/include \ $(LOCAL_PATH)/../bta/sys \ $(LOCAL_PATH)/../bta/dm \ + $(LOCAL_PATH)/../btcore/include \ $(LOCAL_PATH)/../osi/include \ $(LOCAL_PATH)/../gki/common \ $(LOCAL_PATH)/../gki/ulinux \ @@ -96,6 +99,7 @@ LOCAL_C_INCLUDES += . \ $(LOCAL_PATH)/../btif/co \ $(LOCAL_PATH)/../hci/include\ $(LOCAL_PATH)/../vnd/include \ + $(LOCAL_PATH)/../brcm/include \ $(LOCAL_PATH)/../embdrv/sbc/encoder/include \ $(LOCAL_PATH)/../embdrv/sbc/decoder/include \ $(LOCAL_PATH)/../audio_a2dp_hw \ @@ -107,41 +111,44 @@ LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Wno-error=maybe-uninitialized -Wno- LOCAL_CONLYFLAGS := -std=c99 ifeq ($(TARGET_PRODUCT), full_crespo) - LOCAL_CFLAGS += -DTARGET_CRESPO + LOCAL_CFLAGS += -DTARGET_CRESPO endif ifeq ($(TARGET_PRODUCT), full_crespo4g) - LOCAL_CFLAGS += -DTARGET_CRESPO + LOCAL_CFLAGS += -DTARGET_CRESPO endif ifeq ($(TARGET_PRODUCT), full_maguro) - LOCAL_CFLAGS += -DTARGET_MAGURO + LOCAL_CFLAGS += -DTARGET_MAGURO endif LOCAL_SHARED_LIBRARIES := \ - libcutils \ - libdl \ - liblog \ - libpower + libcutils \ + libdl \ + liblog \ + libpower \ LOCAL_STATIC_LIBRARIES := \ - libbt-brcm_bta \ - libbt-brcm_gki \ - libbt-brcm_stack \ - libbt-hci \ - libbt-utils \ - libbt-qcom_sbc_decoder \ - libosi \ - libtinyxml2 \ - libbt-qcom_sbc_decoder + libbt-brcm_bta \ + libbt-brcm_gki \ + libbt-brcm_stack \ + libbtdevice \ + libbt-hci \ + libbt-utils \ + libbtcore \ + libosi \ + libtinyxml2 \ + libbt-qcom_sbc_decoder LOCAL_MODULE := bluetooth.default LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := SHARED_LIBRARIES LOCAL_REQUIRED_MODULES := \ - auto_pair_devlist.conf \ - bt_did.conf \ - bt_stack.conf \ - libbt-vendor + auto_pair_devlist.conf \ + bt_did.conf \ + bt_stack.conf \ + libbt-hci \ + libbt-vendor + LOCAL_MULTILIB := 32 LOCAL_CLANG_CFLAGS := -Wno-error=gnu-variable-sized-type-not-at-end diff --git a/main/bte_conf.c b/main/bte_conf.c index 63ace862a..75738e1cd 100644 --- a/main/bte_conf.c +++ b/main/bte_conf.c @@ -16,44 +16,15 @@ * ******************************************************************************/ -#define LOG_TAG "bte_conf" +#define LOG_TAG "bt_bte_conf" #include <assert.h> #include <stdio.h> #include <string.h> -#include <utils/Log.h> #include "bta_api.h" -#include "config.h" - -// TODO: eliminate these global variables. -extern char hci_logfile[256]; -extern BOOLEAN hci_logging_enabled; -extern BOOLEAN hci_save_log; -extern BOOLEAN trace_conf_enabled; -void bte_trace_conf_config(const config_t *config); - -// Reads the stack configuration file and populates global variables with -// the contents of the file. -void bte_load_conf(const char *path) { - assert(path != NULL); - - ALOGI("%s attempt to load stack conf from %s", __func__, path); - - config_t *config = config_new(path); - if (!config) { - ALOGI("%s file >%s< not found", __func__, path); - return; - } - - strlcpy(hci_logfile, config_get_string(config, CONFIG_DEFAULT_SECTION, "BtSnoopFileName", ""), sizeof(hci_logfile)); - hci_logging_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopLogOutput", false); - hci_save_log = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopSaveLog", false); - trace_conf_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "TraceConf", false); - - bte_trace_conf_config(config); - config_free(config); -} +#include "osi/include/config.h" +#include "osi/include/log.h" #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) extern int btm_ble_tx_power[BTM_BLE_ADV_TX_POWER_MAX + 1]; @@ -61,11 +32,11 @@ void bte_load_ble_conf(const char* path) { assert(path != NULL); - ALOGI("%s attempt to load ble stack conf from %s", __func__, path); + LOG_INFO("%s attempt to load ble stack conf from %s", __func__, path); config_t *config = config_new(path); if (!config) { - ALOGI("%s file >%s< not found", __func__, path); + LOG_INFO("%s file >%s< not found", __func__, path); return; } @@ -73,7 +44,7 @@ void bte_load_ble_conf(const char* path) if(*ble_adv_tx_power) { sscanf(ble_adv_tx_power, "%d,%d,%d,%d,%d", btm_ble_tx_power, btm_ble_tx_power + 1, btm_ble_tx_power + 2, btm_ble_tx_power + 3, btm_ble_tx_power + 4); - ALOGI("loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], + LOG_INFO("loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], btm_ble_tx_power[2], btm_ble_tx_power[3], btm_ble_tx_power[4]); } config_free(config); @@ -87,7 +58,7 @@ void bte_load_did_conf(const char *p_path) { config_t *config = config_new(p_path); if (!config) { - ALOGE("%s unable to load DID config '%s'.", __func__, p_path); + LOG_ERROR("%s unable to load DID config '%s'.", __func__, p_path); return; } @@ -96,7 +67,7 @@ void bte_load_did_conf(const char *p_path) { snprintf(section_name, sizeof(section_name), "DID%d", i); if (!config_has_section(config, section_name)) { - ALOGD("%s no section named %s.", __func__, section_name); + LOG_DEBUG("%s no section named %s.", __func__, section_name); break; } @@ -112,23 +83,23 @@ void bte_load_did_conf(const char *p_path) { if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { - ALOGE("%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); + LOG_ERROR("%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); continue; } - ALOGD("Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); - ALOGD(" vendorId = %04x", record.vendor); - ALOGD(" vendorIdSource = %04x", record.vendor_id_source); - ALOGD(" product = %04x", record.product); - ALOGD(" version = %04x", record.version); - ALOGD(" clientExecutableURL = %s", record.client_executable_url); - ALOGD(" serviceDescription = %s", record.service_description); - ALOGD(" documentationURL = %s", record.documentation_url); + LOG_DEBUG("Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); + LOG_DEBUG(" vendorId = %04x", record.vendor); + LOG_DEBUG(" vendorIdSource = %04x", record.vendor_id_source); + LOG_DEBUG(" product = %04x", record.product); + LOG_DEBUG(" version = %04x", record.version); + LOG_DEBUG(" clientExecutableURL = %s", record.client_executable_url); + LOG_DEBUG(" serviceDescription = %s", record.service_description); + LOG_DEBUG(" documentationURL = %s", record.documentation_url); uint32_t record_handle; tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); if (status != BTA_SUCCESS) { - ALOGE("%s unable to set device ID record %d: error %d.", __func__, i, status); + LOG_ERROR("%s unable to set device ID record %d: error %d.", __func__, i, status); } } diff --git a/main/bte_init.c b/main/bte_init.c index 3e3c1adad..e212f3900 100644 --- a/main/bte_init.c +++ b/main/bte_init.c @@ -31,111 +31,28 @@ #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 @@ -147,20 +64,12 @@ #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" @@ -168,50 +77,6 @@ #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 @@ -219,39 +84,15 @@ #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 @@ -271,7 +112,6 @@ tBTA_JV_CB *bta_jv_cb_ptr = NULL; #include "bta_prm_int.h" #endif /* BTA_INCLUDED */ -// btla-specific -- /***************************************************************************** ** F U N C T I O N S * @@ -292,83 +132,11 @@ tBTA_JV_CB *bta_jv_cb_ptr = NULL; ** Returns void ** ******************************************************************************/ -BT_API void BTE_InitStack(void) +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 ** ***************************/ @@ -389,122 +157,44 @@ BT_API void BTE_InitStack(void) #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 */ +#endif /**************** ** 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 @@ -517,5 +207,5 @@ BT_API void BTE_InitStack(void) #endif #endif /* BTA_INCLUDED == TRUE */ -// btla-specific -- + } diff --git a/main/bte_logmsg.c b/main/bte_logmsg.c index c9fc17eb5..3258f47ca 100644 --- a/main/bte_logmsg.c +++ b/main/bte_logmsg.c @@ -16,76 +16,39 @@ * ******************************************************************************/ -/****************************************************************************** - * - * Contains the LogMsg wrapper routines for BTE. It routes calls the - * appropriate application's LogMsg equivalent. - * - ******************************************************************************/ - #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <sys/time.h> +#include <time.h> -#include "config.h" -#include "gki.h" #include "bte.h" - -#include "bte_appl.h" - -#if MMI_INCLUDED == TRUE -#include "mmi.h" -#endif - -/* always enable trace framework */ - +#include "bta_api.h" #include "btu.h" +#include "osi/include/config.h" +#include "gki.h" #include "l2c_api.h" -#if (RFCOMM_INCLUDED==TRUE) +#include "osi/include/log.h" +#include "stack_config.h" + #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 @@ -96,88 +59,11 @@ #include "smp_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 @@ -185,356 +71,192 @@ const char * const bt_layer_tags[] = { #ifndef BTE_LOG_BUF_SIZE #define BTE_LOG_BUF_SIZE 1024 #endif + #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12) +#define MSG_BUFFER_OFFSET 0 -//#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 +/* LayerIDs for BTA, currently everything maps onto appl_trace_level */ +static 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", + "UNUSED", + "UNUSED", + "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", +}; +static uint8_t BTAPP_SetTraceLevel(uint8_t new_level); +static uint8_t BTIF_SetTraceLevel(uint8_t new_level); +static uint8_t BTU_SetTraceLevel(uint8_t new_level); -// #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 +/* make sure list is order by increasing layer id!!! */ +static 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}, + {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL}, +#if (AVDT_INCLUDED==TRUE) + {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL}, #endif -#if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE) -#define MSG_BUFFER_OFFSET strlen(buffer) -#else -#define MSG_BUFFER_OFFSET 0 + {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL}, +#if (AVDT_INCLUDED==TRUE) + //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL}, #endif - -//#define DBG_TRACE - -#if defined( DBG_TRACE ) -#define DBG_TRACE_API0( m ) BT_TRACE( TRACE_LAYER_HCI, TRACE_TYPE_API, m ) -#define DBG_TRACE_WARNING2( m, p0, p1 ) BT_TRACE( 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 ) +#if (A2D_INCLUDED==TRUE) + {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL}, #endif -#define DBG_TRACE_DEBUG2( m, p0, p1 ) BT_TRACE( 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); +#if (BNEP_INCLUDED==TRUE) + {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL}, #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); + {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL}, +#if (PAN_INCLUDED==TRUE) + {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL}, #endif -#else - write(2, buffer, strlen(buffer)); - write(2, "\n", 1); + {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}, + {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL}, #endif -} -void -ScrLog(UINT32 trace_set_mask, const char *fmt_str, ...) -{ - static char buffer[BTE_LOG_BUF_SIZE]; + /* LayerIDs for BTA, currently everything maps onto appl_trace_level. + */ + {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, "TRC_BTAPP", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL}, - 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); + {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL} +}; -#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 +static const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP); + +void LogMsg(uint32_t 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; + va_start(ap, fmt_str); + vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap); + va_end(ap); + + 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; + } } /* 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; +static uint8_t BTAPP_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) + appl_trace_level = new_level; - return (appl_trace_level); + return appl_trace_level; } -BT_API UINT8 BTIF_SetTraceLevel( UINT8 new_level ) -{ - if (new_level != 0xFF) - btif_trace_level = new_level; +static uint8_t BTIF_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) + btif_trace_level = new_level; - return (btif_trace_level); + return btif_trace_level; } -BTU_API UINT8 BTU_SetTraceLevel( UINT8 new_level ) -{ - if (new_level != 0xFF) - btu_cb.trace_level = new_level; +static uint8_t BTU_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) + btu_cb.trace_level = new_level; - return (btu_cb.trace_level); + return btu_cb.trace_level; } -BOOLEAN trace_conf_enabled = FALSE; - -void bte_trace_conf(const char *p_conf_name, const 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++; - } -} - -void bte_trace_conf_config(const config_t *config) { +static void load_levels_from_config(const config_t *config) { assert(config != NULL); for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) { + LOG_INFO("BTE_InitTraceLevels -- %s", functions->trc_name); int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1); if (value != -1) functions->trace_level = value; + + if (functions->p_f) + functions->p_f(functions->trace_level); } } -/******************************************************************************** - ** - ** 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}, - {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 +static future_t *init(void) { + const stack_config_t *stack_config = stack_config_get_interface(); + if (!stack_config->get_trace_config_enabled()) { + LOG_INFO("[bttrc] using compile default trace settings"); + return NULL; + } -#if (BT_TRACE_BTIF == TRUE) - {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL}, -#endif + load_levels_from_config(stack_config->get_all()); + return NULL; +} - {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL} +const module_t bte_logmsg_module = { + .name = BTE_LOGMSG_MODULE, + .init = init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = NULL, + .dependencies = { + STACK_CONFIG_MODULE, + NULL + } }; - -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 -} diff --git a/main/bte_main.c b/main/bte_main.c index 74983e59e..de62232df 100755 --- a/main/bte_main.c +++ b/main/bte_main.c @@ -23,131 +23,66 @@ * Description: Contains BTE core stack initialization and shutdown code * ******************************************************************************/ -#include <fcntl.h> -#include <stdlib.h> + +#define LOG_TAG "bt_main" + #include <assert.h> +#include <cutils/properties.h> +#include <fcntl.h> +#include <hardware/bluetooth.h> +#include <pthread.h> #include <signal.h> -#include <string.h> +#include <stdlib.h> #include <time.h> -#include <hardware/bluetooth.h> -#include "gki.h" -#include "bd.h" -#include "btu.h" -#include "bte.h" +#include "osi/include/alarm.h" #include "bta_api.h" -#include "bt_utils.h" #include "bt_hci_bdroid.h" +#include "bte.h" +#include "btif_common.h" +#include "btu.h" +#include "btsnoop.h" +#include "bt_utils.h" +#include "btcore/include/counter.h" +#include "osi/include/fixed_queue.h" +#include "osi/include/future.h" +#include "gki.h" +#include "osi/include/hash_functions.h" +#include "osi/include/hash_map.h" +#include "hci_layer.h" +#include "btcore/include/module.h" +#include "osi/include/osi.h" +#include "osi/include/log.h" +#include "stack_config.h" +#include "osi/include/thread.h" /******************************************************************************* ** Constants & Macros *******************************************************************************/ -/* Run-time configuration file */ -#ifndef BTE_STACK_CONF_FILE -#define BTE_STACK_CONF_FILE "/etc/bluetooth/bt_stack.conf" -#endif /* Run-time configuration file for BLE*/ #ifndef BTE_BLE_STACK_CONF_FILE #define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_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 - -/* Stack preload process timeout period */ -#ifndef PRELOAD_START_TIMEOUT_MS -#define PRELOAD_START_TIMEOUT_MS 3000 // 3 seconds -#endif - -/* Stack preload process maximum retry attempts */ -#ifndef PRELOAD_MAX_RETRY_ATTEMPTS -#define PRELOAD_MAX_RETRY_ATTEMPTS 0 -#endif - -/******************************************************************************* -** Local type definitions -*******************************************************************************/ -/* Preload retry control block */ -typedef struct -{ - int retry_counts; - BOOLEAN timer_created; - timer_t timer_id; -} bt_preload_retry_cb_t; - /****************************************************************************** ** Variables ******************************************************************************/ -BOOLEAN hci_logging_enabled = FALSE; /* by default, turn hci log off */ -BOOLEAN hci_logging_config = FALSE; /* configured from bluetooth framework */ -BOOLEAN hci_save_log = FALSE; /* save a copy of the log before starting again */ -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 bt_preload_retry_cb_t preload_retry_cb; -// Lock to serialize cleanup requests from upper layer. -static pthread_mutex_t cleanup_lock; +static const hci_t *hci; /******************************************************************************* ** Static functions *******************************************************************************/ -static void bte_main_in_hw_init(void); -static void bte_hci_enable(void); -static void bte_hci_disable(void); -static void preload_start_wait_timer(void); -static void preload_stop_wait_timer(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); extern void bte_load_ble_conf(const char *p_path); -extern bt_bdaddr_t btif_local_bd_addr; - - -/******************************************************************************* -** 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 -** -******************************************************************************/ -static void bte_main_in_hw_init(void) -{ - if ( (bt_hc_if = (bt_hc_interface_t *) bt_hc_get_interface()) \ - == NULL) - { - APPL_TRACE_ERROR("!!! Failed to get BtHostControllerInterface !!!"); - } - - memset(&preload_retry_cb, 0, sizeof(bt_preload_retry_cb_t)); -} +fixed_queue_t *btu_hci_msg_queue; /****************************************************************************** ** @@ -160,23 +95,26 @@ static void bte_main_in_hw_init(void) ******************************************************************************/ void bte_main_boot_entry(void) { - /* initialize OS */ - GKI_init(); + module_init(get_module(GKI_MODULE)); + module_init(get_module(COUNTER_MODULE)); - bte_main_in_hw_init(); + hci = hci_layer_get_interface(); + if (!hci) + LOG_ERROR("%s could not get hci layer interface.", __func__); + + btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); + if (btu_hci_msg_queue == NULL) { + LOG_ERROR("%s unable to allocate hci message queue.", __func__); + return; + } + + data_dispatcher_register_default(hci->event_dispatcher, btu_hci_msg_queue); + hci->set_data_queue(btu_hci_msg_queue); - bte_load_conf(BTE_STACK_CONF_FILE); #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) bte_load_ble_conf(BTE_BLE_STACK_CONF_FILE); #endif - -#if (BTTRC_INCLUDED == TRUE) - /* Initialize trace feature */ - BTTRC_TraceInit(MAX_TRACE_RAM_SIZE, &BTE_TraceLogBuf[0], BTTRC_METHOD_RAM); -#endif - - pthread_mutex_init(&cleanup_lock, NULL); - + module_init(get_module(STACK_CONFIG_MODULE)); } /****************************************************************************** @@ -190,9 +128,16 @@ void bte_main_boot_entry(void) ******************************************************************************/ void bte_main_shutdown() { - pthread_mutex_destroy(&cleanup_lock); + data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL); + hci->set_data_queue(NULL); + fixed_queue_free(btu_hci_msg_queue, NULL); + + btu_hci_msg_queue = NULL; - GKI_shutdown(); + module_clean_up(get_module(STACK_CONFIG_MODULE)); + + module_clean_up(get_module(COUNTER_MODULE)); + module_clean_up(get_module(GKI_MODULE)); } /****************************************************************************** @@ -209,18 +154,10 @@ void bte_main_enable() { APPL_TRACE_DEBUG("%s", __FUNCTION__); - /* Initialize BTE control block */ - BTE_Init(); - - lpm_enabled = FALSE; + module_start_up(get_module(BTSNOOP_MODULE)); + module_start_up(get_module(HCI_MODULE)); - 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)); - - bte_hci_enable(); - - GKI_run(); + BTU_StartUp(); } /****************************************************************************** @@ -237,203 +174,10 @@ void bte_main_disable(void) { APPL_TRACE_DEBUG("%s", __FUNCTION__); - preload_stop_wait_timer(); - bte_hci_disable(); - GKI_destroy_task(BTU_TASK); -} - -/****************************************************************************** -** -** Function bte_main_config_hci_logging -** -** Description enable or disable HIC snoop logging -** -** Returns None -** -******************************************************************************/ -void bte_main_config_hci_logging(BOOLEAN enable, BOOLEAN bt_disabled) -{ - int old = (hci_logging_enabled == TRUE) || (hci_logging_config == TRUE); - int new; - - if (enable) { - hci_logging_config = TRUE; - } else { - hci_logging_config = FALSE; - } - - new = (hci_logging_enabled == TRUE) || (hci_logging_config == TRUE); - - if ((old == new) || bt_disabled || (bt_hc_if == NULL)) { - return; - } - - bt_hc_if->logging(new ? BT_HC_LOGGING_ON : BT_HC_LOGGING_OFF, hci_logfile, hci_save_log); -} - -/****************************************************************************** -** -** Function bte_hci_enable -** -** Description Enable HCI & Vendor modules -** -** Returns None -** -******************************************************************************/ -static void bte_hci_enable(void) -{ - APPL_TRACE_DEBUG("%s", __FUNCTION__); - - preload_start_wait_timer(); - - if (bt_hc_if) - { - int result = bt_hc_if->init(&hc_callbacks, btif_local_bd_addr.address); - APPL_TRACE_EVENT("libbt-hci init returns %d", result); - - assert(result == BT_HC_STATUS_SUCCESS); - - if (hci_logging_enabled == TRUE || hci_logging_config == TRUE) - bt_hc_if->logging(BT_HC_LOGGING_ON, hci_logfile, hci_save_log); - -#if (defined (BT_CLEAN_TURN_ON_DISABLED) && BT_CLEAN_TURN_ON_DISABLED == TRUE) - APPL_TRACE_DEBUG("%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. + module_shut_down(get_module(HCI_MODULE)); + module_shut_down(get_module(BTSNOOP_MODULE)); - 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); - } -} - -/****************************************************************************** -** -** Function bte_hci_disable -** -** Description Disable HCI & Vendor modules -** -** Returns None -** -******************************************************************************/ -static void bte_hci_disable(void) -{ - APPL_TRACE_DEBUG("%s", __FUNCTION__); - - if (!bt_hc_if) - return; - - // Cleanup is not thread safe and must be protected. - pthread_mutex_lock(&cleanup_lock); - - if (hci_logging_enabled == TRUE || hci_logging_config == TRUE) - bt_hc_if->logging(BT_HC_LOGGING_OFF, hci_logfile, hci_save_log); - bt_hc_if->cleanup(); - - pthread_mutex_unlock(&cleanup_lock); -} - -/******************************************************************************* -** -** Function preload_wait_timeout -** -** Description Timeout thread of preload watchdog timer -** -** Returns None -** -*******************************************************************************/ -static void preload_wait_timeout(union sigval arg) -{ - UNUSED(arg); - - APPL_TRACE_ERROR("...preload_wait_timeout (retried:%d/max-retry:%d)...", - preload_retry_cb.retry_counts, - PRELOAD_MAX_RETRY_ATTEMPTS); - - if (preload_retry_cb.retry_counts++ < PRELOAD_MAX_RETRY_ATTEMPTS) - { - bte_hci_disable(); - GKI_delay(100); - bte_hci_enable(); - } - else - { - /* Notify BTIF_TASK that the init procedure had failed*/ - GKI_send_event(BTIF_TASK, BT_EVT_HARDWARE_INIT_FAIL); - } -} - -/******************************************************************************* -** -** Function preload_start_wait_timer -** -** Description Launch startup watchdog timer -** -** Returns None -** -*******************************************************************************/ -static void preload_start_wait_timer(void) -{ - int status; - struct itimerspec ts; - struct sigevent se; - UINT32 timeout_ms = PRELOAD_START_TIMEOUT_MS; - - if (preload_retry_cb.timer_created == FALSE) - { - se.sigev_notify = SIGEV_THREAD; - se.sigev_value.sival_ptr = &preload_retry_cb.timer_id; - se.sigev_notify_function = preload_wait_timeout; - se.sigev_notify_attributes = NULL; - - status = timer_create(CLOCK_MONOTONIC, &se, &preload_retry_cb.timer_id); - - if (status == 0) - preload_retry_cb.timer_created = TRUE; - } - - if (preload_retry_cb.timer_created == TRUE) - { - ts.it_value.tv_sec = timeout_ms/1000; - ts.it_value.tv_nsec = 1000000*(timeout_ms%1000); - ts.it_interval.tv_sec = 0; - ts.it_interval.tv_nsec = 0; - - status = timer_settime(preload_retry_cb.timer_id, 0, &ts, 0); - if (status == -1) - APPL_TRACE_ERROR("Failed to fire preload watchdog timer"); - } -} - -/******************************************************************************* -** -** Function preload_stop_wait_timer -** -** Description Stop preload watchdog timer -** -** Returns None -** -*******************************************************************************/ -static void preload_stop_wait_timer(void) -{ - if (preload_retry_cb.timer_created == TRUE) - { - timer_delete(preload_retry_cb.timer_id); - preload_retry_cb.timer_created = FALSE; - } + BTU_ShutDown(); } /****************************************************************************** @@ -447,8 +191,7 @@ static void preload_stop_wait_timer(void) ******************************************************************************/ void bte_main_postload_cfg(void) { - if (bt_hc_if) - bt_hc_if->postload(NULL); + hci->do_postload(); } #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE) @@ -463,14 +206,7 @@ void bte_main_postload_cfg(void) ******************************************************************************/ 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_EVENT("HC lib lpm enable=%d return %d", enable, result); + hci->send_low_power_command(enable ? LPM_ENABLE : LPM_DISABLE); } /****************************************************************************** @@ -484,12 +220,7 @@ void bte_main_enable_lpm(BOOLEAN enable) ******************************************************************************/ 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_DEBUG("HC lib lpm deassertion return %d", result); + hci->send_low_power_command(LPM_WAKE_DEASSERT); } /****************************************************************************** @@ -503,75 +234,10 @@ void bte_main_lpm_allow_bt_device_sleep() ******************************************************************************/ 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_DEBUG("HC lib lpm assertion return %d", result); + hci->send_low_power_command(LPM_WAKE_ASSERT); } #endif // HCILP_INCLUDED - -/* NOTICE: - * Definitions for audio state structure, this type needs to match to - * the bt_vendor_op_audio_state_t type defined in bt_vendor_lib.h - */ -typedef struct { - UINT16 handle; - UINT16 peer_codec; - UINT16 state; -} bt_hc_audio_state_t; - -struct bt_audio_state_tag { - BT_HDR hdr; - bt_hc_audio_state_t audio; -}; - -/****************************************************************************** -** -** Function set_audio_state -** -** Description Sets audio state on controller state for SCO (PCM, WBS, FM) -** -** Parameters handle: codec related handle for SCO: sco cb idx, unused for -** codec: BTA_AG_CODEC_MSBC, BTA_AG_CODEC_CSVD or FM codec -** state: codec state, eg. BTA_AG_CO_AUD_STATE_SETUP -** param: future extensions, e.g. call-in structure/event. -** -** Returns None -** -******************************************************************************/ -int set_audio_state(UINT16 handle, UINT16 codec, UINT8 state, void *param) -{ - struct bt_audio_state_tag *p_msg; - int result = -1; - - APPL_TRACE_API("set_audio_state(handle: %d, codec: 0x%x, state: %d)", handle, - codec, state); - if (NULL != param) - APPL_TRACE_WARNING("set_audio_state() non-null param not supported"); - p_msg = (struct bt_audio_state_tag *)GKI_getbuf(sizeof(*p_msg)); - if (!p_msg) - return result; - p_msg->audio.handle = handle; - p_msg->audio.peer_codec = codec; - p_msg->audio.state = state; - - p_msg->hdr.event = MSG_CTRL_TO_HC_CMD | (MSG_SUB_EVT_MASK & BT_HC_AUDIO_STATE); - p_msg->hdr.len = sizeof(p_msg->audio); - p_msg->hdr.offset = 0; - /* layer_specific shall contain return path event! for BTA events! - * 0 means no return message is expected. */ - p_msg->hdr.layer_specific = 0; - if (bt_hc_if) - { - bt_hc_if->tx_cmd((TRANSAC)p_msg, (char *)(&p_msg->audio), sizeof(*p_msg)); - } - return result; -} - - /****************************************************************************** ** ** Function bte_main_hci_send @@ -590,16 +256,13 @@ void bte_main_hci_send (BT_HDR *p_msg, UINT16 event) p_msg->event = event; + counter_add("main.tx.packets", 1); + counter_add("main.tx.bytes", p_msg->len); 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); + hci->transmit_downward(event, p_msg); } else { @@ -607,240 +270,3 @@ void bte_main_hci_send (BT_HDR *p_msg, UINT16 event) 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) -{ - UNUSED(transac); - - APPL_TRACE_EVENT("HC preload_cb %d [0:SUCCESS 1:FAIL]", result); - - if (result == BT_HC_PRELOAD_SUCCESS) - { - preload_stop_wait_timer(); - - /* notify BTU task that libbt-hci is ready */ - GKI_send_event(BTU_TASK, BT_EVT_PRELOAD_CMPL); - } -} - -/****************************************************************************** -** -** 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) -{ - UNUSED(transac); - - APPL_TRACE_EVENT("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_EVENT("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_EVENT("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_DEBUG("HC alloc size=%d", size); - */ - - /* Requested buffer size cannot exceed GKI_MAX_BUF_SIZE. */ - if (size > GKI_MAX_BUF_SIZE) - { - APPL_TRACE_ERROR("HCI DATA SIZE %d greater than MAX %d", - size, GKI_MAX_BUF_SIZE); - return NULL; - } - - p_hdr = (BT_HDR *) GKI_getbuf ((UINT16) size); - - if (p_hdr == NULL) - { - APPL_TRACE_WARNING("alloc returns NO BUFFER! (sz %d)", size); - } - - 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. -** -******************************************************************************/ -static void dealloc(TRANSAC transac) -{ - GKI_freebuf(transac); -} - -/****************************************************************************** -** -** 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) -{ - UNUSED(p_buf); - UNUSED(len); - - /* - APPL_TRACE_DEBUG("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) -{ - UNUSED(p_buf); - /* - APPL_TRACE_DEBUG("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/stack_config.c b/main/stack_config.c new file mode 100644 index 000000000..6e1431ee4 --- /dev/null +++ b/main/stack_config.c @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * Copyright (C) 2014 Google, 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. + * + ******************************************************************************/ + +#define LOG_TAG "bt_stack_config" + +#include <assert.h> + +#include "osi/include/future.h" +#include "stack_config.h" +#include "osi/include/log.h" + +const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName"; +const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput"; +const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog"; +const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf"; + +static config_t *config; + +// Module lifecycle functions + +static future_t *init() { + const char *path = "/etc/bluetooth/bt_stack.conf"; + assert(path != NULL); + + LOG_INFO("%s attempt to load stack conf from %s", __func__, path); + + config = config_new(path); + if (!config) { + LOG_INFO("%s file >%s< not found", __func__, path); + return future_new_immediate(FUTURE_FAIL); + } + + return future_new_immediate(FUTURE_SUCCESS); +} + +static future_t *clean_up() { + config_free(config); + return future_new_immediate(FUTURE_SUCCESS); +} + +const module_t stack_config_module = { + .name = STACK_CONFIG_MODULE, + .init = init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = clean_up, + .dependencies = { + NULL + } +}; + +// Interface functions + +static const char *get_btsnoop_log_path(void) { + return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log"); +} + +static bool get_btsnoop_turned_on(void) { + return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false); +} + +static bool get_btsnoop_should_save_last(void) { + return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false); +} + +static bool get_trace_config_enabled(void) { + return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false); +} + +static config_t *get_all(void) { + return config; +} + +const stack_config_t interface = { + get_btsnoop_log_path, + get_btsnoop_turned_on, + get_btsnoop_should_save_last, + get_trace_config_enabled, + get_all +}; + +const stack_config_t *stack_config_get_interface() { + return &interface; +} |