From e448862a47c08eb23185aaed574b39264f5005fc Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Wed, 22 Feb 2012 13:18:21 -0800 Subject: Initial Bluedroid stack commit --- main/Android.mk | 85 ++++++++ main/bte_init.c | 523 +++++++++++++++++++++++++++++++++++++++++++++++ main/bte_logmsg.c | 589 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main/bte_main.c | 550 +++++++++++++++++++++++++++++++++++++++++++++++++ main/bte_version.c | 14 ++ 5 files changed, 1761 insertions(+) create mode 100644 main/Android.mk create mode 100644 main/bte_init.c create mode 100644 main/bte_logmsg.c create mode 100644 main/bte_main.c create mode 100644 main/bte_version.c (limited to 'main') diff --git a/main/Android.mk b/main/Android.mk new file mode 100644 index 0000000..f30a24a --- /dev/null +++ b/main/Android.mk @@ -0,0 +1,85 @@ +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\ + +# 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_hf.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 \ + +# candidates for vendor lib (keep here for now) +LOCAL_SRC_FILES+= \ + ../udrv/ulinux/unv_linux.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/btm \ + $(LOCAL_PATH)/../hcis \ + $(LOCAL_PATH)/../hcis/include \ + $(LOCAL_PATH)/../hcis/patchram \ + $(LOCAL_PATH)/../udrv/include \ + $(LOCAL_PATH)/../btif/include \ + $(LOCAL_PATH)/../vendor/libvendor/include\ + +LOCAL_CFLAGS += -DBUILDCFG -Werror + +ifeq ($(TARGET_PRODUCT), full_crespo) + LOCAL_CFLAGS += -DTARGET_CRESPO +else + 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-vendor + +#LOCAL_WHOLE_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_stack libbt-brcm_bta +LOCAL_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_stack libbt-brcm_bta + +LOCAL_MODULE := bluetooth.default +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw +LOCAL_MODULE_TAGS := eng + + +include $(BUILD_SHARED_LIBRARY) diff --git a/main/bte_init.c b/main/bte_init.c new file mode 100644 index 0000000..638f2be --- /dev/null +++ b/main/bte_init.c @@ -0,0 +1,523 @@ +/***************************************************************************** +** * +** Name: bte_init.c * +** * +** Description: This module contains the routines that initialize the * +** stack components. It must be called before the BTU task * +** is started. * +** * +** Note: If using dynamic memory, the control bloacks for * +** each component must already be allocated * +** * +** Copyright (c) 2000-2011, Broadcom Corp., All Rights Reserved. * +** Broadcom Bluetooth Core. Proprietary and confidential. * +******************************************************************************/ + +#include "bt_target.h" +#include + +#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(VDP_INCLUDED) && VDP_INCLUDED == TRUE) +#include "vdp_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_AVK_INCLUDED==TRUE +#include "bta_avk_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(VDP_INCLUDED) && VDP_INCLUDED == TRUE) + VDP_Init(); +#endif + +#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_AVK_INCLUDED==TRUE + memset((void *)bta_avk_cb_ptr, 0, sizeof(tBTA_AVK_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..494c1a6 --- /dev/null +++ b/main/bte_logmsg.c @@ -0,0 +1,589 @@ +/***************************************************************************** +** +** Name: bte_logmsg.c +** +** Description: Contains the LogMsg wrapper routines for BTE. It routes calls +** the appropriate application's LogMsg equivalent. +** +** Copyright (c) 2001-2011, WIDCOMM Inc., All Rights Reserved. +** WIDCOMM Bluetooth Core. Proprietary and confidential. +******************************************************************************/ + +#include +#include +#include + +#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 (VDP_INCLUDED==TRUE) +#include "vdp_api.h" +#endif + +#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 +#include + +#if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE)) +#define LOG_TAG "BTLD" + +#ifndef LINUX_NATIVE +#include +#define LOGI0(s) __android_log_write(ANDROID_LOG_INFO, NULL, s) +#define LOGD0(s) __android_log_write(ANDROID_LOG_DEBUG, NULL, s) +#define LOGW0(s) __android_log_write(ANDROID_LOG_WARN, NULL, s) +#define LOGE0(s) __android_log_write(ANDROID_LOG_ERROR, NULL, s) + +#else +#undef ANDROID_USE_LOGCAT +#endif + +#endif + + +//#include "btl_cfg.h" +#define BTL_GLOBAL_PROP_TRC_FLAG "TRC_BTAPP" + + +#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]; + + 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(buffer); + break; + case TRACE_TYPE_WARNING: + LOGW0(buffer); + break; + case TRACE_TYPE_API: + case TRACE_TYPE_EVENT: + LOGI0(buffer); + break; + case TRACE_TYPE_DEBUG: + LOGD0(buffer); + break; + default: + LOGE0(buffer); /* we should never get this */ + break; + } +#else + LOGI0(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; + + 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(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); +} + + + + +/******************************************************************************** + ** + ** 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!!! */ +const tBTTRC_FUNC_MAP bttrc_set_level_map[] = { + { BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, (const tBTTRC_SET_TRACE_LEVEL *)BTU_SetTraceLevel, "TRC_HCI" }, + { BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, (const tBTTRC_SET_TRACE_LEVEL *)L2CA_SetTraceLevel, "TRC_L2CAP" }, +#if (RFCOMM_INCLUDED==TRUE) + { BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, (const tBTTRC_SET_TRACE_LEVEL *)PORT_SetTraceLevel, "TRC_RFCOMM" }, +#endif +#if (OBX_INCLUDED==TRUE) + { BTTRC_ID_STK_OBEX, BTTRC_ID_STK_OBEX, (const tBTTRC_SET_TRACE_LEVEL *)OBX_SetTraceLevel, "TRC_OBEX" }, +#endif +#if (AVCT_INCLUDED==TRUE) + { BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, (tBTTRC_SET_TRACE_LEVEL *)NULL, "TRC_AVCT" }, +#endif +#if (AVDT_INCLUDED==TRUE) + { BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, (const tBTTRC_SET_TRACE_LEVEL *)AVDT_SetTraceLevel, "TRC_AVDT" }, +#endif +#if (AVRC_INCLUDED==TRUE) + { BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, (const tBTTRC_SET_TRACE_LEVEL *)AVRC_SetTraceLevel, "TRC_AVRC" }, +#endif +#if (AVDT_INCLUDED==TRUE) + { BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, (tBTTRC_SET_TRACE_LEVEL *)NULL, "TRC_AVDT_SCB" }, +#endif +#if (A2D_INCLUDED==TRUE) + { BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, (const tBTTRC_SET_TRACE_LEVEL *)A2D_SetTraceLevel, "TRC_A2D" }, +#endif +#if (BIP_INCLUDED==TRUE) + { BTTRC_ID_STK_BIP, BTTRC_ID_STK_BIP, (const tBTTRC_SET_TRACE_LEVEL *)BIP_SetTraceLevel, "TRC_BIP" }, +#endif +#if (BNEP_INCLUDED==TRUE) + { BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, (const tBTTRC_SET_TRACE_LEVEL *)BNEP_SetTraceLevel, "TRC_BNEP" }, +#endif +#if (BPP_INCLUDED==TRUE) + { BTTRC_ID_STK_BPP, BTTRC_ID_STK_BPP, (const tBTTRC_SET_TRACE_LEVEL *)BPP_SetTraceLevel, "TRC_BPP" }, +#endif + { BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, (const tBTTRC_SET_TRACE_LEVEL *)BTM_SetTraceLevel, "TRC_BTM" }, +#if (DUN_INCLUDED==TRUE) + { BTTRC_ID_STK_DUN, BTTRC_ID_STK_DUN, (const tBTTRC_SET_TRACE_LEVEL *)DUN_SetTraceLevel, "TRC_DUN" }, +#endif +#if (GAP_INCLUDED==TRUE) + { BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, (const tBTTRC_SET_TRACE_LEVEL *)GAP_SetTraceLevel, "TRC_GAP" }, +#endif +#if (GOEP_INCLUDED==TRUE) + { BTTRC_ID_STK_GOEP, BTTRC_ID_STK_GOEP, (const tBTTRC_SET_TRACE_LEVEL *)GOEP_SetTraceLevel, "TRC_GOEP" }, +#endif +#if (HCRP_INCLUDED==TRUE) + { BTTRC_ID_STK_HCRP, BTTRC_ID_STK_HCRP, (const tBTTRC_SET_TRACE_LEVEL *)HCRP_SetTraceLevel, "TRC_HCRP" }, +#endif +#if (PAN_INCLUDED==TRUE) + { BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, (const tBTTRC_SET_TRACE_LEVEL *)PAN_SetTraceLevel, "TRC_PAN" }, +#endif +#if (SAP_SERVER_INCLUDED==TRUE) + { BTTRC_ID_STK_SAP, BTTRC_ID_STK_SAP, (tBTTRC_SET_TRACE_LEVEL *)NULL, "TRC_SAP" }, +#endif + { BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, (const tBTTRC_SET_TRACE_LEVEL *)SDP_SetTraceLevel, "TRC_SDP" }, +#if (VDP_INCLUDED==TRUE) + { BTTRC_ID_STK_VDP, BTTRC_ID_STK_VDP, (const tBTTRC_SET_TRACE_LEVEL *)VDP_SetTraceLevel, "TRC_VDP" }, +#endif +#if (BLE_INCLUDED==TRUE) + { BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, (const tBTTRC_SET_TRACE_LEVEL *)GATT_SetTraceLevel , "TRC_GATT" }, +#endif +#if (BLE_INCLUDED==TRUE) + { BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, (const tBTTRC_SET_TRACE_LEVEL *)SMP_SetTraceLevel , "TRC_SMP" }, +#endif + + /* LayerIDs for BTA, currently everything maps onto appl_trace_level. BTL_GLOBAL_PROP_TRC_FLAG + * serves as flag in property. if present, the whole table is scanned. */ +#if (BTA_INCLUDED==TRUE) + { BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, (const tBTTRC_SET_TRACE_LEVEL *)BTAPP_SetTraceLevel, BTL_GLOBAL_PROP_TRC_FLAG }, +#endif + +#if 0 + {BTTRC_ID_BTA_HF 39 /* headset/handsfree AG & HF */ + {BTTRC_ID_BTA_AV 40 /* Advanced audio */ + {BTTRC_ID_BTA_BIP 41 /* Basic Imaging Client */ + {BTTRC_ID_BTA_BP 42 /* Basic Printing Client */ + {BTTRC_ID_BTA_CTP 43 /* cordless telephony profile */ + {BTTRC_ID_BTA_DG 44 /* data gateway */ + {BTTRC_ID_BTA_DM 45 /* device manager */ + {BTTRC_ID_BTA_FM 46 + {BTTRC_ID_BTA_FS 47 /* File System */ + {BTTRC_ID_BTA_FTP 48 /* file transfer client & server */ + {BTTRC_ID_BTA_HID 49 /* hidc & hidd */ + {BTTRC_ID_BTA_JV 50 /* java connector */ + {BTTRC_ID_BTA_OPP 51 /* object push client */ + {BTTRC_ID_BTA_PAN 52 /* Personal Area Networking */ + {BTTRC_ID_BTA_PR 53 /* Printer module */ + {BTTRC_ID_BTA_SC 54 /* SIM Card Access module */ + {BTTRC_ID_BTA_SS 55 /* synchronization module */ + {BTTRC_ID_BTA_SYS 56 /* system manager */ + {BTTRC_ID_BTA_SSR 57 /* GPS sensor */ + {BTTRC_ID_BTA_ME 58 /* message equipement server/client */ + + /* LayerIDs for BT APP */ + { BTTRC_ID_BTAPP, BTTRC_ID_BTAPP, (const tBTTRC_SET_TRACE_LEVEL *)BTAPP_SetTraceLevel, "BTAPP" }, +#endif + + { 0, 0, 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 from android property system and call the different + * XXX_SetTraceLevel(). + */ +#if ( BT_USE_TRACES==TRUE ) + /* read runtime trace settings after init of control block */ + + // BLUEDROID MOD + //if ( !btl_cfg_get_trace_prop() ) + { +#if defined(BTL_CFG_USE_CONF_FILE) && (BTL_CFG_USE_CONF_FILE==TRUE) + if (NULL!=bte_appl_cfg.p_conf_params) + { + if ( 0 > btl_cfg_set_by_idx_conf( &conf_table, bte_appl_cfg.p_conf_params, + BTL_CFG_CONF_TRACE) ) + { + BT_TRACE_0( TRACE_LAYER_NONE, TRACE_TYPE_DEBUG, "[bttrc] using compile default trace settings" ); + } + /* free up property settings data from conf file as needed anymore */ + GKI_os_free(bte_appl_cfg.p_conf_params); + bte_appl_cfg.p_conf_params = NULL; + BT_TRACE_0( TRACE_LAYER_NONE, TRACE_TYPE_DEBUG, "BTE_InitTraceLevels(): freed p_conf_params" ); + } + else + { + BT_TRACE_0( TRACE_LAYER_NONE, TRACE_TYPE_DEBUG, "[bttrc] using compile default trace settings" ); + } +#else + BT_TRACE_0( TRACE_LAYER_NONE, TRACE_TYPE_DEBUG, "[bttrc] using compile default trace settings" ); +#endif + } +#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..5def921 --- /dev/null +++ b/main/bte_main.c @@ -0,0 +1,550 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * This program is the proprietary software of Broadcom Corporation and/or its + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. + * + * Except as expressly set forth in the Authorized License, + * + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of + * Broadcom integrated circuit products. + * + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT + * OF USE OR PERFORMANCE OF THE SOFTWARE. + * + * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: bte_main.c + * + * Description: Contains BTE core stack initialization and shutdown code + * + ******************************************************************************/ +#include +#include + +#include "gki.h" +#include "bd.h" +#include "btu.h" +#include "bte.h" +#include "bta_api.h" +#include "bt_vendor_lib.h" + +/******************************************************************************* +** Constants & Macros +*******************************************************************************/ + +/******************************************************************************* +** Local type definitions +*******************************************************************************/ + +/******************************************************************************* +** Static variables +*******************************************************************************/ +static bt_vendor_interface_t *bt_vendor_if=NULL; +static const bt_vendor_callbacks_t vnd_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 btsnoop_init(void); +extern void btsnoop_open(void); +extern void btsnoop_close(void); +extern void btsnoop_cleanup (void); + + + +/******************************************************************************* +** 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) +{ + GKI_delay(200); + + if ( (bt_vendor_if = (bt_vendor_interface_t *) bt_vendor_get_interface()) == NULL) + { + APPL_TRACE_ERROR0("!!! Failed to get BtVendorInterface !!!"); + } + else + { + int result = bt_vendor_if->init(&vnd_callbacks); + APPL_TRACE_EVENT1("libbt-vendor init returns %d", result); + } +} + +/****************************************************************************** +** +** 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(); + +#if (BTTRC_INCLUDED == TRUE) + /* Initialize trace feature */ + BTTRC_TraceInit(MAX_TRACE_RAM_SIZE, &BTE_TraceLogBuf[0], BTTRC_METHOD_RAM); +#endif + + /* Initialize BTE control block */ + BTE_Init(); +} + +/****************************************************************************** +** +** Function bte_main_shutdown +** +** Description BTE MAIN API - Shutdown code for BTE chip/stack +** +** Returns None +** +******************************************************************************/ +void bte_main_shutdown() +{ + if (bt_vendor_if) + bt_vendor_if->cleanup(); + + bt_vendor_if = NULL; + 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(void) +{ + APPL_TRACE_DEBUG1("%s", __FUNCTION__); + lpm_enabled = FALSE; + + if (bt_vendor_if) + { + /* toggle chip power to ensure we will reset chip in case + a previous stack shutdown wasn't completed gracefully */ + bt_vendor_if->set_power(BT_VENDOR_CHIP_PWR_OFF); + bt_vendor_if->set_power(BT_VENDOR_CHIP_PWR_ON); + + bt_vendor_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__); + + GKI_destroy_task(BTU_TASK); + + GKI_freeze(); + + if (bt_vendor_if) + bt_vendor_if->set_power(BT_VENDOR_CHIP_PWR_OFF); +} + +/****************************************************************************** +** +** Function bte_main_postload_cfg +** +** Description BTE MAIN API - Stack postload configuration +** +** Returns None +** +******************************************************************************/ +void bte_main_postload_cfg(void) +{ + if (bt_vendor_if) + bt_vendor_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_vendor_if) + result = bt_vendor_if->lpm( \ + (enable == TRUE) ? BT_VENDOR_LPM_ENABLE : BT_VENDOR_LPM_DISABLE \ + ); + + APPL_TRACE_EVENT2("vendor 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_vendor_if) && (lpm_enabled == TRUE)) + result = bt_vendor_if->lpm(BT_VENDOR_LPM_WAKE_DEASSERT); + + APPL_TRACE_DEBUG1("vendor 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_vendor_if) && (lpm_enabled == TRUE)) + result = bt_vendor_if->lpm(BT_VENDOR_LPM_WAKE_ASSERT); + + APPL_TRACE_DEBUG1("vendor 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_vendor_if) + bt_vendor_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-vendor Callback Functions +** +*****************************************************************************/ + +/****************************************************************************** +** +** Function preload_cb +** +** Description VENDOR LIB CALLBACK API - This function is called +** when vendor lib completed stack preload process +** +** Returns None +** +******************************************************************************/ +static void preload_cb(TRANSAC transac, bt_vendor_preload_result_t result) +{ + APPL_TRACE_EVENT1("vnd preload_cb %d [0:SUCCESS 1:FAIL]", result); + +// if (result == BT_VENDOR_PRELOAD_SUCCESS) + /* keep going even if firmware patch file is missing */ + { + /* notify BTU task that libbt-vendor is ready */ + GKI_send_event(BTU_TASK, TASK_MBOX_0_EVT_MASK); + } +} + +/****************************************************************************** +** +** Function postload_cb +** +** Description VENDOR LIB CALLBACK API - This function is called +** when vendor lib completed stack postload process +** +** Returns None +** +******************************************************************************/ +static void postload_cb(TRANSAC transac, bt_vendor_postload_result_t result) +{ + APPL_TRACE_EVENT1("vnd postload_cb %d", result); +} + +/****************************************************************************** +** +** Function lpm_cb +** +** Description VENDOR LIB CALLBACK API - This function is called +** back from vendor lib to indicate the current LPM state +** +** Returns None +** +******************************************************************************/ +static void lpm_cb(bt_vendor_lpm_request_result_t result) +{ + APPL_TRACE_EVENT1("vnd lpm_result_cb %d", result); + lpm_enabled = (result == BT_VENDOR_LPM_ENABLED) ? TRUE : FALSE; +} + +/****************************************************************************** +** +** Function hostwake_ind +** +** Description VENDOR LIB CALLOUT API - This function is called +** from vendor lib to indicate the HostWake event +** +** Returns None +** +******************************************************************************/ +static void hostwake_ind(bt_vendor_low_power_event_t event) +{ + APPL_TRACE_EVENT1("vnd hostwake_ind %d", event); +} + +/****************************************************************************** +** +** Function alloc +** +** Description VENDOR LIB CALLOUT API - This function is called +** from vendor lib 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("vnd 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 VENDOR LIB CALLOUT API - This function is called +** from vendor lib to release the data buffer allocated +** through the alloc call earlier. +** +** Returns bt_vnd_status_t +** +******************************************************************************/ +static int dealloc(TRANSAC transac, char *p_buf) +{ + GKI_freebuf(transac); + return BT_VENDOR_STATUS_SUCCESS; +} + +/****************************************************************************** +** +** Function data_ind +** +** Description VENDOR LIB CALLOUT API - This function is called +** from vendor lib to pass in the received HCI packets. +** +** The core stack is responsible for releasing the data buffer +** passed in from vendor lib once the core stack has done with +** it. +** +** Returns bt_vnd_status_t +** +******************************************************************************/ +static int data_ind(TRANSAC transac, char *p_buf, int len) +{ + BT_HDR *p_msg = (BT_HDR *) transac; + +// APPL_TRACE_DEBUG2("vnd data_ind event=0x%04X (len=%d)", p_msg->event, len); + + + GKI_send_msg (BTU_TASK, BTU_HCI_RCV_MBOX, transac); + return BT_VENDOR_STATUS_SUCCESS; +} + +/****************************************************************************** +** +** Function tx_result +** +** Description VENDOR LIB CALLBACK API - This function is called +** from vendor lib 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. +** +** Returns bt_vnd_status_t +** +******************************************************************************/ +static int tx_result(TRANSAC transac, char *p_buf, \ + bt_vendor_transmit_result_t result) +{ + /* + APPL_TRACE_DEBUG2("vnd tx_result %d (event=%04X)", result, \ + ((BT_HDR *)transac)->event); + */ + + if (result == BT_VENDOR_TX_FRAGMENT) + { + GKI_send_msg (BTU_TASK, BTU_HCI_RCV_MBOX, transac); + } + else + { + GKI_freebuf(transac); + } + + return BT_VENDOR_STATUS_SUCCESS; +} + +/***************************************************************************** +** The libbt-vendor Callback Functions Table +*****************************************************************************/ +static const bt_vendor_callbacks_t vnd_callbacks = { + sizeof(bt_vendor_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..96e3a41 --- /dev/null +++ b/main/bte_version.c @@ -0,0 +1,14 @@ +/*****************************************************************************/ +/* */ +/* Name: bte_version.c */ +/* */ +/* Description: */ +/* BTE Version string declaration. */ +/* */ +/* Copyright (c) 2001 - 2004, WIDCOMM Inc., All Rights Reserved. */ +/* WIDCOMM Bluetooth Core. Proprietary and confidential. */ +/*****************************************************************************/ +#include "bt_types.h" + +const UINT8 bte_version_string[] = "BCM1200_PI_10.3.20.33"; + -- cgit v1.1